Files
ww/lib/hash/crc32/crc32_test.ww
Hojun-Cho 2338ea5d59 ww: lib tests run via -T test mode; bare mains retired (closes @test conversion)
'ww test' gains the istest build path (-T injection in build_one/
buildone) and do_test/dotest accept -I, mirroring do_run - both twins.
The 35 converted lib tests drop their interim bare mains (-T
synthesizes the entry from @test fns and rejects a user main); their
35 C run-drivers flip 'ww run' -> 'ww test'; 989_lib_byteid compiles
lib tests under -T (8 user-main probe fixtures stay non-T, gated on
the fixture field). Abort-on-first-failure stands until the deferred
record-and-continue harness lands with the multi-package arc.
2026-06-10 20:45:46 +09:00

55 lines
1.3 KiB
Plaintext

package crc32_test;
import crc32;
fn putstr(s: str, into: []u8, off: i32) i32 = {
let i: i32 = 0;
for (i < s.len) {
into[off + i] = s[i];
i += 1;
};
return off + s.len;
};
fn check(s: str, ieee: u32, cast: u32, koop: u32) void = {
let arr: [128]u8;
let n: i32 = putstr(s, arr[0:128], 0);
let buf: []u8 = arr[0:n];
assert(!(crc32.sum32ieee(buf) != ieee));
assert(!(crc32.sum32castagnoli(buf) != cast));
assert(!(crc32.sum32koopman(buf) != koop));
};
@test fn vec_empty() void = {
let arr: [1]u8;
let buf: []u8 = arr[0:0];
assert(!(crc32.sum32ieee(buf) != 0u32));
assert(!(crc32.sum32castagnoli(buf) != 0u32));
assert(!(crc32.sum32koopman(buf) != 0u32));
};
@test fn vec_fire() void = {
check("Give a man a fire, they be warm for a day",
4026734998u32, 2112273292u32, 1263149916u32);
};
@test fn vec_setfire() void = {
check("Set a man on fire, they be warm for the rest of their life",
3931092334u32, 4172943610u32, 3071632577u32);
};
@test fn vec_blm() void = {
check("Black lives matter",
2370964079u32, 2068416418u32, 4151357773u32);
};
@test fn vec_unix() void = {
check("UNIX is simple and coherent",
3254252081u32, 1650777601u32, 340189632u32);
};
@test fn vec_gnu() void = {
check("GNU's not UNIX",
224734747u32, 200511816u32, 332335539u32);
};