tests/containers: comments: specs only

This commit is contained in:
4DBug committed 2026-11-01 01:49:47 -05:00
1 parent 53aa9a6ebf
commit 70f50917fa
5 files changed
+8 -46

No files matched your search

+1 -11
View File
@@ -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")