Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Constexpr matching support in the range equals matchers

Commit
47ea57d74f8968eae242ea1b068a9e5b257c36b1
Author
Martin Hořeňovský ·
Parents
d838f88b9c9a

Files · Download .tar.gz

Changes

 docs/matchers.md                                      |  2 ++
 tests/SelfTest/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 <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