matchesPattern method

void matchesPattern(
  1. Pattern expected
)

Expects that the string matches the pattern expected.

Fails if expected returns an empty result from calling allMatches with the value.

check(actual).matchesPattern('abc');
check(actual).matchesPattern(RegExp(r'\d'));

Implementation

void matchesPattern(Pattern expected) {
  context.expect(() => prefixFirst('matches ', literal(expected)), (actual) {
    if (expected.allMatches(actual).isNotEmpty) return null;
    return Rejection(
        which: prefixFirst('does not match ', literal(expected)));
  });
}