tests/data: comments: specs only

This commit is contained in:
4DBug committed 2026-11-01 01:51:09 -05:00
1 parent 653ce4e002
commit 7672980c65
12 files changed
+16 -63

No files matched your search

+3 -5
View File
@@ -1,7 +1,6 @@
-- tests/data/Canon: the canonical text of a decoded data value, the same as tools/fixtures/_data_common.py canon() on -- the canonical text of a decoded data value, the same as tools/fixtures/_data_common.py canon() on Python's parse:
-- Python's parse: null n, true t, false f, numbers #%d (integral under 2^53) or #%.17g, strings s<len>:<bytes>, -- null n, true t, false f, numbers #%d (integral under 2^53) or #%.17g, strings s<len>:<bytes>, buffers b<len>:<bytes>,
-- buffers b<len>:<bytes>, arrays [x,...], objects {k=v,...} sorted by key text, dates d<rfc3339>. A module the data -- arrays [x,...], objects {k=v,...} sorted by key text, dates d<rfc3339>.
-- tests require (running it alone does nothing).
local Types = require("@rosetta/Types") local Types = require("@rosetta/Types")
local Canon = {} local Canon = {}
@@ -76,7 +75,6 @@ local function canon(v: any, out: { string })
end end
end end
-- of(v) -> the canonical text
function Canon.of(v: any): string function Canon.of(v: any): string
local out = {} local out = {}
canon(v, out) canon(v, out)
+1 -5
View File
@@ -1,7 +1,4 @@
-- data/cbor tests: the RFC 8949 Appendix A examples and random items encoded by Python's cbor2 decode to cbor2's -- data/cbor tests: RFC 8949 Appendix A and Python's cbor2 (tools/fixtures/cbor.py).
-- values (canonical form), re-encode to the same bytes, big integers as doubles and exact text, indefinite lengths,
-- tags / simple values / undefined, half floats, sequences, options, error codes, and the fuzz pass.
-- Fixtures: tools/fixtures/cbor.py.
local T = require("@tests/T") local T = require("@tests/T")
local Cbor = require("@rosetta/data/cbor") local Cbor = require("@rosetta/data/cbor")
local Bytes = require("@rosetta/core/Bytes") local Bytes = require("@rosetta/core/Bytes")
@@ -68,7 +65,6 @@ for i, c in Fx.wide do
t:eq(Canon.of(plain(dec(c.data, { bigInts = "string" }))), c.canonStr, "wide " .. i .. ": exact") t:eq(Canon.of(plain(dec(c.data, { bigInts = "string" }))), c.canonStr, "wide " .. i .. ": exact")
end end
-- details
do do
local function hex(b: buffer): string local function hex(b: buffer): string
return (string.gsub(buffer.tostring(b), ".", function(ch) return (string.gsub(buffer.tostring(b), ".", function(ch)
+1 -4
View File
@@ -1,6 +1,4 @@
-- data/csv tests: tables written by Python's csv.writer / DictWriter (every delimiter, quotes, line breaks inside -- data/csv tests against Python's csv module (tools/fixtures/csv.py).
-- fields, empty fields) read back as csv.reader does, re-encoded byte for byte, keyed rows with a header, options,
-- error codes, and the fuzz pass. Fixtures: tools/fixtures/csv.py.
local T = require("@tests/T") local T = require("@tests/T")
local F = require("@rosetta") local F = require("@rosetta")
local Csv = require("@rosetta/data/csv") local Csv = require("@rosetta/data/csv")
@@ -41,7 +39,6 @@ for i, c in Fx do
end end
end end
-- details
do do
t:eq(Canon.of(dec("a,b\n\n1,2\r\n3,4\r5,6")), Canon.of({ { "a", "b" }, { "1", "2" }, { "3", "4" }, { "5", "6" } }), "line ends, blank lines") t:eq(Canon.of(dec("a,b\n\n1,2\r\n3,4\r5,6")), Canon.of({ { "a", "b" }, { "1", "2" }, { "3", "4" }, { "5", "6" } }), "line ends, blank lines")
t:eq(Canon.of(dec('"a""b",c"d,"e"x')), Canon.of({ { 'a"b', 'c"d', "ex" } }), "lenient quotes like Python") t:eq(Canon.of(dec('"a""b",c"d,"e"x')), Canon.of({ { 'a"b', 'c"d', "ex" } }), "lenient quotes like Python")
+1 -3
View File
@@ -1,6 +1,4 @@
-- data/ini tests: configs written by Python's configparser read back to configparser's values and re-encoded byte for -- data/ini tests against Python's configparser (tools/fixtures/ini.py).
-- byte, messy hand-written files read as configparser(strict = false) reads them, options (inline comments, keys
-- without values, types, strict), top-level keys, error codes, and the fuzz pass. Fixtures: tools/fixtures/ini.py.
local T = require("@tests/T") local T = require("@tests/T")
local Ini = require("@rosetta/data/ini") local Ini = require("@rosetta/data/ini")
local Bytes = require("@rosetta/core/Bytes") local Bytes = require("@rosetta/core/Bytes")
+1 -6
View File
@@ -1,6 +1,4 @@
-- data/json tests: the contract, the format through the API (F.load / F.save / sniffing), JSON Lines, Python's -- data/json format tests (the codec: tests/codecs/json.luau) against Python's json (tools/fixtures/json.py).
-- json.dumps corpus through the format, and the fuzz pass. The codec itself is tested in tests/codecs/json.luau.
-- Fixtures: tools/fixtures/json.py.
local T = require("@tests/T") local T = require("@tests/T")
local F = require("@rosetta") local F = require("@rosetta")
local JsonF = require("@rosetta/data/json") local JsonF = require("@rosetta/data/json")
@@ -27,7 +25,6 @@ for i, c in Corpus do
t:eq(buffer.tostring(b), c.pretty .. "\n", "corpus " .. i .. ": encode") t:eq(buffer.tostring(b), c.pretty .. "\n", "corpus " .. i .. ": encode")
end end
-- through the API: sniffed, by name, saved
do do
local v, err = F.load(buffer.fromstring('{"a": [1, 2], "b": null}')) local v, err = F.load(buffer.fromstring('{"a": [1, 2], "b": null}'))
t:check(v ~= nil, "F.load sniffs json: " .. tostring(err)) t:check(v ~= nil, "F.load sniffs json: " .. tostring(err))
@@ -40,7 +37,6 @@ do
t:eq(back.y[1], true, "F.data.load") t:eq(back.y[1], true, "F.data.load")
end end
-- JSON Lines
do do
local v = dec('{"a":1}\n{"a":2}\n\n[3]\n', { lines = true }) local v = dec('{"a":1}\n{"a":2}\n\n[3]\n', { lines = true })
t:eq(#v, 3, "lines decode count") t:eq(#v, 3, "lines decode count")
@@ -51,7 +47,6 @@ do
t:eq(e and e.code, Err.TRUNCATED, "lines error") t:eq(e and e.code, Err.TRUNCATED, "lines error")
end end
-- reader range: the data inside a bigger buffer
do do
local big = buffer.fromstring("xx[1,2,3]yy") local big = buffer.fromstring("xx[1,2,3]yy")
local v = JsonF.decode(Bytes.reader(big, 2, 7)) local v = JsonF.decode(Bytes.reader(big, 2, 7))
+1 -4
View File
@@ -1,6 +1,4 @@
-- data/msgpack tests: values packed by Python's msgpack decode to msgpack's own values (canonical form), re-encode to -- data/msgpack tests against Python's msgpack (tools/fixtures/msgpack.py).
-- the same bytes, 64-bit integers as doubles and as exact strings, timestamps / ext, streams, options, error codes,
-- and the fuzz pass. Fixtures: tools/fixtures/msgpack.py.
local T = require("@tests/T") local T = require("@tests/T")
local Mp = require("@rosetta/data/msgpack") local Mp = require("@rosetta/data/msgpack")
local Bytes = require("@rosetta/core/Bytes") local Bytes = require("@rosetta/core/Bytes")
@@ -49,7 +47,6 @@ for i, c in Fx.wide do
t:eq(Canon.of(plain(dec(Mp.encode(v) :: buffer))), c.canon, "wide " .. i .. ": round trip") t:eq(Canon.of(plain(dec(Mp.encode(v) :: buffer))), c.canon, "wide " .. i .. ": round trip")
end end
-- details
do do
t:eq(Mp.isExt(dec("\xd4\x05\x07")), true, "fixext1") t:eq(Mp.isExt(dec("\xd4\x05\x07")), true, "fixext1")
local d = dec("\xd6\xff\x00\x00\x00\x00") local d = dec("\xd6\xff\x00\x00\x00\x00")
+1 -6
View File
@@ -1,7 +1,4 @@
-- data/nbt tests: the contract, nbtlib files through the api (F.load / F.save, NBT -> SNBT -> NBT), detection by -- data/nbt format tests (the engine: tests/codecs/nbt.luau) against nbtlib (tools/fixtures/nbt.py).
-- content and extension, exact round trips (root name, edition, compression and the Bedrock header kept), error
-- codes, and the fuzz pass. The engine itself: tests/codecs/nbt.luau; SNBT files: tests/data/snbt.luau.
-- Fixtures: tools/fixtures/nbt.py.
local T = require("@tests/T") local T = require("@tests/T")
local F = require("@rosetta") local F = require("@rosetta")
local NbtF = require("@rosetta/data/nbt") local NbtF = require("@rosetta/data/nbt")
@@ -34,14 +31,12 @@ for i = 1, 12 do
t:eq(buffer.tostring(assert(F.save(le, nil, { format = "nbt" })) :: buffer), c.header, c.name .. ": Bedrock level.dat same bytes") t:eq(buffer.tostring(assert(F.save(le, nil, { format = "nbt" })) :: buffer), c.header, c.name .. ": Bedrock level.dat same bytes")
end end
-- detection
do do
local c = Fx.cases[3] local c = Fx.cases[3]
t:eq(F.detect(c.gzip, { name = "level.dat" }), "nbt", "detect gzip .dat") t:eq(F.detect(c.gzip, { name = "level.dat" }), "nbt", "detect gzip .dat")
t:eq(F.detect(c.raw, { name = "x.nbt" }), "nbt", "detect raw .nbt") t:eq(F.detect(c.raw, { name = "x.nbt" }), "nbt", "detect raw .nbt")
end end
-- errors
do do
local _, e = NbtF.decode(Bytes.reader(buffer.fromstring("\10\0\0\1"))) local _, e = NbtF.decode(Bytes.reader(buffer.fromstring("\10\0\0\1")))
t:check(e and e.code == Err.TRUNCATED, "truncated") t:check(e and e.code == Err.TRUNCATED, "truncated")
+1 -3
View File
@@ -1,6 +1,4 @@
-- data/plist tests: values written by Python's plistlib as XML and binary decode to plistlib's values; our XML writer -- data/plist tests against Python's plistlib (tools/fixtures/plist.py).
-- reproduces plistlib's XML byte for byte; binary-only values (UIDs, 64-bit integers); a hand-written XML plist;
-- error codes; the fuzz pass (XML and binary). Fixtures: tools/fixtures/plist.py.
local T = require("@tests/T") local T = require("@tests/T")
local F = require("@rosetta") local F = require("@rosetta")
local Plist = require("@rosetta/data/plist") local Plist = require("@rosetta/data/plist")
+1 -3
View File
@@ -1,6 +1,4 @@
-- data/snbt tests: the contract, nbtlib's SNBT text (indented and compact) through the api, conversion to and from -- data/snbt tests (the grammar: tests/codecs/nbt.luau) against nbtlib (tools/fixtures/nbt.py).
-- binary NBT (F.convert), detection against JSON, options (indent, quote), error codes, and the fuzz pass. The
-- grammar itself: tests/codecs/nbt.luau. Fixtures: tools/fixtures/nbt.py.
local T = require("@tests/T") local T = require("@tests/T")
local F = require("@rosetta") local F = require("@rosetta")
local SnbtF = require("@rosetta/data/snbt") local SnbtF = require("@rosetta/data/snbt")
+3 -10
View File
@@ -1,6 +1,5 @@
-- data/toml tests: the toml-test suite's TOML 1.0 files (every valid/ case decodes to its expected value, every -- data/toml tests: the toml-test suite (TOML 1.0) and a tomli-w corpus against Python's tomllib.
-- invalid/ case fails), a tomli-w corpus against Python's tomllib, encoder round trips (decode(encode(v)) is the same -- Fixtures: tools/fixtures/toml.py.
-- value) and exact encoder output, options, error codes, the contract and the fuzz pass. Fixtures: tools/fixtures/toml.py.
local T = require("@tests/T") local T = require("@tests/T")
local Toml = require("@rosetta/data/toml") local Toml = require("@rosetta/data/toml")
local Bytes = require("@rosetta/core/Bytes") local Bytes = require("@rosetta/core/Bytes")
@@ -24,15 +23,13 @@ local function enc(v: any, opts: any?): (string?, any)
return if b then buffer.tostring(b) else nil, e return if b then buffer.tostring(b) else nil, e
end end
-- 1. toml-test
local nv, ni, rt = 0, 0, 0 local nv, ni, rt = 0, 0, 0
for _, c in Suite do for _, c in Suite do
local v, err = dec(c.data) local v, err = dec(c.data)
if c.valid then if c.valid then
t:check(v ~= nil, c.name .. ": parses (" .. tostring(err) .. ")") t:check(v ~= nil, c.name .. ": parses (" .. tostring(err) .. ")")
t:eq(Canon.of(v), c.canon, c.name .. ": value") t:eq(Canon.of(v), c.canon, c.name .. ": value")
-- the encoder's output reads back as the same value (floats that are integral become integers, so compare -- integral floats read back as integers, so compare decoded values, not the toml-test canon
-- the decoded values, not the toml-test canon)
local s, eerr = enc(v) local s, eerr = enc(v)
t:check(s ~= nil, c.name .. ": encodes (" .. tostring(eerr) .. ")") t:check(s ~= nil, c.name .. ": encodes (" .. tostring(eerr) .. ")")
local back, berr = dec(s :: string) local back, berr = dec(s :: string)
@@ -47,7 +44,6 @@ for _, c in Suite do
end end
t:note("toml-test 1.0: %d valid decoded and round-tripped, %d invalid rejected", nv, ni) t:note("toml-test 1.0: %d valid decoded and round-tripped, %d invalid rejected", nv, ni)
-- 2. tomli-w corpus vs tomllib
for i, c in Corpus do for i, c in Corpus do
local v, err = dec(c.data) local v, err = dec(c.data)
t:check(v ~= nil, "corpus " .. i .. ": " .. tostring(err)) t:check(v ~= nil, "corpus " .. i .. ": " .. tostring(err))
@@ -57,7 +53,6 @@ for i, c in Corpus do
t:eq(Canon.of(dec(enc(v, { inline = true }) :: string)), c.canon, "corpus " .. i .. ": inline round trip") t:eq(Canon.of(dec(enc(v, { inline = true }) :: string)), c.canon, "corpus " .. i .. ": inline round trip")
end end
-- 3. API details
do do
local v = dec('z = 1\na = 2\n[t]\ny = "x"\nb = 1979-05-27T07:32:00.5-07:00\n[[arr]]\nk = 1\n[[arr]]\nk = 2\n') local v = dec('z = 1\na = 2\n[t]\ny = "x"\nb = 1979-05-27T07:32:00.5-07:00\n[[arr]]\nk = 1\n[[arr]]\nk = 2\n')
t:eq(table.concat(Types.keys(v), ","), "z,a,t,arr", "key order") t:eq(table.concat(Types.keys(v), ","), "z,a,t,arr", "key order")
@@ -87,7 +82,6 @@ do
t:eq(e4 and e4.code, Err.ARG, "non-string key") t:eq(e4 and e4.code, Err.ARG, "non-string key")
end end
-- 4. errors
local function code(s: string): (string?, number?) local function code(s: string): (string?, number?)
local _, e = dec(s) local _, e = dec(s)
return e and e.code, e and e.offset return e and e.code, e and e.offset
@@ -101,7 +95,6 @@ t:eq(select(2, code("x = 1\na = tru")), 10, "error offset")
t:eq(Toml.sniff(Bytes.reader(buffer.fromstring("# c\n[server]\nport = 80\n"))), 0.2, "sniff") t:eq(Toml.sniff(Bytes.reader(buffer.fromstring("# c\n[server]\nport = 80\n"))), 0.2, "sniff")
t:eq(Toml.sniff(Bytes.reader(buffer.fromstring("{\"a\": 1}"))), 0, "sniff json") t:eq(Toml.sniff(Bytes.reader(buffer.fromstring("{\"a\": 1}"))), 0, "sniff json")
-- 5. fuzz
local samples = {} local samples = {}
for _, c in Suite do for _, c in Suite do
if c.valid and #samples < 80 and #c.data < 400 then if c.valid and #samples < 80 and #c.data < 400 then
+1 -3
View File
@@ -1,6 +1,4 @@
-- data/xml tests: the contract, the format through the API (F.load / F.save / sniffing), documents from Python's -- data/xml format tests (the codec: tests/codecs/xml.luau) against ElementTree (tools/fixtures/xml.py).
-- ElementTree fixtures decoded and re-encoded through the format, and the fuzz pass. The codec itself is tested in
-- tests/codecs/xml.luau. Fixtures: tools/fixtures/xml.py.
local T = require("@tests/T") local T = require("@tests/T")
local F = require("@rosetta") local F = require("@rosetta")
local XmlF = require("@rosetta/data/xml") local XmlF = require("@rosetta/data/xml")
+1 -11
View File
@@ -1,7 +1,4 @@
-- data/yaml tests: the yaml-test-suite (every case with an in.json must decode to it, every error case must be -- data/yaml tests: the yaml-test-suite and a PyYAML corpus against Python's values (tools/fixtures/yaml.py).
-- rejected, the valid cases without JSON must decode), a random corpus dumped by PyYAML in five styles (block, flow,
-- indent 4 with explicit markers, sorted / narrow, multi-document) compared with Python's values, encoder round trips,
-- options, errors and limits, the API, and the fuzz pass. Fixtures: tools/fixtures/yaml.py.
local T = require("@tests/T") local T = require("@tests/T")
local F = require("@rosetta") local F = require("@rosetta")
local Yaml = require("@rosetta/data/yaml") local Yaml = require("@rosetta/data/yaml")
@@ -27,7 +24,6 @@ local function enc(v: any, opts: any?): string?
return if b then buffer.tostring(b) else nil return if b then buffer.tostring(b) else nil
end end
-- 1. yaml-test-suite
local SKIP = { -- !!binary decodes to a buffer; the suite's JSON keeps the base64 text local SKIP = { -- !!binary decodes to a buffer; the suite's JSON keeps the base64 text
["565N"] = true, ["565N"] = true,
["name/construct-binary"] = true, ["name/construct-binary"] = true,
@@ -62,7 +58,6 @@ end
t:note("yaml-test-suite: %d of %d JSON cases match, %d of %d error cases rejected, %d of %d other valid cases decode or say UNSUPPORTED", pass, valid, rejected, errors, otherOk, other) t:note("yaml-test-suite: %d of %d JSON cases match, %d of %d error cases rejected, %d of %d other valid cases decode or say UNSUPPORTED", pass, valid, rejected, errors, otherOk, other)
t:check(otherOk == other, "valid cases without JSON never fail as CORRUPT") t:check(otherOk == other, "valid cases without JSON never fail as CORRUPT")
-- 2. PyYAML's output in five styles
for i, c in Corpus do for i, c in Corpus do
for style, text in c.texts do for style, text in c.texts do
if style == "multi" then if style == "multi" then
@@ -75,7 +70,6 @@ for i, c in Corpus do
t:eq(Canon.of(v), c.canon, "corpus " .. i .. " " .. style) t:eq(Canon.of(v), c.canon, "corpus " .. i .. " " .. style)
end end
end end
-- our own output reads back the same (indent 2 and 4, explicit start)
local v = dec(c.texts.block) local v = dec(c.texts.block)
for _, o in { {}, { indent = 4 }, { explicitStart = true } } do for _, o in { {}, { indent = 4 }, { explicitStart = true } } do
local s = enc(v, o) local s = enc(v, o)
@@ -86,7 +80,6 @@ for i, c in Corpus do
t:eq(Canon.of(dec(enc(m, { all = true }) :: string, { all = true })), c.multi, "corpus " .. i .. ": multi round trip") t:eq(Canon.of(dec(enc(m, { all = true }) :: string, { all = true })), c.multi, "corpus " .. i .. ": multi round trip")
end end
-- 3. details
do do
local v = dec("b: 1\na: 2\nc: {}\nd: []\ne:\nf: ~\n") local v = dec("b: 1\na: 2\nc: {}\nd: []\ne:\nf: ~\n")
t:eq(table.concat(Types.keys(v), ","), "b,a,c,d,e,f", "key order") t:eq(table.concat(Types.keys(v), ","), "b,a,c,d,e,f", "key order")
@@ -127,7 +120,6 @@ do
t:eq(dec("k: |\n a\n b\n\nz: >+\n f\n g\n\n").z, "f g\n\n", "folded keep") t:eq(dec("k: |\n a\n b\n\nz: >+\n f\n g\n\n").z, "f g\n\n", "folded keep")
t:eq(dec("? a\n: b\n").a, "b", "explicit key") t:eq(dec("? a\n: b\n").a, "b", "explicit key")
t:eq(dec("[a: 1, {b: 2}]")[1].a, 1, "single-pair flow mapping") t:eq(dec("[a: 1, {b: 2}]")[1].a, 1, "single-pair flow mapping")
-- strings that need quoting survive
for _, str in { "", "true", "null", "12", "1.5", "- x", "a: b", "# c", "x #y", " lead", "tail ", "multi\nline", "two\n\n", "\ttab", "é", "\0\1", "'", '"', "yes", "on", "~", "[", "@", "&a", "*a", "!t", "%", "---", "...", "a\u{2028}b", ".inf", "0x10", "0o7", "-", "?", ":" } do for _, str in { "", "true", "null", "12", "1.5", "- x", "a: b", "# c", "x #y", " lead", "tail ", "multi\nline", "two\n\n", "\ttab", "é", "\0\1", "'", '"', "yes", "on", "~", "[", "@", "&a", "*a", "!t", "%", "---", "...", "a\u{2028}b", ".inf", "0x10", "0o7", "-", "?", ":" } do
local v2 = dec(enc({ k = str }) :: string) local v2 = dec(enc({ k = str }) :: string)
t:eq(v2 and v2.k, str, "string round trip " .. string.format("%q", str)) t:eq(v2 and v2.k, str, "string round trip " .. string.format("%q", str))
@@ -144,7 +136,6 @@ do
t:eq(enc(buffer.fromstring("hi")), "!!binary aGk=\n", "buffers as !!binary") t:eq(enc(buffer.fromstring("hi")), "!!binary aGk=\n", "buffers as !!binary")
end end
-- 4. errors and limits
local function code(s: string, opts: any?): string? local function code(s: string, opts: any?): string?
local _, e = dec(s, opts) local _, e = dec(s, opts)
return e and e.code return e and e.code
@@ -170,7 +161,6 @@ do
t:eq(e and e.offset, 12, "error offset") t:eq(e and e.offset, 12, "error offset")
end end
-- 5. API
do do
local v, err = F.load(buffer.fromstring("---\nname: x\nlist:\n - 1\n")) local v, err = F.load(buffer.fromstring("---\nname: x\nlist:\n - 1\n"))
t:check(v ~= nil, "F.load sniffs yaml: " .. tostring(err)) t:check(v ~= nil, "F.load sniffs yaml: " .. tostring(err))