// Vectors mirror ref/hare/strings/concat.ha where ww can express them. // External strings_test package per the Go foo_test idiom (rule-5/9 // carve-out, task #16); the shared streq helper lives in // helpers_test.ww — same-package test files compose in dir-mode // (the package, not the file, is the unit of testing). package strings_test; import strings; import os; // ref/hare/strings/concat.ha:18. Rows mirror Hare's vectors (0/1/2/3-arg, // empty-mid, 2-empty) plus empty-first / empty-last / multibyte. @test fn concat_cases() void = { let pool: [17]str; pool[0] = "hello"; pool[1] = "hello "; pool[2] = "world"; pool[3] = "hello"; pool[4] = " "; pool[5] = "world"; pool[6] = "hello"; pool[7] = ""; pool[8] = "world"; pool[9] = ""; pool[10] = ""; pool[11] = ""; pool[12] = "world"; pool[13] = "hello"; pool[14] = ""; pool[15] = "こん"; pool[16] = "にちは"; let argo: [9]i32; let argn: [9]i32; let want: [9]str; let labels: [9]str; argo[0]=0; argn[0]=0; want[0]=""; labels[0]="0-arg"; argo[1]=0; argn[1]=1; want[1]="hello"; labels[1]="1-arg"; argo[2]=1; argn[2]=2; want[2]="hello world"; labels[2]="2-arg"; argo[3]=3; argn[3]=3; want[3]="hello world"; labels[3]="3-arg"; argo[4]=6; argn[4]=3; want[4]="helloworld"; labels[4]="empty-mid"; argo[5]=9; argn[5]=2; want[5]=""; labels[5]="2-empty"; argo[6]=11; argn[6]=2; want[6]="world"; labels[6]="empty-first"; argo[7]=13; argn[7]=2; want[7]="hello"; labels[7]="empty-last"; argo[8]=15; argn[8]=2; want[8]="こんにちは"; labels[8]="multibyte"; let i: i32 = 0; for (i < 9) { let argv: []str; argv.ptr = &pool[argo[i]]; argv.len = argn[i]; argv.cap = argn[i]; let got: str = strings.concat(argv...); assert(!(!streq(got, want[i]))); if (got.len > 0) { os.free(got.ptr: *void, got.len: u64); }; i += 1; }; }; // ref/hare/strings/concat.ha:64. Rows mirror Hare's @test fn join // (0-arg, 1-arg, empty-sep, 3-arg.) plus 2-arg, all-empties, long sep, // multibyte, empty-mid (delim still inserted around the empty slot). @test fn join_cases() void = { let pool: [19]str; pool[0] = "hello"; pool[1] = "a"; pool[2] = "b"; pool[3] = "a"; pool[4] = "b"; pool[5] = "c"; pool[6] = "a"; pool[7] = "b"; pool[8] = "c"; pool[9] = ""; pool[10] = ""; pool[11] = "a"; pool[12] = "b"; pool[13] = "c"; pool[14] = "こん"; pool[15] = "にちは"; pool[16] = "a"; pool[17] = ""; pool[18] = "b"; let argo: [9]i32; let argn: [9]i32; let seps: [9]str; let want: [9]str; argo[0]=0; argn[0]=0; seps[0]="."; want[0]=""; argo[1]=0; argn[1]=1; seps[1]="."; want[1]="hello"; argo[2]=1; argn[2]=2; seps[2]=", "; want[2]="a, b"; argo[3]=3; argn[3]=3; seps[3]="."; want[3]="a.b.c"; argo[4]=6; argn[4]=3; seps[4]=""; want[4]="abc"; argo[5]=9; argn[5]=2; seps[5]=","; want[5]=","; argo[6]=11; argn[6]=3; seps[6]=" :: "; want[6]="a :: b :: c"; argo[7]=14; argn[7]=2; seps[7]="・"; want[7]="こん・にちは"; argo[8]=16; argn[8]=3; seps[8]="-"; want[8]="a--b"; let i: i32 = 0; for (i < 9) { let argv: []str; argv.ptr = &pool[argo[i]]; argv.len = argn[i]; argv.cap = argn[i]; let got: str = strings.join(seps[i], argv...); assert(!(!streq(got, want[i]))); if (got.len > 0) { os.free(got.ptr: *void, got.len: u64); }; i += 1; }; };