diff options
| author | Martin Hořeňovský | 2026-05-12 10:04:14 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2026-05-12 11:05:31 +0200 |
| commit | d838f88b9c9a05d2879d29a5a54f864f823a1d64 (patch) | |
| tree | 46c42efbdbe1908e306d4b6666fb67c445eed093 /tests/SelfTest/UsageTests/MatchersConstexpr.tests.cpp | |
| parent | c267b6eb4de6d9ccdde238334c1248c7b60b8c0b (diff) | |
| download | catch3-d838f88b9c9a05d2879d29a5a54f864f823a1d64.tar.gz | |
Constexpr matching support in generic Contains matchers
Diffstat (limited to 'tests/SelfTest/UsageTests/MatchersConstexpr.tests.cpp')
| -rw-r--r-- | tests/SelfTest/UsageTests/MatchersConstexpr.tests.cpp | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/tests/SelfTest/UsageTests/MatchersConstexpr.tests.cpp b/tests/SelfTest/UsageTests/MatchersConstexpr.tests.cpp index 66fe7c8f..6cd687f8 100644 --- a/tests/SelfTest/UsageTests/MatchersConstexpr.tests.cpp +++ b/tests/SelfTest/UsageTests/MatchersConstexpr.tests.cpp @@ -14,6 +14,7 @@ #include <catch2/matchers/catch_matchers_templated.hpp> #include <catch2/matchers/catch_matchers_container_properties.hpp> #include <catch2/matchers/catch_matchers_quantifiers.hpp> +#include <catch2/matchers/catch_matchers_contains.hpp> #include <array> @@ -47,6 +48,18 @@ namespace { constexpr MatchTrueMatcher MatchTrue() { return MatchTrueMatcher(); } + constexpr std::array<bool, 3> compute_bools( int type ) { + switch ( type ) { + case 0: + return { true, true, true }; + case 1: + return { false, true, false }; + case 2: + return { false, false, false }; + default: + return { false, false, false }; + } + } } // namespace @@ -65,19 +78,6 @@ TEST_CASE( "IsEmpty and HasSize matchers can be used in constexpr contexts", STATIC_REQUIRE_THAT( arr, SizeIs( MatchAll() ) ); } -constexpr std::array<bool, 3> compute_bools( int type ) { - switch ( type ) { - case 0: - return { true, true, true }; - case 1: - return { false, true, false }; - case 2: - return { false, false, false }; - default: - return { false, false, false }; - } -} - TEST_CASE( "Quantifier matchers can be used in constexpr contexts", "[constexpr][matchers][approvals]" ) { using namespace Catch::Matchers; @@ -90,6 +90,14 @@ TEST_CASE( "Quantifier matchers can be used in constexpr contexts", STATIC_REQUIRE_THAT( compute_bools( 2 ), NoneMatch( MatchTrue() ) ); } +TEST_CASE( "Generic Equals matchers can be used in constexpr contexts", + "[constexpr][matchers][approvals]" ) { + using Catch::Matchers::Contains; + STATIC_REQUIRE_THAT( compute_bools( 0 ), Contains( true ) ); + STATIC_REQUIRE_THAT( compute_bools( 1 ), Contains( MatchTrue() ) ); + STATIC_REQUIRE_THAT( compute_bools( 2 ), Contains( true, std::not_equal_to<>{} ) ); +} + // Combining matchers needs C++26 and P2738, so they are in separate preprocessor block # if __cpp_constexpr >= 202306L |