Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57105 - trunk/libs/spirit/test/qi
From: joel_at_[hidden]
Date: 2009-10-23 11:58:47


Author: djowel
Date: 2009-10-23 11:58:46 EDT (Fri, 23 Oct 2009)
New Revision: 57105
URL: http://svn.boost.org/trac/boost/changeset/57105

Log:
alternatives with optional attributes
Text files modified:
   trunk/libs/spirit/test/qi/alternative.cpp | 29 +++++++++++++++++++----------
   1 files changed, 19 insertions(+), 10 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-10-23 11:58:46 EDT (Fri, 23 Oct 2009)
@@ -43,8 +43,7 @@
 
 struct test_action_2
 {
- typedef std::vector<boost::variant<boost::spirit::unused_type, char> >
- result_type;
+ typedef std::vector<boost::optional<char> > result_type;
 
     void operator()(result_type const& v
       , boost::spirit::unused_type
@@ -53,11 +52,10 @@
         using boost::get;
 
         BOOST_TEST(v.size() == 5 &&
- v[0].which() == 0 &&
- v[1].which() == 1 && get<char>(v[1]) == 'a' &&
- v[2].which() == 1 && get<char>(v[2]) == 'b' &&
- v[3].which() == 1 && get<char>(v[3]) == '1' &&
- v[4].which() == 1 && get<char>(v[4]) == '2');
+ v[1] == 'a' &&
+ v[2] == 'b' &&
+ v[3] == '1' &&
+ v[4] == '2');
     }
 };
 
@@ -171,11 +169,22 @@
         using boost::spirit::ascii::alnum;
         using boost::spirit::ascii::alpha;
         using boost::spirit::ascii::digit;
+ using boost::spirit::ascii::string;
+ namespace phx = boost::phoenix;
 
- BOOST_TEST( (test("ab1_", lexeme[*(alnum | char_('_'))][test_action('_')])) );
- BOOST_TEST( (test("ab12", lexeme[*(alpha | digit)][test_action('2')])) );
 
- BOOST_TEST( (test("abcab12", lexeme[*("abc" | alnum)][test_action_2()])) );
+ BOOST_TEST( (test("ab1_", (*(alnum | char_('_')))[test_action('_')])) );
+ BOOST_TEST( (test("ab12", (*(alpha | digit))[test_action('2')])) );
+
+ BOOST_TEST( (test("abcab12", (*("abc" | alnum))[test_action_2()])) );
+
+ std::vector<boost::optional<char> > v;
+ BOOST_TEST( (test("x,y,z", (*(',' | char_))[phx::ref(v) = _1])) );
+ assert(v[0] == 'x');
+ assert(!v[1]);
+ assert(v[2] == 'y');
+ assert(!v[3]);
+ assert(v[4] == 'z');
     }
 
     {


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