Files
ww/lib/strings/concat_test.ww
Hojun-Cho 51cb8e7d64 lib: split strings tests per ref/hare/strings families + helpers file
Unblocked by the package-mode ruling: same-package test files now
compose everywhere (coordinator dir-mode owns test-library and the
libbyteid dir entry owns byte identity), so the per-file standalone
constraint is gone and Go's stdlib layout applies directly. The
15-banner strings_test.ww monolith dissolves into per-ref-file
family files — dup, concat, trim, sub, utf8, iter, tokenize
(tokenize+splitn+cut, all of ref tokenize.ha), pad, replace — plus
helpers_test.ww holding exactly the one cross-family helper (streq),
Go's shared test-helper idiom. Pure moves; family-local helpers
(expect_str_token et al.) stay in their family file. Leading banners
that merely restated the filename dropped; 6 interior sub-family
boundaries remain. lib/ census 141 -> 132.

libbyteid gains the dx() dir-mode entry form decided in B2: compose
every *_test.ww under moddir exactly as pkgcombined does
(module-reset separators, byte-lex order) and byte-id the composed
root through both driver stages. The five per-file strings fx
entries retire into one dx("lib/strings") — every source line they
covered is inside the composed unit, and the completeness scan still
keys the module. NENTEXPECT 60 -> 56.

Recorded, not split: fmt_test's 13 banners are scenario groups over
the one fprint surface and ref/hare/fmt itself keeps a single
+test.ha — a print/wrappers split would fight the ref; memio stays
per the standing ruling (everything ww ports lives in ref
stream.ha).
2026-08-08 19:42:49 +09:00

115 lines
3.4 KiB
Plaintext

// 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;
};
};
// ---- join -------------------------------------------------------------
// 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;
};
};