tests/archive: comments: specs only

This commit is contained in:
4DBug committed 2026-11-01 01:49:50 -05:00
1 parent 54f53a35f6
commit 96602286f8
33 files changed
+34 -226

No files matched your search

+1 -20
View File
@@ -1,10 +1,4 @@
-- archive/zip + containers/Zip tests: generated archives (comment with a fake end record, data descriptors,
-- force_zip64, an all-ZIP64 archive, 66000 entries, a prefix stub, a wrong local header, unicode, empty) read entry by
-- entry against Python's zipfile listing (and every Webamp demo skin when SKINS_DIR is set); lookup rules; bad CRC,
-- encrypted and unsupported entries; the writer (stored / deflated, levels, UTF-8 names, DOS times, comments, ZIP64,
-- raw copies) read back; the Archive API (list / read / add / remove / write, create, encode of a table) and the api;
-- corrupt input never throws. The writer's output was also checked by hand: `unzip -t`, Python zipfile and 7z read it.
-- Ported from zip-luau tests/zip.luau. Fixtures: tools/fixtures/zip.py.
-- archive/zip + containers/Zip tests against Python's zipfile (tools/fixtures/zip.py); SKINS_DIR adds the Webamp demo skins.
local T = require("@tests/T")
local Zip = require("@rosetta/containers/Zip")
local ZipF = require("@rosetta/archive/zip")
@@ -24,7 +18,6 @@ local function dataOf(a: any): string
return buffer.tostring(Deflate.zlib(buffer.fromstring(a.dataZ)) :: buffer)
end
-- open an archive and compare it with zipfile's listing; read every entry
local function verify(a: any, label: string): (any, number)
local z, err = Zip.open(dataOf(a))
t:check(z, label .. ": open: " .. tostring(err))
@@ -61,7 +54,6 @@ else
t:note("(no skins: set SKINS_DIR to the Webamp demo skins)")
end
-- lookup and specifics
do
local z = byName.basic.zip
t:eq(z:find("readme.txt").name, "readme.txt", "find exact")
@@ -88,7 +80,6 @@ do
t:eq(byName.many.zip:readString("d/65999.txt"), "65999", "last of 66000 entries")
t:eq(#byName.empty.zip:list(), 0, "empty archive")
t:check(Zip.isZip(byName.basic.data) and Zip.isZip(byName.empty.data) and not Zip.isZip("GIF89a"), "isZip")
-- a sub-range reader
local s = byName.basic.data
local big = buffer.create(#s + 10)
buffer.writestring(big, 4, s)
@@ -96,7 +87,6 @@ do
t:check(zs and zs:readString("readme.txt") ~= nil, "open a sub-range Reader")
end
-- a bad CRC, encrypted and unsupported entries
do
local data = buffer.fromstring(byName.basic.data)
local z = Zip.open(byName.basic.data)
@@ -118,7 +108,6 @@ do
t:check(oe and oe.code == Err.ARG, "a non-buffer argument")
end
-- the writer
do
local rand = T.rng(5)
local w = Zip.writer()
@@ -162,7 +151,6 @@ do
t:check(list[2].modified.year == 1980 and list[2].modified.month == 1 and list[2].modified.day == 1, "default time 1980-01-01")
t:eq(z.comment, "archive comment", "archive comment written")
t:check(not z.zip64, "small archive is not ZIP64")
-- forced ZIP64
local w64 = Zip.writer()
w64:add("a.txt", text)
w64:add("b.txt", "bee", { method = "store" })
@@ -175,19 +163,16 @@ do
end
local zm = Zip.open(wm:finish() :: buffer)
t:check(zm and zm.zip64 and #zm:list() == 66000 and zm:readString("d/65999.txt") == "65999", "66000 entries")
-- dates
for _, s in { 315532800, 946684799, 1700000000, 4354819198 } do
local tm, dt = Zip.dosTime(s)
t:eq(Zip.unixTime(tm, dt), s - s % 2, "dos time of " .. s)
end
t:check(select(2, Zip.dosTime(0)) == 0x21, "before 1980 clamps")
-- bad arguments
t:check(not w:add("", "x"), "empty name")
t:check(not w:add("x", 5 :: any), "bad data")
t:check(not w:add("x", "y", { method = "lzma" } :: any), "bad method")
end
-- the Archive (archive/zip)
do
t:eq(ZipF.name, "zip", "name")
t:eq(ZipF.category, "archive", "category")
@@ -216,7 +201,6 @@ do
table.insert(names, e.name)
end
t:eq(table.concat(names, ","), "readme.txt,Skin/Main.BMP,Skin/,Skin/sub/deep.txt,empty.txt,__MACOSX/Skin/._Main.BMP,Sk\u{ef}n/\u{fc}nicode.txt,new/one.txt", "order kept")
-- create, encode of a table, encode of another Archive
local c = ZipF.create()
c:add("hello.txt", "hi")
local cz = ZipF.decode(Bytes.reader(ZipF.encode(c) :: buffer)) :: any
@@ -225,10 +209,8 @@ do
t:check(tz:list()[1].name == "a.txt" and buffer.tostring(tz:read("b.txt")) == "bee", "encode a { name = data } table")
local _, ee = ZipF.encode(5 :: any)
t:check(ee and ee.code == Err.ARG, "encode a number")
-- comments survive a rewrite
local cm = ZipF.decode(Bytes.reader(buffer.fromstring(byName.comment.data))) :: any
t:eq(string.sub(Zip.open(cm:write()).comment, 1, 14), "a comment with", "comment kept on write")
-- the api
local la = F.archive.load(byName.basic.data)
t:check(la and la.kind == "archive" and #la:list() == byName.basic.count, "F.archive.load")
t:eq(F.detect(byName.basic.data), "zip", "F.detect")
@@ -238,7 +220,6 @@ do
t:check(saved2 ~= nil, "F.save without a format uses the source format")
end
-- corrupt archives never throw
local samples = {}
for _, a in Fx.archives do
if a.data then