diff options
author | ZyX <kp-pav@yandex.ru> | 2016-02-13 21:39:28 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2016-04-18 02:48:20 +0300 |
commit | 2f67786796d5fb4237f4b0258ec3db0982cc7f53 (patch) | |
tree | dc8a7d2f10ce72316a8e1162ab160de7dc3aa1fb /test/functional/eval/json_functions_spec.lua | |
parent | f1ced96c28b7db7b3dad9b0ca2f71f8d046ef732 (diff) | |
download | rneovim-2f67786796d5fb4237f4b0258ec3db0982cc7f53.tar.gz rneovim-2f67786796d5fb4237f4b0258ec3db0982cc7f53.tar.bz2 rneovim-2f67786796d5fb4237f4b0258ec3db0982cc7f53.zip |
eval: Rename json* functions to json_*
Diffstat (limited to 'test/functional/eval/json_functions_spec.lua')
-rw-r--r-- | test/functional/eval/json_functions_spec.lua | 368 |
1 files changed, 184 insertions, 184 deletions
diff --git a/test/functional/eval/json_functions_spec.lua b/test/functional/eval/json_functions_spec.lua index 398fab6c4b..0b0403ce8e 100644 --- a/test/functional/eval/json_functions_spec.lua +++ b/test/functional/eval/json_functions_spec.lua @@ -7,7 +7,7 @@ local eval = helpers.eval local execute = helpers.execute local exc_exec = helpers.exc_exec -describe('jsondecode() function', function() +describe('json_decode() function', function() local restart = function(cmd) clear(cmd) execute([[ @@ -61,7 +61,7 @@ describe('jsondecode() function', function() end it('accepts readfile()-style list', function() - eq({Test=1}, funcs.jsondecode({ + eq({Test=1}, funcs.json_decode({ '{', '\t"Test": 1', '}', @@ -69,7 +69,7 @@ describe('jsondecode() function', function() end) it('accepts strings with newlines', function() - eq({Test=1}, funcs.jsondecode([[ + eq({Test=1}, funcs.json_decode([[ { "Test": 1 } @@ -77,242 +77,242 @@ describe('jsondecode() function', function() end) it('parses null, true, false', function() - eq(nil, funcs.jsondecode('null')) - eq(true, funcs.jsondecode('true')) - eq(false, funcs.jsondecode('false')) + eq(nil, funcs.json_decode('null')) + eq(true, funcs.json_decode('true')) + eq(false, funcs.json_decode('false')) end) it('fails to parse incomplete null, true, false', function() eq('Vim(call):E474: Expected null: n', - exc_exec('call jsondecode("n")')) + exc_exec('call json_decode("n")')) eq('Vim(call):E474: Expected null: nu', - exc_exec('call jsondecode("nu")')) + exc_exec('call json_decode("nu")')) eq('Vim(call):E474: Expected null: nul', - exc_exec('call jsondecode("nul")')) + exc_exec('call json_decode("nul")')) eq('Vim(call):E474: Expected null: nul\n\t', - exc_exec('call jsondecode("nul\\n\\t")')) + exc_exec('call json_decode("nul\\n\\t")')) eq('Vim(call):E474: Expected true: t', - exc_exec('call jsondecode("t")')) + exc_exec('call json_decode("t")')) eq('Vim(call):E474: Expected true: tr', - exc_exec('call jsondecode("tr")')) + exc_exec('call json_decode("tr")')) eq('Vim(call):E474: Expected true: tru', - exc_exec('call jsondecode("tru")')) + exc_exec('call json_decode("tru")')) eq('Vim(call):E474: Expected true: tru\t\n', - exc_exec('call jsondecode("tru\\t\\n")')) + exc_exec('call json_decode("tru\\t\\n")')) eq('Vim(call):E474: Expected false: f', - exc_exec('call jsondecode("f")')) + exc_exec('call json_decode("f")')) eq('Vim(call):E474: Expected false: fa', - exc_exec('call jsondecode("fa")')) + exc_exec('call json_decode("fa")')) eq('Vim(call):E474: Expected false: fal', - exc_exec('call jsondecode("fal")')) + exc_exec('call json_decode("fal")')) eq('Vim(call):E474: Expected false: fal <', - exc_exec('call jsondecode(" fal <")')) + exc_exec('call json_decode(" fal <")')) eq('Vim(call):E474: Expected false: fals', - exc_exec('call jsondecode("fals")')) + exc_exec('call json_decode("fals")')) end) it('parses integer numbers', function() - eq(100000, funcs.jsondecode('100000')) - eq(-100000, funcs.jsondecode('-100000')) - eq(100000, funcs.jsondecode(' 100000 ')) - eq(-100000, funcs.jsondecode(' -100000 ')) + eq(100000, funcs.json_decode('100000')) + eq(-100000, funcs.json_decode('-100000')) + eq(100000, funcs.json_decode(' 100000 ')) + eq(-100000, funcs.json_decode(' -100000 ')) end) it('fails to parse +numbers', function() eq('Vim(call):E474: Unidentified byte: +1000', - exc_exec('call jsondecode("+1000")')) + exc_exec('call json_decode("+1000")')) end) it('fails to parse negative numbers with space after -', function() eq('Vim(call):E474: Missing number after minus sign: - 1000', - exc_exec('call jsondecode("- 1000")')) + exc_exec('call json_decode("- 1000")')) end) it('fails to parse -', function() eq('Vim(call):E474: Missing number after minus sign: -', - exc_exec('call jsondecode("-")')) + exc_exec('call json_decode("-")')) end) it('parses floating-point numbers', function() - eq('100000.0', eval('string(jsondecode("100000.0"))')) - eq(100000.5, funcs.jsondecode('100000.5')) - eq(-100000.5, funcs.jsondecode('-100000.5')) - eq(-100000.5e50, funcs.jsondecode('-100000.5e50')) - eq(100000.5e50, funcs.jsondecode('100000.5e50')) - eq(100000.5e50, funcs.jsondecode('100000.5e+50')) - eq(-100000.5e-50, funcs.jsondecode('-100000.5e-50')) - eq(100000.5e-50, funcs.jsondecode('100000.5e-50')) + eq('100000.0', eval('string(json_decode("100000.0"))')) + eq(100000.5, funcs.json_decode('100000.5')) + eq(-100000.5, funcs.json_decode('-100000.5')) + eq(-100000.5e50, funcs.json_decode('-100000.5e50')) + eq(100000.5e50, funcs.json_decode('100000.5e50')) + eq(100000.5e50, funcs.json_decode('100000.5e+50')) + eq(-100000.5e-50, funcs.json_decode('-100000.5e-50')) + eq(100000.5e-50, funcs.json_decode('100000.5e-50')) end) it('fails to parse incomplete floating-point numbers', function() eq('Vim(call):E474: Missing number after decimal dot: 0.', - exc_exec('call jsondecode("0.")')) + exc_exec('call json_decode("0.")')) eq('Vim(call):E474: Missing exponent: 0.0e', - exc_exec('call jsondecode("0.0e")')) + exc_exec('call json_decode("0.0e")')) eq('Vim(call):E474: Missing exponent: 0.0e+', - exc_exec('call jsondecode("0.0e+")')) + exc_exec('call json_decode("0.0e+")')) eq('Vim(call):E474: Missing exponent: 0.0e-', - exc_exec('call jsondecode("0.0e-")')) + exc_exec('call json_decode("0.0e-")')) end) it('fails to parse floating-point numbers with spaces inside', function() eq('Vim(call):E474: Missing number after decimal dot: 0. ', - exc_exec('call jsondecode("0. ")')) + exc_exec('call json_decode("0. ")')) eq('Vim(call):E474: Missing number after decimal dot: 0. 0', - exc_exec('call jsondecode("0. 0")')) + exc_exec('call json_decode("0. 0")')) eq('Vim(call):E474: Missing exponent: 0.0e 1', - exc_exec('call jsondecode("0.0e 1")')) + exc_exec('call json_decode("0.0e 1")')) eq('Vim(call):E474: Missing exponent: 0.0e+ 1', - exc_exec('call jsondecode("0.0e+ 1")')) + exc_exec('call json_decode("0.0e+ 1")')) eq('Vim(call):E474: Missing exponent: 0.0e- 1', - exc_exec('call jsondecode("0.0e- 1")')) + exc_exec('call json_decode("0.0e- 1")')) end) it('fails to parse "," and ":"', function() eq('Vim(call):E474: Comma not inside container: , ', - exc_exec('call jsondecode(" , ")')) + exc_exec('call json_decode(" , ")')) eq('Vim(call):E474: Colon not inside container: : ', - exc_exec('call jsondecode(" : ")')) + exc_exec('call json_decode(" : ")')) end) it('parses empty containers', function() - eq({}, funcs.jsondecode('[]')) - eq('[]', eval('string(jsondecode("[]"))')) + eq({}, funcs.json_decode('[]')) + eq('[]', eval('string(json_decode("[]"))')) end) it('fails to parse "[" and "{"', function() eq('Vim(call):E474: Unexpected end of input: {', - exc_exec('call jsondecode("{")')) + exc_exec('call json_decode("{")')) eq('Vim(call):E474: Unexpected end of input: [', - exc_exec('call jsondecode("[")')) + exc_exec('call json_decode("[")')) end) it('fails to parse "}" and "]"', function() eq('Vim(call):E474: No container to close: ]', - exc_exec('call jsondecode("]")')) + exc_exec('call json_decode("]")')) eq('Vim(call):E474: No container to close: }', - exc_exec('call jsondecode("}")')) + exc_exec('call json_decode("}")')) end) it('fails to parse containers which are closed by different brackets', function() eq('Vim(call):E474: Closing dictionary with bracket: ]', - exc_exec('call jsondecode("{]")')) + exc_exec('call json_decode("{]")')) eq('Vim(call):E474: Closing list with figure brace: }', - exc_exec('call jsondecode("[}")')) + exc_exec('call json_decode("[}")')) end) it('fails to parse concat inside container', function() eq('Vim(call):E474: Expected comma before list item: []]', - exc_exec('call jsondecode("[[][]]")')) + exc_exec('call json_decode("[[][]]")')) eq('Vim(call):E474: Expected comma before list item: {}]', - exc_exec('call jsondecode("[{}{}]")')) + exc_exec('call json_decode("[{}{}]")')) eq('Vim(call):E474: Expected comma before list item: ]', - exc_exec('call jsondecode("[1 2]")')) + exc_exec('call json_decode("[1 2]")')) eq('Vim(call):E474: Expected comma before dictionary key: ": 4}', - exc_exec('call jsondecode("{\\"1\\": 2 \\"3\\": 4}")')) + exc_exec('call json_decode("{\\"1\\": 2 \\"3\\": 4}")')) eq('Vim(call):E474: Expected colon before dictionary value: , "3" 4}', - exc_exec('call jsondecode("{\\"1\\" 2, \\"3\\" 4}")')) + exc_exec('call json_decode("{\\"1\\" 2, \\"3\\" 4}")')) end) it('fails to parse containers with leading comma or colon', function() eq('Vim(call):E474: Leading comma: ,}', - exc_exec('call jsondecode("{,}")')) + exc_exec('call json_decode("{,}")')) eq('Vim(call):E474: Leading comma: ,]', - exc_exec('call jsondecode("[,]")')) + exc_exec('call json_decode("[,]")')) eq('Vim(call):E474: Using colon not in dictionary: :]', - exc_exec('call jsondecode("[:]")')) + exc_exec('call json_decode("[:]")')) eq('Vim(call):E474: Unexpected colon: :}', - exc_exec('call jsondecode("{:}")')) + exc_exec('call json_decode("{:}")')) end) it('fails to parse containers with trailing comma', function() eq('Vim(call):E474: Trailing comma: ]', - exc_exec('call jsondecode("[1,]")')) + exc_exec('call json_decode("[1,]")')) eq('Vim(call):E474: Trailing comma: }', - exc_exec('call jsondecode("{\\"1\\": 2,}")')) + exc_exec('call json_decode("{\\"1\\": 2,}")')) end) it('fails to parse dictionaries with missing value', function() eq('Vim(call):E474: Expected value after colon: }', - exc_exec('call jsondecode("{\\"1\\":}")')) + exc_exec('call json_decode("{\\"1\\":}")')) eq('Vim(call):E474: Expected value: }', - exc_exec('call jsondecode("{\\"1\\"}")')) + exc_exec('call json_decode("{\\"1\\"}")')) end) it('fails to parse containers with two commas or colons', function() eq('Vim(call):E474: Duplicate comma: , "2": 2}', - exc_exec('call jsondecode("{\\"1\\": 1,, \\"2\\": 2}")')) + exc_exec('call json_decode("{\\"1\\": 1,, \\"2\\": 2}")')) eq('Vim(call):E474: Duplicate comma: , "2", 2]', - exc_exec('call jsondecode("[\\"1\\", 1,, \\"2\\", 2]")')) + exc_exec('call json_decode("[\\"1\\", 1,, \\"2\\", 2]")')) eq('Vim(call):E474: Duplicate colon: : 2}', - exc_exec('call jsondecode("{\\"1\\": 1, \\"2\\":: 2}")')) + exc_exec('call json_decode("{\\"1\\": 1, \\"2\\":: 2}")')) eq('Vim(call):E474: Comma after colon: , 2}', - exc_exec('call jsondecode("{\\"1\\": 1, \\"2\\":, 2}")')) + exc_exec('call json_decode("{\\"1\\": 1, \\"2\\":, 2}")')) eq('Vim(call):E474: Unexpected colon: : "2": 2}', - exc_exec('call jsondecode("{\\"1\\": 1,: \\"2\\": 2}")')) + exc_exec('call json_decode("{\\"1\\": 1,: \\"2\\": 2}")')) eq('Vim(call):E474: Unexpected colon: :, "2": 2}', - exc_exec('call jsondecode("{\\"1\\": 1:, \\"2\\": 2}")')) + exc_exec('call json_decode("{\\"1\\": 1:, \\"2\\": 2}")')) end) it('fails to parse concat of two values', function() eq('Vim(call):E474: Trailing characters: []', - exc_exec('call jsondecode("{}[]")')) + exc_exec('call json_decode("{}[]")')) end) it('parses containers', function() - eq({1}, funcs.jsondecode('[1]')) - eq({nil, 1}, funcs.jsondecode('[null, 1]')) - eq({['1']=2}, funcs.jsondecode('{"1": 2}')) + eq({1}, funcs.json_decode('[1]')) + eq({nil, 1}, funcs.json_decode('[null, 1]')) + eq({['1']=2}, funcs.json_decode('{"1": 2}')) eq({['1']=2, ['3']={{['4']={['5']={{}, 1}}}}}, - funcs.jsondecode('{"1": 2, "3": [{"4": {"5": [[], 1]}}]}')) + funcs.json_decode('{"1": 2, "3": [{"4": {"5": [[], 1]}}]}')) end) it('fails to parse incomplete strings', function() eq('Vim(call):E474: Expected string end: \t"', - exc_exec('call jsondecode("\\t\\"")')) + exc_exec('call json_decode("\\t\\"")')) eq('Vim(call):E474: Expected string end: \t"abc', - exc_exec('call jsondecode("\\t\\"abc")')) + exc_exec('call json_decode("\\t\\"abc")')) eq('Vim(call):E474: Unfinished escape sequence: \t"abc\\', - exc_exec('call jsondecode("\\t\\"abc\\\\")')) + exc_exec('call json_decode("\\t\\"abc\\\\")')) eq('Vim(call):E474: Unfinished unicode escape sequence: \t"abc\\u', - exc_exec('call jsondecode("\\t\\"abc\\\\u")')) + exc_exec('call json_decode("\\t\\"abc\\\\u")')) eq('Vim(call):E474: Unfinished unicode escape sequence: \t"abc\\u0', - exc_exec('call jsondecode("\\t\\"abc\\\\u0")')) + exc_exec('call json_decode("\\t\\"abc\\\\u0")')) eq('Vim(call):E474: Unfinished unicode escape sequence: \t"abc\\u00', - exc_exec('call jsondecode("\\t\\"abc\\\\u00")')) + exc_exec('call json_decode("\\t\\"abc\\\\u00")')) eq('Vim(call):E474: Unfinished unicode escape sequence: \t"abc\\u000', - exc_exec('call jsondecode("\\t\\"abc\\\\u000")')) + exc_exec('call json_decode("\\t\\"abc\\\\u000")')) eq('Vim(call):E474: Expected four hex digits after \\u: \\u" ', - exc_exec('call jsondecode("\\t\\"abc\\\\u\\" ")')) + exc_exec('call json_decode("\\t\\"abc\\\\u\\" ")')) eq('Vim(call):E474: Expected four hex digits after \\u: \\u0" ', - exc_exec('call jsondecode("\\t\\"abc\\\\u0\\" ")')) + exc_exec('call json_decode("\\t\\"abc\\\\u0\\" ")')) eq('Vim(call):E474: Expected four hex digits after \\u: \\u00" ', - exc_exec('call jsondecode("\\t\\"abc\\\\u00\\" ")')) + exc_exec('call json_decode("\\t\\"abc\\\\u00\\" ")')) eq('Vim(call):E474: Expected four hex digits after \\u: \\u000" ', - exc_exec('call jsondecode("\\t\\"abc\\\\u000\\" ")')) + exc_exec('call json_decode("\\t\\"abc\\\\u000\\" ")')) eq('Vim(call):E474: Expected string end: \t"abc\\u0000', - exc_exec('call jsondecode("\\t\\"abc\\\\u0000")')) + exc_exec('call json_decode("\\t\\"abc\\\\u0000")')) end) it('fails to parse unknown escape sequnces', function() eq('Vim(call):E474: Unknown escape sequence: \\a"', - exc_exec('call jsondecode("\\t\\"\\\\a\\"")')) + exc_exec('call json_decode("\\t\\"\\\\a\\"")')) end) it('parses strings properly', function() - eq('\n', funcs.jsondecode('"\\n"')) - eq('', funcs.jsondecode('""')) - eq('\\/"\t\b\n\r\f', funcs.jsondecode([["\\\/\"\t\b\n\r\f"]])) - eq('/a', funcs.jsondecode([["\/a"]])) + eq('\n', funcs.json_decode('"\\n"')) + eq('', funcs.json_decode('""')) + eq('\\/"\t\b\n\r\f', funcs.json_decode([["\\\/\"\t\b\n\r\f"]])) + eq('/a', funcs.json_decode([["\/a"]])) -- Unicode characters: 2-byte, 3-byte, 4-byte eq({ '«', 'ફ', '\xF0\x90\x80\x80', - }, funcs.jsondecode({ + }, funcs.json_decode({ '[', '"«",', '"ફ",', @@ -323,74 +323,74 @@ describe('jsondecode() function', function() it('fails on strings with invalid bytes', function() eq('Vim(call):E474: Only UTF-8 strings allowed: \255"', - exc_exec('call jsondecode("\\t\\"\\xFF\\"")')) + exc_exec('call json_decode("\\t\\"\\xFF\\"")')) eq('Vim(call):E474: ASCII control characters cannot be present inside string: ', - exc_exec('call jsondecode(["\\"\\n\\""])')) + exc_exec('call json_decode(["\\"\\n\\""])')) -- 0xC2 starts 2-byte unicode character eq('Vim(call):E474: Only UTF-8 strings allowed: \194"', - exc_exec('call jsondecode("\\t\\"\\xC2\\"")')) + exc_exec('call json_decode("\\t\\"\\xC2\\"")')) -- 0xE0 0xAA starts 3-byte unicode character eq('Vim(call):E474: Only UTF-8 strings allowed: \224"', - exc_exec('call jsondecode("\\t\\"\\xE0\\"")')) + exc_exec('call json_decode("\\t\\"\\xE0\\"")')) eq('Vim(call):E474: Only UTF-8 strings allowed: \224\170"', - exc_exec('call jsondecode("\\t\\"\\xE0\\xAA\\"")')) + exc_exec('call json_decode("\\t\\"\\xE0\\xAA\\"")')) -- 0xF0 0x90 0x80 starts 4-byte unicode character eq('Vim(call):E474: Only UTF-8 strings allowed: \240"', - exc_exec('call jsondecode("\\t\\"\\xF0\\"")')) + exc_exec('call json_decode("\\t\\"\\xF0\\"")')) eq('Vim(call):E474: Only UTF-8 strings allowed: \240\144"', - exc_exec('call jsondecode("\\t\\"\\xF0\\x90\\"")')) + exc_exec('call json_decode("\\t\\"\\xF0\\x90\\"")')) eq('Vim(call):E474: Only UTF-8 strings allowed: \240\144\128"', - exc_exec('call jsondecode("\\t\\"\\xF0\\x90\\x80\\"")')) + exc_exec('call json_decode("\\t\\"\\xF0\\x90\\x80\\"")')) -- 0xF9 0x80 0x80 0x80 starts 5-byte unicode character eq('Vim(call):E474: Only UTF-8 strings allowed: \xF9"', - exc_exec('call jsondecode("\\t\\"\\xF9\\"")')) + exc_exec('call json_decode("\\t\\"\\xF9\\"")')) eq('Vim(call):E474: Only UTF-8 strings allowed: \xF9\x80"', - exc_exec('call jsondecode("\\t\\"\\xF9\\x80\\"")')) + exc_exec('call json_decode("\\t\\"\\xF9\\x80\\"")')) eq('Vim(call):E474: Only UTF-8 strings allowed: \xF9\x80\x80"', - exc_exec('call jsondecode("\\t\\"\\xF9\\x80\\x80\\"")')) + exc_exec('call json_decode("\\t\\"\\xF9\\x80\\x80\\"")')) eq('Vim(call):E474: Only UTF-8 strings allowed: \xF9\x80\x80\x80"', - exc_exec('call jsondecode("\\t\\"\\xF9\\x80\\x80\\x80\\"")')) + exc_exec('call json_decode("\\t\\"\\xF9\\x80\\x80\\x80\\"")')) -- 0xFC 0x90 0x80 0x80 0x80 starts 6-byte unicode character eq('Vim(call):E474: Only UTF-8 strings allowed: \xFC"', - exc_exec('call jsondecode("\\t\\"\\xFC\\"")')) + exc_exec('call json_decode("\\t\\"\\xFC\\"")')) eq('Vim(call):E474: Only UTF-8 strings allowed: \xFC\x90"', - exc_exec('call jsondecode("\\t\\"\\xFC\\x90\\"")')) + exc_exec('call json_decode("\\t\\"\\xFC\\x90\\"")')) eq('Vim(call):E474: Only UTF-8 strings allowed: \xFC\x90\x80"', - exc_exec('call jsondecode("\\t\\"\\xFC\\x90\\x80\\"")')) + exc_exec('call json_decode("\\t\\"\\xFC\\x90\\x80\\"")')) eq('Vim(call):E474: Only UTF-8 strings allowed: \xFC\x90\x80\x80"', - exc_exec('call jsondecode("\\t\\"\\xFC\\x90\\x80\\x80\\"")')) + exc_exec('call json_decode("\\t\\"\\xFC\\x90\\x80\\x80\\"")')) eq('Vim(call):E474: Only UTF-8 strings allowed: \xFC\x90\x80\x80\x80"', - exc_exec('call jsondecode("\\t\\"\\xFC\\x90\\x80\\x80\\x80\\"")')) + exc_exec('call json_decode("\\t\\"\\xFC\\x90\\x80\\x80\\x80\\"")')) -- Specification does not allow unquoted characters above 0x10FFFF eq('Vim(call):E474: Only UTF-8 code points up to U+10FFFF are allowed to appear unescaped: \xF9\x80\x80\x80\x80"', - exc_exec('call jsondecode("\\t\\"\\xF9\\x80\\x80\\x80\\x80\\"")')) + exc_exec('call json_decode("\\t\\"\\xF9\\x80\\x80\\x80\\x80\\"")')) eq('Vim(call):E474: Only UTF-8 code points up to U+10FFFF are allowed to appear unescaped: \xFC\x90\x80\x80\x80\x80"', - exc_exec('call jsondecode("\\t\\"\\xFC\\x90\\x80\\x80\\x80\\x80\\"")')) + exc_exec('call json_decode("\\t\\"\\xFC\\x90\\x80\\x80\\x80\\x80\\"")')) -- '"\xF9\x80\x80\x80\x80"', -- '"\xFC\x90\x80\x80\x80\x80"', end) it('parses surrogate pairs properly', function() - eq('\xF0\x90\x80\x80', funcs.jsondecode('"\\uD800\\uDC00"')) - eq('\xED\xA0\x80a\xED\xB0\x80', funcs.jsondecode('"\\uD800a\\uDC00"')) - eq('\xED\xA0\x80\t\xED\xB0\x80', funcs.jsondecode('"\\uD800\\t\\uDC00"')) + eq('\xF0\x90\x80\x80', funcs.json_decode('"\\uD800\\uDC00"')) + eq('\xED\xA0\x80a\xED\xB0\x80', funcs.json_decode('"\\uD800a\\uDC00"')) + eq('\xED\xA0\x80\t\xED\xB0\x80', funcs.json_decode('"\\uD800\\t\\uDC00"')) - eq('\xED\xA0\x80', funcs.jsondecode('"\\uD800"')) - eq('\xED\xA0\x80a', funcs.jsondecode('"\\uD800a"')) - eq('\xED\xA0\x80\t', funcs.jsondecode('"\\uD800\\t"')) + eq('\xED\xA0\x80', funcs.json_decode('"\\uD800"')) + eq('\xED\xA0\x80a', funcs.json_decode('"\\uD800a"')) + eq('\xED\xA0\x80\t', funcs.json_decode('"\\uD800\\t"')) - eq('\xED\xB0\x80', funcs.jsondecode('"\\uDC00"')) - eq('\xED\xB0\x80a', funcs.jsondecode('"\\uDC00a"')) - eq('\xED\xB0\x80\t', funcs.jsondecode('"\\uDC00\\t"')) + eq('\xED\xB0\x80', funcs.json_decode('"\\uDC00"')) + eq('\xED\xB0\x80a', funcs.json_decode('"\\uDC00a"')) + eq('\xED\xB0\x80\t', funcs.json_decode('"\\uDC00\\t"')) - eq('\xED\xB0\x80', funcs.jsondecode('"\\uDC00"')) - eq('a\xED\xB0\x80', funcs.jsondecode('"a\\uDC00"')) - eq('\t\xED\xB0\x80', funcs.jsondecode('"\\t\\uDC00"')) + eq('\xED\xB0\x80', funcs.json_decode('"\\uDC00"')) + eq('a\xED\xB0\x80', funcs.json_decode('"a\\uDC00"')) + eq('\t\xED\xB0\x80', funcs.json_decode('"\\t\\uDC00"')) end) local sp_decode_eq = function(expected, json) meths.set_var('__json', json) - speq(expected, 'jsondecode(g:__json)') + speq(expected, 'json_decode(g:__json)') execute('unlet! g:__json') end @@ -441,47 +441,47 @@ describe('jsondecode() function', function() it('converts strings to latin1 when &encoding is latin1', function() restart('set encoding=latin1') - eq('\xAB', funcs.jsondecode('"\\u00AB"')) + eq('\xAB', funcs.json_decode('"\\u00AB"')) sp_decode_eq({_TYPE='string', _VAL={'\n\xAB\n'}}, '"\\u0000\\u00AB\\u0000"') end) end) -describe('jsonencode() function', function() +describe('json_encode() function', function() before_each(clear) it('dumps strings', function() - eq('"Test"', funcs.jsonencode('Test')) - eq('""', funcs.jsonencode('')) - eq('"\\t"', funcs.jsonencode('\t')) - eq('"\\n"', funcs.jsonencode('\n')) - eq('"\\u001B"', funcs.jsonencode('\27')) - eq('"þÿþ"', funcs.jsonencode('þÿþ')) + eq('"Test"', funcs.json_encode('Test')) + eq('""', funcs.json_encode('')) + eq('"\\t"', funcs.json_encode('\t')) + eq('"\\n"', funcs.json_encode('\n')) + eq('"\\u001B"', funcs.json_encode('\27')) + eq('"þÿþ"', funcs.json_encode('þÿþ')) end) it('dumps numbers', function() - eq('0', funcs.jsonencode(0)) - eq('10', funcs.jsonencode(10)) - eq('-10', funcs.jsonencode(-10)) + eq('0', funcs.json_encode(0)) + eq('10', funcs.json_encode(10)) + eq('-10', funcs.json_encode(-10)) end) it('dumps floats', function() - eq('0.0', eval('jsonencode(0.0)')) - eq('10.5', funcs.jsonencode(10.5)) - eq('-10.5', funcs.jsonencode(-10.5)) - eq('-1.0e-5', funcs.jsonencode(-1e-5)) - eq('1.0e50', eval('jsonencode(1.0e50)')) + eq('0.0', eval('json_encode(0.0)')) + eq('10.5', funcs.json_encode(10.5)) + eq('-10.5', funcs.json_encode(-10.5)) + eq('-1.0e-5', funcs.json_encode(-1e-5)) + eq('1.0e50', eval('json_encode(1.0e50)')) end) it('dumps lists', function() - eq('[]', funcs.jsonencode({})) - eq('[[]]', funcs.jsonencode({{}})) - eq('[[], []]', funcs.jsonencode({{}, {}})) + eq('[]', funcs.json_encode({})) + eq('[[]]', funcs.json_encode({{}})) + eq('[[], []]', funcs.json_encode({{}, {}})) end) it('dumps dictionaries', function() - eq('{}', eval('jsonencode({})')) - eq('{"d": []}', funcs.jsonencode({d={}})) - eq('{"d": [], "e": []}', funcs.jsonencode({d={}, e={}})) + eq('{}', eval('json_encode({})')) + eq('{"d": []}', funcs.json_encode({d={}})) + eq('{"d": [], "e": []}', funcs.json_encode({d={}, e={}})) end) it('cannot dump generic mapping with generic mapping keys and values', @@ -490,148 +490,148 @@ describe('jsonencode() function', function() execute('let todumpv1 = {"_TYPE": v:msgpack_types.map, "_VAL": []}') execute('let todumpv2 = {"_TYPE": v:msgpack_types.map, "_VAL": []}') execute('call add(todump._VAL, [todumpv1, todumpv2])') - eq('Vim(call):E474: Invalid key in special dictionary', exc_exec('call jsonencode(todump)')) + eq('Vim(call):E474: Invalid key in special dictionary', exc_exec('call json_encode(todump)')) end) it('cannot dump generic mapping with ext key', function() execute('let todump = {"_TYPE": v:msgpack_types.ext, "_VAL": [5, ["",""]]}') execute('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}') - eq('Vim(call):E474: Invalid key in special dictionary', exc_exec('call jsonencode(todump)')) + eq('Vim(call):E474: Invalid key in special dictionary', exc_exec('call json_encode(todump)')) end) it('cannot dump generic mapping with array key', function() execute('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": [5, [""]]}') execute('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}') - eq('Vim(call):E474: Invalid key in special dictionary', exc_exec('call jsonencode(todump)')) + eq('Vim(call):E474: Invalid key in special dictionary', exc_exec('call json_encode(todump)')) end) it('cannot dump generic mapping with UINT64_MAX key', function() execute('let todump = {"_TYPE": v:msgpack_types.integer}') execute('let todump._VAL = [1, 3, 0x7FFFFFFF, 0x7FFFFFFF]') execute('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}') - eq('Vim(call):E474: Invalid key in special dictionary', exc_exec('call jsonencode(todump)')) + eq('Vim(call):E474: Invalid key in special dictionary', exc_exec('call json_encode(todump)')) end) it('cannot dump generic mapping with floating-point key', function() execute('let todump = {"_TYPE": v:msgpack_types.float, "_VAL": 0.125}') execute('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}') - eq('Vim(call):E474: Invalid key in special dictionary', exc_exec('call jsonencode(todump)')) + eq('Vim(call):E474: Invalid key in special dictionary', exc_exec('call json_encode(todump)')) end) it('can dump generic mapping with STR special key and NUL', function() execute('let todump = {"_TYPE": v:msgpack_types.string, "_VAL": ["\\n"]}') execute('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}') - eq('{"\\u0000": 1}', eval('jsonencode(todump)')) + eq('{"\\u0000": 1}', eval('json_encode(todump)')) end) it('can dump generic mapping with BIN special key and NUL', function() execute('let todump = {"_TYPE": v:msgpack_types.binary, "_VAL": ["\\n"]}') execute('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}') - eq('{"\\u0000": 1}', eval('jsonencode(todump)')) + eq('{"\\u0000": 1}', eval('json_encode(todump)')) end) it('can dump STR special mapping with NUL and NL', function() execute('let todump = {"_TYPE": v:msgpack_types.string, "_VAL": ["\\n", ""]}') - eq('"\\u0000\\n"', eval('jsonencode(todump)')) + eq('"\\u0000\\n"', eval('json_encode(todump)')) end) it('can dump BIN special mapping with NUL and NL', function() execute('let todump = {"_TYPE": v:msgpack_types.binary, "_VAL": ["\\n", ""]}') - eq('"\\u0000\\n"', eval('jsonencode(todump)')) + eq('"\\u0000\\n"', eval('json_encode(todump)')) end) it('cannot dump special ext mapping', function() execute('let todump = {"_TYPE": v:msgpack_types.ext, "_VAL": [5, ["",""]]}') - eq('Vim(call):E474: Unable to convert EXT string to JSON', exc_exec('call jsonencode(todump)')) + eq('Vim(call):E474: Unable to convert EXT string to JSON', exc_exec('call json_encode(todump)')) end) it('can dump special array mapping', function() execute('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": [5, [""]]}') - eq('[5, [""]]', eval('jsonencode(todump)')) + eq('[5, [""]]', eval('json_encode(todump)')) end) it('can dump special UINT64_MAX mapping', function() execute('let todump = {"_TYPE": v:msgpack_types.integer}') execute('let todump._VAL = [1, 3, 0x7FFFFFFF, 0x7FFFFFFF]') - eq('18446744073709551615', eval('jsonencode(todump)')) + eq('18446744073709551615', eval('json_encode(todump)')) end) it('can dump special INT64_MIN mapping', function() execute('let todump = {"_TYPE": v:msgpack_types.integer}') execute('let todump._VAL = [-1, 2, 0, 0]') - eq('-9223372036854775808', eval('jsonencode(todump)')) + eq('-9223372036854775808', eval('json_encode(todump)')) end) it('can dump special BOOLEAN true mapping', function() execute('let todump = {"_TYPE": v:msgpack_types.boolean, "_VAL": 1}') - eq('true', eval('jsonencode(todump)')) + eq('true', eval('json_encode(todump)')) end) it('can dump special BOOLEAN false mapping', function() execute('let todump = {"_TYPE": v:msgpack_types.boolean, "_VAL": 0}') - eq('false', eval('jsonencode(todump)')) + eq('false', eval('json_encode(todump)')) end) it('can dump special NIL mapping', function() execute('let todump = {"_TYPE": v:msgpack_types.nil, "_VAL": 0}') - eq('null', eval('jsonencode(todump)')) + eq('null', eval('json_encode(todump)')) end) it('fails to dump a function reference', function() eq('Vim(call):E474: Error while dumping encode_tv2json() argument, itself: attempt to dump function reference', - exc_exec('call jsonencode(function("tr"))')) + exc_exec('call json_encode(function("tr"))')) end) it('fails to dump a function reference in a list', function() eq('Vim(call):E474: Error while dumping encode_tv2json() argument, index 0: attempt to dump function reference', - exc_exec('call jsonencode([function("tr")])')) + exc_exec('call json_encode([function("tr")])')) end) it('fails to dump a recursive list', function() execute('let todump = [[[]]]') execute('call add(todump[0][0], todump)') eq('Vim(call):E724: unable to correctly dump variable with self-referencing container', - exc_exec('call jsonencode(todump)')) + exc_exec('call json_encode(todump)')) end) it('fails to dump a recursive dict', function() execute('let todump = {"d": {"d": {}}}') execute('call extend(todump.d.d, {"d": todump})') eq('Vim(call):E724: unable to correctly dump variable with self-referencing container', - exc_exec('call jsonencode([todump])')) + exc_exec('call json_encode([todump])')) end) it('can dump dict with two same dicts inside', function() execute('let inter = {}') execute('let todump = {"a": inter, "b": inter}') - eq('{"a": {}, "b": {}}', eval('jsonencode(todump)')) + eq('{"a": {}, "b": {}}', eval('json_encode(todump)')) end) it('can dump list with two same lists inside', function() execute('let inter = []') execute('let todump = [inter, inter]') - eq('[[], []]', eval('jsonencode(todump)')) + eq('[[], []]', eval('json_encode(todump)')) end) it('fails to dump a recursive list in a special dict', function() execute('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": []}') execute('call add(todump._VAL, todump)') eq('Vim(call):E724: unable to correctly dump variable with self-referencing container', - exc_exec('call jsonencode(todump)')) + exc_exec('call json_encode(todump)')) end) it('fails to dump a recursive (val) map in a special dict', function() execute('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": []}') execute('call add(todump._VAL, ["", todump])') eq('Vim(call):E724: unable to correctly dump variable with self-referencing container', - exc_exec('call jsonencode([todump])')) + exc_exec('call json_encode([todump])')) end) it('fails to dump a recursive (val) map in a special dict, _VAL reference', function() execute('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [["", []]]}') execute('call add(todump._VAL[0][1], todump._VAL)') eq('Vim(call):E724: unable to correctly dump variable with self-referencing container', - exc_exec('call jsonencode(todump)')) + exc_exec('call json_encode(todump)')) end) it('fails to dump a recursive (val) special list in a special dict', @@ -639,35 +639,35 @@ describe('jsonencode() function', function() execute('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": []}') execute('call add(todump._VAL, ["", todump._VAL])') eq('Vim(call):E724: unable to correctly dump variable with self-referencing container', - exc_exec('call jsonencode(todump)')) + exc_exec('call json_encode(todump)')) end) it('fails when called with no arguments', function() - eq('Vim(call):E119: Not enough arguments for function: jsonencode', - exc_exec('call jsonencode()')) + eq('Vim(call):E119: Not enough arguments for function: json_encode', + exc_exec('call json_encode()')) end) it('fails when called with two arguments', function() - eq('Vim(call):E118: Too many arguments for function: jsonencode', - exc_exec('call jsonencode(["", ""], 1)')) + eq('Vim(call):E118: Too many arguments for function: json_encode', + exc_exec('call json_encode(["", ""], 1)')) end) it('converts strings from latin1 when &encoding is latin1', function() clear('set encoding=latin1') - eq('"\\u00AB"', funcs.jsonencode('\xAB')) - eq('"\\u0000\\u00AB\\u0000"', eval('jsonencode({"_TYPE": v:msgpack_types.string, "_VAL": ["\\n\xAB\\n"]})')) + eq('"\\u00AB"', funcs.json_encode('\xAB')) + eq('"\\u0000\\u00AB\\u0000"', eval('json_encode({"_TYPE": v:msgpack_types.string, "_VAL": ["\\n\xAB\\n"]})')) end) it('ignores improper values in &isprint', function() meths.set_option('isprint', '1') eq(1, eval('"\x01" =~# "\\\\p"')) - eq('"\\u0001"', funcs.jsonencode('\x01')) + eq('"\\u0001"', funcs.json_encode('\x01')) end) it('fails when using surrogate character in a UTF-8 string', function() eq('Vim(call):E474: UTF-8 string contains code point which belongs to a surrogate pair: \xED\xA0\x80', - exc_exec('call jsonencode("\xED\xA0\x80")')) + exc_exec('call json_encode("\xED\xA0\x80")')) eq('Vim(call):E474: UTF-8 string contains code point which belongs to a surrogate pair: \xED\xAF\xBF', - exc_exec('call jsonencode("\xED\xAF\xBF")')) + exc_exec('call json_encode("\xED\xAF\xBF")')) end) end) |