tests/vector: comments: specs only
This commit is contained in:
1 parent
58b0df8b21
commit
9fe476b803
2 files changed
+7
-23
No files matched your search
+4
-13
@@ -1,8 +1,5 @@
|
|||||||
-- vector/svg tests: hand-written SVGs, one feature area each (shapes, every path command, arcs, transforms, stroke
|
-- vector/svg tests: hand-written SVGs rasterized by us against resvg by PSNR.
|
||||||
-- joins / caps / dashes, fill rules, opacity, gradients, href, CSS, use / symbol, viewBox + preserveAspectRatio, nested
|
-- Fixtures: tools/fixtures/svg.py.
|
||||||
-- 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.
|
|
||||||
local T = require("@tests/T")
|
local T = require("@tests/T")
|
||||||
local Svg = require("@rosetta/vector/svg")
|
local Svg = require("@rosetta/vector/svg")
|
||||||
local PathData = require("@rosetta/vector/svg/PathData")
|
local PathData = require("@rosetta/vector/svg/PathData")
|
||||||
@@ -16,7 +13,7 @@ local t = T.suite("svg")
|
|||||||
local function decode(s: string): (any, any)
|
local function decode(s: string): (any, any)
|
||||||
return Svg.decode(Bytes.reader(buffer.fromstring(s)))
|
return Svg.decode(Bytes.reader(buffer.fromstring(s)))
|
||||||
end
|
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 function psnr(a: buffer | string, b: string): number
|
||||||
local sa = if type(a) == "string" then a else buffer.tostring(a)
|
local sa = if type(a) == "string" then a else buffer.tostring(a)
|
||||||
local n = math.min(#sa, #b)
|
local n = math.min(#sa, #b)
|
||||||
@@ -39,8 +36,7 @@ t:eq(Svg.name, "svg", "name")
|
|||||||
t:eq(Svg.category, "vector", "category")
|
t:eq(Svg.category, "vector", "category")
|
||||||
t:check(Svg.caps.decode and Svg.caps.encode, "caps")
|
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
|
-- antialiasing differs from resvg (tiny-skia analytic AA vs our exact coverage): the floor catches wrong geometry
|
||||||
-- cost a few dB; the floor catches wrong geometry / paint
|
|
||||||
local FLOOR = 30
|
local FLOOR = 30
|
||||||
local samples = {}
|
local samples = {}
|
||||||
local worst, worstName = 99, ""
|
local worst, worstName = 99, ""
|
||||||
@@ -69,7 +65,6 @@ for _, c in Fx.cases do
|
|||||||
end
|
end
|
||||||
t:note("worst: %s %.1f dB", worstName, worst)
|
t:note("worst: %s %.1f dB", worstName, worst)
|
||||||
|
|
||||||
-- path data
|
|
||||||
do
|
do
|
||||||
local cmds, ok = PathData.parse("M1.5.5L-2-3e1 1e-1.2zm1,1 h2 v2 a1 1 0 0 1 2 2")
|
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")
|
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")
|
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
|
end
|
||||||
|
|
||||||
-- colours and lengths
|
|
||||||
do
|
do
|
||||||
local function col(s: string): string
|
local function col(s: string): string
|
||||||
local c = Style.color(s)
|
local c = Style.color(s)
|
||||||
@@ -109,7 +103,6 @@ do
|
|||||||
t:eq(Style.transform("translate(1,"), nil, "bad transform")
|
t:eq(Style.transform("translate(1,"), nil, "bad transform")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- the model
|
|
||||||
do
|
do
|
||||||
local v = decode(Fx.cases[1].svg)
|
local v = decode(Fx.cases[1].svg)
|
||||||
t:check(#v.paths == 7, "shapes: one path each")
|
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")
|
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>")
|
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")
|
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))
|
local back = decode(buffer.tostring(Svg.encode(v) :: buffer))
|
||||||
t:eq(#back.paths, #v.paths, "round trip path count")
|
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(Fx.cases[1].svg))), 0.95, "sniff")
|
||||||
t:eq(Svg.sniff(Bytes.reader(buffer.fromstring("<html></html>"))), 0, "sniff html")
|
t:eq(Svg.sniff(Bytes.reader(buffer.fromstring("<html></html>"))), 0, "sniff html")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- errors
|
|
||||||
do
|
do
|
||||||
local _, e = decode("<html/>")
|
local _, e = decode("<html/>")
|
||||||
t:check(e and e.code == Err.CORRUPT, "not svg: " .. tostring(e))
|
t:check(e and e.code == Err.CORRUPT, "not svg: " .. tostring(e))
|
||||||
|
|||||||
+3
-10
@@ -1,8 +1,5 @@
|
|||||||
-- vector/tiled tests: hand-written TMX maps (CSV / base64 zlib / gzip / raw / XML tile data, flip bits, infinite
|
-- vector/tiled tests: hand-written TMX maps against Tiled's own TMJ export and TMX re-save.
|
||||||
-- chunks, hexagonal attributes, groups, image layers, every object shape, text, typed properties, embedded and
|
-- Fixtures: tools/fixtures/tiled.py.
|
||||||
-- 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.
|
|
||||||
local T = require("@tests/T")
|
local T = require("@tests/T")
|
||||||
local Tiled = require("@rosetta/vector/tiled")
|
local Tiled = require("@rosetta/vector/tiled")
|
||||||
local Bytes = require("@rosetta/core/Bytes")
|
local Bytes = require("@rosetta/core/Bytes")
|
||||||
@@ -17,7 +14,7 @@ local function decode(s: string | buffer): (any, any)
|
|||||||
return Tiled.decode(Bytes.reader(b))
|
return Tiled.decode(Bytes.reader(b))
|
||||||
end
|
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 SKIP = { version = true, tiledVersion = true, encoding = true, compression = true, meta = true }
|
||||||
local function same(a: any, b: any, path: string, out: { string })
|
local function same(a: any, b: any, path: string, out: { string })
|
||||||
if #out > 8 then
|
if #out > 8 then
|
||||||
@@ -73,7 +70,6 @@ for _, c in Fx.cases do
|
|||||||
table.insert(samples, c.tmj)
|
table.insert(samples, c.tmj)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- details of the orthogonal map
|
|
||||||
do
|
do
|
||||||
local m = maps.ortho
|
local m = maps.ortho
|
||||||
t:eq(m.class, "Level", "map class")
|
t:eq(m.class, "Level", "map class")
|
||||||
@@ -118,7 +114,6 @@ do
|
|||||||
t:eq(maps.infinite.layers[1].chunks[2].x, -16, "chunk position")
|
t:eq(maps.infinite.layers[1].chunks[2].x, -16, "chunk position")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- the external tileset, TSX vs Tiled's TSJ
|
|
||||||
do
|
do
|
||||||
local a = decode(Fx.tsx)
|
local a = decode(Fx.tsx)
|
||||||
local b = decode(Fx.tsj)
|
local b = decode(Fx.tsj)
|
||||||
@@ -136,7 +131,6 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- round trips through every flavour and data encoding
|
|
||||||
for name, m in maps do
|
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
|
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)
|
local out, err = Tiled.encode(m, o :: any)
|
||||||
@@ -161,7 +155,6 @@ for _, c in Ours.checks do
|
|||||||
t:check(c.ok, c.label)
|
t:check(c.ok, c.label)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- errors
|
|
||||||
do
|
do
|
||||||
local zstd = string.gsub(Fx.cases[1].tmx, "compression=\"zlib\"", "compression=\"zstd\"")
|
local zstd = string.gsub(Fx.cases[1].tmx, "compression=\"zlib\"", "compression=\"zstd\"")
|
||||||
local _, e = decode(zstd)
|
local _, e = decode(zstd)
|
||||||
|
|||||||
Reference in new issue
Block a user