diff --git a/examples/archive.luau b/examples/archive.luau
index 2d36ffa..637aa80 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 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..447c7b8 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, 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..28dea25 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, 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 = [[', "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
diff --git a/tests/compat.luau b/tests/compat.luau
index bfba55a..d3ea624 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 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
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")
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
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))
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))))
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")
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
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))
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..358cc5a 100644
--- a/tests/model/bsp.luau
+++ b/tests/model/bsp.luau
@@ -1,8 +1,5 @@
--- 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.
+-- Fixtures: tools/fixtures/bsp.py.
local T = require("@tests/T")
local F = require("@rosetta")
local Bsp = require("@rosetta/model/bsp")
@@ -81,7 +78,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 +90,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 +97,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 +131,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 +146,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 +190,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..b55b28a 100644
--- a/tests/model/md2.luau
+++ b/tests/model/md2.luau
@@ -1,6 +1,5 @@
--- 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.
+-- Fixtures: tools/fixtures/md2.py.
local T = require("@tests/T")
local F = require("@rosetta")
local Md2 = require("@rosetta/model/md2")
@@ -19,12 +18,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 +38,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 +48,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..8334d93 100644
--- a/tests/model/md3.luau
+++ b/tests/model/md3.luau
@@ -1,7 +1,5 @@
--- 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.
+-- Fixtures: tools/fixtures/md3.py.
local T = require("@tests/T")
local F = require("@rosetta")
local Md3 = require("@rosetta/model/md3")
@@ -34,8 +32,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 +64,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..78f62a4 100644
--- a/tests/model/md5.luau
+++ b/tests/model/md5.luau
@@ -1,7 +1,5 @@
--- 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.
+-- Fixtures: tools/fixtures/md5.py.
local T = require("@tests/T")
local F = require("@rosetta")
local Md5 = require("@rosetta/model/md5")
@@ -35,7 +33,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 +60,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 +83,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 +127,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 +134,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..323e9fa 100644
--- a/tests/model/mdl.luau
+++ b/tests/model/mdl.luau
@@ -1,8 +1,5 @@
--- 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.
+-- Fixtures: tools/fixtures/mdl.py.
local T = require("@tests/T")
local F = require("@rosetta")
local Mdl = require("@rosetta/model/mdl")
@@ -24,7 +21,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 +28,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 +64,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 +89,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 +96,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 +121,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 +129,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
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..a250eb3 100644
--- a/tests/music/_hively.luau
+++ b/tests/music/_hively.luau
@@ -1,12 +1,10 @@
--- 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).
+-- Fixtures: tools/fixtures/ahx.py, hvl.py.
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")
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
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")
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)
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