|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r71080 - in trunk/libs/spirit/test: . support
From: hartmut.kaiser_at_[hidden]
Date: 2011-04-07 10:38:34
Author: hkaiser
Date: 2011-04-07 10:38:33 EDT (Thu, 07 Apr 2011)
New Revision: 71080
URL: http://svn.boost.org/trac/boost/changeset/71080
Log:
Spirit: fixing assertions in error_handler when used with multi_pass, added test
Added:
trunk/libs/spirit/test/support/regression_multi_pass_error_handler.cpp (contents, props changed)
Text files modified:
trunk/libs/spirit/test/Jamfile | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
Modified: trunk/libs/spirit/test/Jamfile
==============================================================================
--- trunk/libs/spirit/test/Jamfile (original)
+++ trunk/libs/spirit/test/Jamfile 2011-04-07 10:38:33 EDT (Thu, 07 Apr 2011)
@@ -306,6 +306,7 @@
[ compile support/regression_multi_pass_position_iterator.cpp : : support_regression_multi_pass_position_iterator ]
[ compile support/regression_multi_pass_functor.cpp : : support_regression_multi_pass_functor ]
[ compile support/regression_multi_pass_parse.cpp : : support_regression_multi_pass_parse ]
+ [ run support/regression_multi_pass_error_handler.cpp : : : : regression_multi_pass_error_handler ]
;
}
Added: trunk/libs/spirit/test/support/regression_multi_pass_error_handler.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/support/regression_multi_pass_error_handler.cpp 2011-04-07 10:38:33 EDT (Thu, 07 Apr 2011)
@@ -0,0 +1,65 @@
+// Copyright (c) 2001-2010 Hartmut Kaiser
+// Copyright (c) 2011 Laurent Gomila
+//
+// 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 <boost/config/warning_disable.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/phoenix.hpp>
+#include <boost/spirit/include/support_multi_pass.hpp>
+#include <sstream>
+#include <iostream>
+#include <iterator>
+#include <string>
+
+using namespace boost::spirit;
+using namespace boost;
+
+int main()
+{
+ {
+ std::string input("5x");
+ std::istringstream iss(input);
+
+ typedef std::istreambuf_iterator<char> base_iterator_type;
+ typedef multi_pass<base_iterator_type> iterator_type;
+
+ iterator_type first = make_default_multi_pass(base_iterator_type(iss));
+ iterator_type last = make_default_multi_pass(base_iterator_type());
+
+ std::ostringstream oss;
+
+ qi::rule<iterator_type> r = qi::int_ > qi::int_;
+ qi::on_error<qi::fail>(r, phoenix::ref(oss) << phoenix::val("error"));
+
+ BOOST_TEST(!qi::parse(first, last, r));
+ BOOST_TEST(oss.str() == "error");
+ }
+
+ {
+ std::string input("5x");
+ std::istringstream iss(input);
+
+ typedef std::istreambuf_iterator<char> base_iterator_type;
+ typedef multi_pass<base_iterator_type> iterator_type;
+
+ iterator_type first = make_default_multi_pass(base_iterator_type(iss));
+ iterator_type last = make_default_multi_pass(base_iterator_type());
+
+ std::ostringstream oss;
+
+ qi::rule<iterator_type> r1 = qi::int_ > qi::int_;
+ qi::rule<iterator_type> r2 = qi::int_ > qi::char_;
+ qi::on_error<qi::fail>(r1, phoenix::ref(oss) << phoenix::val("error in r1"));
+ qi::on_error<qi::fail>(r2, phoenix::ref(oss) << phoenix::val("error in r2"));
+
+ BOOST_TEST(qi::parse(first, last, r1 | r2));
+ BOOST_TEST(oss.str() == "error in r1");
+ }
+
+ return boost::report_errors();
+}
+
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk