]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/x3/container_support.cpp
1 /*=============================================================================
2 Copyright (c) 2001-2015 Joel de Guzman
3 Copyright (c) 2001-2011 Hartmut Kaiser
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
8 #include <boost/detail/lightweight_test.hpp>
9 #include <boost/spirit/home/x3.hpp>
10 #include <boost/fusion/include/std_pair.hpp>
14 #include <unordered_map>
15 #include <boost/unordered_map.hpp>
20 #include <unordered_set>
21 #include <boost/unordered_set.hpp>
25 namespace x3
= boost::spirit::x3
;
27 x3::rule
<class pair_rule
, std::pair
<std::string
,std::string
>> const pair_rule("pair");
28 x3::rule
<class string_rule
, std::string
> const string_rule("string");
30 auto const pair_rule_def
= string_rule
> x3::lit('=') > string_rule
;
31 auto const string_rule_def
= x3::lexeme
[*x3::alnum
];
33 BOOST_SPIRIT_DEFINE(pair_rule
, string_rule
);
35 template <typename Container
>
36 void test_map_support(Container
&& container
)
38 using spirit_test::test_attr
;
40 Container
const compare
{{"k1", "v1"}, {"k2", "v2"}};
41 auto const rule
= pair_rule
% x3::lit(',');
43 BOOST_TEST(test_attr("k1=v1,k2=v2,k2=v3", rule
, container
));
44 BOOST_TEST(container
.size() == 2);
45 BOOST_TEST(container
== compare
);
47 // test sequences parsing into containers
48 auto const seq_rule
= pair_rule
>> ',' >> pair_rule
>> ',' >> pair_rule
;
50 BOOST_TEST(test_attr("k1=v1,k2=v2,k2=v3", seq_rule
, container
));
53 template <typename Container
>
54 void test_multimap_support(Container
&& container
)
56 using spirit_test::test_attr
;
58 Container
const compare
{{"k1", "v1"}, {"k2", "v2"}, {"k2", "v3"}};
59 auto const rule
= pair_rule
% x3::lit(',');
61 BOOST_TEST(test_attr("k1=v1,k2=v2,k2=v3", rule
, container
));
62 BOOST_TEST(container
.size() == 3);
63 BOOST_TEST(container
== compare
);
65 // test sequences parsing into containers
66 auto const seq_rule
= pair_rule
>> ',' >> pair_rule
>> ',' >> pair_rule
;
68 BOOST_TEST(test_attr("k1=v1,k2=v2,k2=v3", seq_rule
, container
));
71 template <typename Container
>
72 void test_sequence_support(Container
&& container
)
74 using spirit_test::test_attr
;
76 Container
const compare
{"e1", "e2", "e2"};
77 auto const rule
= string_rule
% x3::lit(',');
79 BOOST_TEST(test_attr("e1,e2,e2", rule
, container
));
80 BOOST_TEST(container
.size() == 3);
81 BOOST_TEST(container
== compare
);
83 // test sequences parsing into containers
84 auto const seq_rule
= string_rule
>> ',' >> string_rule
>> ',' >> string_rule
;
86 BOOST_TEST(test_attr("e1,e2,e2", seq_rule
, container
));
89 template <typename Container
>
90 void test_set_support(Container
&& container
)
92 using spirit_test::test_attr
;
94 Container
const compare
{"e1", "e2"};
95 auto const rule
= string_rule
% x3::lit(',');
97 BOOST_TEST(test_attr("e1,e2,e2", rule
, container
));
98 BOOST_TEST(container
.size() == 2);
99 BOOST_TEST(container
== compare
);
101 // test sequences parsing into containers
102 auto const seq_rule
= string_rule
>> ',' >> string_rule
>> ',' >> string_rule
;
104 BOOST_TEST(test_attr("e1,e2,e2", seq_rule
, container
));
107 template <typename Container
>
108 void test_multiset_support(Container
&& container
)
110 using spirit_test::test_attr
;
112 Container
const compare
{"e1", "e2", "e2"};
113 auto const rule
= string_rule
% x3::lit(',');
115 BOOST_TEST(test_attr("e1,e2,e2", rule
, container
));
116 BOOST_TEST(container
.size() == 3);
117 BOOST_TEST(container
== compare
);
119 // test sequences parsing into containers
120 auto const seq_rule
= string_rule
>> ',' >> string_rule
>> ',' >> string_rule
;
122 BOOST_TEST(test_attr("e1,e2,e2", seq_rule
, container
));
125 template <typename Container
>
126 void test_string_support(Container
&& container
)
128 using spirit_test::test_attr
;
130 Container
const compare
{"e1e2e2"};
131 auto const rule
= string_rule
% x3::lit(',');
133 BOOST_TEST(test_attr("e1,e2,e2", rule
, container
));
134 BOOST_TEST(container
.size() == 6);
135 BOOST_TEST(container
== compare
);
137 // test sequences parsing into containers
138 auto const seq_rule
= string_rule
>> ',' >> string_rule
>> ',' >> string_rule
;
140 BOOST_TEST(test_attr("e1,e2,e2", seq_rule
, container
));
146 using x3::traits::is_associative
;
147 using x3::traits::is_reservable
;
149 static_assert(is_reservable
<std::vector
<int>>::value
, "is_reservable problem");
150 static_assert(is_reservable
<std::string
>::value
, "is_reservable problem");
151 static_assert(is_reservable
<std::unordered_set
<int>>::value
, "is_reservable problem");
152 static_assert(is_reservable
<boost::unordered_set
<int>>::value
, "is_reservable problem");
153 static_assert(is_reservable
<std::unordered_multiset
<int>>::value
, "is_reservable problem");
154 static_assert(is_reservable
<boost::unordered_multiset
<int>>::value
, "is_reservable problem");
155 static_assert(is_reservable
<std::unordered_map
<int,int>>::value
, "is_reservable problem");
156 static_assert(is_reservable
<boost::unordered_map
<int,int>>::value
, "is_reservable problem");
157 static_assert(is_reservable
<std::unordered_multimap
<int,int>>::value
, "is_reservable problem");
158 static_assert(is_reservable
<boost::unordered_multimap
<int,int>>::value
, "is_reservable problem");
160 static_assert(!is_reservable
<std::deque
<int>>::value
, "is_reservable problem");
161 static_assert(!is_reservable
<std::list
<int>>::value
, "is_reservable problem");
162 static_assert(!is_reservable
<std::set
<int>>::value
, "is_reservable problem");
163 static_assert(!is_reservable
<std::multiset
<int>>::value
, "is_reservable problem");
164 static_assert(!is_reservable
<std::map
<int,int>>::value
, "is_reservable problem");
165 static_assert(!is_reservable
<std::multimap
<int,int>>::value
, "is_reservable problem");
167 // ------------------------------------------------------------------
169 static_assert(is_associative
<std::set
<int>>::value
, "is_associative problem");
170 static_assert(is_associative
<std::unordered_set
<int>>::value
, "is_associative problem");
171 static_assert(is_associative
<boost::unordered_set
<int>>::value
, "is_associative problem");
172 static_assert(is_associative
<std::multiset
<int>>::value
, "is_associative problem");
173 static_assert(is_associative
<std::unordered_multiset
<int>>::value
, "is_associative problem");
174 static_assert(is_associative
<boost::unordered_multiset
<int>>::value
, "is_associative problem");
175 static_assert(is_associative
<std::map
<int,int>>::value
, "is_associative problem");
176 static_assert(is_associative
<std::unordered_map
<int,int>>::value
, "is_associative problem");
177 static_assert(is_associative
<boost::unordered_map
<int,int>>::value
, "is_associative problem");
178 static_assert(is_associative
<std::multimap
<int,int>>::value
, "is_associative problem");
179 static_assert(is_associative
<std::unordered_multimap
<int,int>>::value
, "is_associative problem");
180 static_assert(is_associative
<boost::unordered_multimap
<int,int>>::value
, "is_associative problem");
182 static_assert(!is_associative
<std::vector
<int>>::value
, "is_associative problem");
183 static_assert(!is_associative
<std::string
>::value
, "is_associative problem");
184 static_assert(!is_associative
<std::deque
<int>>::value
, "is_associative problem");
185 static_assert(!is_associative
<std::list
<int>>::value
, "is_associative problem");
187 // ------------------------------------------------------------------
189 test_string_support(std::string());
191 test_sequence_support(std::vector
<std::string
>());
192 test_sequence_support(std::list
<std::string
>());
193 test_sequence_support(std::deque
<std::string
>());
195 test_set_support(std::set
<std::string
>());
196 test_set_support(std::unordered_set
<std::string
>());
197 test_set_support(boost::unordered_set
<std::string
>());
199 test_multiset_support(std::multiset
<std::string
>());
200 test_multiset_support(std::unordered_multiset
<std::string
>());
201 test_multiset_support(boost::unordered_multiset
<std::string
>());
203 test_map_support(std::map
<std::string
,std::string
>());
204 test_map_support(std::unordered_map
<std::string
,std::string
>());
205 test_map_support(boost::unordered_map
<std::string
,std::string
>());
207 test_multimap_support(std::multimap
<std::string
,std::string
>());
208 test_multimap_support(std::unordered_multimap
<std::string
,std::string
>());
209 test_multimap_support(boost::unordered_multimap
<std::string
,std::string
>());
211 return boost::report_errors();