20 TEST_CASE(
"unexpected construction") {
23 SUBCASE(
"when E is a integral type, it should be constructible") {
24 unexpected<int> u(42);
25 CHECK_EQ(u.error(), 42);
28 SUBCASE(
"when E is a string, it should be constructible") {
29 unexpected<std::string> u(
"error");
30 CHECK_EQ(u.error(),
"error");
33 SUBCASE(
"when E is a custom type, it should be constructible") {
38 unexpected<CustomError> u(CustomError{404,
"Not Found"});
39 CHECK_EQ(u.error().code, 404);
40 CHECK_EQ(u.error().message,
"Not Found");
45 TEST_CASE(
"unexpected with in_place_t") {
51 unexpected<CustomError> u(std::in_place, 500,
"Internal Server Error");
52 CHECK_EQ(u.error().code, 500);
53 CHECK_EQ(u.error().message,
"Internal Server Error");
56 TEST_CASE(
"unexpected copy construction") {
57 unexpected<int> u1(42);
58 unexpected<int> u2 = u1;
59 CHECK_EQ(u2.error(), 42);
62 TEST_CASE(
"unexpected move construction") {
63 unexpected<int> u1(42);
64 unexpected<int> u2 = std::move(u1);
65 CHECK_EQ(u2.error(), 42);
68 TEST_CASE(
"unexpected assignment") {
69 unexpected<int> u1(42);
70 unexpected<int> u2(100);
72 CHECK_EQ(u2.error(), 42);
74 unexpected<int> u3(200);
76 CHECK_EQ(u3.error(), 42);
79 TEST_CASE(
"unexpected equality comparison") {
80 unexpected<int> u1(42);
81 unexpected<int> u2(42);
82 unexpected<int> u3(100);
85 CHECK_FALSE(u1 == u3);
86 CHECK_FALSE(u2 == u3);
89 TEST_CASE(
"unexpected inequality comparison") {
90 unexpected<int> u1(42);
91 unexpected<int> u2(42);
92 unexpected<int> u3(100);
94 CHECK_FALSE(u1 != u2);
99 TEST_CASE(
"unexpected error access") {
100 unexpected<std::string> u(
"error");
101 CHECK_EQ(u.error(),
"error");
104 std::string& err_ref = u.error();
105 err_ref =
"new error";
106 CHECK_EQ(u.error(),
"new error");
109 unexpected<std::string> u2 = std::move(u);
110 CHECK_EQ(u2.error(),
"new error");