mirror of
https://github.com/TartanLlama/expected.git
synced 2025-08-03 19:04:29 +02:00
map_error tests
This commit is contained in:
1
tests/.#extensions.cpp
Symbolic link
1
tests/.#extensions.cpp
Symbolic link
@@ -0,0 +1 @@
|
||||
simon@archer.2493:1509089313
|
@@ -132,6 +132,67 @@ TEST_CASE("Map extensions", "[extensions.map]") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Map error extensions", "[extensions.map_error]") {
|
||||
auto mul2 = [](auto a) { return a * 2; };
|
||||
auto ret_void = [](auto a) {};
|
||||
|
||||
{
|
||||
tl::expected<int, int> e = 21;
|
||||
auto ret = e.map_error(mul2);
|
||||
REQUIRE(ret);
|
||||
REQUIRE(*ret == 21);
|
||||
}
|
||||
|
||||
{
|
||||
const tl::expected<int, int> e = 21;
|
||||
auto ret = e.map_error(mul2);
|
||||
REQUIRE(ret);
|
||||
REQUIRE(*ret == 21);
|
||||
}
|
||||
|
||||
{
|
||||
tl::expected<int, int> e = 21;
|
||||
auto ret = std::move(e).map_error(mul2);
|
||||
REQUIRE(ret);
|
||||
REQUIRE(*ret == 21);
|
||||
}
|
||||
|
||||
{
|
||||
const tl::expected<int, int> e = 21;
|
||||
auto ret = std::move(e).map_error(mul2);
|
||||
REQUIRE(ret);
|
||||
REQUIRE(*ret == 21);
|
||||
}
|
||||
|
||||
{
|
||||
tl::expected<int, int> e(tl::unexpect, 21);
|
||||
auto ret = e.map_error(mul2);
|
||||
REQUIRE(!ret);
|
||||
REQUIRE(ret.error() == 42);
|
||||
}
|
||||
|
||||
{
|
||||
const tl::expected<int, int> e(tl::unexpect, 21);
|
||||
auto ret = e.map_error(mul2);
|
||||
REQUIRE(!ret);
|
||||
REQUIRE(ret.error() == 42);
|
||||
}
|
||||
|
||||
{
|
||||
tl::expected<int, int> e(tl::unexpect, 21);
|
||||
auto ret = std::move(e).map_error(mul2);
|
||||
REQUIRE(!ret);
|
||||
REQUIRE(ret.error() == 42);
|
||||
}
|
||||
|
||||
{
|
||||
const tl::expected<int, int> e(tl::unexpect, 21);
|
||||
auto ret = std::move(e).map_error(mul2);
|
||||
REQUIRE(!ret);
|
||||
REQUIRE(ret.error() == 42);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("And then extensions", "[extensions.and_then]") {
|
||||
auto succeed = [](auto a) { return tl::expected<int, int>(21 * 2); };
|
||||
auto fail = [](auto a) { return tl::expected<int, int>(tl::unexpect, 17); };
|
||||
@@ -168,7 +229,7 @@ TEST_CASE("And then extensions", "[extensions.and_then]") {
|
||||
tl::expected<int, int> e = 21;
|
||||
auto ret = e.and_then(fail);
|
||||
REQUIRE(!ret);
|
||||
REQUIRE(ret.error() == 17);
|
||||
REQUIRE(ret.error() == 17);
|
||||
}
|
||||
|
||||
{
|
||||
|
Reference in New Issue
Block a user