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#if !defined(BOOST_SPIRIT_TEST_AUTO_HPP)
7#define BOOST_SPIRIT_TEST_AUTO_HPP
8
9#include <boost/spirit/include/karma_auto.hpp>
10
11#include <boost/fusion/include/std_pair.hpp>
12#include <boost/spirit/include/karma_bool.hpp>
13#include <boost/spirit/include/karma_char.hpp>
14#include <boost/spirit/include/karma_numeric.hpp>
15#include <boost/spirit/include/karma_string.hpp>
16#include <boost/spirit/include/karma_nonterminal.hpp>
17#include <boost/spirit/include/karma_operator.hpp>
18#include <boost/spirit/include/karma_directive.hpp>
19
20#include "test.hpp"
21
22namespace karma = boost::spirit::karma;
23namespace traits = boost::spirit::traits;
24
25///////////////////////////////////////////////////////////////////////////////
26template <typename Char, typename T>
27bool test_create_generator(Char const *expected, T const& t)
28{
29 std::basic_string<Char> generated;
30 std::back_insert_iterator<std::basic_string<Char> > sink(generated);
31
32 BOOST_TEST((traits::meta_create_exists<karma::domain, T>::value));
33 bool result = karma::generate(sink, karma::create_generator<T>(), t);
34
35 spirit_test::print_if_failed("test_create_generator", result, generated, expected);
36 return result && generated == expected;
37}
38
39template <typename Char, typename T>
40bool test_create_generator_auto(Char const *expected, T const& t)
41{
42 std::basic_string<Char> generated;
43 std::back_insert_iterator<std::basic_string<Char> > sink(generated);
44
45 BOOST_TEST((traits::meta_create_exists<karma::domain, T>::value));
46 bool result = karma::generate(sink, t);
47
48 spirit_test::print_if_failed("test_create_generator (auto)", result, generated, expected);
49 return result && generated == expected;
50}
51
52template <typename Char, typename Attribute>
53bool test_rule(Char const *expected, Attribute const& attr)
54{
55 BOOST_TEST((traits::meta_create_exists<karma::domain, Attribute>::value));
56
57 typedef typename spirit_test::output_iterator<Char>::type sink_type;
58 karma::rule<sink_type, Attribute()> r =
59 karma::create_generator<Attribute>();
60 return spirit_test::test(expected, r, attr);
61}
62
63template <typename Char, typename Attribute, typename Delimiter>
64bool test_rule_delimited(Char const *expected, Attribute const& attr
65 , Delimiter const& d)
66{
67 BOOST_TEST((traits::meta_create_exists<karma::domain, Attribute>::value));
68
69 typedef typename spirit_test::output_iterator<Char>::type sink_type;
70 karma::rule<sink_type, Attribute(), Delimiter> r =
71 karma::create_generator<Attribute>();
72 return spirit_test::test_delimited(expected, r, attr, d);
73}
74
75struct my_type {};
76
77#endif
78

source code of boost/libs/spirit/test/karma/auto.hpp