Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52932 - trunk/libs/spirit/test/qi
From: hartmut.kaiser_at_[hidden]
Date: 2009-05-11 22:51:35


Author: hkaiser
Date: 2009-05-11 22:51:35 EDT (Mon, 11 May 2009)
New Revision: 52932
URL: http://svn.boost.org/trac/boost/changeset/52932

Log:
Spirit: added test case for fixed attribute calculation for qi alternatives
Text files modified:
   trunk/libs/spirit/test/qi/alternative.cpp | 23 +++++++++++++++++++++++
   1 files changed, 23 insertions(+), 0 deletions(-)

Modified: trunk/libs/spirit/test/qi/alternative.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/alternative.cpp (original)
+++ trunk/libs/spirit/test/qi/alternative.cpp 2009-05-11 22:51:35 EDT (Mon, 11 May 2009)
@@ -21,8 +21,20 @@
 
 #include <string>
 #include <iostream>
+#include <vector>
 #include "test.hpp"
 
+struct print_action
+{
+ void operator()(std::vector<char> const& v
+ , boost::spirit::unused_type
+ , boost::spirit::unused_type) const
+ {
+ BOOST_TEST(v.size() == 4 &&
+ v[0] =='a' && v[1] =='b' && v[2] =='1' && v[3] =='2');
+ }
+};
+
 int
 main()
 {
@@ -114,6 +126,17 @@
         r3 = ((eps >> r1) | r2)[_val += _1];
     }
 
+ // make sure the attribute of an alternative gets properly collapsed
+ {
+ using boost::spirit::qi::lexeme;
+ using boost::spirit::ascii::alnum;
+ using boost::spirit::ascii::alpha;
+ using boost::spirit::ascii::digit;
+
+ BOOST_TEST( (test("ab12", lexeme[*(alnum | '_')][print_action()])) );
+ BOOST_TEST( (test("ab12", lexeme[*(alpha | digit)][print_action()])) );
+ }
+
     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