Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/tests/SelfTest/UsageTests/MatchersRanges.tests.cpp
diff options
context:
space:
mode:
authorUriel García Rivas2020-12-07 17:23:54 -0600
committerMartin Hořeňovský2020-12-27 20:20:55 +0100
commit552af8920df24e16738dbb1cb6b46dd52de7804c (patch)
treec336ff726945350d6943488dbf1102be43246533 /tests/SelfTest/UsageTests/MatchersRanges.tests.cpp
parentce54ec185f69e32661efdcb4659f892415316b0e (diff)
downloadcatch3-552af8920df24e16738dbb1cb6b46dd52de7804c.tar.gz
Added AnyMatch, AllMatch and NoneMatch
Diffstat (limited to 'tests/SelfTest/UsageTests/MatchersRanges.tests.cpp')
-rw-r--r--tests/SelfTest/UsageTests/MatchersRanges.tests.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/SelfTest/UsageTests/MatchersRanges.tests.cpp b/tests/SelfTest/UsageTests/MatchersRanges.tests.cpp
index 505057d3..13b546e3 100644
--- a/tests/SelfTest/UsageTests/MatchersRanges.tests.cpp
+++ b/tests/SelfTest/UsageTests/MatchersRanges.tests.cpp
@@ -5,6 +5,8 @@
#include <catch2/matchers/catch_matchers_container_properties.hpp>
#include <catch2/matchers/catch_matchers_contains.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
+#include <catch2/matchers/catch_matchers_quantifiers.hpp>
+#include <catch2/matchers/catch_matchers_string.hpp>
#include <array>
#include <cmath>
@@ -217,3 +219,56 @@ TEST_CASE("Usage of the SizeIs range matcher", "[matchers][templated][size]") {
REQUIRE_THAT(has_size{}, SizeIs(13));
}
}
+
+TEST_CASE("Usage of the quantifiers matchers", "[matchers][templated][quantifiers]") {
+ using Catch::Matchers::AllMatch;
+ using Catch::Matchers::AnyMatch;
+ using Catch::Matchers::Contains;
+ using Catch::Matchers::EndsWith;
+ using Catch::Matchers::IsEmpty;
+ using Catch::Matchers::NoneMatch;
+ using Catch::Matchers::SizeIs;
+ using Catch::Matchers::StartsWith;
+ std::array<std::array<int, 5>, 5> int_arr_arr{{
+ {{ 0, 1, 2, 3, 5 }},
+ {{ 4,-3,-2, 5, 0 }},
+ {{ 0, 0, 0, 5, 0 }},
+ {{ 0,-5, 0, 5, 0 }},
+ {{ 1, 0, 0,-1, 5 }}
+ }};
+ std::vector<std::string> string_vector{ "Command+", "Catch2+", "CMake+", "C++", "Console+" };
+ std::list<std::vector<int>> int_vectors_list{ { 1, 2 }, { 3, 4 }, { 5, 6 } };
+
+ SECTION("Usage of the AllMatch range matcher") {
+ REQUIRE_THAT(int_arr_arr, AllMatch(Contains(0)));
+ REQUIRE_THAT(int_arr_arr, AllMatch(SizeIs(5)));
+
+ REQUIRE_THAT(string_vector, AllMatch(StartsWith("C")));
+ REQUIRE_THAT(string_vector, AllMatch(EndsWith("+")));
+
+ REQUIRE_THAT(int_vectors_list, AllMatch(!IsEmpty()));
+ REQUIRE_THAT(int_vectors_list, AllMatch(SizeIs(2)));
+ }
+
+ SECTION("Usage of the AnyMatch range matcher") {
+ REQUIRE_THAT(int_arr_arr, AnyMatch(Contains(-2)));
+ REQUIRE_THAT(int_arr_arr, AnyMatch(SizeIs(5)));
+
+ REQUIRE_THAT(string_vector, AnyMatch(StartsWith("CMak")));
+ REQUIRE_THAT(string_vector, AnyMatch(EndsWith("++")));
+
+ REQUIRE_THAT(int_vectors_list, AnyMatch(Contains(4)));
+ REQUIRE_THAT(int_vectors_list, AnyMatch(SizeIs(2)));
+ }
+
+ SECTION("Usage of the NoneMatch range matcher") {
+ REQUIRE_THAT(int_arr_arr, NoneMatch(Contains(-6)));
+ REQUIRE_THAT(int_arr_arr, NoneMatch(SizeIs(42)));
+
+ REQUIRE_THAT(string_vector, NoneMatch(StartsWith("abd")));
+ REQUIRE_THAT(string_vector, NoneMatch(EndsWith("#!--")));
+
+ REQUIRE_THAT(int_vectors_list, NoneMatch(IsEmpty()));
+ REQUIRE_THAT(int_vectors_list, NoneMatch(SizeIs(3)));
+ }
+}