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/spirit/include/karma_symbols.hpp>
8 #include <boost/spirit/include/karma_auxiliary.hpp>
9 #include <boost/spirit/include/karma_char.hpp>
10 #include <boost/spirit/include/karma_string.hpp>
11 #include <boost/spirit/include/karma_operator.hpp>
12 #include <boost/spirit/include/karma_directive.hpp>
13 #include <boost/spirit/include/karma_generate.hpp>
14 #include <boost/spirit/include/karma_nonterminal.hpp>
16 #include <boost/core/lightweight_test_trait.hpp>
20 namespace fusion
= boost::fusion
;
24 make_vector(T
const& t1
, T
const& t2
)
34 using spirit_test::test
;
35 using boost::spirit::karma::symbols
;
38 using boost::spirit::karma::rule
;
39 using boost::spirit::karma::lit
;
40 using boost::spirit::karma::char_
;
42 typedef spirit_test::output_iterator
<char>::type output_iterator_type
;
44 symbols
<char, rule
<output_iterator_type
, char()> > sym
;
45 rule
<output_iterator_type
, char()> r1
= char_
;
54 BOOST_TEST_TRAIT_TRUE((
55 boost::spirit::traits::is_generator
<
56 symbols
<char, rule
<output_iterator_type
, char()> > >));
58 BOOST_TEST((test("J", sym
, make_vector('j', 'J'))));
59 BOOST_TEST((test("H", sym
, make_vector('h', 'H'))));
60 BOOST_TEST((test("T", sym
, make_vector('t', 'T'))));
61 BOOST_TEST((test("K", sym
, make_vector('k', 'K'))));
62 BOOST_TEST((!test("", sym
, 'x')));
65 symbols
<char, rule
<output_iterator_type
, char()> > sym2
;
67 BOOST_TEST((test("J", sym2
, make_vector('j', 'J'))));
68 BOOST_TEST((test("H", sym2
, make_vector('h', 'H'))));
69 BOOST_TEST((test("T", sym2
, make_vector('t', 'T'))));
70 BOOST_TEST((test("K", sym2
, make_vector('k', 'K'))));
71 BOOST_TEST((!test("", sym2
, 'x')));
73 // make sure it plays well with other generators
74 BOOST_TEST((test("Jyo", sym
<< "yo", make_vector('j', 'J'))));
81 BOOST_TEST((!test("", sym
, 'j')));
82 BOOST_TEST((!test("", sym
, 'h')));
86 symbols
<std::string
> sym
;
95 BOOST_TEST_TRAIT_TRUE((
96 boost::spirit::traits::is_generator
<
97 symbols
<char, std::string
> >));
99 BOOST_TEST((test("Joel", sym
, "Joel")));
100 BOOST_TEST((test("Hartmut", sym
, "Hartmut")));
101 BOOST_TEST((test("Tom", sym
, "Tom")));
102 BOOST_TEST((test("Kim", sym
, "Kim")));
103 BOOST_TEST((!test("", sym
, "X")));
106 symbols
<std::string
> sym2
;
108 BOOST_TEST((test("Joel", sym2
, "Joel")));
109 BOOST_TEST((test("Hartmut", sym2
, "Hartmut")));
110 BOOST_TEST((test("Tom", sym2
, "Tom")));
111 BOOST_TEST((test("Kim", sym2
, "Kim")));
112 BOOST_TEST((!test("", sym2
, "X")));
114 // make sure it plays well with other generators
115 BOOST_TEST((test("Joelyo", sym
<< "yo", "Joel")));
122 BOOST_TEST((!test("", sym
, "Joel")));
123 BOOST_TEST((!test("", sym
, "Hartmut")));
127 symbols
<std::string
> sym("test1"), sym2
;
128 BOOST_TEST(sym
.name() == "test1");
131 BOOST_TEST(sym
.name() == "test");
133 BOOST_TEST(sym2
.name() == "test");
135 symbols
<std::string
> sym3(sym
);
136 BOOST_TEST(sym3
.name() == "test");
139 return boost::report_errors();