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:
parent
56dc9c9630
commit
190c5e1ddd
@ -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)
|
||||
|
||||
|
35
tests/result_into_err_tests.cpp
Normal file
35
tests/result_into_err_tests.cpp
Normal file
@ -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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user