1 // Copyright (c) 2001-2011 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_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>
19 namespace fusion
= boost::fusion
;
23 make_vector(T
const& t1
, T
const& t2
)
33 using spirit_test::test
;
34 using boost::spirit::karma::symbols
;
37 using boost::spirit::karma::rule
;
38 using boost::spirit::karma::lit
;
40 typedef spirit_test::output_iterator
<char>::type output_iterator_type
;
42 symbols
<char, rule
<output_iterator_type
> > sym
;
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");
57 boost::mpl::bool_
<boost::spirit::traits::is_generator
<
58 symbols
<char, rule
<output_iterator_type
> > >::value
>();
60 // silence stupid compiler warnings
61 // i.e. MSVC warning C4189: 'f' : local variable is initialized but not referenced
62 BOOST_TEST((f
.value
));
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')));
71 symbols
<char, rule
<output_iterator_type
> > sym2
;
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')));
79 // make sure it plays well with other generators
80 BOOST_TEST((test("Joelyo", sym
<< "yo", 'j')));
87 BOOST_TEST((!test("", sym
, 'j')));
88 BOOST_TEST((!test("", sym
, 'h')));
92 using boost::spirit::karma::rule
;
93 using boost::spirit::karma::lit
;
94 using boost::spirit::karma::string
;
96 typedef spirit_test::output_iterator
<char>::type output_iterator_type
;
98 symbols
<char, rule
<output_iterator_type
, std::string()> > sym
;
99 rule
<output_iterator_type
, std::string()> r1
= string
;
108 boost::mpl::true_ f
=
109 boost::mpl::bool_
<boost::spirit::traits::is_generator
<
110 symbols
<char, std::string
> >::value
>();
112 // silence stupid compiler warnings
113 // i.e. MSVC warning C4189: 'f' : local variable is initialized but not referenced
114 BOOST_TEST((f
.value
));
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')));
123 symbols
<char, rule
<output_iterator_type
, std::string()> > sym2
;
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')));
131 // make sure it plays well with other generators
132 BOOST_TEST((test("Joelyo", sym
<< "yo", fusion::make_vector('j', "Joel"))));
139 BOOST_TEST((!test("", sym
, 'j')));
140 BOOST_TEST((!test("", sym
, 'h')));
143 { // test for proto problem with rvalue references (10-11-2011)
144 symbols
<char, std::string
> sym
;
146 sym
+= std::make_pair('j', "Joel");
147 sym
+= std::make_pair('h', "Hartmut");
149 BOOST_TEST((test("Joel", sym
, 'j')));
150 BOOST_TEST((test("Hartmut", sym
, 'h')));
153 return boost::report_errors();