00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef WSTRINGUTILS_TEST_H
00026 #define WSTRINGUTILS_TEST_H
00027
00028 #include <string>
00029 #include <vector>
00030
00031 #include <cxxtest/TestSuite.h>
00032
00033 #include "../WStringUtils.h"
00034
00035 namespace su = string_utils;
00036
00037
00038
00039
00040 class WStringUtilsTest : public CxxTest::TestSuite
00041 {
00042 public:
00043
00044
00045
00046
00047 void testVectorOutputOperator( void )
00048 {
00049 std::stringstream ss;
00050 std::vector< double > pansen;
00051 using string_utils::operator<<;
00052 ss << pansen;
00053 TS_ASSERT_EQUALS( ss.str(), "[]" );
00054 ss.str( "" );
00055 ss.clear();
00056 pansen = std::vector< double >( 2, 3.1415 );
00057 pansen[1] = 1.414;
00058 std::string expected( "[3.1415000000000002e+00, 1.4139999999999999e+00]" );
00059 ss << pansen;
00060 TS_ASSERT_EQUALS( ss.str(), expected );
00061 }
00062
00063
00064
00065
00066
00067
00068 void testRightTrimming( void )
00069 {
00070 std::string str( " abc\t \r\n \t \n\n\n" );
00071 std::string expected( " abc" );
00072 std::string actual = su::rTrim( str );
00073 TS_ASSERT_EQUALS( expected, actual );
00074 TS_ASSERT_EQUALS( str, " abc\t \r\n \t \n\n\n" );
00075
00076
00077 TS_ASSERT_EQUALS( su::rTrim( std::string( "" ) ), "" );
00078 TS_ASSERT_EQUALS( su::rTrim( std::string( " " ) ), "" );
00079 TS_ASSERT_EQUALS( su::rTrim( std::string( "abc" ) ), "abc" );
00080
00081
00082 str = " pansenn";
00083 TS_ASSERT_EQUALS( su::rTrim( str, "pn" ), " panse" );
00084 }
00085
00086
00087
00088
00089 void testLeftTrimming( void )
00090 {
00091 std::string str( "\t \r\n \t \n\n\nabc " );
00092 std::string expected( "abc " );
00093 std::string actual = su::lTrim( str );
00094 TS_ASSERT_EQUALS( expected, actual );
00095 TS_ASSERT_EQUALS( str, "\t \r\n \t \n\n\nabc " );
00096
00097
00098 TS_ASSERT_EQUALS( su::lTrim( std::string( "" ) ), "" );
00099 TS_ASSERT_EQUALS( su::lTrim( std::string( " " ) ), "" );
00100 TS_ASSERT_EQUALS( su::lTrim( std::string( "abc" ) ), "abc" );
00101
00102
00103 str = "splendor pansen ";
00104 TS_ASSERT_EQUALS( su::lTrim( str, "splendor " ), "ansen " );
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114 void testCaseTransformations( void )
00115 {
00116 std::string str( "loWeR text\t with some ü\n" );
00117 std::string expected( "LOWER TEXT\t WITH SOME ü\n" );
00118
00119 TS_ASSERT_EQUALS( su::toUpper( str ), expected );
00120 TS_ASSERT_EQUALS( str, "loWeR text\t with some ü\n" );
00121 expected = "lower text\t with some ü\n";
00122 TS_ASSERT_EQUALS( su::toLower( str ), expected );
00123 TS_ASSERT_EQUALS( str, "loWeR text\t with some ü\n" );
00124 }
00125
00126
00127
00128
00129
00130 void testTokenizer( void )
00131 {
00132 std::string source;
00133 std::vector< std::string > expected;
00134 TS_ASSERT_EQUALS( su::tokenize( source ), expected );
00135 source = "Foo bar-foo \r\n\t blubb ";
00136 expected.push_back( "Foo" );
00137 expected.push_back( "bar-foo" );
00138 expected.push_back( "blubb" );
00139 TS_ASSERT_EQUALS( su::tokenize( source ), expected );
00140 TS_ASSERT_EQUALS( source, "Foo bar-foo \r\n\t blubb " );
00141 expected.clear();
00142 expected.push_back( "Foo " );
00143 expected.push_back( "ar-foo \r\n\t " );
00144 expected.push_back( "lu" );
00145 expected.push_back( "" );
00146 expected.push_back( " " );
00147 TS_ASSERT_EQUALS( su::tokenize( source, "b", false ), expected );
00148 }
00149 };
00150
00151 #endif // WSTRINGUTILS_TEST_H