diff options
Diffstat (limited to 'main/tests/test_string.cpp')
-rw-r--r-- | main/tests/test_string.cpp | 138 |
1 files changed, 71 insertions, 67 deletions
diff --git a/main/tests/test_string.cpp b/main/tests/test_string.cpp index 84731746fa..775c039282 100644 --- a/main/tests/test_string.cpp +++ b/main/tests/test_string.cpp @@ -45,7 +45,6 @@ namespace TestString { bool test_1() { - OS::get_singleton()->print("\n\nTest 1: Assign from cstr\n"); String s = "Hello"; @@ -57,7 +56,6 @@ bool test_1() { } bool test_2() { - OS::get_singleton()->print("\n\nTest 2: Assign from string (operator=)\n"); String s = "Dolly"; @@ -70,7 +68,6 @@ bool test_2() { } bool test_3() { - OS::get_singleton()->print("\n\nTest 3: Assign from c-string (copycon)\n"); String s("Sheep"); @@ -83,7 +80,6 @@ bool test_3() { } bool test_4() { - OS::get_singleton()->print("\n\nTest 4: Assign from c-widechar (operator=)\n"); String s(L"Give me"); @@ -95,7 +91,6 @@ bool test_4() { } bool test_5() { - OS::get_singleton()->print("\n\nTest 5: Assign from c-widechar (copycon)\n"); String s(L"Wool"); @@ -107,67 +102,72 @@ bool test_5() { } bool test_6() { - OS::get_singleton()->print("\n\nTest 6: comparisons (equal)\n"); String s = "Test Compare"; OS::get_singleton()->print("\tComparing to \"Test Compare\"\n"); - if (!(s == "Test Compare")) + if (!(s == "Test Compare")) { return false; + } - if (!(s == L"Test Compare")) + if (!(s == L"Test Compare")) { return false; + } - if (!(s == String("Test Compare"))) + if (!(s == String("Test Compare"))) { return false; + } return true; } bool test_7() { - OS::get_singleton()->print("\n\nTest 7: comparisons (unequal)\n"); String s = "Test Compare"; OS::get_singleton()->print("\tComparing to \"Test Compare\"\n"); - if (!(s != "Peanut")) + if (!(s != "Peanut")) { return false; + } - if (!(s != L"Coconut")) + if (!(s != L"Coconut")) { return false; + } - if (!(s != String("Butter"))) + if (!(s != String("Butter"))) { return false; + } return true; } bool test_8() { - OS::get_singleton()->print("\n\nTest 8: comparisons (operator<)\n"); String s = "Bees"; OS::get_singleton()->print("\tComparing to \"Bees\"\n"); - if (!(s < "Elephant")) + if (!(s < "Elephant")) { return false; + } - if (s < L"Amber") + if (s < L"Amber") { return false; + } - if (s < String("Beatrix")) + if (s < String("Beatrix")) { return false; + } return true; } bool test_9() { - OS::get_singleton()->print("\n\nTest 9: Concatenation\n"); String s; @@ -186,23 +186,24 @@ bool test_9() { } bool test_10() { - OS::get_singleton()->print("\n\nTest 10: Misc funcs (size/length/empty/etc)\n"); - if (!String("").empty()) + if (!String("").empty()) { return false; + } - if (String("Mellon").size() != 7) + if (String("Mellon").size() != 7) { return false; + } - if (String("Oranges").length() != 7) + if (String("Oranges").length() != 7) { return false; + } return true; } bool test_11() { - OS::get_singleton()->print("\n\nTest 11: Operator[]\n"); String a = "Kugar Sane"; @@ -210,32 +211,34 @@ bool test_11() { a[0] = 'S'; a[6] = 'C'; - if (a != "Sugar Cane") + if (a != "Sugar Cane") { return false; + } - if (a[1] != 'u') + if (a[1] != 'u') { return false; + } return true; } bool test_12() { - OS::get_singleton()->print("\n\nTest 12: case functions\n"); String a = "MoMoNgA"; - if (a.to_upper() != "MOMONGA") + if (a.to_upper() != "MOMONGA") { return false; + } - if (a.nocasecmp_to("momonga") != 0) + if (a.nocasecmp_to("momonga") != 0) { return false; + } return true; } bool test_13() { - OS::get_singleton()->print("\n\nTest 13: UTF8\n"); /* how can i embed UTF in here? */ @@ -252,7 +255,6 @@ bool test_13() { } bool test_14() { - OS::get_singleton()->print("\n\nTest 14: ASCII\n"); String s = L"Primero Leche"; @@ -263,7 +265,6 @@ bool test_14() { } bool test_15() { - OS::get_singleton()->print("\n\nTest 15: substr\n"); String s = "Killer Baby"; @@ -273,7 +274,6 @@ bool test_15() { } bool test_16() { - OS::get_singleton()->print("\n\nTest 16: find\n"); String s = "Pretty Woman"; @@ -281,17 +281,18 @@ bool test_16() { OS::get_singleton()->print("\t\"tty\" is at %i pos.\n", s.find("tty")); OS::get_singleton()->print("\t\"Revenge of the Monster Truck\" is at %i pos.\n", s.find("Revenge of the Monster Truck")); - if (s.find("tty") != 3) + if (s.find("tty") != 3) { return false; + } - if (s.find("Revenge of the Monster Truck") != -1) + if (s.find("Revenge of the Monster Truck") != -1) { return false; + } return true; } bool test_17() { - OS::get_singleton()->print("\n\nTest 17: find no case\n"); String s = "Pretty Whale"; @@ -299,17 +300,18 @@ bool test_17() { OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n", s.findn("WHA")); OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n", s.findn("Revenge of the Monster Truck")); - if (s.findn("WHA") != 7) + if (s.findn("WHA") != 7) { return false; + } - if (s.findn("Revenge of the Monster SawFish") != -1) + if (s.findn("Revenge of the Monster SawFish") != -1) { return false; + } return true; } bool test_18() { - OS::get_singleton()->print("\n\nTest 18: find no case\n"); String s = "Pretty Whale"; @@ -317,17 +319,18 @@ bool test_18() { OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n", s.findn("WHA")); OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n", s.findn("Revenge of the Monster Truck")); - if (s.findn("WHA") != 7) + if (s.findn("WHA") != 7) { return false; + } - if (s.findn("Revenge of the Monster SawFish") != -1) + if (s.findn("Revenge of the Monster SawFish") != -1) { return false; + } return true; } bool test_19() { - OS::get_singleton()->print("\n\nTest 19: Search & replace\n"); String s = "Happy Birthday, Anna!"; @@ -340,7 +343,6 @@ bool test_19() { } bool test_20() { - OS::get_singleton()->print("\n\nTest 20: Insertion\n"); String s = "Who is Frederic?"; @@ -353,7 +355,6 @@ bool test_20() { } bool test_21() { - OS::get_singleton()->print("\n\nTest 21: Number -> String\n"); OS::get_singleton()->print("\tPi is %f\n", 33.141593); @@ -363,7 +364,6 @@ bool test_21() { } bool test_22() { - OS::get_singleton()->print("\n\nTest 22: String -> Int\n"); static const char *nums[4] = { "1237461283", "- 22", "0", " - 1123412" }; @@ -372,15 +372,15 @@ bool test_22() { for (int i = 0; i < 4; i++) { OS::get_singleton()->print("\tString: \"%s\" as Int is %i\n", nums[i], String(nums[i]).to_int()); - if (String(nums[i]).to_int() != num[i]) + if (String(nums[i]).to_int() != num[i]) { return false; + } } return true; } bool test_23() { - OS::get_singleton()->print("\n\nTest 23: String -> Float\n"); static const char *nums[4] = { "-12348298412.2", "0.05", "2.0002", " -0.0001" }; @@ -389,15 +389,15 @@ bool test_23() { for (int i = 0; i < 4; i++) { OS::get_singleton()->print("\tString: \"%s\" as Float is %f\n", nums[i], String(nums[i]).to_double()); - if (ABS(String(nums[i]).to_double() - num[i]) > 0.00001) + if (ABS(String(nums[i]).to_double() - num[i]) > 0.00001) { return false; + } } return true; } bool test_24() { - OS::get_singleton()->print("\n\nTest 24: Slicing\n"); String s = "Mars,Jupiter,Saturn,Uranus"; @@ -407,18 +407,17 @@ bool test_24() { OS::get_singleton()->print("\tSlicing \"%ls\" by \"%s\"..\n", s.c_str(), ","); for (int i = 0; i < s.get_slice_count(","); i++) { - OS::get_singleton()->print("\t\t%i- %ls\n", i + 1, s.get_slice(",", i).c_str()); - if (s.get_slice(",", i) != slices[i]) + if (s.get_slice(",", i) != slices[i]) { return false; + } } return true; } bool test_25() { - OS::get_singleton()->print("\n\nTest 25: Erasing\n"); String s = "Josephine is such a cute girl!"; @@ -433,7 +432,6 @@ bool test_25() { } bool test_26() { - OS::get_singleton()->print("\n\nTest 26: RegEx substitution\n"); #ifndef MODULE_REGEX_ENABLED @@ -461,7 +459,6 @@ struct test_27_data { }; bool test_27() { - OS::get_singleton()->print("\n\nTest 27: begins_with\n"); test_27_data tc[] = { { "res://foobar", "res://", true }, @@ -486,7 +483,6 @@ bool test_27() { }; bool test_28() { - OS::get_singleton()->print("\n\nTest 28: sprintf\n"); bool success, state = true; @@ -822,7 +818,6 @@ bool test_28() { } bool test_29() { - bool state = true; IP_Address ip0("2001:0db8:85a3:0000:0000:8a2e:0370:7334"); @@ -972,28 +967,35 @@ bool test_31() { String a = ""; success = a[0] == 0; OS::get_singleton()->print("Is 0 String[0]:, %s\n", success ? "OK" : "FAIL"); - if (!success) state = false; + if (!success) { + state = false; + } String b = "Godot"; success = b[b.size()] == 0; OS::get_singleton()->print("Is 0 String[size()]:, %s\n", success ? "OK" : "FAIL"); - if (!success) state = false; + if (!success) { + state = false; + } const String c = ""; success = c[0] == 0; OS::get_singleton()->print("Is 0 const String[0]:, %s\n", success ? "OK" : "FAIL"); - if (!success) state = false; + if (!success) { + state = false; + } const String d = "Godot"; success = d[d.size()] == 0; OS::get_singleton()->print("Is 0 const String[size()]:, %s\n", success ? "OK" : "FAIL"); - if (!success) state = false; + if (!success) { + state = false; + } return state; }; bool test_32() { - #define STRIP_TEST(x) \ { \ bool success = x; \ @@ -1071,7 +1073,7 @@ bool test_33() { OS::get_singleton()->print("\n\nTest 33: parse_utf8(null, -1)\n"); String empty; - return empty.parse_utf8(NULL, -1); + return empty.parse_utf8(nullptr, -1); } bool test_34() { @@ -1125,7 +1127,7 @@ bool test_35() { return state; } -typedef bool (*TestFunc)(void); +typedef bool (*TestFunc)(); TestFunc test_funcs[] = { @@ -1164,12 +1166,11 @@ TestFunc test_funcs[] = { test_33, test_34, test_35, - 0 + nullptr }; MainLoop *test() { - /** A character length != wchar_t may be forced, so the tests won't work */ static_assert(sizeof(CharType) == sizeof(wchar_t)); @@ -1178,11 +1179,13 @@ MainLoop *test() { int passed = 0; while (true) { - if (!test_funcs[count]) + if (!test_funcs[count]) { break; + } bool pass = test_funcs[count](); - if (pass) + if (pass) { passed++; + } OS::get_singleton()->print("\t%s\n", pass ? "PASS" : "FAILED"); count++; @@ -1195,6 +1198,7 @@ MainLoop *test() { OS::get_singleton()->print("Passed %i of %i tests\n", passed, count); - return NULL; + return nullptr; } + } // namespace TestString |