Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53086 - in trunk/libs/spirit/test: . karma
From: hartmut.kaiser_at_[hidden]
Date: 2009-05-18 11:26:58


Author: hkaiser
Date: 2009-05-18 11:26:57 EDT (Mon, 18 May 2009)
New Revision: 53086
URL: http://svn.boost.org/trac/boost/changeset/53086

Log:
Spirit: Added karma repeat tests
Added:
   trunk/libs/spirit/test/karma/repeat.cpp (contents, props changed)
Text files modified:
   trunk/libs/spirit/test/CMakeLists.txt | 3 ++-
   trunk/libs/spirit/test/Jamfile | 1 +
   2 files changed, 3 insertions(+), 1 deletions(-)

Modified: trunk/libs/spirit/test/CMakeLists.txt
==============================================================================
--- trunk/libs/spirit/test/CMakeLists.txt (original)
+++ trunk/libs/spirit/test/CMakeLists.txt 2009-05-18 11:26:57 EDT (Mon, 18 May 2009)
@@ -11,7 +11,7 @@
 boost_additional_test_dependencies(spirit BOOST_DEPENDS test variant function_types intrusive lambda assign iostreams math random dynamic_bitset fusion)
 message(STATUS "Boost/libs/spirit/test needs GCC C++ -ftemplate-depth-300 flag")
 
-message(STATUS "Check libs/range/test: need -Wall -Wunused here when under gcc")
+message(STATUS "Check libs/spirit/test: need -Wall -Wunused here when under gcc")
 set( test_compile_flags "")
 IF(CMAKE_COMPILER_IS_GNUCC)
   SET(test_compile_flags "-ftemplate-depth-300")
@@ -86,6 +86,7 @@
 boost_test_run(karma_pattern2 karma/pattern2.cpp COMPILE_FLAGS ${test_compile_flags})
 boost_test_run(karma_plus karma/plus.cpp COMPILE_FLAGS ${test_compile_flags})
 boost_test_run(karma_real_numerics karma/real_numerics.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(karma_repeat karma/repeat.cpp COMPILE_FLAGS ${test_compile_flags})
 boost_test_run(karma_right_alignment karma/right_alignment.cpp COMPILE_FLAGS ${test_compile_flags})
 boost_test_run(karma_sequence karma/sequence.cpp COMPILE_FLAGS ${test_compile_flags})
 boost_test_run(karma_stream karma/stream.cpp COMPILE_FLAGS ${test_compile_flags})

Modified: trunk/libs/spirit/test/Jamfile
==============================================================================
--- trunk/libs/spirit/test/Jamfile (original)
+++ trunk/libs/spirit/test/Jamfile 2009-05-18 11:26:57 EDT (Mon, 18 May 2009)
@@ -90,6 +90,7 @@
     [ run karma/pattern2.cpp : : : : karma_pattern2 ]
     [ run karma/plus.cpp : : : : karma_plus ]
     [ run karma/real_numerics.cpp : : : : ]
+ [ run karma/repeat.cpp : : : : karma_repeat ]
     [ run karma/right_alignment.cpp : : : : ]
     [ run karma/sequence.cpp : : : : karma_sequence ]
     [ run karma/stream.cpp : : : : karma_stream ]

Added: trunk/libs/spirit/test/karma/repeat.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/karma/repeat.cpp 2009-05-18 11:26:57 EDT (Mon, 18 May 2009)
@@ -0,0 +1,118 @@
+// Copyright (c) 2001-2009 Hartmut Kaiser
+//
+// 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/config/warning_disable.hpp>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/utility/enable_if.hpp>
+
+#include <boost/spirit/include/karma_operator.hpp>
+#include <boost/spirit/include/karma_char.hpp>
+#include <boost/spirit/include/karma_string.hpp>
+#include <boost/spirit/include/karma_numeric.hpp>
+#include <boost/spirit/include/karma_directive.hpp>
+#include <boost/spirit/include/karma_action.hpp>
+#include <boost/spirit/include/support_argument.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+
+#include <string>
+#include <iostream>
+#include <vector>
+
+#include "test.hpp"
+
+using namespace spirit_test;
+
+int main()
+{
+ using namespace boost::spirit::ascii;
+ using boost::spirit::karma::repeat;
+ using boost::spirit::karma::inf;
+ using boost::spirit::karma::int_;
+ using boost::spirit::karma::_1;
+
+ {
+ std::string str8("aaaaaaaa");
+ BOOST_TEST(test("aaaaaaaa", repeat[char_], str8)); // kleene synonym
+ BOOST_TEST(test("aaaaaaaa", repeat(8)[char_], str8));
+ BOOST_TEST(test("aaa", repeat(3)[char_], str8));
+ BOOST_TEST(!test("aaaaaaaa", repeat(9)[char_], str8));
+
+ std::string str3("aaa");
+ BOOST_TEST(test("aaaaa", repeat(3, 5)[char_], str8));
+ BOOST_TEST(test("aaa", repeat(3, 5)[char_], str3));
+ BOOST_TEST(!test("aaa", repeat(4, 5)[char_], str3));
+
+ BOOST_TEST(test("aaa", repeat(3, inf)[char_], str3));
+ BOOST_TEST(test("aaaaaaaa", repeat(3, inf)[char_], str8));
+ BOOST_TEST(!test("aaa", repeat(4, inf)[char_], str3));
+ }
+
+ {
+ std::string str8("aaaaaaaa");
+ BOOST_TEST(test_delimited("a a a a a a a a ", repeat[char_], str8, space));
+ BOOST_TEST(test_delimited("a a a a a a a a ", repeat(8)[char_], str8, space));
+ BOOST_TEST(test_delimited("a a a ", repeat(3)[char_], str8, space));
+ BOOST_TEST(!test_delimited("a a a a a a a a ", repeat(9)[char_], str8, space));
+
+ std::string str3("aaa");
+ BOOST_TEST(test_delimited("a a a a a ", repeat(3, 5)[char_], str8, space));
+ BOOST_TEST(test_delimited("a a a ", repeat(3, 5)[char_], str3, space));
+ BOOST_TEST(!test_delimited("a a a ", repeat(4, 5)[char_], str3, space));
+
+ BOOST_TEST(test_delimited("a a a ", repeat(3, inf)[char_], str3, space));
+ BOOST_TEST(test_delimited("a a a a a a a a ", repeat(3, inf)[char_], str8, space));
+ BOOST_TEST(!test_delimited("a a a ", repeat(4, inf)[char_], str3, space));
+ }
+
+ { // lazy repeats
+ using boost::phoenix::val;
+
+ std::string str8("aaaaaaaa");
+ BOOST_TEST(test("aaaaaaaa", repeat[char_], str8)); // kleene synonym
+ BOOST_TEST(test("aaaaaaaa", repeat(val(8))[char_], str8));
+ BOOST_TEST(test("aaa", repeat(val(3))[char_], str8));
+ BOOST_TEST(!test("aaaaaaaa", repeat(val(9))[char_], str8));
+
+ std::string str3("aaa");
+ BOOST_TEST(test("aaaaa", repeat(val(3), val(5))[char_], str8));
+ BOOST_TEST(test("aaa", repeat(val(3), val(5))[char_], str3));
+ BOOST_TEST(!test("aaa", repeat(val(4), val(5))[char_], str3));
+
+ BOOST_TEST(test("aaa", repeat(val(3), val(inf))[char_], str3));
+ BOOST_TEST(test("aaaaaaaa", repeat(val(3), val(inf))[char_], str8));
+ BOOST_TEST(!test("aaa", repeat(val(4), val(inf))[char_], str3));
+ }
+
+ {
+ std::string str("aBcdeFGH");
+ BOOST_TEST(test("abcdefgh", lower[repeat(8)[char_]], str));
+ BOOST_TEST(test_delimited("A B C D E F G H ", upper[repeat(8)[char_]], str, space));
+ }
+
+ { // actions
+ namespace phx = boost::phoenix;
+
+ std::vector<char> v;
+ v.push_back('a');
+ v.push_back('a');
+ v.push_back('a');
+ v.push_back('a');
+ BOOST_TEST(test("aaaa", repeat(4)[char_][_1 = phx::ref(v)]));
+ }
+
+ { // more actions
+ namespace phx = boost::phoenix;
+
+ std::vector<int> v;
+ v.push_back(123);
+ v.push_back(456);
+ v.push_back(789);
+ BOOST_TEST(test_delimited("123 456 789 ", repeat(3)[int_][_1 = phx::ref(v)], 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