1
1
mirror of https://github.com/trafi/maybe-result-cpp synced 2024-11-22 02:32:02 +01:00

Add tests for into_err and fix initializer call.

This commit is contained in:
Nerijus Arlauskas 2016-09-22 11:55:33 +03:00
parent 56dc9c9630
commit 190c5e1ddd
3 changed files with 37 additions and 1 deletions

@ -419,7 +419,7 @@ namespace maybe {
constexpr static result<void, E> default_ok() noexcept
{
return std::experimental::constexpr_move(
result<void, E>(void(), internal::placeholder{}));
result<void, E>(internal::placeholder{}));
}
/**

@ -8,6 +8,7 @@ add_executable(${TARGET}
result_tests.cpp
result_map_tests.cpp
result_map_err_tests.cpp
result_into_err_tests.cpp
result_and_then_tests.cpp
example_test.cpp)

@ -0,0 +1,35 @@
#include "catch.hpp"
#include <maybe/result.hpp>
class A final {
public:
A(std::string value) : value(value)
{
}
std::string value;
};
class B final {
};
using maybe::result;
TEST_CASE("result_into_err")
{
SECTION("converts result<A, E>::err to result<B, E>::err")
{
auto a = result<A, int>::err(42);
auto b = a.into_err<result<B, int>>();
REQUIRE(!b);
REQUIRE(42 == b.err_value());
}
SECTION("converts result<A, E>::err to result<void, E>::err")
{
auto a = result<A, int>::err(42);
auto b = a.into_err<result<void, int>>();
REQUIRE(!b);
REQUIRE(42 == b.err_value());
}
}