• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_front_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 <boost/spirit/include/classic_push_front_actor.hpp>
22 #include <boost/spirit/include/classic_lists.hpp>
23 
24 template<typename ContainerT>
push_front_test()25 void push_front_test()
26 {
27     using namespace BOOST_SPIRIT_CLASSIC_NS;
28 
29     const char* cp = "one,two,three";
30     const char* cp_first = cp;
31     const char* cp_last = cp + test_impl::string_length(cp);
32     const char* cp_i[] = {"one","two","three"};;
33     int i;
34     ContainerT c;
35     typename ContainerT::const_iterator it;
36 
37     scanner<char const*> scan( cp_first, cp_last );
38     match<> hit;
39 
40     hit = list_p( (*alpha_p)[ push_front_a(c)] , ch_p(',') ).parse(scan);
41     BOOST_CHECK(hit);
42     BOOST_CHECK_EQUAL(scan.first, scan.last);
43     BOOST_CHECK_EQUAL( c.size(), static_cast<typename ContainerT::size_type>(3));
44     for (i=2, it = c.begin();i>=0 && it != c.end();--i, ++it)
45         BOOST_CHECK_EQUAL( cp_i[i], *it);
46     scan.first = cp;
47 }
48 
push_front_action_test()49 void push_front_action_test()
50 {
51     push_front_test< std::deque<std::string> >();
52 }
53 
54