mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
Fix & extend tests for comparing const instances of zero lit types
This commit is contained in:
parent
71b11c4e33
commit
05fb437cbb
@ -405,14 +405,26 @@ TEST_CASE( "#2555 - types that can only be compared with 0 literal implemented a
|
|||||||
// have the ambiguity issue) for `==` and `!=`.
|
// have the ambiguity issue) for `==` and `!=`.
|
||||||
TEST_CASE( "Comparing const instances of type registered with capture_by_value",
|
TEST_CASE( "Comparing const instances of type registered with capture_by_value",
|
||||||
"[regression][approvals][compilation]" ) {
|
"[regression][approvals][compilation]" ) {
|
||||||
auto const const_Lit0Type_1 = TypeWithLit0Comparisons{};
|
SECTION("Type with consteval-int constructor") {
|
||||||
auto const const_Lit0Type_2 = TypeWithLit0Comparisons{};
|
auto const const_Lit0Type_1 = TypeWithConstevalLit0Comparison{};
|
||||||
REQUIRE( const_Lit0Type_1 == const_Lit0Type_2 );
|
auto const const_Lit0Type_2 = TypeWithConstevalLit0Comparison{};
|
||||||
REQUIRE( const_Lit0Type_1 <= const_Lit0Type_2 );
|
REQUIRE( const_Lit0Type_1 == const_Lit0Type_2 );
|
||||||
REQUIRE( const_Lit0Type_1 < const_Lit0Type_2 );
|
REQUIRE( const_Lit0Type_1 <= const_Lit0Type_2 );
|
||||||
REQUIRE( const_Lit0Type_1 >= const_Lit0Type_2 );
|
REQUIRE( const_Lit0Type_1 < const_Lit0Type_2 );
|
||||||
REQUIRE( const_Lit0Type_1 > const_Lit0Type_2 );
|
REQUIRE( const_Lit0Type_1 >= const_Lit0Type_2 );
|
||||||
REQUIRE_FALSE( const_Lit0Type_1 != const_Lit0Type_2 );
|
REQUIRE( const_Lit0Type_1 > const_Lit0Type_2 );
|
||||||
|
REQUIRE( const_Lit0Type_1 != const_Lit0Type_2 );
|
||||||
|
}
|
||||||
|
SECTION("Type with constexpr-int constructor") {
|
||||||
|
auto const const_Lit0Type_1 = TypeWithLit0Comparisons{};
|
||||||
|
auto const const_Lit0Type_2 = TypeWithLit0Comparisons{};
|
||||||
|
REQUIRE( const_Lit0Type_1 == const_Lit0Type_2 );
|
||||||
|
REQUIRE( const_Lit0Type_1 <= const_Lit0Type_2 );
|
||||||
|
REQUIRE( const_Lit0Type_1 < const_Lit0Type_2 );
|
||||||
|
REQUIRE( const_Lit0Type_1 >= const_Lit0Type_2 );
|
||||||
|
REQUIRE( const_Lit0Type_1 > const_Lit0Type_2 );
|
||||||
|
REQUIRE( const_Lit0Type_1 != const_Lit0Type_2 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // C++20 consteval
|
#endif // C++20 consteval
|
||||||
|
@ -26,14 +26,20 @@ struct ZeroLiteralAsPointer {
|
|||||||
|
|
||||||
|
|
||||||
struct TypeWithLit0Comparisons {
|
struct TypeWithLit0Comparisons {
|
||||||
#define DEFINE_COMP_OP( op ) \
|
#define DEFINE_COMP_OP( op ) \
|
||||||
constexpr friend bool operator op( TypeWithLit0Comparisons, \
|
constexpr friend bool operator op( TypeWithLit0Comparisons, \
|
||||||
ZeroLiteralAsPointer ) { \
|
ZeroLiteralAsPointer ) { \
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
constexpr friend bool operator op( ZeroLiteralAsPointer, \
|
constexpr friend bool operator op( ZeroLiteralAsPointer, \
|
||||||
TypeWithLit0Comparisons ) { \
|
TypeWithLit0Comparisons ) { \
|
||||||
return false; \
|
return false; \
|
||||||
|
} \
|
||||||
|
/* std::orderings only have these for ==, but we add them for all \
|
||||||
|
operators so we can test all overloads for decomposer */ \
|
||||||
|
constexpr friend bool operator op( TypeWithLit0Comparisons, \
|
||||||
|
TypeWithLit0Comparisons ) { \
|
||||||
|
return true; \
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFINE_COMP_OP( < )
|
DEFINE_COMP_OP( < )
|
||||||
|
Loading…
Reference in New Issue
Block a user