mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-02 04:23:34 +00:00
240 lines
13 KiB
Lua
240 lines
13 KiB
Lua
|
--
|
|||
|
--
|
|||
|
-- Nicolas Seriot's JSONTestSuite
|
|||
|
-- https://github.com/nst/JSONTestSuite
|
|||
|
-- commit d64aefb55228d9584d3e5b2433f720ea8fd00c82
|
|||
|
--
|
|||
|
-- MIT License
|
|||
|
--
|
|||
|
-- Copyright (c) 2016 Nicolas Seriot
|
|||
|
--
|
|||
|
-- Permission is hereby granted, free of charge, to any person obtaining a copy
|
|||
|
-- of this software and associated documentation files (the "Software"), to deal
|
|||
|
-- in the Software without restriction, including without limitation the rights
|
|||
|
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|||
|
-- copies of the Software, and to permit persons to whom the Software is
|
|||
|
-- furnished to do so, subject to the following conditions:
|
|||
|
--
|
|||
|
-- The above copyright notice and this permission notice shall be included in all
|
|||
|
-- copies or substantial portions of the Software.
|
|||
|
--
|
|||
|
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|||
|
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|||
|
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|||
|
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|||
|
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||
|
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||
|
-- SOFTWARE.
|
|||
|
--
|
|||
|
|
|||
|
-- these test cases are prefixed with n_, but
|
|||
|
-- ljson doesn't reject any of them as invalid
|
|||
|
-- we run these tests anyway just to ensure that
|
|||
|
-- no segfaults occurs while parsing these cases
|
|||
|
|
|||
|
|
|||
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_trailing_#.json
|
|||
|
assert(nil ~= pcall(DecodeJson, [[ {"a":"b"}#{} ]]))
|
|||
|
|
|||
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_object_with_trailing_garbage.json
|
|||
|
assert(nil ~= pcall(DecodeJson, [[ {"a": true} "x" ]]))
|
|||
|
|
|||
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_object_followed_by_closing_object.json
|
|||
|
assert(nil ~= pcall(DecodeJson, [[ {}} ]]))
|
|||
|
|
|||
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_number_with_trailing_garbage.json
|
|||
|
assert(nil ~= pcall(DecodeJson, [[ 2@ ]]))
|
|||
|
|
|||
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_no_data.json
|
|||
|
assert(nil ~= pcall(DecodeJson, [[ ]]))
|
|||
|
|
|||
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_end_array.json
|
|||
|
assert(nil ~= pcall(DecodeJson, [[ ] ]]))
|
|||
|
|
|||
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_double_array.json
|
|||
|
assert(nil ~= pcall(DecodeJson, [[ [][] ]]))
|
|||
|
|
|||
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_close_unopened_array.json
|
|||
|
assert(nil ~= pcall(DecodeJson, [[ 1] ]]))
|
|||
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_array_with_extra_array_close.json
|
|||
|
-- (added spaces between [[ and ]] so lua doesn't get confused)
|
|||
|
assert(nil ~= pcall(DecodeJson, [[
|
|||
|
[ 1] ] ]]))
|
|||
|
|
|||
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_array_trailing_garbage.json
|
|||
|
assert(nil ~= pcall(DecodeJson, [[ [1]x ]]))
|
|||
|
|
|||
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_with_trailing_garbage.json
|
|||
|
assert(nil ~= pcall(DecodeJson, [[ ""x ]]))
|
|||
|
|
|||
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_unicode_CapitalU.json
|
|||
|
assert(nil ~= pcall(DecodeJson, [[ "\UA66D" ]]))
|
|||
|
|
|||
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_unescaped_tab.json
|
|||
|
assert(nil ~= pcall(DecodeJson, [[ [" "] ]]))
|
|||
|
|
|||
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_unescaped_newline.json
|
|||
|
assert(nil ~= pcall(DecodeJson, [[
|
|||
|
["new
|
|||
|
line"] ]]))
|
|||
|
|
|||
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_unescaped_ctrl_char.json
|
|||
|
assert(nil ~= pcall(DecodeJson, [[ ["a |