]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/karma/int3.cpp
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_int.hpp>
8 #include <boost/mpl/vector.hpp>
9 #include <boost/mpl/for_each.hpp>
10 #include <boost/mpl/if.hpp>
11 #include <boost/mpl/bool.hpp>
13 #include <boost/phoenix/core.hpp>
14 #include <boost/phoenix/operator.hpp>
16 #include <boost/spirit/include/karma_char.hpp>
17 #include <boost/spirit/include/karma_numeric.hpp>
18 #include <boost/spirit/include/karma_directive.hpp>
19 #include <boost/spirit/include/karma_action.hpp>
20 #include <boost/spirit/include/karma_phoenix_attributes.hpp>
22 #include <boost/limits.hpp>
26 using namespace spirit_test
;
29 std::string
to_string(T v
)
36 ///////////////////////////////////////////////////////////////////////////////
40 void operator()(T
) const
42 using namespace boost::spirit
;
43 using namespace boost::phoenix
;
45 T minval
= (std::numeric_limits
<T
>::min
)();
46 T maxval
= (std::numeric_limits
<T
>::max
)();
48 std::string expected_minval
= to_string(minval
);
49 std::string expected_maxval
= to_string(maxval
);
51 // create a correct generator type from the given integer type
54 boost::mpl::bool_
<std::numeric_limits
<T
>::is_signed
>,
55 karma::int_generator
<T
>,
56 karma::uint_generator
<T
>
60 int_generator_type
const gen
= int_generator_type();
62 BOOST_TEST(test(expected_maxval
, gen
, maxval
));
63 BOOST_TEST(test(expected_minval
, gen
, minval
));
64 BOOST_TEST(test(expected_maxval
, gen(maxval
)));
65 BOOST_TEST(test(expected_minval
, gen(minval
)));
66 BOOST_TEST(test(expected_maxval
, gen(maxval
), maxval
));
67 BOOST_TEST(test(expected_minval
, gen(minval
), minval
));
68 BOOST_TEST(!test("", gen(maxval
), maxval
-1));
69 BOOST_TEST(!test("", gen(minval
), minval
+1));
70 BOOST_TEST(test(expected_maxval
, lit(maxval
)));
71 BOOST_TEST(test(expected_minval
, lit(minval
)));
73 BOOST_TEST(test_delimited(expected_maxval
+ " ", gen
, maxval
, char(' ')));
74 BOOST_TEST(test_delimited(expected_minval
+ " ", gen
, minval
, char(' ')));
75 BOOST_TEST(test_delimited(expected_maxval
+ " ", gen(maxval
), char(' ')));
76 BOOST_TEST(test_delimited(expected_minval
+ " ", gen(minval
), char(' ')));
77 BOOST_TEST(test_delimited(expected_maxval
+ " ", gen(maxval
), maxval
, char(' ')));
78 BOOST_TEST(test_delimited(expected_minval
+ " ", gen(minval
), minval
, char(' ')));
79 BOOST_TEST(!test_delimited("", gen(maxval
), maxval
-1, char(' ')));
80 BOOST_TEST(!test_delimited("", gen(minval
), minval
+1, char(' ')));
81 BOOST_TEST(test_delimited(expected_maxval
+ " ", lit(maxval
), char(' ')));
82 BOOST_TEST(test_delimited(expected_minval
+ " ", lit(minval
), char(' ')));
85 BOOST_TEST(test(expected_maxval
, gen
[_1
= val(maxval
)]));
86 BOOST_TEST(test(expected_minval
, gen
[_1
= val(minval
)]));
89 boost::optional
<T
> optmin
, optmax(maxval
);
91 BOOST_TEST(!test("", gen
, optmin
));
92 BOOST_TEST(!test("", gen(minval
), optmin
));
95 BOOST_TEST(test(expected_minval
, gen
, optmin
));
96 BOOST_TEST(test(expected_maxval
, gen
, optmax
));
97 BOOST_TEST(test(expected_minval
, gen(minval
), optmin
));
98 BOOST_TEST(test(expected_maxval
, gen(maxval
), optmax
));
100 // Phoenix expression tests (only supported while including
101 // karma_phoenix_attributes.hpp
102 namespace phoenix
= boost::phoenix
;
104 BOOST_TEST(test("1", gen
, phoenix::val(1)));
107 BOOST_TEST(test("1", gen
, phoenix::ref(val
)));
108 BOOST_TEST(test("2", gen
, ++phoenix::ref(val
)));
112 ///////////////////////////////////////////////////////////////////////////////
116 using namespace boost::spirit
;
118 // test boundary values
119 typedef boost::mpl::vector
<
120 #ifdef BOOST_HAS_LONG_LONG
121 boost::long_long_type
, boost::ulong_long_type
,
123 short, unsigned short,
127 boost::mpl::for_each
<integer_types
>(test_minmax());
129 return boost::report_errors();