forked from boostorg/algorithm
Tests for join algorihtm added
[SVN r32917]
This commit is contained in:
@ -57,6 +57,14 @@ DEPENDS all : test ;
|
|||||||
std::facet-support
|
std::facet-support
|
||||||
: split
|
: split
|
||||||
]
|
]
|
||||||
|
[ run
|
||||||
|
join_test.cpp
|
||||||
|
: :
|
||||||
|
:
|
||||||
|
std::locale-support
|
||||||
|
std::facet-support
|
||||||
|
: join
|
||||||
|
]
|
||||||
[ run
|
[ run
|
||||||
replace_test.cpp
|
replace_test.cpp
|
||||||
: :
|
: :
|
||||||
|
@ -40,6 +40,12 @@ test-suite algorithm/string
|
|||||||
:
|
:
|
||||||
: split
|
: split
|
||||||
]
|
]
|
||||||
|
[ run
|
||||||
|
join_test.cpp
|
||||||
|
: :
|
||||||
|
:
|
||||||
|
: join
|
||||||
|
]
|
||||||
[ run
|
[ run
|
||||||
replace_test.cpp
|
replace_test.cpp
|
||||||
: :
|
: :
|
||||||
|
@ -93,10 +93,10 @@ void find_test()
|
|||||||
( (nc_result.begin()-str1.begin()) == 9) &&
|
( (nc_result.begin()-str1.begin()) == 9) &&
|
||||||
( (nc_result.end()-str1.begin()) == 12) );
|
( (nc_result.end()-str1.begin()) == 12) );
|
||||||
|
|
||||||
nc_result=find_nth( str1, string("abc"), -1 );
|
nc_result=find_nth( str1, string("abc"), -1 );
|
||||||
BOOST_CHECK(
|
BOOST_CHECK(
|
||||||
( (nc_result.begin()-str1.begin()) == 15) &&
|
( (nc_result.begin()-str1.begin()) == 15) &&
|
||||||
( (nc_result.end()-str1.begin()) == 18) );
|
( (nc_result.end()-str1.begin()) == 18) );
|
||||||
|
|
||||||
|
|
||||||
cv_result=find_nth( const_cast<const string&>(str1), str2, 1 );
|
cv_result=find_nth( const_cast<const string&>(str1), str2, 1 );
|
||||||
@ -104,20 +104,20 @@ void find_test()
|
|||||||
( (cv_result.begin()-str1.begin()) == 9) &&
|
( (cv_result.begin()-str1.begin()) == 9) &&
|
||||||
( (cv_result.end()-str1.begin()) == 12) );
|
( (cv_result.end()-str1.begin()) == 12) );
|
||||||
|
|
||||||
cv_result=find_nth( const_cast<const string&>(str1), str2, -1 );
|
cv_result=find_nth( const_cast<const string&>(str1), str2, -1 );
|
||||||
BOOST_CHECK(
|
BOOST_CHECK(
|
||||||
( (cv_result.begin()-str1.begin()) == 15) &&
|
( (cv_result.begin()-str1.begin()) == 15) &&
|
||||||
( (cv_result.end()-str1.begin()) == 18) );
|
( (cv_result.end()-str1.begin()) == 18) );
|
||||||
|
|
||||||
cv_result=ifind_nth( const_cast<const string&>(str1), "xxx", 1 );
|
cv_result=ifind_nth( const_cast<const string&>(str1), "xxx", 1 );
|
||||||
BOOST_CHECK(
|
BOOST_CHECK(
|
||||||
( (cv_result.begin()-str1.begin()) == 12) &&
|
( (cv_result.begin()-str1.begin()) == 12) &&
|
||||||
( (cv_result.end()-str1.begin()) == 15) );
|
( (cv_result.end()-str1.begin()) == 15) );
|
||||||
|
|
||||||
cv_result=ifind_nth( const_cast<const string&>(str1), "xxx", 1 );
|
cv_result=ifind_nth( const_cast<const string&>(str1), "xxx", 1 );
|
||||||
BOOST_CHECK(
|
BOOST_CHECK(
|
||||||
( (cv_result.begin()-str1.begin()) == 12) &&
|
( (cv_result.begin()-str1.begin()) == 12) &&
|
||||||
( (cv_result.end()-str1.begin()) == 15) );
|
( (cv_result.end()-str1.begin()) == 15) );
|
||||||
|
|
||||||
|
|
||||||
ch_result=find_nth( pch1, "abc", 1 );
|
ch_result=find_nth( pch1, "abc", 1 );
|
||||||
@ -131,10 +131,10 @@ void find_test()
|
|||||||
( (nc_result.begin()-str1.begin()) == 0) &&
|
( (nc_result.begin()-str1.begin()) == 0) &&
|
||||||
( (nc_result.end()-str1.begin()) == 6) );
|
( (nc_result.end()-str1.begin()) == 6) );
|
||||||
|
|
||||||
nc_result=find_head( str1, -6 );
|
nc_result=find_head( str1, -6 );
|
||||||
BOOST_CHECK(
|
BOOST_CHECK(
|
||||||
( (nc_result.begin()-str1.begin()) == 0) &&
|
( (nc_result.begin()-str1.begin()) == 0) &&
|
||||||
( (str1.end()-nc_result.end()) == 6 ) );
|
( (str1.end()-nc_result.end()) == 6 ) );
|
||||||
|
|
||||||
cv_result=find_head( const_cast<const string&>(str1), 6 );
|
cv_result=find_head( const_cast<const string&>(str1), 6 );
|
||||||
BOOST_CHECK(
|
BOOST_CHECK(
|
||||||
@ -152,10 +152,10 @@ void find_test()
|
|||||||
( (nc_result.begin()-str1.begin()) == 15) &&
|
( (nc_result.begin()-str1.begin()) == 15) &&
|
||||||
( (nc_result.end()-str1.begin()) == 21) );
|
( (nc_result.end()-str1.begin()) == 21) );
|
||||||
|
|
||||||
nc_result=find_tail( str1, -6 );
|
nc_result=find_tail( str1, -6 );
|
||||||
BOOST_CHECK(
|
BOOST_CHECK(
|
||||||
( (nc_result.begin()-str1.begin()) == 6) &&
|
( (nc_result.begin()-str1.begin()) == 6) &&
|
||||||
( (nc_result.end()-str1.begin()) == 21) );
|
( (nc_result.end()-str1.begin()) == 21) );
|
||||||
|
|
||||||
|
|
||||||
cv_result=find_tail( const_cast<const string&>(str1), 6 );
|
cv_result=find_tail( const_cast<const string&>(str1), 6 );
|
||||||
|
79
string/test/join_test.cpp
Normal file
79
string/test/join_test.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
// Boost string_algo library iterator_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.
|
||||||
|
|
||||||
|
#include <boost/algorithm/string/join.hpp>
|
||||||
|
#include <boost/algorithm/string/classification.hpp>
|
||||||
|
// equals predicate is used for result comparison
|
||||||
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
|
|
||||||
|
// Include unit test framework
|
||||||
|
#include <boost/test/included/test_exec_monitor.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace boost;
|
||||||
|
|
||||||
|
bool is_not_empty(const std::string& str)
|
||||||
|
{
|
||||||
|
return !str.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
void join_test()
|
||||||
|
{
|
||||||
|
// Prepare inputs
|
||||||
|
vector<string> tokens1;
|
||||||
|
tokens1.push_back("xx");
|
||||||
|
tokens1.push_back("abc");
|
||||||
|
tokens1.push_back("xx");
|
||||||
|
|
||||||
|
vector<string> tokens2;
|
||||||
|
tokens2.push_back("");
|
||||||
|
tokens2.push_back("xx");
|
||||||
|
tokens2.push_back("abc");
|
||||||
|
tokens2.push_back("");
|
||||||
|
tokens2.push_back("abc");
|
||||||
|
tokens2.push_back("xx");
|
||||||
|
tokens2.push_back("");
|
||||||
|
|
||||||
|
vector<string> tokens3;
|
||||||
|
tokens3.push_back("");
|
||||||
|
tokens3.push_back("");
|
||||||
|
tokens3.push_back("");
|
||||||
|
|
||||||
|
vector<string> empty_tokens;
|
||||||
|
|
||||||
|
vector<vector<int> > vtokens;
|
||||||
|
for(unsigned int n=0; n<tokens2.size(); ++n)
|
||||||
|
{
|
||||||
|
vtokens.push_back(vector<int>(tokens2[n].begin(), tokens2[n].end()));
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_CHECK( equals(join(tokens1, "-"), "xx-abc-xx") );
|
||||||
|
BOOST_CHECK( equals(join(tokens2, "-"), "-xx-abc--abc-xx-") );
|
||||||
|
BOOST_CHECK( equals(join(vtokens, "-"), "-xx-abc--abc-xx-") );
|
||||||
|
BOOST_CHECK( equals(join(empty_tokens, "-"), "") );
|
||||||
|
|
||||||
|
BOOST_CHECK( equals(join_if(tokens2, "-", is_not_empty), "xx-abc-abc-xx") );
|
||||||
|
BOOST_CHECK( equals(join_if(empty_tokens, "-", is_not_empty), "") );
|
||||||
|
BOOST_CHECK( equals(join_if(tokens3, "-", is_not_empty), "") );
|
||||||
|
}
|
||||||
|
|
||||||
|
// test main
|
||||||
|
int test_main( int, char*[] )
|
||||||
|
{
|
||||||
|
join_test();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -56,14 +56,14 @@ void predicate_test()
|
|||||||
BOOST_CHECK( iequals( "AbC", "abc" ) );
|
BOOST_CHECK( iequals( "AbC", "abc" ) );
|
||||||
BOOST_CHECK( !iequals( "aBc", "yyy" ) );
|
BOOST_CHECK( !iequals( "aBc", "yyy" ) );
|
||||||
|
|
||||||
BOOST_CHECK( lexicographical_compare("abc", "abd") );
|
BOOST_CHECK( lexicographical_compare("abc", "abd") );
|
||||||
BOOST_CHECK( !lexicographical_compare("abc", "abc") );
|
BOOST_CHECK( !lexicographical_compare("abc", "abc") );
|
||||||
BOOST_CHECK( lexicographical_compare("abc", "abd", is_not_greater()) );
|
BOOST_CHECK( lexicographical_compare("abc", "abd", is_not_greater()) );
|
||||||
BOOST_CHECK( lexicographical_compare("abc", "abc", is_not_greater()) );
|
BOOST_CHECK( lexicographical_compare("abc", "abc", is_not_greater()) );
|
||||||
|
|
||||||
BOOST_CHECK( !ilexicographical_compare("aBD", "AbC") );
|
BOOST_CHECK( !ilexicographical_compare("aBD", "AbC") );
|
||||||
BOOST_CHECK( ilexicographical_compare("aBc", "AbD") );
|
BOOST_CHECK( ilexicographical_compare("aBc", "AbD") );
|
||||||
BOOST_CHECK( lexicographical_compare("abC", "aBc", is_not_igreater()) );
|
BOOST_CHECK( lexicographical_compare("abC", "aBc", is_not_igreater()) );
|
||||||
|
|
||||||
// multi-type comparison test
|
// multi-type comparison test
|
||||||
BOOST_CHECK( starts_with( vec1, string("123") ) );
|
BOOST_CHECK( starts_with( vec1, string("123") ) );
|
||||||
|
@ -136,27 +136,27 @@ void replace_nth_test()
|
|||||||
{
|
{
|
||||||
// replace nth
|
// replace nth
|
||||||
TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ 0 C_ string("YYY"), string("1YYY3abc2") );
|
TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ 0 C_ string("YYY"), string("1YYY3abc2") );
|
||||||
TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ -1 C_ string("YYY"), string("1abc3YYY2") );
|
TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ -1 C_ string("YYY"), string("1abc3YYY2") );
|
||||||
TEST_ALGO( ireplace_nth, "1AbC3abc2", "aBc" C_ 0 C_ "YYY", string("1YYY3abc2") );
|
TEST_ALGO( ireplace_nth, "1AbC3abc2", "aBc" C_ 0 C_ "YYY", string("1YYY3abc2") );
|
||||||
TEST_ALGO( ireplace_nth, "1AbC3abc2", "aBc" C_ -1 C_ "YYY", string("1AbC3YYY2") );
|
TEST_ALGO( ireplace_nth, "1AbC3abc2", "aBc" C_ -1 C_ "YYY", string("1AbC3YYY2") );
|
||||||
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("Z"), string("1Z3abc2") );
|
||||||
TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ 0 C_ string("XXXX"), string("1XXXX3abc2") );
|
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") );
|
TEST_ALGO( replace_nth, "1abc3abc2", "abc" C_ 0 C_ "XXXX", string("1XXXX3abc2") );
|
||||||
TEST_ALGO( replace_nth, "1abc3abc2", "abc" C_ 3 C_ "XXXX", string("1abc3abc2") );
|
TEST_ALGO( replace_nth, "1abc3abc2", "abc" C_ 3 C_ "XXXX", string("1abc3abc2") );
|
||||||
TEST_ALGO( replace_nth, "1abc3abc2", "abc" C_ -3 C_ "XXXX", string("1abc3abc2") );
|
TEST_ALGO( replace_nth, "1abc3abc2", "abc" C_ -3 C_ "XXXX", string("1abc3abc2") );
|
||||||
TEST_ALGO( replace_nth, "1abc3abc2", string("") C_ 0 C_ string("XXXX"), string("1abc3abc2") );
|
TEST_ALGO( replace_nth, "1abc3abc2", string("") C_ 0 C_ string("XXXX"), string("1abc3abc2") );
|
||||||
TEST_ALGO( replace_nth, "", string("") C_ 0 C_ string("XXXX"), string("") );
|
TEST_ALGO( replace_nth, "", string("") C_ 0 C_ string("XXXX"), string("") );
|
||||||
TEST_ALGO( replace_nth, "", string("") C_ -1 C_ string("XXXX"), string("") );
|
TEST_ALGO( replace_nth, "", string("") C_ -1 C_ string("XXXX"), string("") );
|
||||||
TEST_ALGO( erase_nth, "1abc3abc2", string("abc") C_ 0, string("13abc2") );
|
TEST_ALGO( erase_nth, "1abc3abc2", string("abc") C_ 0, string("13abc2") );
|
||||||
TEST_ALGO( erase_nth, "1abc3abc2", string("abc") C_ -1, string("1abc32") );
|
TEST_ALGO( erase_nth, "1abc3abc2", string("abc") C_ -1, string("1abc32") );
|
||||||
TEST_ALGO( erase_nth, "1abc3abc2", string("abc") C_ -3, string("1abc3abc2") );
|
TEST_ALGO( erase_nth, "1abc3abc2", string("abc") C_ -3, string("1abc3abc2") );
|
||||||
TEST_ALGO( ierase_nth, "1aBc3aBc2", "ABC" C_ 0, string("13aBc2") );
|
TEST_ALGO( ierase_nth, "1aBc3aBc2", "ABC" C_ 0, string("13aBc2") );
|
||||||
TEST_ALGO( ierase_nth, "1aBc3aBc2", "ABC" C_ -1, string("1aBc32") );
|
TEST_ALGO( ierase_nth, "1aBc3aBc2", "ABC" C_ -1, string("1aBc32") );
|
||||||
TEST_ALGO( ierase_nth, "1aBc3aBc2", "ABC" C_ -3, string("1aBc3aBc2") );
|
TEST_ALGO( ierase_nth, "1aBc3aBc2", "ABC" C_ -3, string("1aBc3aBc2") );
|
||||||
TEST_ALGO( erase_nth, "1abc3abc2", "abc" C_ 0, string("13abc2") );
|
TEST_ALGO( erase_nth, "1abc3abc2", "abc" C_ 0, string("13abc2") );
|
||||||
TEST_ALGO( erase_nth, "1abc3abc2", string("") C_ 0, string("1abc3abc2") );
|
TEST_ALGO( erase_nth, "1abc3abc2", string("") C_ 0, string("1abc3abc2") );
|
||||||
TEST_ALGO( erase_nth, "", string("abc") C_ 0, string("") );
|
TEST_ALGO( erase_nth, "", string("abc") C_ 0, string("") );
|
||||||
TEST_ALGO( erase_nth, "", string("abc") C_ -1, string("") );
|
TEST_ALGO( erase_nth, "", string("abc") C_ -1, string("") );
|
||||||
TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ 1 C_ string("YYY"), string("1abc3YYY2") );
|
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") );
|
TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ 2 C_ string("YYY"), string("1abc3abc2") );
|
||||||
}
|
}
|
||||||
@ -165,19 +165,19 @@ void replace_head_test()
|
|||||||
{
|
{
|
||||||
// replace head
|
// replace head
|
||||||
TEST_ALGO( replace_head, "abc3abc2", 3 C_ string("YYY"), string("YYY3abc2") );
|
TEST_ALGO( replace_head, "abc3abc2", 3 C_ string("YYY"), string("YYY3abc2") );
|
||||||
TEST_ALGO( replace_head, "abc3abc2", -3 C_ string("YYY"), string("YYYbc2") );
|
TEST_ALGO( replace_head, "abc3abc2", -3 C_ string("YYY"), string("YYYbc2") );
|
||||||
TEST_ALGO( replace_head, "abc3abc2", 3 C_ "YYY", string("YYY3abc2") );
|
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", 3 C_ string("Z"), string("Z") );
|
||||||
TEST_ALGO( replace_head, "abc", 6 C_ string("XXXX"), string("XXXX") );
|
TEST_ALGO( replace_head, "abc", 6 C_ string("XXXX"), string("XXXX") );
|
||||||
TEST_ALGO( replace_head, "abc", -6 C_ string("XXXX"), string("abc") );
|
TEST_ALGO( replace_head, "abc", -6 C_ string("XXXX"), string("abc") );
|
||||||
TEST_ALGO( replace_head, "abc3abc2", 0 C_ string("XXXX"), string("abc3abc2") );
|
TEST_ALGO( replace_head, "abc3abc2", 0 C_ string("XXXX"), string("abc3abc2") );
|
||||||
TEST_ALGO( replace_head, "", 4 C_ string("XXXX"), string("") );
|
TEST_ALGO( replace_head, "", 4 C_ string("XXXX"), string("") );
|
||||||
TEST_ALGO( replace_head, "", -4 C_ string("XXXX"), string("") );
|
TEST_ALGO( replace_head, "", -4 C_ string("XXXX"), string("") );
|
||||||
TEST_ALGO( erase_head, "abc3abc2", 3, string("3abc2") );
|
TEST_ALGO( erase_head, "abc3abc2", 3, string("3abc2") );
|
||||||
TEST_ALGO( erase_head, "abc3abc2", -3, string("bc2") );
|
TEST_ALGO( erase_head, "abc3abc2", -3, string("bc2") );
|
||||||
TEST_ALGO( erase_head, "abc3abc2", 0, string("abc3abc2") );
|
TEST_ALGO( erase_head, "abc3abc2", 0, string("abc3abc2") );
|
||||||
TEST_ALGO( erase_head, "", 4, string("") );
|
TEST_ALGO( erase_head, "", 4, string("") );
|
||||||
TEST_ALGO( erase_head, "", -4, string("") );
|
TEST_ALGO( erase_head, "", -4, string("") );
|
||||||
}
|
}
|
||||||
|
|
||||||
void replace_tail_test()
|
void replace_tail_test()
|
||||||
@ -187,15 +187,15 @@ void replace_tail_test()
|
|||||||
TEST_ALGO( replace_tail, "abc3abc", -3 C_ "YYY", string("abcYYY") );
|
TEST_ALGO( replace_tail, "abc3abc", -3 C_ "YYY", string("abcYYY") );
|
||||||
TEST_ALGO( replace_tail, "abc", 3 C_ string("Z"), string("Z") );
|
TEST_ALGO( replace_tail, "abc", 3 C_ string("Z"), string("Z") );
|
||||||
TEST_ALGO( replace_tail, "abc", 6 C_ string("XXXX"), string("XXXX") );
|
TEST_ALGO( replace_tail, "abc", 6 C_ string("XXXX"), string("XXXX") );
|
||||||
TEST_ALGO( replace_tail, "abc", -6 C_ string("XXXX"), string("abc") );
|
TEST_ALGO( replace_tail, "abc", -6 C_ string("XXXX"), string("abc") );
|
||||||
TEST_ALGO( replace_tail, "abc3abc", 0 C_ string("XXXX"), string("abc3abc") );
|
TEST_ALGO( replace_tail, "abc3abc", 0 C_ string("XXXX"), string("abc3abc") );
|
||||||
TEST_ALGO( replace_tail, "", 4 C_ string("XXXX"), string("") );
|
TEST_ALGO( replace_tail, "", 4 C_ string("XXXX"), string("") );
|
||||||
TEST_ALGO( replace_tail, "", -4 C_ string("XXXX"), string("") );
|
TEST_ALGO( replace_tail, "", -4 C_ string("XXXX"), string("") );
|
||||||
TEST_ALGO( erase_tail, "abc3abc", 3, string("abc3") );
|
TEST_ALGO( erase_tail, "abc3abc", 3, string("abc3") );
|
||||||
TEST_ALGO( erase_tail, "abc3abc", -3, string("abc") );
|
TEST_ALGO( erase_tail, "abc3abc", -3, string("abc") );
|
||||||
TEST_ALGO( erase_tail, "abc3abc", 0, string("abc3abc") );
|
TEST_ALGO( erase_tail, "abc3abc", 0, string("abc3abc") );
|
||||||
TEST_ALGO( erase_tail, "", 4, string("") );
|
TEST_ALGO( erase_tail, "", 4, string("") );
|
||||||
TEST_ALGO( erase_tail, "", -4, string("") );
|
TEST_ALGO( erase_tail, "", -4, string("") );
|
||||||
}
|
}
|
||||||
|
|
||||||
void replace_range_test()
|
void replace_range_test()
|
||||||
|
Reference in New Issue
Block a user