converted json.org tests into lua files

DecodeJson works on strings, so I pasted every JSON file as a
multiline string into a lua file. This required one small change to the
test cases, which is putting a space after every [ or ], so that Lua
doesn't get confused by [[ or ]] which are the multiline string
terminators (see pass2.lua for an example).
This commit is contained in:
ahgamut 2022-07-10 11:38:38 +05:30
parent 2fda71fb2e
commit c85d29ee58
71 changed files with 196 additions and 47 deletions

View file

@ -1 +0,0 @@
"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: fail1.json
assert(DecodeJson([[
"A JSON payload should be an object or array, not a string."
]]))

View file

@ -1 +0,0 @@
{"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: fail10.json
assert(nil == DecodeJson([[
{"Extra value after close": true} "misplaced quoted value"
]]))

View file

@ -1 +0,0 @@
{"Illegal expression": 1 + 2}

View file

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

View file

@ -1 +0,0 @@
{"Illegal invocation": alert()}

View file

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

View file

@ -1 +0,0 @@
{"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: fail13.json
assert(nil == DecodeJson([[
{"Numbers cannot have leading zeroes": 013}
]]))

View file

@ -1 +0,0 @@
{"Numbers cannot be hex": 0x14}

View file

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

View file

@ -1 +0,0 @@
["Illegal backslash escape: \x15"]

View file

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

View file

@ -1 +0,0 @@
[\naked]

View file

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

View file

@ -1 +0,0 @@
["Illegal backslash escape: \017"]

View file

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

View file

@ -1 +0,0 @@
[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]

View file

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

View file

@ -1 +0,0 @@
{"Missing colon" null}

View file

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

View file

@ -1 +0,0 @@
["Unclosed array"

View file

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

View file

@ -1 +0,0 @@
{"Double colon":: null}

View file

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

View file

@ -1 +0,0 @@
{"Comma instead of colon", null}

View file

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

View file

@ -1 +0,0 @@
["Colon instead of comma": false]

View file

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

View file

@ -1 +0,0 @@
["Bad value", truth]

View file

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

View file

@ -1 +0,0 @@
['single quote']

View file

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

View file

@ -1 +0,0 @@
[" tab character in string "]

View file

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

View file

@ -1 +0,0 @@
["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(nil == DecodeJson([[
[ "tab\ character\ in\ string\ "]
]]))

View file

@ -1,2 +0,0 @@
["line
break"]

View file

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

View file

@ -1,2 +0,0 @@
["line\
break"]

View file

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

View file

@ -1 +0,0 @@
[0e]

View file

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

View file

@ -1 +0,0 @@
{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: fail3.json
assert(nil == DecodeJson([[
{unquoted_key: "keys must be quoted"}
]]))

View file

@ -1 +0,0 @@
[0e+]

View file

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

View file

@ -1 +0,0 @@
[0e+-1]

View file

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

View file

@ -1 +0,0 @@
{"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: fail32.json
assert(nil == DecodeJson([[
{"Comma instead if closing brace": true,
]]))

View file

@ -1 +0,0 @@
["mismatch"}

View file

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

View file

@ -1 +0,0 @@
["extra comma",]

View file

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

View file

@ -1 +0,0 @@
["double extra comma",,]

View file

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

View file

@ -1 +0,0 @@
[ , "<-- missing value"]

View file

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

View file

@ -1 +0,0 @@
["Comma after the close"],

View file

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

View file

@ -1 +0,0 @@
["Extra close"]]

View file

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

View file

@ -1 +0,0 @@
{"Extra comma": true,}

View file

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

View file

@ -1,3 +1,6 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: pass1.json
assert(DecodeJson([[
[
"JSON Test Pattern pass1",
{"object with 1 member":[ "array with 1 element"] },
@ -56,3 +59,4 @@
1e-1,
1e00,2e+00,2e-00
,"rosebud"]
]]))

View file

@ -1 +0,0 @@
[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]

View file

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

View file

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

View file

@ -6,9 +6,13 @@ PKGS += TEST_TOOL_NET
TEST_TOOL_NET = $(TOOL_NET_A_DEPS) $(TOOL_NET_A)
TEST_TOOL_NET_A = o/$(MODE)/test/tool/net/net.a
TEST_TOOL_NET_FILES := $(wildcard test/tool/net/*)
TEST_TOOL_NET_JSONORG := $(wildcard test/tool/net/samples/*)
TEST_TOOL_NET_JSONORG_LUA = $(filter %.lua,$(TEST_TOOL_NET_JSONORG))
TEST_TOOL_NET_SRCS = $(filter %.c,$(TEST_TOOL_NET_FILES))
TEST_TOOL_NET_SRCS_TEST = $(filter %_test.c,$(TEST_TOOL_NET_SRCS))
TEST_TOOL_NET_LUAS_TEST = $(filter %_test.lua,$(TEST_TOOL_NET_FILES))
TEST_TOOL_NET_LUAS_TEST = \
$(filter %_test.lua,$(TEST_TOOL_NET_FILES)) \
$(TEST_TOOL_NET_JSONORG_LUA)
TEST_TOOL_NET_HDRS = $(filter %.h,$(TEST_TOOL_NET_FILES))
TEST_TOOL_NET_COMS = $(TEST_TOOL_NET_SRCS:%.c=o/$(MODE)/%.com)