diff --git a/test/testenv/testenv.ww b/test/testenv/testenv.ww index 0403128f..22e59425 100644 --- a/test/testenv/testenv.ww +++ b/test/testenv/testenv.ww @@ -6,6 +6,7 @@ package testenv; // test/package/package_test.ww idiom — not a framework: callers own // discovery, assertions, and verdicts. +import endian; import os; import os.exec; import strings; @@ -153,6 +154,35 @@ export fn same(a: str, b: str) bool = { return true; }; +// The ELF observers under test/object read header fields straight out +// of readfile's byte-carrying str; these getters reinterpret it as +// bytes and route through endian's canonical little-endian readers +// instead of re-deriving the bit math. u64 uniformly so one call +// shape covers u16/u32/u64 fields; callers narrow for offset math. +export fn leu16(s: str, off: i32) u64 = { + let b: []u8; + b.ptr = &s.ptr[off]; + b.len = 2; + b.cap = 2; + return endian.legetu16(b): u64; +}; + +export fn leu32(s: str, off: i32) u64 = { + let b: []u8; + b.ptr = &s.ptr[off]; + b.len = 4; + b.cap = 4; + return endian.legetu32(b): u64; +}; + +export fn leu64(s: str, off: i32) u64 = { + let b: []u8; + b.ptr = &s.ptr[off]; + b.len = 8; + b.cap = 8; + return endian.legetu64(b); +}; + export fn occurrences(haystack: str, needle: str) i32 = { if (needle.len == 0 || haystack.len < needle.len) { return 0; }; let count: i32 = 0;