]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/karma/pattern2.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / spirit / test / karma / pattern2.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_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_statement.hpp>
19 #include <boost/spirit/include/phoenix_fusion.hpp>
20
21 #include "test.hpp"
22
23 using namespace spirit_test;
24
25 ///////////////////////////////////////////////////////////////////////////////
26 int main()
27 {
28 using namespace boost;
29 using namespace boost::spirit;
30 using namespace boost::spirit::ascii;
31
32 typedef spirit_test::output_iterator<char>::type outiter_type;
33
34 // locals test
35 {
36 karma::rule<outiter_type, locals<std::string> > start;
37
38 start = string[_1 = "abc", _a = _1] << int_[_1 = 10] << string[_1 = _a];
39 BOOST_TEST(test("abc10abc", start));
40 }
41
42 {
43 karma::rule<outiter_type, space_type, locals<std::string> > start;
44
45 start = string[_1 = "abc", _a = _1] << int_[_1 = 10] << string[_1 = _a];
46 BOOST_TEST(test_delimited("abc 10 abc ", start, space));
47 }
48
49 // alias tests
50 {
51 typedef variant<char, int, double> var_type;
52
53 karma::rule<outiter_type, var_type()> d, start;
54
55 d = start.alias(); // d will always track start
56
57 start = (char_ | int_ | double_)[_1 = _val];
58
59 var_type v ('a');
60 BOOST_TEST(test("a", d, v));
61 v = 10;
62 BOOST_TEST(test("10", d, v));
63 v = 12.4;
64 BOOST_TEST(test("12.4", d, v));
65 }
66
67 {
68 typedef variant<char, int, double> var_type;
69
70 karma::rule<outiter_type, space_type, var_type()> d, start;
71
72 d = start.alias(); // d will always track start
73
74 start = (char_ | int_ | double_)[_1 = _val];
75
76 var_type v ('a');
77 BOOST_TEST(test_delimited("a ", d, v, space));
78 v = 10;
79 BOOST_TEST(test_delimited("10 ", d, v, space));
80 v = 12.4;
81 BOOST_TEST(test_delimited("12.4 ", d, v, space));
82 }
83
84 {
85 typedef variant<char, int, double> var_type;
86
87 karma::rule<outiter_type, var_type()> d, start;
88
89 d = start.alias(); // d will always track start
90
91 start %= char_ | int_ | double_;
92
93 var_type v ('a');
94 BOOST_TEST(test("a", d, v));
95 v = 10;
96 BOOST_TEST(test("10", d, v));
97 v = 12.4;
98 BOOST_TEST(test("12.4", d, v));
99
100 start = char_ | int_ | double_;
101
102 v = 'a';
103 BOOST_TEST(test("a", d, v));
104 v = 10;
105 BOOST_TEST(test("10", d, v));
106 v = 12.4;
107 BOOST_TEST(test("12.4", d, v));
108 }
109
110 {
111 typedef variant<char, int, double> var_type;
112
113 karma::rule<outiter_type, space_type, var_type()> d, start;
114
115 d = start.alias(); // d will always track start
116
117 start %= char_ | int_ | double_;
118
119 var_type v ('a');
120 BOOST_TEST(test_delimited("a ", d, v, space));
121 v = 10;
122 BOOST_TEST(test_delimited("10 ", d, v, space));
123 v = 12.4;
124 BOOST_TEST(test_delimited("12.4 ", d, v, space));
125
126 start = char_ | int_ | double_;
127
128 v = 'a';
129 BOOST_TEST(test_delimited("a ", d, v, space));
130 v = 10;
131 BOOST_TEST(test_delimited("10 ", d, v, space));
132 v = 12.4;
133 BOOST_TEST(test_delimited("12.4 ", d, v, space));
134 }
135
136 ///////////////////////////////////////////////////////////////////////////
137 {
138 using boost::spirit::karma::int_;
139 using boost::spirit::karma::_1;
140 using boost::spirit::karma::_val;
141 using boost::spirit::karma::space;
142 using boost::spirit::karma::space_type;
143
144 karma::rule<outiter_type, int()> r1 = int_;
145 karma::rule<outiter_type, space_type, int()> r2 = int_;
146
147 int i = 123;
148 int j = 456;
149 BOOST_TEST(test("123", r1[_1 = _val], i));
150 BOOST_TEST(test_delimited("456 ", r2[_1 = _val], j, space));
151 }
152
153 return boost::report_errors();
154 }
155