diff --git a/CMakeLists.txt b/CMakeLists.txt index 6004a8e..f9ced95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,8 @@ set(TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/tests/main.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tests/noexcept.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tests/make_optional.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tests/in_place.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/tests/relops.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/tests/relops.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/tests/observers.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tests/nullopt.cpp) add_executable(tests ${TEST_SOURCES}) diff --git a/tests/assignment.cpp b/tests/assignment.cpp new file mode 100644 index 0000000..603033e --- /dev/null +++ b/tests/assignment.cpp @@ -0,0 +1,4 @@ +#include "catch.hpp" +#include "optional.hpp" + +TEST_CASE("Assignment", "[assignment]") {} diff --git a/tests/constexpr.cpp b/tests/constexpr.cpp new file mode 100644 index 0000000..6366f37 --- /dev/null +++ b/tests/constexpr.cpp @@ -0,0 +1,4 @@ +#include "catch.hpp" +#include "optional.hpp" + +TEST_CASE("Constexpr", "[constexpr]") {} diff --git a/tests/constructors.cpp b/tests/constructors.cpp new file mode 100644 index 0000000..ec4f736 --- /dev/null +++ b/tests/constructors.cpp @@ -0,0 +1,4 @@ +#include "catch.hpp" +#include "optional.hpp" + +TEST_CASE("Constructors", "[constructors]") {} diff --git a/tests/hash.cpp b/tests/hash.cpp new file mode 100644 index 0000000..16437da --- /dev/null +++ b/tests/hash.cpp @@ -0,0 +1,4 @@ +#include "catch.hpp" +#include "optional.hpp" + +TEST_CASE("Hashing", "[hash]") {} diff --git a/tests/observers.cpp b/tests/observers.cpp new file mode 100644 index 0000000..c5e13d7 --- /dev/null +++ b/tests/observers.cpp @@ -0,0 +1,32 @@ +#include "catch.hpp" +#include "optional.hpp" + +struct move_detector { + move_detector() = default; + move_detector(move_detector &&rhs) { rhs.been_moved = true; } + bool been_moved = false; +}; + +TEST_CASE("Observers", "[observers]") { + tl::optional o1 = 42; + tl::optional o2; + const tl::optional o3 = 42; + + REQUIRE(*o1 == 42); + REQUIRE(*o1 == o1.value()); + REQUIRE(o2.value_or(42) == 42); + REQUIRE(o3.value() == 42); + auto success = std::is_same::value; + REQUIRE(success); + success = std::is_same::value; + REQUIRE(success); + success = std::is_same::value; + REQUIRE(success); + success = std::is_same::value; + REQUIRE(success); + + tl::optional o4{tl::in_place}; + move_detector o5 = std::move(o4).value(); + REQUIRE(o4->been_moved); + REQUIRE(!o5.been_moved); +}