|
// Boost string_algo library trim_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/trim.hpp>
/*
// Include unit test framework
#include <boost/test/included/test_exec_monitor.hpp>
*/
#include <string>
#include <iostream>
#include <boost/test/test_tools.hpp>
using namespace std;
using namespace boost;
inline void trim_test()
{
string_t str1(_T(" 1x x x x1 "));
string_t str2(_T(" 2x x x x2 "));
string_t str3(_T(" "));
/*
// *** value passing tests *** //
// general string_t test
BOOST_CHECK( trim_left_copy( str1 )==_T("1x x x x1 ") ) ;
BOOST_CHECK( trim_right_copy( str1 )==_T(" 1x x x x1") ) ;
BOOST_CHECK( trim_copy( str1 )==_T("1x x x x1") ) ;
// spaces-only string_t test
BOOST_CHECK( trim_left_copy( str3 )==_T("") );
BOOST_CHECK( trim_right_copy( str3 )==_T("") );
BOOST_CHECK( trim_copy( str3 )==_T("") );
// empty string_t check
BOOST_CHECK( trim_left_copy( string_t(_T("")) )==_T("") );
BOOST_CHECK( trim_right_copy( string_t(_T("")) )==_T("") );
BOOST_CHECK( trim_copy( string_t(_T("")) )==_T("") );
*/
// iterator tests
string_t str;
trim_left_copy_if( tomato::back_inserter(str), str1, is_space() );
BOOST_CHECK( str==_T("1x x x x1 ") );
tomato::clear(str);
trim_right_copy_if( tomato::back_inserter(str), str1, is_space() );
BOOST_CHECK( str==_T(" 1x x x x1") );
tomato::clear(str);
trim_copy_if( tomato::back_inserter(str), str1, is_space() );
BOOST_CHECK( str==_T("1x x x x1") );
tomato::clear(str);
trim_left_copy_if(
tomato::back_inserter(str),
_T(" 1x x x x1 "),
is_space() );
BOOST_CHECK( str==_T("1x x x x1 ") );
tomato::clear(str);
trim_right_copy_if(
tomato::back_inserter(str),
_T(" 1x x x x1 "),
is_space() );
BOOST_CHECK( str==_T(" 1x x x x1") );
tomato::clear(str);
trim_copy_if(
tomato::back_inserter(str),
_T(" 1x x x x1 "),
is_space() );
BOOST_CHECK( str==_T("1x x x x1") );
/*
// *** inplace tests *** //
// general string_t test
trim_left( str1 );
BOOST_CHECK( str1==_T("1x x x x1 ") );
trim_right( str1 );
BOOST_CHECK( str1==_T("1x x x x1") );
trim( str2 );
BOOST_CHECK( str2==_T("2x x x x2") );
// spaces-only string_t test
str3 = _T(" "); trim_left( str3 );
BOOST_CHECK( str3==_T("") );
str3 = _T(" "); trim_right( str3 );
BOOST_CHECK( str3==_T("") );
str3 = _T(" "); trim( str3 );
BOOST_CHECK( str3==_T("") );
// empty string_t check
str3 = _T(""); trim_left( str3 );
BOOST_CHECK( str3==_T("") );
str3 = _T(""); trim_right( str3 );
BOOST_CHECK( str3==_T("") );
str3 = _T(""); trim( str3 );
BOOST_CHECK( str3==_T("") );
// *** non-standard predicate tests *** //
BOOST_CHECK(
trim_copy_if(
string_t(_T("123abc456")),
is_classified(std::ctype_base::digit) )==_T("abc") );
BOOST_CHECK( trim_copy_if( string_t(_T("<>abc<>")), is_any_of( _T("<<>>") ) )==_T("abc") );
*/
}
/*
// test main
int test_main( int, char*[] )
{
trim_test();
return 0;
}
*/
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here