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
-- Python's parse: null n, true t, false f, numbers #%d (integral under 2^53) or #%.17g, strings s<len>:<bytes>,
-- buffers b<len>:<bytes>, arrays [x,...], objects {k=v,...} sorted by key text, dates d<rfc3339>. A module the data
-- tests require (running it alone does nothing).
-- the canonical text of a decoded data value, the same as tools/fixtures/_data_common.py canon() on Python's parse:
-- null n, true t, false f, numbers #%d (integral under 2^53) or #%.17g, strings s<len>:<bytes>, buffers b<len>:<bytes>,
-- arrays [x,...], objects {k=v,...} sorted by key text, dates d<rfc3339>.
local Types = require("@rosetta/Types")
local Canon = {}
@@ -76,7 +75,6 @@ local function canon(v: any, out: { string })
end
end
-- of(v) -> the canonical text
function Canon.of(v: any): string
local 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
-- 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.
-- data/cbor tests: RFC 8949 Appendix A and Python's cbor2 (tools/fixtures/cbor.py).
local T = require("@tests/T")
local Cbor = require("@rosetta/data/cbor")
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")
end
-- details
do
local function hex(b: buffer): string
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
-- 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.
-- data/csv tests against Python's csv module (tools/fixtures/csv.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Csv = require("@rosetta/data/csv")
@@ -41,7 +39,6 @@ for i, c in Fx do
end
end
-- details
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",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
-- 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.
-- data/ini tests against Python's configparser (tools/fixtures/ini.py).
local T = require("@tests/T")
local Ini = require("@rosetta/data/ini")
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
-- 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.
-- data/json format tests (the codec: tests/codecs/json.luau) against Python's json (tools/fixtures/json.py).
local T = require("@tests/T")
local F = require("@rosetta")
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")
end
-- through the API: sniffed, by name, saved
do
local v, err = F.load(buffer.fromstring('{"a": [1, 2], "b": null}'))
t:check(v ~= nil, "F.load sniffs json: " .. tostring(err))
@@ -40,7 +37,6 @@ do
t:eq(back.y[1], true, "F.data.load")
end
-- JSON Lines
do
local v = dec('{"a":1}\n{"a":2}\n\n[3]\n', { lines = true })
t:eq(#v, 3, "lines decode count")
@@ -51,7 +47,6 @@ do
t:eq(e and e.code, Err.TRUNCATED, "lines error")
end
-- reader range: the data inside a bigger buffer
do
local big = buffer.fromstring("xx[1,2,3]yy")
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
-- 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.
-- data/msgpack tests against Python's msgpack (tools/fixtures/msgpack.py).
local T = require("@tests/T")
local Mp = require("@rosetta/data/msgpack")
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")
end
-- details
do
t:eq(Mp.isExt(dec("\xd4\x05\x07")), true, "fixext1")
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
-- 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.
-- data/nbt format tests (the engine: tests/codecs/nbt.luau) against nbtlib (tools/fixtures/nbt.py).
local T = require("@tests/T")
local F = require("@rosetta")
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")
end
-- detection
do
local c = Fx.cases[3]
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")
end
-- errors
do
local _, e = NbtF.decode(Bytes.reader(buffer.fromstring("\10\0\0\1")))
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
-- 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.
-- data/plist tests against Python's plistlib (tools/fixtures/plist.py).
local T = require("@tests/T")
local F = require("@rosetta")
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
-- 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.
-- data/snbt tests (the grammar: tests/codecs/nbt.luau) against nbtlib (tools/fixtures/nbt.py).
local T = require("@tests/T")
local F = require("@rosetta")
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
-- invalid/ case fails), a tomli-w corpus against Python's tomllib, encoder round trips (decode(encode(v)) is the same
-- value) and exact encoder output, options, error codes, the contract and the fuzz pass. Fixtures: tools/fixtures/toml.py.
-- data/toml tests: the toml-test suite (TOML 1.0) and a tomli-w corpus against Python's tomllib.
-- Fixtures: tools/fixtures/toml.py.
local T = require("@tests/T")
local Toml = require("@rosetta/data/toml")
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
end
-- 1. toml-test
local nv, ni, rt = 0, 0, 0
for _, c in Suite do
local v, err = dec(c.data)
if c.valid then
t:check(v ~= nil, c.name .. ": parses (" .. tostring(err) .. ")")
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
-- the decoded values, not the toml-test canon)
-- integral floats read back as integers, so compare decoded values, not the toml-test canon
local s, eerr = enc(v)
t:check(s ~= nil, c.name .. ": encodes (" .. tostring(eerr) .. ")")
local back, berr = dec(s :: string)
@@ -47,7 +44,6 @@ for _, c in Suite do
end
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
local v, err = dec(c.data)
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")
end
-- 3. API details
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')
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")
end
-- 4. errors
local function code(s: string): (string?, number?)
local _, e = dec(s)
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("{\"a\": 1}"))), 0, "sniff json")
-- 5. fuzz
local samples = {}
for _, c in Suite do
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
-- 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.
-- data/xml format tests (the codec: tests/codecs/xml.luau) against ElementTree (tools/fixtures/xml.py).
local T = require("@tests/T")
local F = require("@rosetta")
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
-- 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.
-- data/yaml tests: the yaml-test-suite and a PyYAML corpus against Python's values (tools/fixtures/yaml.py).
local T = require("@tests/T")
local F = require("@rosetta")
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
end
-- 1. yaml-test-suite
local SKIP = { -- !!binary decodes to a buffer; the suite's JSON keeps the base64 text
["565N"] = 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: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 style, text in c.texts do
if style == "multi" then
@@ -75,7 +70,6 @@ for i, c in Corpus do
t:eq(Canon.of(v), c.canon, "corpus " .. i .. " " .. style)
end
end
-- our own output reads back the same (indent 2 and 4, explicit start)
local v = dec(c.texts.block)
for _, o in { {}, { indent = 4 }, { explicitStart = true } } do
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")
end
-- 3. details
do
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")
@@ -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("? a\n: b\n").a, "b", "explicit key")
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
local v2 = dec(enc({ k = str }) :: string)
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")
end
-- 4. errors and limits
local function code(s: string, opts: any?): string?
local _, e = dec(s, opts)
return e and e.code
@@ -170,7 +161,6 @@ do
t:eq(e and e.offset, 12, "error offset")
end
-- 5. API
do
local v, err = F.load(buffer.fromstring("---\nname: x\nlist:\n - 1\n"))
t:check(v ~= nil, "F.load sniffs yaml: " .. tostring(err))