Skip to content

Commit c0c1c02

Browse files
committed
test: tests for monadic functions
1 parent 6573b26 commit c0c1c02

File tree

5 files changed

+562
-0
lines changed

5 files changed

+562
-0
lines changed

tests/test_expected/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ target_link_libraries(${PROJECT_NAME} Catch2::Catch2)
1313
target_sources(${PROJECT_NAME}
1414
PRIVATE
1515
base_tests.cpp
16+
monadic_tests.cpp
1617
test_expected_main.cpp
1718
)
1819

@@ -29,6 +30,7 @@ target_link_libraries(${PROJECT_NAME}_cpp20 Catch2::Catch2)
2930
target_sources(${PROJECT_NAME}_cpp20
3031
PRIVATE
3132
base_tests.cpp
33+
monadic_tests.cpp
3234
test_expected_main.cpp
3335
)
3436

@@ -45,5 +47,6 @@ target_link_libraries(${PROJECT_NAME}_cpp23 Catch2::Catch2)
4547
target_sources(${PROJECT_NAME}_cpp23
4648
PRIVATE
4749
base_tests.cpp
50+
monadic_tests.cpp
4851
test_expected_main.cpp
4952
)

tests/test_expected/monadic_tests.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <string>
2+
3+
#include <catch2/catch_all.hpp>
4+
5+
#include <zeus/expected.hpp>
6+
7+
using namespace zeus;
8+
9+
TEST_CASE("and_then()", "[monadic]")
10+
{
11+
using T = std::string;
12+
using Expected = expected<int, T>;
13+
14+
{ // non-void
15+
using Expected2 = expected<double, T>;
16+
17+
Expected e = 42;
18+
19+
auto const newVal = e.and_then([](int x) { return Expected2 {x * 2}; });
20+
21+
static_assert(std::is_same_v<std::remove_cv_t<decltype(newVal)>, Expected2>);
22+
}
23+
{ // void
24+
using Expected2 = expected<void, T>;
25+
26+
Expected e = 42;
27+
28+
auto const newVal = e.and_then([](int) -> Expected2 { return Expected2 {}; });
29+
30+
static_assert(std::is_same_v<std::remove_cv_t<decltype(newVal)>, Expected2>);
31+
}
32+
}

tests/third_party/msvc/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
add_subdirectory(msvc_stl_p0323r12_test)
2+
add_subdirectory(msvc_stl_p2505r5_test)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
project(msvc_stl_p2505r5_test)
2+
add_executable(${PROJECT_NAME})
3+
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20)
4+
5+
target_link_libraries(${PROJECT_NAME} zeus::expected)
6+
7+
target_sources(${PROJECT_NAME}
8+
PRIVATE
9+
msvc_stl_p2505r5_test.cpp
10+
)

0 commit comments

Comments
 (0)