test: prove ordinary import binding modes
This commit is contained in:
@@ -19,8 +19,8 @@ import path;
|
||||
// appendnorm @test is needed.
|
||||
|
||||
@test fn push_cases() void = {
|
||||
let buf = buffer { ... };
|
||||
assert(!(string(&buf) != "."));
|
||||
let buf: path.buffer;
|
||||
assert(!(path.string(&buf) != "."));
|
||||
|
||||
// current-dir + parent-dir invariants (stack.ha:82-88). Single
|
||||
// segment per row → table-driven sequential apply.
|
||||
@@ -33,13 +33,13 @@ import path;
|
||||
segs[4]="."; wants[4]="..";
|
||||
let i: i32 = 0;
|
||||
for (i < 5) {
|
||||
assert(!(push(&buf, segs[i])! != wants[i]));
|
||||
assert(!(path.push(&buf, segs[i])! != wants[i]));
|
||||
i += 1;
|
||||
};
|
||||
|
||||
// set(&buf) resets to "." (stack.ha:91). set forwards an EMPTY
|
||||
// variadic into push (KEN-oracle flag 1: zero-arg gather+forward).
|
||||
assert(!(set(&buf)! != "."));
|
||||
assert(!(path.set(&buf)! != "."));
|
||||
|
||||
// regular path + parent (stack.ha:101-104, minus the local() row).
|
||||
let segs2: [3]str;
|
||||
@@ -49,25 +49,25 @@ import path;
|
||||
segs2[2]=".."; wants2[2]=".";
|
||||
let k: i32 = 0;
|
||||
for (k < 3) {
|
||||
assert(!(push(&buf, segs2[k])! != wants2[k]));
|
||||
assert(!(path.push(&buf, segs2[k])! != wants2[k]));
|
||||
k += 1;
|
||||
};
|
||||
|
||||
// multi-segment (stack.ha:107-111). Variadic arity varies (1 or 2)
|
||||
// → inline.
|
||||
assert(!(push(&buf, "a", "b")! != "a/b"));
|
||||
assert(!(push(&buf, "..", "c")! != "a/c"));
|
||||
assert(!(push(&buf, "..")! != "a"));
|
||||
assert(!(path.push(&buf, "a", "b")! != "a/b"));
|
||||
assert(!(path.push(&buf, "..", "c")! != "a/c"));
|
||||
assert(!(path.push(&buf, "..")! != "a"));
|
||||
// stack.ha:110; local()→literal, SEP='/' on Linux, proper local() rides c3
|
||||
assert(!(push(&buf, "/d")! != "a/d"));
|
||||
assert(!(push(&buf, "..", "..")! != ".")); // stack.ha:111
|
||||
assert(!(path.push(&buf, "/d")! != "a/d"));
|
||||
assert(!(path.push(&buf, "..", "..")! != ".")); // stack.ha:111
|
||||
|
||||
// leading-SEP segment into an EMPTY buffer exercises push's
|
||||
// `j==0 && buf.end==0` root-seed arm (stack.ha:18-20), unreached
|
||||
// by the relative rows above. Hare covers it via local("/")-seeded
|
||||
// rows that defer to c3; literal "/foo" stands in (SEP='/' on Linux).
|
||||
assert(!(set(&buf)! != "."));
|
||||
assert(!(push(&buf, "/foo")! != "/foo"));
|
||||
assert(!(path.set(&buf)! != "."));
|
||||
assert(!(path.push(&buf, "/foo")! != "/foo"));
|
||||
};
|
||||
|
||||
// ref/hare/path/stack.ha:172-180. Parent dir; root → root; empty → "..".
|
||||
@@ -76,7 +76,7 @@ import path;
|
||||
// not "") can share the table.
|
||||
|
||||
@test fn parent_cases() void = {
|
||||
let buf = buffer { ... };
|
||||
let buf: path.buffer;
|
||||
let ins: [5]str;
|
||||
let want: [5]str;
|
||||
ins[0]="/usr/lib"; want[0]="/usr";
|
||||
@@ -87,8 +87,8 @@ import path;
|
||||
let i: i32 = 0;
|
||||
for (i < 5) {
|
||||
buf.end = 0;
|
||||
push(&buf, ins[i])!;
|
||||
assert(!(parent(&buf)! != want[i]));
|
||||
path.push(&buf, ins[i])!;
|
||||
assert(!(path.parent(&buf)! != want[i]));
|
||||
i += 1;
|
||||
};
|
||||
};
|
||||
@@ -99,30 +99,30 @@ import path;
|
||||
// #48 respelling didn't smuggle in pop's buf.end mutation.
|
||||
|
||||
@test fn popsplit_cases() void = {
|
||||
let buf = buffer { ... };
|
||||
let buf: path.buffer;
|
||||
|
||||
// empty
|
||||
assert(!(!(pop(&buf) is void)));
|
||||
assert(!(string(&buf) != "."));
|
||||
assert(!(!(path.pop(&buf) is void)));
|
||||
assert(!(path.string(&buf) != "."));
|
||||
|
||||
// root dir
|
||||
buf.end = 0;
|
||||
assert(!(push(&buf, "/")! != "/"));
|
||||
assert(!(!(pop(&buf) is void)));
|
||||
assert(!(string(&buf) != "/"));
|
||||
assert(!(path.push(&buf, "/")! != "/"));
|
||||
assert(!(!(path.pop(&buf) is void)));
|
||||
assert(!(path.string(&buf) != "/"));
|
||||
|
||||
// relative file — peek is NON-mutating
|
||||
buf.end = 0;
|
||||
assert(!(push(&buf, "foo")! != "foo"));
|
||||
assert(!(peek(&buf) as str != "foo"));
|
||||
assert(!(string(&buf) != "foo"));
|
||||
assert(!(pop(&buf) as str != "foo"));
|
||||
assert(!(string(&buf) != "."));
|
||||
assert(!(path.push(&buf, "foo")! != "foo"));
|
||||
assert(!(path.peek(&buf) as str != "foo"));
|
||||
assert(!(path.string(&buf) != "foo"));
|
||||
assert(!(path.pop(&buf) as str != "foo"));
|
||||
assert(!(path.string(&buf) != "."));
|
||||
|
||||
// absolute file
|
||||
buf.end = 0;
|
||||
assert(!(push(&buf, "/foo")! != "/foo"));
|
||||
assert(!(peek(&buf) as str != "foo"));
|
||||
assert(!(pop(&buf) as str != "foo"));
|
||||
assert(!(string(&buf) != "/"));
|
||||
assert(!(path.push(&buf, "/foo")! != "/foo"));
|
||||
assert(!(path.peek(&buf) as str != "foo"));
|
||||
assert(!(path.pop(&buf) as str != "foo"));
|
||||
assert(!(path.string(&buf) != "/"));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user