pub trait StrMatcherConfigurator<ActualT: ?Sized, ExpectedT> {
    // Required methods
    fn ignoring_leading_whitespace(self) -> StrMatcher<ActualT, ExpectedT>;
    fn ignoring_trailing_whitespace(self) -> StrMatcher<ActualT, ExpectedT>;
    fn ignoring_outer_whitespace(self) -> StrMatcher<ActualT, ExpectedT>;
    fn ignoring_ascii_case(self) -> StrMatcher<ActualT, ExpectedT>;
    fn times(
        self,
        times: impl Matcher<ActualT = usize> + 'static
    ) -> StrMatcher<ActualT, 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§

source

fn ignoring_leading_whitespace(self) -> StrMatcher<ActualT, 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.

source

fn ignoring_trailing_whitespace(self) -> StrMatcher<ActualT, 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.

source

fn ignoring_outer_whitespace(self) -> StrMatcher<ActualT, 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.

source

fn ignoring_ascii_case(self) -> StrMatcher<ActualT, 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.

source

fn times( self, times: impl Matcher<ActualT = usize> + 'static ) -> StrMatcher<ActualT, 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.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<ActualT: ?Sized, ExpectedT, MatcherT: Into<StrMatcher<ActualT, ExpectedT>>> StrMatcherConfigurator<ActualT, ExpectedT> for MatcherT