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/karma/repeat1.cpp | 144 +++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 src/boost/libs/spirit/test/karma/repeat1.cpp (limited to 'src/boost/libs/spirit/test/karma/repeat1.cpp') diff --git a/src/boost/libs/spirit/test/karma/repeat1.cpp b/src/boost/libs/spirit/test/karma/repeat1.cpp new file mode 100644 index 00000000..ed0bc5d9 --- /dev/null +++ b/src/boost/libs/spirit/test/karma/repeat1.cpp @@ -0,0 +1,144 @@ +// 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 +#include + +#include "test.hpp" + +using namespace spirit_test; + +/////////////////////////////////////////////////////////////////////////////// +struct action +{ + action (std::vector& vec) + : vec(vec), it(vec.begin()) + {} + + void operator()(unsigned& value, boost::spirit::unused_type, bool& pass) const + { + pass = (it != vec.end()); + if (pass) + value = *it++; + } + + std::vector& vec; + mutable std::vector::iterator it; +}; + +/////////////////////////////////////////////////////////////////////////////// +int main() +{ + using namespace boost::spirit::ascii; + using boost::spirit::karma::repeat; + using boost::spirit::karma::inf; + using boost::spirit::karma::int_; + using boost::spirit::karma::hex; + using boost::spirit::karma::_1; + + { // lazy repeats + using boost::phoenix::val; + + std::string str8("aaaaaaaa"); + BOOST_TEST(test("aaaaaaaa", repeat[char_], str8)); // kleene synonym + BOOST_TEST(test("aaaaaaaa", repeat(val(8))[char_], str8)); + BOOST_TEST(test("aaa", repeat(val(3))[char_], str8)); + BOOST_TEST(!test("aaaaaaaa", repeat(val(9))[char_], str8)); + + std::string str3("aaa"); + BOOST_TEST(test("aaaaa", repeat(val(3), val(5))[char_], str8)); + BOOST_TEST(test("aaa", repeat(val(3), val(5))[char_], str3)); + BOOST_TEST(!test("aaa", repeat(val(4), val(5))[char_], str3)); + + BOOST_TEST(test("aaa", repeat(val(3), val(inf))[char_], str3)); + BOOST_TEST(test("aaaaaaaa", repeat(val(3), val(inf))[char_], str8)); + BOOST_TEST(!test("aaa", repeat(val(4), val(inf))[char_], str3)); + } + + + { + std::string str8("aaaaaaaa"); + BOOST_TEST(test("aaaaaaaa", repeat[char_], str8)); // kleene synonym + BOOST_TEST(test("aaaaaaaa", repeat(8)[char_], str8)); + BOOST_TEST(test("aaa", repeat(3)[char_], str8)); + BOOST_TEST(!test("aaaaaaaa", repeat(9)[char_], str8)); + + std::string str3("aaa"); + BOOST_TEST(test("aaaaa", repeat(3, 5)[char_], str8)); + BOOST_TEST(test("aaa", repeat(3, 5)[char_], str3)); + BOOST_TEST(!test("aaa", repeat(4, 5)[char_], str3)); + + BOOST_TEST(test("aaa", repeat(3, inf)[char_], str3)); + BOOST_TEST(test("aaaaaaaa", repeat(3, inf)[char_], str8)); + BOOST_TEST(!test("aaa", repeat(4, inf)[char_], str3)); + } + + { + std::string str8("aaaaaaaa"); + BOOST_TEST(test_delimited("a a a a a a a a ", repeat[char_], str8, space)); + BOOST_TEST(test_delimited("a a a a a a a a ", repeat(8)[char_], str8, space)); + BOOST_TEST(test_delimited("a a a ", repeat(3)[char_], str8, space)); + BOOST_TEST(!test_delimited("a a a a a a a a ", repeat(9)[char_], str8, space)); + + std::string str3("aaa"); + BOOST_TEST(test_delimited("a a a a a ", repeat(3, 5)[char_], str8, space)); + BOOST_TEST(test_delimited("a a a ", repeat(3, 5)[char_], str3, space)); + BOOST_TEST(!test_delimited("a a a ", repeat(4, 5)[char_], str3, space)); + + BOOST_TEST(test_delimited("a a a ", repeat(3, inf)[char_], str3, space)); + BOOST_TEST(test_delimited("a a a a a a a a ", repeat(3, inf)[char_], str8, space)); + BOOST_TEST(!test_delimited("a a a ", repeat(4, inf)[char_], str3, space)); + } + + { + // make sure user defined end condition is applied if no attribute + // is passed in + using namespace boost::assign; + + std::vector v; + v += 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'; + BOOST_TEST(test("[6162636465666768]", + '[' << repeat[hex[action(v)]] << ']')); + } + +// we support Phoenix attributes only starting with V2.2 +#if SPIRIT_VERSION >= 0x2020 + { + namespace ascii = boost::spirit::ascii; + namespace phoenix = boost::phoenix; + + char c = 'a'; + BOOST_TEST(test("bcd", repeat(3)[ascii::char_[_1 = ++phoenix::ref(c)]])); + + c = 'a'; + BOOST_TEST(test("bcd", repeat(3)[ascii::char_], ++phoenix::ref(c))); + } +#endif + + return boost::report_errors(); +} + -- cgit v1.2.3