Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/tests/SelfTest
diff options
context:
space:
mode:
authorMartin Hořeňovský2021-12-29 16:58:00 +0100
committerMartin Hořeňovský2021-12-29 16:58:22 +0100
commit72a09de2369b1d48954c2e8aa4c001b46c2e34c0 (patch)
treeac4c3e1f31bcb3145d8ec49a6d06faa2e65ef44f /tests/SelfTest
parentf0a89b7345f84436c2af142e39ba304189d3851f (diff)
downloadcatch3-72a09de2369b1d48954c2e8aa4c001b46c2e34c0.tar.gz
Add tests for Optional's op== and !=
Diffstat (limited to 'tests/SelfTest')
-rw-r--r--tests/SelfTest/IntrospectiveTests/Details.tests.cpp28
1 files changed, 28 insertions, 0 deletions
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 );
+ }
+}