lib/strconv tests: hand-main plumbing -> assert (@test conversion B3)
inttest keeps now-inert per-row id params (rows 1:1 per spec; removal deferred, ~100 callsites).
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
// inttest — exercises lib/strconv integer parse: parseint / stoi64 /
|
||||
// stou64 / the iN/uN width wrappers. Run with
|
||||
// `out/bin/ww run lib/strconv/test/inttest.ww`. Same
|
||||
// signalled-then-fail()-with-+10 pattern as decimaltest / bytestest:
|
||||
// a non-zero exit code (signalled+10) pinpoints the failing case.
|
||||
// `out/bin/ww run lib/strconv/test/inttest.ww`. A failing row aborts via
|
||||
// the assert/abort builtin (task #5 @test conversion).
|
||||
//
|
||||
// Verbatim port of ref/hare/strconv/stoi.ha:56-86 (stoi/stoi_bases) and
|
||||
// stou.ha:116-138 (stou/stou_bases). Hare's strconv integer tests are
|
||||
// flat assert SEQUENCES, not row-array tables — mirrored here as inline
|
||||
// per-case checks (feedback_test_match_hare_source: inline @test-fn for
|
||||
// verbatim ports). Each case sets `signalled` first so a failure's exit
|
||||
// code identifies the exact assertion.
|
||||
// verbatim ports). The leading id arg to each check helper is retained
|
||||
// to keep the rows 1:1 but is now inert (signalled plumbing removed, task #5).
|
||||
//
|
||||
// Lives in lib/strconv/test/ (not lib/strconv/) so `import strconv`
|
||||
// resolves to the lib/strconv DIRECTORY (pulls the full package), not
|
||||
@@ -22,124 +21,108 @@
|
||||
package strconv_test;
|
||||
|
||||
import strconv;
|
||||
import os;
|
||||
|
||||
let signalled: i32 = 0;
|
||||
fn fail() void = { os.exit(signalled + 10); };
|
||||
|
||||
fn cki(id: i32, s: str, b: base, want: i64) void = {
|
||||
signalled = id;
|
||||
match (stoi64(s, b)) {
|
||||
case let v: i64 => if (v != want) { fail(); };
|
||||
case let e: invalid => fail();
|
||||
case let e: overflow => fail();
|
||||
case let v: i64 => assert(!(v != want));
|
||||
case let e: invalid => abort();
|
||||
case let e: overflow => abort();
|
||||
};
|
||||
};
|
||||
|
||||
fn cki_inv(id: i32, s: str, b: base, idx: i32) void = {
|
||||
signalled = id;
|
||||
match (stoi64(s, b)) {
|
||||
case let v: i64 => fail();
|
||||
case let e: invalid => if (e: i32 != idx) { fail(); };
|
||||
case let e: overflow => fail();
|
||||
case let v: i64 => abort();
|
||||
case let e: invalid => assert(!(e: i32 != idx));
|
||||
case let e: overflow => abort();
|
||||
};
|
||||
};
|
||||
|
||||
fn cki_ovf(id: i32, s: str, b: base) void = {
|
||||
signalled = id;
|
||||
match (stoi64(s, b)) {
|
||||
case let v: i64 => fail();
|
||||
case let e: invalid => fail();
|
||||
case let v: i64 => abort();
|
||||
case let e: invalid => abort();
|
||||
case let e: overflow => { };
|
||||
};
|
||||
};
|
||||
|
||||
fn cku(id: i32, s: str, b: base, want: u64) void = {
|
||||
signalled = id;
|
||||
match (stou64(s, b)) {
|
||||
case let v: u64 => if (v != want) { fail(); };
|
||||
case let e: invalid => fail();
|
||||
case let e: overflow => fail();
|
||||
case let v: u64 => assert(!(v != want));
|
||||
case let e: invalid => abort();
|
||||
case let e: overflow => abort();
|
||||
};
|
||||
};
|
||||
|
||||
fn cku_inv(id: i32, s: str, b: base, idx: i32) void = {
|
||||
signalled = id;
|
||||
match (stou64(s, b)) {
|
||||
case let v: u64 => fail();
|
||||
case let e: invalid => if (e: i32 != idx) { fail(); };
|
||||
case let e: overflow => fail();
|
||||
case let v: u64 => abort();
|
||||
case let e: invalid => assert(!(e: i32 != idx));
|
||||
case let e: overflow => abort();
|
||||
};
|
||||
};
|
||||
|
||||
fn cku_ovf(id: i32, s: str, b: base) void = {
|
||||
signalled = id;
|
||||
match (stou64(s, b)) {
|
||||
case let v: u64 => fail();
|
||||
case let e: invalid => fail();
|
||||
case let v: u64 => abort();
|
||||
case let e: invalid => abort();
|
||||
case let e: overflow => { };
|
||||
};
|
||||
};
|
||||
|
||||
fn cki32_ovf(id: i32, s: str, b: base) void = {
|
||||
signalled = id;
|
||||
match (stoi32(s, b)) {
|
||||
case let v: i32 => fail();
|
||||
case let e: invalid => fail();
|
||||
case let v: i32 => abort();
|
||||
case let e: invalid => abort();
|
||||
case let e: overflow => { };
|
||||
};
|
||||
};
|
||||
|
||||
fn cki32(id: i32, s: str, b: base, want: i32) void = {
|
||||
signalled = id;
|
||||
match (stoi32(s, b)) {
|
||||
case let v: i32 => if (v != want) { fail(); };
|
||||
case let e: invalid => fail();
|
||||
case let e: overflow => fail();
|
||||
case let v: i32 => assert(!(v != want));
|
||||
case let e: invalid => abort();
|
||||
case let e: overflow => abort();
|
||||
};
|
||||
};
|
||||
|
||||
fn ck_int(id: i32, s: str, b: base, want: int) void = {
|
||||
signalled = id;
|
||||
match (stoi(s, b)) {
|
||||
case let v: int => if (v != want) { fail(); };
|
||||
case let e: invalid => fail();
|
||||
case let e: overflow => fail();
|
||||
case let v: int => assert(!(v != want));
|
||||
case let e: invalid => abort();
|
||||
case let e: overflow => abort();
|
||||
};
|
||||
};
|
||||
|
||||
fn ck_uint(id: i32, s: str, b: base, want: uint) void = {
|
||||
signalled = id;
|
||||
match (stou(s, b)) {
|
||||
case let v: uint => if (v != want) { fail(); };
|
||||
case let e: invalid => fail();
|
||||
case let e: overflow => fail();
|
||||
case let v: uint => assert(!(v != want));
|
||||
case let e: invalid => abort();
|
||||
case let e: overflow => abort();
|
||||
};
|
||||
};
|
||||
|
||||
fn ck_size(id: i32, s: str, b: base, want: size) void = {
|
||||
signalled = id;
|
||||
match (stoz(s, b)) {
|
||||
case let v: size => if (v != want) { fail(); };
|
||||
case let e: invalid => fail();
|
||||
case let e: overflow => fail();
|
||||
case let v: size => assert(!(v != want));
|
||||
case let e: invalid => abort();
|
||||
case let e: overflow => abort();
|
||||
};
|
||||
};
|
||||
|
||||
fn ck_int_ovf(id: i32, s: str, b: base) void = {
|
||||
signalled = id;
|
||||
match (stoi(s, b)) {
|
||||
case let v: int => fail();
|
||||
case let e: invalid => fail();
|
||||
case let v: int => abort();
|
||||
case let e: invalid => abort();
|
||||
case let e: overflow => { };
|
||||
};
|
||||
};
|
||||
|
||||
fn ck_uint_ovf(id: i32, s: str, b: base) void = {
|
||||
signalled = id;
|
||||
match (stou(s, b)) {
|
||||
case let v: uint => fail();
|
||||
case let e: invalid => fail();
|
||||
case let v: uint => abort();
|
||||
case let e: invalid => abort();
|
||||
case let e: overflow => { };
|
||||
};
|
||||
};
|
||||
@@ -251,8 +234,7 @@ fn streq(a: str, b: str) bool = {
|
||||
};
|
||||
|
||||
fn cks(id: i32, got: str, want: str) void = {
|
||||
signalled = id;
|
||||
if (!streq(got, want)) { fail(); };
|
||||
assert(!(!streq(got, want)));
|
||||
};
|
||||
|
||||
// ref/hare/strconv/utos.ha:74-83.
|
||||
|
||||
Reference in New Issue
Block a user