-- archive/macbinary tests: the macbinary cases of tools/fixtures/mac.py against The Unarchiver's listings, our output read by unar, -- round trips with a resource fork and Finder info (tests/archive/_mac.luau), errors, the fuzz pass. local Mod = require("@formats/archive/macbinary") local Bytes = require("@formats/core/Bytes") local Err = require("@formats/core/Err") local run = require("@tests/archive/_mac") local t, samples = run("macbinary", Mod, { {} }) local function code(s: string): string? local _, e = Mod.decode(Bytes.reader(buffer.fromstring(s))) return e and e.code end local good = Mod.encode("hello macbinary", { name = "h" }) :: buffer local bad = buffer.create(buffer.len(good)) buffer.copy(bad, 0, good) buffer.writeu8(bad, 70, 1) t:eq(code(buffer.tostring(bad)), Err.CHECKSUM, "header CRC") t:eq(code(string.sub(buffer.tostring(good), 1, 140)), Err.TRUNCATED, "short data fork") t:eq(code(string.rep("\1", 200)), Err.CORRUPT, "not MacBinary") t:eq(code("short"), Err.TRUNCATED, "short header") t:fuzz("decode", function(b: buffer) return Mod.decode(Bytes.reader(b)) end, samples, { keepHeader = 0 }) t:done()