1 /*=============================================================================
2 Copyright (c) 2003 Vaclav Vesely
3 http://spirit.sourceforge.net/
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>
12 #include <boost/core/lightweight_test.hpp>
14 using namespace boost
;
15 using namespace BOOST_SPIRIT_CLASSIC_NS
;
18 scanner
<char const*, scanner_policies
<skipper_iteration_policy
<> > >
25 void distinct_parser_test()
29 distinct_parser
<> distinct_p
;
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
);
36 // distinct_parser(CharT const* letters)
38 distinct_parser
<> distinct_p("0-9a-zA-Z_");
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
);
47 // distinct_parser(parser<TailT> const & tail_)
55 negated_char_parser
<chlit
<> >
59 distinct_p(alnum_p
| ('-' >> ~ch_p('-')));
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
);
69 void distinct_directive_test()
71 // distinct_directive()
73 distinct_directive
<> distinct_d
;
75 // operator[](CharT const* str) const
77 rule_t r
= distinct_d
["keyword"] >> !ch_p('-') >> int_p
;
78 BOOST_TEST(parse("keyword123", r
, space_p
).full
);
81 // operator[](parser<ParserT> const &subject) const
83 rule_t r
= distinct_d
[str_p("keyword")] >> !ch_p('-') >> int_p
;
84 BOOST_TEST(parse("keyword123", r
, space_p
).full
);
88 // distinct_directive(CharT const* letters)
90 distinct_directive
<> distinct_d("0-9a-zA-Z_");
92 // operator[](CharT const* str) const
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
);
100 // operator[](parser<ParserT> const &subject) const
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
);
109 // distinct_directive(parser<TailT> const & tail_)
117 negated_char_parser
<chlit
<> >
121 distinct_d(alnum_p
| ('-' >> ~ch_p('-')));
123 // operator[](CharT const* str) const
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
);
131 // operator[](parser<ParserT> const &subject) const
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
);
141 void dynamic_distinct_parser_test()
143 // dynamic_distinct_parser()
145 dynamic_distinct_parser
<scanner_t
> distinct_p
;
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
);
152 // dynamic_distinct_parser(CharT const* letters)
154 dynamic_distinct_parser
<scanner_t
> distinct_p("0-9a-zA-Z_");
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
);
163 // dynamic_distinct_parser(parser<TailT> const & tail_)
165 dynamic_distinct_parser
<scanner_t
>
166 distinct_p(alnum_p
| ('-' >> ~ch_p('-')));
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
);
176 void dynamic_distinct_directive_test()
178 // dynamic_distinct_directive()
180 dynamic_distinct_directive
<scanner_t
> distinct_d
;
182 // operator[](CharT const* str) const
184 rule_t r
= distinct_d
["keyword"] >> !ch_p('-') >> int_p
;
185 BOOST_TEST(parse("keyword123", r
, space_p
).full
);
188 // operator[](parser<ParserT> const &subject) const
190 rule_t r
= distinct_d
[str_p("keyword")] >> !ch_p('-') >> int_p
;
191 BOOST_TEST(parse("keyword123", r
, space_p
).full
);
195 // dynamic_distinct_directive(CharT const* letters)
197 dynamic_distinct_directive
<scanner_t
> distinct_d("0-9a-zA-Z_");
199 // operator[](CharT const* str) const
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
);
207 // operator[](parser<ParserT> const &subject) const
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
);
216 // dynamic_distinct_directive(parser<TailT> const & tail_)
218 dynamic_distinct_directive
<scanner_t
>
219 distinct_d(alnum_p
| ('-' >> ~ch_p('-')));
221 // operator[](CharT const* str) const
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
);
229 // operator[](parser<ParserT> const &subject) const
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
);
242 distinct_parser_test();
243 distinct_directive_test();
244 dynamic_distinct_parser_test();
245 dynamic_distinct_directive_test();
247 return boost::report_errors();