2022-07-12 00:24:24 +05:30
|
|
|
--
|
|
|
|
-- 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.
|
|
|
|
--
|
|
|
|
|
2022-07-12 12:30:42 -07:00
|
|
|
-- [jart] these tests deviate from the expectations of the upstream test
|
|
|
|
-- suite. most of these failures are because we permit syntax
|
|
|
|
-- like this since it saves bandwidth and makes the impl smaller.
|
|
|
|
-- we're also more permissive about things like the encoding of
|
|
|
|
-- double exponents and empty double fraction.
|
|
|
|
assert(EncodeLua(DecodeJson('[0 1 2 3 4]')) == '{0, 1, 2, 3, 4}')
|
2022-07-12 06:34:51 +05:30
|
|
|
|
2022-07-12 12:30:42 -07:00
|
|
|
-- from fail4.lua
|
|
|
|
--------------------------------------------------------------------------------
|
2022-07-12 03:46:44 +05:30
|
|
|
|
|
|
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_object_two_commas_in_a_row.json
|
2022-07-11 23:06:49 -07:00
|
|
|
assert(DecodeJson(' {"a":"b",,"c":"d"} '))
|
2022-07-12 12:30:42 -07:00
|
|
|
assert(EncodeLua(DecodeJson(' {"a":"b",,"c":"d"} ')) == '{a="b", c="d"}')
|
2022-07-12 03:46:44 +05:30
|
|
|
|
|
|
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_object_trailing_comma.json
|
2022-07-11 23:06:49 -07:00
|
|
|
assert(DecodeJson(' {"id":0,} '))
|
2022-07-12 12:30:42 -07:00
|
|
|
assert(EncodeLua(DecodeJson(' {"id":0,} ')) == '{id=0}')
|
2022-07-12 03:46:44 +05:30
|
|
|
|
|
|
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_object_several_trailing_commas.json
|
2022-07-11 23:06:49 -07:00
|
|
|
assert(DecodeJson(' {"id":0,,,,,} '))
|
2022-07-12 12:30:42 -07:00
|
|
|
assert(EncodeLua(DecodeJson(' {"id":0,,,,,} ')) == '{id=0}')
|
2022-07-12 00:24:24 +05:30
|
|
|
|
2022-07-12 03:46:44 +05:30
|
|
|
-- from fail1.lua
|
2022-07-12 12:30:42 -07:00
|
|
|
--------------------------------------------------------------------------------
|
2022-07-12 00:24:24 +05:30
|
|
|
|
2022-07-12 12:30:42 -07:00
|
|
|
-- [jart] v8 permits the \xb9 but doesn't permit the trailing comma
|
|
|
|
-- therefore this succeeds beacuse we don't care about comma
|
2022-07-12 06:34:51 +05:30
|
|
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_object_lone_continuation_byte_in_key_and_trailing_comma.json
|
2022-07-11 23:06:49 -07:00
|
|
|
assert(DecodeJson(" {\"\xb9\":\"0\",} "))
|
2022-07-12 12:30:42 -07:00
|
|
|
assert(EncodeLua(DecodeJson(" {\"\xb9\":\"0\",} ")) == '{["\\xb9"]="0"}')
|
2022-07-12 00:24:24 +05:30
|
|
|
|
|
|
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_object_missing_semicolon.json
|
2022-07-11 23:06:49 -07:00
|
|
|
assert(DecodeJson(' {"a" "b"} '))
|
2022-07-12 12:30:42 -07:00
|
|
|
assert(EncodeLua(DecodeJson(' {"a" "b"} ')) == '{a="b"}')
|
2022-07-12 00:24:24 +05:30
|
|
|
|
|
|
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_object_double_colon.json
|
2022-07-11 23:06:49 -07:00
|
|
|
assert(DecodeJson(' {"x"::"b"} '))
|
2022-07-12 12:30:42 -07:00
|
|
|
assert(EncodeLua(DecodeJson(' {"x"::"b"} ')) == '{x="b"}')
|
2022-07-12 00:24:24 +05:30
|
|
|
|
|
|
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_number_real_without_fractional_part.json
|
2022-07-11 23:06:49 -07:00
|
|
|
assert(DecodeJson(' [1.] '))
|
2022-07-12 12:30:42 -07:00
|
|
|
assert(EncodeLua(DecodeJson(' [1.] ')) == EncodeLua({1.0}))
|
2022-07-12 00:24:24 +05:30
|
|
|
|
|
|
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_number_2.e3.json
|
2022-07-11 23:06:49 -07:00
|
|
|
assert(DecodeJson(' [2.e3] '))
|
2022-07-12 12:30:42 -07:00
|
|
|
assert(EncodeLua(DecodeJson(' [2.e3] ')) == '{2000.}')
|
2022-07-12 00:24:24 +05:30
|
|
|
|
|
|
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_number_2.e-3.json
|
2022-07-11 23:06:49 -07:00
|
|
|
assert(DecodeJson(' [2.e-3] '))
|
2022-07-12 12:30:42 -07:00
|
|
|
assert(EncodeLua(DecodeJson(' [2.e-3] ')) == '{0.002}')
|
2022-07-12 00:24:24 +05:30
|
|
|
|
|
|
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_number_2.e+3.json
|
2022-07-11 23:06:49 -07:00
|
|
|
assert(DecodeJson(' [2.e+3] '))
|
2022-07-12 12:30:42 -07:00
|
|
|
assert(EncodeLua(DecodeJson(' [2.e+3] ')) == '{2000.}')
|
2022-07-12 03:46:44 +05:30
|
|
|
|
2022-07-12 00:24:24 +05:30
|
|
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_number_0.e1.json
|
2022-07-11 23:06:49 -07:00
|
|
|
assert(DecodeJson(' [0.e1] '))
|
2022-07-12 12:30:42 -07:00
|
|
|
assert(EncodeLua(DecodeJson(' [0.e1] ')) == '{0.}')
|
2022-07-12 00:24:24 +05:30
|
|
|
|
2022-07-12 03:46:44 +05:30
|
|
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_number_-2..json
|
2022-07-11 23:06:49 -07:00
|
|
|
assert(DecodeJson(' [-2.] '))
|
2022-07-12 12:30:42 -07:00
|
|
|
assert(EncodeLua(DecodeJson(' [-2.] ')) == '{-2.}')
|
2022-07-12 03:46:44 +05:30
|
|
|
|
2022-07-12 12:30:42 -07:00
|
|
|
-- lool
|
|
|
|
assert(not DecodeJson(' [--2.] '))
|
2022-07-12 00:24:24 +05:30
|
|
|
|
|
|
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_array_number_and_several_commas.json
|
2022-07-11 23:06:49 -07:00
|
|
|
assert(DecodeJson(' [1,,] '))
|
2022-07-12 12:30:42 -07:00
|
|
|
assert(EncodeLua(DecodeJson(' [1,,] ')) == '{1}')
|
2022-07-12 00:24:24 +05:30
|
|
|
|
|
|
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_array_number_and_comma.json
|
2022-07-11 23:06:49 -07:00
|
|
|
assert(DecodeJson(' [1,] '))
|
2022-07-12 12:30:42 -07:00
|
|
|
assert(EncodeLua(DecodeJson(' [1,] ')) == '{1}')
|
2022-07-12 00:24:24 +05:30
|
|
|
|
|
|
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_array_missing_value.json
|
2022-07-11 23:06:49 -07:00
|
|
|
assert(DecodeJson(' [ , ""] '))
|
2022-07-12 12:30:42 -07:00
|
|
|
assert(EncodeLua(DecodeJson(' [ , ""] ')) == '{""}')
|
2022-07-12 00:24:24 +05:30
|
|
|
|
|
|
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_array_just_comma.json
|
2022-07-11 23:06:49 -07:00
|
|
|
assert(DecodeJson(' [,] '))
|
2022-07-12 12:30:42 -07:00
|
|
|
assert(EncodeLua(DecodeJson(' [,] ')) == EncodeLua(DecodeJson(' [] ')))
|
2022-07-12 00:24:24 +05:30
|
|
|
|
|
|
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_array_inner_array_no_comma.json
|
|
|
|
-- (added spaces between [[ and ]] so lua doesn't get confused)
|
2022-07-11 23:06:49 -07:00
|
|
|
assert(DecodeJson([[
|
2022-07-12 00:24:24 +05:30
|
|
|
[ 3[ 4] ] ]]))
|
2022-07-12 12:30:42 -07:00
|
|
|
assert(EncodeLua(DecodeJson([[
|
|
|
|
[ 3[ 4] ] ]])) == '{3, {4}}')
|
2022-07-12 00:24:24 +05:30
|
|
|
|
|
|
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_array_extra_comma.json
|
2022-07-11 23:06:49 -07:00
|
|
|
assert(DecodeJson(' ["",] '))
|
2022-07-12 12:30:42 -07:00
|
|
|
assert(EncodeLua(DecodeJson(' ["",] ')) == '{""}')
|
2022-07-12 00:24:24 +05:30
|
|
|
|
|
|
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_array_double_extra_comma.json
|
2022-07-11 23:06:49 -07:00
|
|
|
assert(DecodeJson(' ["x",,] '))
|
2022-07-12 12:30:42 -07:00
|
|
|
assert(EncodeLua(DecodeJson(' ["x",,] ')) == '{"x"}')
|
2022-07-12 03:46:44 +05:30
|
|
|
|
2022-07-12 00:24:24 +05:30
|
|
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_array_double_comma.json
|
2022-07-11 23:06:49 -07:00
|
|
|
assert(DecodeJson(' [1,,2] '))
|
2022-07-12 12:30:42 -07:00
|
|
|
assert(EncodeLua(DecodeJson(' [1,,2] ')) == '{1, 2}')
|
2022-07-12 00:24:24 +05:30
|
|
|
|
|
|
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_array_comma_and_number.json
|
2022-07-11 23:06:49 -07:00
|
|
|
assert(DecodeJson(' [,1] '))
|
2022-07-12 12:30:42 -07:00
|
|
|
assert(EncodeLua(DecodeJson(' [,1] ')) == '{1}')
|
2022-07-12 00:24:24 +05:30
|
|
|
|
|
|
|
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_array_1_true_without_comma.json
|
2022-07-11 23:06:49 -07:00
|
|
|
assert(DecodeJson(' [1 true] '))
|
2022-07-12 12:30:42 -07:00
|
|
|
assert(EncodeLua(DecodeJson(' [1 true] ')) == '{1, true}')
|