]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/karma/omit.cpp
1 // Copyright (c) 2001-2011 Hartmut Kaiser
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 #include <boost/config/warning_disable.hpp>
7 #include <boost/detail/lightweight_test.hpp>
9 #include <boost/spirit/include/karma.hpp>
10 #include <boost/fusion/include/std_pair.hpp>
11 #include <boost/spirit/include/phoenix_core.hpp>
12 #include <boost/spirit/include/phoenix_operator.hpp>
17 using namespace spirit_test
;
21 using boost::spirit::karma::_1
;
22 using boost::spirit::karma::_a
;
23 using boost::spirit::karma::double_
;
24 using boost::spirit::karma::int_
;
25 using boost::spirit::karma::omit
;
26 using boost::spirit::karma::skip
;
27 using boost::spirit::karma::rule
;
28 using boost::spirit::karma::locals
;
30 typedef spirit_test::output_iterator
<char>::type outiter_type
;
31 typedef std::pair
<std::vector
<int>, int> attribute_type
;
33 rule
<outiter_type
, attribute_type(), locals
<int> > r
;
36 a
.first
.push_back(0x01);
37 a
.first
.push_back(0x02);
38 a
.first
.push_back(0x04);
39 a
.first
.push_back(0x08);
42 // omit[] is supposed to execute the embedded generator
44 std::pair
<double, double> p (1.0, 2.0);
45 BOOST_TEST(test("2.0", omit
[double_
] << double_
, p
));
47 r
%= omit
[ *(int_
[_a
= _a
+ _1
]) ] << int_
[_1
= _a
];
48 BOOST_TEST(test("15", r
, a
));
51 // even if omit[] never fails, it has to honor the result of the
54 typedef std::pair
<double, double> attribute_type
;
55 rule
<outiter_type
, attribute_type()> r
;
57 r
%= omit
[double_(1.0) << double_
] | "42";
59 attribute_type
p1 (1.0, 2.0);
60 BOOST_TEST(test("", r
, p1
));
62 attribute_type
p2 (10.0, 2.0);
63 BOOST_TEST(test("42", r
, p2
));
66 // skip[] is not supposed to execute the embedded generator
68 using boost::spirit::karma::double_
;
69 using boost::spirit::karma::skip
;
71 std::pair
<double, double> p (1.0, 2.0);
72 BOOST_TEST(test("2.0", skip
[double_
] << double_
, p
));
74 r
%= skip
[ *(int_
[_a
= _a
+ _1
]) ] << int_
[_1
= _a
];
75 BOOST_TEST(test("0", r
, a
));
78 return boost::report_errors();