mirror of
https://github.com/catchorg/Catch2.git
synced 2025-09-23 13:05:39 +02:00
Use std::optional
This commit is contained in:
@@ -1364,10 +1364,10 @@ Matchers.tests.cpp:<line number>: passed: ( EvilMatcher(), EvilMatcher() ), Evil
|
||||
Matchers.tests.cpp:<line number>: passed: &EvilMatcher(), EvilAddressOfOperatorUsed
|
||||
Matchers.tests.cpp:<line number>: passed: EvilMatcher() || ( EvilMatcher() && !EvilMatcher() )
|
||||
Matchers.tests.cpp:<line number>: passed: ( EvilMatcher() && EvilMatcher() ) || !EvilMatcher()
|
||||
Parse.tests.cpp:<line number>: passed: parseUInt( "0" ) == Optional<unsigned int>{ 0 } for: {?} == {?}
|
||||
Parse.tests.cpp:<line number>: passed: parseUInt( "100" ) == Optional<unsigned int>{ 100 } for: {?} == {?}
|
||||
Parse.tests.cpp:<line number>: passed: parseUInt( "4294967295" ) == Optional<unsigned int>{ 4294967295 } for: {?} == {?}
|
||||
Parse.tests.cpp:<line number>: passed: parseUInt( "0x<hex digits>", 16 ) == Optional<unsigned int>{ 255 } for: {?} == {?}
|
||||
Parse.tests.cpp:<line number>: passed: parseUInt( "0" ) == std::optional<unsigned int>{ 0 } for: {?} == {?}
|
||||
Parse.tests.cpp:<line number>: passed: parseUInt( "100" ) == std::optional<unsigned int>{ 100 } for: {?} == {?}
|
||||
Parse.tests.cpp:<line number>: passed: parseUInt( "4294967295" ) == std::optional<unsigned int>{ 4294967295 } for: {?} == {?}
|
||||
Parse.tests.cpp:<line number>: passed: parseUInt( "0x<hex digits>", 16 ) == std::optional<unsigned int>{ 255 } for: {?} == {?}
|
||||
Parse.tests.cpp:<line number>: passed: !(parseUInt( "" )) for: !{?}
|
||||
Parse.tests.cpp:<line number>: passed: !(parseUInt( "!!KJHF*#" )) for: !{?}
|
||||
Parse.tests.cpp:<line number>: passed: !(parseUInt( "-1" )) for: !{?}
|
||||
|
@@ -1362,10 +1362,10 @@ Matchers.tests.cpp:<line number>: passed: ( EvilMatcher(), EvilMatcher() ), Evil
|
||||
Matchers.tests.cpp:<line number>: passed: &EvilMatcher(), EvilAddressOfOperatorUsed
|
||||
Matchers.tests.cpp:<line number>: passed: EvilMatcher() || ( EvilMatcher() && !EvilMatcher() )
|
||||
Matchers.tests.cpp:<line number>: passed: ( EvilMatcher() && EvilMatcher() ) || !EvilMatcher()
|
||||
Parse.tests.cpp:<line number>: passed: parseUInt( "0" ) == Optional<unsigned int>{ 0 } for: {?} == {?}
|
||||
Parse.tests.cpp:<line number>: passed: parseUInt( "100" ) == Optional<unsigned int>{ 100 } for: {?} == {?}
|
||||
Parse.tests.cpp:<line number>: passed: parseUInt( "4294967295" ) == Optional<unsigned int>{ 4294967295 } for: {?} == {?}
|
||||
Parse.tests.cpp:<line number>: passed: parseUInt( "0x<hex digits>", 16 ) == Optional<unsigned int>{ 255 } for: {?} == {?}
|
||||
Parse.tests.cpp:<line number>: passed: parseUInt( "0" ) == std::optional<unsigned int>{ 0 } for: {?} == {?}
|
||||
Parse.tests.cpp:<line number>: passed: parseUInt( "100" ) == std::optional<unsigned int>{ 100 } for: {?} == {?}
|
||||
Parse.tests.cpp:<line number>: passed: parseUInt( "4294967295" ) == std::optional<unsigned int>{ 4294967295 } for: {?} == {?}
|
||||
Parse.tests.cpp:<line number>: passed: parseUInt( "0x<hex digits>", 16 ) == std::optional<unsigned int>{ 255 } for: {?} == {?}
|
||||
Parse.tests.cpp:<line number>: passed: !(parseUInt( "" )) for: !{?}
|
||||
Parse.tests.cpp:<line number>: passed: !(parseUInt( "!!KJHF*#" )) for: !{?}
|
||||
Parse.tests.cpp:<line number>: passed: !(parseUInt( "-1" )) for: !{?}
|
||||
|
@@ -8848,22 +8848,22 @@ Parse.tests.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
Parse.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE( parseUInt( "0" ) == Optional<unsigned int>{ 0 } )
|
||||
REQUIRE( parseUInt( "0" ) == std::optional<unsigned int>{ 0 } )
|
||||
with expansion:
|
||||
{?} == {?}
|
||||
|
||||
Parse.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE( parseUInt( "100" ) == Optional<unsigned int>{ 100 } )
|
||||
REQUIRE( parseUInt( "100" ) == std::optional<unsigned int>{ 100 } )
|
||||
with expansion:
|
||||
{?} == {?}
|
||||
|
||||
Parse.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE( parseUInt( "4294967295" ) == Optional<unsigned int>{ 4294967295 } )
|
||||
REQUIRE( parseUInt( "4294967295" ) == std::optional<unsigned int>{ 4294967295 } )
|
||||
with expansion:
|
||||
{?} == {?}
|
||||
|
||||
Parse.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE( parseUInt( "0x<hex digits>", 16 ) == Optional<unsigned int>{ 255 } )
|
||||
REQUIRE( parseUInt( "0x<hex digits>", 16 ) == std::optional<unsigned int>{ 255 } )
|
||||
with expansion:
|
||||
{?} == {?}
|
||||
|
||||
|
@@ -8846,22 +8846,22 @@ Parse.tests.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
Parse.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE( parseUInt( "0" ) == Optional<unsigned int>{ 0 } )
|
||||
REQUIRE( parseUInt( "0" ) == std::optional<unsigned int>{ 0 } )
|
||||
with expansion:
|
||||
{?} == {?}
|
||||
|
||||
Parse.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE( parseUInt( "100" ) == Optional<unsigned int>{ 100 } )
|
||||
REQUIRE( parseUInt( "100" ) == std::optional<unsigned int>{ 100 } )
|
||||
with expansion:
|
||||
{?} == {?}
|
||||
|
||||
Parse.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE( parseUInt( "4294967295" ) == Optional<unsigned int>{ 4294967295 } )
|
||||
REQUIRE( parseUInt( "4294967295" ) == std::optional<unsigned int>{ 4294967295 } )
|
||||
with expansion:
|
||||
{?} == {?}
|
||||
|
||||
Parse.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE( parseUInt( "0x<hex digits>", 16 ) == Optional<unsigned int>{ 255 } )
|
||||
REQUIRE( parseUInt( "0x<hex digits>", 16 ) == std::optional<unsigned int>{ 255 } )
|
||||
with expansion:
|
||||
{?} == {?}
|
||||
|
||||
|
@@ -2207,13 +2207,13 @@ ok {test-number} - EvilMatcher() || ( EvilMatcher() && !EvilMatcher() )
|
||||
# Overloaded comma or address-of operators are not used
|
||||
ok {test-number} - ( EvilMatcher() && EvilMatcher() ) || !EvilMatcher()
|
||||
# Parse uints
|
||||
ok {test-number} - parseUInt( "0" ) == Optional<unsigned int>{ 0 } for: {?} == {?}
|
||||
ok {test-number} - parseUInt( "0" ) == std::optional<unsigned int>{ 0 } for: {?} == {?}
|
||||
# Parse uints
|
||||
ok {test-number} - parseUInt( "100" ) == Optional<unsigned int>{ 100 } for: {?} == {?}
|
||||
ok {test-number} - parseUInt( "100" ) == std::optional<unsigned int>{ 100 } for: {?} == {?}
|
||||
# Parse uints
|
||||
ok {test-number} - parseUInt( "4294967295" ) == Optional<unsigned int>{ 4294967295 } for: {?} == {?}
|
||||
ok {test-number} - parseUInt( "4294967295" ) == std::optional<unsigned int>{ 4294967295 } for: {?} == {?}
|
||||
# Parse uints
|
||||
ok {test-number} - parseUInt( "0x<hex digits>", 16 ) == Optional<unsigned int>{ 255 } for: {?} == {?}
|
||||
ok {test-number} - parseUInt( "0x<hex digits>", 16 ) == std::optional<unsigned int>{ 255 } for: {?} == {?}
|
||||
# Parse uints
|
||||
ok {test-number} - !(parseUInt( "" )) for: !{?}
|
||||
# Parse uints
|
||||
|
@@ -2205,13 +2205,13 @@ ok {test-number} - EvilMatcher() || ( EvilMatcher() && !EvilMatcher() )
|
||||
# Overloaded comma or address-of operators are not used
|
||||
ok {test-number} - ( EvilMatcher() && EvilMatcher() ) || !EvilMatcher()
|
||||
# Parse uints
|
||||
ok {test-number} - parseUInt( "0" ) == Optional<unsigned int>{ 0 } for: {?} == {?}
|
||||
ok {test-number} - parseUInt( "0" ) == std::optional<unsigned int>{ 0 } for: {?} == {?}
|
||||
# Parse uints
|
||||
ok {test-number} - parseUInt( "100" ) == Optional<unsigned int>{ 100 } for: {?} == {?}
|
||||
ok {test-number} - parseUInt( "100" ) == std::optional<unsigned int>{ 100 } for: {?} == {?}
|
||||
# Parse uints
|
||||
ok {test-number} - parseUInt( "4294967295" ) == Optional<unsigned int>{ 4294967295 } for: {?} == {?}
|
||||
ok {test-number} - parseUInt( "4294967295" ) == std::optional<unsigned int>{ 4294967295 } for: {?} == {?}
|
||||
# Parse uints
|
||||
ok {test-number} - parseUInt( "0x<hex digits>", 16 ) == Optional<unsigned int>{ 255 } for: {?} == {?}
|
||||
ok {test-number} - parseUInt( "0x<hex digits>", 16 ) == std::optional<unsigned int>{ 255 } for: {?} == {?}
|
||||
# Parse uints
|
||||
ok {test-number} - !(parseUInt( "" )) for: !{?}
|
||||
# Parse uints
|
||||
|
@@ -10530,7 +10530,7 @@ Approx( 1.21999999999999997 )
|
||||
<Section name="proper inputs" filename="tests/<exe-name>/IntrospectiveTests/Parse.tests.cpp" >
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Parse.tests.cpp" >
|
||||
<Original>
|
||||
parseUInt( "0" ) == Optional<unsigned int>{ 0 }
|
||||
parseUInt( "0" ) == std::optional<unsigned int>{ 0 }
|
||||
</Original>
|
||||
<Expanded>
|
||||
{?} == {?}
|
||||
@@ -10538,7 +10538,7 @@ Approx( 1.21999999999999997 )
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Parse.tests.cpp" >
|
||||
<Original>
|
||||
parseUInt( "100" ) == Optional<unsigned int>{ 100 }
|
||||
parseUInt( "100" ) == std::optional<unsigned int>{ 100 }
|
||||
</Original>
|
||||
<Expanded>
|
||||
{?} == {?}
|
||||
@@ -10546,7 +10546,7 @@ Approx( 1.21999999999999997 )
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Parse.tests.cpp" >
|
||||
<Original>
|
||||
parseUInt( "4294967295" ) == Optional<unsigned int>{ 4294967295 }
|
||||
parseUInt( "4294967295" ) == std::optional<unsigned int>{ 4294967295 }
|
||||
</Original>
|
||||
<Expanded>
|
||||
{?} == {?}
|
||||
@@ -10554,7 +10554,7 @@ Approx( 1.21999999999999997 )
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Parse.tests.cpp" >
|
||||
<Original>
|
||||
parseUInt( "0x<hex digits>", 16 ) == Optional<unsigned int>{ 255 }
|
||||
parseUInt( "0x<hex digits>", 16 ) == std::optional<unsigned int>{ 255 }
|
||||
</Original>
|
||||
<Expanded>
|
||||
{?} == {?}
|
||||
|
@@ -10530,7 +10530,7 @@ Approx( 1.21999999999999997 )
|
||||
<Section name="proper inputs" filename="tests/<exe-name>/IntrospectiveTests/Parse.tests.cpp" >
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Parse.tests.cpp" >
|
||||
<Original>
|
||||
parseUInt( "0" ) == Optional<unsigned int>{ 0 }
|
||||
parseUInt( "0" ) == std::optional<unsigned int>{ 0 }
|
||||
</Original>
|
||||
<Expanded>
|
||||
{?} == {?}
|
||||
@@ -10538,7 +10538,7 @@ Approx( 1.21999999999999997 )
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Parse.tests.cpp" >
|
||||
<Original>
|
||||
parseUInt( "100" ) == Optional<unsigned int>{ 100 }
|
||||
parseUInt( "100" ) == std::optional<unsigned int>{ 100 }
|
||||
</Original>
|
||||
<Expanded>
|
||||
{?} == {?}
|
||||
@@ -10546,7 +10546,7 @@ Approx( 1.21999999999999997 )
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Parse.tests.cpp" >
|
||||
<Original>
|
||||
parseUInt( "4294967295" ) == Optional<unsigned int>{ 4294967295 }
|
||||
parseUInt( "4294967295" ) == std::optional<unsigned int>{ 4294967295 }
|
||||
</Original>
|
||||
<Expanded>
|
||||
{?} == {?}
|
||||
@@ -10554,7 +10554,7 @@ Approx( 1.21999999999999997 )
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Parse.tests.cpp" >
|
||||
<Original>
|
||||
parseUInt( "0x<hex digits>", 16 ) == Optional<unsigned int>{ 255 }
|
||||
parseUInt( "0x<hex digits>", 16 ) == std::optional<unsigned int>{ 255 }
|
||||
</Original>
|
||||
<Expanded>
|
||||
{?} == {?}
|
||||
|
@@ -9,7 +9,6 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/internal/catch_enforce.hpp>
|
||||
#include <catch2/internal/catch_case_insensitive_comparisons.hpp>
|
||||
#include <catch2/internal/catch_optional.hpp>
|
||||
|
||||
#include <helpers/type_with_lit_0_comparisons.hpp>
|
||||
|
||||
@@ -62,74 +61,6 @@ TEST_CASE( "CaseInsensitiveEqualsTo is case insensitive",
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Optional comparison ops", "[optional][approvals]") {
|
||||
using Catch::Optional;
|
||||
|
||||
Optional<int> a, b;
|
||||
|
||||
SECTION( "Empty optionals are equal" ) {
|
||||
REQUIRE( a == b );
|
||||
REQUIRE_FALSE( a != b );
|
||||
}
|
||||
SECTION( "Empty and non-empty optionals are never equal" ) {
|
||||
a = 1;
|
||||
REQUIRE_FALSE( a == b );
|
||||
REQUIRE( a != b );
|
||||
}
|
||||
SECTION(
|
||||
"non-empty optionals are equal if the contained elements are equal") {
|
||||
a = 1;
|
||||
b = 2;
|
||||
REQUIRE( a != b );
|
||||
REQUIRE_FALSE( a == b );
|
||||
|
||||
a = 2;
|
||||
REQUIRE( a == b );
|
||||
REQUIRE_FALSE( a != b );
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
struct MoveChecker {
|
||||
bool has_moved = false;
|
||||
MoveChecker() = default;
|
||||
MoveChecker( MoveChecker const& rhs ) = default;
|
||||
MoveChecker& operator=( MoveChecker const& rhs ) = default;
|
||||
MoveChecker( MoveChecker&& rhs ) noexcept { rhs.has_moved = true; }
|
||||
MoveChecker& operator=( MoveChecker&& rhs ) noexcept {
|
||||
rhs.has_moved = true;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
TEST_CASE( "Optional supports move ops", "[optional][approvals]" ) {
|
||||
using Catch::Optional;
|
||||
MoveChecker a;
|
||||
Optional<MoveChecker> opt_A( a );
|
||||
REQUIRE_FALSE( a.has_moved );
|
||||
REQUIRE_FALSE( opt_A->has_moved );
|
||||
|
||||
SECTION( "Move construction from element" ) {
|
||||
Optional<MoveChecker> opt_B( CATCH_MOVE( a ) );
|
||||
REQUIRE( a.has_moved );
|
||||
}
|
||||
SECTION( "Move assignment from element" ) {
|
||||
opt_A = CATCH_MOVE( a );
|
||||
REQUIRE( a.has_moved );
|
||||
}
|
||||
SECTION( "Move construction from optional" ) {
|
||||
Optional<MoveChecker> opt_B( CATCH_MOVE( opt_A ) );
|
||||
REQUIRE( opt_A->has_moved ); // NOLINT(clang-analyzer-cplusplus.Move)
|
||||
}
|
||||
SECTION( "Move assignment from optional" ) {
|
||||
Optional<MoveChecker> opt_B( opt_A );
|
||||
REQUIRE_FALSE( opt_A->has_moved );
|
||||
opt_B = CATCH_MOVE( opt_A );
|
||||
REQUIRE( opt_A->has_moved ); // NOLINT(clang-analyzer-cplusplus.Move)
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE( "Decomposer checks that the argument is 0 when handling "
|
||||
"only-0-comparable types",
|
||||
"[decomposition][approvals]" ) {
|
||||
|
@@ -12,14 +12,13 @@
|
||||
|
||||
TEST_CASE("Parse uints", "[parse-numbers]") {
|
||||
using Catch::parseUInt;
|
||||
using Catch::Optional;
|
||||
|
||||
SECTION("proper inputs") {
|
||||
REQUIRE( parseUInt( "0" ) == Optional<unsigned int>{ 0 } );
|
||||
REQUIRE( parseUInt( "100" ) == Optional<unsigned int>{ 100 } );
|
||||
REQUIRE( parseUInt( "0" ) == std::optional<unsigned int>{ 0 } );
|
||||
REQUIRE( parseUInt( "100" ) == std::optional<unsigned int>{ 100 } );
|
||||
REQUIRE( parseUInt( "4294967295" ) ==
|
||||
Optional<unsigned int>{ 4294967295 } );
|
||||
REQUIRE( parseUInt( "0xFF", 16 ) == Optional<unsigned int>{ 255 } );
|
||||
std::optional<unsigned int>{ 4294967295 } );
|
||||
REQUIRE( parseUInt( "0xFF", 16 ) == std::optional<unsigned int>{ 255 } );
|
||||
}
|
||||
SECTION( "Bad inputs" ) {
|
||||
// empty
|
||||
|
Reference in New Issue
Block a user