Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create containsAllIn matcher #2369

Closed
alanrussian opened this issue Apr 5, 2018 · 3 comments · Fixed by dart-lang/matcher#76
Closed

Create containsAllIn matcher #2369

alanrussian opened this issue Apr 5, 2018 · 3 comments · Fixed by dart-lang/matcher#76

Comments

@alanrussian
Copy link

One of the matchers I use often in Java's truth library is "containsAllIn". I've found myself needing something like this in Dart a few times now.

A comparison of matchers in Truth vs. this package (credit @natebosch):

containsExactlyElementsIn(...) -> unorderedEquals(...)
containsExactlyElementsIn(...).inOrder() -> orderedEquals(...)
containsAll(Iterable matchers) => allOf(matchers.map(contains).toList())
containsAllOf(...).inOrder() -> containsAllInOrder(...)
containsAllIn -> Does not exist

@natebosch
Copy link
Member

On thing that makes this tricky is that to match the semantics of other Iterable matchers in this package we'd want to support some looseness which means that a given element in the checked value could match more than one element of the expectation.

expect([2,1], containsAll([greaterThan(0), greaterThan(1)]);

My first greedy approach to solve this didn't work since the 2 matched the greaterThan(0) and failed to find a match for greaterThan(1). We might need to treat it like a bipartite matching problem.

@natebosch
Copy link
Member

looks like unorderedMatches suffers the same problem
#2370

natebosch referenced this issue in dart-lang/matcher Apr 11, 2018
Closes #72

- Add `mustMatchEveryValue` to the implementation for unordered matches.
- Implement containsAll as an unorderedMatches which does allows extra
  values in the checked iterable.
natebosch referenced this issue in dart-lang/matcher Apr 12, 2018
Closes #72

- Add `allowUnmatchedValues` to the implementation for unordered matches.
- Implement containsAll as an unorderedMatches which does allows extra
  values in the checked iterable.
@alanrussian
Copy link
Author

Thanks for the quick fix, Nate! :-)

mosuem referenced this issue Oct 17, 2024
Closes dart-lang/matcher#72

- Add `allowUnmatchedValues` to the implementation for unordered matches.
- Implement containsAll as an unorderedMatches which does allows extra
  values in the checked iterable.
@mosuem mosuem transferred this issue from dart-lang/matcher Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants