]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/algorithm/string/test/split_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / algorithm / string / test / split_test.cpp
1 // Boost string_algo library iterator_test.cpp file ---------------------------//
2
3 // Copyright Pavol Droba 2002-2003. Use, modification and
4 // distribution is subject to the Boost Software License, Version
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7
8 // See http://www.boost.org for updates, documentation, and revision history.
9
10 #include <boost/algorithm/string/split.hpp>
11 #include <boost/algorithm/string/classification.hpp>
12 // equals predicate is used for result comparison
13 #include <boost/algorithm/string/predicate.hpp>
14
15 // Include unit test framework
16 #define BOOST_TEST_MAIN
17 #include <boost/test/unit_test.hpp>
18
19 #include <string>
20 #include <vector>
21 #include <list>
22 #include <iostream>
23
24 #include <boost/test/test_tools.hpp>
25
26
27 using namespace std;
28 using namespace boost;
29
30 template< typename T1, typename T2 >
31 void deep_compare( const T1& X, const T2& Y )
32 {
33 BOOST_REQUIRE( X.size() == Y.size() );
34 for( unsigned int nIndex=0; nIndex<X.size(); ++nIndex )
35 {
36 BOOST_CHECK( equals( X[nIndex], Y[nIndex] ) );
37 }
38 }
39
40 void iterator_test()
41 {
42 string str1("xx-abc--xx-abb");
43 string str2("Xx-abc--xX-abb-xx");
44 string str3("xx");
45 string strempty("");
46 const char* pch1="xx-abc--xx-abb";
47 vector<string> tokens;
48 vector< vector<int> > vtokens;
49
50 // find_all tests
51 find_all(
52 tokens,
53 pch1,
54 "xx" );
55
56 BOOST_REQUIRE( tokens.size()==2 );
57 BOOST_CHECK( tokens[0]==string("xx") );
58 BOOST_CHECK( tokens[1]==string("xx") );
59
60 ifind_all(
61 tokens,
62 str2,
63 "xx" );
64
65 BOOST_REQUIRE( tokens.size()==3 );
66 BOOST_CHECK( tokens[0]==string("Xx") );
67 BOOST_CHECK( tokens[1]==string("xX") );
68 BOOST_CHECK( tokens[2]==string("xx") );
69
70 find_all(
71 tokens,
72 str1,
73 "xx" );
74
75 BOOST_REQUIRE( tokens.size()==2 );
76 BOOST_CHECK( tokens[0]==string("xx") );
77 BOOST_CHECK( tokens[1]==string("xx") );
78
79 find_all(
80 vtokens,
81 str1,
82 string("xx") );
83 deep_compare( tokens, vtokens );
84
85 // split tests
86 split(
87 tokens,
88 str2,
89 is_any_of("xX"),
90 token_compress_on );
91
92 BOOST_REQUIRE( tokens.size()==4 );
93 BOOST_CHECK( tokens[0]==string("") );
94 BOOST_CHECK( tokens[1]==string("-abc--") );
95 BOOST_CHECK( tokens[2]==string("-abb-") );
96 BOOST_CHECK( tokens[3]==string("") );
97
98 split(
99 tokens,
100 pch1,
101 is_any_of("x"),
102 token_compress_on );
103
104 BOOST_REQUIRE( tokens.size()==3 );
105 BOOST_CHECK( tokens[0]==string("") );
106 BOOST_CHECK( tokens[1]==string("-abc--") );
107 BOOST_CHECK( tokens[2]==string("-abb") );
108
109 split(
110 vtokens,
111 str1,
112 is_any_of("x"),
113 token_compress_on );
114 deep_compare( tokens, vtokens );
115
116 split(
117 tokens,
118 str1,
119 is_punct(),
120 token_compress_off );
121
122 BOOST_REQUIRE( tokens.size()==5 );
123 BOOST_CHECK( tokens[0]==string("xx") );
124 BOOST_CHECK( tokens[1]==string("abc") );
125 BOOST_CHECK( tokens[2]==string("") );
126 BOOST_CHECK( tokens[3]==string("xx") );
127 BOOST_CHECK( tokens[4]==string("abb") );
128
129 split(
130 tokens,
131 str3,
132 is_any_of(","),
133 token_compress_off);
134
135 BOOST_REQUIRE( tokens.size()==1 );
136 BOOST_CHECK( tokens[0]==string("xx") );
137
138 split(
139 tokens,
140 strempty,
141 is_punct(),
142 token_compress_off);
143
144 BOOST_REQUIRE( tokens.size()==1 );
145 BOOST_CHECK( tokens[0]==string("") );
146
147
148 find_iterator<string::iterator> fiter=make_find_iterator(str1, first_finder("xx"));
149 find_iterator<string::iterator> fiter2;
150
151 BOOST_CHECK(equals(*fiter, "xx"));
152 ++fiter;
153
154 fiter2 = fiter;
155 BOOST_CHECK(equals(*fiter, "xx"));
156 BOOST_CHECK(equals(*fiter2, "xx"));
157
158 ++fiter;
159 BOOST_CHECK(fiter==find_iterator<string::iterator>());
160 BOOST_CHECK(equals(*fiter2, "xx"));
161
162 ++fiter2;
163 BOOST_CHECK(fiter2==find_iterator<string::iterator>());
164
165 split_iterator<string::iterator> siter=make_split_iterator(str1, token_finder(is_any_of("-"), token_compress_on));
166 split_iterator<string::iterator> siter2;
167 BOOST_CHECK(equals(*siter, "xx"));
168 ++siter;
169
170 siter2 = siter;
171 BOOST_CHECK(equals(*siter, "abc"));
172 BOOST_CHECK(equals(*siter2, "abc"));
173
174 ++siter;
175 BOOST_CHECK(equals(*siter, "xx"));
176 BOOST_CHECK(equals(*siter2, "abc"));
177
178 ++siter;
179 BOOST_CHECK(equals(*siter, "abb"));
180 ++siter;
181 BOOST_CHECK(siter==split_iterator<string::iterator>(siter));
182 BOOST_CHECK(siter==split_iterator<string::iterator>());
183
184 // Make sure we work with forward iterators
185 // See bug #7989
186 list<char> l1;
187 find_iterator<list<char>::iterator> liter=make_find_iterator(l1, first_finder("xx"));
188 }
189
190 BOOST_AUTO_TEST_CASE( test_main )
191 {
192 iterator_test();
193 }