123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973 |
- #include "tests/ArrayStringTests.h"
- #include "data/HashMap.h"
- #include "test/Test.h"
- #include "utils/ArrayString.h"
- using String8 = Core::String8<128>;
- using String32 = Core::String32<128>;
- static String8 build(const char* cs) {
- String8 s;
- CORE_TEST_ERROR(s.append(cs));
- return s;
- }
- static void testEquality8() {
- String8 s = build("test");
- CORE_TEST_TRUE(s == "test");
- CORE_TEST_TRUE(s == build("test"));
- CORE_TEST_TRUE("test" == s);
- CORE_TEST_TRUE(build("test") == s);
- CORE_TEST_TRUE(s == s);
- }
- static void testUnicodeEquality8() {
- const char* cs = "\u0040\u0400\u8000\U00100000";
- String8 s = build(cs);
- CORE_TEST_TRUE(s == cs);
- CORE_TEST_TRUE(s == build(cs));
- CORE_TEST_TRUE(cs == s);
- CORE_TEST_TRUE(build(cs) == s);
- CORE_TEST_TRUE(s == s);
- }
- static void testInequality8() {
- String8 s = build("test");
- CORE_TEST_FALSE(s != "test");
- CORE_TEST_FALSE(s != build("test"));
- CORE_TEST_FALSE("test" != s);
- CORE_TEST_FALSE(build("test") != s);
- CORE_TEST_FALSE(s != s);
- }
- static void testStringAppend8() {
- String8 s = build("test");
- CORE_TEST_ERROR(s.append("22"));
- CORE_TEST_ERROR(s.append("333"));
- CORE_TEST_ERROR(s.append("4444"));
- CORE_TEST_EQUAL(build("test223334444"), s);
- }
- static void testStringAppendOverflow8() {
- Core::ArrayString<6, char> s;
- CORE_TEST_ERROR(s.append("te"));
- CORE_TEST_EQUAL(Core::Error::CAPACITY_REACHED, s.append("23334444"));
- CORE_TEST_TRUE(build("te23334444") != s);
- }
- static void testCharacters8() {
- String8 s = build("test");
- CORE_TEST_EQUAL('t', s[0]);
- CORE_TEST_EQUAL('e', s[1]);
- CORE_TEST_EQUAL('s', s[2]);
- CORE_TEST_EQUAL('t', s[3]);
- }
- static void testLength8() {
- String8 s = build("test");
- CORE_TEST_EQUAL(4, s.getLength());
- CORE_TEST_ERROR(s.append("aaa"));
- CORE_TEST_EQUAL(7, s.getLength());
- }
- static void testChar8() {
- String8 s = build("test");
- for(char i = 'a'; i < 'd'; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build("testabc"), s);
- }
- static void testSignedChar8() {
- String8 s = build("test");
- for(signed char i = 'b'; i < 'e'; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build("testbcd"), s);
- }
- static void testUnsignedChar8() {
- String8 s = build("test");
- for(unsigned char i = 'c'; i < 'f'; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build("testcde"), s);
- }
- static void testSignedShort8() {
- String8 s = build("test");
- for(signed short i = 100; i < 103; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build("test100101102"), s);
- }
- static void testUnsignedShort8() {
- String8 s = build("test");
- for(unsigned short i = 101; i < 104; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build("test101102103"), s);
- }
- static void testSignedInt8() {
- String8 s = build("test");
- for(signed int i = 102; i < 105; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build("test102103104"), s);
- }
- static void testUnsignedInt8() {
- String8 s = build("test");
- for(unsigned int i = 103; i < 106; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build("test103104105"), s);
- }
- static void testSignedLong8() {
- String8 s = build("test");
- for(signed long i = 104; i < 107; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build("test104105106"), s);
- }
- static void testUnsignedLong8() {
- String8 s = build("test");
- for(unsigned long i = 105; i < 108; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build("test105106107"), s);
- }
- static void testSignedLongLong8() {
- String8 s = build("test");
- for(signed long long i = 106; i < 109; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build("test106107108"), s);
- }
- static void testUnsignedLongLong8() {
- String8 s = build("test");
- for(unsigned long long i = 107; i < 110; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build("test107108109"), s);
- }
- static void testFloat8() {
- String8 s = build("test");
- for(float i = 108; i < 111; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build("test108.00109.00110.00"), s);
- }
- static void testDouble8() {
- String8 s = build("test");
- for(double i = 109; i < 112; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build("test109.00110.00111.00"), s);
- }
- static void testLongDouble8() {
- String8 s = build("test");
- for(long double i = 110; i < 113; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build("test110.00111.00112.00"), s);
- }
- static void testBool8() {
- String8 s = build("test");
- CORE_TEST_ERROR(s.append(true));
- CORE_TEST_ERROR(s.append(false));
- CORE_TEST_ERROR(s.append(true));
- CORE_TEST_EQUAL(build("testtruefalsetrue"), s);
- }
- static void testIntOverflow8() {
- Core::ArrayString<4, char> s;
- CORE_TEST_EQUAL(Core::Error::CAPACITY_REACHED, s.append(123456));
- String8 o;
- for(int i = 0; i < s.getCapacity(); i++) {
- CORE_TEST_ERROR(o.append(i + 1));
- }
- CORE_TEST_TRUE(o == s);
- }
- static void testUnicode8() {
- String8 s;
- CORE_TEST_ERROR(s.append('\u0040'));
- CORE_TEST_ERROR(s.append(L'\u0400'));
- CORE_TEST_ERROR(s.append(L'\u8000'));
- CORE_TEST_ERROR(s.append(U'\U00100000'));
- CORE_TEST_EQUAL(build("\u0040\u0400\u8000\U00100000"), s);
- }
- static void testClear8() {
- String8 s = build("test");
- CORE_TEST_ERROR(s.append(1234));
- s.clear();
- CORE_TEST_ERROR(s.append("wusi"));
- CORE_TEST_ERROR(s.append("1234"));
- CORE_TEST_EQUAL(build("wusi1234"), s);
- }
- static void testHashCode8() {
- String8 s;
- CORE_TEST_ERROR(s.append("a"));
- CORE_TEST_ERROR(s.append("bc"));
- CORE_TEST_ERROR(s.append(20));
- CORE_TEST_ERROR(s.append(25.5f));
- CORE_TEST_ERROR(s.append(true));
- CORE_TEST_EQUAL(build("abc2025.50true").hashCode(), s.hashCode());
- s.clear();
- CORE_TEST_EQUAL(String8().hashCode(), s.hashCode());
- }
- static void testAddSelf8() {
- String8 s;
- CORE_TEST_ERROR(s.append("test1"));
- CORE_TEST_ERROR(s.append(s));
- CORE_TEST_ERROR(s.append(s));
- CORE_TEST_EQUAL(build("test1test1test1test1"), s);
- }
- static void testAsHashMapKey8() {
- Core::HashMap<String8, int> map;
- CORE_TEST_ERROR(map.add(build("wusi"), 3));
- CORE_TEST_ERROR(map.add(build("hiThere"), 7));
- CORE_TEST_ERROR(map.add(build("baum123"), 5));
- int* a = map.search(build("wusi"));
- int* b = map.search(build("hiThere"));
- int* c = map.search(build("baum123"));
- int* d = map.search(build("423hifd"));
- CORE_TEST_NOT_NULL(a);
- CORE_TEST_NOT_NULL(b);
- CORE_TEST_NOT_NULL(c);
- CORE_TEST_NULL(d);
- if(a != nullptr && b != nullptr && c != nullptr) {
- CORE_TEST_EQUAL(3, *a);
- CORE_TEST_EQUAL(7, *b);
- CORE_TEST_EQUAL(5, *c);
- }
- }
- static void testStartsWith8() {
- String8 s;
- CORE_TEST_ERROR(s.append("0123456789"));
- String8 s2;
- CORE_TEST_ERROR(s2.append("123"));
- String8 s3;
- CORE_TEST_ERROR(s3.append("234"));
- String8 s4;
- CORE_TEST_ERROR(s4.append("789"));
- String8 s5;
- CORE_TEST_ERROR(s5.append("124"));
- String8 s6;
- String8 s7;
- CORE_TEST_ERROR(s7.append("7891"));
- CORE_TEST_FALSE(s.startsWidth(s2));
- CORE_TEST_TRUE(s.startsWidth(s2, 1));
- CORE_TEST_FALSE(s.startsWidth(s3));
- CORE_TEST_TRUE(s.startsWidth(s3, 2));
- CORE_TEST_FALSE(s.startsWidth(s4));
- CORE_TEST_TRUE(s.startsWidth(s4, 7));
- CORE_TEST_FALSE(s.startsWidth(s5));
- CORE_TEST_FALSE(s.startsWidth(s5, 3));
- CORE_TEST_TRUE(s.startsWidth(s6));
- CORE_TEST_TRUE(s.startsWidth(s6, 3));
- CORE_TEST_FALSE(s.startsWidth(s7));
- CORE_TEST_FALSE(s.startsWidth(s7, 7));
- }
- static void testSearch8() {
- String8 s;
- CORE_TEST_ERROR(s.append("0123456789"));
- String8 s2;
- CORE_TEST_ERROR(s2.append("123"));
- String8 s3;
- CORE_TEST_ERROR(s3.append("234"));
- String8 s4;
- CORE_TEST_ERROR(s4.append("789"));
- String8 s5;
- CORE_TEST_ERROR(s5.append("124"));
- String8 s6;
- String8 s7;
- CORE_TEST_ERROR(s7.append("7891"));
- CORE_TEST_EQUAL(1, s.search(s2));
- CORE_TEST_EQUAL(2, s.search(s3));
- CORE_TEST_EQUAL(7, s.search(s4));
- CORE_TEST_EQUAL(-1, s.search(s5));
- CORE_TEST_EQUAL(0, s.search(s6));
- CORE_TEST_EQUAL(-1, s.search(s7));
- CORE_TEST_EQUAL(-1, s.search(s2, 3));
- CORE_TEST_EQUAL(-1, s.search(s3, 3));
- CORE_TEST_EQUAL(7, s.search(s4, 3));
- CORE_TEST_EQUAL(-1, s.search(s5, 3));
- CORE_TEST_EQUAL(3, s.search(s6, 3));
- CORE_TEST_EQUAL(-1, s.search(s7, 3));
- }
- static void testContains8() {
- String8 s;
- CORE_TEST_ERROR(s.append("0123456789"));
- String8 s2;
- CORE_TEST_ERROR(s2.append("123"));
- String8 s3;
- CORE_TEST_ERROR(s3.append("234"));
- String8 s4;
- CORE_TEST_ERROR(s4.append("789"));
- String8 s5;
- CORE_TEST_ERROR(s5.append("124"));
- String8 s6;
- String8 s7;
- CORE_TEST_ERROR(s7.append("7891"));
- CORE_TEST_TRUE(s.contains(s2));
- CORE_TEST_TRUE(s.contains(s3));
- CORE_TEST_TRUE(s.contains(s4));
- CORE_TEST_FALSE(s.contains(s5));
- CORE_TEST_TRUE(s.contains(s6));
- CORE_TEST_FALSE(s.contains(s7));
- }
- static void testSearchChar8() {
- String8 s;
- CORE_TEST_ERROR(s.append("01üää3ä"));
- CORE_TEST_EQUAL(0, s.search('0'));
- CORE_TEST_EQUAL(1, s.search('1'));
- CORE_TEST_EQUAL(8, s.search('3'));
- }
- static void testContainsChar8() {
- String8 s;
- CORE_TEST_ERROR(s.append("01üää3ä"));
- CORE_TEST_TRUE(s.contains('0'));
- CORE_TEST_TRUE(s.contains('1'));
- CORE_TEST_TRUE(s.contains('3'));
- CORE_TEST_FALSE(s.contains('a'));
- }
- static void testSubString8() {
- String8 s;
- CORE_TEST_ERROR(s.append("01üää3ä"));
- CORE_TEST_STRING("01üää3ä", s.substring(-2));
- CORE_TEST_STRING("1üää3ä", s.substring(1));
- CORE_TEST_STRING("üää3ä", s.substring(2));
- CORE_TEST_STRING("ää3ä", s.substring(4));
- CORE_TEST_STRING("ä3ä", s.substring(6));
- CORE_TEST_STRING("01üää3ä", s.substring(0, 10));
- CORE_TEST_STRING("1üää3", s.substring(1, 8));
- CORE_TEST_STRING("üää", s.substring(2, 7));
- CORE_TEST_STRING("ä", s.substring(4, 5));
- CORE_TEST_STRING("", s.substring(4, 2));
- CORE_TEST_STRING("ä3ä", s.substring(6, 23));
- }
- static void testReplace8() {
- String8 s;
- CORE_TEST_ERROR(s.append("0äääää1üää3ä"));
- String8 search;
- CORE_TEST_ERROR(search.append("ää"));
- String8 replace;
- CORE_TEST_ERROR(replace.append("ABCD"));
- CORE_TEST_ERROR(s.replace(search, replace));
- CORE_TEST_STRING("0ABCDABCDä1üABCD3ä", s);
- String8 s2;
- CORE_TEST_ERROR(s2.append("0ABCDABCDä1üABCD3ä"));
- CORE_TEST_EQUAL(s2.hashCode(), s.hashCode());
- }
- static void testReplaceChar8() {
- String8 s;
- CORE_TEST_ERROR(s.append("01YXX3X"));
- s.replace('0', 'A');
- CORE_TEST_STRING("A1YXX3X", s);
- s.replace('1', 'B');
- CORE_TEST_STRING("ABYXX3X", s);
- s.replace('Y', 'C');
- CORE_TEST_STRING("ABCXX3X", s);
- s.replace('X', 'D');
- CORE_TEST_STRING("ABCDD3D", s);
- s.replace('3', 'E');
- CORE_TEST_STRING("ABCDDED", s);
- String8 s2;
- CORE_TEST_ERROR(s2.append("ABCDDED"));
- CORE_TEST_EQUAL(s2.hashCode(), s.hashCode());
- }
- static void testCastAppendSelf8() {
- String8 s;
- CORE_TEST_ERROR(s.append("abc"));
- CORE_TEST_ERROR(s.append(s));
- CORE_TEST_ERROR(s.append(static_cast<const char*>(s)));
- CORE_TEST_STRING("abcabcabcabc", s);
- }
- static String32 build(const c32* cs) {
- String32 s;
- CORE_TEST_ERROR(s.append(cs));
- return s;
- }
- static void testEquality32() {
- String32 s = build(U"test");
- CORE_TEST_TRUE(s == U"test");
- CORE_TEST_TRUE(s == build(U"test"));
- CORE_TEST_TRUE(U"test" == s);
- CORE_TEST_TRUE(build(U"test") == s);
- CORE_TEST_TRUE(s == s);
- }
- static void testUnicodeEquality32() {
- const c32* cs = U"\u0040\u0400\u8000\U00100000";
- String32 s = build(cs);
- CORE_TEST_TRUE(s == cs);
- CORE_TEST_TRUE(s == build(cs));
- CORE_TEST_TRUE(cs == s);
- CORE_TEST_TRUE(build(cs) == s);
- CORE_TEST_TRUE(s == s);
- }
- static void testInequality32() {
- String32 s = build(U"test");
- CORE_TEST_FALSE(s != U"test");
- CORE_TEST_FALSE(s != build(U"test"));
- CORE_TEST_FALSE(U"test" != s);
- CORE_TEST_FALSE(build(U"test") != s);
- CORE_TEST_FALSE(s != s);
- }
- static void testStringAppend32() {
- String32 s = build(U"test");
- CORE_TEST_ERROR(s.append(U"22"));
- CORE_TEST_ERROR(s.append(U"333"));
- CORE_TEST_ERROR(s.append(U"4444"));
- CORE_TEST_EQUAL(build(U"test223334444"), s);
- }
- static void testStringAppendOverflow32() {
- Core::ArrayString<6, c32> s;
- CORE_TEST_ERROR(s.append(U"te"));
- CORE_TEST_EQUAL(Core::Error::CAPACITY_REACHED, s.append(U"23334444"));
- CORE_TEST_TRUE(build(U"te23334444") != s);
- }
- static void testCharacters32() {
- String32 s = build(U"test");
- CORE_TEST_EQUAL('t', s[0]);
- CORE_TEST_EQUAL('e', s[1]);
- CORE_TEST_EQUAL('s', s[2]);
- CORE_TEST_EQUAL('t', s[3]);
- }
- static void testLength32() {
- String32 s = build(U"test");
- CORE_TEST_EQUAL(4, s.getLength());
- CORE_TEST_ERROR(s.append(U"aaa"));
- CORE_TEST_EQUAL(7, s.getLength());
- }
- static void testChar32() {
- String32 s = build(U"test");
- for(char i = 'a'; i < 'd'; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build(U"testabc"), s);
- }
- static void testSignedChar32() {
- String32 s = build(U"test");
- for(signed char i = 'b'; i < 'e'; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build(U"testbcd"), s);
- }
- static void testUnsignedChar32() {
- String32 s = build(U"test");
- for(unsigned char i = 'c'; i < 'f'; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build(U"testcde"), s);
- }
- static void testSignedShort32() {
- String32 s = build(U"test");
- for(signed short i = 100; i < 103; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build(U"test100101102"), s);
- }
- static void testUnsignedShort32() {
- String32 s = build(U"test");
- for(unsigned short i = 101; i < 104; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build(U"test101102103"), s);
- }
- static void testSignedInt32() {
- String32 s = build(U"test");
- for(signed int i = 102; i < 105; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build(U"test102103104"), s);
- }
- static void testUnsignedInt32() {
- String32 s = build(U"test");
- for(unsigned int i = 103; i < 106; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build(U"test103104105"), s);
- }
- static void testSignedLong32() {
- String32 s = build(U"test");
- for(signed long i = 104; i < 107; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build(U"test104105106"), s);
- }
- static void testUnsignedLong32() {
- String32 s = build(U"test");
- for(unsigned long i = 105; i < 108; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build(U"test105106107"), s);
- }
- static void testSignedLongLong32() {
- String32 s = build(U"test");
- for(signed long long i = 106; i < 109; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build(U"test106107108"), s);
- }
- static void testUnsignedLongLong32() {
- String32 s = build(U"test");
- for(unsigned long long i = 107; i < 110; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build(U"test107108109"), s);
- }
- static void testFloat32() {
- String32 s = build(U"test");
- for(float i = 108; i < 111; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build(U"test108.00109.00110.00"), s);
- }
- static void testDouble32() {
- String32 s = build(U"test");
- for(double i = 109; i < 112; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build(U"test109.00110.00111.00"), s);
- }
- static void testLongDouble32() {
- String32 s = build(U"test");
- for(long double i = 110; i < 113; i++) {
- CORE_TEST_ERROR(s.append(i));
- }
- CORE_TEST_EQUAL(build(U"test110.00111.00112.00"), s);
- }
- static void testBool32() {
- String32 s = build(U"test");
- CORE_TEST_ERROR(s.append(true));
- CORE_TEST_ERROR(s.append(false));
- CORE_TEST_ERROR(s.append(true));
- CORE_TEST_EQUAL(build(U"testtruefalsetrue"), s);
- }
- static void testIntOverflow32() {
- Core::ArrayString<4, c32> s;
- CORE_TEST_EQUAL(Core::Error::CAPACITY_REACHED, s.append(123456));
- String32 o;
- for(int i = 0; i < s.getCapacity(); i++) {
- CORE_TEST_ERROR(o.append(i + 1));
- }
- CORE_TEST_TRUE(o == s);
- }
- static void testUnicode32() {
- String32 s;
- CORE_TEST_ERROR(s.append('\u0040'));
- CORE_TEST_ERROR(s.append(L'\u0400'));
- CORE_TEST_ERROR(s.append(L'\u8000'));
- CORE_TEST_ERROR(s.append(U'\U00100000'));
- CORE_TEST_EQUAL(build(U"\u0040\u0400\u8000\U00100000"), s);
- }
- static void testClear32() {
- String32 s = build(U"test");
- CORE_TEST_ERROR(s.append(1234));
- s.clear();
- CORE_TEST_ERROR(s.append(U"wusi"));
- CORE_TEST_ERROR(s.append(U"1234"));
- CORE_TEST_EQUAL(build(U"wusi1234"), s);
- }
- static void testHashCode32() {
- String32 s;
- CORE_TEST_ERROR(s.append(U"a"));
- CORE_TEST_ERROR(s.append(U"bc"));
- CORE_TEST_ERROR(s.append(20));
- CORE_TEST_ERROR(s.append(25.5f));
- CORE_TEST_ERROR(s.append(true));
- CORE_TEST_EQUAL(build(U"abc2025.50true").hashCode(), s.hashCode());
- s.clear();
- CORE_TEST_EQUAL(String32().hashCode(), s.hashCode());
- }
- static void testAddSelf32() {
- String32 s;
- CORE_TEST_ERROR(s.append(U"test1"));
- CORE_TEST_ERROR(s.append(s));
- CORE_TEST_ERROR(s.append(s));
- CORE_TEST_EQUAL(build(U"test1test1test1test1"), s);
- }
- static void testAsHashMapKey32() {
- Core::HashMap<String32, int> map;
- CORE_TEST_ERROR(map.add(build(U"wusi"), 3));
- CORE_TEST_ERROR(map.add(build(U"hiThere"), 7));
- CORE_TEST_ERROR(map.add(build(U"baum123"), 5));
- int* a = map.search(build(U"wusi"));
- int* b = map.search(build(U"hiThere"));
- int* c = map.search(build(U"baum123"));
- int* d = map.search(build(U"423hifd"));
- CORE_TEST_NOT_NULL(a);
- CORE_TEST_NOT_NULL(b);
- CORE_TEST_NOT_NULL(c);
- CORE_TEST_NULL(d);
- if(a != nullptr && b != nullptr && c != nullptr) {
- CORE_TEST_EQUAL(3, *a);
- CORE_TEST_EQUAL(7, *b);
- CORE_TEST_EQUAL(5, *c);
- }
- }
- static void testStartsWith32() {
- String32 s;
- CORE_TEST_ERROR(s.append(U"0123456789"));
- String32 s2;
- CORE_TEST_ERROR(s2.append(U"123"));
- String32 s3;
- CORE_TEST_ERROR(s3.append(U"234"));
- String32 s4;
- CORE_TEST_ERROR(s4.append(U"789"));
- String32 s5;
- CORE_TEST_ERROR(s5.append(U"124"));
- String32 s6;
- String32 s7;
- CORE_TEST_ERROR(s7.append(U"7891"));
- CORE_TEST_FALSE(s.startsWidth(s2));
- CORE_TEST_TRUE(s.startsWidth(s2, 1));
- CORE_TEST_FALSE(s.startsWidth(s3));
- CORE_TEST_TRUE(s.startsWidth(s3, 2));
- CORE_TEST_FALSE(s.startsWidth(s4));
- CORE_TEST_TRUE(s.startsWidth(s4, 7));
- CORE_TEST_FALSE(s.startsWidth(s5));
- CORE_TEST_FALSE(s.startsWidth(s5, 3));
- CORE_TEST_TRUE(s.startsWidth(s6));
- CORE_TEST_TRUE(s.startsWidth(s6, 3));
- CORE_TEST_FALSE(s.startsWidth(s7));
- CORE_TEST_FALSE(s.startsWidth(s7, 7));
- }
- static void testSearch32() {
- String32 s;
- CORE_TEST_ERROR(s.append(U"0123456789"));
- String32 s2;
- CORE_TEST_ERROR(s2.append(U"123"));
- String32 s3;
- CORE_TEST_ERROR(s3.append(U"234"));
- String32 s4;
- CORE_TEST_ERROR(s4.append(U"789"));
- String32 s5;
- CORE_TEST_ERROR(s5.append(U"124"));
- String32 s6;
- String32 s7;
- CORE_TEST_ERROR(s7.append(U"7891"));
- CORE_TEST_EQUAL(1, s.search(s2));
- CORE_TEST_EQUAL(2, s.search(s3));
- CORE_TEST_EQUAL(7, s.search(s4));
- CORE_TEST_EQUAL(-1, s.search(s5));
- CORE_TEST_EQUAL(0, s.search(s6));
- CORE_TEST_EQUAL(-1, s.search(s7));
- CORE_TEST_EQUAL(-1, s.search(s2, 3));
- CORE_TEST_EQUAL(-1, s.search(s3, 3));
- CORE_TEST_EQUAL(7, s.search(s4, 3));
- CORE_TEST_EQUAL(-1, s.search(s5, 3));
- CORE_TEST_EQUAL(3, s.search(s6, 3));
- CORE_TEST_EQUAL(-1, s.search(s7, 3));
- }
- static void testContains32() {
- String32 s;
- CORE_TEST_ERROR(s.append(U"0123456789"));
- String32 s2;
- CORE_TEST_ERROR(s2.append(U"123"));
- String32 s3;
- CORE_TEST_ERROR(s3.append(U"234"));
- String32 s4;
- CORE_TEST_ERROR(s4.append(U"789"));
- String32 s5;
- CORE_TEST_ERROR(s5.append(U"124"));
- String32 s6;
- String32 s7;
- CORE_TEST_ERROR(s7.append(U"7891"));
- CORE_TEST_TRUE(s.contains(s2));
- CORE_TEST_TRUE(s.contains(s3));
- CORE_TEST_TRUE(s.contains(s4));
- CORE_TEST_FALSE(s.contains(s5));
- CORE_TEST_TRUE(s.contains(s6));
- CORE_TEST_FALSE(s.contains(s7));
- }
- static void testSearchChar32() {
- String32 s;
- CORE_TEST_ERROR(s.append(U"01üää3ä"));
- CORE_TEST_EQUAL(0, s.search('0'));
- CORE_TEST_EQUAL(1, s.search('1'));
- CORE_TEST_EQUAL(5, s.search('3'));
- CORE_TEST_EQUAL(2, s.search(U'ü'));
- CORE_TEST_EQUAL(3, s.search(U'ä'));
- CORE_TEST_EQUAL(4, s.search(U'ä', 4));
- CORE_TEST_EQUAL(6, s.search(U'ä', 5));
- }
- static void testContainsChar32() {
- String32 s;
- CORE_TEST_ERROR(s.append(U"01üää3ä"));
- CORE_TEST_TRUE(s.contains(U'0'));
- CORE_TEST_TRUE(s.contains(U'1'));
- CORE_TEST_TRUE(s.contains(U'3'));
- CORE_TEST_FALSE(s.contains(U'a'));
- CORE_TEST_TRUE(s.contains(U'0'));
- CORE_TEST_TRUE(s.contains(U'1'));
- CORE_TEST_TRUE(s.contains(U'ü'));
- CORE_TEST_TRUE(s.contains(U'ä'));
- CORE_TEST_FALSE(s.contains(U'ö'));
- }
- static void testSubString32() {
- String32 s;
- CORE_TEST_ERROR(s.append(U"01üää3ä"));
- CORE_TEST_STRING(U"01üää3ä", s.substring(-2));
- CORE_TEST_STRING(U"1üää3ä", s.substring(1));
- CORE_TEST_STRING(U"üää3ä", s.substring(2));
- CORE_TEST_STRING(U"ää3ä", s.substring(3));
- CORE_TEST_STRING(U"ä3ä", s.substring(4));
- CORE_TEST_STRING(U"01üää3ä", s.substring(0, 6));
- CORE_TEST_STRING(U"1üää3", s.substring(1, 5));
- CORE_TEST_STRING(U"üää", s.substring(2, 4));
- CORE_TEST_STRING(U"ä", s.substring(3, 3));
- CORE_TEST_STRING(U"", s.substring(4, 2));
- CORE_TEST_STRING(U"ä3ä", s.substring(4, 23));
- }
- static void testReplace32() {
- String32 s;
- CORE_TEST_ERROR(s.append(U"0äääää1üää3ä"));
- String32 search;
- CORE_TEST_ERROR(search.append(U"ää"));
- String32 replace;
- CORE_TEST_ERROR(replace.append(U"ABCD"));
- CORE_TEST_ERROR(s.replace(search, replace));
- CORE_TEST_STRING(U"0ABCDABCDä1üABCD3ä", s);
- String32 s2;
- CORE_TEST_ERROR(s2.append(U"0ABCDABCDä1üABCD3ä"));
- CORE_TEST_EQUAL(s2.hashCode(), s.hashCode());
- }
- static void testReplaceChar32() {
- String32 s;
- CORE_TEST_ERROR(s.append(U"01üää3ä"));
- s.replace(U'0', U'A');
- CORE_TEST_STRING(U"A1üää3ä", s);
- s.replace(U'1', U'B');
- CORE_TEST_STRING(U"ABüää3ä", s);
- s.replace(U'ü', U'C');
- CORE_TEST_STRING(U"ABCää3ä", s);
- s.replace(U'ä', U'D');
- CORE_TEST_STRING(U"ABCDD3D", s);
- s.replace(U'3', U'E');
- CORE_TEST_STRING(U"ABCDDED", s);
- String32 s2;
- CORE_TEST_ERROR(s2.append(U"ABCDDED"));
- CORE_TEST_EQUAL(s2.hashCode(), s.hashCode());
- }
- static void testCastAppendSelf32() {
- String32 s;
- CORE_TEST_ERROR(s.append("abc"));
- CORE_TEST_ERROR(s.append(s));
- CORE_TEST_ERROR(s.append(static_cast<const c32*>(s)));
- CORE_TEST_STRING("abcabcabcabc", s);
- }
- static void testConversion() {
- const c32* a = U"öüewfde_§$§%$ädsf";
- const char* b = "öüewfde_§$§%$ädsf";
- String32 sa;
- CORE_TEST_ERROR(sa.append(a));
- String8 sb;
- CORE_TEST_ERROR(sb.append(b));
- String8 sa2;
- CORE_TEST_ERROR(sa2.append(sa));
- String32 sb2;
- CORE_TEST_ERROR(sb2.append(sb));
- CORE_TEST_STRING(a, sa2);
- CORE_TEST_STRING(b, sb2);
- }
- void Core::ArrayStringTests::test() {
- testEquality8();
- testUnicodeEquality8();
- testInequality8();
- testStringAppend8();
- testStringAppendOverflow8();
- testCharacters8();
- testLength8();
- testChar8();
- testSignedChar8();
- testUnsignedChar8();
- testSignedShort8();
- testUnsignedShort8();
- testSignedInt8();
- testUnsignedInt8();
- testSignedLong8();
- testUnsignedLong8();
- testSignedLongLong8();
- testUnsignedLongLong8();
- testFloat8();
- testDouble8();
- testLongDouble8();
- testBool8();
- testIntOverflow8();
- testUnicode8();
- testClear8();
- testHashCode8();
- testAddSelf8();
- testAsHashMapKey8();
- testStartsWith8();
- testSearch8();
- testContains8();
- testSearchChar8();
- testContainsChar8();
- testSubString8();
- testReplace8();
- testReplaceChar8();
- testCastAppendSelf8();
- testEquality32();
- testUnicodeEquality32();
- testInequality32();
- testStringAppend32();
- testStringAppendOverflow32();
- testCharacters32();
- testLength32();
- testChar32();
- testSignedChar32();
- testUnsignedChar32();
- testSignedShort32();
- testUnsignedShort32();
- testSignedInt32();
- testUnsignedInt32();
- testSignedLong32();
- testUnsignedLong32();
- testSignedLongLong32();
- testUnsignedLongLong32();
- testFloat32();
- testDouble32();
- testLongDouble32();
- testBool32();
- testIntOverflow32();
- testUnicode32();
- testClear32();
- testHashCode32();
- testAddSelf32();
- testAsHashMapKey32();
- testStartsWith32();
- testSearch32();
- testContains32();
- testSearchChar32();
- testContainsChar32();
- testSubString32();
- testReplace32();
- testReplaceChar32();
- testCastAppendSelf32();
- testConversion();
- }
|