wrapMatcher function

Matcher wrapMatcher (dynamic x)

Takes an argument and returns an equivalent Matcher.

If the argument is already a matcher this does nothing, else if the argument is a function, it generates a predicate function matcher, else it generates an equals matcher.


Matcher wrapMatcher(x) {
  if (x is Matcher) {
    return x;
  } else if (x is _Predicate<Object>) {
    // x is already a predicate that can handle anything
    return predicate(x);
  } else if (x is _Predicate<Null>) {
    // x is a unary predicate, but expects a specific type
    // so wrap it.
    // ignore: unnecessary_lambdas
    return predicate((a) => (x as dynamic)(a));
  } else {
    return equals(x);