]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2003 Jonathan de Halleux (dehalleux@pelikhan.com) | |
3 | http://spirit.sourceforge.net/ | |
4 | ||
5 | Use, modification and distribution is subject to the Boost Software | |
6 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
7 | http://www.boost.org/LICENSE_1_0.txt) | |
8 | =============================================================================*/ | |
9 | ||
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | // Test suite for push_back_actor | |
12 | /////////////////////////////////////////////////////////////////////////////// | |
13 | ||
14 | #include "action_tests.hpp" | |
15 | #include <string> | |
16 | #include <vector> | |
17 | #include <deque> | |
18 | #include <cstring> | |
19 | #include <iostream> | |
20 | #include <boost/spirit/include/classic_core.hpp> | |
21 | #include <algorithm> | |
7c673cae FG |
22 | #include <boost/spirit/include/classic_push_back_actor.hpp> |
23 | #include <boost/spirit/include/classic_lists.hpp> | |
24 | ||
25 | template<typename ContainerT> | |
26 | void push_back_test() | |
27 | { | |
28 | using namespace BOOST_SPIRIT_CLASSIC_NS; | |
29 | ||
30 | const char* cp = "one,two,three"; | |
31 | const char* cp_first = cp; | |
32 | const char* cp_last = cp + test_impl::string_length(cp); | |
33 | const char* cp_i[] = {"one","two","three"}; | |
34 | int i; | |
35 | ContainerT c; | |
36 | typename ContainerT::const_iterator it; | |
37 | ||
38 | scanner<char const*> scan( cp_first, cp_last ); | |
39 | match<> hit; | |
40 | ||
41 | hit = list_p( (*alpha_p)[ push_back_a(c)] , ch_p(',') ).parse(scan); | |
42 | BOOST_CHECK(hit); | |
43 | BOOST_CHECK_EQUAL(scan.first, scan.last); | |
44 | BOOST_CHECK_EQUAL( c.size(), static_cast<typename ContainerT::size_type>(3)); | |
45 | for (i=0, it = c.begin();i<3 && it != c.end();++i, ++it) | |
46 | BOOST_CHECK_EQUAL( cp_i[i], *it); | |
47 | scan.first = cp; | |
48 | } | |
49 | ||
50 | void push_back_action_test() | |
51 | { | |
52 | push_back_test< std::deque<std::string> >(); | |
53 | push_back_test< std::vector<std::string> >(); | |
54 | } | |
55 |