--- a/tests/test_string.c Sat Dec 13 12:50:37 2025 +0100 +++ b/tests/test_string.c Sat Dec 13 12:54:56 2025 +0100 @@ -39,7 +39,7 @@ #str " is not zero terminated") CX_TEST(test_string_construct) { - cxstring s1 = CX_STR("1234"); + cxstring s1 = cx_str("1234"); cxstring s2 = cx_strn("abcd", 2); cxmutstr s3 = cx_mutstr((char *) "1234"); cxmutstr s4 = cx_mutstrn((char *) "abcd", 2); @@ -105,7 +105,7 @@ } CX_TEST(test_strdup) { - cxstring str = CX_STR("test"); + cxstring str = cx_str("test"); cxmutstr dup = cx_strdup(str); CX_TEST_DO { CX_TEST_ASSERT(dup.length == str.length); @@ -116,7 +116,7 @@ } CX_TEST(test_strdup_shortened) { - cxstring str = CX_STR("test"); + cxstring str = cx_str("test"); str.length = 2; cxmutstr dup = cx_strdup(str); CX_TEST_DO { @@ -131,35 +131,35 @@ CxTestingAllocator talloc; cx_testing_allocator_init(&talloc); const CxAllocator *alloc = &talloc.base; - cxstring str = CX_STR("test string"); + cxstring str = cx_str("test string"); str.length = 8; // test with a non-zero-terminated source cxmutstr dup; CX_TEST_DO { // copy into a smaller string - dup = cx_strdup_a(alloc, CX_STR("hello")); + dup = cx_strdup_a(alloc, "hello"); CX_TEST_ASSERT(0 == cx_strcpy_a(alloc, &dup, str)); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(dup), CX_STR("test str"))); + CX_TEST_ASSERT(0 == cx_strcmp(dup, "test str")); ASSERT_ZERO_TERMINATED(dup); cx_strfree_a(alloc, &dup); // copy into a larger string - dup = cx_strdup_a(alloc, CX_STR("hello, world!")); + dup = cx_strdup_a(alloc, "hello, world!"); CX_TEST_ASSERT(0 == cx_strcpy_a(alloc, &dup, str)); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(dup), CX_STR("test str"))); + CX_TEST_ASSERT(0 == cx_strcmp(dup, "test str")); ASSERT_ZERO_TERMINATED(dup); cx_strfree_a(alloc, &dup); // copy into an equal-length string - dup = cx_strdup_a(alloc, CX_STR("testing!")); + dup = cx_strdup_a(alloc, "testing!"); CX_TEST_ASSERT(0 == cx_strcpy_a(alloc, &dup, str)); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(dup), CX_STR("test str"))); + CX_TEST_ASSERT(0 == cx_strcmp(dup, "test str")); ASSERT_ZERO_TERMINATED(dup); cx_strfree_a(alloc, &dup); // copy into a NULL-string dup.ptr = NULL; CX_TEST_ASSERT(0 == cx_strcpy_a(alloc, &dup, str)); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(dup), CX_STR("test str"))); + CX_TEST_ASSERT(0 == cx_strcmp(dup, "test str")); ASSERT_ZERO_TERMINATED(dup); cx_strfree_a(alloc, &dup); } @@ -167,9 +167,9 @@ } CX_TEST(test_strlen) { - cxstring s1 = CX_STR("1234"); - cxstring s2 = CX_STR(".:.:."); - cxstring s3 = CX_STR("X"); + cxstring s1 = cx_str("1234"); + cxstring s2 = cx_str(".:.:."); + cxstring s3 = cx_str("X"); CX_TEST_DO { size_t len0 = cx_strlen(0); size_t len1 = cx_strlen(1, s1); @@ -184,7 +184,7 @@ } CX_TEST(test_strsubs) { - cxstring str = CX_STR("A test string"); + cxstring str = cx_str("A test string"); CX_TEST_DO { cxstring sub = cx_strsubs(str, 0); @@ -210,12 +210,12 @@ // just for coverage, call the _m variant cxmutstr m = cx_strsubs_m(cx_mutstrn(NULL, 0), 0); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(m), cx_str(""))); + CX_TEST_ASSERT(0 == cx_strcmp(m, "")); } } CX_TEST(test_strchr) { - cxstring str = CX_STR("I will find you - and I will kill you"); + cxstring str = cx_str("I will find you - and I will kill you"); CX_TEST_DO { cxstring notfound = cx_strchr(str, 'x'); @@ -227,12 +227,12 @@ // just for coverage, call the _m variant cxmutstr m = cx_strchr_m(cx_mutstrn(NULL, 0), 'a'); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(m), cx_str(""))); + CX_TEST_ASSERT(0 == cx_strcmp(m, "")); } } CX_TEST(test_strrchr) { - cxstring str = CX_STR("X will find you - and I will kill you"); + cxstring str = cx_str("X will find you - and I will kill you"); CX_TEST_DO { cxstring notfound = cx_strrchr(str, 'x'); @@ -251,12 +251,12 @@ // just for coverage, call the _m variant cxmutstr m = cx_strrchr_m(cx_mutstrn(NULL, 0), 'a'); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(m), cx_str(""))); + CX_TEST_ASSERT(0 == cx_strcmp(m, "")); } } CX_TEST(test_strstr) { - cxstring str = CX_STR("find the match in this string"); + cxstring str = cx_str("find the match in this string"); const size_t longstrpatternlen = 64 + cx_strstr_sbo_size; const size_t longstrlen = 320 + longstrpatternlen + 14; @@ -314,7 +314,7 @@ } CX_TEST(test_strcmp) { - cxstring str = CX_STR("compare this"); + cxstring str = cx_str("compare this"); CX_TEST_DO { CX_TEST_ASSERT(0 == cx_strcmp(cx_str(""), cx_str(""))); CX_TEST_ASSERT(0 < cx_strcmp(str, cx_str(""))); @@ -329,15 +329,15 @@ CX_TEST_ASSERT(0 < cx_strcmp(str, cx_str("Lex"))); CX_TEST_ASSERT(0 < cx_strcmp(str, cx_str("Another lex test"))); - cxstring str2 = CX_STR("Compare This"); + cxstring str2 = cx_str("Compare This"); CX_TEST_ASSERT(0 != cx_strcmp_p(&str, &str2)); - str2 = CX_STR("compare this"); + str2 = cx_str("compare this"); CX_TEST_ASSERT(0 == cx_strcmp_p(&str, &str2)); } } CX_TEST(test_strcasecmp) { - cxstring str = CX_STR("compare this"); + cxstring str = cx_str("compare this"); CX_TEST_DO { CX_TEST_ASSERT(0 == cx_strcasecmp(cx_str(""), cx_str(""))); CX_TEST_ASSERT(0 < cx_strcasecmp(str, cx_str(""))); @@ -352,17 +352,17 @@ CX_TEST_ASSERT(0 > cx_strcasecmp(str, cx_str("Lex"))); CX_TEST_ASSERT(0 < cx_strcasecmp(str, cx_str("Another lex test"))); - cxstring str2 = CX_STR("Compare This"); + cxstring str2 = cx_str("Compare This"); CX_TEST_ASSERT(0 == cx_strcasecmp_p(&str, &str2)); - str2 = CX_STR("Compare Tool"); + str2 = cx_str("Compare Tool"); CX_TEST_ASSERT(0 > cx_strcasecmp_p(&str, &str2)); } } CX_TEST(test_strcat) { - cxstring s1 = CX_STR("12"); - cxstring s2 = CX_STR("34"); - cxstring s3 = CX_STR("56"); + cxstring s1 = cx_str("12"); + cxstring s2 = cx_str("34"); + cxstring s3 = cx_str("56"); cxstring sn = {NULL, 0}; CxTestingAllocator talloc; @@ -371,22 +371,22 @@ CX_TEST_DO { cxmutstr t1 = cx_strcat_a(alloc, 2, s1, s2); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t1), cx_str("1234"))); + CX_TEST_ASSERT(0 == cx_strcmp(t1, "1234")); ASSERT_ZERO_TERMINATED(t1); cx_strfree_a(alloc, &t1); cxmutstr t2 = cx_strcat_a(alloc, 3, s1, s2, s3); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t2), cx_str("123456"))); + CX_TEST_ASSERT(0 == cx_strcmp(t2, "123456")); ASSERT_ZERO_TERMINATED(t2); cx_strfree_a(alloc, &t2); cxmutstr t3 = cx_strcat_a(alloc, 6, s1, sn, s2, sn, s3, sn); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t3), cx_str("123456"))); + CX_TEST_ASSERT(0 == cx_strcmp(t3, "123456")); ASSERT_ZERO_TERMINATED(t3); cx_strfree_a(alloc, &t3); cxmutstr t4 = cx_strcat_a(alloc, 2, sn, sn); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t4), cx_str(""))); + CX_TEST_ASSERT(0 == cx_strcmp(t4, "")); ASSERT_ZERO_TERMINATED(t4); cx_strfree_a(alloc, &t4); @@ -394,14 +394,14 @@ // use the macro cxmutstr t5 = cx_strcat(3, s3, s1, s2); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t5), cx_str("561234"))); + CX_TEST_ASSERT(0 == cx_strcmp(t5, "561234")); ASSERT_ZERO_TERMINATED(t5); cx_strfree(&t5); // use an initial string cxmutstr t6 = cx_strdup(cx_str("Hello")); t6 = cx_strcat_m(t6, 2, cx_str(", "), cx_str("World!")); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(t6), cx_str("Hello, World!"))); + CX_TEST_ASSERT(0 == cx_strcmp(t6, "Hello, World!")); ASSERT_ZERO_TERMINATED(t6); cx_strfree(&t6); @@ -420,26 +420,26 @@ } CX_TEST(test_strcat_more_than_eight) { - cxstring s1 = CX_STR("12"); - cxstring s2 = CX_STR("34"); - cxstring s3 = CX_STR("56"); - cxstring s4 = CX_STR("78"); - cxstring s5 = CX_STR("9a"); - cxstring s6 = CX_STR("bc"); - cxstring s7 = CX_STR("de"); - cxstring s8 = CX_STR("f0"); - cxstring s9 = CX_STR("xy"); + cxstring s1 = cx_str("12"); + cxstring s2 = cx_str("34"); + cxstring s3 = cx_str("56"); + cxstring s4 = cx_str("78"); + cxstring s5 = cx_str("9a"); + cxstring s6 = cx_str("bc"); + cxstring s7 = cx_str("de"); + cxstring s8 = cx_str("f0"); + cxstring s9 = cx_str("xy"); CX_TEST_DO { cxmutstr r = cx_strcat(9, s1, s2, s3, s4, s5, s6, s7, s8, s9); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(r), cx_str("123456789abcdef0xy"))); + CX_TEST_ASSERT(0 == cx_strcmp(r, "123456789abcdef0xy")); ASSERT_ZERO_TERMINATED(r); cx_strfree(&r); } } CX_TEST(test_strsplit) { - cxstring test = CX_STR("this,is,a,csv,string"); + cxstring test = cx_str("this,is,a,csv,string"); size_t capa = 8; cxstring list[8]; size_t n; @@ -531,9 +531,9 @@ cxmutstr mlist[4]; n = cx_strsplit_m(mtest, cx_str("is,"), 4, mlist); CX_TEST_ASSERT(n == 3); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[0]), cx_str("th"))); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[1]), cx_str(""))); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[2]), cx_str("a,csv,string"))); + CX_TEST_ASSERT(0 == cx_strcmp(mlist[0], "th")); + CX_TEST_ASSERT(0 == cx_strcmp(mlist[1], "")); + CX_TEST_ASSERT(0 == cx_strcmp(mlist[2], "a,csv,string")); cx_strfree(&mtest); } } @@ -543,7 +543,7 @@ cx_testing_allocator_init(&talloc); CxAllocator *alloc = &talloc.base; - cxstring test = CX_STR("this,is,a,csv,string"); + cxstring test = cx_str("this,is,a,csv,string"); size_t capa = 8; cxstring *list; size_t n; @@ -647,9 +647,9 @@ cxmutstr *mlist; n = cx_strsplit_ma(alloc, mtest, cx_str("is,"), 4, &mlist); CX_TEST_ASSERT(n == 3); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[0]), cx_str("th"))); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[1]), cx_str(""))); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(mlist[2]), cx_str("a,csv,string"))); + CX_TEST_ASSERT(0 == cx_strcmp(mlist[0], "th")); + CX_TEST_ASSERT(0 == cx_strcmp(mlist[1], "")); + CX_TEST_ASSERT(0 == cx_strcmp(mlist[2], "a,csv,string")); cxFree(alloc, mlist); cx_strfree(&mtest); @@ -676,13 +676,13 @@ // call the _m variant just for coverage cxmutstr m1 = cx_strtrim_m(cx_mutstr((char *) " ein test \t ")); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(m1), cx_str("ein test"))); + CX_TEST_ASSERT(0 == cx_strcmp(m1, "ein test")); } } CX_TEST(test_strprefix) { - cxstring str = CX_STR("test my prefix and my suffix"); - cxstring empty = CX_STR(""); + cxstring str = cx_str("test my prefix and my suffix"); + cxstring empty = cx_str(""); CX_TEST_DO { CX_TEST_ASSERT(!cx_strprefix(empty, cx_str("pref"))); CX_TEST_ASSERT(cx_strprefix(str, empty)); @@ -693,8 +693,8 @@ } CX_TEST(test_strsuffix) { - cxstring str = CX_STR("test my prefix and my suffix"); - cxstring empty = CX_STR(""); + cxstring str = cx_str("test my prefix and my suffix"); + cxstring empty = cx_str(""); CX_TEST_DO { CX_TEST_ASSERT(!cx_strsuffix(empty, cx_str("suf"))); CX_TEST_ASSERT(cx_strsuffix(str, empty)); @@ -705,8 +705,8 @@ } CX_TEST(test_strcaseprefix) { - cxstring str = CX_STR("test my prefix and my suffix"); - cxstring empty = CX_STR(""); + cxstring str = cx_str("test my prefix and my suffix"); + cxstring empty = cx_str(""); CX_TEST_DO { CX_TEST_ASSERT(!cx_strcaseprefix(empty, cx_str("pREf"))); CX_TEST_ASSERT(cx_strcaseprefix(str, empty)); @@ -717,8 +717,8 @@ } CX_TEST(test_strcasesuffix) { - cxstring str = CX_STR("test my prefix and my suffix"); - cxstring empty = CX_STR(""); + cxstring str = cx_str("test my prefix and my suffix"); + cxstring empty = cx_str(""); CX_TEST_DO { CX_TEST_ASSERT(!cx_strcasesuffix(empty, cx_str("sUf"))); CX_TEST_ASSERT(cx_strcasesuffix(str, empty)); @@ -733,13 +733,13 @@ cx_testing_allocator_init(&talloc); CxAllocator *alloc = &talloc.base; - cxstring str = CX_STR("test ababab string aba"); - cxstring longstr = CX_STR( + cxstring str = cx_str("test ababab string aba"); + cxstring longstr = cx_str( "xyaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacd"); - cxstring notrail = CX_STR("test abab"); - cxstring empty = CX_STR(""); - cxstring astr = CX_STR("aaaaaaaaaa"); - cxstring csstr = CX_STR("test AB ab TEST xyz"); + cxstring notrail = cx_str("test abab"); + cxstring empty = cx_str(""); + cxstring astr = cx_str("aaaaaaaaaa"); + cxstring csstr = cx_str("test AB ab TEST xyz"); cxmutstr repl = cx_strreplace(str, cx_str("abab"), cx_str("muchlonger")); const char *expected = "test muchlongerab string aba"; @@ -839,8 +839,8 @@ } CX_TEST(test_strtok) { - cxstring str = CX_STR("a,comma,separated,string"); - cxstring delim = CX_STR(","); + cxstring str = cx_str("a,comma,separated,string"); + cxstring delim = cx_str(","); CX_TEST_DO { CxStrtokCtx ctx = cx_strtok(str, delim, 3); CX_TEST_ASSERT(ctx.str.ptr == str.ptr); @@ -857,9 +857,9 @@ } CX_TEST(test_strtok_delim) { - cxstring str = CX_STR("an,arbitrarily|separated;string"); - cxstring delim = CX_STR(","); - cxstring delim_more[2] = {CX_STR("|"), CX_STR(";")}; + cxstring str = cx_str("an,arbitrarily|separated;string"); + cxstring delim = cx_str(","); + cxstring delim_more[2] = {cx_str("|"), cx_str(";")}; CX_TEST_DO { CxStrtokCtx ctx = cx_strtok(str, delim, 3); cx_strtok_delim(&ctx, delim_more, 2); @@ -877,8 +877,8 @@ } CX_TEST(test_strtok_next_easy) { - cxstring str = CX_STR("a,comma,separated,string"); - cxstring delim = CX_STR(","); + cxstring str = cx_str("a,comma,separated,string"); + cxstring delim = cx_str(","); CX_TEST_DO { CxStrtokCtx ctx = cx_strtok(str, delim, 3); bool ret; @@ -918,8 +918,8 @@ } CX_TEST(test_strtok_next_unlimited) { - cxstring str = CX_STR("some;-;otherwise;-;separated;-;string;-;"); - cxstring delim = CX_STR(";-;"); + cxstring str = cx_str("some;-;otherwise;-;separated;-;string;-;"); + cxstring delim = cx_str(";-;"); CX_TEST_DO { CxStrtokCtx ctx = cx_strtok(str, delim, SIZE_MAX); bool ret; @@ -983,8 +983,8 @@ CX_TEST(test_strtok_next_advanced) { cxmutstr str = cx_strdup(cx_str("an,arbitrarily;||separated;string")); - cxstring delim = CX_STR(","); - cxstring delim_more[2] = {CX_STR("||"), CX_STR(";")}; + cxstring delim = cx_str(","); + cxstring delim_more[2] = {cx_str("||"), cx_str(";")}; CX_TEST_DO { CxStrtokCtx ctx = cx_strtok(str, delim, 10); cx_strtok_delim(&ctx, delim_more, 2); @@ -993,7 +993,7 @@ ret = cx_strtok_next_m(&ctx, &tok); CX_TEST_ASSERT(ret); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str("an"))); + CX_TEST_ASSERT(0 == cx_strcmp(tok, "an")); CX_TEST_ASSERT(ctx.pos == 0); CX_TEST_ASSERT(ctx.next_pos == 3); CX_TEST_ASSERT(ctx.delim_pos == 2); @@ -1002,7 +1002,7 @@ ret = cx_strtok_next_m(&ctx, &tok); CX_TEST_ASSERT(ret); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str("arbitrarily"))); + CX_TEST_ASSERT(0 == cx_strcmp(tok, "arbitrarily")); CX_TEST_ASSERT(ctx.pos == 3); CX_TEST_ASSERT(ctx.next_pos == 15); CX_TEST_ASSERT(ctx.delim_pos == 14); @@ -1011,7 +1011,7 @@ ret = cx_strtok_next_m(&ctx, &tok); CX_TEST_ASSERT(ret); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str(""))); + CX_TEST_ASSERT(0 == cx_strcmp(tok, "")); CX_TEST_ASSERT(ctx.pos == 15); CX_TEST_ASSERT(ctx.next_pos == 17); CX_TEST_ASSERT(ctx.delim_pos == 15); @@ -1020,7 +1020,7 @@ ret = cx_strtok_next_m(&ctx, &tok); CX_TEST_ASSERT(ret); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str("separated"))); + CX_TEST_ASSERT(0 == cx_strcmp(tok, "separated")); CX_TEST_ASSERT(ctx.pos == 17); CX_TEST_ASSERT(ctx.next_pos == 27); CX_TEST_ASSERT(ctx.delim_pos == 26); @@ -1029,7 +1029,7 @@ ret = cx_strtok_next_m(&ctx, &tok); CX_TEST_ASSERT(ret); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(tok), cx_str("string"))); + CX_TEST_ASSERT(0 == cx_strcmp(tok, "string")); CX_TEST_ASSERT(ctx.pos == 27); CX_TEST_ASSERT(ctx.next_pos == 33); CX_TEST_ASSERT(ctx.delim_pos == 33); @@ -1043,7 +1043,7 @@ CX_TEST_ASSERT(ctx.delim_pos == 33); CX_TEST_ASSERT(ctx.found == 5); - CX_TEST_ASSERT(0 == cx_strcmp(cx_strcast(str), cx_str("AN,ARBITRARILY;||SEPARATED;STRING"))); + CX_TEST_ASSERT(0 == cx_strcmp(str, "AN,ARBITRARILY;||SEPARATED;STRING")); } cx_strfree(&str); } @@ -1483,7 +1483,7 @@ } CX_TEST(test_strformat) { - cxstring str = CX_STR("Hello, World!"); + cxstring str = cx_str("Hello, World!"); CX_TEST_DO { char actual[64]; snprintf(actual, 64, "Test %"CX_PRIstr " Success.", CX_SFMT(str));