]>
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 =============================================================================*/
12 #include <boost/detail/lightweight_test.hpp>
14 #include <boost/spirit/include/qi_operator.hpp>
15 #include <boost/spirit/include/qi_char.hpp>
16 #include <boost/spirit/include/qi_string.hpp>
17 #include <boost/spirit/include/qi_numeric.hpp>
18 #include <boost/spirit/include/qi_directive.hpp>
19 #include <boost/spirit/include/qi_action.hpp>
20 #include <boost/spirit/include/support_argument.hpp>
21 #include <boost/spirit/include/phoenix_core.hpp>
22 #include <boost/spirit/include/phoenix_operator.hpp>
23 #include <boost/spirit/include/phoenix_object.hpp>
24 #include <boost/spirit/include/phoenix_stl.hpp>
25 #include <boost/fusion/include/std_pair.hpp>
31 using namespace spirit_test
;
36 using namespace boost::spirit::ascii
;
39 BOOST_TEST(test("a,b,c,d,e,f,g,h", char_
% ','));
40 BOOST_TEST(test("a,b,c,d,e,f,g,h,", char_
% ',', false));
44 BOOST_TEST(test("a, b, c, d, e, f, g, h", char_
% ',', space
));
45 BOOST_TEST(test("a, b, c, d, e, f, g, h,", char_
% ',', space
, false));
50 BOOST_TEST(test_attr("a,b,c,d,e,f,g,h", char_
% ',', s
));
51 BOOST_TEST(s
== "abcdefgh");
53 BOOST_TEST(!test("a,b,c,d,e,f,g,h,", char_
% ','));
58 BOOST_TEST(test_attr("ab,cd,ef,gh", (char_
>> char_
) % ',', s
));
59 BOOST_TEST(s
== "abcdefgh");
61 BOOST_TEST(!test("ab,cd,ef,gh,", (char_
>> char_
) % ','));
62 BOOST_TEST(!test("ab,cd,ef,g", (char_
>> char_
) % ','));
65 BOOST_TEST(test_attr("ab,cd,efg", (char_
>> char_
) % ',' >> char_
, s
));
66 BOOST_TEST(s
== "abcdefg");
70 using boost::spirit::int_
;
73 BOOST_TEST(test_attr("1,2", int_
% ',', v
));
74 BOOST_TEST(2 == v
.size() && 1 == v
[0] && 2 == v
[1]);
78 using boost::spirit::int_
;
81 BOOST_TEST(test_attr("(1,2)", '(' >> int_
% ',' >> ')', v
));
82 BOOST_TEST(2 == v
.size() && 1 == v
[0] && 2 == v
[1]);
86 std::vector
<std::string
> v
;
87 BOOST_TEST(test_attr("a,b,c,d", +alpha
% ',', v
));
88 BOOST_TEST(4 == v
.size() && "a" == v
[0] && "b" == v
[1]
89 && "c" == v
[2] && "d" == v
[3]);
93 std::vector
<boost::optional
<char> > v
;
94 BOOST_TEST(test_attr("#a,#", ('#' >> -alpha
) % ',', v
));
95 BOOST_TEST(2 == v
.size() &&
96 !!v
[0] && 'a' == boost::get
<char>(v
[0]) && !v
[1]);
99 BOOST_TEST(test_attr("#a,#", ('#' >> -alpha
) % ',', v2
));
100 BOOST_TEST(1 == v2
.size() && 'a' == v2
[0]);
104 typedef std::set
<std::pair
<std::string
, std::string
> > set_type
;
106 BOOST_TEST(test_attr("k1=v1&k2=v2",
107 (*(char_
- '=') >> '=' >> *(char_
- '&')) % '&', s
));
109 set_type::const_iterator it
= s
.begin();
110 BOOST_TEST(s
.size() == 2);
111 BOOST_TEST(it
!= s
.end() && (*it
).first
== "k1" && (*it
).second
== "v1");
112 BOOST_TEST(++it
!= s
.end() && (*it
).first
== "k2" && (*it
).second
== "v2");
116 typedef std::map
<std::string
, std::string
> map_type
;
118 BOOST_TEST(test_attr("k1=v1&k2=v2",
119 (*(char_
- '=') >> '=' >> *(char_
- '&')) % '&', m
));
121 map_type::const_iterator it
= m
.begin();
122 BOOST_TEST(m
.size() == 2);
123 BOOST_TEST(it
!= m
.end() && (*it
).first
== "k1" && (*it
).second
== "v1");
124 BOOST_TEST(++it
!= m
.end() && (*it
).first
== "k2" && (*it
).second
== "v2");
128 namespace phx
= boost::phoenix
;
129 using boost::phoenix::begin
;
130 using boost::phoenix::end
;
131 using boost::phoenix::construct
;
132 using boost::spirit::qi::_1
;
135 BOOST_TEST(test("a,b,c,d,e,f,g,h", (char_
% ',')
136 [phx::ref(s
) = construct
<std::string
>(begin(_1
), end(_1
))]));
139 return boost::report_errors();