aboutsummaryrefslogtreecommitdiff
path: root/test/functional/eval/json_functions_spec.lua
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2016-02-05 00:29:47 +0300
committerZyX <kp-pav@yandex.ru>2016-04-18 02:45:49 +0300
commit2c378fdfaf4927b7071b2e673c19c8acb8dcdfd4 (patch)
treee954dc73889bed367435214bb098e0974fb2ab85 /test/functional/eval/json_functions_spec.lua
parent634e51d12b90b00dd01b768904d7bf5ade0acbb0 (diff)
downloadrneovim-2c378fdfaf4927b7071b2e673c19c8acb8dcdfd4.tar.gz
rneovim-2c378fdfaf4927b7071b2e673c19c8acb8dcdfd4.tar.bz2
rneovim-2c378fdfaf4927b7071b2e673c19c8acb8dcdfd4.zip
eval/decode: Parse strings with NUL to special dictionaries
Diffstat (limited to 'test/functional/eval/json_functions_spec.lua')
-rw-r--r--test/functional/eval/json_functions_spec.lua71
1 files changed, 70 insertions, 1 deletions
diff --git a/test/functional/eval/json_functions_spec.lua b/test/functional/eval/json_functions_spec.lua
index 651f6c27b3..7916bc829c 100644
--- a/test/functional/eval/json_functions_spec.lua
+++ b/test/functional/eval/json_functions_spec.lua
@@ -1,13 +1,63 @@
local helpers = require('test.functional.helpers')
local clear = helpers.clear
local funcs = helpers.funcs
+local meths = helpers.meths
local eq = helpers.eq
local eval = helpers.eval
local execute = helpers.execute
local exc_exec = helpers.exc_exec
describe('jsondecode() function', function()
- before_each(clear)
+ before_each(function()
+ clear()
+ execute([[
+ function Eq(exp, act)
+ let act = a:act
+ let exp = a:exp
+ if type(exp) != type(act)
+ return 0
+ endif
+ if type(exp) == type({})
+ if sort(keys(exp)) !=# sort(keys(act))
+ return 0
+ endif
+ if sort(keys(exp)) ==# ['_TYPE', '_VAL']
+ let exp_typ = v:msgpack_types[exp._TYPE]
+ let act_typ = act._TYPE
+ if exp_typ isnot act_typ
+ return 0
+ endif
+ return Eq(exp._VAL, act._VAL)
+ else
+ return empty(filter(copy(exp), '!Eq(v:val, act[v:key])'))
+ endif
+ else
+ if type(exp) == type([])
+ if len(exp) != len(act)
+ return 0
+ endif
+ return empty(filter(copy(exp), '!Eq(v:val, act[v:key])'))
+ endif
+ return exp ==# act
+ endif
+ return 1
+ endfunction
+ ]])
+ execute([[
+ function EvalEq(exp, act_expr)
+ let act = eval(a:act_expr)
+ if Eq(a:exp, act)
+ return 1
+ else
+ return string(act)
+ endif
+ endfunction
+ ]])
+ end)
+
+ local speq = function(expected, actual_expr)
+ eq(1, funcs.EvalEq(expected, actual_expr))
+ end
it('accepts readfile()-style list', function()
eq({Test=1}, funcs.jsondecode({
@@ -221,6 +271,14 @@ describe('jsondecode() function', function()
exc_exec('call jsondecode("\\t\\"abc\\\\u00")'))
eq('Vim(call):E474: Unfinished unicode escape sequence: \t"abc\\u000',
exc_exec('call jsondecode("\\t\\"abc\\\\u000")'))
+ eq('Vim(call):E474: Expected four hex digits after \\u: \\u" ',
+ exc_exec('call jsondecode("\\t\\"abc\\\\u\\" ")'))
+ eq('Vim(call):E474: Expected four hex digits after \\u: \\u0" ',
+ exc_exec('call jsondecode("\\t\\"abc\\\\u0\\" ")'))
+ eq('Vim(call):E474: Expected four hex digits after \\u: \\u00" ',
+ exc_exec('call jsondecode("\\t\\"abc\\\\u00\\" ")'))
+ eq('Vim(call):E474: Expected four hex digits after \\u: \\u000" ',
+ exc_exec('call jsondecode("\\t\\"abc\\\\u000\\" ")'))
eq('Vim(call):E474: Expected string end: \t"abc\\u0000',
exc_exec('call jsondecode("\\t\\"abc\\\\u0000")'))
end)
@@ -315,6 +373,17 @@ describe('jsondecode() function', function()
eq('a\xED\xB0\x80', funcs.jsondecode('"a\\uDC00"'))
eq('\t\xED\xB0\x80', funcs.jsondecode('"\\t\\uDC00"'))
end)
+
+ local sp_decode_eq = function(expected, json)
+ meths.set_var('__json', json)
+ speq(expected, 'jsondecode(g:__json)')
+ execute('unlet! g:__json')
+ end
+
+ it('parses strings with NUL properly', function()
+ sp_decode_eq({_TYPE='string', _VAL={'\n'}}, '"\\u0000"')
+ sp_decode_eq({_TYPE='string', _VAL={'\n', '\n'}}, '"\\u0000\\n\\u0000"')
+ end)
end)
describe('jsonencode() function', function()