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

summaryrefslogtreecommitdiffhomepage
path: root/tests/SelfTest/UsageTests/MatchersConstexpr.tests.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2026-05-12 08:57:55 +0200
committerMartin Hořeňovský2026-05-12 11:05:29 +0200
commit3cdae5faf08b7a3861be5e7bf6f1968e9229f460 (patch)
tree883148c9b341e24169bce2595da512159450968e /tests/SelfTest/UsageTests/MatchersConstexpr.tests.cpp
parent651247c7f40eda6846fec736d2f9edac8949dacb (diff)
downloadcatch3-3cdae5faf08b7a3861be5e7bf6f1968e9229f460.tar.gz
Constexpr matching support in IsEmpty and SizeIs matchers
Diffstat (limited to 'tests/SelfTest/UsageTests/MatchersConstexpr.tests.cpp')
-rw-r--r--tests/SelfTest/UsageTests/MatchersConstexpr.tests.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/SelfTest/UsageTests/MatchersConstexpr.tests.cpp b/tests/SelfTest/UsageTests/MatchersConstexpr.tests.cpp
index edd03519..0d910daf 100644
--- a/tests/SelfTest/UsageTests/MatchersConstexpr.tests.cpp
+++ b/tests/SelfTest/UsageTests/MatchersConstexpr.tests.cpp
@@ -8,6 +8,9 @@
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_templated.hpp>
+#include <catch2/matchers/catch_matchers_container_properties.hpp>
+
+#include <array>
#if defined( CATCH_INTERNAL_CONSTEXPR_MATCHERS_ENABLED )
@@ -34,6 +37,15 @@ TEST_CASE( "Constexpr support for matchers", "[constexpr][matchers][approvals]"
STATIC_REQUIRE_THAT( 1, MatchAll() );
}
+TEST_CASE( "IsEmpty and HasSize matchers can be used in constexpr contexts",
+ "[constexpr][matchers][approvals]" ){
+ static constexpr std::array<int, 0> empty{};
+ STATIC_REQUIRE_THAT( empty, Catch::Matchers::IsEmpty() );
+ static constexpr int arr[1] = { 2 };
+ STATIC_REQUIRE_THAT( arr, Catch::Matchers::SizeIs( 1 ) );
+ STATIC_REQUIRE_THAT( arr, Catch::Matchers::SizeIs( MatchAll() ) );
+}
+
// Combining matchers needs C++26 and P2738, so they are in separate preprocessor block
# if __cpp_constexpr >= 202306L