summaryrefslogtreecommitdiff
path: root/src/user/app/tests/libc
diff options
context:
space:
mode:
authordzwdz2022-08-22 13:43:02 +0200
committerdzwdz2022-08-22 13:43:02 +0200
commit6a4eb86c64fa42abcf9199cd968be089ee04c3bc (patch)
tree9fc38291dc469bef2bf7a10cca70459d68068990 /src/user/app/tests/libc
parente35d6a4fde9a0671bc7d2527ff6b55b0ce1b4b1e (diff)
user/libc: strspn, strtok
Diffstat (limited to 'src/user/app/tests/libc')
-rw-r--r--src/user/app/tests/libc/string.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/user/app/tests/libc/string.c b/src/user/app/tests/libc/string.c
index 53fe1c0..f865d72 100644
--- a/src/user/app/tests/libc/string.c
+++ b/src/user/app/tests/libc/string.c
@@ -65,9 +65,45 @@ static void test_strtol(void) {
test(!strcmp("hello", end));
}
+static void test_strspn(void) {
+ test(0 == strspn("", "1234"));
+ test(0 == strspn("asdf", "1234"));
+ test(0 == strspn("a2df", "1234"));
+ test(2 == strspn("42df", "1234"));
+ test(4 == strspn("4211", "1234"));
+
+ test(0 == strcspn("", "1234"));
+ test(4 == strcspn("asdf", "1234"));
+ test(1 == strcspn("a2df", "1234"));
+}
+
+static void test_strtok(void) {
+ const char *sep = " \t";
+ {
+ char line[] = "LINE TO BE SEPARATED";
+ test(!strcmp(strtok(line, sep), "LINE"));
+ test(!strcmp(strtok(NULL, sep), "TO"));
+ test(!strcmp(strtok(NULL, sep), "BE"));
+ test(!strcmp(strtok(NULL, sep), "SEPARATED"));
+ for (int i = 0; i < 4; i++)
+ test(strtok(NULL, sep) == NULL);
+ }
+ {
+ char line[] = " LINE TO\tBE \t SEPARATED ";
+ test(!strcmp(strtok(line, sep), "LINE"));
+ test(!strcmp(strtok(NULL, sep), "TO"));
+ test(!strcmp(strtok(NULL, sep), "BE"));
+ test(!strcmp(strtok(NULL, sep), "SEPARATED"));
+ for (int i = 0; i < 4; i++)
+ test(strtok(NULL, sep) == NULL);
+ }
+}
+
void r_libc_string(void) {
run_test(test_memcmp);
run_test(test_memset);
run_test(test_strcmp);
run_test(test_strtol);
+ run_test(test_strspn);
+ run_test(test_strtok);
}