tests/codecs (m-z): comments: specs only

This commit is contained in:
4DBug committed 2026-11-01 01:50:53 -05:00
1 parent 98b4ce533e
commit a6732d45f2
23 files changed
+46 -177

No files matched your search

+1 -10
View File
@@ -1,6 +1,4 @@
-- codecs/text/Xml tests: random documents (namespaces, escapes, CDATA, comments, PIs, DOCTYPE entities, UTF-16, Latin-1)
-- against Python's ElementTree trees; encode -> decode round trips; well-formedness verdicts against expat
-- (hand-written cases and random mutations); events, helpers, options, error codes; the fuzz pass.
-- codecs/text/Xml tests: random documents against Python's ElementTree, well-formedness against expat, the API.
-- Fixtures: tools/fixtures/xml.py.
local T = require("@tests/T")
local Xml = require("@rosetta/codecs/text/Xml")
@@ -53,7 +51,6 @@ local function canon(e: any, tail: string?): string
return table.concat(out) .. ")t" .. s(tail)
end
-- 1. documents vs ElementTree, and round trips
for i, d in Docs do
local doc, err = Xml.decode(d.data, { whitespace = true })
t:check(doc, "doc " .. i .. ": " .. tostring(err))
@@ -74,7 +71,6 @@ for i, d in Docs do
t:eq(root.ns, want, "doc " .. i .. ": node.ns")
end
-- 2. well-formedness against expat
local agree, total, accepted, rejected = 0, 0, 0, 0
for i, c in Wf do
local doc = Xml.decode(c.data)
@@ -94,7 +90,6 @@ end
t:note("well-formedness: %d of %d verdicts agree with expat (%d well-formed, %d not)", agree, total, accepted, rejected)
t:check(agree >= total * 0.99, "well-formedness agreement >= 99%")
-- 3. API details
do
local src = '<?xml version="1.0"?>\n<!DOCTYPE r [<!ENTITY e "E&#38;#38;">]>\n<!--c--><r xmlns="urn:d" xmlns:p="urn:p" z="1" a="2"><p:x p:k="v">t<![CDATA[<c>]]>u</p:x><?go now?><y/>\n</r>'
local doc = Xml.decode(src, { comments = true, cdata = true, pi = true, namespaces = true }) :: any
@@ -130,7 +125,6 @@ do
local n = Xml.decode("<a b='x\ty\r\nz&#10;'>l1\r\nl2\rl3</a>") :: any
t:eq(n.root.attrs.b, "x y z\n", "attribute value normalization")
t:eq(Xml.text(n.root), "l1\nl2\nl3", "line endings")
-- builders and encode
local e = Xml.element("svg", { width = "10", height = "5" }, { Xml.element("rect", { x = "1" }), "a<b & \"c\"" })
Xml.setAttr(e, "id", "q\"\n")
t:eq(Xml.encode(e), '<svg height="5" width="10" id="q&quot;&#10;"><rect x="1"/>a&lt;b &amp; "c"</svg>', "encode element")
@@ -144,7 +138,6 @@ do
local _, ce = Xml.encode(cyc)
t:eq(ce and ce.code, Err.ARG, "cycle on encode")
t:eq(Xml.encode({ name = "#cdata", attrs = Types.object(), children = {}, text = "a]]>b" } :: any), "<![CDATA[a]]]]><![CDATA[>b]]>", "cdata split")
-- events
local evs = {}
for ev, a in Xml.events("<a x='1'><b>t</b><!--c--></a>") do
table.insert(evs, ev .. (if type(a) == "string" then ":" .. a else ""))
@@ -166,7 +159,6 @@ do
t:eq(ue and ue.code, Err.UNSUPPORTED, "unsupported encoding")
end
-- 4. errors and limits
local function code(src: string, opts: any?): string?
local _, e = Xml.decode(src, opts)
return e and e.code
@@ -182,7 +174,6 @@ t:eq(code("<p:a/>", { namespaces = true }), Err.CORRUPT, "undeclared prefix")
local _, ae = Xml.decode(5 :: any)
t:eq(ae and ae.code, Err.ARG, "bad argument")
-- 5. fuzz
local samples = {}
for i = 1, 40 do
table.insert(samples, Docs[i].data)