The Wayback Machine - https://web.archive.org/web/20220705131749/https://github.com/catchorg/Catch2/issues/2109
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

Add AllMatch, AnyMatch, NoneMatch generic range matchers #2109

Open
horenmar opened this issue Nov 25, 2020 · 4 comments
Open

Add AllMatch, AnyMatch, NoneMatch generic range matchers #2109

horenmar opened this issue Nov 25, 2020 · 4 comments
Labels
Good First Issue Tweak request
Milestone

Comments

@horenmar
Copy link
Member

@horenmar horenmar commented Nov 25, 2020

They should take single matcher during construction, and their match method should take a generic range, using the new generic matcher support.

Expected usage:

REQUIRE_THAT(get_keys(), AllMatch(KeyPattern({1, 2, 3})));
REQUIRE_THAT(get_numbers(), NoneMatch(IsOdd{}));
REQUIRE_THAT(get_strings(), AnyMatch(Contains("webscale") && !Contains("MongoDB")));

the matching semantics are hopefully obvious from the names 😃

@horenmar horenmar added Tweak request Good First Issue labels Nov 25, 2020
@horenmar horenmar added this to the 3.0 milestone Nov 25, 2020
@horenmar
Copy link
Member Author

@horenmar horenmar commented Nov 25, 2020

There might also be interest in simple All, Any, None (or maybe AllTrue, etc.) range matchers that are explicitly specialized for ranges of bools, or types convertible to bool. While they can be simply emulated by composing AllMatch with IsTrue generic matcher, having them out of box would likely be convenient for bunch of users.

@Garz4
Copy link
Contributor

@Garz4 Garz4 commented Dec 1, 2020

@horenmar Hello! I would love to contribute here. Where should I implement those methods? And could you tell me more about the new generic matcher support?

@horenmar
Copy link
Member Author

@horenmar horenmar commented Dec 3, 2020

The new matchers docs are here. There is a very similar functionality in ContainsElementMatcher, in src/catch2/matchers/catch_matchers_contains.hpp, which takes a Matcher at construction, a generic range* at match time, and returns true if at least one element in the range matches.

This is essentially the AnyMatch implementation done already 😃 The other two should be analoguous.

  • Looking at it, I will need to check whether it accepts C++20 ranges, which can have different type returned from begin and from end. I think it currently doesn't.
@Garz4
Copy link
Contributor

@Garz4 Garz4 commented Dec 3, 2020

Thank you! I will be working on this. 🌻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue Tweak request
2 participants