Boost logo

Boost-Commit :

From: joel_at_[hidden]
Date: 2008-04-18 06:32:10


Author: djowel
Date: 2008-04-18 06:32:09 EDT (Fri, 18 Apr 2008)
New Revision: 44537
URL: http://svn.boost.org/trac/boost/changeset/44537

Log:
added actions test + bug fixes
Added:
   trunk/libs/spirit/test/qi/actions.cpp (contents, props changed)
Text files modified:
   trunk/libs/spirit/example/qi/actions.cpp | 6 ++++--
   trunk/libs/spirit/test/Jamfile | 1 +
   trunk/libs/spirit/test/qi/grammar_fail.cpp | 4 ++--
   3 files changed, 7 insertions(+), 4 deletions(-)

Modified: trunk/libs/spirit/example/qi/actions.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/actions.cpp (original)
+++ trunk/libs/spirit/example/qi/actions.cpp 2008-04-18 06:32:09 EDT (Fri, 18 Apr 2008)
@@ -33,26 +33,28 @@
 
 int main()
 {
- char const *s1 = "{42}", *e1 = s1 + std::strlen(s1);
-
     { // example using plain function
 
+ char const *s1 = "{42}", *e1 = s1 + std::strlen(s1);
         qi::parse(s1, e1, '{' >> int_[&write] >> '}');
     }
 
     { // example using simple function object
 
+ char const *s1 = "{43}", *e1 = s1 + std::strlen(s1);
         qi::parse(s1, e1, '{' >> int_[write_action()] >> '}');
     }
 
     { // example using boost.bind
 
+ char const *s1 = "{44}", *e1 = s1 + std::strlen(s1);
         qi::parse(s1, e1, '{' >> int_[boost::bind(&write, _1)] >> '}');
     }
 
     { // example using boost.lambda
 
         using boost::lambda::_1;
+ char const *s1 = "{45}", *e1 = s1 + std::strlen(s1);
         qi::parse(s1, e1, '{' >> int_[std::cout << _1 << '\n'] >> '}');
     }
 

Modified: trunk/libs/spirit/test/Jamfile
==============================================================================
--- trunk/libs/spirit/test/Jamfile (original)
+++ trunk/libs/spirit/test/Jamfile 2008-04-18 06:32:09 EDT (Fri, 18 Apr 2008)
@@ -14,6 +14,7 @@
     test-suite spirit_v2 :
 
     # run Qi tests
+ [ run qi/actions.cpp : : : : ]
     [ run qi/char.cpp : : : : ]
     [ run qi/char_class.cpp : : : : ]
     [ run qi/lit.cpp : : : : ]

Added: trunk/libs/spirit/test/qi/actions.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/qi/actions.cpp 2008-04-18 06:32:09 EDT (Fri, 18 Apr 2008)
@@ -0,0 +1,80 @@
+/*=============================================================================
+ Copyright (c) 2001-2008 Joel de Guzman
+
+ 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.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/bind.hpp>
+
+using namespace boost::spirit;
+
+int x = 0;
+
+void fun1(int const& i)
+{
+ x += i;
+}
+
+void fun2(int i)
+{
+ x += i;
+}
+
+void fun3(int& i)
+{
+ x += i;
+ i = 0;
+}
+
+struct fun_action
+{
+ void operator()(int const& i, unused_type, unused_type) const
+ {
+ x += i;
+ }
+};
+
+int main()
+{
+ {
+ char const *s1 = "{42}", *e1 = s1 + std::strlen(s1);
+ qi::parse(s1, e1, '{' >> int_[&fun1] >> '}');
+ }
+
+ {
+ char const *s1 = "{42}", *e1 = s1 + std::strlen(s1);
+ qi::parse(s1, e1, '{' >> int_[&fun2] >> '}');
+ }
+
+ {
+ char const *s1 = "{42}", *e1 = s1 + std::strlen(s1);
+ qi::parse(s1, e1, '{' >> int_[&fun3] >> '}');
+ }
+
+ {
+ char const *s1 = "{42}", *e1 = s1 + std::strlen(s1);
+ qi::parse(s1, e1, '{' >> int_[fun_action()] >> '}');
+ }
+
+ {
+ char const *s1 = "{42}", *e1 = s1 + std::strlen(s1);
+ qi::parse(s1, e1, '{' >> int_[boost::bind(&fun, _1)] >> '}');
+ }
+
+ {
+ using boost::lambda::_1;
+ using boost::lambda::var;
+ char const *s1 = "{42}", *e1 = s1 + std::strlen(s1);
+ qi::parse(s1, e1, '{' >> int_[var(x) += _1] >> '}');
+ }
+
+ BOOST_TEST(x == (42*6));
+ return 0;
+}
+
+
+
+

Modified: trunk/libs/spirit/test/qi/grammar_fail.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/grammar_fail.cpp (original)
+++ trunk/libs/spirit/test/qi/grammar_fail.cpp 2008-04-18 06:32:09 EDT (Fri, 18 Apr 2008)
@@ -33,10 +33,10 @@
 {
     char const* input = "some input, it doesn't matter";
     char const* end = &input[strlen(input)+1];
-
+
     num_list def;
     bool r = phrase_parse(input, end, make_parser(def),
- space | ('%' >> *~char_('\n') >> '\n'));
+ space | ('%' >> *~char_('\n') >> '\n'));
 
     return 0;
 }


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