Trait googletest::matchers::StrMatcherConfigurator
source · pub trait StrMatcherConfigurator<ExpectedT> {
// Required methods
fn ignoring_leading_whitespace(self) -> StrMatcher<ExpectedT>;
fn ignoring_trailing_whitespace(self) -> StrMatcher<ExpectedT>;
fn ignoring_outer_whitespace(self) -> StrMatcher<ExpectedT>;
fn ignoring_ascii_case(self) -> StrMatcher<ExpectedT>;
fn times(
self,
times: impl Matcher<usize> + 'static,
) -> StrMatcher<ExpectedT>;
}
Expand description
Extension trait to configure StrMatcher
.
Matchers which match against string values and, through configuration,
specialise to StrMatcher
implement this trait. That includes
EqMatcher
and StrMatcher
.
Required Methods§
sourcefn ignoring_leading_whitespace(self) -> StrMatcher<ExpectedT>
fn ignoring_leading_whitespace(self) -> StrMatcher<ExpectedT>
Configures the matcher to ignore any leading whitespace in either the actual or the expected value.
Whitespace is defined as in str::trim_start
.
verify_that!("A string", eq(" A string").ignoring_leading_whitespace())?; // Passes
verify_that!(" A string", eq("A string").ignoring_leading_whitespace())?; // Passes
When all other configuration options are left as the defaults, this is
equivalent to invoking str::trim_start
on both the expected and
actual value.
sourcefn ignoring_trailing_whitespace(self) -> StrMatcher<ExpectedT>
fn ignoring_trailing_whitespace(self) -> StrMatcher<ExpectedT>
Configures the matcher to ignore any trailing whitespace in either the actual or the expected value.
Whitespace is defined as in str::trim_end
.
verify_that!("A string", eq("A string ").ignoring_trailing_whitespace())?; // Passes
verify_that!("A string ", eq("A string").ignoring_trailing_whitespace())?; // Passes
When all other configuration options are left as the defaults, this is
equivalent to invoking str::trim_end
on both the expected and
actual value.
sourcefn ignoring_outer_whitespace(self) -> StrMatcher<ExpectedT>
fn ignoring_outer_whitespace(self) -> StrMatcher<ExpectedT>
Configures the matcher to ignore both leading and trailing whitespace in either the actual or the expected value.
Whitespace is defined as in str::trim
.
verify_that!("A string", eq(" A string ").ignoring_outer_whitespace())?; // Passes
verify_that!(" A string ", eq("A string").ignoring_outer_whitespace())?; // Passes
This is equivalent to invoking both
ignoring_leading_whitespace
and
ignoring_trailing_whitespace
.
When all other configuration options are left as the defaults, this is
equivalent to invoking str::trim
on both the expected and actual
value.
sourcefn ignoring_ascii_case(self) -> StrMatcher<ExpectedT>
fn ignoring_ascii_case(self) -> StrMatcher<ExpectedT>
Configures the matcher to ignore ASCII case when comparing values.
This uses the same rules for case as str::eq_ignore_ascii_case
.
verify_that!("Some value", eq("SOME VALUE").ignoring_ascii_case())?; // Passes
verify_that!("Another value", eq("Some value").ignoring_ascii_case())?; // Fails
This is not guaranteed to match strings with differing upper/lower case characters outside of the codepoints 0-127 covered by ASCII.
sourcefn times(self, times: impl Matcher<usize> + 'static) -> StrMatcher<ExpectedT>
fn times(self, times: impl Matcher<usize> + 'static) -> StrMatcher<ExpectedT>
Configures the matcher to match only strings which otherwise satisfy the
conditions a number times matched by the matcher times
.
verify_that!("Some value\nSome value", contains_substring("value").times(eq(2)))?; // Passes
verify_that!("Some value", contains_substring("value").times(eq(2)))?; // Fails
The matched substrings must be disjoint from one another to be counted. For example:
// Fails: substrings distinct but not disjoint!
verify_that!("ababab", contains_substring("abab").times(eq(2)))?;
This is only meaningful when the matcher was constructed with
contains_substring
. This method will panic when it is used with any
other matcher construction.