From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- .../libs/spirit/classic/test/distinct_tests.cpp | 248 +++++++++++++++++++++ 1 file changed, 248 insertions(+) create mode 100644 src/boost/libs/spirit/classic/test/distinct_tests.cpp (limited to 'src/boost/libs/spirit/classic/test/distinct_tests.cpp') 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 +#include +#include + +using namespace boost; +using namespace BOOST_SPIRIT_CLASSIC_NS; + +typedef + scanner > > + scanner_t; + +typedef + rule + 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 const & tail_) + { + distinct_parser< + char, + alternative< + alnum_parser, + sequence< + chlit<>, + negated_char_parser > + > + > + > + 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 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 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 const & tail_) + { + distinct_directive< + char, + alternative< + alnum_parser, + sequence< + chlit<>, + negated_char_parser > + > + > + > + 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 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 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 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 const & tail_) + { + dynamic_distinct_parser + 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 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 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 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 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 const & tail_) + { + dynamic_distinct_directive + 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 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(); +} + -- cgit v1.2.3