tests/codecs (a-m): comments: specs only
This commit is contained in:
1 parent
a80299dce0
commit
5f7f6005f6
24 files changed
+46
-181
No files matched your search
@@ -1,6 +1,4 @@
|
||||
-- codecs/text/Json tests: the JSONTestSuite parsing corpus (y_ must parse to Python's value, n_ must fail, i_ must not
|
||||
-- throw), Python json.dumps output in four styles parsed and reproduced byte for byte (compact sorted, ordered,
|
||||
-- indent 2, ensure_ascii), events / lines / decodeAt / writer, options, error codes, and the fuzz pass.
|
||||
-- codecs/text/Json tests: the JSONTestSuite corpus, Python json.dumps output reproduced byte for byte, the API.
|
||||
-- Fixtures: tools/fixtures/json.py.
|
||||
local T = require("@tests/T")
|
||||
local Json = require("@rosetta/codecs/text/Json")
|
||||
@@ -47,7 +45,7 @@ local function fromEvents(s: string): (any, any)
|
||||
return top, nil
|
||||
end
|
||||
|
||||
-- 1. JSONTestSuite
|
||||
-- JSONTestSuite: y_ must parse to Python's value, n_ must fail, i_ must not throw
|
||||
local counts = { y = 0, n = 0, i = 0, iok = 0 }
|
||||
for _, c in Suite do
|
||||
local v, err = Json.decode(c.data)
|
||||
@@ -71,7 +69,6 @@ for _, c in Suite do
|
||||
end
|
||||
t:note("JSONTestSuite: %d y_ accepted, %d n_ rejected, %d of %d i_ accepted", counts.y, counts.n, counts.iok, counts.i)
|
||||
|
||||
-- 2. Python's json.dumps output: parse, compare, re-encode byte for byte
|
||||
for i, c in Corpus do
|
||||
local v, err = Json.decode(c.compact)
|
||||
t:check(v ~= nil, "corpus " .. i .. ": " .. tostring(err))
|
||||
@@ -85,7 +82,6 @@ for i, c in Corpus do
|
||||
t:eq(Canon.of(Json.decode(c.pretty)), c.canon, "corpus " .. i .. ": pretty parse")
|
||||
end
|
||||
|
||||
-- 3. options and API
|
||||
do
|
||||
local v = Json.decode('[12345678901234567890, -9007199254740993, 9007199254740991, 1.5e300]', { bigInts = "string" })
|
||||
t:eq(v[1], "12345678901234567890", "bigInts string")
|
||||
@@ -122,7 +118,6 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
-- 4. streaming: lines, decodeAt, writer
|
||||
do
|
||||
local got = {}
|
||||
for _, v in Json.lines('{"a":1}\n[2]\n"x"\n 3 ') do
|
||||
@@ -170,7 +165,6 @@ do
|
||||
t:check(w5:tostring() == nil, "writer: unclosed")
|
||||
end
|
||||
|
||||
-- 5. errors
|
||||
local function code(s: string, opts: any?): string?
|
||||
local _, e = Json.decode(s, opts)
|
||||
return e and e.code
|
||||
@@ -189,7 +183,6 @@ do
|
||||
t:eq(e and e.offset, 6, "error offset")
|
||||
end
|
||||
|
||||
-- 6. fuzz
|
||||
local samples = {}
|
||||
for i = 1, 40 do
|
||||
table.insert(samples, Corpus[i].compact)
|
||||
|
||||
Reference in new issue
Block a user