summaryrefslogtreecommitdiff
path: root/project-base/tests/test_string_utils.c
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-11-23 22:33:43 +0100
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-11-23 22:33:43 +0100
commitb1e857cf1471d1871a9396696b22fa531da98249 (patch)
tree3923008a8653057698cb339faf6dcfa92e18364b /project-base/tests/test_string_utils.c
parent106bb7fcadf637cec883648916cc8d19529d6199 (diff)
add projbase to repo
Diffstat (limited to 'project-base/tests/test_string_utils.c')
-rw-r--r--project-base/tests/test_string_utils.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/project-base/tests/test_string_utils.c b/project-base/tests/test_string_utils.c
new file mode 100644
index 0000000..99cea65
--- /dev/null
+++ b/project-base/tests/test_string_utils.c
@@ -0,0 +1,60 @@
+
+s32 test_string_to_number()
+{
+ error_if(string_to_u64("5294967295") != 5294967295);
+ error_if(string_to_u32("294967295") != 294967295);
+ error_if(string_to_u16("2544") != 2544);
+ error_if(string_to_u8("244") != 244);
+
+ error_if(string_to_s64("-12") != -12);
+ error_if(string_to_s32("-12") != -12);
+ error_if(string_to_s16("-12") != -12);
+ error_if(string_to_s8("-12") != -12);
+
+ error_if(string_to_f32("-1.259223") != -1.259223f);
+ error_if(string_to_f64("346.12323") != 346.12323);
+
+ success;
+}
+
+s32 test_string_contains()
+{
+ error_if(string_contains("lll", "llll*"));
+ error_if(string_contains("lllll", "l*lop"));
+ error_if(string_contains("hello world", "h?lo"));
+ error_if(string_contains("hello world", "h*lo")); // The first L(1) matches with the first L(2), so the next check would be l == o, hence failure.
+ error_if(string_contains("lllll", "llll*l"));
+ error_if(string_contains("lllll", "*llllll*"));
+
+ error_if(!string_contains("22lllll", "l*l"));
+ error_if(!string_contains(" wsdf asd \"hello sailor\" asdf asdf ", "sailor"));
+ error_if(!string_contains(" wsdf asd \"hello sailor\" asdf asdf ", "*sailor"));
+ error_if(!string_contains(" wsdf asd \"hello sailor\" asdf asdf ", "*sailor\""));
+ error_if(!string_contains(" wsdf asd \"hello sailor\" asdf asdf ", "*sailor*"));
+ error_if(!string_contains(" wsdf asd \"hello sailor\" asdf asdf ", "sailor*"));
+ error_if(!string_contains("22lllll pi23hjp rbksje LSKJDh l", "LS*"));
+ error_if(!string_contains("22lllll lal", "l*l"));
+ error_if(!string_contains("lllll", "*l*l"));
+ error_if(!string_contains("hello world", "hello"));
+ error_if(!string_contains("hello world", "h?llo"));
+ error_if(!string_contains("hello world", "h????"));
+ error_if(!string_contains("hello world", "*"));
+ error_if(!string_contains("hello world", "h*"));
+ error_if(!string_contains("hello world", "*o"));
+ error_if(!string_contains("hello world", "h*o"));
+ error_if(!string_contains("hello world", "*lo"));
+ error_if(!string_contains("hello world", "hello"));
+ error_if(!string_contains("lllll", "l*l"));
+ error_if(!string_contains("lllll", "lllll"));
+ error_if(!string_contains("lllll", "l*lll"));
+ error_if(!string_contains("lllll", "*"));
+ error_if(!string_contains("lllll", "l?lll"));
+ error_if(!string_contains("lllll", "lllll"));
+ error_if(!string_contains("lllll", "*llll"));
+ error_if(!string_contains("lllll", "llll*"));
+ error_if(!string_contains("lllll", "*llll*"));
+ error_if(!string_contains("lllll", "*lllll*"));
+ error_if(!string_contains("lllll", "*ll*"));
+
+ success;
+} \ No newline at end of file