lib/path: #138 c3-posix dirname/basename — faithful posix.ha port, table-driven @test (cstage)
dirname/basename ported verbatim from ref/hare/path/posix.ha:17,37, re-routing Hare's byte scanning to bytes.rtrim/rindex. Additive to the c2-stack buffer core; no harness/Makefile/module-const changes. Work-var renamed path->p to avoid Hare's param-shadowing `let path = toutf8(path)`: ww's cgen N_LET prepends the new local into the name-keyed localfind chain BEFORE the init is emitted, so the shadow-init reads the fresh uninit slot — a silent miscompile, both-wrong-identical, filed #152 and fixed independently next. drew ruled path->p a permanent acceptable spelling (internal work-var, not API surface; avoids a param-shadow footgun; not a rule-7 workaround). WHY-comment + #152 pointer at both sites. Tests: 10-row dirname/basename table (posix.ha:51-71 verbatim) — root, no-sep, empty, trailing-sep, multi-sep all covered, expecteds traced. C-first: cstage @test green; the str-view-vs-literal rows are #146-deferred (wwstage byte-id, rides #125). Gate: all 324 passed, byte-id 990-997 green, w6c/w6c_ww unchanged (lib-only additive).
This commit is contained in:
@@ -115,9 +115,43 @@ fn fail() void = { os.exit(signalled + 10); };
|
||||
if (string(&buf) != "foo") { fail(); };
|
||||
};
|
||||
|
||||
// ---- dirname() / basename() -------------------------------------------
|
||||
// ref/hare/path/posix.ha:51-71. Hare seeds each row through _local/local()
|
||||
// for cross-platform SEP; on ww (Linux, SEP='/') that is identity, so the
|
||||
// raw str literals stand in directly (local/_local defer to c3). POSIX
|
||||
// dirname/basename do NOT normalize the input (posix.ha:14-15,35), so no
|
||||
// seeding is needed. Parallel `[N]str` rows (cgen chained-field gap, as
|
||||
// above). Rows whose expected is a borrowed VIEW (not a "."/"/" literal)
|
||||
// compare a computed str to a literal — cstage-correct; wwstage mis-
|
||||
// compares via #146 (str== over a frombytes result), and this @test is
|
||||
// cstage-gated, so those rows are #146-deferred on wwstage only.
|
||||
|
||||
@test fn dirname_basename_cases() void = {
|
||||
let inputs: [10]str;
|
||||
let wantdir: [10]str;
|
||||
let wantbase: [10]str;
|
||||
inputs[0]="usr"; wantdir[0]="."; wantbase[0]="usr";
|
||||
inputs[1]="usr/"; wantdir[1]="."; wantbase[1]="usr";
|
||||
inputs[2]=""; wantdir[2]="."; wantbase[2]=".";
|
||||
inputs[3]="/"; wantdir[3]="/"; wantbase[3]="/";
|
||||
inputs[4]="//"; wantdir[4]="/"; wantbase[4]="/"; // impl-defined
|
||||
inputs[5]="///"; wantdir[5]="/"; wantbase[5]="/";
|
||||
inputs[6]="/usr/"; wantdir[6]="/"; wantbase[6]="usr";
|
||||
inputs[7]="/usr/lib"; wantdir[7]="/usr"; wantbase[7]="lib";
|
||||
inputs[8]="//usr//lib//"; wantdir[8]="//usr"; wantbase[8]="lib";
|
||||
inputs[9]="/home//dwc//test"; wantdir[9]="/home//dwc"; wantbase[9]="test";
|
||||
let i: i32 = 0;
|
||||
for (i < 10) {
|
||||
if (dirname(inputs[i]) != wantdir[i]) { fail(); };
|
||||
if (basename(inputs[i]) != wantbase[i]) { fail(); };
|
||||
i += 1;
|
||||
};
|
||||
};
|
||||
|
||||
export fn main() i32 = {
|
||||
signalled = 1; push_cases();
|
||||
signalled = 2; isroot_cases();
|
||||
signalled = 3; string_cases();
|
||||
signalled = 4; dirname_basename_cases();
|
||||
return 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user