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/test/qi/debug.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/test/qi/debug.cpp')
-rw-r--r-- | src/boost/libs/spirit/test/qi/debug.cpp | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/src/boost/libs/spirit/test/qi/debug.cpp b/src/boost/libs/spirit/test/qi/debug.cpp new file mode 100644 index 00000000..f32dacf9 --- /dev/null +++ b/src/boost/libs/spirit/test/qi/debug.cpp @@ -0,0 +1,131 @@ +/*============================================================================= + Copyright (c) 2001-2010 Joel de Guzman + + 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) +=============================================================================*/ +#define BOOST_SPIRIT_DEBUG + +#include <boost/detail/lightweight_test.hpp> +#include <boost/spirit/include/qi_operator.hpp> +#include <boost/spirit/include/qi_char.hpp> +#include <boost/spirit/include/qi_string.hpp> +#include <boost/spirit/include/qi_numeric.hpp> +#include <boost/spirit/include/qi_auxiliary.hpp> +#include <boost/spirit/include/qi_nonterminal.hpp> +#include <boost/spirit/include/qi_action.hpp> +#include <boost/spirit/include/phoenix_core.hpp> +#include <boost/spirit/include/phoenix_operator.hpp> +#include <boost/spirit/include/phoenix_object.hpp> +#include <boost/spirit/include/phoenix_bind.hpp> +#include <boost/fusion/include/std_pair.hpp> + +#include <string> +#include <cstring> +#include <iostream> +#include "test.hpp" + +int +main() +{ + using spirit_test::test_attr; + using spirit_test::test; + + using namespace boost::spirit::ascii; + using namespace boost::spirit::qi::labels; + using boost::spirit::qi::locals; + using boost::spirit::qi::rule; + using boost::spirit::qi::int_; + using boost::spirit::qi::fail; + using boost::spirit::qi::on_error; + using boost::spirit::qi::debug; + using boost::spirit::qi::alpha; + + namespace phx = boost::phoenix; + + { // basic tests + + rule<char const*> a, b, c, start; + + a = 'a'; + b = 'b'; + c = 'c'; + BOOST_SPIRIT_DEBUG_NODE(a); + BOOST_SPIRIT_DEBUG_NODE(b); + BOOST_SPIRIT_DEBUG_NODE(c); + + start = *(a | b | c); + BOOST_SPIRIT_DEBUG_NODE(start); + BOOST_TEST(test("abcabcacb", start)); + + start = (a | b) >> (start | b); + BOOST_SPIRIT_DEBUG_NODE(start); + BOOST_TEST(test("aaaabababaaabbb", start)); + BOOST_TEST(test("aaaabababaaabba", start, false)); + + // ignore the skipper! + BOOST_TEST(test("aaaabababaaabba", start, space, false)); + } + + { // basic tests w/ skipper + + rule<char const*, space_type> a, b, c, start; + + a = 'a'; + b = 'b'; + c = 'c'; + BOOST_SPIRIT_DEBUG_NODE(a); + BOOST_SPIRIT_DEBUG_NODE(b); + BOOST_SPIRIT_DEBUG_NODE(c); + + start = *(a | b | c); + BOOST_SPIRIT_DEBUG_NODE(start); + BOOST_TEST(test(" a b c a b c a c b ", start, space)); + + start = (a | b) >> (start | b); + BOOST_SPIRIT_DEBUG_NODE(start); + BOOST_TEST(test(" a a a a b a b a b a a a b b b ", start, space)); + BOOST_TEST(test(" a a a a b a b a b a a a b b a ", start, space, false)); + } + + { // std::container attributes + + typedef boost::fusion::vector<int, char> fs; + rule<char const*, std::vector<fs>(), space_type> start; + start = *(int_ >> alpha); + + BOOST_SPIRIT_DEBUG_NODE(start); + BOOST_TEST(test("1 a 2 b 3 c", start, space)); + } + + { // error handling + + using namespace boost::spirit::ascii; + using boost::phoenix::construct; + using boost::phoenix::bind; + + rule<char const*> r; + r = '(' > int_ > ',' > int_ > ')'; + + on_error<fail> + ( + r, std::cout + << phx::val("Error! Expecting: ") + << _4 + << phx::val(", got: \"") + << construct<std::string>(_3, _2) + << phx::val("\"") + << std::endl + ); + + BOOST_SPIRIT_DEBUG_NODE(r); + BOOST_TEST(test("(123,456)", r)); + BOOST_TEST(!test("(abc,def)", r)); + BOOST_TEST(!test("(123,456]", r)); + BOOST_TEST(!test("(123;456)", r)); + BOOST_TEST(!test("[123,456]", r)); + } + + return boost::report_errors(); +} + |