]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/metaparse/test/string.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / metaparse / test / string.cpp
CommitLineData
7c673cae
FG
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)
5
6#define BOOST_TEST_MODULE string
7
8#define BOOST_METAPARSE_LIMIT_STRING_SIZE 64
9
10#include <boost/metaparse/string.hpp>
11
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>
36
37#include <boost/test/unit_test.hpp>
38
39#include <string>
40
41BOOST_AUTO_TEST_CASE(test_string)
42{
43 using boost::mpl::equal;
44 using boost::mpl::equal_to;
45 using boost::mpl::char_;
46 using boost::mpl::int_;
47 using boost::mpl::at;
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;
67
68 using namespace boost;
69
70 // string type
71 ///////////////////////
72
73 typedef metaparse::string<'H','e','l','l','o'> hello;
74 typedef metaparse::string<> empty_string;
75
76 typedef begin<hello>::type begin_hello;
77 typedef end<hello>::type end_hello;
78
79 // test_value_of_empty_string
80 BOOST_REQUIRE_EQUAL(std::string(), c_str<empty_string>::type::value);
81
82 // test_value
83 BOOST_REQUIRE_EQUAL(std::string("Hello"), c_str<hello>::type::value);
84
85 // equal_to
86 BOOST_MPL_ASSERT((equal_to<hello, hello>));
87 BOOST_MPL_ASSERT_NOT((equal_to<hello, empty_string>));
88
89 // at
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>));
92
93 // size
94 BOOST_MPL_ASSERT((equal_to<int_<5>, size<hello>::type>));
95
96 // is_sequence
97 BOOST_MPL_ASSERT((is_sequence<hello>));
98
99 // front
100 BOOST_MPL_ASSERT((equal_to<char_<'H'>, front<hello>::type>));
101
102 // push_front
103 BOOST_MPL_ASSERT((
104 equal_to<
105 metaparse::string<'x','H','e','l','l','o'>,
106 push_front<hello, char_<'x'> >::type
107 >
108 ));
109
110 // back
111 BOOST_MPL_ASSERT((equal_to<char_<'o'>, back<hello>::type>));
112
113 // push_back
114 BOOST_MPL_ASSERT((
115 equal_to<
116 metaparse::string<'H','e','l','l','o', 'x'>,
117 push_back<hello, char_<'x'> >::type
118 >
119 ));
120
121 // clear
122 BOOST_MPL_ASSERT((equal_to<empty_string, clear<hello>::type>));
123
124 // empty
125 BOOST_MPL_ASSERT_NOT((empty<hello>::type));
126 BOOST_MPL_ASSERT((empty<empty_string>::type));
127
128 // string_iterator
129 BOOST_MPL_ASSERT((equal_to<begin_hello, begin_hello>));
130 BOOST_MPL_ASSERT_NOT((equal_to<begin_hello, end_hello>));
131 BOOST_MPL_ASSERT((
132 equal_to<begin<empty_string>::type, end<empty_string>::type>
133 ));
134
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>));
137 BOOST_MPL_ASSERT((
138 equal_to<char_<'e'>, deref<next<begin_hello>::type>::type>
139 ));
140 BOOST_MPL_ASSERT((equal_to<char_<'o'>, deref<prior<end_hello>::type>::type>));
141
142 BOOST_MPL_ASSERT((equal_to<int_<5>, distance<begin_hello, end_hello>::type>));
143
144 // pop_front
145 BOOST_MPL_ASSERT((
146 equal_to<metaparse::string<'e','l','l','o'>, pop_front<hello>::type>
147 ));
148
149 // pop_back
150 BOOST_MPL_ASSERT((
151 equal_to<metaparse::string<'H','e','l','l'>, pop_back<hello>::type>
152 ));
153
b32b8144 154#if BOOST_METAPARSE_STD >= 2011
7c673cae
FG
155 // BOOST_METAPARSE_STRING macro
156 ///////////////////////
157
158 // test_empty_string
159 BOOST_MPL_ASSERT((equal<BOOST_METAPARSE_STRING(""), empty_string>));
160
161 // test_string_creation
162 BOOST_MPL_ASSERT((equal<BOOST_METAPARSE_STRING("Hello"), hello>));
163#endif
164
165}
166