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 ignoring_unicode_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())?; // PassesWhen 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())?; // PassesWhen 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())?; // PassesThis 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())?; // FailsThis is not guaranteed to match strings with differing upper/lower case characters outside of the codepoints 0-127 covered by ASCII.
Sourcefn ignoring_unicode_case(self) -> StrMatcher<ExpectedT>
fn ignoring_unicode_case(self) -> StrMatcher<ExpectedT>
Configures the matcher to ignore Unicode case when comparing values.
This uses the same rules for case as str::to_lowercase.
verify_that!("ὈΔΥΣΣΕΎΣ", eq("ὀδυσσεύς").ignoring_unicode_case())?; // Passes
verify_that!("secret", eq("비밀").ignoring_unicode_case())?; // FailsSourcefn 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)))?; // FailsThe 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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.