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_statement.hpp>
19 #include <boost/spirit/include/phoenix_fusion.hpp>
20 
21 #include "test.hpp"
22 
23 using namespace spirit_test;
24 
25 ///////////////////////////////////////////////////////////////////////////////
main()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     // test rule parameter propagation
35     {
36         using boost::phoenix::at_c;
37 
38         karma::rule<outiter_type, fusion::vector<char, int, double>()> start;
39         fusion::vector<char, int, double> vec('a', 10, 12.4);
40 
41         start %= char_ << int_ << double_;
42         BOOST_TEST(test("a1012.4", start, vec));
43 
44         karma::rule<outiter_type, char()> a;
45         karma::rule<outiter_type, int()> b;
46         karma::rule<outiter_type, double()> c;
47 
48         a %= char_ << eps;
49         b %= int_;
50         c %= double_;
51         start = a[_1 = at_c<0>(_r0)] << b[_1 = at_c<1>(_r0)] << c[_1 = at_c<2>(_r0)];
52         BOOST_TEST(test("a1012.4", start, vec));
53 
54         start = (a << b << c)[_1 = at_c<0>(_r0), _2 = at_c<1>(_r0), _3 = at_c<2>(_r0)];
55         BOOST_TEST(test("a1012.4", start, vec));
56 
57         start = a << b << c;
58         BOOST_TEST(test("a1012.4", start, vec));
59 
60         start %= a << b << c;
61         BOOST_TEST(test("a1012.4", start, vec));
62     }
63 
64     {
65         using boost::phoenix::at_c;
66 
67         karma::rule<outiter_type, space_type, fusion::vector<char, int, double>()> start;
68         fusion::vector<char, int, double> vec('a', 10, 12.4);
69 
70         start %= char_ << int_ << double_;
71         BOOST_TEST(test_delimited("a 10 12.4 ", start, vec, space));
72 
73         karma::rule<outiter_type, space_type, char()> a;
74         karma::rule<outiter_type, space_type, int()> b;
75         karma::rule<outiter_type, space_type, double()> c;
76 
77         a %= char_ << eps;
78         b %= int_;
79         c %= double_;
80         start = a[_1 = at_c<0>(_r0)] << b[_1 = at_c<1>(_r0)] << c[_1 = at_c<2>(_r0)];
81         BOOST_TEST(test_delimited("a  10 12.4 ", start, vec, space));
82 
83         start = (a << b << c)[_1 = at_c<0>(_r0), _2 = at_c<1>(_r0), _3 = at_c<2>(_r0)];
84         BOOST_TEST(test_delimited("a  10 12.4 ", start, vec, space));
85 
86         start = a << b << c;
87         BOOST_TEST(test_delimited("a  10 12.4 ", start, vec, space));
88 
89         start %= a << b << c;
90         BOOST_TEST(test_delimited("a  10 12.4 ", start, vec, space));
91     }
92 
93     // test direct initalization
94     {
95         using boost::phoenix::at_c;
96 
97         fusion::vector<char, int, double> vec('a', 10, 12.4);
98         karma::rule<outiter_type, space_type, fusion::vector<char, int, double>()>
99             start = char_ << int_ << double_;;
100 
101         BOOST_TEST(test_delimited("a 10 12.4 ", start, vec, space));
102 
103         karma::rule<outiter_type, space_type, char()> a = char_ << eps;
104         karma::rule<outiter_type, space_type, int()> b = int_;
105         karma::rule<outiter_type, space_type, double()> c = double_;
106 
107         start = a[_1 = at_c<0>(_r0)] << b[_1 = at_c<1>(_r0)] << c[_1 = at_c<2>(_r0)];
108         BOOST_TEST(test_delimited("a  10 12.4 ", start, vec, space));
109     }
110 
111     return boost::report_errors();
112 }
113 
114