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 -7
View File
@@ -1,8 +1,4 @@
-- archive/7z tests: the contract and sniff; every archive 7-Zip wrote in tools/fixtures/7z.py (LZMA / LZMA2 / copy /
-- Deflate, solid and not, BCJ / ARM64 / ARM / PPC + SPARC / delta chains, plain and encoded headers) lists exactly the
-- source tree (names incl. UTF-16 surrogates, directories, empty files, mtimes) and reads every file back; unsupported
-- methods (PPMd, BCJ2, AES) list but fail on read with Err.UNSUPPORTED naming the method; corrupt CRCs; F.load;
-- the fuzz no-throw pass.
-- archive/7z tests against 7-Zip's archives (tools/fixtures/7z.py).
local T = require("@tests/T")
local SevenZip = require("@rosetta/archive/7z")
local F = require("@rosetta")
@@ -83,7 +79,6 @@ do
t:check(a4 and a4:read("a/b/c/deep.txt"), "checkCrc = false")
end
-- through the api
do
local c = Fx.cases[2]
local a, err = F.load(c.data)
@@ -93,7 +88,6 @@ do
t:check(r and buffer.tostring(r) == want["readme.txt"].data, "F.load read")
end
-- fuzz: decode + read every entry
do
local samples = {}
for _, c in Fx.cases do
+1 -4
View File
@@ -1,6 +1,4 @@
-- shared by the archive tests: check(t, archive, want, label) compares an Archive's entries with the reference listing
-- want = { { name, size?, crc?, mode?, mtime?, dir?, link? } } (only the fields present are compared; every wanted
-- entry must exist; crc is the CRC-32 of the data read back), and the files written by _arch2_ours.luau.
-- shared by the archive tests: entry listings compared with a reference tool's, and the standard file set.
local Crc32 = require("@rosetta/core/Crc32")
local E = {}
@@ -51,7 +49,6 @@ E.FILES = {
{ name = "empty.txt", data = buffer.create(0) },
}
-- roundTrip(t, mod, opts, label): add the standard files to mod.new(), write with opts, decode, compare
function E.roundTrip(t: any, mod: any, opts: any?, label: string): buffer?
local Bytes = require("@rosetta/core/Bytes")
local a = mod.new()
+1 -4
View File
@@ -1,6 +1,4 @@
-- shared by tests/archive/{binhex,macbinary,applesingle}.luau: run(name, module) checks the format's cases of
-- tools/fixtures/mac.py against The Unarchiver's listings (fork names, sizes, data CRCs, type / creator), our writer's
-- output read by unar (fixture step), round trips with a resource fork and Finder info, and the fuzz pass.
-- shared by the binhex / macbinary / applesingle tests: tools/fixtures/mac.py cases against The Unarchiver's listings.
local T = require("@tests/T")
local F = require("@rosetta")
local Bytes = require("@rosetta/core/Bytes")
@@ -42,7 +40,6 @@ return function(name: string, mod: any, encodeVariants: { any }): (any, { string
t:check(o.ok, "unar reads our output (" .. o.variant .. "): " .. o.detail)
end
end
-- round trips: Finder info, dates, a resource fork
for _, opts in encodeVariants do
local a = mod.new()
a:add("Caf\u{e9}", "data fork", { mtime = 1700000000 })
+1 -5
View File
@@ -1,7 +1,4 @@
-- archive/adf tests: DD / HD images formatted OFS, FFS, FFS international, OFS / FFS with directory cache by amitools'
-- xdftool, holding nested directories, an empty file, a file with extension blocks and an ISO-8859-1 name, list the
-- files xdftool reads back (names, sizes, data CRCs, directories, a set date), volume name and file system; errors
-- (root block checksum, bad hash chains); the fuzz pass. Fixtures: tools/fixtures/adf.py (images gzip-compressed).
-- archive/adf tests against amitools' xdftool (tools/fixtures/adf.py, images gzip-compressed).
local T = require("@tests/T")
local F = require("@rosetta")
local Adf = require("@rosetta/archive/adf")
@@ -30,7 +27,6 @@ for _, c in Fx.cases do
t:eq(F.detect(data), "adf", c.name .. ": detect")
end
-- errors
local img = first :: buffer
local function code(b: buffer): string?
local _, e = Adf.decode(Bytes.reader(b))
+1 -2
View File
@@ -1,5 +1,4 @@
-- archive/applesingle tests: the applesingle 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.
-- archive/applesingle tests (cases in tests/archive/_mac.luau).
local Mod = require("@rosetta/archive/applesingle")
local Bytes = require("@rosetta/core/Bytes")
local Err = require("@rosetta/core/Err")
+1 -9
View File
@@ -1,8 +1,4 @@
-- archive/ar tests: GNU ar (deterministic and with times, a library with its "/" symbol table), llvm-ar BSD (#1/ names,
-- __.SYMDEF) and bsdtar arbsd archives list the input files (names, sizes, mtimes, data CRCs) and symbols; the GNU writer
-- gives GNU ar rcSD's bytes for the same files; bsdtar and dpkg-deb archives re-encode to their own bytes; .deb packages
-- from dpkg-deb (xz / gzip / zstd / none) and older bzip2 / lzma members give meta.control and load through the api as
-- their data tar; errors; the fuzz pass. Fixtures: tools/fixtures/ar.py.
-- archive/ar tests against GNU ar, llvm-ar, bsdtar and dpkg-deb (tools/fixtures/ar.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Ar = require("@rosetta/archive/ar")
@@ -47,7 +43,6 @@ local function sortedSymbols(list: { any }): string
return table.concat(s, ",")
end
-- 1. reading
for _, c in Fx.archives do
local a, err = decode(c.data)
t:check(a, c.name .. ": " .. tostring(err))
@@ -65,7 +60,6 @@ for _, c in Fx.archives do
end
end
-- 2. writing: GNU ar rcSD's bytes; BSD names read back; any Archive to ar
do
local a = Ar.new()
for _, f in Fx.files do
@@ -89,7 +83,6 @@ do
t:eq(conv:list()[1].mtime, 5, "tar -> ar: mtime")
end
-- 3. Debian packages
for _, d in Fx.debs do
local a, err = decode(d.data)
t:check(a, d.name .. ": " .. tostring(err))
@@ -112,7 +105,6 @@ for _, d in Fx.debs do
t:eq(outer.format, "ar", d.name .. ": unwrap = false keeps the ar")
end
-- 4. errors
do
local _, e1 = decode("!<thin>\n")
t:check(e1 and e1.code == Err.UNSUPPORTED, "thin archive: " .. tostring(e1))
+1 -4
View File
@@ -1,6 +1,4 @@
-- archive/arj tests: archives by ARJ 3.10 with methods 0 .. 4 (stored, the LHA-style Huffman methods 1 .. 3, method
-- 4) give the files `arj x` extracts (names, sizes, data CRCs); header and data CRC errors, truncation; the fuzz
-- pass. Fixtures: tools/fixtures/arj.py.
-- archive/arj tests against ARJ 3.10 (tools/fixtures/arj.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Arj = require("@rosetta/archive/arj")
@@ -23,7 +21,6 @@ for _, c in Fx.cases do
table.insert(samples, string.sub(c.data, 1, 3000))
end
-- errors
local data = Fx.cases[2].data -- -m1
local function code(s: string): string?
local _, e = Arj.decode(Bytes.reader(buffer.fromstring(s)))
+1 -2
View File
@@ -1,5 +1,4 @@
-- 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.
-- archive/binhex tests (cases in tests/archive/_mac.luau).
local Mod = require("@rosetta/archive/binhex")
local Bytes = require("@rosetta/core/Bytes")
local Err = require("@rosetta/core/Err")
+1 -9
View File
@@ -1,6 +1,4 @@
-- archive/br tests: the contract; fixture streams (tools/fixtures/brotli.py) load as a one-entry stream archive named
-- after the file; detection through F.load (sniff + extension); sniff rejects garbage and other formats; errors as
-- Err values; the fuzz no-throw pass.
-- archive/br tests (tools/fixtures/brotli.py).
local T = require("@tests/T")
local Br = require("@rosetta/archive/br")
local F = require("@rosetta")
@@ -10,12 +8,10 @@ local Fx = require("@tests/gen/brotli")
local t = T.suite("br")
-- 1. the contract
t:eq(Br.name, "br", "name")
t:eq(Br.category, "archive", "category")
t:check(Br.caps.decode and not Br.caps.encode, "caps")
-- 2. fixtures
local n = 0
for i, c in Fx.cases do
if i % 4 == 0 then
@@ -34,13 +30,11 @@ for i, c in Fx.cases do
end
t:note("%d streams", n)
-- default entry name
do
local a = Br.decode(Bytes.reader(buffer.fromstring(Fx.cases[5].data)))
t:eq(a:list()[1].name, "data", "default entry name")
end
-- 3. through the api: by sniff (with and without the extension) and by format name
do
local c = Fx.cases[40]
local a, err = F.load(c.data, { name = "x.br" })
@@ -55,7 +49,6 @@ do
t:check(e and e.code == Err.UNSUPPORTED, "no encoder: " .. tostring(e))
end
-- 4. sniff: garbage and plain text are rejected
do
local rand = T.rng(99)
local hits = 0
@@ -78,7 +71,6 @@ do
t:check(e and Err.is(e) and (e.code == Err.CORRUPT or e.code == Err.TRUNCATED), "bad data: " .. tostring(e))
end
-- 5. fuzz
do
local samples = {}
for i, c in Fx.cases do
+1 -4
View File
@@ -1,6 +1,4 @@
-- archive/bz2 tests: the contract, sniff, a .bz2 as a one-entry single-stream archive (entry named after the file),
-- the api path (F.load by sniff, .tar.bz2 unwrap is the api's: covered once tar exists), errors, the fuzz pass.
-- Fixtures: tools/fixtures/bzip2.py.
-- archive/bz2 tests (tools/fixtures/bzip2.py).
local T = require("@tests/T")
local Bz2 = require("@rosetta/archive/bz2")
local Bytes = require("@rosetta/core/Bytes")
@@ -44,7 +42,6 @@ do
t:eq(a2:list()[1].name, "x.tar", ".tbz2 -> .tar")
local a3 = Bz2.decode(Bytes.reader(buffer.fromstring(c.data)))
t:eq(a3:list()[1].name, "data", "no name -> data")
-- through the api
local v, ferr = F.load(c.data)
t:check(v and v.kind == "archive" and v.format == "bz2", "F.load sniffs bz2: " .. tostring(ferr))
t:eq(F.detect(c.data), "bz2", "F.detect")
+1 -14
View File
@@ -1,11 +1,4 @@
-- archive/cab tests: cabinets by gcab (stored / MSZIP), lcab, a builder of MSZIP blocks that use the previous block as
-- their dictionary (several folders, reserve areas, attributes, UTF-8 names) and libmspack's test cabinets give the
-- files cabextract extracts (names, sizes, data CRCs, DOS times read as UTC); cabextract / gcab / 7z extract our
-- writer's output (fixture step) and it round-trips; spanned files are UNSUPPORTED; checksum, truncation and
-- signature errors, libmspack's broken cabinets; LZX (codecs/compress/Lzx) from a fixture compressor whose cabinets
-- cabextract extracts (windows 2^15 .. 2^21, verbatim / aligned / uncompressed blocks, E8); Quantum
-- (codecs/compress/Quantum) the same way (windows 2^10 .. 2^21, model rescaling); Deflate's preset
-- dictionary; the fuzz pass. Fixtures: tools/fixtures/cab.py.
-- archive/cab tests against cabextract, gcab, lcab, 7z and libmspack's test cabinets (tools/fixtures/cab.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Cab = require("@rosetta/archive/cab")
@@ -38,7 +31,6 @@ for _, c in Fx.cases do
end
t:check(methods.store and methods.mszip and methods.lzx and methods.quantum, "covers store, mszip, lzx and quantum")
-- attributes, UTF-8 names, reserve areas (the builder's two-folder cabinet)
local two = assert(load(Fx.cases[5].data))
local naive = two._byName["na\u{ef}ve \u{2603}.txt"]
t:check(naive and naive.utf8 and naive.attributes == 0x20, "utf-8 name and attributes")
@@ -47,7 +39,6 @@ t:eq(buffer.tostring(two.meta.reserve), "HEADER-RESERVE", "header reserve")
t:eq(#two.meta.folders, 2, "two folders")
t:check(assert(load(Fx.cases[4].data))._byName["b.bin"].readonly, "read-only attribute")
-- our writer
t:check(Fx.ours.ok, "reference tools extract our cabinets: " .. Fx.ours.log)
E.roundTrip(t, Cab, nil, "round trip mszip")
E.roundTrip(t, Cab, { compression = "none" }, "round trip store")
@@ -93,19 +84,16 @@ for _, c in Fx.bad do
table.insert(samples, c.data)
end
-- LZX directly
local Lzx = require("@rosetta/codecs/compress/Lzx")
t:check(not Lzx.decode(buffer.create(10), 0, 10, 100, 14), "LZX window 2^14 unsupported")
t:check(not Lzx.decode(buffer.create(10), 0, 10, 100, 16), "LZX of zeros")
t:check(not Lzx.decode(buffer.create(10), 4, 10, 100, 16), "LZX range past the end")
-- Quantum directly
local Quantum = require("@rosetta/codecs/compress/Quantum")
t:check(not Quantum.decode(buffer.create(10), {}, 0, 9), "Quantum window 2^9 unsupported")
t:check(not Quantum.decode(buffer.create(10), { { at = 0, len = 10, size = 5 } }, 6, 16), "Quantum sizes must add up")
t:check(not Quantum.decode(buffer.create(10), { { at = 4, len = 10, size = 5 } }, 5, 16), "Quantum range past the end")
-- Deflate's preset dictionary and MSZIP blocks
local block1 = assert(Deflate.compress(string.rep("ab", 50)))
local mszip = buffer.create(buffer.len(block1) + 2)
buffer.writestring(mszip, 0, "CK")
@@ -117,7 +105,6 @@ local z = assert(Deflate.compress(dictText .. dictText))
local plain = assert(Deflate.inflate(z, nil, nil, 1600, buffer.fromstring("unused prefix")))
t:eq(buffer.tostring(plain), dictText .. dictText, "inflate with an unused dictionary")
-- errors
local data = Fx.cases[2].data -- gcab -z
local function code(s: string): string?
local a, e = load(s)
+1 -11
View File
@@ -1,8 +1,4 @@
-- archive/cpio tests (and containers/Cpio): GNU cpio archives of one tree in newc / crc / odc / bin (and the bin one
-- byte-swapped to big endian) and bsdtar newc / odc archives list the entries os.lstat sees (names, types, modes, sizes,
-- mtimes, link counts, symlink targets, data CRCs, hard links reading the shared data); re-encoding the GNU newc / crc /
-- odc archives gives GNU's bytes; devices (rdev fields), crc sums, a .cpio.gz through the api, conversions to and from
-- tar (hard links share an inode), errors, the fuzz pass. Fixtures: tools/fixtures/cpio.py.
-- archive/cpio tests (and containers/Cpio) against GNU cpio and bsdtar (tools/fixtures/cpio.py).
local T = require("@tests/T")
local F = require("@rosetta")
local CpioF = require("@rosetta/archive/cpio")
@@ -42,7 +38,6 @@ local function check(a: any, want: any, label: string)
end
end
-- 1. reading
for _, c in Fx.archives do
local a, err = CpioF.decode(Bytes.reader(buffer.fromstring(c.data)))
t:check(a, c.name .. ": " .. tostring(err))
@@ -61,7 +56,6 @@ for _, c in Fx.archives do
end
end
-- 2. writing: GNU's bytes back from the decoded archive (newc / crc / odc)
for _, c in Fx.archives do
if c.gnu and c.format ~= "bin" then
local a = CpioF.decode(Bytes.reader(buffer.fromstring(c.data)))
@@ -71,7 +65,6 @@ for _, c in Fx.archives do
end
end
-- 3. devices, sums, the container directly
do
local list, info = Cpio.read(buffer.fromstring(Fx.devices))
t:check(list and info.format == "newc", "devices: read")
@@ -84,7 +77,6 @@ do
local _, e1 = Cpio.read(buffer.fromstring(Fx.badcrc))
t:check(e1 and e1.code == Err.CHECKSUM, "crc: bad sum: " .. tostring(e1))
t:check(Cpio.read(buffer.fromstring(Fx.badcrc), 0, nil, { verify = false }), "crc: verify = false")
-- devices survive a newc and an odc write
for _, fmt in { "newc", "odc" } do
local a = CpioF.decode(Bytes.reader(buffer.fromstring(Fx.devices)))
local back = CpioF.decode(Bytes.reader(assert(a:write({ format = fmt }))))
@@ -93,7 +85,6 @@ do
end
end
-- 4. the api: .cpio.gz unwraps, Archive values, conversions
do
local a, err = F.load(Fx.gz, { name = "tree.cpio.gz" })
t:check(a and a.format == "cpio" and a.meta.compression == "gzip", "cpio.gz unwraps: " .. tostring(err))
@@ -125,7 +116,6 @@ do
t:eq(cp:list()[1].nlink, 2, "tar hard link -> cpio: nlink")
end
-- 5. errors
do
local good = Fx.archives[1].data
local _, e1 = CpioF.decode(Bytes.reader(buffer.fromstring(string.sub(good, 1, 300))))
+1 -6
View File
@@ -1,7 +1,4 @@
-- archive/d64 tests: D64 / D71 / D81 images made by VICE's c1541 (PRG / SEQ / USR, multi-sector, a deleted file, an
-- error-info block, 30 files over several directory sectors) list the files c1541 reads back (names, sizes, types,
-- data CRCs), disk name and id; our D64 / D71 / D81 output is read by c1541 (fixture step) and round-trips; PETSCII
-- names; errors; the fuzz pass. Fixtures: tools/fixtures/d64.py.
-- archive/d64 tests against VICE's c1541 (tools/fixtures/d64.py).
local T = require("@tests/T")
local F = require("@rosetta")
local D64 = require("@rosetta/archive/d64")
@@ -43,14 +40,12 @@ for _, v in { "d64", "d71", "d81" } do
t:eq(a.meta.disk, "round trip", v .. ": disk name")
end
end
-- PETSCII names: lower / upper case and other bytes survive a round trip
local a = D64.new()
a:add("Mixed Case 1", "x")
a:add("\u{E0D3}hift", "y")
local back = D64.decode(Bytes.reader(a:write() :: buffer)) :: any
t:check(back._byName["Mixed Case 1"] and back._byName["\u{E0D3}hift"] == nil and back._byName["Shift"], "petscii names")
-- errors
local function code(b: buffer): string?
local _, e = D64.decode(Bytes.reader(b))
return e and e.code
+1 -7
View File
@@ -1,8 +1,4 @@
-- archive/fat tests (and containers/Fat): FAT12 (1.44 MB, 720 KB) / FAT16 / FAT32 images by mkfs.fat filled by mtools
-- (long names over several entries, lower-case 8.3, non-ASCII names, nested directories, empty and many-cluster files)
-- and a hard-disk image with an MBR partition list what mtools extracts (names, sizes, data CRCs, dates as UTC,
-- directories), FAT width and label; our floppies pass fsck.fat -n and extract with mtools (fixture step) and
-- round-trip; errors; the fuzz pass. Fixtures: tools/fixtures/fat.py (images gzip-compressed).
-- archive/fat tests (and containers/Fat) against mtools and fsck.fat (tools/fixtures/fat.py, images gzip-compressed).
local T = require("@tests/T")
local F = require("@rosetta")
local FatF = require("@rosetta/archive/fat")
@@ -38,7 +34,6 @@ end
for _, size in { 1440, 720, 360, 2880 } do
E.roundTrip(t, FatF, { size = size }, "round trip " .. size)
end
-- long and short names, directories, dates
local a = FatF.new()
a:add("Some Long Name.html", "a", { mtime = 1700000000 })
a:add("dir/UPPER.TXT", "b", { mtime = 1700000002 })
@@ -55,7 +50,6 @@ t:eq(back._byName["dir/UPPER.TXT"].mtime, 1700000002, "dos time")
t:eq(back._byName["dir/Same Prefix 2.txt"].shortName, "SAMEPR~2.TXT", "numeric tail")
t:eq(back.meta.label, "TEST", "label")
-- errors
local function code(b: buffer): string?
local _, e = FatF.decode(Bytes.reader(b))
return e and e.code
+1 -3
View File
@@ -1,6 +1,4 @@
-- archive/grp tests: Build GRP archives written by tools/fixtures/grp.py list the entries an independent Python
-- reader sees (names, sizes, data CRCs); our writer produces the same bytes as the Python writer and round-trips;
-- conversion from a zip; errors; the fuzz pass. Fixtures: tools/fixtures/grp.py.
-- archive/grp tests against an independent Python reader and writer (tools/fixtures/grp.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Grp = require("@rosetta/archive/grp")
+1 -7
View File
@@ -1,6 +1,4 @@
-- archive/gzip tests: members from Python's gzip and the gzip CLI (FNAME, MTIME, levels, concatenated members) decode
-- to one entry with the right name / mtime / data; the writer round-trips (buffer, string, one-entry archive, several
-- entries as a .tar.gz) and keeps FNAME / MTIME; the api; errors; the fuzz pass. Fixtures: tools/fixtures/tar.py.
-- archive/gzip tests against Python's gzip and the gzip CLI (tools/fixtures/tar.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Gzip = require("@rosetta/archive/gzip")
@@ -34,7 +32,6 @@ do
t:eq(b:list()[1].name, "x.tar", ".tgz entry is a .tar")
end
-- writing
do
local text = string.rep("gzip round trip ", 500)
for _, level in { 0, 1, 6, 9 } do
@@ -48,7 +45,6 @@ do
t:eq(back:list()[1].name, "notes.txt", "FNAME written")
t:eq(back:list()[1].mtime, 1600000000, "MTIME written")
t:eq(buffer.tostring((back:read("notes.txt"))), text, "one-entry archive round trip")
-- a decoded gzip saves back as gzip (its source format)
local g = F.load(Fx.gzips[1].data)
local again = F.load(F.save(g))
t:eq(again:list()[1].name, "story.txt", "F.save(gzip) keeps the name")
@@ -61,7 +57,6 @@ do
t:eq(tar.format, "tar", "several entries write a .tar.gz")
t:eq(tar.meta.compression, "gzip", "unwrapped")
t:eq(buffer.tostring((tar:read("b.txt"))), "BB", ".tar.gz entry")
-- any archive converts: tar -> gzip -> tar
local tb = F.convert(Fx.tars[1].data, "gzip")
local t2 = F.load(tb)
t:eq(#t2:list(), #Fx.tars[1].entries, "tar -> tar.gz -> tar")
@@ -71,7 +66,6 @@ do
t:check(e2 and e2.code == Err.ARG, "not an archive")
end
-- errors
do
local d = Fx.gzips[1].data
local _, e1 = Gzip.decode(Bytes.reader(buffer.fromstring(string.sub(d, 1, 20))))
+1 -10
View File
@@ -1,9 +1,4 @@
-- archive/iso tests (and containers/Iso9660): xorriso images (plain names, Joliet, Rock Ridge, Joliet + Rock Ridge with
-- deep directories / a 200-byte name / a long symlink target) and a genisoimage -J -R image (rr_moved relocation, CE
-- areas) list what the source tree holds (Rock Ridge: names, modes, symlink targets, mtimes, data CRCs) or what pycdlib
-- reads (plain and Joliet names, sizes, data CRCs); prefer = "joliet" on a -J -R image; an El Torito boot catalog as
-- xorriso reports it; a crafted multi-extent file reads whole; an interleaved file is UNSUPPORTED; errors; the fuzz pass.
-- Fixtures: tools/fixtures/iso.py.
-- archive/iso tests (and containers/Iso9660) against xorriso, genisoimage and pycdlib (tools/fixtures/iso.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Iso = require("@rosetta/archive/iso")
@@ -65,12 +60,10 @@ do
t:eq(p.format, "iso", "F.load")
t:eq(p.meta.iso.tree, "iso9660", "plain")
t:check(p.meta.iso.blockSize == 2048 and p.meta.iso.blocks > 0, "volume facts")
-- any Archive converts: iso -> tar
local tar = F.load(assert(F.save(jr, nil, { format = "tar" })))
t:eq(buffer.tostring(tar:read("hello.txt")), "hello, iso\n", "iso -> tar")
end
-- El Torito
do
local a = Iso.decode(Bytes.reader(buffer.fromstring(Fx.boot.data)))
local bt = a.meta.boot
@@ -83,7 +76,6 @@ do
t:check(bt.valid, "boot: validation entry checksum")
end
-- multi-extent and interleaved records
do
local a = Iso.decode(Bytes.reader(buffer.fromstring(Fx.multi.data)))
local n = 0
@@ -100,7 +92,6 @@ do
t:check(e and e.code == Err.UNSUPPORTED, "interleaved: " .. tostring(e))
end
-- errors
do
local good = Fx.images[1].data
local _, e1 = Iso.decode(Bytes.reader(buffer.fromstring(string.sub(good, 1, 20000))))
+1 -5
View File
@@ -1,8 +1,4 @@
-- archive/lha tests (and codecs/compress/Lzh): lhasa's test archives (LHarc lh1, LArc lzs / lz5 / lz4, LHA lh0 / lh5 /
-- lh6 / lh7 by many DOS / Amiga / OS-9 / Unix / Windows tools, header levels 0 / 1 / 2, subdirectories, symlinks, lh1 and
-- lz5 length tests up to 2 MB) and LHa for UNIX archives (-o5 / -o6 / -o7 / -z at levels 0 / 1 / 2) give the files lhasa
-- extracts (names, sizes, data CRCs) and its symlinks; our level-2 lh0 output extracts with lhasa (fixture step) and
-- round-trips; CRC and truncation errors; the fuzz pass. Fixtures: tools/fixtures/lha.py.
-- archive/lha tests (and codecs/compress/Lzh) against lhasa and LHa for UNIX (tools/fixtures/lha.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Lha = require("@rosetta/archive/lha")
+1 -7
View File
@@ -1,8 +1,4 @@
-- archive/lz4 tests (and codecs/compress/Xxh32): frames from the lz4 tool (default, linked blocks, 64 KB blocks, block
-- checksums, content size, no content checksum, HC, legacy), concatenated and skippable frames decode to their corpora;
-- our frames (every option set) decode with `lz4 -d` (verdicts from the fixture step) and round-trip; XXH32 test
-- vectors; checksum / size / truncation errors; the api (.tar.lz4 unwrap, naming); the fuzz pass.
-- Fixtures: tools/fixtures/lz4frame.py.
-- archive/lz4 tests (and codecs/compress/Xxh32) against the lz4 tool (tools/fixtures/lz4frame.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Lz4F = require("@rosetta/archive/lz4")
@@ -51,7 +47,6 @@ for name, data in C do
end
end
-- the api
do
local a = assert(F.load(Fx.cases[1].data, { name = "notes.txt.lz4" }))
t:check(a.meta.stream and a.format == "lz4", "single stream")
@@ -68,7 +63,6 @@ do
t:eq(buffer.tostring(F.load(s):read("data")), "some text", "a string")
end
-- errors
do
local good
for _, c in Fx.cases do
+1 -2
View File
@@ -1,5 +1,4 @@
-- archive/macbinary tests: the macbinary 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.
-- 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")
+1 -6
View File
@@ -1,7 +1,4 @@
-- archive/mpq tests: archives written by StormLib (tools/fixtures/mpq.py; header versions 1-4) list every file and
-- read back its exact bytes: zlib, PKWARE implode, bzip2, LZMA and sparse sectors, imploded files, single-unit,
-- stored, encrypted (plain and fix-key) and sector-CRC files; a prefixed archive; an archive without a listfile
-- (names by block index, opts.names); Huffman sectors are UNSUPPORTED; the hash helper; errors; the fuzz pass.
-- archive/mpq tests against StormLib (tools/fixtures/mpq.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Mpq = require("@rosetta/archive/mpq")
@@ -72,7 +69,6 @@ for _, c in Fx.archives do
t:note("%-9s v%d, %2d entries, %2d files checked", c.name, a.meta.source.version, #a:list(), ok)
end
-- errors
do
local c = Fx.archives[1]
local _, e1 = Mpq.decode(Bytes.reader(buffer.fromstring(string.sub(c.data, 1, 200))))
@@ -100,7 +96,6 @@ t:fuzz("decode", function(b: buffer)
return a
end, samples, { mutations = 60 })
do
-- mutations inside the file data (the tables intact)
local c = Fx.archives[1]
local rand = T.rng(5)
local threw = 0
+1 -5
View File
@@ -1,6 +1,4 @@
-- archive/pak tests: Quake ("PACK") and SiN ("SPAK") archives written by tools/fixtures/pak.py list the entries an
-- independent Python reader sees (names, sizes, data CRCs); our writer produces the same bytes as the Python writer
-- for the same files and round-trips; conversion from a tar; errors; the fuzz pass. Fixtures: tools/fixtures/pak.py.
-- archive/pak tests against an independent Python reader and writer (tools/fixtures/pak.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Pak = require("@rosetta/archive/pak")
@@ -38,12 +36,10 @@ for _, c in Fx do
end
local back = Pak.decode(Bytes.reader(out))
t:eq(#back:list(), #c.files, c.name .. ": round trip count")
-- rewriting a decoded archive keeps its variant
local again = F.save(a) :: buffer
t:eq(buffer.readstring(again, 0, 4), if c.variant == "sin" then "SPAK" else "PACK", c.name .. ": F.save keeps the variant")
end
-- a sub-range reader, conversion from another archive, errors
do
local c = Fx[1]
local big = buffer.create(#c.data + 7)
+1 -6
View File
@@ -1,7 +1,4 @@
-- archive/rpm tests: one package from rpmbuild with each payload compressor (gzip, bzip2, xz, lzma, zstd, none) gives
-- the header fields `rpm -qp --qf` prints, its file list (names, sizes, modes, mtimes, symlink targets; %ghost files
-- skipped), the file data rpm2cpio's stream holds (CRCs, hard links), and Rpm.cpio = rpm2cpio's bytes; errors; the
-- fuzz pass. Fixtures: tools/fixtures/rpm.py.
-- archive/rpm tests against rpm -qp and rpm2cpio (tools/fixtures/rpm.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Rpm = require("@rosetta/archive/rpm")
@@ -48,7 +45,6 @@ for _, c in Fx.rpms do
end
end
t:eq(#a:list(), n, c.name .. ": entry count")
-- hard links: both read the same bytes
t:eq(buffer.tostring(a:read("usr/bin/hello")), "#!/bin/sh\necho hello\n", c.name .. ": hard link (first)")
t:eq(buffer.tostring(a:read("usr/bin/hello2")), "#!/bin/sh\necho hello\n", c.name .. ": hard link (second)")
local raw = Rpm.cpio(Bytes.reader(buffer.fromstring(c.data)))
@@ -67,7 +63,6 @@ do
t:check(e, "rpm is read-only")
end
-- errors
do
local good = Fx.rpms[1].data
local _, e1 = Rpm.decode(Bytes.reader(buffer.fromstring(string.sub(good, 1, 50))))
+2 -11
View File
@@ -1,8 +1,4 @@
-- archive/tar tests: archives from Python's tarfile (ustar / GNU / pax) and GNU tar (ustar / gnu / posix / v7) list
-- the same entries as tarfile reads (names, types, sizes, links, mtimes, modes, data CRCs); the writer produces the same
-- bytes as tarfile for the same entries in all three formats and round-trips; Archive values (add / read / write,
-- conversion of a gzip / any archive to tar); .tar.gz / .tgz / .tar.bz2 / .tar.xz / .tar.zst / .tar.br load through the
-- api as the tar inside; errors; the fuzz pass. Fixtures: tools/fixtures/tar.py.
-- archive/tar tests against Python's tarfile and GNU tar (tools/fixtures/tar.py).
local T = require("@tests/T")
local F = require("@rosetta")
local TarF = require("@rosetta/archive/tar")
@@ -38,7 +34,6 @@ local function check(a: any, want: any, label: string)
end
end
-- 1. reading
for _, c in Fx.tars do
local a, err = TarF.decode(Bytes.reader(buffer.fromstring(c.data)))
t:check(a, c.name .. ": " .. tostring(err))
@@ -47,7 +42,7 @@ for _, c in Fx.tars do
t:note("%-18s %2d entries", c.name, #c.entries)
end
-- 2. writing: byte-identical to Python's tarfile (which pads to 10240-byte records)
-- byte-identical to Python's tarfile (which pads to 10240-byte records)
for _, w in Fx.writes do
local list = {}
for _, e in w.entries do
@@ -83,7 +78,6 @@ for _, w in Fx.writes do
end
end
-- 3. Archive values: add / read / write, other archives to tar
do
local a = TarF.new()
a:add("a.txt", "alpha", { mtime = 5 })
@@ -98,7 +92,6 @@ do
t:check(back:list()[2].dir, "directory entry")
local _, e = back:read("missing")
t:check(e and e.code == Err.ARG, "missing entry")
-- a gzip (single-stream archive) converts to a tar holding its one entry
local g = F.load(Fx.gzips[1].data)
local tb = F.save(g, nil, { format = "tar" })
local ta = F.load(tb)
@@ -106,7 +99,6 @@ do
t:eq(ta:list()[1].size, Fx.gzips[1].size, "gzip -> tar entry size")
end
-- 4. compressed tars through the api
for _, w in Fx.wrapped do
local a, err = F.load(w.data, { name = w.name })
t:check(a, w.name .. ": " .. tostring(err))
@@ -118,7 +110,6 @@ for _, w in Fx.wrapped do
t:eq(outer:list()[1].name, "a.tar", w.name .. ": inner entry named after the file")
end
-- 5. errors
do
local good = Fx.tars[1].data
local b = buffer.fromstring(good)
+1 -5
View File
@@ -1,7 +1,4 @@
-- 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.
-- archive/uu tests against GNU uuencode, uuenview and uudeview (tools/fixtures/uu.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Uu = require("@rosetta/archive/uu")
@@ -53,7 +50,6 @@ 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
+1 -9
View File
@@ -1,7 +1,4 @@
-- archive/vpk tests: version 1 and 2 directory files written by Python's vpk package list the entries it reads back
-- (names, sizes, CRC-32s); a multi-part archive (part files through opts.files and opts.resolve, preload bytes, an
-- embedded entry); our writer's version 1 / 2 output read back by the vpk package (MD5 verify for version 2) and by
-- us; CRC checks; errors; the fuzz pass. Fixtures: tools/fixtures/vpk.py.
-- archive/vpk tests against Python's vpk package (tools/fixtures/vpk.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Vpk = require("@rosetta/archive/vpk")
@@ -32,7 +29,6 @@ local function check(a: any, want: { any }, label: string)
end
end
-- 1. Python's vpk package
for _, c in Fx.cases do
local a, err = Vpk.decode(Bytes.reader(buffer.fromstring(c.data)))
t:check(a, c.name .. ": " .. tostring(err))
@@ -44,7 +40,6 @@ for _, c in Fx.cases do
end
end
-- 2. multi-part
do
local m = Fx.multi
local a = Vpk.decode(Bytes.reader(buffer.fromstring(m.dir)), { files = m.parts, name = "maps/pak01_dir.vpk" })
@@ -63,12 +58,10 @@ do
local _, e = c:read("materials/a.vmt")
t:check(e and e.code == Err.UNSUPPORTED, "missing part: " .. tostring(e))
t:eq(buffer.tostring((c:read("root.txt"))), "embedded", "embedded entry without the parts")
-- multi-part -> single file
local one = F.load(F.save(b) :: buffer)
check(one, m.entries, "multi -> one directory file")
end
-- 3. our writer, read back by the vpk package and by us
for k, v in Fx.ours do
t:check(v.ok, k .. ": the vpk package verifies our MD5s")
t:eq(#v.entries, #Fx.want, k .. ": the vpk package lists every entry")
@@ -83,7 +76,6 @@ for k, v in Fx.ours do
check(Vpk.decode(Bytes.reader(a:write() :: buffer)), Fx.want, k .. ": round trip")
end
-- 4. errors
do
local c = Fx.cases[2]
local bad = buffer.fromstring(c.data)
+1 -14
View File
@@ -1,9 +1,4 @@
-- archive/wad tests: a cut-down Freedoom IWAD (tools/fixtures/wad.py) lists its lumps (names, sizes, data CRCs,
-- namespaces, map lumps as "MAP01/THINGS"); every flat, patch, sprite and graphic decodes to the pixels DeuTex
-- extracts (RGBA CRC, offsets); composed wall textures; MAP01 parses to the counts of an independent parse and its
-- Scene's floor area matches Green's theorem over the sectors' sides; a hand-made room with a pillar (exact areas,
-- walls, things on floors), a UDMF stub, duplicate names, a tall patch; the writer round-trips byte for byte;
-- errors; the fuzz pass. Fixtures: tools/fixtures/wad.py.
-- archive/wad tests: a cut-down Freedoom IWAD against DeuTex, map floor areas by Green's theorem (tools/fixtures/wad.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Wad = require("@rosetta/archive/wad")
@@ -22,7 +17,6 @@ t:check(a, "freedoom: " .. tostring(err))
t:eq(F.detect(fd.data), "wad", "F.detect")
t:eq(a.meta.source.type, "IWAD", "IWAD")
-- 1. lumps
do
local lumps = Wad.lumps(a) :: { Wad.Lump }
t:eq(#lumps, #fd.lumps, "lump count")
@@ -46,7 +40,6 @@ do
t:eq(#Wad.maps(a), 1, "one map")
end
-- 2. images against DeuTex
do
local n = 0
for _, w in fd.images do
@@ -74,7 +67,6 @@ do
end
end
-- 3. MAP01
do
local m = Wad.mapData(a, "MAP01") :: any
local r = fd.map
@@ -116,7 +108,6 @@ do
t:check(lean.textures[1].image == nil and lean.textures[1].uri ~= nil, "textures = false")
end
-- 4. the hand-made room
do
local rm = Wad.decode(Bytes.reader(buffer.fromstring(Fx.room.data)))
t:check(rm, "room decodes")
@@ -170,7 +161,6 @@ do
t:check(buffer.tostring(F.save(rm) :: buffer) == Fx.room.data, "room: decode + save is byte-identical")
end
-- 5. writer
do
t:check(buffer.tostring(F.save(a) :: buffer) == fd.data, "freedoom: decode + save is byte-identical")
local p = Wad.new()
@@ -188,7 +178,6 @@ do
t:eq(Wad.lumps(F.load(F.save(zip, nil, { format = "wad" }) :: buffer))[1].name, "X.LMP", "zip -> wad")
end
-- 6. errors
do
local _, e1 = Wad.decode(Bytes.reader(buffer.fromstring(string.sub(fd.data, 1, 100))))
t:check(e1 and e1.code == Err.TRUNCATED, "truncated: " .. tostring(e1))
@@ -200,7 +189,6 @@ do
t:check(e4 and e4.code == Err.ARG, "missing map")
end
-- 7. fuzz: the directory, then the lumps of the room (maps, pictures)
t:fuzz("decode", function(b: buffer)
local w = Wad.decode(Bytes.reader(b))
if w then
@@ -217,7 +205,6 @@ t:fuzz("decode", function(b: buffer)
return w
end, { Fx.room.data }, { mutations = 300 })
do
-- mutate inside the lumps of the real map and pictures (the directory kept intact)
local rand = T.rng(9)
local threw = 0
for i = 1, 60 do
+1 -6
View File
@@ -1,6 +1,4 @@
-- archive/xz tests: the contract, sniffing (.xz magic, conservative .lzma), every xz / .lzma fixture of
-- tools/fixtures/lzma.py read as a one-entry archive (entry names from opts.name), F.load through the registry, errors,
-- and the fuzz no-throw pass.
-- archive/xz tests (tools/fixtures/lzma.py).
local T = require("@tests/T")
local Xz = require("@rosetta/archive/xz")
local F = require("@rosetta")
@@ -37,12 +35,10 @@ for _, c in Fx.cases do
end
t:note("%d xz / lzma files", n)
-- sniff: not xz
t:eq(Xz.sniff(reader("PK\3\4 hello")), 0, "zip is not xz")
t:eq(Xz.sniff(reader("")), 0, "empty")
t:eq(Xz.sniff(reader(string.rep("\0", 40))), 0, "zeros are not .lzma")
-- through the api
do
local c = Fx.cases[1]
for _, x in Fx.cases do
@@ -62,7 +58,6 @@ do
t:check(e3 and e3.code == Err.TRUNCATED, "truncated: " .. tostring(e3))
end
-- fuzz
do
local samples = {}
for i, c in Fx.cases do
+1 -5
View File
@@ -1,7 +1,4 @@
-- archive/yenc tests: single-part files by uuenview -y (including every byte value and the critical characters), a
-- multi-part posting in order and reversed, two files in one text; part / file CRC and size checks; an incomplete
-- posting; our output decodes with uudeview (fixture step) and round-trips; errors; the fuzz pass.
-- Fixtures: tools/fixtures/yenc.py.
-- 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")
@@ -34,7 +31,6 @@ E.roundTrip(t, Yenc, { line = 7 }, "round trip, 7-character lines")
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")
-- errors
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)))
+1 -5
View File
@@ -1,6 +1,4 @@
-- archive/z tests: .Z files from ncompress load as single-stream archives (entry names from the file name, .taz -> .tar),
-- a .tar.Z unwraps to the tar through the api, writing gives ncompress's bytes (a buffer, a one-entry Archive) and a
-- tar inside for several entries, conversions, errors, the fuzz pass. Fixtures: tools/fixtures/z.py.
-- archive/z tests against ncompress (tools/fixtures/z.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Z = require("@rosetta/archive/z")
@@ -37,7 +35,6 @@ do
t:eq(outer:list()[1].name, "src.tar", "unwrap = false")
end
-- writing
do
local out = assert(F.save(text.input, nil, { format = "z" }))
t:check(buffer.tostring(out) == text.z, "a string: ncompress's bytes")
@@ -54,7 +51,6 @@ do
t:check(buffer.tostring(b10) == Fx.cases[6].z, "maxBits option")
end
-- errors
do
local _, e1 = Z.decode(Bytes.reader(buffer.fromstring("\31\157")))
t:check(e1 and e1.code == Err.TRUNCATED, "short")
+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
+1 -3
View File
@@ -1,6 +1,4 @@
-- archive/zoo tests: zoo archives assembled by tools/fixtures/zoo.py (type 1 / type 2 entries, long and directory
-- names, a deleted entry, methods stored / LZW / lzh, an LZW stream with table resets) give the files The Unarchiver
-- extracts (names, sizes, data CRCs); CRC errors; the fuzz pass. Fixtures: tools/fixtures/zoo.py.
-- archive/zoo tests against The Unarchiver (tools/fixtures/zoo.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Zoo = require("@rosetta/archive/zoo")
+1 -9
View File
@@ -1,6 +1,4 @@
-- archive/zst tests: the contract, sniff (zstd and skippable-frame magic), decode of zstd CLI output into a one-entry
-- single-stream archive (entry name from opts.name, size, read), F.load detection by content, read-only errors, and
-- the fuzz no-throw pass. Fixtures: tools/fixtures/zstd.py (shared with tests/codecs/zstd.luau).
-- archive/zst tests (tools/fixtures/zstd.py, shared with tests/codecs/zstd.luau).
local T = require("@tests/T")
local F = require("@rosetta")
local Zst = require("@rosetta/archive/zst")
@@ -10,7 +8,6 @@ local Fx = require("@tests/gen/zstd")
local t = T.suite("zst")
-- contract
t:eq(Zst.name, "zst", "name")
t:eq(Zst.category, "archive", "category")
t:check(Zst.caps.decode and not Zst.caps.encode, "caps")
@@ -24,13 +21,11 @@ local function case(name: string): any
error("no case " .. name)
end
-- sniff
t:eq(Zst.sniff(Bytes.reader(buffer.fromstring(case("text/l3").data))), 1, "sniff zstd")
t:eq(Zst.sniff(Bytes.reader(buffer.fromstring(case("skipfirst/frames").data))), 0.5, "sniff skippable frame")
t:eq(Zst.sniff(Bytes.reader(buffer.fromstring("PK\3\4"))), 0, "sniff other")
t:eq(Zst.sniff(Bytes.reader(buffer.create(0))), 0, "sniff empty")
-- decode: one entry, named after the file
for _, name in { "text/l3", "runs/ultra22", "multi/frames", "empty/l3", "big/l19" } do
local c = case(name)
local a, err = Zst.decode(Bytes.reader(buffer.fromstring(c.data)), { name = "dir/notes.txt.zst" })
@@ -54,14 +49,12 @@ do
t:check(e and e.code == Err.ARG, "missing entry")
local _, we = a:write()
t:check(we and we.code == Err.UNSUPPORTED, "read-only: " .. tostring(we))
-- inside a bigger buffer (the reader's range)
local big = buffer.create(#c.data + 10)
buffer.writestring(big, 5, c.data)
local a3 = Zst.decode(Bytes.reader(big, 5, #c.data)) :: any
t:check(a3 and buffer.tostring(a3:read("data")) == Fx.corpora.short, "reader range")
end
-- the api: detection by content, the name from opts
do
local c = case("text/l5")
local a, err = F.load(c.data, { name = "x/readme.md.zst" })
@@ -74,7 +67,6 @@ do
t:check(se and se.code == Err.UNSUPPORTED, "no encoder")
end
-- fuzz
do
local samples = {}
for i, c in Fx.cases do