Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r68491 - in trunk/libs/spirit/repository/test: . qi
From: hartmut.kaiser_at_[hidden]
Date: 2011-01-27 17:13:47


Author: hkaiser
Date: 2011-01-27 17:13:46 EST (Thu, 27 Jan 2011)
New Revision: 68491
URL: http://svn.boost.org/trac/boost/changeset/68491

Log:
Spirit: adding advance tests to repository
Added:
   trunk/libs/spirit/repository/test/qi/advance.cpp (contents, props changed)
Text files modified:
   trunk/libs/spirit/repository/test/Jamfile | 1 +
   1 files changed, 1 insertions(+), 0 deletions(-)

Modified: trunk/libs/spirit/repository/test/Jamfile
==============================================================================
--- trunk/libs/spirit/repository/test/Jamfile (original)
+++ trunk/libs/spirit/repository/test/Jamfile 2011-01-27 17:13:46 EST (Thu, 27 Jan 2011)
@@ -22,6 +22,7 @@
     test-suite spirit_v2_repository :
 
     # run Qi repository tests
+ [ run qi/advance.cpp : : : : qi_repo_advance ]
     [ run qi/confix.cpp : : : : qi_repo_confix ]
     [ run qi/distinct.cpp : : : : qi_repo_distinct ]
     [ run qi/subrule.cpp : : : : qi_repo_subrule ]

Added: trunk/libs/spirit/repository/test/qi/advance.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/repository/test/qi/advance.cpp 2011-01-27 17:13:46 EST (Thu, 27 Jan 2011)
@@ -0,0 +1,111 @@
+// Copyright (c) 2001-2010 Hartmut Kaiser
+// Copyright (c) 2001-2010 Joel de Guzman
+// Copyright (c) 2011 Aaron Graham
+//
+// 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/detail/lightweight_test.hpp>
+
+#include <boost/spirit/include/qi_action.hpp>
+#include <boost/spirit/include/qi_auxiliary.hpp>
+#include <boost/spirit/include/qi_binary.hpp>
+#include <boost/spirit/include/qi_char.hpp>
+#include <boost/spirit/include/qi_directive.hpp>
+#include <boost/spirit/include/qi_nonterminal.hpp>
+#include <boost/spirit/include/qi_numeric.hpp>
+#include <boost/spirit/include/qi_operator.hpp>
+#include <boost/spirit/include/qi_string.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+
+#include <boost/spirit/repository/include/qi_advance.hpp>
+
+#include <boost/assign/std/list.hpp>
+#include "test.hpp"
+
+namespace spirit_test
+{
+ template <typename Container, typename Parser>
+ bool test_c(Container const& in, Parser const& p, bool full_match = true)
+ {
+ // we don't care about the results of the "what" function.
+ // we only care that all parsers have it:
+ boost::spirit::qi::what(p);
+
+ typename Container::const_iterator first = in.begin();
+ typename Container::const_iterator const last = in.end();
+ return boost::spirit::qi::parse(first, last, p)
+ && (!full_match || (first == last));
+ }
+}
+
+int main()
+{
+ using spirit_test::test;
+ using spirit_test::test_c;
+
+ using namespace boost::spirit::qi::labels;
+ using boost::spirit::qi::locals;
+ using boost::spirit::qi::rule;
+ using boost::spirit::qi::uint_;
+ using boost::spirit::qi::byte_;
+
+ using namespace boost::assign;
+ using boost::spirit::repository::qi::advance;
+
+ { // test basic functionality with random-access iterators
+ rule<char const*> start;
+
+ start = 'a' >> advance(3) >> "bc";
+ BOOST_TEST(test("a123bc", start));
+
+ start = (advance(3) | 'q') >> 'i';
+ BOOST_TEST(test("qi", start));
+
+ start = advance(-1);
+ BOOST_TEST(!test("0", start));
+
+ start = advance(-1) | "qi";
+ BOOST_TEST(test("qi", start));
+
+ start = advance(0) >> "abc" >> advance(10) >> "nopq" >> advance(0)
+ >> advance(8) >> 'z';
+ BOOST_TEST(test("abcdefghijklmnopqrstuvwxyz", start));
+ }
+
+ { // test locals
+ rule<char const*, locals<unsigned> > start;
+
+ start = byte_ [_a = _1] >> advance(_a) >> "345";
+ BOOST_TEST(test("\x02""12345", start));
+ BOOST_TEST(!test("\x60""345", start));
+ }
+
+ { // test basic functionality with bidirectional iterators
+ rule<std::list<char>::const_iterator, locals<int> > start;
+ std::list<char> list;
+
+ list.clear();
+ list += 1,2,'a','b','c';
+ start = byte_ [_a = _1] >> advance(_a) >> "abc";
+ BOOST_TEST(test_c(list, start));
+
+ list.clear();
+ list += 3,'q','i';
+ start = byte_ [_a = _1] >> advance(_a);
+ BOOST_TEST(!test_c(list, start));
+
+ start = byte_ [_a = _1] >> (advance(_a) | "qi");
+ BOOST_TEST(test_c(list, start));
+
+ list.clear();
+ list += 'a','b','c','d','e','f','g','h','i','j','k','l','m';
+ list += 'n','o','p','q','r','s','t','u','v','w','x','y','z';
+ start = advance(0) >> "abc" >> advance(10) >> "nopq" >> advance(0)
+ >> advance(8) >> 'z';
+ BOOST_TEST(test_c(list, start));
+ }
+
+ 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