diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/utils_str.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/utils_str.c b/test/utils_str.c index c592f6100a..f184abffa6 100644 --- a/test/utils_str.c +++ b/test/utils_str.c @@ -260,6 +260,33 @@ static int test_snprintf(void) TEST_CHECK(strncmp(buffer, "1234", sizeof(buffer))); } +static int test_strcspn(void) +{ + const char str1[] = "abc"; + const char str2[] = "This is a string\nwith newlines!"; + + TEST_EQ(strcspn(str1, "a"), (size_t)0, "%zu"); + TEST_EQ(strcspn(str1, "b"), (size_t)1, "%zu"); + TEST_EQ(strcspn(str1, "c"), (size_t)2, "%zu"); + TEST_EQ(strcspn(str1, "ccc"), (size_t)2, "%zu"); + TEST_EQ(strcspn(str1, "cba"), (size_t)0, "%zu"); + TEST_EQ(strcspn(str1, "cb"), (size_t)1, "%zu"); + TEST_EQ(strcspn(str1, "bc"), (size_t)1, "%zu"); + TEST_EQ(strcspn(str1, "cbc"), (size_t)1, "%zu"); + TEST_EQ(strcspn(str1, "z"), strlen(str1), "%zu"); + TEST_EQ(strcspn(str1, "xyz"), strlen(str1), "%zu"); + TEST_EQ(strcspn(str1, ""), strlen(str1), "%zu"); + + TEST_EQ(strcspn(str2, " "), (size_t)4, "%zu"); + TEST_EQ(strcspn(str2, "\n"), (size_t)16, "%zu"); + TEST_EQ(strcspn(str2, "\n "), (size_t)4, "%zu"); + TEST_EQ(strcspn(str2, "!"), strlen(str2) - 1, "%zu"); + TEST_EQ(strcspn(str2, "z"), strlen(str2), "%zu"); + TEST_EQ(strcspn(str2, "z!"), strlen(str2) - 1, "%zu"); + + return EC_SUCCESS; +} + void run_test(int argc, char **argv) { test_reset(); @@ -279,6 +306,7 @@ void run_test(int argc, char **argv) RUN_TEST(test_strncasecmp); RUN_TEST(test_atoi); RUN_TEST(test_snprintf); + RUN_TEST(test_strcspn); test_print_result(); } |