MCPcopy Create free account
hub / github.com/boostorg/leaf / main

Function main

test/handle_some_test.cpp:57–1515  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55#endif // #if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
56
57int main()
58{
59 // void, try_handle_some (success)
60 {
61 int c=0;
62 leaf::result<void> r = leaf::try_handle_some(
63 [&c]() -> leaf::result<void>
64 {
65 BOOST_LEAF_AUTO(answer, f<int>(my_error_code::ok));
66 c = answer;
67 return { };
68 },
69 [&c]( leaf::error_info const & unmatched )
70 {
71 BOOST_TEST_EQ(c, 0);
72 c = 1;
73 return unmatched.error();
74 } );
75 BOOST_TEST(r);
76 BOOST_TEST_EQ(c, 42);
77 }
78
79 // void, try_handle_some (failure, matched)
80 {
81 int c=0;
82 leaf::result<void> r = leaf::try_handle_some(
83 [&c]() -> leaf::result<void>
84 {
85 BOOST_LEAF_AUTO(answer, f<int>(my_error_code::error1));
86 c = answer;
87 return { };
88 },
89 [&c]( my_error_code ec, info<1> const & x, info<2> y )
90 {
91 BOOST_TEST(ec == my_error_code::error1);
92 BOOST_TEST_EQ(x.value, 1);
93 BOOST_TEST_EQ(y.value, 2);
94 BOOST_TEST_EQ(c, 0);
95 c = 1;
96 } );
97 BOOST_TEST_EQ(c, 1);
98 BOOST_TEST(r);
99 }
100
101#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
102 // void, try_handle_some (failure, matched), match cond_x (single enum value)
103 {
104 int c=0;
105 leaf::result<void> r = leaf::try_handle_some(
106 [&c]() -> leaf::result<void>
107 {
108 BOOST_LEAF_AUTO(answer, f_errc<int>(errc_a::a0));
109 c = answer;
110 return { };
111 },
112 [&c]( leaf::match<leaf::condition<cond_x>, cond_x::x00> ec, info<1> const & x, info<2> const & y )
113 {
114 BOOST_TEST_EQ(ec.matched, make_error_code(errc_a::a0));

Callers

nothing calls this directly

Calls 6

try_handle_someFunction · 0.85
try_handle_allFunction · 0.85
new_errorFunction · 0.85
report_errorsFunction · 0.85
make_error_codeFunction · 0.70
valueMethod · 0.45

Tested by

no test coverage detected