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 --- src/boost/libs/spirit/test/qi/pass_container2.cpp | 266 ++++++++++++++++++++++ 1 file changed, 266 insertions(+) create mode 100644 src/boost/libs/spirit/test/qi/pass_container2.cpp (limited to 'src/boost/libs/spirit/test/qi/pass_container2.cpp') diff --git a/src/boost/libs/spirit/test/qi/pass_container2.cpp b/src/boost/libs/spirit/test/qi/pass_container2.cpp new file mode 100644 index 00000000..ef54dca5 --- /dev/null +++ b/src/boost/libs/spirit/test/qi/pass_container2.cpp @@ -0,0 +1,266 @@ +// Copyright (c) 2001-2011 Hartmut Kaiser +// +// Distributed under 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 +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "test.hpp" + +using namespace spirit_test; + +inline bool compare(std::vector const& v, std::string const& s) +{ + return v.size() == s.size() && std::equal(v.begin(), v.end(), s.begin()); +} + +struct A +{ + int i1; + double d2; +}; + +BOOST_FUSION_ADAPT_STRUCT( + A, + (int, i1) + (double, d2) +) + +int main() +{ + using boost::spirit::qi::char_; + using boost::spirit::qi::omit; + + { + std::vector > v1; + BOOST_TEST(test_attr("abc,def,gh", *~char_(',') % ',', v1) && + v1.size() == 3 && + compare(v1[0], "abc") && + compare(v1[1], "def") && + compare(v1[2], "gh")); + + std::vector v2; + BOOST_TEST(test_attr("abc,def,gh", *~char_(',') % ',', v2) && + v2.size() == 3 && v2[0] == "abc" && v2[1] == "def" && v2[2] == "gh"); + + BOOST_TEST(test("abc,def,gh", *~char_(',') % ',')); + BOOST_TEST(test("abc,def,gh", omit[*~char_(',')] % ',')); + } + + { + std::vector v1; + BOOST_TEST(test_attr("a", char_ >> -(char_ % ','), v1) && + compare(v1, "a")); + v1.clear(); + BOOST_TEST(test_attr("ab,c", char_ >> -(char_ % ','), v1) && + compare(v1, "abc")); + v1.clear(); + BOOST_TEST(test_attr("a", char_ >> -char_, v1) && + compare(v1, "a")); + v1.clear(); + BOOST_TEST(test_attr("ab", char_ >> -char_, v1) && + compare(v1, "ab")); + + std::vector > v2; + BOOST_TEST(test_attr("a", char_ >> -char_, v2) && + v2.size() == 2 && + boost::get(v2[0]) == 'a' && + !v2[1]); + v2.clear(); + BOOST_TEST(test_attr("ab", char_ >> -char_, v2) && + v2.size() == 2 && + boost::get(v2[0]) == 'a' && + boost::get(v2[1]) == 'b'); + + std::string s; + BOOST_TEST(test_attr("a", char_ >> -(char_ % ','), s) && + s == "a"); + s.clear(); + BOOST_TEST(test_attr("ab,c", char_ >> -(char_ % ','), s) && + s == "abc"); + s.clear(); + BOOST_TEST(test_attr("ab", char_ >> -char_, s) && + s == "ab"); + s.clear(); + BOOST_TEST(test_attr("a", char_ >> -char_, s) && + s == "a"); + + BOOST_TEST(test("a", char_ >> -(char_ % ','))); + BOOST_TEST(test("ab,c", char_ >> -(char_ % ','))); + BOOST_TEST(test("a", char_ >> -char_)); + BOOST_TEST(test("ab", char_ >> -char_)); + } + + { + using boost::spirit::qi::eps; + + std::vector v; + BOOST_TEST(test_attr("a", char_ >> ((char_ % ',') | eps), v) && + compare(v, "a")); + v.clear(); + BOOST_TEST(test_attr("ab,c", char_ >> ((char_ % ',') | eps), v) && + compare(v, "abc")); + + std::string s; + BOOST_TEST(test_attr("a", char_ >> ((char_ % ',') | eps), s) && + s == "a"); + s.clear(); + BOOST_TEST(test_attr("ab,c", char_ >> ((char_ % ',') | eps), s) && + s == "abc"); + + BOOST_TEST(test("a", char_ >> ((char_ % ',') | eps))); + BOOST_TEST(test("ab,c", char_ >> ((char_ % ',') | eps))); + } + + { + std::vector v1; + BOOST_TEST(test_attr("abc1,abc2", + *~char_(',') >> *(',' >> *~char_(',')), v1) && + compare(v1, "abc1abc2")); + + std::vector v2; + BOOST_TEST(test_attr("abc1,abc2", + *~char_(',') >> *(',' >> *~char_(',')), v2) && + v2.size() == 2 && + v2[0] == "abc1" && + v2[1] == "abc2"); + + std::string s; + BOOST_TEST(test_attr("abc1,abc2", + *~char_(',') >> *(',' >> *~char_(',')), s) && + s == "abc1abc2"); + } + + { + using boost::spirit::qi::alpha; + using boost::spirit::qi::digit; + + std::vector v1; + BOOST_TEST(test_attr("ab1cd2", *(alpha >> alpha | +digit), v1) && + compare(v1, "ab1cd2")); + v1.clear(); + BOOST_TEST(test_attr("ab1cd2", *(alpha >> alpha | digit), v1) && + compare(v1, "ab1cd2")); + + std::string s1; + BOOST_TEST(test_attr("ab1cd2", *(alpha >> alpha | +digit), s1) && + s1 == "ab1cd2"); + s1.clear(); + BOOST_TEST(test_attr("ab1cd2", *(alpha >> alpha | digit), s1) && + s1 == "ab1cd2"); + } + + { + using boost::spirit::qi::rule; + using boost::spirit::qi::space; + using boost::spirit::qi::space_type; + using boost::spirit::qi::int_; + using boost::spirit::qi::double_; + + std::vector v; + BOOST_TEST(test_attr("A 1 2.0", 'A' >> *(int_ >> double_), v, space) && + v.size() == 1 && v[0].i1 == 1 && v[0].d2 == 2.0); + + v.clear(); + BOOST_TEST(test_attr("1 2.0", *(int_ >> double_), v, space) && + v.size() == 1 && v[0].i1 == 1 && v[0].d2 == 2.0); + + v.clear(); + rule()> r = *(int_ >> ',' >> double_); + BOOST_TEST(test_attr("1,2.0", r, v) && + v.size() == 1 && v[0].i1 == 1 && v[0].d2 == 2.0); + } + + { + using boost::spirit::qi::rule; + using boost::spirit::qi::int_; + using boost::spirit::qi::double_; + + rule r = int_ >> ',' >> double_; + rule()> r2 = 'A' >> *(r >> ',' >> r); + + std::vector v; + BOOST_TEST(test_attr("A1,2.0,3,4.0", r2, v) && + v.size() == 2 && v[0].i1 == 1.0 && v[0].d2 == 2.0 && + v[1].i1 == 3.0 && v[1].d2 == 4.0); + + v.clear(); + BOOST_TEST(test_attr("A1,2.0,3,4.0", 'A' >> *(r >> ',' >> r), v) && + v.size() == 2 && v[0].i1 == 1.0 && v[0].d2 == 2.0 && + v[1].i1 == 3.0 && v[1].d2 == 4.0); + + v.clear(); + BOOST_TEST(test_attr("1,2.0,3,4.0", *(r >> ',' >> r), v) && + v.size() == 2 && v[0].i1 == 1.0 && v[0].d2 == 2.0 && + v[1].i1 == 3.0 && v[1].d2 == 4.0); + } + + { + using boost::spirit::qi::rule; + using boost::spirit::qi::int_; + using boost::spirit::qi::double_; + using boost::fusion::at_c; + + typedef boost::fusion::vector data_type; + + rule r = int_ >> ',' >> double_; + rule()> r2 = 'A' >> *(r >> ',' >> r); + + std::vector v; + BOOST_TEST(test_attr("A1,2.0,3,4.0", r2, v) && + v.size() == 2 && at_c<0>(v[0]) == 1 && at_c<1>(v[0]) == 2.0 && + at_c<0>(v[1]) == 3 && at_c<1>(v[1]) == 4.0); + + v.clear(); + BOOST_TEST(test_attr("A1,2.0,3,4.0", 'A' >> *(r >> ',' >> r), v) && + v.size() == 2 && at_c<0>(v[0]) == 1 && at_c<1>(v[0]) == 2.0 && + at_c<0>(v[1]) == 3 && at_c<1>(v[1]) == 4.0); + + v.clear(); + BOOST_TEST(test_attr("1,2.0,3,4.0", *(r >> ',' >> r), v) && + v.size() == 2 && at_c<0>(v[0]) == 1 && at_c<1>(v[0]) == 2.0 && + at_c<0>(v[1]) == 3 && at_c<1>(v[1]) == 4.0); + } + +// doesn't currently work +// { +// std::vector > v2; +// BOOST_TEST(test_attr("ab1cd123", *(alpha >> alpha | +digit), v2) && +// v2.size() == 4 && +// compare(v2[0], "ab") && +// compare(v2[1], "1") && +// compare(v2[2], "cd") && +// compare(v2[3], "123")); +// +// std::vector v3; +// BOOST_TEST(test_attr("ab1cd123", *(alpha >> alpha | +digit), v3) && +// v3.size() == 4 && +// v3[0] == "ab" && +// v3[1] == "1" && +// v3[2] == "cd" && +// v3[3] == "123"); +// } + + return boost::report_errors(); +} + -- cgit v1.2.3