50 lines
2.0 KiB
Luau
50 lines
2.0 KiB
Luau
-- archive/yenc tests against uuenview and uudeview (tools/fixtures/yenc.py).
|
|
local T = require("@tests/T")
|
|
local F = require("@rosetta")
|
|
local Yenc = require("@rosetta/archive/yenc")
|
|
local Bytes = require("@rosetta/core/Bytes")
|
|
local Err = require("@rosetta/core/Err")
|
|
local E = require("@tests/archive/_entries")
|
|
local Fx = require("@tests/gen/yenc")
|
|
|
|
local t = T.suite("yenc")
|
|
t:eq(Yenc.name, "yenc", "name")
|
|
|
|
local samples = {}
|
|
for _, c in Fx.cases do
|
|
local a, err = Yenc.decode(Bytes.reader(buffer.fromstring(c.data)))
|
|
t:check(a, c.name .. ": " .. tostring(err))
|
|
if a then
|
|
E.check(t, a, c.entries, c.name)
|
|
t:eq(a.meta.incomplete, nil, c.name .. ": complete")
|
|
end
|
|
t:eq(F.detect(c.data), "yenc", c.name .. ": detect")
|
|
if #c.data < 20000 then
|
|
table.insert(samples, c.data)
|
|
end
|
|
end
|
|
t:check(Fx.ours.ok, "our output decodes with uudeview")
|
|
E.roundTrip(t, Yenc, nil, "round trip")
|
|
E.roundTrip(t, Yenc, { line = 7 }, "round trip, 7-character lines")
|
|
|
|
-- only the first part of a posting: a short file flagged incomplete
|
|
local p = Yenc.decode(Bytes.reader(buffer.fromstring(Fx.partial))) :: any
|
|
t:check(p and p.meta.incomplete and p.meta.incomplete[1] == "big.bin" and p:list()[1].complete == false, "incomplete posting")
|
|
|
|
local good = buffer.tostring(Yenc.encode("hello", { name = "h" }) :: buffer)
|
|
local function code(s: string): string?
|
|
local _, e = Yenc.decode(Bytes.reader(buffer.fromstring(s)))
|
|
return e and e.code
|
|
end
|
|
t:eq(code((string.gsub(good, "crc32=%x+", "crc32=00000000"))), Err.CHECKSUM, "bad crc32")
|
|
t:eq(code((string.gsub(good, "=yend size=5", "=yend size=6"))), Err.CORRUPT, "size mismatch")
|
|
t:eq(code((string.gsub(good, "=yend[^\n]*\n", ""))), Err.TRUNCATED, "no =yend")
|
|
t:eq(code("nothing\n"), Err.CORRUPT, "no =ybegin")
|
|
t:eq(code("=ybegin line=128 size=99999999999 name=x\n=yend size=99999999999\n"), Err.LIMIT, "huge size")
|
|
t:eq((select(2, Yenc.encode("x", { line = 1 })) :: any).code, Err.ARG, "bad line length")
|
|
|
|
t:fuzz("decode", function(b: buffer)
|
|
return Yenc.decode(Bytes.reader(b))
|
|
end, samples)
|
|
t:done()
|