]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2001-2011 Joel de Guzman | |
3 | Copyright (c) 2001-2011 Hartmut Kaiser | |
4 | ||
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 | =============================================================================*/ | |
7c673cae | 8 | #include <boost/spirit/include/qi_char.hpp> |
1e59de90 | 9 | |
7c673cae | 10 | #include <boost/spirit/include/qi_action.hpp> |
1e59de90 TL |
11 | #include <boost/phoenix/core.hpp> |
12 | #include <boost/phoenix/operator.hpp> | |
7c673cae FG |
13 | |
14 | #include <iostream> | |
15 | #include "test.hpp" | |
16 | ||
17 | int | |
18 | main() | |
19 | { | |
20 | using spirit_test::test; | |
21 | using spirit_test::test_attr; | |
22 | using spirit_test::print_info; | |
23 | ||
24 | { | |
25 | using namespace boost::spirit::ascii; | |
26 | ||
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')); | |
31 | ||
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'))); | |
37 | ||
11fdf7f2 TL |
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'))); | |
42 | ||
7c673cae FG |
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'))); | |
50 | ||
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'))); | |
58 | } | |
59 | ||
60 | { | |
61 | using namespace boost::spirit::ascii; | |
62 | ||
63 | BOOST_TEST(test(" x", 'x', space)); | |
64 | BOOST_TEST(test(L" x", L'x', space)); | |
65 | ||
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)); | |
71 | } | |
72 | ||
73 | { | |
74 | using namespace boost::spirit::standard_wide; | |
75 | ||
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'))); | |
81 | ||
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'))); | |
89 | ||
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'))); | |
97 | } | |
98 | ||
99 | ||
100 | { // single char strings! | |
101 | namespace ascii = boost::spirit::ascii; | |
102 | namespace wide = boost::spirit::standard_wide; | |
103 | ||
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"))); | |
108 | ||
109 | BOOST_TEST(test("x", ascii::char_("a", "z"))); | |
11fdf7f2 | 110 | BOOST_TEST(test(L"x", wide::char_(L"a", L"z"))); |
7c673cae FG |
111 | } |
112 | ||
113 | { | |
114 | // chsets | |
115 | namespace ascii = boost::spirit::ascii; | |
116 | namespace wide = boost::spirit::standard_wide; | |
117 | ||
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"))); | |
121 | ||
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"))); | |
125 | ||
126 | std::string set = "a-z0-9"; | |
127 | BOOST_TEST(test("x", ascii::char_(set))); | |
128 | ||
129 | #ifdef SPIRIT_NO_COMPILE_CHECK | |
130 | test("", ascii::char_(L"a-z0-9")); | |
131 | #endif | |
132 | } | |
133 | ||
134 | { // lazy chars | |
135 | ||
136 | using namespace boost::spirit::ascii; | |
137 | ||
138 | using boost::phoenix::val; | |
139 | using boost::phoenix::ref; | |
140 | using boost::spirit::_1; | |
141 | ||
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")))); | |
145 | ||
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'); | |
149 | } | |
150 | ||
151 | { // testing "what" | |
152 | ||
153 | using boost::spirit::qi::what; | |
154 | using boost::spirit::ascii::char_; | |
155 | using boost::spirit::ascii::alpha; | |
156 | ||
157 | print_info(what('x')); | |
158 | print_info(what(char_('a','z'))); | |
159 | print_info(what(alpha)); | |
160 | } | |
161 | ||
92f5a8d4 TL |
162 | { |
163 | namespace ascii = boost::spirit::qi::ascii; | |
164 | char const* input = "\x80"; | |
165 | ||
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'))); | |
172 | } | |
173 | ||
7c673cae FG |
174 | return boost::report_errors(); |
175 | } |