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/spirit/include/lex_lexertl.hpp>
8
9#include <boost/core/lightweight_test.hpp>
10#include <iostream>
11#include <algorithm>
12#include "matlib.h"
13
14void test_matrix(std::vector<std::vector<double> > const& x)
15{
16 BOOST_TEST(x.size() == 3);
17 BOOST_TEST(x[0].size() == 2 && x[0][0] == 1 && x[0][1] == 2);
18 BOOST_TEST(x[1].size() == 1 && x[1][0] == 3);
19 BOOST_TEST(x[2].size() == 3 && x[2][0] == 4 && x[2][1] == 5 && x[2][2] == 6);
20}
21
22int main ()
23{
24 std::string input("[[1,2][3][4,5,6]]");
25
26 std::vector<std::vector<double> > results;
27 typedef std::string::iterator iter;
28 typedef boost::spirit::lex::lexertl::actor_lexer<
29 boost::spirit::lex::lexertl::token<iter>
30 > lexer_type;
31
32 typedef matlib_tokens<lexer_type> matlib_type;
33 matlib_type matrix(results);
34 iter first = input.begin();
35
36 try {
37 BOOST_TEST(boost::spirit::lex::tokenize(first, input.end(), matrix));
38 test_matrix(x: results);
39 }
40 catch (std::runtime_error const& e) {
41 std::cerr << "caught exception: " << e.what() << std::endl;
42 BOOST_TEST(false);
43 }
44 return boost::report_errors();
45}
46

source code of boost/libs/spirit/test/lex/regression_matlib_dynamic.cpp