map_error tests

This commit is contained in:
Simon Brand
2017-10-27 12:18:57 +01:00
parent 89831bfa86
commit a089579387
2 changed files with 63 additions and 1 deletions

1
tests/.#extensions.cpp Symbolic link
View File

@@ -0,0 +1 @@
simon@archer.2493:1509089313

View File

@@ -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);
}
{