Strings - Character mapping, conversion to upper/lowercase

This commit is contained in:
Emmanuel BENOîT 2018-05-08 13:58:39 +02:00
parent fbff6e8352
commit d823721fb2
3 changed files with 78 additions and 0 deletions

View file

@ -126,6 +126,10 @@ class StringsTest : public CppUnit::TestFixture
CPPUNIT_TEST( testToSignedLeadingWhitespaceOnly );
CPPUNIT_TEST( testToDouble );
CPPUNIT_TEST( testMapped );
CPPUNIT_TEST( testToUpper );
CPPUNIT_TEST( testToLower );
CPPUNIT_TEST_SUITE_END( );
public:
@ -249,6 +253,10 @@ public:
void testToSignedLeadingWhitespaceOnly( );
void testToDouble( );
void testMapped( );
void testToUpper( );
void testToLower( );
};
CPPUNIT_TEST_SUITE_REGISTRATION( StringsTest );
@ -1182,3 +1190,34 @@ void StringsTest::testToDouble( )
}
#undef M_CHECK_
/*----------------------------------------------------------------------------*/
void StringsTest::testMapped( )
{
const T_String test{ "thisisatest" };
const T_String expected{ "uijtjtbuftu" };
const T_String result{ test.mapped( [](auto c){
return c + 1;
} ) };
CPPUNIT_ASSERT_EQUAL( test.length( ) , result.length( ) );
CPPUNIT_ASSERT( result.equals( expected ) );
}
void StringsTest::testToUpper( )
{
const T_String test{ "This IS a test, 123" };
const T_String expected{ "THIS IS A TEST, 123" };
const T_String result{ test.toUpper( ) };
CPPUNIT_ASSERT_EQUAL( test.length( ) , result.length( ) );
CPPUNIT_ASSERT( result.equals( expected ) );
}
void StringsTest::testToLower( )
{
const T_String test{ "This IS a test, 123" };
const T_String expected{ "this is a test, 123" };
const T_String result{ test.toLower( ) };
CPPUNIT_ASSERT_EQUAL( test.length( ) , result.length( ) );
CPPUNIT_ASSERT( result.equals( expected ) );
}