]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/karma/int3.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / spirit / test / karma / int3.cpp
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 //#define KARMA_FAIL_COMPILATION
7
8 #include <boost/config/warning_disable.hpp>
9 #include <boost/detail/lightweight_test.hpp>
10 #include <boost/lexical_cast.hpp>
11 #include <boost/mpl/vector.hpp>
12 #include <boost/mpl/for_each.hpp>
13 #include <boost/mpl/if.hpp>
14 #include <boost/mpl/bool.hpp>
15
16 #include <boost/spirit/include/phoenix_core.hpp>
17 #include <boost/spirit/include/phoenix_operator.hpp>
18 #include <boost/spirit/include/phoenix_statement.hpp>
19
20 #include <boost/spirit/include/karma_char.hpp>
21 #include <boost/spirit/include/karma_numeric.hpp>
22 #include <boost/spirit/include/karma_directive.hpp>
23 #include <boost/spirit/include/karma_action.hpp>
24 #include <boost/spirit/include/karma_phoenix_attributes.hpp>
25
26 #include <boost/limits.hpp>
27 #include "test.hpp"
28
29 using namespace spirit_test;
30
31 ///////////////////////////////////////////////////////////////////////////////
32 struct test_minmax
33 {
34 template <typename T>
35 void operator()(T) const
36 {
37 using namespace boost::spirit;
38 using namespace boost::phoenix;
39
40 T minval = (std::numeric_limits<T>::min)();
41 T maxval = (std::numeric_limits<T>::max)();
42
43 std::string expected_minval = boost::lexical_cast<std::string>(minval);
44 std::string expected_maxval = boost::lexical_cast<std::string>(maxval);
45
46 // create a correct generator type from the given integer type
47 typedef typename
48 boost::mpl::if_<
49 boost::mpl::bool_<std::numeric_limits<T>::is_signed>,
50 karma::int_generator<T>,
51 karma::uint_generator<T>
52 >::type
53 int_generator_type;
54
55 int_generator_type const gen = int_generator_type();
56
57 BOOST_TEST(test(expected_maxval, gen, maxval));
58 BOOST_TEST(test(expected_minval, gen, minval));
59 BOOST_TEST(test(expected_maxval, gen(maxval)));
60 BOOST_TEST(test(expected_minval, gen(minval)));
61 BOOST_TEST(test(expected_maxval, gen(maxval), maxval));
62 BOOST_TEST(test(expected_minval, gen(minval), minval));
63 BOOST_TEST(!test("", gen(maxval), maxval-1));
64 BOOST_TEST(!test("", gen(minval), minval+1));
65 BOOST_TEST(test(expected_maxval, lit(maxval)));
66 BOOST_TEST(test(expected_minval, lit(minval)));
67
68 BOOST_TEST(test_delimited(expected_maxval + " ", gen, maxval, char(' ')));
69 BOOST_TEST(test_delimited(expected_minval + " ", gen, minval, char(' ')));
70 BOOST_TEST(test_delimited(expected_maxval + " ", gen(maxval), char(' ')));
71 BOOST_TEST(test_delimited(expected_minval + " ", gen(minval), char(' ')));
72 BOOST_TEST(test_delimited(expected_maxval + " ", gen(maxval), maxval, char(' ')));
73 BOOST_TEST(test_delimited(expected_minval + " ", gen(minval), minval, char(' ')));
74 BOOST_TEST(!test_delimited("", gen(maxval), maxval-1, char(' ')));
75 BOOST_TEST(!test_delimited("", gen(minval), minval+1, char(' ')));
76 BOOST_TEST(test_delimited(expected_maxval + " ", lit(maxval), char(' ')));
77 BOOST_TEST(test_delimited(expected_minval + " ", lit(minval), char(' ')));
78
79 // action tests
80 BOOST_TEST(test(expected_maxval, gen[_1 = val(maxval)]));
81 BOOST_TEST(test(expected_minval, gen[_1 = val(minval)]));
82
83 // optional tests
84 boost::optional<T> optmin, optmax(maxval);
85
86 BOOST_TEST(!test("", gen, optmin));
87 BOOST_TEST(!test("", gen(minval), optmin));
88
89 optmin = minval;
90 BOOST_TEST(test(expected_minval, gen, optmin));
91 BOOST_TEST(test(expected_maxval, gen, optmax));
92 BOOST_TEST(test(expected_minval, gen(minval), optmin));
93 BOOST_TEST(test(expected_maxval, gen(maxval), optmax));
94
95 // we support Phoenix attributes only starting with V2.2
96 #if SPIRIT_VERSION >= 0x2020
97 // Phoenix expression tests (only supported while including
98 // karma_phoenix_attributes.hpp
99 namespace phoenix = boost::phoenix;
100
101 BOOST_TEST(test("1", gen, phoenix::val(1)));
102
103 T val = 1;
104 BOOST_TEST(test("1", gen, phoenix::ref(val)));
105 BOOST_TEST(test("2", gen, ++phoenix::ref(val)));
106 #endif
107 }
108 };
109
110 ///////////////////////////////////////////////////////////////////////////////
111 int
112 main()
113 {
114 using namespace boost::spirit;
115
116 // test boundary values
117 typedef boost::mpl::vector<
118 #ifdef BOOST_HAS_LONG_LONG
119 boost::long_long_type, boost::ulong_long_type,
120 #endif
121 short, unsigned short,
122 int, unsigned int,
123 long, unsigned long
124 > integer_types;
125 boost::mpl::for_each<integer_types>(test_minmax());
126
127 return boost::report_errors();
128 }
129