ws-arch2: archive/uu (uuencode / xxencode / base64 blocks, read + write), core/Crc16 (ccitt / arc), Archive.files helper, shared fixture helpers (_arch2.py / _arch2_ours.luau) and tests/archive/_entries.luau
core/Crc16 is new (CRC-16/XMODEM for BinHex / MacBinary, CRC-16/ARC for LHA / Zoo). containers/Archive gains Archive.files(value, name?) (additive).
This commit is contained in:
1 parent
51117f9732
commit
8cdb65367a
10 files changed
+679
No files matched your search
@@ -0,0 +1,70 @@
|
||||
-- archive/uu tests: blocks by GNU uuencode (classic / -m) and uuenview (-u / -x) decode to the right names, sizes,
|
||||
-- modes and data; several blocks in a mail; CRLF lines; our uu / xx / base64 output decodes with uudecode / uudeview
|
||||
-- (fixture step) and is byte-identical to GNU uuencode for one file; round trips; errors; the fuzz pass.
|
||||
-- Fixtures: tools/fixtures/uu.py.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@formats")
|
||||
local Uu = require("@formats/archive/uu")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local E = require("@tests/archive/_entries")
|
||||
local Fx = require("@tests/gen/uu")
|
||||
|
||||
local t = T.suite("uu")
|
||||
t:eq(Uu.name, "uu", "name")
|
||||
|
||||
local samples = {}
|
||||
for _, c in Fx.cases do
|
||||
local a, err = Uu.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)
|
||||
end
|
||||
t:eq(F.detect(c.data), "uu", c.name .. ": detect")
|
||||
table.insert(samples, c.data)
|
||||
end
|
||||
|
||||
-- byte-identical to GNU uuencode (mode 644) for each single file
|
||||
for _, g in Fx.gnu do
|
||||
local data = buffer.create(0)
|
||||
for _, f in E.FILES do
|
||||
if f.name == g.name then
|
||||
data = f.data
|
||||
end
|
||||
end
|
||||
local a = Uu.new()
|
||||
a:add(g.name, data, { mode = 0x1A4 })
|
||||
t:eq(buffer.tostring(a:write() :: buffer), g.uu, g.name .. ": same bytes as uuencode")
|
||||
t:eq(buffer.tostring(a:write({ variant = "base64" }) :: buffer), g.base64, g.name .. ": same bytes as uuencode -m")
|
||||
end
|
||||
for _, o in Fx.ours do
|
||||
t:check(o.ok, "our " .. o.variant .. " output decodes with the reference tool")
|
||||
end
|
||||
for _, v in { "uu", "xx", "base64" } do
|
||||
local out = E.roundTrip(t, Uu, { variant = v }, "round trip " .. v)
|
||||
if out then
|
||||
local back = Uu.decode(Bytes.reader(out)) :: any
|
||||
t:eq(back:list()[1].variant, v, v .. ": variant detected")
|
||||
end
|
||||
end
|
||||
-- a single block is a stream: the api unwraps what is inside (here: a uuencoded uuencoded file)
|
||||
local inner = Uu.encode("abc", { name = "x.uu" }) :: buffer
|
||||
local outer = Uu.encode(inner, { name = "x.uu" }) :: buffer
|
||||
local v = F.load(outer) :: any
|
||||
t:check(v and v.format == "uu" and v.meta.compression == "uu" and buffer.tostring((v:read("x.uu"))) == "abc", "api unwraps a single block")
|
||||
|
||||
-- errors
|
||||
local function code(s: string): string?
|
||||
local _, e = Uu.decode(Bytes.reader(buffer.fromstring(s)))
|
||||
return e and e.code
|
||||
end
|
||||
t:eq(code("no blocks here\n"), Err.CORRUPT, "no begin line")
|
||||
t:eq(code("begin 644 x\n#86)C\n"), Err.TRUNCATED, "no end line")
|
||||
t:eq(code("begin 644 x\n#8~~~\n`\nend\n"), Err.CORRUPT, "bad characters")
|
||||
t:eq(select(2, Uu.encode({})) and (select(2, Uu.encode({})) :: any).code, Err.ARG, "encode a non-archive")
|
||||
t:eq((select(2, Uu.encode("x", { variant = "zz" :: any })) :: any).code, Err.ARG, "bad variant")
|
||||
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Uu.decode(Bytes.reader(b))
|
||||
end, samples)
|
||||
t:done()
|
||||
Reference in new issue
Block a user