Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r61124 - in trunk/libs/spirit/test: . qi
From: hartmut.kaiser_at_[hidden]
Date: 2010-04-07 09:27:53


Author: hkaiser
Date: 2010-04-07 09:27:52 EDT (Wed, 07 Apr 2010)
New Revision: 61124
URL: http://svn.boost.org/trac/boost/changeset/61124

Log:
Spirit: added new test
Added:
   trunk/libs/spirit/test/qi/reorder_test.cpp (contents, props changed)
Text files modified:
   trunk/libs/spirit/test/Jamfile | 5 ++++-
   1 files changed, 4 insertions(+), 1 deletions(-)

Modified: trunk/libs/spirit/test/Jamfile
==============================================================================
--- trunk/libs/spirit/test/Jamfile (original)
+++ trunk/libs/spirit/test/Jamfile 2010-04-07 09:27:52 EDT (Wed, 07 Apr 2010)
@@ -134,6 +134,7 @@
     [ run lex/set_token_value_phoenix.cpp : : : : ]
     [ run lex/semantic_actions.cpp : : : : ]
 
+ # run Lex regression tests
     [ run lex/regression001.cpp : : : : lex_regression001 ]
     [ run lex/regression002.cpp : : : : lex_regression002 ]
     [ run lex/regression003_generate.cpp : $(LEX_DIR)/matlib_static.h : : : lex_regression003_generate ]
@@ -150,7 +151,9 @@
 
 
     # regression tests
- [ run qi/clear_test.cpp : : : : ]
+ [ run qi/clear_test.cpp : : : : ]
+ [ run qi/reorder_test.cpp : : : : ]
+
     ;
 
 }

Added: trunk/libs/spirit/test/qi/reorder_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/qi/reorder_test.cpp 2010-04-07 09:27:52 EDT (Wed, 07 Apr 2010)
@@ -0,0 +1,79 @@
+// Copyright (c) 2010 Olaf Peter
+// 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/detail/lightweight_test.hpp>
+
+#include <boost/spirit/include/qi.hpp>
+#include <boost/fusion/include/nview.hpp>
+
+namespace qi = boost::spirit::qi;
+namespace ascii = boost::spirit::ascii;
+namespace phx = boost::phoenix;
+namespace fusion = boost::fusion;
+namespace mpl = boost::mpl;
+
+int main()
+{
+ using fusion::result_of::as_nview;
+ using fusion::at_c;
+ using boost::optional;
+ using boost::variant;
+ using ascii::space_type;
+ using ascii::no_case;
+ using qi::lit;
+ using qi::double_;
+
+ typedef fusion::vector<
+ optional<double>, // 0 - U
+ optional<double>, // 1 - V
+ optional<double> // 2 - W
+ > uvw_type;
+
+ typedef as_nview<uvw_type, 0, 1, 2>::type uvw_reordered_type;
+ typedef as_nview<uvw_type, 2, 0, 1>::type vwu_reordered_type;
+
+ typedef char const* iterator_type;
+
+ qi::rule<iterator_type, optional<double>(), space_type> u,v,w;
+ qi::rule<iterator_type, uvw_reordered_type(), space_type> uvw;
+ qi::rule<iterator_type, vwu_reordered_type(), space_type> vwu;
+
+ u = no_case[ "NA" ] | ( double_ >> -lit( "U" ) );
+ v = no_case[ "NA" ] | ( double_ >> -lit( "V" ) );
+ w = no_case[ "NA" ] | ( double_ >> -lit( "W" ) );
+
+ uvw = u > v > w;
+ vwu = v > w > u;
+
+ uvw_type uvw_data;
+ {
+ iterator_type first = "1U 2V 3W";
+ iterator_type last = first + std::strlen(first);
+
+ uvw_reordered_type uvw_result( uvw_data );
+
+ BOOST_TEST(qi::phrase_parse(first, last, uvw, ascii::space, uvw_result));
+ BOOST_TEST(fusion::at_c<0>(uvw_result) && *fusion::at_c<0>(uvw_result) == 1);
+ BOOST_TEST(fusion::at_c<1>(uvw_result) && *fusion::at_c<1>(uvw_result) == 2);
+ BOOST_TEST(fusion::at_c<2>(uvw_result) && *fusion::at_c<2>(uvw_result) == 3);
+ }
+
+ {
+ iterator_type first = "2V 3W 1U";
+ iterator_type last = first + std::strlen(first);
+
+ vwu_reordered_type uvw_result(uvw_data);
+
+ BOOST_TEST(qi::phrase_parse(first, last, vwu, ascii::space, uvw_result));
+ BOOST_TEST(fusion::at_c<0>(uvw_result) && *fusion::at_c<0>(uvw_result) == 2);
+ BOOST_TEST(fusion::at_c<1>(uvw_result) && *fusion::at_c<1>(uvw_result) == 3);
+ BOOST_TEST(fusion::at_c<2>(uvw_result) && *fusion::at_c<2>(uvw_result) == 1);
+ }
+
+ 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