mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-10 03:40:29 +00:00
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:
parent
2fda71fb2e
commit
c85d29ee58
71 changed files with 196 additions and 47 deletions
|
@ -1 +0,0 @@
|
|||
"A JSON payload should be an object or array, not a string."
|
5
test/tool/net/samples/fail1.lua
Normal file
5
test/tool/net/samples/fail1.lua
Normal 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."
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
{"Extra value after close": true} "misplaced quoted value"
|
5
test/tool/net/samples/fail10.lua
Normal file
5
test/tool/net/samples/fail10.lua
Normal 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"
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
{"Illegal expression": 1 + 2}
|
5
test/tool/net/samples/fail11.lua
Normal file
5
test/tool/net/samples/fail11.lua
Normal 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}
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
{"Illegal invocation": alert()}
|
5
test/tool/net/samples/fail12.lua
Normal file
5
test/tool/net/samples/fail12.lua
Normal 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()}
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
{"Numbers cannot have leading zeroes": 013}
|
5
test/tool/net/samples/fail13.lua
Normal file
5
test/tool/net/samples/fail13.lua
Normal 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}
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
{"Numbers cannot be hex": 0x14}
|
5
test/tool/net/samples/fail14.lua
Normal file
5
test/tool/net/samples/fail14.lua
Normal 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}
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
["Illegal backslash escape: \x15"]
|
5
test/tool/net/samples/fail15.lua
Normal file
5
test/tool/net/samples/fail15.lua
Normal 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"]
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
[\naked]
|
5
test/tool/net/samples/fail16.lua
Normal file
5
test/tool/net/samples/fail16.lua
Normal file
|
@ -0,0 +1,5 @@
|
|||
-- https://www.json.org/JSON_checker/test.zip
|
||||
-- JSON parsing sample test case: fail16.json
|
||||
assert(nil == DecodeJson([[
|
||||
[ \naked]
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
["Illegal backslash escape: \017"]
|
5
test/tool/net/samples/fail17.lua
Normal file
5
test/tool/net/samples/fail17.lua
Normal 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"]
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]
|
5
test/tool/net/samples/fail18.lua
Normal file
5
test/tool/net/samples/fail18.lua
Normal file
|
@ -0,0 +1,5 @@
|
|||
-- https://www.json.org/JSON_checker/test.zip
|
||||
-- JSON parsing sample test case: fail18.json
|
||||
assert(DecodeJson([[
|
||||
[ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ "Too deep"] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ]
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
{"Missing colon" null}
|
5
test/tool/net/samples/fail19.lua
Normal file
5
test/tool/net/samples/fail19.lua
Normal 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}
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
["Unclosed array"
|
5
test/tool/net/samples/fail2.lua
Normal file
5
test/tool/net/samples/fail2.lua
Normal 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"
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
{"Double colon":: null}
|
5
test/tool/net/samples/fail20.lua
Normal file
5
test/tool/net/samples/fail20.lua
Normal 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}
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
{"Comma instead of colon", null}
|
5
test/tool/net/samples/fail21.lua
Normal file
5
test/tool/net/samples/fail21.lua
Normal 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}
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
["Colon instead of comma": false]
|
5
test/tool/net/samples/fail22.lua
Normal file
5
test/tool/net/samples/fail22.lua
Normal 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]
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
["Bad value", truth]
|
5
test/tool/net/samples/fail23.lua
Normal file
5
test/tool/net/samples/fail23.lua
Normal 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]
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
['single quote']
|
5
test/tool/net/samples/fail24.lua
Normal file
5
test/tool/net/samples/fail24.lua
Normal 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']
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
[" tab character in string "]
|
5
test/tool/net/samples/fail25.lua
Normal file
5
test/tool/net/samples/fail25.lua
Normal 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 "]
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
["tab\ character\ in\ string\ "]
|
5
test/tool/net/samples/fail26.lua
Normal file
5
test/tool/net/samples/fail26.lua
Normal 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\ "]
|
||||
]]))
|
|
@ -1,2 +0,0 @@
|
|||
["line
|
||||
break"]
|
6
test/tool/net/samples/fail27.lua
Normal file
6
test/tool/net/samples/fail27.lua
Normal 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"]
|
||||
]]))
|
|
@ -1,2 +0,0 @@
|
|||
["line\
|
||||
break"]
|
6
test/tool/net/samples/fail28.lua
Normal file
6
test/tool/net/samples/fail28.lua
Normal 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"]
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
[0e]
|
5
test/tool/net/samples/fail29.lua
Normal file
5
test/tool/net/samples/fail29.lua
Normal file
|
@ -0,0 +1,5 @@
|
|||
-- https://www.json.org/JSON_checker/test.zip
|
||||
-- JSON parsing sample test case: fail29.json
|
||||
assert(nil == DecodeJson([[
|
||||
[ 0e]
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
{unquoted_key: "keys must be quoted"}
|
5
test/tool/net/samples/fail3.lua
Normal file
5
test/tool/net/samples/fail3.lua
Normal 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"}
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
[0e+]
|
5
test/tool/net/samples/fail30.lua
Normal file
5
test/tool/net/samples/fail30.lua
Normal file
|
@ -0,0 +1,5 @@
|
|||
-- https://www.json.org/JSON_checker/test.zip
|
||||
-- JSON parsing sample test case: fail30.json
|
||||
assert(nil == DecodeJson([[
|
||||
[ 0e+]
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
[0e+-1]
|
5
test/tool/net/samples/fail31.lua
Normal file
5
test/tool/net/samples/fail31.lua
Normal 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]
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
{"Comma instead if closing brace": true,
|
5
test/tool/net/samples/fail32.lua
Normal file
5
test/tool/net/samples/fail32.lua
Normal 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,
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
["mismatch"}
|
5
test/tool/net/samples/fail33.lua
Normal file
5
test/tool/net/samples/fail33.lua
Normal file
|
@ -0,0 +1,5 @@
|
|||
-- https://www.json.org/JSON_checker/test.zip
|
||||
-- JSON parsing sample test case: fail33.json
|
||||
assert(nil == DecodeJson([[
|
||||
[ "mismatch"}
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
["extra comma",]
|
5
test/tool/net/samples/fail4.lua
Normal file
5
test/tool/net/samples/fail4.lua
Normal 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",]
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
["double extra comma",,]
|
5
test/tool/net/samples/fail5.lua
Normal file
5
test/tool/net/samples/fail5.lua
Normal 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",,]
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
[ , "<-- missing value"]
|
5
test/tool/net/samples/fail6.lua
Normal file
5
test/tool/net/samples/fail6.lua
Normal 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"]
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
["Comma after the close"],
|
5
test/tool/net/samples/fail7.lua
Normal file
5
test/tool/net/samples/fail7.lua
Normal 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"] ,
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
["Extra close"]]
|
5
test/tool/net/samples/fail8.lua
Normal file
5
test/tool/net/samples/fail8.lua
Normal 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"] ]
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
{"Extra comma": true,}
|
5
test/tool/net/samples/fail9.lua
Normal file
5
test/tool/net/samples/fail9.lua
Normal 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,}
|
||||
]]))
|
|
@ -1,8 +1,11 @@
|
|||
[
|
||||
-- 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"]},
|
||||
{"object with 1 member":[ "array with 1 element"] },
|
||||
{},
|
||||
[],
|
||||
[ ] ,
|
||||
-42,
|
||||
true,
|
||||
false,
|
||||
|
@ -24,25 +27,25 @@
|
|||
"ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
|
||||
"digit": "0123456789",
|
||||
"0123456789": "digit",
|
||||
"special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
|
||||
"special": "`1~!@#$%^&*()_+-={':[ ,] }|;.</>?",
|
||||
"hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
|
||||
"true": true,
|
||||
"false": false,
|
||||
"null": null,
|
||||
"array":[ ],
|
||||
"array":[ ] ,
|
||||
"object":{ },
|
||||
"address": "50 St. James Street",
|
||||
"url": "http://www.JSON.org/",
|
||||
"comment": "// /* <!-- --",
|
||||
"# -- --> */": " ",
|
||||
" s p a c e d " :[1,2 , 3
|
||||
" 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\"]}",
|
||||
4 , 5 , 6 ,7 ] ,"compact":[ 1,2,3,4,5,6,7] ,
|
||||
"jsontext": "{\"object with 1 member\":[ \"array with 1 element\"] }",
|
||||
"quotes": "" \u0022 %22 0x22 034 "",
|
||||
"\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
|
||||
"\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[ ] {}|;:',./<>?"
|
||||
: "A key can be any string"
|
||||
},
|
||||
0.5 ,98.6
|
||||
|
@ -55,4 +58,5 @@
|
|||
0.1e1,
|
||||
1e-1,
|
||||
1e00,2e+00,2e-00
|
||||
,"rosebud"]
|
||||
,"rosebud"]
|
||||
]]))
|
|
@ -1 +0,0 @@
|
|||
[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
|
5
test/tool/net/samples/pass2.lua
Normal file
5
test/tool/net/samples/pass2.lua
Normal 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"] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ]
|
||||
]]))
|
|
@ -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."
|
||||
}
|
||||
}
|
||||
|
||||
]]))
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue