wrapMatcher function

Matcher wrapMatcher(
  1. Object? valueOrMatcher

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(Object? valueOrMatcher) {
  if (valueOrMatcher is Matcher) {
    return valueOrMatcher;
  } else if (valueOrMatcher is bool Function(Object?)) {
    // already a predicate that can handle anything
    return predicate(valueOrMatcher);
  } else if (valueOrMatcher is bool Function(Never)) {
    // unary predicate, but expects a specific type
    // so wrap it.
    // ignore: unnecessary_lambdas
    return predicate((a) => (valueOrMatcher as dynamic)(a));
  } else {
    return equals(valueOrMatcher);