combine json.org test cases into groups

- tests that pass are most important because they show ljson accepts
  everything that is valid json
- tests that fail because ljson follows the constraints set by json.org are
  good because they show the limits of ljson's leniency
- tests that fail because ljson is too lenient are okay as long as they
  don't cause a segfault or some other nasty behavior
This commit is contained in:
ahgamut 2022-07-11 22:13:16 +05:30
parent a44074557a
commit 7c6988ad66
38 changed files with 226 additions and 183 deletions

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail1.json
assert(pcall(DecodeJson, [[
"A JSON payload should be an object or array, not a string."
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail10.json
assert(false == pcall(DecodeJson, [[
{"Extra value after close": true} "misplaced quoted value"
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail11.json
assert(false == pcall(DecodeJson, [[
{"Illegal expression": 1 + 2}
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail12.json
assert(false == pcall(DecodeJson, [[
{"Illegal invocation": alert()}
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail13.json
assert(false == pcall(DecodeJson, [[
{"Numbers cannot have leading zeroes": 013}
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail14.json
assert(false == pcall(DecodeJson, [[
{"Numbers cannot be hex": 0x14}
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail15.json
assert(false == pcall(DecodeJson, [[
[ "Illegal backslash escape: \x15"]
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail16.json
assert(false == pcall(DecodeJson, [[
[ \naked]
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail17.json
assert(false == pcall(DecodeJson, [[
[ "Illegal backslash escape: \017"]
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail18.json
assert(pcall(DecodeJson, [[
[ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ "Too deep"] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ]
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail19.json
assert(false == pcall(DecodeJson, [[
{"Missing colon" null}
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail2.json
assert(false == pcall(DecodeJson, [[
[ "Unclosed array"
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail20.json
assert(false == pcall(DecodeJson, [[
{"Double colon":: null}
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail21.json
assert(false == pcall(DecodeJson, [[
{"Comma instead of colon", null}
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail22.json
assert(false == pcall(DecodeJson, [[
[ "Colon instead of comma": false]
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail23.json
assert(false == pcall(DecodeJson, [[
[ "Bad value", truth]
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail24.json
assert(false == pcall(DecodeJson, [[
[ 'single quote']
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail25.json
assert(false == pcall(DecodeJson, [[
[ " tab character in string "]
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail26.json
assert(false == pcall(DecodeJson, [[
[ "tab\ character\ in\ string\ "]
]]))

View file

@ -1,6 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail27.json
assert(false == pcall(DecodeJson, [[
[ "line
break"]
]]))

View file

@ -1,6 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail28.json
assert(false == pcall(DecodeJson, [[
[ "line\
break"]
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail29.json
assert(false == pcall(DecodeJson, [[
[ 0e]
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail3.json
assert(false == pcall(DecodeJson, [[
{unquoted_key: "keys must be quoted"}
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail30.json
assert(false == pcall(DecodeJson, [[
[ 0e+]
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail31.json
assert(false == pcall(DecodeJson, [[
[ 0e+-1]
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail32.json
assert(false == pcall(DecodeJson, [[
{"Comma instead if closing brace": true,
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail33.json
assert(false == pcall(DecodeJson, [[
[ "mismatch"}
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail4.json
assert(false == pcall(DecodeJson, [[
[ "extra comma",]
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail5.json
assert(false == pcall(DecodeJson, [[
[ "double extra comma",,]
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail6.json
assert(false == pcall(DecodeJson, [[
[ , "<-- missing value"]
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail7.json
assert(false == pcall(DecodeJson, [[
[ "Comma after the close"] ,
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail8.json
assert(false == pcall(DecodeJson, [[
[ "Extra close"] ]
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail9.json
assert(false == pcall(DecodeJson, [[
{"Extra comma": true,}
]]))

View file

@ -0,0 +1,101 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail11.json
assert(false == pcall(DecodeJson, [[
{"Illegal expression": 1 + 2}
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail12.json
assert(false == pcall(DecodeJson, [[
{"Illegal invocation": alert()}
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail13.json
assert(false == pcall(DecodeJson, [[
{"Numbers cannot have leading zeroes": 013}
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail14.json
assert(false == pcall(DecodeJson, [[
{"Numbers cannot be hex": 0x14}
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail15.json
assert(false == pcall(DecodeJson, [[
[ "Illegal backslash escape: \x15"]
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail16.json
assert(false == pcall(DecodeJson, [[
[ \naked]
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail17.json
assert(false == pcall(DecodeJson, [[
[ "Illegal backslash escape: \017"]
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail22.json
assert(false == pcall(DecodeJson, [[
[ "Colon instead of comma": false]
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail23.json
assert(false == pcall(DecodeJson, [[
[ "Bad value", truth]
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail24.json
assert(false == pcall(DecodeJson, [[
[ 'single quote']
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail29.json
assert(false == pcall(DecodeJson, [[
[ 0e]
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail2.json
assert(false == pcall(DecodeJson, [[
[ "Unclosed array"
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail30.json
assert(false == pcall(DecodeJson, [[
[ 0e+]
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail31.json
assert(false == pcall(DecodeJson, [[
[ 0e+-1]
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail32.json
assert(false == pcall(DecodeJson, [[
{"Comma instead if closing brace": true,
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail33.json
assert(false == pcall(DecodeJson, [[
[ "mismatch"}
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail3.json
assert(false == pcall(DecodeJson, [[
{unquoted_key: "keys must be quoted"}
]]))

View file

@ -0,0 +1,90 @@
-- json.org says the following test cases should be
-- considered as invalid JSON, but ljson.c is lenient.
-- we run these tests anyway just to ensure that
-- no segfaults occurs while parsing these cases
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail4.json
assert(nil ~= pcall(DecodeJson, [[
[ "extra comma",]
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail5.json
assert(nil ~= pcall(DecodeJson, [[
[ "double extra comma",,]
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail6.json
assert(nil ~= pcall(DecodeJson, [[
[ , "<-- missing value"]
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail7.json
assert(nil ~= pcall(DecodeJson, [[
[ "Comma after the close"] ,
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail8.json
assert(nil ~= pcall(DecodeJson, [[
[ "Extra close"] ]
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail9.json
assert(nil ~= pcall(DecodeJson, [[
{"Extra comma": true,}
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail19.json
assert(nil ~= pcall(DecodeJson, [[
{"Missing colon" null}
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail20.json
assert(nil ~= pcall(DecodeJson, [[
{"Double colon":: null}
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail21.json
assert(nil ~= pcall(DecodeJson, [[
{"Comma instead of colon", null}
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail10.json
assert(nil ~= pcall(DecodeJson, [[
{"Extra value after close": true} "misplaced quoted value"
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail25.json
assert(nil ~= pcall(DecodeJson, [[
[ " tab character in string "]
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail26.json
assert(nil ~= pcall(DecodeJson, [[
[ "tab\ character\ in\ string\ "]
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail27.json
assert(nil ~= pcall(DecodeJson, [[
[ "line
break"]
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail28.json
assert(nil ~= pcall(DecodeJson, [[
[ "line\
break"]
]]))

View file

@ -60,3 +60,38 @@ assert(pcall(DecodeJson, [[
1e00,2e+00,2e-00
,"rosebud"]
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: pass2.json
assert(pcall(DecodeJson, [[
[ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ "Not too deep"] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ]
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: pass3.json
assert(pcall(DecodeJson, [[
{
"JSON Test Pattern pass3": {
"The outermost value": "must be an object or array.",
"In this test": "It is an object."
}
}
]]))
-- json.org says these should fail, but many parsers,
-- including python's json.load allow the following
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail1.json (actually passes)
assert(pcall(DecodeJson, [[
"A JSON payload should be an object or array, not a string."
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail18.json (actually passes)
assert(pcall(DecodeJson, [[
[ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ "Too deep"] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ]
]]))

View file

@ -1,5 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: pass2.json
assert(pcall(DecodeJson, [[
[ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ "Not too deep"] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ]
]]))

View file

@ -1,11 +0,0 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: pass3.json
assert(pcall(DecodeJson, [[
{
"JSON Test Pattern pass3": {
"The outermost value": "must be an object or array.",
"In this test": "It is an object."
}
}
]]))