52 lines
2.3 KiB
Luau
52 lines
2.3 KiB
Luau
-- font/eot tests: DejaVu Sans Mono and Source Sans 3 against fontTools (tools/fixtures/eot.py).
|
|
local T = require("@tests/T")
|
|
local F = require("@rosetta")
|
|
local Eot = require("@rosetta/font/eot")
|
|
local Bytes = require("@rosetta/core/Bytes")
|
|
local Crc32 = require("@rosetta/core/Crc32")
|
|
local Err = require("@rosetta/core/Err")
|
|
local Fx = require("@tests/gen/eot")
|
|
|
|
local t = T.suite("eot")
|
|
t:eq(Eot.name, "eot", "name")
|
|
|
|
local samples = {}
|
|
for _, c in Fx.cases do
|
|
local font, err = Eot.decode(Bytes.reader(buffer.fromstring(c.data)))
|
|
t:check(font, c.name .. ": " .. tostring(err))
|
|
if font then
|
|
local h = font.meta.eot
|
|
t:eq(h.version, c.version, c.name .. ": version")
|
|
t:eq(h.familyName, c.family, c.name .. ": family")
|
|
t:eq(h.styleName, c.style, c.name .. ": style")
|
|
t:eq(h.fullName, c.fullName, c.name .. ": full name")
|
|
t:eq(h.weight, c.weight, c.name .. ": weight")
|
|
t:eq(h.fsType, c.fsType, c.name .. ": fsType")
|
|
t:eq(font.unitsPerEm, c.upem, c.name .. ": units per em")
|
|
t:eq(font.numGlyphs, c.numGlyphs, c.name .. ": glyph count")
|
|
t:eq(Crc32.of(font.meta.fontData), c.fontCrc, c.name .. ": font data")
|
|
for _, g in c.glyphs do
|
|
t:eq(font:glyphIndex(g.cp), g.gid, c.name .. ": cmap " .. g.cp)
|
|
t:eq(font:advance(g.gid), g.advance, c.name .. ": advance " .. g.cp)
|
|
end
|
|
for _, xor in { false, true } do
|
|
local out, werr = Eot.encode(font, { xor = xor })
|
|
t:check(out, c.name .. ": encode: " .. tostring(werr))
|
|
local back = out and Eot.decode(Bytes.reader(out)) :: any
|
|
t:check(back and Crc32.of(back.meta.fontData) == c.fontCrc and back.meta.eot.weight == c.weight and back.meta.eot.familyName == font.info.family, c.name .. ": round trip (xor " .. tostring(xor) .. ")")
|
|
end
|
|
end
|
|
t:eq(F.detect(c.data), "eot", c.name .. ": detect")
|
|
table.insert(samples, string.sub(c.data, 1, 3000))
|
|
end
|
|
local _, merr = Eot.decode(Bytes.reader(buffer.fromstring(Fx.mtx)))
|
|
t:eq(merr and merr.code, Err.UNSUPPORTED, "MTX compressed")
|
|
local _, serr = Eot.decode(Bytes.reader(buffer.fromstring(string.sub(Fx.cases[1].data, 1, 50))))
|
|
t:eq(serr and serr.code, Err.TRUNCATED, "cut header")
|
|
t:eq((select(2, Eot.encode({}))) and (select(2, Eot.encode({})) :: any).code, Err.ARG, "encode a non-font")
|
|
|
|
t:fuzz("decode", function(b: buffer)
|
|
return Eot.decode(Bytes.reader(b))
|
|
end, samples, { mutations = 20 })
|
|
t:done()
|