Files
fx/test/ds/ds-units.c

51 lines
1.2 KiB
C
Raw Permalink Normal View History

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