| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | //  Boost string_algo library substr_test.cpp file  ------------------//
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //  Copyright Pavol Droba 2002-2003. Use, modification and
 | 
					
						
							|  |  |  | //  distribution is subject to the Boost Software License, Version
 | 
					
						
							|  |  |  | //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
 | 
					
						
							|  |  |  | //  http://www.boost.org/LICENSE_1_0.txt)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //  See http://www.boost.org for updates, documentation, and revision history.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-16 14:10:08 +00:00
										 |  |  | #include <boost/algorithm/string/replace.hpp>
 | 
					
						
							|  |  |  | #include <boost/algorithm/string/erase.hpp>
 | 
					
						
							|  |  |  | #include <boost/algorithm/string/std/list_traits.hpp>
 | 
					
						
							|  |  |  | #include <boost/algorithm/string/std/string_traits.hpp>
 | 
					
						
							| 
									
										
										
										
											2011-06-03 21:13:37 +00:00
										 |  |  | #include <boost/algorithm/string/finder.hpp>
 | 
					
						
							|  |  |  | #include <boost/algorithm/string/formatter.hpp>
 | 
					
						
							|  |  |  | #include <boost/algorithm/string/classification.hpp>
 | 
					
						
							| 
									
										
										
										
											2004-07-16 14:10:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | // Include unit test framework
 | 
					
						
							| 
									
										
										
										
											2013-02-25 18:43:26 +00:00
										 |  |  | #define BOOST_TEST_MAIN
 | 
					
						
							|  |  |  | #include <boost/test/unit_test.hpp>
 | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <string>
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | #include <list>
 | 
					
						
							|  |  |  | #include <iostream>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // equals predicate is used for result comparison
 | 
					
						
							|  |  |  | #include <boost/algorithm/string/predicate.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <boost/test/test_tools.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | using namespace boost; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void sequence_traits_test() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // basic_string traits
 | 
					
						
							|  |  |  |     BOOST_CHECK( boost::algorithm::has_native_replace<string>::value ); | 
					
						
							|  |  |  |     BOOST_CHECK( !boost::algorithm::has_stable_iterators<string>::value ); | 
					
						
							|  |  |  |     BOOST_CHECK( !boost::algorithm::has_const_time_insert<string>::value );     | 
					
						
							|  |  |  |     BOOST_CHECK( !boost::algorithm::has_const_time_erase<string>::value );  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // vector traits
 | 
					
						
							|  |  |  |     BOOST_CHECK( !boost::algorithm::has_native_replace< vector<char> >::value ); | 
					
						
							|  |  |  |     BOOST_CHECK( !boost::algorithm::has_stable_iterators< vector<char> >::value ); | 
					
						
							|  |  |  |     BOOST_CHECK( !boost::algorithm::has_const_time_insert< vector<char> >::value );     | 
					
						
							|  |  |  |     BOOST_CHECK( !boost::algorithm::has_const_time_erase< vector<char> >::value );  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // list traits
 | 
					
						
							|  |  |  |     BOOST_CHECK( !boost::algorithm::has_native_replace< list<char> >::value ); | 
					
						
							|  |  |  |     BOOST_CHECK( boost::algorithm::has_stable_iterators< list<char> >::value ); | 
					
						
							|  |  |  |     BOOST_CHECK( boost::algorithm::has_const_time_insert< list<char> >::value );    | 
					
						
							|  |  |  |     BOOST_CHECK( boost::algorithm::has_const_time_erase< list<char> >::value );     | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Combine tests for all variants of the algorithm
 | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  | #define C_ ,
 | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | #define TEST_ALGO( Algo, Input, Params, Output ) \
 | 
					
						
							|  |  |  | {\ | 
					
						
							| 
									
										
										
										
											2013-02-25 18:43:26 +00:00
										 |  |  |     BOOST_TEST_CHECKPOINT( #Algo " - Copy" );\ | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | \ | 
					
						
							|  |  |  |     string str1(Input);\ | 
					
						
							|  |  |  | \ | 
					
						
							|  |  |  |     /* Copy test */ \ | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     BOOST_CHECK( Algo##_copy( str1, Params )==Output );\ | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | \ | 
					
						
							| 
									
										
										
										
											2013-02-25 18:43:26 +00:00
										 |  |  |     BOOST_TEST_CHECKPOINT( #Algo " - Iterator" );\ | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |     /* Iterator test */\ | 
					
						
							|  |  |  |     string strout;\ | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     Algo##_copy( back_inserter(strout), str1, Params );\ | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |     BOOST_CHECK( strout==Output ); \ | 
					
						
							|  |  |  | \ | 
					
						
							|  |  |  |     /* In-place test */\ | 
					
						
							|  |  |  |     vector<char> vec1( str1.begin(), str1.end() );\ | 
					
						
							|  |  |  |     list<char> list1( str1.begin(), str1.end() );\ | 
					
						
							| 
									
										
										
										
											2004-03-09 18:25:03 +00:00
										 |  |  | \ | 
					
						
							| 
									
										
										
										
											2013-02-25 18:43:26 +00:00
										 |  |  |     BOOST_TEST_CHECKPOINT( #Algo " - Inplace(string)" );\ | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     Algo( str1, Params ); \ | 
					
						
							| 
									
										
										
										
											2004-03-12 10:11:18 +00:00
										 |  |  |     BOOST_CHECK( equals( str1, Output ) ); \ | 
					
						
							|  |  |  | \ | 
					
						
							| 
									
										
										
										
											2013-02-25 18:43:26 +00:00
										 |  |  |     BOOST_TEST_CHECKPOINT( #Algo " - Inplace(vector)" );\ | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     Algo( vec1, Params ); \ | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |     BOOST_CHECK( equals( vec1, Output ) );\ | 
					
						
							| 
									
										
										
										
											2004-03-12 10:11:18 +00:00
										 |  |  | \ | 
					
						
							| 
									
										
										
										
											2013-02-25 18:43:26 +00:00
										 |  |  |     BOOST_TEST_CHECKPOINT( #Algo " - Inplace(list)" );\ | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     Algo( list1, Params ); \ | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |     BOOST_CHECK( equals( list1, Output ) );\ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-30 07:44:43 +00:00
										 |  |  | void replace_first_test() | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     // replace first
 | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     TEST_ALGO( replace_first, "1abc3abc2", string("abc") C_ string("YYY"), string("1YYY3abc2") ); | 
					
						
							|  |  |  |     TEST_ALGO( ireplace_first, "1AbC3abc2", "aBc" C_ "YYY", string("1YYY3abc2") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_first, "1abc3abc2", string("abc") C_ string("Z"), string("1Z3abc2") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_first, "1abc3abc2", string("abc") C_ string("XXXX"), string("1XXXX3abc2") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_first, "1abc3abc2", string("") C_ string("XXXX"), string("1abc3abc2") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_first, "1abc3abc2", "" C_ "XXXX", string("1abc3abc2") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_first, "", string("") C_ string("XXXX"), string("") ); | 
					
						
							|  |  |  |     TEST_ALGO( erase_first, "1abc3abc2", string("abc"), string("13abc2") ); | 
					
						
							|  |  |  |     TEST_ALGO( ierase_first, "1aBc3abc2", "abC", "13abc2" ); | 
					
						
							|  |  |  |     TEST_ALGO( erase_first, "1abc3abc2", "abc", "13abc2" ); | 
					
						
							|  |  |  |     TEST_ALGO( erase_first, "1abc3abc2", string(""), string("1abc3abc2") ); | 
					
						
							|  |  |  |     TEST_ALGO( erase_first, "", string("abc"), string("") ); | 
					
						
							| 
									
										
										
										
											2004-07-30 07:44:43 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-30 07:44:43 +00:00
										 |  |  | void replace_last_test() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |     // replace last
 | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     TEST_ALGO( replace_last, "1abc3abc2", string("abc") C_ string("YYY"), string("1abc3YYY2") ); | 
					
						
							|  |  |  |     TEST_ALGO( ireplace_last, "1abc3AbC2", "aBc" C_ "YYY", string("1abc3YYY2") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_last, "1abc3abc2", string("abc") C_ string("Z"), string("1abc3Z2") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_last, "1abc3abc2", string("abc") C_ string("XXXX"), string("1abc3XXXX2") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_last, "1abc3abc2", "abc" C_ "XXXX", string("1abc3XXXX2") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_last, "", string("") C_ string("XXXX"), string("") ); | 
					
						
							|  |  |  |     TEST_ALGO( erase_last, "1abc3abc2", string("abc"), string("1abc32") ); | 
					
						
							|  |  |  |     TEST_ALGO( ierase_last, "1aBc3aBc2", "ABC", string("1aBc32") ); | 
					
						
							|  |  |  |     TEST_ALGO( erase_last, "1abc3abc2", "abc", string("1abc32") ); | 
					
						
							|  |  |  |     TEST_ALGO( erase_last, "1abc3abc2", string(""), string("1abc3abc2") ); | 
					
						
							|  |  |  |     TEST_ALGO( erase_last, "", string("abc"), string("") ); | 
					
						
							| 
									
										
										
										
											2004-07-30 07:44:43 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-30 07:44:43 +00:00
										 |  |  | void replace_all_test() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |     // replace all
 | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     TEST_ALGO( replace_all, "1abc3abc2", string("abc") C_ string("YYY"), string("1YYY3YYY2") ); | 
					
						
							| 
									
										
										
										
											2008-06-19 12:07:24 +00:00
										 |  |  |     TEST_ALGO( replace_all, string("1abc3abc2"), "/" C_ "\\", string("1abc3abc2") ); | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     TEST_ALGO( ireplace_all, "1aBc3AbC2", "abC" C_ "YYY", string("1YYY3YYY2") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_all, "1abc3abc2", string("abc") C_ string("Z"), string("1Z3Z2") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_all, "1abc3abc2", string("abc") C_ string("XXXX"), string("1XXXX3XXXX2") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_all, "1abc3abc2", "abc" C_ "XXXX", string("1XXXX3XXXX2") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_all, "", string("") C_ string("XXXX"), string("") ); | 
					
						
							|  |  |  |     TEST_ALGO( erase_all, "1abc3abc2", string("abc"), string("132") ); | 
					
						
							|  |  |  |     TEST_ALGO( ierase_all, "1aBc3aBc2", "aBC", string("132") ); | 
					
						
							|  |  |  |     TEST_ALGO( erase_all, "1abc3abc2", "abc", string("132") ); | 
					
						
							|  |  |  |     TEST_ALGO( erase_all, "1abc3abc2", string(""), string("1abc3abc2") ); | 
					
						
							|  |  |  |     TEST_ALGO( erase_all, "", string("abc"), string("") ); | 
					
						
							| 
									
										
										
										
											2004-07-30 07:44:43 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-30 07:44:43 +00:00
										 |  |  | void replace_nth_test() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |     // replace nth
 | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ 0 C_ string("YYY"), string("1YYY3abc2") ); | 
					
						
							| 
									
										
										
										
											2006-02-14 09:39:03 +00:00
										 |  |  |     TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ -1 C_ string("YYY"), string("1abc3YYY2") ); | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     TEST_ALGO( ireplace_nth, "1AbC3abc2", "aBc" C_ 0 C_ "YYY", string("1YYY3abc2") ); | 
					
						
							| 
									
										
										
										
											2006-02-14 09:39:03 +00:00
										 |  |  |     TEST_ALGO( ireplace_nth, "1AbC3abc2", "aBc" C_ -1 C_ "YYY", string("1AbC3YYY2") ); | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ 0 C_ string("Z"), string("1Z3abc2") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ 0 C_ string("XXXX"), string("1XXXX3abc2") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_nth, "1abc3abc2", "abc" C_ 0 C_ "XXXX", string("1XXXX3abc2") ); | 
					
						
							| 
									
										
										
										
											2006-02-14 09:39:03 +00:00
										 |  |  |     TEST_ALGO( replace_nth, "1abc3abc2", "abc" C_ 3 C_ "XXXX", string("1abc3abc2") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_nth, "1abc3abc2", "abc" C_ -3 C_ "XXXX", string("1abc3abc2") ); | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     TEST_ALGO( replace_nth, "1abc3abc2", string("") C_ 0 C_ string("XXXX"), string("1abc3abc2") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_nth, "", string("") C_ 0 C_ string("XXXX"), string("") ); | 
					
						
							| 
									
										
										
										
											2006-02-14 09:39:03 +00:00
										 |  |  |     TEST_ALGO( replace_nth, "", string("") C_ -1 C_ string("XXXX"), string("") ); | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     TEST_ALGO( erase_nth, "1abc3abc2", string("abc") C_ 0, string("13abc2") ); | 
					
						
							| 
									
										
										
										
											2006-02-14 09:39:03 +00:00
										 |  |  |     TEST_ALGO( erase_nth, "1abc3abc2", string("abc") C_ -1, string("1abc32") ); | 
					
						
							|  |  |  |     TEST_ALGO( erase_nth, "1abc3abc2", string("abc") C_ -3, string("1abc3abc2") ); | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     TEST_ALGO( ierase_nth, "1aBc3aBc2", "ABC" C_ 0, string("13aBc2") ); | 
					
						
							| 
									
										
										
										
											2006-02-14 09:39:03 +00:00
										 |  |  |     TEST_ALGO( ierase_nth, "1aBc3aBc2", "ABC" C_ -1, string("1aBc32") ); | 
					
						
							|  |  |  |     TEST_ALGO( ierase_nth, "1aBc3aBc2", "ABC" C_ -3, string("1aBc3aBc2") ); | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     TEST_ALGO( erase_nth, "1abc3abc2", "abc" C_ 0, string("13abc2") ); | 
					
						
							|  |  |  |     TEST_ALGO( erase_nth, "1abc3abc2", string("") C_ 0, string("1abc3abc2") ); | 
					
						
							|  |  |  |     TEST_ALGO( erase_nth, "", string("abc") C_ 0, string("") ); | 
					
						
							| 
									
										
										
										
											2006-02-14 09:39:03 +00:00
										 |  |  |     TEST_ALGO( erase_nth, "", string("abc") C_ -1, string("") ); | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ 1 C_ string("YYY"), string("1abc3YYY2") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ 2 C_ string("YYY"), string("1abc3abc2") ); | 
					
						
							| 
									
										
										
										
											2004-07-30 07:44:43 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-30 07:44:43 +00:00
										 |  |  | void replace_head_test() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |     // replace head
 | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     TEST_ALGO( replace_head, "abc3abc2", 3 C_ string("YYY"), string("YYY3abc2") ); | 
					
						
							| 
									
										
										
										
											2006-02-14 09:39:03 +00:00
										 |  |  |     TEST_ALGO( replace_head, "abc3abc2", -3 C_ string("YYY"), string("YYYbc2") ); | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     TEST_ALGO( replace_head, "abc3abc2", 3 C_ "YYY", string("YYY3abc2") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_head, "abc", 3 C_ string("Z"), string("Z") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_head, "abc", 6 C_ string("XXXX"), string("XXXX") ); | 
					
						
							| 
									
										
										
										
											2006-02-14 09:39:03 +00:00
										 |  |  |     TEST_ALGO( replace_head, "abc", -6 C_ string("XXXX"), string("abc") ); | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     TEST_ALGO( replace_head, "abc3abc2", 0 C_ string("XXXX"), string("abc3abc2") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_head, "", 4 C_ string("XXXX"), string("") ); | 
					
						
							| 
									
										
										
										
											2006-02-14 09:39:03 +00:00
										 |  |  |     TEST_ALGO( replace_head, "", -4 C_ string("XXXX"), string("") ); | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     TEST_ALGO( erase_head, "abc3abc2", 3, string("3abc2") ); | 
					
						
							| 
									
										
										
										
											2006-02-14 09:39:03 +00:00
										 |  |  |     TEST_ALGO( erase_head, "abc3abc2", -3, string("bc2") ); | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     TEST_ALGO( erase_head, "abc3abc2", 0, string("abc3abc2") ); | 
					
						
							|  |  |  |     TEST_ALGO( erase_head, "", 4, string("") ); | 
					
						
							| 
									
										
										
										
											2006-02-14 09:39:03 +00:00
										 |  |  |     TEST_ALGO( erase_head, "", -4, string("") ); | 
					
						
							| 
									
										
										
										
											2004-07-30 07:44:43 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-30 07:44:43 +00:00
										 |  |  | void replace_tail_test() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |     // replace tail
 | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     TEST_ALGO( replace_tail, "abc3abc", 3 C_ string("YYY"), string("abc3YYY") ); | 
					
						
							| 
									
										
										
										
											2006-01-31 12:37:06 +00:00
										 |  |  |     TEST_ALGO( replace_tail, "abc3abc", -3 C_ "YYY", string("abcYYY") ); | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     TEST_ALGO( replace_tail, "abc", 3 C_ string("Z"), string("Z") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_tail, "abc", 6 C_ string("XXXX"), string("XXXX") ); | 
					
						
							| 
									
										
										
										
											2006-02-14 09:39:03 +00:00
										 |  |  |     TEST_ALGO( replace_tail, "abc", -6 C_ string("XXXX"), string("abc") ); | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     TEST_ALGO( replace_tail, "abc3abc", 0 C_ string("XXXX"), string("abc3abc") ); | 
					
						
							|  |  |  |     TEST_ALGO( replace_tail, "", 4 C_ string("XXXX"), string("") ); | 
					
						
							| 
									
										
										
										
											2006-02-14 09:39:03 +00:00
										 |  |  |     TEST_ALGO( replace_tail, "", -4 C_ string("XXXX"), string("") ); | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     TEST_ALGO( erase_tail, "abc3abc", 3, string("abc3") ); | 
					
						
							| 
									
										
										
										
											2006-02-14 09:39:03 +00:00
										 |  |  |     TEST_ALGO( erase_tail, "abc3abc", -3, string("abc") ); | 
					
						
							| 
									
										
										
										
											2004-08-06 15:50:35 +00:00
										 |  |  |     TEST_ALGO( erase_tail, "abc3abc", 0, string("abc3abc") ); | 
					
						
							|  |  |  |     TEST_ALGO( erase_tail, "", 4, string("") ); | 
					
						
							| 
									
										
										
										
											2006-02-14 09:39:03 +00:00
										 |  |  |     TEST_ALGO( erase_tail, "", -4, string("") ); | 
					
						
							| 
									
										
										
										
											2004-07-30 07:44:43 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-30 07:44:43 +00:00
										 |  |  | void replace_range_test() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |     // replace_range
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2013-02-25 18:43:26 +00:00
										 |  |  |         BOOST_TEST_CHECKPOINT( "replace_range" ); | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         string str1("1abc3abc2"); | 
					
						
							|  |  |  |         BOOST_CHECK(  | 
					
						
							|  |  |  |             replace_range_copy(  | 
					
						
							|  |  |  |                 str1,  | 
					
						
							|  |  |  |                 make_iterator_range(str1.begin()+1, str1.begin()+4), | 
					
						
							|  |  |  |                 string("XXX") )==string("1XXX3abc2") ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         string strout; | 
					
						
							|  |  |  |         replace_range_copy(  | 
					
						
							|  |  |  |                 back_inserter( strout ), | 
					
						
							|  |  |  |                 str1,  | 
					
						
							|  |  |  |                 make_iterator_range(str1.begin()+1, str1.begin()+4), | 
					
						
							|  |  |  |                 string("XXX") ); | 
					
						
							|  |  |  |         BOOST_CHECK( strout==string("1XXX3abc2") ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         replace_range(  | 
					
						
							|  |  |  |                 str1,  | 
					
						
							|  |  |  |                 make_iterator_range(str1.begin()+1, str1.begin()+4), | 
					
						
							|  |  |  |                 string("XXX") ); | 
					
						
							|  |  |  |         BOOST_CHECK( str1==string("1XXX3abc2") ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     // erase_range
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2013-02-25 18:43:26 +00:00
										 |  |  |         BOOST_TEST_CHECKPOINT( "erase_range" ); | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         string str1("1abc3abc2"); | 
					
						
							|  |  |  |         BOOST_CHECK(  | 
					
						
							|  |  |  |         erase_range_copy(  | 
					
						
							|  |  |  |                 str1,  | 
					
						
							|  |  |  |                 make_iterator_range(str1.begin()+1, str1.begin()+4))==string("13abc2") ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         string strout; | 
					
						
							|  |  |  |         erase_range_copy(  | 
					
						
							|  |  |  |                 back_inserter( strout ), | 
					
						
							|  |  |  |                 str1,  | 
					
						
							|  |  |  |                 make_iterator_range(str1.begin()+1, str1.begin()+4)); | 
					
						
							|  |  |  |         BOOST_CHECK( strout==string("13abc2") ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         erase_range(  | 
					
						
							|  |  |  |                 str1,  | 
					
						
							|  |  |  |                 make_iterator_range(str1.begin()+1, str1.begin()+4)); | 
					
						
							|  |  |  |         BOOST_CHECK( str1==string("13abc2") ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-07-30 07:44:43 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-30 07:44:43 +00:00
										 |  |  | void collection_comp_test() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // container traits compatibility tests
 | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         string strout; | 
					
						
							|  |  |  |         replace_first_copy( back_inserter(strout), "1abc3abc2", "abc", "YYY" ); | 
					
						
							|  |  |  |         BOOST_CHECK( strout==string("1YYY3abc2") );  | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         string strout; | 
					
						
							|  |  |  |         replace_last_copy( back_inserter(strout), "1abc3abc2", "abc", "YYY" ); | 
					
						
							|  |  |  |         BOOST_CHECK( strout==string("1abc3YYY2") );  | 
					
						
							|  |  |  |     }    | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         string strout; | 
					
						
							|  |  |  |         replace_all_copy( back_inserter(strout), "1abc3abc2", "abc", "YYY" ); | 
					
						
							|  |  |  |         BOOST_CHECK( strout==string("1YYY3YYY2") );  | 
					
						
							|  |  |  |     }    | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         string strout; | 
					
						
							|  |  |  |         replace_nth_copy( back_inserter(strout), "1abc3abc2", "abc", 1, "YYY" ); | 
					
						
							|  |  |  |         BOOST_CHECK( strout==string("1abc3YYY2") );  | 
					
						
							|  |  |  |     }    | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         string strout; | 
					
						
							|  |  |  |         replace_head_copy( back_inserter(strout), "abc3abc2", 3 , "YYY" ); | 
					
						
							|  |  |  |         BOOST_CHECK( strout==string("YYY3abc2") );  | 
					
						
							|  |  |  |     }    | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         string strout; | 
					
						
							|  |  |  |         replace_tail_copy( back_inserter(strout), "abc3abc", 3 , "YYY" ); | 
					
						
							|  |  |  |         BOOST_CHECK( strout==string("abc3YYY") );  | 
					
						
							|  |  |  |     }    | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-03 21:13:37 +00:00
										 |  |  | void dissect_format_test() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     BOOST_CHECK( | 
					
						
							|  |  |  |         find_format_all_copy( | 
					
						
							|  |  |  |             string("aBc123Abc"),  | 
					
						
							|  |  |  |             first_finder("abc", is_iequal()),  | 
					
						
							|  |  |  |             dissect_formatter(token_finder(is_upper())))=="B123A"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     BOOST_CHECK( | 
					
						
							|  |  |  |         find_format_all_copy( | 
					
						
							|  |  |  |             string("abc   123   abc"), | 
					
						
							|  |  |  |             token_finder(is_space(), token_compress_on), | 
					
						
							|  |  |  |             dissect_formatter(head_finder(1)))=="abc 123 abc"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-25 18:43:26 +00:00
										 |  |  | BOOST_AUTO_TEST_CASE( test_main ) | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     sequence_traits_test();  | 
					
						
							| 
									
										
										
										
											2004-07-30 07:44:43 +00:00
										 |  |  |     replace_first_test(); | 
					
						
							|  |  |  |     replace_last_test(); | 
					
						
							|  |  |  |     replace_all_test(); | 
					
						
							|  |  |  |     replace_nth_test(); | 
					
						
							|  |  |  |     replace_head_test(); | 
					
						
							|  |  |  |     replace_tail_test(); | 
					
						
							|  |  |  |     replace_range_test(); | 
					
						
							|  |  |  |     collection_comp_test(); | 
					
						
							| 
									
										
										
										
											2011-06-03 21:13:37 +00:00
										 |  |  |     dissect_format_test(); | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | } |