1 // Copyright (c) 2001-2011 Hartmut Kaiser 2 // Copyright (c) 2009 Carl Barron 3 // 4 // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 7 #include <boost/detail/lightweight_test.hpp> 8 #include <boost/spirit/include/lex_lexertl.hpp> 9 #include <iostream> 10 #include <algorithm> 11 #include "matlib.h" 12 test_matrix(std::vector<std::vector<double>> const & x)13void test_matrix(std::vector<std::vector<double> > const& x) 14 { 15 BOOST_TEST(x.size() == 3); 16 BOOST_TEST(x[0].size() == 2 && x[0][0] == 1 && x[0][1] == 2); 17 BOOST_TEST(x[1].size() == 1 && x[1][0] == 3); 18 BOOST_TEST(x[2].size() == 3 && x[2][0] == 4 && x[2][1] == 5 && x[2][2] == 6); 19 } 20 main()21int main () 22 { 23 std::string input("[[1,2][3][4,5,6]]"); 24 25 std::vector<std::vector<double> > results; 26 typedef std::string::iterator iter; 27 typedef boost::spirit::lex::lexertl::actor_lexer< 28 boost::spirit::lex::lexertl::token<iter> 29 > lexer_type; 30 31 typedef matlib_tokens<lexer_type> matlib_type; 32 matlib_type matrix(results); 33 iter first = input.begin(); 34 35 try { 36 BOOST_TEST(boost::spirit::lex::tokenize(first, input.end(), matrix)); 37 test_matrix(results); 38 } 39 catch (std::runtime_error const& e) { 40 std::cerr << "caught exception: " << e.what() << std::endl; 41 BOOST_TEST(false); 42 } 43 return boost::report_errors(); 44 } 45