summaryrefslogtreecommitdiff
path: root/main/tests/test_string.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main/tests/test_string.cpp')
-rw-r--r--main/tests/test_string.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/main/tests/test_string.cpp b/main/tests/test_string.cpp
index 05df888f40..7a41880645 100644
--- a/main/tests/test_string.cpp
+++ b/main/tests/test_string.cpp
@@ -432,6 +432,10 @@ bool test_26() {
OS::get_singleton()->print("\n\nTest 26: RegEx substitution\n");
+#ifndef MODULE_REGEX_ENABLED
+ OS::get_singleton()->print("\tRegEx module disabled, can't run test.");
+ return false;
+#else
String s = "Double all the vowels.";
OS::get_singleton()->print("\tString: %ls\n", s.c_str());
@@ -443,6 +447,7 @@ bool test_26() {
OS::get_singleton()->print("\tResult: %ls\n", s.c_str());
return (s == "Doouublee aall thee vooweels.");
+#endif
}
struct test_27_data {
@@ -1078,6 +1083,44 @@ bool test_34() {
return state;
}
+bool test_35() {
+#define COUNT_TEST(x) \
+ { \
+ bool success = x; \
+ state = state && success; \
+ if (!success) { \
+ OS::get_singleton()->print("\tfailed at: %s\n", #x); \
+ } \
+ }
+
+ OS::get_singleton()->print("\n\nTest 35: count and countn function\n");
+ bool state = true;
+
+ COUNT_TEST(String("").count("Test") == 0);
+ COUNT_TEST(String("Test").count("") == 0);
+ COUNT_TEST(String("Test").count("test") == 0);
+ COUNT_TEST(String("Test").count("TEST") == 0);
+ COUNT_TEST(String("TEST").count("TEST") == 1);
+ COUNT_TEST(String("Test").count("Test") == 1);
+ COUNT_TEST(String("aTest").count("Test") == 1);
+ COUNT_TEST(String("Testa").count("Test") == 1);
+ COUNT_TEST(String("TestTestTest").count("Test") == 3);
+ COUNT_TEST(String("TestTestTest").count("TestTest") == 1);
+ COUNT_TEST(String("TestGodotTestGodotTestGodot").count("Test") == 3);
+
+ COUNT_TEST(String("TestTestTestTest").count("Test", 4, 8) == 1);
+ COUNT_TEST(String("TestTestTestTest").count("Test", 4, 12) == 2);
+ COUNT_TEST(String("TestTestTestTest").count("Test", 4, 16) == 3);
+ COUNT_TEST(String("TestTestTestTest").count("Test", 4) == 3);
+
+ COUNT_TEST(String("Test").countn("test") == 1);
+ COUNT_TEST(String("Test").countn("TEST") == 1);
+ COUNT_TEST(String("testTest-Testatest").countn("tEst") == 4);
+ COUNT_TEST(String("testTest-TeStatest").countn("tEsT", 4, 16) == 2);
+
+ return state;
+}
+
typedef bool (*TestFunc)(void);
TestFunc test_funcs[] = {
@@ -1116,6 +1159,7 @@ TestFunc test_funcs[] = {
test_32,
test_33,
test_34,
+ test_35,
0
};