]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/classic/test/actor/push_back_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / spirit / classic / test / actor / push_back_test.cpp
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>
22 #include <boost/bind.hpp>
23 #include <boost/spirit/include/classic_push_back_actor.hpp>
24 #include <boost/spirit/include/classic_lists.hpp>
25
26 template<typename ContainerT>
27 void push_back_test()
28 {
29 using namespace BOOST_SPIRIT_CLASSIC_NS;
30
31 const char* cp = "one,two,three";
32 const char* cp_first = cp;
33 const char* cp_last = cp + test_impl::string_length(cp);
34 const char* cp_i[] = {"one","two","three"};
35 int i;
36 ContainerT c;
37 typename ContainerT::const_iterator it;
38
39 scanner<char const*> scan( cp_first, cp_last );
40 match<> hit;
41
42 hit = list_p( (*alpha_p)[ push_back_a(c)] , ch_p(',') ).parse(scan);
43 BOOST_CHECK(hit);
44 BOOST_CHECK_EQUAL(scan.first, scan.last);
45 BOOST_CHECK_EQUAL( c.size(), static_cast<typename ContainerT::size_type>(3));
46 for (i=0, it = c.begin();i<3 && it != c.end();++i, ++it)
47 BOOST_CHECK_EQUAL( cp_i[i], *it);
48 scan.first = cp;
49 }
50
51 void push_back_action_test()
52 {
53 push_back_test< std::deque<std::string> >();
54 push_back_test< std::vector<std::string> >();
55 }
56