]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/algorithm/string/test/split_test.cpp
1 // Boost string_algo library iterator_test.cpp file ---------------------------//
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)
8 // See http://www.boost.org for updates, documentation, and revision history.
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>
15 // Include unit test framework
16 #define BOOST_TEST_MAIN
17 #include <boost/test/unit_test.hpp>
24 #include <boost/test/test_tools.hpp>
28 using namespace boost
;
30 template< typename T1
, typename T2
>
31 void deep_compare( const T1
& X
, const T2
& Y
)
33 BOOST_REQUIRE( X
.size() == Y
.size() );
34 for( unsigned int nIndex
=0; nIndex
<X
.size(); ++nIndex
)
36 BOOST_CHECK( equals( X
[nIndex
], Y
[nIndex
] ) );
42 string
str1("xx-abc--xx-abb");
43 string
str2("Xx-abc--xX-abb-xx");
46 const char* pch1
="xx-abc--xx-abb";
47 vector
<string
> tokens
;
48 vector
< vector
<int> > vtokens
;
56 BOOST_REQUIRE( tokens
.size()==2 );
57 BOOST_CHECK( tokens
[0]==string("xx") );
58 BOOST_CHECK( tokens
[1]==string("xx") );
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") );
75 BOOST_REQUIRE( tokens
.size()==2 );
76 BOOST_CHECK( tokens
[0]==string("xx") );
77 BOOST_CHECK( tokens
[1]==string("xx") );
83 deep_compare( tokens
, vtokens
);
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("") );
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") );
114 deep_compare( tokens
, vtokens
);
120 token_compress_off
);
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") );
135 BOOST_REQUIRE( tokens
.size()==1 );
136 BOOST_CHECK( tokens
[0]==string("xx") );
144 BOOST_REQUIRE( tokens
.size()==1 );
145 BOOST_CHECK( tokens
[0]==string("") );
148 find_iterator
<string::iterator
> fiter
=make_find_iterator(str1
, first_finder("xx"));
149 find_iterator
<string::iterator
> fiter2
;
151 BOOST_CHECK(equals(*fiter
, "xx"));
155 BOOST_CHECK(equals(*fiter
, "xx"));
156 BOOST_CHECK(equals(*fiter2
, "xx"));
159 BOOST_CHECK(fiter
==find_iterator
<string::iterator
>());
160 BOOST_CHECK(equals(*fiter2
, "xx"));
163 BOOST_CHECK(fiter2
==find_iterator
<string::iterator
>());
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"));
171 BOOST_CHECK(equals(*siter
, "abc"));
172 BOOST_CHECK(equals(*siter2
, "abc"));
175 BOOST_CHECK(equals(*siter
, "xx"));
176 BOOST_CHECK(equals(*siter2
, "abc"));
179 BOOST_CHECK(equals(*siter
, "abb"));
181 BOOST_CHECK(siter
==split_iterator
<string::iterator
>(siter
));
182 BOOST_CHECK(siter
==split_iterator
<string::iterator
>());
184 // Make sure we work with forward iterators
187 find_iterator
<list
<char>::iterator
> liter
=make_find_iterator(l1
, first_finder("xx"));
190 BOOST_AUTO_TEST_CASE( test_main
)