mirror of
https://github.com/TartanLlama/optional.git
synced 2025-07-31 02:17:14 +02:00
More tests
This commit is contained in:
@ -13,6 +13,7 @@ set(TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/tests/main.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/observers.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/nullopt.cpp)
|
||||
|
||||
add_executable(tests ${TEST_SOURCES})
|
||||
|
4
tests/assignment.cpp
Normal file
4
tests/assignment.cpp
Normal file
@ -0,0 +1,4 @@
|
||||
#include "catch.hpp"
|
||||
#include "optional.hpp"
|
||||
|
||||
TEST_CASE("Assignment", "[assignment]") {}
|
4
tests/constexpr.cpp
Normal file
4
tests/constexpr.cpp
Normal file
@ -0,0 +1,4 @@
|
||||
#include "catch.hpp"
|
||||
#include "optional.hpp"
|
||||
|
||||
TEST_CASE("Constexpr", "[constexpr]") {}
|
4
tests/constructors.cpp
Normal file
4
tests/constructors.cpp
Normal file
@ -0,0 +1,4 @@
|
||||
#include "catch.hpp"
|
||||
#include "optional.hpp"
|
||||
|
||||
TEST_CASE("Constructors", "[constructors]") {}
|
4
tests/hash.cpp
Normal file
4
tests/hash.cpp
Normal file
@ -0,0 +1,4 @@
|
||||
#include "catch.hpp"
|
||||
#include "optional.hpp"
|
||||
|
||||
TEST_CASE("Hashing", "[hash]") {}
|
32
tests/observers.cpp
Normal file
32
tests/observers.cpp
Normal file
@ -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<int> o1 = 42;
|
||||
tl::optional<int> o2;
|
||||
const tl::optional<int> o3 = 42;
|
||||
|
||||
REQUIRE(*o1 == 42);
|
||||
REQUIRE(*o1 == o1.value());
|
||||
REQUIRE(o2.value_or(42) == 42);
|
||||
REQUIRE(o3.value() == 42);
|
||||
auto success = std::is_same<decltype(o1.value()), int &>::value;
|
||||
REQUIRE(success);
|
||||
success = std::is_same<decltype(o3.value()), const int &>::value;
|
||||
REQUIRE(success);
|
||||
success = std::is_same<decltype(std::move(o1).value()), int &&>::value;
|
||||
REQUIRE(success);
|
||||
success = std::is_same<decltype(std::move(o3).value()), const int &&>::value;
|
||||
REQUIRE(success);
|
||||
|
||||
tl::optional<move_detector> o4{tl::in_place};
|
||||
move_detector o5 = std::move(o4).value();
|
||||
REQUIRE(o4->been_moved);
|
||||
REQUIRE(!o5.been_moved);
|
||||
}
|
Reference in New Issue
Block a user