Add json.org tests for DecodeJson (#473)

This commit is contained in:
Gautham 2022-07-10 21:05:51 +05:30 committed by GitHub
parent 5fa77f1e8f
commit c0b325bafa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 313 additions and 10 deletions

View file

@ -0,0 +1,5 @@
-- 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

@ -0,0 +1,5 @@
-- 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

@ -0,0 +1,5 @@
-- 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

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

View file

@ -0,0 +1,5 @@
-- 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

@ -0,0 +1,5 @@
-- 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

@ -0,0 +1,5 @@
-- 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

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

View file

@ -0,0 +1,5 @@
-- 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

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

View file

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

View file

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

View file

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

View file

@ -0,0 +1,5 @@
-- 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

@ -0,0 +1,5 @@
-- 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

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

View file

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

View file

@ -0,0 +1,5 @@
-- 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

@ -0,0 +1,5 @@
-- 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

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

View file

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

View file

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

View file

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

View file

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

View file

@ -0,0 +1,5 @@
-- 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

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

View file

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

View file

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

View file

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

View file

@ -0,0 +1,5 @@
-- 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

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

View file

@ -0,0 +1,5 @@
-- 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,62 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: pass1.json
assert(pcall(DecodeJson, [[
[
"JSON Test Pattern pass1",
{"object with 1 member":[ "array with 1 element"] },
{},
[ ] ,
-42,
true,
false,
null,
{
"integer": 1234567890,
"real": -9876.543210,
"e": 0.123456789e-12,
"E": 1.234567890E+34,
"": 23456789012E66,
"zero": 0,
"one": 1,
"space": " ",
"quote": "\"",
"backslash": "\\",
"controls": "\b\f\n\r\t",
"slash": "/ & \/",
"alpha": "abcdefghijklmnopqrstuvwyz",
"ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
"digit": "0123456789",
"0123456789": "digit",
"special": "`1~!@#$%^&*()_+-={':[ ,] }|;.</>?",
"hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
"true": true,
"false": false,
"null": null,
"array":[ ] ,
"object":{ },
"address": "50 St. James Street",
"url": "http://www.JSON.org/",
"comment": "// /* <!-- --",
"# -- --> */": " ",
" s p a c e d " :[ 1,2 , 3
,
4 , 5 , 6 ,7 ] ,"compact":[ 1,2,3,4,5,6,7] ,
"jsontext": "{\"object with 1 member\":[ \"array with 1 element\"] }",
"quotes": "&#34; \u0022 %22 0x22 034 &#x22;",
"\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[ ] {}|;:',./<>?"
: "A key can be any string"
},
0.5 ,98.6
,
99.44
,
1066,
1e1,
0.1e1,
1e-1,
1e00,2e+00,2e-00
,"rosebud"]
]]))

View file

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

View file

@ -0,0 +1,11 @@
-- 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."
}
}
]]))