Update of /cvsroot/boost/boost/libs/xpressive/test
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv7032/libs/xpressive/test

Modified Files:
        test_actions.cpp 
Log Message:
support for late-bound arguments in actions

Index: test_actions.cpp
===================================================================
RCS file: /cvsroot/boost/boost/libs/xpressive/test/test_actions.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- test_actions.cpp    23 Mar 2007 21:43:13 -0000      1.3
+++ test_actions.cpp    24 Mar 2007 10:07:30 -0000      1.4
@@ -67,7 +67,7 @@
     std::list<int> result;
     std::string str("1 23 456 7890");
     sregex rx = (+_d)[ push_back( result, as<int>(_) ) ] 
-        >> *(' ' >> (+_w)[ push_back( result, as<int>(_) ) ]);
+        >> *(' ' >> (+_d)[ push_back( result, as<int>(_) ) ]);
 
     if(!regex_match(str, rx))
     {
@@ -109,6 +109,35 @@
 }
 
 ///////////////////////////////////////////////////////////////////////////////
+// test4_aux
+//  build a map of strings to integers, with a late-bound action argument.
+void test4_aux()
+{
+    using namespace boost::xpressive;
+    arg< std::map<std::string, int> > map;
+
+    sregex pair = ( (s1= +_w) >> "=>" >> (s2= +_d) )[ map[s1] = as<int>(s2) ];
+    sregex rx = pair >> *(+_s >> pair);
+
+    std::string str("aaa=>1 bbb=>23 ccc=>456");
+    smatch what;
+    std::map<std::string, int> result;
+    what.bind( map = result ); // bind the argument!
+
+    if(!regex_match(str, what, rx))
+    {
+        BOOST_ERROR("oops");
+    }
+    else
+    {
+        BOOST_REQUIRE_EQUAL(result.size(), 3u);
+        BOOST_CHECK_EQUAL(result["aaa"], 1);
+        BOOST_CHECK_EQUAL(result["bbb"], 23);
+        BOOST_CHECK_EQUAL(result["ccc"], 456);
+    }
+}
+
+///////////////////////////////////////////////////////////////////////////////
 // test5
 //  calculator that calculates. This is just silly, but hey.
 void test5()
@@ -117,7 +146,7 @@
 
     int left = 0, right = 0;
     std::stack<int> stack;
-    std::string str("4+5*(1+1)");
+    std::string str("4+5*(3-1)");
 
     sregex group, factor, term, expression;
 
@@ -179,6 +208,7 @@
     test->add(BOOST_TEST_CASE(&test2));
     test->add(BOOST_TEST_CASE(&test3));
     test->add(BOOST_TEST_CASE(&test4));
+    test->add(BOOST_TEST_CASE(&test4_aux));
     test->add(BOOST_TEST_CASE(&test5));
     return test;
 }


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs

Reply via email to