]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/karma/symbols2.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / spirit / test / karma / symbols2.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_auxiliary.hpp>
10 #include <boost/spirit/include/karma_char.hpp>
11 #include <boost/spirit/include/karma_string.hpp>
12 #include <boost/spirit/include/karma_operator.hpp>
13 #include <boost/spirit/include/karma_directive.hpp>
14 #include <boost/spirit/include/karma_generate.hpp>
15 #include <boost/spirit/include/karma_nonterminal.hpp>
16
17 #include "test.hpp"
18
19 namespace fusion = boost::fusion;
20
21 template <typename T>
22 inline std::vector<T>
23 make_vector(T const& t1, T const& t2)
24 {
25 std::vector<T> v;
26 v.push_back(t1);
27 v.push_back(t2);
28 return v;
29 }
30
31 int main()
32 {
33 using spirit_test::test;
34 using boost::spirit::karma::symbols;
35
36 { // advanced
37 using boost::spirit::karma::rule;
38 using boost::spirit::karma::lit;
39
40 typedef spirit_test::output_iterator<char>::type output_iterator_type;
41
42 symbols<char, rule<output_iterator_type> > sym;
43
44 rule<output_iterator_type> r1 = lit("Joel");
45 rule<output_iterator_type> r2 = lit("Hartmut");
46 rule<output_iterator_type> r3 = lit("Tom");
47 rule<output_iterator_type> r4 = lit("Kim");
48
49 sym.add
50 ('j', r1.alias())
51 ('h', r2.alias())
52 ('t', r3.alias())
53 ('k', r4.alias())
54 ;
55
56 boost::mpl::true_ f =
57 boost::mpl::bool_<boost::spirit::traits::is_generator<
58 symbols<char, rule<output_iterator_type> > >::value>();
59
60 // silence stupid compiler warnings
61 // i.e. MSVC warning C4189: 'f' : local variable is initialized but not referenced
62 BOOST_TEST((f.value));
63
64 BOOST_TEST((test("Joel", sym, 'j')));
65 BOOST_TEST((test("Hartmut", sym, 'h')));
66 BOOST_TEST((test("Tom", sym, 't')));
67 BOOST_TEST((test("Kim", sym, 'k')));
68 BOOST_TEST((!test("", sym, 'x')));
69
70 // test copy
71 symbols<char, rule<output_iterator_type> > sym2;
72 sym2 = sym;
73 BOOST_TEST((test("Joel", sym2, 'j')));
74 BOOST_TEST((test("Hartmut", sym2, 'h')));
75 BOOST_TEST((test("Tom", sym2, 't')));
76 BOOST_TEST((test("Kim", sym2, 'k')));
77 BOOST_TEST((!test("", sym2, 'x')));
78
79 // make sure it plays well with other generators
80 BOOST_TEST((test("Joelyo", sym << "yo", 'j')));
81
82 sym.remove
83 ('j')
84 ('h')
85 ;
86
87 BOOST_TEST((!test("", sym, 'j')));
88 BOOST_TEST((!test("", sym, 'h')));
89 }
90
91 { // more advanced
92 using boost::spirit::karma::rule;
93 using boost::spirit::karma::lit;
94 using boost::spirit::karma::string;
95
96 typedef spirit_test::output_iterator<char>::type output_iterator_type;
97
98 symbols<char, rule<output_iterator_type, std::string()> > sym;
99 rule<output_iterator_type, std::string()> r1 = string;
100
101 sym.add
102 ('j', r1.alias())
103 ('h', r1.alias())
104 ('t', r1.alias())
105 ('k', r1.alias())
106 ;
107
108 boost::mpl::true_ f =
109 boost::mpl::bool_<boost::spirit::traits::is_generator<
110 symbols<char, std::string> >::value>();
111
112 // silence stupid compiler warnings
113 // i.e. MSVC warning C4189: 'f' : local variable is initialized but not referenced
114 BOOST_TEST((f.value));
115
116 BOOST_TEST((test("Joel", sym, fusion::make_vector('j', "Joel"))));
117 BOOST_TEST((test("Hartmut", sym, fusion::make_vector('h', "Hartmut"))));
118 BOOST_TEST((test("Tom", sym, fusion::make_vector('t', "Tom"))));
119 BOOST_TEST((test("Kim", sym, fusion::make_vector('k', "Kim"))));
120 BOOST_TEST((!test("", sym, 'x')));
121
122 // test copy
123 symbols<char, rule<output_iterator_type, std::string()> > sym2;
124 sym2 = sym;
125 BOOST_TEST((test("Joel", sym2, fusion::make_vector('j', "Joel"))));
126 BOOST_TEST((test("Hartmut", sym2, fusion::make_vector('h', "Hartmut"))));
127 BOOST_TEST((test("Tom", sym2, fusion::make_vector('t', "Tom"))));
128 BOOST_TEST((test("Kim", sym2, fusion::make_vector('k', "Kim"))));
129 BOOST_TEST((!test("", sym2, 'x')));
130
131 // make sure it plays well with other generators
132 BOOST_TEST((test("Joelyo", sym << "yo", fusion::make_vector('j', "Joel"))));
133
134 sym.remove
135 ('j')
136 ('h')
137 ;
138
139 BOOST_TEST((!test("", sym, 'j')));
140 BOOST_TEST((!test("", sym, 'h')));
141 }
142
143 { // test for proto problem with rvalue references (10-11-2011)
144 symbols<char, std::string> sym;
145
146 sym += std::make_pair('j', "Joel");
147 sym += std::make_pair('h', "Hartmut");
148
149 BOOST_TEST((test("Joel", sym, 'j')));
150 BOOST_TEST((test("Hartmut", sym, 'h')));
151 }
152
153 return boost::report_errors();
154 }