Skip to content
Snippets Groups Projects
StringTest.cpp 1.9 KiB
Newer Older
  • Learn to ignore specific revisions
  • #include "StringTest.h"
    
    CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( StringTest, "bits" );
    CPPUNIT_TEST_SUITE_REGISTRATION( StringTest );
    
    void StringTest::setUp() {
    }
    
    void StringTest::tearDown() {
    }
    
    void StringTest::testToString() {
    
    	CPPUNIT_ASSERT ( ext::to_string ( std::string ( "1" ) ) == "1" );
    	CPPUNIT_ASSERT ( ext::to_string ( 1 ) == "1" );
    	CPPUNIT_ASSERT ( ext::to_string ( 1ul ) == "1" );
    
    
    	StringTest::A a;
    
    	CPPUNIT_ASSERT ( ext::to_string ( a ) == "" );
    
    void StringTest::testExplode ( ) {
    	{
    		std::string one ( "a::bb::ccc" );
    		ext::vector < std::string > oneExploded = ext::explode ( one, "::" );
    
    		std::cout << oneExploded << std::endl;
    
    		CPPUNIT_ASSERT ( oneExploded.size ( ) == 3 );
    		CPPUNIT_ASSERT ( oneExploded [ 0 ] == "a" );
    		CPPUNIT_ASSERT ( oneExploded [ 1 ] == "bb" );
    		CPPUNIT_ASSERT ( oneExploded [ 2 ] == "ccc" );
    	}
    	{
    		std::string one ( "a::bb::ccc::" );
    		ext::vector < std::string > oneExploded = ext::explode ( one, "::" );
    
    		CPPUNIT_ASSERT ( oneExploded.size ( ) == 4 );
    		CPPUNIT_ASSERT ( oneExploded [ 0 ] == "a" );
    		CPPUNIT_ASSERT ( oneExploded [ 1 ] == "bb" );
    		CPPUNIT_ASSERT ( oneExploded [ 2 ] == "ccc" );
    		CPPUNIT_ASSERT ( oneExploded [ 3 ] == "" );
    	}
    	{
    		std::string one ( "" );
    		ext::vector < std::string > oneExploded = ext::explode ( one, "::" );
    
    		CPPUNIT_ASSERT ( oneExploded.size ( ) == 1 );
    		CPPUNIT_ASSERT ( oneExploded [ 0 ] == "" );
    	}
    	{
    		std::string one ( "::aa" );
    		ext::vector < std::string > oneExploded = ext::explode ( one, "::" );
    
    		std::cout << oneExploded << std::endl;
    
    		CPPUNIT_ASSERT ( oneExploded.size ( ) == 2 );
    		CPPUNIT_ASSERT ( oneExploded [ 0 ] == "" );
    		CPPUNIT_ASSERT ( oneExploded [ 1 ] == "aa" );
    	}
    	{
    		std::string one ( "::" );
    		ext::vector < std::string > oneExploded = ext::explode ( one, "::" );
    
    		CPPUNIT_ASSERT ( oneExploded.size ( ) == 2 );
    		CPPUNIT_ASSERT ( oneExploded [ 0 ] == "" );
    		CPPUNIT_ASSERT ( oneExploded [ 1 ] == "" );
    	}
    }