Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53236 - in trunk/libs/spirit/test: . lex
From: hartmut.kaiser_at_[hidden]
Date: 2009-05-24 23:24:46


Author: hkaiser
Date: 2009-05-24 23:24:42 EDT (Sun, 24 May 2009)
New Revision: 53236
URL: http://svn.boost.org/trac/boost/changeset/53236

Log:
Spirit: added more lexer tests
Added:
   trunk/libs/spirit/test/lex/regression003.cpp (contents, props changed)
   trunk/libs/spirit/test/lex/regression003_generate.cpp (contents, props changed)
Text files modified:
   trunk/libs/spirit/test/Jamfile | 4 ++++
   trunk/libs/spirit/test/lex/regression002.cpp | 5 +++--
   2 files changed, 7 insertions(+), 2 deletions(-)

Modified: trunk/libs/spirit/test/Jamfile
==============================================================================
--- trunk/libs/spirit/test/Jamfile (original)
+++ trunk/libs/spirit/test/Jamfile 2009-05-24 23:24:42 EDT (Sun, 24 May 2009)
@@ -17,6 +17,8 @@
     :
     ;
 
+path-constant LEX_DIR : $(BOOST_ROOT)/libs/spirit/test/lex ;
+
 # bring in rules for testing
 import testing ;
 
@@ -109,6 +111,8 @@
 
     [ 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 ]
+ [ run lex/regression003.cpp : : : <dependency>.//lex_regression003_generate : lex_regression003 ]
 
     ;
 

Modified: trunk/libs/spirit/test/lex/regression002.cpp
==============================================================================
--- trunk/libs/spirit/test/lex/regression002.cpp (original)
+++ trunk/libs/spirit/test/lex/regression002.cpp 2009-05-24 23:24:42 EDT (Sun, 24 May 2009)
@@ -25,7 +25,8 @@
     std::vector<std::vector<double> > results;
     typedef std::string::iterator iter;
     typedef boost::spirit::lex::lexertl::actor_lexer<
- boost::spirit::lex::lexertl::token<iter> > lexer_type;
+ boost::spirit::lex::lexertl::token<iter>
+ > lexer_type;
 
     typedef matlib_tokens<lexer_type> matlib_type;
     matlib_type matrix(results);
@@ -37,7 +38,7 @@
     }
     catch (std::runtime_error const& e) {
         std::cerr << "caught exception: " << e.what() << std::endl;
- return -1;
+ BOOST_TEST(false);
     }
     return boost::report_errors();
 }

Added: trunk/libs/spirit/test/lex/regression003.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/lex/regression003.cpp 2009-05-24 23:24:42 EDT (Sun, 24 May 2009)
@@ -0,0 +1,50 @@
+// Copyright (c) 2001-2009 Hartmut Kaiser
+// Copyright (c) 2009 Carl Barron
+//
+// 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/lex_static_lexertl.hpp>
+
+#include <iostream>
+#include <string>
+#include <vector>
+#include <exception>
+
+#include "matlib_static.h"
+#include "matlib.h"
+
+void test_matrix(std::vector<std::vector<double> > const& x)
+{
+ BOOST_TEST(x.size() == 3);
+ BOOST_TEST(x[0].size() == 2 && x[0][0] == 1 && x[0][1] == 2);
+ BOOST_TEST(x[1].size() == 1 && x[1][0] == 3);
+ BOOST_TEST(x[2].size() == 3 && x[2][0] == 4 && x[2][1] == 5 && x[2][2] == 6);
+}
+
+int main()
+{
+ std::string input("[[1,2][3][4,5,6]]");
+ std::vector<std::vector<double> > results;
+
+ typedef std::string::iterator iter;
+ typedef boost::spirit::lex::lexertl::static_actor_lexer<
+ boost::spirit::lex::lexertl::token<iter>,
+ boost::spirit::lex::lexertl::static_::lexer_matlib
+ > lexer_type;
+
+ typedef matlib_tokens<lexer_type> matlib_type;
+ matlib_type matrix(results);
+ iter first = input.begin();
+
+ try {
+ BOOST_TEST(boost::spirit::lex::tokenize(first, input.end(), matrix));
+ test_matrix(results);
+ }
+ catch (std::runtime_error const& e) {
+ std::cerr << e.what() << '\n';
+ BOOST_TEST(false);
+ }
+ return boost::report_errors();
+}

Added: trunk/libs/spirit/test/lex/regression003_generate.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/lex/regression003_generate.cpp 2009-05-24 23:24:42 EDT (Sun, 24 May 2009)
@@ -0,0 +1,32 @@
+// Copyright (c) 2001-2009 Hartmut Kaiser
+// Copyright (c) 2009 Carl Barron
+//
+// 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/lex_lexertl.hpp>
+#include <boost/spirit/include/lex_generate_static_lexertl.hpp>
+
+#include <fstream>
+#include <vector>
+
+#include "matlib.h"
+
+int main(int argc, char* argv[])
+{
+ std::vector<std::vector<double> > results;
+
+ typedef std::string::iterator iter;
+ typedef boost::spirit::lex::lexertl::actor_lexer<
+ boost::spirit::lex::lexertl::token<iter>
+ > lexer_type;
+
+ typedef matlib_tokens<lexer_type> matlib_type;
+ matlib_type matrix(results);
+
+ std::ofstream out(argc < 2 ? "matlib_static.h" : argv[1]);
+ BOOST_TEST(boost::spirit::lex::lexertl::generate_static(matrix, out, "matlib"));
+ 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