34 lines
780 B
C++
34 lines
780 B
C++
#include <gtest/gtest.h>
|
|
|
|
#include <rublon/authentication_step_interface.hpp>
|
|
|
|
#include <tl/expected.hpp>
|
|
class err {};
|
|
|
|
class err2 {};
|
|
|
|
struct expect {
|
|
int s;
|
|
};
|
|
|
|
struct moreexpected {
|
|
int a;
|
|
};
|
|
|
|
tl::expected< expect, err > foo(int a) {
|
|
if(a > 10) {
|
|
return tl::unexpected{err{}};
|
|
}
|
|
return expect{4 * a};
|
|
}
|
|
|
|
TEST(expected, tests) {
|
|
auto value = foo(11)
|
|
.and_then([](const expect & expect) { return tl::expected< moreexpected, err >{moreexpected{expect.s * 2}}; })
|
|
.or_else([](const err & error) { return tl::expected< moreexpected, err >{moreexpected{5}}; })
|
|
.and_then([](const moreexpected &expected){return tl::expected<int, err>{6*expected.a};} )
|
|
;
|
|
|
|
EXPECT_EQ(*value, 5 * 6);
|
|
}
|