diff --git a/tests/.#extensions.cpp b/tests/.#extensions.cpp new file mode 120000 index 0000000..d422a10 --- /dev/null +++ b/tests/.#extensions.cpp @@ -0,0 +1 @@ +simon@archer.2493:1509089313 \ No newline at end of file diff --git a/tests/extensions.cpp b/tests/extensions.cpp index bc619a9..62cab82 100644 --- a/tests/extensions.cpp +++ b/tests/extensions.cpp @@ -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 e = 21; + auto ret = e.map_error(mul2); + REQUIRE(ret); + REQUIRE(*ret == 21); + } + + { + const tl::expected e = 21; + auto ret = e.map_error(mul2); + REQUIRE(ret); + REQUIRE(*ret == 21); + } + + { + tl::expected e = 21; + auto ret = std::move(e).map_error(mul2); + REQUIRE(ret); + REQUIRE(*ret == 21); + } + + { + const tl::expected e = 21; + auto ret = std::move(e).map_error(mul2); + REQUIRE(ret); + REQUIRE(*ret == 21); + } + + { + tl::expected e(tl::unexpect, 21); + auto ret = e.map_error(mul2); + REQUIRE(!ret); + REQUIRE(ret.error() == 42); + } + + { + const tl::expected e(tl::unexpect, 21); + auto ret = e.map_error(mul2); + REQUIRE(!ret); + REQUIRE(ret.error() == 42); + } + + { + tl::expected e(tl::unexpect, 21); + auto ret = std::move(e).map_error(mul2); + REQUIRE(!ret); + REQUIRE(ret.error() == 42); + } + + { + const tl::expected 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(21 * 2); }; auto fail = [](auto a) { return tl::expected(tl::unexpect, 17); }; @@ -168,7 +229,7 @@ TEST_CASE("And then extensions", "[extensions.and_then]") { tl::expected e = 21; auto ret = e.and_then(fail); REQUIRE(!ret); - REQUIRE(ret.error() == 17); + REQUIRE(ret.error() == 17); } {