]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/spirit/test/x3/error_handler.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / spirit / test / x3 / error_handler.cpp
index d22949fd95759516c01f954e4b2ddc5dca18acc6..00d152efb6f3846c5733b27d295cfc91b52a882c 100644 (file)
@@ -5,9 +5,10 @@
     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 =============================================================================*/
 
-#include <boost/detail/lightweight_test.hpp>
 #include <boost/spirit/home/x3.hpp>
 #include <boost/spirit/home/x3/support/utility/annotate_on_success.hpp>
+
+#include <boost/core/lightweight_test.hpp>
 #include <string>
 #include <sstream>
 
@@ -27,18 +28,22 @@ struct error_handler_base
     }
 };
 
+struct test_inner_rule_class;
 struct test_rule_class : x3::annotate_on_success, error_handler_base {};
 
+x3::rule<test_inner_rule_class> const test_inner_rule = "\"bar\"";
 x3::rule<test_rule_class> const test_rule;
-auto const test_rule_def = x3::lit("foo") > x3::lit("bar") > x3::lit("git");
+auto const test_inner_rule_def = x3::lit("bar");
+auto const test_rule_def = x3::lit("foo") > test_inner_rule > x3::lit("git");
 
-BOOST_SPIRIT_DEFINE(test_rule)
+BOOST_SPIRIT_DEFINE(test_inner_rule, test_rule)
 
 void test(std::string const& line_break) {
     std::string const input("foo" + line_break + "  foo" + line_break + "git");
     auto const begin = std::begin(input);
     auto const end = std::end(input);
 
+{
     std::stringstream stream;
     x3::error_handler<std::string::const_iterator> error_handler{begin, end, stream};
 
@@ -48,10 +53,40 @@ void test(std::string const& line_break) {
     BOOST_TEST_EQ(stream.str(), "In line 2:\nError! Expecting: \"bar\" here:\n  foo\n__^_\n");
 }
 
+{ // TODO: cleanup when error_handler is reenterable
+    std::stringstream stream;
+    x3::error_handler<std::string::const_iterator> error_handler{ begin, end, stream };
+
+    auto const parser = x3::with<x3::error_handler_tag>(std::ref(error_handler))[test_rule];
+    x3::parse(begin, end, parser);
+
+    BOOST_TEST_CSTR_EQ(stream.str().c_str(), "In line 1:\nError! Expecting: \"bar\" here:\nfoo\n___^_\n");
+}
+}
+
+void test_line_break_first(std::string const& line_break) {
+    std::string const input(line_break + "foo  foo" + line_break + "git");
+    auto const begin = std::begin(input);
+    auto const end = std::end(input);
+
+    std::stringstream stream;
+    x3::error_handler<std::string::const_iterator> error_handler{begin, end, stream};
+
+    auto const parser = x3::with<x3::error_handler_tag>(std::ref(error_handler))[test_rule];
+    x3::phrase_parse(begin, end, parser, x3::space);
+
+    BOOST_TEST_EQ(stream.str(), "In line 2:\nError! Expecting: \"bar\" here:\nfoo  foo\n_____^_\n");
+}
+
 int main() {
     test("\n");
     test("\r");
     test("\r\n");
 
+    test_line_break_first("\n");
+    test_line_break_first("\r");
+    test_line_break_first("\r\n");
+
+
     return boost::report_errors();
 }