Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

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

Commit
72a09de2369b1d48954c2e8aa4c001b46c2e34c0
Author
Martin Hořeňovský ·
Parents
f0a89b7345f8

Files · Download .tar.gz

Changes

 .../SelfTest/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 <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>
 
 #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<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 );
+    }
+}