From 4b9289cfb260f4bcecaf23a810584ef6ef8e8501 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 30 Mar 2011 22:33:41 +0000 Subject: Ok, string stuff is working much, much better, a load of new unit tests have been added, and I deleted a whole slew of stupid old tests that I don't need. --- src/unit/string.unit | 159 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 152 insertions(+), 7 deletions(-) (limited to 'src/unit') diff --git a/src/unit/string.unit b/src/unit/string.unit index 4911597..5298f8a 100644 --- a/src/unit/string.unit +++ b/src/unit/string.unit @@ -174,7 +174,7 @@ suite String unitTest( a == b ); } - test iterator2 + test iteratorCompare1 { Bu::String a("This is a test."); Bu::String b("--This is a test."); @@ -185,9 +185,12 @@ suite String bi++; bi++; unitTest( ai.compare( bi ) == true ); unitTest( bi.compare( ai ) == true ); + b += "hi"; + unitTest( ai.compare( bi ) == false ); + unitTest( bi.compare( ai ) == false ); } - test iterator3 + test iteratorCompare2 { Bu::String a("1234honour"); Bu::String b("--1234ueje"); @@ -200,19 +203,33 @@ suite String unitTest( bi.compare( ai, 4 ) == true ); unitTest( ai.compare( bi, 5 ) == false ); unitTest( bi.compare( ai, 5 ) == false ); - + + a = "fell"; + b = "-felloo"; + ai = a.begin(); + bi = b.begin()+1; + unitTest( ai.compare( bi, 4 ) == true ); + ai++; + bi++; + unitTest( ai.compare( bi, 4 ) == false ); } - test iterator4 + test iteratorCompare3 { Bu::String a("1234aoeu"); Bu::String::iterator ai = a.begin(); unitTest( ai.compare("1234") == false ); unitTest( ai.compare("1234aoeu") == true ); unitTest( ai.compare("1234aoeuee") == false ); + ai += 4; + unitTest( ai.compare("aoeu") == true ); + unitTest( ai.compare("aoeubo") == false ); + unitTest( ai.compare("aoe") == false ); + unitTest( ai.compare("wrong") == false ); + unitTest( ai.compare("boeu") == false ); } - test iterator5 + test iteratorCompare4 { Bu::String a("1234aoeu"); Bu::String::iterator ai = a.begin(); @@ -221,7 +238,119 @@ suite String unitTest( ai.compare("1234aoeuee", 10) == false ); } - test iterator6 + test iteratorCompare5 + { + Bu::String a("1234aoeu"); + Bu::String b("34ao"); + Bu::String::iterator ai = a.begin(); + unitTest( ai.compare( b ) == false ); + ai += 2; + unitTest( ai.compare( b ) == false ); + b = "oeu"; + ai += 3; + unitTest( ai.compare( b ) == true ); + b += "boo"; + unitTest( ai.compare( b ) == false ); + } + + test iteratorCompare6 + { + Bu::String a("1234aoeu"); + Bu::String::iterator ai = a.begin(); + unitTest( ai.compare( Bu::String("1234"), 4) == true ); + unitTest( ai.compare( Bu::String("1234aoeu"), 8) == true ); + unitTest( ai.compare( Bu::String("1234aoeuee"), 10) == false ); + } + + test const_iteratorCompare1 + { + Bu::String a("This is a test."); + Bu::String b("--This is a test."); + Bu::String::const_iterator ai = a.begin(); + Bu::String::const_iterator bi = b.begin(); + unitTest( ai.compare( bi ) == false ); + unitTest( bi.compare( ai ) == false ); + bi++; bi++; + unitTest( ai.compare( bi ) == true ); + unitTest( bi.compare( ai ) == true ); + b += "hi"; + unitTest( ai.compare( bi ) == false ); + unitTest( bi.compare( ai ) == false ); + } + + test const_iteratorCompare2 + { + Bu::String a("1234honour"); + Bu::String b("--1234ueje"); + Bu::String::const_iterator ai = a.begin(); + Bu::String::const_iterator bi = b.begin(); + unitTest( ai.compare( bi, 4 ) == false ); + unitTest( bi.compare( ai, 4 ) == false ); + bi++; bi++; + unitTest( ai.compare( bi, 4 ) == true ); + unitTest( bi.compare( ai, 4 ) == true ); + unitTest( ai.compare( bi, 5 ) == false ); + unitTest( bi.compare( ai, 5 ) == false ); + + a = "fell"; + b = "-felloo"; + ai = a.begin(); + bi = b.begin()+1; + unitTest( ai.compare( bi, 4 ) == true ); + ai++; + bi++; + unitTest( ai.compare( bi, 4 ) == false ); + } + + test const_iteratorCompare3 + { + Bu::String a("1234aoeu"); + Bu::String::const_iterator ai = a.begin(); + unitTest( ai.compare("1234") == false ); + unitTest( ai.compare("1234aoeu") == true ); + unitTest( ai.compare("1234aoeuee") == false ); + ai += 4; + unitTest( ai.compare("aoeu") == true ); + unitTest( ai.compare("aoeubo") == false ); + unitTest( ai.compare("aoe") == false ); + unitTest( ai.compare("wrong") == false ); + unitTest( ai.compare("boeu") == false ); + } + + test const_iteratorCompare4 + { + Bu::String a("1234aoeu"); + Bu::String::const_iterator ai = a.begin(); + unitTest( ai.compare("1234", 4) == true ); + unitTest( ai.compare("1234aoeu", 8) == true ); + unitTest( ai.compare("1234aoeuee", 10) == false ); + } + + test const_iteratorCompare5 + { + Bu::String a("1234aoeu"); + Bu::String b("34ao"); + Bu::String::const_iterator ai = a.begin(); + unitTest( ai.compare( b ) == false ); + ai += 2; + unitTest( ai.compare( b ) == false ); + b = "oeu"; + ai += 3; + unitTest( ai.compare( b ) == true ); + b += "boo"; + unitTest( ai.compare( b ) == false ); + } + + test const_iteratorCompare6 + { + Bu::String a("1234aoeu"); + Bu::String::const_iterator ai = a.begin(); + unitTest( ai.compare( Bu::String("1234"), 4) == true ); + unitTest( ai.compare( Bu::String("1234aoeu"), 8) == true ); + unitTest( ai.compare( Bu::String("1234aoeuee"), 10) == false ); + } + + test iteratorAppend1 { Bu::String a("just ->this part"); Bu::String b; @@ -247,7 +376,7 @@ suite String unitTest( c == b ); } - test iterator7 + test iteratorAppend2 { Bu::String a("just [this] part"); Bu::String b; @@ -428,6 +557,22 @@ suite String unitTest( s1.toLower() == "hello there, how are you doing?" ); unitTest( s1 == "HeLlO ThErE, HoW ArE YoU DoInG?" ); } + + test trimWhitespace1 + { + unitTest( Bu::String("Hello there").trimWhitespace() + == "Hello there" ); + unitTest( Bu::String(" \t\r\r\nHello there").trimWhitespace() + == "Hello there" ); + unitTest( Bu::String("Hello there \r\n\n\t\t ").trimWhitespace() + == "Hello there" ); + unitTest( Bu::String(" \tHello there\r\n \t").trimWhitespace() + == "Hello there" ); + unitTest( Bu::String(" \t\t\r\n").trimWhitespace() == "" ); + unitTest( Bu::String().trimWhitespace() == "" ); + unitTest( Bu::String(" \tHello \t\t\r\nthere\r\n \t").trimWhitespace() + == "Hello \t\t\r\nthere" ); + } } // 03F09CA4F58AC8CA0E80F0D9D409D0A60700A192270004BC3A99E91D0001034F544603362E35013103313130019CA4F58AC8CA0E0002830800002C4200008AC200EBF7D9D4090127BB010000E3 // -- cgit v1.2.3