• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2001-2011 Joel de Guzman
3     http://spirit.sourceforge.net/
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 =============================================================================*/
8 
9 #include <boost/detail/lightweight_test.hpp>
10 #include <boost/spirit/include/qi_char.hpp>
11 #include <boost/spirit/include/qi_string.hpp>
12 #include <boost/spirit/include/qi_directive.hpp>
13 #include <boost/spirit/include/qi_action.hpp>
14 #include <boost/spirit/include/phoenix_core.hpp>
15 #include <boost/spirit/include/phoenix_operator.hpp>
16 
17 #include <iostream>
18 #include "test.hpp"
19 
20 int
main()21 main()
22 {
23     using spirit_test::test;
24     using spirit_test::test_attr;
25     using boost::spirit::qi::lit;
26 
27     {
28         using namespace boost::spirit::ascii;
29         BOOST_TEST(test("x", no_case[char_]));
30         BOOST_TEST(test("X", no_case[char_('x')]));
31         BOOST_TEST(test("X", no_case[char_('X')]));
32         BOOST_TEST(test("x", no_case[char_('X')]));
33         BOOST_TEST(test("x", no_case[char_('x')]));
34         BOOST_TEST(!test("z", no_case[char_('X')]));
35         BOOST_TEST(!test("z", no_case[char_('x')]));
36         BOOST_TEST(test("x", no_case[char_('a', 'z')]));
37         BOOST_TEST(test("X", no_case[char_('a', 'z')]));
38         BOOST_TEST(!test("a", no_case[char_('b', 'z')]));
39         BOOST_TEST(!test("z", no_case[char_('a', 'y')]));
40     }
41 
42     {
43         using namespace boost::spirit::ascii;
44         BOOST_TEST(test("X", no_case['x']));
45         BOOST_TEST(test("X", no_case['X']));
46         BOOST_TEST(test("x", no_case['X']));
47         BOOST_TEST(test("x", no_case['x']));
48         BOOST_TEST(!test("z", no_case['X']));
49         BOOST_TEST(!test("z", no_case['x']));
50     }
51 
52     {
53         using namespace boost::spirit::iso8859_1;
54         BOOST_TEST(test("X", no_case[char_("a-z")]));
55         BOOST_TEST(!test("1", no_case[char_("a-z")]));
56     }
57 
58     { // test extended ASCII characters
59         using namespace boost::spirit::iso8859_1;
60         BOOST_TEST(test("\xC1", no_case[char_('\xE1')]));
61 
62         BOOST_TEST(test("\xC9", no_case[char_("\xE5-\xEF")]));
63         BOOST_TEST(!test("\xFF", no_case[char_("\xE5-\xEF")]));
64 
65         BOOST_TEST(test("\xC1\xE1", no_case[lit("\xE1\xC1")]));
66         BOOST_TEST(test("\xE1\xE1", no_case[no_case[lit("\xE1\xC1")]]));
67     }
68 
69     {
70         using namespace boost::spirit::ascii;
71         BOOST_TEST(test("Bochi Bochi", no_case[lit("bochi bochi")]));
72         BOOST_TEST(test("BOCHI BOCHI", no_case[lit("bochi bochi")]));
73         BOOST_TEST(!test("Vavoo", no_case[lit("bochi bochi")]));
74     }
75 
76     {
77         // should work!
78         using namespace boost::spirit::ascii;
79         BOOST_TEST(test("x", no_case[no_case[char_]]));
80         BOOST_TEST(test("x", no_case[no_case[char_('x')]]));
81         BOOST_TEST(test("yabadabadoo", no_case[no_case[lit("Yabadabadoo")]]));
82     }
83 
84     {
85         using namespace boost::spirit::ascii;
86         BOOST_TEST(test("X", no_case[alnum]));
87         BOOST_TEST(test("6", no_case[alnum]));
88         BOOST_TEST(!test(":", no_case[alnum]));
89 
90         BOOST_TEST(test("X", no_case[lower]));
91         BOOST_TEST(test("x", no_case[lower]));
92         BOOST_TEST(test("X", no_case[upper]));
93         BOOST_TEST(test("x", no_case[upper]));
94         BOOST_TEST(!test(":", no_case[lower]));
95         BOOST_TEST(!test(":", no_case[upper]));
96     }
97 
98     {
99         using namespace boost::spirit::iso8859_1;
100         BOOST_TEST(test("X", no_case[alnum]));
101         BOOST_TEST(test("6", no_case[alnum]));
102         BOOST_TEST(!test(":", no_case[alnum]));
103 
104         BOOST_TEST(test("X", no_case[lower]));
105         BOOST_TEST(test("x", no_case[lower]));
106         BOOST_TEST(test("X", no_case[upper]));
107         BOOST_TEST(test("x", no_case[upper]));
108         BOOST_TEST(!test(":", no_case[lower]));
109         BOOST_TEST(!test(":", no_case[upper]));
110     }
111 
112     {
113         using namespace boost::spirit::standard;
114         BOOST_TEST(test("X", no_case[alnum]));
115         BOOST_TEST(test("6", no_case[alnum]));
116         BOOST_TEST(!test(":", no_case[alnum]));
117 
118         BOOST_TEST(test("X", no_case[lower]));
119         BOOST_TEST(test("x", no_case[lower]));
120         BOOST_TEST(test("X", no_case[upper]));
121         BOOST_TEST(test("x", no_case[upper]));
122         BOOST_TEST(!test(":", no_case[lower]));
123         BOOST_TEST(!test(":", no_case[upper]));
124     }
125 
126     {
127         // chsets
128         namespace standard = boost::spirit::standard;
129         namespace standard_wide = boost::spirit::standard_wide;
130 
131         BOOST_TEST(test("x", standard::no_case[standard::char_("a-z")]));
132         BOOST_TEST(test("X", standard::no_case[standard::char_("a-z")]));
133         BOOST_TEST(test(L"X", standard_wide::no_case[standard_wide::char_(L"a-z")]));
134         BOOST_TEST(test(L"X", standard_wide::no_case[standard_wide::char_(L"X")]));
135     }
136 
137     {
138         using namespace boost::spirit::standard;
139         std::string s("bochi bochi");
140         BOOST_TEST(test("Bochi Bochi", no_case[lit(s.c_str())]));
141         BOOST_TEST(test("Bochi Bochi", no_case[lit(s)]));
142         BOOST_TEST(test("Bochi Bochi", no_case[s.c_str()]));
143         BOOST_TEST(test("Bochi Bochi", no_case[s]));
144     }
145 
146     {   // lazy no_case chars
147 
148         using namespace boost::spirit::ascii;
149 
150         using boost::phoenix::val;
151         using boost::phoenix::ref;
152         using boost::spirit::_1;
153 
154         BOOST_TEST((test("X", no_case[val('x')])));
155         BOOST_TEST((test("h", no_case[char_(val('a'), val('n'))])));
156         BOOST_TEST(test("0", no_case[char_(val("a-z0-9"))]));
157 
158         char ch; // make sure lazy chars have an attribute
159         BOOST_TEST(test("x", no_case[char_(val('x'))][ref(ch) = _1]));
160         BOOST_TEST(ch == 'x');
161     }
162 
163     {   // lazy no_case lits
164 
165         using namespace boost::spirit::ascii;
166         using boost::phoenix::val;
167 
168         BOOST_TEST(test("Bochi Bochi", no_case[val("bochi bochi")]));
169         BOOST_TEST(test("BOCHI BOCHI", no_case[val("bochi bochi")]));
170         BOOST_TEST(!test("Vavoo", no_case[val("bochi bochi")]));
171     }
172 
173     return boost::report_errors();
174 }
175