Boost logo

Boost-Commit :

From: eric_at_[hidden]
Date: 2007-12-20 15:19:59


Author: eric_niebler
Date: 2007-12-20 15:19:59 EST (Thu, 20 Dec 2007)
New Revision: 42212
URL: http://svn.boost.org/trac/boost/changeset/42212

Log:
back out back change
Text files modified:
   branches/proto/v3/libs/xpressive/test/test_actions.cpp | 250 ++++++++++++++++++++--------------------
   1 files changed, 125 insertions(+), 125 deletions(-)

Modified: branches/proto/v3/libs/xpressive/test/test_actions.cpp
==============================================================================
--- branches/proto/v3/libs/xpressive/test/test_actions.cpp (original)
+++ branches/proto/v3/libs/xpressive/test/test_actions.cpp 2007-12-20 15:19:59 EST (Thu, 20 Dec 2007)
@@ -21,20 +21,20 @@
 // simple action which builds a string
 void test1()
 {
- //using namespace boost::xpressive;
+ using namespace boost::xpressive;
 
- //std::string result;
- //std::string str("foo bar baz foo bar baz");
- //sregex rx = (+_w)[ xp::ref(result) += _ ] >> *(' ' >> (+_w)[ xp::ref(result) += ',' + _ ]);
-
- //if(!regex_match(str, rx))
- //{
- // BOOST_ERROR("oops");
- //}
- //else
- //{
- // BOOST_CHECK_EQUAL(result, "foo,bar,baz,foo,bar,baz");
- //}
+ std::string result;
+ std::string str("foo bar baz foo bar baz");
+ sregex rx = (+_w)[ xp::ref(result) += _ ] >> *(' ' >> (+_w)[ xp::ref(result) += ',' + _ ]);
+
+ if(!regex_match(str, rx))
+ {
+ BOOST_ERROR("oops");
+ }
+ else
+ {
+ BOOST_CHECK_EQUAL(result, "foo,bar,baz,foo,bar,baz");
+ }
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -42,20 +42,20 @@
 // test backtracking over actions
 void test2()
 {
- //using namespace boost::xpressive;
+ using namespace boost::xpressive;
 
- //std::string result;
- //std::string str("foo bar baz foo bar baz");
- //sregex rx = (+_w)[ xp::ref(result) += _ ] >> *(' ' >> (+_w)[ xp::ref(result) += ',' + _ ]) >> repeat<4>(_);
-
- //if(!regex_match(str, rx))
- //{
- // BOOST_ERROR("oops");
- //}
- //else
- //{
- // BOOST_CHECK_EQUAL(result, "foo,bar,baz,foo,bar");
- //}
+ std::string result;
+ std::string str("foo bar baz foo bar baz");
+ sregex rx = (+_w)[ xp::ref(result) += _ ] >> *(' ' >> (+_w)[ xp::ref(result) += ',' + _ ]) >> repeat<4>(_);
+
+ if(!regex_match(str, rx))
+ {
+ BOOST_ERROR("oops");
+ }
+ else
+ {
+ BOOST_CHECK_EQUAL(result, "foo,bar,baz,foo,bar");
+ }
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -63,30 +63,30 @@
 // cast string to int, push back into list, use alternate ->* syntax
 void test3()
 {
-// using namespace boost::xpressive;
-//
-// std::list<int> result;
-// std::string str("1 23 456 7890");
-//#if BOOST_VERSION >= 103500
-// sregex rx = (+_d)[ xp::ref(result)->*push_back( as<int>(_) ) ]
-// >> *(' ' >> (+_d)[ xp::ref(result)->*push_back( as<int>(_) ) ]);
-//#else
-// sregex rx = (+_d)[ push_back(xp::ref(result), as<int>(_) ) ]
-// >> *(' ' >> (+_d)[ push_back(xp::ref(result), as<int>(_) ) ]);
-//#endif
-//
-// if(!regex_match(str, rx))
-// {
-// BOOST_ERROR("oops");
-// }
-// else
-// {
-// BOOST_REQUIRE_EQUAL(result.size(), 4u);
-// BOOST_CHECK_EQUAL(*result.begin(), 1);
-// BOOST_CHECK_EQUAL(*++result.begin(), 23);
-// BOOST_CHECK_EQUAL(*++++result.begin(), 456);
-// BOOST_CHECK_EQUAL(*++++++result.begin(), 7890);
-// }
+ using namespace boost::xpressive;
+
+ std::list<int> result;
+ std::string str("1 23 456 7890");
+#if BOOST_VERSION >= 103500
+ sregex rx = (+_d)[ xp::ref(result)->*push_back( as<int>(_) ) ]
+ >> *(' ' >> (+_d)[ xp::ref(result)->*push_back( as<int>(_) ) ]);
+#else
+ sregex rx = (+_d)[ push_back(xp::ref(result), as<int>(_) ) ]
+ >> *(' ' >> (+_d)[ push_back(xp::ref(result), as<int>(_) ) ]);
+#endif
+
+ if(!regex_match(str, rx))
+ {
+ BOOST_ERROR("oops");
+ }
+ else
+ {
+ BOOST_REQUIRE_EQUAL(result.size(), 4u);
+ BOOST_CHECK_EQUAL(*result.begin(), 1);
+ BOOST_CHECK_EQUAL(*++result.begin(), 23);
+ BOOST_CHECK_EQUAL(*++++result.begin(), 456);
+ BOOST_CHECK_EQUAL(*++++++result.begin(), 7890);
+ }
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -94,24 +94,24 @@
 // build a map of strings to integers
 void test4()
 {
- //using namespace boost::xpressive;
+ using namespace boost::xpressive;
+
+ std::map<std::string, int> result;
+ std::string str("aaa=>1 bbb=>23 ccc=>456");
+ sregex pair = ( (s1= +_w) >> "=>" >> (s2= +_d) )[ xp::ref(result)[s1] = as<int>(s2) ];
+ sregex rx = pair >> *(+_s >> pair);
 
- //std::map<std::string, int> result;
- //std::string str("aaa=>1 bbb=>23 ccc=>456");
- //sregex pair = ( (s1= +_w) >> "=>" >> (s2= +_d) )[ xp::ref(result)[s1] = as<int>(s2) ];
- //sregex rx = pair >> *(+_s >> pair);
-
- //if(!regex_match(str, 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);
- //}
+ if(!regex_match(str, 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);
+ }
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -160,66 +160,66 @@
 // calculator that calculates. This is just silly, but hey.
 void test5()
 {
- //using namespace boost::xpressive;
+ using namespace boost::xpressive;
 
- //// test for "local" variables.
- //local<int> left, right;
+ // test for "local" variables.
+ local<int> left, right;
 
- //// test for reference<> to an existing variable
- //std::stack<int> stack_;
- //reference<std::stack<int> > stack(stack_);
-
- //std::string str("4+5*(3-1)");
-
- //sregex group, factor, term, expression;
-
- //group = '(' >> by_ref(expression) >> ')';
- //factor = (+_d)[ push(stack, as<int>(_)) ] | group;
- //term = factor >> *(
- // ('*' >> factor)
- // [ right = top(stack)
- // , pop(stack)
- // , left = top(stack)
- // , pop(stack)
- // , push(stack, left * right)
- // ]
- // | ('/' >> factor)
- // [ right = top(stack)
- // , pop(stack)
- // , left = top(stack)
- // , pop(stack)
- // , push(stack, left / right)
- // ]
- // );
- //expression = term >> *(
- // ('+' >> term)
- // [ right = top(stack)
- // , pop(stack)
- // , left = top(stack)
- // , pop(stack)
- // , push(stack, left + right)
- // ]
- // | ('-' >> term)
- // [ right = top(stack)
- // , pop(stack)
- // , left = top(stack)
- // , pop(stack)
- // , push(stack, left - right)
- // ]
- // );
-
- //if(!regex_match(str, expression))
- //{
- // BOOST_ERROR("oops");
- //}
- //else
- //{
- // BOOST_REQUIRE_EQUAL(stack_.size(), 1u);
- // BOOST_CHECK_EQUAL(stack_.top(), 14);
-
- // BOOST_REQUIRE_EQUAL(stack.get().size(), 1u);
- // BOOST_CHECK_EQUAL(stack.get().top(), 14);
- //}
+ // test for reference<> to an existing variable
+ std::stack<int> stack_;
+ reference<std::stack<int> > stack(stack_);
+
+ std::string str("4+5*(3-1)");
+
+ sregex group, factor, term, expression;
+
+ group = '(' >> by_ref(expression) >> ')';
+ factor = (+_d)[ push(stack, as<int>(_)) ] | group;
+ term = factor >> *(
+ ('*' >> factor)
+ [ right = top(stack)
+ , pop(stack)
+ , left = top(stack)
+ , pop(stack)
+ , push(stack, left * right)
+ ]
+ | ('/' >> factor)
+ [ right = top(stack)
+ , pop(stack)
+ , left = top(stack)
+ , pop(stack)
+ , push(stack, left / right)
+ ]
+ );
+ expression = term >> *(
+ ('+' >> term)
+ [ right = top(stack)
+ , pop(stack)
+ , left = top(stack)
+ , pop(stack)
+ , push(stack, left + right)
+ ]
+ | ('-' >> term)
+ [ right = top(stack)
+ , pop(stack)
+ , left = top(stack)
+ , pop(stack)
+ , push(stack, left - right)
+ ]
+ );
+
+ if(!regex_match(str, expression))
+ {
+ BOOST_ERROR("oops");
+ }
+ else
+ {
+ BOOST_REQUIRE_EQUAL(stack_.size(), 1u);
+ BOOST_CHECK_EQUAL(stack_.top(), 14);
+
+ BOOST_REQUIRE_EQUAL(stack.get().size(), 1u);
+ BOOST_CHECK_EQUAL(stack.get().top(), 14);
+ }
 }
 
 using namespace boost::unit_test;


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