Add tests for Optional's op== and !=

This commit is contained in:
Martin Hořeňovský 2021-12-29 16:58:00 +01:00
parent f0a89b7345
commit 72a09de236
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A

View File

@ -6,6 +6,7 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <catch2/internal/catch_enforce.hpp> #include <catch2/internal/catch_enforce.hpp>
#include <catch2/internal/catch_case_insensitive_comparisons.hpp> #include <catch2/internal/catch_case_insensitive_comparisons.hpp>
#include <catch2/internal/catch_optional.hpp>
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma warning(push) #pragma warning(push)
@ -55,3 +56,30 @@ TEST_CASE( "CaseInsensitiveEqualsTo is case insensitive",
REQUIRE_FALSE( eq( "a", "B" ) ); REQUIRE_FALSE( eq( "a", "B" ) );
} }
} }
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 );
}
}