diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/spirit/classic/test/distinct_tests.cpp | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/spirit/classic/test/distinct_tests.cpp')
-rw-r--r-- | src/boost/libs/spirit/classic/test/distinct_tests.cpp | 248 |
1 files changed, 248 insertions, 0 deletions
diff --git a/src/boost/libs/spirit/classic/test/distinct_tests.cpp b/src/boost/libs/spirit/classic/test/distinct_tests.cpp new file mode 100644 index 00000000..0ef66b0a --- /dev/null +++ b/src/boost/libs/spirit/classic/test/distinct_tests.cpp @@ -0,0 +1,248 @@ +/*============================================================================= + Copyright (c) 2003 Vaclav Vesely + http://spirit.sourceforge.net/ + + Use, modification and distribution is subject to the Boost Software + License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#include <boost/spirit/include/classic_core.hpp> +#include <boost/spirit/include/classic_distinct.hpp> +#include <boost/detail/lightweight_test.hpp> + +using namespace boost; +using namespace BOOST_SPIRIT_CLASSIC_NS; + +typedef + scanner<char const*, scanner_policies<skipper_iteration_policy<> > > + scanner_t; + +typedef + rule<scanner_t> + rule_t; + +void distinct_parser_test() +{ + // distinct_parser() + { + distinct_parser<> distinct_p; + + // operator()(CharT const* str) const + rule_t r = distinct_p("keyword") >> !ch_p('-') >> int_p; + BOOST_TEST(parse("keyword123", r, space_p).full); + } + + // distinct_parser(CharT const* letters) + { + distinct_parser<> distinct_p("0-9a-zA-Z_"); + + // operator()(CharT const* str) const + rule_t r = distinct_p("keyword") >> !ch_p('-') >> int_p; + BOOST_TEST(parse("keyword 123", r, space_p).full); + BOOST_TEST(parse("keyword-123", r, space_p).full); + BOOST_TEST(!parse("keyword123", r, space_p).hit); + } + + // distinct_parser(parser<TailT> const & tail_) + { + distinct_parser< + char, + alternative< + alnum_parser, + sequence< + chlit<>, + negated_char_parser<chlit<> > + > + > + > + distinct_p(alnum_p | ('-' >> ~ch_p('-'))); + + // operator()(CharT const* str) const + rule_t r = distinct_p("keyword") >> !str_p("--") >> int_p; + BOOST_TEST(parse("keyword 123", r, space_p).full); + BOOST_TEST(parse("keyword--123", r, space_p).full); + BOOST_TEST(!parse("keyword-123", r, space_p).hit); + } +} + +void distinct_directive_test() +{ + // distinct_directive() + { + distinct_directive<> distinct_d; + + // operator[](CharT const* str) const + { + rule_t r = distinct_d["keyword"] >> !ch_p('-') >> int_p; + BOOST_TEST(parse("keyword123", r, space_p).full); + } + + // operator[](parser<ParserT> const &subject) const + { + rule_t r = distinct_d[str_p("keyword")] >> !ch_p('-') >> int_p; + BOOST_TEST(parse("keyword123", r, space_p).full); + } + } + + // distinct_directive(CharT const* letters) + { + distinct_directive<> distinct_d("0-9a-zA-Z_"); + + // operator[](CharT const* str) const + { + rule_t r = distinct_d["keyword"] >> !ch_p('-') >> int_p; + BOOST_TEST(parse("keyword 123", r, space_p).full); + BOOST_TEST(parse("keyword-123", r, space_p).full); + BOOST_TEST(!parse("keyword123", r, space_p).hit); + } + + // operator[](parser<ParserT> const &subject) const + { + rule_t r = distinct_d[str_p("keyword")] >> !ch_p('-') >> int_p; + BOOST_TEST(parse("keyword 123", r, space_p).full); + BOOST_TEST(parse("keyword-123", r, space_p).full); + BOOST_TEST(!parse("keyword123", r, space_p).hit); + } + } + + // distinct_directive(parser<TailT> const & tail_) + { + distinct_directive< + char, + alternative< + alnum_parser, + sequence< + chlit<>, + negated_char_parser<chlit<> > + > + > + > + distinct_d(alnum_p | ('-' >> ~ch_p('-'))); + + // operator[](CharT const* str) const + { + rule_t r = distinct_d["keyword"] >> !str_p("--") >> int_p; + BOOST_TEST(parse("keyword 123", r, space_p).full); + BOOST_TEST(parse("keyword--123", r, space_p).full); + BOOST_TEST(!parse("keyword-123", r, space_p).hit); + } + + // operator[](parser<ParserT> const &subject) const + { + rule_t r = distinct_d[str_p("keyword")] >> !str_p("--") >> int_p; + BOOST_TEST(parse("keyword 123", r, space_p).full); + BOOST_TEST(parse("keyword--123", r, space_p).full); + BOOST_TEST(!parse("keyword-123", r, space_p).hit); + } + } +} + +void dynamic_distinct_parser_test() +{ + // dynamic_distinct_parser() + { + dynamic_distinct_parser<scanner_t> distinct_p; + + // operator()(CharT const* str) const + rule_t r = distinct_p("keyword") >> !ch_p('-') >> int_p; + BOOST_TEST(parse("keyword123", r, space_p).full); + } + + // dynamic_distinct_parser(CharT const* letters) + { + dynamic_distinct_parser<scanner_t> distinct_p("0-9a-zA-Z_"); + + // operator()(CharT const* str) const + rule_t r = distinct_p("keyword") >> !ch_p('-') >> int_p; + BOOST_TEST(parse("keyword 123", r, space_p).full); + BOOST_TEST(parse("keyword-123", r, space_p).full); + BOOST_TEST(!parse("keyword123", r, space_p).hit); + } + + // dynamic_distinct_parser(parser<TailT> const & tail_) + { + dynamic_distinct_parser<scanner_t> + distinct_p(alnum_p | ('-' >> ~ch_p('-'))); + + // operator()(CharT const* str) const + rule_t r = distinct_p("keyword") >> !str_p("--") >> int_p; + BOOST_TEST(parse("keyword 123", r, space_p).full); + BOOST_TEST(parse("keyword--123", r, space_p).full); + BOOST_TEST(!parse("keyword-123", r, space_p).hit); + } +} + +void dynamic_distinct_directive_test() +{ + // dynamic_distinct_directive() + { + dynamic_distinct_directive<scanner_t> distinct_d; + + // operator[](CharT const* str) const + { + rule_t r = distinct_d["keyword"] >> !ch_p('-') >> int_p; + BOOST_TEST(parse("keyword123", r, space_p).full); + } + + // operator[](parser<ParserT> const &subject) const + { + rule_t r = distinct_d[str_p("keyword")] >> !ch_p('-') >> int_p; + BOOST_TEST(parse("keyword123", r, space_p).full); + } + } + + // dynamic_distinct_directive(CharT const* letters) + { + dynamic_distinct_directive<scanner_t> distinct_d("0-9a-zA-Z_"); + + // operator[](CharT const* str) const + { + rule_t r = distinct_d["keyword"] >> !ch_p('-') >> int_p; + BOOST_TEST(parse("keyword 123", r, space_p).full); + BOOST_TEST(parse("keyword-123", r, space_p).full); + BOOST_TEST(!parse("keyword123", r, space_p).hit); + } + + // operator[](parser<ParserT> const &subject) const + { + rule_t r = distinct_d[str_p("keyword")] >> !ch_p('-') >> int_p; + BOOST_TEST(parse("keyword 123", r, space_p).full); + BOOST_TEST(parse("keyword-123", r, space_p).full); + BOOST_TEST(!parse("keyword123", r, space_p).hit); + } + } + + // dynamic_distinct_directive(parser<TailT> const & tail_) + { + dynamic_distinct_directive<scanner_t> + distinct_d(alnum_p | ('-' >> ~ch_p('-'))); + + // operator[](CharT const* str) const + { + rule_t r = distinct_d["keyword"] >> !str_p("--") >> int_p; + BOOST_TEST(parse("keyword 123", r, space_p).full); + BOOST_TEST(parse("keyword--123", r, space_p).full); + BOOST_TEST(!parse("keyword-123", r, space_p).hit); + } + + // operator[](parser<ParserT> const &subject) const + { + rule_t r = distinct_d[str_p("keyword")] >> !str_p("--") >> int_p; + BOOST_TEST(parse("keyword 123", r, space_p).full); + BOOST_TEST(parse("keyword--123", r, space_p).full); + BOOST_TEST(!parse("keyword-123", r, space_p).hit); + } + } +} + +int +main() +{ + distinct_parser_test(); + distinct_directive_test(); + dynamic_distinct_parser_test(); + dynamic_distinct_directive_test(); + + return boost::report_errors(); +} + |