From 72a09de2369b1d48954c2e8aa4c001b46c2e34c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Wed, 29 Dec 2021 16:58:00 +0100 Subject: [PATCH] Add tests for Optional's op== and != --- .../IntrospectiveTests/Details.tests.cpp | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/SelfTest/IntrospectiveTests/Details.tests.cpp b/tests/SelfTest/IntrospectiveTests/Details.tests.cpp index 38adcbac..ca72d733 100644 --- a/tests/SelfTest/IntrospectiveTests/Details.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/Details.tests.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #if defined(_MSC_VER) #pragma warning(push) @@ -55,3 +56,30 @@ TEST_CASE( "CaseInsensitiveEqualsTo is case insensitive", REQUIRE_FALSE( eq( "a", "B" ) ); } } + +TEST_CASE("Optional comparison ops", "[optional][approvals]") { + using Catch::Optional; + + Optional 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 ); + } +}