102 lines
2.8 KiB
Plaintext
102 lines
2.8 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 (path.abs(ins[i])) { got = 1; };
|
|
assert(!(got != want[i]));
|
|
i += 1;
|
|
};
|
|
|
|
// buffer-arm: &buf ptr-ident-widens into the union.
|
|
let buf: path.buffer;
|
|
assert(!(path.abs(&buf))); // empty → false
|
|
assert(!(path.push(&buf, "/foo")! != "/foo"));
|
|
assert(!(!path.abs(&buf))); // "/foo" → true
|
|
buf.end = 0;
|
|
assert(!(path.push(&buf, "foo")! != "foo"));
|
|
assert(!(path.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: path.buffer;
|
|
// empty buffer (end 0)
|
|
assert(!(path.isroot(&buf)));
|
|
|
|
// "/" — root. local() is c3, so seed the SEP byte directly.
|
|
buf.buf[0] = path.SEP; buf.end = 1;
|
|
assert(!(!path.isroot(&buf)));
|
|
assert(!(path.string(&buf) != "/"));
|
|
|
|
// "foo" — relative, not root.
|
|
buf.end = 0;
|
|
assert(!(path.push(&buf, "foo")! != "foo"));
|
|
assert(!(path.isroot(&buf)));
|
|
|
|
// "/foo" — absolute but not root.
|
|
buf.buf[0] = path.SEP; buf.end = 1;
|
|
assert(!(path.push(&buf, "foo")! != "/foo"));
|
|
assert(!(path.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 (path.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: path.buffer;
|
|
assert(!(path.string(&buf) != "."));
|
|
assert(!(path.push(&buf, "foo")! != "foo"));
|
|
assert(!(path.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(!(path.local(ins[i])! != want[i]));
|
|
i += 1;
|
|
};
|
|
};
|