]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/karma/pattern1.cpp
078489bdcf5597db308cd1f4df812d4f4a199b11
[ceph.git] / ceph / src / boost / libs / spirit / test / karma / pattern1.cpp
1 // Copyright (c) 2001-2010 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_operator.hpp>
10 #include <boost/spirit/include/karma_char.hpp>
11 #include <boost/spirit/include/karma_auxiliary.hpp>
12 #include <boost/spirit/include/karma_string.hpp>
13 #include <boost/spirit/include/karma_numeric.hpp>
14 #include <boost/spirit/include/karma_nonterminal.hpp>
15 #include <boost/spirit/include/karma_action.hpp>
16 #include <boost/spirit/include/phoenix_core.hpp>
17 #include <boost/spirit/include/phoenix_operator.hpp>
18 #include <boost/spirit/include/phoenix_fusion.hpp>
19
20 #include "test.hpp"
21
22 using namespace spirit_test;
23
24 ///////////////////////////////////////////////////////////////////////////////
25 int main()
26 {
27 using namespace boost;
28 using namespace boost::spirit;
29 using namespace boost::spirit::ascii;
30
31 typedef spirit_test::output_iterator<char>::type outiter_type;
32
33 // test rule parameter propagation
34 {
35 using boost::phoenix::at_c;
36
37 karma::rule<outiter_type, fusion::vector<char, int, double>()> start;
38 fusion::vector<char, int, double> vec('a', 10, 12.4);
39
40 start %= char_ << int_ << double_;
41 BOOST_TEST(test("a1012.4", start, vec));
42
43 karma::rule<outiter_type, char()> a;
44 karma::rule<outiter_type, int()> b;
45 karma::rule<outiter_type, double()> c;
46
47 a %= char_ << eps;
48 b %= int_;
49 c %= double_;
50 start = a[_1 = at_c<0>(_r0)] << b[_1 = at_c<1>(_r0)] << c[_1 = at_c<2>(_r0)];
51 BOOST_TEST(test("a1012.4", start, vec));
52
53 start = (a << b << c)[_1 = at_c<0>(_r0), _2 = at_c<1>(_r0), _3 = at_c<2>(_r0)];
54 BOOST_TEST(test("a1012.4", start, vec));
55
56 start = a << b << c;
57 BOOST_TEST(test("a1012.4", start, vec));
58
59 start %= a << b << c;
60 BOOST_TEST(test("a1012.4", start, vec));
61 }
62
63 {
64 using boost::phoenix::at_c;
65
66 karma::rule<outiter_type, space_type, fusion::vector<char, int, double>()> start;
67 fusion::vector<char, int, double> vec('a', 10, 12.4);
68
69 start %= char_ << int_ << double_;
70 BOOST_TEST(test_delimited("a 10 12.4 ", start, vec, space));
71
72 karma::rule<outiter_type, space_type, char()> a;
73 karma::rule<outiter_type, space_type, int()> b;
74 karma::rule<outiter_type, space_type, double()> c;
75
76 a %= char_ << eps;
77 b %= int_;
78 c %= double_;
79 start = a[_1 = at_c<0>(_r0)] << b[_1 = at_c<1>(_r0)] << c[_1 = at_c<2>(_r0)];
80 BOOST_TEST(test_delimited("a 10 12.4 ", start, vec, space));
81
82 start = (a << b << c)[_1 = at_c<0>(_r0), _2 = at_c<1>(_r0), _3 = at_c<2>(_r0)];
83 BOOST_TEST(test_delimited("a 10 12.4 ", start, vec, space));
84
85 start = a << b << c;
86 BOOST_TEST(test_delimited("a 10 12.4 ", start, vec, space));
87
88 start %= a << b << c;
89 BOOST_TEST(test_delimited("a 10 12.4 ", start, vec, space));
90 }
91
92 // test direct initialization
93 {
94 using boost::phoenix::at_c;
95
96 fusion::vector<char, int, double> vec('a', 10, 12.4);
97 karma::rule<outiter_type, space_type, fusion::vector<char, int, double>()>
98 start = char_ << int_ << double_;;
99
100 BOOST_TEST(test_delimited("a 10 12.4 ", start, vec, space));
101
102 karma::rule<outiter_type, space_type, char()> a = char_ << eps;
103 karma::rule<outiter_type, space_type, int()> b = int_;
104 karma::rule<outiter_type, space_type, double()> c = double_;
105
106 start = a[_1 = at_c<0>(_r0)] << b[_1 = at_c<1>(_r0)] << c[_1 = at_c<2>(_r0)];
107 BOOST_TEST(test_delimited("a 10 12.4 ", start, vec, space));
108 }
109
110 return boost::report_errors();
111 }
112