diff --git a/CMakeLists.txt b/CMakeLists.txt index fc82b04..61e4731 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,8 @@ add_library(Catch INTERFACE) target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR}) # Make test executable -set(TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/tests/main.cpp) +set(TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/tests/main.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/tests/constructors.cpp) add_executable(tests ${TEST_SOURCES}) diff --git a/tests/constructors.cpp b/tests/constructors.cpp new file mode 100644 index 0000000..219b168 --- /dev/null +++ b/tests/constructors.cpp @@ -0,0 +1,50 @@ +#include "catch.hpp" +#include "expected.hpp" + +#include + +struct takes_init_and_variadic { + std::vector v; + std::tuple t; + template + takes_init_and_variadic(std::initializer_list l, Args &&... args) + : v(l), t(std::forward(args)...) {} +}; + +TEST_CASE("Constructors", "[constructors]") { + { + tl::expected e; + REQUIRE(e); + REQUIRE(e == 0); + } + + { + tl::expected e (tl::in_place, 42); + REQUIRE(e); + REQUIRE(e == 42); + } + + { + tl::expected,int> e (tl::in_place, {0,1}); + REQUIRE(e); + REQUIRE((*e)[0] == 0); + REQUIRE((*e)[1] == 1); + } + + { + tl::expected,int> e (tl::in_place, 0, 1); + REQUIRE(e); + REQUIRE(std::get<0>(*e) == 0); + REQUIRE(std::get<1>(*e) == 1); + } + + { + tl::expected e (tl::in_place, {0,1}, 2, 3); + REQUIRE(e); + REQUIRE(e->v[0] == 0); + REQUIRE(e->v[1] == 1); + REQUIRE(std::get<0>(e->t) == 2); + REQUIRE(std::get<1>(e->t) == 3); + } + +}