mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-24 14:22:28 +00:00
Further improve JSON serialization
This commit is contained in:
parent
4814b6bdf8
commit
6ee18986e4
20 changed files with 868 additions and 687 deletions
|
@ -1,4 +1,3 @@
|
|||
|
||||
--
|
||||
-- Nicolas Seriot's JSONTestSuite
|
||||
-- https://github.com/nst/JSONTestSuite
|
||||
|
@ -33,124 +32,156 @@
|
|||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_whitespace_formfeed.json
|
||||
-- (converted to binary for safety)
|
||||
assert(false == pcall(DecodeJson, ' \x5b\x0c\x5d '))
|
||||
assert(not DecodeJson(' \x5b\x0c\x5d '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_whitespace_U+2060_word_joiner.json
|
||||
-- (converted to binary for safety)
|
||||
assert(false == pcall(DecodeJson, ' \x5b\xe2\x81\xa0\x5d '))
|
||||
assert(not DecodeJson(' \x5b\xe2\x81\xa0\x5d '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_unicode-identifier.json
|
||||
-- (converted to binary for safety)
|
||||
assert(false == pcall(DecodeJson, ' \xc3\xa5 '))
|
||||
assert(not DecodeJson(' \xc3\xa5 '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_unclosed_object.json
|
||||
assert(false == pcall(DecodeJson, ' {"asd":"asd" '))
|
||||
assert(not DecodeJson(' {"asd":"asd" '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_unclosed_array_unfinished_true.json
|
||||
assert(false == pcall(DecodeJson, ' [ false, tru '))
|
||||
assert(not DecodeJson(' [ false, tru '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_unclosed_array_unfinished_false.json
|
||||
assert(false == pcall(DecodeJson, ' [ true, fals '))
|
||||
assert(not DecodeJson(' [ true, fals '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_unclosed_array_partial_null.json
|
||||
assert(false == pcall(DecodeJson, ' [ false, nul '))
|
||||
assert(not DecodeJson(' [ false, nul '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_unclosed_array.json
|
||||
assert(false == pcall(DecodeJson, ' [1 '))
|
||||
assert(not DecodeJson(' [1 '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_uescaped_LF_before_string.json
|
||||
-- (converted to binary for safety)
|
||||
assert(false == pcall(DecodeJson, ' \x5b\x5c\x75\x30\x30\x30\x41\x22\x22\x5d '))
|
||||
assert(not DecodeJson(' \x5b\x5c\x75\x30\x30\x30\x41\x22\x22\x5d '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_single_star.json
|
||||
assert(false == pcall(DecodeJson, ' * '))
|
||||
assert(not DecodeJson(' * '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_single_eacute.json
|
||||
assert(false == pcall(DecodeJson, ' é '))
|
||||
assert(not DecodeJson(' é '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_open_open.json
|
||||
assert(false == pcall(DecodeJson, [[ ["{["{["{["{ ]]))
|
||||
assert(not DecodeJson([[ ["{["{["{["{ ]]))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_open_object_string_with_apostrophes.json
|
||||
-- (converted to binary for safety)
|
||||
assert(false == pcall(DecodeJson, ' \x7b\x27\x61\x27 '))
|
||||
assert(not DecodeJson(' \x7b\x27\x61\x27 '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_open_object_open_string.json
|
||||
-- (converted to binary for safety)
|
||||
assert(false == pcall(DecodeJson, ' \x7b\x22\x61 '))
|
||||
assert(not DecodeJson(' \x7b\x22\x61 '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_open_object_open_array.json
|
||||
assert(false == pcall(DecodeJson, ' {[ '))
|
||||
assert(not DecodeJson(' {[ '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_open_object_comma.json
|
||||
assert(false == pcall(DecodeJson, ' {, '))
|
||||
assert(not DecodeJson(' {, '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_open_object_close_array.json
|
||||
assert(false == pcall(DecodeJson, ' {] '))
|
||||
assert(not DecodeJson(' {] '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_open_object.json
|
||||
assert(false == pcall(DecodeJson, ' { '))
|
||||
assert(not DecodeJson(' { '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_open_array_string.json
|
||||
-- (converted to binary for safety)
|
||||
assert(false == pcall(DecodeJson, ' \x5b\x22\x61\x22 '))
|
||||
assert(not DecodeJson(' \x5b\x22\x61\x22 '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_open_array_open_string.json
|
||||
-- (converted to binary for safety)
|
||||
assert(false == pcall(DecodeJson, ' \x5b\x22\x61 '))
|
||||
assert(not DecodeJson(' \x5b\x22\x61 '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_open_array_open_object.json
|
||||
assert(false == pcall(DecodeJson, ' [{ '))
|
||||
assert(not DecodeJson(' [{ '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_open_array_comma.json
|
||||
assert(false == pcall(DecodeJson, ' [, '))
|
||||
assert(not DecodeJson(' [, '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_open_array_apostrophe.json
|
||||
assert(false == pcall(DecodeJson, ' [\' '))
|
||||
assert(not DecodeJson(' [\' '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_object_with_comment.json
|
||||
assert(false == pcall(DecodeJson, ' {"a":/*comment*/"b"} '))
|
||||
assert(not DecodeJson(' {"a":/*comment*/"b"} '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_object_unclosed_no_value.json
|
||||
assert(false == pcall(DecodeJson, ' {"": '))
|
||||
assert(not DecodeJson(' {"": '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_null-byte-outside-string.json
|
||||
-- (converted to binary for safety)
|
||||
assert(false == pcall(DecodeJson, ' \x5b\x00\x5d '))
|
||||
assert(not DecodeJson(' \x5b\x00\x5d '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_lone-open-bracket.json
|
||||
assert(false == pcall(DecodeJson, ' [ '))
|
||||
assert(not DecodeJson(' [ '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_lone-invalid-utf-8.json
|
||||
-- (converted to binary for safety)
|
||||
assert(false == pcall(DecodeJson, ' \xe5 '))
|
||||
assert(not DecodeJson(' \xe5 '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_incomplete_UTF8_BOM.json
|
||||
assert(false == pcall(DecodeJson, ' ï»{} '))
|
||||
assert(not DecodeJson(' ï»{} '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_comma_instead_of_closing_brace.json
|
||||
assert(false == pcall(DecodeJson, ' {"x": true, '))
|
||||
assert(not DecodeJson(' {"x": true, '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_capitalized_True.json
|
||||
assert(false == pcall(DecodeJson, ' [True] '))
|
||||
assert(not DecodeJson(' [True] '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_ascii-unicode-identifier.json
|
||||
-- (converted to binary for safety)
|
||||
assert(false == pcall(DecodeJson, ' \x61\xc3\xa5 '))
|
||||
assert(not DecodeJson(' \x61\xc3\xa5 '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_array_with_unclosed_string.json
|
||||
-- (converted to binary for safety)
|
||||
assert(false == pcall(DecodeJson, ' \x5b\x22\x61\x73\x64\x5d '))
|
||||
assert(not DecodeJson(' \x5b\x22\x61\x73\x64\x5d '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_angle_bracket_null.json
|
||||
assert(false == pcall(DecodeJson, ' [<null>] '))
|
||||
assert(not DecodeJson(' [<null>] '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_angle_bracket_..json
|
||||
assert(false == pcall(DecodeJson, ' <.> '))
|
||||
assert(not DecodeJson(' <.> '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_UTF8_BOM_no_data.json
|
||||
assert(false == pcall(DecodeJson, '  '))
|
||||
assert(not DecodeJson('  '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_U+2060_word_joined.json
|
||||
-- (converted to binary for safety)
|
||||
assert(false == pcall(DecodeJson, ' \x5b\xe2\x81\xa0\x5d '))
|
||||
assert(not DecodeJson(' \x5b\xe2\x81\xa0\x5d '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_trailing_#.json
|
||||
assert(not DecodeJson(' {"a":"b"}#{} '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_object_with_trailing_garbage.json
|
||||
assert(not DecodeJson(' {"a": true} "x" '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_object_followed_by_closing_object.json
|
||||
assert(not DecodeJson(' {}} '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_number_with_trailing_garbage.json
|
||||
assert(not DecodeJson(' 2@ '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_no_data.json
|
||||
assert(not DecodeJson(' '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_end_array.json
|
||||
assert(not DecodeJson(' ] '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_double_array.json
|
||||
assert(not DecodeJson(' [][] '))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_close_unopened_array.json
|
||||
assert(not 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(not DecodeJson([[
|
||||
[ 1] ] ]]))
|
||||
|
||||
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_structure_array_trailing_garbage.json
|
||||
assert(not DecodeJson(' [1]x '))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue