From 65fb622000af8e3dbb65480e1581758ecf4ba3e2 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 9 Apr 2017 00:12:26 +0300 Subject: functests: Replace execute with either command or feed_command Hope this will make people using feed_command less likely: this hides bugs. Already found at least two: 1. msgpackparse() will show internal error: hash_add() in case of duplicate keys, though it will still work correctly. Currently silenced. 2. ttimeoutlen was spelled incorrectly, resulting in option not being set when expected. Test was still functioning somehow though. Currently fixed. --- test/functional/eval/msgpack_functions_spec.lua | 149 ++++++++++++------------ 1 file changed, 75 insertions(+), 74 deletions(-) (limited to 'test/functional/eval/msgpack_functions_spec.lua') diff --git a/test/functional/eval/msgpack_functions_spec.lua b/test/functional/eval/msgpack_functions_spec.lua index 44c01d2226..c5520deb73 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,9 +331,9 @@ 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 @@ -345,9 +345,9 @@ 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 @@ -359,33 +359,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 +394,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 +449,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) @@ -494,7 +495,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 +515,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 +531,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 +690,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) -- cgit From e82cb5de4adc8a88e8213d0aca85400362df4bd1 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sun, 30 Apr 2017 14:35:36 +0200 Subject: api: add metadata for ui events --- test/functional/eval/msgpack_functions_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/eval/msgpack_functions_spec.lua') diff --git a/test/functional/eval/msgpack_functions_spec.lua b/test/functional/eval/msgpack_functions_spec.lua index c5520deb73..4a052b4aff 100644 --- a/test/functional/eval/msgpack_functions_spec.lua +++ b/test/functional/eval/msgpack_functions_spec.lua @@ -461,7 +461,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() -- cgit From d69286c065a27706b1b8c8992be1bf5238f433a7 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Tue, 6 Jun 2017 11:37:56 -0400 Subject: functests/msgpack: Use assert_equal() for more informative errors --- test/functional/eval/msgpack_functions_spec.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'test/functional/eval/msgpack_functions_spec.lua') diff --git a/test/functional/eval/msgpack_functions_spec.lua b/test/functional/eval/msgpack_functions_spec.lua index 4a052b4aff..8ed01d4996 100644 --- a/test/functional/eval/msgpack_functions_spec.lua +++ b/test/functional/eval/msgpack_functions_spec.lua @@ -337,7 +337,8 @@ describe('msgpack*() functions', function() 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 @@ -351,7 +352,8 @@ describe('msgpack*() functions', function() 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(-0x8000000000000000, parsed[0])') + eq({}, eval('v:errors')) else eq({_TYPE={}, _VAL={-1, 2, 0, 0}}, eval('parsed[0]')) end -- cgit From bf4de3f6f761bc73801eadffc63a0c18d00c2db7 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Tue, 6 Jun 2017 13:38:23 -0400 Subject: functests/msgpack: Correct representation of literal INT64_MIN In order to generate INT64_MIN from literal values, it's necessary to use "-0x7fffffffffffffff - 1". Using "-0x8000000000000000" causes the value to get clamped to INT64_MAX and then negated. --- test/functional/eval/msgpack_functions_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/eval/msgpack_functions_spec.lua') diff --git a/test/functional/eval/msgpack_functions_spec.lua b/test/functional/eval/msgpack_functions_spec.lua index 8ed01d4996..b241635dfe 100644 --- a/test/functional/eval/msgpack_functions_spec.lua +++ b/test/functional/eval/msgpack_functions_spec.lua @@ -352,7 +352,7 @@ describe('msgpack*() functions', function() 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 - command('call assert_equal(-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]')) -- cgit