]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/metaparse/test/string.cpp
1 // Copyright Abel Sinkovics (abel@sinkovics.hu) 2012.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 #define BOOST_TEST_MODULE string
8 #define BOOST_METAPARSE_LIMIT_STRING_SIZE 64
10 #include <boost/metaparse/string.hpp>
12 #include <boost/mpl/equal.hpp>
13 #include <boost/mpl/equal_to.hpp>
14 #include <boost/mpl/assert.hpp>
15 #include <boost/mpl/at.hpp>
16 #include <boost/mpl/char.hpp>
17 #include <boost/mpl/int.hpp>
18 #include <boost/mpl/size.hpp>
19 #include <boost/mpl/back.hpp>
20 #include <boost/mpl/begin_end.hpp>
21 #include <boost/mpl/deref.hpp>
22 #include <boost/mpl/advance.hpp>
23 #include <boost/mpl/next.hpp>
24 #include <boost/mpl/prior.hpp>
25 #include <boost/mpl/distance.hpp>
26 #include <boost/mpl/clear.hpp>
27 #include <boost/mpl/empty.hpp>
28 #include <boost/mpl/front.hpp>
29 #include <boost/mpl/is_sequence.hpp>
30 #include <boost/mpl/pop_front.hpp>
31 #include <boost/mpl/pop_back.hpp>
32 #include <boost/mpl/push_front.hpp>
33 #include <boost/mpl/push_back.hpp>
34 #include <boost/mpl/string.hpp>
35 #include <boost/mpl/assert.hpp>
37 #include <boost/test/unit_test.hpp>
41 BOOST_AUTO_TEST_CASE(test_string
)
43 using boost::mpl::equal
;
44 using boost::mpl::equal_to
;
45 using boost::mpl::char_
;
46 using boost::mpl::int_
;
48 using boost::mpl::at_c
;
49 using boost::mpl::size
;
50 using boost::mpl::back
;
51 using boost::mpl::deref
;
52 using boost::mpl::advance
;
53 using boost::mpl::next
;
54 using boost::mpl::prior
;
55 using boost::mpl::distance
;
56 using boost::mpl::clear
;
57 using boost::mpl::empty
;
58 using boost::mpl::front
;
59 using boost::mpl::is_sequence
;
60 using boost::mpl::pop_front
;
61 using boost::mpl::pop_back
;
62 using boost::mpl::begin
;
63 using boost::mpl::end
;
64 using boost::mpl::c_str
;
65 using boost::mpl::push_front
;
66 using boost::mpl::push_back
;
68 using namespace boost
;
71 ///////////////////////
73 typedef metaparse::string
<'H','e','l','l','o'> hello
;
74 typedef metaparse::string
<> empty_string
;
76 typedef begin
<hello
>::type begin_hello
;
77 typedef end
<hello
>::type end_hello
;
79 // test_value_of_empty_string
80 BOOST_REQUIRE_EQUAL(std::string(), c_str
<empty_string
>::type::value
);
83 BOOST_REQUIRE_EQUAL(std::string("Hello"), c_str
<hello
>::type::value
);
86 BOOST_MPL_ASSERT((equal_to
<hello
, hello
>));
87 BOOST_MPL_ASSERT_NOT((equal_to
<hello
, empty_string
>));
90 BOOST_MPL_ASSERT((equal_to
<char_
<'e'>, at
<hello
, int_
<1> >::type
>));
91 BOOST_MPL_ASSERT((equal_to
<char_
<'e'>, at_c
<hello
, 1>::type
>));
94 BOOST_MPL_ASSERT((equal_to
<int_
<5>, size
<hello
>::type
>));
97 BOOST_MPL_ASSERT((is_sequence
<hello
>));
100 BOOST_MPL_ASSERT((equal_to
<char_
<'H'>, front
<hello
>::type
>));
105 metaparse::string
<'x','H','e','l','l','o'>,
106 push_front
<hello
, char_
<'x'> >::type
111 BOOST_MPL_ASSERT((equal_to
<char_
<'o'>, back
<hello
>::type
>));
116 metaparse::string
<'H','e','l','l','o', 'x'>,
117 push_back
<hello
, char_
<'x'> >::type
122 BOOST_MPL_ASSERT((equal_to
<empty_string
, clear
<hello
>::type
>));
125 BOOST_MPL_ASSERT_NOT((empty
<hello
>::type
));
126 BOOST_MPL_ASSERT((empty
<empty_string
>::type
));
129 BOOST_MPL_ASSERT((equal_to
<begin_hello
, begin_hello
>));
130 BOOST_MPL_ASSERT_NOT((equal_to
<begin_hello
, end_hello
>));
132 equal_to
<begin
<empty_string
>::type
, end
<empty_string
>::type
>
135 BOOST_MPL_ASSERT((equal_to
<char_
<'H'>, deref
<begin_hello
>::type
>));
136 BOOST_MPL_ASSERT((equal_to
<end_hello
, advance
<begin_hello
, int_
<5> >::type
>));
138 equal_to
<char_
<'e'>, deref
<next
<begin_hello
>::type
>::type
>
140 BOOST_MPL_ASSERT((equal_to
<char_
<'o'>, deref
<prior
<end_hello
>::type
>::type
>));
142 BOOST_MPL_ASSERT((equal_to
<int_
<5>, distance
<begin_hello
, end_hello
>::type
>));
146 equal_to
<metaparse::string
<'e','l','l','o'>, pop_front
<hello
>::type
>
151 equal_to
<metaparse::string
<'H','e','l','l'>, pop_back
<hello
>::type
>
154 #ifndef BOOST_NO_CONSTEXPR
155 // BOOST_METAPARSE_STRING macro
156 ///////////////////////
159 BOOST_MPL_ASSERT((equal
<BOOST_METAPARSE_STRING(""), empty_string
>));
161 // test_string_creation
162 BOOST_MPL_ASSERT((equal
<BOOST_METAPARSE_STRING("Hello"), hello
>));