2017-12-19 15:04:45 +00:00
|
|
|
#include "catch.hpp"
|
|
|
|
|
#include "expected.hpp"
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
2018-05-11 08:26:41 +01:00
|
|
|
tl::expected<int, string> getInt3(int val) { return val; }
|
2017-12-19 15:04:45 +00:00
|
|
|
|
2018-05-11 08:26:41 +01:00
|
|
|
tl::expected<int, string> getInt2(int val) { return val; }
|
2017-12-19 15:04:45 +00:00
|
|
|
|
2018-05-11 08:26:41 +01:00
|
|
|
tl::expected<int, string> getInt1() { return getInt2(5).and_then(getInt3); }
|
|
|
|
|
|
|
|
|
|
TEST_CASE("Issue 1", "[issues.1]") { getInt1(); }
|
|
|
|
|
|
|
|
|
|
tl::expected<int, int> operation1() { return 42; }
|
|
|
|
|
|
|
|
|
|
tl::expected<std::string, int> operation2(int const val) { return "Bananas"; }
|
2017-12-19 15:04:45 +00:00
|
|
|
|
2018-05-11 08:26:41 +01:00
|
|
|
TEST_CASE("Issue 17", "[issues.17]") {
|
|
|
|
|
auto const intermediate_result = operation1();
|
2017-12-19 15:04:45 +00:00
|
|
|
|
2018-05-11 08:26:41 +01:00
|
|
|
intermediate_result.and_then(operation2);
|
2017-12-19 15:04:45 +00:00
|
|
|
}
|