20
20
#include " rpc/Errors.hpp"
21
21
#include " rpc/common/Types.hpp"
22
22
23
+ #include < boost/json/array.hpp>
24
+ #include < boost/json/value.hpp>
23
25
#include < gtest/gtest.h>
24
26
25
27
#include < expected>
@@ -34,3 +36,46 @@ TEST(MaybeErrorTest, OperatorEquals)
34
36
EXPECT_EQ (MaybeError{std::unexpected{Status{" Error" }}}, MaybeError{std::unexpected{Status{" Error" }}});
35
37
EXPECT_NE (MaybeError{std::unexpected{Status{" Error" }}}, MaybeError{std::unexpected{Status{" Another_error" }}});
36
38
}
39
+
40
+ TEST (ReturnTypeTests, Constructor)
41
+ {
42
+ boost::json::value const value{42 };
43
+
44
+ {
45
+ ReturnType const r{value};
46
+ ASSERT_TRUE (r.result );
47
+ EXPECT_EQ (r.result .value (), value);
48
+ EXPECT_EQ (r.warnings , boost::json::array{});
49
+ }
50
+
51
+ {
52
+ boost::json::array const warnings{1 , 2 , 3 };
53
+ ReturnType const r{value, warnings};
54
+ ASSERT_TRUE (r.result );
55
+ EXPECT_EQ (r.result .value (), value);
56
+ EXPECT_EQ (r.warnings , warnings);
57
+ }
58
+
59
+ {
60
+ Status const status{" Error" };
61
+
62
+ ReturnType const r{std::unexpected{status}};
63
+ ASSERT_FALSE (r.result );
64
+ EXPECT_EQ (r.result .error (), status);
65
+ EXPECT_EQ (r.warnings , boost::json::array{});
66
+ }
67
+ }
68
+
69
+ TEST (ReturnTypeTests, operatorBool)
70
+ {
71
+ {
72
+ boost::json::value const value{42 };
73
+ ReturnType const r{value};
74
+ EXPECT_TRUE (r);
75
+ }
76
+ {
77
+ Status const status{" Error" };
78
+ ReturnType const r{std::unexpected{status}};
79
+ EXPECT_FALSE (r);
80
+ }
81
+ }
0 commit comments