--- a/tests/test_string.c Sun Dec 28 14:10:14 2025 +0100 +++ b/tests/test_string.c Sun Dec 28 14:47:36 2025 +0100 @@ -63,15 +63,19 @@ } } -CX_TEST(test_string_cast) { +CX_TEST(test_strcast) { char *c1 = (char*) "123"; const char *c2 = "abcde"; unsigned char *c3 = (unsigned char*) "4711"; unsigned const char *c4 = (unsigned const char*) "xyz0815"; + cxstring c5 = cx_str("foobar"); + cxmutstr c6 = cx_mutstr((char*)"hello world"); cxstring s1 = cx_strcast(c1); cxstring s2 = cx_strcast(c2); cxstring s3 = cx_strcast(c3); cxstring s4 = cx_strcast(c4); + cxstring s5 = cx_strcast(c5); + cxstring s6 = cx_strcast(c6); CX_TEST_DO { CX_TEST_ASSERT(s1.length == 3); CX_TEST_ASSERT(strncmp(s1.ptr, "123", 3) == 0); @@ -81,6 +85,39 @@ CX_TEST_ASSERT(strncmp(s3.ptr, "4711", 4) == 0); CX_TEST_ASSERT(s4.length == 7); CX_TEST_ASSERT(strncmp(s4.ptr, "xyz0815", 7) == 0); + CX_TEST_ASSERT(s5.length == 6); + CX_TEST_ASSERT(strncmp(s5.ptr, "foobar", 6) == 0); + CX_TEST_ASSERT(s6.length == 11); + CX_TEST_ASSERT(strncmp(s6.ptr, "hello world", 11) == 0); + } +} + +CX_TEST(test_strcast_m) { + char *c1 = (char*) "123"; + const char *c2 = "abcde"; + unsigned char *c3 = (unsigned char*) "4711"; + unsigned const char *c4 = (unsigned const char*) "xyz0815"; + cxstring c5 = cx_str("foobar"); + cxmutstr c6 = cx_mutstr((char*)"hello world"); + cxmutstr s1 = cx_strcast_m(c1); + cxstring s2 = cx_strcast_m(c2); + cxmutstr s3 = cx_strcast_m(c3); + cxstring s4 = cx_strcast_m(c4); + cxstring s5 = cx_strcast_m(c5); + cxmutstr s6 = cx_strcast_m(c6); + CX_TEST_DO { + CX_TEST_ASSERT(s1.length == 3); + CX_TEST_ASSERT(strncmp(s1.ptr, "123", 3) == 0); + CX_TEST_ASSERT(s2.length == 5); + CX_TEST_ASSERT(strncmp(s2.ptr, "abcde", 5) == 0); + CX_TEST_ASSERT(s3.length == 4); + CX_TEST_ASSERT(strncmp(s3.ptr, "4711", 4) == 0); + CX_TEST_ASSERT(s4.length == 7); + CX_TEST_ASSERT(strncmp(s4.ptr, "xyz0815", 7) == 0); + CX_TEST_ASSERT(s5.length == 6); + CX_TEST_ASSERT(strncmp(s5.ptr, "foobar", 6) == 0); + CX_TEST_ASSERT(s6.length == 11); + CX_TEST_ASSERT(strncmp(s6.ptr, "hello world", 11) == 0); } } @@ -1513,7 +1550,7 @@ cxstring str = cx_str("Hello, World!"); CX_TEST_DO { char actual[64]; - snprintf(actual, 64, "Test %"CX_PRIstr " Success.", CX_SFMT(str)); + snprintf(actual, 64, "Test %" CX_PRIstr " Success.", CX_SFMT(str)); CX_TEST_ASSERT(0 == strncmp("Test Hello, World! Success.", actual, 64)); } } @@ -1522,7 +1559,8 @@ CxTestSuite *suite = cx_test_suite_new("string"); cx_test_register(suite, test_string_construct); - cx_test_register(suite, test_string_cast); + cx_test_register(suite, test_strcast); + cx_test_register(suite, test_strcast_m); cx_test_register(suite, test_strfree); cx_test_register(suite, test_strdup); cx_test_register(suite, test_strdup_shortened);