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>
11 #include <boost/detail/lightweight_test.hpp>
13 using namespace boost
;
14 using namespace BOOST_SPIRIT_CLASSIC_NS
;
17 scanner
<char const*, scanner_policies
<skipper_iteration_policy
<> > >
24 void distinct_parser_test()
28 distinct_parser
<> distinct_p
;
30 // operator()(CharT const* str) const
31 rule_t r
= distinct_p("keyword") >> !ch_p('-') >> int_p
;
32 BOOST_TEST(parse("keyword123", r
, space_p
).full
);
35 // distinct_parser(CharT const* letters)
37 distinct_parser
<> distinct_p("0-9a-zA-Z_");
39 // operator()(CharT const* str) const
40 rule_t r
= distinct_p("keyword") >> !ch_p('-') >> int_p
;
41 BOOST_TEST(parse("keyword 123", r
, space_p
).full
);
42 BOOST_TEST(parse("keyword-123", r
, space_p
).full
);
43 BOOST_TEST(!parse("keyword123", r
, space_p
).hit
);
46 // distinct_parser(parser<TailT> const & tail_)
54 negated_char_parser
<chlit
<> >
58 distinct_p(alnum_p
| ('-' >> ~ch_p('-')));
60 // operator()(CharT const* str) const
61 rule_t r
= distinct_p("keyword") >> !str_p("--") >> int_p
;
62 BOOST_TEST(parse("keyword 123", r
, space_p
).full
);
63 BOOST_TEST(parse("keyword--123", r
, space_p
).full
);
64 BOOST_TEST(!parse("keyword-123", r
, space_p
).hit
);
68 void distinct_directive_test()
70 // distinct_directive()
72 distinct_directive
<> distinct_d
;
74 // operator[](CharT const* str) const
76 rule_t r
= distinct_d
["keyword"] >> !ch_p('-') >> int_p
;
77 BOOST_TEST(parse("keyword123", r
, space_p
).full
);
80 // operator[](parser<ParserT> const &subject) const
82 rule_t r
= distinct_d
[str_p("keyword")] >> !ch_p('-') >> int_p
;
83 BOOST_TEST(parse("keyword123", r
, space_p
).full
);
87 // distinct_directive(CharT const* letters)
89 distinct_directive
<> distinct_d("0-9a-zA-Z_");
91 // operator[](CharT const* str) const
93 rule_t r
= distinct_d
["keyword"] >> !ch_p('-') >> int_p
;
94 BOOST_TEST(parse("keyword 123", r
, space_p
).full
);
95 BOOST_TEST(parse("keyword-123", r
, space_p
).full
);
96 BOOST_TEST(!parse("keyword123", r
, space_p
).hit
);
99 // operator[](parser<ParserT> const &subject) const
101 rule_t r
= distinct_d
[str_p("keyword")] >> !ch_p('-') >> int_p
;
102 BOOST_TEST(parse("keyword 123", r
, space_p
).full
);
103 BOOST_TEST(parse("keyword-123", r
, space_p
).full
);
104 BOOST_TEST(!parse("keyword123", r
, space_p
).hit
);
108 // distinct_directive(parser<TailT> const & tail_)
116 negated_char_parser
<chlit
<> >
120 distinct_d(alnum_p
| ('-' >> ~ch_p('-')));
122 // operator[](CharT const* str) const
124 rule_t r
= distinct_d
["keyword"] >> !str_p("--") >> int_p
;
125 BOOST_TEST(parse("keyword 123", r
, space_p
).full
);
126 BOOST_TEST(parse("keyword--123", r
, space_p
).full
);
127 BOOST_TEST(!parse("keyword-123", r
, space_p
).hit
);
130 // operator[](parser<ParserT> const &subject) const
132 rule_t r
= distinct_d
[str_p("keyword")] >> !str_p("--") >> int_p
;
133 BOOST_TEST(parse("keyword 123", r
, space_p
).full
);
134 BOOST_TEST(parse("keyword--123", r
, space_p
).full
);
135 BOOST_TEST(!parse("keyword-123", r
, space_p
).hit
);
140 void dynamic_distinct_parser_test()
142 // dynamic_distinct_parser()
144 dynamic_distinct_parser
<scanner_t
> distinct_p
;
146 // operator()(CharT const* str) const
147 rule_t r
= distinct_p("keyword") >> !ch_p('-') >> int_p
;
148 BOOST_TEST(parse("keyword123", r
, space_p
).full
);
151 // dynamic_distinct_parser(CharT const* letters)
153 dynamic_distinct_parser
<scanner_t
> distinct_p("0-9a-zA-Z_");
155 // operator()(CharT const* str) const
156 rule_t r
= distinct_p("keyword") >> !ch_p('-') >> int_p
;
157 BOOST_TEST(parse("keyword 123", r
, space_p
).full
);
158 BOOST_TEST(parse("keyword-123", r
, space_p
).full
);
159 BOOST_TEST(!parse("keyword123", r
, space_p
).hit
);
162 // dynamic_distinct_parser(parser<TailT> const & tail_)
164 dynamic_distinct_parser
<scanner_t
>
165 distinct_p(alnum_p
| ('-' >> ~ch_p('-')));
167 // operator()(CharT const* str) const
168 rule_t r
= distinct_p("keyword") >> !str_p("--") >> int_p
;
169 BOOST_TEST(parse("keyword 123", r
, space_p
).full
);
170 BOOST_TEST(parse("keyword--123", r
, space_p
).full
);
171 BOOST_TEST(!parse("keyword-123", r
, space_p
).hit
);
175 void dynamic_distinct_directive_test()
177 // dynamic_distinct_directive()
179 dynamic_distinct_directive
<scanner_t
> distinct_d
;
181 // operator[](CharT const* str) const
183 rule_t r
= distinct_d
["keyword"] >> !ch_p('-') >> int_p
;
184 BOOST_TEST(parse("keyword123", r
, space_p
).full
);
187 // operator[](parser<ParserT> const &subject) const
189 rule_t r
= distinct_d
[str_p("keyword")] >> !ch_p('-') >> int_p
;
190 BOOST_TEST(parse("keyword123", r
, space_p
).full
);
194 // dynamic_distinct_directive(CharT const* letters)
196 dynamic_distinct_directive
<scanner_t
> distinct_d("0-9a-zA-Z_");
198 // operator[](CharT const* str) const
200 rule_t r
= distinct_d
["keyword"] >> !ch_p('-') >> int_p
;
201 BOOST_TEST(parse("keyword 123", r
, space_p
).full
);
202 BOOST_TEST(parse("keyword-123", r
, space_p
).full
);
203 BOOST_TEST(!parse("keyword123", r
, space_p
).hit
);
206 // operator[](parser<ParserT> const &subject) const
208 rule_t r
= distinct_d
[str_p("keyword")] >> !ch_p('-') >> int_p
;
209 BOOST_TEST(parse("keyword 123", r
, space_p
).full
);
210 BOOST_TEST(parse("keyword-123", r
, space_p
).full
);
211 BOOST_TEST(!parse("keyword123", r
, space_p
).hit
);
215 // dynamic_distinct_directive(parser<TailT> const & tail_)
217 dynamic_distinct_directive
<scanner_t
>
218 distinct_d(alnum_p
| ('-' >> ~ch_p('-')));
220 // operator[](CharT const* str) const
222 rule_t r
= distinct_d
["keyword"] >> !str_p("--") >> int_p
;
223 BOOST_TEST(parse("keyword 123", r
, space_p
).full
);
224 BOOST_TEST(parse("keyword--123", r
, space_p
).full
);
225 BOOST_TEST(!parse("keyword-123", r
, space_p
).hit
);
228 // operator[](parser<ParserT> const &subject) const
230 rule_t r
= distinct_d
[str_p("keyword")] >> !str_p("--") >> int_p
;
231 BOOST_TEST(parse("keyword 123", r
, space_p
).full
);
232 BOOST_TEST(parse("keyword--123", r
, space_p
).full
);
233 BOOST_TEST(!parse("keyword-123", r
, space_p
).hit
);
241 distinct_parser_test();
242 distinct_directive_test();
243 dynamic_distinct_parser_test();
244 dynamic_distinct_directive_test();
246 return boost::report_errors();