]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright (c) 2001-2011 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_PP_IS_ITERATING) | |
7 | ||
8 | #if !defined(BOOST_SPIRIT_KARMA_TEST_MANIP_ATTR_APR_24_2009_0834AM) | |
9 | #define BOOST_SPIRIT_KARMA_TEST_MANIP_ATTR_APR_24_2009_0834AM | |
10 | ||
11 | #include <cstring> | |
12 | #include <string> | |
13 | #include <iterator> | |
14 | #include <iostream> | |
15 | #include <typeinfo> | |
16 | ||
17 | #include <boost/spirit/include/karma_stream.hpp> | |
18 | ||
1e59de90 | 19 | #include <boost/core/lightweight_test.hpp> |
7c673cae FG |
20 | #include <boost/preprocessor/iterate.hpp> |
21 | #include <boost/preprocessor/repetition/enum.hpp> | |
22 | #include <boost/preprocessor/repetition/enum_params.hpp> | |
23 | #include <boost/preprocessor/repetition/enum_binary_params.hpp> | |
24 | ||
25 | namespace spirit_test | |
26 | { | |
27 | /////////////////////////////////////////////////////////////////////////// | |
28 | template <typename Char, typename T> | |
29 | void print_if_failed(char const* func, bool result | |
30 | , std::basic_string<Char> const& generated, T const& expected) | |
31 | { | |
32 | if (!result) | |
33 | std::cerr << "in " << func << ": result is false" << std::endl; | |
34 | else if (generated != expected) | |
35 | std::cerr << "in " << func << ": generated \"" | |
36 | << std::string(generated.begin(), generated.end()) | |
37 | << "\"" << std::endl; | |
38 | } | |
39 | } | |
40 | ||
11fdf7f2 | 41 | #define BOOST_PP_FILENAME_1 "test_manip_attr.hpp" |
7c673cae FG |
42 | #define BOOST_PP_ITERATION_LIMITS (1, SPIRIT_ARGUMENTS_LIMIT) |
43 | #include BOOST_PP_ITERATE() | |
44 | ||
45 | #endif | |
46 | ||
47 | /////////////////////////////////////////////////////////////////////////////// | |
48 | // | |
49 | // Preprocessor vertical repetition code | |
50 | // | |
51 | /////////////////////////////////////////////////////////////////////////////// | |
52 | #else // defined(BOOST_PP_IS_ITERATING) | |
53 | ||
54 | #define N BOOST_PP_ITERATION() | |
55 | ||
56 | namespace spirit_test | |
57 | { | |
58 | /////////////////////////////////////////////////////////////////////////// | |
59 | template <typename Char, typename Generator | |
60 | , BOOST_PP_ENUM_PARAMS(N, typename A)> | |
61 | inline bool test(Char const *expected, Generator const& g | |
62 | , BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& attr)) | |
63 | { | |
64 | namespace karma = boost::spirit::karma; | |
65 | ||
66 | std::ostringstream ostrm; | |
67 | ostrm << karma::format(g, BOOST_PP_ENUM_PARAMS(N, attr)); | |
68 | ||
69 | print_if_failed("test", ostrm.good(), ostrm.str(), expected); | |
70 | return ostrm.good() && ostrm.str() == expected; | |
71 | } | |
72 | ||
73 | /////////////////////////////////////////////////////////////////////////// | |
74 | template <typename Char, typename Generator, typename Delimiter | |
75 | , BOOST_PP_ENUM_PARAMS(N, typename A)> | |
76 | inline bool test_delimited(Char const *expected, Generator const& g | |
77 | , Delimiter const& d, BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& attr)) | |
78 | { | |
79 | namespace karma = boost::spirit::karma; | |
80 | ||
81 | std::ostringstream ostrm; | |
82 | ostrm << karma::format_delimited(g, d, BOOST_PP_ENUM_PARAMS(N, attr)); | |
83 | ||
84 | print_if_failed("test_delimited", ostrm.good(), ostrm.str(), expected); | |
85 | return ostrm.good() && ostrm.str() == expected; | |
86 | } | |
87 | ||
88 | /////////////////////////////////////////////////////////////////////////// | |
89 | template <typename Char, typename Generator, typename Delimiter | |
90 | , BOOST_PP_ENUM_PARAMS(N, typename A)> | |
91 | inline bool test_predelimited(Char const *expected, Generator const& g | |
92 | , Delimiter const& d | |
93 | , BOOST_SCOPED_ENUM(boost::spirit::karma::delimit_flag) pre_delimit | |
94 | , BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& attr)) | |
95 | { | |
96 | namespace karma = boost::spirit::karma; | |
97 | ||
98 | std::ostringstream ostrm; | |
99 | ostrm << karma::format_delimited(g, d, pre_delimit | |
100 | , BOOST_PP_ENUM_PARAMS(N, attr)); | |
101 | ||
102 | print_if_failed("test_predelimited", ostrm.good(), ostrm.str(), expected); | |
103 | return ostrm.good() && ostrm.str() == expected; | |
104 | } | |
105 | ||
106 | } // namespace spirit_test | |
107 | ||
108 | #undef N | |
109 | ||
110 | #endif |