Files
fx/test/ds/ds-units.c
2026-03-16 10:35:43 +00:00

51 lines
1.2 KiB
C

#include <CuTest.h>
#include <fx/ds/string.h>
static void test_string_create(CuTest *tc)
{
fx_string *str = fx_string_create();
CuAssertPtrNotNull(tc, str);
CuAssertIntEquals(tc, 0, fx_string_get_size(str, FX_STRLEN_NORMAL));
CuAssertStrEquals(tc, "", fx_string_ptr(str));
fx_string_unref(str);
str = fx_string_create_from_c('A', 8);
CuAssertPtrNotNull(tc, str);
CuAssertIntEquals(tc, 8, fx_string_get_size(str, FX_STRLEN_NORMAL));
CuAssertStrEquals(tc, "AAAAAAAA", fx_string_ptr(str));
fx_string_unref(str);
str = fx_string_create_from_cstr("Hello, world!");
CuAssertPtrNotNull(tc, str);
CuAssertIntEquals(tc, 13, fx_string_get_size(str, FX_STRLEN_NORMAL));
CuAssertStrEquals(tc, "Hello, world!", fx_string_ptr(str));
fx_string_unref(str);
}
static void test_string_length(CuTest *tc)
{
const char *cstr = "Hello, \033[91;1mworld!";
fx_string *s = fx_string_create_from_cstr(cstr);
CuAssertIntEquals(tc, 13, fx_string_get_size(s, FX_STRLEN_IGNORE_ESC));
CuAssertIntEquals(tc, 20, fx_string_get_size(s, FX_STRLEN_NORMAL));
fx_string_unref(s);
}
CuSuite *get_all_tests(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_string_create);
SUITE_ADD_TEST(suite, test_string_length);
return suite;
}