tests/vector: comments: specs only

This commit is contained in:
4DBug committed 2026-11-01 01:49:17 -05:00
1 parent 58b0df8b21
commit 9fe476b803
2 files changed
+7 -23

No files matched your search

+4 -13
View File
@@ -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("<s:svg xmlns:s='http://www.w3.org/2000/svg' width='4' height='4'><s:rect width='4' height='4'/></s:svg>")
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("<html></html>"))), 0, "sniff html")
end
-- errors
do
local _, e = decode("<html/>")
t:check(e and e.code == Err.CORRUPT, "not svg: " .. tostring(e))
+3 -10
View File
@@ -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)