Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60257 - in trunk/libs/spirit/test: . karma
From: hartmut.kaiser_at_[hidden]
Date: 2010-03-06 16:59:17


Author: hkaiser
Date: 2010-03-06 16:59:15 EST (Sat, 06 Mar 2010)
New Revision: 60257
URL: http://svn.boost.org/trac/boost/changeset/60257

Log:
Spirit: implemented new encoding features for Karma, added tests
Added:
   trunk/libs/spirit/test/karma/encoding.cpp (contents, props changed)
   trunk/libs/spirit/test/karma/pattern3.cpp (contents, props changed)
Text files modified:
   trunk/libs/spirit/test/Jamfile | 2 +
   trunk/libs/spirit/test/karma/auto.cpp | 3 -
   trunk/libs/spirit/test/karma/pattern2.cpp | 79 ----------------------------------------
   3 files changed, 3 insertions(+), 81 deletions(-)

Modified: trunk/libs/spirit/test/Jamfile
==============================================================================
--- trunk/libs/spirit/test/Jamfile (original)
+++ trunk/libs/spirit/test/Jamfile 2010-03-06 16:59:15 EST (Sat, 06 Mar 2010)
@@ -88,6 +88,7 @@
     [ run karma/char_class.cpp : : : : karma_char_class ]
     [ run karma/columns.cpp : : : : ]
     [ run karma/delimiter.cpp : : : : ]
+ [ run karma/encoding.cpp : : : : karma_encoding ]
     [ run karma/eol.cpp : : : : karma_eol ]
     [ run karma/eps.cpp : : : : karma_eps ]
     [ run karma/format_manip.cpp : : : : ]
@@ -107,6 +108,7 @@
     [ run karma/optional.cpp : : : : karma_optional ]
     [ run karma/pattern.cpp : : : : karma_pattern ]
     [ run karma/pattern2.cpp : : : : karma_pattern2 ]
+ [ run karma/pattern3.cpp : : : : karma_pattern3 ]
     [ run karma/plus.cpp : : : : karma_plus ]
     [ run karma/real_numerics.cpp : : : : ]
     [ run karma/repeat.cpp : : : : karma_repeat ]

Modified: trunk/libs/spirit/test/karma/auto.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/auto.cpp (original)
+++ trunk/libs/spirit/test/karma/auto.cpp 2010-03-06 16:59:15 EST (Sat, 06 Mar 2010)
@@ -5,9 +5,8 @@
 
 #include <boost/config/warning_disable.hpp>
 #include <boost/detail/lightweight_test.hpp>
-#include <boost/mpl/print.hpp>
-#include <boost/fusion/include/std_pair.hpp>
 
+#include <boost/fusion/include/std_pair.hpp>
 #include <boost/spirit/include/karma_bool.hpp>
 #include <boost/spirit/include/karma_char.hpp>
 #include <boost/spirit/include/karma_numeric.hpp>

Added: trunk/libs/spirit/test/karma/encoding.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/karma/encoding.cpp 2010-03-06 16:59:15 EST (Sat, 06 Mar 2010)
@@ -0,0 +1,84 @@
+// Copyright (c) 2001-2010 Hartmut Kaiser
+// Copyright (c) 2001-2010 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)
+
+// this file intentionally contains non-ascii characters
+// boostinspect:noascii
+
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/spirit/include/karma_char.hpp>
+#include <boost/spirit/include/karma_string.hpp>
+#include <boost/spirit/include/karma_directive.hpp>
+#include <boost/spirit/include/karma_action.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+
+#include <iostream>
+#include "test.hpp"
+
+int
+main()
+{
+ using spirit_test::test;
+ using boost::spirit::karma::lit;
+ using boost::spirit::karma::lower;
+ using boost::spirit::karma::upper;
+ using boost::spirit::karma::char_;
+ using boost::spirit::karma::encoding;
+ namespace char_encoding = boost::spirit::char_encoding;
+
+ encoding<char_encoding::iso8859_1> iso8859_1;
+
+// needed for VC7.1 only
+#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
+#pragma setlocale("french")
+#endif
+
+ {
+ BOOST_TEST(test("á", iso8859_1[lower['á']]));
+ BOOST_TEST(test("Á", iso8859_1[upper['á']]));
+ BOOST_TEST(test("á", iso8859_1[lower[char_('á')]]));
+ BOOST_TEST(test("Á", iso8859_1[upper[char_('á')]]));
+ BOOST_TEST(test("á", iso8859_1[lower[char_]], 'á'));
+ BOOST_TEST(test("Á", iso8859_1[upper[char_]], 'á'));
+ BOOST_TEST(test("á", iso8859_1[lower['Á']]));
+ BOOST_TEST(test("Á", iso8859_1[upper['Á']]));
+ BOOST_TEST(test("á", iso8859_1[lower[char_('Á')]]));
+ BOOST_TEST(test("Á", iso8859_1[upper[char_('Á')]]));
+ BOOST_TEST(test("á", iso8859_1[lower[char_]], 'Á'));
+ BOOST_TEST(test("Á", iso8859_1[upper[char_]], 'Á'));
+ }
+
+// {
+// BOOST_TEST(test("É", iso8859_1[no_case[char_("å-ï")]]));
+// BOOST_TEST(!test("ÿ", iso8859_1[no_case[char_("å-ï")]]));
+// }
+//
+// {
+// BOOST_TEST(test("Áá", iso8859_1[no_case["áÁ"]]));
+// BOOST_TEST(test("Áá", iso8859_1[no_case[lit("áÁ")]]));
+// }
+
+#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
+#pragma setlocale("")
+#endif
+
+// needed for VC7.1 only
+#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
+#pragma setlocale("german")
+#endif
+ {
+ BOOST_TEST(test("ää", iso8859_1[lower["Ää"]]));
+ BOOST_TEST(test("ää", iso8859_1[lower["Ää"]]));
+
+ BOOST_TEST(test("ÄÄ", iso8859_1[upper["Ää"]]));
+ BOOST_TEST(test("ÄÄ", iso8859_1[upper["Ää"]]));
+ }
+#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
+#pragma setlocale("")
+#endif
+
+ return boost::report_errors();
+}

Modified: trunk/libs/spirit/test/karma/pattern2.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/pattern2.cpp (original)
+++ trunk/libs/spirit/test/karma/pattern2.cpp 2010-03-06 16:59:15 EST (Sat, 06 Mar 2010)
@@ -100,85 +100,6 @@
         BOOST_TEST(test_delimited("12.4 ", start, v, space));
     }
 
- {
- karma::rule<outiter_type, void(char, int, double)> start;
- fusion::vector<char, int, double> vec('a', 10, 12.4);
-
- start = char_[_1 = _r1] << int_[_1 = _r2] << double_[_1 = _r3];
- BOOST_TEST(test("a1012.4", start('a', 10, 12.4)));
-
- start = (char_ << int_ << double_)[_1 = _r1, _2 = _r2, _3 = _r3];
- BOOST_TEST(test("a1012.4", start('a', 10, 12.4)));
-
- karma::rule<outiter_type, void(char)> a;
- karma::rule<outiter_type, void(int)> b;
- karma::rule<outiter_type, void(double)> c;
-
- a = char_[_1 = _r1];
- b = int_[_1 = _r1];
- c = double_[_1 = _r1];
- start = a(_r1) << b(_r2) << c(_r3);
- BOOST_TEST(test("a1012.4", start('a', 10, 12.4)));
- }
-
- {
- karma::rule<outiter_type, space_type, void(char, int, double)> start;
- fusion::vector<char, int, double> vec('a', 10, 12.4);
-
- start = char_[_1 = _r1] << int_[_1 = _r2] << double_[_1 = _r3];
- BOOST_TEST(test_delimited("a 10 12.4 ", start('a', 10, 12.4), space));
-
- start = (char_ << int_ << double_)[_1 = _r1, _2 = _r2, _3 = _r3];
- BOOST_TEST(test_delimited("a 10 12.4 ", start('a', 10, 12.4), space));
-
- karma::rule<outiter_type, space_type, void(char)> a;
- karma::rule<outiter_type, space_type, void(int)> b;
- karma::rule<outiter_type, space_type, void(double)> c;
-
- a = char_[_1 = _r1];
- b = int_[_1 = _r1];
- c = double_[_1 = _r1];
- start = a(_r1) << b(_r2) << c(_r3);
- BOOST_TEST(test_delimited("a 10 12.4 ", start('a', 10, 12.4), space));
- }
-
- // copy tests
- {
- typedef variant<char, int, double> var_type;
-
- karma::rule<outiter_type> a, b, c, start;
-
- a = 'a';
- b = int_(10);
- c = double_(12.4);
-
- // The FF is the dynamic equivalent of start = a << b << c;
- start = a;
- start = start.copy() << b;
- start = start.copy() << c;
- start = start.copy();
-
- BOOST_TEST(test("a1012.4", start));
- }
-
- {
- typedef variant<char, int, double> var_type;
-
- karma::rule<outiter_type, space_type> a, b, c, start;
-
- a = 'a';
- b = int_(10);
- c = double_(12.4);
-
- // The FF is the dynamic equivalent of start = a << b << c;
- start = a;
- start = start.copy() << b;
- start = start.copy() << c;
- start = start.copy();
-
- BOOST_TEST(test_delimited("a 10 12.4 ", start, space));
- }
-
     return boost::report_errors();
 }
 

Added: trunk/libs/spirit/test/karma/pattern3.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/karma/pattern3.cpp 2010-03-06 16:59:15 EST (Sat, 06 Mar 2010)
@@ -0,0 +1,154 @@
+// Copyright (c) 2001-2010 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/spirit/include/karma_operator.hpp>
+#include <boost/spirit/include/karma_char.hpp>
+#include <boost/spirit/include/karma_auxiliary.hpp>
+#include <boost/spirit/include/karma_string.hpp>
+#include <boost/spirit/include/karma_numeric.hpp>
+#include <boost/spirit/include/karma_nonterminal.hpp>
+#include <boost/spirit/include/karma_action.hpp>
+#include <boost/spirit/include/karma_directive.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+#include <boost/spirit/include/phoenix_statement.hpp>
+#include <boost/spirit/include/phoenix_fusion.hpp>
+
+#include "test.hpp"
+
+using namespace spirit_test;
+
+///////////////////////////////////////////////////////////////////////////////
+int main()
+{
+ using namespace boost;
+ using namespace boost::spirit;
+ using namespace boost::spirit::ascii;
+
+ typedef spirit_test::output_iterator<char>::type outiter_type;
+
+ {
+ karma::rule<outiter_type, void(char, int, double)> start;
+ fusion::vector<char, int, double> vec('a', 10, 12.4);
+
+ start = char_[_1 = _r1] << int_[_1 = _r2] << double_[_1 = _r3];
+ BOOST_TEST(test("a1012.4", start('a', 10, 12.4)));
+
+ start = (char_ << int_ << double_)[_1 = _r1, _2 = _r2, _3 = _r3];
+ BOOST_TEST(test("a1012.4", start('a', 10, 12.4)));
+
+ karma::rule<outiter_type, void(char)> a;
+ karma::rule<outiter_type, void(int)> b;
+ karma::rule<outiter_type, void(double)> c;
+
+ a = char_[_1 = _r1];
+ b = int_[_1 = _r1];
+ c = double_[_1 = _r1];
+ start = a(_r1) << b(_r2) << c(_r3);
+ BOOST_TEST(test("a1012.4", start('a', 10, 12.4)));
+ }
+
+ {
+ karma::rule<outiter_type, space_type, void(char, int, double)> start;
+ fusion::vector<char, int, double> vec('a', 10, 12.4);
+
+ start = char_[_1 = _r1] << int_[_1 = _r2] << double_[_1 = _r3];
+ BOOST_TEST(test_delimited("a 10 12.4 ", start('a', 10, 12.4), space));
+
+ start = (char_ << int_ << double_)[_1 = _r1, _2 = _r2, _3 = _r3];
+ BOOST_TEST(test_delimited("a 10 12.4 ", start('a', 10, 12.4), space));
+
+ karma::rule<outiter_type, space_type, void(char)> a;
+ karma::rule<outiter_type, space_type, void(int)> b;
+ karma::rule<outiter_type, space_type, void(double)> c;
+
+ a = char_[_1 = _r1];
+ b = int_[_1 = _r1];
+ c = double_[_1 = _r1];
+ start = a(_r1) << b(_r2) << c(_r3);
+ BOOST_TEST(test_delimited("a 10 12.4 ", start('a', 10, 12.4), space));
+ }
+
+ // copy tests
+ {
+ typedef variant<char, int, double> var_type;
+
+ karma::rule<outiter_type> a, b, c, start;
+
+ a = 'a';
+ b = int_(10);
+ c = double_(12.4);
+
+ // The FF is the dynamic equivalent of start = a << b << c;
+ start = a;
+ start = start.copy() << b;
+ start = start.copy() << c;
+ start = start.copy();
+
+ BOOST_TEST(test("a1012.4", start));
+ }
+
+ {
+ typedef variant<char, int, double> var_type;
+
+ karma::rule<outiter_type, space_type> a, b, c, start;
+
+ a = 'a';
+ b = int_(10);
+ c = double_(12.4);
+
+ // The FF is the dynamic equivalent of start = a << b << c;
+ start = a;
+ start = start.copy() << b;
+ start = start.copy() << c;
+ start = start.copy();
+
+ BOOST_TEST(test_delimited("a 10 12.4 ", start, space));
+ }
+
+#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
+#pragma setlocale("french")
+#endif
+ { // specifying the encoding
+ using karma::lower;
+ using karma::upper;
+ using karma::string;
+
+ typedef boost::spirit::char_encoding::iso8859_1 iso8859_1;
+ karma::rule<outiter_type, iso8859_1> r;
+
+ r = lower['á'];
+ BOOST_TEST(test("á", r));
+ r = lower[char_('Á')];
+ BOOST_TEST(test("á", r));
+ r = upper['á'];
+ BOOST_TEST(test("Á", r));
+ r = upper[char_('Á')];
+ BOOST_TEST(test("Á", r));
+
+ r = lower["áÁ"];
+ BOOST_TEST(test("áá", r));
+ r = lower[lit("áÁ")];
+ BOOST_TEST(test("áá", r));
+ r = lower[string("áÁ")];
+ BOOST_TEST(test("áá", r));
+ r = upper["áÁ"];
+ BOOST_TEST(test("ÁÁ", r));
+ r = upper[lit("áÁ")];
+ BOOST_TEST(test("ÁÁ", r));
+ r = upper[string("áÁ")];
+ BOOST_TEST(test("ÁÁ", r));
+ }
+
+#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
+#pragma setlocale("")
+#endif
+
+ 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