lib misc+ww tests: hand-main plumbing -> assert (@test conversion B7)
toktest documents the per-row signalled pinpoint loss.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
// pathtest — exercises lib/path (c2-stack subset). Run with
|
||||
// `out/bin/ww run lib/path/pathtest.ww`. Same signalled-then-fail()
|
||||
// -with-+10 pattern as bytes / getopt tests: a non-zero exit code
|
||||
// pinpoints the failing scenario.
|
||||
// `out/bin/ww run lib/path/pathtest.ww`. A failing row aborts via the
|
||||
// assert/abort builtin (task #5 @test conversion).
|
||||
//
|
||||
// Vectors mirror Hare's @test fns in ref/hare/path/stack.ha:77-119
|
||||
// and buffer.ha. The absolute rows (Hare's `local("/")`-seeded) DEFER
|
||||
@@ -16,10 +15,7 @@
|
||||
package path_test;
|
||||
|
||||
import path;
|
||||
import os;
|
||||
|
||||
let signalled: i32 = 0;
|
||||
fn fail() void = { os.exit(signalled + 10); };
|
||||
|
||||
// ---- push() + appendnorm normalization --------------------------------
|
||||
// ref/hare/path/stack.ha:77-119 (relative rows only; absolute local()
|
||||
@@ -29,7 +25,7 @@ fn fail() void = { os.exit(signalled + 10); };
|
||||
|
||||
@test fn push_cases() void = {
|
||||
let buf = buffer { ... };
|
||||
if (string(&buf) != ".") { fail(); };
|
||||
assert(!(string(&buf) != "."));
|
||||
|
||||
// current-dir + parent-dir invariants (stack.ha:82-88). Single
|
||||
// segment per row → table-driven sequential apply.
|
||||
@@ -42,13 +38,13 @@ fn fail() void = { os.exit(signalled + 10); };
|
||||
segs[4]="."; wants[4]="..";
|
||||
let i: i32 = 0;
|
||||
for (i < 5) {
|
||||
if (push(&buf, segs[i])! != wants[i]) { fail(); };
|
||||
assert(!(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).
|
||||
if (set(&buf)! != ".") { fail(); };
|
||||
assert(!(set(&buf)! != "."));
|
||||
|
||||
// regular path + parent (stack.ha:101-104, minus the local() row).
|
||||
let segs2: [3]str;
|
||||
@@ -58,25 +54,25 @@ fn fail() void = { os.exit(signalled + 10); };
|
||||
segs2[2]=".."; wants2[2]=".";
|
||||
let k: i32 = 0;
|
||||
for (k < 3) {
|
||||
if (push(&buf, segs2[k])! != wants2[k]) { fail(); };
|
||||
assert(!(push(&buf, segs2[k])! != wants2[k]));
|
||||
k += 1;
|
||||
};
|
||||
|
||||
// multi-segment (stack.ha:107-111). Variadic arity varies (1 or 2)
|
||||
// → inline.
|
||||
if (push(&buf, "a", "b")! != "a/b") { fail(); };
|
||||
if (push(&buf, "..", "c")! != "a/c") { fail(); };
|
||||
if (push(&buf, "..")! != "a") { fail(); };
|
||||
assert(!(push(&buf, "a", "b")! != "a/b"));
|
||||
assert(!(push(&buf, "..", "c")! != "a/c"));
|
||||
assert(!(push(&buf, "..")! != "a"));
|
||||
// stack.ha:110; local()→literal, SEP='/' on Linux, proper local() rides c3
|
||||
if (push(&buf, "/d")! != "a/d") { fail(); };
|
||||
if (push(&buf, "..", "..")! != ".") { fail(); }; // stack.ha:111
|
||||
assert(!(push(&buf, "/d")! != "a/d"));
|
||||
assert(!(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).
|
||||
if (set(&buf)! != ".") { fail(); };
|
||||
if (push(&buf, "/foo")! != "/foo") { fail(); };
|
||||
assert(!(set(&buf)! != "."));
|
||||
assert(!(push(&buf, "/foo")! != "/foo"));
|
||||
};
|
||||
|
||||
// ---- abs() ------------------------------------------------------------
|
||||
@@ -95,18 +91,18 @@ fn fail() void = { os.exit(signalled + 10); };
|
||||
for (i < 4) {
|
||||
let got: i32 = 0;
|
||||
if (abs(ins[i])) { got = 1; };
|
||||
if (got != want[i]) { fail(); };
|
||||
assert(!(got != want[i]));
|
||||
i += 1;
|
||||
};
|
||||
|
||||
// buffer-arm: &buf ptr-ident-widens into the union.
|
||||
let buf = buffer { ... };
|
||||
if (abs(&buf)) { fail(); }; // empty → false
|
||||
if (push(&buf, "/foo")! != "/foo") { fail(); };
|
||||
if (!abs(&buf)) { fail(); }; // "/foo" → true
|
||||
assert(!(abs(&buf))); // empty → false
|
||||
assert(!(push(&buf, "/foo")! != "/foo"));
|
||||
assert(!(!abs(&buf))); // "/foo" → true
|
||||
buf.end = 0;
|
||||
if (push(&buf, "foo")! != "foo") { fail(); };
|
||||
if (abs(&buf)) { fail(); }; // "foo" → false
|
||||
assert(!(push(&buf, "foo")! != "foo"));
|
||||
assert(!(abs(&buf))); // "foo" → false
|
||||
};
|
||||
|
||||
// ---- isroot() ---------------------------------------------------------
|
||||
@@ -117,22 +113,22 @@ fn fail() void = { os.exit(signalled + 10); };
|
||||
@test fn isroot_cases() void = {
|
||||
let buf = buffer { ... };
|
||||
// empty buffer (end 0)
|
||||
if (isroot(&buf)) { fail(); };
|
||||
assert(!(isroot(&buf)));
|
||||
|
||||
// "/" — root. local() is c3, so seed the SEP byte directly.
|
||||
buf.buf[0] = SEP; buf.end = 1;
|
||||
if (!isroot(&buf)) { fail(); };
|
||||
if (string(&buf) != "/") { fail(); };
|
||||
assert(!(!isroot(&buf)));
|
||||
assert(!(string(&buf) != "/"));
|
||||
|
||||
// "foo" — relative, not root.
|
||||
buf.end = 0;
|
||||
if (push(&buf, "foo")! != "foo") { fail(); };
|
||||
if (isroot(&buf)) { fail(); };
|
||||
assert(!(push(&buf, "foo")! != "foo"));
|
||||
assert(!(isroot(&buf)));
|
||||
|
||||
// "/foo" — absolute but not root.
|
||||
buf.buf[0] = SEP; buf.end = 1;
|
||||
if (push(&buf, "foo")! != "/foo") { fail(); };
|
||||
if (isroot(&buf)) { fail(); };
|
||||
assert(!(push(&buf, "foo")! != "/foo"));
|
||||
assert(!(isroot(&buf)));
|
||||
|
||||
// str-arm (buffer.ha:47): only the bare separator is root.
|
||||
let ins: [4]str;
|
||||
@@ -145,7 +141,7 @@ fn fail() void = { os.exit(signalled + 10); };
|
||||
for (i < 4) {
|
||||
let got: i32 = 0;
|
||||
if (isroot(ins[i])) { got = 1; };
|
||||
if (got != want[i]) { fail(); };
|
||||
assert(!(got != want[i]));
|
||||
i += 1;
|
||||
};
|
||||
};
|
||||
@@ -156,9 +152,9 @@ fn fail() void = { os.exit(signalled + 10); };
|
||||
|
||||
@test fn string_cases() void = {
|
||||
let buf = buffer { ... };
|
||||
if (string(&buf) != ".") { fail(); };
|
||||
if (push(&buf, "foo")! != "foo") { fail(); };
|
||||
if (string(&buf) != "foo") { fail(); };
|
||||
assert(!(string(&buf) != "."));
|
||||
assert(!(push(&buf, "foo")! != "foo"));
|
||||
assert(!(string(&buf) != "foo"));
|
||||
};
|
||||
|
||||
// ---- dirname() / basename() -------------------------------------------
|
||||
@@ -188,8 +184,8 @@ fn fail() void = { os.exit(signalled + 10); };
|
||||
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(); };
|
||||
assert(!(dirname(inputs[i]) != wantdir[i]));
|
||||
assert(!(basename(inputs[i]) != wantbase[i]));
|
||||
i += 1;
|
||||
};
|
||||
};
|
||||
@@ -208,7 +204,7 @@ fn fail() void = { os.exit(signalled + 10); };
|
||||
ins[3]=""; want[3]="";
|
||||
let i: i32 = 0;
|
||||
for (i < 4) {
|
||||
if (local(ins[i])! != want[i]) { fail(); };
|
||||
assert(!(local(ins[i])! != want[i]));
|
||||
i += 1;
|
||||
};
|
||||
};
|
||||
@@ -232,7 +228,7 @@ fn fail() void = { os.exit(signalled + 10); };
|
||||
for (i < 5) {
|
||||
buf.end = 0;
|
||||
push(&buf, ins[i])!;
|
||||
if (parent(&buf)! != want[i]) { fail(); };
|
||||
assert(!(parent(&buf)! != want[i]));
|
||||
i += 1;
|
||||
};
|
||||
};
|
||||
@@ -247,39 +243,39 @@ fn fail() void = { os.exit(signalled + 10); };
|
||||
let buf = buffer { ... };
|
||||
|
||||
// empty
|
||||
if (!(pop(&buf) is void)) { fail(); };
|
||||
if (string(&buf) != ".") { fail(); };
|
||||
assert(!(!(pop(&buf) is void)));
|
||||
assert(!(string(&buf) != "."));
|
||||
|
||||
// root dir
|
||||
buf.end = 0;
|
||||
if (push(&buf, "/")! != "/") { fail(); };
|
||||
if (!(pop(&buf) is void)) { fail(); };
|
||||
if (string(&buf) != "/") { fail(); };
|
||||
assert(!(push(&buf, "/")! != "/"));
|
||||
assert(!(!(pop(&buf) is void)));
|
||||
assert(!(string(&buf) != "/"));
|
||||
|
||||
// relative file — peek is NON-mutating
|
||||
buf.end = 0;
|
||||
if (push(&buf, "foo")! != "foo") { fail(); };
|
||||
if (peek(&buf) as str != "foo") { fail(); };
|
||||
if (string(&buf) != "foo") { fail(); };
|
||||
if (pop(&buf) as str != "foo") { fail(); };
|
||||
if (string(&buf) != ".") { fail(); };
|
||||
assert(!(push(&buf, "foo")! != "foo"));
|
||||
assert(!(peek(&buf) as str != "foo"));
|
||||
assert(!(string(&buf) != "foo"));
|
||||
assert(!(pop(&buf) as str != "foo"));
|
||||
assert(!(string(&buf) != "."));
|
||||
|
||||
// absolute file
|
||||
buf.end = 0;
|
||||
if (push(&buf, "/foo")! != "/foo") { fail(); };
|
||||
if (peek(&buf) as str != "foo") { fail(); };
|
||||
if (pop(&buf) as str != "foo") { fail(); };
|
||||
if (string(&buf) != "/") { fail(); };
|
||||
assert(!(push(&buf, "/foo")! != "/foo"));
|
||||
assert(!(peek(&buf) as str != "foo"));
|
||||
assert(!(pop(&buf) as str != "foo"));
|
||||
assert(!(string(&buf) != "/"));
|
||||
};
|
||||
|
||||
export fn main() i32 = {
|
||||
signalled = 1; push_cases();
|
||||
signalled = 2; isroot_cases();
|
||||
signalled = 3; string_cases();
|
||||
signalled = 4; dirname_basename_cases();
|
||||
signalled = 5; abs_cases();
|
||||
signalled = 6; local_cases();
|
||||
signalled = 7; parent_cases();
|
||||
signalled = 8; popsplit_cases();
|
||||
push_cases();
|
||||
isroot_cases();
|
||||
string_cases();
|
||||
dirname_basename_cases();
|
||||
abs_cases();
|
||||
local_cases();
|
||||
parent_cases();
|
||||
popsplit_cases();
|
||||
return 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user