]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/classic/test/distinct_tests.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / spirit / classic / test / distinct_tests.cpp
1 /*=============================================================================
2 Copyright (c) 2003 Vaclav Vesely
3 http://spirit.sourceforge.net/
4
5 Use, modification and distribution is subject to the Boost Software
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9 #include <boost/spirit/include/classic_core.hpp>
10 #include <boost/spirit/include/classic_distinct.hpp>
11
12 #include <boost/core/lightweight_test.hpp>
13
14 using namespace boost;
15 using namespace BOOST_SPIRIT_CLASSIC_NS;
16
17 typedef
18 scanner<char const*, scanner_policies<skipper_iteration_policy<> > >
19 scanner_t;
20
21 typedef
22 rule<scanner_t>
23 rule_t;
24
25 void distinct_parser_test()
26 {
27 // distinct_parser()
28 {
29 distinct_parser<> distinct_p;
30
31 // operator()(CharT const* str) const
32 rule_t r = distinct_p("keyword") >> !ch_p('-') >> int_p;
33 BOOST_TEST(parse("keyword123", r, space_p).full);
34 }
35
36 // distinct_parser(CharT const* letters)
37 {
38 distinct_parser<> distinct_p("0-9a-zA-Z_");
39
40 // operator()(CharT const* str) const
41 rule_t r = distinct_p("keyword") >> !ch_p('-') >> int_p;
42 BOOST_TEST(parse("keyword 123", r, space_p).full);
43 BOOST_TEST(parse("keyword-123", r, space_p).full);
44 BOOST_TEST(!parse("keyword123", r, space_p).hit);
45 }
46
47 // distinct_parser(parser<TailT> const & tail_)
48 {
49 distinct_parser<
50 char,
51 alternative<
52 alnum_parser,
53 sequence<
54 chlit<>,
55 negated_char_parser<chlit<> >
56 >
57 >
58 >
59 distinct_p(alnum_p | ('-' >> ~ch_p('-')));
60
61 // operator()(CharT const* str) const
62 rule_t r = distinct_p("keyword") >> !str_p("--") >> int_p;
63 BOOST_TEST(parse("keyword 123", r, space_p).full);
64 BOOST_TEST(parse("keyword--123", r, space_p).full);
65 BOOST_TEST(!parse("keyword-123", r, space_p).hit);
66 }
67 }
68
69 void distinct_directive_test()
70 {
71 // distinct_directive()
72 {
73 distinct_directive<> distinct_d;
74
75 // operator[](CharT const* str) const
76 {
77 rule_t r = distinct_d["keyword"] >> !ch_p('-') >> int_p;
78 BOOST_TEST(parse("keyword123", r, space_p).full);
79 }
80
81 // operator[](parser<ParserT> const &subject) const
82 {
83 rule_t r = distinct_d[str_p("keyword")] >> !ch_p('-') >> int_p;
84 BOOST_TEST(parse("keyword123", r, space_p).full);
85 }
86 }
87
88 // distinct_directive(CharT const* letters)
89 {
90 distinct_directive<> distinct_d("0-9a-zA-Z_");
91
92 // operator[](CharT const* str) const
93 {
94 rule_t r = distinct_d["keyword"] >> !ch_p('-') >> int_p;
95 BOOST_TEST(parse("keyword 123", r, space_p).full);
96 BOOST_TEST(parse("keyword-123", r, space_p).full);
97 BOOST_TEST(!parse("keyword123", r, space_p).hit);
98 }
99
100 // operator[](parser<ParserT> const &subject) const
101 {
102 rule_t r = distinct_d[str_p("keyword")] >> !ch_p('-') >> int_p;
103 BOOST_TEST(parse("keyword 123", r, space_p).full);
104 BOOST_TEST(parse("keyword-123", r, space_p).full);
105 BOOST_TEST(!parse("keyword123", r, space_p).hit);
106 }
107 }
108
109 // distinct_directive(parser<TailT> const & tail_)
110 {
111 distinct_directive<
112 char,
113 alternative<
114 alnum_parser,
115 sequence<
116 chlit<>,
117 negated_char_parser<chlit<> >
118 >
119 >
120 >
121 distinct_d(alnum_p | ('-' >> ~ch_p('-')));
122
123 // operator[](CharT const* str) const
124 {
125 rule_t r = distinct_d["keyword"] >> !str_p("--") >> int_p;
126 BOOST_TEST(parse("keyword 123", r, space_p).full);
127 BOOST_TEST(parse("keyword--123", r, space_p).full);
128 BOOST_TEST(!parse("keyword-123", r, space_p).hit);
129 }
130
131 // operator[](parser<ParserT> const &subject) const
132 {
133 rule_t r = distinct_d[str_p("keyword")] >> !str_p("--") >> int_p;
134 BOOST_TEST(parse("keyword 123", r, space_p).full);
135 BOOST_TEST(parse("keyword--123", r, space_p).full);
136 BOOST_TEST(!parse("keyword-123", r, space_p).hit);
137 }
138 }
139 }
140
141 void dynamic_distinct_parser_test()
142 {
143 // dynamic_distinct_parser()
144 {
145 dynamic_distinct_parser<scanner_t> distinct_p;
146
147 // operator()(CharT const* str) const
148 rule_t r = distinct_p("keyword") >> !ch_p('-') >> int_p;
149 BOOST_TEST(parse("keyword123", r, space_p).full);
150 }
151
152 // dynamic_distinct_parser(CharT const* letters)
153 {
154 dynamic_distinct_parser<scanner_t> distinct_p("0-9a-zA-Z_");
155
156 // operator()(CharT const* str) const
157 rule_t r = distinct_p("keyword") >> !ch_p('-') >> int_p;
158 BOOST_TEST(parse("keyword 123", r, space_p).full);
159 BOOST_TEST(parse("keyword-123", r, space_p).full);
160 BOOST_TEST(!parse("keyword123", r, space_p).hit);
161 }
162
163 // dynamic_distinct_parser(parser<TailT> const & tail_)
164 {
165 dynamic_distinct_parser<scanner_t>
166 distinct_p(alnum_p | ('-' >> ~ch_p('-')));
167
168 // operator()(CharT const* str) const
169 rule_t r = distinct_p("keyword") >> !str_p("--") >> int_p;
170 BOOST_TEST(parse("keyword 123", r, space_p).full);
171 BOOST_TEST(parse("keyword--123", r, space_p).full);
172 BOOST_TEST(!parse("keyword-123", r, space_p).hit);
173 }
174 }
175
176 void dynamic_distinct_directive_test()
177 {
178 // dynamic_distinct_directive()
179 {
180 dynamic_distinct_directive<scanner_t> distinct_d;
181
182 // operator[](CharT const* str) const
183 {
184 rule_t r = distinct_d["keyword"] >> !ch_p('-') >> int_p;
185 BOOST_TEST(parse("keyword123", r, space_p).full);
186 }
187
188 // operator[](parser<ParserT> const &subject) const
189 {
190 rule_t r = distinct_d[str_p("keyword")] >> !ch_p('-') >> int_p;
191 BOOST_TEST(parse("keyword123", r, space_p).full);
192 }
193 }
194
195 // dynamic_distinct_directive(CharT const* letters)
196 {
197 dynamic_distinct_directive<scanner_t> distinct_d("0-9a-zA-Z_");
198
199 // operator[](CharT const* str) const
200 {
201 rule_t r = distinct_d["keyword"] >> !ch_p('-') >> int_p;
202 BOOST_TEST(parse("keyword 123", r, space_p).full);
203 BOOST_TEST(parse("keyword-123", r, space_p).full);
204 BOOST_TEST(!parse("keyword123", r, space_p).hit);
205 }
206
207 // operator[](parser<ParserT> const &subject) const
208 {
209 rule_t r = distinct_d[str_p("keyword")] >> !ch_p('-') >> int_p;
210 BOOST_TEST(parse("keyword 123", r, space_p).full);
211 BOOST_TEST(parse("keyword-123", r, space_p).full);
212 BOOST_TEST(!parse("keyword123", r, space_p).hit);
213 }
214 }
215
216 // dynamic_distinct_directive(parser<TailT> const & tail_)
217 {
218 dynamic_distinct_directive<scanner_t>
219 distinct_d(alnum_p | ('-' >> ~ch_p('-')));
220
221 // operator[](CharT const* str) const
222 {
223 rule_t r = distinct_d["keyword"] >> !str_p("--") >> int_p;
224 BOOST_TEST(parse("keyword 123", r, space_p).full);
225 BOOST_TEST(parse("keyword--123", r, space_p).full);
226 BOOST_TEST(!parse("keyword-123", r, space_p).hit);
227 }
228
229 // operator[](parser<ParserT> const &subject) const
230 {
231 rule_t r = distinct_d[str_p("keyword")] >> !str_p("--") >> int_p;
232 BOOST_TEST(parse("keyword 123", r, space_p).full);
233 BOOST_TEST(parse("keyword--123", r, space_p).full);
234 BOOST_TEST(!parse("keyword-123", r, space_p).hit);
235 }
236 }
237 }
238
239 int
240 main()
241 {
242 distinct_parser_test();
243 distinct_directive_test();
244 dynamic_distinct_parser_test();
245 dynamic_distinct_directive_test();
246
247 return boost::report_errors();
248 }
249