tests/image: comments: specs only

This commit is contained in:
4DBug committed 2026-11-01 01:50:18 -05:00
1 parent e306d5c1d7
commit a80299dce0
27 files changed
+32 -199

No files matched your search

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