Mirror ref/hare/path's impl layout in the test siblings: abs/isroot/string/local rows -> buffer_test.ww (ref/hare/path/ buffer.ha:28-77); push/parent/pop-split rows -> stack_test.ww (ref/hare/path/stack.ha:9-180); dirname/basename rows -> posix_test.ww (ref/hare/path/posix.ha:17-71). Pure move: every @test block is byte-identical; only the section banner lines are deleted (file names now carry them) and each section's ref-cite WHY comment rides with its @test. The suite header's Hare-vector/parallel-array WHY paragraphs ride with stack_test.ww (push is their subject); the stale `ww run lib/path/path_test.ww` sentence is dropped, not relocated. Consumers: Makefile LIBRARY_TESTS entry replaced in place. The byteid roster is untouched: lib/path is enrolled there as an import-probe, not a fixture.
102 lines
2.7 KiB
Plaintext
102 lines
2.7 KiB
Plaintext
package path_test;
|
|
|
|
import path;
|
|
|
|
|
|
// ref/hare/path/buffer.ha:34-41. str literals widen into the (*buffer|str)
|
|
// union arg (str-arm = hasprefix vs sepstr); buffer-arm = byte. Parallel
|
|
// [N]str inputs + [N]i32 wantbool (no [N]bool in the stack; cgen-field gap).
|
|
|
|
@test fn abs_cases() void = {
|
|
let ins: [4]str;
|
|
let want: [4]i32;
|
|
ins[0]="/"; want[0]=1;
|
|
ins[1]="/foo"; want[1]=1;
|
|
ins[2]="foo"; want[2]=0;
|
|
ins[3]=""; want[3]=0;
|
|
let i: i32 = 0;
|
|
for (i < 4) {
|
|
let got: i32 = 0;
|
|
if (abs(ins[i])) { got = 1; };
|
|
assert(!(got != want[i]));
|
|
i += 1;
|
|
};
|
|
|
|
// buffer-arm: &buf ptr-ident-widens into the union.
|
|
let buf = buffer { ... };
|
|
assert(!(abs(&buf))); // empty → false
|
|
assert(!(push(&buf, "/foo")! != "/foo"));
|
|
assert(!(!abs(&buf))); // "/foo" → true
|
|
buf.end = 0;
|
|
assert(!(push(&buf, "foo")! != "foo"));
|
|
assert(!(abs(&buf))); // "foo" → false
|
|
};
|
|
|
|
// ref/hare/path/buffer.ha:44-51. Both arms: str (== sepstr) and *buffer
|
|
// (byte+int). Heterogeneous buffer seeds (manual root seed vs push) →
|
|
// inline; str-arm rows table-driven.
|
|
|
|
@test fn isroot_cases() void = {
|
|
let buf = buffer { ... };
|
|
// empty buffer (end 0)
|
|
assert(!(isroot(&buf)));
|
|
|
|
// "/" — root. local() is c3, so seed the SEP byte directly.
|
|
buf.buf[0] = SEP; buf.end = 1;
|
|
assert(!(!isroot(&buf)));
|
|
assert(!(string(&buf) != "/"));
|
|
|
|
// "foo" — relative, not root.
|
|
buf.end = 0;
|
|
assert(!(push(&buf, "foo")! != "foo"));
|
|
assert(!(isroot(&buf)));
|
|
|
|
// "/foo" — absolute but not root.
|
|
buf.buf[0] = SEP; buf.end = 1;
|
|
assert(!(push(&buf, "foo")! != "/foo"));
|
|
assert(!(isroot(&buf)));
|
|
|
|
// str-arm (buffer.ha:47): only the bare separator is root.
|
|
let ins: [4]str;
|
|
let want: [4]i32;
|
|
ins[0]="/"; want[0]=1;
|
|
ins[1]="/foo"; want[1]=0;
|
|
ins[2]="foo"; want[2]=0;
|
|
ins[3]=""; want[3]=0;
|
|
let i: i32 = 0;
|
|
for (i < 4) {
|
|
let got: i32 = 0;
|
|
if (isroot(ins[i])) { got = 1; };
|
|
assert(!(got != want[i]));
|
|
i += 1;
|
|
};
|
|
};
|
|
|
|
// ref/hare/path/buffer.ha:28-31. Empty buffer views as "."; a filled
|
|
// buffer views the byte prefix.
|
|
|
|
@test fn string_cases() void = {
|
|
let buf = buffer { ... };
|
|
assert(!(string(&buf) != "."));
|
|
assert(!(push(&buf, "foo")! != "foo"));
|
|
assert(!(string(&buf) != "foo"));
|
|
};
|
|
|
|
// ref/hare/path/buffer.ha:55-77. Rewrites '/'→SEP into a static buffer;
|
|
// on Linux (SEP=='/') that is identity. The returned view borrows the
|
|
// module-private localbuf, so compare each row before the next call.
|
|
|
|
@test fn local_cases() void = {
|
|
let ins: [4]str;
|
|
let want: [4]str;
|
|
ins[0]="a/b"; want[0]="a/b";
|
|
ins[1]="/"; want[1]="/";
|
|
ins[2]="foo"; want[2]="foo";
|
|
ins[3]=""; want[3]="";
|
|
let i: i32 = 0;
|
|
for (i < 4) {
|
|
assert(!(local(ins[i])! != want[i]));
|
|
i += 1;
|
|
};
|
|
};
|