]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/qi/omit.cpp
1 /*=============================================================================
2 Copyright (c) 2001-2011 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/include/qi_operator.hpp>
9 #include <boost/spirit/include/qi_char.hpp>
10 #include <boost/spirit/include/qi_string.hpp>
11 #include <boost/spirit/include/qi_directive.hpp>
12 #include <boost/spirit/include/qi_numeric.hpp>
13 #include <boost/spirit/include/qi_action.hpp>
14 #include <boost/spirit/include/support_argument.hpp>
15 #include <boost/spirit/include/phoenix_core.hpp>
16 #include <boost/spirit/include/phoenix_operator.hpp>
25 using namespace boost::spirit::ascii
;
26 using boost::spirit::qi::omit
;
27 using boost::spirit::qi::unused_type
;
28 using boost::spirit::qi::unused
;
29 using boost::spirit::qi::int_
;
30 using boost::spirit::qi::_1
;
32 using boost::fusion::vector
;
33 using boost::fusion::at_c
;
35 using spirit_test::test
;
36 using spirit_test::test_attr
;
39 BOOST_TEST(test("a", omit
['a']));
43 // omit[] means we don't receive the attribute
45 BOOST_TEST((test_attr("abc", omit
[char_
] >> omit
['b'] >> char_
, attr
)));
46 BOOST_TEST((attr
== 'c'));
50 // If all elements except 1 is omitted, the attribute is
51 // a single-element sequence. For this case alone, we allow
52 // naked attributes (unwrapped in a fusion sequence).
54 BOOST_TEST((test_attr("abc", omit
[char_
] >> 'b' >> char_
, attr
)));
55 BOOST_TEST((attr
== 'c'));
59 // omit[] means we don't receive the attribute
61 BOOST_TEST((test_attr("abc", omit
[char_
] >> omit
['b'] >> omit
[char_
], attr
)));
65 // omit[] means we don't receive the attribute
66 // this test is merely a compile test, because using a unused as the
67 // explicit attribute doesn't make any sense
69 BOOST_TEST((test_attr("abc", omit
[char_
>> 'b' >> char_
], attr
)));
73 // omit[] means we don't receive the attribute, if all elements of a
74 // sequence have unused attributes, the whole sequence has an unused
76 vector
<char, char> attr
;
77 BOOST_TEST((test_attr("abcde",
78 char_
>> (omit
[char_
] >> omit
['c'] >> omit
[char_
]) >> char_
, attr
)));
79 BOOST_TEST((at_c
<0>(attr
) == 'a'));
80 BOOST_TEST((at_c
<1>(attr
) == 'e'));
84 // "hello" has an unused_type. unused attrubutes are not part of the sequence
85 vector
<char, char> attr
;
86 BOOST_TEST((test_attr("a hello c", char_
>> "hello" >> char_
, attr
, space
)));
87 BOOST_TEST((at_c
<0>(attr
) == 'a'));
88 BOOST_TEST((at_c
<1>(attr
) == 'c'));
92 // if only one node in a sequence is left (all the others are omitted),
93 // then we need "naked" attributes (not wraped in a tuple)
95 BOOST_TEST((test_attr("a 123 c", omit
['a'] >> int_
>> omit
['c'], attr
, space
)));
96 BOOST_TEST((attr
== 123));
100 // unused means we don't care about the attribute
101 BOOST_TEST((test_attr("abc", char_
>> 'b' >> char_
, unused
)));
104 { // test action with omitted attribute
107 using boost::phoenix::ref
;
109 BOOST_TEST(test("x123\"a string\"", (char_
>> omit
[int_
] >> "\"a string\"")
111 BOOST_TEST(c
== 'x');
115 { // test action with omitted attribute
118 using boost::phoenix::ref
;
120 BOOST_TEST(test("x 123 \"a string\"",
121 (omit
[char_
] >> int_
>> "\"a string\"")[ref(n
) = _1
], space
));
122 BOOST_TEST(n
== 123);
125 return boost::report_errors();