Luna/tests/libc/string.c

63 lines
922 B
C
Raw Normal View History

2022-10-16 13:31:58 +00:00
#include "Test.h"
#include <string.h>
DEFINE_TEST(strlen)
{
START_TEST(strlen);
const char* str = "Hello, World!";
size_t len = strlen(str);
EXPECT_EQ(len, 13);
char null[] = {'\0'};
len = strlen(null);
EXPECT_EQ(len, 0);
2022-10-16 14:00:14 +00:00
TEST_SUCCESS();
}
DEFINE_TEST(strnlen)
{
START_TEST(strnlen);
const char* str = "What is going on?";
size_t len = strnlen(str, 20);
EXPECT_EQ(len, 17);
len = strnlen(str, 15);
EXPECT_EQ(len, 15);
char buf[] = {'H', 'e', 'l', 'l', 'o'};
len = strnlen(buf, sizeof(buf));
EXPECT_EQ(len, sizeof(buf));
2022-10-22 09:57:25 +00:00
TEST_SUCCESS();
}
DEFINE_TEST(strcspn)
{
START_TEST(strcspn);
const char* str = "This string has vowels";
const char* vowels = "aeiou";
size_t len = strcspn(str, vowels);
EXPECT_EQ(len, 2);
str = "WWWWW";
len = strcspn(str, vowels);
EXPECT_EQ(len, 5);
2022-10-16 13:31:58 +00:00
TEST_SUCCESS();
}