cosmopolitan/test/tool/net/jsonorg_lenient_test.lua

65 lines
1.8 KiB
Lua
Raw Normal View History

2022-07-12 00:24:24 +05:30
-- 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
2022-07-11 23:06:49 -07:00
assert(DecodeJson([[
2022-07-12 00:24:24 +05:30
[ "extra comma",]
]]))
2022-07-12 12:30:42 -07:00
-- [jart] we deviate from json.org because we don't care about commas
2022-07-12 00:24:24 +05:30
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail5.json
2022-07-11 23:06:49 -07:00
assert(DecodeJson([[
2022-07-12 00:24:24 +05:30
[ "double extra comma",,]
]]))
2022-07-12 12:30:42 -07:00
-- [jart] we deviate from json.org because we don't care about commas
2022-07-12 00:24:24 +05:30
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail6.json
2022-07-11 23:06:49 -07:00
assert(DecodeJson([[
2022-07-12 00:24:24 +05:30
[ , "<-- missing value"]
]]))
2022-07-12 12:30:42 -07:00
-- [jart] we deviate from json.org because we don't care about commas
2022-07-12 00:24:24 +05:30
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail9.json
2022-07-11 23:06:49 -07:00
assert(DecodeJson([[
2022-07-12 00:24:24 +05:30
{"Extra comma": true,}
]]))
2022-07-12 12:30:42 -07:00
-- [jart] we deviate from json.org because we don't care about colons
2022-07-12 00:24:24 +05:30
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail19.json
2022-07-11 23:06:49 -07:00
assert(DecodeJson([[
2022-07-12 00:24:24 +05:30
{"Missing colon" null}
]]))
2022-07-12 12:30:42 -07:00
-- [jart] we deviate from json.org because we don't care about colons
2022-07-12 00:24:24 +05:30
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail20.json
2022-07-11 23:06:49 -07:00
assert(DecodeJson([[
2022-07-12 00:24:24 +05:30
{"Double colon":: null}
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail25.json
2022-07-12 12:30:42 -07:00
assert(not DecodeJson([[
2022-07-12 00:24:24 +05:30
[ " tab character in string "]
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail27.json
2022-07-12 12:30:42 -07:00
assert(not DecodeJson([[
2022-07-12 00:24:24 +05:30
[ "line
break"]
]]))
-- https://www.json.org/JSON_checker/test.zip
2022-07-11 23:06:49 -07:00
-- JSON parsing sample test case: fail15.json
2022-07-12 12:30:42 -07:00
assert(not DecodeJson([[
2022-07-11 23:06:49 -07:00
[ "Illegal backslash escape: \x15"]
2022-07-12 00:24:24 +05:30
]]))