]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/x3/optional.cpp
1 /*=============================================================================
2 Copyright (c) 2001-2015 Joel de Guzman
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 =============================================================================*/
7 #include <boost/detail/lightweight_test.hpp>
8 #include <boost/spirit/home/x3.hpp>
9 #include <boost/fusion/adapted/struct.hpp>
10 #include <boost/fusion/include/vector.hpp>
18 boost::optional
<int> b
;
21 BOOST_FUSION_ADAPT_STRUCT(adata
,
25 struct test_attribute_type
27 template <typename Context
>
28 void operator()(Context
& ctx
) const
30 BOOST_TEST(typeid(decltype(_attr(ctx
))).name() == typeid(boost::optional
<int>).name());
37 using spirit_test::test
;
38 using spirit_test::test_attr
;
40 using boost::spirit::x3::int_
;
41 using boost::spirit::x3::omit
;
42 using boost::spirit::x3::ascii::char_
;
45 BOOST_TEST((test("1234", -int_
)));
46 BOOST_TEST((test("abcd", -int_
, false)));
49 { // test propagation of unused
50 using boost::fusion::at_c
;
51 using boost::fusion::vector
;
54 BOOST_TEST((test_attr("a1234c", char_
>> -omit
[int_
] >> char_
, v
)));
55 BOOST_TEST((at_c
<0>(v
) == 'a'));
56 BOOST_TEST((at_c
<1>(v
) == 'c'));
58 v
= boost::fusion::vector
<char, char>();
59 BOOST_TEST((test_attr("a1234c", char_
>> omit
[-int_
] >> char_
, v
)));
60 BOOST_TEST((at_c
<0>(v
) == 'a'));
61 BOOST_TEST((at_c
<1>(v
) == 'c'));
64 BOOST_TEST((test_attr(",c", -(',' >> char_
), ch
)));
65 BOOST_TEST((ch
== 'c'));
69 boost::optional
<int> n
= 0;
70 BOOST_TEST((test_attr("1234", (-int_
)[test_attribute_type()], n
)));
71 BOOST_TEST((n
.get() == 1234));
76 BOOST_TEST((test_attr("abc", char_
>> -(char_
>> char_
), s
)));
77 BOOST_TEST(s
== "abc");
81 boost::optional
<int> n
= 0;
82 auto f
= [&](auto& ctx
){ n
= _attr(ctx
); };
84 BOOST_TEST((test("1234", (-int_
)[f
])));
85 BOOST_TEST(n
.get() == 1234);
87 n
= boost::optional
<int>();
88 BOOST_TEST((test("abcd", (-int_
)[f
], false)));
94 BOOST_TEST((test_attr("a 1 2 a 2", *('a' >> int_
>> -int_
), v
96 BOOST_TEST(2 == v
.size() &&
97 1 == v
[0].a
&& v
[0].b
&& 2 == *(v
[0].b
) &&
98 2 == v
[1].a
&& !v
[1].b
);
101 return boost::report_errors();