ws-arch2: archive/binhex, archive/macbinary (I / II / III), archive/applesingle (AppleSingle / AppleDouble v1 / v2), read + write, over the new containers/MacFile (fork convention, Mac OS Roman names, 1904 dates)

This commit is contained in:
4DBug committed 2026-10-31 14:11:03 -05:00
1 parent fe44292f58
commit 3243291877
13 files changed
+1152 -4

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
-- archive/binhex tests: the binhex 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/binhex")
local Bytes = require("@formats/core/Bytes")
local Err = require("@formats/core/Err")
local run = require("@tests/archive/_mac")
local t, samples = run("binhex", Mod, { {} })
local function code(s: string): string?
local _, e = Mod.decode(Bytes.reader(buffer.fromstring(s)))
return e and e.code
end
local good = buffer.tostring(Mod.encode("hello binhex", { name = "h" }) :: buffer)
-- flip one data character (keeps the 6-bit alphabet): a CRC mismatch somewhere
local i = #good - 10
local c = string.sub(good, i, i)
local bad = string.sub(good, 1, i - 1) .. (if c == "!" then "\"" else "!") .. string.sub(good, i + 1)
t:eq(code(bad), Err.CHECKSUM, "flipped character")
t:eq(code(string.sub(good, 1, #good - 3)), Err.TRUNCATED, "no closing colon")
t:eq(code("nothing"), Err.CORRUPT, "no banner")
t:eq(code("(This file must be converted with BinHex 4.0)\n:~~~:"), Err.CORRUPT, "bad character")
t:eq((select(2, Mod.encode({})) :: any).code, Err.ARG, "encode a non-archive")
t:fuzz("decode", function(b: buffer)
return Mod.decode(Bytes.reader(b))
end, samples)
t:done()