Boost logo

Boost-Commit :

From: hartmut.kaiser_at_[hidden]
Date: 2008-04-20 20:20:39


Author: hkaiser
Date: 2008-04-20 20:20:39 EDT (Sun, 20 Apr 2008)
New Revision: 44659
URL: http://svn.boost.org/trac/boost/changeset/44659

Log:
Spirit.Karma: Added actions test
Added:
   trunk/libs/spirit/test/karma/actions.cpp (contents, props changed)
Text files modified:
   trunk/libs/spirit/test/Jamfile | 1 +
   1 files changed, 1 insertions(+), 0 deletions(-)

Modified: trunk/libs/spirit/test/Jamfile
==============================================================================
--- trunk/libs/spirit/test/Jamfile (original)
+++ trunk/libs/spirit/test/Jamfile 2008-04-20 20:20:39 EDT (Sun, 20 Apr 2008)
@@ -53,6 +53,7 @@
     [ compile-fail qi/rule_fail.cpp : : ]
 
     # run Karma tests
+ [ run karma/actions.cpp : : : : karma_actions ]
     [ run karma/alternative.cpp : : : : karma_alternative ]
     [ run karma/binary.cpp : : : : karma_binary ]
     [ run karma/case_handling.cpp : : : : ]

Added: trunk/libs/spirit/test/karma/actions.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/karma/actions.cpp 2008-04-20 20:20:39 EDT (Sun, 20 Apr 2008)
@@ -0,0 +1,91 @@
+/*=============================================================================
+ Copyright (c) 2001-2008 Hartmut Kaiser
+ 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 <strstream>
+
+#include <boost/detail/lightweight_test.hpp>
+
+#include <boost/spirit/include/karma.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/bind.hpp>
+#include <boost/function_output_iterator.hpp>
+
+#include "test.hpp"
+
+using namespace spirit_test;
+using namespace boost::spirit;
+
+void read1(int& i)
+{
+ i = 42;
+}
+
+void read2(int& i, unused_type)
+{
+ i = 42;
+}
+
+void read3(int& i, unused_type, bool&)
+{
+ i = 42;
+}
+
+struct read_action
+{
+ void operator()(int& i, unused_type, unused_type) const
+ {
+ i = 42;
+ }
+};
+
+///////////////////////////////////////////////////////////////////////////////
+int main()
+{
+ using namespace boost::spirit::ascii;
+
+ {
+ BOOST_TEST(test("{42}", '{' << int_[&read1] << '}'));
+ BOOST_TEST(test_delimited("{ 42 } ", '{' << int_[&read1] << '}', space));
+ BOOST_TEST(test("{42}", '{' << int_[&read2] << '}'));
+ BOOST_TEST(test_delimited("{ 42 } ", '{' << int_[&read2] << '}', space));
+ BOOST_TEST(test("{42}", '{' << int_[&read3] << '}'));
+ BOOST_TEST(test_delimited("{ 42 } ", '{' << int_[&read3] << '}', space));
+ }
+
+ {
+ BOOST_TEST(test("{42}", '{' << int_[read_action()] << '}'));
+ BOOST_TEST(test_delimited("{ 42 } ", '{' << int_[read_action()] << '}', space));
+ }
+
+ {
+ BOOST_TEST(test("{42}", '{' << int_[boost::bind(&read1, _1)] << '}'));
+ BOOST_TEST(test_delimited("{ 42 } ",
+ '{' << int_[boost::bind(&read1, _1)] << '}', space));
+ BOOST_TEST(test("{42}", '{' << int_[boost::bind(&read2, _1, _2)] << '}'));
+ BOOST_TEST(test_delimited("{ 42 } ",
+ '{' << int_[boost::bind(&read2, _1, _2)] << '}', space));
+ BOOST_TEST(test("{42}", '{' << int_[boost::bind(&read3, _1, _2, _3)] << '}'));
+ BOOST_TEST(test_delimited("{ 42 } ",
+ '{' << int_[boost::bind(&read3, _1, _2, _3)] << '}', space));
+ }
+
+ {
+ using boost::lambda::_1;
+ {
+ std::stringstream strm("42");
+ BOOST_TEST(test("{42}", '{' << int_[strm >> _1] << '}'));
+ }
+ {
+ std::stringstream strm("42");
+ BOOST_TEST(test_delimited("{ 42 } ", '{' << int_[strm >> _1] << '}', space));
+ }
+ }
+
+ 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