tests/data: comments: specs only
This commit is contained in:
1 parent
653ce4e002
commit
7672980c65
12 files changed
+16
-63
No files matched your search
+1
-11
@@ -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))
|
||||
|
||||
Reference in new issue
Block a user