Audit every single JSON test

This commit is contained in:
Justine Tunney 2022-07-12 12:30:42 -07:00
parent 7965ed0232
commit 3f3e7e92d7
17 changed files with 473 additions and 285 deletions

View file

@ -85,7 +85,6 @@ assert(err == "won't serialize cyclic lua table")
-- pass the parser to itself lool
json, err = EncodeJson(EncodeJson)
assert(not json)
print(err)
assert(err == "unsupported lua type")
-- EncodeJson() sorts table entries
@ -145,6 +144,9 @@ assert(ParseHttpDateTime("Fri, 08 Jul 2022 16:17:43 GMT") == 1657297063)
assert(FormatHttpDateTime(1657297063) == "Fri, 08 Jul 2022 16:17:43 GMT")
assert(VisualizeControlCodes("hello\x00") == "hello␀")
assert(VisualizeControlCodes("\xe2\x80\xa8") == "") -- line separator
assert(VisualizeControlCodes("\xe2\x80\xaa") == "") -- left-to-right embedding
assert(VisualizeControlCodes("\xe2\x80\xab") == "") -- right-to-left embedding
assert(math.floor(10 * MeasureEntropy(" ") + .5) == 0)
assert(math.floor(10 * MeasureEntropy("abcabcabcabc") + .5) == 16)

View file

@ -17,7 +17,6 @@ assert(EncodeLua(assert(DecodeJson[[ 0 ]])) == '0' )
assert(EncodeLua(assert(DecodeJson[[ [1] ]])) == '{1}')
assert(EncodeLua(assert(DecodeJson[[ 2.3 ]])) == '2.3')
assert(EncodeLua(assert(DecodeJson[[ [1,3,2] ]])) == '{1, 3, 2}')
-- assert(EncodeLua(assert(DecodeJson[[ {1: 2, 3: 4} ]])) == '{[1]=2, [3]=4}')
assert(EncodeLua(assert(DecodeJson[[ {"foo": 2, "bar": 4} ]])) == '{bar=4, foo=2}')
assert(EncodeLua(assert(DecodeJson[[ -123 ]])) == '-123')
assert(EncodeLua(assert(DecodeJson[[ 1e6 ]])) == '1000000.')
@ -26,7 +25,6 @@ assert(EncodeLua(assert(DecodeJson[[ 1e-06 ]])) == '0.000001')
assert(EncodeLua(assert(DecodeJson[[ 9.123e6 ]])) == '9123000.')
assert(EncodeLua(assert(DecodeJson[[ [{"heh": [1,3,2]}] ]])) == '{{heh={1, 3, 2}}}')
assert(EncodeLua(assert(DecodeJson[[ 3.14159 ]])) == '3.14159')
-- assert(EncodeLua(assert(DecodeJson[[ {3=4} ]])) == '{[3]=4}')
assert(EncodeLua(assert(DecodeJson[[ 1e-12 ]])) == '1e-12')
assert(EncodeJson(assert(DecodeJson[[ 1e-12 ]])) == '1e-12')
@ -52,6 +50,14 @@ assert(EncodeJson(assert(DecodeJson[[ 9223372036854775807.0 ]])) == '9223372036
assert(EncodeJson(assert(DecodeJson[[ 2.7182818284590452354 ]])) == '2.718281828459045') -- euler constant w/ 17 digit precision
assert( EncodeLua(assert(DecodeJson[[ 2.7182818284590452354 ]])) == '2.718281828459045') -- euler constant w/ 17 digit precision
res, err = DecodeJson[[ null ]]
assert(res == nil)
assert(err == nil)
res, err = DecodeJson[[ false ]]
assert(res == false)
assert(err == nil)
res, err = DecodeJson[[ ]]
assert(not res)
assert(err == 'unexpected eof')
@ -60,14 +66,6 @@ res, err = DecodeJson[[ {} {} ]]
assert(not res)
assert(err == "junk after expression")
res, err = DecodeJson[[ null ]]
assert(not res)
assert(err == "toplevel json can't be null")
res, err = DecodeJson[[ false ]]
assert(not res)
assert(err == "toplevel json can't be false")
res, err = DecodeJson[[ {3:4} ]]
assert(not res)
assert(err == "object key must be string")
@ -96,6 +94,26 @@ res, err = DecodeJson[[ {true:3} ]]
assert(not res)
assert(err == "object key must be string")
res, err = DecodeJson('"\x00"')
assert(res == nil)
assert(err == 'non-del c0 in string')
res, err = DecodeJson('"e')
assert(res == nil)
assert(err == 'unexpected eof in string')
res, err = DecodeJson('"\\xcc\\xa9"')
assert(res == nil)
assert(err == 'hex escape not printable')
res, err = DecodeJson('"\\xcj"')
assert(res == nil)
assert(err == 'invalid hex escape')
res, err = DecodeJson('"\\ucjcc"')
assert(res == nil)
assert(err == 'invalid unicode escape')
res, err = DecodeJson('[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[')
assert(not res)
assert(err == "maximum depth exceeded")

View file

@ -236,8 +236,7 @@ assert(not DecodeJson(' ["x" '))
assert(not DecodeJson(' ["": 1] '))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_array_a_invalid_utf8.json
-- (converted to binary for safety)
assert(not DecodeJson(' \x5b\x61\xe5\x5d '))
assert(not DecodeJson(" [a\xe5] "))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_object_comma_instead_of_colon.json
assert(not DecodeJson(' {"x", null} '))
@ -252,3 +251,21 @@ assert(not DecodeJson(' 123\x00 '))
-- (added spaces between [[ and ]] so lua doesn't get confused)
assert(not DecodeJson([[
[ "x"] ] ]]))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_number_with_leading_zero.json
assert(not DecodeJson(' [012] '))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_number_neg_int_starting_with_zero.json
assert(not DecodeJson(' [-012] '))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_number_1_000.json
assert(not DecodeJson(' [1 000.0] '))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_number_-01.json
assert(not DecodeJson(' [-01] '))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_number_minus_space_1.json
assert(not DecodeJson(' [- 1] '))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_array_just_minus.json
assert(not DecodeJson(' [-] '))

View file

@ -26,7 +26,6 @@
-- SOFTWARE.
--
-- these test cases are prefixed with n_
-- ljson should reject all of them as invalid

View file

@ -1,4 +1,3 @@
--
-- Nicolas Seriot's JSONTestSuite
-- https://github.com/nst/JSONTestSuite
@ -27,7 +26,6 @@
-- SOFTWARE.
--
-- these test cases are prefixed with n_
-- ljson should reject all of them as invalid

View file

@ -1,4 +1,3 @@
--
-- Nicolas Seriot's JSONTestSuite
-- https://github.com/nst/JSONTestSuite
@ -31,48 +30,40 @@
-- ljson should reject all of them as invalid
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_start_escape_unclosed.json
-- (converted to binary for safety)
assert(not DecodeJson(' \x5b\x22\x5c '))
assert(not DecodeJson(" [\"\\ "))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_single_string_no_double_quotes.json
-- (converted to binary for safety)
assert(not DecodeJson(' \x61\x62\x63 '))
assert(not DecodeJson(" abc "))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_single_quote.json
-- (converted to binary for safety)
assert(not DecodeJson(' \x5b\x27\x73\x69\x6e\x67\x6c\x65\x20\x71\x75\x6f\x74\x65\x27\x5d '))
assert(not DecodeJson(" [\'single quote\'] "))
-- disallow escape code outside string
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_no_quotes_with_bad_escape.json
-- (converted to binary for safety)
assert(not DecodeJson(' \x5b\x5c\x6e\x5d '))
assert(not DecodeJson(" [\\n] "))
-- disallow unicode escape outside string
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_leading_uescaped_thinspace.json
-- (converted to binary for safety)
assert(not DecodeJson(' \x5b\x5c\x75\x30\x30\x32\x30\x22\x61\x73\x64\x22\x5d '))
assert(not DecodeJson(" [\\u0020\"asd\"] "))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_incomplete_surrogate_escape_invalid.json
-- (converted to binary for safety)
assert(not DecodeJson(' \x5b\x22\x5c\x75\x44\x38\x30\x30\x5c\x75\x44\x38\x30\x30\x5c\x78\x22\x5d '))
assert(not DecodeJson(" [\"\\uD800\\uD800\\x\"] "))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_incomplete_escape.json
-- (converted to binary for safety)
assert(not DecodeJson(' \x5b\x22\x5c\x22\x5d '))
assert(not DecodeJson(" [\"\\\"] "))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_escaped_backslash_bad.json
-- (converted to binary for safety)
assert(not DecodeJson(' \x5b\x22\x5c\x5c\x5c\x22\x5d '))
assert(not DecodeJson(" [\"\\\\\\\"] "))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_accentuated_char_no_quotes.json
-- (converted to binary for safety)
assert(not DecodeJson(' \x5b\xc3\xa9\x5d '))
assert(not DecodeJson(" [é] "))
assert(DecodeJson(" [\"é\"] "))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_1_surrogate_then_escape.json
-- (converted to binary for safety)
assert(not DecodeJson(' \x5b\x22\x5c\x75\x44\x38\x30\x30\x5c\x22\x5d '))
assert(not DecodeJson(" [\"\\uD800\\\"] "))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_object_with_single_string.json
-- (converted to binary for safety)
assert(not DecodeJson(' \x7b\x20\x22\x66\x6f\x6f\x22\x20\x3a\x20\x22\x62\x61\x72\x22\x2c\x20\x22\x61\x22\x20\x7d '))
assert(not DecodeJson(" { \"foo\" : \"bar\", \"a\" } "))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_object_unterminated-value.json
assert(not DecodeJson(' {"a":"a '))
@ -174,3 +165,15 @@ assert(not DecodeJson(' {"a":"b"}/**// '))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_object_trailing_comment.json
assert(not DecodeJson(' {"a":"b"}/**/ '))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_unescaped_ctrl_char.json
assert(not DecodeJson(" [\"a\x00a\"] "))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_escape_x.json
assert(not DecodeJson(" [\"a\\x00a\"] "))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_unescaped_tab.json
assert(not DecodeJson(" [\"\t\"] "))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_unescaped_newline.json
assert(not DecodeJson(" [\"new\nline\"] "))

View file

@ -26,111 +26,111 @@
-- SOFTWARE.
--
-- [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}')
-- from fail4.lua
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_escape_x.json
-- (converted to binary for safety)
assert(DecodeJson(" [\"\\x00\"] "))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_unescaped_tab.json
-- (converted to binary for safety)
assert(DecodeJson([[ [" "] ]]))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_unescaped_newline.json
-- (converted to binary for safety)
assert(DecodeJson(" [\"new\nline\"] "))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_string_unescaped_ctrl_char.json
-- (converted to binary for safety)
assert(assert(EncodeLua(assert(DecodeJson(" [\"a\x00a\"] ")))) == assert(EncodeLua({"a\x00a"})))
--------------------------------------------------------------------------------
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_object_two_commas_in_a_row.json
assert(assert(EncodeLua(assert(DecodeJson(' {"a":"b",,"c":"d"} ')))) == assert(EncodeLua({a="b", c="d"})))
assert(DecodeJson(' {"a":"b",,"c":"d"} '))
assert(EncodeLua(DecodeJson(' {"a":"b",,"c":"d"} ')) == '{a="b", c="d"}')
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_object_trailing_comma.json
assert(DecodeJson(' {"id":0,} '))
assert(EncodeLua(DecodeJson(' {"id":0,} ')) == '{id=0}')
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_object_several_trailing_commas.json
assert(DecodeJson(' {"id":0,,,,,} '))
assert(EncodeLua(DecodeJson(' {"id":0,,,,,} ')) == '{id=0}')
-- from fail1.lua
--------------------------------------------------------------------------------
-- [jart] v8 permits the \xb9 but doesn't permit the trailing comma
-- therefore this succeeds beacuse we don't care about comma
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_object_lone_continuation_byte_in_key_and_trailing_comma.json
-- (converted to binary for safety)
assert(DecodeJson(" {\"\xb9\":\"0\",} "))
assert(EncodeLua(DecodeJson(" {\"\xb9\":\"0\",} ")) == '{["\\xb9"]="0"}')
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_object_missing_semicolon.json
assert(DecodeJson(' {"a" "b"} '))
assert(EncodeLua(DecodeJson(' {"a" "b"} ')) == '{a="b"}')
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_object_double_colon.json
assert(DecodeJson(' {"x"::"b"} '))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_number_with_leading_zero.json
assert(DecodeJson(' [012] '))
assert(EncodeLua(DecodeJson(' {"x"::"b"} ')) == '{x="b"}')
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_number_real_without_fractional_part.json
assert(DecodeJson(' [1.] '))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_number_neg_int_starting_with_zero.json
assert(DecodeJson(' [-012] '))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_number_minus_space_1.json
assert(DecodeJson(' [- 1] '))
assert(EncodeLua(DecodeJson(' [1.] ')) == EncodeLua({1.0}))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_number_2.e3.json
assert(DecodeJson(' [2.e3] '))
assert(EncodeLua(DecodeJson(' [2.e3] ')) == '{2000.}')
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_number_2.e-3.json
assert(DecodeJson(' [2.e-3] '))
assert(EncodeLua(DecodeJson(' [2.e-3] ')) == '{0.002}')
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_number_2.e+3.json
assert(DecodeJson(' [2.e+3] '))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_number_1_000.json
assert(DecodeJson(' [1 000.0] '))
assert(EncodeLua(DecodeJson(' [2.e+3] ')) == '{2000.}')
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_number_0.e1.json
assert(DecodeJson(' [0.e1] '))
assert(EncodeLua(DecodeJson(' [0.e1] ')) == '{0.}')
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_number_-2..json
assert(DecodeJson(' [-2.] '))
assert(EncodeLua(DecodeJson(' [-2.] ')) == '{-2.}')
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_number_-01.json
assert(DecodeJson(' [-01] '))
-- lool
assert(not DecodeJson(' [--2.] '))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_array_number_and_several_commas.json
assert(DecodeJson(' [1,,] '))
assert(EncodeLua(DecodeJson(' [1,,] ')) == '{1}')
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_array_number_and_comma.json
assert(DecodeJson(' [1,] '))
assert(EncodeLua(DecodeJson(' [1,] ')) == '{1}')
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_array_missing_value.json
assert(DecodeJson(' [ , ""] '))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_array_just_minus.json
assert(DecodeJson(' [-] '))
assert(EncodeLua(DecodeJson(' [ , ""] ')) == '{""}')
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_array_just_comma.json
assert(DecodeJson(' [,] '))
assert(EncodeLua(DecodeJson(' [,] ')) == EncodeLua(DecodeJson(' [] ')))
-- 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)
assert(DecodeJson([[
[ 3[ 4] ] ]]))
assert(EncodeLua(DecodeJson([[
[ 3[ 4] ] ]])) == '{3, {4}}')
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_array_extra_comma.json
assert(DecodeJson(' ["",] '))
assert(EncodeLua(DecodeJson(' ["",] ')) == '{""}')
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_array_double_extra_comma.json
assert(DecodeJson(' ["x",,] '))
assert(EncodeLua(DecodeJson(' ["x",,] ')) == '{"x"}')
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_array_double_comma.json
assert(DecodeJson(' [1,,2] '))
assert(EncodeLua(DecodeJson(' [1,,2] ')) == '{1, 2}')
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_array_comma_and_number.json
assert(DecodeJson(' [,1] '))
assert(EncodeLua(DecodeJson(' [,1] ')) == '{1}')
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/n_array_1_true_without_comma.json
assert(DecodeJson(' [1 true] '))
assert(EncodeLua(DecodeJson(' [1 true] ')) == '{1, true}')

View file

@ -1,4 +1,3 @@
--
-- Nicolas Seriot's JSONTestSuite
-- https://github.com/nst/JSONTestSuite
@ -27,18 +26,17 @@
-- SOFTWARE.
--
-- these test cases are prefixed with i_
-- ljson is free to accept or reject,
-- but we run them anyway to check for segfaults
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_structure_UTF-8_BOM_empty_object.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \xef\xbb\xbf{} '))
assert(not DecodeJson(' \xef\xbb\xbf{} '))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_structure_500_nested_arrays.json
-- (added spaces between [[ and ]] so lua doesn't get confused)
assert(nil ~= pcall(DecodeJson, [[ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [
assert(not DecodeJson([[ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [
[ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [
[ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [
[ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [
@ -66,124 +64,154 @@ assert(nil ~= pcall(DecodeJson, [[ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [
] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ]]))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_string_utf16LE_no_BOM.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \x5b\x00\x22\x00\xe9\x00\x22\x00\x5d\x00 '))
assert(not DecodeJson(" [\x00\"\x00\xe9\x00\"\x00]\x00 "))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_string_utf16BE_no_BOM.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \x00\x5b\x00\x22\x00\xe9\x00\x22\x00\x5d '))
assert(not DecodeJson(" \x00[\x00\"\x00\xe9\x00\"\x00] "))
-- [jart] ljson currently doesn't validate utf-8
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_string_truncated-utf-8.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \x5b\x22\xe0\xff\x22\x5d '))
assert(DecodeJson(" [\"\xe0\xff\"] "))
-- [jart] ljson currently doesn't validate utf-8
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_string_overlong_sequence_6_bytes_null.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \x5b\x22\xfc\x80\x80\x80\x80\x80\x22\x5d '))
assert(DecodeJson(" [\"\xfc\x80\x80\x80\x80\x80\"] "))
-- [jart] ljson currently doesn't validate utf-8
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_string_overlong_sequence_6_bytes.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \x5b\x22\xfc\x83\xbf\xbf\xbf\xbf\x22\x5d '))
assert(DecodeJson(" [\"\xfc\x83\xbf\xbf\xbf\xbf\"] "))
-- [jart] ljson currently doesn't validate utf-8
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_string_overlong_sequence_2_bytes.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \x5b\x22\xc0\xaf\x22\x5d '))
assert(DecodeJson(' \x5b\x22\xc0\xaf\x22\x5d '))
-- [jart] ljson currently doesn't validate utf-8
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_string_not_in_unicode_range.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \x5b\x22\xf4\xbf\xbf\xbf\x22\x5d '))
assert(DecodeJson(" [\"\xf4\xbf\xbf\xbf\"] "))
-- [jart] ljson currently doesn't validate utf-8
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_string_lone_utf8_continuation_byte.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \x5b\x22\x81\x22\x5d '))
assert(DecodeJson(' \x5b\x22\x81\x22\x5d '))
-- [jart] our behavior here is consistent with v8
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_string_lone_second_surrogate.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \x5b\x22\x5c\x75\x44\x46\x41\x41\x22\x5d '))
assert(DecodeJson(" [\"\\uDFAA\"] "))
assert(EncodeJson(DecodeJson(" [\"\\uDFAA\"] ")) == "[\"\\\\uDFAA\"]")
-- [jart] ljson currently doesn't validate utf-8
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_string_iso_latin_1.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \x5b\x22\xe9\x22\x5d '))
assert(DecodeJson(' \x5b\x22\xe9\x22\x5d '))
-- [jart] ljson currently doesn't validate utf-8
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_string_inverted_surrogates_U+1D11E.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \x5b\x22\x5c\x75\x44\x64\x31\x65\x5c\x75\x44\x38\x33\x34\x22\x5d '))
assert(DecodeJson(' \x5b\x22\x5c\x75\x44\x64\x31\x65\x5c\x75\x44\x38\x33\x34\x22\x5d '))
-- [jart] ljson currently doesn't validate utf-8
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_string_invalid_utf-8.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \x5b\x22\xff\x22\x5d '))
assert(DecodeJson(' \x5b\x22\xff\x22\x5d '))
-- [jart] ljson currently doesn't validate utf-8
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_string_invalid_surrogate.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \x5b\x22\x5c\x75\x64\x38\x30\x30\x61\x62\x63\x22\x5d '))
assert(DecodeJson(' \x5b\x22\x5c\x75\x64\x38\x30\x30\x61\x62\x63\x22\x5d '))
-- [jart] ljson currently doesn't validate utf-8
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_string_invalid_lonely_surrogate.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \x5b\x22\x5c\x75\x64\x38\x30\x30\x22\x5d '))
assert(DecodeJson(' \x5b\x22\x5c\x75\x64\x38\x30\x30\x22\x5d '))
-- [jart] ljson currently doesn't validate utf-8
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_string_incomplete_surrogates_escape_valid.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \x5b\x22\x5c\x75\x44\x38\x30\x30\x5c\x75\x44\x38\x30\x30\x5c\x6e\x22\x5d '))
assert(DecodeJson(' \x5b\x22\x5c\x75\x44\x38\x30\x30\x5c\x75\x44\x38\x30\x30\x5c\x6e\x22\x5d '))
-- [jart] ljson currently doesn't validate utf-8
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_string_incomplete_surrogate_pair.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \x5b\x22\x5c\x75\x44\x64\x31\x65\x61\x22\x5d '))
assert(DecodeJson(' \x5b\x22\x5c\x75\x44\x64\x31\x65\x61\x22\x5d '))
-- [jart] ljson currently doesn't validate utf-8
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_string_incomplete_surrogate_and_escape_valid.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \x5b\x22\x5c\x75\x44\x38\x30\x30\x5c\x6e\x22\x5d '))
assert(DecodeJson(' \x5b\x22\x5c\x75\x44\x38\x30\x30\x5c\x6e\x22\x5d '))
-- [jart] ljson currently doesn't validate utf-8
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_string_UTF8_surrogate_U+D800.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \x5b\x22\xed\xa0\x80\x22\x5d '))
assert(DecodeJson(' \x5b\x22\xed\xa0\x80\x22\x5d '))
-- [jart] ljson currently doesn't validate utf-8
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_string_UTF-8_invalid_sequence.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \x5b\x22\xe6\x97\xa5\xd1\x88\xfa\x22\x5d '))
assert(DecodeJson(' \x5b\x22\xe6\x97\xa5\xd1\x88\xfa\x22\x5d '))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_string_UTF-16LE_with_BOM.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \xff\xfe\x5b\x00\x22\x00\xe9\x00\x22\x00\x5d\x00 '))
assert(not DecodeJson(" \xff\xfe[\x00\"\x00\xe9\x00\"\x00]\x00 "))
-- [jart] ljson currently doesn't validate utf-8
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_string_1st_valid_surrogate_2nd_invalid.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \x5b\x22\x5c\x75\x44\x38\x38\x38\x5c\x75\x31\x32\x33\x34\x22\x5d '))
assert(DecodeJson(' \x5b\x22\x5c\x75\x44\x38\x38\x38\x5c\x75\x31\x32\x33\x34\x22\x5d '))
-- [jart] ljson currently doesn't validate utf-8
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_string_1st_surrogate_but_2nd_missing.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \x5b\x22\x5c\x75\x44\x41\x44\x41\x22\x5d '))
assert(DecodeJson(' \x5b\x22\x5c\x75\x44\x41\x44\x41\x22\x5d '))
-- [jart] ljson currently doesn't validate utf-8
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_object_key_lone_2nd_surrogate.json
-- (converted to binary for safety)
assert(nil ~= pcall(DecodeJson, ' \x7b\x22\x5c\x75\x44\x46\x41\x41\x22\x3a\x30\x7d '))
assert(DecodeJson(' \x7b\x22\x5c\x75\x44\x46\x41\x41\x22\x3a\x30\x7d '))
-- [jart] ljson is precicely the same as v8 with integers larger than int64_t
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_number_very_big_negative_int.json
assert(nil ~= pcall(DecodeJson, ' [-237462374673276894279832749832423479823246327846] '))
assert(DecodeJson(' [-237462374673276894279832749832423479823246327846] '))
assert(EncodeJson(DecodeJson(' [-237462374673276894279832749832423479823246327846] ')) == '[-2.374623746732769e+47]')
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_number_too_big_pos_int.json
assert(nil ~= pcall(DecodeJson, ' [100000000000000000000] '))
assert(DecodeJson(' [100000000000000000000] '))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_number_too_big_neg_int.json
assert(nil ~= pcall(DecodeJson, ' [-123123123123123123123123123123] '))
assert(DecodeJson(' [-123123123123123123123123123123] '))
-- [jart] once again consistent with v8
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_number_real_underflow.json
assert(nil ~= pcall(DecodeJson, ' [123e-10000000] '))
assert(DecodeJson(' [123e-10000000] '))
assert(EncodeJson(DecodeJson(' [123e-10000000] ')) == '[0]')
assert(EncodeLua(DecodeJson(' [123e-10000000] ')) == '{0.}')
-- [jart] consistent with v8 we encode Infinity as null (wut?)
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_number_real_pos_overflow.json
assert(nil ~= pcall(DecodeJson, ' [123123e100000] '))
assert(DecodeJson(' [123123e100000] '))
assert(EncodeJson(DecodeJson(' [123123e100000] ')) == '[null]')
-- [jart] consistent with v8 we encode -Infinity as null (wut?)
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_number_real_neg_overflow.json
assert(nil ~= pcall(DecodeJson, ' [-123123e100000] '))
assert(DecodeJson(' [-123123e100000] '))
assert(EncodeJson(DecodeJson(' [-123123e100000] ')) == '[null]')
-- [jart] consistent with v8 we encode Infinity as null (wut?)
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_number_pos_double_huge_exp.json
assert(nil ~= pcall(DecodeJson, ' [1.5e+9999] '))
assert(DecodeJson(' [1.5e+9999] '))
assert(EncodeJson(DecodeJson(' [1.5e+9999] ')) == '[null]')
-- [jart] consistent with v8 we encode -Infinity as null (wut?)
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_number_neg_int_huge_exp.json
assert(nil ~= pcall(DecodeJson, ' [-1e+9999] '))
assert(DecodeJson(' [-1e+9999] '))
assert(EncodeJson(DecodeJson(' [-1e+9999] ')) == '[null]')
-- [jart] consistent with v8 we encode Infinity as null (wut?)
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_number_huge_exp.json
assert(nil ~= pcall(DecodeJson, ' [0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006] '))
assert(DecodeJson(' [0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006] '))
assert(EncodeJson(DecodeJson(' [0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006] ')) == '[null]')
-- [jart] consistent with v8 we encode underflow as 0
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/i_number_double_huge_neg_exp.json
assert(nil ~= pcall(DecodeJson, ' [123.456e-789] '))
assert(DecodeJson(' [123.456e-789] '))
assert(EncodeJson(DecodeJson(' [123.456e-789] ')) == '[0]')

View file

@ -1,4 +1,3 @@
--
-- Nicolas Seriot's JSONTestSuite
-- https://github.com/nst/JSONTestSuite
@ -27,10 +26,21 @@
-- SOFTWARE.
--
-- these test cases are prefixed with y_
-- ljson should accept all of them as valid
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/y_structure_lonely_null.json
val, err = DecodeJson([[ null ]])
assert(not val)
assert(val == nil)
assert(err == nil)
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/y_structure_lonely_false.json
val, err = DecodeJson([[ false ]])
assert(not val)
assert(val == false)
assert(err == nil)
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/y_structure_whitespace_array.json
assert(DecodeJson([[ [] ]]))
@ -49,27 +59,29 @@ assert(DecodeJson([[ true ]]))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/y_structure_lonely_string.json
assert(DecodeJson([[ "asd" ]]))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/y_structure_lonely_null.json
assert(not DecodeJson([[ null ]]))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/y_structure_lonely_negative_real.json
assert(DecodeJson([[ -0.1 ]]))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/y_structure_lonely_int.json
assert(DecodeJson([[ 42 ]]))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/y_structure_lonely_false.json
assert(not DecodeJson([[ false ]]))
-- Raw ASCII DEL allowed in string literals
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/y_string_with_del_character.json
assert(DecodeJson([[ ["aa"] ]]))
assert(DecodeJson(" [\"a\x7fa\"] "))
assert(EncodeJson(DecodeJson(" [\"a\x7fa\"] ")) == '["a\\u007fa"]')
-- EURO SIGN (20AC) and MUSICAL SYMBOL G CLEF (1D11E) in string literal
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/y_string_utf8.json
assert(DecodeJson([[ ["€𝄞"] ]]))
assert(EncodeJson(DecodeJson([[ ["€𝄞"] ]])) == "[\"\\u20ac\\ud834\\udd1e\"]")
assert(EncodeJson(DecodeJson([[ ["€𝄞"] ]])) == EncodeJson(DecodeJson(" [\"\xe2\x82\xac\xf0\x9d\x84\x9e\"] ")))
-- unicode escape for double quote
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/y_string_unicode_escaped_double_quote.json
assert(DecodeJson([[ ["\u0022"] ]]))
assert(DecodeJson([[ ["\u0022"] ]])[1] == '"')
-- replacement character
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/y_string_unicode_U+FFFE_nonchar.json
assert(DecodeJson([[ ["\uFFFE"] ]]))
@ -106,9 +118,11 @@ assert(DecodeJson([[ ["new\u000Aline"] ]]))
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/y_string_uEscape.json
assert(DecodeJson([[ ["\u0061\u30af\u30EA\u30b9"] ]]))
-- paragraph separator trojan source
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/y_string_u+2029_par_sep.json
assert(DecodeJson([[ [""] ]]))
-- line separator trojan source
-- https://github.com/nst/JSONTestSuite/tree/d64aefb55228d9584d3e5b2433f720ea8fd00c82/test_parsing/y_string_u+2028_line_sep.json
assert(DecodeJson([[ [""] ]]))
@ -322,4 +336,3 @@ assert(DecodeJson([[ [""] ]]))
-- (added spaces between [[ and ]] so lua doesn't get confused)
assert(DecodeJson([[
[ [ ] ] ]]))

View file

@ -9,30 +9,35 @@ assert(DecodeJson([[
[ "extra comma",]
]]))
-- [jart] we deviate from json.org because we don't care about commas
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail5.json
assert(DecodeJson([[
[ "double extra comma",,]
]]))
-- [jart] we deviate from json.org because we don't care about commas
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail6.json
assert(DecodeJson([[
[ , "<-- missing value"]
]]))
-- [jart] we deviate from json.org because we don't care about commas
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail9.json
assert(DecodeJson([[
{"Extra comma": true,}
]]))
-- [jart] we deviate from json.org because we don't care about colons
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail19.json
assert(DecodeJson([[
{"Missing colon" null}
]]))
-- [jart] we deviate from json.org because we don't care about colons
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail20.json
assert(DecodeJson([[
@ -41,19 +46,19 @@ assert(DecodeJson([[
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail25.json
assert(DecodeJson([[
assert(not DecodeJson([[
[ " tab character in string "]
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail27.json
assert(DecodeJson([[
assert(not DecodeJson([[
[ "line
break"]
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail15.json
assert(DecodeJson([[
assert(not DecodeJson([[
[ "Illegal backslash escape: \x15"]
]]))

View file

@ -1,6 +1,6 @@
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: pass1.json
assert(pcall(DecodeJson, [[
assert(DecodeJson([[
[
"JSON Test Pattern pass1",
{"object with 1 member":[ "array with 1 element"] },
@ -63,14 +63,13 @@ assert(pcall(DecodeJson, [[
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: pass2.json
assert(pcall(DecodeJson, [[
assert(DecodeJson([[
[ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ "Not too deep"] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ]
]]))
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: pass3.json
assert(pcall(DecodeJson, [[
assert(DecodeJson([[
{
"JSON Test Pattern pass3": {
"The outermost value": "must be an object or array.",
@ -80,18 +79,20 @@ assert(pcall(DecodeJson, [[
]]))
-- json.org says these should fail, but many parsers,
-- including python's json.load allow the following
-- [jart] our behavior is consistent with v8
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail1.json (actually passes)
assert(pcall(DecodeJson, [[
assert(DecodeJson([[
"A JSON payload should be an object or array, not a string."
]]))
-- [jart] this deviates from json.org
-- we permit depth up to 128
-- https://www.json.org/JSON_checker/test.zip
-- JSON parsing sample test case: fail18.json (actually passes)
assert(pcall(DecodeJson, [[
assert(DecodeJson([[
[ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ "Too deep"] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ]
]]))