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 -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