1
1
mirror of https://github.com/trafi/maybe-result-cpp synced 2024-11-26 04:26:06 +01:00
maybe-result-cpp/tests/result_map_tests.cpp
2016-07-07 01:10:45 +03:00

40 lines
806 B
C++

#include "catch.hpp"
#include <maybe/result.hpp>
class A final {
public:
A(std::string value) : value(value)
{
}
std::string value;
};
class B final {
public:
B(std::string value) : value(value)
{
}
std::string value;
};
using maybe::result;
TEST_CASE("result_map")
{
SECTION("converts result A to result B")
{
auto a = result<A, int>::ok(A("hello"));
auto b = a.map([](A v) { return B(v.value + " world"); });
REQUIRE(b);
REQUIRE(b.ok_value().value == "hello world");
}
SECTION("does not convert result A to result B if value was error")
{
auto a = result<A, int>::err(43);
auto b = a.map([](A v) { return B(v.value = " world"); });
REQUIRE(!b);
REQUIRE(b.err_value() == 43);
}
}