]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/qi/char1.cpp
c34bb7a517083be27422bc947d292b8dd55bf3e8
1 /*=============================================================================
2 Copyright (c) 2001-2011 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/spirit/include/qi_char.hpp>
10 #include <boost/spirit/include/qi_action.hpp>
11 #include <boost/phoenix/core.hpp>
12 #include <boost/phoenix/operator.hpp>
20 using spirit_test::test
;
21 using spirit_test::test_attr
;
22 using spirit_test::print_info
;
25 using namespace boost::spirit::ascii
;
27 BOOST_TEST(test("x", 'x'));
28 BOOST_TEST(test(L
"x", L
'x'));
29 BOOST_TEST(!test("y", 'x'));
30 BOOST_TEST(!test(L
"y", L
'x'));
32 BOOST_TEST(test("x", char_
));
33 BOOST_TEST(test("x", char_('x')));
34 BOOST_TEST(!test("x", char_('y')));
35 BOOST_TEST(test("x", char_('a', 'z')));
36 BOOST_TEST(!test("x", char_('0', '9')));
38 BOOST_TEST(test("0", char_('0', '9')));
39 BOOST_TEST(test("9", char_('0', '9')));
40 BOOST_TEST(!test("0", ~char_('0', '9')));
41 BOOST_TEST(!test("9", ~char_('0', '9')));
43 BOOST_TEST(!test("x", ~char_
));
44 BOOST_TEST(!test("x", ~char_('x')));
45 BOOST_TEST(test(" ", ~char_('x')));
46 BOOST_TEST(test("X", ~char_('x')));
47 BOOST_TEST(!test("x", ~char_('b', 'y')));
48 BOOST_TEST(test("a", ~char_('b', 'y')));
49 BOOST_TEST(test("z", ~char_('b', 'y')));
51 BOOST_TEST(test("x", ~~char_
));
52 BOOST_TEST(test("x", ~~char_('x')));
53 BOOST_TEST(!test(" ", ~~char_('x')));
54 BOOST_TEST(!test("X", ~~char_('x')));
55 BOOST_TEST(test("x", ~~char_('b', 'y')));
56 BOOST_TEST(!test("a", ~~char_('b', 'y')));
57 BOOST_TEST(!test("z", ~~char_('b', 'y')));
61 using namespace boost::spirit::ascii
;
63 BOOST_TEST(test(" x", 'x', space
));
64 BOOST_TEST(test(L
" x", L
'x', space
));
66 BOOST_TEST(test(" x", char_
, space
));
67 BOOST_TEST(test(" x", char_('x'), space
));
68 BOOST_TEST(!test(" x", char_('y'), space
));
69 BOOST_TEST(test(" x", char_('a', 'z'), space
));
70 BOOST_TEST(!test(" x", char_('0', '9'), space
));
74 using namespace boost::spirit::standard_wide
;
76 BOOST_TEST(test(L
"x", char_
));
77 BOOST_TEST(test(L
"x", char_(L
'x')));
78 BOOST_TEST(!test(L
"x", char_(L
'y')));
79 BOOST_TEST(test(L
"x", char_(L
'a', L
'z')));
80 BOOST_TEST(!test(L
"x", char_(L
'0', L
'9')));
82 BOOST_TEST(!test(L
"x", ~char_
));
83 BOOST_TEST(!test(L
"x", ~char_(L
'x')));
84 BOOST_TEST(test(L
" ", ~char_(L
'x')));
85 BOOST_TEST(test(L
"X", ~char_(L
'x')));
86 BOOST_TEST(!test(L
"x", ~char_(L
'b', L
'y')));
87 BOOST_TEST(test(L
"a", ~char_(L
'b', L
'y')));
88 BOOST_TEST(test(L
"z", ~char_(L
'b', L
'y')));
90 BOOST_TEST(test(L
"x", ~~char_
));
91 BOOST_TEST(test(L
"x", ~~char_(L
'x')));
92 BOOST_TEST(!test(L
" ", ~~char_(L
'x')));
93 BOOST_TEST(!test(L
"X", ~~char_(L
'x')));
94 BOOST_TEST(test(L
"x", ~~char_(L
'b', L
'y')));
95 BOOST_TEST(!test(L
"a", ~~char_(L
'b', L
'y')));
96 BOOST_TEST(!test(L
"z", ~~char_(L
'b', L
'y')));
100 { // single char strings!
101 namespace ascii
= boost::spirit::ascii
;
102 namespace wide
= boost::spirit::standard_wide
;
104 BOOST_TEST(test("x", "x"));
105 BOOST_TEST(test(L
"x", L
"x"));
106 BOOST_TEST(test("x", ascii::char_("x")));
107 BOOST_TEST(test(L
"x", wide::char_(L
"x")));
109 BOOST_TEST(test("x", ascii::char_("a", "z")));
110 BOOST_TEST(test(L
"x", wide::char_(L
"a", L
"z")));
115 namespace ascii
= boost::spirit::ascii
;
116 namespace wide
= boost::spirit::standard_wide
;
118 BOOST_TEST(test("x", ascii::char_("a-z")));
119 BOOST_TEST(!test("1", ascii::char_("a-z")));
120 BOOST_TEST(test("1", ascii::char_("a-z0-9")));
122 BOOST_TEST(test("x", wide::char_(L
"a-z")));
123 BOOST_TEST(!test("1", wide::char_(L
"a-z")));
124 BOOST_TEST(test("1", wide::char_(L
"a-z0-9")));
126 std::string set
= "a-z0-9";
127 BOOST_TEST(test("x", ascii::char_(set
)));
129 #ifdef SPIRIT_NO_COMPILE_CHECK
130 test("", ascii::char_(L
"a-z0-9"));
136 using namespace boost::spirit::ascii
;
138 using boost::phoenix::val
;
139 using boost::phoenix::ref
;
140 using boost::spirit::_1
;
142 BOOST_TEST((test("x", char_(val('x')))));
143 BOOST_TEST((test("h", char_(val('a'), val('n')))));
144 BOOST_TEST(test("0", char_(val("a-z0-9"))));
146 char ch
; // make sure lazy chars have an attribute
147 BOOST_TEST(test("x", char_(val('x'))[ref(ch
) = _1
]));
148 BOOST_TEST(ch
== 'x');
153 using boost::spirit::qi::what
;
154 using boost::spirit::ascii::char_
;
155 using boost::spirit::ascii::alpha
;
157 print_info(what('x'));
158 print_info(what(char_('a','z')));
159 print_info(what(alpha
));
163 namespace ascii
= boost::spirit::qi::ascii
;
164 char const* input
= "\x80";
166 // ascii > 7 bits (this should fail, not assert!)
167 BOOST_TEST(!test(input
, ascii::char_
));
168 BOOST_TEST(!test(input
, ascii::char_('a')));
169 BOOST_TEST(!test(input
, ascii::alnum
));
170 BOOST_TEST(!test(input
, ascii::char_("a-z")));
171 BOOST_TEST(!test(input
, ascii::char_('0', '9')));
174 return boost::report_errors();