Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r66169 - in trunk/libs/spirit/test: . qi
From: hartmut.kaiser_at_[hidden]
Date: 2010-10-24 20:53:56


Author: hkaiser
Date: 2010-10-24 20:53:56 EDT (Sun, 24 Oct 2010)
New Revision: 66169
URL: http://svn.boost.org/trac/boost/changeset/66169

Log:
Spirit: added regression test for qi::repeat
Added:
   trunk/libs/spirit/test/qi/repeat_regression.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 2010-10-24 20:53:56 EDT (Sun, 24 Oct 2010)
@@ -162,6 +162,7 @@
     [ compile qi/single_element_sequence_attribute.cpp : : qi_single_element_sequence_attribute ]
     [ compile qi/debug_optional.cpp : : qi_debug_optional ]
     [ run karma/real_scientific.cpp : : : : ]
+ [ run qi/repeat_regression.cpp : : : : ]
 
     ;
 

Added: trunk/libs/spirit/test/qi/repeat_regression.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/qi/repeat_regression.cpp 2010-10-24 20:53:56 EDT (Sun, 24 Oct 2010)
@@ -0,0 +1,44 @@
+// Copyright (c) 2001-2010 Hartmut Kaiser
+// Copyright (c) 2010 Head Geek
+//
+// 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 <iostream>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/spirit/include/qi.hpp>
+
+namespace qi = boost::spirit::qi;
+using qi::omit;
+using qi::repeat;
+using std::cout;
+using std::endl;
+
+typedef qi::rule<std::string::const_iterator, std::string()> strrule_type;
+
+void test(const std::string input, strrule_type rule, std::string result)
+{
+ std::string target;
+ std::string::const_iterator i = input.begin(), ie = input.end();
+
+ BOOST_TEST(qi::parse(i, ie, rule, target) && target == result);
+}
+
+int main()
+{
+ strrule_type obsolete_year =
+ omit[-qi::char_(" \t")] >>
+ repeat(2)[qi::digit] >>
+ omit[-qi::char_(" \t")];
+ strrule_type correct_year = repeat(4)[qi::digit];
+
+ test("1776", correct_year | repeat(2)[qi::digit], "1776");
+ test("76", obsolete_year, "76");
+ test("76", obsolete_year | correct_year, "76");
+ test(" 76", correct_year | obsolete_year, "76");
+ test("76", correct_year | obsolete_year, "76");
+ test("76", correct_year | repeat(2)[qi::digit], "76");
+
+ 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