From 47ea57d74f8968eae242ea1b068a9e5b257c36b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Tue, 12 May 2026 10:06:20 +0200 Subject: [PATCH] Constexpr matching support in the range equals matchers --- docs/matchers.md | 2 ++ .../UsageTests/MatchersConstexpr.tests.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+) 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 #include #include +#include #include @@ -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