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

summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMartin Hořeňovský2026-05-12 10:06:20 +0200
committerMartin Hořeňovský2026-05-12 11:05:33 +0200
commit47ea57d74f8968eae242ea1b068a9e5b257c36b1 (patch)
treeccec9f01fc06668e30ee5b8a6122749852888591
parentd838f88b9c9a05d2879d29a5a54f864f823a1d64 (diff)
downloadcatch3-47ea57d74f8968eae242ea1b068a9e5b257c36b1.tar.gz
Constexpr matching support in the range equals matchers
-rw-r--r--docs/matchers.md2
-rw-r--r--tests/SelfTest/UsageTests/MatchersConstexpr.tests.cpp15
2 files changed, 17 insertions, 0 deletions
diff --git a/docs/matchers.md b/docs/matchers.md
index 5f912e44..a57dc6d3 100644
--- a/docs/matchers.md
+++ b/docs/matchers.md
@@ -504,6 +504,8 @@ matching. Currently, this includes:
* `AllTrue()`, `AnyTrue()`, `NoneTrue()`
* `Contains(T&& target_element, Comparator = std::equal_to<>{})`
* `Contains(Matcher element_matcher)`
+* `RangeEquals(TargetRangeLike&&, Comparator = std::equal_to<>{})`
+* `UnorderedRangeEquals(TargetRangeLike&&, Comparator = std::equal_to<>{})`
---
diff --git a/tests/SelfTest/UsageTests/MatchersConstexpr.tests.cpp b/tests/SelfTest/UsageTests/MatchersConstexpr.tests.cpp
index 6cd687f8..ad0eb1ee 100644
--- a/tests/SelfTest/UsageTests/MatchersConstexpr.tests.cpp
+++ b/tests/SelfTest/UsageTests/MatchersConstexpr.tests.cpp
@@ -15,6 +15,7 @@
#include <catch2/matchers/catch_matchers_container_properties.hpp>
#include <catch2/matchers/catch_matchers_quantifiers.hpp>
#include <catch2/matchers/catch_matchers_contains.hpp>
+#include <catch2/matchers/catch_matchers_range_equals.hpp>
#include <array>
@@ -56,6 +57,10 @@ namespace {
return { false, true, false };
case 2:
return { false, false, false };
+ case 3:
+ return { true, false, false };
+ case 4:
+ return { true, true, false };
default:
return { false, false, false };
}
@@ -98,6 +103,16 @@ TEST_CASE( "Generic Equals matchers can be used in constexpr contexts",
STATIC_REQUIRE_THAT( compute_bools( 2 ), Contains( true, std::not_equal_to<>{} ) );
}
+TEST_CASE( "Range equals matchers can be used in constexpr contexts",
+ "[constexpr][matchers][approvals]" ) {
+ using Catch::Matchers::RangeEquals;
+ using Catch::Matchers::UnorderedRangeEquals;
+ STATIC_REQUIRE_THAT( compute_bools( 0 ), RangeEquals( compute_bools( 0 ) ) );
+ STATIC_REQUIRE_THAT( compute_bools( 2 ), RangeEquals( compute_bools( 0 ), std::not_equal_to<>{} ) );
+ STATIC_REQUIRE_THAT( compute_bools( 1 ), UnorderedRangeEquals( compute_bools( 3 ) ) );
+ STATIC_REQUIRE_THAT( compute_bools( 1 ), UnorderedRangeEquals( compute_bools( 4 ), std::not_equal_to<>{} ) );
+}
+
// Combining matchers needs C++26 and P2738, so they are in separate preprocessor block
# if __cpp_constexpr >= 202306L