]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/karma/omit.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / spirit / test / karma / omit.cpp
1 // Copyright (c) 2001-2011 Hartmut Kaiser
2 //
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)
5
6 #include <boost/config/warning_disable.hpp>
7 #include <boost/detail/lightweight_test.hpp>
8
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>
13
14 #include <iostream>
15 #include "test.hpp"
16
17 using namespace spirit_test;
18
19 int main()
20 {
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;
29
30 typedef spirit_test::output_iterator<char>::type outiter_type;
31 typedef std::pair<std::vector<int>, int> attribute_type;
32
33 rule<outiter_type, attribute_type(), locals<int> > r;
34
35 attribute_type a;
36 a.first.push_back(0x01);
37 a.first.push_back(0x02);
38 a.first.push_back(0x04);
39 a.first.push_back(0x08);
40 a.second = 0;
41
42 // omit[] is supposed to execute the embedded generator
43 {
44 std::pair<double, double> p (1.0, 2.0);
45 BOOST_TEST(test("2.0", omit[double_] << double_, p));
46
47 r %= omit[ *(int_[_a = _a + _1]) ] << int_[_1 = _a];
48 BOOST_TEST(test("15", r, a));
49 }
50
51 // even if omit[] never fails, it has to honor the result of the
52 // embedded generator
53 {
54 typedef std::pair<double, double> attribute_type;
55 rule<outiter_type, attribute_type()> r;
56
57 r %= omit[double_(1.0) << double_] | "42";
58
59 attribute_type p1 (1.0, 2.0);
60 BOOST_TEST(test("", r, p1));
61
62 attribute_type p2 (10.0, 2.0);
63 BOOST_TEST(test("42", r, p2));
64 }
65
66 // skip[] is not supposed to execute the embedded generator
67 {
68 using boost::spirit::karma::double_;
69 using boost::spirit::karma::skip;
70
71 std::pair<double, double> p (1.0, 2.0);
72 BOOST_TEST(test("2.0", skip[double_] << double_, p));
73
74 r %= skip[ *(int_[_a = _a + _1]) ] << int_[_1 = _a];
75 BOOST_TEST(test("0", r, a));
76 }
77
78 return boost::report_errors();
79 }