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
|
||||
-- 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))
|
||||
|
||||
Reference in new issue
Block a user