From e0ab8950272f22dd37f3b195bb0b33da59b4616f Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:49:12 -0500 Subject: [PATCH 01/25] tests: top-level test comments: specs only --- tests/T.luau | 19 ++----------------- tests/api.luau | 8 +------- tests/compat.luau | 15 +-------------- 3 files changed, 4 insertions(+), 38 deletions(-) diff --git a/tests/T.luau b/tests/T.luau index b92063e..84d2fcc 100644 --- a/tests/T.luau +++ b/tests/T.luau @@ -1,18 +1,9 @@ --!strict --- tests/T: the test helper every tests/**/*.luau uses, under both runtimes (luau --codegen -O2 and LuaJIT through the --- build). A failed check throws, so the runner (tools/test.sh) sees a non-zero exit. --- --- local T = require("@tests/T") --- local t = T.suite("png") --- t:check(cond, "label") -- truthy --- t:eq(got, want, "label") -- ==, with both values in the message --- t:fuzz("decode", function(b) return Png.decode(Bytes.reader(b)) end, samples) -- the no-throw pass --- t:done() -- prints "png: 123 checks passed (luajit)" +-- tests/T: the test helper; a failed check throws, so tools/test.sh sees a non-zero exit. local T = {} T.runtime = if (_G :: any).jit ~= nil then "luajit" else "luau" --- deterministic LCG (the same numbers on both runtimes): rand(n) -> 0 .. n - 1 function T.rng(seed: number): (n: number) -> number local s = seed % 2147483648 return function(n: number): number @@ -21,7 +12,6 @@ function T.rng(seed: number): (n: number) -> number end end --- bytes({ 1, 2, 3 }) -> buffer function T.bytes(t: { number }): buffer local b = buffer.create(#t) for i, v in t do @@ -30,7 +20,6 @@ function T.bytes(t: { number }): buffer return b end --- hex(buf, max?) -> "89 50 4e 47 ..." function T.hex(b: buffer, max: number?): string local n = math.min(buffer.len(b), max or 64) local out = table.create(n) @@ -40,7 +29,6 @@ function T.hex(b: buffer, max: number?): string return table.concat(out, " ") .. (if buffer.len(b) > n then " ..." else "") end --- clock() -> seconds (os.clock on both runtimes) function T.clock(): number return os.clock() end @@ -68,14 +56,11 @@ function Suite.eq(self: Suite, got: any, want: any, label: string) self.passed += 1 end --- note(fmt, ...): an indented progress line function Suite.note(_self: Suite, fmt: string, ...: any) print(" " .. string.format(fmt, ...)) end --- fuzz(label, decode, samples, opts?): the no-throw pass every format test runs. For each sample (buffer or string): --- truncations at several cuts, opts.mutations (default 8) copies with 1..4 random bytes changed, plus --- opts.garbage (default 200) random buffers. decode(buf) may return anything except throw. Returns the counts. +-- the no-throw pass: truncations, opts.mutations (default 8) random byte changes, opts.garbage (default 200) random buffers. function Suite.fuzz(self: Suite, label: string, decode: (buffer) -> any, samples: { any }, opts: { mutations: number?, garbage: number?, seed: number?, keepHeader: number? }?): (number, number) local o: { mutations: number?, garbage: number?, seed: number?, keepHeader: number? } = opts or {} local rand = T.rng(o.seed or 1234) diff --git a/tests/api.luau b/tests/api.luau index a88ae24..fd881d7 100644 --- a/tests/api.luau +++ b/tests/api.luau @@ -1,6 +1,4 @@ --- API tests (src/Rosetta/init.luau): load / save / saveString / convert / open / detect / formats / format, the --- category facades, sniff-then-extension detection, errors as Err values (never a throw), and file paths on hosts with --- a file system (LuaJIT: a temporary file; the luau CLI has none). +-- API tests: load / save / convert / open / detect, the category facades, errors as values, file paths. local T = require("@tests/T") local F = require("@rosetta") local Err = require("@rosetta/core/Err") @@ -15,10 +13,8 @@ local function image(w: number, h: number): any return img end --- host t:eq(F.host.name, if T.runtime == "luajit" then "luajit" else "luau", "host detected") --- formats() do local all = F.formats() t:check(#all >= 1, "formats() lists the registry") @@ -57,7 +53,6 @@ do t:eq(F.detect(buf), "png", "detect") local conv = F.convert(s, "png", { level = 1 }) t:check(conv and F.load(conv).width == 7, "convert") - -- format options reach the encoder local stored = F.save(img, nil, { format = "png", level = 0 }) :: buffer t:check(buffer.len(stored) > buffer.len(buf :: buffer), "opts.level reaches the encoder") end @@ -116,7 +111,6 @@ else t:check(e2 and e2.code == Err.IO, "no file system: load of a path is Err.IO") end --- Types constructors do local T2 = F.Types t:eq(buffer.len(T2.Image.new(3, 2, "rgb8").pixels), 18, "Image.new rgb8") diff --git a/tests/compat.luau b/tests/compat.luau index bfba55a..82eea17 100644 --- a/tests/compat.luau +++ b/tests/compat.luau @@ -1,12 +1,8 @@ --- compat tests: the Luau semantics the library relies on, checked under both runtimes. Under luau these pin down what --- Luau does; under LuaJIT they check compat/luajit.lua (bit32, buffer, table / math / string / utf8 additions, typeof) --- and tools/build.py's lowering (generalized iteration, if-expression chains, continue, compound assignment, string --- interpolation, floor division, number literals). +-- compat tests: the Luau semantics the library relies on, under luau and under LuaJIT (compat/luajit.lua + build.py lowering). local T = require("@tests/T") local t = T.suite("compat") --- ------------------------------------------------------------------------------------------------ bit32 do t:eq(bit32.band(0xFFFFFFFF, 0x0F0F0F0F), 0x0F0F0F0F, "band unsigned") t:eq(bit32.band(-1), 0xFFFFFFFF, "band(-1)") @@ -46,7 +42,6 @@ do t:check(bit32.btest(6, 2) and not bit32.btest(4, 2), "btest") end --- ------------------------------------------------------------------------------------------------ buffer do local b = buffer.create(16) t:eq(buffer.len(b), 16, "len") @@ -92,7 +87,6 @@ do t:check(not pcall(buffer.readstring, b, 10, 7), "readstring past the end throws") t:check(not pcall(buffer.copy, b, 10, b, 0, 7), "copy past the end throws") t:check(not pcall(buffer.fill, b, 10, 0, 7), "fill past the end throws") - -- strings, NULs, copy, fill local s = buffer.fromstring("a\0b\255c") t:eq(buffer.len(s), 5, "fromstring with NUL") t:eq(buffer.tostring(s), "a\0b\255c", "tostring with NUL") @@ -112,7 +106,6 @@ do t:eq(buffer.tostring(c), "ABBA", "fill value wraps") t:eq(buffer.len(buffer.create(0)), 0, "empty buffer") t:eq(buffer.tostring(buffer.create(0)), "", "empty tostring") - -- readbits / writebits local bb = buffer.create(8) buffer.writeu32(bb, 0, 0xDEADBEEF) t:eq(buffer.readbits(bb, 4, 12), 3054, "readbits") @@ -130,7 +123,6 @@ do t:eq(buffer.readu8(big, 500000), 0, "big buffer zero-filled") end --- ------------------------------------------------------------------------------------------------ typeof / type do local b = buffer.create(1) t:eq(typeof(b), "buffer", "typeof buffer") @@ -141,7 +133,6 @@ do t:eq(typeof("s"), "string", "typeof string") end --- ------------------------------------------------------------------------------------------------ table / math / string do local c = table.create(3, 7) t:eq(#c, 3, "table.create size") @@ -177,7 +168,6 @@ do t:eq(math.floor(-3.5), -4, "floor") end --- ------------------------------------------------------------------------------------------------ utf8 do t:eq(utf8.char(72, 228, 8364, 128512), "H\xC3\xA4\xE2\x82\xAC\xF0\x9F\x98\x80", "utf8.char") t:eq(utf8.len("h\xC3\xA4ll\xE2\x82\xAC"), 5, "utf8.len") @@ -193,9 +183,7 @@ do t:check(string.find("\xC3\xA4", utf8.charpattern) == 1, "utf8.charpattern") end --- ------------------------------------------------------------------------------------------------ syntax lowering do - -- generalized iteration: arrays (in order), dictionaries, mixed, iterator functions, nested local order = {} for i, v in { 10, 20, 30 } do table.insert(order, i * 100 + v) @@ -253,7 +241,6 @@ do local v = 5 local arith = if v > 3 then v * 2 else v - 1 t:eq(arith, 10, "if-expression arithmetic") - -- continue, compound assignment, interpolation, floor division, literals local odd = 0 for i = 1, 10 do if i % 2 == 0 then From 928ac9b39f1f187bcf5903e478e1c7a34aaadf15 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:49:12 -0500 Subject: [PATCH 02/25] tests/playlist, tests/subtitle: comments: specs only --- tests/playlist/m3u.luau | 19 +++---------------- tests/playlist/pls.luau | 8 ++------ tests/playlist/xspf.luau | 8 +------- tests/subtitle/ass.luau | 5 +---- tests/subtitle/srt.luau | 8 +------- tests/subtitle/vtt.luau | 6 ++---- 6 files changed, 10 insertions(+), 44 deletions(-) diff --git a/tests/playlist/m3u.luau b/tests/playlist/m3u.luau index 7548608..44988de 100644 --- a/tests/playlist/m3u.luau +++ b/tests/playlist/m3u.luau @@ -1,8 +1,5 @@ --- playlist/m3u tests (+ the PLS parts of the ported suite): M3U / M3U8 (EXTINF, comments, BOM, CRLF / CR, --- Windows-1252, relative / absolute / local locations), PLS, HLS master and media playlists, detection, serialize round --- trips, bad input; Python-written playlists (tools/fixtures/playlist.py) decode to their entries, and our M3U8 output --- decodes back; the api; the fuzz pass. Ported from playlist-luau tests/playlist.luau. Fixtures: --- tools/fixtures/playlist.py. +-- playlist/m3u tests: M3U / M3U8, PLS, HLS master and media playlists, against Python-written playlists. +-- Fixtures: tools/fixtures/playlist.py. local T = require("@tests/T") local M3u = require("@rosetta/playlist/m3u") local Pls = require("@rosetta/playlist/pls") @@ -23,7 +20,6 @@ local function has(list: { string }, pattern: string): boolean return false end --- the playlist-luau API on top of the two formats (the ported tests below use it) local Playlist = {} function Playlist.detect(text: string): string if type(text) ~= "string" then @@ -42,7 +38,7 @@ function Playlist.parse(text: any, baseUrl: string?): any local kind = Playlist.detect(text) local mod = if kind == "pls" then Pls else M3u local pl = mod.decode(Bytes.reader(buffer.fromstring(text)), { baseUrl = baseUrl }) :: any - pl.kind = pl.format -- the old field + pl.kind = pl.format return pl end function Playlist.serialize(entries: any, opts: any?): string @@ -102,7 +98,6 @@ do eq(pl3.entries[1].url, "C:\\Music\\a.mp3", "windows base") eq(pl3.entries[2].url, "C:\\Music\\sub\\b.mp3", "windows base sub") eq(pl3.entries[1].playable, false, "windows base unplayable") - -- file: base local pl4 = Playlist.parse("a.mp3", "file:///C:/Music/list.m3u") eq(pl4.entries[1].url, "file:///C:/Music/a.mp3", "file base") eq(pl4.entries[1].reason, "local path", "file base local") @@ -123,7 +118,6 @@ do eq(pl3.entries[1].url, "http://x/Bj%C3%B6rk.mp3", "utf-8 url encoded") end --- PLS do local text = "[playlist]\r\nNumberOfEntries=3\r\nFile2=http://s.example:8000/live\r\nTitle2=(#1) Some Radio\r\nLength2=-1\r\n" .. "File1=music/a.mp3\r\nTitle1=Artist - Song\r\nLength1=200\r\n; comment\r\nfile10 = http://x/z.mp3\r\nVersion=2\r\n" @@ -235,7 +229,6 @@ do eq(none.entries[1].playable, true, "METHOD=NONE is clear") end --- detection do eq(Playlist.detect("[playlist]\nFile1=a"), "pls", "detect pls") eq(Playlist.detect("\239\187\191 [PLAYLIST]\r\n"), "pls", "detect pls with BOM / spaces") @@ -245,7 +238,6 @@ do eq(Playlist.detect("a.mp3"), "m3u", "detect plain") end --- serialize: M3U8, round trip do local entries = { { url = "http://x/a.mp3", title = "A - B", duration = 61.6 }, @@ -265,7 +257,6 @@ do eq(back.entries[2].title, nil, "round trip no title") eq(back.entries[3].duration, nil, "round trip unknown duration") eq(Playlist.serialize({}), "#EXTM3U\n", "serialize empty") - -- parse -> serialize -> parse keeps everything of a real playlist local pl = Playlist.parse("#EXTM3U\n#EXTINF:100,X - Y\nhttp://h/1.mp3\n#EXTINF:-1,Live\nhttp://h/live\n") local again = Playlist.parse(Playlist.serialize(pl.entries)) for i, e in pl.entries do @@ -275,7 +266,6 @@ do end end --- bad input never throws do local inputs: { any } = { "", "\n\n\n", "#EXTM3U", "#EXTINF:abc,\n", "[playlist]\n=\nFile=\nFilex1=y", "#EXT-X-STREAM-INF:\n", "#EXT-X-STREAM-INF:BANDWIDTH=\"unterminated\n", "#EXT-X-BYTERANGE:x\n#EXT-X-TARGETDURATION:\n", "\255\254\0\0", 42, nil } @@ -288,7 +278,6 @@ do eq(has(Playlist.parse(42 :: any).warnings, "expected a string"), true, "non-string warning") local ok = pcall(Playlist.serialize, { 1, "x", { url = 5 } } :: any) eq(ok, true, "serialize skips junk") - -- random bytes local state = 7 for _ = 1, 300 do local t = table.create(80) @@ -305,7 +294,6 @@ do end --- Python-written playlists for _, c in Cases do local pl = M3u.decode(Bytes.reader(buffer.fromstring(c.m3u))) :: any eq(#pl.entries, #c.entries, c.name .. ": entries") @@ -326,7 +314,6 @@ for _, c in Cases do end t:note("%d Python-written M3U8 files decode to their entries", #Cases) --- the contract and the api do eq(M3u.name, "m3u", "name") eq(M3u.category, "playlist", "category") diff --git a/tests/playlist/pls.luau b/tests/playlist/pls.luau index 3b1a112..df8e6ed 100644 --- a/tests/playlist/pls.luau +++ b/tests/playlist/pls.luau @@ -1,7 +1,5 @@ --- playlist/pls tests: Python-written PLS files (tools/fixtures/playlist.py) decode to their entries; keys in any case --- and order, gaps in the numbering, comments, NumberOfEntries mismatches, Windows-1252, relative locations; the --- writer round-trips (titles, unknown lengths, line breaks); the api; the fuzz pass. (The playlist-luau PLS cases run --- in tests/playlist/m3u.luau.) Fixtures: tools/fixtures/playlist.py. +-- playlist/pls tests: Python-written PLS files decode to their entries; writer round trips. +-- Fixtures: tools/fixtures/playlist.py. local T = require("@tests/T") local Pls = require("@rosetta/playlist/pls") local Bytes = require("@rosetta/core/Bytes") @@ -44,13 +42,11 @@ do t:eq(cp.entries[1].title, "Bj\u{f6}rk", "Windows-1252 text") local loc = decode("[playlist]\nFile1=C:\\Music\\a.mp3\nNumberOfEntries=1\n") t:check(not loc.entries[1].playable and loc.entries[1].reason == "local path", "local path") - -- the writer local out = buffer.tostring(Pls.encode({ { url = "http://a/1.mp3", title = "One\nTwo", duration = 61.6 }, { url = "http://a/2.mp3" }, { url = 5 } } :: any) :: buffer) t:eq(out, "[playlist]\nFile1=http://a/1.mp3\nTitle1=One Two\nLength1=62\nFile2=http://a/2.mp3\nLength2=-1\nNumberOfEntries=2\nVersion=2\n", "writer output") t:check(select(2, Pls.encode(5 :: any)) ~= nil, "encode a number") t:eq(Pls.sniff(Bytes.reader(buffer.fromstring("\239\187\191 [playlist]\r\nFile1=a"))), 0.95, "sniff") t:eq(Pls.sniff(Bytes.reader(buffer.fromstring("#EXTM3U"))), 0, "sniff m3u") - -- the api t:eq(F.detect(Cases[1].pls), "pls", "F.detect") local a = F.playlist.load(Cases[1].pls) t:check(a and a.format == "pls", "F.playlist.load") diff --git a/tests/playlist/xspf.luau b/tests/playlist/xspf.luau index 7dfa21e..4933715 100644 --- a/tests/playlist/xspf.luau +++ b/tests/playlist/xspf.luau @@ -1,7 +1,4 @@ --- playlist/xspf tests: XSPF files written by Python's xml.etree.ElementTree (tools/fixtures/playlist.py) decode to --- their entries; every track field, multiple locations, xml:base, relative / local locations, a prefixed namespace; --- the writer round-trips (and escapes; its output was also checked by hand with ElementTree); errors (malformed XML, --- another root); the api; the fuzz pass. +-- playlist/xspf tests: XSPF files written by Python's xml.etree.ElementTree decode to their entries. -- Fixtures: tools/fixtures/playlist.py. local T = require("@tests/T") local Xspf = require("@rosetta/playlist/xspf") @@ -57,12 +54,10 @@ do t:eq(pl.entries[2].url, "http://other.example/b.mp3", "xml:base on a track") t:check(not pl.entries[3].playable and pl.entries[3].reason == "local path", "local path") t:check(#pl.warnings >= 2, "warnings for the missing location and the local path") - -- writer: escaping, extra fields, a plain entry list local out = buffer.tostring(Xspf.encode({ { url = "http://x/a?b=1&c=2", title = "", duration = 2.5, creator = "C" } } :: any) :: buffer) t:check(string.find(out, "http://x/a?b=1&c=2", 1, true) ~= nil and string.find(out, "<A & B>", 1, true) ~= nil, "escaping") local back = decode(out) t:check(back.entries[1].url == "http://x/a?b=1&c=2" and back.entries[1].title == "" and back.entries[1].duration == 2.5 and back.entries[1].creator == "C", "writer round trip") - -- errors local _, e1 = decode("") t:check(e1 and Err.is(e1), "malformed XML: " .. tostring(e1)) local _, e2 = decode("") @@ -70,7 +65,6 @@ do t:check(select(2, Xspf.encode(5 :: any)) ~= nil, "encode a number") t:eq(Xspf.sniff(Bytes.reader(buffer.fromstring(Cases[1].xspf))), 0.95, "sniff") t:eq(Xspf.sniff(Bytes.reader(buffer.fromstring(""))), 0, "sniff without the namespace") - -- the api t:eq(F.detect(Cases[1].xspf), "xspf", "F.detect") local la = F.playlist.load(Cases[1].xspf) t:check(la and la.format == "xspf" and #la.entries == #Cases[1].entries, "F.playlist.load") diff --git a/tests/subtitle/ass.luau b/tests/subtitle/ass.luau index 83ff1c1..d65032d 100644 --- a/tests/subtitle/ass.luau +++ b/tests/subtitle/ass.luau @@ -1,6 +1,4 @@ --- subtitle/ass tests: ffmpeg's ASS output of a random script (times to the centisecond, text through the override --- markup), hand-written ASS (styles, comments, commas in text, overrides, [Fonts]) and SSA v4 files against ffmpeg's --- SRT conversion of them, styles as data, round trips through the encoder, the contract and the fuzz pass. +-- subtitle/ass tests: ffmpeg's ASS output and hand-written ASS / SSA files against ffmpeg's SRT conversion. -- Fixtures: tools/fixtures/subtitles.py. local T = require("@tests/T") local Ass = require("@rosetta/subtitle/ass") @@ -87,7 +85,6 @@ for _, s in { a, ssa, subs } do end end t:eq(buffer.tostring(Ass.encode(a) :: buffer), Fx.hand[2].data, "hand ASS written back byte for byte") --- cues from another format: markup converted, a Default style made do local out = Ass.encode({ kind = "subtitles", cues = { { start = 1, stop = 2.5, text = "it and bold\nline x" } }, styles = {}, meta = {} } :: any) :: buffer local back = Ass.decode(Bytes.reader(out)) diff --git a/tests/subtitle/srt.luau b/tests/subtitle/srt.luau index 8f2c763..2371917 100644 --- a/tests/subtitle/srt.luau +++ b/tests/subtitle/srt.luau @@ -1,6 +1,4 @@ --- subtitle/srt tests: a random SRT script against ffmpeg (its own parse via its srt muxer: times to the millisecond, --- text), ffmpeg's conversions of WebVTT / ASS / SSA files to SRT, odd layouts (no index, blank lines in text, CRLF, --- BOM, dot decimals, coordinates), round trips through the encoder, the contract and the fuzz pass. +-- subtitle/srt tests: a random SRT script and ffmpeg's WebVTT / ASS / SSA conversions against ffmpeg. -- Fixtures: tools/fixtures/subtitles.py. local T = require("@tests/T") local Srt = require("@rosetta/subtitle/srt") @@ -35,7 +33,6 @@ t:eq(Srt.name, "srt", "name") t:eq(Srt.category, "subtitle", "category") t:check(Srt.caps.decode and Srt.caps.encode, "caps") --- the random script and ffmpeg's re-mux of it local subs, err = decode(Fx.srt) t:check(subs, "decode: " .. tostring(err)) same(subs, Fx.cues, "random") @@ -48,7 +45,6 @@ for _, h in Fx.hand do same(decode(h.ffmpeg_srt), h.cues, "ffmpeg " .. h.name .. " -> srt") end --- odd layouts do local s = "\239\187\1911\r\n00:00:01.5 --> 00:00:02,25 X1:10 X2:20 Y1:5 Y2:6\r\nfirst\r\n\r\nsecond paragraph\r\n\r\n\r\n00:00:03,000 --> 00:00:04,000\r\nno index\r\n2\r\n00:00:05,000-->00:00:06,000\r\n" local r = decode(s) @@ -66,7 +62,6 @@ do t:eq(again.cues[1].settings, r.cues[1].settings, "odd: round trip keeps the coordinates") end --- round trips (LF and CRLF) for _, crlf in { false, true } do local out = Srt.encode(subs, { crlf = crlf }) :: buffer local back = Srt.decode(Bytes.reader(out)) @@ -82,7 +77,6 @@ for _, crlf in { false, true } do end end --- errors do local _, e = decode("just some text\nno timings") t:check(e and e.code == Err.CORRUPT, "no cues: " .. tostring(e)) diff --git a/tests/subtitle/vtt.luau b/tests/subtitle/vtt.luau index 5c97aaa..b8ee62d 100644 --- a/tests/subtitle/vtt.luau +++ b/tests/subtitle/vtt.luau @@ -1,6 +1,5 @@ --- subtitle/vtt tests: ffmpeg's WebVTT output of a random script (times, text), a hand-written file with a header, --- STYLE / REGION / NOTE blocks, ids, settings and hour timestamps against ffmpeg's SRT conversion of it, round trips --- through the encoder, the contract and the fuzz pass. Fixtures: tools/fixtures/subtitles.py. +-- subtitle/vtt tests: ffmpeg's WebVTT output and a hand-written file against ffmpeg's SRT conversion. +-- Fixtures: tools/fixtures/subtitles.py. local T = require("@tests/T") local Vtt = require("@rosetta/subtitle/vtt") local Bytes = require("@rosetta/core/Bytes") @@ -76,7 +75,6 @@ do local back = decode(buffer.tostring(Vtt.encode(v) :: buffer)) t:eq(back.meta.css[1], v.meta.css[1], "rt css") t:eq(back.meta.regions[1], v.meta.regions[1], "rt region") - -- text that WebVTT cannot hold local w = Vtt.encode({ kind = "subtitles", cues = { { start = 0, stop = 1, text = "a\n\nb --> c" } }, styles = {}, meta = {} } :: any) :: buffer local wb = Vtt.decode(Bytes.reader(w)) t:eq(wb.cues[1].text, "a\nb --> c", "blank lines dropped, arrow escaped") From a07d4065a603a277339fbddda1e12dc448e7c521 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:49:17 -0500 Subject: [PATCH 03/25] tests/cad: comments: specs only --- tests/cad/step.luau | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/tests/cad/step.luau b/tests/cad/step.luau index 76c525a..21b7c19 100644 --- a/tests/cad/step.luau +++ b/tests/cad/step.luau @@ -1,9 +1,5 @@ --- cad/step tests: STEP files written by OCCT (solids modelled in gmsh's OpenCASCADE kernel) and public sample files, --- against an independent Python Part 21 census (instances, count per type); our writer's output read back by OCCT --- (solids, volume, faces, area, bounding box equal to the originals); parse -> write -> parse equality; every --- parameter kind and string escape, complex instances, edition 3 sections, comments; the api (F.load / F.save / --- F.cad.*); the B-rep plug-in path through brep-luau (luau CLI only: the alias in tests/gen/.luaurc) against OCCT's --- volumes and bounds, and a custom plug-in table; errors; the fuzz no-throw pass. Fixtures: tools/fixtures/step.py. +-- cad/step tests: OCCT-written and public STEP files against a Python Part 21 census, OCCT and brep-luau. +-- Fixtures: tools/fixtures/step.py. local T = require("@tests/T") local F = require("@rosetta") local Step = require("@rosetta/cad/step") @@ -25,12 +21,10 @@ local function near(a: number, b: number, rel: number): boolean return math.abs(a - b) <= rel * math.max(1, math.abs(a), math.abs(b)) end --- 1. contract t:eq(Step.name, "step", "name") t:eq(Step.category, "cad", "category") t:check(Step.caps.decode and Step.caps.encode and table.find(Step.extensions, "stp"), "contract") --- deep equality of two decoded values (buffers, the real marks of lists included) local function same(a: any, b: any, path: string, depth: number?): (boolean, string) local d = depth or 0 if type(a) ~= "table" or type(b) ~= "table" then @@ -69,7 +63,6 @@ local function same(a: any, b: any, path: string, depth: number?): (boolean, str return true, path end --- 2. fixtures: census, round trips; OCCT read our output like the original local decoded = {} local samples = {} local t0 = T.clock() @@ -111,7 +104,6 @@ end local dt = T.clock() - t0 t:note("%d files (%.1f MB): census, OCCT read-back, round trips (%.2f s)", #Cases, bytes / 1e6, dt) --- 3. every parameter kind, escapes, complex instances, sections, comments local CRAFT = [[ ISO-10303-21; /* a comment */ HEADER; @@ -212,7 +204,6 @@ t:check(string.find(e3text, "ANCHOR;\n = #1;\nENDSEC;", 1, local e3b = decode(e3text) t:check(e3b and same(e3.entities, e3b.entities, "e"), "ed3: round trip") --- 4. building a file local new = Step.new("AP242") local pt = Step.add(new, "cartesian_point", { "origin", Step.real({ 0, 0, 1.25 }, 1) }) Step.add(new, "VERTEX_POINT", { "", { ref = pt } }) @@ -231,7 +222,6 @@ t:eq(bad3 and bad3.code, Err.ARG, "encode: cycle -> ARG") local _, bad4 = Step.encode({ kind = "image" } :: any) t:eq(bad4 and bad4.code, Err.ARG, "encode: not a Cad") --- 5. errors and sniff local function code(s: string, opts: any?): string? local v, e = decode(s, opts) return if v then nil else e.code @@ -249,7 +239,6 @@ t:eq(Step.sniff(Bytes.reader(buffer.fromstring(CRAFT))), 1, "sniff") t:eq(Step.sniff(Bytes.reader(buffer.fromstring("\239\187\191/* x */ ISO-10303-21;"))), 1, "sniff: BOM + comment") t:eq(Step.sniff(Bytes.reader(buffer.fromstring("ISO-10303-28"))), 0, "sniff: other") --- 6. the api local loaded, lerr = F.load(CRAFT) t:check(loaded and loaded.kind == "cad", "F.load: " .. tostring(lerr)) t:eq(F.detect(CRAFT), "step", "F.detect") @@ -260,7 +249,6 @@ t:eq(nop and nop.code, Err.UNSUPPORTED, "toBodies without a plug-in") local _, nop2 = F.cad.tessellate(loaded) t:eq(nop2 and nop2.code, Err.UNSUPPORTED, "F.cad.tessellate without a plug-in") --- 7. the plug-in: a custom interface table local calls = {} local fake = { read = function(text: string, _opts: any): any @@ -296,7 +284,7 @@ local fapi = F.cad.tessellate(loaded) t:check(fapi and fapi.kind == "scene", "F.cad.tessellate through F.plugins") F.plugins.brep = nil --- 8. brep-luau (luau CLI: tests/gen/.luaurc aliases it; LuaJIT has no `vector` type: skipped) +-- brep-luau: luau CLI only (tests/gen/.luaurc aliases it); LuaJIT has no `vector` type local function volume(scene: any): (number, { number }) local v = 0 local lo, hi = { math.huge, math.huge, math.huge }, { -math.huge, -math.huge, -math.huge } @@ -364,7 +352,6 @@ if brepOk then end end end - -- kernel bodies -> our Cad -> our text -> bodies again local M = brep.M local part = brep.Boolean.subtract(brep.Build.box(M.v(0, 0, 0), M.v(40, 30, 5)), brep.Build.cylinder(M.v(20, 15, -1), 6, 7))[1] part.color = { r = 0.2, g = 0.5, b = 0.9 } @@ -383,7 +370,6 @@ else t:note("brep-luau plug-in part skipped (%s)", if T.runtime ~= "luau" then "LuaJIT: no vector type" else "no ~/dev/luau/brep-luau") end --- 9. fuzz table.insert(samples, buffer.fromstring(CRAFT)) table.insert(samples, buffer.fromstring(ED3)) t:fuzz("decode", function(b: buffer): any From 58b0df8b21c725847b1046de1ae6945b1c86e03d Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:49:17 -0500 Subject: [PATCH 04/25] tests/layered: comments: specs only --- tests/layered/aseprite.luau | 13 ++----------- tests/layered/ora.luau | 7 ++----- tests/layered/psd.luau | 18 ++++-------------- 3 files changed, 8 insertions(+), 30 deletions(-) diff --git a/tests/layered/aseprite.luau b/tests/layered/aseprite.luau index 27b2014..b816ba2 100644 --- a/tests/layered/aseprite.luau +++ b/tests/layered/aseprite.luau @@ -1,8 +1,5 @@ --- layered/aseprite tests: sprites written by tools/fixtures/aseprite.py (RGBA / grayscale / indexed; raw, zlib and --- linked cels; groups, hidden layers, blend modes, layer and cel opacity; old and new palettes; tags; user data) and --- by LibreSprite (re-saved and from a GIF): every cel's pixels and position, and our flatten of every frame against --- LibreSprite's rendering (PSNR); our encoder's sprite rendered by LibreSprite (tools/fixtures/_ours.luau); round --- trips (linked cels kept), the contract and the fuzz pass. Fixtures: tools/fixtures/aseprite.py. +-- layered/aseprite tests: generated and LibreSprite sprites, flatten against LibreSprite's rendering by PSNR. +-- Fixtures: tools/fixtures/aseprite.py. local T = require("@tests/T") local Ase = require("@rosetta/layered/aseprite") local LayerOps = require("@rosetta/ops/LayerOps") @@ -35,7 +32,6 @@ local function psnr(a: buffer, b: string): number end return 10 * math.log10(255 * 255 / (se / n)) end --- the n-th node (groups included, file order) of a frame's tree local function nodes(layers: { any }, out: { any }?): { any } local o = out or {} for _, l in layers do @@ -63,7 +59,6 @@ for _, c in Fx.cases do t:check(l and l.x == cel.x and l.y == cel.y and l.image.width == cel.w and l.image.height == cel.h, label .. ": position / size") t:eq(Crc32.of(l.image.pixels), cel.crc, label .. ": pixels") end - -- our flatten vs LibreSprite's rendering of each frame for fi, want in c.frames do local img = LayerOps.flatten(doc, { frame = fi }) :: any local p = psnr(img.pixels, want) @@ -75,7 +70,6 @@ for _, c in Fx.cases do table.insert(samples, c.data) end --- the hand-made RGBA sprite's details do local doc = decode(Fx.cases[1].data) local L = doc.layers @@ -101,7 +95,6 @@ do t:eq(#idx.meta.palette, 5, "old palette chunk") t:eq(idx.meta.colorDepth, 8, "indexed") - -- round trips: every frame's nodes and pixels, linked cels stay shared, depth kept for ci, c in Fx.cases do local d = decode(c.data) local out, eerr = Ase.encode(d) @@ -132,7 +125,6 @@ do end table.insert(samples, buffer.tostring(out :: buffer)) end - -- forced depths local _, e = Ase.encode(doc, { depth = 16 }) t:check(e and e.code == Err.ARG, "colour sprite as grayscale: " .. tostring(e)) local g = decode(Fx.cases[2].data) @@ -140,7 +132,6 @@ do t:eq(g32.meta.colorDepth, 32, "grayscale written as RGBA") end --- LibreSprite renders our encoder's sprite like our flatten does t:eq(#Ours.frames, Ours.nframes, "LibreSprite read every frame of our sprite") for fi, want in Ours.frames do local ours = Ours.ours[fi] diff --git a/tests/layered/ora.luau b/tests/layered/ora.luau index c70114b..6bc4c9e 100644 --- a/tests/layered/ora.luau +++ b/tests/layered/ora.luau @@ -1,7 +1,5 @@ --- layered/ora tests: OpenRaster files assembled by the spec (offsets, opacity, hidden, composite-ops, nested isolate / --- auto stacks, no merged image) against the attributes and pixels written there; our encoder's file taken apart by --- python (stored mimetype first, stack.xml, Pillow's read of every PNG); round trips; hooks; errors; the fuzz no-throw --- pass. Fixtures: tools/fixtures/ora.py. +-- layered/ora tests: spec-assembled OpenRaster files; our encoder's output checked by python and Pillow. +-- Fixtures: tools/fixtures/ora.py. local T = require("@tests/T") local Ora = require("@rosetta/layered/ora") local Png = require("@rosetta/image/png") @@ -67,7 +65,6 @@ for _, c in Fx.cases do if c.dpi then t:eq(doc.meta.dpi.x, c.dpi, c.name .. ": dpi") end - -- round trip local enc, eerr = Ora.encode(doc, hooks) t:check(enc, c.name .. ": encode " .. tostring(eerr)) local back = Ora.decode(Bytes.reader(enc :: buffer), hooks) diff --git a/tests/layered/psd.luau b/tests/layered/psd.luau index 5b45cb8..5b3ee11 100644 --- a/tests/layered/psd.luau +++ b/tests/layered/psd.luau @@ -1,8 +1,5 @@ --- layered/psd tests: PSD / PSB files of every colour mode and depth, compression, groups, pass-through, clipping, --- masks, fill opacity and blend mode (written by tools/fixtures/psd.py) plus an ImageMagick PSD, against psd-tools: --- the merged image and every layer's pixels exact (8-bit; 16 / 32-bit within rounding), our flatten (ops/LayerOps) --- against psd-tools' composite by PSNR; our encoder's PSD read back by psd-tools (tools/fixtures/_ours.luau), round --- trips, the contract and the fuzz pass. Fixtures: tools/fixtures/psd.py. +-- layered/psd tests: PSD / PSB files against psd-tools (layers exact, flatten by PSNR). +-- Fixtures: tools/fixtures/psd.py. local T = require("@tests/T") local Psd = require("@rosetta/layered/psd") local LayerOps = require("@rosetta/ops/LayerOps") @@ -18,8 +15,7 @@ local function decode(s: string | buffer, opts: any?): (any, any) local b = if type(s) == "string" then buffer.fromstring(s) else s return Psd.decode(Bytes.reader(b), opts) end --- PSNR of two rgba8 buffers, colours premultiplied by alpha (the colour of a transparent pixel does not matter); --- identical -> 99 +-- colours premultiplied by alpha: the colour of a transparent pixel does not matter local function psnr(a: buffer, b: string, opaque: boolean?): number local n = math.min(buffer.len(a), #b) local se = 0 @@ -51,8 +47,7 @@ t:eq(Psd.name, "psd", "name") t:eq(Psd.category, "layered", "category") t:check(Psd.caps.decode and Psd.caps.encode, "caps") --- PSNR floors for our flatten vs psd-tools' composite: blend modes where psd-tools' formulas differ from the W3C ones --- (Photoshop's own differ from both) get a lower bar +-- psd-tools' blend formulas differ from the W3C ones (Photoshop's differ from both): lower floors for those local LOW = { ["blend-diss"] = 8, ["blend-hMix"] = 15, ["blend-sLit"] = 30, ["blend-vLit"] = 25, ["blend-lLit"] = 30, ["blend-pLit"] = 30, ["blend-div"] = 30, ["blend-idiv"] = 30, ["blend-fdiv"] = 25, ["blend-hue"] = 25, ["blend-sat"] = 25, ["blend-colr"] = 25, ["blend-lum"] = 25 } local samples = {} for _, c in Fx.cases do @@ -75,7 +70,6 @@ for _, c in Fx.cases do t:note("%s: merged image vs psd-tools %.1f dB", c.name, p) end end - -- layers, in order, against psd-tools local ours = leaves(doc.layers) local ref = {} for _, l in c.layers do @@ -94,7 +88,6 @@ for _, c in Fx.cases do t:eq(Crc32.of(l.image.pixels), r.crc, c.name .. ": " .. r.name .. ": pixels") end end - -- our flatten vs psd-tools' composite if c.flat and #ours > 0 then local flat = LayerOps.flatten(doc) :: any local p = psnr(flat.pixels, c.flat) @@ -109,7 +102,6 @@ for _, c in Fx.cases do end end --- the full document's structure do local doc for _, c in Fx.cases do @@ -133,7 +125,6 @@ do local only = decode(Fx.cases[1].data, { layers = false }) t:check(only and #only.layers == 0 and only.meta.composite, "layers = false: merged image only") - -- round trip: our PSD of the decoded document decodes to the same layers, and its merged image is our flatten local out, eerr = Psd.encode(doc) t:check(out, "encode: " .. tostring(eerr)) local back = decode(out :: buffer) @@ -164,7 +155,6 @@ for _, c in Ours.checks do end t:note("psd-tools agrees with our PSD on %d facts", #Ours.checks) --- errors do local _, e = decode("8BPS\0\1\0\0\0\0\0\0\0\3\0\0\0\10\0\0\0\10\0\8\0\3") t:check(e and e.code == Err.TRUNCATED, "truncated after the header: " .. tostring(e)) From 9fe476b8035fa2c7ed5a0893754aa99c9b273449 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:49:17 -0500 Subject: [PATCH 05/25] tests/vector: comments: specs only --- tests/vector/svg.luau | 17 ++++------------- tests/vector/tiled.luau | 13 +++---------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/tests/vector/svg.luau b/tests/vector/svg.luau index f90f456..02819e9 100644 --- a/tests/vector/svg.luau +++ b/tests/vector/svg.luau @@ -1,8 +1,5 @@ --- vector/svg tests: hand-written SVGs, one feature area each (shapes, every path command, arcs, transforms, stroke --- joins / caps / dashes, fill rules, opacity, gradients, href, CSS, use / symbol, viewBox + preserveAspectRatio, nested --- svg, clip paths, units, colours, inheritance), rasterized by us and compared with resvg by PSNR; our SVG writer's --- output rendered by resvg against resvg's rendering of the original (tools/fixtures/_ours.luau); path data and --- colour parsing details; round trips; errors; the fuzz pass. Fixtures: tools/fixtures/svg.py. +-- vector/svg tests: hand-written SVGs rasterized by us against resvg by PSNR. +-- Fixtures: tools/fixtures/svg.py. local T = require("@tests/T") local Svg = require("@rosetta/vector/svg") local PathData = require("@rosetta/vector/svg/PathData") @@ -16,7 +13,7 @@ local t = T.suite("svg") local function decode(s: string): (any, any) return Svg.decode(Bytes.reader(buffer.fromstring(s))) end --- PSNR over premultiplied RGBA (the colour of transparent pixels does not matter) +-- premultiplied: the colour of transparent pixels does not matter local function psnr(a: buffer | string, b: string): number local sa = if type(a) == "string" then a else buffer.tostring(a) local n = math.min(#sa, #b) @@ -39,8 +36,7 @@ t:eq(Svg.name, "svg", "name") t:eq(Svg.category, "vector", "category") t:check(Svg.caps.decode and Svg.caps.encode, "caps") --- antialiasing differs between rasterizers (resvg: tiny-skia's analytic AA; ours: exact area coverage), so edges --- cost a few dB; the floor catches wrong geometry / paint +-- antialiasing differs from resvg (tiny-skia analytic AA vs our exact coverage): the floor catches wrong geometry local FLOOR = 30 local samples = {} local worst, worstName = 99, "" @@ -69,7 +65,6 @@ for _, c in Fx.cases do end t:note("worst: %s %.1f dB", worstName, worst) --- path data do local cmds, ok = PathData.parse("M1.5.5L-2-3e1 1e-1.2zm1,1 h2 v2 a1 1 0 0 1 2 2") t:check(ok, "parse ok") @@ -88,7 +83,6 @@ do t:eq(PathData.serialize({ { op = "M", 1, 2.5 }, { op = "C", 0.12345, 1, 2, 3, 4, 5 }, { op = "Z" } }), "M 1 2.5 C 0.1235 1 2 3 4 5 Z", "serialize") end --- colours and lengths do local function col(s: string): string local c = Style.color(s) @@ -109,7 +103,6 @@ do t:eq(Style.transform("translate(1,"), nil, "bad transform") end --- the model do local v = decode(Fx.cases[1].svg) t:check(#v.paths == 7, "shapes: one path each") @@ -119,14 +112,12 @@ do t:check(text.meta.unsupported.text == 1 and text.meta.unsupported.image == 1 and #text.paths == 1, "unsupported elements counted") local ns = decode("") t:check(ns and #ns.paths == 1, "prefixed SVG namespace") - -- a round trip keeps the paths local back = decode(buffer.tostring(Svg.encode(v) :: buffer)) t:eq(#back.paths, #v.paths, "round trip path count") t:eq(Svg.sniff(Bytes.reader(buffer.fromstring(Fx.cases[1].svg))), 0.95, "sniff") t:eq(Svg.sniff(Bytes.reader(buffer.fromstring(""))), 0, "sniff html") end --- errors do local _, e = decode("") t:check(e and e.code == Err.CORRUPT, "not svg: " .. tostring(e)) diff --git a/tests/vector/tiled.luau b/tests/vector/tiled.luau index 36a4c08..d4db698 100644 --- a/tests/vector/tiled.luau +++ b/tests/vector/tiled.luau @@ -1,8 +1,5 @@ --- vector/tiled tests: hand-written TMX maps (CSV / base64 zlib / gzip / raw / XML tile data, flip bits, infinite --- chunks, hexagonal attributes, groups, image layers, every object shape, text, typed properties, embedded and --- external tilesets with per-tile data) against Tiled's own TMJ export and TMX re-save of them (the same TileMap from --- all three), a TSX tileset against Tiled's TSJ, our encoder's TMX / TMJ read back by Tiled (tools/fixtures/_ours.luau), --- round trips in every data encoding, errors, and the fuzz pass. Fixtures: tools/fixtures/tiled.py. +-- vector/tiled tests: hand-written TMX maps against Tiled's own TMJ export and TMX re-save. +-- Fixtures: tools/fixtures/tiled.py. local T = require("@tests/T") local Tiled = require("@rosetta/vector/tiled") local Bytes = require("@rosetta/core/Bytes") @@ -17,7 +14,7 @@ local function decode(s: string | buffer): (any, any) return Tiled.decode(Bytes.reader(b)) end --- deep comparison of decoded maps, without the fields that only say who wrote the file +-- ignores the fields that only say who wrote the file local SKIP = { version = true, tiledVersion = true, encoding = true, compression = true, meta = true } local function same(a: any, b: any, path: string, out: { string }) if #out > 8 then @@ -73,7 +70,6 @@ for _, c in Fx.cases do table.insert(samples, c.tmj) end --- details of the orthogonal map do local m = maps.ortho t:eq(m.class, "Level", "map class") @@ -118,7 +114,6 @@ do t:eq(maps.infinite.layers[1].chunks[2].x, -16, "chunk position") end --- the external tileset, TSX vs Tiled's TSJ do local a = decode(Fx.tsx) local b = decode(Fx.tsj) @@ -136,7 +131,6 @@ do end end --- round trips through every flavour and data encoding for name, m in maps do for _, o in { { format = "tmx" }, { format = "tmx", encoding = "base64" }, { format = "tmx", encoding = "base64", compression = "zlib" }, { format = "tmx", encoding = "base64", compression = "gzip" }, { format = "tmx", encoding = "xml" }, { format = "tmj" }, { format = "tmj", encoding = "base64", compression = "zlib" }, { format = "json", indent = 0 } } do local out, err = Tiled.encode(m, o :: any) @@ -161,7 +155,6 @@ for _, c in Ours.checks do t:check(c.ok, c.label) end --- errors do local zstd = string.gsub(Fx.cases[1].tmx, "compression=\"zlib\"", "compression=\"zstd\"") local _, e = decode(zstd) From 2591255694eba06643e8583398df9c1921273baa Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:49:23 -0500 Subject: [PATCH 06/25] tests: shorten two header lines --- tests/T.luau | 2 +- tests/compat.luau | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/T.luau b/tests/T.luau index 84d2fcc..b111cfb 100644 --- a/tests/T.luau +++ b/tests/T.luau @@ -60,7 +60,7 @@ function Suite.note(_self: Suite, fmt: string, ...: any) print(" " .. string.format(fmt, ...)) end --- the no-throw pass: truncations, opts.mutations (default 8) random byte changes, opts.garbage (default 200) random buffers. +-- the no-throw pass: truncations, opts.mutations (default 8) mutated copies, opts.garbage (default 200) random buffers. function Suite.fuzz(self: Suite, label: string, decode: (buffer) -> any, samples: { any }, opts: { mutations: number?, garbage: number?, seed: number?, keepHeader: number? }?): (number, number) local o: { mutations: number?, garbage: number?, seed: number?, keepHeader: number? } = opts or {} local rand = T.rng(o.seed or 1234) diff --git a/tests/compat.luau b/tests/compat.luau index 82eea17..d3ea624 100644 --- a/tests/compat.luau +++ b/tests/compat.luau @@ -1,4 +1,4 @@ --- compat tests: the Luau semantics the library relies on, under luau and under LuaJIT (compat/luajit.lua + build.py lowering). +-- compat tests: the Luau semantics the library relies on, under luau and LuaJIT (compat/luajit.lua, build.py lowering). local T = require("@tests/T") local t = T.suite("compat") From e23adf2a2d5890712ad07ba949c141ccf540424e Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:49:44 -0500 Subject: [PATCH 07/25] examples: short headers --- examples/archive.luau | 4 +--- examples/audio.luau | 3 +-- examples/cad.luau | 6 ++---- examples/data.luau | 3 +-- examples/font.luau | 6 ++---- examples/image.luau | 5 ++--- examples/layered.luau | 4 +--- examples/music.luau | 4 +--- examples/playlist.luau | 3 +-- examples/scene.luau | 4 +--- examples/tilemap.luau | 3 +-- examples/vector.luau | 3 +-- examples/video.luau | 4 +--- 13 files changed, 16 insertions(+), 36 deletions(-) diff --git a/examples/archive.luau b/examples/archive.luau index 2d36ffa..a2c372c 100644 --- a/examples/archive.luau +++ b/examples/archive.luau @@ -1,5 +1,4 @@ --- examples/archive.luau: builds a zip, lists and reads it, edits it, converts it to a .tar.gz and back, and gzips a --- single file. Run from the repository root: luau examples/archive.luau (docs/guide/archive.md explains the API). +-- examples/archive.luau: build, read and edit a zip, convert it to .tar.gz and back, gzip a file (docs/guide/archive.md). local F = require("@rosetta") -- a new zip: a directory, a text file, an incompressible file stored as is @@ -16,7 +15,6 @@ zip:add("game/noise.bin", noise, { method = "store" }) local zipBytes = assert(F.save(zip, nil, { format = "zip", comment = "example" })) print(string.format("zip: %d bytes", buffer.len(zipBytes))) --- list and read local loaded = assert(F.archive.load(zipBytes)) for _, e in loaded:list() do print(string.format(" %-18s %6d -> %6s %s", e.name, e.size, tostring(e.compressedSize), e.method or (if e.dir then "dir" else ""))) diff --git a/examples/audio.luau b/examples/audio.luau index 57ee594..feec73e 100644 --- a/examples/audio.luau +++ b/examples/audio.luau @@ -1,5 +1,4 @@ --- Audio example (rosetta): build a sound, edit it with F.ops.audio, encode it to several formats, then stream it --- back with a Decoder. Run from the repository root: luau examples/audio.luau (docs/guide/audio.md explains the API). +-- examples/audio.luau: build a sound, edit it, encode it to several formats, stream it back (docs/guide/audio.md). local F = require("@rosetta") local A = F.ops.audio diff --git a/examples/cad.luau b/examples/cad.luau index 1437b43..b7cfa38 100644 --- a/examples/cad.luau +++ b/examples/cad.luau @@ -1,6 +1,5 @@ --- examples/cad.luau: reads a small STEP file, walks its entity graph (references, complex instances), adds an entity --- and writes it back under another schema. Run from the repository root: luau examples/cad.luau --- Solid geometry (B-rep bodies, meshes) needs a kernel plug-in, F.plugins.brep: see docs/guide/cad.md. +-- examples/cad.luau: read a STEP file, walk its entity graph, add an entity, write it as AP242 (docs/guide/cad.md). +-- Solid geometry (B-rep bodies, meshes) needs a kernel plug-in, F.plugins.brep. local F = require("@rosetta") local STEP = [[ @@ -54,7 +53,6 @@ local si = assert(step.part(cad.entities[20], "SI_UNIT")) print("length unit:", si[1].enum, si[2].enum) -- MILLI METRE assert(si[1].enum == "MILLI") --- the product name local product = cad.entities[step.byType(cad, "PRODUCT")[1]] print("product:", product.args[1], product.args[2]) diff --git a/examples/data.luau b/examples/data.luau index a20c524..83cf206 100644 --- a/examples/data.luau +++ b/examples/data.luau @@ -1,5 +1,4 @@ --- examples/data.luau: one record through JSON, YAML, TOML, MessagePack and CBOR, plus CSV rows, an INI file and an --- XML document. Run from the repository root: luau examples/data.luau (docs/guide/data.md explains the values). +-- examples/data.luau: one record through JSON, YAML, TOML, MessagePack and CBOR; CSV, INI and XML (docs/guide/data.md). local F = require("@rosetta") local Types = F.Types diff --git a/examples/font.luau b/examples/font.luau index 0aa42c6..c162f1d 100644 --- a/examples/font.luau +++ b/examples/font.luau @@ -1,7 +1,5 @@ --- examples/font.luau: loads a TrueType font, prints its metrics, renders a line of text into a PNG and bakes the font --- into a BMFont (descriptor + page images). Run from the repository root: luau examples/font.luau --- It needs a .ttf: from the repo it uses the docs test font (generate it first with python3 -I tools/fixtures.py docs), --- elsewhere set TTF_BYTES below to the bytes of any font (the luau CLI cannot read files). docs/guide/font.md explains. +-- examples/font.luau: load a TrueType font, render text into a PNG, bake a BMFont (docs/guide/font.md). +-- Needs a .ttf: in the repo, the docs test font (python3 -I tools/fixtures.py docs); elsewhere set TTF_BYTES below. local F = require("@rosetta") local TTF_BYTES: buffer? = nil diff --git a/examples/image.luau b/examples/image.luau index 7680994..3ec3080 100644 --- a/examples/image.luau +++ b/examples/image.luau @@ -1,6 +1,5 @@ --- examples/image.luau: build an image, edit it with F.ops.image, save it in several formats, make an animated GIF and --- read it back. Run from the repository root: luau examples/image.luau (the .luaurc alias @rosetta points at src/). --- On LuaJIT / LÖVE, the same calls work with local F = require("rosetta") (docs/guide/image.md). +-- examples/image.luau: build an image, edit it, save it in several formats, make an animated GIF (docs/guide/image.md). +-- On LuaJIT / LÖVE: local F = require("rosetta"). local F = require("@rosetta") local I = F.ops.image diff --git a/examples/layered.luau b/examples/layered.luau index a70d490..8691935 100644 --- a/examples/layered.luau +++ b/examples/layered.luau @@ -1,6 +1,4 @@ --- examples/layered.luau: build a layered document (a group, a clipping layer, a blend mode), flatten it, save it as --- PSD and Aseprite, and make a small Aseprite animation exported as a GIF. Run from the repository root: --- luau examples/layered.luau (docs/guide/layered.md explains the type). +-- examples/layered.luau: build a layered document, flatten it, save PSD and Aseprite, export a GIF (docs/guide/layered.md). local F = require("@rosetta") local I, L = F.ops.image, F.Types.Layered diff --git a/examples/music.luau b/examples/music.luau index 99769ca..3bf186c 100644 --- a/examples/music.luau +++ b/examples/music.luau @@ -1,6 +1,4 @@ --- Music example (rosetta): write a MIDI file from scratch, read it back, and render it to audio with the built-in --- waveforms (pass a SoundFont as { soundfont = sf2Bytes } for real instruments). Run from the repository root: --- luau examples/music.luau (docs/guide/music.md explains the API). +-- examples/music.luau: write a MIDI file, read it back, render it to audio (docs/guide/music.md). local F = require("@rosetta") -- 1. a Midi: 480 ticks per quarter note, absolute ticks, a tempo, a track name and a little melody diff --git a/examples/playlist.luau b/examples/playlist.luau index 1e931fa..cb38c67 100644 --- a/examples/playlist.luau +++ b/examples/playlist.luau @@ -1,5 +1,4 @@ --- examples/playlist.luau: reads an M3U with a base URL, inspects an HLS master playlist, and converts a playlist to --- PLS and XSPF. Run from the repository root: luau examples/playlist.luau (docs/guide/playlist.md explains the type). +-- examples/playlist.luau: read an M3U, inspect an HLS master playlist, convert to PLS and XSPF (docs/guide/playlist.md). local F = require("@rosetta") local M3U = "#EXTM3U\n#PLAYLIST:Road Trip\n#EXTINF:215,Ada - First Song\nmusic/first.mp3\n" diff --git a/examples/scene.luau b/examples/scene.luau index d8d2565..034d122 100644 --- a/examples/scene.luau +++ b/examples/scene.luau @@ -1,6 +1,4 @@ --- examples/scene.luau: builds a 3D scene from scratch (a cube with a material, plus a voxel grid), edits it with --- F.ops.mesh and saves it as GLB, OBJ + MTL and STL. Run from the repository root: luau examples/scene.luau --- (docs/guide/scene.md explains the Scene type). +-- examples/scene.luau: build a 3D scene and a voxel grid, edit it, save as GLB, OBJ and STL (docs/guide/scene.md). local F = require("@rosetta") local S = F.Types.Scene diff --git a/examples/tilemap.luau b/examples/tilemap.luau index ddd7778..e4c5322 100644 --- a/examples/tilemap.luau +++ b/examples/tilemap.luau @@ -1,5 +1,4 @@ --- examples/tilemap.luau: read a Tiled map (TMX), walk its tile layer with the flip flags, find an object, edit the map --- and convert it to TMJ. Run from the repository root: luau examples/tilemap.luau (docs/guide/tilemap.md). +-- examples/tilemap.luau: read a TMX map, walk a tile layer, find an object, edit, write TMJ (docs/guide/tilemap.md). local F = require("@rosetta") local tmx = [[ diff --git a/examples/vector.luau b/examples/vector.luau index 9b584ab..4d479f7 100644 --- a/examples/vector.luau +++ b/examples/vector.luau @@ -1,5 +1,4 @@ --- examples/vector.luau: parse an SVG, inspect its paths, rasterize it at two sizes, build a Vector from scratch and --- write it as SVG. Run from the repository root: luau examples/vector.luau (docs/guide/vector.md explains the type). +-- examples/vector.luau: parse an SVG, rasterize it, build a Vector and write it as SVG (docs/guide/vector.md). local F = require("@rosetta") local svg = [[ diff --git a/examples/video.luau b/examples/video.luau index b61dd19..be70380 100644 --- a/examples/video.luau +++ b/examples/video.luau @@ -1,6 +1,4 @@ --- Video example (rosetta): make frames with F.ops.image, write them as an AVI (Motion-JPEG), then open the --- video, walk its packets and frames, seek, and turn it into an animated GIF. Run from the repository root: --- luau examples/video.luau (docs/guide/video.md explains the API). +-- examples/video.luau: write frames as an MJPEG AVI, open it, walk packets and frames, seek, make a GIF (docs/guide/video.md). local F = require("@rosetta") local I = F.ops.image From 53aa9a6ebf2b1c6ad6718700864eaf1f6776232e Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:49:47 -0500 Subject: [PATCH 08/25] tests/core: comments: specs only --- tests/core/base64.luau | 6 +----- tests/core/bits.luau | 9 +-------- tests/core/bytes.luau | 11 +---------- tests/core/md5.luau | 1 - 4 files changed, 3 insertions(+), 24 deletions(-) diff --git a/tests/core/base64.luau b/tests/core/base64.luau index 79d895c..8738d75 100644 --- a/tests/core/base64.luau +++ b/tests/core/base64.luau @@ -1,5 +1,4 @@ --- core/Base64 tests: the RFC 4648 vectors, encode / decode against Python's base64 (standard, URL-safe, unpadded) for every length 0..70 --- and some large inputs, whitespace and missing padding on decode, data: URIs, bad input, and the fuzz no-throw pass. +-- core/Base64 tests: the RFC 4648 vectors and Python's base64 (standard, URL-safe, unpadded), data: URIs, bad input. -- Fixtures: tools/fixtures/base64.py. local T = require("@tests/T") local Base64 = require("@rosetta/core/Base64") @@ -43,15 +42,12 @@ end t:eq(Base64.encode("foobarfoobarfo", { wrap = 8 }), "Zm9vYmFy\nZm9vYmFy\nZm8=", "wrap 8") t:eq(Base64.encode("foobarfoobar", { wrap = 8 }), "Zm9vYmFy\nZm9vYmFy", "wrap at the end") t:eq(Base64.encode("foobarfoobar", { wrap = 9 }), "Zm9vYmFy\nZm9vYmFy", "wrap rounds to groups") --- a sub-range t:eq(Base64.encode(buffer.fromstring("xxhelloyy"), nil, 2, 5), "aGVsbG8=", "encode a range") --- data URIs local b, mime = Base64.decodeDataUri("data:application/gltf-buffer;base64,AAEC") t:check(b and buffer.len(b) == 3 and buffer.readu8(b, 2) == 2 and mime == "application/gltf-buffer", "data URI") local b2, m2 = Base64.decodeDataUri("data:,a%20b") t:check(b2 and buffer.tostring(b2) == "a b" and m2 == "text/plain", "percent-encoded data URI") t:eq(Base64.dataUri(buffer.fromstring("hi"), "text/plain"), "data:text/plain;base64,aGk=", "dataUri") --- bad input t:check(Base64.decode("ab$d") == nil, "bad character") t:check(Base64.decode("abcde") == nil, "a lone last character") t:check(Base64.decode("ab==cd") == nil, "data after padding") diff --git a/tests/core/bits.luau b/tests/core/bits.luau index 1562fd2..19bedf5 100644 --- a/tests/core/bits.luau +++ b/tests/core/bits.luau @@ -1,6 +1,4 @@ --- core/Bits and codecs/entropy/Huffman tests: LSB / MSB readers and writers round-trip random fields of 1..32 bits, align / --- peek / bytePos, overrun is a sticky error; canonical codes, length-limited code lengths, LSB and MSB decoding tables --- (with subtables) decode what the writers wrote; invalid code sets are rejected. +-- core/Bits and codecs/entropy/Huffman tests: bit readers / writers, canonical codes, length limits, decoding tables. local T = require("@tests/T") local Bits = require("@rosetta/core/Bits") local Huffman = require("@rosetta/codecs/entropy/Huffman") @@ -9,7 +7,6 @@ local Err = require("@rosetta/core/Err") local t = T.suite("bits") local rand = T.rng(7) --- round trips for _, kind in { "lsb", "msb" } do local w = if kind == "lsb" then Bits.lsbWriter() else Bits.msbWriter() local fields = {} @@ -46,7 +43,6 @@ for _, kind in { "lsb", "msb" } do t:check(r.err and r.err.code == Err.TRUNCATED, kind .. ": overrun is TRUNCATED") end --- known bit orders do local lsb = Bits.lsbReader(T.bytes({ 0xB4 })) -- 1011 0100 t:eq(lsb:read(3), 4, "lsb: first field is the low bits") @@ -83,7 +79,6 @@ do t:eq(Huffman.reverse(1, 3), 4, "reverse 3 bits") end --- lengths: limits, Kraft equality, single symbol local function kraft(lens: { number }): number local s = 0 for _, l in lens do @@ -113,7 +108,6 @@ do t:check(u[1] == 2 and u[4] == 2, "uniform") end --- decoding tables: random code sets, encode with the writer, decode through LSB and MSB tables for trial = 1, 30 do local nsym = 2 + rand(300) local freqs = {} @@ -161,7 +155,6 @@ for trial = 1, 30 do end end --- invalid code sets do local over = T.bytes({ 1, 1, 1 }) -- three 1-bit codes t:eq(Huffman.buildLsb(over, 0, 3, buffer.create(1024 * 4), 8), -1, "over-subscribed") diff --git a/tests/core/bytes.luau b/tests/core/bytes.luau index e73191e..466da83 100644 --- a/tests/core/bytes.luau +++ b/tests/core/bytes.luau @@ -1,6 +1,4 @@ --- core/Bytes, core/Err, core/Crc32, core/Adler32, core/Input tests: every Reader / Writer method both endians, the --- sticky TRUNCATED error (never a throw), sub-readers without copies, Writer growth and patching, Bytes.span, the --- MSB-first CRC-32 (MPEG-2 / bzip2 check values). +-- core/Bytes, Err, Crc32, Adler32 and Input tests. local T = require("@tests/T") local Bytes = require("@rosetta/core/Bytes") local Err = require("@rosetta/core/Err") @@ -10,7 +8,6 @@ local Input = require("@rosetta/core/Input") local t = T.suite("bytes") --- Writer -> Reader round trip of every type do local w = Bytes.writer(4) -- grows w:u8(0xAB) @@ -97,7 +94,6 @@ do local nilv, e = r4:fail(Err.CORRUPT, "bad thing") t:check(nilv == nil and e.code == Err.CORRUPT and tostring(e) == "CORRUPT at 0x0: bad thing", "fail(): " .. tostring(e)) t:check(not r4:need(5) and r4.err == e, "need keeps the first error") - -- every method on an empty reader: no throw local empty = Bytes.reader(buffer.create(0)) for _, m in { "u8", "i8", "u16le", "u16be", "i16le", "i16be", "u24le", "u24be", "u32le", "u32be", "i32le", "i32be", "u64le", "u64be", "i64le", "i64be", "f16le", "f16be", "f32le", "f32be", "f64le", "f64be", "cstring" } do local ok, v = pcall((Bytes.Reader :: any)[m], empty) @@ -113,7 +109,6 @@ do t:check(ok, "string / bytes / slice / skip / align on an empty reader") end --- ranges, sub-readers, peek, match do local buf = buffer.fromstring("0123456789") local r = Bytes.reader(buf, 2, 5) -- "23456" @@ -141,7 +136,6 @@ do t:check(a:align(4) and a:tell() == 4, "align") end --- checksums do t:eq(Crc32.string("123456789"), 0xCBF43926, "crc32 check value") t:eq(Crc32.of(buffer.fromstring("xx123456789yy"), 2, 9), 0xCBF43926, "crc32 range") @@ -151,7 +145,6 @@ do t:eq(Adler32.string("pedia", Adler32.string("Wiki")), 0x11E60398, "adler32 continuation") end --- Input (without a host) do local b = buffer.create(3) t:check(Input.resolve(b) == b, "a buffer passes through") @@ -173,7 +166,6 @@ do t:eq(buffer.tostring(db :: buffer), "img.png", "opts.data forces data") end --- Err do local e = Err.new(Err.CORRUPT, "bad", 16) t:check(Err.is(e) and not Err.is({}) and not Err.is("x"), "Err.is") @@ -182,7 +174,6 @@ do t:check(w.code == Err.CORRUPT and w.format == "gif", "wrap a string") end --- Bytes.span: codec argument checking do local b, o, n = Bytes.span("x", "hello", 1, 10) t:check(type(b) == "buffer" and o == 1 and n == 4, "span clamps the length") diff --git a/tests/core/md5.luau b/tests/core/md5.luau index 901eb97..32db5be 100644 --- a/tests/core/md5.luau +++ b/tests/core/md5.luau @@ -15,7 +15,6 @@ local VECTORS = { for _, v in VECTORS do t:eq(Md5.of(buffer.fromstring(v[1])), v[2], "md5 of " .. string.format("%q", v[1])) end --- incremental: every split point of a 130-byte message, three pieces local msg = string.rep("The quick brown fox jumps over the lazy dog. ", 3) local want = Md5.of(buffer.fromstring(msg)) for cut = 0, #msg, 7 do From 70f50917fa836fe747b79f4c66fa8488b3fcdb38 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:49:47 -0500 Subject: [PATCH 09/25] tests/containers: comments: specs only --- tests/containers/chunks.luau | 3 +-- tests/containers/isobmff.luau | 15 ++------------- tests/containers/ogg.luau | 15 +++------------ tests/containers/riff.luau | 12 +----------- tests/containers/tar.luau | 9 +-------- 5 files changed, 8 insertions(+), 46 deletions(-) diff --git a/tests/containers/chunks.luau b/tests/containers/chunks.luau index 8fd962e..630260b 100644 --- a/tests/containers/chunks.luau +++ b/tests/containers/chunks.luau @@ -1,5 +1,4 @@ --- containers/Chunks tests: RIFF (padding, an odd chunk without its pad byte, open-ended data), IFF big-endian, PNG --- (size first + CRC trailer, truncation), CAF 64-bit sizes, resize hooks, find, and a no-throw pass over garbage. +-- containers/Chunks tests: RIFF, IFF, PNG and CAF chunks, resize hooks, find, and a no-throw pass over garbage. local T = require("@tests/T") local Chunks = require("@rosetta/containers/Chunks") diff --git a/tests/containers/isobmff.luau b/tests/containers/isobmff.luau index 0a5b34c..49efeec 100644 --- a/tests/containers/isobmff.luau +++ b/tests/containers/isobmff.luau @@ -1,8 +1,5 @@ --- containers/IsoBmff tests: ffmpeg / MP4Box files (H.264 + AAC with B-frames, fast start, QuickTime MJPEG + PCM, HEVC, --- fragmented by ffmpeg and MP4Box, stz2 + co64, ALAC) demuxed packet for packet against ffprobe (-ignore_editlist); --- track facts and codec configurations; iTunes tags and cover art; AVIF items (libavif, plain and with alpha); the --- muxer round-trips through the demuxer (sizes, times, cts, sync, tags, 64-bit sizes); a sub-range reader; the fuzz --- no-throw pass. Fixtures: tools/fixtures/isobmff.py. +-- containers/IsoBmff tests: ffmpeg / MP4Box files against ffprobe (-ignore_editlist), AVIF items, the muxer. +-- Fixtures: tools/fixtures/isobmff.py. local T = require("@tests/T") local IsoBmff = require("@rosetta/containers/IsoBmff") local Bytes = require("@rosetta/core/Bytes") @@ -22,7 +19,6 @@ local function reader(s: string, pad: number?): Bytes.Reader return Bytes.reader(buffer.fromstring(s)) end --- every fixture against ffprobe for _, c in Fx.cases do for _, pad in { 0, 5 } do local r = reader(c.data, if pad > 0 then pad else nil) @@ -46,7 +42,6 @@ for _, c in Fx.cases do t:eq(if tr.config then buffer.len(tr.config) else 0, s.extradata, label .. ": codec config size") end end - -- packets in file order local n, bad = 0, nil local base = r.base for p in dmx:packets() do @@ -73,7 +68,6 @@ for _, c in Fx.cases do end end --- per-track packets, seek do local c = Fx.cases[1] local dmx = IsoBmff.demux(reader(c.data)) @@ -90,7 +84,6 @@ do t:check(v.skip >= 0 and v.edits ~= nil, "edit list parsed") end --- tags and cover do local r = reader(Fx.tagged.data) local movie = IsoBmff.parse(r) :: IsoBmff.Movie @@ -104,7 +97,6 @@ do t:eq(pics[1] and pics[1].mime, "image/png", "cover mime") end --- AVIF items for _, c in Fx.avif do local r = reader(c.data) t:check(IsoBmff.sniff(r) == "avif", c.name .. ": brand") @@ -139,7 +131,6 @@ for _, c in Fx.avif do t:eq(auxl ~= nil, c.alpha, c.name .. ": alpha auxiliary item") end --- the muxer: round trip through the demuxer do local rand = T.rng(5) local function sample(n: number): buffer @@ -199,7 +190,6 @@ do t:check(tags.title == "Mux Test" and tags.artist == "Me" and tags.track == "2" and tags.tracktotal == "9" and tags.custom == "free form" and tags.bpm == "120", "mux: tags round trip") t:check(#pics == 1 and buffer.len(pics[1].data) == 4, "mux: cover round trip") t:note("mux: %d bytes, crc %08x", buffer.len(file :: buffer), Crc32.of(file :: buffer)) - -- data + sizes form, bad specs local f2 = IsoBmff.mux({ tracks = { { kind = "audio", entry = "alac", timescale = 8000, data = buffer.create(30), sizes = { 10, 10, 10 }, durations = { 4096, 4096, 100 }, config = buffer.create(24) } } }) local d2 = IsoBmff.demux(Bytes.reader(f2 :: buffer)) t:check(d2 and d2.tracks[1].codec == "alac" and d2.tracks[1].sampleCount == 3 and d2.tracks[1].durations[3] == 100 and buffer.len(d2.tracks[1].config) == 24, "mux: data + sizes, alac cookie") @@ -209,7 +199,6 @@ do end end --- fuzz do local samples = {} for _, c in Fx.cases do diff --git a/tests/containers/ogg.luau b/tests/containers/ogg.luau index 227996b..75d60bc 100644 --- a/tests/containers/ogg.luau +++ b/tests/containers/ogg.luau @@ -1,9 +1,6 @@ --- containers/Ogg tests: real encoder files (opusenc, flac --ogg, ffmpeg vorbis) and hand-made multiplexed files, --- checked packet by packet against the independent Python parser of tools/fixtures/ogg.py; seeking on each; a big --- multiplexed file written with the muxer (bisection seeks); muxer edge cases (lacing at 255 multiples, page breaks, --- continued packets, flush, eos); a sub-range Reader; truncated / garbage input never throws. The muxer was also --- checked by hand against opus-tools: an opusenc file remuxed through it passes opusinfo and decodes identically. --- Ported from ogg-luau tests/ogg.luau. Fixtures: tools/fixtures/ogg.py. +-- containers/Ogg tests: encoder and hand-made multiplexed files against the parser in tools/fixtures/ogg.py, the muxer. +-- The muxer was checked against opus-tools: an opusenc file remuxed through it passes opusinfo, decodes identically. +-- Fixtures: tools/fixtures/ogg.py. local T = require("@tests/T") local Ogg = require("@rosetta/containers/Ogg") local Bytes = require("@rosetta/core/Bytes") @@ -13,7 +10,6 @@ local Cases = require("@tests/gen/ogg_cases") local t = T.suite("ogg") --- seek expectations from a packet list: { size, crc, granule, bos, eos } local function expectSeek(list: { any }, g: number): (number, number) local start, idx = -1, 1 for i, p in list do @@ -77,7 +73,6 @@ for _, fx in Cases do t:eq(counts[i], #fx.streams[i].packets, fx.name .. ": interleaved count") end end - -- seeking for _, es in fx.streams do local serial = es.serial local last = es.lastGranule @@ -104,7 +99,6 @@ for _, fx in Cases do end end end - -- a Reader over a sub-range of a bigger buffer local big = buffer.create(#fx.data + 20) buffer.writestring(big, 11, fx.data) local ds = Ogg.open(Bytes.reader(big, 11, #fx.data)) @@ -221,7 +215,6 @@ do t:check(pages > 70, "edge: page breaks (" .. pages .. " pages)") t:eq(d:stream(42).lastGranule, #sizes * 10, "edge: last granule") t:eq(d:stream(42).codec, "unknown", "edge: codec") - -- strings, ranges and bad arguments local m2 = Ogg.muxer() local s2 = m2:stream() t:check(s2:packet("OpusHead" .. string.rep("\0", 11), 0, { flush = true }), "string packet") @@ -237,7 +230,6 @@ do t:check(d2:nextPacket(1) == nil, "empty eos page ends the stream") end --- errors and garbage do local _, e1 = Ogg.open(buffer.create(0)) t:check(e1 and e1.code == Err.CORRUPT, "empty: " .. tostring(e1)) @@ -246,7 +238,6 @@ do t:check(e2 and e2.code == Err.ARG, "not a buffer: " .. tostring(e2)) end --- fuzz: open + read every packet + seek never throws t:fuzz("open + read + seek", function(b: buffer) local d = Ogg.open(b) if d then diff --git a/tests/containers/riff.luau b/tests/containers/riff.luau index 1f53a25..bb80e7e 100644 --- a/tests/containers/riff.luau +++ b/tests/containers/riff.luau @@ -1,6 +1,4 @@ --- containers/Riff tests: the writer (RIFF, RIFX, forced RF64 with ds64, LIST/INFO, odd pad bytes, parts) read back by --- the reader; lenient reading (missing pad byte, truncated chunk, open-ended data of size 0 / 0xFFFFFFFF, the ds64 --- table, a sub-range Reader); errors; the fuzz pass. The WAVE form is checked against ffmpeg in tests/audio/wav.luau. +-- containers/Riff tests: writer -> reader, lenient reading, errors. WAVE vs ffmpeg is in tests/audio/wav.luau. local T = require("@tests/T") local Riff = require("@rosetta/containers/Riff") local Bytes = require("@rosetta/core/Bytes") @@ -14,7 +12,6 @@ local function u32(v: number): string return buffer.tostring(b) end --- writer -> reader local samples = {} for _, mode in { "riff", "rifx", "rf64" } do local w = Riff.writer("TEST", { bigEndian = mode == "rifx", rf64 = mode == "rf64", sampleCount = 77 }) @@ -49,7 +46,6 @@ for _, mode in { "riff", "rifx", "rf64" } do if mode == "rf64" then t:check(f.ds64 and f.ds64.dataSize == 8 and f.ds64.sampleCount == 77 and d.declared == 0xFFFFFFFF, "rf64: ds64") end - -- parts: the same bytes local parts = w:finish({ parts = true }) :: { buffer } local j = Bytes.writer() for _, p in parts do @@ -59,28 +55,23 @@ for _, mode in { "riff", "rifx", "rf64" } do end t:check(not Riff.writer("WAVE", { bigEndian = true, rf64 = true }):finish(), "RIFX RF64 refused") --- lenient reading do -- a missing pad byte after an odd chunk local body = "WAVE" .. "abcd" .. u32(5) .. "12345" .. "next" .. u32(2) .. "ok" local f = Riff.read(buffer.fromstring("RIFF" .. u32(#body) .. body)) :: any t:check(#f.chunks == 2 and f.chunks[2].id == "next", "missing pad byte detected") - -- truncated local tb = "WAVE" .. "data" .. u32(100) .. "short" local ft = Riff.read(buffer.fromstring("RIFF" .. u32(#tb) .. tb)) :: any t:check(ft.chunks[1].truncated and ft.chunks[1].avail == 5 and ft.chunks[1].size == 100, "truncated chunk") - -- open-ended for _, sz in { 0, 0xFFFFFFFF } do local ob = "WAVE" .. "data" .. u32(sz) .. "abcdefLIST" local fo = Riff.read(buffer.fromstring("RIFF" .. u32(0) .. ob), { openEnded = { data = true } }) :: any t:check(#fo.chunks == 1 and fo.chunks[1].streamed and fo.chunks[1].size == 10, "open-ended data " .. sz) end - -- ds64 table local ds = "ds64" .. u32(40) .. u32(0) .. u32(0) .. u32(4) .. u32(0) .. u32(0) .. u32(0) .. u32(1) .. "big " .. u32(3) .. u32(0) local rb = "WAVE" .. ds .. "big " .. u32(0xFFFFFFFF) .. "xyz" .. "\0" local fr = Riff.read(buffer.fromstring("RF64" .. u32(0xFFFFFFFF) .. rb)) :: any t:check(fr.ds64 and fr.ds64.table["big "] == 3 and fr.chunks[2].size == 3, "ds64 table") - -- a sub-range reader local s = samples[1] local big = buffer.create(#s + 7) buffer.writestring(big, 3, s) @@ -89,7 +80,6 @@ do t:eq(Riff.sniff(Bytes.reader(buffer.fromstring(s))), "TEST", "sniff") end --- errors do local _, e1 = Riff.read(buffer.fromstring("RIFF")) t:check(e1 and e1.code == Err.TRUNCATED, "too short") diff --git a/tests/containers/tar.luau b/tests/containers/tar.luau index 1f2b6fc..5c82d6c 100644 --- a/tests/containers/tar.luau +++ b/tests/containers/tar.luau @@ -1,7 +1,4 @@ --- containers/Tar and containers/Archive tests: hand-made headers for the edge cases the reference archives do not hit --- (base-256 numbers, the historical signed checksum, GNU 'K' long links, pax 'g' global records, pax size overrides, --- v7 headers without magic, a missing end-of-archive marker), the writer's GNU / pax extensions (long links, fractional --- and negative mtimes), and Archive helpers (streamName, entries of foreign archive values, failing loaders). +-- containers/Tar and Archive tests: hand-made headers for edge cases the reference archives miss, the writer, helpers. local T = require("@tests/T") local Tar = require("@rosetta/containers/Tar") local Archive = require("@rosetta/containers/Archive") @@ -9,7 +6,6 @@ local Err = require("@rosetta/core/Err") local t = T.suite("containers/tar") --- a header block built by hand local function hdr(fields: { [string]: any }): buffer local h = buffer.create(512) buffer.writestring(h, 0, fields.name or "f") @@ -94,7 +90,6 @@ do t:eq(list[3].uname, "globaluser", "global records apply to later entries") end --- errors do local _, e1 = Tar.read(cat({ hdr({ size = "00000002000\0" }), block("x") })) t:check(e1 and e1.code == Err.TRUNCATED, "data past the end: " .. tostring(e1)) @@ -109,7 +104,6 @@ do t:check(list and #list == 0, "empty input is an empty archive") end --- writer extensions do local long = string.rep("n", 120) for _, fmt in { "gnu", "pax" } do @@ -128,7 +122,6 @@ do t:check(e and e.code == Err.ARG, "empty name") end --- Archive helpers do t:eq(Archive.streamName({ name = "/x/y/notes.txt.gz" }, { "gz" }), "notes.txt", "streamName strips the extension") t:eq(Archive.streamName({ name = "a.tbz2" }, { "bz2" }), "a.tar", "streamName .tbz2") From 54f53a35f61e8f58f7f164a375ce918d84e45216 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:49:47 -0500 Subject: [PATCH 10/25] tests/host: comments: specs only --- tests/host/roblox.luau | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/host/roblox.luau b/tests/host/roblox.luau index eb2fe99..7d5fa30 100644 --- a/tests/host/roblox.luau +++ b/tests/host/roblox.luau @@ -1,6 +1,4 @@ --- host/Roblox tests: the pure half of the EditableMesh adapter (meshPages: triangle runs within the triangle / vertex --- limits, corners mapping back to the source indices, double-sided counting, errors; pageData: centring, per-axis --- scale, inverse-scaled unit normals, uvs + flipV, linear -> sRGB colours). toEditableMesh itself needs Roblox. +-- host/Roblox tests: the pure half of the EditableMesh adapter (meshPages, pageData); toEditableMesh needs Roblox. local T = require("@tests/T") local Host = require("@rosetta/host/Roblox") local Types = require("@rosetta/Types") @@ -20,7 +18,6 @@ local function near(a: number, b: number, eps: number?): boolean return math.abs(a - b) <= (eps or 1e-5) end --- an n x n grid of quads in the xz plane (two triangles each), u16 indices, normals up, uvs, colours local function grid(n: number): Types.Primitive local pos, nrm, uv, col = {}, {}, {}, {} for z = 0, n do @@ -59,7 +56,6 @@ local function grid(n: number): Types.Primitive } end --- 1. pages within the limits, covering every triangle once, corners = the source indices local prim = grid(10) -- 121 vertices, 200 triangles local pages = assert(Host.meshPages(prim, { maxTriangles = 64 })) t:eq(#pages, 4, "200 triangles / 64 per page") @@ -100,7 +96,6 @@ local sp = assert(Host.meshPages(soup :: any)) t:eq(sp[1].count, 2, "unindexed triangles") t:eq(#sp[1].vertices, 6, "unindexed vertices") --- 2. errors local _, e1 = Host.meshPages({ attributes = { POSITION = f32({ 0, 0, 0 }, 3) }, mode = "lines" } :: any) t:check(e1 and e1.code == Err.ARG, "lines are not triangles") local _, e2 = Host.meshPages({} :: any) @@ -112,7 +107,6 @@ t:check(e3 and e3.code == Err.ARG, "index out of range") local _, e4 = Host.pageData(prim, {} :: any) t:check(e4 and e4.code == Err.ARG, "pageData needs a page") --- 3. pageData: centred, scaled, normals, uvs, colours local pg = one[1] local d = assert(Host.pageData(prim, pg, { scale = { 2, 1, 4 } })) t:eq(d.vertexCount, 121, "vertex count") From 96602286f804124be0d203b2cf923a6247bde3cd Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:49:50 -0500 Subject: [PATCH 11/25] tests/archive: comments: specs only --- tests/archive/7z.luau | 8 +------- tests/archive/_entries.luau | 5 +---- tests/archive/_mac.luau | 5 +---- tests/archive/adf.luau | 6 +----- tests/archive/applesingle.luau | 3 +-- tests/archive/ar.luau | 10 +--------- tests/archive/arj.luau | 5 +---- tests/archive/binhex.luau | 3 +-- tests/archive/br.luau | 10 +--------- tests/archive/bz2.luau | 5 +---- tests/archive/cab.luau | 15 +-------------- tests/archive/cpio.luau | 12 +----------- tests/archive/d64.luau | 7 +------ tests/archive/fat.luau | 8 +------- tests/archive/grp.luau | 4 +--- tests/archive/gzip.luau | 8 +------- tests/archive/iso.luau | 11 +---------- tests/archive/lha.luau | 6 +----- tests/archive/lz4.luau | 8 +------- tests/archive/macbinary.luau | 3 +-- tests/archive/mpq.luau | 7 +------ tests/archive/pak.luau | 6 +----- tests/archive/rpm.luau | 7 +------ tests/archive/tar.luau | 13 ++----------- tests/archive/uu.luau | 6 +----- tests/archive/vpk.luau | 10 +--------- tests/archive/wad.luau | 15 +-------------- tests/archive/xz.luau | 7 +------ tests/archive/yenc.luau | 6 +----- tests/archive/z.luau | 6 +----- tests/archive/zip.luau | 21 +-------------------- tests/archive/zoo.luau | 4 +--- tests/archive/zst.luau | 10 +--------- 33 files changed, 34 insertions(+), 226 deletions(-) diff --git a/tests/archive/7z.luau b/tests/archive/7z.luau index 42aa684..d447db9 100644 --- a/tests/archive/7z.luau +++ b/tests/archive/7z.luau @@ -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 diff --git a/tests/archive/_entries.luau b/tests/archive/_entries.luau index 211de7c..b282f87 100644 --- a/tests/archive/_entries.luau +++ b/tests/archive/_entries.luau @@ -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() diff --git a/tests/archive/_mac.luau b/tests/archive/_mac.luau index bdeb54a..2f9fb01 100644 --- a/tests/archive/_mac.luau +++ b/tests/archive/_mac.luau @@ -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 }) diff --git a/tests/archive/adf.luau b/tests/archive/adf.luau index 533dc88..0cb8546 100644 --- a/tests/archive/adf.luau +++ b/tests/archive/adf.luau @@ -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)) diff --git a/tests/archive/applesingle.luau b/tests/archive/applesingle.luau index d61d5d1..e722367 100644 --- a/tests/archive/applesingle.luau +++ b/tests/archive/applesingle.luau @@ -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") diff --git a/tests/archive/ar.luau b/tests/archive/ar.luau index e74201e..1746911 100644 --- a/tests/archive/ar.luau +++ b/tests/archive/ar.luau @@ -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("!\n") t:check(e1 and e1.code == Err.UNSUPPORTED, "thin archive: " .. tostring(e1)) diff --git a/tests/archive/arj.luau b/tests/archive/arj.luau index 5f9eca7..6507e21 100644 --- a/tests/archive/arj.luau +++ b/tests/archive/arj.luau @@ -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))) diff --git a/tests/archive/binhex.luau b/tests/archive/binhex.luau index 773d4b4..2c359fe 100644 --- a/tests/archive/binhex.luau +++ b/tests/archive/binhex.luau @@ -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") diff --git a/tests/archive/br.luau b/tests/archive/br.luau index c330359..cb48481 100644 --- a/tests/archive/br.luau +++ b/tests/archive/br.luau @@ -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 diff --git a/tests/archive/bz2.luau b/tests/archive/bz2.luau index 4aa7c0a..b9604ff 100644 --- a/tests/archive/bz2.luau +++ b/tests/archive/bz2.luau @@ -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") diff --git a/tests/archive/cab.luau b/tests/archive/cab.luau index 77a64d3..c70ad2e 100644 --- a/tests/archive/cab.luau +++ b/tests/archive/cab.luau @@ -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) diff --git a/tests/archive/cpio.luau b/tests/archive/cpio.luau index 64d4902..c167beb 100644 --- a/tests/archive/cpio.luau +++ b/tests/archive/cpio.luau @@ -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)))) diff --git a/tests/archive/d64.luau b/tests/archive/d64.luau index c58d752..6ca80b9 100644 --- a/tests/archive/d64.luau +++ b/tests/archive/d64.luau @@ -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 diff --git a/tests/archive/fat.luau b/tests/archive/fat.luau index 0678812..3dc373e 100644 --- a/tests/archive/fat.luau +++ b/tests/archive/fat.luau @@ -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 diff --git a/tests/archive/grp.luau b/tests/archive/grp.luau index 608b442..1a28bb1 100644 --- a/tests/archive/grp.luau +++ b/tests/archive/grp.luau @@ -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") diff --git a/tests/archive/gzip.luau b/tests/archive/gzip.luau index d92d928..6e4c2cf 100644 --- a/tests/archive/gzip.luau +++ b/tests/archive/gzip.luau @@ -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)))) diff --git a/tests/archive/iso.luau b/tests/archive/iso.luau index f175996..de9f3c8 100644 --- a/tests/archive/iso.luau +++ b/tests/archive/iso.luau @@ -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)))) diff --git a/tests/archive/lha.luau b/tests/archive/lha.luau index d8c565a..a15888d 100644 --- a/tests/archive/lha.luau +++ b/tests/archive/lha.luau @@ -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") diff --git a/tests/archive/lz4.luau b/tests/archive/lz4.luau index 5d4cde2..effadab 100644 --- a/tests/archive/lz4.luau +++ b/tests/archive/lz4.luau @@ -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 diff --git a/tests/archive/macbinary.luau b/tests/archive/macbinary.luau index 8bb0765..1289b9e 100644 --- a/tests/archive/macbinary.luau +++ b/tests/archive/macbinary.luau @@ -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") diff --git a/tests/archive/mpq.luau b/tests/archive/mpq.luau index b36da87..dad88e0 100644 --- a/tests/archive/mpq.luau +++ b/tests/archive/mpq.luau @@ -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 diff --git a/tests/archive/pak.luau b/tests/archive/pak.luau index 6cad750..22be859 100644 --- a/tests/archive/pak.luau +++ b/tests/archive/pak.luau @@ -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) diff --git a/tests/archive/rpm.luau b/tests/archive/rpm.luau index a13a6bb..d5b2bab 100644 --- a/tests/archive/rpm.luau +++ b/tests/archive/rpm.luau @@ -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)))) diff --git a/tests/archive/tar.luau b/tests/archive/tar.luau index f67d97d..8979bea 100644 --- a/tests/archive/tar.luau +++ b/tests/archive/tar.luau @@ -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) diff --git a/tests/archive/uu.luau b/tests/archive/uu.luau index b448b5d..8b77a05 100644 --- a/tests/archive/uu.luau +++ b/tests/archive/uu.luau @@ -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 diff --git a/tests/archive/vpk.luau b/tests/archive/vpk.luau index cb4f6dc..8260e83 100644 --- a/tests/archive/vpk.luau +++ b/tests/archive/vpk.luau @@ -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) diff --git a/tests/archive/wad.luau b/tests/archive/wad.luau index 01eb93a..fe095d9 100644 --- a/tests/archive/wad.luau +++ b/tests/archive/wad.luau @@ -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 diff --git a/tests/archive/xz.luau b/tests/archive/xz.luau index 8071f82..6176837 100644 --- a/tests/archive/xz.luau +++ b/tests/archive/xz.luau @@ -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 diff --git a/tests/archive/yenc.luau b/tests/archive/yenc.luau index c91febf..7a68616 100644 --- a/tests/archive/yenc.luau +++ b/tests/archive/yenc.luau @@ -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))) diff --git a/tests/archive/z.luau b/tests/archive/z.luau index bef6f2f..77d1981 100644 --- a/tests/archive/z.luau +++ b/tests/archive/z.luau @@ -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") diff --git a/tests/archive/zip.luau b/tests/archive/zip.luau index 203ed8b..03392c2 100644 --- a/tests/archive/zip.luau +++ b/tests/archive/zip.luau @@ -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 diff --git a/tests/archive/zoo.luau b/tests/archive/zoo.luau index cb4f840..bfee9ac 100644 --- a/tests/archive/zoo.luau +++ b/tests/archive/zoo.luau @@ -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") diff --git a/tests/archive/zst.luau b/tests/archive/zst.luau index 0bb0d07..592038f 100644 --- a/tests/archive/zst.luau +++ b/tests/archive/zst.luau @@ -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 From 1d4f02d984b5f58d0bbbc1e02fa54492cdbca5d4 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:49:51 -0500 Subject: [PATCH 12/25] tests/video: comments: specs only --- tests/video/_common.luau | 20 ++++++-------------- tests/video/avi.luau | 7 ++----- tests/video/encode.luau | 8 ++------ tests/video/fli.luau | 9 +++------ tests/video/flv.luau | 17 +++-------------- tests/video/h264.luau | 9 ++------- tests/video/mkv.luau | 12 ++---------- tests/video/mp4.luau | 10 +++------- tests/video/mpeg2.luau | 7 ++----- tests/video/mpegps.luau | 7 ++----- tests/video/mpegts.luau | 4 +--- tests/video/ogv.luau | 16 +++------------- tests/video/smk.luau | 11 +++-------- tests/video/y4m.luau | 9 +++------ 14 files changed, 37 insertions(+), 109 deletions(-) diff --git a/tests/video/_common.luau b/tests/video/_common.luau index cf5c1b4..354eaec 100644 --- a/tests/video/_common.luau +++ b/tests/video/_common.luau @@ -1,6 +1,4 @@ --- tests/video/_common: shared checks for the video container tests (mkv, avi, y4m, mpegts, mpegps, mp4): a demuxer's --- tracks and packets against ffprobe's, decoded frames against ffmpeg's (CRC-32 for bit-exact codecs, PSNR for the --- others), audio through the api's hook against ffmpeg's f32 decode, seeking. Not a test by itself. +-- tests/video/_common: shared checks for the video container tests against ffprobe / ffmpeg. Not a test by itself. local F = require("@rosetta") local Bytes = require("@rosetta/core/Bytes") local Crc32 = require("@rosetta/core/Crc32") @@ -11,7 +9,6 @@ local C = {} -- the codecs whose decode must equal ffmpeg's bit for bit C.EXACT = { vp8 = true, rawvideo = true } --- psnr(a, b, off?, n?) -> dB between two byte strings / buffers (math.huge when equal) function C.psnr(a: buffer, b: buffer, n: number?): number local len = n or math.min(buffer.len(a), buffer.len(b)) local se = 0 @@ -25,7 +22,6 @@ function C.psnr(a: buffer, b: buffer, n: number?): number return 10 * math.log10(255 * 255 * len / se) end --- snr(ours f32 buffer, reference f32 string, n samples) -> dB function C.snr(ours: buffer, ref: string, n: number): number local rb = buffer.fromstring(ref) local sig, err = 0, 0 @@ -41,8 +37,8 @@ function C.snr(ours: buffer, ref: string, n: number): number return 10 * math.log10(sig / err) end --- packets(t, dmx, c, label, opts?): every track's packets against ffprobe's (in order): size, CRC, time, keyframe. --- opts.skipStream(ffprobePacket, track) -> true skips a stream (ffmpeg's parsers re-split some, e.g. MPEG audio in TS) +-- every track's packets against ffprobe's (in order): size, CRC, time, keyframe. +-- opts.skipStream: ffmpeg's parsers re-split some streams, e.g. MPEG audio in TS function C.packets(t: any, dmx: any, c: any, label: string, opts: any?) local o = opts or {} local trackOf = {} -- ffprobe stream index -> our track @@ -85,7 +81,7 @@ function C.packets(t: any, dmx: any, c: any, label: string, opts: any?) t:check(extra == 0, label .. ": no extra packets (" .. extra .. ")") end --- frames(t, v, c, label): every decoded frame against ffmpeg's (CRC for EXACT codecs, else PSNR of the raw ones) +-- CRC for EXACT codecs, else PSNR of the raw frames function C.frames(t: any, v: any, c: any, label: string, minPsnr: number?) if not c.frames then return @@ -152,9 +148,8 @@ function C.audio(t: any, v: any, c: any, label: string, exact: boolean?, minSnr: end local n = got * a.channels t:check(n == want or n * 4 == c.pcmBytes, label .. ": " .. n .. " samples read of " .. want) - -- the whole stream: as long as ffmpeg's decode (priming and end padding trimmed the same way: MP4 edit lists). - -- Not yet for Matroska / WebM, where ffmpeg also cuts the end padding of the last packets (Vorbis, MP2: a few - -- hundred frames) and we do not. + -- the whole stream as long as ffmpeg's decode (priming and end padding trimmed the same way: MP4 edit lists). + -- Not for Matroska / WebM, where ffmpeg also cuts the last packets' end padding (Vorbis, MP2) and we do not. if c.pcmBytes and v.format ~= "mkv" and v.format ~= "webm" then local total = got while true do @@ -184,7 +179,6 @@ function C.audio(t: any, v: any, c: any, label: string, exact: boolean?, minSnr: end end --- seek(t, v, c, label, at): after seek(at) the next frame is the first at or after `at` function C.seek(t: any, v: any, c: any, label: string, at: number) if not (c.frames or c.rgba) or not Video.canDecode(v.codec) then return @@ -208,7 +202,6 @@ function C.seek(t: any, v: any, c: any, label: string, at: number) v:reset() end --- fuzzOpen(Fmt) -> a fuzz function: open, read every packet, decode up to 8 frames, read some audio function C.fuzzOpen(Fmt: any): (buffer) -> any return function(b: buffer): any local v = Fmt.open(Bytes.reader(b), { openAudio = function(d: any, tr: any): any @@ -234,7 +227,6 @@ function C.fuzzOpen(Fmt: any): (buffer) -> any end end --- open(data, opts?) -> VideoDecoder through the api (category video) function C.open(data: string, opts: any?): (any, any) return F.video.open(buffer.fromstring(data), opts) end diff --git a/tests/video/avi.luau b/tests/video/avi.luau index ae3e702..03d0655 100644 --- a/tests/video/avi.luau +++ b/tests/video/avi.luau @@ -1,7 +1,5 @@ --- video/avi tests: AVI files from ffmpeg (MJPEG + PCM s16 / u8 / IMA ADPCM, MPEG-1 + MP2, uncompressed BGR24 / BGRA / --- I420) read through the OpenDML indexes, idx1 alone, and a movi scan: tracks and every packet against ffprobe, --- frames against ffmpeg, audio through the api hook, seeking; our muxer (MJPEG + PCM) read back; a GIF converted to --- AVI. Fixtures: tools/fixtures/avi.py. +-- video/avi tests: AVI files from ffmpeg against ffprobe (packets) and ffmpeg (frames, audio); our muxer read back. +-- Fixtures: tools/fixtures/avi.py. local T = require("@tests/T") local C = require("@tests/video/_common") local F = require("@rosetta") @@ -87,7 +85,6 @@ do end end --- fuzz local samples = {} for _, n in { "mjpeg_pcm.avi", "mjpeg_ima.avi", "idx1_only.avi", "i420.avi" } do local d = byName[n].data diff --git a/tests/video/encode.luau b/tests/video/encode.luau index cbf1fcf..4b948de 100644 --- a/tests/video/encode.luau +++ b/tests/video/encode.luau @@ -1,8 +1,5 @@ --- video writer tests: files our muxers wrote (tools/fixtures/_video_encode.luau: WebM remux, MJPEG Matroska / AVI --- copied and re-encoded from VP8 / MPEG-1, an animated GIF with uneven delays to AVI / Matroska / Y4M, WebM to Y4M) --- were probed by ffprobe and decoded by ffmpeg at fixture time; here our demuxers must see the same packets, our --- decoders the same frames (CRC for VP8 / raw, PSNR for MJPEG) and audio; the writers are rerun and must give the same --- bytes. Fixtures: tools/fixtures/videoenc.py. +-- video writer tests: our muxers' files, probed by ffprobe and decoded by ffmpeg at fixture time, read back. +-- Fixtures: tools/fixtures/videoenc.py (tools/fixtures/_video_encode.luau). local T = require("@tests/T") local C = require("@tests/video/_common") local F = require("@rosetta") @@ -97,7 +94,6 @@ do end end --- the writers are deterministic: the same bytes again do local Mkv = require("@tests/gen/mkv_cases") local remux = byName["remux.webm"] diff --git a/tests/video/fli.luau b/tests/video/fli.luau index 3a15d84..b138e25 100644 --- a/tests/video/fli.luau +++ b/tests/video/fli.luau @@ -1,7 +1,5 @@ --- video/fli tests: FLI (COLOR_64, BRUN, LC, BLACK, COPY, PSTAMP, a ring frame), FLC (prefix chunk, COLOR_256, SS2 with --- line skips and the last-byte opcode, an empty frame), an odd-size FLC, and 15 / 16 / 24-bit FLCs (BRUN, DTA_BRUN, --- DELTA, DTA_LC, COPY, DTA_COPY, BLACK), all encoded by the fixture script: every frame equals ffmpeg's decode --- (CRC-32 of rgba), frame rates, the ring frame option, seeking, errors, the fuzz pass. Fixtures: tools/fixtures/fli.py. +-- video/fli tests: FLI / FLC files encoded by the fixture script; every frame equals ffmpeg's decode (CRC-32 of rgba). +-- Fixtures: tools/fixtures/fli.py. local T = require("@tests/T") local F = require("@rosetta") local Fli = require("@rosetta/video/fli") @@ -59,7 +57,6 @@ for _, c in Fx do end end --- errors do local _, e = Fli.open(reader(string.sub(Fx[1].data, 1, 100))) t:check(e ~= nil and e.code == Err.TRUNCATED, "short header: TRUNCATED") @@ -85,7 +82,7 @@ t:fuzz("open", function(b: buffer) end return v end, samples, { mutations = 12, garbage = 40, keepHeader = 16 }) --- the frame decoder itself (codecs/video/Legacy/Flic, native: no pcall in between) +-- the frame decoder itself (native: no pcall in between) local Flic = require("@rosetta/codecs/video/Legacy").Flic for _, c in { Fx[1], Fx[2], Fx[4], Fx[6] } do local d = Fli.demux(reader(c.data)) diff --git a/tests/video/flv.luau b/tests/video/flv.luau index 75f5c7a..e985608 100644 --- a/tests/video/flv.luau +++ b/tests/video/flv.luau @@ -1,10 +1,5 @@ --- video/flv tests: FLV files from ffmpeg (Sorenson Spark + MP3 / PCM s16 / PCM u8 / ADPCM / Nellymoser / Speex / --- A-law, H.264 with B-frames + AAC, Flash screen video, audio only): tracks and every packet against ffprobe --- (composition times in the pts, keyframes), onMetaData, frames against ffmpeg (Sorenson bit-exact, H.264 PSNR), audio --- through the api hook (PCM and Flash ADPCM mono / stereo exact against ffmpeg's adpcm_swf; Nellymoser / Speex known --- but UNSUPPORTED), seeking; crafted VP6 / enhanced FourCC / encrypted / truncated files; our writer (FLV, MP4, --- Matroska sources) read back by ffprobe and ffmpeg (tools/fixtures/flv.py) and by our demuxer with the source's --- packets; fuzz. Fixtures: tools/fixtures/flv.py. +-- video/flv tests: FLV files from ffmpeg against ffprobe / ffmpeg (Nellymoser, Speex, VP6: known but UNSUPPORTED). +-- Fixtures: tools/fixtures/flv.py. local T = require("@tests/T") local C = require("@tests/video/_common") local F = require("@rosetta") @@ -27,7 +22,6 @@ for _, c in Fx do byName[c.name] = c end --- every frame's CRC against ffmpeg's (codecs we decode bit-exactly), else PSNR local function frames(v: any, c: any, label: string) if v.codec == "flv1" then v:reset() @@ -88,7 +82,6 @@ for _, c in Fx do end end --- details: H.264 config and composition times, metadata, screen video size do local v = assert(C.open(byName["h264_aac.flv"].data)) local vt, at = v.demuxer:track("video"), v.demuxer:track("audio") @@ -110,8 +103,7 @@ do t:check(s.codec == "flashsv" and s.width == 64 and s.height == 48, "screen video: known codec, size from its first packet") end --- crafted files: VP6 (known, UNSUPPORTED, size from its key frame header), an enhanced FourCC tag, encrypted tags, --- truncation, not FLV +-- crafted files: VP6 (known, UNSUPPORTED, size from its key frame header), an enhanced FourCC tag, encrypted tags local function flv(tags: { { any } }): buffer local w = Bytes.writer(256) w:string("FLV") @@ -176,7 +168,6 @@ do t:check(e2 ~= nil and e2.code == F.Err.CORRUPT, "not FLV: CORRUPT") end --- our writer: read back by ffprobe / ffmpeg (fixtures) and by our demuxer, packets equal to the source's local SOURCES = { mp4 = Src.mp4, mkv = Src.mkv, ts = Src.ts } for _, c in Mx do local label = "write " .. c.name @@ -193,7 +184,6 @@ for _, c in Mx do if at then C.audio(t, v, c, label, EXACT_AUDIO[at.codec], 30) end - -- the source's packets, byte for byte local src = assert(C.open(SOURCES[c.source] or byName[c.source].data)) local a, b = src.demuxer, v.demuxer local same = true @@ -226,7 +216,6 @@ for _, c in Mx do end end --- fuzz local samples = {} for _, n in { "sorenson_mp3.flv", "h264_aac.flv", "sorenson_pcm.flv", "screen.flv" } do local d = byName[n].data diff --git a/tests/video/h264.luau b/tests/video/h264.luau index 2e46af4..aa9996c 100644 --- a/tests/video/h264.luau +++ b/tests/video/h264.luau @@ -1,7 +1,5 @@ --- video/h264 tests: H.264 through F.video.open end to end: raw Annex B (.h264, the video/h264 format), MP4 and MKV --- (avcC + length-prefixed samples) and MPEG-TS / AVI (Annex B packets) written by ffmpeg / libx264, frames bit-exact --- against ffmpeg's decode of each file; display-order timestamps; the raw writer (MP4 -> .h264) read back; sniffing; --- the fuzz no-throw pass on the raw demuxer. Fixtures: tools/fixtures/h264.py (h264_containers). +-- video/h264 tests: H.264 by ffmpeg / libx264 in raw Annex B, MP4, MKV, MPEG-TS and AVI, bit-exact against ffmpeg. +-- Fixtures: tools/fixtures/h264.py (h264_containers). local T = require("@tests/T") local F = require("@rosetta") local Fmt = require("@rosetta/video/h264") @@ -50,7 +48,6 @@ for _, c in Cases do end end --- raw format directly: sniff, demux, 25 fps output order do local c = byName["cabac_b.h264"] local r = Bytes.reader(buffer.fromstring(c.data)) @@ -63,7 +60,6 @@ do t:check(#got == #c.frames and math.abs(got[2].pts - 1 / 25) < 1e-9, "raw: pts in output order at 25 fps") end --- writer: the MP4's H.264 track as a raw Annex B stream, decoded again for _, src in { "cabac_b.mp4", "baseline.mkv", "baseline.ts" } do local c = byName[src] local v = F.video.open(c.data) @@ -83,7 +79,6 @@ for _, src in { "cabac_b.mp4", "baseline.mkv", "baseline.ts" } do end end --- fuzz: the raw demuxer + decoder local samples = { byName["baseline.h264"].data, byName["cabac_b.h264"].data } t:fuzz("open + frames", function(b: buffer) local v = Fmt.open(Bytes.reader(b), { maxPixels = 2 ^ 18 }) diff --git a/tests/video/mkv.luau b/tests/video/mkv.luau index 16faa15..b121cef 100644 --- a/tests/video/mkv.luau +++ b/tests/video/mkv.luau @@ -1,8 +1,5 @@ --- video/mkv tests: Matroska / WebM files from ffmpeg and mkvmerge (VP8 + Opus / Vorbis, MJPEG + PCM, MPEG-1 + MP2, --- VP8 + FLAC, srt subtitles, Xiph / EBML / fixed lacing, zlib compression, unknown-size clusters, a truncated file): --- tracks and every packet against ffprobe, frames against ffmpeg (bit-exact VP8, PSNR for MJPEG / MPEG-1), audio --- through the api hook against ffmpeg, seeking, subtitles; our muxer's output (remux and MJPEG) read back. Fixtures: --- tools/fixtures/mkv.py. +-- video/mkv tests: Matroska / WebM files from ffmpeg and mkvmerge against ffprobe / ffmpeg; our muxer read back. +-- Fixtures: tools/fixtures/mkv.py. local T = require("@tests/T") local C = require("@tests/video/_common") local F = require("@rosetta") @@ -13,7 +10,6 @@ local Fx = require("@tests/gen/mkv_cases") local t = T.suite("mkv") --- 1. contract t:eq(Mkv.name, "mkv", "name") t:eq(Mkv.category, "video", "category") t:check(table.find(Mkv.extensions, "webm") ~= nil, "webm extension") @@ -24,7 +20,6 @@ for _, c in Fx do byName[c.name] = c end --- 2. every fixture for _, c in Fx do local label = c.name t:check(Mkv.sniff(Bytes.reader(buffer.fromstring(c.data))) > 0, label .. ": sniff") @@ -68,7 +63,6 @@ for _, c in Fx do end end --- 3. specific files do local v = C.open(byName["vp8_opus.webm"].data) t:eq(v.format, "webm", "webm: format") @@ -98,7 +92,6 @@ do t:eq(F.format("webm").name, "mkv", "format(webm) is mkv") end --- 4. our muxer: remux WebM (VP8 + Opus copied) and read it back packet for packet do local src = byName["vp8_opus.webm"] local v = C.open(src.data) @@ -126,7 +119,6 @@ do t:check(bad == nil and berr ~= nil and berr.code == Err.UNSUPPORTED, "webm refuses MJPEG: " .. tostring(berr)) end --- 5. errors and the fuzz pass local e1 = select(2, Mkv.open(Bytes.reader(buffer.fromstring("\26\69\223\163\128")))) t:check(e1 ~= nil, "empty EBML header fails") local samples = {} diff --git a/tests/video/mp4.luau b/tests/video/mp4.luau index 045a9d6..207f8e2 100644 --- a/tests/video/mp4.luau +++ b/tests/video/mp4.luau @@ -1,7 +1,5 @@ --- video/mp4 tests: MP4 / MOV files from ffmpeg (MJPEG + AAC / PCM / FLAC / MP2, H.264 with B-frames and edit lists + --- AAC, fragmented MP4, MPEG-1 + Opus): tracks and every packet against ffprobe (pts moved by the edit lists, as ffmpeg), --- frames against ffmpeg (PSNR), audio through the api hook (AAC priming dropped), seeking, our MP4 / MOV writer read --- back, the H.264 yield hook and maxSide, fuzz. Fixtures: tools/fixtures/mp4.py. +-- video/mp4 tests: MP4 / MOV files from ffmpeg against ffprobe (pts moved by edit lists, as ffmpeg) and ffmpeg. +-- Fixtures: tools/fixtures/mp4.py. local T = require("@tests/T") local C = require("@tests/video/_common") local F = require("@rosetta") @@ -36,7 +34,6 @@ for _, c in Fx do end end --- our writer: MP4 (MJPEG + AAC copied) and MOV (MJPEG + PCM) read back packet for packet for _, job in { { "mjpeg_aac.mp4", "mp4" }, { "mjpeg_pcm.mov", "mov" }, { "h264_aac.mp4", "mp4" } } do local src = byName[job[1]] local v = C.open(src.data) @@ -76,8 +73,7 @@ for _, job in { { "mjpeg_aac.mp4", "mp4" }, { "mjpeg_pcm.mov", "mov" }, { "h264_ end end --- H.264 with the cooperative yield hook (decoding inside a coroutine that yields at every hook call: the same pictures) --- and maxSide (frames shrunk to the longer side, aspect kept) +-- the yield hook (decoding in a coroutine that yields at every hook call) gives the same pictures do local Crc32 = require("@rosetta/core/Crc32") local data = byName["h264_aac.mp4"].data diff --git a/tests/video/mpeg2.luau b/tests/video/mpeg2.luau index 0e5a7cb..13e43e3 100644 --- a/tests/video/mpeg2.luau +++ b/tests/video/mpeg2.luau @@ -1,7 +1,5 @@ --- MPEG-2 video in the containers (tools/fixtures/mpeg2.py, "mpeg2_containers"): the same elementary stream copied by --- ffmpeg into MPEG-TS (stream type 0x02, and the PMT patched to 0x80, private / DigiCipher II video), MPEG-PS (VOB), --- Matroska (V_MPEG2) and AVI: each opens through F.video.open with codec "mpeg2", its frames equal ffmpeg's --- `-idct int` decode (luma CRC per frame, display order), seeking lands on a frame; the raw .m2v opens too. +-- MPEG-2 video in MPEG-TS (stream types 0x02, 0x80), MPEG-PS, Matroska and AVI against ffmpeg's `-idct int` decode. +-- Fixtures: tools/fixtures/mpeg2.py (mpeg2_containers). local T = require("@tests/T") local F = require("@rosetta") local Base64 = require("@rosetta/core/Base64") @@ -54,7 +52,6 @@ for _, c in CASES do end end --- the elementary stream itself do local v, err = F.video.open(Base64.decode(Prog.file) :: buffer) t:check(v ~= nil and v.codec == "mpeg2", "m2v: opens as mpeg2: " .. tostring(err)) diff --git a/tests/video/mpegps.luau b/tests/video/mpegps.luau index bd6be3b..a3a9f1b 100644 --- a/tests/video/mpegps.luau +++ b/tests/video/mpegps.luau @@ -1,7 +1,5 @@ --- video/mpegps tests: program streams from ffmpeg (MPEG-1 system stream, B-frames, MPEG-2 PS / VOB packs, a raw .m1v --- elementary stream): tracks, picture packets (count and timestamps against ffmpeg's frames), frames against ffmpeg --- (PSNR) once an MPEG-1 decoder is registered, audio through the api hook (SNR), seeking, fuzz. Fixtures: --- tools/fixtures/mpegts.py. +-- video/mpegps tests: program streams from ffmpeg against ffmpeg's frames (timestamps, PSNR) and audio (SNR). +-- Fixtures: tools/fixtures/mpegts.py. local T = require("@tests/T") local C = require("@tests/video/_common") local Ps = require("@rosetta/video/mpegps") @@ -21,7 +19,6 @@ for _, c in Fx do local vt = dmx:track("video") t:check(vt ~= nil and vt.codec == "mpeg1", label .. ": an MPEG-1 video track") t:eq(dmx:count(vt.id), #c.frames, label .. ": one packet per picture") - -- presentation times: one per frame slot local seen, ok = {}, true for k = 1, dmx:count(vt.id) do local pts = dmx:info(vt.id, k) diff --git a/tests/video/mpegts.luau b/tests/video/mpegts.luau index 1b13a71..2b85b67 100644 --- a/tests/video/mpegts.luau +++ b/tests/video/mpegts.luau @@ -1,6 +1,4 @@ --- video/mpegts tests: transport streams from ffmpeg (MPEG-1 + MP2, B-frames, H.264 + AAC, M2TS, garbage before the --- first packet, a truncated file): tracks and the video packets against ffprobe (time, size, CRC, keyframe), frames --- against ffmpeg (PSNR) once an MPEG-1 decoder is registered, audio through the api hook (SNR), seeking, fuzz. +-- video/mpegts tests: transport streams from ffmpeg against ffprobe (video packets) and ffmpeg (frames, audio). -- Fixtures: tools/fixtures/mpegts.py. local T = require("@tests/T") local C = require("@tests/video/_common") diff --git a/tests/video/ogv.luau b/tests/video/ogv.luau index 88dbdeb..89b91ee 100644 --- a/tests/video/ogv.luau +++ b/tests/video/ogv.luau @@ -1,8 +1,5 @@ --- video/ogv tests: Ogg Theora files from ffmpeg (libtheora + libvorbis; tools/fixtures/theora.py): sniffing (Theora --- BOS pages, plain Ogg Vorbis left to the audio formats), tracks, granule times, every frame through F.video.open --- bit-exact with ffmpeg's (Adler-32 of yuv420p, its framecrc), an empty packet (a repeated frame), the Vorbis track --- through the api's audio hook against ffmpeg's decode, tags, seeking, remuxing (ogv -> ogv, mkv -> ogv, ogv -> mkv) --- read back, errors and the fuzz no-throw pass. +-- video/ogv tests: Ogg Theora from ffmpeg (libtheora + libvorbis), bit-exact with its framecrc (Adler-32 of yuv420p). +-- Fixtures: tools/fixtures/theora.py. local T = require("@tests/T") local C = require("@tests/video/_common") local F = require("@rosetta") @@ -27,8 +24,7 @@ local function file(fx: any): buffer return Base64.decode(fx.file) :: buffer end --- every frame of a VideoDecoder against ffmpeg's framecrc (yuv420p, keyed by frame number); frames ffmpeg does not --- show (empty packets) must repeat the previous one +-- frames ffmpeg does not show (empty packets) must repeat the previous one local function frames(v: any, fx: any, label: string, fps: number) local want: { [number]: number } = {} for _, f in fx.frames do @@ -59,7 +55,6 @@ local function frames(v: any, fx: any, label: string, fps: number) return n end --- 1. contract and sniffing t:eq(Ogv.name, "ogv", "name") t:eq(Ogv.category, "video", "category") t:check(table.find(Ogv.extensions, "ogv") ~= nil, "ogv extension") @@ -68,7 +63,6 @@ t:eq(Ogv.sniff(Bytes.reader(file(Q0))), 1, "sniff: Theora") t:eq(Ogv.sniff(Bytes.reader(buffer.fromstring("OggS\0\2" .. string.rep("\0", 40)))), 0, "sniff: an Ogg page without Theora") t:eq(Ogv.sniff(Bytes.reader(buffer.fromstring("RIFF"))), 0, "sniff: not Ogg") --- 2. Theora + Vorbis through the api local v, err = F.video.open(file(AV)) t:check(v ~= nil, "open: " .. tostring(err)) if v then @@ -90,7 +84,6 @@ if v then frames(v, AV, "av", 25) local pcm = Base64.decode(AV.pcm) :: buffer C.audio(t, v, { pcm = buffer.tostring(pcm) }, "av", false, 20) - -- seeking v:seek(0.5) local f = v:nextFrame() t:check(f ~= nil and f.pts >= 0.5 - 1e-6 and f.pts < 0.6, "seek 0.5 -> " .. tostring(f and f.pts)) @@ -103,7 +96,6 @@ if v then end t:eq(Adler32.of(f.image.pixels, nil, nil, 0), want, "the frame after seeking equals ffmpeg's") end - -- remux ogv -> ogv v:reset() local out, rerr = F.save(v, nil, { format = "ogv" }) t:check(out ~= nil, "remux: " .. tostring(rerr)) @@ -116,7 +108,6 @@ if v then C.audio(t, v2, { pcm = buffer.tostring(pcm) }, "remux", false, 20) end end - -- remux ogv -> mkv (V_THEORA) v:reset() local mk, merr = F.save(v, nil, { format = "mkv" }) t:check(mk ~= nil, "to mkv: " .. tostring(merr)) @@ -205,7 +196,6 @@ do t:check(vc ~= nil, "a truncated file opens") end --- 7. fuzz t:fuzz("open", C.fuzzOpen(Ogv), { buffer.tostring(file(Q0)) }, { mutations = 16, garbage = 50 }) t:done() diff --git a/tests/video/smk.luau b/tests/video/smk.luau index 4f1556b..ef97469 100644 --- a/tests/video/smk.luau +++ b/tests/video/smk.luau @@ -1,8 +1,5 @@ --- video/smk tests: Smacker files encoded by the fixture script (SMK2 and SMK4, every block type and run, the trees' --- escape cache, palette updates, a ring frame, ms and 10 us frame times; packed 16-bit stereo / 8-bit mono / 16-bit --- mono / 8-bit stereo audio and raw s16le / u8 tracks): every video frame and every audio track equal ffmpeg's --- decode (CRC-32 of rgba / f32le), audio seeking, errors, and the fuzz pass on the container, the video codec and the --- audio codec. Fixtures: tools/fixtures/smk.py. +-- video/smk tests: Smacker files by the fixture script; video and audio equal ffmpeg's decode (CRC-32 of rgba / f32le). +-- Fixtures: tools/fixtures/smk.py. local T = require("@tests/T") local F = require("@rosetta") local Smk = require("@rosetta/video/smk") @@ -21,7 +18,6 @@ local function reader(s: string): Bytes.Reader return Bytes.reader(buffer.fromstring(s)) end --- every frame of an audio Decoder -> f32 buffer, frames local function drain(dec: any): (buffer, number) local chunks, total = {}, 0 while true do @@ -118,7 +114,6 @@ for _, c in Fx do end end --- errors do local _, e = Smk.open(reader(string.sub(Fx[1].data, 1, 60))) t:check(e ~= nil and e.code == Err.TRUNCATED, "short header: TRUNCATED") @@ -131,7 +126,7 @@ do t:check(e4 ~= nil and e4.code == Err.TRUNCATED, "trees past the end: TRUNCATED") end --- fuzz: the container, the video codec (native, no pcall in between) and the audio codec +-- fuzz: the video codec is native, no pcall in between local samples = {} for _, c in Fx do table.insert(samples, c.data) diff --git a/tests/video/y4m.luau b/tests/video/y4m.luau index f256b03..8902ffd 100644 --- a/tests/video/y4m.luau +++ b/tests/video/y4m.luau @@ -1,7 +1,5 @@ --- video/y4m tests: YUV4MPEG2 streams from ffmpeg (C420jpeg at an odd size, C420mpeg2, C422, C444, Cmono, C420p10) --- against ffmpeg's yuv420p decode (bit-exact for 4:2:0 8-bit, PSNR for the converted layouts), the header fields, --- our writer round trip (and from an rgba frames-backed video), errors and the fuzz pass. Fixtures: --- tools/fixtures/y4m.py. +-- video/y4m tests: YUV4MPEG2 from ffmpeg against its yuv420p decode (bit-exact for 4:2:0 8-bit, else PSNR). +-- Fixtures: tools/fixtures/y4m.py. local T = require("@tests/T") local C = require("@tests/video/_common") local F = require("@rosetta") @@ -47,7 +45,7 @@ for _, c in Fx do end end --- writer: a y4m stream back to y4m is byte-identical in its frames; header as ffmpeg writes it +-- header as ffmpeg writes it do local c = Fx[1] local v = F.video.open(buffer.fromstring(c.data)) @@ -86,7 +84,6 @@ do end end --- errors local function code(s: string): string? local _, e = Y4m.open(Bytes.reader(buffer.fromstring(s))) return e and e.code From cbd994131888ac63f470c0c19e7e854a5eabc081 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:49:54 -0500 Subject: [PATCH 13/25] examples: headers within 120 columns --- examples/archive.luau | 2 +- examples/layered.luau | 2 +- examples/playlist.luau | 2 +- examples/video.luau | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/archive.luau b/examples/archive.luau index a2c372c..637aa80 100644 --- a/examples/archive.luau +++ b/examples/archive.luau @@ -1,4 +1,4 @@ --- examples/archive.luau: build, read and edit a zip, convert it to .tar.gz and back, gzip a file (docs/guide/archive.md). +-- examples/archive.luau: build, read and edit a zip, convert to .tar.gz and back, gzip a file (docs/guide/archive.md). local F = require("@rosetta") -- a new zip: a directory, a text file, an incompressible file stored as is diff --git a/examples/layered.luau b/examples/layered.luau index 8691935..74bb66a 100644 --- a/examples/layered.luau +++ b/examples/layered.luau @@ -1,4 +1,4 @@ --- examples/layered.luau: build a layered document, flatten it, save PSD and Aseprite, export a GIF (docs/guide/layered.md). +-- examples/layered.luau: build a layered document, flatten it, save PSD and Aseprite, make a GIF (docs/guide/layered.md). local F = require("@rosetta") local I, L = F.ops.image, F.Types.Layered diff --git a/examples/playlist.luau b/examples/playlist.luau index cb38c67..28dea25 100644 --- a/examples/playlist.luau +++ b/examples/playlist.luau @@ -1,4 +1,4 @@ --- examples/playlist.luau: read an M3U, inspect an HLS master playlist, convert to PLS and XSPF (docs/guide/playlist.md). +-- examples/playlist.luau: read an M3U, inspect an HLS master playlist, convert to PLS, XSPF (docs/guide/playlist.md). local F = require("@rosetta") local M3U = "#EXTM3U\n#PLAYLIST:Road Trip\n#EXTINF:215,Ada - First Song\nmusic/first.mp3\n" diff --git a/examples/video.luau b/examples/video.luau index be70380..6a4180e 100644 --- a/examples/video.luau +++ b/examples/video.luau @@ -1,4 +1,4 @@ --- examples/video.luau: write frames as an MJPEG AVI, open it, walk packets and frames, seek, make a GIF (docs/guide/video.md). +-- examples/video.luau: write an MJPEG AVI, open it, walk packets and frames, seek, make a GIF (docs/guide/video.md). local F = require("@rosetta") local I = F.ops.image From e306d5c1d7b5878d29e5d09df26e495096a00732 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:49:58 -0500 Subject: [PATCH 14/25] examples/layered: header width --- examples/layered.luau | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/layered.luau b/examples/layered.luau index 74bb66a..447c7b8 100644 --- a/examples/layered.luau +++ b/examples/layered.luau @@ -1,4 +1,4 @@ --- examples/layered.luau: build a layered document, flatten it, save PSD and Aseprite, make a GIF (docs/guide/layered.md). +-- examples/layered.luau: build a layered document, flatten it, save PSD and Aseprite, a GIF (docs/guide/layered.md). local F = require("@rosetta") local I, L = F.ops.image, F.Types.Layered From a80299dce0d1567e4626d357d9904d47c2bb7697 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:50:18 -0500 Subject: [PATCH 15/25] tests/image: comments: specs only --- tests/image/_raster.luau | 8 +------- tests/image/ani.luau | 5 +---- tests/image/apng.luau | 11 +---------- tests/image/blp.luau | 6 +----- tests/image/bmp.luau | 20 +------------------- tests/image/dds.luau | 9 +-------- tests/image/exr.luau | 10 +--------- tests/image/gif.luau | 14 +------------- tests/image/hdr.luau | 8 +------- tests/image/icns.luau | 6 +----- tests/image/ico.luau | 7 +------ tests/image/ilbm.luau | 5 +---- tests/image/jpeg.luau | 14 ++------------ tests/image/ktx.luau | 8 +------- tests/image/pcx.luau | 4 +--- tests/image/png.luau | 12 +----------- tests/image/pnm.luau | 8 +------- tests/image/qoi.luau | 7 +------ tests/image/sgi.luau | 3 +-- tests/image/sunras.luau | 3 +-- tests/image/tga.luau | 7 +------ tests/image/tiff.luau | 13 +------------ tests/image/tim.luau | 13 +++++-------- tests/image/vtf.luau | 5 +---- tests/image/webp.luau | 16 +--------------- tests/image/xbm.luau | 4 +--- tests/image/xpm.luau | 5 +---- 27 files changed, 32 insertions(+), 199 deletions(-) diff --git a/tests/image/_raster.luau b/tests/image/_raster.luau index f95e211..c63a1af 100644 --- a/tests/image/_raster.luau +++ b/tests/image/_raster.luau @@ -1,5 +1,4 @@ --- tests/image/_raster: the shared checks of the simple raster formats' tests (pcx, sgi, sunras, xbm, xpm, ilbm, icns, --- ani): decode every case against its reference rgba8 pixels, round-trip images through the encoder, fuzz samples. +-- shared checks of the simple raster formats' tests: decode against reference rgba8, round trips, fuzz samples. local Bytes = require("@rosetta/core/Bytes") local Types = require("@rosetta/Types") @@ -17,7 +16,6 @@ local function maxDiff(a: buffer, b: buffer, n: number): (number, number) end R.maxDiff = maxDiff --- cases: { { name, data, w, h, rgba, tol? } } (rgba: the reference decode) function R.decodes(t: any, Fmt: any, cases: { any }, opts: any?): number local n = 0 for _, c in cases do @@ -31,7 +29,6 @@ function R.decodes(t: any, Fmt: any, cases: { any }, opts: any?): number end n += 1 end - -- from inside a bigger buffer local big = buffer.create(#c.data + 9) buffer.writestring(big, 5, c.data) local img2 = Fmt.decode(Bytes.reader(big, 5, #c.data), opts) @@ -40,14 +37,12 @@ function R.decodes(t: any, Fmt: any, cases: { any }, opts: any?): number return n end --- image(w, h, rgba string) -> Types.Image function R.image(w: number, h: number, rgba: string): Types.Image local img = Types.Image.new(w, h) img.pixels = buffer.fromstring(rgba) return img end --- roundTrip(t, Fmt, img, encodeOpts?, label, tol?) -> the encoded buffer function R.roundTrip(t: any, Fmt: any, img: Types.Image, eopts: any?, label: string, tol: number?): buffer? local enc, err = Fmt.encode(img, eopts) t:check(enc, label .. ": encode " .. tostring(err)) @@ -64,7 +59,6 @@ function R.roundTrip(t: any, Fmt: any, img: Types.Image, eopts: any?, label: str return enc end --- samples(cases, every?) -> the fuzz samples (every n-th case's data) function R.samples(cases: { any }, every: number?): { string } local samples = {} for i, c in cases do diff --git a/tests/image/ani.luau b/tests/image/ani.luau index d0262a2..0df0794 100644 --- a/tests/image/ani.luau +++ b/tests/image/ani.luau @@ -1,6 +1,4 @@ --- image/ani tests: animated cursors around Pillow-written ICO / CUR frames (seq + rate, plain, cursor hotspots, INFO --- title) against Pillow's frame decodes and the written steps / delays; AF_ICON clear and a missing hook are --- UNSUPPORTED; the encoder through the ICO hook round-trips; the fuzz no-throw pass. Fixtures: tools/fixtures/ani.py. +-- image/ani tests against Pillow (tools/fixtures/ani.py). local T = require("@tests/T") local Ani = require("@rosetta/image/ani") local Ico = require("@rosetta/image/ico") @@ -47,7 +45,6 @@ for _, c in Fx.cases do if c.hotspot then t:check(img.meta.hotspot and img.meta.hotspot.x == c.hotspot[1] and img.meta.hotspot.y == c.hotspot[2], c.name .. ": hotspot") end - -- re-encode through the ICO hook local enc, eerr = Ani.encode(img, hooks) t:check(enc, c.name .. ": encode " .. tostring(eerr)) local back = Ani.decode(Bytes.reader(enc :: buffer), hooks) :: any diff --git a/tests/image/apng.luau b/tests/image/apng.luau index a28870d..2db0dd2 100644 --- a/tests/image/apng.luau +++ b/tests/image/apng.luau @@ -1,7 +1,4 @@ --- image/png APNG tests: animated PNGs from ffmpeg's encoder and hand-written ones (every dispose / blend op, sub-rects, --- palette + tRNS, grey, RGB, a hidden default image) decoded into frames and composited, compared with ffmpeg's --- composited canvases (CRC-32); the APNG encoder's round trips; bad sequence numbers / rectangles; the fuzz pass. --- Fixtures: tools/fixtures/apng.py. +-- image/png APNG tests against ffmpeg's composited canvases (tools/fixtures/apng.py). local T = require("@tests/T") local Png = require("@rosetta/image/png") local Bytes = require("@rosetta/core/Bytes") @@ -65,7 +62,6 @@ for _, c in Cases do for i, want in c.crcs do t:eq(canvasCrc(canv[i].pixels, c.opaque), want, c.name .. ": composited frame " .. i .. (if c.ffmpeg then " vs ffmpeg" else " vs reference")) end - -- round trip through the encoder: the same frames, rectangles, ops, delays, loops and default image local enc, eerr = Png.encode(img) t:check(enc, c.name .. ": encode " .. tostring(eerr)) local back, berr = Png.decode(Bytes.reader(enc :: buffer), { checkCrc = true }) @@ -82,7 +78,6 @@ for _, c in Cases do end t:note("%d APNGs match the reference canvases and round-trip", #Cases) --- encoder: frames built here (sub-rects, delays in seconds), opts.apng, validation do local function solid(w: number, h: number, r: number, g: number, b: number, a: number): Types.Image local im = Types.Image.new(w, h) @@ -112,13 +107,11 @@ do t:eq(buffer.readu8(canv[2].pixels, o + 3), 255, "over: alpha") t:eq(buffer.readu8(canv[2].pixels, o), (128 * 200 + 127 * 10 + 128) * 257 // 65536, "over: red") t:eq(buffer.readu32(canv[3].pixels, o), 0, "background dispose cleared frame 2's rect") - -- one frame + opts.apng; a still image stays a PNG local still = solid(4, 4, 1, 2, 3, 255) local plain = decode(Png.encode(still) :: buffer) t:check(plain.frames == nil, "still image: no acTL") local one = decode(Png.encode(still, { apng = true }) :: buffer) t:check(one.frames and #one.frames == 1 and same(one.frames[1].image, still), "opts.apng: a one-frame APNG") - -- bad frames local function bad(frames: any, label: string) local im = solid(4, 4, 0, 0, 0, 255) im.frames = frames @@ -132,7 +125,6 @@ do bad({ { image = still }, { image = still, delay = -1 } }, "negative delay") end --- crafted bad input: a broken sequence number, a frame outside the canvas do local c = Cases[1] local s = c.data @@ -153,7 +145,6 @@ do t:check(Png.composite({} :: any) == nil, "composite of a non-image") end --- fuzz do local samples = {} for _, c in Cases do diff --git a/tests/image/blp.luau b/tests/image/blp.luau index 505e335..67e2c6a 100644 --- a/tests/image/blp.luau +++ b/tests/image/blp.luau @@ -1,7 +1,4 @@ --- image/blp tests: BLP1 / BLP2 palette files written by Pillow and DXT1 / DXT3 / DXT5 / palette-with-alpha files --- written by tools/fixtures/blp.py decode to Pillow's RGBA; BLP1 JPEG (3 components) to Pillow's, 4 components (BGRA) --- within a PSNR of the source; BLP2 BGRA and BLP1 palette + alpha against the writer; our BLP2 writer round-trips --- (with mips); errors; the fuzz pass. Fixtures: tools/fixtures/blp.py. +-- image/blp tests against Pillow and the fixture writer (tools/fixtures/blp.py). local T = require("@tests/T") local F = require("@rosetta") local Blp = require("@rosetta/image/blp") @@ -61,7 +58,6 @@ for _, c in Fx do else t:check(buffer.tostring(img.pixels) == c.rgba, c.name .. ": pixels against the writer") end - -- our writer: BLP2 BGRA, lossless local enc = Blp.encode(img, { mips = true }) :: buffer local back = Blp.decode(Bytes.reader(enc)) :: any t:eq(Crc32.of(back.pixels), Crc32.of(img.pixels), c.name .. ": BLP2 BGRA round trip") diff --git a/tests/image/bmp.luau b/tests/image/bmp.luau index 45c1301..40cc1c5 100644 --- a/tests/image/bmp.luau +++ b/tests/image/bmp.luau @@ -1,8 +1,4 @@ --- image/bmp tests: synthesized BMPs (every header type, bit depth and compression, row order, palettes, masks and alpha --- rules, the RLE escapes, the lenient paths, errors), the BMP Suite against Pillow (g/ must match, q/ and b/ must not --- throw), the encoder byte-exact against Pillow (24 bpp, 8 bpp paletted, 32 bpp BI_RGB) plus the V4 alpha header and --- round trips (the V4 output was also checked by hand: Pillow and ImageMagick read the same RGBA), the api, and the --- fuzz passes. Ported from bmp-luau tests/core.luau + tests/files.luau. +-- image/bmp tests: synthesized BMPs, the BMP Suite against Pillow (g/ must match, q/ and b/ must not throw). -- Fixtures: tools/fixtures/bmp.py. local T = require("@tests/T") local BmpF = require("@rosetta/image/bmp") @@ -19,8 +15,6 @@ local function check(cond: any, label: string) t:check(cond, label) end --- the bmp-luau API on top of the contract (the ported tests below use it): decode(string | buffer) -> image with the --- old fields | nil, message local Bmp = {} function Bmp.decode(s: any, opts: any?): (any, any) local b = if type(s) == "string" then buffer.fromstring(s) else s @@ -59,8 +53,6 @@ local function i32(v: number): string return le(if v < 0 then v + 4294967296 else v, 4) end --- Builds a BMP. o: w, h (negative = top-down), bpp, comp, hs (12, 40, 52, 56, 108, 124), palette ({ {r,g,b} }), --- clrUsed, masks ({r,g,b[,a]}: in the header for hs >= 52, else after it), pixels (string), off / bfSize overrides. local function make(o): string local hs = o.hs or 40 local hdr @@ -130,7 +122,6 @@ do check(td.topDown and td.height == 2, "top-down fields") is(td, 0, 0, 255, 0, 0, 255, "top-down first row on top") is(td, 0, 1, 255, 255, 255, 255, "top-down second row") - -- string and buffer input are the same local b = Bmp.decode(buffer.fromstring(make({ w = 3, h = 2, bpp = 24, pixels = bottom .. top }))) check(b and buffer.tostring(b.pixels) == buffer.tostring(img.pixels), "buffer input") end @@ -210,7 +201,6 @@ do is(img5, 0, 0, 255, 131, 8, 255, "v4 BI_RGB 16 -> 555") end --- 32 bpp do -- BI_RGB, alpha bytes all zero -> opaque local img = decode(make({ w = 2, h = 1, bpp = 32, pixels = "\1\2\3\0\4\5\6\0" }), "rgb32 zero alpha") @@ -311,7 +301,6 @@ do is(t2, 3, 3, 0, 0, 0, 255, "no pixel data: index 0") end --- info / isBmp do local s = make({ hs = 124, w = 7, h = -5, bpp = 32, comp = 3, masks = { 0xFF0000, 0xFF00, 0xFF, 0xFF000000 }, pixels = "" }) local info = Bmp.info(s) @@ -347,7 +336,6 @@ do fails(make({ w = 100, h = 100, bpp = 24, pixels = "" }), "too large", "maxPixels option", { maxPixels = 9999 }) end --- fuzz: truncations and byte flips of every kind of file above must never throw do local seeds = { make({ w = 3, h = 2, bpp = 24, pixels = string.rep("\1\2\3", 8) }), @@ -387,8 +375,6 @@ do t:note("fuzz: %d decodes, no throw", runs) end - --- ------------------------------------------------------------------------------------------------ the BMP Suite do local nMatch, nOther = 0, 0 local samples = {} @@ -413,7 +399,6 @@ do end, samples, { mutations = 6 }) end --- ------------------------------------------------------------------------------------------------ encoder do for _, c in Enc do local img = Types.Image.new(c.w, c.h) @@ -438,7 +423,6 @@ do end end t:note("encoder: %d files identical to Pillow", #Enc) - -- forced depths, dpi, errors local img = Types.Image.new(5, 4) for i = 0, 19 do buffer.writeu32(img.pixels, i * 4, 0xFF000000 + i * 0x010203) @@ -462,14 +446,12 @@ do t:check(e2 and e2.code == Err.ARG, "not an image") local _, e3 = BmpF.encode(img, { bitDepth = 16 } :: any) t:check(e3 and e3.code == Err.ARG, "bitDepth 16") - -- the api local c = Enc[1] local loaded = F.image.load(c.bmp) t:check(loaded and loaded.width == c.w and buffer.tostring(loaded.pixels) == c.rgba, "F.image.load") t:eq(F.detect(c.bmp), "bmp", "F.detect") local saved = F.save(loaded, nil, { format = "bmp" }) t:check(saved and buffer.tostring(saved) == c.bmp, "F.save bmp") - -- a sub-range reader local big = buffer.create(#c.bmp + 5) buffer.writestring(big, 3, c.bmp) local sub = BmpF.decode(Bytes.reader(big, 3, #c.bmp)) :: any diff --git a/tests/image/dds.luau b/tests/image/dds.luau index 4ac16ef..b598940 100644 --- a/tests/image/dds.luau +++ b/tests/image/dds.luau @@ -1,7 +1,4 @@ --- image/dds tests: files from NVIDIA Texture Tools (BGRA, BC1..BC7 incl. BC6H, mips, DX10, cube / array / volume) --- and ImageMagick against every surface's reference decode (Pillow per surface, Godot floats for BC6H); hand-written --- uncompressed DXGI / legacy / FourCC formats against their values (rgba8 and native floats); our encoder's files read --- by Pillow and nvddsinfo, and round trips; errors; the fuzz no-throw pass. Fixtures: tools/fixtures/dds.py. +-- image/dds tests against NVIDIA Texture Tools, ImageMagick, Pillow and Godot (BC6H floats) (tools/fixtures/dds.py). local T = require("@tests/T") local Dds = require("@rosetta/image/dds") local Bytes = require("@rosetta/core/Bytes") @@ -26,7 +23,6 @@ local function maxDiff(a: buffer, b: buffer, n: number): number return worst end --- tool-written files local surfaces = 0 for _, c in Fx.cases do local img, err = dec(c.data, { mips = true }) @@ -70,7 +66,6 @@ for _, c in Fx.cases do end t:note("%d tool-written files, %d surfaces match the references", #Fx.cases, surfaces) --- hand-written formats for _, c in Fx.hand do local img, err = dec(c.data) t:check(img, c.name .. ": " .. tostring(err)) @@ -158,7 +153,6 @@ for _, o in Fx.ours do end t:note("%d of our files read by Pillow / nvddsinfo", #Fx.ours) --- round trips do local img = Types.Image.new(37, 23) img.pixels = src @@ -178,7 +172,6 @@ do t:check(e2 and e2.code == Err.ARG, "no bc7 encoder") end --- sniff and errors do local c = Fx.cases[1] t:eq(Dds.sniff(Bytes.reader(buffer.fromstring(c.data))), 1, "sniff") diff --git a/tests/image/exr.luau b/tests/image/exr.luau index 7c904cb..9fccb10 100644 --- a/tests/image/exr.luau +++ b/tests/image/exr.luau @@ -1,8 +1,4 @@ --- image/exr tests: files from the OpenEXR 3.5 bindings (NONE / RLE / ZIPS / ZIP / PIZ; HALF / FLOAT / UINT; offset --- data window; decreasing lines; Y-only; a layer), a hand-written subsampled file, exrmaketiled tiles (one level, --- mip-map, rip-map, round up) and exrmultipart parts against the bindings' reads; PXR24 / B44 / DWAA UNSUPPORTED; our --- files read back by the bindings and exrheader; round trips; errors; the fuzz no-throw pass. Fixtures: --- tools/fixtures/exr.py. +-- image/exr tests against the OpenEXR 3.5 bindings, exrmaketiled, exrmultipart and exrheader (tools/fixtures/exr.py). local T = require("@tests/T") local Exr = require("@rosetta/image/exr") local Bytes = require("@rosetta/core/Bytes") @@ -19,7 +15,6 @@ local function dec(data: any, opts: any?): (any, any) return Exr.decode(Bytes.reader(if type(data) == "string" then buffer.fromstring(data) else data), opts) end --- the largest difference between two rgbaf32 buffers (exact for HALF / FLOAT, UINT as their values) local function worst(a: buffer, b: buffer, n: number): number local m = 0 for i = 0, n * 4 - 1 do @@ -54,13 +49,11 @@ for _, c in Fx.cases do local up = string.find(c.name, "up") ~= nil t:eq(mm[1].width, if up then math.ceil(c.w / 2) else c.w // 2, c.name .. ": level 1 width") end - -- the rgba8 display conversion local d8 = dec(c.data, { layer = c.layer, part = c.part }) t:eq(d8.format, "rgba8", c.name .. ": rgba8 by default") end t:note("%d files match the OpenEXR bindings", #Fx.cases) --- the window, the attributes do for _, c in Fx.cases do if c.name == "window_zip.exr" then @@ -109,7 +102,6 @@ do t:check(e and e.code == Err.ARG, "no PIZ encoder") end --- sniff, info, errors do local c = Fx.cases[1] t:eq(Exr.sniff(Bytes.reader(buffer.fromstring(c.data))), 1, "sniff") diff --git a/tests/image/gif.luau b/tests/image/gif.luau index a53e631..1f31619 100644 --- a/tests/image/gif.luau +++ b/tests/image/gif.luau @@ -1,8 +1,4 @@ --- image/gif tests: GIFs from ImageMagick and Pillow (static, interlaced, 2..256 colours, grey, transparency, --- animations with every disposal, sub-rectangles, local colour tables, loop counts, comments) against ImageMagick's --- decode of every frame; the encoder (lossless round trips at <= 256 colours, quantized PSNR above, animations with --- frames / delays / disposal / transparency / loops, options); error codes; the fuzz no-throw pass. --- Fixtures: tools/fixtures/gif.py. +-- image/gif tests against ImageMagick's decodes (tools/fixtures/gif.py). local T = require("@tests/T") local Gif = require("@rosetta/image/gif") local Bytes = require("@rosetta/core/Bytes") @@ -31,12 +27,10 @@ local function norm(px: buffer): buffer return c end --- the contract t:eq(Gif.name, "gif", "name") t:eq(Gif.category, "image", "category") t:check(Gif.caps.decode and Gif.caps.encode and Gif.caps.animation, "caps") --- every fixture against ImageMagick local nframes = 0 for _, c in Fx do local img, err = decode(c.data) @@ -69,7 +63,6 @@ for _, c in Fx do end t:note("%d files, %d frames match ImageMagick", #Fx, nframes) --- sniff, meta, limits, errors do local c = Fx[1] t:eq(Gif.sniff(Bytes.reader(buffer.fromstring(c.data))), 1, "sniff a GIF") @@ -100,7 +93,6 @@ do end end --- the encoder local rand = T.rng(17) local function image(w: number, h: number, colors: number?, alpha: boolean?): Types.Image local img = Types.Image.new(w, h) @@ -161,7 +153,6 @@ do local small = Gif.encode(photo, { maxColors = 4 }) :: buffer local sb = decode(small) t:check(sb.meta.palette and #sb.meta.palette <= 4, "maxColors = 4") - -- animation: frames, delays, disposal, transparency, loops, comment, local / global palettes local anim = image(40, 30, 50) anim.frames = { { image = image(40, 30, 50), x = 0, y = 0, delay = 0.1, dispose = "none", blend = "source" }, @@ -189,9 +180,7 @@ do t:check(psnr(back.frames[3].image.pixels, anim.frames[3].image.pixels) > 25, "frame 3 quantized") t:eq(back.meta.source.localPalettes, if global then 0 else 3, "palettes") end - -- deterministic output t:eq(Crc32.of(Gif.encode(photo, { dither = true }) :: buffer), Crc32.of(Gif.encode(photo, { dither = true }) :: buffer), "deterministic") - -- bad arguments local _, e = Gif.encode({} :: any) t:check(e and e.code == Err.ARG, "encode of a non-image") local _, e2 = Gif.encode(photo, { maxColors = 1 }) @@ -202,7 +191,6 @@ do t:check(e4 and e4.code == Err.ARG, "too wide") end --- fuzz do local samples = {} for _, c in Fx do diff --git a/tests/image/hdr.luau b/tests/image/hdr.luau index 4abce53..58daba3 100644 --- a/tests/image/hdr.luau +++ b/tests/image/hdr.luau @@ -1,7 +1,4 @@ --- image/hdr tests: ImageMagick-written Radiance files (new-style RLE) against its float decodes, hand-written ones --- (flat and old-style RLE scanlines, "#?RGBE", EXPOSURE products, all orientations) against the rgbe.c rule; the --- display conversion to rgba8; our encoder round-trips (RLE and flat, rgbaf32 and rgba8) within RGBE precision; --- errors; the fuzz no-throw pass. Fixtures: tools/fixtures/hdr.py. +-- image/hdr tests against ImageMagick's float decodes and the rgbe.c rule (tools/fixtures/hdr.py). local T = require("@tests/T") local Hdr = require("@rosetta/image/hdr") local Bytes = require("@rosetta/core/Bytes") @@ -18,7 +15,6 @@ local function dec(data: any, opts: any?): (any, any) return Hdr.decode(Bytes.reader(if type(data) == "string" then buffer.fromstring(data) else data), opts) end --- worst relative error between two rgbaf32 buffers local function relErr(a: buffer, b: buffer, n: number): number local worst = 0 for i = 0, n * 4 - 1 do @@ -40,7 +36,6 @@ for _, c in Fx do if c.exposure then t:check(math.abs(img.meta.exposure - c.exposure) < 1e-9, c.name .. ": exposure") end - -- the default rgba8 display conversion local d8 = dec(c.data) t:eq(d8.format, "rgba8", c.name .. ": rgba8 by default") local v = buffer.readf32(img.pixels, 0) @@ -77,7 +72,6 @@ do end end t:check(worst < 1 / 128, "float precision " .. worst) - -- rgba8 in, rgba8 out local i8 = Types.Image.new(9, 2) for i = 0, 17 do buffer.writeu32(i8.pixels, i * 4, 0xFF000000 + (i * 14) * 0x10101) diff --git a/tests/image/icns.luau b/tests/image/icns.luau index 40ac440..892be67 100644 --- a/tests/image/icns.luau +++ b/tests/image/icns.luau @@ -1,7 +1,4 @@ --- image/icns tests: a libicns file (RLE entries + masks, JPEG 2000 entries skipped), a Pillow file (PNG entries through --- the decodeImage hook) and a hand-written one (ics#, raw is32, ic04 ARGB) against icns2png's / the written pixels; --- our RLE file read back by icns2png; PNG entries through encodeImage; errors; the fuzz no-throw pass. Fixtures: --- tools/fixtures/icns.py. +-- image/icns tests against libicns' icns2png and Pillow (tools/fixtures/icns.py). local T = require("@tests/T") local Icns = require("@rosetta/image/icns") local Png = require("@rosetta/image/png") @@ -55,7 +52,6 @@ end t:note("%d files and our encoder's file match", #Fx.cases) do - -- PNG entries through the hooks, legacy entries without them local img = Types.Image.new(64, 64) for i = 0, 64 * 64 - 1 do buffer.writeu32(img.pixels, i * 4, i * 2654435761 % 4294967296) diff --git a/tests/image/ico.luau b/tests/image/ico.luau index 43de1cf..0eab3f8 100644 --- a/tests/image/ico.luau +++ b/tests/image/ico.luau @@ -1,7 +1,4 @@ --- image/ico tests: ImageMagick- and Pillow-written icons (PNG and BMP entries, a 256 PNG entry) and hand-built ones --- (1 / 4 / 8 / 24 / 32-bit DIBs with AND masks, a cursor with hotspots) against Pillow's decode of every entry; PNG --- entries through opts.decodeImage (and UNSUPPORTED without it); the main image is the largest entry; our encoder --- (DIB, PNG through opts.encodeImage, cursors) round-trips; errors; the fuzz no-throw pass. Fixtures: tools/fixtures/ico.py. +-- image/ico tests against Pillow's decode of every entry (tools/fixtures/ico.py). local T = require("@tests/T") local Ico = require("@rosetta/image/ico") local Png = require("@rosetta/image/png") @@ -47,7 +44,6 @@ for _, c in Fx do entries += 1 end t:eq(img.width * img.height, biggest, c.name .. ": the main image is the largest entry") - -- round trip through our encoder (DIB entries, and PNG for 256 through the hook) local enc, eerr = Ico.encode(img, hooks) t:check(enc, c.name .. ": encode: " .. tostring(eerr)) local back = dec(enc, hooks) @@ -90,7 +86,6 @@ do t:eq(buffer.readu16(cenc, 2), 2, "cursor written as CUR") local cb = dec(cenc) t:check(cb.meta.hotspot.x == 3 and cb.frames[2].image.meta.hotspot.y == 6, "hotspots round-trip") - -- PNG entries on request local small = Types.Image.new(16, 16) buffer.fill(small.pixels, 0, 200, 16 * 16 * 4) local pe = Ico.encode(small, { png = true, encodeImage = hooks.encodeImage }) :: buffer diff --git a/tests/image/ilbm.luau b/tests/image/ilbm.luau index 68d52bd..f4773cb 100644 --- a/tests/image/ilbm.luau +++ b/tests/image/ilbm.luau @@ -1,7 +1,4 @@ --- image/ilbm tests: files from netpbm's ppmtoilbm (palette, uncompressed, HAM6, HAM8, 24-bit) and hand-written ones --- (EHB, chunky PBM, a mask plane, a transparent colour) against ilbmtoppm (colours) and the written masks (alpha); our --- encoder's files read by ilbmtoppm; round trips (palette, 24 and 32 planes, uncompressed); errors; the fuzz no-throw --- pass. Fixtures: tools/fixtures/ilbm.py. +-- image/ilbm tests against netpbm's ilbmtoppm (tools/fixtures/ilbm.py). local T = require("@tests/T") local Ilbm = require("@rosetta/image/ilbm") local Bytes = require("@rosetta/core/Bytes") diff --git a/tests/image/jpeg.luau b/tests/image/jpeg.luau index 4b38d90..9b541a1 100644 --- a/tests/image/jpeg.luau +++ b/tests/image/jpeg.luau @@ -1,8 +1,5 @@ --- image/jpeg tests: every cjpeg / jpegtran fixture (baseline, progressive, arithmetic, every sampling, restarts, grey, --- RGB, 12-bit, odd sizes, stripped DHT) against djpeg's decodes at scales 1, 1/2, 1/4, 1/8 (bit-exact, CRC-32); --- CMYK / YCCK against Pillow; refused files; info / meta (EXIF orientation applied, ICC, comment, density); the --- encoder byte-identical to cjpeg for the same settings, its PSNR, round trips through our decoder; truncated files; --- the fuzz no-throw pass. Ported from jpeg-luau tests/jpeg.luau. Fixtures: tools/fixtures/jpeg.py. +-- image/jpeg tests: decodes bit-exact with djpeg (CMYK / YCCK against Pillow), encoder byte-identical to cjpeg. +-- Fixtures: tools/fixtures/jpeg.py. local T = require("@tests/T") local Jpeg = require("@rosetta/image/jpeg") local Bytes = require("@rosetta/core/Bytes") @@ -19,12 +16,10 @@ local function decode(data: any, opts: any?): (any, any) return Jpeg.decode(Bytes.reader(b), opts) end --- the contract t:eq(Jpeg.name, "jpeg", "name") t:eq(Jpeg.category, "image", "category") t:check(Jpeg.caps.decode and Jpeg.caps.encode, "caps") --- decodes against djpeg / Pillow local files: { [string]: string } = {} do local refs, arith = 0, 0 @@ -69,7 +64,6 @@ local function file(name: string): buffer return buffer.fromstring(files[name]) end --- sniff, info, meta, options do t:eq(Jpeg.sniff(Bytes.reader(file("photo_q90_420"))), 1, "sniff a JPEG") t:eq(Jpeg.sniff(Bytes.reader(buffer.fromstring("GIF89a"))), 0, "sniff a GIF") @@ -102,7 +96,6 @@ do t:check(e2 and e2.code == Err.ARG, "bad scale") local _, e3 = decode("nope") t:check(e3 and e3.code == Err.CORRUPT, "junk: " .. tostring(e3)) - -- a range inside a bigger buffer local data = files["photo_q90_420"] local big = buffer.create(#data + 20) buffer.writestring(big, 11, data) @@ -171,7 +164,6 @@ do t:check(img.meta.dpi == nil, "no density in cjpeg's JFIF (aspect only)") end --- the encoder: byte-identical to cjpeg local function source(c: any): any local img = Types.Image.new(c.width, c.height, c.format) if c.format == "rgb8" then @@ -227,7 +219,6 @@ do t:note("%d encodes byte-identical to cjpeg", exact) end --- encoder: meta segments round trip, rgba8 input, options, errors do local c = Enc[1] local rgb = source(c) @@ -281,7 +272,6 @@ do t:note("%d truncated files, %d decoded partially", count, partial) end --- fuzz do local samples = {} for i, c in Dec do diff --git a/tests/image/ktx.luau b/tests/image/ktx.luau index c4142ab..15bd347 100644 --- a/tests/image/ktx.luau +++ b/tests/image/ktx.luau @@ -1,8 +1,4 @@ --- image/ktx tests: KTX2 files from KTX-Software (`ktx create` from PNGs and raw data in uncompressed / packed / float / --- BCn / ETC2 / EAC formats, mips, cube maps, arrays, 3D, Zstandard and ZLIB supercompression; Basis Universal is --- UNSUPPORTED) and KTX1 files from toktx / nvcompress / hand-written ones (big-endian, packed types, row padding, --- KTXorientation) against their sources or reference decodes; our KTX2 files through `ktx validate` / `ktx extract`; --- round trips; errors; the fuzz no-throw pass. Fixtures: tools/fixtures/ktx.py. +-- image/ktx tests against KTX-Software (ktx create / validate / extract), toktx and nvcompress (tools/fixtures/ktx.py). local T = require("@tests/T") local Ktx = require("@rosetta/image/ktx") local Bytes = require("@rosetta/core/Bytes") @@ -119,7 +115,6 @@ for _, o in Fx.ours do end t:note("%d of our files pass ktx validate", #Fx.ours) --- round trips do local img = Types.Image.new(37, 23) img.pixels = src @@ -139,7 +134,6 @@ do t:check(e2 and e2.code == Err.ARG, "zlib level") end --- sniff, info, errors do local c = Fx.cases[1] t:eq(Ktx.sniff(Bytes.reader(buffer.fromstring(c.data))), 1, "sniff KTX2") diff --git a/tests/image/pcx.luau b/tests/image/pcx.luau index 0304263..2a49375 100644 --- a/tests/image/pcx.luau +++ b/tests/image/pcx.luau @@ -1,6 +1,4 @@ --- image/pcx tests: files from netpbm (24-bit, 8-bit, packed 2 / 4-bit, 3 / 4 planes, mono), ImageMagick and Pillow --- against pcxtoppm's decode; our files read by ImageMagick; round trips (palette, 24-bit, 32-bit alpha); errors; the --- fuzz no-throw pass. Fixtures: tools/fixtures/pcx.py. +-- image/pcx tests against netpbm's pcxtoppm and ImageMagick (tools/fixtures/pcx.py). local T = require("@tests/T") local Pcx = require("@rosetta/image/pcx") local Bytes = require("@rosetta/core/Bytes") diff --git a/tests/image/png.luau b/tests/image/png.luau index b9e317f..5adf460 100644 --- a/tests/image/png.luau +++ b/tests/image/png.luau @@ -1,7 +1,4 @@ --- image/png tests: the whole PngSuite against reference decodes (pypng: tools/fixtures/_png_reference.py), the corrupt --- x* files rejected (with checkCrc), generated images of every colour type / depth / interlace / filter, the encoder --- (round trips for every colour type it picks, levels, text), the contract, and the fuzz no-throw pass. --- Ported from png-luau tests/png.luau. Fixtures: tools/fixtures/png.py. +-- image/png tests: the PngSuite against pypng (tools/fixtures/_png_reference.py). Fixtures: tools/fixtures/png.py. local T = require("@tests/T") local Png = require("@rosetta/image/png") local Bytes = require("@rosetta/core/Bytes") @@ -18,7 +15,6 @@ local function decode(data: any, opts: any?): (any, any) return Png.decode(Bytes.reader(b), opts) end --- the contract t:eq(Png.name, "png", "name") t:eq(Png.category, "image", "category") t:check(table.find(Png.extensions, "png") ~= nil, "extensions") @@ -32,7 +28,6 @@ local function verify(c: any, label: string) t:eq(buffer.len(img.pixels), c.width * c.height * 4, label .. ": pixel buffer size") local crc = Crc32.of(img.pixels) t:check(crc == c.crc, string.format("%s: pixels crc %08x, expected %08x", label, crc, c.crc)) - -- without the CRC check too, and at an offset inside a bigger buffer (the Reader's range) local img2 = decode(c.data) t:check(img2 and Crc32.of(img2.pixels) == c.crc, label .. ": no-CRC decode") local big = buffer.create(#c.data + 10) @@ -59,7 +54,6 @@ for _, c in Gen do end t:note("%d generated images match", #Gen) --- sniff, info, palette, meta, limits do local c for _, s in Suite do @@ -83,7 +77,6 @@ do t:check(e2 and e2.code == Err.CORRUPT, "junk: " .. tostring(e2)) end --- the encoder: round trips, colour type choice, levels, text do local rand = T.rng(99) local function image(w: number, h: number, kind: string): Types.Image @@ -120,20 +113,17 @@ do end end end - -- forced colour type, text chunks local img = image(16, 16, "rgba") img.meta.text = { Comment = "hello", Software = "rosetta" } local png = Png.encode(img, { colorType = "rgba" }) :: buffer local back = Png.decode(Bytes.reader(png)) t:check(back.meta.text and back.meta.text.Comment == "hello" and back.meta.text.Software == "rosetta", "tEXt round trip") - -- the photo bench image compresses local _, e = Png.encode({} :: any) t:check(e and e.code == Err.ARG, "encode of a non-image returns Err.ARG") local _, e2 = Png.encode(img, { colorType = "cmyk" } :: any) t:check(e2 and e2.code == Err.ARG, "unknown colorType returns Err.ARG") end --- fuzz: truncations, mutations (also of the IHDR fields) and garbage never throw do local samples = {} for i, c in Suite do diff --git a/tests/image/pnm.luau b/tests/image/pnm.luau index 412f03f..3b36eae 100644 --- a/tests/image/pnm.luau +++ b/tests/image/pnm.luau @@ -1,7 +1,4 @@ --- image/pnm tests: ImageMagick-written P1-P7 / PFM files (ASCII and binary, 8 / 16-bit, PAM tuple types, both PFM --- byte orders) and hand-written edge cases (comments, packed P1 digits, odd maxvals) against ImageMagick's RGBA --- decodes (8-bit; 16-bit and float natively); round trips of every subtype through our encoder, binary and ASCII; --- errors; the fuzz no-throw pass. Fixtures: tools/fixtures/pnm.py. +-- image/pnm tests against ImageMagick's decodes (tools/fixtures/pnm.py). local T = require("@tests/T") local Pnm = require("@rosetta/image/pnm") local Bytes = require("@rosetta/core/Bytes") @@ -18,7 +15,6 @@ local function dec(data: any, opts: any?): (any, any) return Pnm.decode(Bytes.reader(if type(data) == "string" then buffer.fromstring(data) else data), opts) end --- channel c (0..3) of pixel i of a native image, in 16-bit scale local function chan16(img: any, i: number, c: number): number local px, f = img.pixels, img.format if f == "gray16" then @@ -65,7 +61,6 @@ for _, c in Fx do end t:check(fw < 1e-6, c.name .. ": floats") end - -- round trips through our encoder: the same subtype, binary and ASCII local ext = string.match(c.name, "%.(%a+)$") for _, ascii in { false, true } do local enc, eerr = Pnm.encode(nat, { format = ext, ascii = ascii }) @@ -76,7 +71,6 @@ for _, c in Fx do end t:note("%d files match ImageMagick and round-trip", #Fx) --- encoder choices, conversions, options do local img = Types.Image.new(3, 2) for i = 0, 23 do diff --git a/tests/image/qoi.luau b/tests/image/qoi.luau index 1e8c01a..6435dcb 100644 --- a/tests/image/qoi.luau +++ b/tests/image/qoi.luau @@ -1,6 +1,4 @@ --- image/qoi tests: Pillow-written QOI files (RGB / RGBA, noise / gradients / runs / small deltas, 1x1 to 500x1) --- decode to Pillow's pixels; our encoder writes the same bytes as Pillow for the same pixels and round-trips exactly; --- native rgb8 output, the colour space tag, errors, and the fuzz no-throw pass. Fixtures: tools/fixtures/qoi.py. +-- image/qoi tests: decodes and encoder bytes against Pillow (tools/fixtures/qoi.py). local T = require("@tests/T") local Qoi = require("@rosetta/image/qoi") local Bytes = require("@rosetta/core/Bytes") @@ -20,7 +18,6 @@ for _, c in Fx do t:check(img, c.name .. ": " .. tostring(err)) t:check(img.width == c.width and img.height == c.height and img.format == "rgba8", c.name .. ": size") t:eq(Crc32.of(img.pixels), c.crc, c.name .. ": pixels against Pillow") - -- encode the source pixels: the same bytes as Pillow's writer local src = Types.Image.new(c.width, c.height, if c.channels == 4 then "rgba8" else "rgb8") src.pixels = buffer.fromstring(c.pixels) local enc = Qoi.encode(src, { channels = c.channels, linear = string.byte(c.data, 14) == 1 }) :: buffer -- Pillow tags its files linear @@ -29,7 +26,6 @@ for _, c in Fx do end local back = Qoi.decode(Bytes.reader(enc)) t:eq(Crc32.of(back.pixels), c.crc, c.name .. ": our encoding round-trips") - -- native rgb8 if c.channels == 3 then local n = Qoi.decode(Bytes.reader(buffer.fromstring(c.data)), { native = true }) t:check(n.format == "rgb8" and buffer.tostring(n.pixels) == c.pixels, c.name .. ": native rgb8") @@ -38,7 +34,6 @@ end t:eq(same, #Fx, "byte-identical to Pillow's encoder") t:note("%d Pillow files decode; %d of our encodings are byte-identical to Pillow's", #Fx, same) --- round trips of random images, a sub-range reader, colour space, errors do local rand = T.rng(5) for _, s in { { 1, 1 }, { 70, 3 }, { 33, 33 } } do diff --git a/tests/image/sgi.luau b/tests/image/sgi.luau index e4ddca4..97121d7 100644 --- a/tests/image/sgi.luau +++ b/tests/image/sgi.luau @@ -1,5 +1,4 @@ --- image/sgi tests: files from netpbm / ImageMagick / Pillow against ImageMagick's decode, our encoder's files read --- by ImageMagick, round trips through every option, errors, the fuzz no-throw pass. Fixtures: tools/fixtures/sgi.py. +-- image/sgi tests against ImageMagick (tools/fixtures/sgi.py). local T = require("@tests/T") local Sgi = require("@rosetta/image/sgi") local Bytes = require("@rosetta/core/Bytes") diff --git a/tests/image/sunras.luau b/tests/image/sunras.luau index 7acceb3..d44ffb3 100644 --- a/tests/image/sunras.luau +++ b/tests/image/sunras.luau @@ -1,5 +1,4 @@ --- image/sunras tests: files from netpbm / ImageMagick against ImageMagick's decode, our encoder's files read --- by rasttopnm, round trips through every option, errors, the fuzz no-throw pass. Fixtures: tools/fixtures/sunras.py. +-- image/sunras tests against ImageMagick and rasttopnm (tools/fixtures/sunras.py). local T = require("@tests/T") local Sunras = require("@rosetta/image/sunras") local Bytes = require("@rosetta/core/Bytes") diff --git a/tests/image/tga.luau b/tests/image/tga.luau index 07d84d3..751408d 100644 --- a/tests/image/tga.luau +++ b/tests/image/tga.luau @@ -1,7 +1,4 @@ --- image/tga tests: Pillow- and ImageMagick-written TGAs (RGB / RGBA / grey / grey + alpha / palette, raw and RLE, both --- origins) and hand-written ones (15 / 16-bit pixels and colour maps, first index, right-to-left, RLE across rows, an --- image ID) against the reference RGBA decodes; our encoder (raw / RLE, origins, 24 / 32-bit / grey) round-trips; --- sniffing stays low without a footer; errors; the fuzz no-throw pass. Fixtures: tools/fixtures/tga.py. +-- image/tga tests against Pillow's and ImageMagick's decodes (tools/fixtures/tga.py). local T = require("@tests/T") local Tga = require("@rosetta/image/tga") local Bytes = require("@rosetta/core/Bytes") @@ -31,7 +28,6 @@ for _, c in Fx do end t:check(worst == 0, string.format("%s: differs from the reference by %d at byte %d", c.name, worst, at)) t:check(not img.meta.truncated, c.name .. ": not truncated") - -- round trips through our encoder for _, rle in { false, true } do for _, origin in { "bottom-left", "top-left" } do local enc = Tga.encode(img, { rle = rle, origin = origin }) :: buffer @@ -61,7 +57,6 @@ do t:eq(Tga.sniff(Bytes.reader(Tga.encode(p) :: buffer)), 0.9, "sniff with the footer") t:eq(Tga.sniff(Bytes.reader(buffer.fromstring("\0\0\1\0\1\0\16\16\0\0\1\0\32\0\0\0\0\0\0\0\0\0"))), 0, "an ICO header is not a TGA") t:eq(Tga.sniff(Bytes.reader(buffer.fromstring("\137PNG\r\n\26\n\0\0\0\13IHDR\0\0\0\0\0\0"))), 0, "a PNG is not a TGA") - -- encoder choices local img = Types.Image.new(3, 2) buffer.fill(img.pixels, 0, 255, 24) t:eq(buffer.readu8(Tga.encode(img) :: buffer, 16), 24, "opaque rgba8 -> 24-bit") diff --git a/tests/image/tiff.luau b/tests/image/tiff.luau index e950e14..f2b6c0d 100644 --- a/tests/image/tiff.luau +++ b/tests/image/tiff.luau @@ -1,7 +1,4 @@ --- image/tiff tests: files written by tifffile / imagecodecs and ImageMagick (every compression, predictors, strips and --- tiles, planar, both byte orders, BigTIFF, 1..32-bit integer and 16 / 32 / 64-bit float samples, palette, CMYK, --- alpha, multi-page) against tifffile's decode, in rgba8 and native layouts; the JPEG hook; encoder round trips for --- every layout and compression; errors; the fuzz pass. Fixtures: tools/fixtures/tiff.py. +-- image/tiff tests against tifffile's decode (tools/fixtures/tiff.py). local T = require("@tests/T") local Tiff = require("@rosetta/image/tiff") local Bytes = require("@rosetta/core/Bytes") @@ -17,14 +14,12 @@ local function decode(data: any, opts: any?): (any, any) return Tiff.decode(Bytes.reader(b), opts) end --- contract t:eq(Tiff.name, "tiff", "name") t:check(Tiff.caps.decode and Tiff.caps.encode, "caps") t:eq(Tiff.sniff(Bytes.reader(buffer.fromstring("II*\0\8\0\0\0"))), 1, "sniff II") t:eq(Tiff.sniff(Bytes.reader(buffer.fromstring("MM\0*"))), 1, "sniff MM") t:eq(Tiff.sniff(Bytes.reader(buffer.fromstring("\137PNG"))), 0, "sniff png") --- reference files local pagesChecked = 0 for _, c in Fx.cases do local img, err = decode(c.data) @@ -43,7 +38,6 @@ for _, c in Fx.cases do t:check(ncrc == p.ncrc, string.format("%s page %d: native crc %08x, want %08x", c.name, i, ncrc, p.ncrc)) pagesChecked += 1 end - -- inside a bigger buffer local big = buffer.create(#c.data + 9) buffer.writestring(big, 5, c.data) local img3 = Tiff.decode(Bytes.reader(big, 5, #c.data)) @@ -51,7 +45,6 @@ for _, c in Fx.cases do end t:note("%d files, %d pages match tifffile", #Fx.cases, pagesChecked) --- info, single page, meta do local multi for _, c in Fx.cases do @@ -104,7 +97,6 @@ do t:note("JPEG-in-TIFF through F.load: max error %d against tifffile / libjpeg-turbo", worst) end --- encoder round trips do local rand = T.rng(11) local function image(fmt: string, w: number, h: number): Types.Image @@ -141,7 +133,6 @@ do end end t:note("%d encoder round trips", trips) - -- multi-page local a, b = image("rgb8", 20, 10), image("gray16", 7, 9) local anim = image("rgb8", 20, 10) anim.frames = { { image = a, delay = 0, x = 0, y = 0, dispose = "none", blend = "source" }, { image = b, delay = 0, x = 0, y = 0, dispose = "none", blend = "source" } } :: any @@ -158,7 +149,6 @@ do t:check(e3 and e3.code == Err.ARG, "unsupported layout") end --- errors do local _, e = decode("II*\0\255\255\0\0") t:check(e and (e.code == Err.TRUNCATED or e.code == Err.CORRUPT), "bad IFD offset") @@ -166,7 +156,6 @@ do t:check(e2 and e2.code == Err.TRUNCATED or e2.code == Err.CORRUPT, "junk") end --- fuzz do local samples = {} for i, c in Fx.cases do diff --git a/tests/image/tim.luau b/tests/image/tim.luau index fc7eb7a..8524d80 100644 --- a/tests/image/tim.luau +++ b/tests/image/tim.luau @@ -1,6 +1,4 @@ --- image/tim tests: PlayStation TIM files written by tools/fixtures/tim.py (4 / 8-bit CLUT, 15-bit, 24-bit) decode to --- ImageMagick's RGB, colour 0x0000 is transparent, CLUT rows, the VRAM position; the encoder round-trips 16 / 24 / --- 8 / 4-bit; errors; the fuzz pass. +-- image/tim tests against ImageMagick (tools/fixtures/tim.py). local T = require("@tests/T") local F = require("@rosetta") local Tim = require("@rosetta/image/tim") @@ -42,8 +40,7 @@ for _, c in Fx do local other = Tim.decode(Bytes.reader(buffer.fromstring(c.data)), { clut = 1 }) :: any t:check(Crc32.of(other.pixels) ~= Crc32.of(img.pixels) and other.meta.source.clut.row == 1, c.name .. ": second CLUT row") end - -- round trips: decoded 4 / 8 / 15-bit pixels are PSX colours, so every depth that fits is lossless (24-bit only - -- round-trips as 24-bit) + -- decoded 4 / 8 / 15-bit pixels are PSX colours, so every depth that fits is lossless (24-bit only as 24-bit) for _, bpp in (if c.bpp == 24 then { 24 } else { 16, 24, 8, 4 }) do local enc, eerr = Tim.encode(img, { bpp = bpp }) if bpp == 24 then @@ -68,9 +65,9 @@ end do local img = Types.Image.new(3, 1) - buffer.writeu32(img.pixels, 0, 0xFF000000) -- opaque black - buffer.writeu32(img.pixels, 4, 0x00FFFFFF) -- transparent - buffer.writeu32(img.pixels, 8, 0xFF0000FF) -- red + buffer.writeu32(img.pixels, 0, 0xFF000000) + buffer.writeu32(img.pixels, 4, 0x00FFFFFF) + buffer.writeu32(img.pixels, 8, 0xFF0000FF) local back = Tim.decode(Bytes.reader(Tim.encode(img) :: buffer)) :: any t:eq(buffer.readu32(back.pixels, 0), 0xFF000000, "opaque black stays opaque (STP)") t:eq(buffer.readu32(back.pixels, 4), 0, "transparent") diff --git a/tests/image/vtf.luau b/tests/image/vtf.luau index 5f1a7cf..c93d6b8 100644 --- a/tests/image/vtf.luau +++ b/tests/image/vtf.luau @@ -1,7 +1,4 @@ --- image/vtf tests: VTFs written by srctools (tools/fixtures/vtf.py: every texel format it writes, versions 7.2 / 7.4 --- / 7.5, mips, two-frame animations) decode to srctools' own RGBA (DXT within its libsquish rounding), frames, the --- mip / thumbnail layout; the half / float / 16-bit formats srctools cannot write against the fixture writer; errors; --- the fuzz pass. +-- image/vtf tests against srctools (DXT within its libsquish rounding) and the fixture writer (tools/fixtures/vtf.py). local T = require("@tests/T") local F = require("@rosetta") local Vtf = require("@rosetta/image/vtf") diff --git a/tests/image/webp.luau b/tests/image/webp.luau index 73ba084..cb12624 100644 --- a/tests/image/webp.luau +++ b/tests/image/webp.luau @@ -1,8 +1,4 @@ --- image/webp tests: every still file of tools/fixtures/webp.py (cwebp lossless / lossy / alpha variants, libvpx key --- frames with token partitions, metadata) against dwebp (-pam, -nofancy -pam, -yuv: bit-exact), animations (img2webp, --- gif2webp, webpmux) against Pillow's WebPAnimDecoder frames (bit-exact), our encoder (round trips at every effort, --- dwebp / Pillow decoding our files at fixture time, metadata, animations), error codes, and the fuzz no-throw pass. --- Fixtures: tools/fixtures/webp.py. +-- image/webp tests: stills bit-exact with dwebp, animations with Pillow's WebPAnimDecoder (tools/fixtures/webp.py). local T = require("@tests/T") local Webp = require("@rosetta/image/webp") local Bytes = require("@rosetta/core/Bytes") @@ -21,13 +17,11 @@ local function decode(data: any, opts: any?): (any, any) return Webp.decode(Bytes.reader(b), opts) end --- the contract t:eq(Webp.name, "webp", "name") t:eq(Webp.category, "image", "category") t:check(table.find(Webp.extensions, "webp") ~= nil, "extensions") t:check(Webp.caps.decode and Webp.caps.encode and Webp.caps.animation and Webp.caps.alpha, "caps") --- still files, bit-exact with dwebp do local lossy, lossless, alpha = 0, 0, 0 for _, c in Cases do @@ -60,7 +54,6 @@ do t:check(img.meta.xmp and buffer.tostring(img.meta.xmp) == c.xmp, c.name .. ": XMP") end end - -- inside a bigger buffer (the Reader's range) local c = Cases[3] local big = buffer.create(#c.data + 11) buffer.writestring(big, 5, c.data) @@ -69,7 +62,6 @@ do t:note("%d lossless and %d lossy files (%d with alpha) match dwebp", lossless, lossy, alpha) end --- animations, bit-exact with Pillow (libwebp WebPAnimDecoder) local function opaque(px: buffer, n: number): buffer local b = buffer.create(n * 4) buffer.copy(b, 0, px, 0, n * 4) @@ -113,7 +105,6 @@ for _, a in Anims do end t:note("%d animations match Pillow", #Anims) --- the encoder: round trips, the fixture-time dwebp / Pillow checks of our files, metadata, animations local function image(s: any): Types.Image local img = Types.Image.new(s.width, s.height) img.pixels = buffer.fromstring(s.rgba) @@ -163,7 +154,6 @@ do return f end)(), loops = a.loops, rgba = true }, "our " .. a.name) end - -- metadata chunks local img = image(Src[1]) img.meta.icc = buffer.fromstring("icc profile bytes") img.meta.exif = buffer.fromstring("Exif\0\0MM") @@ -173,7 +163,6 @@ do t:check(back.meta.exif and buffer.tostring(back.meta.exif) == "Exif\0\0MM", "EXIF round trip") t:check(back.meta.xmp and buffer.tostring(back.meta.xmp) == "", "XMP round trip") t:check(back.meta.source.extended and buffer.tostring(back.pixels) == Src[1].rgba, "VP8X still round trip") - -- an animation round trip through our own decoder (frame fields kept) local anim = Types.Image.new(8, 6) local f1 = Types.Image.new(8, 6) buffer.fill(f1.pixels, 0, 200) @@ -189,7 +178,6 @@ do t:check(ab.frames[2].x == 2 and ab.frames[2].y == 4 and ab.frames[2].dispose == "background" and ab.frames[2].blend == "over" and ab.frames[2].delay == 1.5, "animation round trip: frame fields") t:check(buffer.tostring(ab.frames[2].image.pixels) == buffer.tostring(f2.pixels), "animation round trip: frame pixels") t:check(ab.meta.background[1] == 10 and ab.meta.background[4] == 40, "animation round trip: background") - -- bad arguments local _, e1 = Webp.encode({} :: any) t:check(e1 and e1.code == Err.ARG, "encode a non-image: ARG") local _, e2 = Webp.encode(img, { lossless = false }) @@ -201,7 +189,6 @@ do t:check(e4 and e4.code == Err.ARG, "frame outside the canvas: ARG") end --- sniff, info, errors do local c = Cases[1] t:eq(Webp.sniff(Bytes.reader(buffer.fromstring(c.data))), 1, "sniff WebP") @@ -222,7 +209,6 @@ do t:check(e4 and e4.code == Err.CORRUPT, "junk: " .. tostring(e4)) end --- fuzz: truncations, mutations and garbage never throw do local samples = {} for i, c in Cases do diff --git a/tests/image/xbm.luau b/tests/image/xbm.luau index d2a20c8..1df021d 100644 --- a/tests/image/xbm.luau +++ b/tests/image/xbm.luau @@ -1,6 +1,4 @@ --- image/xbm tests: files from netpbm / ImageMagick / Pillow and hand-written ones against the reference decode --- (xbmtopbm), our encoder's files read back by it, round trips, errors, the fuzz no-throw pass. --- Fixtures: tools/fixtures/xbm.py. +-- image/xbm tests against xbmtopbm (tools/fixtures/xbm.py). local T = require("@tests/T") local Xbm = require("@rosetta/image/xbm") local Bytes = require("@rosetta/core/Bytes") diff --git a/tests/image/xpm.luau b/tests/image/xpm.luau index 56b0165..7a269cf 100644 --- a/tests/image/xpm.luau +++ b/tests/image/xpm.luau @@ -1,6 +1,4 @@ --- image/xpm tests: files from netpbm / ImageMagick and hand-written ones against the reference decode --- (ImageMagick), our encoder's files read back by it, round trips, errors, the fuzz no-throw pass. --- Fixtures: tools/fixtures/xpm.py. +-- image/xpm tests against ImageMagick (tools/fixtures/xpm.py). local T = require("@tests/T") local Xpm = require("@rosetta/image/xpm") local Bytes = require("@rosetta/core/Bytes") @@ -29,7 +27,6 @@ do t:eq(Xpm.sniff(Bytes.reader(buffer.fromstring("/* XPM */\n"))), 1, "sniff") local _, e = Xpm.decode(Bytes.reader(buffer.fromstring('/* XPM */ static char *x[] = {"2 1 5 1", "a c red"};'))) t:check(e and e.code == Err.TRUNCATED, "short colour table") - -- many colours: two chars per pixel local big = R.image(300, 1, "") big.pixels = buffer.create(1200) for i = 0, 299 do From 5f7f6005f60d73afd6dfad0d2625dc1d01487b0a Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:50:19 -0500 Subject: [PATCH 16/25] tests/codecs (a-m): comments: specs only --- tests/codecs/aac.luau | 12 ++---------- tests/codecs/ac3.luau | 5 +---- tests/codecs/adpcm.luau | 15 ++------------- tests/codecs/alac.luau | 9 ++------- tests/codecs/apetag.luau | 7 +------ tests/codecs/bcn.luau | 12 ++---------- tests/codecs/bitmap.luau | 4 +--- tests/codecs/brotli.luau | 12 ++---------- tests/codecs/bzip2.luau | 8 +------- tests/codecs/dct.luau | 8 ++------ tests/codecs/deflate.luau | 12 ++---------- tests/codecs/draco.luau | 9 ++------- tests/codecs/etc.luau | 6 ++---- tests/codecs/explode.luau | 5 ++--- tests/codecs/h263.luau | 15 ++------------- tests/codecs/h264.luau | 12 ++---------- tests/codecs/h264_jvt.luau | 7 ++----- tests/codecs/jpeg.luau | 20 ++++++-------------- tests/codecs/json.luau | 11 ++--------- tests/codecs/legacy.luau | 7 +------ tests/codecs/lz4.luau | 7 ++----- tests/codecs/lzma.luau | 12 ++---------- tests/codecs/lzw.luau | 9 ++------- tests/codecs/mat4.luau | 3 +-- 24 files changed, 46 insertions(+), 181 deletions(-) diff --git a/tests/codecs/aac.luau b/tests/codecs/aac.luau index fd57c67..cb23a3b 100644 --- a/tests/codecs/aac.luau +++ b/tests/codecs/aac.luau @@ -1,7 +1,5 @@ --- codecs/audio/Aac tests: AudioSpecificConfig parsing (every fixture's esds, explicit SBR / PS signalling from fdkaac, --- crafted configs: PCE channel counts, 960-sample frames, Main / LTP object types), ADTS headers, raw frames decoded --- straight from ADTS against ffmpeg's float decode, the FIL extension hook on HE-AAC (implicit SBR), reset, errors, --- the fuzz no-throw pass on raw frames. Fixtures: tools/fixtures/m4a.py. +-- codecs/audio/Aac tests: AudioSpecificConfig parsing, ADTS headers, raw frames against ffmpeg's float decode, errors. +-- Fixtures: tools/fixtures/m4a.py. local T = require("@tests/T") local Aac = require("@rosetta/codecs/audio/Aac") local IsoBmff = require("@rosetta/containers/IsoBmff") @@ -13,7 +11,6 @@ local He = require("@tests/gen/m4a_he") local t = T.suite("aac-codec") --- ADTS frames of a stream: { offset, size } of the raw blocks local function frames(data: buffer): ({ { number } }, Aac.Adts?) local out, p, first = {}, 0, nil while true do @@ -28,7 +25,6 @@ local function frames(data: buffer): ({ { number } }, Aac.Adts?) return out, first end --- ASCs from the M4A fixtures for _, c in Fx do if c.container == "m4a" then local r = Bytes.reader(buffer.fromstring(c.data)) @@ -49,7 +45,6 @@ for _, c in He do end end --- crafted configs do local asc = Aac.asc(2, 4, 2) local cfg = Aac.config(asc) :: Aac.Config @@ -90,7 +85,6 @@ do t:check(e4 and e4.code == Err.ARG, "decoder of a string") end --- ADTS headers + raw frames against ffmpeg for _, c in Fx do if c.container ~= "adts" then continue @@ -148,7 +142,6 @@ for _, c in He do end end --- errors do local dec = Aac.decoder(Aac.asc(2, 4, 2)) :: Aac.Decoder local _, e = dec:decode(buffer.fromstring("\x20\x00\x00\x00\x00")) @@ -158,7 +151,6 @@ do t:check(Aac.adts(buffer.fromstring("\255\241"), 0, 2) == nil, "short ADTS header") end --- fuzz raw frames (stereo with every tool, mono, 5.1) do local pick = {} for _, c in Fx do diff --git a/tests/codecs/ac3.luau b/tests/codecs/ac3.luau index 1fb818b..ea93ec9 100644 --- a/tests/codecs/ac3.luau +++ b/tests/codecs/ac3.luau @@ -1,6 +1,4 @@ --- codecs/audio/Ac3 tests: the codec API under audio/ac3 and the container hook: header fields of every fixture layout, --- the CRC (a syncframe checks to 0), one-frame decodes against the reference (frame by frame, as a container feeds --- them), the block offsets, reset, argument / data errors, and a fuzz pass over single frames (CRC off). +-- codecs/audio/Ac3 tests: header fields, the CRC (a syncframe checks to 0), one-frame decodes against the reference. -- Fixtures: tools/fixtures/ac3.py. local T = require("@tests/T") local Ac3 = require("@rosetta/codecs/audio/Ac3") @@ -38,7 +36,6 @@ for _, c in Fx do table.insert(frames, buffer.readstring(b, 0, h.frameSize)) end --- errors do local d = Ac3.decoder() local _, e = d:decode(buffer.create(10), 20) diff --git a/tests/codecs/adpcm.luau b/tests/codecs/adpcm.luau index 4ae9ad5..774863a 100644 --- a/tests/codecs/adpcm.luau +++ b/tests/codecs/adpcm.luau @@ -1,9 +1,5 @@ --- codecs/adpcm tests: every decoder kernel of codecs/audio/Adpcm against a reference decoder, bit-exact as s16 --- (tools/fixtures/adpcm.py: ADX from ffmpeg and PS-ADPCM / DSP from our Python encoders decoded by vgmstream, Apple --- ima4 from ffmpeg, IMA nibble streams decoded by ffmpeg); ADX coefficients; the encoders (IMA nibbles, IMA WAV --- blocks, MS blocks) decoded back with a signal-to-noise floor; the Decoder layouts (seeking matches a straight --- read); Flash ADPCM by hand; a fuzz pass of random bytes through every kernel (ranges valid, contents random) and --- the layouts. +-- codecs/adpcm tests: every kernel of codecs/audio/Adpcm bit-exact as s16 against a reference decoder, the encoders. +-- Fixtures: tools/fixtures/adpcm.py (ADX and ima4 from ffmpeg; PS-ADPCM / DSP decoded by vgmstream). local T = require("@tests/T") local Adpcm = require("@rosetta/codecs/audio/Adpcm") local Decoder = require("@rosetta/codecs/audio/Adpcm/Decoder") @@ -12,7 +8,6 @@ local Sig = require("@tests/gen/adpcm_sig") local t = T.suite("adpcm codec") --- s16le reference vs interleaved f32: the count of differing samples and the first one local function compare(out: buffer, ref: string, count: number): (number, number) local r = buffer.fromstring(ref) local bad, first = 0, -1 @@ -27,7 +22,6 @@ local function compare(out: buffer, ref: string, count: number): (number, number return bad, first end --- ------------------------------------------------------------------------------------------------ kernels for _, c in Cases do local src = buffer.fromstring(c.data) local ch, frames = c.ch, c.frames @@ -108,7 +102,6 @@ do end end --- ------------------------------------------------------------------------------------------------ encoders local function snr(x: buffer, y: buffer, count: number): number local sig, err = 0, 0 for i = 0, count - 1 do @@ -123,7 +116,6 @@ end do local x = buffer.fromstring(Sig.data) local ch, n = Sig.channels, Sig.frames - -- IMA nibbles, both nibble orders for _, hi in { true, false } do local raw = buffer.create((n * ch + 1) // 2) local st = buffer.create(8 * ch) @@ -139,7 +131,6 @@ do t:check(s > 20, string.format("ima encode (hi %s): %.1f dB", tostring(hi), s)) t:check(buffer.readi32(st, 0) == buffer.readi32(ds, 0), "ima encoder and decoder end in the same state") end - -- IMA WAV and MS blocks for _, kind in { "ima_wav", "ms" } do local ba = 512 local spb = Decoder.blockFrames(kind, ba, ch) :: number @@ -174,7 +165,6 @@ do end end --- ------------------------------------------------------------------------------------------------ Decoder layouts local function readAll(dec: any, step: number): buffer local out = buffer.create(dec.frames * dec.channels * 4) local got = 0 @@ -224,7 +214,6 @@ do t:eq(dec.frames, 3 * 4 * 28 + 28, "cut interleaved: the whole frames both channels have") end --- ------------------------------------------------------------------------------------------------ fuzz local samples = {} for _, c in Cases do table.insert(samples, c.data) diff --git a/tests/codecs/alac.luau b/tests/codecs/alac.luau index 947f6f6..6c8e30c 100644 --- a/tests/codecs/alac.luau +++ b/tests/codecs/alac.luau @@ -1,7 +1,5 @@ --- codecs/audio/Alac tests: encoder -> decoder round trips over silence (zero runs), full-scale noise (uncompressed frames), --- tones, steps, 1 - 8 channels, 16 / 20 / 24 bits, partial and tiny frames, custom frame lengths; ffmpeg's ALAC --- packets (through containers/IsoBmff) decode to the source integers; the magic cookie (plain, behind frma / alac atoms, --- bad versions / depths); errors; the fuzz no-throw pass on packets. Fixtures: tools/fixtures/m4a.py. +-- codecs/audio/Alac tests: encoder -> decoder round trips, ffmpeg's ALAC packets, the magic cookie, errors. +-- Fixtures: tools/fixtures/m4a.py. local T = require("@tests/T") local Alac = require("@rosetta/codecs/audio/Alac") local IsoBmff = require("@rosetta/containers/IsoBmff") @@ -97,7 +95,6 @@ roundTrip("identical channels", 2, 16, 5000, function(i) return math.floor(math.sin(i * 0.02) * 20000) end) --- ffmpeg's packets for _, c in Fx do if c.container == "m4a" then local r = Bytes.reader(buffer.fromstring(c.data)) @@ -120,7 +117,6 @@ for _, c in Fx do end end --- the cookie behind QuickTime atoms, bad cookies do local enc = Alac.encoder({ sampleRate = 48000, channels = 2 }) :: Alac.Encoder local plain = Alac.cookie(enc.config) @@ -149,7 +145,6 @@ do t:check(e5 and e5.code == Err.CORRUPT, "bad packet: " .. tostring(e5)) end --- fuzz the packet decoder do local enc = Alac.encoder({ sampleRate = 44100, channels = 2, bitDepth = 16 }) :: Alac.Encoder local src = table.create(2 * 3000, 0) diff --git a/tests/codecs/apetag.luau b/tests/codecs/apetag.luau index be65a99..5382dc2 100644 --- a/tests/codecs/apetag.luau +++ b/tests/codecs/apetag.luau @@ -1,6 +1,4 @@ --- codecs/audio/ApeTag tests: APEv2 tags with and without a header, APEv1, multi-value items, binary items, an ID3v1 --- tag after the APE tag, a tag inside a sub-range, malformed sizes / counts; the fuzz no-throw pass. The real files --- (wavpack -w, mac -t, ...) are covered by tests/audio/wavpack.luau and tests/audio/ape.luau. +-- codecs/audio/ApeTag tests: hand-made APEv1 / APEv2 tags. The real files are in tests/audio/wavpack.luau and ape.luau. local T = require("@tests/T") local ApeTag = require("@rosetta/codecs/audio/ApeTag") @@ -9,7 +7,6 @@ local t = T.suite("apetag") local function u32(v: number): string return string.char(v % 256, (v // 256) % 256, (v // 65536) % 256, (v // 16777216) % 256) end --- tag(items, version, header) -> the tag bytes; items = { { key, value, flags? } } local function tag(items: { any }, version: number, header: boolean): string local body = {} for _, it in items do @@ -41,11 +38,9 @@ do t:eq(#info.items, 6, "items") t:eq(info.items[5].kind, "binary", "binary kind") t:eq(info.items[5].value, "f.png\0PNG", "binary value") - -- ID3v1 after it local s2 = s .. "TAG" .. string.rep("x", 125) local tags2, info2 = ApeTag.find(buffer.fromstring(s2), 0, #s2) t:check(tags2 and tags2.title == "Hello" and info2.stop == #s, "before ID3v1") - -- inside a sub-range local s3 = "zz" .. s .. "yyy" local tags3, info3 = ApeTag.find(buffer.fromstring(s3), 2, 2 + #s) t:check(tags3 and tags3.title == "Hello" and info3.start == 12, "sub-range") diff --git a/tests/codecs/bcn.luau b/tests/codecs/bcn.luau index e07f4ec..d4195b1 100644 --- a/tests/codecs/bcn.luau +++ b/tests/codecs/bcn.luau @@ -1,6 +1,5 @@ --- codecs/image/Bcn tests: random BC1..BC7 blocks (every BC7 and BC6H mode, the BC1 3-colour mode, odd sizes) against --- Pillow's and Godot's (bcdec) decodes; BC6H floats against Godot; the encoders (BC1 / BC3 / BC4 / BC5) within reach --- of Pillow's encoder PSNR, exact on flat blocks; argument errors; the fuzz no-throw pass. Fixtures: tools/fixtures/bcn.py. +-- codecs/image/Bcn tests: random BC1..BC7 blocks against Pillow's and Godot's (bcdec) decodes, the encoders. +-- Fixtures: tools/fixtures/bcn.py. local T = require("@tests/T") local Bcn = require("@rosetta/codecs/image/Bcn") local Half = require("@rosetta/codecs/image/Half") @@ -8,7 +7,6 @@ local Fx = require("@tests/gen/bcn") local t = T.suite("bcn") --- the largest per-byte difference between two rgba8 buffers (channels: which of r, g, b, a count) local function maxDiff(a: buffer, b: buffer, n: number, channels: { number }): (number, number) local worst, at = 0, -1 for i = 0, n - 1 do @@ -23,7 +21,6 @@ local function maxDiff(a: buffer, b: buffer, n: number, channels: { number }): ( end local RGBA, RGB, RG, R = { 0, 1, 2, 3 }, { 0, 1, 2 }, { 0, 1 }, { 0 } --- which channels each reference defines, and the allowed difference to it local PILLOW: { [string]: { any } } = { bc1 = { RGBA, 0 }, bc2 = { RGBA, 0 }, @@ -82,7 +79,6 @@ for _, c in Fx.cases do stats.godot += 1 end end - -- into a bigger buffer at an offset, from an offset local big = buffer.create(buffer.len(src) + 5) buffer.copy(big, 5, src) local bpp = if Bcn.FLOAT[c.kind] then 16 else 4 @@ -113,7 +109,6 @@ do end end --- encoders local function psnr(a: buffer, b: buffer, n: number, channels: { number }): number local se = 0 for i = 0, n - 1 do @@ -194,7 +189,6 @@ do end end --- Half do t:eq(Half.fromFloat(1), 0x3C00, "half 1") t:eq(Half.fromFloat(-2), 0xC000, "half -2") @@ -212,7 +206,6 @@ do t:check(ok, "half round trip of every pattern") end --- errors do local _, e1 = Bcn.decode("bc9", buffer.create(8), 0, 4, 4) t:check(e1 and string.find(e1, "unsupported") ~= nil, "unknown kind") @@ -224,7 +217,6 @@ do t:check(e4 ~= nil, "short pixels") end --- fuzz: random block data of every kind and size local samples = {} for _, c in Fx.cases do table.insert(samples, buffer.fromstring(c.data)) diff --git a/tests/codecs/bitmap.luau b/tests/codecs/bitmap.luau index c87a599..d6c3d4f 100644 --- a/tests/codecs/bitmap.luau +++ b/tests/codecs/bitmap.luau @@ -1,6 +1,4 @@ --- codecs/font/Bitmap tests: 1-bit row pack / unpack round trips (MSB- and LSB-first, padded strides), the Font over a --- strike (glyphIndex / advance / rasterize / default glyph), Bitmap.strike of a bitmap font and of the first outline --- font from tools/fixtures/fonts.py (thresholded rasterization), and argument errors. +-- codecs/font/Bitmap tests: 1-bit row pack / unpack, the Font over a strike, Bitmap.strike, argument errors. local T = require("@tests/T") local Bitmap = require("@rosetta/codecs/font/Bitmap") local Ttf = require("@rosetta/font/ttf") diff --git a/tests/codecs/brotli.luau b/tests/codecs/brotli.luau index ce2be95..462d6db 100644 --- a/tests/codecs/brotli.luau +++ b/tests/codecs/brotli.luau @@ -1,7 +1,5 @@ --- codecs/compress/Brotli tests: every fixture stream (reference encoder: qualities 0..11, windows 10..24, text / font / generic --- modes, large windows) decodes to its corpus; consumedEnd; offsets inside a bigger buffer; the static dictionary; --- hand-made streams (empty, metadata, uncompressed); maxBytes; truncated / corrupted / random input returns nil, Err --- and never throws. Fixtures: tools/fixtures/brotli.py. +-- codecs/compress/Brotli tests: reference encoder streams (qualities 0..11, windows 10..24), hand-made streams. +-- Fixtures: tools/fixtures/brotli.py. local T = require("@tests/T") local Brotli = require("@rosetta/codecs/compress/Brotli") local Err = require("@rosetta/core/Err") @@ -10,14 +8,12 @@ local Fx = require("@tests/gen/brotli") local t = T.suite("brotli") --- the static dictionary do local d = Brotli.dictionary() t:check(d and buffer.len(d) == 122784, "dictionary size") t:eq(buffer.readstring(d :: buffer, 0, 8), "timedown", "dictionary starts with the length-4 words") end --- every case local nbytes = 0 for _, c in Fx.cases do local want = Fx.corpora[c.corpus] @@ -31,7 +27,6 @@ for _, c in Fx.cases do end t:note("%d fixture streams, %.1f MB decoded", #Fx.cases, nbytes / 1e6) --- at an offset inside a bigger buffer, with trailing bytes do local c = Fx.cases[30] local big = buffer.create(#c.data + 13) @@ -41,7 +36,6 @@ do t:check(out and buffer.tostring(out) == Fx.corpora[c.corpus] and e == 5 + #c.data, "at an offset") end --- hand-made streams do local bytes = T.bytes -- WBITS 16 (bit 0), ISLAST, ISLASTEMPTY: 0b110 = 6 @@ -72,7 +66,6 @@ do t:check(ok and r1 == nil and r2.code == Err.ARG, "a non-buffer argument returns Err.ARG") end --- maxBytes do local c for _, x in Fx.cases do @@ -110,7 +103,6 @@ do t:eq(bad, 0, "corrupted streams never decode to the original") end --- truncation, corruption and garbage never throw do local samples = {} for i, c in Fx.cases do diff --git a/tests/codecs/bzip2.luau b/tests/codecs/bzip2.luau index e723122..32b4f30 100644 --- a/tests/codecs/bzip2.luau +++ b/tests/codecs/bzip2.luau @@ -1,6 +1,4 @@ --- codecs/compress/Bzip2 tests: every fixture stream (Python bz2 = libbzip2, block sizes 1..9, RLE1 run edges, block-boundary --- runs, random / skewed data, concatenated streams with trailing garbage) decodes exactly; offsets / consumedEnd; --- maxBytes; CRC mismatches are Err.CHECKSUM; truncations are Err.TRUNCATED; the fuzz no-throw pass. +-- codecs/compress/Bzip2 tests: Python bz2 (libbzip2) streams decode exactly, CRC mismatches, truncations. -- Fixtures: tools/fixtures/bzip2.py. local T = require("@tests/T") local Bzip2 = require("@rosetta/codecs/compress/Bzip2") @@ -33,7 +31,6 @@ local function case(name: string): any error("no case " .. name) end --- inside a bigger buffer, at an offset do local c = case("text/l9") local big = buffer.create(#c.data + 20) @@ -44,7 +41,6 @@ do t:eq(consumed, 7 + #c.data, "consumedEnd at an offset") end --- maxBytes do local c = case("zeros/l9") local _, e = Bzip2.decompress(c.data, nil, nil, { maxBytes = 1000 }) @@ -53,7 +49,6 @@ do t:check(ok ~= nil, "maxBytes = exact size") end --- block CRC / stream CRC mismatches do local c = case("text/l9") local b = buffer.fromstring(c.data) @@ -84,7 +79,6 @@ do t:check(e3 and e3.code == Err.ARG, "bad offset") end --- fuzz do local samples = {} for i, c in Fx.cases do diff --git a/tests/codecs/dct.luau b/tests/codecs/dct.luau index 589797c..e5e4ac9 100644 --- a/tests/codecs/dct.luau +++ b/tests/codecs/dct.luau @@ -1,7 +1,5 @@ --- codecs/image/Dct tests: the islow inverse DCT against a double-precision reference (within 1 level per sample, as T.81 --- annex A accuracy needs), forward DCT + quantiser against the reference transform (round to nearest of v / (8 q)), --- fdct -> idct round trips at q = 1 within 1 level, edge replication of fdctQuantize, and garbage coefficients never --- throw (outputs stay clamped). The bit-exact djpeg / cjpeg checks are in tests/image/jpeg.luau. +-- codecs/image/Dct tests: the islow IDCT against a double-precision reference, the forward DCT + quantiser. +-- The bit-exact djpeg / cjpeg checks are in tests/image/jpeg.luau. local T = require("@tests/T") local Dct = require("@rosetta/codecs/image/Dct") @@ -62,7 +60,6 @@ do t:note("idct: worst error %d over 300 random blocks", worst) end --- forward + quantiser do local worst = 0 for _ = 1, 200 do @@ -91,7 +88,6 @@ do end end t:check(worst <= 0.75, "fdct + quantise within rounding of the float reference: " .. worst) - -- round trip at q = 1 local rt = 0 for _ = 1, 100 do local src = buffer.create(64) diff --git a/tests/codecs/deflate.luau b/tests/codecs/deflate.luau index ad1b138..14583d9 100644 --- a/tests/codecs/deflate.luau +++ b/tests/codecs/deflate.luau @@ -1,7 +1,5 @@ --- codecs/compress/Deflate tests: every fixture case (Python zlib, levels 0-9, every strategy, small windows, flushes, gzip --- headers, multi-member gzip) decodes; exact-size mode; checksum vectors; the compressor round-trips every corpus at --- every level (and its zlib / gzip framing); truncated / corrupted / random input returns nil, Err and never throws. --- Ported from deflate-luau tests/inflate.luau. Fixtures: tools/fixtures/deflate.py. +-- codecs/compress/Deflate tests: Python zlib streams (levels 0-9, every strategy, gzip), the compressor round trips. +-- Fixtures: tools/fixtures/deflate.py. local T = require("@tests/T") local Deflate = require("@rosetta/codecs/compress/Deflate") local Err = require("@rosetta/core/Err") @@ -19,7 +17,6 @@ local function decode(kind: string, b: buffer, ...: any): (buffer?, any) end end --- checksum vectors t:eq(Deflate.crc32("123456789"), 0xCBF43926, "crc32 check value") t:eq(Deflate.crc32(""), 0, "crc32 empty") t:eq(Deflate.adler32("Wikipedia"), 0x11E60398, "adler32 Wikipedia") @@ -35,7 +32,6 @@ do t:eq(Deflate.crc32(b, 3, 17), Deflate.crc32(string.sub(s, 4, 20)), "crc32 range") end --- every case decodes to its corpus local nbytes = 0 for _, c in Fx.cases do local want = Fx.corpora[c.corpus] @@ -65,10 +61,8 @@ for _, c in Fx.cases do end t:note("%d fixture streams, %.1f MB decoded", #Fx.cases, nbytes / 1e6) --- strings are accepted t:check(buffer.tostring((Deflate.zlib(Fx.cases[25].data))) == Fx.corpora[Fx.cases[25].corpus], "string input") --- corrupted checksums do local z for _, c in Fx.cases do @@ -93,7 +87,6 @@ do end end --- hand-made streams do local bytes = T.bytes -- stored block "hi" then a fixed block with only end-of-block @@ -148,7 +141,6 @@ do t:check(e and e.code == Err.ARG, "bad level returns Err.ARG") end --- truncation, corruption and garbage never throw do local samples = {} local kinds = {} diff --git a/tests/codecs/draco.luau b/tests/codecs/draco.luau index 2a2f068..8f5879c 100644 --- a/tests/codecs/draco.luau +++ b/tests/codecs/draco.luau @@ -1,8 +1,5 @@ --- codecs/model/Draco tests: Google's Draco test data (bitstreams 0.9 - 2.2) and files encoded by draco_encoder 1.5.7 --- at every compression level, quantization and as point clouds, decoded and compared byte for byte (points, faces, --- every attribute's values per point, as CRCs) with libdraco's own decoder (tools/fixtures/_draco_dump.cc), kd-tree --- point clouds included; argument errors; the fuzz no-throw pass (which also fails on any internal error the --- decoder's safety net caught). Fixtures: tools/fixtures/draco.py. +-- codecs/model/Draco tests: Google's test data and draco_encoder 1.5.7 files against libdraco's decoder. +-- Fixtures: tools/fixtures/draco.py (dumps from tools/fixtures/_draco_dump.cc). local T = require("@tests/T") local Draco = require("@rosetta/codecs/model/Draco") local Err = require("@rosetta/core/Err") @@ -50,14 +47,12 @@ for _, c in Cases do end t:note("%d files decoded exactly like libdraco (%d kd-tree point clouds), %d rejected by both", counts.exact, counts.kd, counts.rejected) --- the attribute lookup and the header local first = Cases[1] local info = Draco.info(first.data) t:check(info and (info.kind == "mesh" or info.kind == "points"), "info") t:check(Draco.sniff(buffer.fromstring(first.data)), "sniff") t:check(not Draco.sniff(buffer.fromstring("DRAC")), "sniff short") --- errors local _, e1 = Draco.decode(buffer.fromstring("NOTDRACO......")) t:check(e1 and e1.code == Err.CORRUPT, "not Draco data: " .. tostring(e1)) local _, e2 = Draco.decode(buffer.fromstring("DRACO\9\0\1\1\0\0")) diff --git a/tests/codecs/etc.luau b/tests/codecs/etc.luau index 727f53f..56ee90b 100644 --- a/tests/codecs/etc.luau +++ b/tests/codecs/etc.luau @@ -1,6 +1,5 @@ --- codecs/image/Etc tests: random ETC1 / ETC2 (every mode: individual, differential, T, H, planar; RGB A1 opaque and --- transparent; RGBA with EAC alpha) and EAC R11 / RG11 (unsigned, signed, multiplier 0) blocks against Godot 4's --- decode (etcpak); odd sizes; the 16-bit EAC output; errors; the fuzz no-throw pass. Fixtures: tools/fixtures/etc.py. +-- codecs/image/Etc tests: random ETC1 / ETC2 / EAC blocks against Godot 4's decode (etcpak), the 16-bit EAC output. +-- Fixtures: tools/fixtures/etc.py. local T = require("@tests/T") local Etc = require("@rosetta/codecs/image/Etc") local Fx = require("@tests/gen/etc") @@ -99,7 +98,6 @@ for _, c in Fx do end t:check(ok, c.name .. ": rgba16 ~ rgba8") end - -- from / into offsets local big = buffer.create(buffer.len(src) + 3) buffer.copy(big, 3, src) local out = buffer.create(n * 4 + 4) diff --git a/tests/codecs/explode.luau b/tests/codecs/explode.luau index 4766e9f..87467ea 100644 --- a/tests/codecs/explode.luau +++ b/tests/codecs/explode.luau @@ -1,6 +1,5 @@ --- codecs/compress/Explode tests: PKWARE DCL streams written by StormLib's SCompImplode (tools/fixtures/mpq.py: --- text, noise, a short repeat, zeros) decompress to the source bytes; maxOut stops early; hand-made streams with --- coded literals; bad headers and truncations; the fuzz pass. +-- codecs/compress/Explode tests: PKWARE DCL streams from StormLib's SCompImplode, hand-made streams, bad headers. +-- Fixtures: tools/fixtures/mpq.py. local T = require("@tests/T") local Explode = require("@rosetta/codecs/compress/Explode") local Crc32 = require("@rosetta/core/Crc32") diff --git a/tests/codecs/h263.luau b/tests/codecs/h263.luau index f43c294..b4e914f 100644 --- a/tests/codecs/h263.luau +++ b/tests/codecs/h263.luau @@ -1,9 +1,5 @@ --- codecs/video/H263 tests. Against `ffmpeg -idct int` (tools/fixtures/h263.py): H.263 streams (sub-QCIF .. 4CIF, GOB --- headers, DQUANT, q 1 .. high quantisers), H.263+ PLUSPTYPE streams (custom sizes, sizes that are not a multiple of --- 16, the rounding type, unrestricted vectors with reversible codes, slice structure) and Sorenson Spark streams (standard, 8-bit and --- 16-bit custom sizes, 11-bit escapes, high motion, disposable inter pictures) decode one picture at a time to exactly --- ffmpeg's planes, every frame; header info; frameImage; the registry's decoders (h263, flv1); unsupported options are --- UNSUPPORTED; truncated and corrupted pictures never throw; the fuzz no-throw pass. +-- codecs/video/H263 tests: H.263, H.263+ and Sorenson Spark streams bit-exact against `ffmpeg -idct int`. +-- Fixtures: tools/fixtures/h263.py. local T = require("@tests/T") local H263 = require("@rosetta/codecs/video/H263") local Video = require("@rosetta/codecs/video/Video") @@ -55,7 +51,6 @@ local function crcs(f: any): (number, number, number) return planeCrc(f.y, f.stride, w, h), planeCrc(f.cb, f.stride // 2, cw, ch), planeCrc(f.cr, f.stride // 2, cw, ch) end --- differing luma samples against a reference frame (detail on a mismatch) local function lumaDiff(f: any, ref: buffer): (number, number) local n, first = 0, -1 for y = 0, f.height - 1 do @@ -71,7 +66,6 @@ local function lumaDiff(f: any, ref: buffer): (number, number) return n, first end --- 1. every stream against ffmpeg, bit-exact local total = 0 local disposables = 0 for _, fx in STREAMS do @@ -117,7 +111,6 @@ for _, fx in STREAMS do end t:check(disposables > 0, "disposable Sorenson pictures decoded (" .. disposables .. ")") --- 2. header info do local fx = STREAMS[8] -- plus_custom local file = b64(fx.file) @@ -136,14 +129,12 @@ do t:check(e ~= nil and e.code == Err.CORRUPT, "no start code: CORRUPT") end --- 3. unsupported H.263+ options for name, data in BAD do local dec = H263.new() local f, e = dec:decode(b64(data)) t:check(f == nil and e ~= nil and e.code == Err.UNSUPPORTED, name .. ": UNSUPPORTED (" .. tostring(e) .. ")") end --- 4. frameImage do local fx = STREAMS[14] local dec = H263.new({ flv = true }) @@ -159,7 +150,6 @@ do t:check(dec:decode(42 :: any) == nil, "decode of a non-buffer is nil") end --- 5. the registry's decoders do t:check(Video.fromFourcc("H263") == "h263" and Video.fromFourcc("s263") == "h263" and Video.fromFourcc("FLV1") == "flv1", "registry names") t:check(Video.canDecode("h263") and Video.canDecode("flv1"), "registry decoders") @@ -191,7 +181,6 @@ do end end --- 6. robustness: truncated and corrupted pictures, garbage (never throws), the fuzz pass do local samples = {} for _, idx in { 1, 6, 8, 10, 11, 13, 16 } do diff --git a/tests/codecs/h264.luau b/tests/codecs/h264.luau index 4d58a1e..780d22f 100644 --- a/tests/codecs/h264.luau +++ b/tests/codecs/h264.luau @@ -1,8 +1,5 @@ --- codecs/video/H264 tests: libx264 streams at many settings (Baseline / Main / High, CAVLC / CABAC, B frames, references, --- weighted prediction, 8x8 transforms, scaling matrices, slices, odd sizes with cropping, ...) decoded and compared --- per frame with ffmpeg's decoder (CRC-32 of the yuv420p planes, bit-exact); the AVCC (avcC + length-prefixed --- samples) and NAL-at-a-time paths; pts propagation; UNSUPPORTED streams (interlaced, 4:2:2, 4:4:4, 10-bit); error --- codes; and the fuzz no-throw pass. Fixtures: tools/fixtures/h264.py. +-- codecs/video/H264 tests: libx264 streams at many settings, per frame against ffmpeg (CRC-32 of yuv420p planes). +-- Fixtures: tools/fixtures/h264.py. local T = require("@tests/T") require("@rosetta/host") -- LuaJIT: the trace limits the api sets (host/init.luau) local H264 = require("@rosetta/codecs/video/H264") @@ -13,7 +10,6 @@ local Bad = require("@tests/gen/h264_bad") local t = T.suite("h264") --- 1. every stream, whole, against ffmpeg local nframes = 0 for _, c in Cases do local frames, err = H264.decodeAll(c.data) @@ -33,7 +29,6 @@ for _, c in Cases do end t:note("%d streams, %d frames bit-exact with ffmpeg", #Cases, nframes) --- 2. AVCC samples, NAL-at-a-time input, pts local function splitAnnexB(s: string): { string } local out = {} local i = 1 @@ -107,13 +102,11 @@ for _, c in Cases do end end --- 3. unsupported streams for _, c in Bad do local frames, err = H264.decodeAll(c.data) t:check(frames == nil and err and err.code == c.code, c.name .. ": " .. tostring(err)) end --- 4. error codes do local _, e1 = H264.decodeAll(123 :: any) t:check(e1 and e1.code == Err.ARG, "decode of a number: ARG") @@ -134,7 +127,6 @@ do t:check(ld and #ld == #c.frames and Crc32.of(ld[#ld].image.pixels) == c.frames[#c.frames], "lowDelay on a P-only stream") end --- 5. fuzz: streams with damaged bytes / truncations must never throw local samples = {} for _, c in Cases do if #c.data < 20000 and #samples < 14 then diff --git a/tests/codecs/h264_jvt.luau b/tests/codecs/h264_jvt.luau index b9b2eb6..386c8fb 100644 --- a/tests/codecs/h264_jvt.luau +++ b/tests/codecs/h264_jvt.luau @@ -1,8 +1,5 @@ --- codecs/video/H264 conformance: a selection of the ITU-T H.264.1 (JVT) conformance bitstreams (Baseline / Main / Extended --- without SP / High: CAVLC, CABAC, B frames, weighted prediction, multiple slices, MMCO / long-term references, --- frame_num gaps, cropping, PCM, 8x8 transforms, scaling matrices, ...) decoded bit-exact against the reference --- decoder's yuv (JM, shipped in each zip; ffmpeg where there is none), and interlaced / SP / 4:2:2 streams refused --- with UNSUPPORTED. Fixtures: tools/fixtures/h264_jvt.py (downloaded from itu.int; skipped when unreachable). +-- codecs/video/H264 conformance: ITU-T H.264.1 (JVT) bitstreams bit-exact against the JM yuv (ffmpeg where none). +-- Fixtures: tools/fixtures/h264_jvt.py (downloaded from itu.int; skipped when unreachable). local T = require("@tests/T") require("@rosetta/host") -- LuaJIT: the trace limits the api sets (host/init.luau) local H264 = require("@rosetta/codecs/video/H264") diff --git a/tests/codecs/jpeg.luau b/tests/codecs/jpeg.luau index 2df942e..eb0a170 100644 --- a/tests/codecs/jpeg.luau +++ b/tests/codecs/jpeg.luau @@ -1,9 +1,5 @@ --- codecs/image/Jpeg tests (the Motion-JPEG side; tests/image/jpeg.luau covers the still-image decoder and encoder through --- image/jpeg): ffmpeg mjpeg frames (4:2:0, 4:2:2, 4:4:4, odd sizes, stripped DHT, AVI1 + junk after EOI) decoded --- to yuv420p bit-exact with libjpeg-turbo's IDCT planes (TurboJPEG) and to rgba8 bit-exact with djpeg, and within --- PSNR thresholds of ffmpeg's own decode; an interlaced AVI1 frame (two fields) woven; the yuv420p encoder --- byte-identical to TurboJPEG's tj3CompressFromYUV8, read back by djpeg (exact) and ffmpeg (PSNR); the API's --- arguments; the fuzz no-throw pass. Fixtures: tools/fixtures/mjpeg.py. +-- codecs/image/Jpeg tests (Motion-JPEG; still images are in tests/image/jpeg.luau): ffmpeg mjpeg frames, the encoder. +-- Fixtures: tools/fixtures/mjpeg.py. local T = require("@tests/T") local Jpeg = require("@rosetta/codecs/image/Jpeg") local Crc32 = require("@rosetta/core/Crc32") @@ -37,7 +33,6 @@ for _, c in Enc do c.want = b64(c.want) end --- PSNR of n bytes of a at ao against b at bo local function psnr(a: buffer, ao: number, b: buffer, bo: number, n: number): number local se = 0 for i = 0, n - 1 do @@ -50,7 +45,6 @@ local function psnr(a: buffer, ao: number, b: buffer, bo: number, n: number): nu return 10 * math.log10(255 * 255 * n / se) end --- PSNR of the RGB channels of two rgba8 buffers of n pixels local function psnrRgb(a: buffer, b: buffer, n: number): number local se = 0 for i = 0, n - 1 do @@ -71,7 +65,7 @@ local function hasDht(s: string): boolean return at ~= nil and sos ~= nil and at < sos end --- 1. ffmpeg's frames: yuv420p (TurboJPEG planes) and rgba8 (djpeg) bit-exact, PSNR against ffmpeg's decode +-- yuv420p bit-exact with TurboJPEG's planes, rgba8 bit-exact with djpeg, PSNR against ffmpeg's decode do local frames, worstY, worstC, worstRgb = 0, 99, 99, 99 for _, s in Fx.streams do @@ -118,7 +112,7 @@ do t:note("%d ffmpeg mjpeg frames bit-exact (yuv420p: TurboJPEG, rgba8: djpeg); worst PSNR against ffmpeg: luma %.1f, chroma %.1f, rgba %.1f dB", frames, worstY, worstC, worstRgb) end --- 2. an interlaced frame: two fields (AVI1 polarity 1) woven, field 1 on the even rows +-- an interlaced frame: two fields (AVI1 polarity 1) woven, field 1 on the even rows do local F = Fx.fields local b = buffer.fromstring(F.data) @@ -140,7 +134,7 @@ do t:check(Jpeg.info(b).avi1 == 1, "fields: info.avi1") end --- 3. the yuv420p encoder: byte-identical with TurboJPEG, read back by djpeg (exact) and ffmpeg (PSNR) +-- the yuv420p encoder: byte-identical with TurboJPEG's tj3CompressFromYUV8 do local exact = 0 for _, c in Enc do @@ -193,7 +187,6 @@ do t:check(sd.meta.text and sd.meta.text.comment == "hello" and sd.meta.dpi and sd.meta.dpi.x == 72, "segments and density") end --- 4. the API: ranges, options, fallbacks, errors do local s = Fx.streams[1] local data = s.frames[1].data @@ -237,7 +230,7 @@ do t:note("%d truncated frames, %d decoded partially", cuts, partial) end --- 5. speed (a note; tools/bench.luau has the real numbers) +-- speed (a note; tools/bench.luau has the real numbers) do local s = Fx.streams[1] local frames = {} @@ -254,7 +247,6 @@ do t:note("%dx%d yuv420p decode: %.0f fps", s.width, s.height, n / (os.clock() - t0)) end --- 6. fuzz do local samples = {} for k, s in Fx.streams do diff --git a/tests/codecs/json.luau b/tests/codecs/json.luau index 45234b5..18eb23d 100644 --- a/tests/codecs/json.luau +++ b/tests/codecs/json.luau @@ -1,6 +1,4 @@ --- codecs/text/Json tests: the JSONTestSuite parsing corpus (y_ must parse to Python's value, n_ must fail, i_ must not --- throw), Python json.dumps output in four styles parsed and reproduced byte for byte (compact sorted, ordered, --- indent 2, ensure_ascii), events / lines / decodeAt / writer, options, error codes, and the fuzz pass. +-- codecs/text/Json tests: the JSONTestSuite corpus, Python json.dumps output reproduced byte for byte, the API. -- Fixtures: tools/fixtures/json.py. local T = require("@tests/T") local Json = require("@rosetta/codecs/text/Json") @@ -47,7 +45,7 @@ local function fromEvents(s: string): (any, any) return top, nil end --- 1. JSONTestSuite +-- JSONTestSuite: y_ must parse to Python's value, n_ must fail, i_ must not throw local counts = { y = 0, n = 0, i = 0, iok = 0 } for _, c in Suite do local v, err = Json.decode(c.data) @@ -71,7 +69,6 @@ for _, c in Suite do end t:note("JSONTestSuite: %d y_ accepted, %d n_ rejected, %d of %d i_ accepted", counts.y, counts.n, counts.iok, counts.i) --- 2. Python's json.dumps output: parse, compare, re-encode byte for byte for i, c in Corpus do local v, err = Json.decode(c.compact) t:check(v ~= nil, "corpus " .. i .. ": " .. tostring(err)) @@ -85,7 +82,6 @@ for i, c in Corpus do t:eq(Canon.of(Json.decode(c.pretty)), c.canon, "corpus " .. i .. ": pretty parse") end --- 3. options and API do local v = Json.decode('[12345678901234567890, -9007199254740993, 9007199254740991, 1.5e300]', { bigInts = "string" }) t:eq(v[1], "12345678901234567890", "bigInts string") @@ -122,7 +118,6 @@ do end end --- 4. streaming: lines, decodeAt, writer do local got = {} for _, v in Json.lines('{"a":1}\n[2]\n"x"\n 3 ') do @@ -170,7 +165,6 @@ do t:check(w5:tostring() == nil, "writer: unclosed") end --- 5. errors local function code(s: string, opts: any?): string? local _, e = Json.decode(s, opts) return e and e.code @@ -189,7 +183,6 @@ do t:eq(e and e.offset, 6, "error offset") end --- 6. fuzz local samples = {} for i = 1, 40 do table.insert(samples, Corpus[i].compact) diff --git a/tests/codecs/legacy.luau b/tests/codecs/legacy.luau index c2bc268..f3039e9 100644 --- a/tests/codecs/legacy.luau +++ b/tests/codecs/legacy.luau @@ -1,7 +1,4 @@ --- codecs/video/Legacy tests: Cinepak (24-bit, grey, 8-bit palettised, several strips, a 92x68 size), Microsoft Video 1 --- (16-bit, 8-bit with an AVI palette), QuickTime RLE (depths 1 / 2 / 4 / 8 with colour tables, default Macintosh --- tables and grey ramps; 16 / 24 / 32-bit and grey from ffmpeg) and QuickTime SMC, in AVI, MOV and MKV: every frame --- equals ffmpeg's decode (CRC-32 of rgba); seeking; the registry entries; the fuzz pass on each codec's packet decoder. +-- codecs/video/Legacy tests: Cinepak, MS Video 1, QuickTime RLE and SMC: every frame equals ffmpeg's (CRC-32 of rgba). -- Fixtures: tools/fixtures/legacy.py. local T = require("@tests/T") local F = require("@rosetta") @@ -12,7 +9,6 @@ local Fx = require("@tests/gen/legacy_cases") local t = T.suite("legacy") --- the registry t:eq(Video.fromFourcc("cvid"), "cinepak", "cvid") t:eq(Video.fromFourcc("CRAM"), "msvideo1", "CRAM") t:eq(Video.fromFourcc("msvc"), "msvideo1", "msvc") @@ -50,7 +46,6 @@ for _, c in Fx do v:seek(0) local f = v:nextFrame() t:check(f ~= nil and Crc32.of(f.image.pixels) == c.frames[1], label .. ": seek(0)") - -- packets for the fuzz pass local dmx = v.demuxer local tr = dmx:track("video") if not samples[c.codec] then diff --git a/tests/codecs/lz4.luau b/tests/codecs/lz4.luau index 06f40e0..7806c37 100644 --- a/tests/codecs/lz4.luau +++ b/tests/codecs/lz4.luau @@ -1,7 +1,5 @@ --- codecs/compress/Lz4 tests: every reference block (python-lz4 fast at accelerations 1 / 4 / 16, HC 4 / 9 / 12) --- decodes to its corpus, with and without the size; our encoder's blocks decode with the reference (fixture verdicts) --- and round trip here; linked blocks through decodeInto's history; error codes; truncated / mutated / random blocks --- never throw. Fixtures: tools/fixtures/lz4.py. +-- codecs/compress/Lz4 tests: python-lz4 blocks (fast 1 / 4 / 16, HC 4 / 9 / 12), our encoder, linked blocks. +-- Fixtures: tools/fixtures/lz4.py. local T = require("@tests/T") local Lz4 = require("@rosetta/codecs/compress/Lz4") local Err = require("@rosetta/core/Err") @@ -63,7 +61,6 @@ do t:check(b2 ~= nil, "second half") end --- errors do local _, e1 = Lz4.decompress("") t:check(e1 and e1.code == Err.TRUNCATED, "empty: " .. tostring(e1)) diff --git a/tests/codecs/lzma.luau b/tests/codecs/lzma.luau index 278e6fb..55d0a7b 100644 --- a/tests/codecs/lzma.luau +++ b/tests/codecs/lzma.luau @@ -1,7 +1,5 @@ --- codecs/compress/Lzma tests: every fixture (liblzma through Python's lzma module and the xz CLI: presets 0-9 and -e, lc / lp / --- pb variants, raw LZMA1 / LZMA2, .lzma files, xz with every check type, BCJ and delta filters, multiple blocks, --- multiple streams and stream padding) decodes to its corpus; consumed offsets; checksum / size / truncation errors; --- maxBytes; the fuzz no-throw pass. Fixtures: tools/fixtures/lzma.py. +-- codecs/compress/Lzma tests: liblzma (Python lzma, the xz CLI) .lzma / .xz / raw streams, check and size errors. +-- Fixtures: tools/fixtures/lzma.py. local T = require("@tests/T") local Lzma = require("@rosetta/codecs/compress/Lzma") local Err = require("@rosetta/core/Err") @@ -34,7 +32,6 @@ for _, c in Fx.cases do end t:note("%d fixture streams, %.1f MB decoded", #Fx.cases, nbytes / 1e6) --- at an offset inside a bigger buffer, with trailing bytes do for _, c in Fx.cases do if c.kind == "xz" and c.name == "text/xz-6" then @@ -47,7 +44,6 @@ do end end --- errors do local xz, xzc for _, c in Fx.cases do @@ -60,11 +56,9 @@ do -- the check field: the last bytes before the index; flip a data bit near the end of the block instead local b = buffer.fromstring(xzc.data) local n = buffer.len(b) - -- footer magic buffer.writeu8(b, n - 1, 0) local _, e1 = Lzma.xz(b) t:check(e1 and (e1.code == Err.CORRUPT or e1.code == Err.CHECKSUM), "bad footer: " .. tostring(e1)) - -- the stream header CRC local b2 = buffer.fromstring(xz.data) buffer.writeu8(b2, 8, bit32.bxor(buffer.readu8(b2, 8), 1)) local _, e2 = Lzma.xz(b2) @@ -83,7 +77,6 @@ do -- truncations are TRUNCATED or CORRUPT, never a throw local _, e4 = Lzma.xz(buffer.fromstring(string.sub(xzc.data, 1, #xzc.data // 2))) t:check(e4 and e4.code == Err.TRUNCATED, "truncated xz: " .. tostring(e4)) - -- maxBytes local _, e5 = Lzma.xz(xzc.data, nil, nil, { maxBytes = 1000 }) t:check(e5 and e5.code == Err.LIMIT, "maxBytes: " .. tostring(e5)) local ok, r1, r2 = pcall(Lzma.xz, 5 :: any) @@ -107,7 +100,6 @@ do end end --- fuzz do local samples = {} for i, c in Fx.cases do diff --git a/tests/codecs/lzw.luau b/tests/codecs/lzw.luau index 1f13972..c4166e3 100644 --- a/tests/codecs/lzw.luau +++ b/tests/codecs/lzw.luau @@ -1,6 +1,5 @@ --- codecs/compress/Lzw tests: GIF (LSB) and TIFF (MSB, early change) code streams from Pillow / libtiff decode to their data; --- our encoder round-trips random and structured data at every GIF minimum code size and through table resets; the --- output limit, truncated and corrupt streams; the fuzz no-throw pass. Fixtures: tools/fixtures/lzw.py. +-- codecs/compress/Lzw tests: GIF (LSB) and TIFF (MSB, early change) streams from Pillow / libtiff, the encoder. +-- Fixtures: tools/fixtures/lzw.py. local T = require("@tests/T") local Lzw = require("@rosetta/codecs/compress/Lzw") local Fx = require("@tests/gen/lzw") @@ -13,7 +12,6 @@ local function dec(codes: buffer, n: number, variant: string, min: number?): (st return buffer.tostring(out), got, err end --- reference streams for _, c in Fx.gif do local s, n, err = dec(buffer.fromstring(c.codes), #c.data, "gif", c.min) t:check(err == nil, "gif " .. c.name .. ": " .. tostring(err)) @@ -28,7 +26,6 @@ for _, c in Fx.tiff do end t:note("%d GIF and %d TIFF reference streams decode", #Fx.gif, #Fx.tiff) --- round trips local rand = T.rng(3) local function data(n: number, kind: number, max: number): buffer local b = buffer.create(n) @@ -77,7 +74,6 @@ do t:check(buffer.readstring(out, 10, 100) == buffer.readstring(big, 100, 100), "sub-range data") end --- limits, truncation, corruption do local d = data(1000, 2, 16) local codes = Lzw.encode(d, 0, 1000, "gif", 4) @@ -94,7 +90,6 @@ do t:check(err4 == "corrupt", "bad min code size") end --- fuzz do local samples = {} for i, c in Fx.gif do diff --git a/tests/codecs/mat4.luau b/tests/codecs/mat4.luau index d6834ec..45f752e 100644 --- a/tests/codecs/mat4.luau +++ b/tests/codecs/mat4.luau @@ -1,5 +1,4 @@ --- codecs/model/Mat4 tests: compose / decompose round trips (with a mirrored axis), strict decompose refusing shear, --- quaternion <-> matrix, Euler orders, the affine inverse, row-major conversion, points, the normal matrix. +-- codecs/model/Mat4 tests: compose / decompose, quaternions, Euler orders, the affine inverse, the normal matrix. local T = require("@tests/T") local Mat4 = require("@rosetta/codecs/model/Mat4") From fe7566cbba2eeb5bed8bc1aa9aee11200a113c18 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:50:23 -0500 Subject: [PATCH 17/25] tests/model: comments: specs only --- tests/model/3ds.luau | 25 +++---------------------- tests/model/3mf.luau | 19 ++----------------- tests/model/_rbx.luau | 15 ++++----------- tests/model/_soup.luau | 13 +++---------- tests/model/_vrml_common.luau | 4 +--- tests/model/b3d.luau | 12 ++---------- tests/model/bsp.luau | 14 ++------------ tests/model/dae.luau | 18 ++---------------- tests/model/fbx.luau | 22 ++-------------------- tests/model/gltf.luau | 15 ++------------- tests/model/gltf_draco.luau | 9 ++------- tests/model/iqm.luau | 16 ++-------------- tests/model/ldraw.luau | 17 ++--------------- tests/model/lwo.luau | 13 ++----------- tests/model/mca.luau | 8 +------- tests/model/md2.luau | 8 +------- tests/model/md3.luau | 9 ++------- tests/model/md5.luau | 10 +--------- tests/model/mdl.luau | 13 +------------ tests/model/ms3d.luau | 17 ++--------------- tests/model/obj.luau | 17 ++--------------- tests/model/off.luau | 14 ++------------ tests/model/ply.luau | 17 ++--------------- tests/model/pmx.luau | 12 ++---------- tests/model/qb.luau | 9 ++------- tests/model/rbxm.luau | 13 +------------ tests/model/rbxmx.luau | 7 +------ tests/model/robloxmesh.luau | 9 +-------- tests/model/robloxmesh_draco.luau | 8 ++------ tests/model/schematic.luau | 16 +++------------- tests/model/smd.luau | 8 ++------ tests/model/stl.luau | 16 ++-------------- tests/model/usda.luau | 30 +++--------------------------- tests/model/vox.luau | 14 ++------------ tests/model/vrml.luau | 17 ++--------------- tests/model/x.luau | 14 ++------------ tests/model/x3d.luau | 14 ++------------ 37 files changed, 72 insertions(+), 440 deletions(-) diff --git a/tests/model/3ds.luau b/tests/model/3ds.luau index c2ae5da..017dab7 100644 --- a/tests/model/3ds.luau +++ b/tests/model/3ds.luau @@ -1,9 +1,5 @@ --- model/3ds tests: assimp's 3DS test models (meshes, materials, textures, keyframer hierarchies, pivots, camera / --- target / rotation animation, cameras, lights) and assimp's 3DS exporter output, against assimp (meshes, faces, --- corners, materials, animations, cameras, lights, world bounds); the keyframer placing every mesh where its mesh --- matrix says; round trips through our writer (world triangles, materials, textures, cameras, lights, sampled --- animation) for the reference files and for glTF sample models; assimp reading our files like the originals --- (3ds_xcheck); errors; the fuzz no-throw pass. Fixtures: tools/fixtures/3ds.py. +-- model/3ds tests: assimp's 3DS models and exporter output against assimp; round trips; assimp reading ours. +-- Fixtures: tools/fixtures/3ds.py. local T = require("@tests/T") local F = require("@rosetta") local ThreeDs = require("@rosetta/model/3ds") @@ -32,7 +28,6 @@ local function near(a: number, b: number, eps: number): boolean return math.abs(a - b) <= eps * math.max(1, math.abs(a), math.abs(b)) end --- placed primitives, triangles, corners local function counts(scene: any): (number, number, number) local prims, faces, corners = 0, 0, 0 local seen = {} @@ -92,9 +87,7 @@ local function bstr(lo: any, hi: any): string return string.format("(%.4g %.4g %.4g) (%.4g %.4g %.4g)", lo[1], lo[2], lo[3], hi[1], hi[2], hi[3]) end --- ------------------------------------------------------------------------------------------------ reference files --- assimp ignores the camera / light frame of their children (CameraRollAnimWithChildObject: a box linked to the --- camera); our bounds follow the mesh matrices there (checked below) +-- assimp ignores the camera / light frame of their children (CameraRollAnimWithChildObject); ours follow the mesh matrices local ASSIMP_BOUNDS_DIFFER = { ["assimp/models/CameraRollAnimWithChildObject.3ds"] = true } local function boundsDiffer(i: number): boolean return ASSIMP_BOUNDS_DIFFER[Cases[i].name] == true @@ -172,7 +165,6 @@ do t:note("%d keyframer scenes match their stored vertices", n) end --- ------------------------------------------------------------------------------------------------ round trips local function triArea(prim: any): number local P = S.reader(prim.attributes.POSITION) :: any local I = S.reader(prim.indices) :: any @@ -187,7 +179,6 @@ local function triArea(prim: any): number return area end --- the world matrices of the nodes with a camera / light, in tree order local function worldOf(s: any, field: string): { { number } } local out = {} local function visit(i: number, parent: { number }) @@ -206,7 +197,6 @@ local function worldOf(s: any, field: string): { { number } } return out end --- channel value at a time (LINEAR / STEP; quaternions lerped the short way) local function evalCh(ch: any, time: number, comps: number): { number } local IN, OUT = S.reader(ch.input) :: any, S.reader(ch.output) :: any local n = ch.input.count @@ -243,7 +233,6 @@ local function evalCh(ch: any, time: number, comps: number): { number } return v(n - 1) end --- the world matrix of every named node at a time (animations[1] applied) local function posed(s: any, time: number): { [string]: { number } } local byNode: { [number]: { [string]: any } } = {} local anim = s.animations[1] @@ -349,7 +338,6 @@ local function compare(a: any, b: any, label: string, eps: number, animTimes: { t:check(near(hfov(c), hfov(c2), 1e-5), label .. ": camera " .. k .. " fov") end end - -- one timeline: the first animation's node transforms local trs = false for _, ch in (if a.animations[1] then a.animations[1].channels else {}) :: { any } do trs = trs or ch.path ~= "weights" @@ -406,7 +394,6 @@ for i, c in Cases do end end --- glTF sample models through 3DS local gltfScenes = {} local ng = 0 for gi, g in Picks do @@ -435,8 +422,6 @@ for gi, g in Picks do end t:note("%d reference files and %d glTF models through our writer and back", nrt, ng) --- ------------------------------------------------------------------------------------------------ cross-check --- assimp reads our files like the originals local nx = 0 for _, x in Xcheck do local a = x.assimp @@ -468,7 +453,6 @@ for _, x in Xcheck do end t:note("%d of our files read back by assimp", nx) --- ------------------------------------------------------------------------------------------------ details do local byName = {} for i, c in Cases do @@ -530,7 +514,6 @@ do end t:check(types.point and types.spot, "omni and spot lights") end - -- the api local s = F.load(Cases[1].data) t:check(s and s.kind == "scene" and s.meta.source.format == "3ds", "F.load detects 3DS") local viaApi = F.save(s, nil, { format = "3ds" }) @@ -564,7 +547,6 @@ do t:eq(back.nodes[2].name, "copy", "instance name") end --- ------------------------------------------------------------------------------------------------ errors do local empty = decode("MM\6\0\0\0") t:check(empty and #empty.meshes == 0 and #empty.nodes == 0, "an empty main chunk: an empty scene") @@ -581,7 +563,6 @@ do t:eq(ThreeDs.sniff(Bytes.reader(buffer.fromstring("MM junk junk junk"))), 0, "sniff junk") end --- ------------------------------------------------------------------------------------------------ fuzz do local samples = {} for i, c in Cases do diff --git a/tests/model/3mf.luau b/tests/model/3mf.luau index 8c57175..38afd21 100644 --- a/tests/model/3mf.luau +++ b/tests/model/3mf.luau @@ -1,9 +1,5 @@ --- model/3mf tests: the lib3mf test suite and SDK files, assimp's box.3mf and files from assimp's / trimesh's 3MF --- exporters against lib3mf (world triangles, area, bounds through build items and components; unit), assimp and --- trimesh; our writer's output read back by lib3mf / assimp / trimesh (3mf_xcheck); round trips through our own reader --- (materials, vertex colours, textures, hierarchy, units); hand-written packages for per-corner colour / texture --- groups, composite and multiproperties, components across model parts (p:path), units; error codes; the fuzz --- no-throw pass. Fixtures: tools/fixtures/3mf.py. +-- model/3mf tests: lib3mf's suite and SDK files, assimp and trimesh exports, against lib3mf, assimp and trimesh. +-- Fixtures: tools/fixtures/3mf.py. local T = require("@tests/T") local ThreeMf = require("@rosetta/model/3mf") local Bytes = require("@rosetta/core/Bytes") @@ -28,7 +24,6 @@ local function near(a: number, b: number, eps: number): boolean return math.abs(a - b) <= eps * math.max(1, math.abs(a), math.abs(b)) end --- world-space triangles, area and bounds of every placed primitive local function metrics(scene: any): (number, number, { number }, { number }) local tris, area = 0, 0 local lo, hi = { math.huge, math.huge, math.huge }, { -math.huge, -math.huge, -math.huge } @@ -75,7 +70,6 @@ local function boundsNear(lo: { number }, hi: { number }, rmin: { number }, rmax return true end --- ------------------------------------------------------------------------------------------------ reference files local UNIT_NAMES = { micron = 1e-6, millimeter = 1e-3, centimeter = 1e-2, inch = 0.0254, foot = 0.3048, meter = 1 } local refCount, rejectedOk, unsupported = 0, 0, 0 local byIndex = {} @@ -115,7 +109,6 @@ for i, c in Cases do end t:note("%d files: %d against lib3mf, %d rejected by lib3mf (decoded without throwing), %d secure content (UNSUPPORTED)", #Cases, refCount, rejectedOk, unsupported) --- ------------------------------------------------------------------------------------------------ our output read back local xchecked, withTextures = 0, 0 for _, x in Xcheck do local c = Cases[x.case] @@ -159,7 +152,6 @@ for _, x in Xcheck do end t:note("%d of our files read back by lib3mf / assimp / trimesh like the originals (%d with textures)", xchecked, withTextures) --- ------------------------------------------------------------------------------------------------ round trips (ours) local rts = 0 for i, c in Cases do local scene = byIndex[i] @@ -173,7 +165,6 @@ for i, c in Cases do t:eq(a2, a1, c.name .. ": round trip triangles") t:check(near(b2, b1, 1e-6), c.name .. ": round trip area") t:eq(back.meta.unit, scene.meta.unit, c.name .. ": round trip unit") - -- textures: the same bytes local used = 0 for _, m in back.materials do if m.baseColorTexture then @@ -186,7 +177,6 @@ for i, c in Cases do end t:note("%d round trips through our writer", rts) --- ------------------------------------------------------------------------------------------------ hand-written packages local function package(model: string, extra: { [string]: string }?): buffer local w = Zip.writer() w:add("[Content_Types].xml", '', { method = "store" }) @@ -232,7 +222,6 @@ do -- per-corner colours: vertex 0 has two different colours -> split t:check(math.abs(col[8] - 128 / 255) < 1e-6, "colours: alpha kept linear") t:eq(s.nodes[1].matrix[13], 10, "colours: transform tx") t:eq(s.nodes[1].matrix[15], 30, "colours: transform tz") - -- through our writer and back: the same colours local back = decode((ThreeMf.encode(s))) local col2 = f32s(back.meshes[1].primitives[1].attributes.COLOR_0) local same = #col2 == #col @@ -285,7 +274,6 @@ do -- base materials, object defaults, composite, multiproperties, textures t:eq(s.materials[prims[4].material].name, "half", "materials: multiproperties -> first layer") t:eq(prims[4].indices.count, 6, "materials: multi and base 'half' share a primitive") t:check(math.abs(s.materials[prims[4].material].baseColor[1] - half ^ 2.4) < 1e-6, "materials: sRGB -> linear") - -- round trip: texture + materials survive local out = assert(ThreeMf.encode(s)) local back = assert(decode(out)) local tm = nil @@ -375,7 +363,6 @@ do -- a Scene built by hand: strips, fans, polygons, vertex colours + texture co t:check(select(2, ThreeMf.encode({} :: any)).code == Err.ARG, "encode: not a scene") end --- ------------------------------------------------------------------------------------------------ errors do local _, e1 = decode("not a zip at all") t:check(e1 and e1.code ~= nil, "errors: not a zip") @@ -395,13 +382,11 @@ do t:eq(e6 and e6.code, Err.LIMIT, "errors: maxVertices") table.insert(samples, package(bad)) table.insert(samples, package(cyc)) - -- sniff t:eq(ThreeMf.sniff(Bytes.reader(package(bad))), 0.95, "sniff: a 3MF package") t:eq(ThreeMf.sniff(Bytes.reader((w:finish()))), 0, "sniff: another zip") t:eq(ThreeMf.sniff(Bytes.reader(buffer.fromstring("solid x"))), 0, "sniff: not a zip") end --- ------------------------------------------------------------------------------------------------ fuzz do for _, c in Cases do if #c.data < 20000 then diff --git a/tests/model/_rbx.luau b/tests/model/_rbx.luau index c0dd2d7..4d0a181 100644 --- a/tests/model/_rbx.luau +++ b/tests/model/_rbx.luau @@ -1,6 +1,4 @@ --- tests/model/_rbx: helpers shared by the model/rbxm and model/rbxmx tests: instance paths (the scheme of the lune dump --- in tools/fixtures/rbxmx.py), our property values in lune's canonical form, a dump comparison, a deep tree comparison, --- and a tree with a value of every type built from scratch. +-- tests/model/_rbx: helpers shared by the rbxm and rbxmx tests (instance paths as in tools/fixtures/rbxmx.py's lune dump). local Rbx = require("@rosetta/codecs/model/Rbx") local H = {} @@ -17,7 +15,7 @@ local function hex(s: string): string end)) end --- paths(tree) -> { [path] = instance }, { [instance] = path }: names joined with "/", "#k" for the k-th sibling of a name +-- names joined with "/", "#k" for the k-th sibling of a name function H.paths(tree: any): ({ [string]: any }, { [any]: string }) local byPath, ofInst = {}, {} local function walk(list: { any }, prefix: string) @@ -54,7 +52,6 @@ local function numbers(t: string, v: any): { number }? return v end --- same(ours: Value, want: lune canon, pathOf, propName) -> ok, detail function H.same(v: any, want: any, pathOf: { [any]: string }, pname: string): (boolean, string) local t = if v then v.type else "nil" local x = if v then v.value else nil @@ -101,7 +98,6 @@ function H.same(v: any, want: any, pathOf: { [any]: string }, pname: string): (b return true, "" end --- compare(t, tree, dump, label) -> properties compared: every instance / property of a lune dump against our tree function H.compare(t: any, tree: any, dump: any, label: string): number local byPath, pathOf = H.paths(tree) local n = 0 @@ -121,7 +117,7 @@ function H.compare(t: any, tree: any, dump: any, label: string): number return n end --- the type family a value compares under (a binary file has one string type; XML writes BrickColor as an int) +-- a binary file has one string type; XML writes BrickColor as an int local FAMILY: { [string]: string } = { String = "string", BinaryString = "string", @@ -135,7 +131,6 @@ local function family(t: string): string return FAMILY[t] or t end --- equal(a, b, pathA, pathB) -> ok, where: values compared deeply (Refs / Content objects by path) local function equal(a: any, b: any, pa: { [any]: string }, pb: { [any]: string }): boolean if type(a) ~= type(b) then return false @@ -161,8 +156,7 @@ local function equal(a: any, b: any, pa: { [any]: string }, pb: { [any]: string return true end --- sameTree(t, a, b, label, opts?) -> instances compared: class, name, children and every property (opts.loose: --- string / int families compare as one type, properties only b has are allowed when another instance of the class has them in a; opts.skipRaw: Raw values are not compared) +-- opts.loose: string / int families compare as one type; properties only b has are allowed when another instance of the class has them in a function H.sameTree(t: any, a: any, b: any, label: string, opts: any?): number local o = opts or {} local pa = select(2, H.paths(a)) @@ -222,7 +216,6 @@ function H.sameTree(t: any, a: any, b: any, label: string, opts: any?): number return n end --- everything() -> a model with one value of every type (and several instances per class) function H.everything(): any local tree = Rbx.tree() local root = Rbx.add(tree, Rbx.instance("Model", "Everything")) diff --git a/tests/model/_soup.luau b/tests/model/_soup.luau index c7b1b48..03d7d08 100644 --- a/tests/model/_soup.luau +++ b/tests/model/_soup.luau @@ -1,5 +1,4 @@ --- tests/model/_soup: helpers for the game model tests: a primitive's triangle soup (positions, morph target frames, --- texture coordinates in index order) and a tolerant comparison against assimp's soup. +-- tests/model/_soup: triangle soups of a primitive and a tolerant comparison against assimp's soup. local Types = require("@rosetta/Types") local Soup = {} @@ -20,8 +19,7 @@ function Soup.positions(prim: any, target: number?): buffer return out end --- uvs(prim, set?, flip?) -> { u, v, ... } of the corners in index order (flip: v -> 1 - v, assimp's convention; --- "neg": v -> -v, assimp's Half-Life loader) +-- flip: v -> 1 - v (assimp's convention); "neg": v -> -v (assimp's Half-Life loader) function Soup.uvs(prim: any, set: number?, flip: (boolean | string)?): { number } local tc = Types.Scene.reader(prim.attributes["TEXCOORD_" .. (set or 0)]) :: any local idx = prim.indices @@ -34,7 +32,6 @@ function Soup.uvs(prim: any, set: number?, flip: (boolean | string)?): { number return out end --- close(a: buffer f32 | {number}, b: {number}, tol) -> true | false, first index that differs function Soup.close(a: any, b: { number }, tol: number): (boolean, number?) local n = if type(a) == "buffer" then buffer.len(a) // 4 else #a if n ~= #b then @@ -49,9 +46,7 @@ function Soup.close(a: any, b: { number }, tol: number): (boolean, number?) return true, nil end --- triangles(a, b, tol, stride?) -> true when the triangle lists a and b (flat numbers, stride per corner: 3 for --- positions, 2 for texture coordinates) hold the same triangles in the same order, each up to a cyclic rotation of --- its corners (assimp rotates them); false, the first differing triangle otherwise +-- triangles compare up to a cyclic rotation of their corners (assimp rotates them) function Soup.triangles(a: { number }, b: { number }, tol: number, stride: number?): (boolean, number?) local s = stride or 3 if #a ~= #b then @@ -82,7 +77,6 @@ function Soup.triangles(a: { number }, b: { number }, tol: number, stride: numbe return true, nil end --- list(buf) -> the f32 values of a buffer as numbers function Soup.list(b: buffer): { number } local out = table.create(buffer.len(b) // 4) for i = 0, buffer.len(b) // 4 - 1 do @@ -91,7 +85,6 @@ function Soup.list(b: buffer): { number } return out end --- slice(list, from, n) -> n values from index from (1-based) function Soup.slice(list: { number }, from: number, n: number): { number } return table.move(list, from, from + n - 1, 1, table.create(n)) end diff --git a/tests/model/_vrml_common.luau b/tests/model/_vrml_common.luau index 2bbe34f..bbb0ea3 100644 --- a/tests/model/_vrml_common.luau +++ b/tests/model/_vrml_common.luau @@ -1,6 +1,4 @@ --- tests/model/_vrml_common: helpers shared by the VRML and X3D tests (tests/model/vrml.luau, x3d.luau): counts over --- placed primitives (instances count, as the reference readers count them) and world bounds that include lines and --- points (MeshOps.merge skips them). +-- tests/model/_vrml_common: VRML / X3D counts as the reference readers count them; bounds include lines and points. local Types = require("@rosetta/Types") local C = {} diff --git a/tests/model/b3d.luau b/tests/model/b3d.luau index 41f95c9..bffea28 100644 --- a/tests/model/b3d.luau +++ b/tests/model/b3d.luau @@ -1,8 +1,5 @@ --- model/b3d tests: assimp's Blitz3D models (WusonBlitz, dwarf2, turtle1) and generated files (textures, brushes, --- vertex colours, two UV sets, nested rotated / scaled / mirrored nodes, pivots, master brushes, bones, keys + ANIM) --- against assimp (meshes, faces, materials, animations, channels, bones; world bounds, triangle area and signed --- volume from its PreTransformVertices export: the left- to right-handed conversion and the winding) and the counts --- the generator wrote; the skin's bind pose; error codes; the fuzz no-throw pass. Fixtures: tools/fixtures/b3d.py. +-- model/b3d tests: assimp's Blitz3D models and generated files against assimp (PreTransformVertices export). +-- Fixtures: tools/fixtures/b3d.py. local T = require("@tests/T") local B3d = require("@rosetta/model/b3d") local MeshOps = require("@rosetta/ops/MeshOps") @@ -28,7 +25,6 @@ local function near(a: number, b: number, eps: number): boolean return math.abs(a - b) <= eps * math.max(1, math.abs(a), math.abs(b)) end --- world triangles of the merged scene: area and signed volume local function measure(prim: any): (number, number) local get = assert(Types.Scene.reader(prim.attributes.POSITION)) local idx = prim.indices and Types.Scene.reader(prim.indices) @@ -76,7 +72,6 @@ local function boneCount(scene: any): number return n end --- ------------------------------------------------------------------------------------------------ cases local samples = {} for _, c in Cases do local scene, err = decode(c.data, { files = c.files }) @@ -119,7 +114,6 @@ for _, c in Cases do if not (c.want and c.want.mirrored) then t:check(near(vol, a.volume, 1e-3), string.format("%s: signed volume %.6g (assimp %.6g)", c.name, vol, a.volume)) end - -- textures resolved through files for _, tex in scene.textures do local base = string.match(tex.uri, "([^/\\]+)$") t:check((tex.data ~= nil) == (c.files[base] ~= nil), c.name .. ": texture data " .. tostring(tex.uri)) @@ -203,7 +197,6 @@ for _, c in Cases do end end --- ------------------------------------------------------------------------------------------------ errors do local _, e = decode("BB3D\4\0\0\0\1\0\0\0") t:check(e and e.code == Err.CORRUPT, "no NODE: CORRUPT") @@ -218,7 +211,6 @@ do t:check(e3 and e3.code == Err.LIMIT, "maxVertices: LIMIT") end --- ------------------------------------------------------------------------------------------------ fuzz t:fuzz("decode", function(b: buffer) local s = B3d.decode(Bytes.reader(b)) if s then diff --git a/tests/model/bsp.luau b/tests/model/bsp.luau index b8ca152..9a44314 100644 --- a/tests/model/bsp.luau +++ b/tests/model/bsp.luau @@ -1,8 +1,4 @@ --- model/bsp tests: Quake 1, Half-Life, Quake II and Quake III maps written by tools/fixtures/bsp.py: every model's --- triangles per texture (positions, normals, texture coordinates against the documented rules), counter-clockwise --- about the face normals, embedded textures (Quake through the palette, Half-Life through its own), WAD / .wal --- textures as URIs, entities; Quake III: polygon / mesh faces against assimp's soup (of a .pk3) and the writer, --- lightmaps, vertex colours, a tessellated patch; errors; the fuzz pass. +-- model/bsp tests: generated Quake 1 / Half-Life / Quake II / Quake III maps; Quake III faces against assimp. local T = require("@tests/T") local F = require("@rosetta") local Bsp = require("@rosetta/model/bsp") @@ -81,7 +77,6 @@ local function brush(label: string, c: any, opts: any) return s end --- 1. Quake 1, Half-Life do local q1 = brush("q1", Fx.q1, { palette = Fx.q1.palette }) t:eq(Crc32.of(q1.textures[1].image.pixels), Fx.q1.textures[1], "q1: embedded texture through the palette") @@ -94,7 +89,6 @@ do t:eq(grey.meta.source.palette, false, "q1 without a palette: grey") end --- 2. Quake II do local q2 = brush("q2", Fx.q2, { files = { ["textures/brick.wal"] = Fx.q2.wal } }) t:eq(q2.textures[1].uri, "textures/brick.wal", "q2: .wal URI") @@ -102,7 +96,6 @@ do t:eq(q2.materials[2].extras.bsp.texels, true, "q2: texel coordinates without the .wal") end --- 3. Quake III do local q = Fx.q3 local s, err = Bsp.decode(Bytes.reader(buffer.fromstring(q.data))) @@ -137,7 +130,6 @@ do t:check(windingOk(prim), "q3: " .. key .. " counter-clockwise about the normals") end end - -- assimp: the polygon / mesh faces local all = {} local apos = q.assimp.pos for _, mesh in s.meshes do @@ -153,8 +145,7 @@ do end end t:eq(q.assimp.faces, 6, "q3: assimp reads the 3 quads") - -- compare triangle sets: every assimp triangle is one of ours (up to corner rotation); assimp keeps the stored - -- clockwise order, we reverse it +-- every assimp triangle is one of ours (up to corner rotation): assimp keeps the stored clockwise order, we reverse it local found = 0 for k = 0, #apos // 9 - 1 do local tri = Soup.slice(apos, k * 9 + 1, 9) @@ -198,7 +189,6 @@ do t:check(lean ~= nil, "q3: patchLevel 1") end --- 4. errors, fuzz do local _, e1 = Bsp.decode(Bytes.reader(buffer.fromstring(string.sub(Fx.q1.data, 1, 100)))) t:check(e1 and e1.code == Err.TRUNCATED, "truncated: " .. tostring(e1)) diff --git a/tests/model/dae.luau b/tests/model/dae.luau index 9efd419..98991fb 100644 --- a/tests/model/dae.luau +++ b/tests/model/dae.luau @@ -1,10 +1,5 @@ --- model/dae tests: assimp's Collada test models (triangles / polylist / polygons / tristrips, UTF-16 and BOM files, --- decimal commas, 2 UV sets, vertex colours, instance_node, cameras, lights, nested / clipped / full-rotation --- animations, skins, .zae) and glTF samples exported by assimp's Collada exporter, against `assimp info -r` (meshes, --- faces, bounds in assimp's space, materials, animations, cameras, lights), and against the glTF originals read by --- model/gltf (skinned rest-pose bounds, joints, every LINEAR animation key); our writer's output read back by assimp --- (dae_xcheck) and by us (round trips, .dae and .zae); polygons kept with triangulate = false; textures decoded lazily --- at the api layer; errors; the fuzz no-throw pass. Fixtures: tools/fixtures/dae.py. +-- model/dae tests: assimp's Collada models and exports against `assimp info -r` and the glTF originals. +-- Fixtures: tools/fixtures/dae.py. local T = require("@tests/T") local F = require("@rosetta") local Dae = require("@rosetta/model/dae") @@ -68,7 +63,6 @@ local function counts(scene: any): (number, number) end local function inverse(m: { number }): { number } - -- general 4x4 inverse (column-major; cofactors) local inv = table.create(16, 0) local a = m inv[1] = a[6] * a[11] * a[16] - a[6] * a[12] * a[15] - a[10] * a[7] * a[16] + a[10] * a[8] * a[15] + a[14] * a[7] * a[12] - a[14] * a[8] * a[11] @@ -145,7 +139,6 @@ local function assimpBounds(scene: any, written: boolean?): ({ number }?, { numb return lo, hi end --- world matrices (correct order) of every node local function worlds(scene: any): { [number]: { number } } local w = {} local function visit(i: number, parent: { number }) @@ -222,7 +215,6 @@ local function lightCount(scene: any): number return n end --- a channel's value at time tm (LINEAR; rotations nlerped) local function channelAt(ch: any, tm: number): { number } local inp, out = Scene.reader(ch.input) :: any, Scene.reader(ch.output) :: any local n, c = ch.input.count, ch.output.components @@ -280,7 +272,6 @@ for i, c in Cases do t:eq(#scene.animations, ref.animations, c.name .. ": animations (assimp)") checked.assimp += 1 end - -- against the glTF original of an assimp export if c.gltf then local g, gerr = Gltf.decode(Bytes.reader(buffer.fromstring(c.gltf)), { files = c.gltfFiles }) t:check(g, c.name .. ": gltf original: " .. tostring(gerr)) @@ -374,7 +365,6 @@ for i, c in Cases do end t:check(worst >= math.cos(math.rad(45)) - 1e-6, "full rotations: subdivided (worst dot " .. worst .. ")") end - -- round trip through our writer (.dae, and .zae for a few) local tri = decode(c.data, { files = c.files }) decoded[i] = tri local files = {} @@ -413,7 +403,6 @@ for i, c in Cases do end end --- assimp reads what we wrote like the source for _, x in Xcheck do local src = decoded[x.case] local ref = x.assimp @@ -432,7 +421,6 @@ for _, x in Xcheck do end end --- polygons: kept or fan-triangulated local function case(name: string): any for i, c in Cases do if string.find(c.name, name, 1, true) then @@ -540,7 +528,6 @@ do end end --- api: F.load by content / extension do local c = case("cube_tristrips") if c then @@ -551,7 +538,6 @@ do end end --- errors do local _, e1 = decode('') t:check(e1 and e1.code == Err.CORRUPT, "not COLLADA: CORRUPT") diff --git a/tests/model/fbx.luau b/tests/model/fbx.luau index 9e99de3..e09130d 100644 --- a/tests/model/fbx.luau +++ b/tests/model/fbx.luau @@ -1,10 +1,5 @@ --- model/fbx tests: assimp's FBX test models (binary 7.4 / 7.5, ASCII 7.4 - 7.7, embedded textures, skeletons, --- animation), Blender's exporter (materials, textures, colours, skin, shape keys, animation, camera, lights) and --- assimp's exporters (binary and ASCII), against assimp (meshes, polygons, vertices, world bounds, materials, --- animations, cameras, lights) and Blender's importer (meshes, polygons, materials, bones, shape keys, cameras, --- lights, images); round trips through our writer (binary and ASCII) and glTF sample models through FBX (world --- triangles, materials, textures, skins, morph targets, sampled animation, cameras, lights); assimp and Blender --- reading our files like the originals (fbx_xcheck); errors; the fuzz no-throw pass. Fixtures: tools/fixtures/fbx.py. +-- model/fbx tests: assimp's FBX models, Blender and assimp exports, against assimp and Blender's importer. +-- Fixtures: tools/fixtures/fbx.py. local T = require("@tests/T") local F = require("@rosetta") local Fbx = require("@rosetta/model/fbx") @@ -51,7 +46,6 @@ local function triArea(prim: any): number return area end --- assimp-like counts: placed primitives, polygons, corners local function counts(scene: any): (number, number, number) local prims, faces, verts = 0, 0, 0 local seen = {} @@ -109,7 +103,6 @@ local function boundsMatch(lo: { number }, hi: { number }, want: any, eps: numbe return eq({ lo[1], lo[3], -hi[2] }, { hi[1], hi[3], -lo[2] }, want.min, want.max) end --- ------------------------------------------------------------------------------------------------ reference files local checked = { assimp = 0, blender = 0, roundTrips = 0, failed = 0 } local scenes = {} for i, c in Cases do @@ -152,8 +145,6 @@ for i, c in Cases do end t:note("%d files: %d against assimp, %d against Blender, %d rejected by both", #Cases, checked.assimp, checked.blender, checked.failed) --- ------------------------------------------------------------------------------------------------ round trips --- world triangles (area, count, bounds), materials, textures, skins, morph targets, animation samples, cameras, lights local function compare(a: any, b: any, label: string, eps: number) local ma, mb = MeshOps.merge(a), MeshOps.merge(b) local na = if ma and ma.indices then ma.indices.count // 3 else 0 @@ -281,7 +272,6 @@ local function compare(a: any, b: any, label: string, eps: number) for ai, an in a.animations do local bn = b.animations[ai] if bn then - -- channels by node name + path local byKey = {} for _, ch in an.channels do byKey[(a.nodes[ch.node].name or "") .. "/" .. ch.path] = ch @@ -336,7 +326,6 @@ for i, c in Cases do end end --- glTF sample models through FBX local ng = 0 for _, g in GltfCases do local scene, gerr = Gltf.decode(Bytes.reader(buffer.fromstring(g.data)), { files = g.files }) @@ -365,8 +354,6 @@ for _, g in GltfCases do end t:note("%d round trips of the reference files (binary + ASCII), %d glTF models through FBX", checked.roundTrips, ng) --- ------------------------------------------------------------------------------------------------ cross-check --- assimp and Blender read our files like the originals local nx = 0 for _, x in Xcheck do local c = Cases[x.case] @@ -403,7 +390,6 @@ for _, x in Xcheck do end t:note("%d of our files read back by assimp / Blender like the originals", nx) --- ------------------------------------------------------------------------------------------------ details do local byName = {} for i, c in Cases do @@ -463,10 +449,8 @@ do t:check(emb.textures[1] and emb.textures[1].data and emb.meta.source.binary == false, "ASCII: base64 embedded texture") t:eq(emb.meta.up, "z", "3ds Max: Z up") end - -- polygons kept / triangulated local box = decode(Cases[2].data) t:check(box.meshes[1].primitives[1].mode == "triangles", "triangulated by default") - -- through the api local s = F.load(Cases[2].data) t:check(s and s.kind == "scene" and s.meta.source.format == "fbx", "F.load detects binary FBX") local viaApi = F.save(s, nil, { format = "fbx" }) @@ -493,7 +477,6 @@ do t:check(qb and qb.meshes[1].primitives[1].faces.count == 1 and qb.meshes[1].primitives[1].indices.count == 4, "a quad stays one polygon") end --- ------------------------------------------------------------------------------------------------ errors do local _, e1 = decode("; FBX 6.1.0 project file\nFBXHeaderExtension: {\n\tFBXVersion: 6100\n}\n") t:check(e1 and e1.code == Err.UNSUPPORTED, "FBX 6: " .. tostring(e1)) @@ -514,7 +497,6 @@ do t:check(e8 and e8.code == Err.ARG, "encode version 6100") end --- ------------------------------------------------------------------------------------------------ fuzz do local samples = {} for i, c in Cases do diff --git a/tests/model/gltf.luau b/tests/model/gltf.luau index 65e6941..26a1383 100644 --- a/tests/model/gltf.luau +++ b/tests/model/gltf.luau @@ -1,9 +1,5 @@ --- model/gltf tests: Khronos glTF-Sample-Assets models (JSON with external / embedded buffers, GLB, sparse, interleaved, --- quantized, morph targets, skins, animations, cameras, lights, texture transforms, material extensions), gltfpack --- quantized variants and assimp's exporter output, against assimp (meshes, faces, bounds, animations, cameras, --- lights) and trimesh (area, triangles); full-structure round trips through GLB, embedded .gltf and external files; --- assimp / trimesh reading our output (gltf_xcheck); textures decoded lazily at the api layer; errors; the fuzz --- no-throw pass. Fixtures: tools/fixtures/gltf.py. +-- model/gltf tests: glTF-Sample-Assets, gltfpack and assimp output against assimp and trimesh; round trips. +-- Fixtures: tools/fixtures/gltf.py. local T = require("@tests/T") local F = require("@rosetta") local Gltf = require("@rosetta/model/gltf") @@ -76,7 +72,6 @@ local function counts(scene: any): (number, number) return prims, faces end --- every value of two scenes equal (buffers by content), meta skipped local function same(a: any, b: any, path: string, seen: { [any]: boolean }?, skip: { [string]: boolean }?): (boolean, string?) local s = seen or {} local sk = skip or { meta = true, extras = true } @@ -154,7 +149,6 @@ for i, c in Cases do end checked.trimesh += 1 end - -- round trips: GLB, embedded .gltf, external files local glb, gerr = Gltf.encode(scene, { binary = true }) t:check(glb, c.name .. ": encode glb: " .. tostring(gerr)) local back = decode(glb) @@ -179,7 +173,6 @@ for i, c in Cases do end t:note("%d files: %d against assimp, %d against trimesh, %d round trips", #Cases, checked.assimp, checked.trimesh, checked.roundTrips) --- the reference tools read our files like the originals local nx = 0 for _, x in Xcheck do local c = Cases[x.case] @@ -202,7 +195,6 @@ for _, x in Xcheck do end t:note("%d of our files read back by assimp / trimesh like the originals", nx) --- details do local function load(name: string): any local c = byName[name] @@ -298,7 +290,6 @@ do local out = Gltf.encode(s2, { binary = true }) :: buffer local back = decode(out) t:check(back and back.meshes[1].primitives[1].indices.count == 6 and back.meshes[1].primitives[1].attributes.COLOR_0.type == "unorm8", "polygons fan-triangulated, unorm8 VEC3 colours (padded stride)") - -- through the api: the destination's extension picks GLB local viaApi = F.save(s2, nil, { format = "glb" }) t:check(viaApi and buffer.readstring(viaApi, 0, 4) == "glTF", "F.save format glb") local viaApi2 = F.save(s2, nil, { format = "gltf" }) @@ -307,7 +298,6 @@ do t:check(loaded and loaded.kind == "scene" and loaded.meta.source.format == "gltf", "F.load detects GLB") end --- errors do local _, e = decode("{ not json") t:check(e and (e.code == Err.CORRUPT or e.code == Err.TRUNCATED), "bad JSON: " .. tostring(e)) @@ -330,7 +320,6 @@ do t:check(e8 and e8.code == Err.ARG, "encode a short accessor: " .. tostring(e8)) end --- fuzz do local samples = {} for _, c in Cases do diff --git a/tests/model/gltf_draco.luau b/tests/model/gltf_draco.luau index e88b668..5096b6d 100644 --- a/tests/model/gltf_draco.luau +++ b/tests/model/gltf_draco.luau @@ -1,8 +1,5 @@ --- model/gltf KHR_draco_mesh_compression tests: the Khronos samples compressed by draco_transcoder (two quantizations), --- Draco's and assimp's Draco glTF files. Every Draco primitive against libdraco's decode of its buffer view (points, --- faces, index and attribute CRCs); the transcoded files against their uncompressed sources (meshes, primitives, --- nodes, materials, skins, animations, triangles, world bounds within the quantization step); the scene saved back --- (uncompressed, without the extension) and reloaded; the fuzz no-throw pass. Fixtures: tools/fixtures/gltf_draco.py. +-- model/gltf KHR_draco_mesh_compression tests: Draco primitives against libdraco, transcoded files against their sources. +-- Fixtures: tools/fixtures/gltf_draco.py. local T = require("@tests/T") local Gltf = require("@rosetta/model/gltf") local MeshOps = require("@rosetta/ops/MeshOps") @@ -62,7 +59,6 @@ for _, c in Cases do checked.prims += 1 end end - -- against the uncompressed source local o = c.original if o then local orig, oerr = decode(o.data, o.files) @@ -95,7 +91,6 @@ for _, c in Cases do checked.originals += 1 end end - -- saved back without the extension local glb = Gltf.encode(scene, { binary = true }) t:check(glb, c.name .. ": encode") if glb then diff --git a/tests/model/iqm.luau b/tests/model/iqm.luau index 48aa118..8b3148a 100644 --- a/tests/model/iqm.luau +++ b/tests/model/iqm.luau @@ -1,8 +1,5 @@ --- model/iqm tests: assimp's mrfixit.iqm against assimp (meshes, triangles, vertices, materials, bind pose bounds), an --- independent Python reader (joints, anims) and the bounds the IQM tool stored per frame (our decoded skeleton and --- animation, skinned here, must reproduce them); writer round trips (mrfixit, glTF sample models with and without --- skins) read back by our reader, by assimp and by the Python reader, whose skinning of our files must match ours; --- errors; the fuzz no-throw pass. Fixtures: tools/fixtures/iqm.py. +-- model/iqm tests: mrfixit.iqm against assimp, a Python reader and the IQM tool's stored per-frame bounds. +-- Fixtures: tools/fixtures/iqm.py. local T = require("@tests/T") local Iqm = require("@rosetta/model/iqm") local Gltf = require("@rosetta/model/gltf") @@ -31,7 +28,6 @@ t:check(Iqm.caps.decode and Iqm.caps.encode, "caps") local function near(a: number, b: number, eps: number): boolean return math.abs(a - b) <= eps * math.max(1, math.abs(a), math.abs(b)) end --- the largest coordinate difference between two boxes local function boxDiff(lo: { number }, hi: { number }, want: any): number local d = 0 for k = 1, 3 do @@ -64,7 +60,6 @@ local function counts(scene: any): (number, number, number) return prims, tris, verts end --- the bounding box of every mesh vertex, skinned with the scene's skins at time t of anim (nil: the rest pose) local function skinnedBounds(scene: any, anim: any?, time: number): ({ number }, { number }) local pose = if anim then Sampler.pose(scene, anim, time) else nil local parent = {} @@ -149,7 +144,6 @@ local function xcheck(name: string): any return nil end --- ------------------------------------------------------------------------------------------------ mrfixit local fixit = Cases[1] local scene, err = decode(fixit.data) t:check(scene, "mrfixit: decode " .. tostring(err)) @@ -190,14 +184,12 @@ do t:check(scene.meta.source.bounds and #scene.meta.source.bounds == ref.frames, "mrfixit: bounds block read") end --- ------------------------------------------------------------------------------------------------ round trips do local out = assert(Iqm.encode(scene)) local back = assert(decode(out)) local p1, t1, v1 = counts(scene) local p2, t2, v2 = counts(back) t:check(p1 == p2 and t1 == t2 and v1 == v2, "round trip: counts") - -- positions and indices exact local same = true for mi, m in scene.meshes do local a, b = m.primitives[1], back.meshes[mi].primitives[1] @@ -235,7 +227,6 @@ do end end t:check(worst < 2e-3, "round trip: the animation skins the same (worst " .. worst .. ")") - -- assimp and the Python reader on our file local x = assert(xcheck("rt_mrfixit.iqm"), "xcheck rt_mrfixit") t:eq(x.assimp.faces, fixit.assimp.faces, "round trip: assimp triangles") t:eq(x.assimp.vertices, fixit.assimp.vertices, "round trip: assimp vertices") @@ -250,7 +241,6 @@ do t:check(w3 < 1e-4, "round trip: our bounds block matches the Python skinning (worst " .. w3 .. ")") end --- glTF sample models through the writer for _, p in Picks do local g = assert(Gltf.decode(Bytes.reader(buffer.fromstring(p.data)), { files = p.files })) local out, e = Iqm.encode(g) @@ -283,7 +273,6 @@ for _, p in Picks do end end --- ------------------------------------------------------------------------------------------------ errors do local _, e1 = decode("INTERQUAKEMODEL\0") t:check(e1 and e1.code == Err.TRUNCATED, "short: " .. tostring(e1)) @@ -303,7 +292,6 @@ do t:eq(Iqm.sniff(Bytes.reader(buffer.fromstring(fixit.data))), 1, "sniff") end --- ------------------------------------------------------------------------------------------------ fuzz do local small = assert(Iqm.encode(assert(Gltf.decode(Bytes.reader(buffer.fromstring(Picks[2].data)), { files = Picks[2].files })))) local samples = { small, string.sub(fixit.data, 1, 20000) } diff --git a/tests/model/ldraw.luau b/tests/model/ldraw.luau index 746be59..8b5dabd 100644 --- a/tests/model/ldraw.luau +++ b/tests/model/ldraw.luau @@ -1,11 +1,5 @@ --- model/ldraw tests: hand-written LDraw files (a brick of primitives found through library paths, an MPD with --- embedded parts and sub-models, BFC CW / CCW / INVERTNEXT / NOCLIP / uncertified files, mirrored references, colours --- 16 / 24 / direct / local !COLOUR, optional lines, a missing part, a self-reference, bad lines, CRLF) and real library --- parts and models (3001, 3062b, 4073, 3626c, car.ldr, pyramid.ldr) against an independent expansion in the generator --- (world triangles per colour, double-sided faces, lines, area, signed volume of the one-sided faces, bounds, missing --- files) and LeoCAD's OBJ export (bounds, area); node / flattened / un-flipped scenes agree; mesh sharing; the --- built-in colour table against LDConfig.ldr; resolve; error codes; the fuzz no-throw pass. Fixtures: --- tools/fixtures/ldraw.py. +-- model/ldraw tests: hand-written and real LDraw files against the generator's own expansion and LeoCAD's OBJ export. +-- Fixtures: tools/fixtures/ldraw.py. local T = require("@tests/T") local Ldraw = require("@rosetta/model/ldraw") local MeshOps = require("@rosetta/ops/MeshOps") @@ -33,7 +27,6 @@ t:check(Ldraw.sniff(Bytes.reader(buffer.fromstring("0 FILE main.ldr\n1 16 0 0 0 t:check(Ldraw.sniff(Bytes.reader(buffer.fromstring("0 x\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 3001.dat\n"))) >= 0.8, "sniff LDR") t:eq(Ldraw.sniff(Bytes.reader(buffer.fromstring("solid cube\n facet normal 0 0 1\n"))), 0, "sniff other") --- ------------------------------------------------------------------------------------------------ colour table do local tbl = Ldraw.colors() local bad = 0 @@ -48,7 +41,6 @@ do t:check(over[4].rgb == 0x010203 and over[4].edge == 0 and over[4].name == "Mine", "ldconfig overrides") end --- ------------------------------------------------------------------------------------------------ measuring type Stats = { triangles: number, lines: number, optional: number, ds: number, area: number, volume: number, colours: { [number]: number } } local function det3(m: { number }): number @@ -120,7 +112,6 @@ local function compare(label: string, s: Stats, w: any) t:check(near(s.volume, w.volume, 1e-5), string.format("%s: signed volume %.6f / %.6f", label, s.volume, w.volume)) end --- ------------------------------------------------------------------------------------------------ cases local samples = {} local lib: any = nil for _, c in Cases do @@ -172,12 +163,10 @@ for _, c in Cases do table.insert(steps, scene.nodes[ci].extras.ldraw.step) end t:eq(table.concat(steps, ","), "1,1,1,2", "two.ldr: steps") - -- through resolve instead of files local viaResolve = assert(decode(c.data, { resolve = function(uri: string): any return c.files[uri] end })) t:eq(measure(viaResolve).triangles, w.triangles, "two.ldr: resolve") - -- optional lines on request local withOpt = assert(decode(c.data, { files = c.files, optionalLines = true, lines = false })) local so = measure(withOpt) t:check(so.optional == w.optional and so.lines == 0, "two.ldr: optional lines only") @@ -202,7 +191,6 @@ for _, c in Cases do end end --- ------------------------------------------------------------------------------------------------ errors do local _, e = decode("") t:check(e and e.code == Err.CORRUPT, "empty: CORRUPT") @@ -214,7 +202,6 @@ do t:check(e and e.code == Err.LIMIT, "maxDepth: LIMIT") end --- ------------------------------------------------------------------------------------------------ fuzz t:fuzz("decode", function(b: buffer) local s = Ldraw.decode(Bytes.reader(b), { files = lib, optionalLines = true }) if s then diff --git a/tests/model/lwo.luau b/tests/model/lwo.luau index b176e34..22fa0ca 100644 --- a/tests/model/lwo.luau +++ b/tests/model/lwo.luau @@ -1,7 +1,5 @@ --- model/lwo tests: assimp's LightWave test models (LWO2, LWOB, Modo LXOB) against assimp (meshes per layer and --- surface, polygons, corners, materials, world bounds); layer hierarchy and pivots, UV / colour / normal maps, --- surfaces and image blocks; a hand-built LWO2 (VMAD splits, MORF / SPOT targets, weight maps, lines, points, skipped --- curves, PTCH flag, derived surface, XREF clip); errors; the fuzz no-throw pass. Fixtures: tools/fixtures/lwo.py. +-- model/lwo tests: assimp's LightWave models (LWO2, LWOB, LXOB) against assimp, and a hand-built LWO2. +-- Fixtures: tools/fixtures/lwo.py. local T = require("@tests/T") local Lwo = require("@rosetta/model/lwo") local MeshOps = require("@rosetta/ops/MeshOps") @@ -25,7 +23,6 @@ local function near(a: number, b: number, eps: number): boolean return math.abs(a - b) <= eps * math.max(1, math.abs(a), math.abs(b)) end --- assimp's counts: one mesh per (layer, surface), polygons, corners local function counts(scene: any): (number, number, number) local meshes, faces, corners = 0, 0, 0 for _, m in scene.meshes do @@ -52,7 +49,6 @@ local function find(name: string): any return nil end --- ------------------------------------------------------------------------------------------------ assimp local checked, scenes = 0, {} for i, c in Cases do local a = c.assimp @@ -77,7 +73,6 @@ for i, c in Cases do end t:check(ok, string.format("%s: world bounds (assimp) %s / %s", c.name, if lo then table.concat(lo, " ") else "-", if hi then table.concat(hi, " ") else "-")) end - -- triangulated: the same corners as triangles local tri = decode(c.data) t:check(tri and tri.meshes[1] and tri.meshes[1].primitives[1].mode ~= "polygons", c.name .. ": triangulated by default") checked += 1 @@ -86,7 +81,6 @@ for i, c in Cases do end t:note("%d files checked against assimp", checked) --- ------------------------------------------------------------------------------------------------ details do local c = find("models/LWO2/hierarchy.lwo") local s = decode(c.data) @@ -159,7 +153,6 @@ do t:check(sb.materials[1].extras.lwo.glos ~= nil, "LWOB glossiness") end --- ------------------------------------------------------------------------------------------------ hand-built LWO2 local function be16(n: number): string return string.char(bit32.band(bit32.rshift(n, 8), 255), bit32.band(n, 255)) end @@ -278,7 +271,6 @@ do t:check(ux * vy - uy * vx < 0, "hand-built: facing kept (LightWave +z normal -> glTF -z)") end --- ------------------------------------------------------------------------------------------------ errors do local _, e1 = decode("FORM\0\0\0\4LWO3") t:check(e1 and e1.code == Err.UNSUPPORTED, "LWO3: " .. tostring(e1)) @@ -295,7 +287,6 @@ do t:eq(Lwo.sniff(Bytes.reader(buffer.fromstring("FORM\0\0\0\4AIFF"))), 0, "sniff AIFF") end --- ------------------------------------------------------------------------------------------------ fuzz do local samples = { quadFile() } for _, c in Cases do diff --git a/tests/model/mca.luau b/tests/model/mca.luau index d911580..fcc79e9 100644 --- a/tests/model/mca.luau +++ b/tests/model/mca.luau @@ -1,7 +1,4 @@ --- model/mca tests: region files with 1.18+ chunks (each compression: zlib, gzip, stored, LZ4 block streams), --- 1.16 / 1.13 / 1.12 chunks (palettes non-spanning and spanning, numeric ids with Add nibbles) and an external .mcc --- chunk: every cell of the assembled grid against the fixture (a CRC of the cell texts), placement, the chunk list, --- block entities, opts.chunks / opts.area / maxCells, Mca.list / Mca.chunk, detection, errors and the fuzz pass. +-- model/mca tests: region files of every chunk version and compression against the fixture's cell texts. -- Fixtures: tools/fixtures/mca.py. local T = require("@tests/T") local F = require("@rosetta") @@ -85,7 +82,6 @@ for _, c in Fx.regions do t:check(air > 0 and air < buffer.len(v.data), c.name .. ": colour grid") end --- details on the 1.18+ region do local c = Fx.regions[1] local list = assert(Mca.list(reader(c.data))) @@ -94,7 +90,6 @@ do t:check(nbt and nbt.xPos == 3 and nbt.Status == "minecraft:full", "Mca.chunk") t:eq(comp, "lz4", "Mca.chunk compression") t:eq(Mca.chunk(reader(c.data), 9, 9), nil, "absent chunk") - -- only some chunks / an area local one = assert(Mca.decode(reader(c.data), { chunks = { { 1, 0 } }, keepNbt = false })) t:eq(table.concat((one.voxels :: { Types.Voxels })[1].size, ","), "16,48,16", "opts.chunks") t:eq(one.meta.source.chunks[1].nbt, nil, "keepNbt = false") @@ -128,7 +123,6 @@ do t:check(F.save(viaApi, nil, { format = "schem" }) ~= nil, "region -> .schem") end --- errors do local ext = Fx.regions[3] local _, e1 = Mca.decode(reader(ext.data)) diff --git a/tests/model/md2.luau b/tests/model/md2.luau index bd689d6..c673453 100644 --- a/tests/model/md2.luau +++ b/tests/model/md2.luau @@ -1,6 +1,4 @@ --- model/md2 tests: MD2 files written by tools/fixtures/md2.py decode to assimp's frame-0 triangle soup (positions, --- texture coordinates) and to the writer's exact positions for every frame (base + morph target deltas), frame --- groups as animations, skins as texture URIs, opts.frame / morph = false, errors, the fuzz pass. +-- model/md2 tests: generated MD2 files against assimp's frame-0 soup and the writer's exact frames. local T = require("@tests/T") local F = require("@rosetta") local Md2 = require("@rosetta/model/md2") @@ -19,12 +17,10 @@ for _, c in Fx do t:eq(F.detect(c.data), "md2", c.name .. ": F.detect") local prim = s.meshes[1].primitives[1] t:eq(prim.indices.count, c.tris * 3, c.name .. ": triangles") - -- assimp, frame 0 local ok, at = Soup.close(Soup.positions(prim), c.assimp.pos, 1e-5) t:check(ok, c.name .. ": positions against assimp (" .. tostring(at) .. ")") local uok, uat = Soup.close(Soup.uvs(prim, 0, true), c.assimp.uv, 1e-6) t:check(uok, c.name .. ": texture coordinates against assimp (" .. tostring(uat) .. ")") - -- every frame, exact t:eq(Crc32.of(Soup.positions(prim)), c.crcs[1], c.name .. ": frame 1 exact") for k = 1, c.frames do local f = Soup.positions(prim, k) @@ -41,7 +37,6 @@ for _, c in Fx do end)(), 1e-5) t:check(fok, c.name .. ": morph target " .. k .. " = frame " .. k) end - -- animations from the frame names local groups = {} for _, a in s.animations do table.insert(groups, a.name) @@ -52,7 +47,6 @@ for _, c in Fx do t:eq(table.concat(groups, ","), "stand,run,attack,pain", c.name .. ": animation groups") t:eq(s.animations[2].channels[1].input.count, 4, c.name .. ": run has 4 keys") end - -- skins t:eq(#s.textures, #c.skins, c.name .. ": skins") if #c.skins > 0 then t:eq(s.textures[1].uri, c.skins[1], c.name .. ": skin uri") diff --git a/tests/model/md3.luau b/tests/model/md3.luau index b682e9e..ea73add 100644 --- a/tests/model/md3.luau +++ b/tests/model/md3.luau @@ -1,7 +1,4 @@ --- model/md3 tests: MD3 files written by tools/fixtures/md3.py (several surfaces, frames, tags) decode to assimp's --- frame-0 triangle soup (every surface: positions, texture coordinates) and to the writer's exact positions and --- normals for every frame, shaders as texture URIs, tags as nodes with their per-frame channels, errors, the fuzz --- pass. +-- model/md3 tests: generated MD3 files against assimp's frame-0 soup and the writer's exact frames and tags. local T = require("@tests/T") local F = require("@rosetta") local Md3 = require("@rosetta/model/md3") @@ -34,8 +31,7 @@ for _, c in Fx do t:eq(F.detect(c.data), "md3", c.name .. ": F.detect") local prims = s.meshes[1].primitives t:eq(#prims, #c.surfaces, c.name .. ": a primitive per surface") - -- assimp: every surface's frame 0 (assimp orders the meshes differently and rotates triangle corners: match each - -- assimp mesh to the surface whose triangles it holds) +-- assimp orders the meshes differently and rotates triangle corners: match each mesh to the surface holding its triangles t:eq(c.assimp.meshes, #c.surfaces, c.name .. ": assimp meshes") local matched = 0 for mi, m in c.assimp.per do @@ -67,7 +63,6 @@ for _, c in Fx do t:eq(#prims[si].targets, c.frames, c.name .. ": morph targets") end end - -- tags local ntags = #c.tags // c.frames t:eq(#s.meta.source.tags, ntags, c.name .. ": tags") for _, tg in c.tags do diff --git a/tests/model/md5.luau b/tests/model/md5.luau index e69563b..27d60ba 100644 --- a/tests/model/md5.luau +++ b/tests/model/md5.luau @@ -1,7 +1,4 @@ --- model/md5 tests: an .md5mesh and two .md5anim files written by tools/fixtures/md5.py: the bind pose against --- assimp's triangle soup (positions, texture coordinates) and the writer's exact weighted positions, the joints' --- model-space pose through the node tree, weights, animations through opts.files / opts.resolve (every frame's --- parent-relative pose), a standalone .md5anim, missing animations, errors, the fuzz pass. +-- model/md5 tests: generated .md5mesh / .md5anim files against assimp's bind-pose soup and the writer's poses. local T = require("@tests/T") local F = require("@rosetta") local Md5 = require("@rosetta/model/md5") @@ -35,7 +32,6 @@ local s, err = Md5.decode(Bytes.reader(buffer.fromstring(M.data)), { anims = { " t:check(s, "md5mesh: " .. tostring(err)) t:eq(F.detect(M.data), "md5", "F.detect") --- 1. geometry do local prims = s.meshes[1].primitives t:eq(#prims, #M.positions, "a primitive per mesh") @@ -63,7 +59,6 @@ do t:eq(matched, #M.positions, "every mesh matches assimp's bind pose") end --- 2. skeleton: the model-space joint poses through the node tree do local skin = s.skins[1] t:eq(#skin.joints, #M.joints, "joints") @@ -87,7 +82,6 @@ do t:check(s.meshes[1].primitives[1].attributes.JOINTS_0 ~= nil, "skinned") end --- 3. animations local function checkAnim(scene: any, a: any, anim: any, label: string) t:eq(anim.name, a.name, label .. ": name") local byNode = {} @@ -132,7 +126,6 @@ do t:check(e and e.code == Err.UNSUPPORTED, "missing animation") local skip = Md5.decode(Bytes.reader(buffer.fromstring(M.data)), { anims = { "run.md5anim" }, skipMissing = true }) :: any t:check(skip and #skip.animations == 0, "skipMissing") - -- a standalone .md5anim local a = Fx.anims[2] local alone = Md5.decode(Bytes.reader(buffer.fromstring(a.data)), { name = "models/walk.md5anim" }) :: any t:check(alone and #alone.skins == 1, "md5anim alone: skeleton") @@ -140,7 +133,6 @@ do t:eq(alone.meta.source.kind, "anim", "md5anim alone: kind") end --- 4. errors, fuzz do local _, e1 = Md5.decode(Bytes.reader(buffer.fromstring("MD5Version 11\n"))) t:check(e1 and e1.code == Err.UNSUPPORTED, "version 11") diff --git a/tests/model/mdl.luau b/tests/model/mdl.luau index 0073a97..ddd60ff 100644 --- a/tests/model/mdl.luau +++ b/tests/model/mdl.luau @@ -1,8 +1,4 @@ --- model/mdl tests: a Quake 1 and a Half-Life 1 model written by tools/fixtures/mdl.py. Quake: assimp's frame-0 --- triangle soup (positions, texture coordinates), every frame exact, skins through opts.palette / opts.resolve / --- the grey ramp, frame-name animations. Half-Life: assimp's bind-pose soup per mesh (positions, texture --- coordinates), the bones' TRS, the skin, every sequence's animation values against the writer's, textures with --- their palettes, the skin family. Errors and the fuzz pass. +-- model/mdl tests: generated Quake 1 and Half-Life 1 models against assimp's soups and the writer's values. local T = require("@tests/T") local F = require("@rosetta") local Mdl = require("@rosetta/model/mdl") @@ -24,7 +20,6 @@ local function near(a: { number }, b: { number }, tol: number): boolean return true end --- assimp mesh mi of a soup -> positions, uvs local function assimpMesh(a: any, mi: number): ({ number }, { number }, number) local m = a.per[mi] local nextStart = if a.per[mi + 1] then a.per[mi + 1].start else a.faces @@ -32,7 +27,6 @@ local function assimpMesh(a: any, mi: number): ({ number }, { number }, number) return Soup.slice(a.pos, m.start * 9 + 1, nf * 9), Soup.slice(a.uv, m.start * 6 + 1, nf * 6), nf end --- 1. Quake do local q = Fx.quake local s, err = Mdl.decode(Bytes.reader(buffer.fromstring(q.data)), { palette = q.palette }) @@ -69,7 +63,6 @@ do t:eq(grey.meta.source.palette, false, "quake: meta.source.palette") end --- 2. Half-Life do local h = Fx.halflife local s, err = Mdl.decode(Bytes.reader(buffer.fromstring(h.data))) @@ -95,7 +88,6 @@ do t:eq(p.indices.count, h.tris[i] * 3, "halflife: mesh " .. i .. " triangles") t:check(p.attributes.JOINTS_0 and p.attributes.WEIGHTS_0, "halflife: skinned") end - -- bones local skin = s.skins[1] t:eq(#skin.joints, #h.bones, "halflife: joints") for i, bn in h.bones do @@ -103,7 +95,6 @@ do t:eq(node.name, bn.name, "halflife: bone name " .. i) t:check(near(node.translation, bn.t, 1e-6) and near(node.rotation, bn.q, 1e-6), "halflife: bone " .. bn.name .. " TRS") end - -- animations t:eq(#s.animations, #h.sequences, "halflife: sequences") for si, sq in h.sequences do local a = s.animations[si] @@ -129,7 +120,6 @@ do end t:check(ok, "halflife: " .. sq.name .. ": every value against the writer") end - -- textures, skin family 0 for i, tx in h.textures do t:eq(s.textures[i].name, tx.name, "halflife: texture name") t:eq(Crc32.of(s.textures[i].image.pixels), tx.crc, "halflife: texture " .. i .. " through its palette") @@ -138,7 +128,6 @@ do t:eq(mesh.primitives[2].material, 2, "halflife: mesh 2 -> skin ref 1 -> texture 2") end --- 3. errors, fuzz do local _, e1 = Mdl.decode(Bytes.reader(buffer.fromstring(string.sub(Fx.quake.data, 1, 200)))) t:check(e1 and (e1.code == Err.TRUNCATED or e1.code == Err.CORRUPT), "quake truncated: " .. tostring(e1)) diff --git a/tests/model/ms3d.luau b/tests/model/ms3d.luau index b25a21b..688e395 100644 --- a/tests/model/ms3d.luau +++ b/tests/model/ms3d.luau @@ -1,9 +1,5 @@ --- model/ms3d tests: assimp's MilkShape 3D test models (groups, materials, textures, version 4 with and without the --- sub-versioned blocks) against assimp (meshes, faces, corners, materials, world bounds); round trips through our --- writer, of those files and of glTF sample models (world triangles, materials, textures, skins: joints, inverse bind --- matrices, skinned vertices; animation sampled through the skeleton); assimp reading our files (meshes, faces, --- bones, animations, bounds: ms3d_xcheck); comments and extras; errors; the fuzz no-throw pass. Fixtures: --- tools/fixtures/ms3d.py. +-- model/ms3d tests: assimp's MilkShape 3D models against assimp; round trips; assimp reading ours. +-- Fixtures: tools/fixtures/ms3d.py. local T = require("@tests/T") local F = require("@rosetta") local Ms3d = require("@rosetta/model/ms3d") @@ -84,7 +80,6 @@ local function bones(scene: any): number return n end --- ------------------------------------------------------------------------------------------------ reference files local scenes = {} for i, c in Cases do local scene, err = decode(c.data) @@ -107,8 +102,6 @@ for i, c in Cases do end t:note("%d files against assimp", #Cases) --- ------------------------------------------------------------------------------------------------ round trips --- skinned world positions at a time: the skeleton posed by animations[1], vertices blended by their joints local function skinnedPositions(s: any, time: number): { number } local byNode: { [number]: { [string]: any } } = {} for _, ch in (if s.animations[1] then s.animations[1].channels else {}) :: { any } do @@ -250,7 +243,6 @@ local function compare(a: any, b: any, label: string, eps: number) if a.skins[1] then t:eq(#b.skins[1].joints, #a.skins[1].joints, label .. ": joints") end - -- the same posed triangles (the corners in order) at a few times for _, time in { 0, 0.3, 0.75, 1.2, 2.5, 4 } do local pa, pb = skinnedPositions(a, time), skinnedPositions(b, time) local ok = #pa == #pb @@ -315,7 +307,6 @@ for gi, g in Picks do end t:note("%d reference files and %d glTF models through our writer and back", #Cases, ng) --- ------------------------------------------------------------------------------------------------ cross-check local nx = 0 for _, x in Xcheck do local a = x.assimp @@ -339,7 +330,6 @@ for _, x in Xcheck do end t:note("%d of our files read back by assimp", nx) --- ------------------------------------------------------------------------------------------------ details do local byName = {} for i, c in Cases do @@ -359,7 +349,6 @@ do t:eq(mats.meta.source.vertexVersion, 3, "vertex extras subversion 3") t:check(mats.materials[2].extras.ms3d.shininess > 0, "shininess in extras") end - -- a skinned scene by hand: two joints, comments, weights split between them local gl = gltfScenes[3] if gl then local out = Ms3d.encode(gl) :: buffer @@ -388,7 +377,6 @@ do t:check(viaApi and buffer.readstring(viaApi, 0, 10) == "MS3D000000", "F.save format ms3d") end --- ------------------------------------------------------------------------------------------------ errors do local data = Cases[2].data local _, e1 = decode(string.sub(data, 1, 100)) @@ -404,7 +392,6 @@ do t:eq(Ms3d.sniff(Bytes.reader(buffer.fromstring(data))), 1, "sniff") end --- ------------------------------------------------------------------------------------------------ fuzz do local samples = {} for _, c in Cases do diff --git a/tests/model/obj.luau b/tests/model/obj.luau index ed26274..3530f5f 100644 --- a/tests/model/obj.luau +++ b/tests/model/obj.luau @@ -1,8 +1,5 @@ --- model/obj tests: OBJ / MTL files (materials and texture maps, objects and groups, n-gons, negative indices, vertex --- colours, continuations, lines and points, a concave polygon, assimp's exporter output) against assimp (meshes, --- vertices, faces, bounds, materials) and trimesh (area, triangles); MTL mapping; ear clipping (MeshOps) against the --- exact polygon area; round trips through the writer, and assimp / trimesh reading our output (obj_xcheck); errors; --- the fuzz no-throw pass. Fixtures: tools/fixtures/obj.py. +-- model/obj tests: OBJ / MTL files against assimp and trimesh; ear clipping against the exact polygon area. +-- Fixtures: tools/fixtures/obj.py. local T = require("@tests/T") local Obj = require("@rosetta/model/obj") local MeshOps = require("@rosetta/ops/MeshOps") @@ -87,7 +84,6 @@ for _, c in Cases do if #scene.materials > 0 then t:eq(#scene.materials, c.assimp.materials, c.name .. ": materials (assimp)") end - -- round trip through our writer local files = {} local out, eerr = Obj.encode(scene, { name = "rt.obj", files = files }) t:check(out, c.name .. ": encode: " .. tostring(eerr)) @@ -110,7 +106,6 @@ for _, c in Cases do t:eq(#back.materials, #scene.materials, c.name .. ": round trip materials") end --- the reference tools read our output like the original for _, x in Xcheck do local orig = byName[string.sub(x.name, 4)] t:check(orig ~= nil, x.name .. ": a case") @@ -128,7 +123,6 @@ for _, x in Xcheck do end t:note("%d files match assimp / trimesh; %d of our files read back by assimp / trimesh", #Cases, #Xcheck) --- the cube in detail: nodes, materials, textures do local c = byName["cube.obj"] local s = decode(c.data, { files = c.files }) @@ -146,7 +140,6 @@ do t:check(red.extras.obj.values.Ns[1] == 50 and red.extras.obj.values.illum[1] == 2, "Phong values in extras") t:check(blue.baseColor[4] == 0.5 and blue.alphaMode == "blend" and blue.roughness == 0.25 and blue.metallic == 1 and blue.emissive[3] == 0.3, "blue: d, Pr, Pm, Ke") t:check(s.nodes[root.children[1]].extras.obj.smoothing == "1", "smoothing group kept") - -- the uv flip local top = s.meshes[s.nodes[root.children[1]].mesh].primitives[1] t:check(top.attributes.TEXCOORD_0 ~= nil and buffer.readf32(top.attributes.TEXCOORD_0.data, 4) == 1, "vt 0 0 -> (0, 1) (top-left origin)") local s2 = decode(c.data, { files = c.files, flipV = false }) @@ -155,7 +148,6 @@ do -- without the MTL: named default materials, the library listed as missing local s3 = decode(c.data) t:check(#s3.materials == 2 and s3.meta.source.missingMtl[1] == "cube.mtl", "missing mtllib") - -- through opts.mtl / resolve local s4 = decode(c.data, { mtl = c.files["cube.mtl"] }) t:check(s4.materials[1].baseColor[1] == 1 and s4.textures[1].data == nil, "opts.mtl (texture bytes not found)") local asked = {} @@ -164,7 +156,6 @@ do return c.files[uri] end }) t:check(s5.materials[2].baseColor[4] == 0.5 and table.find(asked, "cube.mtl") and table.find(asked, "textures/tex.png"), "opts.resolve") - -- the MTL written back keeps the maps and their options local files = {} Obj.encode(s, { name = "x.obj", files = files }) local mtl = files["x.mtl"] @@ -183,14 +174,12 @@ do t:check(near(triArea(tri), c.polygonArea, 1e-9), "ear clipping area " .. triArea(tri) .. " = " .. c.polygonArea) local fan = MeshOps.triangulate(p, { method = "fan" }) :: any t:check(near(triArea(fan), c.trimesh.area, 1e-9), "fan area = trimesh's (fan) area") - -- n-gons written as n-gons local out = Obj.encode(s) :: buffer t:check(string.find(buffer.tostring(out), "\nf 7 8 9 10 11 12 13 14", 1, true) ~= nil, "an octagon written as one face") local back = decode(out, { triangulate = false }) t:eq(back.meshes[1].primitives[1].faces.count, 2, "polygons round trip") end --- lines and points do local s = decode(byName["wire.obj"].data) local modes = {} @@ -200,7 +189,6 @@ do t:check(modes.lines and modes.lines.indices.count == 8 and modes.points and modes.triangles, "l (polyline -> 4 segments), p, f") end --- errors do local _, e = decode("v 0 0 0\nf 1 2 3\n") t:check(e and e.code == Err.CORRUPT, "index out of range: " .. tostring(e)) @@ -216,7 +204,6 @@ do t:check(empty and #empty.nodes == 0, "an empty file is an empty scene") end --- fuzz do local samples = {} for _, c in Cases do diff --git a/tests/model/off.luau b/tests/model/off.luau index d2c6649..b5d89db 100644 --- a/tests/model/off.luau +++ b/tests/model/off.luau @@ -1,9 +1,5 @@ --- model/off tests: OFF files written by trimesh and by the generator (COFF integer / float colours, RGB / RGBA, NOFF, --- STOFF, STCNOFF, face colours, colormap indices, comments, counts on the header line, CRLF, tabs, n-gons, a point --- cloud) against the values they were written from (positions cross-checked with trimesh); our encoder's output read --- back by trimesh, assimp and the generator's reader (verdicts from the fixture step); round trips (polygons, --- triangles, face colours, scenes); the contract, error codes and the fuzz no-throw pass. Fixtures: --- tools/fixtures/off.py. +-- model/off tests: trimesh and generated OFF files against the values they were written from; trimesh / assimp read ours. +-- Fixtures: tools/fixtures/off.py. local T = require("@tests/T") local Off = require("@rosetta/model/off") local Bytes = require("@rosetta/core/Bytes") @@ -27,13 +23,11 @@ local function same(a: any, b: any): boolean return a.type == b.type and a.components == b.components and a.count == b.count and buffer.tostring(a.data) == buffer.tostring(b.data) end --- 1. the contract t:eq(Off.name, "off", "name") t:eq(Off.category, "model", "category") t:check(table.find(Off.extensions, "off") ~= nil, "extensions") t:check(Off.caps.decode and Off.caps.encode, "caps") --- 2. every fixture against the values it was written from; 3. round trips for _, c in Fx.cases do local label = c.name local scene, err = decode(c.data) @@ -70,7 +64,6 @@ for _, c in Fx.cases do end end t:eq(Off.sniff(Bytes.reader(buffer.fromstring(c.data))), 0.9, label .. ": sniff") - -- polygons kept local poly = decode(c.data, { triangulate = false }) local pp = poly.meshes[1].primitives[1] if c.faces > 0 and not c.allTri then @@ -106,7 +99,6 @@ for _, v in Fx.ours do end t:note("%d encodings read back by trimesh, assimp and the generator", #Fx.ours) --- the encoder scenes: decode(encode()) gives the scene back (identity transforms) local function build(spec: any): Types.Scene local scene = Types.Scene.new() for i, m in spec.meshes do @@ -160,7 +152,6 @@ do t:check(string.find(cm, "STCNOFF\n# made here\n", 1, true) ~= nil, "comment option") end --- 4. error codes do local function code(s: string, opts: any?): string? local _, e = decode(s, opts) @@ -193,7 +184,6 @@ do t:eq(Off.sniff(Bytes.reader(buffer.fromstring("solid x\n"))), 0, "sniff an STL") end --- 5. fuzz do local samples = {} for _, c in Fx.cases do diff --git a/tests/model/ply.luau b/tests/model/ply.luau index 900e76e..c9ba8d1 100644 --- a/tests/model/ply.luau +++ b/tests/model/ply.luau @@ -1,9 +1,5 @@ --- model/ply tests: files written by plyfile (ascii / binary LE / BE, every property type and spelling, odd orders, --- n-gons up to 300 vertices, face properties and lists, extra elements, comments, point clouds) and by assimp, against --- plyfile's reading mapped to the Scene conventions (CRC-32 of every attribute, the indices triangulated or as --- polygons, face data, raw elements); our encoder's output read back by plyfile and assimp (verdicts from the fixture --- step); round trips in every encoding (fixtures and generated scenes, polygons and points); the contract, error --- codes, the fuzz no-throw pass and a binary decode throughput note. Fixtures: tools/fixtures/ply.py. +-- model/ply tests: plyfile and assimp files against plyfile's reading (CRC-32 per attribute); plyfile / assimp read ours. +-- Fixtures: tools/fixtures/ply.py. local T = require("@tests/T") local Ply = require("@rosetta/model/ply") local Bytes = require("@rosetta/core/Bytes") @@ -22,13 +18,11 @@ end local ENCODINGS = { "ascii", "binary_little_endian", "binary_big_endian" } --- 1. the contract t:eq(Ply.name, "ply", "name") t:eq(Ply.category, "model", "category") t:check(table.find(Ply.extensions, "ply") ~= nil, "extensions") t:check(Ply.caps.decode and Ply.caps.encode, "caps") --- a decoded scene against a reference case (triangulated) local function verify(scene: any, c: any, label: string) t:check(scene.kind == "scene" and #scene.meshes == 1 and #scene.meshes[1].primitives == 1, label .. ": one primitive") local p = scene.meshes[1].primitives[1] @@ -101,7 +95,6 @@ local function verify(scene: any, c: any, label: string) end end --- 2. every fixture against plyfile; 3. round trips of every fixture in every encoding for _, c in Fx.cases do local label = c.name local scene, err = decode(c.data) @@ -116,7 +109,6 @@ for _, c in Fx.cases do buffer.writestring(big, 4, c.data) local s2 = Ply.decode(Bytes.reader(big, 4, #c.data)) t:check(s2 and Crc32.of(s2.meshes[1].primitives[1].attributes.POSITION.data) == c.attrs.POSITION.crc, label .. ": decode from a sub-range") - -- polygons kept local poly = decode(c.data, { triangulate = false }) local pp = poly.meshes[1].primitives[1] if c.faces > 0 and not c.allTri then @@ -144,7 +136,6 @@ for _, c in Fx.cases do end end verify(back, cc, label .. " -> " .. enc) - -- polygons in, polygons out local pout = Ply.encode(poly, { format = enc }) :: buffer local pback = decode(pout, { triangulate = false }) verify(decode(pout), c, label .. " -> " .. enc .. " (polygons)") @@ -169,7 +160,6 @@ for _, v in Fx.ours do end t:note("%d encodings read back by plyfile and assimp", #Fx.ours) --- the encoder scenes: decode(encode()) against the properties computed by the generator local function build(spec: any): Types.Scene local scene = Types.Scene.new() for i, m in spec.meshes do @@ -263,7 +253,6 @@ for _, spec in Scenes do end end --- options and meta: comments, extra elements written back, faceAttributes of a triangulated mesh do local scene = build(Scenes[1]) scene.meta.ply = { comments = { "first" }, objInfo = { "info line" } } @@ -282,7 +271,6 @@ do t:eq(decode(Ply.encode(bare) :: buffer).meta.source.vertices, 20, "a scene without nodes") end --- 4. error codes do local function code(s: string, opts: any?): string? local _, e = decode(s, opts) @@ -323,7 +311,6 @@ do t:check(a2 and a2.code == Err.ARG, "no POSITION: " .. tostring(a2)) end --- 5. fuzz do local samples = {} for _, c in Fx.cases do diff --git a/tests/model/pmx.luau b/tests/model/pmx.luau index 4a10d87..a35b526 100644 --- a/tests/model/pmx.luau +++ b/tests/model/pmx.luau @@ -1,8 +1,5 @@ --- model/pmx tests: assimp's MMD model (Alicia_blade.pmx) and synthetic PMX 2.0 / 2.1 models (UTF-16 / UTF-8, index --- sizes 1 / 2 / 4, additional UVs, BDEF1 / BDEF2 / BDEF4 / SDEF / QDEF, every morph type, IK / inherit / axis bones, --- display frames, rigid bodies, joints) against assimp (meshes, faces per mesh, materials, bones, world bounds) and the --- generator's facts (vertices, weights, bones, morphs, textures); the same models as PMD against their PMX decode; --- errors; the fuzz no-throw pass. Fixtures: tools/fixtures/pmx.py. +-- model/pmx tests: assimp's Alicia_blade.pmx and generated PMX 2.0 / 2.1 / PMD models against assimp and the generator. +-- Fixtures: tools/fixtures/pmx.py. local T = require("@tests/T") local F = require("@rosetta") local Pmx = require("@rosetta/model/pmx") @@ -55,7 +52,6 @@ local function findVertex(scene: any, pos: { number }, uv: { number }): (any, nu return nil, nil end --- ------------------------------------------------------------------------------------------------ reference files local scenes = {} local checked = { assimp = 0, expect = 0 } for i, c in Cases do @@ -167,7 +163,6 @@ do local skin = s.skins[1] local ok = true local world = {} - -- world matrices by walking from the root local function walk(n: number, parent: { number }) local w = Types.Scene.mul(parent, Types.Scene.nodeMatrix(s.nodes[n])) world[n] = w @@ -186,7 +181,6 @@ do end end --- ------------------------------------------------------------------------------------------------ PMD for _, c in Pmds do local s, err = decode(c.data) t:check(s, c.name .. ": decode: " .. tostring(err)) @@ -215,7 +209,6 @@ for _, c in Pmds do end end --- ------------------------------------------------------------------------------------------------ api, errors do local c = Cases[2] t:eq(F.detect(c.data), "pmx", "F.detect pmx") @@ -240,7 +233,6 @@ do t:check(e7 and (e7.code == Err.TRUNCATED or e7.code == Err.CORRUPT), "PMD truncated: " .. tostring(e7)) end --- ------------------------------------------------------------------------------------------------ fuzz do local samples = {} for _, c in Cases do diff --git a/tests/model/qb.luau b/tests/model/qb.luau index 96edb5e..f52be64 100644 --- a/tests/model/qb.luau +++ b/tests/model/qb.luau @@ -1,7 +1,5 @@ --- model/qb tests: Qubicle Binary files with every option (RGBA / BGRA, left- / right-handed, RLE or not, visibility --- masks, more than 255 colours) against the reference reader / writer of the fixture (exact colours of every cell, --- names, positions), the indexed palette view, our encodings read back by the reference (same settings, flipped --- settings, palette grids with computed masks), the api, error codes and the fuzz pass. Fixtures: tools/fixtures/qb.py. +-- model/qb tests: Qubicle Binary files of every option against the fixture's reference reader / writer. +-- Fixtures: tools/fixtures/qb.py. local T = require("@tests/T") local F = require("@rosetta") local Qb = require("@rosetta/model/qb") @@ -62,7 +60,6 @@ for _, c in Fx.cases do t:eq(F.detect(c.data), "qb", c.name .. ": detect") end --- our encodings, read by the reference for name, want in Fx.ours do local base = string.match(name, "^(case%d)_") if base then @@ -100,7 +97,6 @@ do t:eq(buffer.readu8(colors, 0 * 4 + 3), 1 + 2 + 16 + 64, "corner cell mask (left, bottom, back)") end --- api and conversion to .vox do local s = assert(F.load(Fx.cases[1].data)) t:check(s.kind == "scene", "F.load") @@ -108,7 +104,6 @@ do t:check(F.save(s, nil, { format = "schem" }) ~= nil, "qb -> schem") end --- errors do local _, e1 = dec("\1\1\0\0") t:check(e1 and e1.code == Err.TRUNCATED, "truncated header") diff --git a/tests/model/rbxm.luau b/tests/model/rbxm.luau index 24e369e..7ca46ff 100644 --- a/tests/model/rbxm.luau +++ b/tests/model/rbxm.luau @@ -1,7 +1,4 @@ --- model/rbxm tests: binary models and places built by rojo 7.7 and lune 0.11 (rbx-dom) decode to the values lune reads --- from them (every property the files hold); the binary decode equals the decode of the XML twin; Zstandard and raw --- chunk variants; an unknown chunk and an unknown property type round trip raw; our rbxm output read back by lune --- equals the original (fixture verdicts); round trips of a tree with every type; options, errors and the fuzz pass. +-- model/rbxm tests: rojo 7.7 / lune 0.11 binary models and places against lune's reading and their XML twins. -- Fixtures: tools/fixtures/rbxmx.py. local T = require("@tests/T") local Rbxm = require("@rosetta/model/rbxm") @@ -33,7 +30,6 @@ local function file(name: string): any error("no fixture " .. name) end --- every binary reference file against lune's reading of it, and against the decode of its XML twin local nprops = 0 local trees: { [string]: any } = {} for _, f in Fx.files do @@ -109,7 +105,6 @@ do t:eq(#Rbx.list(tree), 1 + 12 + 2 + 120, "every instance") end --- chunk variants: Zstandard, raw, an unknown chunk and an unknown property type do local base = trees["model.rbxm"] t:eq(table.concat(base.meta.source.compression, ","), "lz4,none", "rojo: lz4 chunks (END raw)") @@ -153,7 +148,6 @@ do t:check(edited and not still, "a raw column is dropped when its class changes") end --- our encoder: lune reads our rbxm back to the same values (tools/fixtures/rbxmx.py) local nours = 0 for _, v in Ours do if string.sub(v.name, -5) == "/rbxm" then @@ -163,7 +157,6 @@ for _, v in Ours do end t:note("%d of our rbxm files read back by lune", nours) --- round trips: every reference file, and a tree with every type for name, tree in trees do local out, err = Rbxm.encode(tree) t:check(out ~= nil, name .. ": encode " .. tostring(err)) @@ -183,7 +176,6 @@ do H.sameTree(t, tree, back2, "every type, raw chunks", { loose = true }) t:eq(table.concat(back2.meta.source.compression, ","), "none", "compression = none") t:check(buffer.len(raw) > buffer.len(out), "lz4 chunks are smaller") - -- through XML and back local viaXml = Rbxmx.decode(Bytes.reader(Rbxmx.encode(back) :: buffer)) H.sameTree(t, tree, decode(Rbxm.encode(viaXml) :: buffer), "every type via rbxmx", { loose = true }) -- a place: roots marked as services @@ -198,7 +190,6 @@ do t:eq(decode(Rbxm.encode(tree) :: buffer).metadata.ExplicitAutoJoints, "true", "META") end --- sniff, errors do local data = file("model.rbxm").data t:eq(Rbxm.sniff(Bytes.reader(buffer.fromstring(data))), 1, "sniff") @@ -240,7 +231,6 @@ do t:check(e8 and e8.code == Err.CORRUPT, "a cycle: " .. tostring(e8)) end --- through the api: detection (variant: rbxl for places), load, save, convert do local F = require("@rosetta") t:eq(F.detect(file("place.rbxl").data), "rbxl", "detect a place") @@ -257,7 +247,6 @@ do t:eq(F.detect(l), "rbxl", "save as rbxl marks services") end --- fuzz do local samples = { file("model-raw.rbxm").data, Rbxm.encode(H.everything(), { compression = "none" }) :: buffer, Rbxm.encode(H.everything()) :: buffer } t:fuzz("decode", function(b: buffer) diff --git a/tests/model/rbxmx.luau b/tests/model/rbxmx.luau index 551bd90..1da6a62 100644 --- a/tests/model/rbxmx.luau +++ b/tests/model/rbxmx.luau @@ -1,7 +1,4 @@ --- model/rbxmx tests: XML models and places built by rojo 7.7 and lune 0.11 (rbx-dom) decode to the values lune reads --- from them; our rbxmx output read back by lune equals the original (fixture verdicts); round trips of every reference --- file and of a tree with every type; XML specifics (BinaryString, CDATA, packed Color3, INF / NAN, unknown property --- tags kept raw, referents, SharedStrings, floats written exactly); errors and the fuzz pass. +-- model/rbxmx tests: rojo 7.7 / lune 0.11 XML models and places against lune's reading; lune reads ours. -- Fixtures: tools/fixtures/rbxmx.py. local T = require("@tests/T") local Rbxmx = require("@rosetta/model/rbxmx") @@ -86,7 +83,6 @@ do t:check(not string.find(flat, "\n @@ -161,7 +157,6 @@ do t:eq(fb.C.value[1], buffer.readf32(v, 0), "f32 exact") end --- sniff, errors do local data = Fx.files[2].data t:eq(Rbxmx.sniff(Bytes.reader(buffer.fromstring(data))), 1, "sniff") diff --git a/tests/model/robloxmesh.luau b/tests/model/robloxmesh.luau index f0bac5f..5e03e20 100644 --- a/tests/model/robloxmesh.luau +++ b/tests/model/robloxmesh.luau @@ -1,8 +1,4 @@ --- model/robloxmesh tests: meshes of every version written by the fixture's spec writer (1.00 / 1.01 ASCII, 2.00 with --- 36- and 40-byte vertices, 3.00 / 3.01 LODs, 4.00 / 4.01 / 5.00 skinned with one and several subsets, 5.00 FACS, --- 6.00 / 7.00 chunked) decode to the values they were written from (attribute CRCs, LOD index CRCs, global joints and --- weights, bone names / parents / world transforms, FACS, raw chunks); a COREMESH v2 that is not a Draco stream is CORRUPT; our 2.00 / --- 4.00 output read back by the fixture's reader (verdicts); round trips; errors and the fuzz pass. +-- model/robloxmesh tests: meshes of every version from the fixture's spec writer against the values written. -- Fixtures: tools/fixtures/robloxmesh.py. local T = require("@tests/T") local RobloxMesh = require("@rosetta/model/robloxmesh") @@ -24,7 +20,6 @@ local function decode(data: any, opts: any?): (any, any) return RobloxMesh.decode(Bytes.reader(if type(data) == "string" then buffer.fromstring(data) else data), opts) end --- a world matrix of node i (parents through the children lists) local function world(scene: any, i: number): { number } local parent = {} for k, n in scene.nodes do @@ -119,7 +114,6 @@ for _, v in Fx.ours do end t:note("%d of our files read back by the fixture's reader", #Fx.ours) --- round trips through our encoder do for _, name in { "v2.00-40", "v4.00-lods", "v4.00-40bones", "v6.00" } do local c @@ -164,7 +158,6 @@ do t:check(qa.COLOR_0 == nil, "white / no colours: 36-byte vertices") end --- sniff, errors do local c = Fx.cases[3] t:eq(RobloxMesh.sniff(Bytes.reader(buffer.fromstring(c.data))), 1, "sniff") diff --git a/tests/model/robloxmesh_draco.luau b/tests/model/robloxmesh_draco.luau index b57a35a..9c53860 100644 --- a/tests/model/robloxmesh_draco.luau +++ b/tests/model/robloxmesh_draco.luau @@ -1,8 +1,5 @@ --- model/robloxmesh with a Draco-compressed COREMESH (6.00 / 7.00, COREMESH v2): draco_encoder streams of a UV sphere --- (normals, uvs) and a coloured PLY at three compression levels, wrapped in the chunk layout. Positions, normals, --- uvs, colours and indices match libdraco's decode byte for byte, and the scene equals the decode of the same mesh --- written with a plain COREMESH v1; corrupt streams fail without throwing (fuzz). Fixtures: --- tools/fixtures/robloxmesh_draco.py. +-- model/robloxmesh Draco COREMESH v2 tests: draco_encoder streams against libdraco's decode, byte for byte. +-- Fixtures: tools/fixtures/robloxmesh_draco.py. local T = require("@tests/T") local RobloxMesh = require("@rosetta/model/robloxmesh") local Bytes = require("@rosetta/core/Bytes") @@ -43,7 +40,6 @@ for _, c in Cases do t:eq(Crc32.of(a[name].data), Crc32.of(pp.attributes[name].data), c.name .. ": " .. name .. " like COREMESH v1") end t:eq(Crc32.of(prim.indices.data), Crc32.of(pp.indices.data), c.name .. ": indices like COREMESH v1") - -- written back as 2.00 and read again local back = assert(decode(buffer.tostring(assert(RobloxMesh.encode(scene))))) t:eq(back.meshes[1].primitives[1].indices.count, c.faces * 3, c.name .. ": round trip") if #c.data < 3000 then diff --git a/tests/model/schematic.luau b/tests/model/schematic.luau index 60e2bdc..e860527 100644 --- a/tests/model/schematic.luau +++ b/tests/model/schematic.luau @@ -1,9 +1,5 @@ --- model/schematic tests: .litematic files written by litemapy (several regions, negative sizes, a 40-state palette, --- tile entities), Sponge .schem v2 (litemapy) and v1 / v3 (nbtlib, by the spec; two-byte varints), MCEdit --- .schematic (legacy ids + data, WorldEdit AddBlocks, a Schematica name table): every cell's block state, placement, --- block entities; our re-encodings give the same NBT for the same variant, and the reference readers (litemapy / --- nbtlib, in the fixture step) read our output, across variants and from colour-only grids, to the same cells; --- detection, the api, error codes and the fuzz pass. Fixtures: tools/fixtures/schematic.py. +-- model/schematic tests: litemapy / nbtlib-written .litematic, .schem v1-v3 and MCEdit .schematic files; they read ours. +-- Fixtures: tools/fixtures/schematic.py. local T = require("@tests/T") local F = require("@rosetta") local Schematic = require("@rosetta/model/schematic") @@ -61,7 +57,6 @@ local function sameRegion(got: any, want: any, label: string) end end --- 1. reference files local decoded: { [string]: Types.Scene } = {} for _, c in Fx.cases do local scene, err = dec(c.data) @@ -108,13 +103,11 @@ for _, c in Fx.cases do for i, r in regions(again) do sameRegion(r, regs[i], c.name .. " again region " .. i) end - -- api: detection by content (the flavour) and loading t:eq(F.detect(c.data), c.variant, c.name .. ": F.detect") local viaApi = F.load(c.data) t:check(viaApi and viaApi.kind == "scene", c.name .. ": F.load") end --- 2. our encodings read back by litemapy / nbtlib (fixture step) local outputs: { [string]: () -> (buffer?, any) } = {} local function colorGrid(): Types.Voxels local v = Types.Voxels.new(4, 3, 2) @@ -156,7 +149,6 @@ for name, ref in Ours do count += 1 end t:eq(count, 14, "every output checked") --- the source cells survive the conversions do local function cellsVia(name: string): string return regions(assert(dec(assert(outputs[name]()))))[1].cells @@ -177,7 +169,6 @@ do t:eq(first[4], "minecraft:light_blue_stained_glass", "translucent blue -> stained glass") end --- 3. through the api do local scene = assert(F.load(Fx.cases[1].data, { name = "x.litematic" })) local schem = assert(F.save(scene, nil, { format = "schem" })) :: buffer @@ -193,7 +184,6 @@ do t:check(F.save(g, nil, { format = "schem" }) ~= nil, "save a bare Voxels") end --- 4. errors do local _, e1 = dec(assert(Nbt.encode(Nbt.compound({ a = 1 }, { "a" })))) t:check(e1 and e1.code == Err.CORRUPT, "not a schematic") @@ -208,7 +198,7 @@ do t:check(e5 and e5.code == Err.TRUNCATED, "short Blocks") end --- 5. fuzz (the uncompressed NBT too, so mutations reach the layouts, not just gzip's CRC) +-- fuzz the uncompressed NBT too, so mutations reach the layouts, not just gzip's CRC local samples = {} for _, c in Fx.cases do local s = assert(dec(c.data)) diff --git a/tests/model/smd.luau b/tests/model/smd.luau index c4725ee..baee54c 100644 --- a/tests/model/smd.luau +++ b/tests/model/smd.luau @@ -1,7 +1,5 @@ --- model/smd tests: SMD files written by tools/fixtures/smd.py decode to assimp's triangle soup (positions, texture --- coordinates per material) and to the writer's exact values (bind pose TRS, per-vertex weights and joints, every --- skeleton frame of the animation); an animation-only SMD; our writer's output re-read by us (same soup, weights, --- poses) and by assimp (faces, bones); errors; the fuzz pass. Fixtures: tools/fixtures/smd.py. +-- model/smd tests: generated SMD files against assimp's soup and the writer's exact values; assimp reads ours. +-- Fixtures: tools/fixtures/smd.py. local T = require("@tests/T") local F = require("@rosetta") local Smd = require("@rosetta/model/smd") @@ -120,7 +118,6 @@ for _, c in Fx.cases do end t:eq(matched, #c.materials, c.name .. ": every material mesh matches assimp's positions") end - -- our writer, read back by us local out = Smd.encode(s) :: buffer local back, berr = Smd.decode(Bytes.reader(out)) t:check(back, c.name .. ": re-read our SMD: " .. tostring(berr)) @@ -133,7 +130,6 @@ for _, c in Fx.cases do only.tris = {} check(anim, only, c.name .. " (written animation)") end - -- assimp reads our output local ours = Fx.ours[c.name] if ours and #c.tris > 0 then t:eq(ours.faces, #c.tris, c.name .. ": assimp reads our triangles") diff --git a/tests/model/stl.luau b/tests/model/stl.luau index 286ff95..ae7ca9e 100644 --- a/tests/model/stl.luau +++ b/tests/model/stl.luau @@ -1,8 +1,5 @@ --- model/stl tests: files made by trimesh, assimp and by hand (binary starting with "solid", VisCAM / Magics colours, --- raw attribute words, odd ASCII, several solids, quads, no endsolid, trailing bytes) against trimesh's raw reader --- (CRC-32 of the f32 vertices / normals, area, bounds), our encoder's output read back by trimesh and assimp (verdicts --- from the fixture step), round trips of every encoding and option, the contract, error codes, the fuzz no-throw pass --- and a binary decode throughput note. Fixtures: tools/fixtures/stl.py. +-- model/stl tests: trimesh, assimp and hand-made STL files against trimesh's raw reader; trimesh / assimp read ours. +-- Fixtures: tools/fixtures/stl.py. local T = require("@tests/T") local Stl = require("@rosetta/model/stl") local Bytes = require("@rosetta/core/Bytes") @@ -19,7 +16,6 @@ local function decode(data: any, opts: any?): (any, any) return Stl.decode(Bytes.reader(b), opts) end --- every primitive's accessor `name` concatenated (nil when a primitive lacks it) local function concat(scene: any, name: string): buffer? local parts = {} for _, p in scene.meshes[1].primitives do @@ -32,13 +28,11 @@ local function concat(scene: any, name: string): buffer? return buffer.fromstring(table.concat(parts)) end --- 1. the contract t:eq(Stl.name, "stl", "name") t:eq(Stl.category, "model", "category") t:check(table.find(Stl.extensions, "stl") ~= nil, "extensions") t:check(Stl.caps.decode and Stl.caps.encode, "caps") --- 2. every fixture against the reference for _, c in Fx.cases do local label = c.name local scene, err = decode(c.data) @@ -115,7 +109,6 @@ for _, c in Fx.cases do t:eq(prims[i].attributes.POSITION.count, c.solidFacets[i] * 3, label .. ": solid facets") end end - -- inside a bigger buffer (the Reader's range) local big = buffer.create(#c.data + 11) buffer.writestring(big, 5, c.data) local s2 = Stl.decode(Bytes.reader(big, 5, #c.data)) @@ -148,13 +141,11 @@ for _, c in Fx.cases do end t:note("%d files match trimesh / the generator", #Fx.cases) --- 3. the reference tools read our output for _, v in Fx.ours do t:check(v.ok, "trimesh / assimp read our " .. v.name .. ": " .. v.detail) end t:note("%d encodings read back by trimesh and assimp", #Fx.ours) --- round trips of the encoder scenes: world-space soup as the generator computed it, colour words, idempotence local function acc(s: string, ty: string, comps: number, count: number): Types.Accessor return Types.Scene.accessor(buffer.fromstring(s), ty, comps, count) end @@ -237,7 +228,6 @@ for _, spec in Scenes do t:check(buffer.tostring(again) == buffer.tostring(out :: buffer), label .. ": re-encode is identical") end end --- options: header, name, computed vs attribute normals do local scene = build(Scenes[1]) local out = Stl.encode(scene, { header = "my header", ascii = false }) :: buffer @@ -258,7 +248,6 @@ do t:eq(buffer.len(Stl.encode(bare) :: buffer), 84 + 50 * 60, "a scene without nodes") end --- 4. error codes do local cube = Fx.cases[1].data local _, e1 = decode(string.sub(cube, 1, 84 + 50 * 3 + 7)) @@ -302,7 +291,6 @@ do t:eq(Stl.sniff(Bytes.reader(buffer.fromstring("ply\nformat ascii 1.0\n"))), 0, "sniff a PLY") end --- 5. fuzz do local samples = {} for i, c in Fx.cases do diff --git a/tests/model/usda.luau b/tests/model/usda.luau index 7d69eae..7efd1f6 100644 --- a/tests/model/usda.luau +++ b/tests/model/usda.luau @@ -1,10 +1,5 @@ --- model/usda tests: stages authored with OpenUSD's API (every xform op kind / order, pivots, resetXformStack, --- primvar interpolations, holes, leftHanded, n-gons, UsdPreviewSurface networks, GeomSubsets, inherited bindings, --- cameras, lights, time samples, a USDZ package, a USDC file), a hand-written grammar test, assimp's USD models --- (usda + usdc converted by Sdf), Blender 5 exports of glTF samples - all against OpenUSD (pxr: world transforms, --- triangles, area and bounds per mesh, bound materials, PreviewSurface inputs and textures, cameras, lights, xform time --- samples); OpenUSD's schema layers parse-only (prim spec counts); round trips through our writer (stable text) and --- pxr reading our output (usda_xcheck); the api; errors; the fuzz no-throw pass. Fixtures: tools/fixtures/usda.py. +-- model/usda tests: OpenUSD-authored stages, assimp's USD models and Blender exports against OpenUSD (pxr). +-- Fixtures: tools/fixtures/usda.py. local T = require("@tests/T") local F = require("@rosetta") local Usda = require("@rosetta/model/usda") @@ -42,8 +37,6 @@ local function nearAll(a: { number }, b: { number }, eps: number): boolean return true end --- ------------------------------------------------------------------------------------------------ scene helpers --- a node's channels evaluated at time s (seconds): translation / rotation / scale overrides local function animated(scene: any, s: number?): { [number]: any } local out: { [number]: any } = {} if not s then @@ -79,7 +72,6 @@ local function animated(scene: any, s: number?): { [number]: any } return out end --- world matrices of every node (at animation time s when given) local function worlds(scene: any, s: number?): { [number]: { number } } local over = animated(scene, s) local out: { [number]: { number } } = {} @@ -118,7 +110,6 @@ local function byPath(scene: any): { [string]: number } return out end --- triangles, world area and bounds of a node's mesh (or of everything: node = nil) local function geometry(scene: any, ws: { [number]: { number } }, only: number?): (number, number, { number }, { number }) local tris, area = 0, 0 local lo, hi = { math.huge, math.huge, math.huge }, { -math.huge, -math.huge, -math.huge } @@ -152,7 +143,6 @@ local function geometry(scene: any, ws: { [number]: { number } }, only: number?) return tris, area, lo, hi end --- pxr's totals over every mesh local function refTotals(ref: any): (number, number, { number }, { number }) local tris, area = 0, 0 local lo, hi = { math.huge, math.huge, math.huge }, { -math.huge, -math.huge, -math.huge } @@ -172,7 +162,6 @@ end local LIGHT_TYPES = { DistantLight = "directional", SphereLight = "point", RectLight = "spot", DiskLight = "spot" } local SKIP_TYPES = { Skeleton = true, SkelRoot = true } --- ------------------------------------------------------------------------------------------------ against pxr local decoded: { [number]: any } = {} local counts = { xforms = 0, meshes = 0, materials = 0, cameras = 0, lights = 0, samples = 0, textures = 0 } for ci, c in Cases do @@ -206,7 +195,6 @@ for ci, c in Cases do end end end - -- meshes for _, m in ref.meshes do local ni = paths[m.path] local node = ni and scene.nodes[ni] @@ -236,7 +224,6 @@ for ci, c in Cases do counts.meshes += 1 end end - -- cameras for _, cam in ref.cameras do local ni = paths[cam.path] local camera = ni and scene.nodes[ni].camera and scene.cameras[scene.nodes[ni].camera] @@ -252,7 +239,6 @@ for ci, c in Cases do counts.cameras += 1 end end - -- lights for _, l in ref.lights do local ni = paths[l.path] local light = ni and scene.nodes[ni].light and scene.lights[scene.nodes[ni].light] @@ -267,7 +253,6 @@ for ci, c in Cases do counts.lights += 1 end end - -- materials local mats = {} for _, m in scene.materials do if m.extras and m.extras.usd and m.extras.usd.path then @@ -311,7 +296,6 @@ for ci, c in Cases do counts.materials += 1 end end - -- xform time samples for _, a in ref.anim do local ni = paths[a.path] for _, smp in a.samples do @@ -330,7 +314,6 @@ for ci, c in Cases do end t:note("%d files against pxr: %d transforms, %d meshes, %d materials (%d textures), %d cameras, %d lights, %d time samples", #Cases, counts.xforms, counts.meshes, counts.materials, counts.textures, counts.cameras, counts.lights, counts.samples) --- ------------------------------------------------------------------------------------------------ specific facts do local hand for ci, c in Cases do @@ -382,7 +365,6 @@ do end end --- ------------------------------------------------------------------------------------------------ parse-only for _, s in Specs do local layer, err = Usda.parse(s.data) t:check(layer, s.name .. ": parse: " .. tostring(err)) @@ -400,7 +382,6 @@ for _, s in Specs do end t:note("%d OpenUSD schema layers parsed", #Specs) --- ------------------------------------------------------------------------------------------------ round trips local rt = 0 local texts: { [number]: string } = {} for ci = 1, #Cases do @@ -440,8 +421,7 @@ for ci = 1, #Cases do t:check(near(x2, y2, 1e-4) and nearAll(x3, y3, 1e-4), string.format("%s: round trip animation at %g s", name, s)) end end - -- our text is stable: after one cycle (a scene with several roots gains a "root" prim), writing what we - -- read from our own output gives the same text +-- a scene with several roots gains a "root" prim on the first cycle; after that our text is stable local again = Usda.encode(back, { files = {}, name = "rt.usda" }) :: buffer local third = Usda.encode((decode(again)), { files = {}, name = "rt.usda" }) :: buffer t:eq(buffer.tostring(third), buffer.tostring(again), name .. ": stable text") @@ -451,7 +431,6 @@ for ci = 1, #Cases do end t:note("%d round trips", rt) --- ------------------------------------------------------------------------------------------------ pxr reads our output local xc = 0 for _, x in Xcheck do local scene = decoded[x.case] @@ -500,7 +479,6 @@ for _, x in Xcheck do end t:note("%d of our files read back by pxr like the originals", xc) --- ------------------------------------------------------------------------------------------------ api do local scene, err = F.model.load(Cases[1].data) t:check(scene and scene.meta.source.format == "usda", "api: F.model.load sniffs usda: " .. tostring(err)) @@ -511,7 +489,6 @@ do t:eq(F.detect(Cases[1].data), "usda", "api: detect") end --- ------------------------------------------------------------------------------------------------ errors do local _, e1 = decode("#usda 1.0\ndef Xform \"a\" {\n") t:check(e1 and e1.code == Err.TRUNCATED, "truncated prim: " .. tostring(e1)) @@ -530,7 +507,6 @@ do t:check(e7 and e7.code == Err.CORRUPT, "nesting limit") end --- ------------------------------------------------------------------------------------------------ fuzz local samples = {} for _, c in Cases do if #c.data < 40000 then diff --git a/tests/model/vox.luau b/tests/model/vox.luau index 061227c..614806c 100644 --- a/tests/model/vox.luau +++ b/tests/model/vox.luau @@ -1,8 +1,5 @@ --- model/vox tests: MagicaVoxel files (ephtracy samples, opengametools scene files saved by MagicaVoxel 0.99.x) and --- synthetic files with every chunk type, against an independent reader (tools/fixtures/vox.py): grids (CRC), palette, --- the default palette (parsed from the spec text), scene graph world transforms (rotations, mirrors, nesting), layers, --- materials, notes, cameras, render objects; greedy meshes (MeshOps) against the exposed face count; round trips --- through the writer; error codes; the fuzz no-throw pass. Fixtures: tools/fixtures/vox.py. +-- model/vox tests: MagicaVoxel and synthetic files against an independent reader; greedy meshes against the exposed face count. +-- Fixtures: tools/fixtures/vox.py. local T = require("@tests/T") local Vox = require("@rosetta/model/vox") local MeshOps = require("@rosetta/ops/MeshOps") @@ -20,7 +17,6 @@ local function decode(data: any, opts: any?): (any, any) return Vox.decode(Bytes.reader(b), opts) end --- the contract t:eq(Vox.name, "vox", "name") t:eq(Vox.category, "model", "category") t:check(Vox.extensions[1] == "vox" and Vox.caps.decode and Vox.caps.encode, "contract") @@ -57,7 +53,6 @@ local function countKeys(tbl: any): number return n end --- shape nodes depth first with world matrices (column-major 4x4) local function shapes(scene: any): { any } local out = {} local function walk(i: number, parent: { number }) @@ -121,7 +116,6 @@ local function checkScene(scene: any, c: any, label: string) end end --- area and winding of a greedy mesh local function meshFacts(prim: any): (number, boolean, number) local pos, nrm = prim.attributes.POSITION.data, prim.attributes.NORMAL.data local ind = prim.indices.data @@ -166,7 +160,6 @@ for _, c in Cases do totalQuads += tris // 2 totalFaces += m.faces end - -- round trip through the writer local out, eerr = Vox.encode(scene) t:check(out, label .. ": encode: " .. tostring(eerr)) local back, berr = Vox.decode(Bytes.reader(out :: buffer)) @@ -181,7 +174,6 @@ for _, c in Cases do end t:note("%d files: grids, palettes, scene graphs and round trips match; greedy: %d quads for %d faces", #Cases, totalQuads, totalFaces) --- the synthetic scene in detail: names, hidden, layers, animation frames, materials, notes, IMAP, unknown chunks do local c for _, x in Cases do @@ -246,7 +238,6 @@ do t:eq(prim.indices.count, 72, "two separate cubes: 12 quads") end --- errors do local _, e = decode("nope") t:check(e and e.code == Err.CORRUPT, "junk: " .. tostring(e)) @@ -268,7 +259,6 @@ do t:check(e7 and e7.code == Err.ARG, "voxelsToPrimitive of junk") end --- fuzz do local samples = {} for _, c in Cases do diff --git a/tests/model/vrml.luau b/tests/model/vrml.luau index 0bc3fbf..c2806cb 100644 --- a/tests/model/vrml.luau +++ b/tests/model/vrml.luau @@ -1,10 +1,5 @@ --- model/vrml tests: assimp's WRL test models (HelloWorld, Wuson, the MotionCaptureROM animation), scenes and glTF --- samples written by VTK's VRML exporter, and hand-written feature files (PROTO, DEF / USE, per-face colours and --- separate indices, primitives, ElevationGrid, Extrusion, Switch, LOD, lights, viewpoints, ROUTE animations, --- PixelTexture, Inline), against VTK's vtkVRMLImporter (polygons, points, world bounds where VTK's transforms are --- right) and exact expectations; the writer: round trips of every case and of glTF sample models (world triangles, --- materials, textures, cameras, lights, animation samples), VTK reading our files like the originals; errors; the --- fuzz no-throw pass. Fixtures: tools/fixtures/vrml.py. +-- model/vrml tests: assimp's WRL models, VTK exports and hand-written files against vtkVRMLImporter and exact values. +-- Fixtures: tools/fixtures/vrml.py. local T = require("@tests/T") local F = require("@rosetta") local Vrml = require("@rosetta/model/vrml") @@ -31,7 +26,6 @@ t:eq(Vrml.name, "vrml", "name") t:eq(Vrml.category, "model", "category") t:check(Vrml.caps.decode and Vrml.caps.encode, "contract") --- ------------------------------------------------------------------------------------------------ reference files local scenes, byName = {}, {} local checked = { vtk = 0, bounds = 0, none = 0 } for i, c in Cases do @@ -60,7 +54,6 @@ for i, c in Cases do end t:note("%d files: %d against VTK (%d with bounds), %d VTK cannot read", #Cases, checked.vtk, checked.bounds, checked.none) --- ------------------------------------------------------------------------------------------------ exact expectations local function prims(scene: any): { any } local out = {} for _, pl in Types.Scene.flatten(scene) do @@ -228,7 +221,6 @@ do end end --- ------------------------------------------------------------------------------------------------ writer local function compare(a: any, b: any, label: string) local sa, sb = C.stats(a), C.stats(b) t:eq(sb.prims, sa.prims, label .. ": placed primitives") @@ -274,7 +266,6 @@ for i, c in Cases do end end --- glTF samples through VRML: world triangles, materials, textures, cameras, lights, animation samples local gltfScenes = {} for i, c in GltfCases do local g = Gltf.decode(Bytes.reader(buffer.fromstring(c.data)), { files = c.files }) @@ -305,7 +296,6 @@ for i, c in GltfCases do t:check(t2.data and buffer.tostring(t2.data) == buffer.tostring(tex.data), c.name .. ": texture " .. k .. " bytes") end end - -- animations: the translation / rotation / scale channels, sampled at their keys local want = 0 for _, a in g.animations do for _, ch in a.channels do @@ -323,7 +313,6 @@ for i, c in GltfCases do end t:note("%d round trips", rt) --- VTK reads our files like the originals local xc = 0 for _, x in Xcheck do local v = x.vtk @@ -344,7 +333,6 @@ for _, x in Xcheck do end t:note("%d of our files read by VTK", xc) --- ------------------------------------------------------------------------------------------------ api, options, errors do local text = Cases[1].data t:eq(F.detect(text), "vrml", "F.detect") @@ -390,7 +378,6 @@ do t:check(q and q.meshes[1].primitives[1].faces.count == 1 and q.nodes[1].name == "quad", "a quad stays one polygon, names kept") end --- ------------------------------------------------------------------------------------------------ fuzz do local samples = {} for _, c in Cases do diff --git a/tests/model/x.luau b/tests/model/x.luau index 2f9b872..4712af3 100644 --- a/tests/model/x.luau +++ b/tests/model/x.luau @@ -1,8 +1,5 @@ --- model/x tests: assimp's DirectX test models (text, binary 32-bit, MSZIP-compressed binary) and variants made by --- tools/fixtures/x.py (binary with 64-bit floats, MSZIP-compressed text), against assimp (meshes per material, faces, --- corners, materials, animations, bones, world bounds); frames, materials and textures, vertex colours, skins --- (influences, inverse bind matrices against the bind pose), animation keys (the rotation convention against the --- bind pose); an inline text file; errors; the fuzz no-throw pass. Fixtures: tools/fixtures/x.py. +-- model/x tests: assimp's DirectX models and generated variants (64-bit floats, MSZIP text) against assimp. +-- Fixtures: tools/fixtures/x.py. local T = require("@tests/T") local X = require("@rosetta/model/x") local MeshOps = require("@rosetta/ops/MeshOps") @@ -75,7 +72,6 @@ local function boundsMatch(lo: { number }?, hi: { number }?, a: any, eps: number return true end --- ------------------------------------------------------------------------------------------------ assimp local scenes, byName = {}, {} local checked = 0 for i, c in Cases do @@ -105,7 +101,6 @@ for i, c in Cases do end t:note("%d files checked against assimp", checked) --- variants decode like their originals for _, c in Cases do if c.of then local a, b = scenes[c.name], scenes[c.of] @@ -121,7 +116,6 @@ for _, c in Cases do end end --- ------------------------------------------------------------------------------------------------ details do local s = scenes["models/kwxport_test_cubewithvcolors.x"] local p = s.meshes[1].primitives[1] @@ -135,7 +129,6 @@ do t:eq(v.meta.source.floatSize, 64, "64-bit floats") end do - -- textures: uri names, TEXCOORD_0 local s = scenes["models/test.x"] local any = false for _, m in s.materials do @@ -225,7 +218,6 @@ do t:check(total > 0 and same >= total * 0.5, string.format("first rotation keys match the bind pose (%d / %d)", same, total)) end --- ------------------------------------------------------------------------------------------------ inline file local CUBE = [[xof 0303txt 0032 // a quad and a triangle, two materials, one animated frame Material Red { 1.0; 0.0; 0.0; 1.0;; 10.0; 0.5; 0.5; 0.5;; 0.0; 0.0; 0.0;; TextureFilename { "tex\\red.png"; } } @@ -275,7 +267,6 @@ do t:eq(tri.meshes[1].primitives[1].indices.count, 6, "inline: quad fan-triangulated") end --- ------------------------------------------------------------------------------------------------ errors do local _, e1 = decode("xof 0303txt 00") t:check(e1 and e1.code == Err.TRUNCATED, "short: " .. tostring(e1)) @@ -294,7 +285,6 @@ do t:eq(X.sniff(Bytes.reader(buffer.fromstring(CUBE))), 1, "sniff") end --- ------------------------------------------------------------------------------------------------ fuzz do local samples = { CUBE } for _, c in Cases do diff --git a/tests/model/x3d.luau b/tests/model/x3d.luau index 0d6c051..683b425 100644 --- a/tests/model/x3d.luau +++ b/tests/model/x3d.luau @@ -1,9 +1,5 @@ --- model/x3d tests: assimp's X3D / X3DV / X3DB test models, scenes and glTF samples written by VTK's X3D exporter and --- by assimp's X3D exporter, and hand-written feature files (the X3D triangle / quad / line sets, ColorRGBA, --- ProtoDeclare / ProtoInstance with SFNode defaults, PhysicalMaterial, UnlitMaterial, OrthoViewpoint, ROUTE --- animation, UNIT, the classic encoding's header statements), against assimp's X3D reader (meshes, faces, materials, --- world bounds) and exact expectations; .x3dv against the same model as .x3d; the writer (XML and classic): round --- trips, and assimp reading our X3D like the originals; errors; the fuzz no-throw pass. Fixtures: tools/fixtures/x3d.py. +-- model/x3d tests: assimp's X3D models, VTK / assimp exports and hand-written files against assimp and exact values. +-- Fixtures: tools/fixtures/x3d.py. local T = require("@tests/T") local F = require("@rosetta") local X3d = require("@rosetta/model/x3d") @@ -34,7 +30,6 @@ t:check(X3d.caps.decode and X3d.caps.encode, "contract") -- exporter writes points and lines as 1- / 2-vertex faces (not valid IndexedFaceSet faces, dropped here) local QUIRK = { ["assimp/X3D/ComputerKeyboard.x3d"] = "all", ["assimp-export/assimp_MeshPrimitiveModes.x3d"] = "all" } --- ------------------------------------------------------------------------------------------------ reference files local scenes, byName = {}, {} local checked = { assimp = 0, none = 0 } for i, c in Cases do @@ -73,7 +68,6 @@ for i, c in Cases do end t:note("%d files: %d against assimp, %d without a reference", #Cases, checked.assimp, checked.none) --- ------------------------------------------------------------------------------------------------ exact expectations do local kb = byName["assimp/X3D/ComputerKeyboard.x3d"] if kb then @@ -177,7 +171,6 @@ do end end --- ------------------------------------------------------------------------------------------------ writer local function compare(a: any, b: any, label: string) local sa, sb = C.stats(a), C.stats(b) t:eq(sb.prims, sa.prims, label .. ": placed primitives") @@ -215,7 +208,6 @@ for i, c in Cases do end t:note("%d round trips", rt) --- assimp reads our X3D like the source local sources: { [string]: { any } } = { xcase = {}, wcase = {}, xgltf = {} } for i, c in Cases do sources.xcase[i] = { scenes[i], c } @@ -260,7 +252,6 @@ for _, x in Xcheck do end t:note("%d of our files read by assimp (%d skipped: empty nodes)", xc, skipped) --- ------------------------------------------------------------------------------------------------ api, errors do local hw = Cases[2] t:eq(F.detect(hw.data), "x3d", "F.detect .x3d") @@ -288,7 +279,6 @@ do t:check(us and #u.meshes == 2 and us.prims == 3 and near(us.hi[1], 6, 1e-9) and near(us.hi[2], 2, 1e-6), "USE / containerField / Switch in XML") end --- ------------------------------------------------------------------------------------------------ fuzz do local samples = {} for _, c in Cases do From 98b4ce533eac261eaab53f9e5593d88c8a889218 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:50:30 -0500 Subject: [PATCH 18/25] tests/music: comments: specs only --- tests/music/669.luau | 5 ++--- tests/music/_hively.luau | 5 +---- tests/music/_midivar.luau | 8 ++------ tests/music/_similar.luau | 17 ++++------------- tests/music/ahx.luau | 8 ++------ tests/music/far.luau | 5 ++--- tests/music/hmp.luau | 5 ++--- tests/music/hvl.luau | 8 ++------ tests/music/it.luau | 7 ++----- tests/music/med.luau | 5 ++--- tests/music/midi.luau | 14 +++----------- tests/music/mod.luau | 11 +++-------- tests/music/mtm.luau | 5 ++--- tests/music/mus.luau | 7 ++----- tests/music/okt.luau | 5 ++--- tests/music/ptm.luau | 5 ++--- tests/music/s3m.luau | 7 ++----- tests/music/sf2.luau | 13 ++----------- tests/music/stm.luau | 5 ++--- tests/music/ult.luau | 5 ++--- tests/music/umx.luau | 5 ++--- tests/music/xm.luau | 8 ++------ tests/music/xmi.luau | 5 ++--- 23 files changed, 49 insertions(+), 119 deletions(-) diff --git a/tests/music/669.luau b/tests/music/669.luau index 6717e40..953d8a7 100644 --- a/tests/music/669.luau +++ b/tests/music/669.luau @@ -1,6 +1,5 @@ --- music/669 tests: generated Composer 669 / UNIS 669 modules (tools/fixtures/669.py) parsed, rendered through --- codecs/audio/Tracker and compared with openmpt123's render (loudness envelope, band spectrum, stereo balance, song --- length), the contract, and the fuzz no-throw pass. +-- music/669 tests: generated Composer 669 / UNIS 669 modules vs openmpt123's render. +-- Fixtures: tools/fixtures/669.py. local T = require("@tests/T") local S = require("@tests/music/_similar") local Six69 = require("@rosetta/music/669") diff --git a/tests/music/_hively.luau b/tests/music/_hively.luau index 93e5e09..dcf819c 100644 --- a/tests/music/_hively.luau +++ b/tests/music/_hively.luau @@ -1,12 +1,9 @@ --- tests/music/_hively: shared helper of the AHX / HVL tests (not a test itself): renders a fixture case through the --- format and compares it with hvl2wav's output exactly (16-bit samples: CRC-32 of the whole stream, the first --- differing frame located inside the raw head kept by tools/fixtures/ahx.py / hvl.py). +-- tests/music/_hively: shared helper of the AHX / HVL tests: exact against hvl2wav (CRC-32 of the 16-bit stream). local Bytes = require("@rosetta/core/Bytes") local Crc32 = require("@rosetta/core/Crc32") local H = {} --- check(t, Format, c): decode + render + exact comparison; returns the song function H.check(t: any, Format: any, c: any): any local song, err = Format.decode(Bytes.reader(buffer.fromstring(c.data))) t:check(song, c.name .. ": " .. tostring(err)) diff --git a/tests/music/_midivar.luau b/tests/music/_midivar.luau index 85c1a15..45f374b 100644 --- a/tests/music/_midivar.luau +++ b/tests/music/_midivar.luau @@ -1,7 +1,5 @@ --- tests/music/_midivar: shared helper of the MUS / XMI / HMP tests (not a test itself): compares a decoded Midi's --- channel events (codecs/audio/MidiRender.timeline: play order, seconds) with wildmidi -x's conversion --- (tools/fixtures/_midivar.py): notes on / off, program changes, pitch bends (MSB) and controllers, matched per --- (kind, channel, data) in time order, times within 0.1 ms + 1e-5 relative. +-- tests/music/_midivar: shared helper of the MUS / XMI / HMP tests: channel events against wildmidi -x's conversion +-- (tools/fixtures/_midivar.py), matched per (kind, channel, data) in time order, within 0.1 ms + 1e-5 relative. local Render = require("@rosetta/codecs/audio/MidiRender") local M = {} @@ -22,7 +20,6 @@ local function kindOf(status: number, d1: number, d2: number): string? return nil end --- the comparable events of a list of { seconds, status, d1, d2 }: key -> { seconds } local function index(list: { { number } }, opts: any): ({ [string]: { number } }, { [string]: number }) local by: { [string]: { number } }, counts: { [string]: number } = {}, {} for _, e in list do @@ -38,7 +35,6 @@ local function index(list: { { number } }, opts: any): ({ [string]: { number } } return by, counts end --- compare(t, midi, ref, label, opts?) -> worst time difference (s). opts.skip = { cc = true, ... } function M.compare(t: any, midi: any, ref: any, label: string, opts: any?): number local o = opts or {} local tl = Render.timeline(midi) diff --git a/tests/music/_similar.luau b/tests/music/_similar.luau index 2b5dc82..3933b47 100644 --- a/tests/music/_similar.luau +++ b/tests/music/_similar.luau @@ -1,6 +1,5 @@ --- tests/music/_similar: shared helper of the tracker tests (not a test itself): renders a module through a Decoder and --- compares it with a reference render's features (tools/fixtures/_tracker.py: per 2048-frame block the RMS of left, --- right and mid, and 40 log-spaced band magnitudes of mid from a Hann-windowed FFT). Same definitions on both sides. +-- tests/music/_similar: shared helper of the tracker tests: a render's features against a reference render's +-- (tools/fixtures/_tracker.py: per 2048-frame block the RMS of L / R / mid, 40 log bands of mid). Same definitions. local S = {} local SR, HOP, BANDS = 44100, 2048, 40 @@ -53,7 +52,6 @@ local function fft(re: { number }, im: { number }, n: number) end end --- features(samples (interleaved stereo f32 buffer), frames) -> { frames, rmsL, rmsR, rmsM, bands } function S.features(buf: buffer, frames: number): any local n = frames // HOP local out = { frames = n, rmsL = {}, rmsR = {}, rmsM = {}, bands = {} } @@ -88,7 +86,6 @@ function S.features(buf: buffer, frames: number): any return out end --- renderAll(decoder, maxFrames) -> interleaved buffer, frames function S.renderAll(dec: any, maxFrames: number): (buffer, number) local total = math.min(dec.frames, maxFrames) local out = buffer.create(math.max(1, total) * 8) @@ -109,7 +106,7 @@ local function db(x: number): number return 20 * math.log10(x + 1e-6) end --- compare(ours, ref) -> { gainDb, envCorr, spectral, balance } over the common frames: +-- compare(ours, ref) over the common frames: -- gainDb total mid energy ratio in dB (ours / ref) -- envCorr Pearson correlation of the per-block mid loudness in dB (blocks above -60 dB in either) -- envErr mean absolute difference of the per-block mid loudness in dB, after removing gainDb (same blocks) @@ -181,7 +178,6 @@ function S.compare(a: any, b: any): any } end --- worst(ours, ref, count) -> the blocks with the lowest spectral similarity (for debugging): { {block, sim} } function S.worst(a: any, b: any, count: number): { { number } } local list = {} for k = 1, math.min(a.frames, b.frames) do @@ -206,10 +202,7 @@ function S.worst(a: any, b: any, count: number): { { number } } return out end --- against(t, Fmt, cases, thresh, family?): the shared body of the tracker loader tests (ws-audio2: mtm, 669, stm, ult, --- okt, med, ptm, far, umx): each case decodes, sniffs, plays as long as openmpt's render (thresh.duration s) and --- matches its loudness / envelope / spectrum / balance within thresh; then a seek. cases: { name, data, ref, --- duration }. Returns the decoded modules. The tests run their fuzz pass with S.fuzzer / S.samples. +-- the shared body of the tracker loader tests: durations within thresh.duration s of openmpt's render function S.against(t: any, Fmt: any, cases: { any }, thresh: any, family: string?): { any } local Bytes = require("@rosetta/core/Bytes") local Tracker = require("@rosetta/codecs/audio/Tracker") @@ -256,7 +249,6 @@ function S.against(t: any, Fmt: any, cases: { any }, thresh: any, family: string return mods end --- fuzzer(Fmt) -> the fuzz function of a tracker loader: decode, and a short render of whatever decodes function S.fuzzer(Fmt: any): (buffer) -> any local Bytes = require("@rosetta/core/Bytes") local Tracker = require("@rosetta/codecs/audio/Tracker") @@ -272,7 +264,6 @@ function S.fuzzer(Fmt: any): (buffer) -> any end end --- samples(cases) -> the fuzz seeds (each case's data) function S.samples(cases: { any }): { string } local out = {} for _, c in cases do diff --git a/tests/music/ahx.luau b/tests/music/ahx.luau index 3adacfc..0270b63 100644 --- a/tests/music/ahx.luau +++ b/tests/music/ahx.luau @@ -1,7 +1,5 @@ --- music/ahx tests: AHX songs written by tools/fixtures/_hively.py (every waveform, filter and square sweeps, PList --- commands, effects, subsongs, AHX versions 0..2) and karma.ahx from the HivelyTracker source, rendered through --- codecs/audio/Hively and compared sample for sample with hvl2wav at several stereo separations and rates; the Module --- shape, bad input, and the fuzz no-throw pass. Fixtures: tools/fixtures/ahx.py. +-- music/ahx tests: AHX songs (tools/fixtures/_hively.py, karma.ahx) rendered by codecs/audio/Hively vs hvl2wav. +-- Fixtures: tools/fixtures/ahx.py. local T = require("@tests/T") local H = require("@tests/music/_hively") local Ahx = require("@rosetta/music/ahx") @@ -30,7 +28,6 @@ for _, c in Cases do t:eq(song.patterns[2].rows, 16, "track rows") t:eq(buffer.readu8(song.patterns[2].data, 0), 25, "track 1 row 0 note") t:eq(#song.subsongs, 1, "subsongs") - -- seek back and read again: the same samples local dec = song:render() local a = dec:read(4410) dec:seek(0.5) @@ -43,7 +40,6 @@ for _, c in Cases do end end --- bad input local function code(s: string): string? local _, e = Ahx.decode(Bytes.reader(buffer.fromstring(s))) return e and e.code diff --git a/tests/music/far.luau b/tests/music/far.luau index 0313c54..47fd345 100644 --- a/tests/music/far.luau +++ b/tests/music/far.luau @@ -1,6 +1,5 @@ --- music/far tests: generated Farandole Composer modules (tools/fixtures/far.py) parsed, rendered through --- codecs/audio/Tracker and compared with openmpt123's render (loudness envelope, band spectrum, stereo balance, song --- length), the contract, and the fuzz no-throw pass. +-- music/far tests: generated Farandole Composer modules vs openmpt123's render. +-- Fixtures: tools/fixtures/far.py. local T = require("@tests/T") local S = require("@tests/music/_similar") local Far = require("@rosetta/music/far") diff --git a/tests/music/hmp.luau b/tests/music/hmp.luau index a4ad666..b845ddc 100644 --- a/tests/music/hmp.luau +++ b/tests/music/hmp.luau @@ -1,6 +1,5 @@ --- music/hmp tests: HMP (old and "013195" headers, several tick rates) and HMI files (tools/fixtures/hmp.py) decoded and --- compared with wildmidi -x's conversion (notes, HMI note durations, programs, bends, controllers), the FE / loop --- events skipped, a render, bad input, and the fuzz no-throw pass. +-- music/hmp tests: HMP and HMI files against wildmidi -x's conversion. +-- Fixtures: tools/fixtures/hmp.py. local T = require("@tests/T") local V = require("@tests/music/_midivar") local Hmp = require("@rosetta/music/hmp") diff --git a/tests/music/hvl.luau b/tests/music/hvl.luau index 826acae..6950878 100644 --- a/tests/music/hvl.luau +++ b/tests/music/hvl.luau @@ -1,7 +1,5 @@ --- music/hvl tests: HVL songs written by tools/fixtures/_hively.py (4..8 channels, two effect columns, ring modulation, --- panning, mix gain / stereo from the file, subsongs) and songs from the HivelyTracker source, rendered through --- codecs/audio/Hively and compared sample for sample with hvl2wav (44.1 and 48 kHz); the Module shape, bad input, and --- the fuzz no-throw pass. Fixtures: tools/fixtures/hvl.py. +-- music/hvl tests: HVL songs (tools/fixtures/_hively.py, HivelyTracker's) rendered by codecs/audio/Hively vs hvl2wav. +-- Fixtures: tools/fixtures/hvl.py. local T = require("@tests/T") local H = require("@tests/music/_hively") local Hvl = require("@rosetta/music/hvl") @@ -32,7 +30,6 @@ for _, c in Cases do t:eq(song.patterns[2].rows, 16, "track rows") t:eq(buffer.readu8(song.patterns[2].data, 0), 25, "track 1 row 0 note") t:eq(#song.subsongs, 1, "subsongs") - -- seek back and read again: the same samples local dec = song:render() local a = dec:read(4410) dec:seek(0.5) @@ -45,7 +42,6 @@ for _, c in Cases do end end --- bad input local function code(s: string): string? local _, e = Hvl.decode(Bytes.reader(buffer.fromstring(s))) return e and e.code diff --git a/tests/music/it.luau b/tests/music/it.luau index e9f4f56..a938e03 100644 --- a/tests/music/it.luau +++ b/tests/music/it.luau @@ -1,6 +1,5 @@ --- music/it tests: generated Impulse Tracker modules (tools/fixtures/it.py) parsed, rendered through codecs/audio/Tracker and --- compared with openmpt123's render (loudness envelope, band spectrum, stereo balance, song length), the contract, --- and the fuzz no-throw pass. +-- music/it tests: generated Impulse Tracker modules vs openmpt123's render. +-- Fixtures: tools/fixtures/it.py. local T = require("@tests/T") local S = require("@tests/music/_similar") local It = require("@rosetta/music/it") @@ -54,7 +53,6 @@ for _, c in Cases do end end --- seek: the position after a seek and the output continuing do local m = load(Cases[1].data) local dec = m:render() @@ -65,7 +63,6 @@ do t:check(Tracker.duration(m) == dec.duration, "duration()") end --- the fuzz pass: decode, and a short render of whatever decodes local samples = {} for _, c in Cases do table.insert(samples, c.data) diff --git a/tests/music/med.luau b/tests/music/med.luau index bd76566..a973628 100644 --- a/tests/music/med.luau +++ b/tests/music/med.luau @@ -1,6 +1,5 @@ --- music/med tests: generated MED / OctaMED modules (tools/fixtures/med.py: MMD0, MMD1 with hold / decay and finetune, --- MMD2 with a play sequence, an IFF 3-octave sample) parsed, rendered through codecs/audio/Tracker and compared with openmpt123's render --- (loudness envelope, band spectrum, stereo balance, song length), the contract, and the fuzz no-throw pass. +-- music/med tests: generated MED / OctaMED modules vs openmpt123's render. +-- Fixtures: tools/fixtures/med.py. local T = require("@tests/T") local S = require("@tests/music/_similar") local Med = require("@rosetta/music/med") diff --git a/tests/music/midi.luau b/tests/music/midi.luau index 71894f8..6209df7 100644 --- a/tests/music/midi.luau +++ b/tests/music/midi.luau @@ -1,7 +1,5 @@ --- music/midi tests: SMF formats 0 / 1 / 2 + SMPTE + RMID parsed exactly as python mido parses them, mido's own files --- re-encoded byte for byte, round trips without running status, the tempo map against mido's message times and --- lengths, meta summaries, crafted bad files, truncation (lenient / strict), the fallback-synth render (duration, --- level, seek), and the fuzz no-throw pass (decode, and decode + a short render). Fixtures: tools/fixtures/midi.py. +-- music/midi tests: SMF files parsed exactly as python mido parses them; mido's own files re-encoded byte for byte. +-- Fixtures: tools/fixtures/midi.py. local T = require("@tests/T") local Midi = require("@rosetta/music/midi") local Bytes = require("@rosetta/core/Bytes") @@ -18,7 +16,6 @@ local function decode(data: any, opts: any?): (any, any) return Midi.decode(Bytes.reader(b), opts) end --- the contract t:eq(Midi.name, "midi", "name") t:eq(Midi.category, "music", "category") t:check(table.find(Midi.extensions, "mid") ~= nil, "extensions") @@ -108,7 +105,6 @@ for _, c in Cases do end t:note("%d files parse as mido parses them; mido's files re-encode byte for byte", #Cases) --- meta summaries do local m = decode(byName.format0.data) t:eq(m.tracks[1].name, "format zero", "track name") @@ -186,7 +182,6 @@ do t:eq(#m.tracks[1].events, 2, "the caller's events are not changed") end --- crafted bad files for _, c in Bad do local ok, m, err = pcall(decode, c.data) t:check(ok, c.name .. ": threw " .. tostring(m)) @@ -210,7 +205,6 @@ do t:check(l == nil and lerr.code == Err.LIMIT, "maxEvents: LIMIT") end --- render through the built-in waveform set do local song = decode(byName.song.data) local dec = song:render({ tail = 0.5 }) @@ -253,9 +247,8 @@ do end end t:check(same, "seek renders the same samples as reading through") - a:seek(0.25) -- backwards + a:seek(0.25) t:check(math.abs(a:position() - 0.25) < 1e-4, "seek backwards") - -- open = decode + render local o = Midi.open(Bytes.reader(buffer.fromstring(byName.song.data)), { sampleRate = 22050, tail = 0 }) t:check(o and o.sampleRate == 22050, "open: a Decoder at the asked rate") local bad, berr = Midi.render(song, { sampleRate = 5 }) @@ -264,7 +257,6 @@ do t:check(bs == nil and Err.is(bserr), "render: bad soundfont bytes") end --- the fuzz no-throw pass local samples = {} for _, c in Cases do if #c.data < 20000 then diff --git a/tests/music/mod.luau b/tests/music/mod.luau index e778ac6..7fc36e6 100644 --- a/tests/music/mod.luau +++ b/tests/music/mod.luau @@ -1,6 +1,5 @@ --- music/mod tests: generated ProTracker modules (tools/fixtures/mod.py) parsed, rendered through codecs/audio/Tracker and --- compared with openmpt123's render (loudness envelope, band spectrum, stereo balance, song length), the MOD writer's --- round trip, the contract, and the fuzz no-throw pass. +-- music/mod tests: generated ProTracker modules vs openmpt123's render. +-- Fixtures: tools/fixtures/mod.py. local T = require("@tests/T") local S = require("@tests/music/_similar") local Mod = require("@rosetta/music/mod") @@ -47,8 +46,7 @@ for _, c in Cases do t:eq(buffer.tostring(out :: buffer), c.data, c.name .. ": round trip bytes") end --- MOD -> XM: the converted module plays as long, and sounds alike (XM has no channel panning and uses FT2's NTSC --- Amiga clock, so only the duration and the band spectrum are compared) +-- MOD -> XM: only duration and band spectrum compared (XM has no channel panning, uses the FT2 NTSC Amiga clock) local Xm = require("@rosetta/music/xm") for _, c in Cases do local m = load(c.data) @@ -63,7 +61,6 @@ for _, c in Cases do t:check(r.spectral > 0.9, string.format("%s: xm spectrum %.3f", c.name, r.spectral)) end --- through the API: load sniffs the MOD, open gives a Decoder, save converts to XM, load(as audio) renders do local F = require("@rosetta") local m, err = F.load(Cases[1].data) @@ -75,7 +72,6 @@ do t:eq(F.saveString(m, { format = "mod" }), Cases[1].data, "F.saveString keeps the MOD bytes") end --- seek: the position after a seek and the output continuing do local m = load(Cases[1].data) local dec = m:render() @@ -108,7 +104,6 @@ do t:check(total == 240000 and math.abs(l.duration - dec.duration) < 0.01, "loop plays past the end") end --- the fuzz pass: decode, and a short render of whatever decodes local samples = {} for _, c in Cases do table.insert(samples, c.data) diff --git a/tests/music/mtm.luau b/tests/music/mtm.luau index 1e7c70e..ef1866f 100644 --- a/tests/music/mtm.luau +++ b/tests/music/mtm.luau @@ -1,6 +1,5 @@ --- music/mtm tests: generated MultiTracker modules (tools/fixtures/mtm.py) parsed, rendered through codecs/audio/Tracker --- and compared with openmpt123's render (loudness envelope, band spectrum, stereo balance, song length), the contract, --- and the fuzz no-throw pass. +-- music/mtm tests: generated MultiTracker modules vs openmpt123's render. +-- Fixtures: tools/fixtures/mtm.py. local T = require("@tests/T") local S = require("@tests/music/_similar") local Mtm = require("@rosetta/music/mtm") diff --git a/tests/music/mus.luau b/tests/music/mus.luau index b785040..82fd86e 100644 --- a/tests/music/mus.luau +++ b/tests/music/mus.luau @@ -1,6 +1,5 @@ --- music/mus tests: Doom MUS files (tools/fixtures/mus.py) decoded and compared with wildmidi -x's conversion (notes, --- programs, pitch bend MSB, controllers; times at wildmidi's tick rate), system events / measure ends, the tick rate --- option, a render, bad input, and the fuzz no-throw pass. +-- music/mus tests: Doom MUS files against wildmidi -x's conversion (times at wildmidi's tick rate). +-- Fixtures: tools/fixtures/mus.py. local T = require("@tests/T") local V = require("@tests/music/_midivar") local Mus = require("@rosetta/music/mus") @@ -57,7 +56,6 @@ do t:eq(q.meta.length, p.meta.length, "measures: same length") end --- a render through the built-in waveforms do local m = assert(decode(Cases[1].data)) local dec = m:render({ sampleRate = 22050, tail = 0.2 }) @@ -70,7 +68,6 @@ do t:check(peak > 0.01, "render makes sound") end --- bad input local _, e1 = decode("MUS\x1a\1\0") t:eq(e1 and e1.code, Err.TRUNCATED, "short header") local _, e2 = decode("MUS\x1a\2\0\200\0\1\0\0\0\0\0\0\0") diff --git a/tests/music/okt.luau b/tests/music/okt.luau index e0882a6..4bfb232 100644 --- a/tests/music/okt.luau +++ b/tests/music/okt.luau @@ -1,6 +1,5 @@ --- music/okt tests: generated Oktalyzer modules (tools/fixtures/okt.py) parsed, rendered through codecs/audio/Tracker --- and compared with openmpt123's render (loudness envelope, band spectrum, stereo balance, song length), the contract, --- and the fuzz no-throw pass. +-- music/okt tests: generated Oktalyzer modules vs openmpt123's render. +-- Fixtures: tools/fixtures/okt.py. local T = require("@tests/T") local S = require("@tests/music/_similar") local Okt = require("@rosetta/music/okt") diff --git a/tests/music/ptm.luau b/tests/music/ptm.luau index fd363c1..32dac33 100644 --- a/tests/music/ptm.luau +++ b/tests/music/ptm.luau @@ -1,6 +1,5 @@ --- music/ptm tests: generated PolyTracker modules (tools/fixtures/ptm.py) parsed, rendered through codecs/audio/Tracker --- and compared with openmpt123's render (loudness envelope, band spectrum, stereo balance, song length), the contract, --- and the fuzz no-throw pass. +-- music/ptm tests: generated PolyTracker modules vs openmpt123's render. +-- Fixtures: tools/fixtures/ptm.py. local T = require("@tests/T") local S = require("@tests/music/_similar") local Ptm = require("@rosetta/music/ptm") diff --git a/tests/music/s3m.luau b/tests/music/s3m.luau index c3807b7..b9b523a 100644 --- a/tests/music/s3m.luau +++ b/tests/music/s3m.luau @@ -1,6 +1,5 @@ --- music/s3m tests: generated Scream Tracker 3 modules (tools/fixtures/s3m.py) parsed, rendered through codecs/audio/Tracker and --- compared with openmpt123's render (loudness envelope, band spectrum, stereo balance, song length), the contract, --- and the fuzz no-throw pass. +-- music/s3m tests: generated Scream Tracker 3 modules vs openmpt123's render. +-- Fixtures: tools/fixtures/s3m.py. local T = require("@tests/T") local S = require("@tests/music/_similar") local S3m = require("@rosetta/music/s3m") @@ -41,7 +40,6 @@ for _, c in Cases do t:check(r.balance < THRESH.balance, c.name .. ": stereo balance") end --- seek: the position after a seek and the output continuing do local m = load(Cases[1].data) local dec = m:render() @@ -52,7 +50,6 @@ do t:check(Tracker.duration(m) == dec.duration, "duration()") end --- the fuzz pass: decode, and a short render of whatever decodes local samples = {} for _, c in Cases do table.insert(samples, c.data) diff --git a/tests/music/sf2.luau b/tests/music/sf2.luau index 67932f3..6bef0fb 100644 --- a/tests/music/sf2.luau +++ b/tests/music/sf2.luau @@ -1,7 +1,5 @@ --- music/sf2 + codecs/audio/SoundFont tests: a self-made SF2 parsed (INFO, presets, sample headers, instruments, generator --- merging with preset / instrument global zones, 16-bit and sm24 samples), a test song rendered through it compared --- with FluidSynth's render (loudness envelope and per-segment band spectra by correlation, pitch peaks), bad files, --- the built-in fallback waveform set, and the fuzz no-throw pass. Fixtures: tools/fixtures/sf2.py. +-- music/sf2 + codecs/audio/SoundFont tests: a self-made SF2; a test song rendered through it vs FluidSynth. +-- Fixtures: tools/fixtures/sf2.py. local T = require("@tests/T") local Sf2 = require("@rosetta/music/sf2") local Midi = require("@rosetta/music/midi") @@ -16,14 +14,12 @@ local function reader(s: string): Bytes.Reader return Bytes.reader(buffer.fromstring(s)) end --- the contract t:eq(Sf2.name, "sf2", "name") t:eq(Sf2.category, "music", "category") t:check(Sf2.caps.decode and not Sf2.caps.encode, "caps") t:eq(Sf2.sniff(reader(Fx.sf2)), 1, "sniff") t:eq(Sf2.sniff(reader("RIFF\0\0\0\0WAVE")), 0, "sniff WAVE") --- parse local sf, err = Sf2.decode(reader(Fx.sf2)) t:check(sf, "decode: " .. tostring(err)) local E = Fx.expect @@ -93,7 +89,6 @@ do t:eq(buffer.len(sf.samples), (sf.sampleCount + 1) * 4, "samples: one pad sample") end --- ------------------------------------------------------------------------------------------------ vs FluidSynth local F = Fx.fluid local song = Midi.decode(reader(Fx.song)) t:check(song, "song decodes") @@ -134,7 +129,6 @@ local function pearson(a: { number }, b: { number }): number return sab / math.sqrt(saa * sbb + 1e-30) end --- in-place radix-2 FFT of re / im (1-based arrays of length n, a power of two) local function fft(re: { number }, im: { number }, n: number) local j = 0 for i = 0, n - 2 do @@ -248,7 +242,6 @@ for wi, w in F.windows do t:note("window %g-%g s: peak %.1f Hz (FluidSynth %.1f Hz)", w[1], w[2], hz, F.peaks[wi]) end --- ------------------------------------------------------------------------------------------------ bad files local function bad(data: string, code: string, label: string) local ok, v, e = pcall(Sf2.decode, reader(data)) t:check(ok, label .. ": threw " .. tostring(v)) @@ -265,7 +258,6 @@ t:check(lim2 == nil and lerr2.code == Err.LIMIT, "maxRegions: LIMIT") local p, perr = SoundFont.parse(42 :: any) t:check(p == nil and perr.code == Err.ARG, "parse: bad argument") --- ------------------------------------------------------------------------------------------------ fallback do local fb = SoundFont.fallback() t:eq(#fb.presets, 129, "fallback: 128 programs + a drum kit") @@ -310,7 +302,6 @@ do t:check(true, "out-of-range render requests are clipped") end --- the fuzz no-throw pass (parse, then a few notes through whatever parsed) t:fuzz("decode", function(b: buffer) local f = Sf2.decode(Bytes.reader(b)) if f then diff --git a/tests/music/stm.luau b/tests/music/stm.luau index eea0197..05eb641 100644 --- a/tests/music/stm.luau +++ b/tests/music/stm.luau @@ -1,6 +1,5 @@ --- music/stm tests: generated Scream Tracker 2 modules (tools/fixtures/stm.py) parsed, rendered through --- codecs/audio/Tracker and compared with openmpt123's render (loudness envelope, band spectrum, stereo balance, song --- length), the contract, and the fuzz no-throw pass. +-- music/stm tests: generated Scream Tracker 2 modules vs openmpt123's render. +-- Fixtures: tools/fixtures/stm.py. local T = require("@tests/T") local S = require("@tests/music/_similar") local Stm = require("@rosetta/music/stm") diff --git a/tests/music/ult.luau b/tests/music/ult.luau index 63772aa..179bd55 100644 --- a/tests/music/ult.luau +++ b/tests/music/ult.luau @@ -1,6 +1,5 @@ --- music/ult tests: generated UltraTracker modules (tools/fixtures/ult.py) parsed, rendered through codecs/audio/Tracker --- and compared with openmpt123's render (loudness envelope, band spectrum, stereo balance, song length), the contract, --- and the fuzz no-throw pass. +-- music/ult tests: generated UltraTracker modules vs openmpt123's render. +-- Fixtures: tools/fixtures/ult.py. local T = require("@tests/T") local S = require("@tests/music/_similar") local Ult = require("@rosetta/music/ult") diff --git a/tests/music/umx.luau b/tests/music/umx.luau index 5437288..d39dc91 100644 --- a/tests/music/umx.luau +++ b/tests/music/umx.luau @@ -1,6 +1,5 @@ --- music/umx tests: Unreal packages wrapping generated S3M / IT modules (tools/fixtures/umx.py): the export found and --- unwrapped (bytes equal to the module put in), loaded through the api's decodeModule hook and rendered like --- openmpt123 renders the package, UNSUPPORTED without the hook, the contract, and the fuzz no-throw pass. +-- music/umx tests: Unreal packages wrapping generated S3M / IT modules, rendered like openmpt123 renders the package. +-- Fixtures: tools/fixtures/umx.py. local T = require("@tests/T") local S = require("@tests/music/_similar") local F = require("@rosetta") diff --git a/tests/music/xm.luau b/tests/music/xm.luau index a224314..f81805e 100644 --- a/tests/music/xm.luau +++ b/tests/music/xm.luau @@ -1,7 +1,5 @@ --- music/xm tests: generated FastTracker 2 modules (tools/fixtures/xm.py) parsed, rendered through codecs/audio/Tracker and --- compared with openmpt123's render (loudness envelope, band spectrum, stereo balance, song length; a ModPlug ADPCM --- sample), the XM writer's --- round trip, the contract, and the fuzz no-throw pass. +-- music/xm tests: generated FastTracker 2 modules vs openmpt123's render. +-- Fixtures: tools/fixtures/xm.py. local T = require("@tests/T") local S = require("@tests/music/_similar") local Xm = require("@rosetta/music/xm") @@ -53,7 +51,6 @@ for _, c in Cases do end end --- seek: the position after a seek and the output continuing do local m = load(Cases[1].data) local dec = m:render() @@ -64,7 +61,6 @@ do t:check(Tracker.duration(m) == dec.duration, "duration()") end --- the fuzz pass: decode, and a short render of whatever decodes local samples = {} for _, c in Cases do table.insert(samples, c.data) diff --git a/tests/music/xmi.luau b/tests/music/xmi.luau index c787a6e..3d6889c 100644 --- a/tests/music/xmi.luau +++ b/tests/music/xmi.luau @@ -1,6 +1,5 @@ --- music/xmi tests: XMIDI files (tools/fixtures/xmi.py: XDIR + CAT XMID with one or two songs, a bare FORM XMID, with --- and without TIMB) decoded and compared with wildmidi -x's conversion of song 1 (notes from durations, programs, --- bends, controllers; 120 Hz), song selection, export to SMF, a render, bad input, and the fuzz no-throw pass. +-- music/xmi tests: XMIDI files against wildmidi -x's conversion of song 1 (120 Hz). +-- Fixtures: tools/fixtures/xmi.py. local T = require("@tests/T") local V = require("@tests/music/_midivar") local Xmi = require("@rosetta/music/xmi") From a6732d45f25aa8f147e53ac634cc032ae541adad Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:50:53 -0500 Subject: [PATCH 19/25] tests/codecs (m-z): comments: specs only --- tests/codecs/mdct.luau | 8 ++------ tests/codecs/minecraft.luau | 12 +++--------- tests/codecs/mpeg1.luau | 20 +++++--------------- tests/codecs/mpeg2.luau | 24 ++++++------------------ tests/codecs/musepack.luau | 6 ++---- tests/codecs/nbt.luau | 14 +------------- tests/codecs/packbits.luau | 3 +-- tests/codecs/polygon.luau | 3 +-- tests/codecs/quantize.luau | 8 +------- tests/codecs/raster.luau | 12 +++--------- tests/codecs/resample.luau | 11 ++--------- tests/codecs/rig.luau | 7 +------ tests/codecs/sampler.luau | 4 +--- tests/codecs/theora.luau | 18 ++++-------------- tests/codecs/unixcompress.luau | 6 ++---- tests/codecs/url.luau | 9 ++------- tests/codecs/vp8.luau | 8 ++------ tests/codecs/vp8l.luau | 8 +------- tests/codecs/vp8video.luau | 8 +------- tests/codecs/vrml.luau | 9 +-------- tests/codecs/xml.luau | 11 +---------- tests/codecs/yuv.luau | 4 +--- tests/codecs/zstd.luau | 10 ++-------- 23 files changed, 46 insertions(+), 177 deletions(-) diff --git a/tests/codecs/mdct.luau b/tests/codecs/mdct.luau index 2ad003b..c49765d 100644 --- a/tests/codecs/mdct.luau +++ b/tests/codecs/mdct.luau @@ -1,6 +1,5 @@ --- codecs/audio/Mdct tests: the FFT against a direct DFT for mixed-radix sizes, the forward / inverse MDCT and the DCT-IV --- against their O(N^2) definitions (AAC, Vorbis and CELT sizes), perfect reconstruction (TDAC) with the sine, KBD and --- Vorbis windows, window power complementarity, bad sizes. No fixtures (the definitions are the reference). +-- codecs/audio/Mdct tests: the FFT, MDCT and DCT-IV against their O(N^2) definitions, TDAC with every window. +-- No fixtures: the definitions are the reference. local T = require("@tests/T") local Mdct = require("@rosetta/codecs/audio/Mdct") @@ -16,7 +15,6 @@ local function noise(n: number): { number } return a end --- FFT vs DFT for _, n in { 1, 2, 3, 4, 5, 6, 7, 8, 12, 15, 16, 30, 49, 60, 64, 120, 240, 480, 77 } do local plan = Mdct.fft(n) t:check(plan, "fft plan " .. n) @@ -39,7 +37,6 @@ for _, n in { 1, 2, 3, 4, 5, 6, 7, 8, 12, 15, 16, 30, 49, 60, 64, 120, 240, 480, t:check(err < 1e-9 * n, string.format("fft %d: max error %g", n, err)) end --- MDCT / IMDCT vs the definitions local maxErr = 0 for _, n in { 4, 8, 16, 64, 240, 256, 480, 1920, 2048 } do local plan = Mdct.new(n) :: Mdct.Plan @@ -127,7 +124,6 @@ do t:check(e < 1e-10, "dct4 involution: " .. e) end --- bad sizes t:check(Mdct.new(6) == nil and Mdct.new(0) == nil and Mdct.new(-8) == nil and Mdct.new(8.5) == nil and Mdct.new("x" :: any) == nil, "bad mdct sizes") t:check(Mdct.fft(0) == nil and Mdct.window("nope", 8) == nil and Mdct.window("sine", 7) == nil, "bad fft sizes / windows") diff --git a/tests/codecs/minecraft.luau b/tests/codecs/minecraft.luau index 25f2557..04cd922 100644 --- a/tests/codecs/minecraft.luau +++ b/tests/codecs/minecraft.luau @@ -1,6 +1,4 @@ --- codecs/model/Minecraft tests: packed index arrays (spanning and not, 1..16 bits, against a bit-by-bit reference), --- Sponge varints, nibble arrays, YZX reordering, block-state strings and their NBT form, every legacy id / data pair --- through legacyState / legacyId, colours (air, families, fallbacks), voxels / blocksOf and nearest-colour blocks. +-- codecs/model/Minecraft tests: packed arrays, varints, nibbles, block states, legacy ids, colours, voxels. -- The formats using it: tests/model/schematic.luau, tests/model/mca.luau. local T = require("@tests/T") local Mc = require("@rosetta/codecs/model/Minecraft") @@ -10,7 +8,7 @@ local t = T.suite("minecraft") local P = Mc.Packed local rand = T.rng(3) --- 1. packed arrays against a reference that walks the bits one at a time +-- packed arrays against a reference that walks the bits one at a time local function refBit(longs: buffer, p: number): number return bit32.extract(buffer.readu8(longs, p // 8), p % 8, 1) end @@ -52,7 +50,6 @@ do t:eq(P.bitsFor(1, 2), 2, "bitsFor minimum") end --- 2. varints, nibbles, YZX do local idx = buffer.create(400) for i = 0, 199 do @@ -84,7 +81,6 @@ do t:eq(buffer.tostring(P.toYzx(vox, sx, sy, sz)), buffer.tostring(yzx), "toYzx") end --- 3. states do local name, props = Mc.parseState("oak_log[axis=y, foo = bar]") t:eq(name, "minecraft:oak_log", "namespace added") @@ -97,7 +93,7 @@ do t:check(Mc.isAir("minecraft:cave_air") and not Mc.isAir("minecraft:stone"), "isAir") end --- 4. legacy ids: every id / data pair reads back exactly +-- legacy ids: every id / data pair reads back exactly do local bad = 0 for id = 0, 255 do @@ -116,7 +112,6 @@ do t:eq(select(1, Mc.legacyId("minecraft:white_concrete")), 251, "modern name -> legacy id") end --- 5. colours do t:eq(Mc.color("minecraft:air"), nil, "air") local function hex(s: string): string @@ -132,7 +127,6 @@ do t:eq(hex("mod:something_odd"), "909090ff", "fallback") end --- 6. voxels / blocksOf do local states = { "minecraft:air", "minecraft:stone", "minecraft:red_wool", "minecraft:stone" } local idx = buffer.create(8 * 2) diff --git a/tests/codecs/mpeg1.luau b/tests/codecs/mpeg1.luau index b0fe7a8..ccc48cd 100644 --- a/tests/codecs/mpeg1.luau +++ b/tests/codecs/mpeg1.luau @@ -1,12 +1,5 @@ --- codecs/video/Mpeg1 tests, ported from mpeg1-luau tests/decode.luau and tests/robust.luau. Every frame bit-exact with --- `ffmpeg -idct int` (the IDCT codecs/video/Dsp reproduces; frames with concealed macroblocks excepted). Against ffmpeg --- (tools/fixtures/mpeg1.py): every stream decodes, one access unit at a time, to as many frames as ffmpeg's decode, --- in display order; each frame's RGBA channel means within 1.5 of ffmpeg's; whole sampled frames within 2 MAE per --- channel (IDCT and colour rounding) and, as yuv420p (frameImage), within a PSNR floor of ffmpeg -pix_fmt yuv420p; --- the same stream written in random pieces through write() / decodeFrame() gives identical frames; a size change. --- Robustness / API: bad arguments, pictures before the first sequence header, reset(), rgba = false, tags through --- B-frame reordering, string input, truncated units, bit flips and garbage (never throws, recovers at an --- I-picture), an oversized sequence header; frameImage; the fuzz no-throw pass. +-- codecs/video/Mpeg1 tests: every frame bit-exact with `ffmpeg -idct int` (concealed macroblocks excepted), the API. +-- Fixtures: tools/fixtures/mpeg1.py. local T = require("@tests/T") local Mpeg1 = require("@rosetta/codecs/video/Mpeg1") local Base64 = require("@rosetta/core/Base64") @@ -43,7 +36,6 @@ local function z64(s: string): buffer return Deflate.zlib(b64(s)) :: buffer end --- mean absolute error per channel (r, g, b) between two RGBA8 buffers of n pixels, and the largest difference local function mae(a: buffer, b: buffer, n: number): (number, number, number, number) local sr, sg, sb, mx = 0, 0, 0, 0 for i = 0, n - 1 do @@ -86,7 +78,6 @@ local MAE_LIMIT = 2 local totalExact, totalConcealed = 0, 0 local MEAN_LIMIT = 1.5 --- 1. every stream against ffmpeg local worst, worstY, worstC = 0, 99, 99 for _, fx in STREAMS do local name = fx.name @@ -211,7 +202,7 @@ end t:note("worst sampled-frame MAE %.3f (limit %d); worst yuv420p PSNR luma %.1f, chroma %.1f dB", worst, MAE_LIMIT, worstY, worstC) t:note("%d frames bit-exact with ffmpeg -idct int, %d with concealed macroblocks (ffmpeg error concealment)", totalExact, totalConcealed) --- 2. a size change mid-stream +-- a size change mid-stream do local file = b64(SizeChange.file) local dec = Mpeg1.new() @@ -235,7 +226,6 @@ do end end --- 3. robustness and the API local function slice(b: buffer, from: number, n: number): buffer local out = buffer.create(n) buffer.copy(out, 0, b, from, n) @@ -254,7 +244,7 @@ do t:eq(#ref, #main.units, "reference decode") end -do -- bad arguments +do local dec = Mpeg1.new() t:check(dec:decode((nil :: any)) == nil, "decode(nil)") t:check(dec:decode((42 :: any)) == nil, "decode(number)") @@ -488,7 +478,7 @@ do -- a hostile sequence header: a huge size is rejected t:eq(dec.width, 0, "oversized sequence header rejected") end --- 4. the fuzz pass: whole elementary streams (cut, mutated, garbage) through one decoder each +-- the fuzz pass: whole elementary streams (cut, mutated, garbage) through one decoder each do local samples = {} for _, k in { 1, 9 } do diff --git a/tests/codecs/mpeg2.luau b/tests/codecs/mpeg2.luau index 9b98e12..9385dde 100644 --- a/tests/codecs/mpeg2.luau +++ b/tests/codecs/mpeg2.luau @@ -1,10 +1,5 @@ --- codecs/video/Mpeg2 tests. Against `ffmpeg -idct int` (tools/fixtures/mpeg2.py): every stream (progressive and --- interlaced frame pictures with field prediction and field DCT, top / bottom field first, 4:2:2, the alternate scan, --- Table B-15, the non-linear quantiser scale, DC precision 9..11, custom luma / chroma matrices, f_code > 1, an odd --- size, B-frames, dual prime, field pictures, concealment vectors) decodes one access unit at a time to exactly ffmpeg's planes, every frame, in display --- order; the same stream written in random pieces gives the same frames; frame flags (mpeg2, chroma, progressive, --- topFieldFirst); frameImage (4:2:2 -> yuv420p, rgba8); the registry's VideoCodecDecoder; truncated and corrupted --- streams never throw; the fuzz no-throw pass. +-- codecs/video/Mpeg2 tests: every stream decodes to exactly `ffmpeg -idct int`'s planes, every frame, display order. +-- Fixtures: tools/fixtures/mpeg2.py. local T = require("@tests/T") local Mpeg2 = require("@rosetta/codecs/video/Mpeg2") local Video = require("@rosetta/codecs/video/Video") @@ -35,7 +30,6 @@ local function b64(s: string): buffer return Base64.decode(s) :: buffer end --- CRC-32 of a plane cropped to w x h from a buffer with stride local function planeCrc(b: buffer, stride: number, w: number, h: number): number local row = buffer.create(w * h) for y = 0, h - 1 do @@ -44,7 +38,6 @@ local function planeCrc(b: buffer, stride: number, w: number, h: number): number return Crc32.of(row) end --- the cropped planes of a frame, as ffmpeg writes them (w x h luma, ceil(w / 2) x (h or ceil(h / 2)) chroma) local function crcs(f: any): (number, number, number) local w, h = f.width, f.height local cw = (w + 1) // 2 @@ -53,7 +46,6 @@ local function crcs(f: any): (number, number, number) return planeCrc(f.y, f.codedWidth, w, h), planeCrc(f.cb, chw, cw, ch), planeCrc(f.cr, chw, cw, ch) end --- differing samples between a frame's luma and a reference yuv frame (debug detail on a mismatch) local function lumaDiff(f: any, ref: buffer): (number, number) local n, first = 0, -1 for y = 0, f.height - 1 do @@ -103,9 +95,8 @@ local function decodeUnits(fx: any, file: buffer): { any } return out end --- 1. every stream against ffmpeg, bit-exact. ffmpeg's encoder sometimes ends a B-picture slice before the row's last --- macroblock (invalid MPEG-2); both decoders conceal the gap, ffmpeg with its error-resilience guesses and deblocking. --- Frames with concealed macroblocks compare every 16-line luma band but those and their neighbours. +-- ffmpeg's encoder sometimes ends a B-picture slice before the row's last macroblock (invalid MPEG-2); both decoders +-- conceal the gap differently, so frames with concealed macroblocks skip those 16-line luma bands and their neighbours. local total, concealedFrames = 0, 0 for _, fx in STREAMS do local name = fx.name @@ -154,7 +145,6 @@ for _, fx in STREAMS do if fx.chroma == 2 then "4:2:2" else "4:2:0", #got, #got / dt) end --- 2. interlace flags do local got = decodeUnits(STREAMS[2], b64(STREAMS[2].file)) t:check(got[1][4].progressive == false and got[1][4].topFieldFirst == true, "tff: interlaced, top field first") @@ -164,7 +154,7 @@ do t:check(got[1][4].progressive == true, "prog: progressive") end --- 3. the same stream written in random pieces (decodeFrame) gives the same frames as unit by unit +-- the same stream written in random pieces (decodeFrame) gives the same frames as unit by unit for _, idx in { 2, 9, 12 } do local fx = STREAMS[idx] local file = b64(fx.file) @@ -200,7 +190,6 @@ for _, idx in { 2, 9, 12 } do t:check(ok and k == fx.frames, string.format("%s: random pieces give the same %d frames (%d)", fx.name, fx.frames, k)) end --- 4. frameImage: yuv420p (4:2:2 converted), rgba8 do local fx = STREAMS[9] local dec = Mpeg2.new({ reorder = false, rgba = true }) @@ -222,7 +211,7 @@ do t:check(Mpeg2.frameImage({} :: any) == nil, "frameImage of a non-frame is nil") end --- 5. the registry's decoder (packets = access units), display order with pts +-- the registry's decoder (packets = access units), display order with pts do t:check(Video.fromFourcc("mpg2") == "mpeg2" and Video.fromMatroska("V_MPEG2") == "mpeg2", "registry names") t:check(Video.canDecode("mpeg2") and Video.canDecode("mpeg1"), "registry decoders") @@ -256,7 +245,6 @@ do t:check(order, "registry decoder: frames in display order, equal to the codec's") end --- 6. robustness: truncated units, bit flips, garbage (never throws), and the fuzz pass do local samples = {} for _, idx in { 1, 2, 9, 11 } do diff --git a/tests/codecs/musepack.luau b/tests/codecs/musepack.luau index 530157b..fe3d352 100644 --- a/tests/codecs/musepack.luau +++ b/tests/codecs/musepack.luau @@ -1,7 +1,5 @@ --- codecs/audio/Musepack tests: the codec API under audio/mpc: magic, the stream fields of SV7 / SV8 fixtures (version, --- rate, channels, band count, packet layout, gapless length), packets decoded by hand against libmpcdec (the --- synthesis delay at the front), out-of-order decodes, and a fuzz pass over open + every packet. Fixtures: --- tools/fixtures/mpc.py. +-- codecs/audio/Musepack tests: SV7 / SV8 stream fields, packets against libmpcdec (synthesis delay at the front). +-- Fixtures: tools/fixtures/mpc.py. local T = require("@tests/T") local Musepack = require("@rosetta/codecs/audio/Musepack") local Fx = require("@tests/gen/mpc_cases") diff --git a/tests/codecs/nbt.luau b/tests/codecs/nbt.luau index 4da181e..df83f42 100644 --- a/tests/codecs/nbt.luau +++ b/tests/codecs/nbt.luau @@ -1,7 +1,4 @@ --- codecs/text/Nbt tests: random trees written by Python's nbtlib (Java big-endian, Bedrock little-endian, gzip, zlib, --- the level.dat header) decode to nbtlib's typed values (a canonical dump), re-encode to nbtlib's exact bytes in both --- byte orders, nbtlib's SNBT (indented and compact) parses to the same values and our SNBT reads back exactly; --- Bedrock network varint NBT; modified UTF-8; long extremes; SNBT grammar details; peek; errors; the fuzz pass. +-- codecs/text/Nbt tests: random trees by Python's nbtlib (Java / Bedrock, gzip, zlib) decode, re-encode exactly, SNBT. -- Fixtures: tools/fixtures/nbt.py. local T = require("@tests/T") local Nbt = require("@rosetta/codecs/text/Nbt") @@ -68,7 +65,6 @@ local function same(a: buffer, b: string): boolean return buffer.tostring(a) == b end --- 1. nbtlib trees for _, c in Fx.cases do local v, info = Nbt.decode(c.raw) t:check(v ~= nil, c.name .. ": decode " .. tostring(info)) @@ -87,7 +83,6 @@ for _, c in Fx.cases do t:eq(wi.endian, if k == "little" or k == "header" then "little" else "big", c.name .. ": " .. k .. " endian") end t:eq(wi.compression, if k == "gzip" or k == "zlib" then k else "none", c.name .. ": " .. k .. " compression") - -- written back the same way it was read local again = Nbt.encode(w) :: buffer local w2, wi2 = Nbt.decode(again) t:eq(canon(w2), c.canon, c.name .. ": " .. k .. " round trip") @@ -116,7 +111,6 @@ for _, c in Fx.cases do end end --- 2. Bedrock network NBT for i, c in Fx.net do local v, info = Nbt.decode(c.data, { varint = true }) t:check(v ~= nil, "net " .. i .. ": " .. tostring(info)) @@ -124,7 +118,6 @@ for i, c in Fx.net do t:check(same(Nbt.encode(v, { varint = true }) :: buffer, c.data), "net " .. i .. ": same bytes") end --- 3. details do -- longs: exact past 2^53, both directions for _, s in { "9223372036854775807", "-9223372036854775808", "9007199254740993", "-9007199254740993", "4294967296", "-1" } do @@ -155,14 +148,12 @@ do t:eq(tostring(Nbt.byte(3)), "3b", "tostring byte") t:eq(tostring(Nbt.float(0.1)), "0.1f", "tostring float (shortest)") t:check(Nbt.short(5) == Nbt.short(5) and Nbt.short(5) ~= Nbt.int(5) :: any, "tag equality") - -- get local g = assert(Nbt.parse("{Data:{Pos:[1.0d,2.5d,3.0d],Inv:[{id:\"x\"}]}}")) t:eq(Nbt.get(g, "Data.Pos[1]").value, 2.5, "get list element") t:eq(Nbt.get(g, "Data.Inv[0].id"), "x", "get nested") t:eq(Nbt.get(g, "Data.Missing.x"), nil, "get missing") end --- 4. SNBT grammar do local cases: { { string } } = { { "1b", "byte:1" }, { "-5S", "short:-5" }, { "7", "int:7" }, { "7i", "int:7" }, { "1_000", "int:1000" }, @@ -200,7 +191,6 @@ do t:check(e3 and e3.code == Err.LIMIT, "depth limit") end --- 5. peek do local c = Fx.cases[2] for _, k in { "raw", "gzip", "zlib", "header" } do @@ -210,7 +200,6 @@ do t:eq(Nbt.peek(buffer.fromstring("hello world")), nil, "peek text") end --- 6. errors do local _, e = Nbt.decode("\10\0\0\1\0\1a") t:check(e and e.code == Err.TRUNCATED, "truncated") @@ -233,7 +222,6 @@ do t:check(e6 and e6.code == Err.ARG, "encode function") end --- 7. fuzz local samples = {} for i = 1, 8 do table.insert(samples, Fx.cases[i].raw) diff --git a/tests/codecs/packbits.luau b/tests/codecs/packbits.luau index ceea442..3ae473e 100644 --- a/tests/codecs/packbits.luau +++ b/tests/codecs/packbits.luau @@ -1,5 +1,4 @@ --- codecs/compress/PackBits tests: the Apple technote example, encode -> decode round trips of random / runny rows, --- the clean flag on short input and overflowing runs, and a no-throw pass over garbage. +-- codecs/compress/PackBits tests: the Apple technote example, round trips, the clean flag, garbage. local T = require("@tests/T") local PackBits = require("@rosetta/codecs/compress/PackBits") diff --git a/tests/codecs/polygon.luau b/tests/codecs/polygon.luau index 4bd215e..6533fa0 100644 --- a/tests/codecs/polygon.luau +++ b/tests/codecs/polygon.luau @@ -1,5 +1,4 @@ --- codecs/model/Polygon tests: convex / concave / holed / nested polygons triangulate to the exact area in --- counter-clockwise triangles, either input orientation; degenerate loops; a fuzz of random loops never throws. +-- codecs/model/Polygon tests: polygons triangulate to the exact area in counter-clockwise triangles, degenerate loops. local T = require("@tests/T") local Polygon = require("@rosetta/codecs/model/Polygon") diff --git a/tests/codecs/quantize.luau b/tests/codecs/quantize.luau index 16a88dd..37ae3cd 100644 --- a/tests/codecs/quantize.luau +++ b/tests/codecs/quantize.luau @@ -1,6 +1,4 @@ --- codecs/image/Quantize tests: palette size bounds for every method and colour budget, the exact (lossless) palette at --- <= maxColors colours, transparency handling, PSNR of quantized images above thresholds, determinism of both --- methods and of Floyd-Steinberg dithering (the same CRC on both runtimes), bad arguments, and a no-throw pass. +-- codecs/image/Quantize tests: palette bounds, exact palettes, transparency, PSNR thresholds, determinism. local T = require("@tests/T") local Quantize = require("@rosetta/codecs/image/Quantize") local Crc32 = require("@rosetta/core/Crc32") @@ -43,7 +41,6 @@ end local W, H = 128, 96 local px = photo(W, H) --- palette bounds and quality local MIN_PSNR = { [256] = 30, [64] = 24, [16] = 17, [2] = 10 } for _, method in { "mediancut", "octree" } do for _, k in { 2, 16, 64, 256 } do @@ -66,7 +63,6 @@ for _, method in { "mediancut", "octree" } do end end --- exact palettes: lossless do local n = 50 * 40 local b = buffer.create(n * 4) @@ -84,7 +80,6 @@ do t:check(e3 and #p3 == 200 and buffer.tostring(render(i3, p3, n)) == buffer.tostring(b), "quantize() exact") end --- transparency do local b = buffer.create(16 * 4) for i = 0, 15 do @@ -112,7 +107,6 @@ do t:check(#o1 == #o2 and o1[#o1][1] == o2[#o2][1], "octree deterministic") end --- bad arguments never throw do t:eq(#Quantize.palette(nil :: any, 1, 1, 4), 0, "nil pixels") t:eq(#Quantize.palette(buffer.create(3), 1, 1, 4), 0, "short buffer") diff --git a/tests/codecs/raster.luau b/tests/codecs/raster.luau index 4aece49..f6757cb 100644 --- a/tests/codecs/raster.luau +++ b/tests/codecs/raster.luau @@ -1,7 +1,5 @@ --- codecs/image/Raster tests: exact coverage of axis-aligned rectangles at fractional positions; areas of circles; random --- polygons and curves under random transforms against an independent 12 x 12 supersampled winding-number reference --- (both fill rules); clipping, the stroker (width, caps, joins against analytic areas), fill() compositing and paint --- functions; malformed paths never throw. Glyph rendering against FreeType is in tests/font/ttf.luau. +-- codecs/image/Raster tests: coverage against a 12 x 12 supersampled winding reference, the stroker, fill(). +-- Glyph rendering against FreeType is in tests/font/ttf.luau. local T = require("@tests/T") local R = require("@rosetta/codecs/image/Raster") local Types = require("@rosetta/Types") @@ -27,7 +25,6 @@ local function at(m: any, x: number, y: number): number return buffer.readu8(m.coverage, j * m.width + i) end --- 1. rectangles: exact per-pixel coverage do local p = R.path():rect(1.25, 2.5, 3.5, 2) local m = R.mask(p) :: any @@ -54,7 +51,7 @@ for _, r in { 3, 10.5, 40 } do t:check(math.abs(a - math.pi * r * r) < 0.01 * math.pi * r * r + 1, string.format("circle r=%g area %.2f", r, a)) end --- 3. random paths against a supersampled winding reference +-- random paths against a supersampled winding reference local function wind(polys: { { number } }, px: number, py: number): number local w = 0 for _, poly in polys do @@ -143,7 +140,6 @@ do t:check(math.abs(sum(R.mask(q)) - 84) < 0.01, "nonzero hole with opposite winding") end --- 5. clipping: a shape larger than the clip, partly outside on every side do local m = R.mask(R.path():rect(-20.5, -3.25, 100, 50), { clip = { 0, 0, 16, 8 } }) :: any t:check(m and m.x == 0 and m.y == 0 and m.width == 16 and m.height == 8, "clipped bounds") @@ -178,7 +174,6 @@ do t:check(math.abs(a - 2 * math.pi * 10) < 1, "circle outline " .. a) end --- 7. fill onto an image: colours, opacity, paint functions, compositing over existing pixels do local img = Types.Image.new(8, 8) t:check(R.fill(img, R.path():rect(0, 0, 4, 8), { 255, 0, 0, 255 }), "fill red") @@ -208,7 +203,6 @@ do end) == false, "a failing paint function returns false") end --- 8. malformed paths and huge / non-finite coordinates never throw do local bad: { any } = { { { op = "moveTo" }, { op = "lineTo", 1 }, { op = "quadTo", 1, 2, "x", 4 }, { op = "close" } }, diff --git a/tests/codecs/resample.luau b/tests/codecs/resample.luau index 229c04b..5412cba 100644 --- a/tests/codecs/resample.luau +++ b/tests/codecs/resample.luau @@ -1,6 +1,4 @@ --- codecs/audio/Resample tests: sines through common rate pairs (44100 <-> 48000, 8000 -> 48000, 48000 -> 22050, an inexact --- ratio) against the analytic signal, alias rejection when downsampling, output lengths, streaming in odd chunks = --- the whole-buffer result, multichannel, a Pcm source wrapper, bad arguments, and a no-throw pass over garbage. +-- codecs/audio/Resample tests: sines against the analytic signal, alias rejection, streaming, a Pcm source. local T = require("@tests/T") local Resample = require("@rosetta/codecs/audio/Resample") local Pcm = require("@rosetta/codecs/audio/Pcm") @@ -19,7 +17,6 @@ local function sine(frames: number, ch: number, rate: number, freqs: { number }) return b end --- snr(out, frames, ch, rate, freqs, skip) -> dB of the analytic sine against the error, away from the edges local function snr(b: buffer, frames: number, ch: number, rate: number, freqs: { number }, skip: number): number local sig, err = 0, 0 for i = skip, frames - 1 - skip do @@ -42,7 +39,6 @@ local function rms(b: buffer, frames: number, skip: number): number return math.sqrt(s / math.max(1, frames - 2 * skip)) end --- 1. accuracy on in-band sines for _, c in { { 44100, 48000, 1000, "medium", 80 }, { 48000, 44100, 3000, "medium", 80 }, { 8000, 48000, 440, "medium", 80 }, { 48000, 22050, 5000, "high", 90 }, { 44100, 48000, 1000, "low", 55 }, { 44100, 47999, 1000, "medium", 75 } } do local from, to, f, q, want = c[1], c[2], c[3], c[4], c[5] local n = from // 4 @@ -65,7 +61,7 @@ do t:check(level < 1e-3, string.format("alias rejection: %.2e", level)) end --- 3. streaming in odd chunk sizes gives the whole-buffer result; stereo channels stay apart +-- streaming in odd chunk sizes gives the whole-buffer result; stereo channels stay apart do local n, ch = 10007, 2 local src = sine(n, ch, 44100, { 700, 1900 }) @@ -92,7 +88,6 @@ do t:check(snr(got, gf, ch, 48000, { 700, 1900 }, 500) > 80, "stereo accuracy") end --- 4. a codecs/audio/Pcm source at a new rate do local a = Types.Audio.new(22050, 1, 5000) a.samples = sine(5000, 1, 22050, { 500 }) @@ -103,7 +98,6 @@ do t:check(col and snr(col.samples, col.frames, 1, 32000, { 500 }, 300) > 80, "source accuracy") end --- 5. identity, empty input, bad arguments do local src = sine(1000, 1, 48000, { 1000 }) local out = Resample.buffer(src, 1000, 1, 48000, 48000) @@ -116,7 +110,6 @@ do t:check(Resample.buffer(buffer.create(4), 10, 1, 44100, 48000) == nil, "short buffer") end --- 6. no throw on garbage (NaN / Inf samples, odd lengths, chunk sizes) local samples = {} for i = 1, 4 do table.insert(samples, buffer.tostring(sine(100 * i, 1, 8000, { 300 }))) diff --git a/tests/codecs/rig.luau b/tests/codecs/rig.luau index e86a72c..c203d24 100644 --- a/tests/codecs/rig.luau +++ b/tests/codecs/rig.luau @@ -1,6 +1,4 @@ --- codecs/model/Rig tests: morph targets and weights animations from frames, skeletons in local and world space --- (node TRS, inverse bind matrices against Mat4), influences (top four, normalised), joint TRS animations; and --- Pixels.palette. +-- codecs/model/Rig tests: morph targets, skeletons (inverse bind matrices against Mat4), influences, Pixels.palette. local T = require("@tests/T") local Rig = require("@rosetta/codecs/model/Rig") local Mat4 = require("@rosetta/codecs/model/Mat4") @@ -21,7 +19,6 @@ local function near(a: number, b: number): boolean return math.abs(a - b) < 1e-5 end --- morph do local base = { 0, 0, 0, 1, 0, 0 } local prim: Types.Primitive = { attributes = { POSITION = Scene.accessor(f32s(base), "f32", 3, 2) }, mode = "points" } @@ -44,7 +41,6 @@ do t:eq(buffer.readf32(ch.output.data, (3 + 2) * 4), 1, "key 2 -> target 3") end --- skeleton do local q = Mat4.axisAngle(0, 0, 1, 90) local joints = { @@ -81,7 +77,6 @@ do t:eq(s.animations[ai].channels[1].node, nodes[2], "channel node") end --- palette do local pal = Pixels.palette(buffer.fromstring("\1\2\3\4\5\6"), 0, 2) t:eq(buffer.readu32(pal, 4), 0xFF060504, "rgb triples") diff --git a/tests/codecs/sampler.luau b/tests/codecs/sampler.luau index 6d66433..ef28e08 100644 --- a/tests/codecs/sampler.luau +++ b/tests/codecs/sampler.luau @@ -1,6 +1,4 @@ --- codecs/model/Sampler tests: STEP / LINEAR / CUBICSPLINE channels (glTF's Hermite definition), quaternion slerp --- (shortest path, unit length), clamping outside the keys, weights channels, Sampler.times and Sampler.pose; glTF's --- InterpolationTest sample model (every interpolation) sampled at its keys gives the key values; bad channels. +-- codecs/model/Sampler tests: STEP / LINEAR / CUBICSPLINE (glTF's Hermite definition), slerp, InterpolationTest. local T = require("@tests/T") local Sampler = require("@rosetta/codecs/model/Sampler") local Gltf = require("@rosetta/model/gltf") diff --git a/tests/codecs/theora.luau b/tests/codecs/theora.luau index c928965..3bee30c 100644 --- a/tests/codecs/theora.luau +++ b/tests/codecs/theora.luau @@ -1,11 +1,5 @@ --- codecs/video/Theora tests. Against ffmpeg (tools/fixtures/theora.py, its vp3 decoder = libtheora's output): every --- frame of every stream, bit-exact (Adler-32 of the native planes of the picture region, as ffmpeg's framecrc): 4:2:0 / --- 4:2:2 / 4:4:4, qualities 0..10, a 300 kbit/s high-motion stream (4MV, golden frames, multiple qi), picture regions --- smaller than the coded frame (even sizes from the encoder, odd sizes at offsets patched into the header), frames --- the encoder dropped (empty packets: ffmpeg outputs nothing, we repeat the previous picture) and one spliced in; --- image() as yuv420p (4:2:2 / 4:4:4 chroma averaged); Theora in Matroska through the codecs/video/Video registry. --- Errors: missing / bad headers, maxPixels, header packets in the data, garbage packets; the fuzz no-throw passes --- (headers, key and inter frames). +-- codecs/video/Theora tests: every frame bit-exact against ffmpeg's vp3 decoder (Adler-32 of planes, as framecrc). +-- Fixtures: tools/fixtures/theora.py. local T = require("@tests/T") local Theora = require("@rosetta/codecs/video/Theora") local Video = require("@rosetta/codecs/video/Video") @@ -33,7 +27,6 @@ local FIXTURES: { [string]: any } = { crop422 = require("@tests/gen/theora_crop422"), } --- the Theora packets of an Ogg file: headers, data packets local function packets(file: buffer): ({ buffer }, { buffer }) local d = Ogg.open(file) local serial = d:find("theora") @@ -58,7 +51,6 @@ end local samples: { buffer } = {} local headerSets: { { buffer } } = {} --- 1. every fixture, every frame for _, name in CASES do local fx = FIXTURES[name] local hdrs, data = packets(Base64.decode(fx.file) :: buffer) @@ -126,7 +118,6 @@ do t:eq(bad, 0, "dupe: the other frames") end --- 3. image(): yuv420p, the planes as they are (4:2:0) or averaged (4:2:2 / 4:4:4) for _, name in { "q6", "crop", "yuv422", "crop422", "odd444" } do local fx = FIXTURES[name] local hdrs, data = packets(Base64.decode(fx.file) :: buffer) @@ -164,7 +155,7 @@ for _, name in { "q6", "crop", "yuv422", "crop422", "odd444" } do t:eq(img.meta.yuv and img.meta.yuv.matrix, "bt601", name .. ": colour matrix") end --- 4. Theora in Matroska: the registry entry (V_THEORA, Xiph-laced CodecPrivate) through video/mkv +-- Theora in Matroska: the registry entry (V_THEORA, Xiph-laced CodecPrivate) through video/mkv do t:eq(Video.fromMatroska("V_THEORA"), "theora", "registry: V_THEORA") t:check(Video.canDecode("theora"), "registry: theora decodes") @@ -199,7 +190,6 @@ do end end --- 5. API details and errors do local fx = FIXTURES.q6 local hdrs, data = packets(Base64.decode(fx.file) :: buffer) @@ -261,7 +251,7 @@ do t:check(nv == nil and nerr ~= nil, "newVideoDecoder without config") end --- 6. fuzz: headers, keyframes and inter frames (a decoder primed with a keyframe, fed mutated packets) +-- fuzz: a decoder primed with a keyframe, fed mutated packets do local hdrs = headerSets[1] t:fuzz("headers", function(b: buffer) diff --git a/tests/codecs/unixcompress.luau b/tests/codecs/unixcompress.luau index 916d796..8e35af3 100644 --- a/tests/codecs/unixcompress.luau +++ b/tests/codecs/unixcompress.luau @@ -1,6 +1,5 @@ --- codecs/compress/UnixCompress tests: ncompress 5.0 files (widths 10..16, block mode, CLEAR codes after the ratio --- check, empty / one-byte / random inputs) decode to their inputs; compress() gives ncompress's bytes for the same input --- and width; non-block-mode streams; errors; the fuzz pass. Fixtures: tools/fixtures/z.py. +-- codecs/compress/UnixCompress tests: ncompress 5.0 files decode, compress() gives ncompress's bytes, errors. +-- Fixtures: tools/fixtures/z.py. local T = require("@tests/T") local UnixCompress = require("@rosetta/codecs/compress/UnixCompress") local Crc32 = require("@rosetta/core/Crc32") @@ -45,7 +44,6 @@ do t:eq(out and buffer.tostring(out), "ABABABA", "non-block mode") end --- errors do local _, e1 = UnixCompress.decompress("\31\157") t:check(e1 and e1.code == Err.TRUNCATED, "short header") diff --git a/tests/codecs/url.luau b/tests/codecs/url.luau index 20b5345..a1106b7 100644 --- a/tests/codecs/url.luau +++ b/tests/codecs/url.luau @@ -1,7 +1,5 @@ --- codecs/text/Url + codecs/text/Text tests: every example of RFC 3986 section 5.4 (normal and abnormal), dot-segment removal, --- splitting, encoding and the location helpers (ported from playlist-luau tests/url.luau); random references against --- Python's urllib.parse.urljoin; Url.locate / Url.base; Windows-1252 decoding against Python's cp1252 codec; lines, --- BOM, trim; the fuzz pass. Fixtures: tools/fixtures/playlist.py. +-- codecs/text/Url + Text tests: RFC 3986 5.4 examples, urljoin against Python's urllib, cp1252 against Python. +-- Fixtures: tools/fixtures/playlist.py. local T = require("@tests/T") local Url = require("@rosetta/codecs/text/Url") local Text = require("@rosetta/codecs/text/Text") @@ -62,13 +60,11 @@ eq(Url.scheme("HTTPS://x"), "https", "scheme lower-cased") eq(Url.scheme("music/a.mp3"), nil, "relative has no scheme") --- Python's urljoin for _, c in Ref do eq(Url.resolve(c[1], c[2]), c[3], "urljoin " .. c[1] .. " against " .. c[2]) end t:note("%d random references resolve as urllib.parse.urljoin", #Ref) --- locate / base do local w = {} local base, scheme = Url.base("https://h/a/list.m3u", w) @@ -82,7 +78,6 @@ do t:check(select(2, Url.base("C:\\Music\\l.m3u")) == "windows", "windows base") end --- Text do for _, c in Cp do eq(Text.toUtf8("x" .. string.char(c[1]) .. "y"), "x" .. c[2] .. "y", string.format("cp1252 0x%02x", c[1])) diff --git a/tests/codecs/vp8.luau b/tests/codecs/vp8.luau index 7ba6a3b..80bc411 100644 --- a/tests/codecs/vp8.luau +++ b/tests/codecs/vp8.luau @@ -1,7 +1,5 @@ --- codecs/image/Vp8 tests: the VP8 key frames of the WebP fixtures (cwebp at many settings and libvpx through ffmpeg, with --- 1..8 token partitions) decoded through the codec API: the yuv420p planes against dwebp -yuv, toRgba against --- dwebp -pam (fancy upsampling) and -nofancy, the decoder object over successive frames, headers, error codes and the --- fuzz no-throw pass on raw frames. Fixtures: tools/fixtures/webp.py. +-- codecs/image/Vp8 tests: WebP key frames: yuv420p against dwebp -yuv, toRgba against dwebp -pam and -nofancy. +-- Fixtures: tools/fixtures/webp.py. local T = require("@tests/T") local Vp8 = require("@rosetta/codecs/image/Vp8") local Crc32 = require("@rosetta/core/Crc32") @@ -50,7 +48,6 @@ for _, c in Cases do end t:note("%d VP8 key frames (%d from libvpx) match dwebp: planes, fancy and point upsampling", n, vpx) --- errors do local f = buffer.fromstring(frames[1]) local inter = buffer.fromstring(frames[1]) @@ -69,7 +66,6 @@ do t:check(e5 and e5.code == Err.ARG, "toRgba of a non-yuv image") end --- fuzz on raw frames t:fuzz("decodeFrame", function(b: buffer) return Vp8.decodeFrame(b, 0, buffer.len(b), { maxPixels = 2 ^ 20 }) end, frames, { mutations = 12, keepHeader = 10 }) diff --git a/tests/codecs/vp8l.luau b/tests/codecs/vp8l.luau index 2084a20..b032ba9 100644 --- a/tests/codecs/vp8l.luau +++ b/tests/codecs/vp8l.luau @@ -1,6 +1,4 @@ --- codecs/image/Vp8L tests: the VP8L bitstreams of the WebP fixtures (cwebp -z 0..9, -exact, near-lossless) decoded through --- the codec API against dwebp, the encoder at every effort on generated images (gradients, noise, palettes of 1..300 --- colours, odd sizes, alpha), headerless alpha streams, error codes, and the fuzz no-throw pass on raw bitstreams. +-- codecs/image/Vp8L tests: the WebP fixtures' VP8L (cwebp -z 0..9, -exact, near-lossless) against dwebp, the encoder. -- Fixtures: tools/fixtures/webp.py. local T = require("@tests/T") local Vp8L = require("@rosetta/codecs/image/Vp8L") @@ -10,7 +8,6 @@ local Cases = require("@tests/gen/webp_cases") local t = T.suite("vp8l") --- the VP8L chunk of a simple-format file local function chunk(data: string): (buffer?, number, number) if string.sub(data, 13, 16) ~= "VP8L" then return nil, 0, 0 @@ -40,7 +37,6 @@ for _, c in Cases do end t:note("%d VP8L bitstreams match dwebp", n) --- the encoder: round trips at every effort local rand = T.rng(5) local function gen(w: number, h: number, kind: string): buffer local px = buffer.create(w * h * 4) @@ -92,7 +88,6 @@ for _, kind in { "grad", "alpha", "noise", "pal1", "pal4", "pal40", "pal300" } d end t:note("%d encoder round trips", count) --- errors do local _, e1 = Vp8L.decode(buffer.fromstring("\x2e\0\0\0\0")) t:check(e1 and e1.code == Err.CORRUPT, "bad signature: " .. tostring(e1)) @@ -109,7 +104,6 @@ do t:check(e6 and e6.code == Err.ARG, "encode: short pixel buffer") end --- fuzz on raw bitstreams t:fuzz("decode", function(b: buffer) return Vp8L.decode(b, 0, buffer.len(b), 2 ^ 20) end, streams, { mutations = 10, keepHeader = 5 }) diff --git a/tests/codecs/vp8video.luau b/tests/codecs/vp8video.luau index 2ef1db9..5c3416f 100644 --- a/tests/codecs/vp8video.luau +++ b/tests/codecs/vp8video.luau @@ -1,8 +1,4 @@ --- codecs/image/Vp8 video tests: whole IVF streams through one decoder object, every shown frame bit-exact against ffmpeg's --- native vp8 decoder (yuv420p CRC32): the official VP8 test vectors (vp80-00-comprehensive-001..018 and others) and --- libvpx clips at many settings (alt-ref / hidden frames, golden, token partitions, error resilience, profiles 1-3, --- sharpness, segmentation, q extremes, short key frame intervals, motion off the frame, odd sizes). Also hidden --- frames, reset() and inter frames without a key frame, and the fuzz no-throw pass over damaged streams. +-- codecs/image/Vp8 video tests: VP8 test vectors and libvpx IVF clips bit-exact against ffmpeg's vp8 (yuv420p CRC32). -- Fixtures: tools/fixtures/vp8video.py. local T = require("@tests/T") local Vp8 = require("@rosetta/codecs/image/Vp8") @@ -12,7 +8,6 @@ local Cases = require("@tests/gen/vp8video_cases") local t = T.suite("vp8video") --- the frames of an IVF file: { offset, length } local function ivfFrames(b: buffer): { { number } } local out = {} local p = buffer.readu16(b, 6) -- header length (32) @@ -110,7 +105,6 @@ do t:check(e3 and e3.code == Err.TRUNCATED, "truncated frame tag: " .. tostring(e3)) end --- fuzz: whole damaged streams through one decoder (truncated / mutated frames after valid ones) local function feed(b: buffer) local dec = Vp8.newDecoder() local any = false diff --git a/tests/codecs/vrml.luau b/tests/codecs/vrml.luau index 0cb4f31..6f042c8 100644 --- a/tests/codecs/vrml.luau +++ b/tests/codecs/vrml.luau @@ -1,7 +1,4 @@ --- codecs/model/Vrml tests: the classic-encoding lexer and parser (comments, commas, string escapes, hex / exponent --- numbers, DEF / USE, PROTO with IS fields, nested PROTOs and ROUTEs in bodies, EXTERNPROTO, Script interfaces, --- IMPORT / EXPORT, the X3D header statements), the XML encoding's adapter (containerField, ProtoDeclare / --- ProtoInstance, IS / connect), typed field reads of raw XML attributes, detection, errors, the fuzz pass. +-- codecs/model/Vrml tests: the classic-encoding lexer and parser, the XML encoding's adapter, detection, errors. local T = require("@tests/T") local Vrml = require("@rosetta/codecs/model/Vrml") local Fields = require("@rosetta/codecs/model/Vrml/Fields") @@ -9,7 +6,6 @@ local Err = require("@rosetta/core/Err") local t = T.suite("vrml codec") --- ------------------------------------------------------------------------------------------------ lexer / parser do local g = assert(Vrml.parse([[#VRML V2.0 utf8 # a comment, then commas as blanks @@ -81,7 +77,6 @@ do t:eq(s.meta.unit, 0.3048, "UNIT length -> meta.unit") end --- ------------------------------------------------------------------------------------------------ XML adapter do local g = assert(Vrml.graph([[ @@ -111,7 +106,6 @@ do t:eq(Fields.strs(single, "url")[1], "plain name.png", "unquoted single MFString") end --- ------------------------------------------------------------------------------------------------ errors do local function code(text: string): string? local _, e = Vrml.graph(text) @@ -129,7 +123,6 @@ do t:eq(e and e.code, Err.ARG, "encode junk") end --- ------------------------------------------------------------------------------------------------ fuzz do local samples = { "#VRML V2.0 utf8\nPROTO P [ field SFFloat a 1 ] { Box { size IS a IS a } }\nDEF X P { a 2 } USE X ROUTE X.a TO X.b\n", diff --git a/tests/codecs/xml.luau b/tests/codecs/xml.luau index 69fd59e..65d688e 100644 --- a/tests/codecs/xml.luau +++ b/tests/codecs/xml.luau @@ -1,6 +1,4 @@ --- codecs/text/Xml tests: random documents (namespaces, escapes, CDATA, comments, PIs, DOCTYPE entities, UTF-16, Latin-1) --- against Python's ElementTree trees; encode -> decode round trips; well-formedness verdicts against expat --- (hand-written cases and random mutations); events, helpers, options, error codes; the fuzz pass. +-- codecs/text/Xml tests: random documents against Python's ElementTree, well-formedness against expat, the API. -- Fixtures: tools/fixtures/xml.py. local T = require("@tests/T") local Xml = require("@rosetta/codecs/text/Xml") @@ -53,7 +51,6 @@ local function canon(e: any, tail: string?): string return table.concat(out) .. ")t" .. s(tail) end --- 1. documents vs ElementTree, and round trips for i, d in Docs do local doc, err = Xml.decode(d.data, { whitespace = true }) t:check(doc, "doc " .. i .. ": " .. tostring(err)) @@ -74,7 +71,6 @@ for i, d in Docs do t:eq(root.ns, want, "doc " .. i .. ": node.ns") end --- 2. well-formedness against expat local agree, total, accepted, rejected = 0, 0, 0, 0 for i, c in Wf do local doc = Xml.decode(c.data) @@ -94,7 +90,6 @@ end t:note("well-formedness: %d of %d verdicts agree with expat (%d well-formed, %d not)", agree, total, accepted, rejected) t:check(agree >= total * 0.99, "well-formedness agreement >= 99%") --- 3. API details do local src = '\n]>\nt]]>u\n' local doc = Xml.decode(src, { comments = true, cdata = true, pi = true, namespaces = true }) :: any @@ -130,7 +125,6 @@ do local n = Xml.decode("l1\r\nl2\rl3") :: any t:eq(n.root.attrs.b, "x y z\n", "attribute value normalization") t:eq(Xml.text(n.root), "l1\nl2\nl3", "line endings") - -- builders and encode local e = Xml.element("svg", { width = "10", height = "5" }, { Xml.element("rect", { x = "1" }), "aa<b & "c"', "encode element") @@ -144,7 +138,6 @@ do local _, ce = Xml.encode(cyc) t:eq(ce and ce.code, Err.ARG, "cycle on encode") t:eq(Xml.encode({ name = "#cdata", attrs = Types.object(), children = {}, text = "a]]>b" } :: any), "b]]>", "cdata split") - -- events local evs = {} for ev, a in Xml.events("t") do table.insert(evs, ev .. (if type(a) == "string" then ":" .. a else "")) @@ -166,7 +159,6 @@ do t:eq(ue and ue.code, Err.UNSUPPORTED, "unsupported encoding") end --- 4. errors and limits local function code(src: string, opts: any?): string? local _, e = Xml.decode(src, opts) return e and e.code @@ -182,7 +174,6 @@ t:eq(code("", { namespaces = true }), Err.CORRUPT, "undeclared prefix") local _, ae = Xml.decode(5 :: any) t:eq(ae and ae.code, Err.ARG, "bad argument") --- 5. fuzz local samples = {} for i = 1, 40 do table.insert(samples, Docs[i].data) diff --git a/tests/codecs/yuv.luau b/tests/codecs/yuv.luau index 8b2d258..4036487 100644 --- a/tests/codecs/yuv.luau +++ b/tests/codecs/yuv.luau @@ -1,5 +1,4 @@ --- codecs/image/Yuv tests: scale (yuv420p planes resized bilinear: flat planes stay flat, a horizontal ramp stays a --- monotonic ramp, output sizes with odd dimensions, identity size, short input), imageScale, and a toRgba round trip. +-- codecs/image/Yuv tests: scale (bilinear yuv420p), imageScale, and a toRgba round trip. local T = require("@tests/T") local Yuv = require("@rosetta/codecs/image/Yuv") local Types = require("@rosetta/Types") @@ -48,7 +47,6 @@ for _, c in { { 64, 48, 32, 24 }, { 800, 600, 480, 360 }, { 33, 17, 13, 9 }, { 2 t:check(buffer.readu8(out, 0) <= 16 and buffer.readu8(out, dw - 1) >= 239, label .. ": ramp ends") end --- the same size copies local src = picture(20, 20) t:eq(buffer.tostring(Yuv.scale(src, 20, 20, 20, 20)), buffer.tostring(src), "identity") -- a short source gives a zero picture of the right size, no throw diff --git a/tests/codecs/zstd.luau b/tests/codecs/zstd.luau index 343aed3..b320d8b 100644 --- a/tests/codecs/zstd.luau +++ b/tests/codecs/zstd.luau @@ -1,7 +1,5 @@ --- codecs/compress/Zstd tests: every fixture case (the zstd CLI at levels 1..19, --ultra -22, --fast, --long, small windows, --- with / without checksum and content size, multi-frame and skippable frames, empty input) decodes to its corpus; --- offsets / consumedEnd; XXH64 vectors; checksum, limit and error codes; truncated / corrupted / random input never --- throws. Fixtures: tools/fixtures/zstd.py. +-- codecs/compress/Zstd tests: zstd CLI frames (levels 1..19, --ultra -22, --fast, --long) decode, XXH64, errors. +-- Fixtures: tools/fixtures/zstd.py. local T = require("@tests/T") local Zstd = require("@rosetta/codecs/compress/Zstd") local Err = require("@rosetta/core/Err") @@ -22,7 +20,6 @@ do t:eq(hex(string.rep("0123456789", 10)), "f80e7b96315afffa", "xxh64 100 bytes") end --- every case decodes to its corpus local nbytes = 0 for _, c in Fx.cases do local want = Fx.corpora[c.corpus] @@ -44,7 +41,6 @@ local function case(name: string): any error("no case " .. name) end --- at an offset inside a bigger buffer, and string input do local c = case("text/l3") local big = buffer.create(#c.data + 20) @@ -73,7 +69,6 @@ do t:check(out2 and buffer.tostring(out2) == Fx.corpora.text, "verify = false") end --- limits and arguments do local c = case("text/l3") local _, e = Zstd.decompress(c.data, nil, nil, { maxBytes = 1000 }) @@ -95,7 +90,6 @@ do t:check(e6 and e6.code == Err.CORRUPT, "reserved block type: " .. tostring(e6)) end --- truncation, corruption and garbage never throw do local samples = {} for i, c in Fx.cases do From 653ce4e002cf4e860fa866e97afecd7a2f96acea Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:51:09 -0500 Subject: [PATCH 20/25] tests/archive: comments: wrap long headers --- tests/archive/wad.luau | 3 ++- tests/archive/zip.luau | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/archive/wad.luau b/tests/archive/wad.luau index fe095d9..09b232c 100644 --- a/tests/archive/wad.luau +++ b/tests/archive/wad.luau @@ -1,4 +1,5 @@ --- archive/wad tests: a cut-down Freedoom IWAD against DeuTex, map floor areas by Green's theorem (tools/fixtures/wad.py). +-- archive/wad tests: a cut-down Freedoom IWAD against DeuTex, map floor areas by Green's theorem. +-- Fixtures: tools/fixtures/wad.py. local T = require("@tests/T") local F = require("@rosetta") local Wad = require("@rosetta/archive/wad") diff --git a/tests/archive/zip.luau b/tests/archive/zip.luau index 03392c2..8bbbeff 100644 --- a/tests/archive/zip.luau +++ b/tests/archive/zip.luau @@ -1,4 +1,5 @@ --- archive/zip + containers/Zip tests against Python's zipfile (tools/fixtures/zip.py); SKINS_DIR adds the Webamp demo skins. +-- archive/zip + containers/Zip tests against Python's zipfile; SKINS_DIR adds the Webamp demo skins. +-- Fixtures: tools/fixtures/zip.py. local T = require("@tests/T") local Zip = require("@rosetta/containers/Zip") local ZipF = require("@rosetta/archive/zip") From 7672980c65b4038a75bd6af55ed6fcd5d6da36fe Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:51:09 -0500 Subject: [PATCH 21/25] tests/data: comments: specs only --- tests/data/Canon.luau | 8 +++----- tests/data/cbor.luau | 6 +----- tests/data/csv.luau | 5 +---- tests/data/ini.luau | 4 +--- tests/data/json.luau | 7 +------ tests/data/msgpack.luau | 5 +---- tests/data/nbt.luau | 7 +------ tests/data/plist.luau | 4 +--- tests/data/snbt.luau | 4 +--- tests/data/toml.luau | 13 +++---------- tests/data/xml.luau | 4 +--- tests/data/yaml.luau | 12 +----------- 12 files changed, 16 insertions(+), 63 deletions(-) diff --git a/tests/data/Canon.luau b/tests/data/Canon.luau index f6d3536..33fe797 100644 --- a/tests/data/Canon.luau +++ b/tests/data/Canon.luau @@ -1,7 +1,6 @@ --- tests/data/Canon: the canonical text of a decoded data value, the same as tools/fixtures/_data_common.py canon() on --- Python's parse: null n, true t, false f, numbers #%d (integral under 2^53) or #%.17g, strings s:, --- buffers b:, arrays [x,...], objects {k=v,...} sorted by key text, dates d. A module the data --- tests require (running it alone does nothing). +-- the canonical text of a decoded data value, the same as tools/fixtures/_data_common.py canon() on Python's parse: +-- null n, true t, false f, numbers #%d (integral under 2^53) or #%.17g, strings s:, buffers b:, +-- arrays [x,...], objects {k=v,...} sorted by key text, dates d. local Types = require("@rosetta/Types") local Canon = {} @@ -76,7 +75,6 @@ local function canon(v: any, out: { string }) end end --- of(v) -> the canonical text function Canon.of(v: any): string local out = {} canon(v, out) diff --git a/tests/data/cbor.luau b/tests/data/cbor.luau index 7fea94f..e614b88 100644 --- a/tests/data/cbor.luau +++ b/tests/data/cbor.luau @@ -1,7 +1,4 @@ --- data/cbor tests: the RFC 8949 Appendix A examples and random items encoded by Python's cbor2 decode to cbor2's --- values (canonical form), re-encode to the same bytes, big integers as doubles and exact text, indefinite lengths, --- tags / simple values / undefined, half floats, sequences, options, error codes, and the fuzz pass. --- Fixtures: tools/fixtures/cbor.py. +-- data/cbor tests: RFC 8949 Appendix A and Python's cbor2 (tools/fixtures/cbor.py). local T = require("@tests/T") local Cbor = require("@rosetta/data/cbor") local Bytes = require("@rosetta/core/Bytes") @@ -68,7 +65,6 @@ for i, c in Fx.wide do t:eq(Canon.of(plain(dec(c.data, { bigInts = "string" }))), c.canonStr, "wide " .. i .. ": exact") end --- details do local function hex(b: buffer): string return (string.gsub(buffer.tostring(b), ".", function(ch) diff --git a/tests/data/csv.luau b/tests/data/csv.luau index 7f9b229..0bfe6b4 100644 --- a/tests/data/csv.luau +++ b/tests/data/csv.luau @@ -1,6 +1,4 @@ --- data/csv tests: tables written by Python's csv.writer / DictWriter (every delimiter, quotes, line breaks inside --- fields, empty fields) read back as csv.reader does, re-encoded byte for byte, keyed rows with a header, options, --- error codes, and the fuzz pass. Fixtures: tools/fixtures/csv.py. +-- data/csv tests against Python's csv module (tools/fixtures/csv.py). local T = require("@tests/T") local F = require("@rosetta") local Csv = require("@rosetta/data/csv") @@ -41,7 +39,6 @@ for i, c in Fx do end end --- details do t:eq(Canon.of(dec("a,b\n\n1,2\r\n3,4\r5,6")), Canon.of({ { "a", "b" }, { "1", "2" }, { "3", "4" }, { "5", "6" } }), "line ends, blank lines") t:eq(Canon.of(dec('"a""b",c"d,"e"x')), Canon.of({ { 'a"b', 'c"d', "ex" } }), "lenient quotes like Python") diff --git a/tests/data/ini.luau b/tests/data/ini.luau index 67adfa1..b00f88b 100644 --- a/tests/data/ini.luau +++ b/tests/data/ini.luau @@ -1,6 +1,4 @@ --- data/ini tests: configs written by Python's configparser read back to configparser's values and re-encoded byte for --- byte, messy hand-written files read as configparser(strict = false) reads them, options (inline comments, keys --- without values, types, strict), top-level keys, error codes, and the fuzz pass. Fixtures: tools/fixtures/ini.py. +-- data/ini tests against Python's configparser (tools/fixtures/ini.py). local T = require("@tests/T") local Ini = require("@rosetta/data/ini") local Bytes = require("@rosetta/core/Bytes") diff --git a/tests/data/json.luau b/tests/data/json.luau index 493341d..d286694 100644 --- a/tests/data/json.luau +++ b/tests/data/json.luau @@ -1,6 +1,4 @@ --- data/json tests: the contract, the format through the API (F.load / F.save / sniffing), JSON Lines, Python's --- json.dumps corpus through the format, and the fuzz pass. The codec itself is tested in tests/codecs/json.luau. --- Fixtures: tools/fixtures/json.py. +-- data/json format tests (the codec: tests/codecs/json.luau) against Python's json (tools/fixtures/json.py). local T = require("@tests/T") local F = require("@rosetta") local JsonF = require("@rosetta/data/json") @@ -27,7 +25,6 @@ for i, c in Corpus do t:eq(buffer.tostring(b), c.pretty .. "\n", "corpus " .. i .. ": encode") end --- through the API: sniffed, by name, saved do local v, err = F.load(buffer.fromstring('{"a": [1, 2], "b": null}')) t:check(v ~= nil, "F.load sniffs json: " .. tostring(err)) @@ -40,7 +37,6 @@ do t:eq(back.y[1], true, "F.data.load") end --- JSON Lines do local v = dec('{"a":1}\n{"a":2}\n\n[3]\n', { lines = true }) t:eq(#v, 3, "lines decode count") @@ -51,7 +47,6 @@ do t:eq(e and e.code, Err.TRUNCATED, "lines error") end --- reader range: the data inside a bigger buffer do local big = buffer.fromstring("xx[1,2,3]yy") local v = JsonF.decode(Bytes.reader(big, 2, 7)) diff --git a/tests/data/msgpack.luau b/tests/data/msgpack.luau index 536806c..b3354b9 100644 --- a/tests/data/msgpack.luau +++ b/tests/data/msgpack.luau @@ -1,6 +1,4 @@ --- data/msgpack tests: values packed by Python's msgpack decode to msgpack's own values (canonical form), re-encode to --- the same bytes, 64-bit integers as doubles and as exact strings, timestamps / ext, streams, options, error codes, --- and the fuzz pass. Fixtures: tools/fixtures/msgpack.py. +-- data/msgpack tests against Python's msgpack (tools/fixtures/msgpack.py). local T = require("@tests/T") local Mp = require("@rosetta/data/msgpack") local Bytes = require("@rosetta/core/Bytes") @@ -49,7 +47,6 @@ for i, c in Fx.wide do t:eq(Canon.of(plain(dec(Mp.encode(v) :: buffer))), c.canon, "wide " .. i .. ": round trip") end --- details do t:eq(Mp.isExt(dec("\xd4\x05\x07")), true, "fixext1") local d = dec("\xd6\xff\x00\x00\x00\x00") diff --git a/tests/data/nbt.luau b/tests/data/nbt.luau index 7d3df0a..31f192b 100644 --- a/tests/data/nbt.luau +++ b/tests/data/nbt.luau @@ -1,7 +1,4 @@ --- data/nbt tests: the contract, nbtlib files through the api (F.load / F.save, NBT -> SNBT -> NBT), detection by --- content and extension, exact round trips (root name, edition, compression and the Bedrock header kept), error --- codes, and the fuzz pass. The engine itself: tests/codecs/nbt.luau; SNBT files: tests/data/snbt.luau. --- Fixtures: tools/fixtures/nbt.py. +-- data/nbt format tests (the engine: tests/codecs/nbt.luau) against nbtlib (tools/fixtures/nbt.py). local T = require("@tests/T") local F = require("@rosetta") local NbtF = require("@rosetta/data/nbt") @@ -34,14 +31,12 @@ for i = 1, 12 do t:eq(buffer.tostring(assert(F.save(le, nil, { format = "nbt" })) :: buffer), c.header, c.name .. ": Bedrock level.dat same bytes") end --- detection do local c = Fx.cases[3] t:eq(F.detect(c.gzip, { name = "level.dat" }), "nbt", "detect gzip .dat") t:eq(F.detect(c.raw, { name = "x.nbt" }), "nbt", "detect raw .nbt") end --- errors do local _, e = NbtF.decode(Bytes.reader(buffer.fromstring("\10\0\0\1"))) t:check(e and e.code == Err.TRUNCATED, "truncated") diff --git a/tests/data/plist.luau b/tests/data/plist.luau index d39e211..108d838 100644 --- a/tests/data/plist.luau +++ b/tests/data/plist.luau @@ -1,6 +1,4 @@ --- data/plist tests: values written by Python's plistlib as XML and binary decode to plistlib's values; our XML writer --- reproduces plistlib's XML byte for byte; binary-only values (UIDs, 64-bit integers); a hand-written XML plist; --- error codes; the fuzz pass (XML and binary). Fixtures: tools/fixtures/plist.py. +-- data/plist tests against Python's plistlib (tools/fixtures/plist.py). local T = require("@tests/T") local F = require("@rosetta") local Plist = require("@rosetta/data/plist") diff --git a/tests/data/snbt.luau b/tests/data/snbt.luau index f70ba36..150f9de 100644 --- a/tests/data/snbt.luau +++ b/tests/data/snbt.luau @@ -1,6 +1,4 @@ --- data/snbt tests: the contract, nbtlib's SNBT text (indented and compact) through the api, conversion to and from --- binary NBT (F.convert), detection against JSON, options (indent, quote), error codes, and the fuzz pass. The --- grammar itself: tests/codecs/nbt.luau. Fixtures: tools/fixtures/nbt.py. +-- data/snbt tests (the grammar: tests/codecs/nbt.luau) against nbtlib (tools/fixtures/nbt.py). local T = require("@tests/T") local F = require("@rosetta") local SnbtF = require("@rosetta/data/snbt") diff --git a/tests/data/toml.luau b/tests/data/toml.luau index a776ed1..46f75c9 100644 --- a/tests/data/toml.luau +++ b/tests/data/toml.luau @@ -1,6 +1,5 @@ --- data/toml tests: the toml-test suite's TOML 1.0 files (every valid/ case decodes to its expected value, every --- invalid/ case fails), a tomli-w corpus against Python's tomllib, encoder round trips (decode(encode(v)) is the same --- value) and exact encoder output, options, error codes, the contract and the fuzz pass. Fixtures: tools/fixtures/toml.py. +-- data/toml tests: the toml-test suite (TOML 1.0) and a tomli-w corpus against Python's tomllib. +-- Fixtures: tools/fixtures/toml.py. local T = require("@tests/T") local Toml = require("@rosetta/data/toml") local Bytes = require("@rosetta/core/Bytes") @@ -24,15 +23,13 @@ local function enc(v: any, opts: any?): (string?, any) return if b then buffer.tostring(b) else nil, e end --- 1. toml-test local nv, ni, rt = 0, 0, 0 for _, c in Suite do local v, err = dec(c.data) if c.valid then t:check(v ~= nil, c.name .. ": parses (" .. tostring(err) .. ")") t:eq(Canon.of(v), c.canon, c.name .. ": value") - -- the encoder's output reads back as the same value (floats that are integral become integers, so compare - -- the decoded values, not the toml-test canon) + -- integral floats read back as integers, so compare decoded values, not the toml-test canon local s, eerr = enc(v) t:check(s ~= nil, c.name .. ": encodes (" .. tostring(eerr) .. ")") local back, berr = dec(s :: string) @@ -47,7 +44,6 @@ for _, c in Suite do end t:note("toml-test 1.0: %d valid decoded and round-tripped, %d invalid rejected", nv, ni) --- 2. tomli-w corpus vs tomllib for i, c in Corpus do local v, err = dec(c.data) t:check(v ~= nil, "corpus " .. i .. ": " .. tostring(err)) @@ -57,7 +53,6 @@ for i, c in Corpus do t:eq(Canon.of(dec(enc(v, { inline = true }) :: string)), c.canon, "corpus " .. i .. ": inline round trip") end --- 3. API details do local v = dec('z = 1\na = 2\n[t]\ny = "x"\nb = 1979-05-27T07:32:00.5-07:00\n[[arr]]\nk = 1\n[[arr]]\nk = 2\n') t:eq(table.concat(Types.keys(v), ","), "z,a,t,arr", "key order") @@ -87,7 +82,6 @@ do t:eq(e4 and e4.code, Err.ARG, "non-string key") end --- 4. errors local function code(s: string): (string?, number?) local _, e = dec(s) return e and e.code, e and e.offset @@ -101,7 +95,6 @@ t:eq(select(2, code("x = 1\na = tru")), 10, "error offset") t:eq(Toml.sniff(Bytes.reader(buffer.fromstring("# c\n[server]\nport = 80\n"))), 0.2, "sniff") t:eq(Toml.sniff(Bytes.reader(buffer.fromstring("{\"a\": 1}"))), 0, "sniff json") --- 5. fuzz local samples = {} for _, c in Suite do if c.valid and #samples < 80 and #c.data < 400 then diff --git a/tests/data/xml.luau b/tests/data/xml.luau index 80bd017..c8fa680 100644 --- a/tests/data/xml.luau +++ b/tests/data/xml.luau @@ -1,6 +1,4 @@ --- data/xml tests: the contract, the format through the API (F.load / F.save / sniffing), documents from Python's --- ElementTree fixtures decoded and re-encoded through the format, and the fuzz pass. The codec itself is tested in --- tests/codecs/xml.luau. Fixtures: tools/fixtures/xml.py. +-- data/xml format tests (the codec: tests/codecs/xml.luau) against ElementTree (tools/fixtures/xml.py). local T = require("@tests/T") local F = require("@rosetta") local XmlF = require("@rosetta/data/xml") diff --git a/tests/data/yaml.luau b/tests/data/yaml.luau index ea28e16..ae88449 100644 --- a/tests/data/yaml.luau +++ b/tests/data/yaml.luau @@ -1,7 +1,4 @@ --- data/yaml tests: the yaml-test-suite (every case with an in.json must decode to it, every error case must be --- rejected, the valid cases without JSON must decode), a random corpus dumped by PyYAML in five styles (block, flow, --- indent 4 with explicit markers, sorted / narrow, multi-document) compared with Python's values, encoder round trips, --- options, errors and limits, the API, and the fuzz pass. Fixtures: tools/fixtures/yaml.py. +-- data/yaml tests: the yaml-test-suite and a PyYAML corpus against Python's values (tools/fixtures/yaml.py). local T = require("@tests/T") local F = require("@rosetta") local Yaml = require("@rosetta/data/yaml") @@ -27,7 +24,6 @@ local function enc(v: any, opts: any?): string? return if b then buffer.tostring(b) else nil end --- 1. yaml-test-suite local SKIP = { -- !!binary decodes to a buffer; the suite's JSON keeps the base64 text ["565N"] = true, ["name/construct-binary"] = true, @@ -62,7 +58,6 @@ end t:note("yaml-test-suite: %d of %d JSON cases match, %d of %d error cases rejected, %d of %d other valid cases decode or say UNSUPPORTED", pass, valid, rejected, errors, otherOk, other) t:check(otherOk == other, "valid cases without JSON never fail as CORRUPT") --- 2. PyYAML's output in five styles for i, c in Corpus do for style, text in c.texts do if style == "multi" then @@ -75,7 +70,6 @@ for i, c in Corpus do t:eq(Canon.of(v), c.canon, "corpus " .. i .. " " .. style) end end - -- our own output reads back the same (indent 2 and 4, explicit start) local v = dec(c.texts.block) for _, o in { {}, { indent = 4 }, { explicitStart = true } } do local s = enc(v, o) @@ -86,7 +80,6 @@ for i, c in Corpus do t:eq(Canon.of(dec(enc(m, { all = true }) :: string, { all = true })), c.multi, "corpus " .. i .. ": multi round trip") end --- 3. details do local v = dec("b: 1\na: 2\nc: {}\nd: []\ne:\nf: ~\n") t:eq(table.concat(Types.keys(v), ","), "b,a,c,d,e,f", "key order") @@ -127,7 +120,6 @@ do t:eq(dec("k: |\n a\n b\n\nz: >+\n f\n g\n\n").z, "f g\n\n", "folded keep") t:eq(dec("? a\n: b\n").a, "b", "explicit key") t:eq(dec("[a: 1, {b: 2}]")[1].a, 1, "single-pair flow mapping") - -- strings that need quoting survive for _, str in { "", "true", "null", "12", "1.5", "- x", "a: b", "# c", "x #y", " lead", "tail ", "multi\nline", "two\n\n", "\ttab", "é", "\0\1", "'", '"', "yes", "on", "~", "[", "@", "&a", "*a", "!t", "%", "---", "...", "a\u{2028}b", ".inf", "0x10", "0o7", "-", "?", ":" } do local v2 = dec(enc({ k = str }) :: string) t:eq(v2 and v2.k, str, "string round trip " .. string.format("%q", str)) @@ -144,7 +136,6 @@ do t:eq(enc(buffer.fromstring("hi")), "!!binary aGk=\n", "buffers as !!binary") end --- 4. errors and limits local function code(s: string, opts: any?): string? local _, e = dec(s, opts) return e and e.code @@ -170,7 +161,6 @@ do t:eq(e and e.offset, 12, "error offset") end --- 5. API do local v, err = F.load(buffer.fromstring("---\nname: x\nlist:\n - 1\n")) t:check(v ~= nil, "F.load sniffs yaml: " .. tostring(err)) From 9d80ee11b96b2ce4c73822c1613e2165a91e7c59 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:51:09 -0500 Subject: [PATCH 22/25] tests/font: comments: specs only --- tests/font/_bitmap.luau | 4 +--- tests/font/bdf.luau | 7 +------ tests/font/bmfont.luau | 13 ++----------- tests/font/eot.luau | 6 +----- tests/font/fon.luau | 4 +--- tests/font/hershey.luau | 4 +--- tests/font/pcf.luau | 6 +----- tests/font/psf.luau | 7 +------ tests/font/ttf.luau | 13 ++----------- tests/font/type1.luau | 7 +------ tests/font/woff.luau | 6 +----- tests/font/woff2.luau | 7 ++----- 12 files changed, 15 insertions(+), 69 deletions(-) diff --git a/tests/font/_bitmap.luau b/tests/font/_bitmap.luau index aa7d3e5..02f16fe 100644 --- a/tests/font/_bitmap.luau +++ b/tests/font/_bitmap.luau @@ -1,6 +1,4 @@ --- shared by the bitmap font tests: compare(t, font, ref, label) checks every glyph FreeType rendered (code point, --- bitmap size, left / top offsets, advance, pixels) against font:rasterize(font:glyphIndex(cp)) (by the font's own --- codes when FreeType had no Unicode charmap). +-- shared by the bitmap font tests: every glyph FreeType rendered against font:rasterize. local B = {} function B.compare(t: any, font: any, ref: any, label: string) diff --git a/tests/font/bdf.luau b/tests/font/bdf.luau index 792bd59..fd738c8 100644 --- a/tests/font/bdf.luau +++ b/tests/font/bdf.luau @@ -1,6 +1,4 @@ --- font/bdf tests: Spleen BDF fonts against FreeType's renders (bitmaps, offsets, advances), properties and metrics; our --- BDF output (of BDF, PCF and outline fonts) read back by FreeType identically (fixture step) and round-tripping; an --- outline font written as BDF; errors; the fuzz pass. Fixtures: tools/fixtures/bitmapfonts.py, tools/fixtures/fonts.py. +-- font/bdf tests: Spleen BDF fonts against FreeType's renders (tools/fixtures/bitmapfonts.py, tools/fixtures/fonts.py). local T = require("@tests/T") local F = require("@rosetta") local Bdf = require("@rosetta/font/bdf") @@ -25,7 +23,6 @@ for _, c in Fx.fonts do t:eq(font.ascent, c.ref.ascent, c.name .. ": ascent") t:eq(-font.descent, c.ref.descent, c.name .. ": descent") t:eq(font.info.family, "Spleen", c.name .. ": family") - -- round trip through our writer local out = Bdf.encode(font) :: buffer local back = Bdf.decode(Bytes.reader(out)) :: any t:check(back and #back.bitmap.glyphs == #font.bitmap.glyphs, c.name .. ": round trip glyph count") @@ -38,14 +35,12 @@ for _, c in Fx.fonts do end end --- an outline font as BDF local ttf = Ttf.decode(Bytes.reader(buffer.fromstring(Fonts.fonts[1].data))) local out, err = Bdf.encode(ttf, { px = 14, chars = "Hello" }) t:check(out, "ttf -> bdf: " .. tostring(err)) local back = Bdf.decode(Bytes.reader(out :: buffer)) :: any t:check(back and back:glyphIndex(72) > 0 and back.unitsPerEm == 14 and back:rasterize(back:glyphIndex(72), 14).width > 3, "ttf -> bdf glyphs") --- errors local function code(s: string): string? local _, e = Bdf.decode(Bytes.reader(buffer.fromstring(s))) return e and e.code diff --git a/tests/font/bmfont.luau b/tests/font/bmfont.luau index 848b0da..1a3e095 100644 --- a/tests/font/bmfont.luau +++ b/tests/font/bmfont.luau @@ -1,8 +1,4 @@ --- font/bmfont tests: the text, XML and binary descriptors (an independent Python writer, glyphs rendered by FreeType) --- decode to the reference description; each variant re-encodes to every variant and decodes back unchanged (binary: --- byte-identical to the Python writer); Font methods (glyphIndex / advance / kern); lazy pages through opts.loadPage --- and the page PNG (glyph crops against FreeType's bitmaps); bake() from a TrueType font; errors; the fuzz pass. --- Fixtures: tools/fixtures/bmfont.py. +-- font/bmfont tests against an independent Python writer and FreeType's bitmaps (tools/fixtures/bmfont.py). local T = require("@tests/T") local F = require("@rosetta") local Bmfont = require("@rosetta/font/bmfont") @@ -47,7 +43,6 @@ local function sameDesc(got: any, want: any, label: string, faceQuotes: boolean) end end --- 1. the three encodings local fonts = {} for _, v in { "text", "xml", "binary" } do local f, err = Bmfont.decode(Bytes.reader(buffer.fromstring(Fx[v]))) @@ -58,7 +53,6 @@ for _, v in { "text", "xml", "binary" } do t:eq(F.detect(Fx[v]), "bmfont", v .. ": F.detect") end --- 2. re-encode every variant to every variant for from, f in fonts do for _, to in { "text", "xml", "binary" } do local b, err = Bmfont.encode(f, { variant = to :: any }) @@ -73,7 +67,6 @@ for from, f in fonts do end t:eq(buffer.tostring(F.save(fonts.xml, nil, { format = "fnt" })):sub(1, 5), " glyph --- pair); our PSF 2 / PSF 1 output read back by psfgettable and the parser (fixture step) and round-tripping; an --- outline font written as PSF; .psfu.gz through the api; errors; the fuzz pass. Fixtures: tools/fixtures/psf.py. +-- font/psf tests against an independent parser and kbd's psfgettable (tools/fixtures/psf.py). local T = require("@tests/T") local F = require("@rosetta") local Psf = require("@rosetta/font/psf") @@ -58,14 +55,12 @@ for _, c in Fx.fonts do end end --- an outline font as PSF 2 local ttf = Ttf.decode(Bytes.reader(buffer.fromstring(Fonts.fonts[1].data))) local out, err = Psf.encode(ttf, { px = 16, chars = "AB" }) t:check(out, "ttf -> psf: " .. tostring(err)) local back = Psf.decode(Bytes.reader(out :: buffer)) :: any t:check(back and back:glyphIndex(66) == 2 and back.meta.source.version == 2, "ttf -> psf glyphs") --- errors local function code(s: string): string? local _, e = Psf.decode(Bytes.reader(buffer.fromstring(s))) return e and e.code diff --git a/tests/font/ttf.luau b/tests/font/ttf.luau index 2469f8b..a7a44c6 100644 --- a/tests/font/ttf.luau +++ b/tests/font/ttf.luau @@ -1,7 +1,4 @@ --- font/ttf tests (and codecs/font/TrueType, codecs/font/Cff): for the imgui-luau TrueType fonts, Source Sans 3 (CFF), a --- 'kern'-table font and a collection: metrics, names, cmap samples, advances / side bearings, outline control boxes and --- areas against fontTools; kerning against HarfBuzz (GPOS) and FreeType ('kern'); rasterize() against FreeType's --- unhinted renders (PSNR); the api; errors; the fuzz pass. Fixtures: tools/fixtures/fonts.py. +-- font/ttf tests (and codecs/font/TrueType, Cff) against fontTools, HarfBuzz and FreeType (tools/fixtures/fonts.py). local T = require("@tests/T") local F = require("@rosetta") local Ttf = require("@rosetta/font/ttf") @@ -31,7 +28,6 @@ local function area(cmds: any): number end local function psnr(img: any, r: any): (number, number) - -- union of both bitmaps, aligned on the pen position local ax0, ay0 = img.meta.left, -img.meta.top local bx0, by0 = r.left, -r.top local x0, y0 = math.min(ax0, bx0), math.min(ay0, by0) @@ -137,7 +133,6 @@ do t:check(nz > 20, "fixtures have non-zero kerning pairs: " .. nz) end --- collections if Fx.ttc then local b = buffer.fromstring(Fx.ttc.data) t:eq(Ttf.count(Bytes.reader(b)), Fx.ttc.count, "collection count") @@ -149,7 +144,6 @@ if Fx.ttc then t:check(f1 and f1.info.family == fonts["collection-1"].info.family, "F.load with opts.index") end --- the api: detection by content, the font facade do local c = Fx.fonts[1] t:eq(F.detect(c.data), "ttf", "F.detect") @@ -166,7 +160,6 @@ do t:check(e and e.code == Err.UNSUPPORTED, "ttf is read-only") end --- errors do local _, e1 = Ttf.decode(Bytes.reader(buffer.fromstring("OTTO"))) t:check(e1 and e1.code == Err.TRUNCATED, "short file: " .. tostring(e1)) @@ -175,7 +168,6 @@ do t:eq(Ttf.sniff(Bytes.reader(buffer.fromstring("wOFF"))), 0, "sniff rejects woff") end --- fuzz: whole-font mutations, then glyph access on whatever still parses do local samples = {} for _, c in Fx.fonts do @@ -198,9 +190,8 @@ do end return f end, samples, { mutations = 30, garbage = 200 }) - -- mutations inside the glyph data only (the header survives, so the outline parsers see the damage) local hits = 0 - local cff = Fx.fonts[#Fx.fonts - 2] -- (any font: the loop below picks the CFF one) + local cff = Fx.fonts[#Fx.fonts - 2] for _, c in Fx.fonts do if c.cff then cff = c diff --git a/tests/font/type1.luau b/tests/font/type1.luau index 3d31c08..918b59f 100644 --- a/tests/font/type1.luau +++ b/tests/font/type1.luau @@ -1,7 +1,4 @@ --- font/type1 tests (and codecs/font/GlyphNames): Latin Modern PFB fonts and a PFA (t1ascii) against fontTools --- (outline control boxes, areas, advances of sample glyphs including flex, hint replacement, seac accents and --- ligatures; code points from glyph names) and FreeType's unhinted renders (PSNR); errors; the fuzz pass. --- Fixtures: tools/fixtures/type1.py. +-- font/type1 tests (and codecs/font/GlyphNames): Latin Modern against fontTools and FreeType (tools/fixtures/type1.py). local T = require("@tests/T") local F = require("@rosetta") local Type1 = require("@rosetta/font/type1") @@ -37,7 +34,6 @@ local function area(cmds: any): number end local function psnr(img: any, r: any): (number, number) - -- union of both bitmaps, aligned on the pen position local ax0, ay0 = img.meta.left, -img.meta.top local bx0, by0 = r.left, -r.top local x0, y0 = math.min(ax0, bx0), math.min(ay0, by0) @@ -65,7 +61,6 @@ local function psnr(img: any, r: any): (number, number) return 10 * math.log10(255 * 255 / (se / n)), ink end - local worst = 99 local samples = {} for _, c in Fx.fonts do diff --git a/tests/font/woff.luau b/tests/font/woff.luau index ac40d98..1c9232f 100644 --- a/tests/font/woff.luau +++ b/tests/font/woff.luau @@ -1,6 +1,4 @@ --- font/woff tests: every fixture font as WOFF 1.0 (fontTools, zlib tables) decodes to the same font as the sfnt itself (font/ttf, checked against --- fontTools / FreeType in tests/font/ttf.luau): metrics, names, every glyph's outline, advance and side bearing, --- cmap and kerning samples; rasterize works; the api detects it; errors; the fuzz pass. Fixtures: tools/fixtures/fonts.py. +-- font/woff tests: fontTools' WOFF 1.0 decodes to the same font as the sfnt (tools/fixtures/fonts.py). local T = require("@tests/T") local F = require("@rosetta") local Woff = require("@rosetta/font/woff") @@ -66,7 +64,6 @@ for _, w in Fx.woff do end t:check(n >= 6, "fixture count") --- the api do local data = Fx.woff[1].woff t:eq(F.detect(data), "woff", "F.detect") @@ -75,7 +72,6 @@ do t:eq(Woff.sniff(Bytes.reader(buffer.fromstring("wOFF"))) + Woff.sniff(Bytes.reader(buffer.fromstring("wOF2"))), 1, "sniff") end --- errors do local data = Fx.woff[1].woff local _, e1 = Woff.decode(Bytes.reader(buffer.fromstring(string.sub(data, 1, 30)))) diff --git a/tests/font/woff2.luau b/tests/font/woff2.luau index 762ffdc..66aa035 100644 --- a/tests/font/woff2.luau +++ b/tests/font/woff2.luau @@ -1,6 +1,5 @@ --- font/woff2 tests: every fixture font as WOFF2 (fontTools: the default glyf / loca transform, and with the hmtx transform too) decodes to the same font as the sfnt itself (font/ttf, checked against --- fontTools / FreeType in tests/font/ttf.luau): metrics, names, every glyph's outline, advance and side bearing, --- cmap and kerning samples; rasterize works; the api detects it; errors; the fuzz pass. Fixtures: tools/fixtures/fonts.py. +-- font/woff2 tests: fontTools' WOFF2 (glyf / loca and hmtx transforms) decodes to the same font as the sfnt. +-- Fixtures: tools/fixtures/fonts.py. local T = require("@tests/T") local F = require("@rosetta") local Woff2 = require("@rosetta/font/woff2") @@ -66,7 +65,6 @@ for _, w in Fx.woff do end t:check(n >= 6, "fixture count") --- the api do local data = Fx.woff[1].woff2 t:eq(F.detect(data), "woff2", "F.detect") @@ -75,7 +73,6 @@ do t:eq(Woff2.sniff(Bytes.reader(buffer.fromstring("wOFF"))) + Woff2.sniff(Bytes.reader(buffer.fromstring("wOF2"))), 1, "sniff") end --- errors do local data = Fx.woff[1].woff2 local _, e1 = Woff2.decode(Bytes.reader(buffer.fromstring(string.sub(data, 1, 30)))) From 75ddfb4068902079a31d1390c324e8cda7922b7b Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:51:09 -0500 Subject: [PATCH 23/25] tests/ops: comments: specs only --- tests/ops/audioops.luau | 11 +---------- tests/ops/imageops.luau | 16 +--------------- tests/ops/layerops.luau | 6 +----- tests/ops/meshops.luau | 17 ++--------------- tests/ops/musicops.luau | 15 ++------------- 5 files changed, 7 insertions(+), 58 deletions(-) diff --git a/tests/ops/audioops.luau b/tests/ops/audioops.luau index be56fc6..cb26d62 100644 --- a/tests/ops/audioops.luau +++ b/tests/ops/audioops.luau @@ -1,6 +1,4 @@ --- ops/AudioOps tests: toAudio from a Decoder, gain / gainDb / normalize, peak / RMS of known signals, remix matrices --- (5.1 -> stereo -> mono, mono -> stereo / 5.1), resample through codecs/audio/Resample, trim, concat and mix with rate / --- channel conversion, fades, bad arguments (Err.ARG, never a throw), and the F.ops facade. +-- ops/AudioOps tests on known signals. local T = require("@tests/T") local AudioOps = require("@rosetta/ops/AudioOps") local Types = require("@rosetta/Types") @@ -31,7 +29,6 @@ local sine = audio(8000, 2, 8000, function(f, c) return (if c == 0 then 0.5 else 0.25) * math.sin(2 * math.pi * 440 * f / 8000) end) --- toAudio do local dec = Pcm.audioDecoder(sine) local a = AudioOps.toAudio(dec) :: Types.Audio @@ -41,7 +38,6 @@ do t:check(e2 and e2.code == Err.LIMIT, "maxFrames -> LIMIT") end --- levels do local p, per = AudioOps.peak(sine) t:check(near(p :: number, 0.5, 1e-3) and near((per :: any)[2], 0.25, 1e-3), "peak") @@ -57,7 +53,6 @@ do t:check(z and z.frames == 10, "normalize silence") end --- channels do -- 5.1 (WAVE order FL FR C LFE BL BR) with distinct constants local five = audio(8000, 6, 4, function(_, c) @@ -81,7 +76,6 @@ do t:check(e and e.code == Err.ARG, "downmix to more channels: ARG") end --- time do local r = AudioOps.resample(sine, 16000) :: Types.Audio t:check(r.sampleRate == 16000 and r.frames == 16000, "resample 8 -> 16 kHz") @@ -108,7 +102,6 @@ do t:check(at(fd, 0, 0) == 0 and near(at(fd, 2000, 0), at(sine, 2000, 0) * 0.5, 1e-6) and near(at(fd, 7999, 0), 0), "fades") end --- bad arguments: Err.ARG, never a throw do local junk: { any } = { nil, 5, "x", {}, { kind = "audio" }, Types.Image.new(2, 2) } local calls = { @@ -134,7 +127,6 @@ do t:check(AudioOps.remix(sine, 0) == nil, "zero channels") end --- the F.ops facade do t:check(F.ops.audio == AudioOps, "F.ops.audio") t:check(F.ops.image ~= nil and type(F.ops.image.resize) == "function", "F.ops.image") @@ -147,5 +139,4 @@ do t:check(F.ops.nothing == nil, "unknown ops: nil") end --- (no decoder here: the no-throw pass is the bad-arguments block above) t:done() diff --git a/tests/ops/imageops.luau b/tests/ops/imageops.luau index f4740b3..f3244f7 100644 --- a/tests/ops/imageops.luau +++ b/tests/ops/imageops.luau @@ -1,8 +1,4 @@ --- ops/ImageOps tests: against Pillow (tools/fixtures/imageops.py): grey conversion (exact), resize nearest / bilinear / --- Lanczos up and down (max error), rotate with bilinear + expand (PSNR), alpha_composite (exact); property tests for --- every pixel format (conversion round trips, flips, quarter turns, crop, premultiply, pixel access, fill), blit --- clipping and blend modes, animation helpers (coalesce with each disposal, fromFrames, durations), and a pass of bad --- arguments that must return nil, Err without throwing. +-- ops/ImageOps tests against Pillow (tools/fixtures/imageops.py) and property tests. local T = require("@tests/T") local Ops = require("@rosetta/ops/ImageOps") local Types = require("@rosetta/Types") @@ -17,7 +13,6 @@ local function image(w: number, h: number, fmt: string, px: string): any return img end --- max abs difference and PSNR of two byte strings / buffers local function diff(a: buffer, b: string): (number, number) local n = #b local mx, se = 0, 0 @@ -36,7 +31,6 @@ local rgb = image(Fx.rgb.w, Fx.rgb.h, "rgb8", Fx.rgb.px) local rgba = image(Fx.rgba.w, Fx.rgba.h, "rgba8", Fx.rgba.px) local rgba2 = image(Fx.rgba2.w, Fx.rgba2.h, "rgba8", Fx.rgba2.px) --- Pillow references do local g = Ops.convert(rgb, "gray8") :: any t:check(buffer.tostring(g.pixels) == Fx.gray, "rgb8 -> gray8 matches Pillow convert('L')") @@ -67,7 +61,6 @@ do t:check(mx == 0, "alpha_composite matches Pillow exactly (max error " .. mx .. ")") end --- conversions between every format local FORMATS = { "rgba8", "rgba16", "rgbaf32", "rgb8", "gray8", "gray16", "graya8", "alpha8", "yuv420p" } do for _, f in FORMATS do @@ -104,7 +97,6 @@ do t:check(buffer.readu8(b.pixels, 0) == 255 and buffer.readu8(b.pixels, 1) == 0 and buffer.readu8(b.pixels, 2) == 128, "float -> 8 bit clamps and rounds") end --- geometry properties on every format do for _, f in FORMATS do local img = Ops.convert(rgba, f) :: any @@ -131,7 +123,6 @@ do local rr = Ops.rotate(img, 33) :: any t:check(rr and rr.format == f, f .. ": rotate 33") end - -- crop content, nearest identity, ccw convention local c = Ops.crop(rgba, 3, 4, 5, 6) :: any t:check(buffer.readu32(c.pixels, 0) == buffer.readu32(rgba.pixels, (4 * rgba.width + 3) * 4), "crop origin") t:check(buffer.tostring((Ops.resize(rgba, rgba.width, rgba.height, "lanczos") :: any).pixels) == buffer.tostring(rgba.pixels), "same-size resize is a copy") @@ -139,7 +130,6 @@ do t:eq(buffer.readu32(q.pixels, 0), buffer.readu32(rgba.pixels, (rgba.width - 1) * 4), "rotate90 is counter-clockwise") end --- pixels, fill, premultiply do for _, f in FORMATS do local img = Ops.new(3, 2, f) :: any @@ -173,7 +163,6 @@ do t:note("premultiply round trip: max error %d for alpha >= 32", worst) end --- blit do local dst = Ops.new(10, 10, "rgba8") :: any Ops.fill(dst, 10, 20, 30, 255) @@ -191,7 +180,6 @@ do Ops.blit(dst, src, 5, 5, { opacity = 0.5 }) local r = Ops.getPixel(dst, 5, 5) t:check(math.abs(r - 133) <= 1, "opacity 0.5 over (10 -> " .. r .. ")") - -- rgb8 destination, gray source, float destination local d3 = Ops.convert(dst, "rgb8") :: any t:check(Ops.blit(d3, Ops.convert(src, "graya8") :: any, 1, 1) == d3, "blit onto rgb8") local df = Ops.convert(dst, "rgbaf32") :: any @@ -200,7 +188,6 @@ do t:check(Ops.blit(dy, src, 3, 3) == dy, "blit onto yuv420p") end --- animation helpers do local W, H = 6, 4 local function solid(w: number, h: number, r: number, a: number): any @@ -241,7 +228,6 @@ do t:check(Ops.fromFrames({ fr[1], rgba }) == nil, "fromFrames refuses mixed sizes") end --- bad arguments: nil, Err, never a throw do local rand = T.rng(5) local junk: { any } = { nil, 0, -1, 1.5, 2 ^ 40, "x", {}, true, 0 / 0, math.huge, -7 } diff --git a/tests/ops/layerops.luau b/tests/ops/layerops.luau index 92a743c..c95723c 100644 --- a/tests/ops/layerops.luau +++ b/tests/ops/layerops.luau @@ -1,6 +1,4 @@ --- ops/LayerOps + codecs/image/Blend tests: blend mode formulas on single pixels against hand-computed W3C values, opacity, --- masks, clipping, isolated vs pass-through groups, hidden layers, frames, leaves, bad arguments. (Whole-document --- flattening against psd-tools is in tests/layered/psd.luau.) +-- ops/LayerOps + codecs/image/Blend tests against hand-computed W3C values (flattening: tests/layered/psd.luau). local T = require("@tests/T") local LayerOps = require("@rosetta/ops/LayerOps") local Blend = require("@rosetta/codecs/image/Blend") @@ -72,7 +70,6 @@ do local r2, _, _, a2 = get(LayerOps.flatten(doc({ top }))) t:check(r2 == 255 and math.abs(a2 - 128) <= 1, "over transparent: alpha scales") end --- hidden layers, masks, clipping do local top = L("top", px(255, 0, 0, 255)) top.visible = false @@ -124,7 +121,6 @@ do t:check(math.abs(get(LayerOps.flatten(doc({ bottom, g }))) - 100) <= 1, "pass-through: disabled mask ignored") g.mask = nil end --- frames, leaves, flattenFrames do local d = doc({ L("a", px(1, 2, 3, 255)) }) d.frames = { { layers = d.layers, delay = 0.1 }, { layers = { L("b", px(9, 8, 7, 255)) }, delay = 0.2 } } diff --git a/tests/ops/meshops.luau b/tests/ops/meshops.luau index 315a3dc..128e679 100644 --- a/tests/ops/meshops.luau +++ b/tests/ops/meshops.luau @@ -1,8 +1,4 @@ --- ops/MeshOps tests: triangulate (strips, fans, convex / concave / degenerate n-gons), transform (normals by the inverse --- transpose, mirrors flip the winding), computeNormals (smooth sphere normals = the radial direction, flat cube normals), --- computeTangents (orthogonal, unit, handedness), weld / unweld, bounds, merge (instances baked, mixed attributes), --- scale / setUnit / setUp, greedy voxel meshing (exposed face area, winding, the checkerboard worst case), errors. --- Analytic references (closed forms); the format tests check merge / bounds against assimp and trimesh. +-- ops/MeshOps tests against analytic references (closed forms). local T = require("@tests/T") local MeshOps = require("@rosetta/ops/MeshOps") local Types = require("@rosetta/Types") @@ -52,7 +48,6 @@ local function area(prim: any): number return total end --- a unit cube as 6 quads (polygons), 24 corners local function cube(): Types.Primitive local P = {} local faces = { @@ -76,7 +71,6 @@ local function cube(): Types.Primitive return { attributes = { POSITION = f32(P, 3) }, indices = u32(ind), faces = u32(sizes), mode = "polygons" } end --- triangulate do local c = cube() local tri = MeshOps.triangulate(c) :: any @@ -95,7 +89,6 @@ do end end t:check(outward, "triangulated winding keeps the faces outward") - -- strips and fans local P = f32({ 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 2, 0, 1, 2, 0 }, 3) local strip = MeshOps.triangulate({ attributes = { POSITION = P }, mode = "triangle_strip" }) :: any t:check(table.concat(idx(strip.indices), ",") == "0,1,2,2,1,3,2,3,4,4,3,5", "strip unrolled with alternating winding") @@ -130,7 +123,6 @@ do t:check(MeshOps.triangulate(lines) == lines, "lines come back unchanged") end --- transform do local tri = MeshOps.triangulate(cube()) :: any MeshOps.computeNormals(MeshOps.unweld(tri)) @@ -173,7 +165,6 @@ do t:check(e and e.code == Err.ARG, "transform: a bad matrix") end --- normals, tangents on a UV sphere do local rings, segs = 16, 32 local P, UV, ind = {}, {}, {} @@ -253,7 +244,6 @@ do t:check(axis, "flat cube normals are axis-aligned") end --- weld do local soup = MeshOps.unweld(MeshOps.triangulate(cube()) :: any) :: any t:eq(soup.attributes.POSITION.count, 36, "unwelded cube: 36 vertices") @@ -271,7 +261,6 @@ do t:eq(positionsOnly.attributes.POSITION.count, 8, "positionsOnly: 8") end --- merge, bounds do local s = S.new() local tri = MeshOps.triangulate(cube()) :: any @@ -301,11 +290,10 @@ do t:check(e and e.code == Err.ARG, "merge junk") end --- units and up axis do local s = S.fromPrimitive(MeshOps.triangulate(cube()) :: any) s.nodes[1].translation = { 1, 2, 3 } - s.meta.unit = 0.01 -- centimetres + s.meta.unit = 0.01 MeshOps.setUnit(s, 1) local lo, hi = MeshOps.bounds(s) t:check(lo and near(lo[1], 0.01) and near(hi[1], 0.02) and near(lo[3], 0.03), "cm -> m") @@ -318,7 +306,6 @@ do t:check(MeshOps.setUp(s, "x" :: any) == nil, "setUp: bad axis") end --- greedy voxels do local v = Types.Voxels.new(4, 4, 4) for x = 0, 3 do diff --git a/tests/ops/musicops.luau b/tests/ops/musicops.luau index 7259be5..caf7a2d 100644 --- a/tests/ops/musicops.luau +++ b/tests/ops/musicops.luau @@ -1,6 +1,4 @@ --- ops/MusicOps tests (F.music.new / addPattern / setCell / getCell / addSample / addInstrument / note) and the --- music-as-audio bridges of the api: F.save / F.convert of a Module or a Midi to an audio format (rendered, render --- options through opts), F.audio.open / F.audio.load of music bytes. Everything is built here (no fixtures). +-- ops/MusicOps tests and the music-as-audio bridges of the api; everything is built here (no fixtures). local T = require("@tests/T") local F = require("@rosetta") local Err = require("@rosetta/core/Err") @@ -16,7 +14,6 @@ local function sine(rate: number, frames: number): any return a end --- note names do t:eq(F.music.note("C-0"), 1, "C-0") t:eq(F.music.note("C-4"), 49, "C-4") @@ -32,7 +29,6 @@ do end end --- a MOD built from scratch: saved, reloaded, rendered local a = sine(8363, 8363) local song = assert(F.music.new({ format = "mod", channels = 4, title = "demo", speed = 3 })) do @@ -47,7 +43,6 @@ do t:check(F.music.setCell(song, p, 32, 2, { note = "E-4", instrument = s, effect = 0xC, param = 32 }), "setCell 2") local c = assert(F.music.getCell(song, p, 32, 2)) t:check(c.note == 53 and c.instrument == 1 and c.effect == 0xC and c.param == 32 and c.volume == 0, "getCell") - -- bad arguments local _, e1 = F.music.setCell(song, p, 64, 1, {}) t:check(e1 and e1.code == Err.ARG, "row out of range") local _, e2 = F.music.setCell(song, p, 0, 5, {}) @@ -65,7 +60,7 @@ do local _, e8 = F.music.addPattern({} :: any) t:check(e8 and e8.code == Err.ARG, "not a module") - local mod = assert(F.save(song)) -- the source format + local mod = assert(F.save(song)) t:eq(F.detect(mod), "mod", "saved as MOD") local back = assert(F.music.load(mod)) t:eq(back.title, "demo", "title round trip") @@ -77,7 +72,6 @@ do t:check(au.frames > 22050 and F.ops.audio.peak(au) > 0.05, "renders sound") end --- an XM with an instrument and a volume envelope do local xm = assert(F.music.new({ format = "xm", channels = 2 })) local s = assert(F.music.addSample(xm, { audio = a, rate = 16726 })) -- an octave up: relativeNote 12 @@ -96,7 +90,6 @@ do t:check(eenv and eenv.code == Err.ARG, "envelope ticks must increase") end --- music saved and converted as audio: rendered, with the render options from opts do local wav = assert(F.save(song, nil, { format = "wav", sampleRate = 22050 })) local au = assert(F.audio.load(wav)) @@ -118,7 +111,6 @@ do local mid = assert(F.save(m, nil, { format = "midi" })) t:eq(F.detect(assert(F.convert(mid, "wav"))), "wav", "F.convert(midi, wav)") - -- F.audio.open / load of music bytes: the rendered Decoder local d1 = assert(F.audio.open(mid, { tail = 0 })) t:check(d1.channels == 2 and d1.sampleRate == 44100 and d1.frames == 22050, "F.audio.open(midi)") local d2 = assert(F.audio.open(mod)) @@ -127,15 +119,12 @@ do t:check(a2.kind == "audio" and a2.sampleRate == 8000, "F.audio.load(mod)") local d3 = assert(F.audio.open(mod, { format = "mod" })) t:check(d3.frames > 0, "F.audio.open with format = mod") - -- still an error for data no format reads local _, e = F.audio.open(buffer.fromstring("not audio at all")) t:check(e and e.code == Err.UNKNOWN_FORMAT, "unknown data") - -- and a soundfont is not audio local _, e2 = F.audio.save(m, nil, { format = "png" }) t:check(e2 ~= nil, "music to a non-audio format fails") end --- no throws on random cell / sample arguments do local rng = T.rng(7) local ok = true From 0eec255bfbbd72632101d9219f4a8521323242d3 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:51:26 -0500 Subject: [PATCH 24/25] tests/audio: comments: specs only --- tests/audio/_adpcm.luau | 6 +----- tests/audio/_encode_cases.luau | 3 +-- tests/audio/_lossless.luau | 12 +++--------- tests/audio/_opus_cases.luau | 4 +--- tests/audio/_signal.luau | 4 +--- tests/audio/aac.luau | 9 +-------- tests/audio/ac3.luau | 14 ++++---------- tests/audio/adpcm.luau | 9 ++------- tests/audio/adx.luau | 7 ++----- tests/audio/aiff.luau | 12 +----------- tests/audio/ape.luau | 10 ++-------- tests/audio/au.luau | 5 ++--- tests/audio/brstm.luau | 5 ++--- tests/audio/caf.luau | 9 ++------- tests/audio/flac.luau | 17 ++++------------- tests/audio/flac_encode.luau | 7 ++----- tests/audio/m4a.luau | 16 ++-------------- tests/audio/mp3.luau | 21 ++++----------------- tests/audio/mp3_encode.luau | 13 +++---------- tests/audio/mpc.luau | 13 +++---------- tests/audio/opus.luau | 21 +++------------------ tests/audio/opus_encode.luau | 10 +--------- tests/audio/qoa.luau | 8 ++------ tests/audio/tta.luau | 10 +++------- tests/audio/vag.luau | 7 ++----- tests/audio/voc.luau | 5 +---- tests/audio/vorbis.luau | 10 ++-------- tests/audio/vorbis_encode.luau | 8 ++------ tests/audio/wav.luau | 24 +++++------------------- tests/audio/wavpack.luau | 11 ++--------- 30 files changed, 66 insertions(+), 244 deletions(-) diff --git a/tests/audio/_adpcm.luau b/tests/audio/_adpcm.luau index 7561c0d..a45ba3d 100644 --- a/tests/audio/_adpcm.luau +++ b/tests/audio/_adpcm.luau @@ -1,11 +1,8 @@ --- tests/audio/_adpcm: shared checks of the ADPCM game-audio formats (adx, vag, brstm): a file against the reference --- decoder's s16le output, bit-exact, through decode() and through open() with seeks (forward into unvisited packets, --- back, the end), loop points; the SNR of an encoder's round trip. +-- tests/audio/_adpcm: shared checks of adx, vag, brstm: bit-exact against the reference decoder's s16le output. local Bytes = require("@rosetta/core/Bytes") local H = {} --- same(f32 buffer, s16le reference buffer, first reference sample, count) -> true when every sample is equal function H.same(out: buffer, ref: buffer, from: number, count: number): boolean for i = 0, count - 1 do if buffer.readf32(out, i * 4) * 32768 ~= buffer.readi16(ref, (from + i) * 2) then @@ -26,7 +23,6 @@ function H.snr(x: buffer, y: buffer, count: number): number return if err == 0 then 200 else 10 * math.log10(sig / err) end --- check(t, Fmt, c, opts?): c = { name, data, rate, ch, frames?, ref, loopStart?, loopEnd? } function H.check(t: any, Fmt: any, c: any, opts: any?) local ref = buffer.fromstring(c.ref) local frames = buffer.len(ref) // (2 * c.ch) diff --git a/tests/audio/_encode_cases.luau b/tests/audio/_encode_cases.luau index 0869ec6..4563859 100644 --- a/tests/audio/_encode_cases.luau +++ b/tests/audio/_encode_cases.luau @@ -1,5 +1,4 @@ --- tests/audio/_encode_cases: the files our ALAC / CAF writers produce for the reference check (tools/fixtures/m4a.py --- runs tools/fixtures/_m4a_encode.luau over them; tests/audio/m4a.luau and caf.luau re-encode and compare). +-- tests/audio/_encode_cases: the ALAC / CAF writer inputs of the reference check (tools/fixtures/m4a.py). return { { name = "ours_alac16_stereo", container = "m4a", rate = 44100, frames = 4096 * 3 + 1234, channels = 2, bits = 16, seed = 1, tags = { title = "Our Title \u{e9}", artist = "rosetta", album = "Tests", track = "5", tracktotal = "10", date = "2026", genre = "Test", comment = "round trip" } }, { name = "ours_alac16_mono", container = "m4a", rate = 22050, frames = 5000, channels = 1, bits = 16, seed = 2 }, diff --git a/tests/audio/_lossless.luau b/tests/audio/_lossless.luau index d44260f..85f0d52 100644 --- a/tests/audio/_lossless.luau +++ b/tests/audio/_lossless.luau @@ -1,8 +1,5 @@ --- Shared checks of the lossless audio format tests (wavpack, ape, tta): every fixture opened, decoded bit-exact --- against the reference decoder's samples (readInt for integer streams, the f32 bytes for float ones), f32 scaling --- and output reuse, seeking to sample-accurate positions, reading past the end, tags, sniff. A fixture is a table --- { name, data, rate, channels, bits, float, frames, crc, tags?, partial? } (partial: a cut file whose decode stops --- with an error; the reference decoded its first `frames` frames). +-- Shared checks of the lossless audio format tests (wavpack, ape, tta): bit-exact against the reference decoder. +-- partial: a cut file whose decode stops with an error; the reference decoded its first `frames` frames. local T = require("@tests/T") local Bytes = require("@rosetta/core/Bytes") local Crc32 = require("@rosetta/core/Crc32") @@ -20,7 +17,6 @@ local function open(mod: any, b: any, opts: any?): (any, any) end L.open = open --- all(dec, fx) -> crc of every sample read (i32 for integer streams, f32 bytes for floats), frames, the values function L.all(dec: any, fx: any): (number, number, { number }) local ch = dec.channels local vals = table.create(fx.frames * ch, 0) @@ -52,7 +48,6 @@ function L.all(dec: any, fx: any): (number, number, { number }) return crc, n, vals end --- cases(t, mod, cases, optsOf?) -> seeks checked: the per-fixture checks; optsOf(fx) gives the open options function L.cases(t: any, mod: any, cases: { any }, optsOf: ((any) -> any)?): number local seekChecks = 0 for _, fx in cases do @@ -73,7 +68,6 @@ function L.cases(t: any, mod: any, cases: { any }, optsOf: ((any) -> any)?): num end t:eq(n, fx.frames, name .. ": decoded frames") t:eq(crc, fx.crc, name .. ": samples identical to the reference decoder") - -- f32 scaling, output reuse local ch = dec.channels dec:seek(0) local reuse = buffer.create(100 * ch * 4) @@ -120,7 +114,7 @@ function L.cases(t: any, mod: any, cases: { any }, optsOf: ((any) -> any)?): num return seekChecks end --- subrange(t, mod, fx, depth) : decode() from a Reader over a sub-range equals read(); meta.source +-- decode() from a Reader over a sub-range equals read() function L.subrange(t: any, mod: any, fx: any, format: string) local name = fx.name local big = buffer.create(#fx.data + 13) diff --git a/tests/audio/_opus_cases.luau b/tests/audio/_opus_cases.luau index 5cade81..5f913bf 100644 --- a/tests/audio/_opus_cases.luau +++ b/tests/audio/_opus_cases.luau @@ -1,6 +1,4 @@ --- tests/audio/_opus_cases: the inputs of the CELT encoder reference check (tools/fixtures/opus_celt.py runs --- tools/fixtures/_opus_encode.luau over them; tests/audio/opus_encode.luau re-encodes and compares): a deterministic --- music-like signal (chord + vibrato + chirp + clicks + a silent stretch) at a given rate / channel count. +-- tests/audio/_opus_cases: the CELT encoder reference check inputs (tools/fixtures/opus_celt.py). local Types = require("@rosetta/Types") local Cases = {} diff --git a/tests/audio/_signal.luau b/tests/audio/_signal.luau index 27b9fd5..eb206f8 100644 --- a/tests/audio/_signal.luau +++ b/tests/audio/_signal.luau @@ -1,6 +1,4 @@ --- tests/audio/_signal: the deterministic integer test signal of tools/fixtures/_m4a_signal.py (the same numbers), as --- an interleaved integer array and as a Types.Audio (f32, exact for up to 24 bits). Used by the m4a / caf tests and the --- fixture-time encoder runs (tools/fixtures/_m4a_encode.luau). +-- tests/audio/_signal: the deterministic integer test signal of tools/fixtures/_m4a_signal.py (the same numbers). local Types = require("@rosetta/Types") local Signal = {} diff --git a/tests/audio/aac.luau b/tests/audio/aac.luau index 0772b88..593dd50 100644 --- a/tests/audio/aac.luau +++ b/tests/audio/aac.luau @@ -1,6 +1,4 @@ --- audio/aac tests: ADTS streams from ffmpeg and fdkaac (stereo, mono 32 kHz) against ffmpeg's float decode (SNR, --- length); an HE-AAC ADTS stream plays its core; a leading ID3v2 tag (skipped, text frames as tags) and garbage before --- the first frame (resync); a truncated last frame; streaming + seek; sniff; errors; the fuzz no-throw pass. +-- audio/aac tests: ADTS streams from ffmpeg and fdkaac against ffmpeg's float decode (SNR, length). -- Fixtures: tools/fixtures/m4a.py. local T = require("@tests/T") local AacF = require("@rosetta/audio/aac") @@ -49,7 +47,6 @@ for _, c in Fx do t:note("%s: %d ch %d Hz, %d frames, SNR %.1f dB vs ffmpeg", c.name, c.channels, c.rate, a.frames, s) end --- HE-AAC ADTS: the core for _, c in He do if string.sub(c.name, -4) == ".aac" then local a, err = AacF.decode(reader(c.data)) @@ -57,7 +54,6 @@ for _, c in He do end end --- ID3v2 in front + garbage, truncated tail do local function frame(id: string, text: string): string local body = "\3" .. text @@ -77,7 +73,6 @@ do t:check(cut and cut.frames == first.frames - 1024, "truncated last frame dropped") end --- streaming + seek do local whole = AacF.decode(reader(first.data)) :: any local dec = AacF.open(reader(first.data)) :: any @@ -94,14 +89,12 @@ do end end --- errors do t:eq(AacF.sniff(reader("RIFF....WAVE")), 0, "sniff a WAV") local _, e = AacF.decode(reader(string.rep("\0", 100))) t:check(e and e.code == Err.CORRUPT, "no frames: " .. tostring(e)) end --- fuzz do local samples = {} for _, c in Fx do diff --git a/tests/audio/ac3.luau b/tests/audio/ac3.luau index 6dc0c96..1b48e66 100644 --- a/tests/audio/ac3.luau +++ b/tests/audio/ac3.luau @@ -1,9 +1,6 @@ --- audio/ac3 tests: AC-3 streams from ffmpeg (every acmod with and without LFE, coupling incl. cplbegf 0, rematrixing, --- 32 / 44.1 / 48 kHz) and aften (block switching, 1+1 dual mono, dynamic range profiles, the alternate BSI) against --- ffmpeg's float decode, or liba52's for block-switched streams (SNR, max difference; dithflags cleared in the --- fixture step so both sides decode the same numbers); dynamic range on; the encoders' dithered originals; AC-3 tracks --- of MKV / MP4 / MPEG-TS / AVI through the api's audio hook; exact seeking; resync and truncation; error codes (E-AC-3, --- CRC); the fuzz no-throw pass. Fixtures: tools/fixtures/ac3.py. +-- audio/ac3 tests: AC-3 streams from ffmpeg and aften against ffmpeg's float decode, or liba52's for block-switched +-- streams (dithflags cleared in the fixture step so both sides decode the same numbers). +-- Fixtures: tools/fixtures/ac3.py. local T = require("@tests/T") local F = require("@rosetta") local Ac3F = require("@rosetta/audio/ac3") @@ -19,7 +16,6 @@ local function reader(s: string): Bytes.Reader return Bytes.reader(buffer.fromstring(s)) end --- SNR (dB) and the largest difference of interleaved f32 `got` against the f32le reference `ref` local function compare(got: buffer, ref: string, count: number): (number, number) local rb = buffer.fromstring(ref) local n = math.min(count, #ref // 4, buffer.len(got) // 4) @@ -104,7 +100,6 @@ do end end --- resync over garbage, a truncated last frame, the raw codec API do local c = byName.stereo_44k local a = Ac3F.decode(reader("\0\11\119garbage" .. c.data)) :: any @@ -118,7 +113,6 @@ do t:check(n == 1536 and d.channels == 2 and #d.pcm == 1536 * 2, "decoder: one syncframe") end --- errors do local c = byName.stereo_44k.data t:eq(Ac3F.sniff(reader("RIFF....WAVE")), 0, "sniff a WAV") @@ -138,7 +132,7 @@ do t:check(e and e.code == Err.LIMIT, "maxFrames: " .. tostring(e)) end --- fuzz (without the CRC check, so mutations reach the decoder) +-- fuzz without the CRC check, so mutations reach the decoder do local samples = {} for _, c in Fx do diff --git a/tests/audio/adpcm.luau b/tests/audio/adpcm.luau index 8d99537..593ca86 100644 --- a/tests/audio/adpcm.luau +++ b/tests/audio/adpcm.luau @@ -1,7 +1,5 @@ --- audio/adpcm tests: headerless streams (IMA nibbles, IMA WAV / MS blocks, Apple ima4, PS-ADPCM) decoded with the --- layout in the options, bit-exact against ffmpeg / vgmstream (tools/fixtures/adpcm.py), with seeking; our encoder's --- streams (ima, ms, ima_wav) as ffmpeg decodes them (wrapped in KVAG / WAV in the fixture step) against our decode of --- the same bytes, and their quality; options and errors; the api by format name; the fuzz pass. +-- audio/adpcm tests: headerless ADPCM streams bit-exact against ffmpeg / vgmstream; our encoder's via ffmpeg. +-- Fixtures: tools/fixtures/adpcm.py. local T = require("@tests/T") local Raw = require("@rosetta/audio/adpcm") local Bytes = require("@rosetta/core/Bytes") @@ -47,7 +45,6 @@ for _, c in Cases do end t:note("%d raw streams bit-exact with ffmpeg / vgmstream", #Cases) --- ------------------------------------------------------------------------------------------------ encoder local function snr(x: buffer, y: buffer, count: number): number local sig, err = 0, 0 for i = 0, count - 1 do @@ -100,7 +97,6 @@ do t:check(lo.frames == 6 and buffer.tostring(lo.samples) == buffer.tostring(hi.samples), "nibble order") end --- ------------------------------------------------------------------------------------------------ api do local c = Cases[1] local a, err = F.audio.load(c.data, { format = "adpcm", codec = c.codec, sampleRate = c.rate, channels = c.ch }) @@ -110,7 +106,6 @@ do t:check(out ~= nil and buffer.len(out) % 256 == 0, "F.save adpcm") end --- ------------------------------------------------------------------------------------------------ fuzz local kinds = { "ima", "ima_wav", "ms", "ima_qt", "psx" } local k = 0 t:fuzz("open + read + seek", function(b: buffer) diff --git a/tests/audio/adx.luau b/tests/audio/adx.luau index 2d1852b..1542bd2 100644 --- a/tests/audio/adx.luau +++ b/tests/audio/adx.luau @@ -1,6 +1,5 @@ --- audio/adx tests: ffmpeg's ADX files (version 3) and a version 4 file with history and loop points, bit-exact with --- vgmstream (tools/fixtures/adx.py) through decode and open with seeks; our encoder's files as vgmstream decodes them --- (equal to our decode, loops reported) and their quality; header errors; the api; the fuzz pass. +-- audio/adx tests: ffmpeg's ADX files and a version 4 file with loop points, bit-exact with vgmstream. +-- Fixtures: tools/fixtures/adx.py. local T = require("@tests/T") local Adx = require("@rosetta/audio/adx") local Bytes = require("@rosetta/core/Bytes") @@ -24,7 +23,6 @@ for _, c in Cases do end t:note("%d files bit-exact with vgmstream", #Cases) --- ------------------------------------------------------------------------------------------------ encoder local audio = Types.Audio.new(Sig.rate, Sig.channels, Sig.frames) buffer.writestring(audio.samples, 0, Sig.data) for _, c in Ours do @@ -49,7 +47,6 @@ do t:check(e3 and e3.code == Err.ARG, "bad cutoff") end --- ------------------------------------------------------------------------------------------------ errors do local base = Cases[1].data local function patch(at: number, bytes: string): buffer diff --git a/tests/audio/aiff.luau b/tests/audio/aiff.luau index 956e1af..39387d0 100644 --- a/tests/audio/aiff.luau +++ b/tests/audio/aiff.luau @@ -1,6 +1,4 @@ --- audio/aiff tests: files written by ffmpeg and sox in every sample format (AIFF 8 / 12 / 16 / 24 / 32-bit, AIFF-C --- sowt / fl32 / fl64 / ulaw / alaw / ima4, 6 channels, text chunks) against ffmpeg's decode; streaming reads and seeks; --- our encoder's output for every sample format decoded by ffmpeg (fixture step) and by us; errors; fuzz. +-- audio/aiff tests: AIFF / AIFF-C files written by ffmpeg and sox against ffmpeg's decode; our encoder's via ffmpeg. -- Fixtures: tools/fixtures/aiff.py. local T = require("@tests/T") local Aiff = require("@rosetta/audio/aiff") @@ -16,7 +14,6 @@ local t = T.suite("aiff") local function reader(s: string): Bytes.Reader return Bytes.reader(buffer.fromstring(s)) end --- max |a - b| over n f32 samples (a at byte ao, b at byte bo) local function maxDiff(a: buffer, ao: number, b: buffer, bo: number, n: number): number local m = 0 for i = 0, n - 1 do @@ -28,12 +25,10 @@ local function maxDiff(a: buffer, ao: number, b: buffer, bo: number, n: number): return m end --- the contract t:eq(Aiff.name, "aiff", "name") t:eq(Aiff.category, "audio", "category") t:check(Aiff.caps.decode and Aiff.caps.encode and table.find(Aiff.extensions, "aif") ~= nil, "caps / extensions") --- reference files: decode, stream, seek for _, c in Cases do local a, err = Aiff.decode(reader(c.data)) t:check(a, c.name .. ": " .. tostring(err)) @@ -63,7 +58,6 @@ for _, c in Cases do end t:note("%d reference files match ffmpeg", #Cases) --- details of particular files local function case(name: string): any for _, c in Cases do if c.name == name then @@ -86,7 +80,6 @@ do t:check(s12.meta.source.bitDepth == 12 and maxDiff(s12.samples, 0, buffer.fromstring(s16.ref), 0, s16.frames * 2) < 1e-6, "12-bit sample size") local sw = Aiff.info(reader(case("ffmpeg-sowt").data)) t:check(sw and sw.compression == "sowt" and sw.format == "s16le", "info: sowt") - -- inside a bigger buffer local c = case("ffmpeg-s16be") local big = buffer.create(#c.data + 9) buffer.writestring(big, 5, c.data) @@ -114,7 +107,6 @@ for _, e in Enc do end t:note("%d encoder outputs read back by ffmpeg and by us", #Enc) --- encoder: tags, odd sizes, errors do local a = Types.Audio.new(44100, 1, 3) buffer.writef32(a.samples, 0, 0.5) @@ -143,7 +135,6 @@ do t:eq(Aiff.sniff(reader("")), 0, "sniff nothing") end --- errors do local _, e = Aiff.decode(reader("FORM\0\0\0\4WAVE")) t:check(e and e.code == Err.CORRUPT, "wrong FORM type: " .. tostring(e)) @@ -160,7 +151,6 @@ do t:check(e4 and e4.code == Err.LIMIT, "maxFrames: LIMIT") end --- fuzz do local samples = {} for i, c in Cases do diff --git a/tests/audio/ape.luau b/tests/audio/ape.luau index 79c77a9..02be12e 100644 --- a/tests/audio/ape.luau +++ b/tests/audio/ape.luau @@ -1,8 +1,5 @@ --- audio/ape tests: every fixture from tools/fixtures/ape.py (mac -c1000 .. -c5000, 8 - 32-bit int and 32-bit float, --- 1 - 8 channels, special frames (silence, pseudo stereo), odd rates and lengths, a second frame, APEv2 tags, the FATE --- sample of an older 3.99 encoder cut mid-frame) decoded bit-exact against `mac -d`; seeking; f32 scaling and output --- reuse; decode() from a sub-range Reader; an ID3v2 tag in front; the header facts; sniff; the api; a damaged frame --- (CRC); the fuzz pass. Fixtures: tools/fixtures/ape.py. +-- audio/ape tests: tools/fixtures/ape.py's files (mac -c1000 .. -c5000, a FATE 3.99 sample) bit-exact against `mac -d`. +-- Fixtures: tools/fixtures/ape.py. local T = require("@tests/T") local Ape = require("@rosetta/audio/ape") local Bytes = require("@rosetta/core/Bytes") @@ -30,7 +27,6 @@ for _, name in { "s16_c2000", "tags", "f32", "ch6" } do L.subrange(t, Ape, byName[name], "ape") end --- header facts do local d = open(byName.s16_c5000.data) t:eq(d.level, "insane", "level") @@ -50,7 +46,6 @@ do t:check(dec and (L.all(dec, fx)) == fx.crc, "ID3v2 in front") end --- the api do local fx = byName.s16_c2000 local _ = fx @@ -79,7 +74,6 @@ do t:eq(Ape.sniff(Bytes.reader(buffer.fromstring("RIFF"))), 0, "sniff RIFF") end --- the fuzz pass local samples = {} for _, name in { "s16_c2000", "s16_c4000", "mono", "s24", "s32", "f32", "ch6", "silence", "pseudo_stereo" } do table.insert(samples, buffer.fromstring(byName[name].data)) diff --git a/tests/audio/au.luau b/tests/audio/au.luau index 7de870c..24ef135 100644 --- a/tests/audio/au.luau +++ b/tests/audio/au.luau @@ -1,6 +1,5 @@ --- audio/au tests: files written by ffmpeg and sox in every encoding (8 / 16 / 24 / 32-bit, float, double, mu-law, --- A-law, an annotation) against ffmpeg's decode; streaming reads and seeks; our encoder's output for every encoding --- decoded by ffmpeg (fixture step) and by us; an unknown data size; errors; fuzz. Fixtures: tools/fixtures/au.py. +-- audio/au tests: files written by ffmpeg and sox against ffmpeg's decode; our encoder's output via ffmpeg. +-- Fixtures: tools/fixtures/au.py. local T = require("@tests/T") local Au = require("@rosetta/audio/au") local Bytes = require("@rosetta/core/Bytes") diff --git a/tests/audio/brstm.luau b/tests/audio/brstm.luau index 0304901..ca7aa33 100644 --- a/tests/audio/brstm.luau +++ b/tests/audio/brstm.luau @@ -1,6 +1,5 @@ --- audio/brstm tests: BRSTM / BCSTM / BFSTM files (DSP ADPCM, PCM16, PCM8; big- and little-endian; loops) from our --- Python writer, bit-exact with vgmstream (tools/fixtures/brstm.py) through decode and open with seeks (forward seeks --- start from the ADPC / SEEK history table); errors; the api; the fuzz pass. +-- audio/brstm tests: BRSTM / BCSTM / BFSTM files from our Python writer, bit-exact with vgmstream (forward seeks +-- start from the ADPC / SEEK history table). Fixtures: tools/fixtures/brstm.py. local T = require("@tests/T") local Brstm = require("@rosetta/audio/brstm") local Bytes = require("@rosetta/core/Bytes") diff --git a/tests/audio/caf.luau b/tests/audio/caf.luau index 69b938d..2cec86f 100644 --- a/tests/audio/caf.luau +++ b/tests/audio/caf.luau @@ -1,7 +1,5 @@ --- audio/caf tests: ALAC CAF from ffmpeg bit-exact; AAC CAF (ffmpeg's ADTS frames wrapped by the fixture) against --- ffmpeg's float decode; our CAF writer (PCM 16 / 24-bit, ALAC; re-encoded here and compared with the bytes ffmpeg --- decoded bit-exactly); PCM layouts (little / big endian, float) through our writer + a hand-built header; info tags; --- seek; errors; the fuzz no-throw pass. Fixtures: tools/fixtures/m4a.py. +-- audio/caf tests: ALAC CAF from ffmpeg bit-exact; AAC CAF against ffmpeg's float decode; our writer's bytes. +-- Fixtures: tools/fixtures/m4a.py. local T = require("@tests/T") local Caf = require("@rosetta/audio/caf") local Bytes = require("@rosetta/core/Bytes") @@ -128,7 +126,6 @@ do t:check(le and math.abs(buffer.readf32(le.samples, 4) - 0.5) < 1e-7 and math.abs(buffer.readf32(le.samples, 16) + 1) < 1e-7, "24-bit LE values") end --- seek do local c = Alac[#Alac] local whole = Caf.decode(reader(c.data)) :: any @@ -145,7 +142,6 @@ do end end --- errors do t:eq(Caf.sniff(reader("caff\0\2\0\0")), 0, "sniff: wrong version") local _, e = Caf.decode(reader("caff\0\1\0\0")) @@ -154,7 +150,6 @@ do t:check(e2 and e2.code == Err.ARG, "bad codec: " .. tostring(e2)) end --- fuzz do local samples = {} for _, c in Alac do diff --git a/tests/audio/flac.luau b/tests/audio/flac.luau index ba87253..354b166 100644 --- a/tests/audio/flac.luau +++ b/tests/audio/flac.luau @@ -1,8 +1,5 @@ --- audio/flac tests: every fixture from tools/fixtures/flac.py (flac 0-8, 4-32 bits, 1-6 channels, odd rates and block --- sizes, LPC order 32, wasted bits, every stereo mode, ffmpeg's encoder, Ogg FLAC, ID3v2 in front) decoded bit-exact --- against `flac -d`; sample-accurate seeking; f32 scaling and output reuse; decode() to an Audio from a sub-range --- Reader; tags and pictures; the length from the last frame; sniff; the api; damaged frames skipped; the fuzz pass. --- Ported from flac-luau tests/flac.luau. Fixtures: tools/fixtures/flac.py. +-- audio/flac tests: tools/fixtures/flac.py's files (flac 0-8, ffmpeg's encoder, Ogg FLAC) bit-exact against `flac -d`. +-- Fixtures: tools/fixtures/flac.py. local T = require("@tests/T") local VorbisComment = require("@rosetta/codecs/audio/VorbisComment") local Flac = require("@rosetta/audio/flac") @@ -23,7 +20,7 @@ for _, c in Cases do end t:eq(Flac.name, "flac", "name") -t:check(Flac.caps.decode and Flac.caps.encode, "caps") -- encode: ws-audio (tests/audio/flac_encode.luau) +t:check(Flac.caps.decode and Flac.caps.encode, "caps") local seekChecks = 0 for _, fx in Cases do @@ -53,7 +50,6 @@ for _, fx in Cases do t:eq(n, fx.frames, name .. ": decoded frames") t:eq(crc, fx.crc, name .. ": samples identical to flac -d") t:eq(select(2, dec:position()), fx.frames, name .. ": position at end") - -- f32 scaling, output reuse dec:seekSample(0) local reuse = buffer.create(100 * ch * 4) local f, gotf = dec:read(100, reuse) @@ -66,7 +62,6 @@ for _, fx in Cases do end end t:eq(bad, 0, name .. ": f32 samples") - -- seeking local rand = T.rng(99) local targets = { 0, 1, fx.frames - 1, fx.frames // 2, 4096, 4095, 4097, 1152, 1151 } for _ = 1, 12 do @@ -100,7 +95,6 @@ for _, fx in Cases do end t:note("%d fixtures bit-exact against flac -d, %d seeks", #Cases, seekChecks) --- decode() from a sub-range Reader for _, name in { "s16_l5", "ogg_s16", "id3", "s24_96k" } do local fx = byName[name] local big = buffer.create(#fx.data + 13) @@ -113,7 +107,6 @@ for _, name in { "s16_l5", "ogg_s16", "id3", "s24_96k" } do t:eq(a.meta.source.bitDepth, fx.bps, name .. ": meta.source") end --- tags and pictures do local dec = open(byName.s16_noseek.data) t:check(#dec.pictures == 1 and dec.pictures[1].mime == "image/png" and dec.pictures[1].width == 1, "picture") @@ -142,7 +135,6 @@ for _, name in { "s16_l5", "varblock", "bs17" } do t:check(n == fx.frames and crc == fx.crc, name .. ": decode without total length") end --- sniff, errors, the api do t:eq(Flac.sniff(Bytes.reader(buffer.fromstring("ID3\4\0\0\0\0\0\2xxfLaC"))), 1, "sniff ID3 + fLaC") t:eq(Flac.sniff(Bytes.reader(buffer.fromstring("ID3\4\0\0\0\0\0\2xx\255\251"))), 0, "sniff ID3 + mp3") @@ -157,7 +149,7 @@ do t:check(a and a.frames == fx.frames, "F.audio.load") local d = F.audio.open(byName.s16_l3.data) t:check(d and d.frames == byName.s16_l3.frames, "F.audio.open") - local saved, se = F.save(a, nil, { format = "flac" }) -- the encoder (ws-audio) + local saved, se = F.save(a, nil, { format = "flac" }) t:check(saved and F.audio.load(saved).frames == fx.frames, "F.save flac: " .. tostring(se)) end @@ -178,7 +170,6 @@ do t:check(total < d.frames and total >= d.frames - 2 * 4096, "one damaged frame dropped: " .. total) end --- fuzz local samples = {} for _, name in { "s16_l5", "ogg_s16", "id3", "varblock", "s32_rice2", "u8_mono", "bits4" } do table.insert(samples, byName[name].data) diff --git a/tests/audio/flac_encode.luau b/tests/audio/flac_encode.luau index 50617c2..893ffa7 100644 --- a/tests/audio/flac_encode.luau +++ b/tests/audio/flac_encode.luau @@ -1,7 +1,5 @@ --- audio/flac encoder tests: every fixture-step encode (levels 0-8, 1 / 2 / 6 channels, 8 / 12 / 16 / 20 / 24 bits, --- odd lengths and block sizes, odd rates, seek tables, padding) passed `flac -t` and carries the MD5 of the quantized --- input; sizes within 10% of libFLAC at the same level; each decodes bit-exactly through our own decoder; streaming --- from a Decoder gives the same bytes; tags; option errors. Fixtures: tools/fixtures/flac_enc.py. +-- audio/flac encoder tests: each fixture-step encode passed `flac -t`, has the input's MD5, is within 10% of libFLAC. +-- Fixtures: tools/fixtures/flac_enc.py. local T = require("@tests/T") local Flac = require("@rosetta/audio/flac") local Bytes = require("@rosetta/core/Bytes") @@ -88,7 +86,6 @@ do t:check(e0 and e0.frames == 0, "empty audio") end --- errors do local a = Types.Audio.new(44100, 2, 10) local function code(v: any, o: any): string? diff --git a/tests/audio/m4a.luau b/tests/audio/m4a.luau index 0e18208..c6e1924 100644 --- a/tests/audio/m4a.luau +++ b/tests/audio/m4a.luau @@ -1,8 +1,5 @@ --- audio/m4a tests: ALAC files from ffmpeg decode bit-exactly (16 / 24-bit, mono / stereo / 5.1, partial frames); --- AAC-LC files from ffmpeg and fdkaac (stereo / mono / 5.1, 8 - 96 kHz, PNS / intensity / M/S / TNS) against ffmpeg's --- float decode (SNR, gapless length through the edit list); HE-AAC / HE-AACv2 play their core; our ALAC writer --- (re-encoded here, compared with the bytes ffmpeg decoded bit-exactly and MP4Box accepted in the fixture step); tags --- and cover art round trips; streaming reads, seeking; the contract; the fuzz no-throw pass. +-- audio/m4a tests: ALAC from ffmpeg bit-exact; AAC from ffmpeg and fdkaac against ffmpeg's float decode (gapless). +-- our ALAC writer's bytes as ffmpeg decoded them bit-exactly and MP4Box accepted in the fixture step. -- Fixtures: tools/fixtures/m4a.py. local T = require("@tests/T") local M4a = require("@rosetta/audio/m4a") @@ -22,7 +19,6 @@ local function reader(s: string | buffer): Bytes.Reader return Bytes.reader(if type(s) == "string" then buffer.fromstring(s) else s) end --- the integers of a decoded Audio (exact for <= 24-bit sources), CRC-32 as little-endian int32 local function intCrc(a: any, bits: number): number local n = a.frames * a.channels local b = buffer.create(n * 4) @@ -49,12 +45,10 @@ local function snr(a: any, ref: string): (number, number) return 10 * math.log10(sig / err), n end --- the contract t:eq(M4a.name, "m4a", "name") t:eq(M4a.category, "audio", "category") t:check(M4a.caps.decode and M4a.caps.encode, "caps") --- ALAC from ffmpeg: bit-exact for _, c in Alac do if c.container ~= "m4a" then continue @@ -70,7 +64,6 @@ for _, c in Alac do end t:note("%d ffmpeg ALAC files decode bit-exactly", #Alac - 1) --- AAC: against ffmpeg's float decode local worst = math.huge for _, c in Aac do if c.container ~= "m4a" then @@ -102,7 +95,6 @@ for _, c in He do t:check(n == 8192 and e > 1, c.name .. ": the core decodes (energy " .. e .. ")") end --- our ALAC writer: the bytes ffmpeg validated do local byName = {} for _, o in Ours do @@ -141,7 +133,6 @@ do end end --- cover art + streaming a decoder into the encoder do local a = Signal.audio(44100, 5000, 2, 16, 9) a.meta.pictures = { { mime = "image/png", data = buffer.fromstring("\137PNG fake") } } @@ -164,7 +155,6 @@ for _, c in { Aac[1], Alac[1] } do local whole = M4a.decode(reader(c.data)) :: any local dec = M4a.open(reader(c.data)) :: any t:eq(dec.frames, whole.frames, c.name .. ": decoder frames") - -- read in odd chunks local got, out = 0, buffer.create(whole.frames * whole.channels * 4) while true do local b, n = dec:read(777) @@ -188,7 +178,6 @@ for _, c in { Aac[1], Alac[1] } do end end --- errors do local _, e = M4a.decode(reader("\0\0\0\8ftypM4A ")) t:check(e ~= nil, "a lone ftyp: " .. tostring(e)) @@ -197,7 +186,6 @@ do t:eq(M4a.sniff(reader("hello")), 0, "sniff junk") end --- fuzz do local samples = {} for i, c in Alac do diff --git a/tests/audio/mp3.luau b/tests/audio/mp3.luau index f1252cb..c80037c 100644 --- a/tests/audio/mp3.luau +++ b/tests/audio/mp3.luau @@ -1,8 +1,5 @@ --- audio/mp3 tests: every fixture against its minimp3 reference decode (exact length, SNR > 90 dB on windows, block --- energies) and against ffmpeg (length, SNR > 75 dB), lame-written streams against ffmpeg; chunked reads, reads into --- a caller buffer, sample-accurate seeking; robustness (garbage, corruption, truncation, mono / stereo switches, API --- misuse); ID3v1 / v2.2 / 2.3 / 2.4 and APE tags; the contract, sniff, decode to Audio, the fuzz no-throw pass. --- Ported from mp3-luau tests/decode.luau, robust.luau, tags.luau. Fixtures: tools/fixtures/mp3.py. +-- audio/mp3 tests: every fixture against its minimp3 reference decode (SNR > 90 dB) and ffmpeg (SNR > 75 dB). +-- Fixtures: tools/fixtures/mp3.py. local T = require("@tests/T") local Mp3 = require("@rosetta/audio/mp3") local Bytes = require("@rosetta/core/Bytes") @@ -78,13 +75,11 @@ end local rand = T.rng(12345) --- ------------------------------------------------------------------------------------------------ contract t:eq(Mp3.name, "mp3", "name") t:eq(Mp3.category, "audio", "category") t:check(table.find(Mp3.extensions, "mp3") ~= nil and table.find(Mp3.extensions, "mp2") ~= nil, "extensions") -t:check(Mp3.caps.decode and Mp3.caps.encode and Mp3.open ~= nil, "caps") -- encode: ws-audio (tests/audio/mp3_encode.luau) +t:check(Mp3.caps.decode and Mp3.caps.encode and Mp3.open ~= nil, "caps") --- ------------------------------------------------------------------------------------------------ decode vs references for _, c in Cases do local name = c.name local buf = buffer.fromstring(c.data) @@ -105,7 +100,6 @@ for _, c in Cases do t:eq(dec.frames, c.ffFrames, name .. ": frames vs ffmpeg") t:check(dec.bitrate > 0, name .. ": bitrate") - -- whole decode in chunks of varied sizes local all = buffer.create(dec.frames * ch * 4) local total = 0 while true do @@ -184,7 +178,6 @@ for _, c in Cases do local pcm0, n3 = dec:read(256) t:check(n3 == 256 and maxDiff(pcm0, 0, all, 0, 256 * ch) == 0, name .. ": seek back to the start") - -- decode to Audio, also from a sub-range of a bigger buffer local big = buffer.create(buffer.len(buf) + 17) buffer.copy(big, 9, buf) local a, aerr = Mp3.decode(Bytes.reader(big, 9, buffer.len(buf))) @@ -196,7 +189,6 @@ for _, c in Cases do t:note("%-20s L%d MPEG-%s %5d Hz %d ch %6d frames %3d kbps SNR minimp3 %s, ffmpeg %.1f dB", name, dec.layer, tostring(dec.version), dec.sampleRate, ch, dec.frames, dec.bitrate // 1000, if ref then string.format("%.1f", worst) else "-", worstFF) end --- ------------------------------------------------------------------------------------------------ robustness local function concat(...: buffer): buffer local n = 0 for _, b in { ... } do @@ -215,7 +207,6 @@ local function slice(b: buffer, i: number, j: number): buffer buffer.copy(out, 0, b, i, j - i) return out end --- decodes everything; checks every sample is finite; returns pcm, frames, decoder local function decodeAll(b: buffer, label: string): (buffer?, number, any) local ok, dec, err = pcall(open, b) t:check(ok, label .. ": open does not throw (" .. tostring(dec) .. ")") @@ -303,7 +294,6 @@ do end t:check(same, "switch: mono part duplicated") end --- bad input and API misuse do local d, err = open(buffer.create(0)) t:check(d == nil and Err.is(err) and err.code == Err.CORRUPT, "empty buffer") @@ -333,7 +323,6 @@ do t:eq(Mp3.sniff(Bytes.reader(buffer.create(0))), 0, "sniff nothing") end --- ------------------------------------------------------------------------------------------------ tags local function eq(a: any, b: any, label: string) t:eq(a, b, label) end @@ -478,7 +467,6 @@ do t:check(dec == nil or dec.frames <= plain.frames, "truncated tag") end --- ------------------------------------------------------------------------------------------------ through the api do local F = require("@rosetta") local data = byName.l3_tags.data @@ -487,11 +475,10 @@ do t:check(a and a.kind == "audio" and a.frames == 22050 and a.tags.title == "Test Title", "F.audio.load: " .. tostring(err)) local dec = F.audio.open(data) t:check(dec and dec.sampleRate == 44100 and dec.frames == 22050, "F.audio.open") - local saved, serr = F.save(a, nil, { format = "mp3" }) -- the layer III encoder (ws-audio) + local saved, serr = F.save(a, nil, { format = "mp3" }) t:check(saved and F.audio.load(saved).sampleRate == 44100, "F.save mp3: " .. tostring(serr)) end --- ------------------------------------------------------------------------------------------------ fuzz do local samples = {} for _, name in { "l3_cbr32_mono", "l3_mpeg2_22k", "l3_mpeg25_8k", "l2_64_mono", "l2_mpeg2_24k", "l3_tags", "lame_cbr64_mono_22k" } do diff --git a/tests/audio/mp3_encode.luau b/tests/audio/mp3_encode.luau index e7adf34..14db6fb 100644 --- a/tests/audio/mp3_encode.luau +++ b/tests/audio/mp3_encode.luau @@ -1,7 +1,5 @@ --- audio/mp3 encoder tests (layer III and layer II): every fixture-step encode (sample rates of MPEG-1 / 2 / 2.5, --- bit rates 24 .. 384 kbps, stereo / joint / mono) decodes in ffmpeg without errors and in LAME, with the expected --- length and an SNR over a per-bit-rate floor after aligning the decoder delay; our own decoder (the minimp3 port) --- agrees; streaming from a Decoder gives the same bytes; the ID3v2 tag round-trips; option errors. +-- audio/mp3 encoder tests (layer III and II): fixture-step encodes decode in ffmpeg and LAME, SNR over a per-bit-rate +-- floor after aligning the decoder delay. -- Fixtures: tools/fixtures/mp3_enc.py. local T = require("@tests/T") local Mp3 = require("@rosetta/audio/mp3") @@ -21,7 +19,6 @@ local function audio(name: string): Types.Audio return a end --- SNR of y (delayed by lag frames) against x over frames [from, to) local function snr(x: Types.Audio, y: Types.Audio, lag: number, from: number, to: number): number local ch = x.channels local sig, er = 0, 0 @@ -85,7 +82,6 @@ for _, e in Enc do if f > -math.huge then minByLayer[e.layer] = math.min(minByLayer[e.layer], e.ffSnr) end - -- our decoder agrees with ffmpeg local x = audio(e.sig) local y, err = Mp3.decode(Bytes.reader(buffer.fromstring(e.data))) t:check(y, e.name .. ": our decoder: " .. tostring(err)) @@ -96,7 +92,6 @@ for _, e in Enc do end t:note("%d encodes: ffmpeg + LAME decode them; lowest SNR layer III %.1f dB, layer II %.1f dB", #Enc, minByLayer[3], minByLayer[2]) --- streaming, tags, defaults do local a = audio("music_2_44100") local f1 = Mp3.encode(a, { bitrate = 128 }) :: buffer @@ -128,8 +123,7 @@ do t:check(empty and buffer.len(empty) > 0, "empty input: one flush frame") end --- other input rates are resampled (codecs/audio/Resample) to the next rate up: 44 kHz -> 44.1 kHz, 46 kHz -> 48 kHz, --- layer II 8 kHz -> 16 kHz, opts.sampleRate +-- other input rates are resampled to the next rate up (codecs/audio/Resample) do local function tone(rate: number, f: number): any local n = rate @@ -166,7 +160,6 @@ do end end --- errors do local function code(v: any, o: any): string? local _, e = Mp3.encode(v, o) diff --git a/tests/audio/mpc.luau b/tests/audio/mpc.luau index ea60b6a..785d6fb 100644 --- a/tests/audio/mpc.luau +++ b/tests/audio/mpc.luau @@ -1,7 +1,5 @@ --- audio/mpc tests: Musepack SV8 (mpcenc 1.30: stereo / mono, 32 / 44.1 / 48 kHz, quality 1 .. 9, 1 / 4 / 16 / 64 --- frames per packet) and SV7 (mppenc 1.16, quality 2 / 5 / 8) against libmpcdec's float output (mpcf32: gapless --- length, near bit-exact) and ffmpeg's decode (SNR); APEv2 tags; seeking (SV8 exact, SV7 like libmpcdec); a leading --- ID3v2 tag; truncated files; error codes; the fuzz no-throw pass. Fixtures: tools/fixtures/mpc.py. +-- audio/mpc tests: Musepack SV8 (mpcenc 1.30) and SV7 (mppenc 1.16) against libmpcdec's float output and ffmpeg. +-- Fixtures: tools/fixtures/mpc.py. local T = require("@tests/T") local Mpc = require("@rosetta/audio/mpc") local Bytes = require("@rosetta/core/Bytes") @@ -15,7 +13,6 @@ local function reader(s: string): Bytes.Reader return Bytes.reader(buffer.fromstring(s)) end --- SNR (dB) and the largest difference of frames [from, to) of got against a f32le reference (frames from 0) local function compare(got: buffer, gotFrom: number, ref: string, ch: number, frames: number): (number, number) local rb = buffer.fromstring(ref) local n = math.min(frames * ch, #ref // 4) @@ -64,8 +61,7 @@ for _, c in Fx do end end --- seeking: SV8 is exact (one packet of pre-roll); SV7 decodes like libmpcdec's seek (32 frames of pre-roll from reset --- scalefactors) +-- SV8 seeks exactly; SV7 like libmpcdec's seek (32 frames of pre-roll from reset scalefactors) for _, sk in Seek do local c = byName[sk.name] local whole = Mpc.decode(reader(c.data)) :: any @@ -94,7 +90,6 @@ for _, sk in Seek do t:check(n0 == 1000 and d0 < 1e-5, sk.name .. ": seek back to 0") end --- an ID3v2 tag in front; truncated files do local c = byName.sv8_q5_stereo local id3 = "ID3\3\0\0\0\0\0\20" .. string.rep("\0", 20) @@ -112,7 +107,6 @@ do end end --- errors do local c8, c7 = byName.sv8_q5_stereo.data, byName.sv7_q5_stereo.data t:eq(Mpc.sniff(reader("RIFF....WAVE")), 0, "sniff a WAV") @@ -131,7 +125,6 @@ do t:check(e and e.code == Err.LIMIT, "maxFrames: " .. tostring(e)) end --- fuzz do local samples = {} for _, c in Fx do diff --git a/tests/audio/opus.luau b/tests/audio/opus.luau index 00094fe..3f54bee 100644 --- a/tests/audio/opus.luau +++ b/tests/audio/opus.luau @@ -1,9 +1,5 @@ --- audio/opus tests: every fixture (opusenc / ffmpeg libopus: CELT frame sizes and bitrates, SILK NB / MB / WB, hybrid, --- mode transitions, 5.1 multistream, a long tagged file) through open / read against opusdec --float (frame counts, --- SNR per fixture), CELT-only and SILK-only decoding with the private decoders alone, SILK packet loss concealment, --- tags, seeking, the stereo downmix, decode() to an Audio, the contract, sniff, error codes, random / bit-flipped --- packets through the packet decoder, and the fuzz no-throw pass over whole files. --- Ported from opus-luau tests/opus.luau, celt.luau, silk.luau, fuzz.luau. Fixtures: tools/fixtures/opus.py. +-- audio/opus tests: every fixture (opusenc / ffmpeg libopus) against opusdec --float (frame counts, SNR per fixture). +-- Fixtures: tools/fixtures/opus.py. local T = require("@tests/T") local Opus = require("@rosetta/audio/opus") local Packet = require("@rosetta/codecs/audio/Opus/Packet") @@ -58,7 +54,6 @@ do Pcm.reorder(fx.ref, 0, buffer.len(fx.ref) // 24, 6, Pcm.WAVE_FROM_VORBIS[6]) end --- SNR in dB of f32 samples against a reference over n samples; returns snr, max abs error local function snr(out: buffer, ref: buffer, n: number, outOff: number?, refOff: number?): (number, number) local oo, ro = outOff or 0, refOff or 0 local sig, err, maxe = 0, 0, 0 @@ -77,7 +72,6 @@ local function snr(out: buffer, ref: buffer, n: number, outOff: number?, refOff: return 10 * math.log10(sig / err), maxe end --- the packets of the first stream: { data, offset, size } local function packets(buf: buffer): { any } local d = Ogg.open(buf) local out = {} @@ -87,7 +81,6 @@ local function packets(buf: buffer): { any } return out end --- ------------------------------------------------------------------------------------------------ contract t:eq(Opus.name, "opus", "name") t:eq(Opus.category, "audio", "category") t:check(Opus.caps.decode and Opus.caps.encode and Opus.open ~= nil and Opus.decode ~= nil and Opus.encode ~= nil, "caps (the CELT encoder: tests/audio/opus_encode.luau)") @@ -95,7 +88,6 @@ t:eq(Opus.sniff(Bytes.reader(FX.celt_st_128.data)), 1, "sniff an Opus file") t:eq(Opus.sniff(Bytes.reader(buffer.fromstring("OggS" .. string.rep("\0", 40)))), 0, "sniff another Ogg") t:eq(Opus.sniff(Bytes.reader(buffer.create(0))), 0, "sniff nothing") --- ------------------------------------------------------------------------------------------------ open / read vs opusdec -- name, minimum SNR (dB). CELT is float-exact (> 130 dB in practice), SILK bit-exact; hybrid / transitions mix both. local cases = { { "celt_st_128", 100 }, { "celt_st_32", 100 }, { "celt_st_64", 100 }, { "celt_st_256", 100 }, @@ -134,7 +126,6 @@ for _, case in cases do t:check(math.abs(dec:position() - dec.duration) < 1e-9, name .. ": position at end") end --- read into a caller buffer, decode() to an Audio, a sub-range Reader do local fx = FX.hybrid_st local dec = Opus.open(Bytes.reader(fx.data)) @@ -151,7 +142,6 @@ do t:eq(a.meta.source.format, "opus", "decode: meta.source") end --- ------------------------------------------------------------------------------------------------ tags, seeking do local dec = Opus.open(Bytes.reader(FX.long_128.data)) t:eq(dec.tags.title, "Long Test", "tags: title") @@ -203,7 +193,6 @@ do t:check(db > 100, string.format("downmix SNR %.1f", db)) end --- ------------------------------------------------------------------------------------------------ CELT alone do local endbands = { [Packet.BW_NB] = 13, [Packet.BW_MB] = 17, [Packet.BW_WB] = 17, [Packet.BW_SWB] = 19, [Packet.BW_FB] = 21 } for _, name in { "celt_st_128", "celt_st_32", "celt_st_64", "celt_st_256", "celt_mono_64", "celt_fs2_5", "celt_fs5", "celt_fs10", "celt_fs40", "celt_fs60", "ff_cbr", "ff_lowdelay" } do @@ -243,7 +232,6 @@ do end end --- ------------------------------------------------------------------------------------------------ SILK alone do local rates = { [Packet.BW_NB] = 8000, [Packet.BW_MB] = 12000, [Packet.BW_WB] = 16000 } local function decodeSilk(name: string, hybridOk: boolean?, lose: boolean?): ({ number }, number, number, number) @@ -323,7 +311,6 @@ do end end --- ------------------------------------------------------------------------------------------------ errors do local d, err = Opus.open(Bytes.reader(buffer.fromstring("not an ogg file at all"))) t:check(d == nil and err and err.code == Err.CORRUPT, "garbage is CORRUPT: " .. tostring(err)) @@ -371,8 +358,7 @@ do end end --- ------------------------------------------------------------------------------------------------ packet fuzz --- random packets (every TOC config, random payloads) and bit-flipped real packets: never throw, output finite +-- random packets (every TOC config) and bit-flipped real packets: never throw, output finite do local rand = T.rng(987654321) local pcm = table.create(5760 * 2, 0) @@ -431,7 +417,6 @@ do t:note("packet fuzz: %d packets decoded, %d rejected", decoded, rejected) end --- ------------------------------------------------------------------------------------------------ fuzz (whole files) do local samples = {} for _, name in { "hybrid_fb", "silk_nb", "celt_fs5" } do diff --git a/tests/audio/opus_encode.luau b/tests/audio/opus_encode.luau index 1952ac3..b49794b 100644 --- a/tests/audio/opus_encode.luau +++ b/tests/audio/opus_encode.luau @@ -1,7 +1,4 @@ --- audio/opus encoder tests (the CELT-only writer, ws-m4a; mono and mid / side stereo): our Ogg Opus files (re-encoded here, compared with the bytes --- checked in the fixture step) decode in libopus' opusdec to the input's exact length (pre-skip + end trimming) with a --- minimum SNR, opusinfo finds no problem, ffmpeg reads them, OpusTags carry the tags; our decoder agrees with opusdec; --- resampled 44.1 kHz input; silence frames; streaming input; errors; a fuzz no-throw pass over our files. +-- audio/opus encoder tests (CELT-only): our Ogg Opus decodes in opusdec to the input's exact length, opusinfo-clean. -- Fixtures: tools/fixtures/opus_celt.py. local T = require("@tests/T") local Opus = require("@rosetta/audio/opus") @@ -46,7 +43,6 @@ for _, c in Cases.list do local ch = c.channels t:eq(#fx.opusdec // (4 * ch), frames48, c.name .. ": opusdec length = the input's (pre-skip + end trimming)") t:eq(fx.ffmpegFrames, frames48, c.name .. ": ffmpeg length") - -- our decoder vs opusdec local ours = Opus.decode(Bytes.reader(file :: buffer)) :: any t:eq(ours.frames, frames48, c.name .. ": our decoder's length") local ref = buffer.fromstring(fx.opusdec) @@ -66,7 +62,6 @@ for _, c in Cases.list do end end --- silence frames decode to silence do local c = Cases.list[1] local ref = buffer.fromstring(byName[c.name].opusdec) @@ -77,7 +72,6 @@ do t:check(peak < 1e-3, "digital silence stays silent (peak " .. peak .. ")") end --- a streaming decoder as the input do local c = Cases.list[1] local dec = Opus.open(Bytes.reader(files[1] :: buffer)) :: any @@ -90,7 +84,6 @@ do t:check(kb ~= nil and buffer.tostring(kb :: buffer) == buffer.tostring(again :: buffer), "bitrate 64 = 64000 bit/s") end --- errors do local three = Cases.signal({ rate = 48000, channels = 3, seconds = 0.05 }) local _, e = Opus.encode(three) @@ -101,7 +94,6 @@ do t:check(e3 and e3.code == Err.ARG, "not audio") end --- fuzz the decoder over our files do local samples = {} for i, f in files do diff --git a/tests/audio/qoa.luau b/tests/audio/qoa.luau index 4e03808..0858af5 100644 --- a/tests/audio/qoa.luau +++ b/tests/audio/qoa.luau @@ -1,7 +1,5 @@ --- audio/qoa tests: files written by qoa.h (tools/fixtures/qoa.py; 1, 2 and 6 channels, a frame boundary, a partial --- last slice, clipping signals) decoded bit-exact against ffmpeg and qoa.h; our encoder byte-for-byte equal to --- qoa.h's qoa_encode, from an Audio and from a streaming Decoder; seeking; streaming files (total 0); a cut file; errors; --- the api; the fuzz pass. +-- audio/qoa tests: qoa.h's files bit-exact against ffmpeg and qoa.h; our encoder byte-for-byte equal to qoa_encode. +-- Fixtures: tools/fixtures/qoa.py. local T = require("@tests/T") local Qoa = require("@rosetta/audio/qoa") local Bytes = require("@rosetta/core/Bytes") @@ -51,7 +49,6 @@ for _, c in Cases do end t:note("%d qoa.h files decoded bit-exact (ffmpeg, qoa.h) and re-encoded byte-for-byte", #Cases) --- ------------------------------------------------------------------------------------------------ variants do local c = Cases[1] local ref = buffer.fromstring(c.ref) @@ -64,7 +61,6 @@ do -- a cut file keeps its whole frames local cut = Qoa.decode(Bytes.reader(buffer.fromstring(string.sub(c.data, 1, #c.data - 100)))) :: any t:check(cut and cut.frames == 5120 * 2 and H.same(cut.samples, ref, 0, cut.frames * c.ch), "cut file: the whole frames") - -- errors local _, e1 = Qoa.open(Bytes.reader(buffer.fromstring("qoaf\0\0\0\1"))) t:check(e1 and e1.code == Err.TRUNCATED, "no frames: " .. tostring(e1)) local bad = buffer.fromstring(c.data) diff --git a/tests/audio/tta.luau b/tests/audio/tta.luau index 732671f..e7bea11 100644 --- a/tests/audio/tta.luau +++ b/tests/audio/tta.luau @@ -1,8 +1,5 @@ --- audio/tta tests: every fixture from tools/fixtures/tta.py (ttaenc 3.4.1: 8 / 16 / 24 bits, 1 - 6 channels, odd --- rates and lengths, several frames, silence, noise; the FATE sample inside.tta cut mid-file) decoded bit-exact --- against `ttaenc -d`; seeking; f32 scaling and output reuse; decode() from a sub-range Reader; an ID3v2 tag in front --- and an APEv2 tag at the end; password-protected files (UNSUPPORTED); header / seek table / frame CRCs; sniff; the --- api; the fuzz pass. Fixtures: tools/fixtures/tta.py. +-- audio/tta tests: tools/fixtures/tta.py's files (ttaenc 3.4.1, FATE's inside.tta) bit-exact against `ttaenc -d`. +-- Fixtures: tools/fixtures/tta.py. local T = require("@tests/T") local Tta = require("@rosetta/audio/tta") local Bytes = require("@rosetta/core/Bytes") @@ -72,7 +69,6 @@ do t:eq(Tta.sniff(Bytes.reader(buffer.fromstring("RIFF"))), 0, "sniff RIFF") end --- the api do local fx = byName.s16 t:eq(F.detect(buffer.fromstring(fx.data)), "tta", "detect") @@ -80,7 +76,7 @@ do t:check(a and a.frames == fx.frames and a.meta.source.format == "tta", "F.audio.load") end --- the fuzz pass (the frame CRC rejects most mutations; the second set skips it to reach the decoder) +-- the frame CRC rejects most mutations; the second fuzz set skips it to reach the decoder local samples = {} for _, name in { "s16", "mono", "s24", "u8", "ch6" } do table.insert(samples, buffer.fromstring(byName[name].data)) diff --git a/tests/audio/vag.luau b/tests/audio/vag.luau index c388120..62b3ba7 100644 --- a/tests/audio/vag.luau +++ b/tests/audio/vag.luau @@ -1,6 +1,5 @@ --- audio/vag tests: VAGp (with and without loop flags), VAGi and KVAG files from our Python encoders, bit-exact with --- vgmstream / ffmpeg (tools/fixtures/vag.py) through decode and open with seeks; our encoder's files as vgmstream --- decodes them (loops reported where vgmstream reads them), their quality; errors; the api; the fuzz pass. +-- audio/vag tests: VAGp, VAGi and KVAG files from our Python encoders, bit-exact with vgmstream / ffmpeg. +-- Fixtures: tools/fixtures/vag.py. local T = require("@tests/T") local Vag = require("@rosetta/audio/vag") local Bytes = require("@rosetta/core/Bytes") @@ -27,7 +26,6 @@ for _, c in Cases do end t:note("%d files bit-exact with vgmstream / ffmpeg", #Cases) --- ------------------------------------------------------------------------------------------------ encoder local function audioOf(S: any): any local a = Types.Audio.new(S.rate, S.channels, S.frames) buffer.writestring(a.samples, 0, S.data) @@ -57,7 +55,6 @@ do t:check(e3 and e3.code == Err.ARG, "bad interleave") end --- ------------------------------------------------------------------------------------------------ errors do local base = Cases[1].data local hevag = buffer.fromstring(base) diff --git a/tests/audio/voc.luau b/tests/audio/voc.luau index 1df70ee..f96fdaf 100644 --- a/tests/audio/voc.luau +++ b/tests/audio/voc.luau @@ -1,6 +1,4 @@ --- audio/voc tests: files written by ffmpeg (type 1 + 8 blocks for 8-bit, type 9 otherwise) and sox against ffmpeg's --- decode; silence / text / continuation blocks and repeat markers built here; streaming reads and seeks; our --- encoder's output for every sample format decoded by ffmpeg (fixture step) and by us; errors; fuzz. +-- audio/voc tests: files written by ffmpeg and sox against ffmpeg's decode; our encoder's output via ffmpeg. -- Fixtures: tools/fixtures/voc.py. local T = require("@tests/T") local Voc = require("@rosetta/audio/voc") @@ -45,7 +43,6 @@ for _, c in Cases do end t:note("%d reference files match ffmpeg", #Cases) --- hand-built blocks: text, type 1 u8, silence, continuation, repeat markers, terminator do local hdr = "Creative Voice File\26\26\0\10\1\41\17" local function blk(typ: number, payload: string): string diff --git a/tests/audio/vorbis.luau b/tests/audio/vorbis.luau index 89608c7..18943e7 100644 --- a/tests/audio/vorbis.luau +++ b/tests/audio/vorbis.luau @@ -1,7 +1,5 @@ --- audio/vorbis tests: oggenc / ffmpeg streams (qualities -1 .. 10, managed bitrate, 8 .. 96 kHz, mono / stereo / 5.1, --- transients, silence, tags, sub-block lengths) against oggdec (libvorbisfile: sample counts and 16-bit samples, so --- start / end trimming is exact) and ffmpeg's f32 decode (SNR); streaming reads; seeking (sample-exact against the --- reference at the target); the packet-level decoder; errors; fuzz. Fixtures: tools/fixtures/vorbis.py. +-- audio/vorbis tests: oggenc / ffmpeg streams against oggdec (16-bit, exact trimming) and ffmpeg's f32 decode (SNR). +-- Fixtures: tools/fixtures/vorbis.py. local T = require("@tests/T") local Vorbis = require("@rosetta/audio/vorbis") local Bytes = require("@rosetta/core/Bytes") @@ -20,7 +18,6 @@ local function s16(x: number): number local v = math.floor(x * 32768 + 0.5) return math.clamp(v, -32768, 32767) end --- the largest |our sample as s16 - oggdec's| over n samples of ours at byte a0 against ref16 from sample r0 local function maxDiff16(a: buffer, a0: number, ref: buffer, r0: number, n: number): number local m = 0 for i = 0, n - 1 do @@ -76,7 +73,6 @@ for _, c in Cases do minSnr = math.min(minSnr, s) t:check(s > 100, string.format("%s: SNR vs ffmpeg %.1f dB", c.name, s)) end - -- streaming in odd chunks gives the same samples local dec = Vorbis.open(reader(c.data)) :: Types.Decoder t:eq(dec.frames, c.frames, c.name .. ": Decoder.frames") local got, ok = 0, true @@ -117,7 +113,6 @@ local function case(name: string): any error("no case " .. name) end --- tags, meta, sniff, sub-range do local c = case("q2-stereo-32k-tags") local dec = Vorbis.open(reader(c.data)) :: any @@ -164,7 +159,6 @@ do t:check(e and e.code == Err.CORRUPT, "packetDecoder with headers swapped") end --- errors do local _, e1 = Vorbis.decode(reader("OggS but not really")) t:check(e1 and Err.is(e1), "junk: " .. tostring(e1)) diff --git a/tests/audio/vorbis_encode.luau b/tests/audio/vorbis_encode.luau index b7a6c4c..94a5cea 100644 --- a/tests/audio/vorbis_encode.luau +++ b/tests/audio/vorbis_encode.luau @@ -1,7 +1,5 @@ --- audio/vorbis encoder tests: every fixture-step encode (qualities -1 .. 10, mono / stereo / 5.1, 8 .. 96 kHz, odd --- lengths, silence) passes ogginfo, decodes in oggdec (libvorbisfile) with the exact input length and an SNR over a --- per-quality floor, and in ffmpeg; our own decoder gives the same; the codebooks are valid prefix codes; streaming --- from a Decoder gives the same bytes; tags round-trip; option errors. Fixtures: tools/fixtures/vorbis_enc.py. +-- audio/vorbis encoder tests: each fixture-step encode passes ogginfo, decodes in oggdec with the exact length and +-- an SNR over a per-quality floor, and in ffmpeg. Fixtures: tools/fixtures/vorbis_enc.py. local T = require("@tests/T") local Vorbis = require("@rosetta/audio/vorbis") local VEnc = require("@rosetta/audio/vorbis/Encode") @@ -75,7 +73,6 @@ for _, e in Enc do end t:note("%d encodes pass ogginfo / oggdec / ffmpeg; lowest SNR %.1f dB", #Enc, minSnr) --- streaming, tags do local a = audio("music_2_3000_44100") local f1 = Vorbis.encode(a) :: buffer @@ -92,7 +89,6 @@ do t:check(e0 and e0.frames == 0, "empty input") end --- errors do local a = Types.Audio.new(44100, 2, 10) local function code(v: any, o: any): string? diff --git a/tests/audio/wav.luau b/tests/audio/wav.luau index c1a2033..fafae6a 100644 --- a/tests/audio/wav.luau +++ b/tests/audio/wav.luau @@ -1,9 +1,5 @@ --- audio/wav tests: every format / container / damaged variant from tools/fixtures/wav.py decoded in reads of mixed --- sizes against ffmpeg's (or sox's) f32 decode, with tags, seeking and output-buffer reuse; hand-built files (header --- parsing, errors, argument clamping, EXTENSIBLE with valid bits, the truncated flag); the encoder byte-exact against --- ffmpeg -bitexact (u8 / s16 / s24 / s32 / f32, 1-8 channels, > 48 kHz, RF64), round trips from an Audio and from a --- streaming Decoder, tags, encodeParts, the RF64 switch; the api (F.audio.load / open / save); the fuzz pass. --- Ported from wav-luau tests/core.luau + tests/decode.luau. Fixtures: tools/fixtures/wav.py. +-- audio/wav tests: tools/fixtures/wav.py's files against ffmpeg's (or sox's) f32 decode; encoder vs ffmpeg -bitexact. +-- Fixtures: tools/fixtures/wav.py. local T = require("@tests/T") local Wav = require("@rosetta/audio/wav") local Bytes = require("@rosetta/core/Bytes") @@ -63,12 +59,10 @@ local function riff(...: string): string return "RIFF" .. u32(#body) .. body end --- the contract t:eq(Wav.name, "wav", "name") t:eq(Wav.category, "audio", "category") t:check(Wav.caps.decode and Wav.caps.encode and Wav.open ~= nil, "caps / open") --- ------------------------------------------------------------------------------------------------ fixtures local function readAll(dec: any, sizes: { number }): (buffer, number) local out = buffer.create(dec.frames * dec.channels * 4) local got, i = 0, 0 @@ -138,7 +132,6 @@ for _, fx in Cases do end t:note("%d fixture files match ffmpeg / sox", #Cases) --- ------------------------------------------------------------------------------------------------ hand-built files do local dec = open(riff(fmt(1, 2, 8000, 16), chunk("data", i16s(16384, -16384, 32767, -32768)))) t:check(dec, "open minimal") @@ -179,13 +172,13 @@ do -- EXTENSIBLE: 24 valid bits in a 32-bit container local _, e = open(riff(fmt(0xFFFE, 1, 8000, 16), chunk("data", "\0\0"))) t:check(e and e.code == Err.CORRUPT, "extensible without extension") end -do -- tags +do local info = "INFO" .. "INAM" .. u32(3) .. "abc\0" .. "IART" .. u32(6) .. "xy\0\0\0\0" .. "IXYZ" .. u32(2) .. "zz" .. "ITRK" .. u32(2) .. "7\0" local dec = open(riff(fmt(1, 1, 8000, 8), chunk("LIST", info), chunk("data", "\128\128\128"))) t:check(dec and dec.tags.title == "abc" and dec.tags.artist == "xy" and dec.tags.ixyz == "zz" and dec.tags.track == "7", "tags") t:check(dec and dec.frames == 3, "8-bit odd data") end -do -- 8-bit, A-law and mu-law values +do local o = open(riff(fmt(1, 1, 8000, 8), chunk("data", "\0\128\255"))):read(3) t:check(buffer.readf32(o, 0) == -1 and buffer.readf32(o, 4) == 0 and buffer.readf32(o, 8) == 127 / 128, "u8 values") local m = open(riff(fmt(7, 1, 8000, 8), chunk("data", "\255\127\0\128"))):read(4) @@ -195,7 +188,7 @@ do -- 8-bit, A-law and mu-law values t:check(buffer.readf32(a, 0) == 8 / 32768 and buffer.readf32(a, 4) == -8 / 32768, "A-law smallest") t:check(buffer.readf32(a, 8) == -32256 / 32768 and buffer.readf32(a, 12) == 32256 / 32768, "A-law extremes") end -do -- errors: nil, Err +do local function fails(s: any, code: string, pattern: string, label: string) local ok, dec, err = pcall(open, s) t:check(ok, label .. ": threw " .. tostring(dec)) @@ -216,7 +209,6 @@ do -- errors: nil, Err t:eq(Wav.sniff(Bytes.reader(buffer.fromstring("RIFF\0\0\0\0AVI "))), 0, "sniff AVI") end --- ------------------------------------------------------------------------------------------------ encoder do for _, c in Enc do local a = Types.Audio.new(c.rate, c.channels, c.frames) @@ -229,7 +221,6 @@ do t:note("%s: ffmpeg %s", c.name, T.hex(buffer.fromstring(c.file), 80)) end t:check(same, c.name .. ": identical to ffmpeg -bitexact") - -- and back local back = Wav.decode(Bytes.reader(out :: buffer)) t:check(back and back.frames == c.frames and buffer.tostring(back.samples) == c.samples, c.name .. ": round trip") -- from a streaming Decoder (our own, over ffmpeg's file) @@ -238,7 +229,6 @@ do t:check(out2 and buffer.tostring(out2) == c.file, c.name .. ": encode from a Decoder") end t:note("encoder: %d files identical to ffmpeg -bitexact", #Enc) - -- clamping and rounding local a = Types.Audio.new(8000, 1, 6) for i, v in { 2, -2, 0.5 / 32768, -0.5 / 32768, 1.5 / 32768, 0 / 0 } do buffer.writef32(a.samples, (i - 1) * 4, v) @@ -248,7 +238,6 @@ do for i, w in want do t:eq(math.floor(buffer.readf32(d.samples, (i - 1) * 4) * 32768 + 0.5), w, "s16 rounding / clamping " .. i) end - -- tags a.tags = { title = "Hello", artist = "Someone", IXYZ = "kept", comment = "" } local tg = Wav.decode(Bytes.reader(Wav.encode(a, { sampleFormat = "u8" }) :: buffer)) :: any t:check(tg.tags.title == "Hello" and tg.tags.artist == "Someone" and tg.tags.ixyz == "kept" and tg.tags.comment == nil, "tag round trip") @@ -269,7 +258,6 @@ do t:check(rd.container == "RF64" and rd.frames == 3000, "RF64 reads back") t:check(buffer.tostring(rd:read(3000)) == buffer.tostring(Wav.decode(Bytes.reader(Wav.encode(big) :: buffer)).samples), "RF64 samples") t:eq(buffer.readstring(Wav.encode(big) :: buffer, 0, 4), "RIFF", "plain RIFF below the threshold") - -- bad arguments local _, e1 = Wav.encode({} :: any) t:check(e1 and e1.code == Err.ARG, "encode {}: " .. tostring(e1)) local _, e2 = Wav.encode(a, { sampleFormat = "s12" } :: any) @@ -280,7 +268,6 @@ do t:check(e3 and e3.code == Err.ARG, "short samples buffer") end --- ------------------------------------------------------------------------------------------------ api do local c = Enc[1] local a, err = F.audio.load(c.file) @@ -292,7 +279,6 @@ do t:eq(F.detect(c.file), "wav", "F.detect") end --- ------------------------------------------------------------------------------------------------ fuzz t:fuzz("open + read + seek", function(b: buffer) local dec = Wav.open(Bytes.reader(b)) if dec then diff --git a/tests/audio/wavpack.luau b/tests/audio/wavpack.luau index 7557be3..fb4ffed 100644 --- a/tests/audio/wavpack.luau +++ b/tests/audio/wavpack.luau @@ -1,8 +1,5 @@ --- audio/wavpack tests: every fixture from tools/fixtures/wavpack.py (wavpack -f / -g / -h / -hh / -x1..6, joint stereo --- on / off, 8 - 32-bit int and 32-bit float, 1 - 8 channels, odd rates and lengths, hybrid lossy and hybrid lossless --- with the .wvc, noise shaping, ffmpeg's encoder) decoded bit-exact against wvunpack; seeking; f32 scaling and output --- reuse; decode() from a sub-range Reader; APEv2 tags and the MD5; the correction file through opts.resolve; sniff; --- the api; damaged blocks; the fuzz pass. Fixtures: tools/fixtures/wavpack.py. +-- audio/wavpack tests: tools/fixtures/wavpack.py's files (every mode, hybrid + .wvc) bit-exact against wvunpack. +-- Fixtures: tools/fixtures/wavpack.py. local T = require("@tests/T") local WavPack = require("@rosetta/audio/wavpack") local Bytes = require("@rosetta/core/Bytes") @@ -39,12 +36,10 @@ for _, fx in Cases do end t:note("%d fixtures bit-exact against wvunpack, %d seeks", #Cases, seekChecks) --- decode() from a sub-range Reader for _, name in { "s16_g", "md5_tags", "f32", "ch6" } do L.subrange(t, WavPack, byName[name], "wavpack") end --- tags, md5, the source facts do local dec = open(byName.md5_tags.data) t:eq(#dec.md5, 32, "md5") @@ -72,7 +67,6 @@ do t:check(dec2 and not dec2.lossless, "resolve: no wvc -> lossy") end --- the api do local fx = byName.s16_g t:eq(F.detect(buffer.fromstring(fx.data)), "wavpack", "detect") @@ -101,7 +95,6 @@ do t:eq(WavPack.sniff(Bytes.reader(buffer.fromstring("RIFF"))), 0, "sniff RIFF") end --- the fuzz pass local samples = {} for _, name in { "s16_g", "f32", "hyb_b3", "s32_hh", "ch6", "u8" } do table.insert(samples, buffer.fromstring(byName[name].data)) From 086b39a5952bf1b304c592594dc52fc391bf7498 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:52:13 -0500 Subject: [PATCH 25/25] tests: restore fixture provenance lines dropped with long headers --- tests/archive/applesingle.luau | 1 + tests/archive/binhex.luau | 1 + tests/archive/macbinary.luau | 1 + tests/codecs/bitmap.luau | 1 + tests/model/bsp.luau | 1 + tests/model/md2.luau | 1 + tests/model/md3.luau | 1 + tests/model/md5.luau | 1 + tests/model/mdl.luau | 1 + tests/music/_hively.luau | 1 + 10 files changed, 10 insertions(+) diff --git a/tests/archive/applesingle.luau b/tests/archive/applesingle.luau index e722367..48cc5e3 100644 --- a/tests/archive/applesingle.luau +++ b/tests/archive/applesingle.luau @@ -1,4 +1,5 @@ -- archive/applesingle tests (cases in tests/archive/_mac.luau). +-- Fixtures: tools/fixtures/mac.py. local Mod = require("@rosetta/archive/applesingle") local Bytes = require("@rosetta/core/Bytes") local Err = require("@rosetta/core/Err") diff --git a/tests/archive/binhex.luau b/tests/archive/binhex.luau index 2c359fe..35ec7ca 100644 --- a/tests/archive/binhex.luau +++ b/tests/archive/binhex.luau @@ -1,4 +1,5 @@ -- archive/binhex tests (cases in tests/archive/_mac.luau). +-- Fixtures: tools/fixtures/mac.py. local Mod = require("@rosetta/archive/binhex") local Bytes = require("@rosetta/core/Bytes") local Err = require("@rosetta/core/Err") diff --git a/tests/archive/macbinary.luau b/tests/archive/macbinary.luau index 1289b9e..6969fa5 100644 --- a/tests/archive/macbinary.luau +++ b/tests/archive/macbinary.luau @@ -1,4 +1,5 @@ -- archive/macbinary tests (cases in tests/archive/_mac.luau). +-- Fixtures: tools/fixtures/mac.py. local Mod = require("@rosetta/archive/macbinary") local Bytes = require("@rosetta/core/Bytes") local Err = require("@rosetta/core/Err") diff --git a/tests/codecs/bitmap.luau b/tests/codecs/bitmap.luau index d6c3d4f..72297a9 100644 --- a/tests/codecs/bitmap.luau +++ b/tests/codecs/bitmap.luau @@ -1,4 +1,5 @@ -- codecs/font/Bitmap tests: 1-bit row pack / unpack, the Font over a strike, Bitmap.strike, argument errors. +-- Fixtures: tools/fixtures/fonts.py. local T = require("@tests/T") local Bitmap = require("@rosetta/codecs/font/Bitmap") local Ttf = require("@rosetta/font/ttf") diff --git a/tests/model/bsp.luau b/tests/model/bsp.luau index 9a44314..358cc5a 100644 --- a/tests/model/bsp.luau +++ b/tests/model/bsp.luau @@ -1,4 +1,5 @@ -- model/bsp tests: generated Quake 1 / Half-Life / Quake II / Quake III maps; Quake III faces against assimp. +-- Fixtures: tools/fixtures/bsp.py. local T = require("@tests/T") local F = require("@rosetta") local Bsp = require("@rosetta/model/bsp") diff --git a/tests/model/md2.luau b/tests/model/md2.luau index c673453..b55b28a 100644 --- a/tests/model/md2.luau +++ b/tests/model/md2.luau @@ -1,4 +1,5 @@ -- model/md2 tests: generated MD2 files against assimp's frame-0 soup and the writer's exact frames. +-- Fixtures: tools/fixtures/md2.py. local T = require("@tests/T") local F = require("@rosetta") local Md2 = require("@rosetta/model/md2") diff --git a/tests/model/md3.luau b/tests/model/md3.luau index ea73add..8334d93 100644 --- a/tests/model/md3.luau +++ b/tests/model/md3.luau @@ -1,4 +1,5 @@ -- model/md3 tests: generated MD3 files against assimp's frame-0 soup and the writer's exact frames and tags. +-- Fixtures: tools/fixtures/md3.py. local T = require("@tests/T") local F = require("@rosetta") local Md3 = require("@rosetta/model/md3") diff --git a/tests/model/md5.luau b/tests/model/md5.luau index 27d60ba..78f62a4 100644 --- a/tests/model/md5.luau +++ b/tests/model/md5.luau @@ -1,4 +1,5 @@ -- model/md5 tests: generated .md5mesh / .md5anim files against assimp's bind-pose soup and the writer's poses. +-- Fixtures: tools/fixtures/md5.py. local T = require("@tests/T") local F = require("@rosetta") local Md5 = require("@rosetta/model/md5") diff --git a/tests/model/mdl.luau b/tests/model/mdl.luau index ddd60ff..323e9fa 100644 --- a/tests/model/mdl.luau +++ b/tests/model/mdl.luau @@ -1,4 +1,5 @@ -- model/mdl tests: generated Quake 1 and Half-Life 1 models against assimp's soups and the writer's values. +-- Fixtures: tools/fixtures/mdl.py. local T = require("@tests/T") local F = require("@rosetta") local Mdl = require("@rosetta/model/mdl") diff --git a/tests/music/_hively.luau b/tests/music/_hively.luau index dcf819c..a250eb3 100644 --- a/tests/music/_hively.luau +++ b/tests/music/_hively.luau @@ -1,4 +1,5 @@ -- tests/music/_hively: shared helper of the AHX / HVL tests: exact against hvl2wav (CRC-32 of the 16-bit stream). +-- Fixtures: tools/fixtures/ahx.py, hvl.py. local Bytes = require("@rosetta/core/Bytes") local Crc32 = require("@rosetta/core/Crc32")