Skip to content

Commit a0868d5

Browse files
committed
test: more tests
1 parent eb61cea commit a0868d5

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

tests/test_expected/monadic_tests.cpp

+57
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <string>
2+
#include <type_traits>
23

34
#include <catch2/catch_all.hpp>
45

@@ -30,3 +31,59 @@ TEST_CASE("and_then()", "[monadic]")
3031
static_assert(std::is_same_v<std::remove_cv_t<decltype(newVal)>, Expected2>);
3132
}
3233
}
34+
35+
TEST_CASE("void-T and_then()", "[monadic, void-T]")
36+
{
37+
using T = std::string;
38+
using Expected = expected<void, T>;
39+
40+
{ // non-void
41+
using Expected2 = expected<double, T>;
42+
43+
Expected e {};
44+
45+
auto const newVal = e.and_then([]() { return Expected2 {}; });
46+
47+
static_assert(std::is_same_v<std::remove_cv_t<decltype(newVal)>, Expected2>);
48+
}
49+
{ // void
50+
using Expected2 = expected<void, T>;
51+
52+
Expected e {};
53+
54+
auto const newVal = e.and_then([]() -> Expected2 { return Expected2 {}; });
55+
56+
static_assert(std::is_same_v<std::remove_cv_t<decltype(newVal)>, Expected2>);
57+
}
58+
}
59+
60+
TEST_CASE("or_else()", "[monadic]")
61+
{
62+
using T = std::string;
63+
using Expected = expected<T, int>;
64+
65+
{ // non-void
66+
using Expected2 = expected<T, double>;
67+
68+
Expected e {};
69+
70+
auto const newVal = e.or_else([](auto&&) { return Expected2 {}; });
71+
72+
static_assert(std::is_same_v<std::remove_cv_t<decltype(newVal)>, Expected2>);
73+
}
74+
}
75+
76+
TEST_CASE("void-T or_else()", "[monadic, void-T]")
77+
{
78+
using Expected = expected<void, int>;
79+
80+
{ // non-void
81+
using Expected2 = expected<void, double>;
82+
83+
Expected e {};
84+
85+
auto const newVal = e.or_else([](auto&&) { return Expected2 {}; });
86+
87+
static_assert(std::is_same_v<std::remove_cv_t<decltype(newVal)>, Expected2>);
88+
}
89+
}

0 commit comments

Comments
 (0)