Audit every single JSON test

This commit is contained in:
Justine Tunney 2022-07-12 12:30:42 -07:00
parent 7965ed0232
commit 3f3e7e92d7
17 changed files with 473 additions and 285 deletions

View file

@ -1,6 +1,6 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: pass1.json
assert(pcall(DecodeJson, [[
assert(DecodeJson([[
[
"JSON Test Pattern pass1",
{"object with 1 member":[ "array with 1 element"] },
@ -63,14 +63,13 @@ assert(pcall(DecodeJson, [[
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: pass2.json
assert(pcall(DecodeJson, [[
assert(DecodeJson([[
[ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ "Not too deep"] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ]
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: pass3.json
assert(pcall(DecodeJson, [[
assert(DecodeJson([[
{
"JSON Test Pattern pass3": {
"The outermost value": "must be an object or array.",
@ -80,18 +79,20 @@ assert(pcall(DecodeJson, [[
]]))
-- json.org says these should fail, but many parsers,
-- including python's json.load allow the following
-- [jart] our behavior is consistent with v8
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail1.json (actually passes)
assert(pcall(DecodeJson, [[
assert(DecodeJson([[
"A JSON payload should be an object or array, not a string."
]]))
-- [jart] this deviates from json.org
-- we permit depth up to 128
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail18.json (actually passes)
assert(pcall(DecodeJson, [[
assert(DecodeJson([[
[ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ "Too deep"] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ]
]]))