aboutsummaryrefslogtreecommitdiff
path: root/test/functional/eval/msgpack_functions_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/eval/msgpack_functions_spec.lua')
-rw-r--r--test/functional/eval/msgpack_functions_spec.lua157
1 files changed, 80 insertions, 77 deletions
diff --git a/test/functional/eval/msgpack_functions_spec.lua b/test/functional/eval/msgpack_functions_spec.lua
index 44c01d2226..b241635dfe 100644
--- a/test/functional/eval/msgpack_functions_spec.lua
+++ b/test/functional/eval/msgpack_functions_spec.lua
@@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local funcs = helpers.funcs
local eval, eq = helpers.eval, helpers.eq
-local execute = helpers.execute
+local command = helpers.command
local nvim = helpers.nvim
local exc_exec = helpers.exc_exec
@@ -331,13 +331,14 @@ describe('msgpack*() functions', function()
obj_test('are able to dump and restore floating-point value', {0.125})
it('can restore and dump UINT64_MAX', function()
- execute('let dumped = ["\\xCF" . repeat("\\xFF", 8)]')
- execute('let parsed = msgpackparse(dumped)')
- execute('let dumped2 = msgpackdump(parsed)')
+ command('let dumped = ["\\xCF" . repeat("\\xFF", 8)]')
+ command('let parsed = msgpackparse(dumped)')
+ command('let dumped2 = msgpackdump(parsed)')
eq(1, eval('type(parsed[0]) == type(0) ' ..
'|| parsed[0]._TYPE is v:msgpack_types.integer'))
if eval('type(parsed[0]) == type(0)') == 1 then
- eq(1, eval('0xFFFFFFFFFFFFFFFF == parsed[0]'))
+ command('call assert_equal(0xFFFFFFFFFFFFFFFF, parsed[0])')
+ eq({}, eval('v:errors'))
else
eq({_TYPE={}, _VAL={1, 3, 0x7FFFFFFF, 0x7FFFFFFF}}, eval('parsed[0]'))
end
@@ -345,13 +346,14 @@ describe('msgpack*() functions', function()
end)
it('can restore and dump INT64_MIN', function()
- execute('let dumped = ["\\xD3\\x80" . repeat("\\n", 7)]')
- execute('let parsed = msgpackparse(dumped)')
- execute('let dumped2 = msgpackdump(parsed)')
+ command('let dumped = ["\\xD3\\x80" . repeat("\\n", 7)]')
+ command('let parsed = msgpackparse(dumped)')
+ command('let dumped2 = msgpackdump(parsed)')
eq(1, eval('type(parsed[0]) == type(0) ' ..
'|| parsed[0]._TYPE is v:msgpack_types.integer'))
if eval('type(parsed[0]) == type(0)') == 1 then
- eq(1, eval('-0x8000000000000000 == parsed[0]'))
+ command('call assert_equal(-0x7fffffffffffffff - 1, parsed[0])')
+ eq({}, eval('v:errors'))
else
eq({_TYPE={}, _VAL={-1, 2, 0, 0}}, eval('parsed[0]'))
end
@@ -359,33 +361,33 @@ describe('msgpack*() functions', function()
end)
it('can restore and dump BIN string with zero byte', function()
- execute('let dumped = ["\\xC4\\x01\\n"]')
- execute('let parsed = msgpackparse(dumped)')
- execute('let dumped2 = msgpackdump(parsed)')
+ command('let dumped = ["\\xC4\\x01\\n"]')
+ command('let parsed = msgpackparse(dumped)')
+ command('let dumped2 = msgpackdump(parsed)')
eq({{_TYPE={}, _VAL={'\n'}}}, eval('parsed'))
eq(1, eval('parsed[0]._TYPE is v:msgpack_types.binary'))
eq(1, eval('dumped ==# dumped2'))
end)
it('can restore and dump STR string with zero byte', function()
- execute('let dumped = ["\\xA1\\n"]')
- execute('let parsed = msgpackparse(dumped)')
- execute('let dumped2 = msgpackdump(parsed)')
+ command('let dumped = ["\\xA1\\n"]')
+ command('let parsed = msgpackparse(dumped)')
+ command('let dumped2 = msgpackdump(parsed)')
eq({{_TYPE={}, _VAL={'\n'}}}, eval('parsed'))
eq(1, eval('parsed[0]._TYPE is v:msgpack_types.string'))
eq(1, eval('dumped ==# dumped2'))
end)
it('can restore and dump BIN string with NL', function()
- execute('let dumped = ["\\xC4\\x01", ""]')
- execute('let parsed = msgpackparse(dumped)')
- execute('let dumped2 = msgpackdump(parsed)')
+ command('let dumped = ["\\xC4\\x01", ""]')
+ command('let parsed = msgpackparse(dumped)')
+ command('let dumped2 = msgpackdump(parsed)')
eq({"\n"}, eval('parsed'))
eq(1, eval('dumped ==# dumped2'))
end)
it('dump and restore special mapping with floating-point value', function()
- execute('let todump = {"_TYPE": v:msgpack_types.float, "_VAL": 0.125}')
+ command('let todump = {"_TYPE": v:msgpack_types.float, "_VAL": 0.125}')
eq({0.125}, eval('msgpackparse(msgpackdump([todump]))'))
end)
end)
@@ -394,52 +396,53 @@ describe('msgpackparse() function', function()
before_each(clear)
it('restores nil as v:null', function()
- execute('let dumped = ["\\xC0"]')
- execute('let parsed = msgpackparse(dumped)')
+ command('let dumped = ["\\xC0"]')
+ command('let parsed = msgpackparse(dumped)')
eq('[v:null]', eval('string(parsed)'))
end)
it('restores boolean false as v:false', function()
- execute('let dumped = ["\\xC2"]')
- execute('let parsed = msgpackparse(dumped)')
+ command('let dumped = ["\\xC2"]')
+ command('let parsed = msgpackparse(dumped)')
eq({false}, eval('parsed'))
end)
it('restores boolean true as v:true', function()
- execute('let dumped = ["\\xC3"]')
- execute('let parsed = msgpackparse(dumped)')
+ command('let dumped = ["\\xC3"]')
+ command('let parsed = msgpackparse(dumped)')
eq({true}, eval('parsed'))
end)
it('restores FIXSTR as special dict', function()
- execute('let dumped = ["\\xa2ab"]')
- execute('let parsed = msgpackparse(dumped)')
+ command('let dumped = ["\\xa2ab"]')
+ command('let parsed = msgpackparse(dumped)')
eq({{_TYPE={}, _VAL={'ab'}}}, eval('parsed'))
eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.string'))
end)
it('restores BIN 8 as string', function()
- execute('let dumped = ["\\xC4\\x02ab"]')
+ command('let dumped = ["\\xC4\\x02ab"]')
eq({'ab'}, eval('msgpackparse(dumped)'))
end)
it('restores FIXEXT1 as special dictionary', function()
- execute('let dumped = ["\\xD4\\x10", ""]')
- execute('let parsed = msgpackparse(dumped)')
+ command('let dumped = ["\\xD4\\x10", ""]')
+ command('let parsed = msgpackparse(dumped)')
eq({{_TYPE={}, _VAL={0x10, {"", ""}}}}, eval('parsed'))
eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.ext'))
end)
it('restores MAP with BIN key as special dictionary', function()
- execute('let dumped = ["\\x81\\xC4\\x01a\\xC4\\n"]')
- execute('let parsed = msgpackparse(dumped)')
+ command('let dumped = ["\\x81\\xC4\\x01a\\xC4\\n"]')
+ command('let parsed = msgpackparse(dumped)')
eq({{_TYPE={}, _VAL={{'a', ''}}}}, eval('parsed'))
eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.map'))
end)
it('restores MAP with duplicate STR keys as special dictionary', function()
- execute('let dumped = ["\\x82\\xA1a\\xC4\\n\\xA1a\\xC4\\n"]')
- execute('let parsed = msgpackparse(dumped)')
+ command('let dumped = ["\\x82\\xA1a\\xC4\\n\\xA1a\\xC4\\n"]')
+ -- FIXME Internal error bug
+ command('silent! let parsed = msgpackparse(dumped)')
eq({{_TYPE={}, _VAL={ {{_TYPE={}, _VAL={'a'}}, ''},
{{_TYPE={}, _VAL={'a'}}, ''}}} }, eval('parsed'))
eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.map'))
@@ -448,8 +451,8 @@ describe('msgpackparse() function', function()
end)
it('restores MAP with MAP key as special dictionary', function()
- execute('let dumped = ["\\x81\\x80\\xC4\\n"]')
- execute('let parsed = msgpackparse(dumped)')
+ command('let dumped = ["\\x81\\x80\\xC4\\n"]')
+ command('let parsed = msgpackparse(dumped)')
eq({{_TYPE={}, _VAL={{{}, ''}}}}, eval('parsed'))
eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.map'))
end)
@@ -460,7 +463,7 @@ describe('msgpackparse() function', function()
eval(cmd)
eval(cmd) -- do it again (try to force segfault)
local api_info = eval(cmd) -- do it again
- eq({'error_types', 'functions', 'types', 'version'}, api_info)
+ eq({'error_types', 'functions', 'types', 'ui_events', 'version'}, api_info)
end)
it('fails when called with no arguments', function()
@@ -494,7 +497,7 @@ describe('msgpackparse() function', function()
end)
it('fails to parse a partial', function()
- execute('function T() dict\nendfunction')
+ command('function T() dict\nendfunction')
eq('Vim(call):E686: Argument of msgpackparse() must be a List',
exc_exec('call msgpackparse(function("T", [1, 2], {}))'))
end)
@@ -514,10 +517,10 @@ describe('msgpackdump() function', function()
end)
it('can dump generic mapping with generic mapping keys and values', function()
- execute('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": []}')
- 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])')
+ command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": []}')
+ command('let todumpv1 = {"_TYPE": v:msgpack_types.map, "_VAL": []}')
+ command('let todumpv2 = {"_TYPE": v:msgpack_types.map, "_VAL": []}')
+ command('call add(todump._VAL, [todumpv1, todumpv2])')
eq({'\129\128\128'}, eval('msgpackdump([todump])'))
end)
@@ -530,130 +533,130 @@ describe('msgpackdump() function', function()
end)
it('can v:null', function()
- execute('let todump = v:null')
+ command('let todump = v:null')
end)
it('can dump special bool mapping (true)', function()
- execute('let todump = {"_TYPE": v:msgpack_types.boolean, "_VAL": 1}')
+ command('let todump = {"_TYPE": v:msgpack_types.boolean, "_VAL": 1}')
eq({'\195'}, eval('msgpackdump([todump])'))
end)
it('can dump special bool mapping (false)', function()
- execute('let todump = {"_TYPE": v:msgpack_types.boolean, "_VAL": 0}')
+ command('let todump = {"_TYPE": v:msgpack_types.boolean, "_VAL": 0}')
eq({'\194'}, eval('msgpackdump([todump])'))
end)
it('can dump special nil mapping', function()
- execute('let todump = {"_TYPE": v:msgpack_types.nil, "_VAL": 0}')
+ command('let todump = {"_TYPE": v:msgpack_types.nil, "_VAL": 0}')
eq({'\192'}, eval('msgpackdump([todump])'))
end)
it('can dump special ext mapping', function()
- execute('let todump = {"_TYPE": v:msgpack_types.ext, "_VAL": [5, ["",""]]}')
+ command('let todump = {"_TYPE": v:msgpack_types.ext, "_VAL": [5, ["",""]]}')
eq({'\212\005', ''}, eval('msgpackdump([todump])'))
end)
it('can dump special array mapping', function()
- execute('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": [5, [""]]}')
+ command('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": [5, [""]]}')
eq({'\146\005\145\196\n'}, eval('msgpackdump([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]')
+ command('let todump = {"_TYPE": v:msgpack_types.integer}')
+ command('let todump._VAL = [1, 3, 0x7FFFFFFF, 0x7FFFFFFF]')
eq({'\207\255\255\255\255\255\255\255\255'}, eval('msgpackdump([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]')
+ command('let todump = {"_TYPE": v:msgpack_types.integer}')
+ command('let todump._VAL = [-1, 2, 0, 0]')
eq({'\211\128\n\n\n\n\n\n\n'}, eval('msgpackdump([todump])'))
end)
it('fails to dump a function reference', function()
- execute('let Todump = function("tr")')
+ command('let Todump = function("tr")')
eq('Vim(call):E5004: Error while dumping msgpackdump() argument, index 0, itself: attempt to dump function reference',
exc_exec('call msgpackdump([Todump])'))
end)
it('fails to dump a partial', function()
- execute('function T() dict\nendfunction')
- execute('let Todump = function("T", [1, 2], {})')
+ command('function T() dict\nendfunction')
+ command('let Todump = function("T", [1, 2], {})')
eq('Vim(call):E5004: Error while dumping msgpackdump() argument, index 0, itself: attempt to dump function reference',
exc_exec('call msgpackdump([Todump])'))
end)
it('fails to dump a function reference in a list', function()
- execute('let todump = [function("tr")]')
+ command('let todump = [function("tr")]')
eq('Vim(call):E5004: Error while dumping msgpackdump() argument, index 0, index 0: attempt to dump function reference',
exc_exec('call msgpackdump([todump])'))
end)
it('fails to dump a recursive list', function()
- execute('let todump = [[[]]]')
- execute('call add(todump[0][0], todump)')
+ command('let todump = [[[]]]')
+ command('call add(todump[0][0], todump)')
eq('Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in index 0, index 0, index 0',
exc_exec('call msgpackdump([todump])'))
end)
it('fails to dump a recursive dict', function()
- execute('let todump = {"d": {"d": {}}}')
- execute('call extend(todump.d.d, {"d": todump})')
+ command('let todump = {"d": {"d": {}}}')
+ command('call extend(todump.d.d, {"d": todump})')
eq('Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in key \'d\', key \'d\', key \'d\'',
exc_exec('call msgpackdump([todump])'))
end)
it('can dump dict with two same dicts inside', function()
- execute('let inter = {}')
- execute('let todump = {"a": inter, "b": inter}')
+ command('let inter = {}')
+ command('let todump = {"a": inter, "b": inter}')
eq({"\130\161a\128\161b\128"}, eval('msgpackdump([todump])'))
end)
it('can dump list with two same lists inside', function()
- execute('let inter = []')
- execute('let todump = [inter, inter]')
+ command('let inter = []')
+ command('let todump = [inter, inter]')
eq({"\146\144\144"}, eval('msgpackdump([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)')
+ command('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": []}')
+ command('call add(todump._VAL, todump)')
eq('Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in index 0',
exc_exec('call msgpackdump([todump])'))
end)
it('fails to dump a recursive (key) map in a special dict', function()
- execute('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": []}')
- execute('call add(todump._VAL, [todump, 0])')
+ command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": []}')
+ command('call add(todump._VAL, [todump, 0])')
eq('Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in index 1',
exc_exec('call msgpackdump([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, [0, todump])')
+ command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": []}')
+ command('call add(todump._VAL, [0, todump])')
eq('Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in key 0 at index 0 from special map',
exc_exec('call msgpackdump([todump])'))
end)
it('fails to dump a recursive (key) map in a special dict, _VAL reference', function()
- execute('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[[], []]]}')
- execute('call add(todump._VAL[0][0], todump._VAL)')
+ command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[[], []]]}')
+ command('call add(todump._VAL[0][0], todump._VAL)')
eq('Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in key [[[[...@0], []]]] at index 0 from special map, index 0',
exc_exec('call msgpackdump([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)')
+ command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[[], []]]}')
+ command('call add(todump._VAL[0][1], todump._VAL)')
eq('Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in key [] at index 0 from special map, index 0',
exc_exec('call msgpackdump([todump])'))
end)
it('fails to dump a recursive (val) special list in a special dict',
function()
- execute('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": []}')
- execute('call add(todump._VAL, [0, todump._VAL])')
+ command('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": []}')
+ command('call add(todump._VAL, [0, todump._VAL])')
eq('Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in index 0, index 1',
exc_exec('call msgpackdump([todump])'))
end)
@@ -689,7 +692,7 @@ describe('msgpackdump() function', function()
end)
it('fails to dump a partial', function()
- execute('function T() dict\nendfunction')
+ command('function T() dict\nendfunction')
eq('Vim(call):E686: Argument of msgpackdump() must be a List',
exc_exec('call msgpackdump(function("T", [1, 2], {}))'))
end)