]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/karma/pattern1.cpp
9892bb058acbda525952035c87ed81f9dee49094
1 // Copyright (c) 2001-2010 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_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>
22 using namespace spirit_test
;
24 ///////////////////////////////////////////////////////////////////////////////
27 using namespace boost
;
28 using namespace boost::spirit
;
29 using namespace boost::spirit::ascii
;
31 typedef spirit_test::output_iterator
<char>::type outiter_type
;
33 // test rule parameter propagation
35 using boost::phoenix::at_c
;
37 karma::rule
<outiter_type
, fusion::vector
<char, int, double>()> start
;
38 fusion::vector
<char, int, double> vec('a', 10, 12.4);
40 start
%= char_
<< int_
<< double_
;
41 BOOST_TEST(test("a1012.4", start
, vec
));
43 karma::rule
<outiter_type
, char()> a
;
44 karma::rule
<outiter_type
, int()> b
;
45 karma::rule
<outiter_type
, double()> c
;
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
));
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
));
57 BOOST_TEST(test("a1012.4", start
, vec
));
60 BOOST_TEST(test("a1012.4", start
, vec
));
64 using boost::phoenix::at_c
;
66 karma::rule
<outiter_type
, space_type
, fusion::vector
<char, int, double>()> start
;
67 fusion::vector
<char, int, double> vec('a', 10, 12.4);
69 start
%= char_
<< int_
<< double_
;
70 BOOST_TEST(test_delimited("a 10 12.4 ", start
, vec
, space
));
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
;
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
));
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
));
86 BOOST_TEST(test_delimited("a 10 12.4 ", start
, vec
, space
));
89 BOOST_TEST(test_delimited("a 10 12.4 ", start
, vec
, space
));
92 // test direct initalization
94 using boost::phoenix::at_c
;
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_
;;
100 BOOST_TEST(test_delimited("a 10 12.4 ", start
, vec
, space
));
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_
;
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
));
110 return boost::report_errors();