]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/qi/list.cpp
1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 =============================================================================*/
7 #include <boost/spirit/include/qi_list.hpp>
9 #include <boost/spirit/include/qi_operator.hpp>
10 #include <boost/spirit/include/qi_char.hpp>
11 #include <boost/spirit/include/qi_string.hpp>
12 #include <boost/spirit/include/qi_numeric.hpp>
13 #include <boost/spirit/include/qi_directive.hpp>
14 #include <boost/spirit/include/qi_action.hpp>
15 #include <boost/spirit/include/support_argument.hpp>
16 #include <boost/phoenix/core.hpp>
17 #include <boost/phoenix/operator.hpp>
18 #include <boost/phoenix/object.hpp>
19 #include <boost/phoenix/stl/container.hpp>
20 #include <boost/fusion/include/std_pair.hpp>
29 using namespace spirit_test
;
34 using namespace boost::spirit::ascii
;
37 BOOST_TEST(test("a,b,c,d,e,f,g,h", char_
% ','));
38 BOOST_TEST(test("a,b,c,d,e,f,g,h,", char_
% ',', false));
42 BOOST_TEST(test("a, b, c, d, e, f, g, h", char_
% ',', space
));
43 BOOST_TEST(test("a, b, c, d, e, f, g, h,", char_
% ',', space
, false));
48 BOOST_TEST(test_attr("a,b,c,d,e,f,g,h", char_
% ',', s
));
49 BOOST_TEST(s
== "abcdefgh");
51 BOOST_TEST(!test("a,b,c,d,e,f,g,h,", char_
% ','));
56 BOOST_TEST(test_attr("ab,cd,ef,gh", (char_
>> char_
) % ',', s
));
57 BOOST_TEST(s
== "abcdefgh");
59 BOOST_TEST(!test("ab,cd,ef,gh,", (char_
>> char_
) % ','));
60 BOOST_TEST(!test("ab,cd,ef,g", (char_
>> char_
) % ','));
63 BOOST_TEST(test_attr("ab,cd,efg", (char_
>> char_
) % ',' >> char_
, s
));
64 BOOST_TEST(s
== "abcdefg");
68 using boost::spirit::int_
;
71 BOOST_TEST(test_attr("1,2", int_
% ',', v
));
72 BOOST_TEST(2 == v
.size() && 1 == v
[0] && 2 == v
[1]);
76 using boost::spirit::int_
;
79 BOOST_TEST(test_attr("(1,2)", '(' >> int_
% ',' >> ')', v
));
80 BOOST_TEST(2 == v
.size() && 1 == v
[0] && 2 == v
[1]);
84 std::vector
<std::string
> v
;
85 BOOST_TEST(test_attr("a,b,c,d", +alpha
% ',', v
));
86 BOOST_TEST(4 == v
.size() && "a" == v
[0] && "b" == v
[1]
87 && "c" == v
[2] && "d" == v
[3]);
91 std::vector
<boost::optional
<char> > v
;
92 BOOST_TEST(test_attr("#a,#", ('#' >> -alpha
) % ',', v
));
93 BOOST_TEST(2 == v
.size() &&
94 !!v
[0] && 'a' == boost::get
<char>(v
[0]) && !v
[1]);
97 BOOST_TEST(test_attr("#a,#", ('#' >> -alpha
) % ',', v2
));
98 BOOST_TEST(1 == v2
.size() && 'a' == v2
[0]);
102 typedef std::set
<std::pair
<std::string
, std::string
> > set_type
;
104 BOOST_TEST(test_attr("k1=v1&k2=v2",
105 (*(char_
- '=') >> '=' >> *(char_
- '&')) % '&', s
));
107 set_type::const_iterator it
= s
.begin();
108 BOOST_TEST(s
.size() == 2);
109 BOOST_TEST(it
!= s
.end() && (*it
).first
== "k1" && (*it
).second
== "v1");
110 BOOST_TEST(++it
!= s
.end() && (*it
).first
== "k2" && (*it
).second
== "v2");
114 typedef std::map
<std::string
, std::string
> map_type
;
116 BOOST_TEST(test_attr("k1=v1&k2=v2",
117 (*(char_
- '=') >> '=' >> *(char_
- '&')) % '&', m
));
119 map_type::const_iterator it
= m
.begin();
120 BOOST_TEST(m
.size() == 2);
121 BOOST_TEST(it
!= m
.end() && (*it
).first
== "k1" && (*it
).second
== "v1");
122 BOOST_TEST(++it
!= m
.end() && (*it
).first
== "k2" && (*it
).second
== "v2");
126 namespace phx
= boost::phoenix
;
127 using boost::phoenix::begin
;
128 using boost::phoenix::end
;
129 using boost::phoenix::construct
;
130 using boost::spirit::qi::_1
;
133 BOOST_TEST(test("a,b,c,d,e,f,g,h", (char_
% ',')
134 [phx::ref(s
) = construct
<std::string
>(begin(_1
), end(_1
))]));
137 return boost::report_errors();