updated test cases to use pcall

pcall catches errors
This commit is contained in:
ahgamut 2022-07-10 13:42:57 +05:30
parent c85d29ee58
commit ff64ded383
36 changed files with 36 additions and 36 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,6 @@
-- https://www.json.org/JSON_checker/test.zip -- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: pass1.json -- JSON parsing sample test case: pass1.json
assert(DecodeJson([[ assert(pcall(DecodeJson, [[
[ [
"JSON Test Pattern pass1", "JSON Test Pattern pass1",
{"object with 1 member":[ "array with 1 element"] }, {"object with 1 member":[ "array with 1 element"] },

View file

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

View file

@ -1,6 +1,6 @@
-- https://www.json.org/JSON_checker/test.zip -- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: pass3.json -- JSON parsing sample test case: pass3.json
assert(DecodeJson([[ assert(pcall(DecodeJson, [[
{ {
"JSON Test Pattern pass3": { "JSON Test Pattern pass3": {
"The outermost value": "must be an object or array.", "The outermost value": "must be an object or array.",