]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/leaf/test/match_test.cpp
1 // Copyright 2018-2022 Emil Dotchevski and Reverge Studios, Inc.
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #ifdef BOOST_LEAF_TEST_SINGLE_HEADER
9 # include <boost/leaf/handle_errors.hpp>
10 # include <boost/leaf/pred.hpp>
11 # include <boost/leaf/result.hpp>
14 #include "_test_ec.hpp"
15 #include "lightweight_test.hpp"
18 namespace leaf
= boost::leaf
;
20 enum class my_error
{ e1
=1, e2
, e3
};
22 struct e_my_error
{ int value
; };
24 #if __cplusplus >= 201703L
25 template <my_error value
>
26 constexpr bool cmp_my_error( my_error
const & e
) noexcept
32 constexpr bool e_my_error_gt( e_my_error
const & e
) noexcept
38 struct my_exception
: std::exception
44 template <class M
, class E
>
45 bool test(E
const & e
)
50 BOOST_TEST(e
== m
.matched
);
62 BOOST_TEST(( test
<leaf::match
<int, 42>>(e
) ));
63 BOOST_TEST(( !test
<leaf::match
<int, 41>>(e
) ));
64 BOOST_TEST(( test
<leaf::match
<int, 42, 41>>(e
) ));
66 BOOST_TEST(( !test
<leaf::if_not
<leaf::match
<int, 42>>>(e
) ));
67 BOOST_TEST(( test
<leaf::if_not
<leaf::match
<int, 41>>>(e
) ));
68 BOOST_TEST(( !test
<leaf::if_not
<leaf::match
<int, 42, 41>>>(e
) ));
72 my_error e
= my_error::e1
;
74 BOOST_TEST(( test
<leaf::match
<my_error
, my_error::e1
>>(e
) ));
75 BOOST_TEST(( !test
<leaf::match
<my_error
, my_error::e2
>>(e
) ));
76 BOOST_TEST(( test
<leaf::match
<my_error
, my_error::e2
, my_error::e1
>>(e
) ));
78 BOOST_TEST(( !test
<leaf::if_not
<leaf::match
<my_error
, my_error::e1
>>>(e
) ));
79 BOOST_TEST(( test
<leaf::if_not
<leaf::match
<my_error
, my_error::e2
>>>(e
) ));
80 BOOST_TEST(( !test
<leaf::if_not
<leaf::match
<my_error
, my_error::e2
, my_error::e1
>>>(e
) ));
83 #if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
85 std::error_code e
= errc_a::a0
;
87 BOOST_TEST(( test
<leaf::match
<leaf::condition
<cond_x
>, cond_x::x00
>>(e
) ));
88 BOOST_TEST(( !test
<leaf::match
<leaf::condition
<cond_x
>, cond_x::x11
>>(e
) ));
89 BOOST_TEST(( test
<leaf::match
<leaf::condition
<cond_x
>, cond_x::x11
, cond_x::x00
>>(e
) ));
92 BOOST_TEST(( !test
<leaf::if_not
<leaf::match
<leaf::condition
<cond_x
>, cond_x::x00
>>>(e
) ));
93 BOOST_TEST(( test
<leaf::if_not
<leaf::match
<leaf::condition
<cond_x
>, cond_x::x11
>>>(e
) ));
94 BOOST_TEST(( !test
<leaf::if_not
<leaf::match
<leaf::condition
<cond_x
>, cond_x::x11
, cond_x::x00
>>>(e
) ));
96 #if __cplusplus >= 201703L
97 BOOST_TEST(( test
<leaf::match
<std::error_code
, errc_a::a0
>>(e
) ));
98 BOOST_TEST(( !test
<leaf::match
<std::error_code
, errc_a::a2
>>(e
) ));
99 BOOST_TEST(( test
<leaf::match
<std::error_code
, errc_a::a2
, errc_a::a0
>>(e
) ));
101 BOOST_TEST(( !test
<leaf::if_not
<leaf::match
<std::error_code
, errc_a::a0
>>>(e
) ));
102 BOOST_TEST(( test
<leaf::if_not
<leaf::match
<std::error_code
, errc_a::a2
>>>(e
) ));
103 BOOST_TEST(( !test
<leaf::if_not
<leaf::match
<std::error_code
, errc_a::a2
, errc_a::a0
>>>(e
) ));
108 #if __cplusplus >= 201703L
110 my_error e
= my_error::e1
;
112 BOOST_TEST(( test
<leaf::match
<my_error
, cmp_my_error
<my_error::e1
>>>(e
) ));
113 BOOST_TEST(( !test
<leaf::match
<my_error
, cmp_my_error
<my_error::e2
>>>(e
) ));
118 int r
= leaf::try_handle_all(
119 []() -> leaf::result
<int>
121 return leaf::new_error(my_error::e1
);
124 []( leaf::match
<my_error
, my_error::e1
> )
137 int r
= leaf::try_handle_all(
138 []() -> leaf::result
<int>
140 return leaf::new_error(my_error::e1
);
143 []( leaf::match
<my_error
, my_error::e2
> )
156 int r
= leaf::try_handle_all(
157 []() -> leaf::result
<int>
159 return leaf::new_error(my_error::e1
);
162 []( leaf::if_not
<leaf::match
<my_error
, my_error::e1
>> )
180 int r
= leaf::try_handle_all(
181 []() -> leaf::result
<int>
183 return leaf::new_error();
186 []( leaf::if_not
<leaf::match
<my_error
, my_error::e1
>> )
203 #if __cplusplus >= 201703L
205 int r
= leaf::try_handle_all(
206 []() -> leaf::result
<int>
208 return leaf::new_error(my_error::e1
);
211 []( leaf::match
<my_error
, cmp_my_error
<my_error::e1
>> )
224 int r
= leaf::try_handle_all(
225 []() -> leaf::result
<int>
227 return leaf::new_error(my_error::e1
);
230 []( leaf::match
<my_error
, cmp_my_error
<my_error::e2
>> )
243 int r
= leaf::try_handle_all(
244 []() -> leaf::result
<int>
246 return leaf::new_error(e_my_error
{42});
249 []( leaf::match
<e_my_error
, e_my_error_gt
<41>> m
)
262 int r
= leaf::try_handle_all(
263 []() -> leaf::result
<int>
265 return leaf::new_error(e_my_error
{42});
268 []( leaf::match
<e_my_error
, e_my_error_gt
<42>> m
)
281 return boost::report_errors();