-- archive/macbinary tests (cases in tests/archive/_mac.luau). local Mod = require("@rosetta/archive/macbinary") local Bytes = require("@rosetta/core/Bytes") local Err = require("@rosetta/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()