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