From 0f3afdaa1b5a75a5ed54a69dc43e32ddbb6a32ea Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 21 Mar 2017 16:22:04 +0100 Subject: vim-patch:8.0.0259 Problem: Tab commands do not handle count correctly. (Ken Hamada) Solution: Add ADDR_TABS_RELATIVE. (Hirohito Higashi) https://github.com/vim/vim/commit/2f72c70657129c16e6b0e413752a775c804f02f8 --- test/functional/legacy/062_tab_pages_spec.lua | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'test') diff --git a/test/functional/legacy/062_tab_pages_spec.lua b/test/functional/legacy/062_tab_pages_spec.lua index d5b10b160e..71a0a77354 100644 --- a/test/functional/legacy/062_tab_pages_spec.lua +++ b/test/functional/legacy/062_tab_pages_spec.lua @@ -99,10 +99,6 @@ describe('tab pages', function() eq(7, eval('tabpagenr()')) execute('tabmove') eq(10, eval('tabpagenr()')) - execute('tabmove -20') - eq(1, eval('tabpagenr()')) - execute('tabmove +20') - eq(10, eval('tabpagenr()')) execute('0tabmove') eq(1, eval('tabpagenr()')) execute('$tabmove') @@ -172,7 +168,7 @@ describe('tab pages', function() C tabnext 1 autocmd TabDestructive TabEnter * nested \ :C tabnext 2 | C tabclose 3 - C tabnext 3 + C tabnext 2 let g:r+=[tabpagenr().'/'.tabpagenr('$')] endfunction call Test() @@ -233,22 +229,14 @@ describe('tab pages', function() WinEnter TabEnter BufEnter - === tabnext 3 === - BufLeave - WinLeave - TabLeave - WinEnter - TabEnter === tabnext 2 === - BufLeave WinLeave TabLeave WinEnter TabEnter === tabnext 2 === === tabclose 3 === - BufEnter - === tabclose 3 === 2/2]]) + eq(2, eval("tabpagenr('$')")) end) end) -- cgit From b2b88423aa0087e5d4aaa122e63dffb97f85222f Mon Sep 17 00:00:00 2001 From: Matthew Malcomson Date: Mon, 27 Feb 2017 09:46:50 +0000 Subject: Robustly handle folds during a :move command In order to re-order marks according to the :move command, do_move() uses mark_adjust() in a non-standard manner. The non-standard action is that it moves some marks *past* other marks. This doesn't matter for marks, but mark_adjust() calls foldMarkAdjust() which simply changes fold starts and lengths and doesn't have enough information to know that other folds have to be checked and reordered. The array of folds for each window are assumed to be in order of increasing line number, and if this gets broken some folds can get "lost". There has been a previous patch to avoid this problem by deleting and recalculating all folds in the window, but this comes at the cost of closing all folds when executing :move, and doesn't cover the case of manual folds. This patch adds a new function foldMoveRange() specifically for the :move command that handles reordering folds as well as simply moving them. Additionally, we allow calling mark_adjust_nofold() that does the same as mark_adjust() but doesn't affect any fold array. Calling mark_adjust_nofold() should be done in the same manner as calling mark_adjust(), but according changes to the fold arrays must be done seperately by the calling function. vim-patch:8.0.0457 vim-patch:8.0.0459 vim-patch:8.0.0461 vim-patch:8.0.0465 --- test/functional/normal/fold_spec.lua | 186 +++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) (limited to 'test') diff --git a/test/functional/normal/fold_spec.lua b/test/functional/normal/fold_spec.lua index a2a2a35a8b..5584db20ba 100644 --- a/test/functional/normal/fold_spec.lua +++ b/test/functional/normal/fold_spec.lua @@ -5,9 +5,13 @@ local insert = helpers.insert local feed = helpers.feed local expect = helpers.expect local execute = helpers.execute +local funcs = helpers.funcs +local foldlevel, foldclosedend = funcs.foldlevel, funcs.foldclosedend +local eq = helpers.eq describe('Folds', function() clear() + before_each(function() execute('enew!') end) it('manual folding adjusts with filter', function() insert([[ 1 @@ -44,4 +48,186 @@ describe('Folds', function() 8 9]]) end) + describe('adjusting folds after :move', function() + local function manually_fold_indent() + -- setting foldmethod twice is a trick to get vim to set the folds for me + execute('set foldmethod=indent', 'set foldmethod=manual') + -- Ensure that all folds will get closed (makes it easier to test the + -- length of folds). + execute('set foldminlines=0') + -- Start with all folds open (so :move ranges aren't affected by closed + -- folds). + execute('%foldopen!') + end + + local function get_folds() + local rettab = {} + for i = 1, funcs.line('$') do + table.insert(rettab, foldlevel(i)) + end + return rettab + end + + local function test_move_indent(insert_string, move_command) + -- This test is easy because we just need to ensure that the resulting + -- fold is the same as calculated when creating folds from scratch. + insert(insert_string) + execute(move_command) + local after_move_folds = get_folds() + -- Doesn't change anything, but does call foldUpdateAll() + execute('set foldminlines=0') + eq(after_move_folds, get_folds()) + -- Set up the buffer with insert_string for the manual fold testing. + execute('enew!') + insert(insert_string) + manually_fold_indent() + execute(move_command) + end + + it('neither closes nor corrupts folds', function() + test_move_indent([[ +a + a + a + a + a + a +a + a + a + a + a + a +a + a + a + a + a + a]], '7,12m0') + expect([[ +a + a + a + a + a + a +a + a + a + a + a + a +a + a + a + a + a + a]]) + -- lines are not closed, folds are correct + for i = 1,funcs.line('$') do + eq(-1, funcs.foldclosed(i)) + if i == 1 or i == 7 or i == 13 then + eq(0, foldlevel(i)) + elseif i == 4 then + eq(2, foldlevel(i)) + else + eq(1, foldlevel(i)) + end + end + -- folds are not corrupted + feed('zM') + eq(6, foldclosedend(2)) + eq(12, foldclosedend(8)) + eq(18, foldclosedend(14)) + end) + it("doesn't split a fold when the move is within it", function() + test_move_indent([[ +a + a + a + a + a + a + a + a + a +a]], '5m6') + eq({0, 1, 1, 2, 2, 2, 2, 1, 1, 0}, get_folds()) + end) + it('truncates folds that end in the moved range', function() + test_move_indent([[ +a + a + a + a + a +a +a]], '4,5m6') + eq({0, 1, 2, 0, 0, 0, 0}, get_folds()) + end) + it('moves folds that start between moved range and destination', function() + test_move_indent([[ +a + a + a + a + a +a +a + a + a + a +a +a + a]], '3,4m$') + eq({0, 1, 1, 0, 0, 1, 2, 1, 0, 0, 1, 0, 0}, get_folds()) + end) + it('does not affect folds outside changed lines', function() + test_move_indent([[ + a + a + a +a +a +a + a + a + a]], '4m5') + eq({1, 1, 1, 0, 0, 0, 1, 1, 1}, get_folds()) + end) + it('moves and truncates folds that start in moved range', function() + test_move_indent([[ +a + a + a + a + a +a +a +a +a +a]], '1,3m7') + eq({0, 0, 0, 0, 0, 1, 2, 0, 0, 0}, get_folds()) + end) + it('breaks a fold when moving text into it', function() + test_move_indent([[ +a + a + a + a + a +a +a]], '$m4') + eq({0, 1, 2, 2, 0, 0, 0}, get_folds()) + end) + it('adjusts correctly when moving a range backwards', function() + test_move_indent([[ +a + a + a + a +a]], '2,3m0') + eq({1, 2, 0, 0, 0}, get_folds()) + end) + end) end) -- cgit From 43a99f77a82e3de980798383ae8a4134953ece06 Mon Sep 17 00:00:00 2001 From: Yichao Zhou Date: Sun, 26 Mar 2017 04:04:20 -0700 Subject: highlight: :match should override 'list' (#6343) Closes #4946 --- test/functional/ui/highlight_spec.lua | 39 ++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/functional/ui/highlight_spec.lua b/test/functional/ui/highlight_spec.lua index 945b16ef92..7a1b8c91e7 100644 --- a/test/functional/ui/highlight_spec.lua +++ b/test/functional/ui/highlight_spec.lua @@ -401,7 +401,7 @@ describe('guisp (special/undercurl)', function() end) end) -describe("'cursorline' with 'listchars'", function() +describe("'listchars' highlight", function() local screen before_each(function() @@ -644,4 +644,41 @@ describe("'cursorline' with 'listchars'", function() | ]]) end) + + it("'cursorline' with :match", function() + screen:set_default_attr_ids({ + [0] = {bold=true, foreground=Screen.colors.Blue}, + [1] = {background=Screen.colors.Grey90}, + [2] = {foreground=Screen.colors.Red}, + [3] = {foreground=Screen.colors.Green1}, + }) + execute('highlight clear ModeMsg') + execute('highlight SpecialKey guifg=#FF0000') + execute('highlight Error guifg=#00FF00') + execute('set nowrap') + feed('ia \t bc \t ') + screen:expect([[ + a bc ^ | + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]) + execute('set listchars=space:.,eol:¬,tab:>-,extends:>,precedes:<,trail:* list') + screen:expect([[ + a{2:.>-----.}bc{2:*>---*^*}{0:¬} | + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]) + execute('match Error /\\s\\+$/') + screen:expect([[ + a{2:.>-----.}bc{3:*>---*^*}{0:¬} | + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]) + end) end) -- cgit From f551df17f33e7f38b7e5693eb923118ca1542d27 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 10 Jul 2016 08:03:14 +0300 Subject: viml/executor: Directly generate typval_T values Note: this will *still* crash when using API in cases similar to the one described in first commit. Just it needs different code to reproduce. --- test/functional/lua_spec.lua | 143 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 test/functional/lua_spec.lua (limited to 'test') diff --git a/test/functional/lua_spec.lua b/test/functional/lua_spec.lua new file mode 100644 index 0000000000..fdfd9b4c2d --- /dev/null +++ b/test/functional/lua_spec.lua @@ -0,0 +1,143 @@ +local helpers = require('test.functional.helpers')(after_each) + +local eq = helpers.eq +local neq = helpers.neq +local NIL = helpers.NIL +local eval = helpers.eval +local clear = helpers.clear +local funcs = helpers.funcs +local meths = helpers.meths +local exc_exec = helpers.exc_exec +local curbufmeths = helpers.curbufmeths + +local function startswith(expected, actual) + eq(expected, actual:sub(1, #expected)) +end + +before_each(clear) + +describe('luaeval() function', function() + local nested_by_level = {} + local nested = {} + local nested_s = '{}' + for i=1,100 do + if i % 2 == 0 then + nested = {nested} + nested_s = '{' .. nested_s .. '}' + else + nested = {nested=nested} + nested_s = '{nested=' .. nested_s .. '}' + end + nested_by_level[i] = {o=nested, s=nested_s} + end + + it('correctly evaluates scalars', function() + eq(1, funcs.luaeval('1')) + eq(0, eval('type(luaeval("1"))')) + + eq(1.5, funcs.luaeval('1.5')) + eq(5, eval('type(luaeval("1.5"))')) + + eq("test", funcs.luaeval('"test"')) + eq(1, eval('type(luaeval("\'test\'"))')) + + eq('', funcs.luaeval('""')) + eq({_TYPE={}, _VAL={'\n'}}, funcs.luaeval([['\0']])) + eq({_TYPE={}, _VAL={'\n', '\n'}}, funcs.luaeval([['\0\n\0']])) + eq(1, eval([[luaeval('"\0\n\0"')._TYPE is v:msgpack_types.binary]])) + + eq(true, funcs.luaeval('true')) + eq(false, funcs.luaeval('false')) + eq(NIL, funcs.luaeval('nil')) + end) + + it('correctly evaluates containers', function() + eq({}, funcs.luaeval('{}')) + eq(3, eval('type(luaeval("{}"))')) + + eq({test=1, foo=2}, funcs.luaeval('{test=1, foo=2}')) + eq(4, eval('type(luaeval("{test=1, foo=2}"))')) + + eq({4, 2}, funcs.luaeval('{4, 2}')) + eq(3, eval('type(luaeval("{4, 2}"))')) + + local level = 30 + eq(nested_by_level[level].o, funcs.luaeval(nested_by_level[level].s)) + + eq({_TYPE={}, _VAL={{{_TYPE={}, _VAL={'\n', '\n'}}, {_TYPE={}, _VAL={'\n', '\n\n'}}}}}, + funcs.luaeval([[{['\0\n\0']='\0\n\0\0'}]])) + eq(1, eval([[luaeval('{["\0\n\0"]="\0\n\0\0"}')._TYPE is v:msgpack_types.map]])) + eq(1, eval([[luaeval('{["\0\n\0"]="\0\n\0\0"}')._VAL[0][0]._TYPE is v:msgpack_types.string]])) + eq(1, eval([[luaeval('{["\0\n\0"]="\0\n\0\0"}')._VAL[0][1]._TYPE is v:msgpack_types.binary]])) + eq({nested={{_TYPE={}, _VAL={{{_TYPE={}, _VAL={'\n', '\n'}}, {_TYPE={}, _VAL={'\n', '\n\n'}}}}}}}, + funcs.luaeval([[{nested={{['\0\n\0']='\0\n\0\0'}}}]])) + end) + + it('correctly passes scalars as argument', function() + eq(1, funcs.luaeval('_A', 1)) + eq(1.5, funcs.luaeval('_A', 1.5)) + eq('', funcs.luaeval('_A', '')) + eq('test', funcs.luaeval('_A', 'test')) + eq(NIL, funcs.luaeval('_A', NIL)) + eq(true, funcs.luaeval('_A', true)) + eq(false, funcs.luaeval('_A', false)) + end) + + it('correctly passes containers as argument', function() + eq({}, funcs.luaeval('_A', {})) + eq({test=1}, funcs.luaeval('_A', {test=1})) + eq({4, 2}, funcs.luaeval('_A', {4, 2})) + local level = 28 + eq(nested_by_level[level].o, funcs.luaeval('_A', nested_by_level[level].o)) + end) + + local function sp(typ, val) + return ('{"_TYPE": v:msgpack_types.%s, "_VAL": %s}'):format(typ, val) + end + local function mapsp(...) + local val = '' + for i=1,(select('#', ...)/2) do + val = ('%s[%s,%s],'):format(val, select(i * 2 - 1, ...), + select(i * 2, ...)) + end + return sp('map', '[' .. val .. ']') + end + local function luaevalarg(argexpr, expr) + return eval(([=[ + [ + extend(g:, {'_ret': luaeval(%s, %s)})._ret, + type(g:_ret)==type({})&&has_key(g:_ret, '_TYPE') + ? [ + get(keys(filter(copy(v:msgpack_types), 'v:val is g:_ret._TYPE')), 0, + g:_ret._TYPE), + get(g:_ret, '_VAL', g:_ret) + ] + : [0, g:_ret]][1] + ]=]):format(expr or '"_A"', argexpr):gsub('\n', '')) + end + + it('correctly passes special dictionaries', function() + eq({'binary', {'\n', '\n'}}, luaevalarg(sp('binary', '["\\n", "\\n"]'))) + eq({'binary', {'\n', '\n'}}, luaevalarg(sp('string', '["\\n", "\\n"]'))) + eq({0, true}, luaevalarg(sp('boolean', 1))) + eq({0, false}, luaevalarg(sp('boolean', 0))) + eq({0, NIL}, luaevalarg(sp('nil', 0))) + eq({0, {[""]=""}}, luaevalarg(mapsp(sp('binary', '[""]'), '""'))) + eq({0, {[""]=""}}, luaevalarg(mapsp(sp('string', '[""]'), '""'))) + end) + + it('issues an error in some cases', function() + eq("Vim(call):E5100: Cannot convert given lua table: table should either have a sequence of positive integer keys or contain only string keys", + exc_exec('call luaeval("{1, foo=2}")')) + eq("Vim(call):E5101: Cannot convert given lua type", + exc_exec('call luaeval("vim.api.buffer_get_line_slice")')) + startswith("Vim(call):E5107: Error while creating lua chunk for luaeval(): ", + exc_exec('call luaeval("1, 2, 3")')) + startswith("Vim(call):E5108: Error while calling lua chunk for luaeval(): ", + exc_exec('call luaeval("(nil)()")')) + + -- The following should not crash: conversion error happens inside + eq("Vim(call):E5101: Cannot convert given lua type", + exc_exec('call luaeval("vim.api")')) + end) +end) -- cgit From ed3115bd26047c9b125798d9cb56d09b155a243b Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 11 Jul 2016 20:42:27 +0300 Subject: executor: Make sure it works with API values --- test/functional/lua_spec.lua | 94 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/functional/lua_spec.lua b/test/functional/lua_spec.lua index fdfd9b4c2d..4f00189519 100644 --- a/test/functional/lua_spec.lua +++ b/test/functional/lua_spec.lua @@ -8,7 +8,7 @@ local clear = helpers.clear local funcs = helpers.funcs local meths = helpers.meths local exc_exec = helpers.exc_exec -local curbufmeths = helpers.curbufmeths +local redir_exec = helpers.redir_exec local function startswith(expected, actual) eq(expected, actual:sub(1, #expected)) @@ -139,5 +139,97 @@ describe('luaeval() function', function() -- The following should not crash: conversion error happens inside eq("Vim(call):E5101: Cannot convert given lua type", exc_exec('call luaeval("vim.api")')) + -- The following should not show internal error + eq("\nE5101: Cannot convert given lua type\n0", + redir_exec('echo luaeval("vim.api")')) end) + + it('correctly converts containers with type_idx', function() + eq(5, eval('type(luaeval("{[vim.type_idx]=vim.types.float, [vim.val_idx]=0}"))')) + eq(4, eval([[type(luaeval('{[vim.type_idx]=vim.types.dictionary}'))]])) + eq(3, eval([[type(luaeval('{[vim.type_idx]=vim.types.array}'))]])) + + eq({}, funcs.luaeval('{[vim.type_idx]=vim.types.array}')) + + -- Presence of type_idx makes Vim ignore some keys + eq({42}, funcs.luaeval('{[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}')) + eq({foo=2}, funcs.luaeval('{[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}')) + eq(10, funcs.luaeval('{[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}')) + + -- The following should not crash + eq({}, funcs.luaeval('{[vim.type_idx]=vim.types.dictionary}')) + end) + + it('correctly converts from API objects', function() + eq(1, funcs.luaeval('vim.api.vim_eval("1")')) + eq('1', funcs.luaeval([[vim.api.vim_eval('"1"')]])) + eq({}, funcs.luaeval('vim.api.vim_eval("[]")')) + eq({}, funcs.luaeval('vim.api.vim_eval("{}")')) + eq(1, funcs.luaeval('vim.api.vim_eval("1.0")')) + eq(true, funcs.luaeval('vim.api.vim_eval("v:true")')) + eq(false, funcs.luaeval('vim.api.vim_eval("v:false")')) + eq(NIL, funcs.luaeval('vim.api.vim_eval("v:null")')) + + eq(0, eval([[type(luaeval('vim.api.vim_eval("1")'))]])) + eq(1, eval([[type(luaeval('vim.api.vim_eval("''1''")'))]])) + eq(3, eval([[type(luaeval('vim.api.vim_eval("[]")'))]])) + eq(4, eval([[type(luaeval('vim.api.vim_eval("{}")'))]])) + eq(5, eval([[type(luaeval('vim.api.vim_eval("1.0")'))]])) + eq(6, eval([[type(luaeval('vim.api.vim_eval("v:true")'))]])) + eq(6, eval([[type(luaeval('vim.api.vim_eval("v:false")'))]])) + eq(7, eval([[type(luaeval('vim.api.vim_eval("v:null")'))]])) + + eq({foo=42}, funcs.luaeval([[vim.api.vim_eval('{"foo": 42}')]])) + eq({42}, funcs.luaeval([[vim.api.vim_eval('[42]')]])) + + eq({foo={bar=42}, baz=50}, funcs.luaeval([[vim.api.vim_eval('{"foo": {"bar": 42}, "baz": 50}')]])) + eq({{42}, {}}, funcs.luaeval([=[vim.api.vim_eval('[[42], []]')]=])) + end) + + it('correctly converts to API objects', function() + eq(1, funcs.luaeval('vim.api._vim_id(1)')) + eq('1', funcs.luaeval('vim.api._vim_id("1")')) + eq({1}, funcs.luaeval('vim.api._vim_id({1})')) + eq({foo=1}, funcs.luaeval('vim.api._vim_id({foo=1})')) + eq(1.5, funcs.luaeval('vim.api._vim_id(1.5)')) + eq(true, funcs.luaeval('vim.api._vim_id(true)')) + eq(false, funcs.luaeval('vim.api._vim_id(false)')) + eq(NIL, funcs.luaeval('vim.api._vim_id(nil)')) + + eq(0, eval([[type(luaeval('vim.api._vim_id(1)'))]])) + eq(1, eval([[type(luaeval('vim.api._vim_id("1")'))]])) + eq(3, eval([[type(luaeval('vim.api._vim_id({1})'))]])) + eq(4, eval([[type(luaeval('vim.api._vim_id({foo=1})'))]])) + eq(5, eval([[type(luaeval('vim.api._vim_id(1.5)'))]])) + eq(6, eval([[type(luaeval('vim.api._vim_id(true)'))]])) + eq(6, eval([[type(luaeval('vim.api._vim_id(false)'))]])) + eq(7, eval([[type(luaeval('vim.api._vim_id(nil)'))]])) + + eq({foo=1, bar={42, {{baz=true}, 5}}}, funcs.luaeval('vim.api._vim_id({foo=1, bar={42, {{baz=true}, 5}}})')) + end) + + it('correctly converts containers with type_idx to API objects', function() + -- TODO: Similar tests with _vim_array_id and _vim_dictionary_id, that will + -- follow slightly different code paths. + eq(5, eval('type(luaeval("vim.api._vim_id({[vim.type_idx]=vim.types.float, [vim.val_idx]=0})"))')) + eq(4, eval([[type(luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.dictionary})'))]])) + eq(3, eval([[type(luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.array})'))]])) + + eq({}, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.array})')) + + -- Presence of type_idx makes Vim ignore some keys + -- FIXME + -- eq({42}, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) + eq({foo=2}, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) + eq(10, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) + end) + -- TODO: check what happens when it errors out on second list item +--[[FIXME + [ + [ it('correctly converts self-containing containers', function() + [ meths.set_var('l', {}) + [ eval('add(l, l)') + [ eq(true, eval('luaeval("_A == _A[1]", l)')) + [ end) + ]] end) -- cgit From 3fa4ca81880bc5113c32a89de965ce593e9b001f Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 12 Jul 2016 19:04:12 +0300 Subject: executor/converter: Fix conversion of self-containing containers --- test/functional/lua_spec.lua | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/functional/lua_spec.lua b/test/functional/lua_spec.lua index 4f00189519..5c6dee90a3 100644 --- a/test/functional/lua_spec.lua +++ b/test/functional/lua_spec.lua @@ -224,12 +224,23 @@ describe('luaeval() function', function() eq(10, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) end) -- TODO: check what happens when it errors out on second list item ---[[FIXME - [ - [ it('correctly converts self-containing containers', function() - [ meths.set_var('l', {}) - [ eval('add(l, l)') - [ eq(true, eval('luaeval("_A == _A[1]", l)')) - [ end) - ]] + -- TODO: check what happens if API function receives wrong number of + -- arguments. + -- TODO: check what happens if API function receives wrong argument types. + + it('correctly converts self-containing containers', function() + meths.set_var('l', {}) + eval('add(l, l)') + eq(true, eval('luaeval("_A == _A[1]", l)')) + eq(true, eval('luaeval("_A[1] == _A[1][1]", [l])')) + eq(true, eval('luaeval("_A.d == _A.d[1]", {"d": l})')) + eq(true, eval('luaeval("_A ~= _A[1]", [l])')) + + meths.set_var('d', {foo=42}) + eval('extend(d, {"d": d})') + eq(true, eval('luaeval("_A == _A.d", d)')) + eq(true, eval('luaeval("_A[1] == _A[1].d", [d])')) + eq(true, eval('luaeval("_A.d == _A.d.d", {"d": d})')) + eq(true, eval('luaeval("_A ~= _A.d", {"d": d})')) + end) end) -- cgit From 9297d941e2f1576006d77bfd6391cecc3bea37b0 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 12 Jul 2016 19:20:57 +0300 Subject: executor/converter: Fix how maxidx is determined --- test/functional/lua_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/functional/lua_spec.lua b/test/functional/lua_spec.lua index 5c6dee90a3..e16f41dba2 100644 --- a/test/functional/lua_spec.lua +++ b/test/functional/lua_spec.lua @@ -218,10 +218,10 @@ describe('luaeval() function', function() eq({}, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.array})')) -- Presence of type_idx makes Vim ignore some keys - -- FIXME - -- eq({42}, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) + eq({42}, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) eq({foo=2}, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) eq(10, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) + eq({}, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})')) end) -- TODO: check what happens when it errors out on second list item -- TODO: check what happens if API function receives wrong number of -- cgit From 425d348f0f9f680a44af31fc3cecd20a07374bb5 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 16 Jul 2016 00:34:24 +0300 Subject: executor/converter: Make nlua_pop_Object not recursive --- test/functional/lua_spec.lua | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/functional/lua_spec.lua b/test/functional/lua_spec.lua index e16f41dba2..bd1ed51c2d 100644 --- a/test/functional/lua_spec.lua +++ b/test/functional/lua_spec.lua @@ -31,6 +31,9 @@ describe('luaeval() function', function() nested_by_level[i] = {o=nested, s=nested_s} end + -- Not checked: funcrefs converted to NIL. To be altered to something more + -- meaningful later. + it('correctly evaluates scalars', function() eq(1, funcs.luaeval('1')) eq(0, eval('type(luaeval("1"))')) @@ -135,6 +138,10 @@ describe('luaeval() function', function() exc_exec('call luaeval("1, 2, 3")')) startswith("Vim(call):E5108: Error while calling lua chunk for luaeval(): ", exc_exec('call luaeval("(nil)()")')) + eq("Vim(call):E5101: Cannot convert given lua type", + exc_exec('call luaeval("{42, vim.api}")')) + eq("Vim(call):E5101: Cannot convert given lua type", + exc_exec('call luaeval("{foo=42, baz=vim.api}")')) -- The following should not crash: conversion error happens inside eq("Vim(call):E5101: Cannot convert given lua type", @@ -208,9 +215,7 @@ describe('luaeval() function', function() eq({foo=1, bar={42, {{baz=true}, 5}}}, funcs.luaeval('vim.api._vim_id({foo=1, bar={42, {{baz=true}, 5}}})')) end) - it('correctly converts containers with type_idx to API objects', function() - -- TODO: Similar tests with _vim_array_id and _vim_dictionary_id, that will - -- follow slightly different code paths. + it('correctly converts container objects with type_idx to API objects', function() eq(5, eval('type(luaeval("vim.api._vim_id({[vim.type_idx]=vim.types.float, [vim.val_idx]=0})"))')) eq(4, eval([[type(luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.dictionary})'))]])) eq(3, eval([[type(luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.array})'))]])) @@ -223,10 +228,18 @@ describe('luaeval() function', function() eq(10, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) eq({}, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})')) end) - -- TODO: check what happens when it errors out on second list item - -- TODO: check what happens if API function receives wrong number of - -- arguments. - -- TODO: check what happens if API function receives wrong argument types. + + it('correctly converts arrays with type_idx to API objects', function() + eq(3, eval([[type(luaeval('vim.api._vim_id_array({[vim.type_idx]=vim.types.array})'))]])) + + eq({}, funcs.luaeval('vim.api._vim_id_array({[vim.type_idx]=vim.types.array})')) + + -- Presence of type_idx makes Vim ignore some keys + eq({42}, funcs.luaeval('vim.api._vim_id_array({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) + eq({{foo=2}}, funcs.luaeval('vim.api._vim_id_array({{[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) + eq({10}, funcs.luaeval('vim.api._vim_id_array({{[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) + eq({}, funcs.luaeval('vim.api._vim_id_array({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})')) + end) it('correctly converts self-containing containers', function() meths.set_var('l', {}) @@ -243,4 +256,14 @@ describe('luaeval() function', function() eq(true, eval('luaeval("_A.d == _A.d.d", {"d": d})')) eq(true, eval('luaeval("_A ~= _A.d", {"d": d})')) end) + + it('errors out correctly when working with API', function() + eq(0, exc_exec([[call luaeval("vim.api.id")]])) + end) + + -- TODO: check buffer/window/etc. + -- TODO: check what happens when it errors out on second list item + -- TODO: check what happens if API function receives wrong number of + -- arguments. + -- TODO: check what happens if API function receives wrong argument types. end) -- cgit From 7a013e93e0364f78a2bc04eadaaeeaa689d0258a Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 16 Jul 2016 00:48:25 +0300 Subject: executor/converter: Make it possible to supply `{}` to Dictionary arg --- test/functional/lua_spec.lua | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/functional/lua_spec.lua b/test/functional/lua_spec.lua index bd1ed51c2d..082efe4c0e 100644 --- a/test/functional/lua_spec.lua +++ b/test/functional/lua_spec.lua @@ -234,11 +234,29 @@ describe('luaeval() function', function() eq({}, funcs.luaeval('vim.api._vim_id_array({[vim.type_idx]=vim.types.array})')) - -- Presence of type_idx makes Vim ignore some keys eq({42}, funcs.luaeval('vim.api._vim_id_array({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) eq({{foo=2}}, funcs.luaeval('vim.api._vim_id_array({{[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) eq({10}, funcs.luaeval('vim.api._vim_id_array({{[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) eq({}, funcs.luaeval('vim.api._vim_id_array({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})')) + + eq({}, funcs.luaeval('vim.api._vim_id_array({})')) + eq(3, eval([[type(luaeval('vim.api._vim_id_array({})'))]])) + end) + + it('correctly converts dictionaries with type_idx to API objects', function() + eq(4, eval([[type(luaeval('vim.api._vim_id_dictionary({[vim.type_idx]=vim.types.dictionary})'))]])) + + eq({}, funcs.luaeval('vim.api._vim_id_dictionary({[vim.type_idx]=vim.types.dictionary})')) + + eq({v={42}}, funcs.luaeval('vim.api._vim_id_dictionary({v={[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) + eq({foo=2}, funcs.luaeval('vim.api._vim_id_dictionary({[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) + eq({v=10}, funcs.luaeval('vim.api._vim_id_dictionary({v={[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) + eq({v={}}, funcs.luaeval('vim.api._vim_id_dictionary({v={[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2}})')) + + -- If API requests dictionary, then empty table will be the one. This is not + -- the case normally because empty table is an empty arrray. + eq({}, funcs.luaeval('vim.api._vim_id_dictionary({})')) + eq(4, eval([[type(luaeval('vim.api._vim_id_dictionary({})'))]])) end) it('correctly converts self-containing containers', function() -- cgit From ba2f615cd40d5d809d1a141c7b098e3bd22ff7bb Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 16 Jul 2016 02:26:04 +0300 Subject: functests: Test for error conditions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit During testing found the following bugs: 1. msgpack-gen.lua script is completely unprepared for Float values either in return type or in arguments. Specifically: 1. At the time of writing relevant code FLOAT_OBJ did not exist as well as FLOATING_OBJ, but it would be used by msgpack-gen.lua should return type be Float. I added FLOATING_OBJ macros later because did not know that msgpack-gen.lua uses these _OBJ macros, otherwise it would be FLOAT_OBJ. 2. msgpack-gen.lua should use .data.floating in place of .data.float. But it did not expect that .data subattribute may have name different from lowercased type name. 2. vim_replace_termcodes returned its argument as-is if it receives an empty string (as well as _vim_id*() functions did). But if something in returned argument lives in an allocated memory such action will cause double free: once when freeing arguments, then when freeing return value. It did not cause problems yet because msgpack bindings return empty string as {NULL, 0} and nothing was actually allocated. 3. New code in msgpack-gen.lua popped arguments in reversed order, making lua bindings’ signatures be different from API ones. --- test/functional/api/vim_spec.lua | 11 +++++++++ test/functional/lua_spec.lua | 51 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 3348368a36..24ed0afe67 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -219,6 +219,17 @@ describe('api', function() eq('\128\253\44', helpers.nvim('replace_termcodes', '', true, true, true)) end) + + it('does not crash when transforming an empty string', function() + -- Actually does not test anything, because current code will use NULL for + -- an empty string. + -- + -- Problem here is that if String argument has .data in allocated memory + -- then `return str` in vim_replace_termcodes body will make Neovim free + -- `str.data` twice: once when freeing arguments, then when freeing return + -- value. + eq('', meths.replace_termcodes('', true, true, true)) + end) end) describe('nvim_feedkeys', function() diff --git a/test/functional/lua_spec.lua b/test/functional/lua_spec.lua index 082efe4c0e..8ca47718aa 100644 --- a/test/functional/lua_spec.lua +++ b/test/functional/lua_spec.lua @@ -276,12 +276,53 @@ describe('luaeval() function', function() end) it('errors out correctly when working with API', function() - eq(0, exc_exec([[call luaeval("vim.api.id")]])) + -- Conversion errors + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Cannot convert given lua type', + exc_exec([[call luaeval("vim.api._vim_id(vim.api._vim_id)")]])) + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Cannot convert given lua table', + exc_exec([[call luaeval("vim.api._vim_id({1, foo=42})")]])) + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Cannot convert given lua type', + exc_exec([[call luaeval("vim.api._vim_id({42, vim.api._vim_id})")]])) + -- Errors in number of arguments + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected 1 argument', + exc_exec([[call luaeval("vim.api._vim_id()")]])) + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected 1 argument', + exc_exec([[call luaeval("vim.api._vim_id(1, 2)")]])) + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected 2 arguments', + exc_exec([[call luaeval("vim.api.vim_set_var(1, 2, 3)")]])) + -- Error in argument types + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected lua string', + exc_exec([[call luaeval("vim.api.vim_set_var(1, 2)")]])) + + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected lua number', + exc_exec([[call luaeval("vim.api.buffer_get_line(0, 'test')")]])) + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Number is not integral', + exc_exec([[call luaeval("vim.api.buffer_get_line(0, 1.5)")]])) + + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected lua table', + exc_exec([[call luaeval("vim.api._vim_id_float('test')")]])) + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Unexpected type', + exc_exec([[call luaeval("vim.api._vim_id_float({[vim.type_idx]=vim.types.dictionary})")]])) + + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected lua table', + exc_exec([[call luaeval("vim.api._vim_id_array(1)")]])) + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Unexpected type', + exc_exec([[call luaeval("vim.api._vim_id_array({[vim.type_idx]=vim.types.dictionary})")]])) + + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected lua table', + exc_exec([[call luaeval("vim.api._vim_id_dictionary(1)")]])) + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Unexpected type', + exc_exec([[call luaeval("vim.api._vim_id_dictionary({[vim.type_idx]=vim.types.array})")]])) + -- TODO: check for errors with Tabpage argument + -- TODO: check for errors with Window argument + -- TODO: check for errors with Buffer argument + end) + + it('accepts any value as API Boolean', function() + eq('', funcs.luaeval('vim.api.vim_replace_termcodes("", vim, false, nil)')) + eq('', funcs.luaeval('vim.api.vim_replace_termcodes("", 0, 1.5, "test")')) + eq('', funcs.luaeval('vim.api.vim_replace_termcodes("", true, {}, {[vim.type_idx]=vim.types.array})')) end) -- TODO: check buffer/window/etc. - -- TODO: check what happens when it errors out on second list item - -- TODO: check what happens if API function receives wrong number of - -- arguments. - -- TODO: check what happens if API function receives wrong argument types. end) -- cgit From a3ea05c1e5965ca23b1b926c41b00597e9d0211c Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 21 Jan 2017 00:00:47 +0300 Subject: functests: Add some tests --- test/functional/lua/api_spec.lua | 36 ++++++++++++++++++++ test/functional/lua/commands_spec.lua | 4 +++ test/functional/lua/luaeval_spec.lua | 63 +++++++++++++++++++++++++++++++++++ test/helpers.lua | 9 +++++ 4 files changed, 112 insertions(+) create mode 100644 test/functional/lua/api_spec.lua create mode 100644 test/functional/lua/commands_spec.lua create mode 100644 test/functional/lua/luaeval_spec.lua (limited to 'test') diff --git a/test/functional/lua/api_spec.lua b/test/functional/lua/api_spec.lua new file mode 100644 index 0000000000..6652c60adb --- /dev/null +++ b/test/functional/lua/api_spec.lua @@ -0,0 +1,36 @@ +-- Test suite for testing interactions with API bindings +local helpers = require('test.functional.helpers')(after_each) + +local funcs = helpers.funcs +local clear = helpers.clear +local NIL = helpers.NIL +local eq = helpers.eq + +before_each(clear) + +describe('luaeval(vim.api.…)', function() + describe('with channel_id and buffer handle', function() + describe('nvim_buf_get_lines', function() + it('works', function() + funcs.setline(1, {"abc", "def", "a\nb", "ttt"}) + eq({{_TYPE={}, _VAL={'a\nb'}}}, + funcs.luaeval('vim.api.nvim_buf_get_lines(1, 2, 3, false)')) + end) + end) + describe('nvim_buf_set_lines', function() + it('works', function() + funcs.setline(1, {"abc", "def", "a\nb", "ttt"}) + eq(NIL, funcs.luaeval('vim.api.nvim_buf_set_lines(1, 1, 2, false, {"b\\0a"})')) + eq({'abc', {_TYPE={}, _VAL={'b\na'}}, {_TYPE={}, _VAL={'a\nb'}}, 'ttt'}, + funcs.luaeval('vim.api.nvim_buf_get_lines(1, 0, 4, false)')) + end) + end) + end) + describe('with errors', function() + it('transforms API errors into lua errors', function() + funcs.setline(1, {"abc", "def", "a\nb", "ttt"}) + eq({false, 'string cannot contain newlines'}, + funcs.luaeval('{pcall(vim.api.nvim_buf_set_lines, 1, 1, 2, false, {"b\\na"})}')) + end) + end) +end) diff --git a/test/functional/lua/commands_spec.lua b/test/functional/lua/commands_spec.lua new file mode 100644 index 0000000000..191504bfaa --- /dev/null +++ b/test/functional/lua/commands_spec.lua @@ -0,0 +1,4 @@ +-- Test suite for checking :lua* commands +local helpers = require('test.functional.helpers')(after_each) + +local eq = helpers.eq diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua new file mode 100644 index 0000000000..5b7f365ef3 --- /dev/null +++ b/test/functional/lua/luaeval_spec.lua @@ -0,0 +1,63 @@ +-- Test suite for testing luaeval() function +local helpers = require('test.functional.helpers')(after_each) + +local command = helpers.command +local meths = helpers.meths +local funcs = helpers.funcs +local clear = helpers.clear +local NIL = helpers.NIL +local eq = helpers.eq + +before_each(clear) + +describe('luaeval()', function() + describe('second argument', function() + it('is successfully received', function() + local t = {t=true, f=false, --[[n=NIL,]] d={l={'string', 42, 0.42}}} + eq(t, funcs.luaeval("_A", t)) + -- Not tested: nil, funcrefs, returned object identity: behaviour will + -- most likely change. + end) + end) + describe('lua values', function() + it('are successfully transformed', function() + eq({n=1, f=1.5, s='string', l={4, 2}}, + funcs.luaeval('{n=1, f=1.5, s="string", l={4, 2}}')) + -- Not tested: nil inside containers: behaviour will most likely change. + eq(NIL, funcs.luaeval('nil')) + end) + end) + describe('recursive lua values', function() + it('are successfully transformed', function() + funcs.luaeval('rawset(_G, "d", {})') + funcs.luaeval('rawset(d, "d", d)') + eq('\n{\'d\': {...@0}}', funcs.execute('echo luaeval("d")')) + + funcs.luaeval('rawset(_G, "l", {})') + funcs.luaeval('table.insert(l, l)') + eq('\n[[...@0]]', funcs.execute('echo luaeval("l")')) + end) + end) + describe('strings', function() + it('are successfully converted to special dictionaries', function() + command([[let s = luaeval('"\0"')]]) + eq({_TYPE={}, _VAL={'\n'}}, meths.get_var('s')) + eq(1, funcs.eval('s._TYPE is v:msgpack_types.binary')) + end) + it('are successfully converted to special dictionaries in table keys', + function() + command([[let d = luaeval('{["\0"]=1}')]]) + eq({_TYPE={}, _VAL={{{_TYPE={}, _VAL={'\n'}}, 1}}}, meths.get_var('d')) + eq(1, funcs.eval('d._TYPE is v:msgpack_types.map')) + eq(1, funcs.eval('d._VAL[0][0]._TYPE is v:msgpack_types.string')) + end) + it('are successfully converted to special dictionaries from a list', + function() + command([[let l = luaeval('{"abc", "a\0b", "c\0d", "def"}')]]) + eq({'abc', {_TYPE={}, _VAL={'a\nb'}}, {_TYPE={}, _VAL={'c\nd'}}, 'def'}, + meths.get_var('l')) + eq(1, funcs.eval('l[1]._TYPE is v:msgpack_types.binary')) + eq(1, funcs.eval('l[2]._TYPE is v:msgpack_types.binary')) + end) + end) +end) diff --git a/test/helpers.lua b/test/helpers.lua index e5224349c2..18f47e950b 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -225,6 +225,14 @@ local function which(exe) end end +local function shallowcopy(orig) + local copy = {} + for orig_key, orig_value in pairs(orig) do + copy[orig_key] = orig_value + end + return copy +end + return { eq = eq, neq = neq, @@ -238,4 +246,5 @@ return { check_cores = check_cores, hasenv = hasenv, which = which, + shallowcopy = shallowcopy, } -- cgit From bca9c2f3c4af9c132439bbfeaed028ac3171db48 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 21 Jan 2017 01:10:44 +0300 Subject: functests: Move existing tests from lua_spec to lua/*, fix them --- test/functional/lua/api_spec.lua | 143 +++++++++++++++ test/functional/lua/luaeval_spec.lua | 181 +++++++++++++++++++ test/functional/lua_spec.lua | 328 ----------------------------------- 3 files changed, 324 insertions(+), 328 deletions(-) delete mode 100644 test/functional/lua_spec.lua (limited to 'test') diff --git a/test/functional/lua/api_spec.lua b/test/functional/lua/api_spec.lua index 6652c60adb..31c855c2c1 100644 --- a/test/functional/lua/api_spec.lua +++ b/test/functional/lua/api_spec.lua @@ -1,8 +1,10 @@ -- Test suite for testing interactions with API bindings local helpers = require('test.functional.helpers')(after_each) +local exc_exec = helpers.exc_exec local funcs = helpers.funcs local clear = helpers.clear +local eval = helpers.eval local NIL = helpers.NIL local eq = helpers.eq @@ -33,4 +35,145 @@ describe('luaeval(vim.api.…)', function() funcs.luaeval('{pcall(vim.api.nvim_buf_set_lines, 1, 1, 2, false, {"b\\na"})}')) end) end) + + it('correctly converts from API objects', function() + eq(1, funcs.luaeval('vim.api.nvim_eval("1")')) + eq('1', funcs.luaeval([[vim.api.nvim_eval('"1"')]])) + eq({}, funcs.luaeval('vim.api.nvim_eval("[]")')) + eq({}, funcs.luaeval('vim.api.nvim_eval("{}")')) + eq(1, funcs.luaeval('vim.api.nvim_eval("1.0")')) + eq(true, funcs.luaeval('vim.api.nvim_eval("v:true")')) + eq(false, funcs.luaeval('vim.api.nvim_eval("v:false")')) + eq(NIL, funcs.luaeval('vim.api.nvim_eval("v:null")')) + + eq(0, eval([[type(luaeval('vim.api.nvim_eval("1")'))]])) + eq(1, eval([[type(luaeval('vim.api.nvim_eval("''1''")'))]])) + eq(3, eval([[type(luaeval('vim.api.nvim_eval("[]")'))]])) + eq(4, eval([[type(luaeval('vim.api.nvim_eval("{}")'))]])) + eq(5, eval([[type(luaeval('vim.api.nvim_eval("1.0")'))]])) + eq(6, eval([[type(luaeval('vim.api.nvim_eval("v:true")'))]])) + eq(6, eval([[type(luaeval('vim.api.nvim_eval("v:false")'))]])) + eq(7, eval([[type(luaeval('vim.api.nvim_eval("v:null")'))]])) + + eq({foo=42}, funcs.luaeval([[vim.api.nvim_eval('{"foo": 42}')]])) + eq({42}, funcs.luaeval([[vim.api.nvim_eval('[42]')]])) + + eq({foo={bar=42}, baz=50}, funcs.luaeval([[vim.api.nvim_eval('{"foo": {"bar": 42}, "baz": 50}')]])) + eq({{42}, {}}, funcs.luaeval([=[vim.api.nvim_eval('[[42], []]')]=])) + end) + + it('correctly converts to API objects', function() + eq(1, funcs.luaeval('vim.api._vim_id(1)')) + eq('1', funcs.luaeval('vim.api._vim_id("1")')) + eq({1}, funcs.luaeval('vim.api._vim_id({1})')) + eq({foo=1}, funcs.luaeval('vim.api._vim_id({foo=1})')) + eq(1.5, funcs.luaeval('vim.api._vim_id(1.5)')) + eq(true, funcs.luaeval('vim.api._vim_id(true)')) + eq(false, funcs.luaeval('vim.api._vim_id(false)')) + eq(NIL, funcs.luaeval('vim.api._vim_id(nil)')) + + eq(0, eval([[type(luaeval('vim.api._vim_id(1)'))]])) + eq(1, eval([[type(luaeval('vim.api._vim_id("1")'))]])) + eq(3, eval([[type(luaeval('vim.api._vim_id({1})'))]])) + eq(4, eval([[type(luaeval('vim.api._vim_id({foo=1})'))]])) + eq(5, eval([[type(luaeval('vim.api._vim_id(1.5)'))]])) + eq(6, eval([[type(luaeval('vim.api._vim_id(true)'))]])) + eq(6, eval([[type(luaeval('vim.api._vim_id(false)'))]])) + eq(7, eval([[type(luaeval('vim.api._vim_id(nil)'))]])) + + eq({foo=1, bar={42, {{baz=true}, 5}}}, funcs.luaeval('vim.api._vim_id({foo=1, bar={42, {{baz=true}, 5}}})')) + end) + + it('correctly converts container objects with type_idx to API objects', function() + eq(5, eval('type(luaeval("vim.api._vim_id({[vim.type_idx]=vim.types.float, [vim.val_idx]=0})"))')) + eq(4, eval([[type(luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.dictionary})'))]])) + eq(3, eval([[type(luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.array})'))]])) + + eq({}, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.array})')) + + -- Presence of type_idx makes Vim ignore some keys + eq({42}, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) + eq({foo=2}, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) + eq(10, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) + eq({}, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})')) + end) + + it('correctly converts arrays with type_idx to API objects', function() + eq(3, eval([[type(luaeval('vim.api._vim_id_array({[vim.type_idx]=vim.types.array})'))]])) + + eq({}, funcs.luaeval('vim.api._vim_id_array({[vim.type_idx]=vim.types.array})')) + + eq({42}, funcs.luaeval('vim.api._vim_id_array({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) + eq({{foo=2}}, funcs.luaeval('vim.api._vim_id_array({{[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) + eq({10}, funcs.luaeval('vim.api._vim_id_array({{[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) + eq({}, funcs.luaeval('vim.api._vim_id_array({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})')) + + eq({}, funcs.luaeval('vim.api._vim_id_array({})')) + eq(3, eval([[type(luaeval('vim.api._vim_id_array({})'))]])) + end) + + it('correctly converts dictionaries with type_idx to API objects', function() + eq(4, eval([[type(luaeval('vim.api._vim_id_dictionary({[vim.type_idx]=vim.types.dictionary})'))]])) + + eq({}, funcs.luaeval('vim.api._vim_id_dictionary({[vim.type_idx]=vim.types.dictionary})')) + + eq({v={42}}, funcs.luaeval('vim.api._vim_id_dictionary({v={[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) + eq({foo=2}, funcs.luaeval('vim.api._vim_id_dictionary({[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) + eq({v=10}, funcs.luaeval('vim.api._vim_id_dictionary({v={[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) + eq({v={}}, funcs.luaeval('vim.api._vim_id_dictionary({v={[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2}})')) + + -- If API requests dictionary, then empty table will be the one. This is not + -- the case normally because empty table is an empty arrray. + eq({}, funcs.luaeval('vim.api._vim_id_dictionary({})')) + eq(4, eval([[type(luaeval('vim.api._vim_id_dictionary({})'))]])) + end) + + it('errors out correctly when working with API', function() + -- Conversion errors + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Cannot convert given lua type', + exc_exec([[call luaeval("vim.api._vim_id(vim.api._vim_id)")]])) + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Cannot convert given lua table', + exc_exec([[call luaeval("vim.api._vim_id({1, foo=42})")]])) + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Cannot convert given lua type', + exc_exec([[call luaeval("vim.api._vim_id({42, vim.api._vim_id})")]])) + -- Errors in number of arguments + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Expected 1 argument', + exc_exec([[call luaeval("vim.api._vim_id()")]])) + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Expected 1 argument', + exc_exec([[call luaeval("vim.api._vim_id(1, 2)")]])) + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Expected 2 arguments', + exc_exec([[call luaeval("vim.api.nvim_set_var(1, 2, 3)")]])) + -- Error in argument types + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Expected lua string', + exc_exec([[call luaeval("vim.api.nvim_set_var(1, 2)")]])) + + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Expected lua number', + exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 'test', 1, false)")]])) + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Number is not integral', + exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 1.5, 1, false)")]])) + + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Expected lua table', + exc_exec([[call luaeval("vim.api._vim_id_float('test')")]])) + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Unexpected type', + exc_exec([[call luaeval("vim.api._vim_id_float({[vim.type_idx]=vim.types.dictionary})")]])) + + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Expected lua table', + exc_exec([[call luaeval("vim.api._vim_id_array(1)")]])) + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Unexpected type', + exc_exec([[call luaeval("vim.api._vim_id_array({[vim.type_idx]=vim.types.dictionary})")]])) + + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Expected lua table', + exc_exec([[call luaeval("vim.api._vim_id_dictionary(1)")]])) + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Unexpected type', + exc_exec([[call luaeval("vim.api._vim_id_dictionary({[vim.type_idx]=vim.types.array})")]])) + -- TODO: check for errors with Tabpage argument + -- TODO: check for errors with Window argument + -- TODO: check for errors with Buffer argument + end) + + it('accepts any value as API Boolean', function() + eq('', funcs.luaeval('vim.api.nvim_replace_termcodes("", vim, false, nil)')) + eq('', funcs.luaeval('vim.api.nvim_replace_termcodes("", 0, 1.5, "test")')) + eq('', funcs.luaeval('vim.api.nvim_replace_termcodes("", true, {}, {[vim.type_idx]=vim.types.array})')) + end) end) diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua index 5b7f365ef3..345848cfff 100644 --- a/test/functional/lua/luaeval_spec.lua +++ b/test/functional/lua/luaeval_spec.lua @@ -1,16 +1,37 @@ -- Test suite for testing luaeval() function local helpers = require('test.functional.helpers')(after_each) +local redir_exec = helpers.redir_exec +local exc_exec = helpers.exc_exec local command = helpers.command local meths = helpers.meths local funcs = helpers.funcs local clear = helpers.clear +local eval = helpers.eval local NIL = helpers.NIL local eq = helpers.eq before_each(clear) +local function startswith(expected, actual) + eq(expected, actual:sub(1, #expected)) +end + describe('luaeval()', function() + local nested_by_level = {} + local nested = {} + local nested_s = '{}' + for i=1,100 do + if i % 2 == 0 then + nested = {nested} + nested_s = '{' .. nested_s .. '}' + else + nested = {nested=nested} + nested_s = '{nested=' .. nested_s .. '}' + end + nested_by_level[i] = {o=nested, s=nested_s} + end + describe('second argument', function() it('is successfully received', function() local t = {t=true, f=false, --[[n=NIL,]] d={l={'string', 42, 0.42}}} @@ -60,4 +81,164 @@ describe('luaeval()', function() eq(1, funcs.eval('l[2]._TYPE is v:msgpack_types.binary')) end) end) + + -- Not checked: funcrefs converted to NIL. To be altered to something more + -- meaningful later. + + it('correctly evaluates scalars', function() + eq(1, funcs.luaeval('1')) + eq(0, eval('type(luaeval("1"))')) + + eq(1.5, funcs.luaeval('1.5')) + eq(5, eval('type(luaeval("1.5"))')) + + eq("test", funcs.luaeval('"test"')) + eq(1, eval('type(luaeval("\'test\'"))')) + + eq('', funcs.luaeval('""')) + eq({_TYPE={}, _VAL={'\n'}}, funcs.luaeval([['\0']])) + eq({_TYPE={}, _VAL={'\n', '\n'}}, funcs.luaeval([['\0\n\0']])) + eq(1, eval([[luaeval('"\0\n\0"')._TYPE is v:msgpack_types.binary]])) + + eq(true, funcs.luaeval('true')) + eq(false, funcs.luaeval('false')) + eq(NIL, funcs.luaeval('nil')) + end) + + it('correctly evaluates containers', function() + eq({}, funcs.luaeval('{}')) + eq(3, eval('type(luaeval("{}"))')) + + eq({test=1, foo=2}, funcs.luaeval('{test=1, foo=2}')) + eq(4, eval('type(luaeval("{test=1, foo=2}"))')) + + eq({4, 2}, funcs.luaeval('{4, 2}')) + eq(3, eval('type(luaeval("{4, 2}"))')) + + local level = 30 + eq(nested_by_level[level].o, funcs.luaeval(nested_by_level[level].s)) + + eq({_TYPE={}, _VAL={{{_TYPE={}, _VAL={'\n', '\n'}}, {_TYPE={}, _VAL={'\n', '\n\n'}}}}}, + funcs.luaeval([[{['\0\n\0']='\0\n\0\0'}]])) + eq(1, eval([[luaeval('{["\0\n\0"]="\0\n\0\0"}')._TYPE is v:msgpack_types.map]])) + eq(1, eval([[luaeval('{["\0\n\0"]="\0\n\0\0"}')._VAL[0][0]._TYPE is v:msgpack_types.string]])) + eq(1, eval([[luaeval('{["\0\n\0"]="\0\n\0\0"}')._VAL[0][1]._TYPE is v:msgpack_types.binary]])) + eq({nested={{_TYPE={}, _VAL={{{_TYPE={}, _VAL={'\n', '\n'}}, {_TYPE={}, _VAL={'\n', '\n\n'}}}}}}}, + funcs.luaeval([[{nested={{['\0\n\0']='\0\n\0\0'}}}]])) + end) + + it('correctly passes scalars as argument', function() + eq(1, funcs.luaeval('_A', 1)) + eq(1.5, funcs.luaeval('_A', 1.5)) + eq('', funcs.luaeval('_A', '')) + eq('test', funcs.luaeval('_A', 'test')) + eq(NIL, funcs.luaeval('_A', NIL)) + eq(true, funcs.luaeval('_A', true)) + eq(false, funcs.luaeval('_A', false)) + end) + + it('correctly passes containers as argument', function() + eq({}, funcs.luaeval('_A', {})) + eq({test=1}, funcs.luaeval('_A', {test=1})) + eq({4, 2}, funcs.luaeval('_A', {4, 2})) + local level = 28 + eq(nested_by_level[level].o, funcs.luaeval('_A', nested_by_level[level].o)) + end) + + local function sp(typ, val) + return ('{"_TYPE": v:msgpack_types.%s, "_VAL": %s}'):format(typ, val) + end + local function mapsp(...) + local val = '' + for i=1,(select('#', ...)/2) do + val = ('%s[%s,%s],'):format(val, select(i * 2 - 1, ...), + select(i * 2, ...)) + end + return sp('map', '[' .. val .. ']') + end + local function luaevalarg(argexpr, expr) + return eval(([=[ + [ + extend(g:, {'_ret': luaeval(%s, %s)})._ret, + type(g:_ret)==type({})&&has_key(g:_ret, '_TYPE') + ? [ + get(keys(filter(copy(v:msgpack_types), 'v:val is g:_ret._TYPE')), 0, + g:_ret._TYPE), + get(g:_ret, '_VAL', g:_ret) + ] + : [0, g:_ret]][1] + ]=]):format(expr or '"_A"', argexpr):gsub('\n', '')) + end + + it('correctly passes special dictionaries', function() + eq({'binary', {'\n', '\n'}}, luaevalarg(sp('binary', '["\\n", "\\n"]'))) + eq({'binary', {'\n', '\n'}}, luaevalarg(sp('string', '["\\n", "\\n"]'))) + eq({0, true}, luaevalarg(sp('boolean', 1))) + eq({0, false}, luaevalarg(sp('boolean', 0))) + eq({0, NIL}, luaevalarg(sp('nil', 0))) + eq({0, {[""]=""}}, luaevalarg(mapsp(sp('binary', '[""]'), '""'))) + eq({0, {[""]=""}}, luaevalarg(mapsp(sp('string', '[""]'), '""'))) + end) + + it('issues an error in some cases', function() + eq("Vim(call):E5100: Cannot convert given lua table: table should either have a sequence of positive integer keys or contain only string keys", + exc_exec('call luaeval("{1, foo=2}")')) + eq("Vim(call):E5101: Cannot convert given lua type", + exc_exec('call luaeval("vim.api.nvim_buf_get_lines")')) + startswith("Vim(call):E5107: Error while creating lua chunk for luaeval(): ", + exc_exec('call luaeval("1, 2, 3")')) + startswith("Vim(call):E5108: Error while calling lua chunk for luaeval(): ", + exc_exec('call luaeval("(nil)()")')) + eq("Vim(call):E5101: Cannot convert given lua type", + exc_exec('call luaeval("{42, vim.api}")')) + eq("Vim(call):E5101: Cannot convert given lua type", + exc_exec('call luaeval("{foo=42, baz=vim.api}")')) + + -- The following should not crash: conversion error happens inside + eq("Vim(call):E5101: Cannot convert given lua type", + exc_exec('call luaeval("vim.api")')) + -- The following should not show internal error + eq("\nE5101: Cannot convert given lua type\n0", + redir_exec('echo luaeval("vim.api")')) + end) + + it('correctly converts containers with type_idx', function() + eq(5, eval('type(luaeval("{[vim.type_idx]=vim.types.float, [vim.val_idx]=0}"))')) + eq(4, eval([[type(luaeval('{[vim.type_idx]=vim.types.dictionary}'))]])) + eq(3, eval([[type(luaeval('{[vim.type_idx]=vim.types.array}'))]])) + + eq({}, funcs.luaeval('{[vim.type_idx]=vim.types.array}')) + + -- Presence of type_idx makes Vim ignore some keys + eq({42}, funcs.luaeval('{[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}')) + eq({foo=2}, funcs.luaeval('{[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}')) + eq(10, funcs.luaeval('{[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}')) + + -- The following should not crash + eq({}, funcs.luaeval('{[vim.type_idx]=vim.types.dictionary}')) + end) + + it('correctly converts self-containing containers', function() + meths.set_var('l', {}) + eval('add(l, l)') + eq(true, eval('luaeval("_A == _A[1]", l)')) + eq(true, eval('luaeval("_A[1] == _A[1][1]", [l])')) + eq(true, eval('luaeval("_A.d == _A.d[1]", {"d": l})')) + eq(true, eval('luaeval("_A ~= _A[1]", [l])')) + + meths.set_var('d', {foo=42}) + eval('extend(d, {"d": d})') + eq(true, eval('luaeval("_A == _A.d", d)')) + eq(true, eval('luaeval("_A[1] == _A[1].d", [d])')) + eq(true, eval('luaeval("_A.d == _A.d.d", {"d": d})')) + eq(true, eval('luaeval("_A ~= _A.d", {"d": d})')) + end) + + it('errors out correctly when doing incorrect things in lua', function() + -- Conversion errors + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: attempt to call field \'xxx_nonexistent_key_xxx\' (a nil value)', + exc_exec([[call luaeval("vim.xxx_nonexistent_key_xxx()")]])) + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: ERROR', + exc_exec([[call luaeval("error('ERROR')")]])) + end) end) diff --git a/test/functional/lua_spec.lua b/test/functional/lua_spec.lua deleted file mode 100644 index 8ca47718aa..0000000000 --- a/test/functional/lua_spec.lua +++ /dev/null @@ -1,328 +0,0 @@ -local helpers = require('test.functional.helpers')(after_each) - -local eq = helpers.eq -local neq = helpers.neq -local NIL = helpers.NIL -local eval = helpers.eval -local clear = helpers.clear -local funcs = helpers.funcs -local meths = helpers.meths -local exc_exec = helpers.exc_exec -local redir_exec = helpers.redir_exec - -local function startswith(expected, actual) - eq(expected, actual:sub(1, #expected)) -end - -before_each(clear) - -describe('luaeval() function', function() - local nested_by_level = {} - local nested = {} - local nested_s = '{}' - for i=1,100 do - if i % 2 == 0 then - nested = {nested} - nested_s = '{' .. nested_s .. '}' - else - nested = {nested=nested} - nested_s = '{nested=' .. nested_s .. '}' - end - nested_by_level[i] = {o=nested, s=nested_s} - end - - -- Not checked: funcrefs converted to NIL. To be altered to something more - -- meaningful later. - - it('correctly evaluates scalars', function() - eq(1, funcs.luaeval('1')) - eq(0, eval('type(luaeval("1"))')) - - eq(1.5, funcs.luaeval('1.5')) - eq(5, eval('type(luaeval("1.5"))')) - - eq("test", funcs.luaeval('"test"')) - eq(1, eval('type(luaeval("\'test\'"))')) - - eq('', funcs.luaeval('""')) - eq({_TYPE={}, _VAL={'\n'}}, funcs.luaeval([['\0']])) - eq({_TYPE={}, _VAL={'\n', '\n'}}, funcs.luaeval([['\0\n\0']])) - eq(1, eval([[luaeval('"\0\n\0"')._TYPE is v:msgpack_types.binary]])) - - eq(true, funcs.luaeval('true')) - eq(false, funcs.luaeval('false')) - eq(NIL, funcs.luaeval('nil')) - end) - - it('correctly evaluates containers', function() - eq({}, funcs.luaeval('{}')) - eq(3, eval('type(luaeval("{}"))')) - - eq({test=1, foo=2}, funcs.luaeval('{test=1, foo=2}')) - eq(4, eval('type(luaeval("{test=1, foo=2}"))')) - - eq({4, 2}, funcs.luaeval('{4, 2}')) - eq(3, eval('type(luaeval("{4, 2}"))')) - - local level = 30 - eq(nested_by_level[level].o, funcs.luaeval(nested_by_level[level].s)) - - eq({_TYPE={}, _VAL={{{_TYPE={}, _VAL={'\n', '\n'}}, {_TYPE={}, _VAL={'\n', '\n\n'}}}}}, - funcs.luaeval([[{['\0\n\0']='\0\n\0\0'}]])) - eq(1, eval([[luaeval('{["\0\n\0"]="\0\n\0\0"}')._TYPE is v:msgpack_types.map]])) - eq(1, eval([[luaeval('{["\0\n\0"]="\0\n\0\0"}')._VAL[0][0]._TYPE is v:msgpack_types.string]])) - eq(1, eval([[luaeval('{["\0\n\0"]="\0\n\0\0"}')._VAL[0][1]._TYPE is v:msgpack_types.binary]])) - eq({nested={{_TYPE={}, _VAL={{{_TYPE={}, _VAL={'\n', '\n'}}, {_TYPE={}, _VAL={'\n', '\n\n'}}}}}}}, - funcs.luaeval([[{nested={{['\0\n\0']='\0\n\0\0'}}}]])) - end) - - it('correctly passes scalars as argument', function() - eq(1, funcs.luaeval('_A', 1)) - eq(1.5, funcs.luaeval('_A', 1.5)) - eq('', funcs.luaeval('_A', '')) - eq('test', funcs.luaeval('_A', 'test')) - eq(NIL, funcs.luaeval('_A', NIL)) - eq(true, funcs.luaeval('_A', true)) - eq(false, funcs.luaeval('_A', false)) - end) - - it('correctly passes containers as argument', function() - eq({}, funcs.luaeval('_A', {})) - eq({test=1}, funcs.luaeval('_A', {test=1})) - eq({4, 2}, funcs.luaeval('_A', {4, 2})) - local level = 28 - eq(nested_by_level[level].o, funcs.luaeval('_A', nested_by_level[level].o)) - end) - - local function sp(typ, val) - return ('{"_TYPE": v:msgpack_types.%s, "_VAL": %s}'):format(typ, val) - end - local function mapsp(...) - local val = '' - for i=1,(select('#', ...)/2) do - val = ('%s[%s,%s],'):format(val, select(i * 2 - 1, ...), - select(i * 2, ...)) - end - return sp('map', '[' .. val .. ']') - end - local function luaevalarg(argexpr, expr) - return eval(([=[ - [ - extend(g:, {'_ret': luaeval(%s, %s)})._ret, - type(g:_ret)==type({})&&has_key(g:_ret, '_TYPE') - ? [ - get(keys(filter(copy(v:msgpack_types), 'v:val is g:_ret._TYPE')), 0, - g:_ret._TYPE), - get(g:_ret, '_VAL', g:_ret) - ] - : [0, g:_ret]][1] - ]=]):format(expr or '"_A"', argexpr):gsub('\n', '')) - end - - it('correctly passes special dictionaries', function() - eq({'binary', {'\n', '\n'}}, luaevalarg(sp('binary', '["\\n", "\\n"]'))) - eq({'binary', {'\n', '\n'}}, luaevalarg(sp('string', '["\\n", "\\n"]'))) - eq({0, true}, luaevalarg(sp('boolean', 1))) - eq({0, false}, luaevalarg(sp('boolean', 0))) - eq({0, NIL}, luaevalarg(sp('nil', 0))) - eq({0, {[""]=""}}, luaevalarg(mapsp(sp('binary', '[""]'), '""'))) - eq({0, {[""]=""}}, luaevalarg(mapsp(sp('string', '[""]'), '""'))) - end) - - it('issues an error in some cases', function() - eq("Vim(call):E5100: Cannot convert given lua table: table should either have a sequence of positive integer keys or contain only string keys", - exc_exec('call luaeval("{1, foo=2}")')) - eq("Vim(call):E5101: Cannot convert given lua type", - exc_exec('call luaeval("vim.api.buffer_get_line_slice")')) - startswith("Vim(call):E5107: Error while creating lua chunk for luaeval(): ", - exc_exec('call luaeval("1, 2, 3")')) - startswith("Vim(call):E5108: Error while calling lua chunk for luaeval(): ", - exc_exec('call luaeval("(nil)()")')) - eq("Vim(call):E5101: Cannot convert given lua type", - exc_exec('call luaeval("{42, vim.api}")')) - eq("Vim(call):E5101: Cannot convert given lua type", - exc_exec('call luaeval("{foo=42, baz=vim.api}")')) - - -- The following should not crash: conversion error happens inside - eq("Vim(call):E5101: Cannot convert given lua type", - exc_exec('call luaeval("vim.api")')) - -- The following should not show internal error - eq("\nE5101: Cannot convert given lua type\n0", - redir_exec('echo luaeval("vim.api")')) - end) - - it('correctly converts containers with type_idx', function() - eq(5, eval('type(luaeval("{[vim.type_idx]=vim.types.float, [vim.val_idx]=0}"))')) - eq(4, eval([[type(luaeval('{[vim.type_idx]=vim.types.dictionary}'))]])) - eq(3, eval([[type(luaeval('{[vim.type_idx]=vim.types.array}'))]])) - - eq({}, funcs.luaeval('{[vim.type_idx]=vim.types.array}')) - - -- Presence of type_idx makes Vim ignore some keys - eq({42}, funcs.luaeval('{[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}')) - eq({foo=2}, funcs.luaeval('{[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}')) - eq(10, funcs.luaeval('{[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}')) - - -- The following should not crash - eq({}, funcs.luaeval('{[vim.type_idx]=vim.types.dictionary}')) - end) - - it('correctly converts from API objects', function() - eq(1, funcs.luaeval('vim.api.vim_eval("1")')) - eq('1', funcs.luaeval([[vim.api.vim_eval('"1"')]])) - eq({}, funcs.luaeval('vim.api.vim_eval("[]")')) - eq({}, funcs.luaeval('vim.api.vim_eval("{}")')) - eq(1, funcs.luaeval('vim.api.vim_eval("1.0")')) - eq(true, funcs.luaeval('vim.api.vim_eval("v:true")')) - eq(false, funcs.luaeval('vim.api.vim_eval("v:false")')) - eq(NIL, funcs.luaeval('vim.api.vim_eval("v:null")')) - - eq(0, eval([[type(luaeval('vim.api.vim_eval("1")'))]])) - eq(1, eval([[type(luaeval('vim.api.vim_eval("''1''")'))]])) - eq(3, eval([[type(luaeval('vim.api.vim_eval("[]")'))]])) - eq(4, eval([[type(luaeval('vim.api.vim_eval("{}")'))]])) - eq(5, eval([[type(luaeval('vim.api.vim_eval("1.0")'))]])) - eq(6, eval([[type(luaeval('vim.api.vim_eval("v:true")'))]])) - eq(6, eval([[type(luaeval('vim.api.vim_eval("v:false")'))]])) - eq(7, eval([[type(luaeval('vim.api.vim_eval("v:null")'))]])) - - eq({foo=42}, funcs.luaeval([[vim.api.vim_eval('{"foo": 42}')]])) - eq({42}, funcs.luaeval([[vim.api.vim_eval('[42]')]])) - - eq({foo={bar=42}, baz=50}, funcs.luaeval([[vim.api.vim_eval('{"foo": {"bar": 42}, "baz": 50}')]])) - eq({{42}, {}}, funcs.luaeval([=[vim.api.vim_eval('[[42], []]')]=])) - end) - - it('correctly converts to API objects', function() - eq(1, funcs.luaeval('vim.api._vim_id(1)')) - eq('1', funcs.luaeval('vim.api._vim_id("1")')) - eq({1}, funcs.luaeval('vim.api._vim_id({1})')) - eq({foo=1}, funcs.luaeval('vim.api._vim_id({foo=1})')) - eq(1.5, funcs.luaeval('vim.api._vim_id(1.5)')) - eq(true, funcs.luaeval('vim.api._vim_id(true)')) - eq(false, funcs.luaeval('vim.api._vim_id(false)')) - eq(NIL, funcs.luaeval('vim.api._vim_id(nil)')) - - eq(0, eval([[type(luaeval('vim.api._vim_id(1)'))]])) - eq(1, eval([[type(luaeval('vim.api._vim_id("1")'))]])) - eq(3, eval([[type(luaeval('vim.api._vim_id({1})'))]])) - eq(4, eval([[type(luaeval('vim.api._vim_id({foo=1})'))]])) - eq(5, eval([[type(luaeval('vim.api._vim_id(1.5)'))]])) - eq(6, eval([[type(luaeval('vim.api._vim_id(true)'))]])) - eq(6, eval([[type(luaeval('vim.api._vim_id(false)'))]])) - eq(7, eval([[type(luaeval('vim.api._vim_id(nil)'))]])) - - eq({foo=1, bar={42, {{baz=true}, 5}}}, funcs.luaeval('vim.api._vim_id({foo=1, bar={42, {{baz=true}, 5}}})')) - end) - - it('correctly converts container objects with type_idx to API objects', function() - eq(5, eval('type(luaeval("vim.api._vim_id({[vim.type_idx]=vim.types.float, [vim.val_idx]=0})"))')) - eq(4, eval([[type(luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.dictionary})'))]])) - eq(3, eval([[type(luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.array})'))]])) - - eq({}, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.array})')) - - -- Presence of type_idx makes Vim ignore some keys - eq({42}, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) - eq({foo=2}, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) - eq(10, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) - eq({}, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})')) - end) - - it('correctly converts arrays with type_idx to API objects', function() - eq(3, eval([[type(luaeval('vim.api._vim_id_array({[vim.type_idx]=vim.types.array})'))]])) - - eq({}, funcs.luaeval('vim.api._vim_id_array({[vim.type_idx]=vim.types.array})')) - - eq({42}, funcs.luaeval('vim.api._vim_id_array({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) - eq({{foo=2}}, funcs.luaeval('vim.api._vim_id_array({{[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) - eq({10}, funcs.luaeval('vim.api._vim_id_array({{[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) - eq({}, funcs.luaeval('vim.api._vim_id_array({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})')) - - eq({}, funcs.luaeval('vim.api._vim_id_array({})')) - eq(3, eval([[type(luaeval('vim.api._vim_id_array({})'))]])) - end) - - it('correctly converts dictionaries with type_idx to API objects', function() - eq(4, eval([[type(luaeval('vim.api._vim_id_dictionary({[vim.type_idx]=vim.types.dictionary})'))]])) - - eq({}, funcs.luaeval('vim.api._vim_id_dictionary({[vim.type_idx]=vim.types.dictionary})')) - - eq({v={42}}, funcs.luaeval('vim.api._vim_id_dictionary({v={[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) - eq({foo=2}, funcs.luaeval('vim.api._vim_id_dictionary({[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) - eq({v=10}, funcs.luaeval('vim.api._vim_id_dictionary({v={[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) - eq({v={}}, funcs.luaeval('vim.api._vim_id_dictionary({v={[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2}})')) - - -- If API requests dictionary, then empty table will be the one. This is not - -- the case normally because empty table is an empty arrray. - eq({}, funcs.luaeval('vim.api._vim_id_dictionary({})')) - eq(4, eval([[type(luaeval('vim.api._vim_id_dictionary({})'))]])) - end) - - it('correctly converts self-containing containers', function() - meths.set_var('l', {}) - eval('add(l, l)') - eq(true, eval('luaeval("_A == _A[1]", l)')) - eq(true, eval('luaeval("_A[1] == _A[1][1]", [l])')) - eq(true, eval('luaeval("_A.d == _A.d[1]", {"d": l})')) - eq(true, eval('luaeval("_A ~= _A[1]", [l])')) - - meths.set_var('d', {foo=42}) - eval('extend(d, {"d": d})') - eq(true, eval('luaeval("_A == _A.d", d)')) - eq(true, eval('luaeval("_A[1] == _A[1].d", [d])')) - eq(true, eval('luaeval("_A.d == _A.d.d", {"d": d})')) - eq(true, eval('luaeval("_A ~= _A.d", {"d": d})')) - end) - - it('errors out correctly when working with API', function() - -- Conversion errors - eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Cannot convert given lua type', - exc_exec([[call luaeval("vim.api._vim_id(vim.api._vim_id)")]])) - eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Cannot convert given lua table', - exc_exec([[call luaeval("vim.api._vim_id({1, foo=42})")]])) - eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Cannot convert given lua type', - exc_exec([[call luaeval("vim.api._vim_id({42, vim.api._vim_id})")]])) - -- Errors in number of arguments - eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected 1 argument', - exc_exec([[call luaeval("vim.api._vim_id()")]])) - eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected 1 argument', - exc_exec([[call luaeval("vim.api._vim_id(1, 2)")]])) - eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected 2 arguments', - exc_exec([[call luaeval("vim.api.vim_set_var(1, 2, 3)")]])) - -- Error in argument types - eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected lua string', - exc_exec([[call luaeval("vim.api.vim_set_var(1, 2)")]])) - - eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected lua number', - exc_exec([[call luaeval("vim.api.buffer_get_line(0, 'test')")]])) - eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Number is not integral', - exc_exec([[call luaeval("vim.api.buffer_get_line(0, 1.5)")]])) - - eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected lua table', - exc_exec([[call luaeval("vim.api._vim_id_float('test')")]])) - eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Unexpected type', - exc_exec([[call luaeval("vim.api._vim_id_float({[vim.type_idx]=vim.types.dictionary})")]])) - - eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected lua table', - exc_exec([[call luaeval("vim.api._vim_id_array(1)")]])) - eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Unexpected type', - exc_exec([[call luaeval("vim.api._vim_id_array({[vim.type_idx]=vim.types.dictionary})")]])) - - eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected lua table', - exc_exec([[call luaeval("vim.api._vim_id_dictionary(1)")]])) - eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Unexpected type', - exc_exec([[call luaeval("vim.api._vim_id_dictionary({[vim.type_idx]=vim.types.array})")]])) - -- TODO: check for errors with Tabpage argument - -- TODO: check for errors with Window argument - -- TODO: check for errors with Buffer argument - end) - - it('accepts any value as API Boolean', function() - eq('', funcs.luaeval('vim.api.vim_replace_termcodes("", vim, false, nil)')) - eq('', funcs.luaeval('vim.api.vim_replace_termcodes("", 0, 1.5, "test")')) - eq('', funcs.luaeval('vim.api.vim_replace_termcodes("", true, {}, {[vim.type_idx]=vim.types.array})')) - end) - - -- TODO: check buffer/window/etc. -end) -- cgit From 666d85d3ce80c19c9cd2acd156edbf50fd7e8741 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 21 Jan 2017 01:52:19 +0300 Subject: functests: Some more tests --- test/functional/lua/api_spec.lua | 10 ++++++++++ test/functional/lua/luaeval_spec.lua | 7 +++++++ 2 files changed, 17 insertions(+) (limited to 'test') diff --git a/test/functional/lua/api_spec.lua b/test/functional/lua/api_spec.lua index 31c855c2c1..f6f65cb741 100644 --- a/test/functional/lua/api_spec.lua +++ b/test/functional/lua/api_spec.lua @@ -36,6 +36,16 @@ describe('luaeval(vim.api.…)', function() end) end) + it('correctly evaluates API code which calls luaeval', function() + eq(1, funcs.luaeval(([===[vim.api.nvim_eval([==[ + luaeval('vim.api.nvim_eval([=[ + luaeval("vim.api.nvim_eval([[ + luaeval(1) + ]])") + ]=])') + ]==])]===]):gsub('\n', ' '))) + end) + it('correctly converts from API objects', function() eq(1, funcs.luaeval('vim.api.nvim_eval("1")')) eq('1', funcs.luaeval([[vim.api.nvim_eval('"1"')]])) diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua index 345848cfff..b0169c3d6b 100644 --- a/test/functional/lua/luaeval_spec.lua +++ b/test/functional/lua/luaeval_spec.lua @@ -241,4 +241,11 @@ describe('luaeval()', function() eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: ERROR', exc_exec([[call luaeval("error('ERROR')")]])) end) + + it('does not leak memory when called with too long line with syntax error', + function() + local s = ('x'):rep(65536) + eq('Vim(call):E5107: Error while creating lua chunk for luaeval(): [string ""]:1: unexpected symbol near \')\'', + exc_exec([[call luaeval("(']] .. s ..[[' + )")]])) + end) end) -- cgit From 140cd0da1d0b10cf19a501696971ca2e20eff75b Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 29 Jan 2017 00:52:48 +0300 Subject: functests: Fix “function has more then 60 upvalues” error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/functional/helpers.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 13a0cff137..a62c05128b 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -570,7 +570,7 @@ local curbufmeths = create_callindex(curbuf) local curwinmeths = create_callindex(curwin) local curtabmeths = create_callindex(curtab) -local M = { +local module = { prepend_argv = prepend_argv, clear = clear, connect = connect, @@ -644,5 +644,5 @@ return function(after_each) check_cores('build/bin/nvim') end) end - return M + return module end -- cgit From 7a5646d594ef4ed97f1969103a1cee32733bfa2d Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 29 Jan 2017 04:11:18 +0300 Subject: functests: Add tests for :lua --- test/functional/lua/commands_spec.lua | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'test') diff --git a/test/functional/lua/commands_spec.lua b/test/functional/lua/commands_spec.lua index 191504bfaa..6a37d1fd1b 100644 --- a/test/functional/lua/commands_spec.lua +++ b/test/functional/lua/commands_spec.lua @@ -2,3 +2,56 @@ local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq +local clear = helpers.clear +local meths = helpers.meths +local source = helpers.source +local dedent = helpers.dedent +local exc_exec = helpers.exc_exec +local redir_exec = helpers.redir_exec +local curbufmeths = helpers.curbufmeths + +before_each(clear) + +describe(':lua command', function() + it('works', function() + eq('', redir_exec( + 'lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TEST"})')) + eq({'', 'TEST'}, curbufmeths.get_lines(0, 100, false)) + source(dedent([[ + lua << EOF + vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TSET"}) + EOF]])) + eq({'', 'TSET'}, curbufmeths.get_lines(0, 100, false)) + source(dedent([[ + lua << EOF + vim.api.nvim_buf_set_lines(1, 1, 2, false, {"SETT"})]])) + eq({'', 'SETT'}, curbufmeths.get_lines(0, 100, false)) + source(dedent([[ + lua << EOF + vim.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"}) + vim.api.nvim_buf_set_lines(1, 2, 3, false, {"TTSE"}) + vim.api.nvim_buf_set_lines(1, 3, 4, false, {"STTE"}) + EOF]])) + eq({'', 'ETTS', 'TTSE', 'STTE'}, curbufmeths.get_lines(0, 100, false)) + end) + it('throws catchable errors', function() + eq([[Vim(lua):E5104: Error while creating lua chunk: [string ""]:1: unexpected symbol near ')']], + exc_exec('lua ()')) + eq([[Vim(lua):E5105: Error while calling lua chunk: [string ""]:1: TEST]], + exc_exec('lua error("TEST")')) + eq([[Vim(lua):E5105: Error while calling lua chunk: [string ""]:1: Invalid buffer id]], + exc_exec('lua vim.api.nvim_buf_set_lines(-10, 1, 1, false, {"TEST"})')) + eq({''}, curbufmeths.get_lines(0, 100, false)) + end) + it('accepts embedded NLs without heredoc', function() + -- Such code is usually used for `:execute 'lua' {generated_string}`: + -- heredocs do not work in this case. + meths.command([[ + lua + vim.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"}) + vim.api.nvim_buf_set_lines(1, 2, 3, false, {"TTSE"}) + vim.api.nvim_buf_set_lines(1, 3, 4, false, {"STTE"}) + ]]) + eq({'', 'ETTS', 'TTSE', 'STTE'}, curbufmeths.get_lines(0, 100, false)) + end) +end) -- cgit From b4e2860c69a4e96fa305b535ce0dbdde37632fe1 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 29 Jan 2017 05:09:54 +0300 Subject: doc,functests: Add documentation Missing: updates to various lists. --- test/functional/lua/commands_spec.lua | 8 ++++++++ test/functional/lua/luaeval_spec.lua | 1 + 2 files changed, 9 insertions(+) (limited to 'test') diff --git a/test/functional/lua/commands_spec.lua b/test/functional/lua/commands_spec.lua index 6a37d1fd1b..c607889edb 100644 --- a/test/functional/lua/commands_spec.lua +++ b/test/functional/lua/commands_spec.lua @@ -2,8 +2,10 @@ local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq +local NIL = helpers.NIL local clear = helpers.clear local meths = helpers.meths +local funcs = helpers.funcs local source = helpers.source local dedent = helpers.dedent local exc_exec = helpers.exc_exec @@ -54,4 +56,10 @@ describe(':lua command', function() ]]) eq({'', 'ETTS', 'TTSE', 'STTE'}, curbufmeths.get_lines(0, 100, false)) end) + it('preserves global and not preserves local variables', function() + eq('', redir_exec('lua gvar = 42')) + eq('', redir_exec('lua local lvar = 100500')) + eq(NIL, funcs.luaeval('lvar')) + eq(42, funcs.luaeval('gvar')) + end) end) diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua index b0169c3d6b..6132d44bee 100644 --- a/test/functional/lua/luaeval_spec.lua +++ b/test/functional/lua/luaeval_spec.lua @@ -46,6 +46,7 @@ describe('luaeval()', function() funcs.luaeval('{n=1, f=1.5, s="string", l={4, 2}}')) -- Not tested: nil inside containers: behaviour will most likely change. eq(NIL, funcs.luaeval('nil')) + eq({['']=1}, funcs.luaeval('{[""]=1}')) end) end) describe('recursive lua values', function() -- cgit From 9114d9be778b07f4a49edc078f1c159aa51320d8 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 29 Jan 2017 18:40:39 +0300 Subject: executor: Add :luado command --- test/functional/lua/luaeval_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua index 6132d44bee..5d0180b212 100644 --- a/test/functional/lua/luaeval_spec.lua +++ b/test/functional/lua/luaeval_spec.lua @@ -36,7 +36,7 @@ describe('luaeval()', function() it('is successfully received', function() local t = {t=true, f=false, --[[n=NIL,]] d={l={'string', 42, 0.42}}} eq(t, funcs.luaeval("_A", t)) - -- Not tested: nil, funcrefs, returned object identity: behaviour will + -- Not tested: nil, funcrefs, returned object identity: behaviour will -- most likely change. end) end) -- cgit From e1bbaca7acf7fc498da49081d069b00aa05506df Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 29 Jan 2017 19:26:22 +0300 Subject: executor,functests: Add tests for :luado, also some fixes Fixes: 1. Allocate space for the NUL byte. 2. Do not exclude last line from range. 3. Remove code for sandbox: it is handled earlier. 4. Fix index in new_line_transformed when converting NULs to NLs. 5. Always allocate new_line_transformed, but save allocated value. --- test/functional/lua/commands_spec.lua | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'test') diff --git a/test/functional/lua/commands_spec.lua b/test/functional/lua/commands_spec.lua index c607889edb..f1d430b34c 100644 --- a/test/functional/lua/commands_spec.lua +++ b/test/functional/lua/commands_spec.lua @@ -63,3 +63,48 @@ describe(':lua command', function() eq(42, funcs.luaeval('gvar')) end) end) + +describe(':luado command', function() + it('works', function() + curbufmeths.set_lines(0, 1, false, {"ABC", "def", "gHi"}) + eq('', redir_exec('luado lines = (lines or {}) lines[#lines + 1] = {linenr, line}')) + eq({'ABC', 'def', 'gHi'}, curbufmeths.get_lines(0, -1, false)) + eq({{1, 'ABC'}, {2, 'def'}, {3, 'gHi'}}, funcs.luaeval('lines')) + + -- Automatic transformation of numbers + eq('', redir_exec('luado return linenr')) + eq({'1', '2', '3'}, curbufmeths.get_lines(0, -1, false)) + + eq('', redir_exec('luado return ("<%02x>"):format(line:byte())')) + eq({'<31>', '<32>', '<33>'}, curbufmeths.get_lines(0, -1, false)) + end) + it('stops processing lines when suddenly out of lines', function() + curbufmeths.set_lines(0, 1, false, {"ABC", "def", "gHi"}) + eq('', redir_exec('2,$luado runs = ((runs or 0) + 1) vim.api.nvim_command("%d")')) + eq({''}, curbufmeths.get_lines(0, -1, false)) + eq(1, funcs.luaeval('runs')) + end) + it('works correctly when changing lines out of range', function() + curbufmeths.set_lines(0, 1, false, {"ABC", "def", "gHi"}) + eq('\nE322: line number out of range: 1 past the end\nE320: Cannot find line 2', + redir_exec('2,$luado vim.api.nvim_command("%d") return linenr')) + eq({''}, curbufmeths.get_lines(0, -1, false)) + end) + it('fails on errors', function() + eq([[Vim(luado):E5109: Error while creating lua chunk: [string ""]:1: unexpected symbol near ')']], + exc_exec('luado ()')) + eq([[Vim(luado):E5111: Error while calling lua function: [string ""]:1: attempt to perform arithmetic on global 'liness' (a nil value)]], + exc_exec('luado return liness + 1')) + end) + it('fails in sandbox when needed', function() + curbufmeths.set_lines(0, 1, false, {"ABC", "def", "gHi"}) + eq('\nE48: Not allowed in sandbox: sandbox luado runs = (runs or 0) + 1', + redir_exec('sandbox luado runs = (runs or 0) + 1')) + eq(NIL, funcs.luaeval('runs')) + end) + it('works with long strings', function() + local s = ('x'):rep(100500) + eq('', redir_exec(('luado return "%s"'):format(s))) + eq({s}, curbufmeths.get_lines(0, -1, false)) + end) +end) -- cgit From 295e7607c472b49e8c0762977e38c4527b746b6f Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 29 Jan 2017 19:32:01 +0300 Subject: executor: Fix some memory leaks --- test/functional/lua/commands_spec.lua | 13 +++++++++++++ test/functional/lua/luaeval_spec.lua | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/functional/lua/commands_spec.lua b/test/functional/lua/commands_spec.lua index f1d430b34c..41a5a8d9e0 100644 --- a/test/functional/lua/commands_spec.lua +++ b/test/functional/lua/commands_spec.lua @@ -62,6 +62,15 @@ describe(':lua command', function() eq(NIL, funcs.luaeval('lvar')) eq(42, funcs.luaeval('gvar')) end) + it('works with long strings', function() + local s = ('x'):rep(100500) + + eq('\nE5104: Error while creating lua chunk: [string ""]:1: unfinished string near \'\'', redir_exec(('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"%s})'):format(s))) + eq({''}, curbufmeths.get_lines(0, -1, false)) + + eq('', redir_exec(('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"%s"})'):format(s))) + eq({'', s}, curbufmeths.get_lines(0, -1, false)) + end) end) describe(':luado command', function() @@ -104,6 +113,10 @@ describe(':luado command', function() end) it('works with long strings', function() local s = ('x'):rep(100500) + + eq('\nE5109: Error while creating lua chunk: [string ""]:1: unfinished string near \'\'', redir_exec(('luado return "%s'):format(s))) + eq({''}, curbufmeths.get_lines(0, -1, false)) + eq('', redir_exec(('luado return "%s"'):format(s))) eq({s}, curbufmeths.get_lines(0, -1, false)) end) diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua index 5d0180b212..7973cabae4 100644 --- a/test/functional/lua/luaeval_spec.lua +++ b/test/functional/lua/luaeval_spec.lua @@ -243,10 +243,11 @@ describe('luaeval()', function() exc_exec([[call luaeval("error('ERROR')")]])) end) - it('does not leak memory when called with too long line with syntax error', + it('does not leak memory when called with too long line', function() local s = ('x'):rep(65536) eq('Vim(call):E5107: Error while creating lua chunk for luaeval(): [string ""]:1: unexpected symbol near \')\'', exc_exec([[call luaeval("(']] .. s ..[[' + )")]])) + eq(s, funcs.luaeval('"' .. s .. '"')) end) end) -- cgit From dcb992ab3759b604c1824913002714a018be0532 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 29 Jan 2017 19:51:55 +0300 Subject: executor: Add :luafile command --- test/functional/lua/commands_spec.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test') diff --git a/test/functional/lua/commands_spec.lua b/test/functional/lua/commands_spec.lua index 41a5a8d9e0..80fac07f8c 100644 --- a/test/functional/lua/commands_spec.lua +++ b/test/functional/lua/commands_spec.lua @@ -9,6 +9,7 @@ local funcs = helpers.funcs local source = helpers.source local dedent = helpers.dedent local exc_exec = helpers.exc_exec +local write_file = helpers.write_file local redir_exec = helpers.redir_exec local curbufmeths = helpers.curbufmeths @@ -121,3 +122,30 @@ describe(':luado command', function() eq({s}, curbufmeths.get_lines(0, -1, false)) end) end) + +describe(':luafile', function() + local fname = 'Xtest-functional-lua-commands-luafile' + + after_each(function() + os.remove(fname) + end) + + it('works', function() + write_file(fname, [[ + vim.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"}) + vim.api.nvim_buf_set_lines(1, 2, 3, false, {"TTSE"}) + vim.api.nvim_buf_set_lines(1, 3, 4, false, {"STTE"}) + ]]) + eq('', redir_exec('luafile ' .. fname)) + eq({'', 'ETTS', 'TTSE', 'STTE'}, curbufmeths.get_lines(0, 100, false)) + end) + + it('correctly errors out', function() + write_file(fname, '()') + eq(("Vim(luafile):E5112: Error while creating lua chunk: %s:1: unexpected symbol near ')'"):format(fname), + exc_exec('luafile ' .. fname)) + write_file(fname, 'vimm.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"})') + eq(("Vim(luafile):E5113: Error while calling lua chunk: %s:1: attempt to index global 'vimm' (a nil value)"):format(fname), + exc_exec('luafile ' .. fname)) + end) +end) -- cgit From 9fd2bf67aa1db66e3465753d5aaaec342f4ce193 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 29 Jan 2017 23:22:50 +0300 Subject: executor,functests: Add print() tests, some fixes --- test/functional/lua/commands_spec.lua | 13 +++++++ test/functional/lua/luaeval_spec.lua | 2 ++ test/functional/lua/overrides_spec.lua | 65 ++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 test/functional/lua/overrides_spec.lua (limited to 'test') diff --git a/test/functional/lua/commands_spec.lua b/test/functional/lua/commands_spec.lua index 80fac07f8c..017ee55729 100644 --- a/test/functional/lua/commands_spec.lua +++ b/test/functional/lua/commands_spec.lua @@ -46,6 +46,10 @@ describe(':lua command', function() exc_exec('lua vim.api.nvim_buf_set_lines(-10, 1, 1, false, {"TEST"})')) eq({''}, curbufmeths.get_lines(0, 100, false)) end) + it('works with NULL errors', function() + eq([=[Vim(lua):E5105: Error while calling lua chunk: [NULL]]=], + exc_exec('lua error(nil)')) + end) it('accepts embedded NLs without heredoc', function() -- Such code is usually used for `:execute 'lua' {generated_string}`: -- heredocs do not work in this case. @@ -106,6 +110,10 @@ describe(':luado command', function() eq([[Vim(luado):E5111: Error while calling lua function: [string ""]:1: attempt to perform arithmetic on global 'liness' (a nil value)]], exc_exec('luado return liness + 1')) end) + it('works with NULL errors', function() + eq([=[Vim(luado):E5111: Error while calling lua function: [NULL]]=], + exc_exec('luado error(nil)')) + end) it('fails in sandbox when needed', function() curbufmeths.set_lines(0, 1, false, {"ABC", "def", "gHi"}) eq('\nE48: Not allowed in sandbox: sandbox luado runs = (runs or 0) + 1', @@ -148,4 +156,9 @@ describe(':luafile', function() eq(("Vim(luafile):E5113: Error while calling lua chunk: %s:1: attempt to index global 'vimm' (a nil value)"):format(fname), exc_exec('luafile ' .. fname)) end) + it('works with NULL errors', function() + write_file(fname, 'error(nil)') + eq([=[Vim(luafile):E5113: Error while calling lua chunk: [NULL]]=], + exc_exec('luafile ' .. fname)) + end) end) diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua index 7973cabae4..6da0001cea 100644 --- a/test/functional/lua/luaeval_spec.lua +++ b/test/functional/lua/luaeval_spec.lua @@ -241,6 +241,8 @@ describe('luaeval()', function() exc_exec([[call luaeval("vim.xxx_nonexistent_key_xxx()")]])) eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: ERROR', exc_exec([[call luaeval("error('ERROR')")]])) + eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [NULL]', + exc_exec([[call luaeval("error(nil)")]])) end) it('does not leak memory when called with too long line', diff --git a/test/functional/lua/overrides_spec.lua b/test/functional/lua/overrides_spec.lua new file mode 100644 index 0000000000..92167d18dc --- /dev/null +++ b/test/functional/lua/overrides_spec.lua @@ -0,0 +1,65 @@ +-- Test for Vim overrides of lua built-ins +local helpers = require('test.functional.helpers')(after_each) + +local eq = helpers.eq +local NIL = helpers.NIL +local clear = helpers.clear +local funcs = helpers.funcs +local meths = helpers.meths +local command = helpers.command +local write_file = helpers.write_file +local redir_exec = helpers.redir_exec + +local fname = 'Xtest-functional-lua-overrides-luafile' + +before_each(clear) + +after_each(function() + os.remove(fname) +end) + +describe('print', function() + it('returns nothing', function() + eq(NIL, funcs.luaeval('print("abc")')) + eq(0, funcs.luaeval('select("#", print("abc"))')) + end) + it('allows catching printed text with :execute', function() + eq('\nabc', funcs.execute('lua print("abc")')) + eq('\nabc', funcs.execute('luado print("abc")')) + eq('\nabc', funcs.execute('call luaeval("print(\'abc\')")')) + write_file(fname, 'print("abc")') + eq('\nabc', funcs.execute('luafile ' .. fname)) + + eq('\nabc', redir_exec('lua print("abc")')) + eq('\nabc', redir_exec('luado print("abc")')) + eq('\nabc', redir_exec('call luaeval("print(\'abc\')")')) + write_file(fname, 'print("abc")') + eq('\nabc', redir_exec('luafile ' .. fname)) + end) + it('handles errors in __tostring', function() + write_file(fname, [[ + local meta_nilerr = { __tostring = function() error(nil) end } + local meta_abcerr = { __tostring = function() error("abc") end } + local meta_tblout = { __tostring = function() return {"TEST"} end } + v_nilerr = setmetatable({}, meta_nilerr) + v_abcerr = setmetatable({}, meta_abcerr) + v_tblout = setmetatable({}, meta_tblout) + ]]) + eq('', redir_exec('luafile ' .. fname)) + eq('\nE5114: Error while converting print argument #2: [NULL]', + redir_exec('lua print("foo", v_nilerr, "bar")')) + eq('\nE5114: Error while converting print argument #2: Xtest-functional-lua-overrides-luafile:2: abc', + redir_exec('lua print("foo", v_abcerr, "bar")')) + eq('\nE5114: Error while converting print argument #2: ', + redir_exec('lua print("foo", v_tblout, "bar")')) + end) + it('prints strings with NULs and NLs correctly', function() + meths.set_option('more', true) + eq('\nabc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT\n', + redir_exec([[lua print("abc \0 def\nghi\0\0\0jkl\nTEST\n\n\nT\n")]])) + eq('\nabc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT^@', + redir_exec([[lua print("abc \0 def\nghi\0\0\0jkl\nTEST\n\n\nT\0")]])) + eq('\nT^@', redir_exec([[lua print("T\0")]])) + eq('\nT\n', redir_exec([[lua print("T\n")]])) + end) +end) -- cgit From d13fdfd4467db8245159d10d96c1f30b24b51565 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 30 Jan 2017 03:30:45 +0300 Subject: functests: Add test for debug.debug --- test/functional/lua/overrides_spec.lua | 111 +++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) (limited to 'test') diff --git a/test/functional/lua/overrides_spec.lua b/test/functional/lua/overrides_spec.lua index 92167d18dc..60a0589b48 100644 --- a/test/functional/lua/overrides_spec.lua +++ b/test/functional/lua/overrides_spec.lua @@ -1,8 +1,10 @@ -- Test for Vim overrides of lua built-ins local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') local eq = helpers.eq local NIL = helpers.NIL +local feed = helpers.feed local clear = helpers.clear local funcs = helpers.funcs local meths = helpers.meths @@ -10,6 +12,8 @@ local command = helpers.command local write_file = helpers.write_file local redir_exec = helpers.redir_exec +local screen + local fname = 'Xtest-functional-lua-overrides-luafile' before_each(clear) @@ -63,3 +67,110 @@ describe('print', function() eq('\nT\n', redir_exec([[lua print("T\n")]])) end) end) + +describe('debug.debug', function() + before_each(function() + screen = Screen.new() + screen:attach() + screen:set_default_attr_ids({ + [0] = {bold=true, foreground=255}, + E = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, + cr = {bold = true, foreground = Screen.colors.SeaGreen4}, + }) + end) + it('works', function() + write_file(fname, [[ + function Test(a) + print(a) + debug.debug() + print(a * 100) + end + ]]) + eq('', redir_exec('luafile ' .. fname)) + feed(':lua Test()\n') + screen:expect([[ + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + nil | + lua_debug> ^ | + ]]) + feed('print("TEST")\n') + screen:expect([[ + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + nil | + lua_debug> print("TEST") | + TEST | + lua_debug> ^ | + ]]) + feed('') + screen:expect([[ + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + nil | + lua_debug> print("TEST") | + TEST | + | + {E:E5105: Error while calling lua chunk: Xtest-functiona}| + {E:l-lua-overrides-luafile:4: attempt to perform arithme}| + {E:tic on local 'a' (a nil value)} | + Interrupt: {cr:Press ENTER or type command to continue}^ | + ]]) + feed(':lua Test()\n') + screen:expect([[ + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + nil | + lua_debug> ^ | + ]]) + feed('\n') + screen:expect([[ + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + nil | + lua_debug> | + {E:E5105: Error while calling lua chunk: Xtest-functiona}| + {E:l-lua-overrides-luafile:4: attempt to perform arithme}| + {E:tic on local 'a' (a nil value)} | + {cr:Press ENTER or type command to continue}^ | + ]]) + end) +end) -- cgit From a24e94215ed0a4bfe55b6741ab2e9477b278dbb7 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 30 Jan 2017 03:35:45 +0300 Subject: eval,functests: Fix linter errors --- test/functional/lua/overrides_spec.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/functional/lua/overrides_spec.lua b/test/functional/lua/overrides_spec.lua index 60a0589b48..c8aee130a7 100644 --- a/test/functional/lua/overrides_spec.lua +++ b/test/functional/lua/overrides_spec.lua @@ -79,14 +79,13 @@ describe('debug.debug', function() }) end) it('works', function() - write_file(fname, [[ + command([[lua function Test(a) print(a) debug.debug() print(a * 100) end ]]) - eq('', redir_exec('luafile ' .. fname)) feed(':lua Test()\n') screen:expect([[ {0:~ }| @@ -133,9 +132,9 @@ describe('debug.debug', function() lua_debug> print("TEST") | TEST | | - {E:E5105: Error while calling lua chunk: Xtest-functiona}| - {E:l-lua-overrides-luafile:4: attempt to perform arithme}| - {E:tic on local 'a' (a nil value)} | + {E:E5105: Error while calling lua chunk: [string ""]:5: attempt to perform arithmetic o}| + {E:n local 'a' (a nil value)} | Interrupt: {cr:Press ENTER or type command to continue}^ | ]]) feed(':lua Test()\n') @@ -167,9 +166,9 @@ describe('debug.debug', function() {0:~ }| nil | lua_debug> | - {E:E5105: Error while calling lua chunk: Xtest-functiona}| - {E:l-lua-overrides-luafile:4: attempt to perform arithme}| - {E:tic on local 'a' (a nil value)} | + {E:E5105: Error while calling lua chunk: [string ""]:5: attempt to perform arithmetic o}| + {E:n local 'a' (a nil value)} | {cr:Press ENTER or type command to continue}^ | ]]) end) -- cgit From 7bc37ffb22a84668bba5b2e3589c4c05ad43f7d0 Mon Sep 17 00:00:00 2001 From: Jakob Schnitzer Date: Fri, 24 Mar 2017 20:21:05 +0100 Subject: terminal: global 'scrollback' #6352 Make the 'scrollback' option work like most other buffer-local options: - `:set scrollback=x` sets the global and local value - `:setglobal scrollback=x` sets only the global default - new terminal buffers inherit the global Normal buffers are still always -1, and :setlocal there is an error. Closes #6337 --- test/functional/terminal/scrollback_spec.lua | 37 +++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index 81649f2bde..4ead288a19 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -8,6 +8,7 @@ local command = helpers.command local wait = helpers.wait local retry = helpers.retry local curbufmeths = helpers.curbufmeths +local nvim = helpers.nvim local feed_data = thelpers.feed_data if helpers.pending_win32(pending) then return end @@ -368,6 +369,12 @@ describe("'scrollback' option", function() clear() end) + local function set_fake_shell() + -- shell-test.c is a fake shell that prints its arguments and exits. + nvim('set_option', 'shell', nvim_dir..'/shell-test') + nvim('set_option', 'shellcmdflag', 'EXE') + end + local function expect_lines(expected, epsilon) local ep = epsilon and epsilon or 0 local actual = eval("line('$')") @@ -421,12 +428,13 @@ describe("'scrollback' option", function() screen:detach() end) - it('defaults to 1000', function() - execute('terminal') + it('defaults to 1000 in terminal buffers', function() + set_fake_shell() + command('terminal') eq(1000, curbufmeths.get_option('scrollback')) end) - it('error if set to invalid values', function() + it('error if set to invalid value', function() local status, rv = pcall(command, 'set scrollback=-2') eq(false, status) -- assert failure eq('E474:', string.match(rv, "E%d*:")) @@ -437,15 +445,32 @@ describe("'scrollback' option", function() end) it('defaults to -1 on normal buffers', function() - execute('new') + command('new') eq(-1, curbufmeths.get_option('scrollback')) end) - it('error if set on a normal buffer', function() + it(':setlocal in a normal buffer is an error', function() command('new') - execute('set scrollback=42') + execute('setlocal scrollback=42') feed('') eq('E474:', string.match(eval("v:errmsg"), "E%d*:")) + eq(-1, curbufmeths.get_option('scrollback')) + end) + + it(':set updates local value and global default', function() + set_fake_shell() + command('set scrollback=42') -- set global and (attempt) local + eq(-1, curbufmeths.get_option('scrollback')) -- normal buffer: -1 + command('terminal') + eq(42, curbufmeths.get_option('scrollback')) -- inherits global default + command('setlocal scrollback=99') + eq(99, curbufmeths.get_option('scrollback')) + command('set scrollback<') -- reset to global default + eq(42, curbufmeths.get_option('scrollback')) + command('setglobal scrollback=734') -- new global default + eq(42, curbufmeths.get_option('scrollback')) -- local value did not change + command('terminal') + eq(734, curbufmeths.get_option('scrollback')) end) end) -- cgit From e20e9645b2c74b8cf6e1ba90961c08b079bbee3c Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 27 Mar 2017 14:12:23 +0200 Subject: build: Rename NEOVIM_* to NVIM_* --- test/unit/os/env_spec.lua | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'test') diff --git a/test/unit/os/env_spec.lua b/test/unit/os/env_spec.lua index 1ffed784ff..823b6d6a85 100644 --- a/test/unit/os/env_spec.lua +++ b/test/unit/os/env_spec.lua @@ -35,17 +35,17 @@ describe('env function', function() local OK = 0 itp('sets an env variable and returns OK', function() - local name = 'NEOVIM_UNIT_TEST_SETENV_1N' - local value = 'NEOVIM_UNIT_TEST_SETENV_1V' + local name = 'NVIM_UNIT_TEST_SETENV_1N' + local value = 'NVIM_UNIT_TEST_SETENV_1V' eq(nil, os.getenv(name)) eq(OK, (os_setenv(name, value, 1))) eq(value, os.getenv(name)) end) itp("dosn't overwrite an env variable if overwrite is 0", function() - local name = 'NEOVIM_UNIT_TEST_SETENV_2N' - local value = 'NEOVIM_UNIT_TEST_SETENV_2V' - local value_updated = 'NEOVIM_UNIT_TEST_SETENV_2V_UPDATED' + local name = 'NVIM_UNIT_TEST_SETENV_2N' + local value = 'NVIM_UNIT_TEST_SETENV_2V' + local value_updated = 'NVIM_UNIT_TEST_SETENV_2V_UPDATED' eq(OK, (os_setenv(name, value, 0))) eq(value, os.getenv(name)) eq(OK, (os_setenv(name, value_updated, 0))) @@ -69,8 +69,8 @@ describe('env function', function() describe('os_getenv', function() itp('reads an env variable', function() - local name = 'NEOVIM_UNIT_TEST_GETENV_1N' - local value = 'NEOVIM_UNIT_TEST_GETENV_1V' + local name = 'NVIM_UNIT_TEST_GETENV_1N' + local value = 'NVIM_UNIT_TEST_GETENV_1V' eq(NULL, os_getenv(name)) -- need to use os_setenv, because lua dosn't have a setenv function os_setenv(name, value, 1) @@ -78,7 +78,7 @@ describe('env function', function() end) itp('returns NULL if the env variable is not found', function() - local name = 'NEOVIM_UNIT_TEST_GETENV_NOTFOUND' + local name = 'NVIM_UNIT_TEST_GETENV_NOTFOUND' return eq(NULL, os_getenv(name)) end) end) @@ -97,8 +97,8 @@ describe('env function', function() describe('os_getenvname_at_index', function() itp('returns names of environment variables', function() - local test_name = 'NEOVIM_UNIT_TEST_GETENVNAME_AT_INDEX_1N' - local test_value = 'NEOVIM_UNIT_TEST_GETENVNAME_AT_INDEX_1V' + local test_name = 'NVIM_UNIT_TEST_GETENVNAME_AT_INDEX_1N' + local test_value = 'NVIM_UNIT_TEST_GETENVNAME_AT_INDEX_1V' os_setenv(test_name, test_value, 1) local i = 0 local names = { } @@ -160,16 +160,16 @@ describe('env function', function() describe('expand_env_esc', function() itp('expands environment variables', function() - local name = 'NEOVIM_UNIT_TEST_EXPAND_ENV_ESCN' - local value = 'NEOVIM_UNIT_TEST_EXPAND_ENV_ESCV' + local name = 'NVIM_UNIT_TEST_EXPAND_ENV_ESCN' + local value = 'NVIM_UNIT_TEST_EXPAND_ENV_ESCV' os_setenv(name, value, 1) -- TODO(bobtwinkles) This only tests Unix expansions. There should be a -- test for Windows as well - local input1 = to_cstr('$NEOVIM_UNIT_TEST_EXPAND_ENV_ESCN/test') - local input2 = to_cstr('${NEOVIM_UNIT_TEST_EXPAND_ENV_ESCN}/test') + local input1 = to_cstr('$NVIM_UNIT_TEST_EXPAND_ENV_ESCN/test') + local input2 = to_cstr('${NVIM_UNIT_TEST_EXPAND_ENV_ESCN}/test') local output_buff1 = cstr(255, '') local output_buff2 = cstr(255, '') - local output_expected = 'NEOVIM_UNIT_TEST_EXPAND_ENV_ESCV/test' + local output_expected = 'NVIM_UNIT_TEST_EXPAND_ENV_ESCV/test' cimp.expand_env_esc(input1, output_buff1, 255, false, true, NULL) cimp.expand_env_esc(input2, output_buff2, 255, false, true, NULL) eq(output_expected, ffi.string(output_buff1)) -- cgit From e86042ae178736d657b5da12adce4479633aa8d5 Mon Sep 17 00:00:00 2001 From: lonerover Date: Wed, 29 Mar 2017 07:30:54 +0800 Subject: vim-patch:7.4.2343 and mark NA patches (#6384) vim-patch:7.4.2343 Problem: Too many old file tests. Solution: Turn several into new style tests. (Yegappan Lakshmanan) https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed --- test/functional/legacy/arglist_spec.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'test') diff --git a/test/functional/legacy/arglist_spec.lua b/test/functional/legacy/arglist_spec.lua index f5e3522972..b9075620dc 100644 --- a/test/functional/legacy/arglist_spec.lua +++ b/test/functional/legacy/arglist_spec.lua @@ -269,4 +269,33 @@ describe('argument list commands', function() eq(0, eval('argidx()')) execute('%argd') end) + + + it('test for autocommand that redefines the argument list, when doing ":all"', function() + execute('autocmd BufReadPost Xxx2 next Xxx2 Xxx1') + execute("call writefile(['test file Xxx1'], 'Xxx1')") + execute("call writefile(['test file Xxx2'], 'Xxx2')") + execute("call writefile(['test file Xxx3'], 'Xxx3')") + + execute('new') + -- redefine arglist; go to Xxx1 + execute('next! Xxx1 Xxx2 Xxx3') + -- open window for all args + execute('all') + eq('test file Xxx1', eval('getline(1)')) + execute('wincmd w') + execute('wincmd w') + eq('test file Xxx1', eval('getline(1)')) + -- should now be in Xxx2 + execute('rewind') + eq('test file Xxx2', eval('getline(1)')) + + execute('autocmd! BufReadPost Xxx2') + execute('enew! | only') + execute("call delete('Xxx1')") + execute("call delete('Xxx2')") + execute("call delete('Xxx3')") + execute('argdelete Xxx*') + execute('bwipe! Xxx1 Xxx2 Xxx3') + end) end) -- cgit From 18e7d552008b92dd3ecd42bf6855530838fd22ab Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 29 Mar 2017 02:13:50 +0200 Subject: terminal.c:redraw(): Avoid invalid cursor col (#6379) Removed the call to validate_cursor() because mb_check_adjust_col() is already called in adjust_topline(). Closes #6378 References #6203 https://s3.amazonaws.com/archive.travis-ci.org/jobs/215498258/log.txt [ ERROR ] ...ovim/neovim/test/functional/terminal/scrollback_spec.lua @ 386: 'scrollback' option set to 0 behaves as 1 (10621.17 ms) ==================== File /home/travis/build/neovim/neovim/build/log/ubsan.12836 ==================== = ================================================================= = ==12836==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x62100002cd00 at pc 0x000000eafe90 bp 0x7ffc8661fe50 sp 0x7ffc8661fe48 = READ of size 1 at 0x62100002cd00 thread T0 = #0 0xeafe8f in utf_head_off /home/travis/build/neovim/neovim/src/nvim/mbyte.c:1457:7 = #1 0x6b890e in getvcol /home/travis/build/neovim/neovim/src/nvim/charset.c:1169:15 = #2 0x6bc777 in getvvcol /home/travis/build/neovim/neovim/src/nvim/charset.c:1336:5 = #3 0xfc067b in curs_columns /home/travis/build/neovim/neovim/src/nvim/move.c:730:5 = #4 0xfbc8db in validate_cursor /home/travis/build/neovim/neovim/src/nvim/move.c:510:5 = #5 0x14479ed in setcursor /home/travis/build/neovim/neovim/src/nvim/screen.c:6363:5 = #6 0x17fe054 in redraw /home/travis/build/neovim/neovim/src/nvim/terminal.c:1175:5 = #7 0x17f95e4 in terminal_enter /home/travis/build/neovim/neovim/src/nvim/terminal.c:392:3 = #8 0x70eb2b in edit /home/travis/build/neovim/neovim/src/nvim/edit.c:1300:7 = #9 0x11097d1 in normal_finish_command /home/travis/build/neovim/neovim/src/nvim/normal.c:947:13 = #10 0x1081191 in normal_execute /home/travis/build/neovim/neovim/src/nvim/normal.c:1138:3 = #11 0x170b813 in state_enter /home/travis/build/neovim/neovim/src/nvim/state.c:58:26 = #12 0x103631b in normal_enter /home/travis/build/neovim/neovim/src/nvim/normal.c:464:3 = #13 0xdfb7a8 in main /home/travis/build/neovim/neovim/src/nvim/main.c:552:3 = #14 0x2b8a3c85bf44 in __libc_start_main /build/eglibc-MjiXCM/eglibc-2.19/csu/libc-start.c:287 = #15 0x447b25 in _start (/home/travis/build/neovim/neovim/build/bin/nvim+0x447b25) = = 0x62100002cd00 is located 0 bytes to the right of 4096-byte region [0x62100002bd00,0x62100002cd00) = allocated by thread T0 here: = #0 0x4f1e98 in malloc (/home/travis/build/neovim/neovim/build/bin/nvim+0x4f1e98) = #1 0xf28774 in try_malloc /home/travis/build/neovim/neovim/src/nvim/memory.c:84:15 = #2 0xf28934 in xmalloc /home/travis/build/neovim/neovim/src/nvim/memory.c:118:15 = #3 0xec7be8 in mf_alloc_bhdr /home/travis/build/neovim/neovim/src/nvim/memfile.c:646:17 = #4 0xec58d4 in mf_new /home/travis/build/neovim/neovim/src/nvim/memfile.c:297:12 = #5 0xeda8a8 in ml_new_data /home/travis/build/neovim/neovim/src/nvim/memline.c:2697:16 = #6 0xed7beb in ml_open /home/travis/build/neovim/neovim/src/nvim/memline.c:349:8 = #7 0x643fcd in open_buffer /home/travis/build/neovim/neovim/src/nvim/buffer.c:109:7 = #8 0xa7038c in do_ecmd /home/travis/build/neovim/neovim/src/nvim/ex_cmds.c:2483:24 = #9 0xb5bb49 in do_exedit /home/travis/build/neovim/neovim/src/nvim/ex_docmd.c:6839:9 = #10 0xb7b6d8 in ex_edit /home/travis/build/neovim/neovim/src/nvim/ex_docmd.c:6767:3 = #11 0xb2a598 in do_one_cmd /home/travis/build/neovim/neovim/src/nvim/ex_docmd.c:2208:5 = #12 0xb08f47 in do_cmdline /home/travis/build/neovim/neovim/src/nvim/ex_docmd.c:602:20 = #13 0x109997b in nv_colon /home/travis/build/neovim/neovim/src/nvim/normal.c:4492:18 = #14 0x1081188 in normal_execute /home/travis/build/neovim/neovim/src/nvim/normal.c:1135:3 = #15 0x170b813 in state_enter /home/travis/build/neovim/neovim/src/nvim/state.c:58:26 = #16 0x103631b in normal_enter /home/travis/build/neovim/neovim/src/nvim/normal.c:464:3 = #17 0xdfb7a8 in main /home/travis/build/neovim/neovim/src/nvim/main.c:552:3 = #18 0x2b8a3c85bf44 in __libc_start_main /build/eglibc-MjiXCM/eglibc-2.19/csu/libc-start.c:287 = = SUMMARY: AddressSanitizer: heap-buffer-overflow /home/travis/build/neovim/neovim/src/nvim/mbyte.c:1457:7 in utf_head_off = Shadow bytes around the buggy address: = 0x0c427fffd950: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 = 0x0c427fffd960: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 = 0x0c427fffd970: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 = 0x0c427fffd980: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 = 0x0c427fffd990: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 = =>0x0c427fffd9a0:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa = 0x0c427fffd9b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa = 0x0c427fffd9c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa = 0x0c427fffd9d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa = 0x0c427fffd9e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa = 0x0c427fffd9f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa = Shadow byte legend (one shadow byte represents 8 application bytes): = Addressable: 00 = Partially addressable: 01 02 03 04 05 06 07 = Heap left redzone: fa = Heap right redzone: fb = Freed heap region: fd = Stack left redzone: f1 = Stack mid redzone: f2 = Stack right redzone: f3 = Stack partial redzone: f4 = Stack after return: f5 = Stack use after scope: f8 = Global redzone: f9 = Global init order: f6 = Poisoned by user: f7 = Container overflow: fc = Array cookie: ac = Intra object redzone: bb = ASan internal: fe = Left alloca redzone: ca = Right alloca redzone: cb = ==12836==ABORTING ===================================================================================================== ./test/helpers.lua:82: assertion failed! stack traceback: ./test/helpers.lua:82: in function 'check_logs' ./test/functional/helpers.lua:643: in function <./test/functional/helpers.lua:642> --- test/functional/terminal/cursor_spec.lua | 17 +++++++++-------- test/functional/terminal/tui_spec.lua | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/functional/terminal/cursor_spec.lua b/test/functional/terminal/cursor_spec.lua index d990f92c3a..84f14585fa 100644 --- a/test/functional/terminal/cursor_spec.lua +++ b/test/functional/terminal/cursor_spec.lua @@ -60,16 +60,17 @@ describe('terminal cursor', function() ]]) end) - pending('is positioned correctly when focused', function() + it('is positioned correctly when focused', function() feed('i') + helpers.wait() screen:expect([[ - 1 tty ready | - 2 {1: } | - 3 | - 4 | - 5 | - 6 | - -- TERMINAL -- | + {7: 1 }tty ready | + {7: 2 }{1: } | + {7: 3 } | + {7: 4 } | + {7: 5 } | + {7: 6 } | + {3:-- TERMINAL --} | ]]) end) end) diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 0e5c437c28..90051b8cd5 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -322,6 +322,7 @@ describe("tui 't_Co' (terminal colors)", function() helpers.nvim_prog)) thelpers.feed_data(":echo &t_Co\n") + helpers.wait() local tline if maxcolors == 8 then tline = "~ " -- cgit From fb146e80aa1ead96518f38b9684e39249bc83485 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 26 Jul 2016 23:16:23 +0300 Subject: eval: Split eval.c into smaller files --- test/unit/eval/decode_spec.lua | 2 +- test/unit/eval/helpers.lua | 16 ++++++++-------- test/unit/eval/tricks_spec.lua | 2 +- test/unit/eval/tv_clear_spec.lua | 12 ++++++------ 4 files changed, 16 insertions(+), 16 deletions(-) (limited to 'test') diff --git a/test/unit/eval/decode_spec.lua b/test/unit/eval/decode_spec.lua index 2d7597c0f4..0b2a423cd6 100644 --- a/test/unit/eval/decode_spec.lua +++ b/test/unit/eval/decode_spec.lua @@ -7,7 +7,7 @@ local eq = helpers.eq local neq = helpers.neq local ffi = helpers.ffi -local decode = cimport('./src/nvim/eval/decode.h', './src/nvim/eval_defs.h', +local decode = cimport('./src/nvim/eval/decode.h', './src/nvim/eval/typval.h', './src/nvim/globals.h', './src/nvim/memory.h', './src/nvim/message.h') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index 1377d5b501..49f929937f 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -5,7 +5,7 @@ local to_cstr = helpers.to_cstr local ffi = helpers.ffi local eq = helpers.eq -local eval = cimport('./src/nvim/eval.h', './src/nvim/eval_defs.h', +local eval = cimport('./src/nvim/eval.h', './src/nvim/eval/typval.h', './src/nvim/hashtab.h') local null_string = {[true]='NULL string'} @@ -33,7 +33,7 @@ local function li_alloc(nogc) end local function list(...) - local ret = ffi.gc(eval.list_alloc(), eval.list_unref) + local ret = ffi.gc(eval.tv_list_alloc(), eval.tv_list_unref) eq(0, ret.lv_refcount) ret.lv_refcount = 1 for i = 1, select('#', ...) do @@ -241,7 +241,7 @@ local typvalt = function(typ, vval) elseif type(typ) == 'string' then typ = eval[typ] end - return ffi.gc(ffi.new('typval_T', {v_type=typ, vval=vval}), eval.clear_tv) + return ffi.gc(ffi.new('typval_T', {v_type=typ, vval=vval}), eval.tv_clear) end local lua2typvalt_type_tab = { @@ -256,14 +256,14 @@ local lua2typvalt_type_tab = { processed[l].lv_refcount = processed[l].lv_refcount + 1 return typvalt(eval.VAR_LIST, {v_list=processed[l]}) end - local lst = eval.list_alloc() + local lst = eval.tv_list_alloc() lst.lv_refcount = 1 processed[l] = lst local ret = typvalt(eval.VAR_LIST, {v_list=lst}) for i = 1, #l do local item_tv = ffi.gc(lua2typvalt(l[i], processed), nil) - eval.list_append_tv(lst, item_tv) - eval.clear_tv(item_tv) + eval.tv_list_append_tv(lst, item_tv) + eval.tv_clear(item_tv) end return ret end, @@ -281,7 +281,7 @@ local lua2typvalt_type_tab = { local di = eval.dictitem_alloc(to_cstr(k)) local val_tv = ffi.gc(lua2typvalt(v, processed), nil) eval.copy_tv(val_tv, di.di_tv) - eval.clear_tv(val_tv) + eval.tv_clear(val_tv) eval.dict_add(dct, di) end end @@ -301,7 +301,7 @@ local lua2typvalt_type_tab = { for i, arg in ipairs(l.args) do local arg_tv = ffi.gc(lua2typvalt(arg, processed), nil) eval.copy_tv(arg_tv, argv[i - 1]) - eval.clear_tv(arg_tv) + eval.tv_clear(arg_tv) end end local dict = nil diff --git a/test/unit/eval/tricks_spec.lua b/test/unit/eval/tricks_spec.lua index ec79a9cad5..7f0a445f2c 100644 --- a/test/unit/eval/tricks_spec.lua +++ b/test/unit/eval/tricks_spec.lua @@ -10,7 +10,7 @@ local eval = cimport('./src/nvim/eval.h', './src/nvim/memory.h') local eval_expr = function(expr) return ffi.gc(eval.eval_expr(to_cstr(expr), nil), function(tv) - eval.clear_tv(tv) + eval.tv_clear(tv) eval.xfree(tv) end) end diff --git a/test/unit/eval/tv_clear_spec.lua b/test/unit/eval/tv_clear_spec.lua index 47d4661ad8..ca37301b32 100644 --- a/test/unit/eval/tv_clear_spec.lua +++ b/test/unit/eval/tv_clear_spec.lua @@ -14,7 +14,7 @@ local list_items = eval_helpers.list_items local dict_items = eval_helpers.dict_items local lua2typvalt = eval_helpers.lua2typvalt -local lib = cimport('./src/nvim/eval_defs.h', './src/nvim/eval.h') +local lib = cimport('./src/nvim/eval/typval.h', './src/nvim/eval.h') local alloc_log = alloc_log_new() @@ -26,7 +26,7 @@ after_each(function() alloc_log:after_each() end) -describe('clear_tv()', function() +describe('tv_clear()', function() itp('successfully frees all lists in [&l [1], *l, *l]', function() local l_inner = {1} local list = {l_inner, l_inner, l_inner} @@ -44,7 +44,7 @@ describe('clear_tv()', function() a.li(lis[3]), }) eq(3, list_inner_p.lv_refcount) - lib.clear_tv(list_tv) + lib.tv_clear(list_tv) alloc_log:check({ a.freed(lis_inner[1]), a.freed(list_inner_p), @@ -69,7 +69,7 @@ describe('clear_tv()', function() a.li(lis[3]), }) eq(3, list_inner_p.lv_refcount) - lib.clear_tv(list_tv) + lib.tv_clear(list_tv) alloc_log:check({ a.freed(list_inner_p), a.freed(lis[1]), @@ -92,7 +92,7 @@ describe('clear_tv()', function() a.li(lis[2]), }) eq(2, dict_inner_p.dv_refcount) - lib.clear_tv(list_tv) + lib.tv_clear(list_tv) alloc_log:check({ a.freed(dict_inner_p), a.freed(lis[1]), @@ -116,7 +116,7 @@ describe('clear_tv()', function() a.li(lis[2]), }) eq(2, dict_inner_p.dv_refcount) - lib.clear_tv(list_tv) + lib.tv_clear(list_tv) alloc_log:check({ a.freed(dis.a), a.freed(dict_inner_p), -- cgit From 50a48f2a0ecf7f767df961f7f5060505cf28e331 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 30 Jul 2016 01:39:32 +0300 Subject: functests: Add tests for some *buf* functions --- test/functional/eval/buf_functions_spec.lua | 300 ++++++++++++++++++++++++++++ 1 file changed, 300 insertions(+) create mode 100644 test/functional/eval/buf_functions_spec.lua (limited to 'test') diff --git a/test/functional/eval/buf_functions_spec.lua b/test/functional/eval/buf_functions_spec.lua new file mode 100644 index 0000000000..a130da4452 --- /dev/null +++ b/test/functional/eval/buf_functions_spec.lua @@ -0,0 +1,300 @@ +local helpers = require('test.functional.helpers')(after_each) + +local lfs = require('lfs') + +local eq = helpers.eq +local clear = helpers.clear +local funcs = helpers.funcs +local meths = helpers.meths +local command = helpers.command +local exc_exec = helpers.exc_exec +local bufmeths = helpers.bufmeths +local winmeths = helpers.winmeths +local curbufmeths = helpers.curbufmeths +local curwinmeths = helpers.curwinmeths +local curtabmeths = helpers.curtabmeths + +local fname = 'Xtest-functional-eval-buf_functions' +local fname2 = fname .. '.2' +local dirname = fname .. '.d' + +before_each(clear) + +for _, func in ipairs({'bufname(%s)', 'bufnr(%s)', 'bufwinnr(%s)', + 'getbufline(%s, 1)', 'getbufvar(%s, "changedtick")', + 'setbufvar(%s, "f", 0)'}) do + local funcname = func:match('%w+') + describe(funcname .. '() function', function() + it('errors out when receives v:true/v:false/v:null', function() + -- Not compatible with Vim: in Vim it always results in buffer not found + -- without any error messages. + for _, var in ipairs({'v:true', 'v:false', 'v:null'}) do + eq('Vim(call):E5300: Expected a Number or a String', + exc_exec('call ' .. func:format(var))) + end + end) + it('errors out when receives invalid argument', function() + eq('Vim(call):E745: Expected a Number or a String, List found', + exc_exec('call ' .. func:format('[]'))) + eq('Vim(call):E728: Expected a Number or a String, Dictionary found', + exc_exec('call ' .. func:format('{}'))) + eq('Vim(call):E805: Expected a Number or a String, Float found', + exc_exec('call ' .. func:format('0.0'))) + eq('Vim(call):E703: Expected a Number or a String, Funcref found', + exc_exec('call ' .. func:format('function("tr")'))) + end) + end) +end + +describe('bufname() function', function() + it('returns empty string when buffer was not found', function() + command('file ' .. fname) + eq('', funcs.bufname(2)) + eq('', funcs.bufname('non-existent-buffer')) + eq('', funcs.bufname('#')) + command('edit ' .. fname2) + eq(2, funcs.bufnr('%')) + eq('', funcs.bufname('X')) + end) + before_each(function() + lfs.mkdir(dirname) + end) + after_each(function() + lfs.rmdir(dirname) + end) + it('returns expected buffer name', function() + eq('', funcs.bufname('%')) -- Buffer has no name yet + command('file ' .. fname) + local wd = lfs.currentdir() + local curdirname = funcs.fnamemodify(wd, ':t') + for _, arg in ipairs({'%', 1, 'X', wd}) do + eq(fname, funcs.bufname(arg)) + meths.set_current_dir('..') + eq(curdirname .. '/' .. fname, funcs.bufname(arg)) + meths.set_current_dir(curdirname) + meths.set_current_dir(dirname) + eq(wd .. '/' .. fname, funcs.bufname(arg)) + meths.set_current_dir('..') + eq(fname, funcs.bufname(arg)) + command('enew') + end + eq('', funcs.bufname('%')) + eq('', funcs.bufname('$')) + eq(2, funcs.bufnr('%')) + end) +end) + +describe('bufnr() function', function() + it('returns -1 when buffer was not found', function() + command('file ' .. fname) + eq(-1, funcs.bufnr(2)) + eq(-1, funcs.bufnr('non-existent-buffer')) + eq(-1, funcs.bufnr('#')) + command('edit ' .. fname2) + eq(2, funcs.bufnr('%')) + eq(-1, funcs.bufnr('X')) + end) + it('returns expected buffer number', function() + eq(1, funcs.bufnr('%')) + command('file ' .. fname) + local wd = lfs.currentdir() + local curdirname = funcs.fnamemodify(wd, ':t') + eq(1, funcs.bufnr(fname)) + eq(1, funcs.bufnr(wd)) + eq(1, funcs.bufnr(curdirname)) + eq(1, funcs.bufnr('X')) + end) + it('returns number of last buffer with "$"', function() + eq(1, funcs.bufnr('$')) + command('new') + eq(2, funcs.bufnr('$')) + command('new') + eq(3, funcs.bufnr('$')) + command('only') + eq(3, funcs.bufnr('$')) + eq(3, funcs.bufnr('%')) + command('buffer 1') + eq(3, funcs.bufnr('$')) + eq(1, funcs.bufnr('%')) + command('bwipeout 2') + eq(3, funcs.bufnr('$')) + eq(1, funcs.bufnr('%')) + command('bwipeout 3') + eq(1, funcs.bufnr('$')) + eq(1, funcs.bufnr('%')) + command('new') + eq(4, funcs.bufnr('$')) + end) +end) + +describe('bufwinnr() function', function() + it('returns -1 when buffer was not found', function() + command('file ' .. fname) + eq(-1, funcs.bufwinnr(2)) + eq(-1, funcs.bufwinnr('non-existent-buffer')) + eq(-1, funcs.bufwinnr('#')) + command('split ' .. fname2) -- It would be OK if there was one window + eq(2, funcs.bufnr('%')) + eq(-1, funcs.bufwinnr('X')) + end) + before_each(function() + lfs.mkdir(dirname) + end) + after_each(function() + lfs.rmdir(dirname) + end) + it('returns expected window number', function() + eq(1, funcs.bufwinnr('%')) + command('file ' .. fname) + command('vsplit') + command('split ' .. fname2) + eq(2, funcs.bufwinnr(fname)) + eq(1, funcs.bufwinnr(fname2)) + eq(-1, funcs.bufwinnr(fname:sub(1, #fname - 1))) + meths.set_current_dir(dirname) + eq(2, funcs.bufwinnr(fname)) + eq(1, funcs.bufwinnr(fname2)) + eq(-1, funcs.bufwinnr(fname:sub(1, #fname - 1))) + eq(1, funcs.bufwinnr('%')) + eq(2, funcs.bufwinnr(1)) + eq(1, funcs.bufwinnr(2)) + eq(-1, funcs.bufwinnr(3)) + eq(1, funcs.bufwinnr('$')) + end) +end) + +describe('getbufline() function', function() + it('returns empty list when buffer was not found', function() + command('file ' .. fname) + eq({}, funcs.getbufline(2, 1)) + eq({}, funcs.getbufline('non-existent-buffer', 1)) + eq({}, funcs.getbufline('#', 1)) + command('edit ' .. fname2) + eq(2, funcs.bufnr('%')) + eq({}, funcs.getbufline('X', 1)) + end) + it('returns empty list when range is invalid', function() + eq({}, funcs.getbufline(1, 0)) + curbufmeths.set_lines(0, 1, false, {'foo', 'bar', 'baz'}) + eq({}, funcs.getbufline(1, 2, 1)) + eq({}, funcs.getbufline(1, -10, -20)) + eq({}, funcs.getbufline(1, -2, -1)) + eq({}, funcs.getbufline(1, -1, 9999)) + end) + it('returns expected lines', function() + meths.set_option('hidden', true) + command('file ' .. fname) + curbufmeths.set_lines(0, 1, false, {'foo\0', '\0bar', 'baz'}) + command('edit ' .. fname2) + curbufmeths.set_lines(0, 1, false, {'abc\0', '\0def', 'ghi'}) + eq({'foo\n', '\nbar', 'baz'}, funcs.getbufline(1, 1, 9999)) + eq({'abc\n', '\ndef', 'ghi'}, funcs.getbufline(2, 1, 9999)) + eq({'foo\n', '\nbar', 'baz'}, funcs.getbufline(1, 1, '$')) + eq({'baz'}, funcs.getbufline(1, '$', '$')) + eq({'baz'}, funcs.getbufline(1, '$', 9999)) + end) +end) + +describe('getbufvar() function', function() + it('returns empty list when buffer was not found', function() + command('file ' .. fname) + eq('', funcs.getbufvar(2, '&autoindent')) + eq('', funcs.getbufvar('non-existent-buffer', '&autoindent')) + eq('', funcs.getbufvar('#', '&autoindent')) + command('edit ' .. fname2) + eq(2, funcs.bufnr('%')) + eq('', funcs.getbufvar('X', '&autoindent')) + end) + it('returns empty list when variable/option/etc was not found', function() + command('file ' .. fname) + eq('', funcs.getbufvar(1, '&autondent')) + eq('', funcs.getbufvar(1, 'changedtic')) + end) + it('returns expected option value', function() + eq(0, funcs.getbufvar(1, '&autoindent')) + eq(0, funcs.getbufvar(1, '&l:autoindent')) + eq(0, funcs.getbufvar(1, '&g:autoindent')) + -- Also works with global-only options + eq(0, funcs.getbufvar(1, '&hidden')) + eq(0, funcs.getbufvar(1, '&l:hidden')) + eq(0, funcs.getbufvar(1, '&g:hidden')) + -- Also works with window-local options + eq(0, funcs.getbufvar(1, '&number')) + eq(0, funcs.getbufvar(1, '&l:number')) + eq(0, funcs.getbufvar(1, '&g:number')) + command('new') + -- But with window-local options it probably does not what you expect + curwinmeths.set_option('number', true) + -- (note that current window’s buffer is 2, but getbufvar() receives 1) + eq(2, bufmeths.get_number(curwinmeths.get_buf())) + eq(1, funcs.getbufvar(1, '&number')) + eq(1, funcs.getbufvar(1, '&l:number')) + -- You can get global value though, if you find this useful. + eq(0, funcs.getbufvar(1, '&g:number')) + end) + it('returns expected variable value', function() + eq(2, funcs.getbufvar(1, 'changedtick')) + curbufmeths.set_lines(0, 1, false, {'abc\0', '\0def', 'ghi'}) + eq(3, funcs.getbufvar(1, 'changedtick')) + curbufmeths.set_var('test', true) + eq(true, funcs.getbufvar(1, 'test')) + eq({test=true, changedtick=3}, funcs.getbufvar(1, '')) + command('new') + eq(3, funcs.getbufvar(1, 'changedtick')) + eq(true, funcs.getbufvar(1, 'test')) + eq({test=true, changedtick=3}, funcs.getbufvar(1, '')) + end) +end) + +describe('setbufvar() function', function() + it('throws the error or ignores the input when buffer was not found', function() + command('file ' .. fname) + eq(0, + exc_exec('call setbufvar(2, "&autoindent", 0)')) + eq('Vim(call):E94: No matching buffer for non-existent-buffer', + exc_exec('call setbufvar("non-existent-buffer", "&autoindent", 0)')) + eq(0, + exc_exec('call setbufvar("#", "&autoindent", 0)')) + command('edit ' .. fname2) + eq(2, funcs.bufnr('%')) + eq('Vim(call):E93: More than one match for X', + exc_exec('call setbufvar("X", "&autoindent", 0)')) + end) + it('may set options, including window-local and global values', function() + local buf1 = meths.get_current_buf() + eq(false, curwinmeths.get_option('number')) + command('split') + command('new') + eq(2, bufmeths.get_number(curwinmeths.get_buf())) + funcs.setbufvar(1, '&number', true) + local windows = curtabmeths.list_wins() + eq(false, winmeths.get_option(windows[1], 'number')) + eq(true, winmeths.get_option(windows[2], 'number')) + eq(false, winmeths.get_option(windows[3], 'number')) + eq(false, winmeths.get_option(meths.get_current_win(), 'number')) + + eq(false, meths.get_option('hidden')) + funcs.setbufvar(1, '&hidden', true) + eq(true, meths.get_option('hidden')) + + eq(false, bufmeths.get_option(buf1, 'autoindent')) + funcs.setbufvar(1, '&autoindent', true) + eq(true, bufmeths.get_option(buf1, 'autoindent')) + eq('Vim(call):E355: Unknown option: xxx', + exc_exec('call setbufvar(1, "&xxx", 0)')) + end) + it('may set variables', function() + local buf1 = meths.get_current_buf() + command('split') + command('new') + eq(2, curbufmeths.get_number()) + funcs.setbufvar(1, 'number', true) + eq(true, bufmeths.get_var(buf1, 'number')) + eq('Vim(call):E461: Illegal variable name: b:', + exc_exec('call setbufvar(1, "", 0)')) + eq(true, bufmeths.get_var(buf1, 'number')) + funcs.setbufvar(1, 'changedtick', true) + -- eq(true, bufmeths.get_var(buf1, 'changedtick')) + eq(2, funcs.getbufvar(1, 'changedtick')) + end) +end) -- cgit From e18a5783080f7c94f408ec5f53dedffdb69789e1 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 Aug 2016 22:24:34 +0300 Subject: *: Move some dictionary functions to typval.h and use char* Also fixes buffer reusage in setmatches() and complete(). --- test/functional/eval/match_functions_spec.lua | 39 ++++++++++ test/functional/eval/string_spec.lua | 10 +-- .../functional/ex_cmds/dict_notifications_spec.lua | 4 +- test/functional/ex_cmds/quickfix_commands_spec.lua | 83 ++++++++++++++++++++++ test/functional/viml/completion_spec.lua | 36 ++++++++++ test/unit/eval/helpers.lua | 6 +- 6 files changed, 164 insertions(+), 14 deletions(-) create mode 100644 test/functional/eval/match_functions_spec.lua create mode 100644 test/functional/ex_cmds/quickfix_commands_spec.lua (limited to 'test') diff --git a/test/functional/eval/match_functions_spec.lua b/test/functional/eval/match_functions_spec.lua new file mode 100644 index 0000000000..df91e41475 --- /dev/null +++ b/test/functional/eval/match_functions_spec.lua @@ -0,0 +1,39 @@ +local helpers = require('test.functional.helpers')(after_each) + +local eq = helpers.eq +local clear = helpers.clear +local funcs = helpers.funcs +local command = helpers.command + +before_each(clear) + +describe('setmatches()', function() + it('correctly handles case when both group and pattern entries are numbers', + function() + command('hi def link 1 PreProc') + eq(0, funcs.setmatches({{group=1, pattern=2, id=3, priority=4}})) + eq({{ + group='1', + pattern='2', + id=3, + priority=4, + }}, funcs.getmatches()) + eq(0, funcs.setmatches({{group=1, pattern=2, id=3, priority=4, conceal=5}})) + eq({{ + group='1', + pattern='2', + id=3, + priority=4, + conceal='5', + }}, funcs.getmatches()) + eq(0, funcs.setmatches({{group=1, pos1={2}, pos2={6}, id=3, priority=4, conceal=5}})) + eq({{ + group='1', + pos1={2}, + pos2={6}, + id=3, + priority=4, + conceal='5', + }}, funcs.getmatches()) + end) +end) diff --git a/test/functional/eval/string_spec.lua b/test/functional/eval/string_spec.lua index f6279e85e8..adc1af9b8e 100644 --- a/test/functional/eval/string_spec.lua +++ b/test/functional/eval/string_spec.lua @@ -7,7 +7,6 @@ local eval = helpers.eval local exc_exec = helpers.exc_exec local redir_exec = helpers.redir_exec local funcs = helpers.funcs -local write_file = helpers.write_file local NIL = helpers.NIL local source = helpers.source local dedent = helpers.dedent @@ -105,10 +104,8 @@ describe('string() function', function() end) describe('used to represent funcrefs', function() - local fname = 'Xtest-functional-eval-string_spec-fref-script.vim' - before_each(function() - write_file(fname, [[ + source([[ function Test1() endfunction @@ -120,11 +117,6 @@ describe('string() function', function() let g:Test2_f = function('s:Test2') ]]) - command('source ' .. fname) - end) - - after_each(function() - os.remove(fname) end) it('dumps references to built-in functions', function() diff --git a/test/functional/ex_cmds/dict_notifications_spec.lua b/test/functional/ex_cmds/dict_notifications_spec.lua index 30753c34ac..057245db1c 100644 --- a/test/functional/ex_cmds/dict_notifications_spec.lua +++ b/test/functional/ex_cmds/dict_notifications_spec.lua @@ -48,7 +48,7 @@ describe('dictionary change notifications', function() eq({'notification', 'values', {key, vals}}, next_msg()) end - describe('watcher', function() + describe(dict_expr .. ' watcher', function() if dict_init then setup(function() source(dict_init) @@ -58,7 +58,7 @@ describe('dictionary change notifications', function() before_each(function() source([[ function! g:Changed(dict, key, value) - if a:dict != ]]..dict_expr..[[ | + if a:dict isnot ]]..dict_expr..[[ | throw 'invalid dict' endif call rpcnotify(g:channel, 'values', a:key, a:value) diff --git a/test/functional/ex_cmds/quickfix_commands_spec.lua b/test/functional/ex_cmds/quickfix_commands_spec.lua new file mode 100644 index 0000000000..5ab34db3fb --- /dev/null +++ b/test/functional/ex_cmds/quickfix_commands_spec.lua @@ -0,0 +1,83 @@ +local helpers = require('test.functional.helpers')(after_each) + +local eq = helpers.eq +local clear = helpers.clear +local funcs = helpers.funcs +local command = helpers.command +local exc_exec = helpers.exc_exec +local write_file = helpers.write_file +local curbufmeths = helpers.curbufmeths + +local file_base = 'Xtest-functional-ex_cmds-quickfix_commands' + +before_each(clear) + +for _, c in ipairs({'l', 'c'}) do + local file = ('%s.%s'):format(file_base, c) + local filecmd = c .. 'file' + local getfcmd = c .. 'getfile' + local addfcmd = c .. 'addfile' + local getlist = (c == 'c') and funcs.getqflist or ( + function() return funcs.getloclist(0) end) + + describe((':%s*file commands'):format(c), function() + before_each(function() + write_file(file, ([[ + %s-1.res:700:10:Line 700 + %s-2.res:800:15:Line 800 + ]]):format(file, file)) + end) + after_each(function() + os.remove(file) + end) + + it('work', function() + command(('%s %s'):format(filecmd, file)) + -- Second line of each entry (i.e. `nr=-1, …`) was obtained from actual + -- results. First line (i.e. `{lnum=…`) was obtained from legacy test. + local list = { + {lnum=700, col=10, text='Line 700', + nr=-1, bufnr=2, valid=1, pattern='', vcol=0, ['type']=''}, + {lnum=800, col=15, text='Line 800', + nr=-1, bufnr=3, valid=1, pattern='', vcol=0, ['type']=''}, + } + eq(list, getlist()) + eq(('%s-1.res'):format(file), funcs.bufname(list[1].bufnr)) + eq(('%s-2.res'):format(file), funcs.bufname(list[2].bufnr)) + + -- Run cfile/lfile from a modified buffer + command('enew!') + curbufmeths.set_lines(1, 1, true, {'Quickfix'}) + eq(('Vim(%s):E37: No write since last change (add ! to override)'):format( + filecmd), + exc_exec(('%s %s'):format(filecmd, file))) + + write_file(file, ([[ + %s-3.res:900:30:Line 900 + ]]):format(file)) + command(('%s %s'):format(addfcmd, file)) + list[#list + 1] = { + lnum=900, col=30, text='Line 900', + nr=-1, bufnr=5, valid=1, pattern='', vcol=0, ['type']='', + } + eq(list, getlist()) + eq(('%s-3.res'):format(file), funcs.bufname(list[3].bufnr)) + + write_file(file, ([[ + %s-1.res:222:77:Line 222 + %s-2.res:333:88:Line 333 + ]]):format(file, file)) + command('enew!') + command(('%s %s'):format(getfcmd, file)) + list = { + {lnum=222, col=77, text='Line 222', + nr=-1, bufnr=2, valid=1, pattern='', vcol=0, ['type']=''}, + {lnum=333, col=88, text='Line 333', + nr=-1, bufnr=3, valid=1, pattern='', vcol=0, ['type']=''}, + } + eq(list, getlist()) + eq(('%s-1.res'):format(file), funcs.bufname(list[1].bufnr)) + eq(('%s-2.res'):format(file), funcs.bufname(list[2].bufnr)) + end) + end) +end diff --git a/test/functional/viml/completion_spec.lua b/test/functional/viml/completion_spec.lua index cd5f4260e0..3c09d71eb7 100644 --- a/test/functional/viml/completion_spec.lua +++ b/test/functional/viml/completion_spec.lua @@ -3,6 +3,7 @@ local Screen = require('test.functional.ui.screen') local clear, feed = helpers.clear, helpers.feed local eval, eq, neq = helpers.eval, helpers.eq, helpers.neq local execute, source, expect = helpers.execute, helpers.source, helpers.expect +local meths = helpers.meths if helpers.pending_win32(pending) then return end @@ -814,6 +815,41 @@ describe('completion', function() end) end) + describe('with numeric items', function() + before_each(function() + source([[ + function! TestComplete() abort + call complete(1, g:_complist) + return '' + endfunction + ]]) + meths.set_option('completeopt', 'menuone,noselect') + meths.set_var('_complist', {{ + word=0, + abbr=1, + menu=2, + kind=3, + info=4, + icase=5, + dup=6, + empty=7, + }}) + end) + + it('shows correct variant as word', function() + feed('i=TestComplete()') + screen:expect([[ + ^ | + {1:1 3 2 }{0: }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {3:-- INSERT --} | + ]]) + end) + end) end) describe('External completion popupmenu', function() diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index 49f929937f..be77ef4c83 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -272,17 +272,17 @@ local lua2typvalt_type_tab = { processed[l].dv_refcount = processed[l].dv_refcount + 1 return typvalt(eval.VAR_DICT, {v_dict=processed[l]}) end - local dct = eval.dict_alloc() + local dct = eval.tv_dict_alloc() dct.dv_refcount = 1 processed[l] = dct local ret = typvalt(eval.VAR_DICT, {v_dict=dct}) for k, v in pairs(l) do if type(k) == 'string' then - local di = eval.dictitem_alloc(to_cstr(k)) + local di = eval.tv_dict_item_alloc(to_cstr(k)) local val_tv = ffi.gc(lua2typvalt(v, processed), nil) eval.copy_tv(val_tv, di.di_tv) eval.tv_clear(val_tv) - eval.dict_add(dct, di) + eval.tv_dict_add(dct, di) end end return ret -- cgit From 54bd2e8b731376b29c150f909c6b50103bfbb91a Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 Aug 2016 22:25:57 +0300 Subject: eval: Make setmatches() return -1 in case of some failures --- test/functional/eval/match_functions_spec.lua | 7 +++++++ test/functional/legacy/063_match_and_matchadd_spec.lua | 5 ++--- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/functional/eval/match_functions_spec.lua b/test/functional/eval/match_functions_spec.lua index df91e41475..f6bad59c66 100644 --- a/test/functional/eval/match_functions_spec.lua +++ b/test/functional/eval/match_functions_spec.lua @@ -36,4 +36,11 @@ describe('setmatches()', function() conceal='5', }}, funcs.getmatches()) end) + + it('fails with -1 if highlight group is not defined', function() + eq(-1, funcs.setmatches({{group=1, pattern=2, id=3, priority=4}})) + eq({}, funcs.getmatches()) + eq(-1, funcs.setmatches({{group=1, pos1={2}, pos2={6}, id=3, priority=4, conceal=5}})) + eq({}, funcs.getmatches()) + end) end) diff --git a/test/functional/legacy/063_match_and_matchadd_spec.lua b/test/functional/legacy/063_match_and_matchadd_spec.lua index 298e0a31ea..5818bb6b3a 100644 --- a/test/functional/legacy/063_match_and_matchadd_spec.lua +++ b/test/functional/legacy/063_match_and_matchadd_spec.lua @@ -97,11 +97,10 @@ describe('063: Test for ":match", "matchadd()" and related functions', function( -- Check that "setmatches()" will not add two matches with the same ID. The -- expected behaviour (for now) is to add the first match but not the - -- second and to return 0 (even though it is a matter of debate whether - -- this can be considered successful behaviour). + -- second and to return -1. execute("let r1 = setmatches([{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}, {'group': 'MyGroup2', 'pattern': 'FIXME', 'priority': 10, 'id': 1}])") feed("") - eq(0, eval("r1")) + eq(-1, eval("r1")) eq({{group = 'MyGroup1', pattern = 'TODO', priority = 10, id = 1}}, eval('getmatches()')) -- Check that "setmatches()" returns 0 if successful and otherwise -1. -- cgit From 7ee5cc7429017a4a08a8b62b628bea156fea0008 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 28 Aug 2016 08:09:29 +0300 Subject: eval: Move get_tv_lnum and get_tv_float to eval/typval.h Additionally - Rename former tv_get_float to tv_get_float_chk due to name conflict (former get_tv_float is better suited for being tv_get_float). - Add E907 error to get_tv_float() and test that it is being raised when appropriate. --- test/functional/eval/sort_spec.lua | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 test/functional/eval/sort_spec.lua (limited to 'test') diff --git a/test/functional/eval/sort_spec.lua b/test/functional/eval/sort_spec.lua new file mode 100644 index 0000000000..4e5a0afba4 --- /dev/null +++ b/test/functional/eval/sort_spec.lua @@ -0,0 +1,41 @@ +local helpers = require('test.functional.helpers')(after_each) + +local eq = helpers.eq +local NIL = helpers.NIL +local eval = helpers.eval +local clear = helpers.clear +local meths = helpers.meths +local funcs = helpers.funcs +local command = helpers.command +local exc_exec = helpers.exc_exec + +before_each(clear) + +describe('sort()', function() + it('errors out when sorting special values', function() + eq('Vim(call):E907: Using a special value as a Float', + exc_exec('call sort([v:true, v:false], "f")')) + end) + + it('sorts “wrong” values between -0.0001 and 0.0001, preserving order', + function() + meths.set_var('list', {true, false, NIL, {}, {a=42}, 'check', + 0.0001, -0.0001}) + command('call insert(g:list, function("tr"))') + local error_lines = funcs.split( + funcs.execute('silent! call sort(g:list, "f")'), '\n') + local errors = {} + for _, err in ipairs(error_lines) do + errors[err] = true + end + eq({ + ['E891: Using a Funcref as a Float']=true, + ['E892: Using a String as a Float']=true, + ['E893: Using a List as a Float']=true, + ['E894: Using a Dictionary as a Float']=true, + ['E907: Using a special value as a Float']=true, + }, errors) + eq('[-1.0e-4, function(\'tr\'), v:true, v:false, v:null, [], {\'a\': 42}, \'check\', 1.0e-4]', + eval('string(g:list)')) + end) +end) -- cgit From c8e63a8db84e9d9f7bd855085a87d93631504fc7 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 4 Sep 2016 02:25:24 +0300 Subject: eval: Move remaining get_tv_string* functions to eval/typval.c --- test/functional/eval/input_spec.lua | 38 ++++++++++++ test/functional/eval/match_functions_spec.lua | 15 +++++ .../functional/ex_cmds/dict_notifications_spec.lua | 67 ++++++++++++++++------ 3 files changed, 102 insertions(+), 18 deletions(-) create mode 100644 test/functional/eval/input_spec.lua (limited to 'test') diff --git a/test/functional/eval/input_spec.lua b/test/functional/eval/input_spec.lua new file mode 100644 index 0000000000..393fc10175 --- /dev/null +++ b/test/functional/eval/input_spec.lua @@ -0,0 +1,38 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') + +local feed = helpers.feed +local clear = helpers.clear +local command = helpers.command + +local screen + +before_each(function() + clear() + screen = Screen.new(25, 5) + screen:attach() +end) + +describe('input()', function() + it('works correctly with multiline prompts', function() + feed([[:call input("Test\nFoo")]]) + screen:expect([[ + {1:~ }| + {1:~ }| + {1:~ }| + Test | + Foo^ | + ]], {{bold=true, foreground=Screen.colors.Blue}}) + end) + it('works correctly with multiline prompts and :echohl', function() + command('hi Test ctermfg=Red guifg=Red term=bold') + feed([[:echohl Test | call input("Test\nFoo")]]) + screen:expect([[ + {1:~ }| + {1:~ }| + {1:~ }| + {2:Test} | + {2:Foo}^ | + ]], {{bold=true, foreground=Screen.colors.Blue}, {foreground=Screen.colors.Red}}) + end) +end) diff --git a/test/functional/eval/match_functions_spec.lua b/test/functional/eval/match_functions_spec.lua index f6bad59c66..3150d89f62 100644 --- a/test/functional/eval/match_functions_spec.lua +++ b/test/functional/eval/match_functions_spec.lua @@ -44,3 +44,18 @@ describe('setmatches()', function() eq({}, funcs.getmatches()) end) end) + +describe('matchadd()', function() + it('correctly works when first two arguments and conceal are numbers at once', + function() + command('hi def link 1 PreProc') + eq(4, funcs.matchadd(1, 2, 3, 4, {conceal=5})) + eq({{ + group='1', + pattern='2', + priority=3, + id=4, + conceal='5', + }}, funcs.getmatches()) + end) +end) diff --git a/test/functional/ex_cmds/dict_notifications_spec.lua b/test/functional/ex_cmds/dict_notifications_spec.lua index 057245db1c..8cc717483e 100644 --- a/test/functional/ex_cmds/dict_notifications_spec.lua +++ b/test/functional/ex_cmds/dict_notifications_spec.lua @@ -9,7 +9,7 @@ local eval = helpers.eval describe('dictionary change notifications', function() local channel - setup(function() + before_each(function() clear() channel = nvim('get_api_info')[1] nvim('set_var', 'channel', channel) @@ -18,19 +18,15 @@ describe('dictionary change notifications', function() -- the same set of tests are applied to top-level dictionaries(g:, b:, w: and -- t:) and a dictionary variable, so we generate them in the following -- function. - local function gentests(dict_expr, dict_expr_suffix, dict_init) - if not dict_expr_suffix then - dict_expr_suffix = '' - end - + local function gentests(dict_expr, dict_init) local function update(opval, key) if not key then key = 'watched' end if opval == '' then - nvim('command', "unlet "..dict_expr..dict_expr_suffix..key) + command(('unlet %s[\'%s\']'):format(dict_expr, key)) else - nvim('command', "let "..dict_expr..dict_expr_suffix..key.." "..opval) + command(('let %s[\'%s\'] %s'):format(dict_expr, key, opval)) end end @@ -50,7 +46,7 @@ describe('dictionary change notifications', function() describe(dict_expr .. ' watcher', function() if dict_init then - setup(function() + before_each(function() source(dict_init) end) end @@ -143,6 +139,32 @@ describe('dictionary change notifications', function() ]]) end) + it('is triggered for empty keys', function() + command([[ + call dictwatcheradd(]]..dict_expr..[[, "", "g:Changed") + ]]) + update('= 1', '') + verify_value({new = 1}, '') + update('= 2', '') + verify_value({old = 1, new = 2}, '') + command([[ + call dictwatcherdel(]]..dict_expr..[[, "", "g:Changed") + ]]) + end) + + it('is triggered for empty keys when using catch-all *', function() + command([[ + call dictwatcheradd(]]..dict_expr..[[, "*", "g:Changed") + ]]) + update('= 1', '') + verify_value({new = 1}, '') + update('= 2', '') + verify_value({old = 1, new = 2}, '') + command([[ + call dictwatcherdel(]]..dict_expr..[[, "*", "g:Changed") + ]]) + end) + -- test a sequence of updates of different types to ensure proper memory -- management(with ASAN) local function test_updates(tests) @@ -190,10 +212,10 @@ describe('dictionary change notifications', function() gentests('b:') gentests('w:') gentests('t:') - gentests('g:dict_var', '.', 'let g:dict_var = {}') + gentests('g:dict_var', 'let g:dict_var = {}') describe('multiple watchers on the same dict/key', function() - setup(function() + before_each(function() source([[ function! g:Watcher1(dict, key, value) call rpcnotify(g:channel, '1', a:key, a:value) @@ -213,6 +235,9 @@ describe('dictionary change notifications', function() end) it('only removes watchers that fully match dict, key and callback', function() + nvim('command', 'let g:key = "value"') + eq({'notification', '1', {'key', {new = 'value'}}}, next_msg()) + eq({'notification', '2', {'key', {new = 'value'}}}, next_msg()) nvim('command', 'call dictwatcherdel(g:, "key", "g:Watcher1")') nvim('command', 'let g:key = "v2"') eq({'notification', '2', {'key', {old = 'value', new = 'v2'}}}, next_msg()) @@ -220,6 +245,17 @@ describe('dictionary change notifications', function() end) describe('errors', function() + before_each(function() + source([[ + function! g:Watcher1(dict, key, value) + call rpcnotify(g:channel, '1', a:key, a:value) + endfunction + function! g:Watcher2(dict, key, value) + call rpcnotify(g:channel, '2', a:key, a:value) + endfunction + ]]) + end) + -- WARNING: This suite depends on the above tests it('fails to remove if no watcher with matching callback is found', function() eq("Vim(call):Couldn't find a watcher matching key and callback", @@ -236,15 +272,10 @@ describe('dictionary change notifications', function() command('call dictwatcherdel(g:, "key", "g:InvalidCb")') end) - it('fails with empty keys', function() - eq("Vim(call):E713: Cannot use empty key for Dictionary", - exc_exec('call dictwatcheradd(g:, "", "g:Watcher1")')) - eq("Vim(call):E713: Cannot use empty key for Dictionary", - exc_exec('call dictwatcherdel(g:, "", "g:Watcher1")')) - end) - it('does not fail to replace a watcher function', function() source([[ + let g:key = 'v2' + call dictwatcheradd(g:, "key", "g:Watcher2") function! g:ReplaceWatcher2() function! g:Watcher2(dict, key, value) call rpcnotify(g:channel, '2b', a:key, a:value) -- cgit From 5df35297f832b3247c18253c916be6066c603739 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 4 Sep 2016 02:50:50 +0300 Subject: eval: Remove eval_expr() completely --- test/unit/eval/tricks_spec.lua | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/unit/eval/tricks_spec.lua b/test/unit/eval/tricks_spec.lua index 7f0a445f2c..54029734fb 100644 --- a/test/unit/eval/tricks_spec.lua +++ b/test/unit/eval/tricks_spec.lua @@ -6,13 +6,17 @@ local to_cstr = helpers.to_cstr local ffi = helpers.ffi local eq = helpers.eq -local eval = cimport('./src/nvim/eval.h', './src/nvim/memory.h') +local eval = cimport('./src/nvim/eval.h', './src/nvim/eval/typval.h', + './src/nvim/memory.h') -local eval_expr = function(expr) - return ffi.gc(eval.eval_expr(to_cstr(expr), nil), function(tv) - eval.tv_clear(tv) - eval.xfree(tv) - end) +local eval0 = function(expr) + local tv = ffi.gc(ffi.new('typval_T', {v_type=eval.VAR_UNKNOWN}), + eval.tv_clear) + if eval.eval0(to_cstr(expr), tv, nil, true) == 0 then + return nil + else + return tv + end end describe('NULL typval_T', function() @@ -25,19 +29,19 @@ describe('NULL typval_T', function() while os.getenv(unexistent_env) ~= nil do unexistent_env = unexistent_env .. '_XXX' end - local rettv = eval_expr('$' .. unexistent_env) + local rettv = eval0('$' .. unexistent_env) eq(eval.VAR_STRING, rettv.v_type) eq(nil, rettv.vval.v_string) end) itp('is produced by v:_null_list', function() - local rettv = eval_expr('v:_null_list') + local rettv = eval0('v:_null_list') eq(eval.VAR_LIST, rettv.v_type) eq(nil, rettv.vval.v_list) end) itp('is produced by v:_null_dict', function() - local rettv = eval_expr('v:_null_dict') + local rettv = eval0('v:_null_dict') eq(eval.VAR_DICT, rettv.v_type) eq(nil, rettv.vval.v_dict) end) -- cgit From 86fc4580b83f20211d7f85566e84a0e1dad0a136 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 4 Sep 2016 18:40:19 +0300 Subject: eval: Fix max_min functions Found two bugs: 1. Multiple unneeded error messages, vim/vim#1039. 2. Unformatted error string, vim/vim#1040. --- test/functional/eval/minmax_functions_spec.lua | 51 ++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test/functional/eval/minmax_functions_spec.lua (limited to 'test') diff --git a/test/functional/eval/minmax_functions_spec.lua b/test/functional/eval/minmax_functions_spec.lua new file mode 100644 index 0000000000..c6eb754f91 --- /dev/null +++ b/test/functional/eval/minmax_functions_spec.lua @@ -0,0 +1,51 @@ +local helpers = require('test.functional.helpers')(after_each) + +local eq = helpers.eq +local eval = helpers.eval +local clear = helpers.clear +local funcs = helpers.funcs +local redir_exec = helpers.redir_exec + +before_each(clear) +for _, func in ipairs({'min', 'max'}) do + describe(func .. '()', function() + it('gives a single error message when multiple values failed conversions', + function() + eq('\nE745: Using a List as a Number\n0', + redir_exec('echo ' .. func .. '([-5, [], [], [], 5])')) + eq('\nE745: Using a List as a Number\n0', + redir_exec('echo ' .. func .. '({1:-5, 2:[], 3:[], 4:[], 5:5})')) + for errmsg, errinput in pairs({ + ['E745: Using a List as a Number'] = '[]', + ['E805: Using a Float as a Number'] = '0.0', + ['E703: Using a Funcref as a Number'] = 'function("tr")', + ['E728: Using a Dictionary as a Number'] = '{}', + }) do + eq('\n' .. errmsg .. '\n0', + redir_exec('echo ' .. func .. '([' .. errinput .. '])')) + eq('\n' .. errmsg .. '\n0', + redir_exec('echo ' .. func .. '({1:' .. errinput .. '})')) + end + end) + it('works with arrays/dictionaries with zero items', function() + eq(0, funcs[func]({})) + eq(0, eval(func .. '({})')) + end) + it('works with arrays/dictionaries with one item', function() + eq(5, funcs[func]({5})) + eq(5, funcs[func]({test=5})) + end) + it('works with NULL arrays/dictionaries', function() + eq(0, eval(func .. '(v:_null_list)')) + eq(0, eval(func .. '(v:_null_dict)')) + end) + it('errors out for invalid types', function() + for _, errinput in ipairs({'1', 'v:true', 'v:false', 'v:null', + 'function("tr")', '""'}) do + eq(('\nE712: Argument of %s() must be a List or Dictionary\n0'):format( + func), + redir_exec('echo ' .. func .. '(' .. errinput .. ')')) + end + end) + end) +end -- cgit From 2ad4fba46db26d0724106b194f7cb628fb9b02e8 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 11 Sep 2016 03:37:03 +0300 Subject: eval: Move copy_tv to eval/typval --- test/unit/eval/helpers.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index be77ef4c83..c603953a05 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -280,7 +280,7 @@ local lua2typvalt_type_tab = { if type(k) == 'string' then local di = eval.tv_dict_item_alloc(to_cstr(k)) local val_tv = ffi.gc(lua2typvalt(v, processed), nil) - eval.copy_tv(val_tv, di.di_tv) + eval.tv_copy(val_tv, di.di_tv) eval.tv_clear(val_tv) eval.tv_dict_add(dct, di) end @@ -300,7 +300,7 @@ local lua2typvalt_type_tab = { argv = ffi.gc(ffi.cast('typval_T*', eval.xmalloc(ffi.sizeof('typval_T') * #l.args)), nil) for i, arg in ipairs(l.args) do local arg_tv = ffi.gc(lua2typvalt(arg, processed), nil) - eval.copy_tv(arg_tv, argv[i - 1]) + eval.tv_copy(arg_tv, argv[i - 1]) eval.tv_clear(arg_tv) end end -- cgit From a394167177390a66c275d32e3862c82c546970ff Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 12 Mar 2017 13:41:11 +0300 Subject: unittests: Test tv_list_item_\* functions To check that memory is free()d correctly. --- test/unit/eval/helpers.lua | 11 ++- test/unit/eval/typval_spec.lua | 210 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 217 insertions(+), 4 deletions(-) create mode 100644 test/unit/eval/typval_spec.lua (limited to 'test') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index c603953a05..8bf06e61f1 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -12,6 +12,7 @@ local null_string = {[true]='NULL string'} local null_list = {[true]='NULL list'} local null_dict = {[true]='NULL dict'} local type_key = {[true]='type key'} +local locks_key = {[true]='locks key'} local list_type = {[true]='list type'} local dict_type = {[true]='dict type'} local func_type = {[true]='func type'} @@ -23,9 +24,9 @@ local nil_value = {[true]='nil'} local lua2typvalt local function li_alloc(nogc) - local gcfunc = eval.listitem_free + local gcfunc = eval.tv_list_item_free if nogc then gcfunc = nil end - local li = ffi.gc(eval.listitem_alloc(), gcfunc) + local li = ffi.gc(eval.tv_list_item_alloc(), gcfunc) li.li_next = nil li.li_prev = nil li.li_tv = {v_type=eval.VAR_UNKNOWN, v_lock=eval.VAR_UNLOCKED} @@ -373,8 +374,9 @@ lua2typvalt = function(l, processed) end end +local void_ptr = ffi.typeof('void *') local function void(ptr) - return ffi.cast('void*', ptr) + return ffi.cast(void_ptr, ptr) end local alloc_logging_helpers = { @@ -386,7 +388,7 @@ local alloc_logging_helpers = { end, str = function(s, size) return {func='malloc', args={size + 1}, ret=void(s)} end, - freed = function(p) return {func='free', args={p and void(p)}} end, + freed = function(p) return {func='free', args={type(p) == 'table' and p or void(p)}} end, } return { @@ -402,6 +404,7 @@ return { nil_value=nil_value, type_key=type_key, + locks_key=locks_key, list=list, lst2tbl=lst2tbl, diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua new file mode 100644 index 0000000000..f2cb593cf5 --- /dev/null +++ b/test/unit/eval/typval_spec.lua @@ -0,0 +1,210 @@ +local helpers = require('test.unit.helpers')(after_each) +local eval_helpers = require('test.unit.eval.helpers') + +local itp = helpers.gen_itp(it) + +local eq = helpers.eq +local neq = helpers.neq +local ffi = helpers.ffi +local NULL = helpers.NULL +local cimport = helpers.cimport +local alloc_log_new = helpers.alloc_log_new + +local a = eval_helpers.alloc_logging_helpers +local list = eval_helpers.list +local lst2tbl = eval_helpers.lst2tbl +local type_key = eval_helpers.type_key +local dict_type = eval_helpers.dict_type +local lua2typvalt = eval_helpers.lua2typvalt + +local lib = cimport('./src/nvim/eval/typval.h', './src/nvim/memory.h') + +local function li_alloc(nogc) + local gcfunc = lib.tv_list_item_free + if nogc then gcfunc = nil end + local li = ffi.gc(lib.tv_list_item_alloc(), gcfunc) + li.li_next = nil + li.li_prev = nil + li.li_tv = {v_type=lib.VAR_UNKNOWN, v_lock=lib.VAR_UNLOCKED} + return li +end + +local function list_index(l, idx) + return tv_list_find(l, idx) +end + +local function list_items(l) + local lis = {} + local li = l.lv_first + for i = 1, l.lv_len do + lis[i] = li + li = li.li_next + end + return lis +end + +local function list_watch(li) + return ffi.new('listwatch_T', {lw_item=li}) +end + +local alloc_log +local restore_allocators + +local to_cstr_nofree = function(v) return lib.xstrdup(v) end + +local alloc_log = alloc_log_new() + +before_each(function() + alloc_log:before_each() +end) + +after_each(function() + alloc_log:after_each() +end) + +describe('typval.c', function() + describe('list', function() + describe('item', function() + describe('alloc()/free()', function() + itp('works', function() + local li = li_alloc(true) + neq(nil, li) + lib.tv_list_item_free(li) + alloc_log:check({ + a.li(li), + a.freed(li), + }) + end) + itp('also frees the value', function() + local li + local s + local l + local tv + li = li_alloc(true) + li.li_tv.v_type = lib.VAR_NUMBER + li.li_tv.vval.v_number = 10 + lib.tv_list_item_free(li) + alloc_log:check({ + a.li(li), + a.freed(li), + }) + + li = li_alloc(true) + li.li_tv.v_type = lib.VAR_FLOAT + li.li_tv.vval.v_float = 10.5 + lib.tv_list_item_free(li) + alloc_log:check({ + a.li(li), + a.freed(li), + }) + + li = li_alloc(true) + li.li_tv.v_type = lib.VAR_STRING + li.li_tv.vval.v_string = nil + lib.tv_list_item_free(li) + alloc_log:check({ + a.li(li), + a.freed(alloc_log.null), + a.freed(li), + }) + + li = li_alloc(true) + li.li_tv.v_type = lib.VAR_STRING + s = to_cstr_nofree('test') + li.li_tv.vval.v_string = s + lib.tv_list_item_free(li) + alloc_log:check({ + a.li(li), + a.str(s, #('test')), + a.freed(s), + a.freed(li), + }) + + li = li_alloc(true) + li.li_tv.v_type = lib.VAR_LIST + l = list() + l.lv_refcount = 2 + li.li_tv.vval.v_list = l + lib.tv_list_item_free(li) + alloc_log:check({ + a.li(li), + a.list(l), + a.freed(li), + }) + eq(1, l.lv_refcount) + + li = li_alloc(true) + tv = lua2typvalt({[type_key]=dict_type}) + tv.vval.v_dict.dv_refcount = 2 + li.li_tv = tv + lib.tv_list_item_free(li) + alloc_log:check({ + a.li(li), + a.dict(tv.vval.v_dict), + a.freed(li), + }) + eq(1, tv.vval.v_dict.dv_refcount) + end) + end) + describe('remove()', function() + itp('works', function() + local l = list(1, 2, 3, 4, 5, 6, 7) + neq(nil, l) + local lis = list_items(l) + alloc_log:check({ + a.list(l), + a.li(lis[1]), + a.li(lis[2]), + a.li(lis[3]), + a.li(lis[4]), + a.li(lis[5]), + a.li(lis[6]), + a.li(lis[7]), + }) + + lib.tv_list_item_remove(l, lis[1]) + alloc_log:check({ + a.freed(table.remove(lis, 1)), + }) + eq(lis, list_items(l)) + + lib.tv_list_item_remove(l, lis[6]) + alloc_log:check({ + a.freed(table.remove(lis)), + }) + eq(lis, list_items(l)) + + lib.tv_list_item_remove(l, lis[3]) + alloc_log:check({ + a.freed(table.remove(lis, 3)), + }) + eq(lis, list_items(l)) + end) + itp('works and adjusts watchers correctly', function() + local l = ffi.gc(list(1, 2, 3, 4, 5, 6, 7), nil) + neq(nil, l) + local lis = list_items(l) + -- Three watchers: pointing to first, middle and last elements. + local lws = {list_watch(lis[1]), list_watch(lis[4]), list_watch(lis[7])} + lib.tv_list_watch_add(l, lws[1]) + lib.tv_list_watch_add(l, lws[2]) + lib.tv_list_watch_add(l, lws[3]) + + lib.tv_list_item_remove(l, lis[4]) + eq({lis[1], lis[5], lis[7]}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item}) + + lib.tv_list_item_remove(l, lis[2]) + eq({lis[1], lis[5], lis[7]}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item}) + + lib.tv_list_item_remove(l, lis[7]) + eq({lis[1], lis[5], nil}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil}) + + lib.tv_list_item_remove(l, lis[1]) + eq({lis[3], lis[5], nil}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil}) + + lib.tv_list_free(l) + end) + end) + end) + end) +end) -- cgit From d2639e1e1d041af583dadd08e34405321fc24eea Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 14 Sep 2016 19:39:19 +0300 Subject: unittests: Add tests for list watchers and list alloc/free/unref --- test/unit/eval/typval_spec.lua | 180 +++++++++++++++++++++++++++++++++++------ 1 file changed, 154 insertions(+), 26 deletions(-) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index f2cb593cf5..0967e38eef 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -6,49 +6,48 @@ local itp = helpers.gen_itp(it) local eq = helpers.eq local neq = helpers.neq local ffi = helpers.ffi -local NULL = helpers.NULL local cimport = helpers.cimport local alloc_log_new = helpers.alloc_log_new local a = eval_helpers.alloc_logging_helpers local list = eval_helpers.list -local lst2tbl = eval_helpers.lst2tbl local type_key = eval_helpers.type_key +local li_alloc = eval_helpers.li_alloc local dict_type = eval_helpers.dict_type +local list_type = eval_helpers.list_type local lua2typvalt = eval_helpers.lua2typvalt local lib = cimport('./src/nvim/eval/typval.h', './src/nvim/memory.h') -local function li_alloc(nogc) - local gcfunc = lib.tv_list_item_free - if nogc then gcfunc = nil end - local li = ffi.gc(lib.tv_list_item_alloc(), gcfunc) - li.li_next = nil - li.li_prev = nil - li.li_tv = {v_type=lib.VAR_UNKNOWN, v_lock=lib.VAR_UNLOCKED} - return li -end - -local function list_index(l, idx) - return tv_list_find(l, idx) -end - local function list_items(l) local lis = {} local li = l.lv_first for i = 1, l.lv_len do - lis[i] = li + lis[i] = ffi.gc(li, nil) li = li.li_next end return lis end -local function list_watch(li) - return ffi.new('listwatch_T', {lw_item=li}) +local function list_watch_alloc(li) + return ffi.cast('listwatch_T*', ffi.new('listwatch_T[1]', {{lw_item=li}})) end -local alloc_log -local restore_allocators +local function list_watch(l, li) + local lw = list_watch_alloc(li or l.lv_first) + lib.tv_list_watch_add(l, lw) + return lw +end + +local function get_alloc_rets(exp_log, res) + for i = 1,#exp_log do + if ({malloc=true, calloc=true})[exp_log[i].func] then + res[#res + 1] = exp_log[i].ret + end + end + res.freed = function(r, n) return {func='free', args={r[n]}} end + return exp_log +end local to_cstr_nofree = function(v) return lib.xstrdup(v) end @@ -122,7 +121,7 @@ describe('typval.c', function() li = li_alloc(true) li.li_tv.v_type = lib.VAR_LIST - l = list() + l = ffi.gc(list(), nil) l.lv_refcount = 2 li.li_tv.vval.v_list = l lib.tv_list_item_free(li) @@ -185,26 +184,155 @@ describe('typval.c', function() neq(nil, l) local lis = list_items(l) -- Three watchers: pointing to first, middle and last elements. - local lws = {list_watch(lis[1]), list_watch(lis[4]), list_watch(lis[7])} - lib.tv_list_watch_add(l, lws[1]) - lib.tv_list_watch_add(l, lws[2]) - lib.tv_list_watch_add(l, lws[3]) + local lws = { + list_watch(l, lis[1]), + list_watch(l, lis[4]), + list_watch(l, lis[7]), + } lib.tv_list_item_remove(l, lis[4]) + ffi.gc(lis[4], lib.tv_list_item_free) eq({lis[1], lis[5], lis[7]}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item}) lib.tv_list_item_remove(l, lis[2]) + ffi.gc(lis[2], lib.tv_list_item_free) eq({lis[1], lis[5], lis[7]}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item}) lib.tv_list_item_remove(l, lis[7]) + ffi.gc(lis[7], lib.tv_list_item_free) eq({lis[1], lis[5], nil}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil}) lib.tv_list_item_remove(l, lis[1]) + ffi.gc(lis[1], lib.tv_list_item_free) eq({lis[3], lis[5], nil}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil}) + alloc_log:clear() lib.tv_list_free(l) + alloc_log:check({ + a.freed(lis[3]), + a.freed(lis[5]), + a.freed(lis[6]), + a.freed(l), + }) end) end) end) + describe('watch', function() + describe('remove()', function() + itp('works', function() + local l = ffi.gc(list(1, 2, 3, 4, 5, 6, 7), nil) + eq(nil, l.lv_watch) + local lw = list_watch(l) + neq(nil, l.lv_watch) + alloc_log:clear() + lib.tv_list_watch_remove(l, lw) + eq(nil, l.lv_watch) + alloc_log:check({ + -- Does not free anything. + }) + local lws = { list_watch(l), list_watch(l), list_watch(l) } + alloc_log:clear() + lib.tv_list_watch_remove(l, lws[2]) + eq(lws[3], l.lv_watch) + eq(lws[1], l.lv_watch.lw_next) + lib.tv_list_watch_remove(l, lws[1]) + eq(lws[3], l.lv_watch) + eq(nil, l.lv_watch.lw_next) + lib.tv_list_watch_remove(l, lws[3]) + eq(nil, l.lv_watch) + alloc_log:check({ + -- Does not free anything. + }) + end) + itp('ignores not found watchers', function() + local l = list(1, 2, 3, 4, 5, 6, 7) + local lw = list_watch_alloc() + lib.tv_list_watch_remove(l, lw) + end) + end) + end) + -- add() and fix() were tested when testing tv_list_item_remove() + describe('alloc()/free()', function() + itp('recursively frees list with', function() + local l1 = ffi.gc(list(1, 'abc'), nil) + local l2 = ffi.gc(list({[type_key]=dict_type}), nil) + local l3 = ffi.gc(list({[type_key]=list_type}), nil) + local alloc_rets = {} + alloc_log:check(get_alloc_rets({ + a.list(l1), + a.li(l1.lv_first), + a.str(l1.lv_last.li_tv.vval.v_string, #('abc')), + a.li(l1.lv_last), + a.list(l2), + a.dict(l2.lv_first.li_tv.vval.v_dict), + a.li(l2.lv_first), + a.list(l3), + a.list(l3.lv_first.li_tv.vval.v_list), + a.li(l3.lv_first), + }, alloc_rets)) + lib.tv_list_free(l1) + alloc_log:check({ + alloc_rets:freed(2), + alloc_rets:freed(3), + alloc_rets:freed(4), + alloc_rets:freed(1), + }) + lib.tv_list_free(l2) + alloc_log:check({ + alloc_rets:freed(6), + alloc_rets:freed(7), + alloc_rets:freed(5), + }) + lib.tv_list_free(l3) + alloc_log:check({ + alloc_rets:freed(9), + alloc_rets:freed(10), + alloc_rets:freed(8), + }) + end) + itp('frees all containers inside a list', function() + local l1 = ffi.gc(list('abc', {[type_key]=dict_type}, {[type_key]=list_type}), nil) + local alloc_rets = {} + alloc_log:check(get_alloc_rets({ + a.list(l1), + a.str(l1.lv_first.li_tv.vval.v_string, #('abc')), + a.li(l1.lv_first), + a.dict(l1.lv_first.li_next.li_tv.vval.v_dict), + a.li(l1.lv_first.li_next), + a.list(l1.lv_last.li_tv.vval.v_list), + a.li(l1.lv_last), + }, alloc_rets)) + lib.tv_list_free(l1) + alloc_log:check({ + alloc_rets:freed(2), + alloc_rets:freed(3), + alloc_rets:freed(4), + alloc_rets:freed(5), + alloc_rets:freed(6), + alloc_rets:freed(7), + alloc_rets:freed(1), + }) + end) + end) + describe('unref()', function() + itp('recursively frees list when reference count goes to 0', function() + local l = ffi.gc(list({[type_key]=list_type}), nil) + local alloc_rets = {} + alloc_log:check(get_alloc_rets({ + a.list(l), + a.list(l.lv_first.li_tv.vval.v_list), + a.li(l.lv_first), + }, alloc_rets)) + l.lv_refcount = 2 + lib.tv_list_unref(l) + alloc_log:check({}) + lib.tv_list_unref(l) + alloc_log:check({ + alloc_rets:freed(2), + alloc_rets:freed(3), + alloc_rets:freed(1), + }) + end) + end) end) end) -- cgit From be360d88414fa3b874262f3ed3a2bba5926a751e Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 14 Sep 2016 20:32:07 +0300 Subject: unittests: Add tests for tv_list_insert() --- test/unit/eval/typval_spec.lua | 72 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 0967e38eef..fa15686fb2 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -16,6 +16,7 @@ local li_alloc = eval_helpers.li_alloc local dict_type = eval_helpers.dict_type local list_type = eval_helpers.list_type local lua2typvalt = eval_helpers.lua2typvalt +local typvalt2lua = eval_helpers.typvalt2lua local lib = cimport('./src/nvim/eval/typval.h', './src/nvim/memory.h') @@ -334,5 +335,76 @@ describe('typval.c', function() }) end) end) + describe('remove_items()', function() + itp('works', function() + local l_tv = lua2typvalt({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}) + local l = l_tv.vval.v_list + local lis = list_items(l) + -- Three watchers: pointing to first, middle and last elements. + local lws = { + list_watch(l, lis[1]), + list_watch(l, lis[7]), + list_watch(l, lis[13]), + } + alloc_log:clear() + + lib.tv_list_remove_items(l, lis[1], lis[3]) + eq({4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, typvalt2lua(l_tv)) + eq({lis[4], lis[7], lis[13]}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item}) + + lib.tv_list_remove_items(l, lis[11], lis[13]) + eq({4, 5, 6, 7, 8, 9, 10}, typvalt2lua(l_tv)) + eq({lis[4], lis[7], nil}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil}) + + lib.tv_list_remove_items(l, lis[6], lis[8]) + eq({4, 5, 9, 10}, typvalt2lua(l_tv)) + eq({lis[4], lis[9], nil}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil}) + + lib.tv_list_remove_items(l, lis[4], lis[10]) + eq({[type_key]=list_type}, typvalt2lua(l_tv)) + eq({true, true, true}, {lws[1].lw_item == nil, lws[2].lw_item == nil, lws[3].lw_item == nil}) + + alloc_log:check({}) + end) + end) + describe('insert()', function() + itp('works', function() + local l_tv = lua2typvalt({1, 2, 3, 4, 5, 6, 7}) + local l = l_tv.vval.v_list + local lis = list_items(l) + local li + + li = li_alloc(true) + li.li_tv = {v_type=lib.VAR_FLOAT, vval={v_float=100500}} + lib.tv_list_insert(l, li, nil) + eq(l.lv_last, li) + eq({1, 2, 3, 4, 5, 6, 7, 100500}, typvalt2lua(l_tv)) + + li = li_alloc(true) + li.li_tv = {v_type=lib.VAR_FLOAT, vval={v_float=0}} + lib.tv_list_insert(l, li, lis[1]) + eq(l.lv_first, li) + eq({0, 1, 2, 3, 4, 5, 6, 7, 100500}, typvalt2lua(l_tv)) + + li = li_alloc(true) + li.li_tv = {v_type=lib.VAR_FLOAT, vval={v_float=4.5}} + lib.tv_list_insert(l, li, lis[5]) + eq(list_items(l)[6], li) + eq({0, 1, 2, 3, 4, 4.5, 5, 6, 7, 100500}, typvalt2lua(l_tv)) + end) + itp('works with an empty list', function() + local l_tv = lua2typvalt({[type_key]=list_type}) + local l = l_tv.vval.v_list + + eq(nil, l.lv_first) + eq(nil, l.lv_last) + + local li = li_alloc(true) + li.li_tv = {v_type=lib.VAR_FLOAT, vval={v_float=100500}} + lib.tv_list_insert(l, li, nil) + eq(l.lv_last, li) + eq({100500}, typvalt2lua(l_tv)) + end) + end) end) end) -- cgit From 9b8beaff021fd83770fb5510904910de2e696263 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 17 Sep 2016 04:25:49 +0300 Subject: unittests: Add tests for tv_list_insert*()/…append*() functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/unit/eval/helpers.lua | 18 +++- test/unit/eval/typval_spec.lua | 228 +++++++++++++++++++++++++++++++++++------ 2 files changed, 210 insertions(+), 36 deletions(-) (limited to 'test') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index 8bf06e61f1..f4ea6799f5 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -369,7 +369,7 @@ lua2typvalt = function(l, processed) return typvalt(eval.VAR_STRING, {v_string=eval.xmemdupz(to_cstr(l), #l)}) elseif type(l) == 'cdata' then local tv = typvalt(eval.VAR_UNKNOWN) - eval.copy_tv(l, tv) + eval.tv_copy(l, tv) return tv end end @@ -379,14 +379,28 @@ local function void(ptr) return ffi.cast(void_ptr, ptr) end +local function alloc_len(len, get_ptr) + if type(len) == 'string' or type(len) == 'table' then + return #len + elseif len == nil then + return eval.strlen(get_ptr()) + else + return len + end +end + local alloc_logging_helpers = { list = function(l) return {func='calloc', args={1, ffi.sizeof('list_T')}, ret=void(l)} end, li = function(li) return {func='malloc', args={ffi.sizeof('listitem_T')}, ret=void(li)} end, dict = function(d) return {func='malloc', args={ffi.sizeof('dict_T')}, ret=void(d)} end, di = function(di, size) + size = alloc_len(size, function() return di.di_key end) return {func='malloc', args={ffi.offsetof('dictitem_T', 'di_key') + size + 1}, ret=void(di)} end, - str = function(s, size) return {func='malloc', args={size + 1}, ret=void(s)} end, + str = function(s, size) + size = alloc_len(size, function() return s end) + return {func='malloc', args={size + 1}, ret=void(s)} + end, freed = function(p) return {func='free', args={type(p) == 'table' and p or void(p)}} end, } diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index fa15686fb2..680d5fa3b4 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -13,10 +13,14 @@ local a = eval_helpers.alloc_logging_helpers local list = eval_helpers.list local type_key = eval_helpers.type_key local li_alloc = eval_helpers.li_alloc +local int_type = eval_helpers.int_type local dict_type = eval_helpers.dict_type local list_type = eval_helpers.list_type +local null_list = eval_helpers.null_list +local null_dict = eval_helpers.null_dict local lua2typvalt = eval_helpers.lua2typvalt local typvalt2lua = eval_helpers.typvalt2lua +local null_string = eval_helpers.null_string local lib = cimport('./src/nvim/eval/typval.h', './src/nvim/memory.h') @@ -367,43 +371,199 @@ describe('typval.c', function() alloc_log:check({}) end) end) - describe('insert()', function() - itp('works', function() - local l_tv = lua2typvalt({1, 2, 3, 4, 5, 6, 7}) - local l = l_tv.vval.v_list - local lis = list_items(l) - local li - - li = li_alloc(true) - li.li_tv = {v_type=lib.VAR_FLOAT, vval={v_float=100500}} - lib.tv_list_insert(l, li, nil) - eq(l.lv_last, li) - eq({1, 2, 3, 4, 5, 6, 7, 100500}, typvalt2lua(l_tv)) - - li = li_alloc(true) - li.li_tv = {v_type=lib.VAR_FLOAT, vval={v_float=0}} - lib.tv_list_insert(l, li, lis[1]) - eq(l.lv_first, li) - eq({0, 1, 2, 3, 4, 5, 6, 7, 100500}, typvalt2lua(l_tv)) - - li = li_alloc(true) - li.li_tv = {v_type=lib.VAR_FLOAT, vval={v_float=4.5}} - lib.tv_list_insert(l, li, lis[5]) - eq(list_items(l)[6], li) - eq({0, 1, 2, 3, 4, 4.5, 5, 6, 7, 100500}, typvalt2lua(l_tv)) + describe('insert', function() + describe('()', function() + itp('works', function() + local l_tv = lua2typvalt({1, 2, 3, 4, 5, 6, 7}) + local l = l_tv.vval.v_list + local lis = list_items(l) + local li + + li = li_alloc(true) + li.li_tv = {v_type=lib.VAR_FLOAT, vval={v_float=100500}} + lib.tv_list_insert(l, li, nil) + eq(l.lv_last, li) + eq({1, 2, 3, 4, 5, 6, 7, 100500}, typvalt2lua(l_tv)) + + li = li_alloc(true) + li.li_tv = {v_type=lib.VAR_FLOAT, vval={v_float=0}} + lib.tv_list_insert(l, li, lis[1]) + eq(l.lv_first, li) + eq({0, 1, 2, 3, 4, 5, 6, 7, 100500}, typvalt2lua(l_tv)) + + li = li_alloc(true) + li.li_tv = {v_type=lib.VAR_FLOAT, vval={v_float=4.5}} + lib.tv_list_insert(l, li, lis[5]) + eq(list_items(l)[6], li) + eq({0, 1, 2, 3, 4, 4.5, 5, 6, 7, 100500}, typvalt2lua(l_tv)) + end) + itp('works with an empty list', function() + local l_tv = lua2typvalt({[type_key]=list_type}) + local l = l_tv.vval.v_list + + eq(nil, l.lv_first) + eq(nil, l.lv_last) + + local li = li_alloc(true) + li.li_tv = {v_type=lib.VAR_FLOAT, vval={v_float=100500}} + lib.tv_list_insert(l, li, nil) + eq(l.lv_last, li) + eq({100500}, typvalt2lua(l_tv)) + end) end) - itp('works with an empty list', function() - local l_tv = lua2typvalt({[type_key]=list_type}) - local l = l_tv.vval.v_list + describe('tv()', function() + itp('works', function() + local l_tv = lua2typvalt({[type_key]=list_type}) + local l = l_tv.vval.v_list + + local l_l_tv = lua2typvalt({[type_key]=list_type}) + alloc_log:clear() + local l_l = l_l_tv.vval.v_list + eq(1, l_l.lv_refcount) + lib.tv_list_insert_tv(l, l_l_tv, nil) + eq(2, l_l.lv_refcount) + eq(l_l, l.lv_first.li_tv.vval.v_list) + alloc_log:check({ + a.li(l.lv_first), + }) - eq(nil, l.lv_first) - eq(nil, l.lv_last) + local l_s_tv = lua2typvalt('test') + alloc_log:check({ + a.str(l_s_tv.vval.v_string, 'test'), + }) + lib.tv_list_insert_tv(l, l_s_tv, l.lv_first) + alloc_log:check({ + a.li(l.lv_first), + a.str(l.lv_first.li_tv.vval.v_string, 'test'), + }) + + eq({'test', {[type_key]=list_type}}, typvalt2lua(l_tv)) + end) + end) + end) + describe('append', function() + describe('list()', function() + itp('works', function() + local l_tv = lua2typvalt({[type_key]=list_type}) + local l = l_tv.vval.v_list + + local l_l = list(1) + alloc_log:clear() + eq(1, l_l.lv_refcount) + lib.tv_list_append_list(l, l_l) + eq(2, l_l.lv_refcount) + eq(l_l, l.lv_first.li_tv.vval.v_list) + alloc_log:check({ + a.li(l.lv_last), + }) + + lib.tv_list_append_list(l, nil) + alloc_log:check({ + a.li(l.lv_last), + }) + + eq({{1}, null_list}, typvalt2lua(l_tv)) + end) + end) + describe('dict()', function() + itp('works', function() + local l_tv = lua2typvalt({[type_key]=list_type}) + local l = l_tv.vval.v_list + + local l_d_tv = lua2typvalt({test=1}) + local l_d = l_d_tv.vval.v_dict + alloc_log:clear() + eq(1, l_d.dv_refcount) + lib.tv_list_append_dict(l, l_d) + eq(2, l_d.dv_refcount) + eq(l_d, l.lv_first.li_tv.vval.v_list) + alloc_log:check({ + a.li(l.lv_last), + }) - local li = li_alloc(true) - li.li_tv = {v_type=lib.VAR_FLOAT, vval={v_float=100500}} - lib.tv_list_insert(l, li, nil) - eq(l.lv_last, li) - eq({100500}, typvalt2lua(l_tv)) + lib.tv_list_append_dict(l, nil) + alloc_log:check({ + a.li(l.lv_last), + }) + + eq({{test=1}, null_dict}, typvalt2lua(l_tv)) + end) + end) + describe('string()', function() + itp('works', function() + local l_tv = lua2typvalt({[type_key]=list_type}) + local l = l_tv.vval.v_list + + alloc_log:clear() + lib.tv_list_append_string(l, 'test', 3) + alloc_log:check({ + a.str(l.lv_last.li_tv.vval.v_string, 'tes'), + a.li(l.lv_last), + }) + + lib.tv_list_append_string(l, nil, 0) + alloc_log:check({ + a.li(l.lv_last), + }) + + lib.tv_list_append_string(l, nil, -1) + alloc_log:check({ + a.li(l.lv_last), + }) + + lib.tv_list_append_string(l, 'test', -1) + alloc_log:check({ + a.str(l.lv_last.li_tv.vval.v_string, 'test'), + a.li(l.lv_last), + }) + + eq({'tes', null_string, null_string, 'test'}, typvalt2lua(l_tv)) + end) + end) + describe('allocated string()', function() + itp('works', function() + local l_tv = lua2typvalt({[type_key]=list_type}) + local l = l_tv.vval.v_list + + local s = lib.xstrdup('test') + alloc_log:clear() + lib.tv_list_append_allocated_string(l, s) + alloc_log:check({ + a.li(l.lv_last), + }) + + lib.tv_list_append_allocated_string(l, nil) + alloc_log:check({ + a.li(l.lv_last), + }) + + lib.tv_list_append_allocated_string(l, nil) + alloc_log:check({ + a.li(l.lv_last), + }) + + eq({'test', null_string, null_string}, typvalt2lua(l_tv)) + end) + end) + describe('number()', function() + itp('works', function() + local l_tv = lua2typvalt({[type_key]=list_type}) + local l = l_tv.vval.v_list + + alloc_log:clear() + lib.tv_list_append_number(l, -100500) + alloc_log:check({ + a.li(l.lv_last), + }) + + lib.tv_list_append_number(l, 100500) + alloc_log:check({ + a.li(l.lv_last), + }) + + eq({{[type_key]=int_type, value=-100500}, + {[type_key]=int_type, value=100500}}, typvalt2lua(l_tv)) + end) end) end) end) -- cgit From 9898f36aa306d2a7f53fbe08c64048260992d3bb Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 17 Sep 2016 22:06:11 +0300 Subject: unittests: Test tv_list_copy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also found some bugs: 1. var_item_copy() always fails to copy v:_null_list and v:_null_dict. Fixing this should mean fixing `deepcopy(v:_null_list)` which should’ve been, but was not listed in #4615. This also fixes `deepcopy(v:_null_dict)`. 2. var_item_copy() crashes when trying to copy NULL string with `conv != NULL`. 3. `conv` argument is ignored when copying list unless `deep` is true, but it was not reflected in documentation. 4. `tv_dict_item_alloc_len()` allocated more memory then needed. 5. typvalt2lua was not able to handle self-referencing containers. --- test/unit/eval/typval_spec.lua | 183 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 182 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 680d5fa3b4..7a6b4579f9 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -3,17 +3,21 @@ local eval_helpers = require('test.unit.eval.helpers') local itp = helpers.gen_itp(it) +local OK = helpers.OK local eq = helpers.eq local neq = helpers.neq local ffi = helpers.ffi local cimport = helpers.cimport +local to_cstr = helpers.to_cstr local alloc_log_new = helpers.alloc_log_new local a = eval_helpers.alloc_logging_helpers local list = eval_helpers.list +local lst2tbl = eval_helpers.lst2tbl local type_key = eval_helpers.type_key local li_alloc = eval_helpers.li_alloc local int_type = eval_helpers.int_type +local first_di = eval_helpers.first_di local dict_type = eval_helpers.dict_type local list_type = eval_helpers.list_type local null_list = eval_helpers.null_list @@ -22,7 +26,8 @@ local lua2typvalt = eval_helpers.lua2typvalt local typvalt2lua = eval_helpers.typvalt2lua local null_string = eval_helpers.null_string -local lib = cimport('./src/nvim/eval/typval.h', './src/nvim/memory.h') +local lib = cimport('./src/nvim/eval/typval.h', './src/nvim/memory.h', + './src/nvim/mbyte.h') local function list_items(l) local lis = {} @@ -62,6 +67,30 @@ before_each(function() alloc_log:before_each() end) +local function clear_tmp_allocs() + local toremove = {} + local allocs = {} + for i, v in ipairs(alloc_log.log) do + if v.func == 'malloc' or v.func == 'calloc' then + allocs[tostring(v.ret)] = i + elseif v.func == 'realloc' or v.func == 'free' then + if allocs[tostring(v.args[1])] then + toremove[#toremove + 1] = allocs[tostring(v.args[1])] + if v.func == 'free' then + toremove[#toremove + 1] = i + end + end + if v.func == 'realloc' then + allocs[tostring(v.ret)] = i + end + end + end + table.sort(toremove) + for i = #toremove,1,-1 do + table.remove(alloc_log.log, toremove[i]) + end +end + after_each(function() alloc_log:after_each() end) @@ -566,5 +595,157 @@ describe('typval.c', function() end) end) end) + describe('copy()', function() + local function tv_list_copy(...) + return ffi.gc(lib.tv_list_copy(...), lib.tv_list_unref) + end + itp('copies NULL correctly', function() + eq(nil, lib.tv_list_copy(nil, nil, true, 0)) + eq(nil, lib.tv_list_copy(nil, nil, false, 0)) + eq(nil, lib.tv_list_copy(nil, nil, true, 1)) + eq(nil, lib.tv_list_copy(nil, nil, false, 1)) + end) + itp('copies list correctly without converting items', function() + local v = {{['«']='»'}, {'„'}, 1, '“', null_string, null_list, null_dict} + local l_tv = lua2typvalt(v) + local l = l_tv.vval.v_list + local lis = list_items(l) + alloc_log:clear() + + eq(1, lis[1].li_tv.vval.v_dict.dv_refcount) + eq(1, lis[2].li_tv.vval.v_list.lv_refcount) + local l_copy1 = tv_list_copy(nil, l, false, 0) + eq(2, lis[1].li_tv.vval.v_dict.dv_refcount) + eq(2, lis[2].li_tv.vval.v_list.lv_refcount) + local lis_copy1 = list_items(l_copy1) + eq(lis[1].li_tv.vval.v_dict, lis_copy1[1].li_tv.vval.v_dict) + eq(lis[2].li_tv.vval.v_list, lis_copy1[2].li_tv.vval.v_list) + eq(v, lst2tbl(l_copy1)) + alloc_log:check({ + a.list(l_copy1), + a.li(lis_copy1[1]), + a.li(lis_copy1[2]), + a.li(lis_copy1[3]), + a.li(lis_copy1[4]), + a.str(lis_copy1[4].li_tv.vval.v_string, #v[4]), + a.li(lis_copy1[5]), + a.li(lis_copy1[6]), + a.li(lis_copy1[7]), + }) + lib.tv_list_free(ffi.gc(l_copy1, nil)) + alloc_log:clear() + + eq(1, lis[1].li_tv.vval.v_dict.dv_refcount) + eq(1, lis[2].li_tv.vval.v_list.lv_refcount) + local l_deepcopy1 = tv_list_copy(nil, l, true, 0) + neq(nil, l_deepcopy1) + eq(1, lis[1].li_tv.vval.v_dict.dv_refcount) + eq(1, lis[2].li_tv.vval.v_list.lv_refcount) + local lis_deepcopy1 = list_items(l_deepcopy1) + neq(lis[1].li_tv.vval.v_dict, lis_deepcopy1[1].li_tv.vval.v_dict) + neq(lis[2].li_tv.vval.v_list, lis_deepcopy1[2].li_tv.vval.v_list) + eq(v, lst2tbl(l_deepcopy1)) + local di_deepcopy1 = first_di(lis_deepcopy1[1].li_tv.vval.v_dict) + alloc_log:check({ + a.list(l_deepcopy1), + a.li(lis_deepcopy1[1]), + a.dict(lis_deepcopy1[1].li_tv.vval.v_dict), + a.di(di_deepcopy1, #('«')), + a.str(di_deepcopy1.di_tv.vval.v_string, #v[1]['«']), + a.li(lis_deepcopy1[2]), + a.list(lis_deepcopy1[2].li_tv.vval.v_list), + a.li(lis_deepcopy1[2].li_tv.vval.v_list.lv_first), + a.str(lis_deepcopy1[2].li_tv.vval.v_list.lv_first.li_tv.vval.v_string, #v[2][1]), + a.li(lis_deepcopy1[3]), + a.li(lis_deepcopy1[4]), + a.str(lis_deepcopy1[4].li_tv.vval.v_string, #v[4]), + a.li(lis_deepcopy1[5]), + a.li(lis_deepcopy1[6]), + a.li(lis_deepcopy1[7]), + }) + end) + itp('copies list correctly and converts items', function() + local vc = ffi.gc(ffi.new('vimconv_T[1]'), function(vc) + lib.convert_setup(vc, nil, nil) + end) + -- UTF-8 ↔ latin1 conversions need no iconv + eq(OK, lib.convert_setup(vc, to_cstr('utf-8'), to_cstr('latin1'))) + + local v = {{['«']='»'}, {'„'}, 1, '“', null_string, null_list, null_dict} + local l_tv = lua2typvalt(v) + local l = l_tv.vval.v_list + local lis = list_items(l) + alloc_log:clear() + + eq(1, lis[1].li_tv.vval.v_dict.dv_refcount) + eq(1, lis[2].li_tv.vval.v_list.lv_refcount) + local l_deepcopy1 = tv_list_copy(vc, l, true, 0) + neq(nil, l_deepcopy1) + eq(1, lis[1].li_tv.vval.v_dict.dv_refcount) + eq(1, lis[2].li_tv.vval.v_list.lv_refcount) + local lis_deepcopy1 = list_items(l_deepcopy1) + neq(lis[1].li_tv.vval.v_dict, lis_deepcopy1[1].li_tv.vval.v_dict) + neq(lis[2].li_tv.vval.v_list, lis_deepcopy1[2].li_tv.vval.v_list) + eq({{['\171']='\187'}, {'\191'}, 1, '\191', null_string, null_list, null_dict}, + lst2tbl(l_deepcopy1)) + local di_deepcopy1 = first_di(lis_deepcopy1[1].li_tv.vval.v_dict) + clear_tmp_allocs() + alloc_log:check({ + a.list(l_deepcopy1), + a.li(lis_deepcopy1[1]), + a.dict(lis_deepcopy1[1].li_tv.vval.v_dict), + a.di(di_deepcopy1, 1), + a.str(di_deepcopy1.di_tv.vval.v_string, 2), + a.li(lis_deepcopy1[2]), + a.list(lis_deepcopy1[2].li_tv.vval.v_list), + a.li(lis_deepcopy1[2].li_tv.vval.v_list.lv_first), + a.str(lis_deepcopy1[2].li_tv.vval.v_list.lv_first.li_tv.vval.v_string, #v[2][1]), + a.li(lis_deepcopy1[3]), + a.li(lis_deepcopy1[4]), + a.str(lis_deepcopy1[4].li_tv.vval.v_string, #v[4]), + a.li(lis_deepcopy1[5]), + a.li(lis_deepcopy1[6]), + a.li(lis_deepcopy1[7]), + }) + end) + itp('returns different/same containers with(out) copyID', function() + local l_inner_tv = lua2typvalt({[type_key]=list_type}) + local l_tv = lua2typvalt({l_inner_tv, l_inner_tv}) + eq(3, l_inner_tv.vval.v_list.lv_refcount) + local l = l_tv.vval.v_list + eq(l.lv_first.li_tv.vval.v_list, l.lv_last.li_tv.vval.v_list) + + local l_copy1 = tv_list_copy(nil, l, true, 0) + neq(l_copy1.lv_first.li_tv.vval.v_list, l_copy1.lv_last.li_tv.vval.v_list) + eq({{[type_key]=list_type}, {[type_key]=list_type}}, lst2tbl(l_copy1)) + + local l_copy2 = tv_list_copy(nil, l, true, 2) + eq(l_copy2.lv_first.li_tv.vval.v_list, l_copy2.lv_last.li_tv.vval.v_list) + eq({{[type_key]=list_type}, {[type_key]=list_type}}, lst2tbl(l_copy2)) + + eq(3, l_inner_tv.vval.v_list.lv_refcount) + end) + itp('works with self-referencing list with copyID', function() + local l_tv = lua2typvalt({[type_key]=list_type}) + local l = l_tv.vval.v_list + eq(1, l.lv_refcount) + lib.tv_list_append_list(l, l) + eq(2, l.lv_refcount) + + local l_copy1 = tv_list_copy(nil, l, true, 2) + eq(2, l_copy1.lv_refcount) + local v = {} + v[1] = v + eq(v, lst2tbl(l_copy1)) + + local lis = list_items(l) + lib.tv_list_item_remove(l, lis[1]) + eq(1, l.lv_refcount) + + local lis_copy1 = list_items(l_copy1) + lib.tv_list_item_remove(l_copy1, lis_copy1[1]) + eq(1, l_copy1.lv_refcount) + end) + end) end) end) -- cgit From 82e6cac5f9d437da5aeb8c4cf51945cfeb5922ff Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 18 Sep 2016 01:54:23 +0300 Subject: functests: Add null_spec.lua from #4615 For now it is full of FIXMEs and tests for incorrect behaviour. Sorted out to have FIXMEs in one place, commented crashing tests in other and correctly working tests in the third one. --- test/functional/eval/null_spec.lua | 141 +++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 test/functional/eval/null_spec.lua (limited to 'test') diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua new file mode 100644 index 0000000000..9a35905be0 --- /dev/null +++ b/test/functional/eval/null_spec.lua @@ -0,0 +1,141 @@ +local helpers = require('test.functional.helpers')(after_each) + +local curbufmeths = helpers.curbufmeths +local redir_exec = helpers.redir_exec +local exc_exec = helpers.exc_exec +local command = helpers.command +local clear = helpers.clear +local meths = helpers.meths +local funcs = helpers.funcs +local eq = helpers.eq + +describe('NULL', function() + before_each(function() + clear() + command('let L = v:_null_list') + command('let D = v:_null_dict') + command('let S = $XXX_NONEXISTENT_VAR_XXX') + end) + local tmpfname = 'Xtest-functional-viml-null' + after_each(function() + os.remove(tmpfname) + end) + describe('list', function() + local null_list_test = function(name, cmd, err) + it(name, function() + eq(err, exc_exec(cmd)) + end) + end + local null_list_expr_test = function(name, expr, err, val, after) + it(name, function() + eq((err == 0) and ('') or ('\n' .. err), + redir_exec('let g:_var = ' .. expr)) + if val == nil then + eq(0, funcs.exists('g:_var')) + else + eq(val, meths.get_var('_var')) + end + if after ~= nil then + after() + end + end) + end + + -- Incorrect behaviour + + -- FIXME map() should not return 0 without error + null_list_expr_test('does not crash map()', 'map(L, "v:val")', 0, 0) + -- FIXME map() should not return 0 without error + null_list_expr_test('does not crash filter()', 'filter(L, "1")', 0, 0) + -- FIXME map() should at least return L + null_list_expr_test('makes map() return v:_null_list', 'map(L, "v:val") is# L', 0, 0) + -- FIXME filter() should at least return L + null_list_expr_test('makes filter() return v:_null_list', 'map(L, "1") is# L', 0, 0) + -- FIXME add() should not return 1 at all + null_list_expr_test('does not crash add()', 'add(L, 0)', 0, 1) + -- FIXME extend() should not return 0 without error + null_list_expr_test('does not crash extend()', 'extend(L, [1])', 0, 0) + -- FIXME extend() should not return 0 at all + null_list_expr_test('does not crash extend() (second position)', 'extend([1], L)', 0, 0) + -- FIXME Should return 1 + null_list_expr_test('is equal to itself', 'L == L', 0, 0) + -- FIXME Should return 0 + null_list_expr_test('is not not equal to itself', 'L != L', 0, 1) + -- FIXME Should return empty list + null_list_expr_test('can be added to itself', '(L + L)', 'E15: Invalid expression: (L + L)', nil) + -- FIXME Should return [1] + null_list_expr_test('can be added to non-empty list (reversed)', '(L + [1])', + 'E15: Invalid expression: (L + [1])', nil) + -- FIXME Should return [1] + null_list_expr_test('can be added to non-empty list', '([1] + L)', + 'E15: Invalid expression: ([1] + L)', nil) + -- FIXME Should return 1 + null_list_expr_test('counts correctly', 'count([L], L)', 0, 0) + -- FIXME should be accepted by inputlist() + null_list_expr_test('is accepted as an empty list by inputlist()', + '[feedkeys("\\n"), inputlist(L)]', 'E686: Argument of inputlist() must be a List', {0, 0}) + -- FIXME should be accepted by writefile(), return {0, {}} + null_list_expr_test('is accepted as an empty list by writefile()', + ('[writefile(L, "%s"), readfile("%s")]'):format(tmpfname, tmpfname), + 'E484: Can\'t open file ' .. tmpfname, {0, {}}) + -- FIXME should give error message + null_list_expr_test('does not crash remove()', 'remove(L, 0)', 0, 0) + -- FIXME should return 0 + null_list_expr_test('is accepted by setqflist()', 'setqflist(L)', 0, -1) + -- FIXME should return 0 + null_list_expr_test('is accepted by setloclist()', 'setloclist(1, L)', 0, -1) + -- FIXME should return 0 + null_list_expr_test('is accepted by setmatches()', 'setmatches(L)', 0, -1) + -- FIXME should return empty list or error out + null_list_expr_test('is accepted by sort()', 'sort(L)', 0, 0) + -- FIXME Should return 1 + null_list_expr_test('is accepted by sort()', 'sort(L) is L', 0, 0) + -- FIXME should not error out + null_list_test('is accepted by :cexpr', 'cexpr L', 'Vim(cexpr):E777: String or List expected') + -- FIXME should not error out + null_list_test('is accepted by :lexpr', 'lexpr L', 'Vim(lexpr):E777: String or List expected') + -- FIXME should not error out + null_list_test('is accepted by :for', 'for x in L|throw x|endfor', 'Vim(for):E714: List required') + + -- Subjectable behaviour + + -- FIXME Should return 1 + null_list_expr_test('is equal to empty list', 'L == []', 0, 0) + -- FIXME Should return 1 + null_list_expr_test('is equal to empty list (reverse order)', '[] == L', 0, 0) + -- FIXME Should return 1 + null_list_expr_test('is not locked', 'islocked("v:_null_list")', 0, 0) + + -- Crashes + + -- null_list_expr_test('does not crash setreg', 'setreg("x", L)', 0, 0) + -- null_list_expr_test('does not crash setline', 'setline(1, L)', 0, 0) + -- null_list_expr_test('does not crash system()', 'system("cat", L)', 0, '') + -- null_list_expr_test('does not crash systemlist()', 'systemlist("cat", L)', 0, {}) + + -- Correct behaviour + null_list_expr_test('does not crash append()', 'append(1, L)', 0, 0, function() + eq({''}, curbufmeths.get_lines(0, -1, false)) + end) + null_list_expr_test('is identical to itself', 'L is L', 0, 1) + null_list_expr_test('can be sliced', 'L[:]', 0, {}) + null_list_expr_test('can be copied', 'copy(L)', 0, {}) + null_list_expr_test('can be deepcopied', 'deepcopy(L)', 0, {}) + null_list_expr_test('does not crash when indexed', 'L[1]', + 'E684: list index out of range: 1\nE15: Invalid expression: L[1]', nil) + null_list_expr_test('does not crash call()', 'call("arglistid", L)', 0, 0) + null_list_expr_test('does not crash col()', 'col(L)', 0, 0) + null_list_expr_test('does not crash virtcol()', 'virtcol(L)', 0, 0) + null_list_expr_test('does not crash line()', 'line(L)', 0, 0) + null_list_expr_test('does not crash count()', 'count(L, 1)', 0, 0) + null_list_expr_test('does not crash cursor()', 'cursor(L)', 'E474: Invalid argument', -1) + null_list_expr_test('is empty', 'empty(L)', 0, 1) + null_list_expr_test('does not crash get()', 'get(L, 1, 10)', 0, 10) + null_list_expr_test('has zero length', 'len(L)', 0, 0) + null_list_expr_test('is accepted as an empty list by max()', 'max(L)', 0, 0) + null_list_expr_test('is accepted as an empty list by min()', 'min(L)', 0, 0) + null_list_expr_test('is stringified correctly', 'string(L)', 0, '[]') + null_list_expr_test('is JSON encoded correctly', 'json_encode(L)', 0, '[]') + null_list_test('does not crash lockvar', 'lockvar! L', 0) + end) +end) -- cgit From f80a00469fdba8a3dec0edae30c911d050485055 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 18 Sep 2016 01:59:07 +0300 Subject: eval/typval: Make tv_list_concat handle NULL lists correctly Fixes some FIXMEs in eval/null_spec.lua. --- test/functional/eval/null_spec.lua | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua index 9a35905be0..ccdd1ce34c 100644 --- a/test/functional/eval/null_spec.lua +++ b/test/functional/eval/null_spec.lua @@ -61,14 +61,6 @@ describe('NULL', function() null_list_expr_test('is equal to itself', 'L == L', 0, 0) -- FIXME Should return 0 null_list_expr_test('is not not equal to itself', 'L != L', 0, 1) - -- FIXME Should return empty list - null_list_expr_test('can be added to itself', '(L + L)', 'E15: Invalid expression: (L + L)', nil) - -- FIXME Should return [1] - null_list_expr_test('can be added to non-empty list (reversed)', '(L + [1])', - 'E15: Invalid expression: (L + [1])', nil) - -- FIXME Should return [1] - null_list_expr_test('can be added to non-empty list', '([1] + L)', - 'E15: Invalid expression: ([1] + L)', nil) -- FIXME Should return 1 null_list_expr_test('counts correctly', 'count([L], L)', 0, 0) -- FIXME should be accepted by inputlist() @@ -137,5 +129,9 @@ describe('NULL', function() null_list_expr_test('is stringified correctly', 'string(L)', 0, '[]') null_list_expr_test('is JSON encoded correctly', 'json_encode(L)', 0, '[]') null_list_test('does not crash lockvar', 'lockvar! L', 0) + null_list_expr_test('can be added to itself', '(L + L)', 0, {}) + null_list_expr_test('can be added to itself', '(L + L) is L', 0, 1) + null_list_expr_test('can be added to non-empty list', '([1] + L)', 0, {1}) + null_list_expr_test('can be added to non-empty list (reversed)', '(L + [1])', 0, {1}) end) end) -- cgit From 56e4c2f67e54b88f637d30e565313bc6b2c22f29 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 19 Sep 2016 00:50:07 +0300 Subject: unittests: Test tv_list_concat() --- test/unit/eval/typval_spec.lua | 142 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 7a6b4579f9..2cc22053f3 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -14,6 +14,7 @@ local alloc_log_new = helpers.alloc_log_new local a = eval_helpers.alloc_logging_helpers local list = eval_helpers.list local lst2tbl = eval_helpers.lst2tbl +local typvalt = eval_helpers.typvalt local type_key = eval_helpers.type_key local li_alloc = eval_helpers.li_alloc local int_type = eval_helpers.int_type @@ -747,5 +748,146 @@ describe('typval.c', function() eq(1, l_copy1.lv_refcount) end) end) + describe('concat()', function() + itp('works with NULL lists', function() + local l = list(1, {}) + alloc_log:clear() + eq(1, l.lv_refcount) + eq(1, l.lv_last.li_tv.vval.v_dict.dv_refcount) + + local rettv1 = typvalt() + eq(OK, lib.tv_list_concat(nil, l, rettv1)) + eq(1, l.lv_refcount) + eq(tonumber(lib.VAR_LIST), tonumber(rettv1.v_type)) + eq({1, {}}, typvalt2lua(rettv1)) + eq(1, rettv1.vval.v_list.lv_refcount) + alloc_log:check({ + a.list(rettv1.vval.v_list), + a.li(rettv1.vval.v_list.lv_first), + a.li(rettv1.vval.v_list.lv_last), + }) + eq(2, l.lv_last.li_tv.vval.v_dict.dv_refcount) + + local rettv2 = typvalt() + eq(OK, lib.tv_list_concat(l, nil, rettv2)) + eq(1, l.lv_refcount) + eq(tonumber(lib.VAR_LIST), tonumber(rettv2.v_type)) + eq({1, {}}, typvalt2lua(rettv2)) + eq(1, rettv2.vval.v_list.lv_refcount) + alloc_log:check({ + a.list(rettv2.vval.v_list), + a.li(rettv2.vval.v_list.lv_first), + a.li(rettv2.vval.v_list.lv_last), + }) + eq(3, l.lv_last.li_tv.vval.v_dict.dv_refcount) + + local rettv3 = typvalt() + eq(OK, lib.tv_list_concat(nil, nil, rettv3)) + eq(tonumber(lib.VAR_LIST), tonumber(rettv3.v_type)) + eq(null_list, typvalt2lua(rettv3)) + alloc_log:check({}) + end) + itp('works with two different lists', function() + local l1 = list(1, {}) + local l2 = list(3, {[type_key]=list_type}) + eq(1, l1.lv_refcount) + eq(1, l1.lv_last.li_tv.vval.v_dict.dv_refcount) + eq(1, l2.lv_refcount) + eq(1, l2.lv_last.li_tv.vval.v_list.lv_refcount) + alloc_log:clear() + + local rettv = typvalt() + eq(OK, lib.tv_list_concat(l1, l2, rettv)) + eq(1, l1.lv_refcount) + eq(2, l1.lv_last.li_tv.vval.v_dict.dv_refcount) + eq(1, l2.lv_refcount) + eq(2, l2.lv_last.li_tv.vval.v_list.lv_refcount) + alloc_log:check({ + a.list(rettv.vval.v_list), + a.li(rettv.vval.v_list.lv_first), + a.li(rettv.vval.v_list.lv_first.li_next), + a.li(rettv.vval.v_list.lv_last.li_prev), + a.li(rettv.vval.v_list.lv_last), + }) + eq({1, {}, 3, {[type_key]=list_type}}, typvalt2lua(rettv)) + end) + itp('can concatenate list with itself', function() + local l = list(1, {}) + eq(1, l.lv_refcount) + eq(1, l.lv_last.li_tv.vval.v_dict.dv_refcount) + alloc_log:clear() + + local rettv = typvalt() + eq(OK, lib.tv_list_concat(l, l, rettv)) + eq(1, l.lv_refcount) + eq(3, l.lv_last.li_tv.vval.v_dict.dv_refcount) + alloc_log:check({ + a.list(rettv.vval.v_list), + a.li(rettv.vval.v_list.lv_first), + a.li(rettv.vval.v_list.lv_first.li_next), + a.li(rettv.vval.v_list.lv_last.li_prev), + a.li(rettv.vval.v_list.lv_last), + }) + eq({1, {}, 1, {}}, typvalt2lua(rettv)) + end) + itp('can concatenate empty non-NULL lists', function() + local l = list(1, {}) + local le = list() + local le2 = list() + eq(1, l.lv_refcount) + eq(1, l.lv_last.li_tv.vval.v_dict.dv_refcount) + eq(1, le.lv_refcount) + eq(1, le2.lv_refcount) + alloc_log:clear() + + local rettv1 = typvalt() + eq(OK, lib.tv_list_concat(l, le, rettv1)) + eq(1, l.lv_refcount) + eq(2, l.lv_last.li_tv.vval.v_dict.dv_refcount) + eq(1, le.lv_refcount) + eq(1, le2.lv_refcount) + alloc_log:check({ + a.list(rettv1.vval.v_list), + a.li(rettv1.vval.v_list.lv_first), + a.li(rettv1.vval.v_list.lv_last), + }) + eq({1, {}}, typvalt2lua(rettv1)) + + local rettv2 = typvalt() + eq(OK, lib.tv_list_concat(le, l, rettv2)) + eq(1, l.lv_refcount) + eq(3, l.lv_last.li_tv.vval.v_dict.dv_refcount) + eq(1, le.lv_refcount) + eq(1, le2.lv_refcount) + alloc_log:check({ + a.list(rettv2.vval.v_list), + a.li(rettv2.vval.v_list.lv_first), + a.li(rettv2.vval.v_list.lv_last), + }) + eq({1, {}}, typvalt2lua(rettv2)) + + local rettv3 = typvalt() + eq(OK, lib.tv_list_concat(le, le, rettv3)) + eq(1, l.lv_refcount) + eq(3, l.lv_last.li_tv.vval.v_dict.dv_refcount) + eq(1, le.lv_refcount) + eq(1, le2.lv_refcount) + alloc_log:check({ + a.list(rettv3.vval.v_list), + }) + eq({[type_key]=list_type}, typvalt2lua(rettv3)) + + local rettv4 = typvalt() + eq(OK, lib.tv_list_concat(le, le2, rettv4)) + eq(1, l.lv_refcount) + eq(3, l.lv_last.li_tv.vval.v_dict.dv_refcount) + eq(1, le.lv_refcount) + eq(1, le2.lv_refcount) + alloc_log:check({ + a.list(rettv4.vval.v_list), + }) + eq({[type_key]=list_type}, typvalt2lua(rettv4)) + end) + end) end) end) -- cgit From 7ceebacb3fad49ba8321397cf839948caa55b3f5 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 24 Sep 2016 00:51:34 +0300 Subject: eval/typval,tests: Fix extending list with itself, add tests Adds unit test for tv_list_extend and regression test for extend() VimL function. --- test/functional/eval/container_functions_spec.lua | 24 +++ test/unit/eval/helpers.lua | 2 + test/unit/eval/typval_spec.lua | 184 +++++++++++++++++++--- 3 files changed, 184 insertions(+), 26 deletions(-) create mode 100644 test/functional/eval/container_functions_spec.lua (limited to 'test') diff --git a/test/functional/eval/container_functions_spec.lua b/test/functional/eval/container_functions_spec.lua new file mode 100644 index 0000000000..04a3248c49 --- /dev/null +++ b/test/functional/eval/container_functions_spec.lua @@ -0,0 +1,24 @@ +local helpers = require('test.functional.helpers')(after_each) + +local eq = helpers.eq +local eval = helpers.eval +local meths = helpers.meths +local clear = helpers.clear + +before_each(clear) + +describe('extend()', function() + it('suceeds to extend list with itself', function() + meths.set_var('l', {1, {}}) + eq({1, {}, 1, {}}, eval('extend(l, l)')) + eq({1, {}, 1, {}}, meths.get_var('l')) + + meths.set_var('l', {1, {}}) + eq({1, {}, 1, {}}, eval('extend(l, l, 0)')) + eq({1, {}, 1, {}}, meths.get_var('l')) + + meths.set_var('l', {1, {}}) + eq({1, 1, {}, {}}, eval('extend(l, l, 1)')) + eq({1, 1, {}, {}}, meths.get_var('l')) + end) +end) diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index f4ea6799f5..eea5cc8880 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -439,4 +439,6 @@ return { list_items=list_items, dict_items=dict_items, + + empty_list = {[type_key]=list_type}, } diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 2cc22053f3..926bf1c478 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -19,10 +19,9 @@ local type_key = eval_helpers.type_key local li_alloc = eval_helpers.li_alloc local int_type = eval_helpers.int_type local first_di = eval_helpers.first_di -local dict_type = eval_helpers.dict_type -local list_type = eval_helpers.list_type local null_list = eval_helpers.null_list local null_dict = eval_helpers.null_dict +local empty_list = eval_helpers.empty_list local lua2typvalt = eval_helpers.lua2typvalt local typvalt2lua = eval_helpers.typvalt2lua local null_string = eval_helpers.null_string @@ -168,7 +167,7 @@ describe('typval.c', function() eq(1, l.lv_refcount) li = li_alloc(true) - tv = lua2typvalt({[type_key]=dict_type}) + tv = lua2typvalt({}) tv.vval.v_dict.dv_refcount = 2 li.li_tv = tv lib.tv_list_item_free(li) @@ -290,8 +289,8 @@ describe('typval.c', function() describe('alloc()/free()', function() itp('recursively frees list with', function() local l1 = ffi.gc(list(1, 'abc'), nil) - local l2 = ffi.gc(list({[type_key]=dict_type}), nil) - local l3 = ffi.gc(list({[type_key]=list_type}), nil) + local l2 = ffi.gc(list({}), nil) + local l3 = ffi.gc(list(empty_list), nil) local alloc_rets = {} alloc_log:check(get_alloc_rets({ a.list(l1), @@ -325,8 +324,8 @@ describe('typval.c', function() alloc_rets:freed(8), }) end) - itp('frees all containers inside a list', function() - local l1 = ffi.gc(list('abc', {[type_key]=dict_type}, {[type_key]=list_type}), nil) + itp('does not free container items with recurse=false', function() + local l1 = ffi.gc(list('abc', {}, empty_list), nil) local alloc_rets = {} alloc_log:check(get_alloc_rets({ a.list(l1), @@ -351,7 +350,7 @@ describe('typval.c', function() end) describe('unref()', function() itp('recursively frees list when reference count goes to 0', function() - local l = ffi.gc(list({[type_key]=list_type}), nil) + local l = ffi.gc(list(empty_list), nil) local alloc_rets = {} alloc_log:check(get_alloc_rets({ a.list(l), @@ -395,7 +394,7 @@ describe('typval.c', function() eq({lis[4], lis[9], nil}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil}) lib.tv_list_remove_items(l, lis[4], lis[10]) - eq({[type_key]=list_type}, typvalt2lua(l_tv)) + eq(empty_list, typvalt2lua(l_tv)) eq({true, true, true}, {lws[1].lw_item == nil, lws[2].lw_item == nil, lws[3].lw_item == nil}) alloc_log:check({}) @@ -428,7 +427,7 @@ describe('typval.c', function() eq({0, 1, 2, 3, 4, 4.5, 5, 6, 7, 100500}, typvalt2lua(l_tv)) end) itp('works with an empty list', function() - local l_tv = lua2typvalt({[type_key]=list_type}) + local l_tv = lua2typvalt(empty_list) local l = l_tv.vval.v_list eq(nil, l.lv_first) @@ -443,10 +442,10 @@ describe('typval.c', function() end) describe('tv()', function() itp('works', function() - local l_tv = lua2typvalt({[type_key]=list_type}) + local l_tv = lua2typvalt(empty_list) local l = l_tv.vval.v_list - local l_l_tv = lua2typvalt({[type_key]=list_type}) + local l_l_tv = lua2typvalt(empty_list) alloc_log:clear() local l_l = l_l_tv.vval.v_list eq(1, l_l.lv_refcount) @@ -467,14 +466,14 @@ describe('typval.c', function() a.str(l.lv_first.li_tv.vval.v_string, 'test'), }) - eq({'test', {[type_key]=list_type}}, typvalt2lua(l_tv)) + eq({'test', empty_list}, typvalt2lua(l_tv)) end) end) end) describe('append', function() describe('list()', function() itp('works', function() - local l_tv = lua2typvalt({[type_key]=list_type}) + local l_tv = lua2typvalt(empty_list) local l = l_tv.vval.v_list local l_l = list(1) @@ -497,7 +496,7 @@ describe('typval.c', function() end) describe('dict()', function() itp('works', function() - local l_tv = lua2typvalt({[type_key]=list_type}) + local l_tv = lua2typvalt(empty_list) local l = l_tv.vval.v_list local l_d_tv = lua2typvalt({test=1}) @@ -521,7 +520,7 @@ describe('typval.c', function() end) describe('string()', function() itp('works', function() - local l_tv = lua2typvalt({[type_key]=list_type}) + local l_tv = lua2typvalt(empty_list) local l = l_tv.vval.v_list alloc_log:clear() @@ -552,7 +551,7 @@ describe('typval.c', function() end) describe('allocated string()', function() itp('works', function() - local l_tv = lua2typvalt({[type_key]=list_type}) + local l_tv = lua2typvalt(empty_list) local l = l_tv.vval.v_list local s = lib.xstrdup('test') @@ -577,7 +576,7 @@ describe('typval.c', function() end) describe('number()', function() itp('works', function() - local l_tv = lua2typvalt({[type_key]=list_type}) + local l_tv = lua2typvalt(empty_list) local l = l_tv.vval.v_list alloc_log:clear() @@ -710,7 +709,7 @@ describe('typval.c', function() }) end) itp('returns different/same containers with(out) copyID', function() - local l_inner_tv = lua2typvalt({[type_key]=list_type}) + local l_inner_tv = lua2typvalt(empty_list) local l_tv = lua2typvalt({l_inner_tv, l_inner_tv}) eq(3, l_inner_tv.vval.v_list.lv_refcount) local l = l_tv.vval.v_list @@ -718,16 +717,16 @@ describe('typval.c', function() local l_copy1 = tv_list_copy(nil, l, true, 0) neq(l_copy1.lv_first.li_tv.vval.v_list, l_copy1.lv_last.li_tv.vval.v_list) - eq({{[type_key]=list_type}, {[type_key]=list_type}}, lst2tbl(l_copy1)) + eq({empty_list, empty_list}, lst2tbl(l_copy1)) local l_copy2 = tv_list_copy(nil, l, true, 2) eq(l_copy2.lv_first.li_tv.vval.v_list, l_copy2.lv_last.li_tv.vval.v_list) - eq({{[type_key]=list_type}, {[type_key]=list_type}}, lst2tbl(l_copy2)) + eq({empty_list, empty_list}, lst2tbl(l_copy2)) eq(3, l_inner_tv.vval.v_list.lv_refcount) end) itp('works with self-referencing list with copyID', function() - local l_tv = lua2typvalt({[type_key]=list_type}) + local l_tv = lua2typvalt(empty_list) local l = l_tv.vval.v_list eq(1, l.lv_refcount) lib.tv_list_append_list(l, l) @@ -748,6 +747,139 @@ describe('typval.c', function() eq(1, l_copy1.lv_refcount) end) end) + describe('extend()', function() + itp('can extend list with itself', function() + local l + + l = list(1, {}) + alloc_log:clear() + eq(1, l.lv_refcount) + eq(1, l.lv_last.li_tv.vval.v_dict.dv_refcount) + + lib.tv_list_extend(l, l, nil) + alloc_log:check({ + a.li(l.lv_last.li_prev), + a.li(l.lv_last), + }) + eq(1, l.lv_refcount) + eq(2, l.lv_last.li_tv.vval.v_dict.dv_refcount) + eq({1, {}, 1, {}}, lst2tbl(l)) + + l = list(1, {}) + alloc_log:clear() + eq(1, l.lv_refcount) + eq(1, l.lv_last.li_tv.vval.v_dict.dv_refcount) + + lib.tv_list_extend(l, l, l.lv_last) + alloc_log:check({ + a.li(l.lv_last.li_prev.li_prev), + a.li(l.lv_last.li_prev), + }) + eq({1, 1, {}, {}}, lst2tbl(l)) + eq(1, l.lv_refcount) + eq(2, l.lv_last.li_tv.vval.v_dict.dv_refcount) + + l = list(1, {}) + alloc_log:clear() + eq(1, l.lv_refcount) + eq(1, l.lv_last.li_tv.vval.v_dict.dv_refcount) + + lib.tv_list_extend(l, l, l.lv_first) + alloc_log:check({ + a.li(l.lv_first), + a.li(l.lv_first.li_next), + }) + eq({1, {}, 1, {}}, lst2tbl(l)) + eq(1, l.lv_refcount) + eq(2, l.lv_last.li_tv.vval.v_dict.dv_refcount) + end) + itp('can extend list with an empty list', function() + local l = list(1, {}) + local el = list() + alloc_log:clear() + eq(1, l.lv_refcount) + eq(1, l.lv_last.li_tv.vval.v_dict.dv_refcount) + eq(1, el.lv_refcount) + + lib.tv_list_extend(l, el, nil) + alloc_log:check({ + }) + eq(1, l.lv_refcount) + eq(1, l.lv_last.li_tv.vval.v_dict.dv_refcount) + eq(1, el.lv_refcount) + eq({1, {}}, lst2tbl(l)) + + lib.tv_list_extend(l, el, l.lv_first) + alloc_log:check({ + }) + eq(1, l.lv_refcount) + eq(1, l.lv_last.li_tv.vval.v_dict.dv_refcount) + eq(1, el.lv_refcount) + eq({1, {}}, lst2tbl(l)) + + lib.tv_list_extend(l, el, l.lv_last) + alloc_log:check({ + }) + eq(1, l.lv_refcount) + eq(1, l.lv_last.li_tv.vval.v_dict.dv_refcount) + eq(1, el.lv_refcount) + eq({1, {}}, lst2tbl(l)) + end) + itp('can extend list with another non-empty list', function() + local l + local l2 = list(42, empty_list) + eq(1, l2.lv_refcount) + eq(1, l2.lv_last.li_tv.vval.v_list.lv_refcount) + + l = ffi.gc(list(1, {}), nil) + alloc_log:clear() + eq(1, l.lv_refcount) + eq(1, l.lv_last.li_tv.vval.v_dict.dv_refcount) + + lib.tv_list_extend(l, l2, nil) + alloc_log:check({ + a.li(l.lv_last.li_prev), + a.li(l.lv_last), + }) + eq(1, l2.lv_refcount) + eq(2, l2.lv_last.li_tv.vval.v_list.lv_refcount) + eq({1, {}, 42, empty_list}, lst2tbl(l)) + lib.tv_list_free(l) + eq(1, l2.lv_last.li_tv.vval.v_list.lv_refcount) + + l = ffi.gc(list(1, {}), nil) + alloc_log:clear() + eq(1, l.lv_refcount) + eq(1, l.lv_last.li_tv.vval.v_dict.dv_refcount) + + lib.tv_list_extend(l, l2, l.lv_first) + alloc_log:check({ + a.li(l.lv_first), + a.li(l.lv_first.li_next), + }) + eq(1, l2.lv_refcount) + eq(2, l2.lv_last.li_tv.vval.v_list.lv_refcount) + eq({42, empty_list, 1, {}}, lst2tbl(l)) + lib.tv_list_free(l) + eq(1, l2.lv_last.li_tv.vval.v_list.lv_refcount) + + l = ffi.gc(list(1, {}), nil) + alloc_log:clear() + eq(1, l.lv_refcount) + eq(1, l.lv_last.li_tv.vval.v_dict.dv_refcount) + + lib.tv_list_extend(l, l2, l.lv_last) + alloc_log:check({ + a.li(l.lv_first.li_next), + a.li(l.lv_first.li_next.li_next), + }) + eq(1, l2.lv_refcount) + eq(2, l2.lv_last.li_tv.vval.v_list.lv_refcount) + eq({1, 42, empty_list, {}}, lst2tbl(l)) + lib.tv_list_free(l) + eq(1, l2.lv_last.li_tv.vval.v_list.lv_refcount) + end) + end) describe('concat()', function() itp('works with NULL lists', function() local l = list(1, {}) @@ -789,7 +921,7 @@ describe('typval.c', function() end) itp('works with two different lists', function() local l1 = list(1, {}) - local l2 = list(3, {[type_key]=list_type}) + local l2 = list(3, empty_list) eq(1, l1.lv_refcount) eq(1, l1.lv_last.li_tv.vval.v_dict.dv_refcount) eq(1, l2.lv_refcount) @@ -809,7 +941,7 @@ describe('typval.c', function() a.li(rettv.vval.v_list.lv_last.li_prev), a.li(rettv.vval.v_list.lv_last), }) - eq({1, {}, 3, {[type_key]=list_type}}, typvalt2lua(rettv)) + eq({1, {}, 3, empty_list}, typvalt2lua(rettv)) end) itp('can concatenate list with itself', function() local l = list(1, {}) @@ -875,7 +1007,7 @@ describe('typval.c', function() alloc_log:check({ a.list(rettv3.vval.v_list), }) - eq({[type_key]=list_type}, typvalt2lua(rettv3)) + eq(empty_list, typvalt2lua(rettv3)) local rettv4 = typvalt() eq(OK, lib.tv_list_concat(le, le2, rettv4)) @@ -886,7 +1018,7 @@ describe('typval.c', function() alloc_log:check({ a.list(rettv4.vval.v_list), }) - eq({[type_key]=list_type}, typvalt2lua(rettv4)) + eq(empty_list, typvalt2lua(rettv4)) end) end) end) -- cgit From cf45c7bb059dafeb882133273f77042cb06b37e4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 25 Sep 2016 18:16:17 +0300 Subject: unittests: Fix tests crash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tests crash at some point without - `after_each(collectgarbage)` right before “typval.c list copy() copies list correctly and converts items” test. - Commenting out that test. - Adding `collectgarbage()` after the test (what actually this commit does). Adding `collectgarbage()` to top-level `after_each` block right after `restore_allocators` makes running this file crash even if it is run alone. --- test/unit/eval/typval_spec.lua | 113 +++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 55 deletions(-) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 926bf1c478..2c9b7c66db 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -606,63 +606,66 @@ describe('typval.c', function() eq(nil, lib.tv_list_copy(nil, nil, false, 1)) end) itp('copies list correctly without converting items', function() - local v = {{['«']='»'}, {'„'}, 1, '“', null_string, null_list, null_dict} - local l_tv = lua2typvalt(v) - local l = l_tv.vval.v_list - local lis = list_items(l) - alloc_log:clear() + do + local v = {{['«']='»'}, {'„'}, 1, '“', null_string, null_list, null_dict} + local l_tv = lua2typvalt(v) + local l = l_tv.vval.v_list + local lis = list_items(l) + alloc_log:clear() - eq(1, lis[1].li_tv.vval.v_dict.dv_refcount) - eq(1, lis[2].li_tv.vval.v_list.lv_refcount) - local l_copy1 = tv_list_copy(nil, l, false, 0) - eq(2, lis[1].li_tv.vval.v_dict.dv_refcount) - eq(2, lis[2].li_tv.vval.v_list.lv_refcount) - local lis_copy1 = list_items(l_copy1) - eq(lis[1].li_tv.vval.v_dict, lis_copy1[1].li_tv.vval.v_dict) - eq(lis[2].li_tv.vval.v_list, lis_copy1[2].li_tv.vval.v_list) - eq(v, lst2tbl(l_copy1)) - alloc_log:check({ - a.list(l_copy1), - a.li(lis_copy1[1]), - a.li(lis_copy1[2]), - a.li(lis_copy1[3]), - a.li(lis_copy1[4]), - a.str(lis_copy1[4].li_tv.vval.v_string, #v[4]), - a.li(lis_copy1[5]), - a.li(lis_copy1[6]), - a.li(lis_copy1[7]), - }) - lib.tv_list_free(ffi.gc(l_copy1, nil)) - alloc_log:clear() + eq(1, lis[1].li_tv.vval.v_dict.dv_refcount) + eq(1, lis[2].li_tv.vval.v_list.lv_refcount) + local l_copy1 = tv_list_copy(nil, l, false, 0) + eq(2, lis[1].li_tv.vval.v_dict.dv_refcount) + eq(2, lis[2].li_tv.vval.v_list.lv_refcount) + local lis_copy1 = list_items(l_copy1) + eq(lis[1].li_tv.vval.v_dict, lis_copy1[1].li_tv.vval.v_dict) + eq(lis[2].li_tv.vval.v_list, lis_copy1[2].li_tv.vval.v_list) + eq(v, lst2tbl(l_copy1)) + alloc_log:check({ + a.list(l_copy1), + a.li(lis_copy1[1]), + a.li(lis_copy1[2]), + a.li(lis_copy1[3]), + a.li(lis_copy1[4]), + a.str(lis_copy1[4].li_tv.vval.v_string, #v[4]), + a.li(lis_copy1[5]), + a.li(lis_copy1[6]), + a.li(lis_copy1[7]), + }) + lib.tv_list_free(ffi.gc(l_copy1, nil)) + alloc_log:clear() - eq(1, lis[1].li_tv.vval.v_dict.dv_refcount) - eq(1, lis[2].li_tv.vval.v_list.lv_refcount) - local l_deepcopy1 = tv_list_copy(nil, l, true, 0) - neq(nil, l_deepcopy1) - eq(1, lis[1].li_tv.vval.v_dict.dv_refcount) - eq(1, lis[2].li_tv.vval.v_list.lv_refcount) - local lis_deepcopy1 = list_items(l_deepcopy1) - neq(lis[1].li_tv.vval.v_dict, lis_deepcopy1[1].li_tv.vval.v_dict) - neq(lis[2].li_tv.vval.v_list, lis_deepcopy1[2].li_tv.vval.v_list) - eq(v, lst2tbl(l_deepcopy1)) - local di_deepcopy1 = first_di(lis_deepcopy1[1].li_tv.vval.v_dict) - alloc_log:check({ - a.list(l_deepcopy1), - a.li(lis_deepcopy1[1]), - a.dict(lis_deepcopy1[1].li_tv.vval.v_dict), - a.di(di_deepcopy1, #('«')), - a.str(di_deepcopy1.di_tv.vval.v_string, #v[1]['«']), - a.li(lis_deepcopy1[2]), - a.list(lis_deepcopy1[2].li_tv.vval.v_list), - a.li(lis_deepcopy1[2].li_tv.vval.v_list.lv_first), - a.str(lis_deepcopy1[2].li_tv.vval.v_list.lv_first.li_tv.vval.v_string, #v[2][1]), - a.li(lis_deepcopy1[3]), - a.li(lis_deepcopy1[4]), - a.str(lis_deepcopy1[4].li_tv.vval.v_string, #v[4]), - a.li(lis_deepcopy1[5]), - a.li(lis_deepcopy1[6]), - a.li(lis_deepcopy1[7]), - }) + eq(1, lis[1].li_tv.vval.v_dict.dv_refcount) + eq(1, lis[2].li_tv.vval.v_list.lv_refcount) + local l_deepcopy1 = tv_list_copy(nil, l, true, 0) + neq(nil, l_deepcopy1) + eq(1, lis[1].li_tv.vval.v_dict.dv_refcount) + eq(1, lis[2].li_tv.vval.v_list.lv_refcount) + local lis_deepcopy1 = list_items(l_deepcopy1) + neq(lis[1].li_tv.vval.v_dict, lis_deepcopy1[1].li_tv.vval.v_dict) + neq(lis[2].li_tv.vval.v_list, lis_deepcopy1[2].li_tv.vval.v_list) + eq(v, lst2tbl(l_deepcopy1)) + local di_deepcopy1 = first_di(lis_deepcopy1[1].li_tv.vval.v_dict) + alloc_log:check({ + a.list(l_deepcopy1), + a.li(lis_deepcopy1[1]), + a.dict(lis_deepcopy1[1].li_tv.vval.v_dict), + a.di(di_deepcopy1, #('«')), + a.str(di_deepcopy1.di_tv.vval.v_string, #v[1]['«']), + a.li(lis_deepcopy1[2]), + a.list(lis_deepcopy1[2].li_tv.vval.v_list), + a.li(lis_deepcopy1[2].li_tv.vval.v_list.lv_first), + a.str(lis_deepcopy1[2].li_tv.vval.v_list.lv_first.li_tv.vval.v_string, #v[2][1]), + a.li(lis_deepcopy1[3]), + a.li(lis_deepcopy1[4]), + a.str(lis_deepcopy1[4].li_tv.vval.v_string, #v[4]), + a.li(lis_deepcopy1[5]), + a.li(lis_deepcopy1[6]), + a.li(lis_deepcopy1[7]), + }) + end + collectgarbage() end) itp('copies list correctly and converts items', function() local vc = ffi.gc(ffi.new('vimconv_T[1]'), function(vc) -- cgit From 4f9e7844272335943c075b9444934f77d3cba234 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 25 Sep 2016 22:50:03 +0300 Subject: unittests: Test tv_list_join() --- test/unit/eval/typval_spec.lua | 43 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 2c9b7c66db..382ec79429 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -27,7 +27,7 @@ local typvalt2lua = eval_helpers.typvalt2lua local null_string = eval_helpers.null_string local lib = cimport('./src/nvim/eval/typval.h', './src/nvim/memory.h', - './src/nvim/mbyte.h') + './src/nvim/mbyte.h', './src/nvim/garray.h') local function list_items(l) local lis = {} @@ -95,6 +95,13 @@ after_each(function() alloc_log:after_each() end) +local function ga_alloc(itemsize, growsize) + local ga = ffi.gc(ffi.cast('garray_T*', ffi.new('garray_T[1]', {})), + lib.ga_clear) + lib.ga_init(ga, itemsize or 1, growsize or 80) + return ga +end + describe('typval.c', function() describe('list', function() describe('item', function() @@ -1025,4 +1032,38 @@ describe('typval.c', function() end) end) end) + describe('join()', function() + local function list_join(l, sep, ret) + local ga = ga_alloc() + eq(ret or OK, lib.tv_list_join(ga, l, sep)) + if ga.ga_data == nil then return '' + else return ffi.string(ga.ga_data) + end + end + it('works', function() + local l + l = list('boo', 'far') + eq('boo far', list_join(l, ' ')) + eq('boofar', list_join(l, '')) + + l = list('boo') + eq('boo', list_join(l, ' ')) + + l = list() + eq('', list_join(l, ' ')) + + l = list({}, 'far') + eq('{} far', list_join(l, ' ')) + + local recursive_list = {} + recursive_list[1] = recursive_list + l = ffi.gc(list(recursive_list, 'far'), nil) + eq('[[...@0]] far', list_join(l, ' ')) + + local recursive_l = l.lv_first.li_tv.vval.v_list + local recursive_li = recursive_l.lv_first + lib.tv_list_item_remove(recursive_l, recursive_li) + lib.tv_list_free(l, true) + end) + end) end) -- cgit From b3672ae2fced4715963442d2e19048f8fadbe0b8 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 2 Oct 2016 04:34:30 +0300 Subject: eval/typval: Add tv_list_equal() tests, compare NULL lists equal --- test/functional/eval/null_spec.lua | 9 +-- test/unit/eval/typval_spec.lua | 133 ++++++++++++++++++++++++++++--------- 2 files changed, 104 insertions(+), 38 deletions(-) (limited to 'test') diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua index ccdd1ce34c..e587ede319 100644 --- a/test/functional/eval/null_spec.lua +++ b/test/functional/eval/null_spec.lua @@ -57,12 +57,6 @@ describe('NULL', function() null_list_expr_test('does not crash extend()', 'extend(L, [1])', 0, 0) -- FIXME extend() should not return 0 at all null_list_expr_test('does not crash extend() (second position)', 'extend([1], L)', 0, 0) - -- FIXME Should return 1 - null_list_expr_test('is equal to itself', 'L == L', 0, 0) - -- FIXME Should return 0 - null_list_expr_test('is not not equal to itself', 'L != L', 0, 1) - -- FIXME Should return 1 - null_list_expr_test('counts correctly', 'count([L], L)', 0, 0) -- FIXME should be accepted by inputlist() null_list_expr_test('is accepted as an empty list by inputlist()', '[feedkeys("\\n"), inputlist(L)]', 'E686: Argument of inputlist() must be a List', {0, 0}) @@ -133,5 +127,8 @@ describe('NULL', function() null_list_expr_test('can be added to itself', '(L + L) is L', 0, 1) null_list_expr_test('can be added to non-empty list', '([1] + L)', 0, {1}) null_list_expr_test('can be added to non-empty list (reversed)', '(L + [1])', 0, {1}) + null_list_expr_test('is equal to itself', 'L == L', 0, 1) + null_list_expr_test('is not not equal to itself', 'L != L', 0, 0) + null_list_expr_test('counts correctly', 'count([L], L)', 0, 1) end) end) diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 382ec79429..8740e9eb1f 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1031,39 +1031,108 @@ describe('typval.c', function() eq(empty_list, typvalt2lua(rettv4)) end) end) - end) - describe('join()', function() - local function list_join(l, sep, ret) - local ga = ga_alloc() - eq(ret or OK, lib.tv_list_join(ga, l, sep)) - if ga.ga_data == nil then return '' - else return ffi.string(ga.ga_data) + describe('join()', function() + local function list_join(l, sep, ret) + local ga = ga_alloc() + eq(ret or OK, lib.tv_list_join(ga, l, sep)) + if ga.ga_data == nil then return '' + else return ffi.string(ga.ga_data) + end end - end - it('works', function() - local l - l = list('boo', 'far') - eq('boo far', list_join(l, ' ')) - eq('boofar', list_join(l, '')) - - l = list('boo') - eq('boo', list_join(l, ' ')) - - l = list() - eq('', list_join(l, ' ')) - - l = list({}, 'far') - eq('{} far', list_join(l, ' ')) - - local recursive_list = {} - recursive_list[1] = recursive_list - l = ffi.gc(list(recursive_list, 'far'), nil) - eq('[[...@0]] far', list_join(l, ' ')) - - local recursive_l = l.lv_first.li_tv.vval.v_list - local recursive_li = recursive_l.lv_first - lib.tv_list_item_remove(recursive_l, recursive_li) - lib.tv_list_free(l, true) + itp('works', function() + local l + l = list('boo', 'far') + eq('boo far', list_join(l, ' ')) + eq('boofar', list_join(l, '')) + + l = list('boo') + eq('boo', list_join(l, ' ')) + + l = list() + eq('', list_join(l, ' ')) + + l = list({}, 'far') + eq('{} far', list_join(l, ' ')) + + local recursive_list = {} + recursive_list[1] = recursive_list + l = ffi.gc(list(recursive_list, 'far'), nil) + eq('[[...@0]] far', list_join(l, ' ')) + + local recursive_l = l.lv_first.li_tv.vval.v_list + local recursive_li = recursive_l.lv_first + lib.tv_list_item_remove(recursive_l, recursive_li) + lib.tv_list_free(l, true) + end) + end) + describe('equal()', function() + itp('compares empty and NULL lists correctly', function() + local l = list() + local l2 = list() + + -- NULL lists are not equal to empty lists + eq(false, lib.tv_list_equal(l, nil, true, false)) + eq(false, lib.tv_list_equal(nil, l, false, false)) + eq(false, lib.tv_list_equal(nil, l, false, true)) + eq(false, lib.tv_list_equal(l, nil, true, true)) + + -- Yet NULL lists are equal themselves + eq(true, lib.tv_list_equal(nil, nil, true, false)) + eq(true, lib.tv_list_equal(nil, nil, false, false)) + eq(true, lib.tv_list_equal(nil, nil, false, true)) + eq(true, lib.tv_list_equal(nil, nil, true, true)) + + -- As well as empty lists + eq(true, lib.tv_list_equal(l, l, true, false)) + eq(true, lib.tv_list_equal(l, l2, false, false)) + eq(true, lib.tv_list_equal(l2, l, false, true)) + eq(true, lib.tv_list_equal(l2, l2, true, true)) + end) + -- Must not use recursive=true argument in the following tests because it + -- indicates that tv_equal_recurse_limit and recursive_cnt were set which + -- is essential. This argument will be set when comparing inner lists. + itp('compares lists correctly when case is not ignored', function() + local l1 = list('abc', {1, 2, 'Abc'}, 'def') + local l2 = list('abc', {1, 2, 'Abc'}) + local l3 = list('abc', {1, 2, 'Abc'}, 'Def') + local l4 = list('abc', {1, 2, 'Abc', 4}, 'def') + local l5 = list('Abc', {1, 2, 'Abc'}, 'def') + local l6 = list('abc', {1, 2, 'Abc'}, 'def') + local l7 = list('abc', {1, 2, 'abc'}, 'def') + local l8 = list('abc', nil, 'def') + local l9 = list('abc', {1, 2, nil}, 'def') + + eq(true, lib.tv_list_equal(l1, l1, false, false)) + eq(false, lib.tv_list_equal(l1, l2, false, false)) + eq(false, lib.tv_list_equal(l1, l3, false, false)) + eq(false, lib.tv_list_equal(l1, l4, false, false)) + eq(false, lib.tv_list_equal(l1, l5, false, false)) + eq(true, lib.tv_list_equal(l1, l6, false, false)) + eq(false, lib.tv_list_equal(l1, l7, false, false)) + eq(false, lib.tv_list_equal(l1, l8, false, false)) + eq(false, lib.tv_list_equal(l1, l9, false, false)) + end) + itp('compares lists correctly when case is ignored', function() + local l1 = list('abc', {1, 2, 'Abc'}, 'def') + local l2 = list('abc', {1, 2, 'Abc'}) + local l3 = list('abc', {1, 2, 'Abc'}, 'Def') + local l4 = list('abc', {1, 2, 'Abc', 4}, 'def') + local l5 = list('Abc', {1, 2, 'Abc'}, 'def') + local l6 = list('abc', {1, 2, 'Abc'}, 'def') + local l7 = list('abc', {1, 2, 'abc'}, 'def') + local l8 = list('abc', nil, 'def') + local l9 = list('abc', {1, 2, nil}, 'def') + + eq(true, lib.tv_list_equal(l1, l1, true, false)) + eq(false, lib.tv_list_equal(l1, l2, true, false)) + eq(true, lib.tv_list_equal(l1, l3, true, false)) + eq(false, lib.tv_list_equal(l1, l4, true, false)) + eq(true, lib.tv_list_equal(l1, l5, true, false)) + eq(true, lib.tv_list_equal(l1, l6, true, false)) + eq(true, lib.tv_list_equal(l1, l7, true, false)) + eq(false, lib.tv_list_equal(l1, l8, true, false)) + eq(false, lib.tv_list_equal(l1, l9, true, false)) + end) end) end) end) -- cgit From e5edf07ec44f8d147d7482cae2997be62c30373f Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 4 Nov 2016 19:33:36 +0300 Subject: unittests: Add tests for tv_list_find*() functions Additional modifications: - More `const` qualifiers in tested functions. - `tv_list_find_str()` second argument is more in-line with other `tv_list_find*()` functions. --- test/unit/eval/helpers.lua | 6 ++ test/unit/eval/typval_spec.lua | 190 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 196 insertions(+) (limited to 'test') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index eea5cc8880..cd85b143d9 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -405,7 +405,13 @@ local alloc_logging_helpers = { freed = function(p) return {func='free', args={type(p) == 'table' and p or void(p)}} end, } +local function int(n) + return {[type_key]=int_type, value=n} +end + return { + int=int, + null_string=null_string, null_list=null_list, null_dict=null_dict, diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 8740e9eb1f..94ee394009 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -12,6 +12,7 @@ local to_cstr = helpers.to_cstr local alloc_log_new = helpers.alloc_log_new local a = eval_helpers.alloc_logging_helpers +local int = eval_helpers.int local list = eval_helpers.list local lst2tbl = eval_helpers.lst2tbl local typvalt = eval_helpers.typvalt @@ -1134,5 +1135,194 @@ describe('typval.c', function() eq(false, lib.tv_list_equal(l1, l9, true, false)) end) end) + describe('find', function() + describe('()', function() + itp('correctly indexes list', function() + local l = list(1, 2, 3, 4, 5) + local lis = list_items(l) + clear_alloc_log() + + eq(nil, lib.tv_list_find(nil, -1)) + eq(nil, lib.tv_list_find(nil, 0)) + eq(nil, lib.tv_list_find(nil, 1)) + + eq(nil, lib.tv_list_find(l, 5)) + eq(nil, lib.tv_list_find(l, -6)) + eq(lis[1], lib.tv_list_find(l, -5)) + eq(lis[5], lib.tv_list_find(l, 4)) + eq(lis[3], lib.tv_list_find(l, 2)) + eq(lis[3], lib.tv_list_find(l, -3)) + eq(lis[3], lib.tv_list_find(l, 2)) + eq(lis[3], lib.tv_list_find(l, 2)) + eq(lis[3], lib.tv_list_find(l, -3)) + + l.lv_idx_item = nil + eq(lis[1], lib.tv_list_find(l, -5)) + l.lv_idx_item = nil + eq(lis[5], lib.tv_list_find(l, 4)) + l.lv_idx_item = nil + eq(lis[3], lib.tv_list_find(l, 2)) + l.lv_idx_item = nil + eq(lis[3], lib.tv_list_find(l, -3)) + l.lv_idx_item = nil + eq(lis[3], lib.tv_list_find(l, 2)) + l.lv_idx_item = nil + eq(lis[3], lib.tv_list_find(l, 2)) + l.lv_idx_item = nil + eq(lis[3], lib.tv_list_find(l, -3)) + + l.lv_idx_item = nil + eq(lis[3], lib.tv_list_find(l, 2)) + eq(lis[1], lib.tv_list_find(l, -5)) + eq(lis[3], lib.tv_list_find(l, 2)) + eq(lis[5], lib.tv_list_find(l, 4)) + eq(lis[3], lib.tv_list_find(l, 2)) + eq(lis[3], lib.tv_list_find(l, 2)) + eq(lis[3], lib.tv_list_find(l, 2)) + eq(lis[3], lib.tv_list_find(l, -3)) + eq(lis[3], lib.tv_list_find(l, 2)) + eq(lis[3], lib.tv_list_find(l, 2)) + eq(lis[3], lib.tv_list_find(l, 2)) + eq(lis[3], lib.tv_list_find(l, -3)) + + check_alloc_log({}) + end) + end) + local function check_emsg(f, msg) + local saved_last_msg_hist = lib.last_msg_hist + local ret = {f()} + if msg ~= nil then + neq(saved_last_msg_hist, lib.last_msg_hist) + eq(msg, ffi.string(lib.last_msg_hist.msg)) + else + eq(saved_last_msg_hist, lib.last_msg_hist) + end + return unpack(ret) + end + describe('nr()', function() + local function tv_list_find_nr(l, n, msg) + return check_emsg(function() + local err = ffi.new('bool[1]', {false}) + local ret = lib.tv_list_find_nr(l, n, err) + return (err[0] == true), ret + end, msg) + end + it('returns correct number', function() + local l = list(int(1), int(2), int(3), int(4), int(5)) + clear_alloc_log() + + eq({false, 1}, {tv_list_find_nr(l, -5)}) + eq({false, 5}, {tv_list_find_nr(l, 4)}) + eq({false, 3}, {tv_list_find_nr(l, 2)}) + eq({false, 3}, {tv_list_find_nr(l, -3)}) + + check_alloc_log({}) + end) + it('returns correct number when given a string', function() + local l = list('1', '2', '3', '4', '5') + clear_alloc_log() + + eq({false, 1}, {tv_list_find_nr(l, -5)}) + eq({false, 5}, {tv_list_find_nr(l, 4)}) + eq({false, 3}, {tv_list_find_nr(l, 2)}) + eq({false, 3}, {tv_list_find_nr(l, -3)}) + + check_alloc_log({}) + end) + it('returns zero when given a NULL string', function() + local l = list(null_string) + clear_alloc_log() + + eq({false, 0}, {tv_list_find_nr(l, 0)}) + + check_alloc_log({}) + end) + it('errors out on NULL lists', function() + eq({true, -1}, {tv_list_find_nr(nil, -5)}) + eq({true, -1}, {tv_list_find_nr(nil, 4)}) + eq({true, -1}, {tv_list_find_nr(nil, 2)}) + eq({true, -1}, {tv_list_find_nr(nil, -3)}) + + check_alloc_log({}) + end) + it('errors out on out-of-range indexes', function() + local l = list(int(1), int(2), int(3), int(4), int(5)) + clear_alloc_log() + + eq({true, -1}, {tv_list_find_nr(l, -6)}) + eq({true, -1}, {tv_list_find_nr(l, 5)}) + + check_alloc_log({}) + end) + it('errors out on invalid types', function() + local l = list(1, empty_list, {}) + + eq({true, 0}, {tv_list_find_nr(l, 0, 'E805: Using a Float as a Number')}) + eq({true, 0}, {tv_list_find_nr(l, 1, 'E745: Using a List as a Number')}) + eq({true, 0}, {tv_list_find_nr(l, 2, 'E728: Using a Dictionary as a Number')}) + eq({true, 0}, {tv_list_find_nr(l, -1, 'E728: Using a Dictionary as a Number')}) + eq({true, 0}, {tv_list_find_nr(l, -2, 'E745: Using a List as a Number')}) + eq({true, 0}, {tv_list_find_nr(l, -3, 'E805: Using a Float as a Number')}) + end) + end) + local function tv_list_find_str(l, n, msg) + return check_emsg(function() + local ret = lib.tv_list_find_str(l, n) + local s = nil + if ret ~= nil then + s = ffi.string(ret) + end + return s + end, msg) + end + describe('str()', function() + it('returns correct string', function() + local l = list(int(1), int(2), int(3), int(4), int(5)) + clear_alloc_log() + + eq('1', tv_list_find_str(l, -5)) + eq('5', tv_list_find_str(l, 4)) + eq('3', tv_list_find_str(l, 2)) + eq('3', tv_list_find_str(l, -3)) + + check_alloc_log({}) + end) + it('returns string when used with VAR_STRING items', function() + local l = list('1', '2', '3', '4', '5') + clear_alloc_log() + + eq('1', tv_list_find_str(l, -5)) + eq('5', tv_list_find_str(l, 4)) + eq('3', tv_list_find_str(l, 2)) + eq('3', tv_list_find_str(l, -3)) + + check_alloc_log({}) + end) + it('returns empty when used with NULL string', function() + local l = list(null_string) + clear_alloc_log() + + eq('', tv_list_find_str(l, 0)) + + check_alloc_log({}) + end) + it('fails with error message when index is out of range', function() + local l = list(int(1), int(2), int(3), int(4), int(5)) + + eq(nil, tv_list_find_str(l, -6, 'E684: list index out of range: -6')) + eq(nil, tv_list_find_str(l, 5, 'E684: list index out of range: 5')) + end) + it('fails with error message on invalid types', function() + local l = list(1, empty_list, {}) + + eq('', tv_list_find_str(l, 0, 'E806: using Float as a String')) + eq('', tv_list_find_str(l, 1, 'E730: using List as a String')) + eq('', tv_list_find_str(l, 2, 'E731: using Dictionary as a String')) + eq('', tv_list_find_str(l, -1, 'E731: using Dictionary as a String')) + eq('', tv_list_find_str(l, -2, 'E730: using List as a String')) + eq('', tv_list_find_str(l, -3, 'E806: using Float as a String')) + end) + end) + end) end) end) -- cgit From 56e51033abf00d66e9c6f9412e8f57c9a24b86ae Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 5 Nov 2016 00:07:34 +0300 Subject: unittests: Add tests for tv_list_idx_of_item --- test/unit/eval/typval_spec.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 94ee394009..d308ee5794 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1324,5 +1324,21 @@ describe('typval.c', function() end) end) end) + describe('idx_of_item()', function() + it('works', function() + local l = list(1, 2, 3, 4, 5) + local l2 = list(42, empty_list) + local lis = list_items(l) + local lis2 = list_items(l2) + + for i, li in ipairs(lis) do + eq(i - 1, lib.tv_list_idx_of_item(l, li)) + end + eq(-1, lib.tv_list_idx_of_item(l, lis2[1])) + eq(-1, lib.tv_list_idx_of_item(l, nil)) + eq(-1, lib.tv_list_idx_of_item(nil, nil)) + eq(-1, lib.tv_list_idx_of_item(nil, lis[1])) + end) + end) end) end) -- cgit From 4bcee963471abd939bb9edd1709418e30be7290f Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 5 Nov 2016 01:03:44 +0300 Subject: *: Fix some Windows-specific warnings Also fixed an error in path_fnamecmp(). --- test/unit/eval/typval_spec.lua | 130 ++++++++++++++++++++++++++++------------- 1 file changed, 88 insertions(+), 42 deletions(-) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index d308ee5794..a785350c15 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -294,8 +294,8 @@ describe('typval.c', function() end) end) -- add() and fix() were tested when testing tv_list_item_remove() - describe('alloc()/free()', function() - itp('recursively frees list with', function() + describe('free()', function() + itp('recursively frees list', function() local l1 = ffi.gc(list(1, 'abc'), nil) local l2 = ffi.gc(list({}), nil) local l3 = ffi.gc(list(empty_list), nil) @@ -332,27 +332,73 @@ describe('typval.c', function() alloc_rets:freed(8), }) end) - itp('does not free container items with recurse=false', function() - local l1 = ffi.gc(list('abc', {}, empty_list), nil) + end) + describe('free_list()', function() + itp('does not free list contents', function() + local l1 = ffi.gc(list(1, 'abc'), nil) + local l2 = ffi.gc(list({}), nil) + local l3 = ffi.gc(list(empty_list), nil) local alloc_rets = {} alloc_log:check(get_alloc_rets({ a.list(l1), - a.str(l1.lv_first.li_tv.vval.v_string, #('abc')), a.li(l1.lv_first), - a.dict(l1.lv_first.li_next.li_tv.vval.v_dict), - a.li(l1.lv_first.li_next), - a.list(l1.lv_last.li_tv.vval.v_list), + a.str(l1.lv_last.li_tv.vval.v_string, #('abc')), a.li(l1.lv_last), + a.list(l2), + a.dict(l2.lv_first.li_tv.vval.v_dict), + a.li(l2.lv_first), + a.list(l3), + a.list(l3.lv_first.li_tv.vval.v_list), + a.li(l3.lv_first), }, alloc_rets)) - lib.tv_list_free(l1) + lib.tv_list_free_list(l1) + alloc_log:check({ + alloc_rets:freed(1), + }) + lib.tv_list_free_list(l2) + alloc_log:check({ + alloc_rets:freed(5), + }) + lib.tv_list_free_list(l3) + alloc_log:check({ + alloc_rets:freed(8), + }) + end) + end) + describe('free_contents()', function() + itp('recursively frees list, except for the list structure itself', + function() + local l1 = ffi.gc(list(1, 'abc'), nil) + local l2 = ffi.gc(list({}), nil) + local l3 = ffi.gc(list(empty_list), nil) + local alloc_rets = {} + alloc_log:check(get_alloc_rets({ + a.list(l1), + a.li(l1.lv_first), + a.str(l1.lv_last.li_tv.vval.v_string, #('abc')), + a.li(l1.lv_last), + a.list(l2), + a.dict(l2.lv_first.li_tv.vval.v_dict), + a.li(l2.lv_first), + a.list(l3), + a.list(l3.lv_first.li_tv.vval.v_list), + a.li(l3.lv_first), + }, alloc_rets)) + lib.tv_list_free_contents(l1) alloc_log:check({ alloc_rets:freed(2), alloc_rets:freed(3), alloc_rets:freed(4), - alloc_rets:freed(5), + }) + lib.tv_list_free_contents(l2) + alloc_log:check({ alloc_rets:freed(6), alloc_rets:freed(7), - alloc_rets:freed(1), + }) + lib.tv_list_free_contents(l3) + alloc_log:check({ + alloc_rets:freed(9), + alloc_rets:freed(10), }) end) end) @@ -1063,8 +1109,8 @@ describe('typval.c', function() local recursive_l = l.lv_first.li_tv.vval.v_list local recursive_li = recursive_l.lv_first lib.tv_list_item_remove(recursive_l, recursive_li) - lib.tv_list_free(l, true) - end) + lib.tv_list_free(l) + end, true) end) describe('equal()', function() itp('compares empty and NULL lists correctly', function() @@ -1140,7 +1186,7 @@ describe('typval.c', function() itp('correctly indexes list', function() local l = list(1, 2, 3, 4, 5) local lis = list_items(l) - clear_alloc_log() + alloc_log:clear() eq(nil, lib.tv_list_find(nil, -1)) eq(nil, lib.tv_list_find(nil, 0)) @@ -1185,7 +1231,7 @@ describe('typval.c', function() eq(lis[3], lib.tv_list_find(l, 2)) eq(lis[3], lib.tv_list_find(l, -3)) - check_alloc_log({}) + alloc_log:check({}) end) end) local function check_emsg(f, msg) @@ -1207,54 +1253,54 @@ describe('typval.c', function() return (err[0] == true), ret end, msg) end - it('returns correct number', function() + itp('returns correct number', function() local l = list(int(1), int(2), int(3), int(4), int(5)) - clear_alloc_log() + alloc_log:clear() eq({false, 1}, {tv_list_find_nr(l, -5)}) eq({false, 5}, {tv_list_find_nr(l, 4)}) eq({false, 3}, {tv_list_find_nr(l, 2)}) eq({false, 3}, {tv_list_find_nr(l, -3)}) - check_alloc_log({}) + alloc_log:check({}) end) - it('returns correct number when given a string', function() + itp('returns correct number when given a string', function() local l = list('1', '2', '3', '4', '5') - clear_alloc_log() + alloc_log:clear() eq({false, 1}, {tv_list_find_nr(l, -5)}) eq({false, 5}, {tv_list_find_nr(l, 4)}) eq({false, 3}, {tv_list_find_nr(l, 2)}) eq({false, 3}, {tv_list_find_nr(l, -3)}) - check_alloc_log({}) + alloc_log:check({}) end) - it('returns zero when given a NULL string', function() + itp('returns zero when given a NULL string', function() local l = list(null_string) - clear_alloc_log() + alloc_log:clear() eq({false, 0}, {tv_list_find_nr(l, 0)}) - check_alloc_log({}) + alloc_log:check({}) end) - it('errors out on NULL lists', function() + itp('errors out on NULL lists', function() eq({true, -1}, {tv_list_find_nr(nil, -5)}) eq({true, -1}, {tv_list_find_nr(nil, 4)}) eq({true, -1}, {tv_list_find_nr(nil, 2)}) eq({true, -1}, {tv_list_find_nr(nil, -3)}) - check_alloc_log({}) + alloc_log:check({}) end) - it('errors out on out-of-range indexes', function() + itp('errors out on out-of-range indexes', function() local l = list(int(1), int(2), int(3), int(4), int(5)) - clear_alloc_log() + alloc_log:clear() eq({true, -1}, {tv_list_find_nr(l, -6)}) eq({true, -1}, {tv_list_find_nr(l, 5)}) - check_alloc_log({}) + alloc_log:check({}) end) - it('errors out on invalid types', function() + itp('errors out on invalid types', function() local l = list(1, empty_list, {}) eq({true, 0}, {tv_list_find_nr(l, 0, 'E805: Using a Float as a Number')}) @@ -1276,43 +1322,43 @@ describe('typval.c', function() end, msg) end describe('str()', function() - it('returns correct string', function() + itp('returns correct string', function() local l = list(int(1), int(2), int(3), int(4), int(5)) - clear_alloc_log() + alloc_log:clear() eq('1', tv_list_find_str(l, -5)) eq('5', tv_list_find_str(l, 4)) eq('3', tv_list_find_str(l, 2)) eq('3', tv_list_find_str(l, -3)) - check_alloc_log({}) + alloc_log:check({}) end) - it('returns string when used with VAR_STRING items', function() + itp('returns string when used with VAR_STRING items', function() local l = list('1', '2', '3', '4', '5') - clear_alloc_log() + alloc_log:clear() eq('1', tv_list_find_str(l, -5)) eq('5', tv_list_find_str(l, 4)) eq('3', tv_list_find_str(l, 2)) eq('3', tv_list_find_str(l, -3)) - check_alloc_log({}) + alloc_log:check({}) end) - it('returns empty when used with NULL string', function() + itp('returns empty when used with NULL string', function() local l = list(null_string) - clear_alloc_log() + alloc_log:clear() eq('', tv_list_find_str(l, 0)) - check_alloc_log({}) + alloc_log:check({}) end) - it('fails with error message when index is out of range', function() + itp('fails with error message when index is out of range', function() local l = list(int(1), int(2), int(3), int(4), int(5)) eq(nil, tv_list_find_str(l, -6, 'E684: list index out of range: -6')) eq(nil, tv_list_find_str(l, 5, 'E684: list index out of range: 5')) end) - it('fails with error message on invalid types', function() + itp('fails with error message on invalid types', function() local l = list(1, empty_list, {}) eq('', tv_list_find_str(l, 0, 'E806: using Float as a String')) @@ -1325,7 +1371,7 @@ describe('typval.c', function() end) end) describe('idx_of_item()', function() - it('works', function() + itp('works', function() local l = list(1, 2, 3, 4, 5) local l2 = list(42, empty_list) local lis = list_items(l) -- cgit From 5239616297182601a5d244a482e6cef307e901f1 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 5 Nov 2016 21:34:22 +0300 Subject: functests: Fix buf_functions test on Windows --- test/functional/eval/buf_functions_spec.lua | 6 ++++-- test/functional/helpers.lua | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/functional/eval/buf_functions_spec.lua b/test/functional/eval/buf_functions_spec.lua index a130da4452..db50874c53 100644 --- a/test/functional/eval/buf_functions_spec.lua +++ b/test/functional/eval/buf_functions_spec.lua @@ -13,6 +13,7 @@ local winmeths = helpers.winmeths local curbufmeths = helpers.curbufmeths local curwinmeths = helpers.curwinmeths local curtabmeths = helpers.curtabmeths +local get_pathsep = helpers.get_pathsep local fname = 'Xtest-functional-eval-buf_functions' local fname2 = fname .. '.2' @@ -66,14 +67,15 @@ describe('bufname() function', function() eq('', funcs.bufname('%')) -- Buffer has no name yet command('file ' .. fname) local wd = lfs.currentdir() + local sep = get_pathsep() local curdirname = funcs.fnamemodify(wd, ':t') for _, arg in ipairs({'%', 1, 'X', wd}) do eq(fname, funcs.bufname(arg)) meths.set_current_dir('..') - eq(curdirname .. '/' .. fname, funcs.bufname(arg)) + eq(curdirname .. sep .. fname, funcs.bufname(arg)) meths.set_current_dir(curdirname) meths.set_current_dir(dirname) - eq(wd .. '/' .. fname, funcs.bufname(arg)) + eq(wd .. sep .. fname, funcs.bufname(arg)) meths.set_current_dir('..') eq(fname, funcs.bufname(arg)) command('enew') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 13a0cff137..7ce95d0b7c 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -570,6 +570,10 @@ local curbufmeths = create_callindex(curbuf) local curwinmeths = create_callindex(curwin) local curtabmeths = create_callindex(curtab) +local function get_pathsep() + return funcs.fnamemodify('.', ':p'):sub(-1) +end + local M = { prepend_argv = prepend_argv, clear = clear, @@ -635,6 +639,7 @@ local M = { tmpname = tmpname, meth_pcall = meth_pcall, NIL = mpack.NIL, + get_pathsep = get_pathsep, } return function(after_each) -- cgit From 1e3e302dc2bdced563ecd2c3fb101af31f72b3df Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 4 Dec 2016 21:58:19 +0300 Subject: eval: Move part of dictwatcher* functions to eval/typval --- test/functional/eval/null_spec.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test') diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua index e587ede319..f72d05f2a3 100644 --- a/test/functional/eval/null_spec.lua +++ b/test/functional/eval/null_spec.lua @@ -80,8 +80,7 @@ describe('NULL', function() null_list_test('is accepted by :cexpr', 'cexpr L', 'Vim(cexpr):E777: String or List expected') -- FIXME should not error out null_list_test('is accepted by :lexpr', 'lexpr L', 'Vim(lexpr):E777: String or List expected') - -- FIXME should not error out - null_list_test('is accepted by :for', 'for x in L|throw x|endfor', 'Vim(for):E714: List required') + null_list_test('is accepted by :for', 'for x in L|throw x|endfor', 0) -- Subjectable behaviour -- cgit From 3025431c81daac873e69a71aee695ebfd00504f7 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 4 Dec 2016 22:59:25 +0300 Subject: eval: Make sure that v:_null_dict does not crash dictwatcher*() Ref #4615 --- .../functional/ex_cmds/dict_notifications_spec.lua | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test') diff --git a/test/functional/ex_cmds/dict_notifications_spec.lua b/test/functional/ex_cmds/dict_notifications_spec.lua index 8cc717483e..e3b4a1c504 100644 --- a/test/functional/ex_cmds/dict_notifications_spec.lua +++ b/test/functional/ex_cmds/dict_notifications_spec.lua @@ -244,6 +244,16 @@ describe('dictionary change notifications', function() end) end) + it('errors out when adding to v:_null_dict', function() + command([[ + function! g:Watcher1(dict, key, value) + call rpcnotify(g:channel, '1', a:key, a:value) + endfunction + ]]) + eq('Vim(call):E46: Cannot change read-only variable "dictwatcheradd() argument"', + exc_exec('call dictwatcheradd(v:_null_dict, "x", "g:Watcher1")')) + end) + describe('errors', function() before_each(function() source([[ @@ -272,6 +282,20 @@ describe('dictionary change notifications', function() command('call dictwatcherdel(g:, "key", "g:InvalidCb")') end) + it('fails to remove watcher from v:_null_dict', function() + eq("Vim(call):Couldn't find a watcher matching key and callback", + exc_exec('call dictwatcherdel(v:_null_dict, "x", "g:Watcher2")')) + end) + + --[[ + [ it("fails to add/remove if the callback doesn't exist", function() + [ eq("Vim(call):Function g:InvalidCb doesn't exist", + [ exc_exec('call dictwatcheradd(g:, "key", "g:InvalidCb")')) + [ eq("Vim(call):Function g:InvalidCb doesn't exist", + [ exc_exec('call dictwatcherdel(g:, "key", "g:InvalidCb")')) + [ end) + ]] + it('does not fail to replace a watcher function', function() source([[ let g:key = 'v2' -- cgit From 140174669e359ae7147288366dd94952955980cc Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 4 Mar 2017 21:46:24 +0300 Subject: unittests: Run tv_list_join tests in case it stopped failing --- test/unit/eval/typval_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index a785350c15..b0a7e9109a 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1110,7 +1110,7 @@ describe('typval.c', function() local recursive_li = recursive_l.lv_first lib.tv_list_item_remove(recursive_l, recursive_li) lib.tv_list_free(l) - end, true) + end) end) describe('equal()', function() itp('compares empty and NULL lists correctly', function() -- cgit From 4c3be98db9b24b7d5b8dc2cf55574e778b7ad137 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 4 Mar 2017 23:28:54 +0300 Subject: unittests: Add tv_dict_watcher_{add,remove} tests --- test/unit/eval/helpers.lua | 246 ++++++++++++++++++++++++++++------------- test/unit/eval/typval_spec.lua | 115 ++++++++++++++++++- 2 files changed, 282 insertions(+), 79 deletions(-) (limited to 'test') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index cd85b143d9..21ef51ff20 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -33,18 +33,62 @@ local function li_alloc(nogc) return li end -local function list(...) - local ret = ffi.gc(eval.tv_list_alloc(), eval.tv_list_unref) - eq(0, ret.lv_refcount) - ret.lv_refcount = 1 - for i = 1, select('#', ...) do - local val = select(i, ...) - local li_tv = ffi.gc(lua2typvalt(val), nil) - local li = li_alloc(true) - li.li_tv = li_tv - eval.tv_list_append(ret, li) +local function populate_list(l, lua_l, processed) + processed = processed or {} + eq(0, l.lv_refcount) + l.lv_refcount = 1 + processed[lua_l] = l + for i = 1, #lua_l do + local item_tv = ffi.gc(lua2typvalt(lua_l[i], processed), nil) + local item_li = eval.tv_list_item_alloc() + item_li.li_tv = item_tv + eval.tv_list_append(l, item_li) end - return ret + return l +end + +local function populate_dict(d, lua_d, processed) + processed = processed or {} + eq(0, d.dv_refcount) + d.dv_refcount = 1 + processed[lua_d] = d + for k, v in pairs(lua_d) do + if type(k) == 'string' then + local di = eval.tv_dict_item_alloc(to_cstr(k)) + local val_tv = ffi.gc(lua2typvalt(v, processed), nil) + eval.tv_copy(val_tv, di.di_tv) + eval.tv_clear(val_tv) + eval.tv_dict_add(d, di) + end + end + return d +end + +local function populate_partial(pt, lua_pt, processed) + processed = processed or {} + eq(0, pt.pt_refcount) + processed[lua_pt] = pt + local argv = nil + if lua_pt.args and #lua_pt.args > 0 then + argv = ffi.gc(ffi.cast('typval_T*', eval.xmalloc(ffi.sizeof('typval_T') * #lua_pt.args)), nil) + for i, arg in ipairs(lua_pt.args) do + local arg_tv = ffi.gc(lua2typvalt(arg, processed), nil) + argv[i - 1] = arg_tv + end + end + local dict = nil + if lua_pt.dict then + local dict_tv = ffi.gc(lua2typvalt(lua_pt.dict, processed), nil) + assert(dict_tv.v_type == eval.VAR_DICT) + dict = dict_tv.vval.v_dict + end + pt.pt_refcount = 1 + pt.pt_name = eval.xmemdupz(to_cstr(lua_pt.value), #lua_pt.value) + pt.pt_auto = not not lua_pt.auto + pt.pt_argc = lua_pt.args and #lua_pt.args or 0 + pt.pt_argv = argv + pt.pt_dict = dict + return pt end local ptr2key = function(ptr) @@ -55,6 +99,30 @@ local lst2tbl local dct2tbl local typvalt2lua + +local function partial2lua(pt, processed) + processed = processed or {} + local value, auto, dict, argv = nil, nil, nil, nil + if pt ~= nil then + value = ffi.string(pt.pt_name) + auto = pt.pt_auto and true or nil + argv = {} + for i = 1, pt.pt_argc do + argv[i] = typvalt2lua(pt.pt_argv[i - 1], processed) + end + if pt.pt_dict ~= nil then + dict = dct2tbl(pt.pt_dict) + end + end + return { + [type_key]=func_type, + value=value, + auto=auto, + args=argv, + dict=dict, + } +end + local typvalt2lua_tab = nil local function typvalt2lua_tab_init() @@ -97,26 +165,7 @@ local function typvalt2lua_tab_init() if processed[p_key] then return processed[p_key] end - local pt = t.vval.v_partial - local value, auto, dict, argv = nil, nil, nil, nil - if pt ~= nil then - value = ffi.string(pt.pt_name) - auto = pt.pt_auto and true or nil - argv = {} - for i = 1, pt.pt_argc do - argv[i] = typvalt2lua(pt.pt_argv[i - 1], processed) - end - if pt.pt_dict ~= nil then - dict = dct2tbl(pt.pt_dict) - end - end - return { - [type_key]=func_type, - value=value, - auto=auto, - args=argv, - dict=dict, - } + return partial2lua(t.vval.v_partial, processed) end, } end @@ -257,36 +306,16 @@ local lua2typvalt_type_tab = { processed[l].lv_refcount = processed[l].lv_refcount + 1 return typvalt(eval.VAR_LIST, {v_list=processed[l]}) end - local lst = eval.tv_list_alloc() - lst.lv_refcount = 1 - processed[l] = lst - local ret = typvalt(eval.VAR_LIST, {v_list=lst}) - for i = 1, #l do - local item_tv = ffi.gc(lua2typvalt(l[i], processed), nil) - eval.tv_list_append_tv(lst, item_tv) - eval.tv_clear(item_tv) - end - return ret + local lst = populate_list(eval.tv_list_alloc(), l, processed) + return typvalt(eval.VAR_LIST, {v_list=lst}) end, [dict_type] = function(l, processed) if processed[l] then processed[l].dv_refcount = processed[l].dv_refcount + 1 return typvalt(eval.VAR_DICT, {v_dict=processed[l]}) end - local dct = eval.tv_dict_alloc() - dct.dv_refcount = 1 - processed[l] = dct - local ret = typvalt(eval.VAR_DICT, {v_dict=dct}) - for k, v in pairs(l) do - if type(k) == 'string' then - local di = eval.tv_dict_item_alloc(to_cstr(k)) - local val_tv = ffi.gc(lua2typvalt(v, processed), nil) - eval.tv_copy(val_tv, di.di_tv) - eval.tv_clear(val_tv) - eval.tv_dict_add(dct, di) - end - end - return ret + local dct = populate_dict(eval.tv_dict_alloc(), l, processed) + return typvalt(eval.VAR_DICT, {v_dict=dct}) end, [func_type] = function(l, processed) if processed[l] then @@ -294,29 +323,8 @@ local lua2typvalt_type_tab = { return typvalt(eval.VAR_PARTIAL, {v_partial=processed[l]}) end if l.args or l.dict then - local pt = ffi.gc(ffi.cast('partial_T*', eval.xmalloc(ffi.sizeof('partial_T'))), nil) - processed[l] = pt - local argv = nil - if l.args and #l.args > 0 then - argv = ffi.gc(ffi.cast('typval_T*', eval.xmalloc(ffi.sizeof('typval_T') * #l.args)), nil) - for i, arg in ipairs(l.args) do - local arg_tv = ffi.gc(lua2typvalt(arg, processed), nil) - eval.tv_copy(arg_tv, argv[i - 1]) - eval.tv_clear(arg_tv) - end - end - local dict = nil - if l.dict then - local dict_tv = ffi.gc(lua2typvalt(l.dict, processed), nil) - assert(dict_tv.v_type == eval.VAR_DICT) - dict = dict_tv.vval.v_dict - end - pt.pt_refcount = 1 - pt.pt_name = eval.xmemdupz(to_cstr(l.value), #l.value) - pt.pt_auto = not not l.auto - pt.pt_argc = l.args and #l.args or 0 - pt.pt_argv = argv - pt.pt_dict = dict + local pt = populate_partial(ffi.gc(ffi.cast('partial_T*', + eval.xcalloc(1, ffi.sizeof('partial_T'))), nil), l, processed) return typvalt(eval.VAR_PARTIAL, {v_partial=pt}) else return typvalt(eval.VAR_FUNC, { @@ -402,13 +410,91 @@ local alloc_logging_helpers = { return {func='malloc', args={size + 1}, ret=void(s)} end, + dwatcher = function(w) return {func='malloc', args={ffi.sizeof('DictWatcher')}, ret=void(w)} end, + freed = function(p) return {func='free', args={type(p) == 'table' and p or void(p)}} end, + + -- lua_…: allocated by this file, not by some Neovim function + lua_pt = function(pt) return {func='calloc', args={1, ffi.sizeof('partial_T')}, ret=void(pt)} end, + lua_tvs = function(argv, argc) return {func='malloc', args={ffi.sizeof('typval_T')*argc}, ret=void(argv)} end, } local function int(n) return {[type_key]=int_type, value=n} end +local function list(...) + return populate_list(ffi.gc(eval.tv_list_alloc(), eval.tv_list_unref), + {...}, {}) +end + +local function dict(d) + return populate_dict(ffi.gc(eval.tv_dict_alloc(), eval.tv_dict_free), + d, {}) +end + +local callback2tbl_type_tab = nil + +local function init_callback2tbl_type_tab() + if callback2tbl_type_tab then + return + end + callback2tbl_type_tab = { + [tonumber(eval.kCallbackNone)] = function(_) return {type='none'} end, + [tonumber(eval.kCallbackFuncref)] = function(cb) + return {type='fref', fref=ffi.string(cb.data.funcref)} + end, + [tonumber(eval.kCallbackPartial)] = function(cb) + local lua_pt = partial2lua(cb.data.partial) + return {type='pt', fref=ffi.string(lua_pt.value), pt=lua_pt} + end + } +end + +local function callback2tbl(cb) + init_callback2tbl_type_tab() + return callback2tbl_type_tab[tonumber(cb.type)](cb) +end + +local function tbl2callback(tbl) + local ret = nil + if tbl.type == 'none' then + ret = ffi.new('Callback[1]', {{type=eval.kCallbackNone}}) + elseif tbl.type == 'fref' then + ret = ffi.new('Callback[1]', {{type=eval.kCallbackFuncref, + data={funcref=eval.xstrdup(tbl.fref)}}}) + elseif tbl.type == 'pt' then + local pt = ffi.gc(ffi.cast('partial_T*', + eval.xcalloc(1, ffi.sizeof('partial_T'))), eval.partial_unref) + ret = ffi.new('Callback[1]', {{type=eval.kCallbackPartial, + data={partial=populate_partial(pt, tbl.pt, {})}}}) + else + assert(false) + end + return ffi.gc(ffi.cast('Callback*', ret), helpers.callback_free) +end + +local function dict_watchers(d) + local ret = {} + local h = d.watchers + local q = h.next + local qs = {} + local key_patterns = {} + while q ~= h do + local qitem = ffi.cast('DictWatcher *', + ffi.cast('char *', q) - ffi.offsetof('DictWatcher', 'node')) + ret[#ret + 1] = { + cb=callback2tbl(qitem.callback), + pat=ffi.string(qitem.key_pattern, qitem.key_pattern_len), + busy=qitem.busy, + } + qs[#qs + 1] = qitem + key_patterns[#key_patterns + 1] = {qitem.key_pattern, qitem.key_pattern_len} + q = q.next + end + return ret, qs, key_patterns +end + return { int=int, @@ -427,6 +513,7 @@ return { locks_key=locks_key, list=list, + dict=dict, lst2tbl=lst2tbl, dct2tbl=dct2tbl, @@ -446,5 +533,8 @@ return { list_items=list_items, dict_items=dict_items, + dict_watchers=dict_watchers, + tbl2callback=tbl2callback, + empty_list = {[type_key]=list_type}, } diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index b0a7e9109a..4efde9c6c1 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -14,21 +14,26 @@ local alloc_log_new = helpers.alloc_log_new local a = eval_helpers.alloc_logging_helpers local int = eval_helpers.int local list = eval_helpers.list +local dict = eval_helpers.dict local lst2tbl = eval_helpers.lst2tbl local typvalt = eval_helpers.typvalt local type_key = eval_helpers.type_key local li_alloc = eval_helpers.li_alloc local int_type = eval_helpers.int_type local first_di = eval_helpers.first_di +local func_type = eval_helpers.func_type local null_list = eval_helpers.null_list local null_dict = eval_helpers.null_dict local empty_list = eval_helpers.empty_list local lua2typvalt = eval_helpers.lua2typvalt local typvalt2lua = eval_helpers.typvalt2lua local null_string = eval_helpers.null_string +local tbl2callback = eval_helpers.tbl2callback +local dict_watchers = eval_helpers.dict_watchers local lib = cimport('./src/nvim/eval/typval.h', './src/nvim/memory.h', - './src/nvim/mbyte.h', './src/nvim/garray.h') + './src/nvim/mbyte.h', './src/nvim/garray.h', + './src/nvim/eval.h') local function list_items(l) local lis = {} @@ -1387,4 +1392,112 @@ describe('typval.c', function() end) end) end) + describe('dict', function() + describe('watcher', function() + describe('add/remove', function() + itp('works with an empty key', function() + local d = dict({}) + eq({}, dict_watchers(d)) + local cb = ffi.gc(tbl2callback({type='none'}), nil) + alloc_log:clear() + lib.tv_dict_watcher_add(d, '*', 0, cb[0]) + local ws, qs = dict_watchers(d) + local key_p = qs[1].key_pattern + alloc_log:check({ + a.dwatcher(qs[1]), + a.str(key_p, 0), + }) + eq({{busy=false, cb={type='none'}, pat=''}}, ws) + eq(true, lib.tv_dict_watcher_remove(d, 'x', 0, cb[0])) + alloc_log:check({ + a.freed(key_p), + a.freed(qs[1]), + }) + eq({}, dict_watchers(d)) + end) + itp('works with multiple callbacks', function() + local d = dict({}) + eq({}, dict_watchers(d)) + alloc_log:check({a.dict(d)}) + local cbs = {} + cbs[1] = {'te', ffi.gc(tbl2callback({type='none'}), nil)} + alloc_log:check({}) + cbs[2] = {'foo', ffi.gc(tbl2callback({type='fref', fref='tr'}), nil)} + alloc_log:check({ + a.str(cbs[2][2].data.funcref, #('tr')), + }) + cbs[3] = {'te', ffi.gc(tbl2callback({type='pt', fref='tr', pt={ + value='tr', + args={'test'}, + dict={}, + }}), nil)} + local pt3 = cbs[3][2].data.partial + local pt3_argv = pt3.pt_argv + local pt3_dict = pt3.pt_dict + local pt3_name = pt3.pt_name + local pt3_str_arg = pt3.pt_argv[0].vval.v_string + alloc_log:check({ + a.lua_pt(pt3), + a.lua_tvs(pt3_argv, pt3.pt_argc), + a.str(pt3_str_arg, #('test')), + a.dict(pt3_dict), + a.str(pt3_name, #('tr')), + }) + for _, v in ipairs(cbs) do + lib.tv_dict_watcher_add(d, v[1], #(v[1]), v[2][0]) + end + local ws, qs, kps = dict_watchers(d) + eq({{busy=false, pat=cbs[1][1], cb={type='none'}}, + {busy=false, pat=cbs[2][1], cb={type='fref', fref='tr'}}, + {busy=false, pat=cbs[3][1], cb={type='pt', fref='tr', pt={ + [type_key]=func_type, + value='tr', + args={'test'}, + dict={}, + }}}}, ws) + alloc_log:check({ + a.dwatcher(qs[1]), + a.str(kps[1][1], kps[1][2]), + a.dwatcher(qs[2]), + a.str(kps[2][1], kps[2][2]), + a.dwatcher(qs[3]), + a.str(kps[3][1], kps[3][2]), + }) + eq(true, lib.tv_dict_watcher_remove(d, cbs[2][1], #cbs[2][1], cbs[2][2][0])) + alloc_log:check({ + a.freed(cbs[2][2].data.funcref), + a.freed(kps[2][1]), + a.freed(qs[2]), + }) + eq(false, lib.tv_dict_watcher_remove(d, cbs[2][1], #cbs[2][1], cbs[2][2][0])) + eq({{busy=false, pat=cbs[1][1], cb={type='none'}}, + {busy=false, pat=cbs[3][1], cb={type='pt', fref='tr', pt={ + [type_key]=func_type, + value='tr', + args={'test'}, + dict={}, + }}}}, dict_watchers(d)) + eq(true, lib.tv_dict_watcher_remove(d, cbs[3][1], #cbs[3][1], cbs[3][2][0])) + alloc_log:check({ + a.freed(pt3_str_arg), + a.freed(pt3_argv), + a.freed(pt3_dict), + a.freed(pt3_name), + a.freed(pt3), + a.freed(kps[3][1]), + a.freed(qs[3]), + }) + eq(false, lib.tv_dict_watcher_remove(d, cbs[3][1], #cbs[3][1], cbs[3][2][0])) + eq({{busy=false, pat=cbs[1][1], cb={type='none'}}}, dict_watchers(d)) + eq(true, lib.tv_dict_watcher_remove(d, cbs[1][1], #cbs[1][1], cbs[1][2][0])) + alloc_log:check({ + a.freed(kps[1][1]), + a.freed(qs[1]), + }) + eq(false, lib.tv_dict_watcher_remove(d, cbs[1][1], #cbs[1][1], cbs[1][2][0])) + eq({}, dict_watchers(d)) + end) + end) + end) + end) end) -- cgit From cdb1aa3e47cb0ec19d2ae597c1d21b7e892d0d7e Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 5 Mar 2017 00:47:37 +0300 Subject: eval: Fix len argument to xstrlcat --- test/functional/shada/shada_spec.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/functional/shada/shada_spec.lua b/test/functional/shada/shada_spec.lua index 32598fc399..ca44026852 100644 --- a/test/functional/shada/shada_spec.lua +++ b/test/functional/shada/shada_spec.lua @@ -180,8 +180,7 @@ describe('ShaDa support code', function() nvim_command('undo') nvim_command('set shada+=%') nvim_command('wshada! ' .. shada_fname) - local readme_fname = paths.test_source_path .. '/README.md' - readme_fname = helpers.eval( 'resolve("' .. readme_fname .. '")' ) + local readme_fname = funcs.resolve(paths.test_source_path) .. '/README.md' eq({[7]=1, [8]=2, [9]=1, [10]=4, [11]=1}, find_file(readme_fname)) nvim_command('set shada+=r~') nvim_command('wshada! ' .. shada_fname) @@ -189,7 +188,8 @@ describe('ShaDa support code', function() nvim_command('set shada-=r~') nvim_command('wshada! ' .. shada_fname) eq({[7]=1, [8]=2, [9]=1, [10]=4, [11]=1}, find_file(readme_fname)) - nvim_command('set shada+=r' .. paths.test_source_path) + nvim_command('set shada+=r' .. funcs.escape( + funcs.escape(paths.test_source_path, '$~'), ' "\\,')) nvim_command('wshada! ' .. shada_fname) eq({}, find_file(readme_fname)) end) -- cgit From ffaf7c7521399826d9a32b12a1180bcd162f88be Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 5 Mar 2017 01:09:55 +0300 Subject: unittests: Add tv_dict_item_{alloc,free} tests --- test/helpers.lua | 14 +++++++++++++ test/unit/eval/typval_spec.lua | 45 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) (limited to 'test') diff --git a/test/helpers.lua b/test/helpers.lua index e5224349c2..1a86effa1c 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -225,6 +225,19 @@ local function which(exe) end end +local function concat_tables(...) + local ret = {} + for i = 1, select('#', ...) do + local tbl = select(i, ...) + if tbl then + for _, v in ipairs(tbl) do + ret[#ret + 1] = v + end + end + end + return ret +end + return { eq = eq, neq = neq, @@ -238,4 +251,5 @@ return { check_cores = check_cores, hasenv = hasenv, which = which, + concat_tables = concat_tables, } diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 4efde9c6c1..3bd7d9dbaf 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1,4 +1,5 @@ local helpers = require('test.unit.helpers')(after_each) +local global_helpers = require('test.helpers') local eval_helpers = require('test.unit.eval.helpers') local itp = helpers.gen_itp(it) @@ -31,6 +32,8 @@ local null_string = eval_helpers.null_string local tbl2callback = eval_helpers.tbl2callback local dict_watchers = eval_helpers.dict_watchers +local concat_tables = global_helpers.concat_tables + local lib = cimport('./src/nvim/eval/typval.h', './src/nvim/memory.h', './src/nvim/mbyte.h', './src/nvim/garray.h', './src/nvim/eval.h') @@ -1498,6 +1501,48 @@ describe('typval.c', function() eq({}, dict_watchers(d)) end) end) + describe('notify', function() + -- Way too hard to test it here, functional tests in + -- dict_notifications_spec.lua. + end) + end) + describe('item', function() + describe('alloc/free', function() + local function check_tv_dict_item_alloc_len(s, len, tv, more_frees) + local di + if len == nil then + di = ffi.gc(lib.tv_dict_item_alloc(s), nil) + len = #s + else + di = ffi.gc(lib.tv_dict_item_alloc_len(s, len or #s), nil) + end + eq(s:sub(1, len), ffi.string(di.di_key)) + alloc_log:check({a.di(di, len)}) + if tv then + di.di_tv = tv + else + di.di_tv.v_type = lib.VAR_UNKNOWN + end + lib.tv_dict_item_free(di) + alloc_log:check(concat_tables(more_frees, {a.freed(di)})) + end + local function check_tv_dict_item_alloc(s, tv, more_frees) + return check_tv_dict_item_alloc_len(s, nil, tv, more_frees) + end + itp('works', function() + check_tv_dict_item_alloc('') + check_tv_dict_item_alloc('t') + check_tv_dict_item_alloc('TEST') + check_tv_dict_item_alloc_len('', 0) + check_tv_dict_item_alloc_len('TEST', 2) + local tv = lua2typvalt('test') + alloc_log:check({a.str(tv.vval.v_string, #('test'))}) + check_tv_dict_item_alloc('', tv, {a.freed(tv.vval.v_string)}) + tv = lua2typvalt('test') + alloc_log:check({a.str(tv.vval.v_string, #('test'))}) + check_tv_dict_item_alloc_len('', 0, tv, {a.freed(tv.vval.v_string)}) + end) + end) end) end) end) -- cgit From 6c622ed08bb56f08f4cc4dbf6251220ccf7ba2ba Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 5 Mar 2017 01:26:26 +0300 Subject: unittests: Add tv_dict_item_{add,remove} tests --- test/unit/eval/helpers.lua | 7 +++++-- test/unit/eval/typval_spec.lua | 46 ++++++++++++++++++++++++++++++++---------- 2 files changed, 40 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index 21ef51ff20..8faa8dbf5c 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -416,7 +416,10 @@ local alloc_logging_helpers = { -- lua_…: allocated by this file, not by some Neovim function lua_pt = function(pt) return {func='calloc', args={1, ffi.sizeof('partial_T')}, ret=void(pt)} end, - lua_tvs = function(argv, argc) return {func='malloc', args={ffi.sizeof('typval_T')*argc}, ret=void(argv)} end, + lua_tvs = function(argv, argc) + argc = alloc_len(argc) + return {func='malloc', args={ffi.sizeof('typval_T')*argc}, ret=void(argv)} + end, } local function int(n) @@ -430,7 +433,7 @@ end local function dict(d) return populate_dict(ffi.gc(eval.tv_dict_alloc(), eval.tv_dict_free), - d, {}) + d or {}, {}) end local callback2tbl_type_tab = nil diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 3bd7d9dbaf..ebd53469e8 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -8,6 +8,7 @@ local OK = helpers.OK local eq = helpers.eq local neq = helpers.neq local ffi = helpers.ffi +local FAIL = helpers.FAIL local cimport = helpers.cimport local to_cstr = helpers.to_cstr local alloc_log_new = helpers.alloc_log_new @@ -17,6 +18,7 @@ local int = eval_helpers.int local list = eval_helpers.list local dict = eval_helpers.dict local lst2tbl = eval_helpers.lst2tbl +local dct2tbl = eval_helpers.dct2tbl local typvalt = eval_helpers.typvalt local type_key = eval_helpers.type_key local li_alloc = eval_helpers.li_alloc @@ -111,6 +113,18 @@ local function ga_alloc(itemsize, growsize) return ga end +local function check_emsg(f, msg) + local saved_last_msg_hist = lib.last_msg_hist + local ret = {f()} + if msg ~= nil then + neq(saved_last_msg_hist, lib.last_msg_hist) + eq(msg, ffi.string(lib.last_msg_hist.msg)) + else + eq(saved_last_msg_hist, lib.last_msg_hist) + end + return unpack(ret) +end + describe('typval.c', function() describe('list', function() describe('item', function() @@ -1242,17 +1256,6 @@ describe('typval.c', function() alloc_log:check({}) end) end) - local function check_emsg(f, msg) - local saved_last_msg_hist = lib.last_msg_hist - local ret = {f()} - if msg ~= nil then - neq(saved_last_msg_hist, lib.last_msg_hist) - eq(msg, ffi.string(lib.last_msg_hist.msg)) - else - eq(saved_last_msg_hist, lib.last_msg_hist) - end - return unpack(ret) - end describe('nr()', function() local function tv_list_find_nr(l, n, msg) return check_emsg(function() @@ -1543,6 +1546,27 @@ describe('typval.c', function() check_tv_dict_item_alloc_len('', 0, tv, {a.freed(tv.vval.v_string)}) end) end) + describe('add/remove', function() + itp('works', function() + local d = dict() + eq({}, dct2tbl(d)) + alloc_log:check({a.dict(d)}) + local di = ffi.gc(lib.tv_dict_item_alloc(''), nil) + local tv = lua2typvalt('test') + di.di_tv = tv + alloc_log:check({a.di(di, ''), a.str(tv.vval.v_string, 'test')}) + eq(OK, lib.tv_dict_add(d, di)) + alloc_log:check({}) + eq(FAIL, check_emsg(function() return lib.tv_dict_add(d, di) end, + 'E685: Internal error: hash_add()')) + alloc_log:clear() + lib.tv_dict_item_remove(d, di) + alloc_log:check({ + a.freed(tv.vval.v_string), + a.freed(di), + }) + end) + end) end) end) end) -- cgit From 38dd81c136c2edbda66614622a4747bf1785af94 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 5 Mar 2017 02:15:17 +0300 Subject: eval/typval: Fix SEGV in test_alot.vim test --- test/functional/eval/null_spec.lua | 6 ++++++ test/unit/eval/typval_spec.lua | 7 +++++++ 2 files changed, 13 insertions(+) (limited to 'test') diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua index f72d05f2a3..3b361ceeda 100644 --- a/test/functional/eval/null_spec.lua +++ b/test/functional/eval/null_spec.lua @@ -130,4 +130,10 @@ describe('NULL', function() null_list_expr_test('is not not equal to itself', 'L != L', 0, 0) null_list_expr_test('counts correctly', 'count([L], L)', 0, 1) end) + describe('dict', function() + it('does not crash when indexing NULL dict', function() + eq('\nE716: Key not present in Dictionary: test\nE15: Invalid expression: v:_null_dict.test', + redir_exec('echo v:_null_dict.test')) + end) + end) end) diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index ebd53469e8..937869a7bc 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1568,5 +1568,12 @@ describe('typval.c', function() end) end) end) + describe('indexing', function() + describe('find', function() + itp('works with NULL dict', function() + eq(nil, lib.tv_dict_find(nil, '', 0)) + end) + end) + end) end) end) -- cgit From 52e226ff74f49a02f884247b61d1865fa14e810d Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 5 Mar 2017 03:53:42 +0300 Subject: unittests: Disable tv_list_join test on Mac OS only --- test/unit/eval/typval_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 937869a7bc..2653706e5b 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -34,6 +34,7 @@ local null_string = eval_helpers.null_string local tbl2callback = eval_helpers.tbl2callback local dict_watchers = eval_helpers.dict_watchers +local uname = global_helpers.uname local concat_tables = global_helpers.concat_tables local lib = cimport('./src/nvim/eval/typval.h', './src/nvim/memory.h', @@ -1132,7 +1133,7 @@ describe('typval.c', function() local recursive_li = recursive_l.lv_first lib.tv_list_item_remove(recursive_l, recursive_li) lib.tv_list_free(l) - end) + end, uname() == 'Darwin') end) describe('equal()', function() itp('compares empty and NULL lists correctly', function() -- cgit From 5ce624324136408a3f412d6c2ff437455f1e3344 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 12 Mar 2017 14:55:14 +0300 Subject: unittests: Enable tv_list_join tests back Unable to reproduce the problem on Mac OS X Sierra VPS, need to check whether it is reproducible on travis. --- test/unit/eval/typval_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 2653706e5b..2f01e9634e 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1133,7 +1133,7 @@ describe('typval.c', function() local recursive_li = recursive_l.lv_first lib.tv_list_item_remove(recursive_l, recursive_li) lib.tv_list_free(l) - end, uname() == 'Darwin') + end) end) describe('equal()', function() itp('compares empty and NULL lists correctly', function() -- cgit From bc87d23c28c10c70b4addaf18ae16bcbe0682c8a Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 12 Mar 2017 21:58:57 +0300 Subject: unittests: Add tests for dictionary indexing --- test/unit/eval/helpers.lua | 1 + test/unit/eval/typval_spec.lua | 281 ++++++++++++++++++++++++++++++++++------- test/unit/helpers.lua | 23 ++++ 3 files changed, 262 insertions(+), 43 deletions(-) (limited to 'test') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index 8faa8dbf5c..6909953022 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -538,6 +538,7 @@ return { dict_watchers=dict_watchers, tbl2callback=tbl2callback, + callback2tbl=callback2tbl, empty_list = {[type_key]=list_type}, } diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 2f01e9634e..d91fd3e78d 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -20,26 +20,26 @@ local dict = eval_helpers.dict local lst2tbl = eval_helpers.lst2tbl local dct2tbl = eval_helpers.dct2tbl local typvalt = eval_helpers.typvalt -local type_key = eval_helpers.type_key -local li_alloc = eval_helpers.li_alloc -local int_type = eval_helpers.int_type -local first_di = eval_helpers.first_di -local func_type = eval_helpers.func_type -local null_list = eval_helpers.null_list -local null_dict = eval_helpers.null_dict -local empty_list = eval_helpers.empty_list -local lua2typvalt = eval_helpers.lua2typvalt -local typvalt2lua = eval_helpers.typvalt2lua -local null_string = eval_helpers.null_string +local type_key = eval_helpers.type_key +local li_alloc = eval_helpers.li_alloc +local first_di = eval_helpers.first_di +local func_type = eval_helpers.func_type +local null_list = eval_helpers.null_list +local null_dict = eval_helpers.null_dict +local dict_items = eval_helpers.dict_items +local empty_list = eval_helpers.empty_list +local lua2typvalt = eval_helpers.lua2typvalt +local typvalt2lua = eval_helpers.typvalt2lua +local null_string = eval_helpers.null_string +local callback2tbl = eval_helpers.callback2tbl local tbl2callback = eval_helpers.tbl2callback local dict_watchers = eval_helpers.dict_watchers -local uname = global_helpers.uname local concat_tables = global_helpers.concat_tables local lib = cimport('./src/nvim/eval/typval.h', './src/nvim/memory.h', './src/nvim/mbyte.h', './src/nvim/garray.h', - './src/nvim/eval.h') + './src/nvim/eval.h', './src/nvim/vim.h') local function list_items(l) local lis = {} @@ -79,30 +79,6 @@ before_each(function() alloc_log:before_each() end) -local function clear_tmp_allocs() - local toremove = {} - local allocs = {} - for i, v in ipairs(alloc_log.log) do - if v.func == 'malloc' or v.func == 'calloc' then - allocs[tostring(v.ret)] = i - elseif v.func == 'realloc' or v.func == 'free' then - if allocs[tostring(v.args[1])] then - toremove[#toremove + 1] = allocs[tostring(v.args[1])] - if v.func == 'free' then - toremove[#toremove + 1] = i - end - end - if v.func == 'realloc' then - allocs[tostring(v.ret)] = i - end - end - end - table.sort(toremove) - for i = #toremove,1,-1 do - table.remove(alloc_log.log, toremove[i]) - end -end - after_each(function() alloc_log:after_each() end) @@ -116,12 +92,19 @@ end local function check_emsg(f, msg) local saved_last_msg_hist = lib.last_msg_hist + if saved_last_msg_hist == nil then + saved_last_msg_hist = nil + end local ret = {f()} if msg ~= nil then - neq(saved_last_msg_hist, lib.last_msg_hist) eq(msg, ffi.string(lib.last_msg_hist.msg)) + neq(saved_last_msg_hist, lib.last_msg_hist) else - eq(saved_last_msg_hist, lib.last_msg_hist) + if saved_last_msg_hist ~= lib.last_msg_hist then + eq(nil, ffi.string(lib.last_msg_hist.msg)) + else + eq(saved_last_msg_hist, lib.last_msg_hist) + end end return unpack(ret) end @@ -667,8 +650,7 @@ describe('typval.c', function() a.li(l.lv_last), }) - eq({{[type_key]=int_type, value=-100500}, - {[type_key]=int_type, value=100500}}, typvalt2lua(l_tv)) + eq({int(-100500), int(100500)}, typvalt2lua(l_tv)) end) end) end) @@ -769,7 +751,7 @@ describe('typval.c', function() eq({{['\171']='\187'}, {'\191'}, 1, '\191', null_string, null_list, null_dict}, lst2tbl(l_deepcopy1)) local di_deepcopy1 = first_di(lis_deepcopy1[1].li_tv.vval.v_dict) - clear_tmp_allocs() + alloc_log:clear_tmp_allocs() alloc_log:check({ a.list(l_deepcopy1), a.li(lis_deepcopy1[1]), @@ -1570,9 +1552,222 @@ describe('typval.c', function() end) end) describe('indexing', function() - describe('find', function() + describe('find()', function() + local function tv_dict_find(d, key, key_len) + local di = lib.tv_dict_find(d, key, key_len or #key) + if di == nil then + return nil, nil, nil + end + return typvalt2lua(di.di_tv), ffi.string(di.di_key), di + end itp('works with NULL dict', function() eq(nil, lib.tv_dict_find(nil, '', 0)) + eq(nil, lib.tv_dict_find(nil, 'test', -1)) + eq(nil, lib.tv_dict_find(nil, nil, 0)) + end) + itp('works with NULL key', function() + local lua_d = { + ['']=0, + t=1, + te=2, + tes=3, + test=4, + testt=5, + } + local d = dict(lua_d) + alloc_log:clear() + eq(lua_d, dct2tbl(d)) + alloc_log:check({}) + local dis = dict_items(d) + eq({0, '', dis['']}, {tv_dict_find(d, '', 0)}) + eq({0, '', dis['']}, {tv_dict_find(d, nil, 0)}) + end) + itp('works with len properly', function() + local lua_d = { + ['']=0, + t=1, + te=2, + tes=3, + test=4, + testt=5, + } + local d = dict(lua_d) + alloc_log:clear() + eq(lua_d, dct2tbl(d)) + alloc_log:check({}) + for i = 0, 5 do + local v, k = tv_dict_find(d, 'testt', i) + eq({i, ('testt'):sub(1, i)}, {v, k}) + end + eq(nil, tv_dict_find(d, 'testt', 6)) -- Should take NUL byte + eq(5, tv_dict_find(d, 'testt', -1)) + alloc_log:check({}) + end) + end) + describe('get_number()', function() + itp('works with NULL dict', function() + eq(0, check_emsg(function() return lib.tv_dict_get_number(nil, 'test') end, + nil)) + end) + itp('works', function() + local d = ffi.gc(dict({test={}}), nil) + eq(0, check_emsg(function() return lib.tv_dict_get_number(d, 'test') end, + 'E728: Using a Dictionary as a Number')) + d = ffi.gc(dict({tes=int(42), t=44, te='43'}), nil) + alloc_log:clear() + eq(0, check_emsg(function() return lib.tv_dict_get_number(d, 'test') end, + nil)) + eq(42, check_emsg(function() return lib.tv_dict_get_number(d, 'tes') end, + nil)) + eq(43, check_emsg(function() return lib.tv_dict_get_number(d, 'te') end, + nil)) + alloc_log:check({}) + eq(0, check_emsg(function() return lib.tv_dict_get_number(d, 't') end, + 'E805: Using a Float as a Number')) + end) + end) + describe('get_string()', function() + itp('works with NULL dict', function() + eq(nil, check_emsg(function() return lib.tv_dict_get_string(nil, 'test', false) end, + nil)) + end) + itp('works', function() + local d = ffi.gc(dict({test={}}), nil) + eq('', ffi.string(check_emsg(function() return lib.tv_dict_get_string(d, 'test', false) end, + 'E731: using Dictionary as a String'))) + d = ffi.gc(dict({tes=int(42), t=44, te='43', xx=int(45)}), nil) + alloc_log:clear() + local dis = dict_items(d) + eq(nil, check_emsg(function() return lib.tv_dict_get_string(d, 'test', false) end, + nil)) + local s42 = check_emsg(function() return lib.tv_dict_get_string(d, 'tes', false) end, + nil) + eq('42', ffi.string(s42)) + local s45 = check_emsg(function() return lib.tv_dict_get_string(d, 'xx', false) end, + nil) + eq(s42, s45) + eq('45', ffi.string(s45)) + eq('45', ffi.string(s42)) + local s43 = check_emsg(function() return lib.tv_dict_get_string(d, 'te', false) end, + nil) + eq('43', ffi.string(s43)) + neq(s42, s43) + eq(s43, dis.te.di_tv.vval.v_string) + alloc_log:check({}) + eq('', ffi.string(check_emsg(function() return lib.tv_dict_get_string(d, 't', false) end, + 'E806: using Float as a String'))) + end) + itp('allocates a string copy when requested', function() + local function tv_dict_get_string_alloc(d, key, emsg) + alloc_log:clear() + local ret = check_emsg(function() return lib.tv_dict_get_string(d, key, true) end, + emsg) + local s_ret = (ret ~= nil) and ffi.string(ret) or nil + if not emsg then + if s_ret then + alloc_log:check({a.str(ret, s_ret)}) + else + alloc_log:check({}) + end + end + lib.xfree(ret) + return s_ret + end + local d = ffi.gc(dict({test={}}), nil) + eq('', tv_dict_get_string_alloc(d, 'test', 'E731: using Dictionary as a String')) + d = ffi.gc(dict({tes=int(42), t=44, te='43', xx=int(45)}), nil) + alloc_log:clear() + eq(nil, tv_dict_get_string_alloc(d, 'test')) + eq('42', tv_dict_get_string_alloc(d, 'tes')) + eq('45', tv_dict_get_string_alloc(d, 'xx')) + eq('43', tv_dict_get_string_alloc(d, 'te')) + eq('', tv_dict_get_string_alloc(d, 't', 'E806: using Float as a String')) + end) + end) + describe('get_string_buf()', function() + local function tv_dict_get_string_buf(d, key, buf, emsg) + buf = buf or ffi.gc(lib.xmalloc(lib.NUMBUFLEN), lib.xfree) + alloc_log:clear() + local ret = check_emsg(function() return lib.tv_dict_get_string_buf(d, key, buf) end, + emsg) + local s_ret = (ret ~= nil) and ffi.string(ret) or nil + if not emsg then + alloc_log:check({}) + end + return s_ret, ret, buf + end + itp('works with NULL dict', function() + eq(nil, tv_dict_get_string_buf(nil, 'test')) + end) + itp('works', function() + local lua_d = { + ['']={}, + t=1, + te=int(2), + tes=empty_list, + test='tset', + testt=5, + } + local d = dict(lua_d) + alloc_log:clear() + eq(lua_d, dct2tbl(d)) + alloc_log:check({}) + local s, r, b + s, r, b = tv_dict_get_string_buf(d, 'test') + neq(r, b) + eq('tset', s) + s, r, b = tv_dict_get_string_buf(d, 't', nil, 'E806: using Float as a String') + neq(r, b) + eq('', s) + s, r, b = tv_dict_get_string_buf(d, 'te') + eq(r, b) + eq('2', s) + end) + end) + describe('get_callback()', function() + local function tv_dict_get_callback(d, key, key_len, emsg) + key_len = key_len or #key + local cb = ffi.gc(ffi.cast('Callback*', lib.xmalloc(ffi.sizeof('Callback'))), lib.callback_free) + alloc_log:clear() + local ret = check_emsg(function() + return lib.tv_dict_get_callback(d, key, key_len, cb) + end, emsg) + local cb_lua = callback2tbl(cb[0]) + return cb_lua, ret + end + itp('works with NULL dict', function() + eq({{type='none'}, true}, + {tv_dict_get_callback(nil, nil, 0)}) + end) + itp('works', function() + local lua_d = { + ['']='tr', + t=int(1), + te={[type_key]=func_type, value='tr'}, + tes={[type_key]=func_type, value='tr', args={'a', 'b'}}, + test={[type_key]=func_type, value='Test', dict={test=1}, args={}}, + testt={[type_key]=func_type, value='Test', dict={test=1}, args={1}}, + } + local d = dict(lua_d) + eq(lua_d, dct2tbl(d)) + eq({{type='fref', fref='tr'}, true}, + {tv_dict_get_callback(d, nil, 0)}) + eq({{type='fref', fref='tr'}, true}, + {tv_dict_get_callback(d, '', -1)}) + eq({{type='none'}, true}, + {tv_dict_get_callback(d, 'x', -1)}) + eq({{type='fref', fref='tr'}, true}, + {tv_dict_get_callback(d, 'testt', 0)}) + eq({{type='none'}, false}, + {tv_dict_get_callback(d, 'test', 1, 'E6000: Argument is not a function or function name')}) + eq({{type='fref', fref='tr'}, true}, + {tv_dict_get_callback(d, 'testt', 2)}) + eq({{ type='pt', fref='tr', pt={ [type_key]=func_type, value='tr', args={ 'a', 'b' } } }, true}, + {tv_dict_get_callback(d, 'testt', 3)}) + eq({{ type='pt', fref='Test', pt={ [type_key]=func_type, value='Test', dict={ test=1 }, args={} } }, true}, + {tv_dict_get_callback(d, 'testt', 4)}) + eq({{ type='pt', fref='Test', pt={ [type_key]=func_type, value='Test', dict={ test=1 }, args={1} } }, true}, + {tv_dict_get_callback(d, 'testt', 5)}) end) end) end) diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 612b337ee7..8aad3acd98 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -314,6 +314,29 @@ local function alloc_log_new() eq(exp, self.log) self:clear() end + function log:clear_tmp_allocs() + local toremove = {} + local allocs = {} + for i, v in ipairs(self.log) do + if v.func == 'malloc' or v.func == 'calloc' then + allocs[tostring(v.ret)] = i + elseif v.func == 'realloc' or v.func == 'free' then + if allocs[tostring(v.args[1])] then + toremove[#toremove + 1] = allocs[tostring(v.args[1])] + if v.func == 'free' then + toremove[#toremove + 1] = i + end + end + if v.func == 'realloc' then + allocs[tostring(v.ret)] = i + end + end + end + table.sort(toremove) + for i = #toremove,1,-1 do + table.remove(self.log, toremove[i]) + end + end function log:restore_original_functions() -- Do nothing: set mocks live in a separate process return -- cgit From 270a3889af024485fa7b63f34c4dd3f92f6e0f98 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 13 Mar 2017 01:45:44 +0300 Subject: unittests: Add tv_dict_add* unit tests Also fixes incorrect location of `tv_dict_add` function and three bugs in other functions: 1. `tv_dict_add_list` may free list it does not own (vim/vim#1555). 2. `tv_dict_add_dict` may free dictionary it does not own (vim/vim#1555). 3. `tv_dict_add_dict` ignores `key_len` argument. --- test/unit/eval/typval_spec.lua | 116 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index d91fd3e78d..c710171779 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1770,6 +1770,122 @@ describe('typval.c', function() {tv_dict_get_callback(d, 'testt', 5)}) end) end) + describe('dict_add()', function() + itp('works', function() + local di = lib.tv_dict_item_alloc_len('t-est', 5) + alloc_log:check({a.di(di, 't-est')}) + di.di_tv.v_type = lib.VAR_NUMBER + di.di_tv.vval.v_number = 42 + local d = dict({test=10}) + local dis = dict_items(d) + alloc_log:check({ + a.dict(d), + a.di(dis.test, 'test') + }) + eq({test=10}, dct2tbl(d)) + alloc_log:clear() + eq(OK, lib.tv_dict_add(d, di)) + alloc_log:check({}) + eq({test=10, ['t-est']=int(42)}, dct2tbl(d)) + eq(FAIL, check_emsg(function() return lib.tv_dict_add(d, di) end, + 'E685: Internal error: hash_add()')) + end) + end) + describe('dict_add_list()', function() + itp('works', function() + local l = list(1, 2, 3) + alloc_log:clear() + eq(1, l.lv_refcount) + local d = dict({test=10}) + alloc_log:clear() + eq({test=10}, dct2tbl(d)) + eq(OK, lib.tv_dict_add_list(d, 'testt', 3, l)) + local dis = dict_items(d) + alloc_log:check({a.di(dis.tes, 'tes')}) + eq({test=10, tes={1, 2, 3}}, dct2tbl(d)) + eq(2, l.lv_refcount) + eq(FAIL, check_emsg(function() return lib.tv_dict_add_list(d, 'testt', 3, l) end, + 'E685: Internal error: hash_add()')) + eq(2, l.lv_refcount) + alloc_log:clear() + lib.emsg_skip = lib.emsg_skip + 1 + eq(FAIL, check_emsg(function() return lib.tv_dict_add_list(d, 'testt', 3, l) end, + nil)) + eq(2, l.lv_refcount) + lib.emsg_skip = lib.emsg_skip - 1 + alloc_log:clear_tmp_allocs() + alloc_log:check({}) + end) + end) + describe('dict_add_dict()', function() + itp('works', function() + local d2 = dict({foo=42}) + alloc_log:clear() + eq(1, d2.dv_refcount) + local d = dict({test=10}) + alloc_log:clear() + eq({test=10}, dct2tbl(d)) + eq(OK, lib.tv_dict_add_dict(d, 'testt', 3, d2)) + local dis = dict_items(d) + alloc_log:check({a.di(dis.tes, 'tes')}) + eq({test=10, tes={foo=42}}, dct2tbl(d)) + eq(2, d2.dv_refcount) + eq(FAIL, check_emsg(function() return lib.tv_dict_add_dict(d, 'testt', 3, d2) end, + 'E685: Internal error: hash_add()')) + eq(2, d2.dv_refcount) + alloc_log:clear() + lib.emsg_skip = lib.emsg_skip + 1 + eq(FAIL, check_emsg(function() return lib.tv_dict_add_dict(d, 'testt', 3, d2) end, + nil)) + eq(2, d2.dv_refcount) + lib.emsg_skip = lib.emsg_skip - 1 + alloc_log:clear_tmp_allocs() + alloc_log:check({}) + end) + end) + describe('dict_add_nr()', function() + itp('works', function() + local d = dict({test=10}) + alloc_log:clear() + eq({test=10}, dct2tbl(d)) + eq(OK, lib.tv_dict_add_nr(d, 'testt', 3, 2)) + local dis = dict_items(d) + alloc_log:check({a.di(dis.tes, 'tes')}) + eq({test=10, tes=int(2)}, dct2tbl(d)) + eq(FAIL, check_emsg(function() return lib.tv_dict_add_nr(d, 'testt', 3, 2) end, + 'E685: Internal error: hash_add()')) + alloc_log:clear() + lib.emsg_skip = lib.emsg_skip + 1 + eq(FAIL, check_emsg(function() return lib.tv_dict_add_nr(d, 'testt', 3, 2) end, + nil)) + lib.emsg_skip = lib.emsg_skip - 1 + alloc_log:clear_tmp_allocs() + alloc_log:check({}) + end) + end) + describe('dict_add_str()', function() + itp('works', function() + local d = dict({test=10}) + alloc_log:clear() + eq({test=10}, dct2tbl(d)) + eq(OK, lib.tv_dict_add_str(d, 'testt', 3, 'TEST')) + local dis = dict_items(d) + alloc_log:check({ + a.di(dis.tes, 'tes'), + a.str(dis.tes.di_tv.vval.v_string, 'TEST') + }) + eq({test=10, tes='TEST'}, dct2tbl(d)) + eq(FAIL, check_emsg(function() return lib.tv_dict_add_str(d, 'testt', 3, 'TEST') end, + 'E685: Internal error: hash_add()')) + alloc_log:clear() + lib.emsg_skip = lib.emsg_skip + 1 + eq(FAIL, check_emsg(function() return lib.tv_dict_add_str(d, 'testt', 3, 'TEST') end, + nil)) + lib.emsg_skip = lib.emsg_skip - 1 + alloc_log:clear_tmp_allocs() + alloc_log:check({}) + end) + end) end) end) end) -- cgit From 4987850cacc9f0c5674bc4cb8197a6fa0a343167 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 13 Mar 2017 13:43:25 +0300 Subject: unittests: Add tv_dict_clear tests --- test/unit/eval/typval_spec.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index c710171779..b16e118053 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1887,5 +1887,23 @@ describe('typval.c', function() end) end) end) + describe('clear()', function() + itp('works', function() + local d = dict() + alloc_log:check({a.dict(d)}) + eq({}, dct2tbl(d)) + lib.tv_dict_clear(d) + eq({}, dct2tbl(d)) + lib.tv_dict_add_str(d, 'TEST', 3, 'tEsT') + local dis = dict_items(d) + local di = dis.TES + local di_s = di.di_tv.vval.v_string + alloc_log:check({a.di(di), a.str(di_s)}) + eq({TES='tEsT'}, dct2tbl(d)) + lib.tv_dict_clear(d) + alloc_log:check({a.freed(di_s), a.freed(di)}) + eq({}, dct2tbl(d)) + end) + end) end) end) -- cgit From fa852e7cdc365b6fcd39d677f4067963274c44c3 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 13 Mar 2017 14:17:35 +0300 Subject: eval: Fix extend() behaviour with NULL lists and dictionaries Ref #4615 Ref vim/vim#768 --- test/functional/eval/null_spec.lua | 147 ++++++++++++++++++------------------- 1 file changed, 73 insertions(+), 74 deletions(-) (limited to 'test') diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua index 3b361ceeda..6fd30caec9 100644 --- a/test/functional/eval/null_spec.lua +++ b/test/functional/eval/null_spec.lua @@ -20,120 +20,119 @@ describe('NULL', function() after_each(function() os.remove(tmpfname) end) + local null_test = function(name, cmd, err) + it(name, function() + eq(err, exc_exec(cmd)) + end) + end + local null_expr_test = function(name, expr, err, val, after) + it(name, function() + eq((err == 0) and ('') or ('\n' .. err), + redir_exec('let g:_var = ' .. expr)) + if val == nil then + eq(0, funcs.exists('g:_var')) + else + eq(val, meths.get_var('_var')) + end + if after ~= nil then + after() + end + end) + end describe('list', function() - local null_list_test = function(name, cmd, err) - it(name, function() - eq(err, exc_exec(cmd)) - end) - end - local null_list_expr_test = function(name, expr, err, val, after) - it(name, function() - eq((err == 0) and ('') or ('\n' .. err), - redir_exec('let g:_var = ' .. expr)) - if val == nil then - eq(0, funcs.exists('g:_var')) - else - eq(val, meths.get_var('_var')) - end - if after ~= nil then - after() - end - end) - end - -- Incorrect behaviour -- FIXME map() should not return 0 without error - null_list_expr_test('does not crash map()', 'map(L, "v:val")', 0, 0) + null_expr_test('does not crash map()', 'map(L, "v:val")', 0, 0) -- FIXME map() should not return 0 without error - null_list_expr_test('does not crash filter()', 'filter(L, "1")', 0, 0) + null_expr_test('does not crash filter()', 'filter(L, "1")', 0, 0) -- FIXME map() should at least return L - null_list_expr_test('makes map() return v:_null_list', 'map(L, "v:val") is# L', 0, 0) + null_expr_test('makes map() return v:_null_list', 'map(L, "v:val") is# L', 0, 0) -- FIXME filter() should at least return L - null_list_expr_test('makes filter() return v:_null_list', 'map(L, "1") is# L', 0, 0) + null_expr_test('makes filter() return v:_null_list', 'map(L, "1") is# L', 0, 0) -- FIXME add() should not return 1 at all - null_list_expr_test('does not crash add()', 'add(L, 0)', 0, 1) - -- FIXME extend() should not return 0 without error - null_list_expr_test('does not crash extend()', 'extend(L, [1])', 0, 0) - -- FIXME extend() should not return 0 at all - null_list_expr_test('does not crash extend() (second position)', 'extend([1], L)', 0, 0) + null_expr_test('does not crash add()', 'add(L, 0)', 0, 1) + null_expr_test('does not crash extend()', 'extend(L, [1])', 'E742: Cannot change value of extend() argument', 0) + null_expr_test('does not crash extend() (second position)', 'extend([1], L)', 0, {1}) -- FIXME should be accepted by inputlist() - null_list_expr_test('is accepted as an empty list by inputlist()', + null_expr_test('is accepted as an empty list by inputlist()', '[feedkeys("\\n"), inputlist(L)]', 'E686: Argument of inputlist() must be a List', {0, 0}) -- FIXME should be accepted by writefile(), return {0, {}} - null_list_expr_test('is accepted as an empty list by writefile()', + null_expr_test('is accepted as an empty list by writefile()', ('[writefile(L, "%s"), readfile("%s")]'):format(tmpfname, tmpfname), 'E484: Can\'t open file ' .. tmpfname, {0, {}}) -- FIXME should give error message - null_list_expr_test('does not crash remove()', 'remove(L, 0)', 0, 0) + null_expr_test('does not crash remove()', 'remove(L, 0)', 0, 0) -- FIXME should return 0 - null_list_expr_test('is accepted by setqflist()', 'setqflist(L)', 0, -1) + null_expr_test('is accepted by setqflist()', 'setqflist(L)', 0, -1) -- FIXME should return 0 - null_list_expr_test('is accepted by setloclist()', 'setloclist(1, L)', 0, -1) + null_expr_test('is accepted by setloclist()', 'setloclist(1, L)', 0, -1) -- FIXME should return 0 - null_list_expr_test('is accepted by setmatches()', 'setmatches(L)', 0, -1) + null_expr_test('is accepted by setmatches()', 'setmatches(L)', 0, -1) -- FIXME should return empty list or error out - null_list_expr_test('is accepted by sort()', 'sort(L)', 0, 0) + null_expr_test('is accepted by sort()', 'sort(L)', 0, 0) -- FIXME Should return 1 - null_list_expr_test('is accepted by sort()', 'sort(L) is L', 0, 0) + null_expr_test('is accepted by sort()', 'sort(L) is L', 0, 0) -- FIXME should not error out - null_list_test('is accepted by :cexpr', 'cexpr L', 'Vim(cexpr):E777: String or List expected') + null_test('is accepted by :cexpr', 'cexpr L', 'Vim(cexpr):E777: String or List expected') -- FIXME should not error out - null_list_test('is accepted by :lexpr', 'lexpr L', 'Vim(lexpr):E777: String or List expected') - null_list_test('is accepted by :for', 'for x in L|throw x|endfor', 0) + null_test('is accepted by :lexpr', 'lexpr L', 'Vim(lexpr):E777: String or List expected') + null_test('is accepted by :for', 'for x in L|throw x|endfor', 0) -- Subjectable behaviour -- FIXME Should return 1 - null_list_expr_test('is equal to empty list', 'L == []', 0, 0) + null_expr_test('is equal to empty list', 'L == []', 0, 0) -- FIXME Should return 1 - null_list_expr_test('is equal to empty list (reverse order)', '[] == L', 0, 0) + null_expr_test('is equal to empty list (reverse order)', '[] == L', 0, 0) -- FIXME Should return 1 - null_list_expr_test('is not locked', 'islocked("v:_null_list")', 0, 0) + null_expr_test('is not locked', 'islocked("v:_null_list")', 0, 0) -- Crashes - -- null_list_expr_test('does not crash setreg', 'setreg("x", L)', 0, 0) - -- null_list_expr_test('does not crash setline', 'setline(1, L)', 0, 0) - -- null_list_expr_test('does not crash system()', 'system("cat", L)', 0, '') - -- null_list_expr_test('does not crash systemlist()', 'systemlist("cat", L)', 0, {}) + -- null_expr_test('does not crash setreg', 'setreg("x", L)', 0, 0) + -- null_expr_test('does not crash setline', 'setline(1, L)', 0, 0) + -- null_expr_test('does not crash system()', 'system("cat", L)', 0, '') + -- null_expr_test('does not crash systemlist()', 'systemlist("cat", L)', 0, {}) -- Correct behaviour - null_list_expr_test('does not crash append()', 'append(1, L)', 0, 0, function() + null_expr_test('does not crash append()', 'append(1, L)', 0, 0, function() eq({''}, curbufmeths.get_lines(0, -1, false)) end) - null_list_expr_test('is identical to itself', 'L is L', 0, 1) - null_list_expr_test('can be sliced', 'L[:]', 0, {}) - null_list_expr_test('can be copied', 'copy(L)', 0, {}) - null_list_expr_test('can be deepcopied', 'deepcopy(L)', 0, {}) - null_list_expr_test('does not crash when indexed', 'L[1]', + null_expr_test('is identical to itself', 'L is L', 0, 1) + null_expr_test('can be sliced', 'L[:]', 0, {}) + null_expr_test('can be copied', 'copy(L)', 0, {}) + null_expr_test('can be deepcopied', 'deepcopy(L)', 0, {}) + null_expr_test('does not crash when indexed', 'L[1]', 'E684: list index out of range: 1\nE15: Invalid expression: L[1]', nil) - null_list_expr_test('does not crash call()', 'call("arglistid", L)', 0, 0) - null_list_expr_test('does not crash col()', 'col(L)', 0, 0) - null_list_expr_test('does not crash virtcol()', 'virtcol(L)', 0, 0) - null_list_expr_test('does not crash line()', 'line(L)', 0, 0) - null_list_expr_test('does not crash count()', 'count(L, 1)', 0, 0) - null_list_expr_test('does not crash cursor()', 'cursor(L)', 'E474: Invalid argument', -1) - null_list_expr_test('is empty', 'empty(L)', 0, 1) - null_list_expr_test('does not crash get()', 'get(L, 1, 10)', 0, 10) - null_list_expr_test('has zero length', 'len(L)', 0, 0) - null_list_expr_test('is accepted as an empty list by max()', 'max(L)', 0, 0) - null_list_expr_test('is accepted as an empty list by min()', 'min(L)', 0, 0) - null_list_expr_test('is stringified correctly', 'string(L)', 0, '[]') - null_list_expr_test('is JSON encoded correctly', 'json_encode(L)', 0, '[]') - null_list_test('does not crash lockvar', 'lockvar! L', 0) - null_list_expr_test('can be added to itself', '(L + L)', 0, {}) - null_list_expr_test('can be added to itself', '(L + L) is L', 0, 1) - null_list_expr_test('can be added to non-empty list', '([1] + L)', 0, {1}) - null_list_expr_test('can be added to non-empty list (reversed)', '(L + [1])', 0, {1}) - null_list_expr_test('is equal to itself', 'L == L', 0, 1) - null_list_expr_test('is not not equal to itself', 'L != L', 0, 0) - null_list_expr_test('counts correctly', 'count([L], L)', 0, 1) + null_expr_test('does not crash call()', 'call("arglistid", L)', 0, 0) + null_expr_test('does not crash col()', 'col(L)', 0, 0) + null_expr_test('does not crash virtcol()', 'virtcol(L)', 0, 0) + null_expr_test('does not crash line()', 'line(L)', 0, 0) + null_expr_test('does not crash count()', 'count(L, 1)', 0, 0) + null_expr_test('does not crash cursor()', 'cursor(L)', 'E474: Invalid argument', -1) + null_expr_test('is empty', 'empty(L)', 0, 1) + null_expr_test('does not crash get()', 'get(L, 1, 10)', 0, 10) + null_expr_test('has zero length', 'len(L)', 0, 0) + null_expr_test('is accepted as an empty list by max()', 'max(L)', 0, 0) + null_expr_test('is accepted as an empty list by min()', 'min(L)', 0, 0) + null_expr_test('is stringified correctly', 'string(L)', 0, '[]') + null_expr_test('is JSON encoded correctly', 'json_encode(L)', 0, '[]') + null_test('does not crash lockvar', 'lockvar! L', 0) + null_expr_test('can be added to itself', '(L + L)', 0, {}) + null_expr_test('can be added to itself', '(L + L) is L', 0, 1) + null_expr_test('can be added to non-empty list', '([1] + L)', 0, {1}) + null_expr_test('can be added to non-empty list (reversed)', '(L + [1])', 0, {1}) + null_expr_test('is equal to itself', 'L == L', 0, 1) + null_expr_test('is not not equal to itself', 'L != L', 0, 0) + null_expr_test('counts correctly', 'count([L], L)', 0, 1) end) describe('dict', function() it('does not crash when indexing NULL dict', function() eq('\nE716: Key not present in Dictionary: test\nE15: Invalid expression: v:_null_dict.test', redir_exec('echo v:_null_dict.test')) end) + null_expr_test('makes extend error out', 'extend(D, {})', 'E742: Cannot change value of extend() argument', 0) + null_expr_test('makes extend do nothing', 'extend({1: 2}, D)', 0, {['1']=2}) end) end) -- cgit From 8b9a1fbf7a630b68b1428a39f25e1fa38fe0cc9f Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 13 Mar 2017 14:35:53 +0300 Subject: unittests: Add tests for tv_dict_extend --- test/unit/eval/helpers.lua | 12 ++++ test/unit/eval/tricks_spec.lua | 14 ++--- test/unit/eval/typval_spec.lua | 129 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 144 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index 6909953022..a3cb062b7b 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -498,6 +498,16 @@ local function dict_watchers(d) return ret, qs, key_patterns end +local function eval0(expr) + local tv = ffi.gc(ffi.new('typval_T', {v_type=eval.VAR_UNKNOWN}), + eval.tv_clear) + if eval.eval0(to_cstr(expr), tv, nil, true) == 0 then + return nil + else + return tv + end +end + return { int=int, @@ -540,5 +550,7 @@ return { tbl2callback=tbl2callback, callback2tbl=callback2tbl, + eval0=eval0, + empty_list = {[type_key]=list_type}, } diff --git a/test/unit/eval/tricks_spec.lua b/test/unit/eval/tricks_spec.lua index 54029734fb..ae569bed11 100644 --- a/test/unit/eval/tricks_spec.lua +++ b/test/unit/eval/tricks_spec.lua @@ -1,4 +1,6 @@ local helpers = require('test.unit.helpers')(after_each) +local eval_helpers = require('test.unit.eval.helpers') + local itp = helpers.gen_itp(it) local cimport = helpers.cimport @@ -6,19 +8,11 @@ local to_cstr = helpers.to_cstr local ffi = helpers.ffi local eq = helpers.eq +local eval0 = eval_helpers.eval0 + local eval = cimport('./src/nvim/eval.h', './src/nvim/eval/typval.h', './src/nvim/memory.h') -local eval0 = function(expr) - local tv = ffi.gc(ffi.new('typval_T', {v_type=eval.VAR_UNKNOWN}), - eval.tv_clear) - if eval.eval0(to_cstr(expr), tv, nil, true) == 0 then - return nil - else - return tv - end -end - describe('NULL typval_T', function() itp('is produced by $XXX_UNEXISTENT_VAR_XXX', function() -- Required for various tests which need to check whether typval_T with NULL diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index b16e118053..00dc230e89 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1,6 +1,7 @@ +local bit = require('bit') local helpers = require('test.unit.helpers')(after_each) -local global_helpers = require('test.helpers') local eval_helpers = require('test.unit.eval.helpers') +local global_helpers = require('test.helpers') local itp = helpers.gen_itp(it) @@ -17,6 +18,7 @@ local a = eval_helpers.alloc_logging_helpers local int = eval_helpers.int local list = eval_helpers.list local dict = eval_helpers.dict +local eval0 = eval_helpers.eval0 local lst2tbl = eval_helpers.lst2tbl local dct2tbl = eval_helpers.dct2tbl local typvalt = eval_helpers.typvalt @@ -1905,5 +1907,130 @@ describe('typval.c', function() eq({}, dct2tbl(d)) end) end) + describe('extend()', function() + local function tv_dict_extend(d1, d2, action, emsg) + action = action or "force" + check_emsg(function() return lib.tv_dict_extend(d1, d2, action) end, emsg) + end + itp('works', function() + local d1 = dict() + alloc_log:check({a.dict(d1)}) + eq({}, dct2tbl(d1)) + local d2 = dict() + alloc_log:check({a.dict(d2)}) + eq({}, dct2tbl(d2)) + tv_dict_extend(d1, d2, 'error') + tv_dict_extend(d1, d2, 'keep') + tv_dict_extend(d1, d2, 'force') + alloc_log:check({}) + + d1 = dict({a='TEST'}) + eq({a='TEST'}, dct2tbl(d1)) + local dis1 = dict_items(d1) + local a1_s = dis1.a.di_tv.vval.v_string + alloc_log:clear_tmp_allocs() + alloc_log:check({ + a.dict(d1), + a.di(dis1.a), + a.str(a1_s), + }) + d2 = dict({a='TSET'}) + eq({a='TSET'}, dct2tbl(d2)) + local dis2 = dict_items(d2) + local a2_s = dis2.a.di_tv.vval.v_string + alloc_log:clear_tmp_allocs() + alloc_log:check({ + a.dict(d2), + a.di(dis2.a), + a.str(a2_s), + }) + + tv_dict_extend(d1, d2, 'error', 'E737: Key already exists: a') + eq({a='TEST'}, dct2tbl(d1)) + eq({a='TSET'}, dct2tbl(d2)) + alloc_log:clear() + + tv_dict_extend(d1, d2, 'keep') + alloc_log:check({}) + eq({a='TEST'}, dct2tbl(d1)) + eq({a='TSET'}, dct2tbl(d2)) + + tv_dict_extend(d1, d2, 'force') + alloc_log:check({ + a.freed(a1_s), + a.str(dis1.a.di_tv.vval.v_string), + }) + eq({a='TSET'}, dct2tbl(d1)) + eq({a='TSET'}, dct2tbl(d2)) + end) + itp('disallows overriding builtin or user functions', function() + local d = dict() + d.dv_scope = lib.VAR_DEF_SCOPE + local f_lua = { + [type_key]=func_type, + value='tr', + } + local f_tv = lua2typvalt(f_lua) + local p_lua = { + [type_key]=func_type, + value='tr', + args={1}, + } + local p_tv = lua2typvalt(p_lua) + eq(lib.VAR_PARTIAL, p_tv.v_type) + local d2 = dict({tr=f_tv}) + local d3 = dict({tr=p_tv}) + local d4 = dict({['TEST:THIS']=p_tv}) + local d5 = dict({Test=f_tv}) + local d6 = dict({Test=p_tv}) + eval0([[execute("function Test()\nendfunction")]]) + tv_dict_extend(d, d2, 'force', + 'E704: Funcref variable name must start with a capital: tr') + tv_dict_extend(d, d3, 'force', + 'E704: Funcref variable name must start with a capital: tr') + tv_dict_extend(d, d4, 'force', + 'E461: Illegal variable name: TEST:THIS') + tv_dict_extend(d, d5, 'force', + 'E705: Variable name conflicts with existing function: Test') + tv_dict_extend(d, d6, 'force', + 'E705: Variable name conflicts with existing function: Test') + eq({}, dct2tbl(d)) + d.dv_scope = lib.VAR_SCOPE + tv_dict_extend(d, d4, 'force', + 'E461: Illegal variable name: TEST:THIS') + eq({}, dct2tbl(d)) + tv_dict_extend(d, d2, 'force') + eq({tr=f_lua}, dct2tbl(d)) + tv_dict_extend(d, d3, 'force') + eq({tr=p_lua}, dct2tbl(d)) + tv_dict_extend(d, d5, 'force') + eq({tr=p_lua, Test=f_lua}, dct2tbl(d)) + tv_dict_extend(d, d6, 'force') + eq({tr=p_lua, Test=p_lua}, dct2tbl(d)) + end) + itp('cares about locks and read-only items', function() + local d_lua = {tv_locked=1, tv_fixed=2, di_ro=3, di_ro_sbx=4} + local d = dict(d_lua) + local dis = dict_items(d) + dis.tv_locked.di_tv.v_lock = lib.VAR_LOCKED + dis.tv_fixed.di_tv.v_lock = lib.VAR_FIXED + dis.di_ro.di_flags = bit.bor(dis.di_ro.di_flags, lib.DI_FLAGS_RO) + dis.di_ro_sbx.di_flags = bit.bor(dis.di_ro_sbx.di_flags, lib.DI_FLAGS_RO_SBX) + lib.sandbox = true + local d1 = dict({tv_locked=41}) + local d2 = dict({tv_fixed=42}) + local d3 = dict({di_ro=43}) + local d4 = dict({di_ro_sbx=44}) + tv_dict_extend(d, d1, 'force', 'E741: Value is locked: extend() argument') + tv_dict_extend(d, d2, 'force', 'E742: Cannot change value of extend() argument') + tv_dict_extend(d, d3, 'force', 'E46: Cannot change read-only variable "extend() argument"') + tv_dict_extend(d, d4, 'force', 'E794: Cannot set variable in the sandbox: "extend() argument"') + eq(d_lua, dct2tbl(d)) + lib.sandbox = false + tv_dict_extend(d, d4, 'force') + d_lua.di_ro_sbx = 44 + eq(d_lua, dct2tbl(d)) + end) + end) end) end) -- cgit From 368a61c5259384d3c32cef4c482953ec318cf900 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 13 Mar 2017 19:00:36 +0300 Subject: unittests: Add tv_dict_copy tests --- test/unit/eval/typval_spec.lua | 175 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 165 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 00dc230e89..f81f7561b9 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -29,6 +29,7 @@ local func_type = eval_helpers.func_type local null_list = eval_helpers.null_list local null_dict = eval_helpers.null_dict local dict_items = eval_helpers.dict_items +local list_items = eval_helpers.list_items local empty_list = eval_helpers.empty_list local lua2typvalt = eval_helpers.lua2typvalt local typvalt2lua = eval_helpers.typvalt2lua @@ -43,16 +44,6 @@ local lib = cimport('./src/nvim/eval/typval.h', './src/nvim/memory.h', './src/nvim/mbyte.h', './src/nvim/garray.h', './src/nvim/eval.h', './src/nvim/vim.h') -local function list_items(l) - local lis = {} - local li = l.lv_first - for i = 1, l.lv_len do - lis[i] = ffi.gc(li, nil) - li = li.li_next - end - return lis -end - local function list_watch_alloc(li) return ffi.cast('listwatch_T*', ffi.new('listwatch_T[1]', {{lw_item=li}})) end @@ -2032,5 +2023,169 @@ describe('typval.c', function() eq(d_lua, dct2tbl(d)) end) end) + describe('equal()', function() + local function tv_dict_equal(d1, d2, ic, recursive) + return lib.tv_dict_equal(d1, d2, ic or false, recursive or false) + end + itp('works', function() + eq(true, tv_dict_equal(nil, nil)) + local d1 = dict() + alloc_log:check({a.dict(d1)}) + eq(1, d1.dv_refcount) + eq(false, tv_dict_equal(nil, d1)) + eq(false, tv_dict_equal(d1, nil)) + eq(true, tv_dict_equal(d1, d1)) + eq(1, d1.dv_refcount) + alloc_log:check({}) + local d_upper = dict({a='TEST'}) + local dis_upper = dict_items(d_upper) + local d_lower = dict({a='test'}) + local dis_lower = dict_items(d_lower) + local d_kupper_upper = dict({A='TEST'}) + local dis_kupper_upper = dict_items(d_kupper_upper) + local d_kupper_lower = dict({A='test'}) + local dis_kupper_lower = dict_items(d_kupper_lower) + alloc_log:clear_tmp_allocs() + alloc_log:check({ + a.dict(d_upper), + a.di(dis_upper.a), + a.str(dis_upper.a.di_tv.vval.v_string), + + a.dict(d_lower), + a.di(dis_lower.a), + a.str(dis_lower.a.di_tv.vval.v_string), + + a.dict(d_kupper_upper), + a.di(dis_kupper_upper.A), + a.str(dis_kupper_upper.A.di_tv.vval.v_string), + + a.dict(d_kupper_lower), + a.di(dis_kupper_lower.A), + a.str(dis_kupper_lower.A.di_tv.vval.v_string), + }) + eq(true, tv_dict_equal(d_upper, d_upper)) + eq(true, tv_dict_equal(d_upper, d_upper, true)) + eq(false, tv_dict_equal(d_upper, d_lower, false)) + eq(true, tv_dict_equal(d_upper, d_lower, true)) + eq(true, tv_dict_equal(d_kupper_upper, d_kupper_lower, true)) + eq(false, tv_dict_equal(d_kupper_upper, d_lower, true)) + eq(false, tv_dict_equal(d_kupper_upper, d_upper, true)) + eq(true, tv_dict_equal(d_upper, d_upper, true, true)) + alloc_log:check({}) + end) + end) + describe('copy()', function() + local function tv_dict_copy(...) + return ffi.gc(lib.tv_dict_copy(...), lib.tv_dict_unref) + end + itp('copies NULL correctly', function() + eq(nil, lib.tv_dict_copy(nil, nil, true, 0)) + eq(nil, lib.tv_dict_copy(nil, nil, false, 0)) + eq(nil, lib.tv_dict_copy(nil, nil, true, 1)) + eq(nil, lib.tv_dict_copy(nil, nil, false, 1)) + end) + itp('copies dict correctly without converting items', function() + do + local v = {a={['«']='»'}, b={'„'}, ['1']=1, ['«»']='“', ns=null_string, nl=null_list, nd=null_dict} + local d_tv = lua2typvalt(v) + local d = d_tv.vval.v_dict + local dis = dict_items(d) + alloc_log:clear() + + eq(1, dis.a.di_tv.vval.v_dict.dv_refcount) + eq(1, dis.b.di_tv.vval.v_list.lv_refcount) + local d_copy1 = tv_dict_copy(nil, d, false, 0) + eq(2, dis.a.di_tv.vval.v_dict.dv_refcount) + eq(2, dis.b.di_tv.vval.v_list.lv_refcount) + local dis_copy1 = dict_items(d_copy1) + eq(dis.a.di_tv.vval.v_dict, dis_copy1.a.di_tv.vval.v_dict) + eq(dis.b.di_tv.vval.v_list, dis_copy1.b.di_tv.vval.v_list) + eq(v, dct2tbl(d_copy1)) + alloc_log:clear() + lib.tv_dict_free(ffi.gc(d_copy1, nil)) + alloc_log:clear() + + eq(1, dis.a.di_tv.vval.v_dict.dv_refcount) + eq(1, dis.b.di_tv.vval.v_list.lv_refcount) + local d_deepcopy1 = tv_dict_copy(nil, d, true, 0) + neq(nil, d_deepcopy1) + eq(1, dis.a.di_tv.vval.v_dict.dv_refcount) + eq(1, dis.b.di_tv.vval.v_list.lv_refcount) + local dis_deepcopy1 = dict_items(d_deepcopy1) + neq(dis.a.di_tv.vval.v_dict, dis_deepcopy1.a.di_tv.vval.v_dict) + neq(dis.b.di_tv.vval.v_list, dis_deepcopy1.b.di_tv.vval.v_list) + eq(v, dct2tbl(d_deepcopy1)) + local di_deepcopy1 = first_di(dis_deepcopy1.a.di_tv.vval.v_dict) + alloc_log:clear() + end + collectgarbage() + end) + itp('copies dict correctly and converts items', function() + local vc = ffi.gc(ffi.new('vimconv_T[1]'), function(vc) + lib.convert_setup(vc, nil, nil) + end) + -- UTF-8 ↔ latin1 conversions need no iconv + eq(OK, lib.convert_setup(vc, to_cstr('utf-8'), to_cstr('latin1'))) + + local v = {a={['«']='»'}, b={'„'}, ['1']=1, ['«»']='“', ns=null_string, nl=null_list, nd=null_dict} + local d_tv = lua2typvalt(v) + local d = d_tv.vval.v_dict + local dis = dict_items(d) + alloc_log:clear() + + eq(1, dis.a.di_tv.vval.v_dict.dv_refcount) + eq(1, dis.b.di_tv.vval.v_list.lv_refcount) + local d_deepcopy1 = tv_dict_copy(vc, d, true, 0) + neq(nil, d_deepcopy1) + eq(1, dis.a.di_tv.vval.v_dict.dv_refcount) + eq(1, dis.b.di_tv.vval.v_list.lv_refcount) + local dis_deepcopy1 = dict_items(d_deepcopy1) + neq(dis.a.di_tv.vval.v_dict, dis_deepcopy1.a.di_tv.vval.v_dict) + neq(dis.b.di_tv.vval.v_list, dis_deepcopy1.b.di_tv.vval.v_list) + eq({a={['\171']='\187'}, b={'\191'}, ['1']=1, ['\171\187']='\191', ns=null_string, nl=null_list, nd=null_dict}, + dct2tbl(d_deepcopy1)) + alloc_log:clear_tmp_allocs() + alloc_log:clear() + end) + itp('returns different/same containers with(out) copyID', function() + local d_inner_tv = lua2typvalt({}) + local d_tv = lua2typvalt({a=d_inner_tv, b=d_inner_tv}) + eq(3, d_inner_tv.vval.v_dict.dv_refcount) + local d = d_tv.vval.v_dict + local dis = dict_items(d) + eq(dis.a.di_tv.vval.v_dict, dis.b.di_tv.vval.v_dict) + + local d_copy1 = tv_dict_copy(nil, d, true, 0) + local dis_copy1 = dict_items(d_copy1) + neq(dis_copy1.a.di_tv.vval.v_dict, dis_copy1.b.di_tv.vval.v_dict) + eq({a={}, b={}}, dct2tbl(d_copy1)) + + local d_copy2 = tv_dict_copy(nil, d, true, 2) + local dis_copy2 = dict_items(d_copy2) + eq(dis_copy2.a.di_tv.vval.v_dict, dis_copy2.b.di_tv.vval.v_dict) + eq({a={}, b={}}, dct2tbl(d_copy2)) + + eq(3, d_inner_tv.vval.v_dict.dv_refcount) + end) + itp('works with self-referencing dict with copyID', function() + local d_tv = lua2typvalt({}) + local d = d_tv.vval.v_dict + eq(1, d.dv_refcount) + lib.tv_dict_add_dict(d, 'test', 4, d) + eq(2, d.dv_refcount) + + local d_copy1 = tv_dict_copy(nil, d, true, 2) + eq(2, d_copy1.dv_refcount) + local v = {} + v.test = v + eq(v, dct2tbl(d_copy1)) + + lib.tv_dict_clear(d) + eq(1, d.dv_refcount) + + lib.tv_dict_clear(d_copy1) + eq(1, d_copy1.dv_refcount) + end) + end) end) end) -- cgit From e43de6bb3e1efb58669ab904c5672f4ae87003c0 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 13 Mar 2017 19:04:59 +0300 Subject: unittests: Add test for tv_dict_set_keys_readonly --- test/unit/eval/typval_spec.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index f81f7561b9..0d894ff8b0 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -2187,5 +2187,18 @@ describe('typval.c', function() eq(1, d_copy1.dv_refcount) end) end) + describe('set_keys_readonly()', function() + itp('works', function() + local d = dict({a=true}) + local dis = dict_items(d) + alloc_log:check({a.dict(d), a.di(dis.a)}) + eq(0, bit.band(dis.a.di_flags, lib.DI_FLAGS_RO)) + eq(0, bit.band(dis.a.di_flags, lib.DI_FLAGS_FIX)) + lib.tv_dict_set_keys_readonly(d) + alloc_log:check({}) + eq(lib.DI_FLAGS_RO, bit.band(dis.a.di_flags, lib.DI_FLAGS_RO)) + eq(lib.DI_FLAGS_FIX, bit.band(dis.a.di_flags, lib.DI_FLAGS_FIX)) + end) + end) end) end) -- cgit From f0bbd1e825841c55a1f75d66a9caeaa50cc2259c Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 13 Mar 2017 19:35:12 +0300 Subject: unittests: Add tests for tv_clear() --- test/unit/eval/typval_spec.lua | 73 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 0d894ff8b0..8b0470d3b7 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -55,12 +55,16 @@ local function list_watch(l, li) end local function get_alloc_rets(exp_log, res) + setmetatable(res, { + __index={ + freed=function(r, n) return {func='free', args={r[n]}} end + } + }) for i = 1,#exp_log do if ({malloc=true, calloc=true})[exp_log[i].func] then res[#res + 1] = exp_log[i].ret end end - res.freed = function(r, n) return {func='free', args={r[n]}} end return exp_log end @@ -2201,4 +2205,71 @@ describe('typval.c', function() end) end) end) + describe('tv', function() + describe('alloc', function() + describe('list ret()', function() + itp('works', function() + local rettv = typvalt(lib.VAR_UNKNOWN) + local l = lib.tv_list_alloc_ret(rettv) + eq(empty_list, typvalt2lua(rettv)) + eq(rettv.vval.v_list, l) + end) + end) + describe('dict ret()', function() + itp('works', function() + local rettv = typvalt(lib.VAR_UNKNOWN) + lib.tv_dict_alloc_ret(rettv) + eq({}, typvalt2lua(rettv)) + end) + end) + end) + describe('clear()', function() + itp('works', function() + local function deffrees(alloc_rets) + local ret = {} + for i = #alloc_rets, 1, -1 do + ret[#alloc_rets - i + 1] = alloc_rets:freed(i) + end + return ret + end + local function defalloc() + return {} + end + alloc_log:check({}) + lib.tv_clear(nil) + alloc_log:check({}) + local ll = {} + local ll_l = nil + ll[1] = ll + local dd = {} + dd.dd = dd + for _, v in ipairs({ + {nil}, + {null_string, nil, function() return {a.freed(alloc_log.null)} end}, + {0}, + {int(0)}, + {true}, + {false}, + {{}, function(tv) return {a.dict(tv.vval.v_dict)} end}, + {empty_list, function(tv) return {a.list(tv.vval.v_list)} end}, + {ll, function(tv) + ll_l = tv.vval.v_list + return {a.list(tv.vval.v_list), a.li(tv.vval.v_list.lv_first)} + end, defalloc}, + {dd, function(tv) + dd_d = tv.vval.v_dict + return {a.dict(tv.vval.v_dict), a.di(first_di(tv.vval.v_dict))} + end, defalloc}, + }) do + local tv = lua2typvalt(v[1]) + local alloc_rets = {} + alloc_log:check(get_alloc_rets((v[2] or defalloc)(tv), alloc_rets)) + lib.tv_clear(tv) + alloc_log:check((v[3] or deffrees)(alloc_rets)) + end + eq(1, ll_l.lv_refcount) + eq(1, dd_d.dv_refcount) + end) + end) + end) end) -- cgit From ed4948a93317bf801eb2454fd5597a4388730a7b Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 13 Mar 2017 19:49:13 +0300 Subject: unittests: Test tv_copy() --- test/unit/eval/helpers.lua | 8 +++---- test/unit/eval/typval_spec.lua | 47 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index a3cb062b7b..fa76113756 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -132,10 +132,10 @@ local function typvalt2lua_tab_init() typvalt2lua_tab = { [tonumber(eval.VAR_SPECIAL)] = function(t) return ({ - [eval.kSpecialVarFalse] = false, - [eval.kSpecialVarNull] = nil_value, - [eval.kSpecialVarTrue] = true, - })[t.vval.v_special] + [tonumber(eval.kSpecialVarFalse)] = false, + [tonumber(eval.kSpecialVarNull)] = nil_value, + [tonumber(eval.kSpecialVarTrue)] = true, + })[tonumber(t.vval.v_special)] end, [tonumber(eval.VAR_NUMBER)] = function(t) return {[type_key]=int_type, value=tonumber(t.vval.v_number)} diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 8b0470d3b7..9745a432c3 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -25,6 +25,7 @@ local typvalt = eval_helpers.typvalt local type_key = eval_helpers.type_key local li_alloc = eval_helpers.li_alloc local first_di = eval_helpers.first_di +local nil_value = eval_helpers.nil_value local func_type = eval_helpers.func_type local null_list = eval_helpers.null_list local null_dict = eval_helpers.null_dict @@ -2223,6 +2224,9 @@ describe('typval.c', function() end) end) end) + local function defalloc() + return {} + end describe('clear()', function() itp('works', function() local function deffrees(alloc_rets) @@ -2232,9 +2236,6 @@ describe('typval.c', function() end return ret end - local function defalloc() - return {} - end alloc_log:check({}) lib.tv_clear(nil) alloc_log:check({}) @@ -2244,12 +2245,13 @@ describe('typval.c', function() local dd = {} dd.dd = dd for _, v in ipairs({ - {nil}, + {nil_value}, {null_string, nil, function() return {a.freed(alloc_log.null)} end}, {0}, {int(0)}, {true}, {false}, + {'true', function(tv) return {a.str(tv.vval.v_string)} end}, {{}, function(tv) return {a.dict(tv.vval.v_dict)} end}, {empty_list, function(tv) return {a.list(tv.vval.v_list)} end}, {ll, function(tv) @@ -2271,5 +2273,42 @@ describe('typval.c', function() eq(1, dd_d.dv_refcount) end) end) + describe('copy()', function() + itp('works', function() + local function strallocs(tv) + return {a.str(tv.vval.v_string)} + end + for _, v in ipairs({ + {nil_value}, + {null_string}, + {0}, + {int(0)}, + {true}, + {false}, + {{}, function(tv) return {a.dict(tv.vval.v_dict)} end, nil, function(from, to) + eq(2, to.vval.v_dict.dv_refcount) + eq(to.vval.v_dict, from.vval.v_dict) + end}, + {empty_list, function(tv) return {a.list(tv.vval.v_list)} end, nil, function(from, to) + eq(2, to.vval.v_list.lv_refcount) + eq(to.vval.v_list, from.vval.v_list) + end}, + {'test', strallocs, strallocs, function(from, to) + neq(to.vval.v_string, from.vval.v_string) + end}, + }) do + local from = lua2typvalt(v[1]) + alloc_log:check((v[2] or defalloc)(from)) + local to = typvalt(lib.VAR_UNKNOWN) + lib.tv_copy(from, to) + local res = v[1] + eq(res, typvalt2lua(to)) + alloc_log:check((v[3] or defalloc)(to)) + if v[4] then + v[4](from, to) + end + end + end) + end) end) end) -- cgit From 630ff33dc144a64b5488b4132c0fc4351a5c84db Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 25 Mar 2017 19:52:20 +0300 Subject: unittests: Test locks section --- test/unit/eval/typval_spec.lua | 114 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 9745a432c3..0619e43d08 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -2310,5 +2310,119 @@ describe('typval.c', function() end end) end) + describe('item_lock()', function() + itp('does not alter VAR_PARTIAL', function() + local p_tv = lua2typvalt({ + [type_key]=func_type, + value='tr', + dict={}, + }) + lib.tv_item_lock(p_tv, -1, true) + eq(lib.VAR_UNLOCKED, p_tv.vval.v_partial.pt_dict.dv_lock) + end) + itp('does not change VAR_FIXED values', function() + local d_tv = lua2typvalt({}) + local l_tv = lua2typvalt(empty_list) + alloc_log:clear() + d_tv.v_lock = lib.VAR_FIXED + d_tv.vval.v_dict.dv_lock = lib.VAR_FIXED + l_tv.v_lock = lib.VAR_FIXED + l_tv.vval.v_list.lv_lock = lib.VAR_FIXED + lib.tv_item_lock(d_tv, 1, true) + lib.tv_item_lock(l_tv, 1, true) + eq(lib.VAR_FIXED, d_tv.v_lock) + eq(lib.VAR_FIXED, l_tv.v_lock) + eq(lib.VAR_FIXED, d_tv.vval.v_dict.dv_lock) + eq(lib.VAR_FIXED, l_tv.vval.v_list.lv_lock) + lib.tv_item_lock(d_tv, 1, false) + lib.tv_item_lock(l_tv, 1, false) + eq(lib.VAR_FIXED, d_tv.v_lock) + eq(lib.VAR_FIXED, l_tv.v_lock) + eq(lib.VAR_FIXED, d_tv.vval.v_dict.dv_lock) + eq(lib.VAR_FIXED, l_tv.vval.v_list.lv_lock) + alloc_log:check({}) + end) + itp('works with NULL values', function() + local l_tv = lua2typvalt(null_list) + local d_tv = lua2typvalt(null_dict) + local s_tv = lua2typvalt(null_string) + alloc_log:clear() + lib.tv_item_lock(l_tv, 1, true) + lib.tv_item_lock(d_tv, 1, true) + lib.tv_item_lock(s_tv, 1, true) + eq(null_list, typvalt2lua(l_tv)) + eq(null_dict, typvalt2lua(d_tv)) + eq(null_string, typvalt2lua(s_tv)) + eq(lib.VAR_LOCKED, d_tv.v_lock) + eq(lib.VAR_LOCKED, l_tv.v_lock) + eq(lib.VAR_LOCKED, s_tv.v_lock) + alloc_log:check({}) + end) + end) + describe('islocked()', function() + itp('works with NULL values', function() + local l_tv = lua2typvalt(null_list) + local d_tv = lua2typvalt(null_dict) + eq(false, lib.tv_islocked(l_tv)) + eq(false, lib.tv_islocked(d_tv)) + end) + itp('works', function() + local tv = lua2typvalt() + local d_tv = lua2typvalt({}) + local l_tv = lua2typvalt(empty_list) + alloc_log:clear() + eq(false, lib.tv_islocked(tv)) + eq(false, lib.tv_islocked(l_tv)) + eq(false, lib.tv_islocked(d_tv)) + d_tv.vval.v_dict.dv_lock = lib.VAR_LOCKED + l_tv.vval.v_list.lv_lock = lib.VAR_LOCKED + eq(true, lib.tv_islocked(l_tv)) + eq(true, lib.tv_islocked(d_tv)) + tv.v_lock = lib.VAR_LOCKED + d_tv.v_lock = lib.VAR_LOCKED + l_tv.v_lock = lib.VAR_LOCKED + eq(true, lib.tv_islocked(tv)) + eq(true, lib.tv_islocked(l_tv)) + eq(true, lib.tv_islocked(d_tv)) + d_tv.vval.v_dict.dv_lock = lib.VAR_UNLOCKED + l_tv.vval.v_list.lv_lock = lib.VAR_UNLOCKED + eq(true, lib.tv_islocked(tv)) + eq(true, lib.tv_islocked(l_tv)) + eq(true, lib.tv_islocked(d_tv)) + tv.v_lock = lib.VAR_FIXED + d_tv.v_lock = lib.VAR_FIXED + l_tv.v_lock = lib.VAR_FIXED + eq(false, lib.tv_islocked(tv)) + eq(false, lib.tv_islocked(l_tv)) + eq(false, lib.tv_islocked(d_tv)) + d_tv.vval.v_dict.dv_lock = lib.VAR_LOCKED + l_tv.vval.v_list.lv_lock = lib.VAR_LOCKED + eq(true, lib.tv_islocked(l_tv)) + eq(true, lib.tv_islocked(d_tv)) + d_tv.vval.v_dict.dv_lock = lib.VAR_FIXED + l_tv.vval.v_list.lv_lock = lib.VAR_FIXED + eq(false, lib.tv_islocked(l_tv)) + eq(false, lib.tv_islocked(d_tv)) + alloc_log:check({}) + end) + end) + describe('check_lock()', function() + local function tv_check_lock(lock, name, name_len, emsg) + return check_emsg(function() + return lib.tv_check_lock(lock, name, name_len) + end, emsg) + end + itp('works', function() + eq(false, tv_check_lock(lib.VAR_UNLOCKED, 'test', 3)) + eq(true, tv_check_lock(lib.VAR_LOCKED, 'test', 3, + 'E741: Value is locked: tes')) + eq(true, tv_check_lock(lib.VAR_FIXED, 'test', 3, + 'E742: Cannot change value of tes')) + eq(true, tv_check_lock(lib.VAR_LOCKED, nil, 0, + 'E741: Value is locked: Unknown')) + eq(true, tv_check_lock(lib.VAR_FIXED, nil, 0, + 'E742: Cannot change value of Unknown')) + end) + end) end) end) -- cgit From 389274bef77798af83013bda1e4f1c261db38de5 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 25 Mar 2017 20:01:08 +0300 Subject: unittests: Add tv_equal() tests --- test/unit/eval/typval_spec.lua | 121 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 0619e43d08..74dba4377f 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -2424,5 +2424,126 @@ describe('typval.c', function() 'E742: Cannot change value of Unknown')) end) end) + describe('equal()', function() + itp('compares empty and NULL lists correctly', function() + local l = lua2typvalt(empty_list) + local l2 = lua2typvalt(empty_list) + local nl = lua2typvalt(null_list) + + -- NULL lists are not equal to empty lists + eq(false, lib.tv_equal(l, nl, true, false)) + eq(false, lib.tv_equal(nl, l, false, false)) + eq(false, lib.tv_equal(nl, l, false, true)) + eq(false, lib.tv_equal(l, nl, true, true)) + + -- Yet NULL lists are equal themselves + eq(true, lib.tv_equal(nl, nl, true, false)) + eq(true, lib.tv_equal(nl, nl, false, false)) + eq(true, lib.tv_equal(nl, nl, false, true)) + eq(true, lib.tv_equal(nl, nl, true, true)) + + -- As well as empty lists + eq(true, lib.tv_equal(l, l, true, false)) + eq(true, lib.tv_equal(l, l2, false, false)) + eq(true, lib.tv_equal(l2, l, false, true)) + eq(true, lib.tv_equal(l2, l2, true, true)) + end) + -- Must not use recursive=true argument in the following tests because it + -- indicates that tv_equal_recurse_limit and recursive_cnt were set which + -- is essential. This argument will be set when comparing inner lists. + itp('compares lists correctly when case is not ignored', function() + local l1 = lua2typvalt({'abc', {1, 2, 'Abc'}, 'def'}) + local l2 = lua2typvalt({'abc', {1, 2, 'Abc'}}) + local l3 = lua2typvalt({'abc', {1, 2, 'Abc'}, 'Def'}) + local l4 = lua2typvalt({'abc', {1, 2, 'Abc', 4}, 'def'}) + local l5 = lua2typvalt({'Abc', {1, 2, 'Abc'}, 'def'}) + local l6 = lua2typvalt({'abc', {1, 2, 'Abc'}, 'def'}) + local l7 = lua2typvalt({'abc', {1, 2, 'abc'}, 'def'}) + local l8 = lua2typvalt({'abc', nil, 'def'}) + local l9 = lua2typvalt({'abc', {1, 2, nil}, 'def'}) + + eq(true, lib.tv_equal(l1, l1, false, false)) + eq(false, lib.tv_equal(l1, l2, false, false)) + eq(false, lib.tv_equal(l1, l3, false, false)) + eq(false, lib.tv_equal(l1, l4, false, false)) + eq(false, lib.tv_equal(l1, l5, false, false)) + eq(true, lib.tv_equal(l1, l6, false, false)) + eq(false, lib.tv_equal(l1, l7, false, false)) + eq(false, lib.tv_equal(l1, l8, false, false)) + eq(false, lib.tv_equal(l1, l9, false, false)) + end) + itp('compares lists correctly when case is ignored', function() + local l1 = lua2typvalt({'abc', {1, 2, 'Abc'}, 'def'}) + local l2 = lua2typvalt({'abc', {1, 2, 'Abc'}}) + local l3 = lua2typvalt({'abc', {1, 2, 'Abc'}, 'Def'}) + local l4 = lua2typvalt({'abc', {1, 2, 'Abc', 4}, 'def'}) + local l5 = lua2typvalt({'Abc', {1, 2, 'Abc'}, 'def'}) + local l6 = lua2typvalt({'abc', {1, 2, 'Abc'}, 'def'}) + local l7 = lua2typvalt({'abc', {1, 2, 'abc'}, 'def'}) + local l8 = lua2typvalt({'abc', nil, 'def'}) + local l9 = lua2typvalt({'abc', {1, 2, nil}, 'def'}) + + eq(true, lib.tv_equal(l1, l1, true, false)) + eq(false, lib.tv_equal(l1, l2, true, false)) + eq(true, lib.tv_equal(l1, l3, true, false)) + eq(false, lib.tv_equal(l1, l4, true, false)) + eq(true, lib.tv_equal(l1, l5, true, false)) + eq(true, lib.tv_equal(l1, l6, true, false)) + eq(true, lib.tv_equal(l1, l7, true, false)) + eq(false, lib.tv_equal(l1, l8, true, false)) + eq(false, lib.tv_equal(l1, l9, true, false)) + end) + local function tv_equal(d1, d2, ic, recursive) + return lib.tv_equal(d1, d2, ic or false, recursive or false) + end + itp('works with dictionaries', function() + local nd = lua2typvalt(null_dict) + eq(true, tv_equal(nd, nd)) + alloc_log:check({}) + local d1 = lua2typvalt({}) + alloc_log:check({a.dict(d1.vval.v_dict)}) + eq(1, d1.vval.v_dict.dv_refcount) + eq(false, tv_equal(nd, d1)) + eq(false, tv_equal(d1, nd)) + eq(true, tv_equal(d1, d1)) + eq(1, d1.vval.v_dict.dv_refcount) + alloc_log:check({}) + local d_upper = lua2typvalt({a='TEST'}) + local dis_upper = dict_items(d_upper.vval.v_dict) + local d_lower = lua2typvalt({a='test'}) + local dis_lower = dict_items(d_lower.vval.v_dict) + local d_kupper_upper = lua2typvalt({A='TEST'}) + local dis_kupper_upper = dict_items(d_kupper_upper.vval.v_dict) + local d_kupper_lower = lua2typvalt({A='test'}) + local dis_kupper_lower = dict_items(d_kupper_lower.vval.v_dict) + alloc_log:clear_tmp_allocs() + alloc_log:check({ + a.dict(d_upper.vval.v_dict), + a.di(dis_upper.a), + a.str(dis_upper.a.di_tv.vval.v_string), + + a.dict(d_lower.vval.v_dict), + a.di(dis_lower.a), + a.str(dis_lower.a.di_tv.vval.v_string), + + a.dict(d_kupper_upper.vval.v_dict), + a.di(dis_kupper_upper.A), + a.str(dis_kupper_upper.A.di_tv.vval.v_string), + + a.dict(d_kupper_lower.vval.v_dict), + a.di(dis_kupper_lower.A), + a.str(dis_kupper_lower.A.di_tv.vval.v_string), + }) + eq(true, tv_equal(d_upper, d_upper)) + eq(true, tv_equal(d_upper, d_upper, true)) + eq(false, tv_equal(d_upper, d_lower, false)) + eq(true, tv_equal(d_upper, d_lower, true)) + eq(true, tv_equal(d_kupper_upper, d_kupper_lower, true)) + eq(false, tv_equal(d_kupper_upper, d_lower, true)) + eq(false, tv_equal(d_kupper_upper, d_upper, true)) + eq(true, tv_equal(d_upper, d_upper, true, true)) + alloc_log:check({}) + end) + end) end) end) -- cgit From 49195063fd864960437b84cae5fc8b2ca9885d59 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 25 Mar 2017 20:15:37 +0300 Subject: unittests: Add tv_check… tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/unit/eval/typval_spec.lua | 98 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 74dba4377f..143f4544e6 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1381,7 +1381,7 @@ describe('typval.c', function() end) describe('dict', function() describe('watcher', function() - describe('add/remove', function() + describe('add()/remove()', function() itp('works with an empty key', function() local d = dict({}) eq({}, dict_watchers(d)) @@ -1491,7 +1491,7 @@ describe('typval.c', function() end) end) describe('item', function() - describe('alloc/free', function() + describe('alloc()/free()', function() local function check_tv_dict_item_alloc_len(s, len, tv, more_frees) local di if len == nil then @@ -1527,7 +1527,7 @@ describe('typval.c', function() check_tv_dict_item_alloc_len('', 0, tv, {a.freed(tv.vval.v_string)}) end) end) - describe('add/remove', function() + describe('add()/remove()', function() itp('works', function() local d = dict() eq({}, dct2tbl(d)) @@ -2545,5 +2545,97 @@ describe('typval.c', function() alloc_log:check({}) end) end) + describe('check', function() + describe('str_or_nr()', function() + itp('works', function() + local tv = typvalt() + local mem = lib.xmalloc(1) + tv.vval.v_list = mem -- Should crash when actually accessed + alloc_log:clear() + for _, v in ipairs({ + {lib.VAR_NUMBER, nil}, + {lib.VAR_FLOAT, 'E805: Expected a Number or a String, Float found'}, + {lib.VAR_PARTIAL, 'E703: Expected a Number or a String, Funcref found'}, + {lib.VAR_FUNC, 'E703: Expected a Number or a String, Funcref found'}, + {lib.VAR_LIST, 'E745: Expected a Number or a String, List found'}, + {lib.VAR_DICT, 'E728: Expected a Number or a String, Dictionary found'}, + {lib.VAR_SPECIAL, 'E5300: Expected a Number or a String'}, + {lib.VAR_UNKNOWN, 'E685: Internal error: tv_check_str_or_nr(UNKNOWN)'}, + }) do + local typ = v[1] + local emsg = v[2] + local ret = true + if emsg then ret = false end + tv.v_type = typ + eq(ret, check_emsg(function() return lib.tv_check_str_or_nr(tv) end, emsg)) + if emsg then + alloc_log:clear() + else + alloc_log:check({}) + end + end + end) + end) + describe('num()', function() + itp('works', function() + local tv = typvalt() + local mem = lib.xmalloc(1) + tv.vval.v_list = mem -- Should crash when actually accessed + alloc_log:clear() + for _, v in ipairs({ + {lib.VAR_NUMBER, nil}, + {lib.VAR_FLOAT, 'E805: Using a Float as a Number'}, + {lib.VAR_PARTIAL, 'E703: Using a Funcref as a Number'}, + {lib.VAR_FUNC, 'E703: Using a Funcref as a Number'}, + {lib.VAR_LIST, 'E745: Using a List as a Number'}, + {lib.VAR_DICT, 'E728: Using a Dictionary as a Number'}, + {lib.VAR_SPECIAL, nil}, + {lib.VAR_UNKNOWN, 'E685: using an invalid value as a Number'}, + }) do + local typ = v[1] + local emsg = v[2] + local ret = true + if emsg then ret = false end + tv.v_type = typ + eq(ret, check_emsg(function() return lib.tv_check_num(tv) end, emsg)) + if emsg then + alloc_log:clear() + else + alloc_log:check({}) + end + end + end) + end) + describe('str()', function() + itp('works', function() + local tv = typvalt() + local mem = lib.xmalloc(1) + tv.vval.v_list = mem -- Should crash when actually accessed + alloc_log:clear() + for _, v in ipairs({ + {lib.VAR_NUMBER, nil}, + {lib.VAR_FLOAT, 'E806: using Float as a String'}, + {lib.VAR_PARTIAL, 'E729: using Funcref as a String'}, + {lib.VAR_FUNC, 'E729: using Funcref as a String'}, + {lib.VAR_LIST, 'E730: using List as a String'}, + {lib.VAR_DICT, 'E731: using Dictionary as a String'}, + {lib.VAR_SPECIAL, nil}, + {lib.VAR_UNKNOWN, 'E908: using an invalid value as a String'}, + }) do + local typ = v[1] + local emsg = v[2] + local ret = true + if emsg then ret = false end + tv.v_type = typ + eq(ret, check_emsg(function() return lib.tv_check_str(tv) end, emsg)) + if emsg then + alloc_log:clear() + else + alloc_log:check({}) + end + end + end) + end) + end) end) end) -- cgit From 4536c064e43dd93337d4809f6178c1ffc7034ebe Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 25 Mar 2017 20:17:00 +0300 Subject: unittests: Move tv_dict_add* tests to a proper describe() block --- test/unit/eval/typval_spec.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 143f4544e6..101adf3de4 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1768,7 +1768,9 @@ describe('typval.c', function() {tv_dict_get_callback(d, 'testt', 5)}) end) end) - describe('dict_add()', function() + end) + describe('add', function() + describe('()', function() itp('works', function() local di = lib.tv_dict_item_alloc_len('t-est', 5) alloc_log:check({a.di(di, 't-est')}) @@ -1789,7 +1791,7 @@ describe('typval.c', function() 'E685: Internal error: hash_add()')) end) end) - describe('dict_add_list()', function() + describe('list()', function() itp('works', function() local l = list(1, 2, 3) alloc_log:clear() @@ -1815,7 +1817,7 @@ describe('typval.c', function() alloc_log:check({}) end) end) - describe('dict_add_dict()', function() + describe('dict()', function() itp('works', function() local d2 = dict({foo=42}) alloc_log:clear() @@ -1841,7 +1843,7 @@ describe('typval.c', function() alloc_log:check({}) end) end) - describe('dict_add_nr()', function() + describe('nr()', function() itp('works', function() local d = dict({test=10}) alloc_log:clear() @@ -1861,7 +1863,7 @@ describe('typval.c', function() alloc_log:check({}) end) end) - describe('dict_add_str()', function() + describe('str()', function() itp('works', function() local d = dict({test=10}) alloc_log:clear() -- cgit From e08b27ba4acf22fe180c2a4a6b00f0ea0cfc3a79 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 25 Mar 2017 20:46:39 +0300 Subject: unittests: Add tv_get number tests --- test/unit/eval/typval_spec.lua | 124 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 123 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 101adf3de4..f9bb2a942c 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -10,6 +10,7 @@ local eq = helpers.eq local neq = helpers.neq local ffi = helpers.ffi local FAIL = helpers.FAIL +local NULL = helpers.NULL local cimport = helpers.cimport local to_cstr = helpers.to_cstr local alloc_log_new = helpers.alloc_log_new @@ -43,7 +44,8 @@ local concat_tables = global_helpers.concat_tables local lib = cimport('./src/nvim/eval/typval.h', './src/nvim/memory.h', './src/nvim/mbyte.h', './src/nvim/garray.h', - './src/nvim/eval.h', './src/nvim/vim.h') + './src/nvim/eval.h', './src/nvim/vim.h', + './src/nvim/globals.h') local function list_watch_alloc(li) return ffi.cast('listwatch_T*', ffi.new('listwatch_T[1]', {{lw_item=li}})) @@ -2639,5 +2641,125 @@ describe('typval.c', function() end) end) end) + describe('get', function() + describe('number()', function() + itp('works', function() + for _, v in ipairs({ + {lib.VAR_NUMBER, {v_number=42}, nil, 42}, + {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, 100500}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E805: Using a Float as a Number', 0}, + {lib.VAR_PARTIAL, {v_partial=NULL}, 'E703: Using a Funcref as a Number', 0}, + {lib.VAR_FUNC, {v_string=NULL}, 'E703: Using a Funcref as a Number', 0}, + {lib.VAR_LIST, {v_list=NULL}, 'E745: Using a List as a Number', 0}, + {lib.VAR_DICT, {v_dict=NULL}, 'E728: Using a Dictionary as a Number', 0}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 0}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarTrue}, nil, 1}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 0}, + {lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', 0}, + }) do + local tv = typvalt(v[1], v[2]) + alloc_log:check({}) + local emsg = v[3] + local ret = v[4] + eq(ret, check_emsg(function() return lib.tv_get_number(tv) end, emsg)) + if emsg then + alloc_log:clear() + else + alloc_log:check({}) + end + end + end) + end) + describe('number_chk()', function() + itp('works', function() + for _, v in ipairs({ + {lib.VAR_NUMBER, {v_number=42}, nil, 42}, + {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, 100500}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E805: Using a Float as a Number', 0}, + {lib.VAR_PARTIAL, {v_partial=NULL}, 'E703: Using a Funcref as a Number', 0}, + {lib.VAR_FUNC, {v_string=NULL}, 'E703: Using a Funcref as a Number', 0}, + {lib.VAR_LIST, {v_list=NULL}, 'E745: Using a List as a Number', 0}, + {lib.VAR_DICT, {v_dict=NULL}, 'E728: Using a Dictionary as a Number', 0}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 0}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarTrue}, nil, 1}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 0}, + {lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', 0}, + }) do + local tv = typvalt(v[1], v[2]) + alloc_log:check({}) + local emsg = v[3] + local ret = {v[4], not not emsg} + eq(ret, check_emsg(function() + local err = ffi.new('bool[1]', {false}) + local res = lib.tv_get_number_chk(tv, err) + return {res, err[0]} + end, emsg)) + if emsg then + alloc_log:clear() + else + alloc_log:check({}) + end + end + end) + end) + describe('lnum()', function() + itp('works', function() + for _, v in ipairs({ + {lib.VAR_NUMBER, {v_number=42}, nil, 42}, + {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, 100500}, + {lib.VAR_STRING, {v_string=to_cstr('.')}, nil, 46}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E805: Using a Float as a Number', -1}, + {lib.VAR_PARTIAL, {v_partial=NULL}, 'E703: Using a Funcref as a Number', -1}, + {lib.VAR_FUNC, {v_string=NULL}, 'E703: Using a Funcref as a Number', -1}, + {lib.VAR_LIST, {v_list=NULL}, 'E745: Using a List as a Number', -1}, + {lib.VAR_DICT, {v_dict=NULL}, 'E728: Using a Dictionary as a Number', -1}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 0}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarTrue}, nil, 1}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 0}, + {lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', -1}, + }) do + lib.curwin.w_cursor.lnum = 46 + local tv = typvalt(v[1], v[2]) + alloc_log:check({}) + local emsg = v[3] + local ret = v[4] + eq(ret, check_emsg(function() return lib.tv_get_lnum(tv) end, emsg)) + if emsg then + alloc_log:clear() + else + alloc_log:check({}) + end + end + end) + end) + describe('float()', function() + itp('works', function() + for _, v in ipairs({ + {lib.VAR_NUMBER, {v_number=42}, nil, 42}, + {lib.VAR_STRING, {v_string=to_cstr('100500')}, 'E892: Using a String as a Float', 0}, + {lib.VAR_FLOAT, {v_float=42.53}, nil, 42.53}, + {lib.VAR_PARTIAL, {v_partial=NULL}, 'E891: Using a Funcref as a Float', 0}, + {lib.VAR_FUNC, {v_string=NULL}, 'E891: Using a Funcref as a Float', 0}, + {lib.VAR_LIST, {v_list=NULL}, 'E893: Using a List as a Float', 0}, + {lib.VAR_DICT, {v_dict=NULL}, 'E894: Using a Dictionary as a Float', 0}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, 'E907: Using a special value as a Float', 0}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarTrue}, 'E907: Using a special value as a Float', 0}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, 'E907: Using a special value as a Float', 0}, + {lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_float(UNKNOWN)', 0}, + }) do + local tv = typvalt(v[1], v[2]) + alloc_log:check({}) + local emsg = v[3] + local ret = v[4] + eq(ret, check_emsg(function() return lib.tv_get_float(tv) end, emsg)) + if emsg then + alloc_log:clear() + else + alloc_log:check({}) + end + end + end) + end) + end) end) end) -- cgit From 7826ee1c035a99804dfeba80523c3f2992f7e6b6 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 25 Mar 2017 20:59:59 +0300 Subject: unittests: Add tv_get_string* tests --- test/unit/eval/typval_spec.lua | 166 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index f9bb2a942c..d861f81105 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -2760,6 +2760,172 @@ describe('typval.c', function() end end) end) + describe('string()', function() + itp('works', function() + local buf = lib.tv_get_string(lua2typvalt(int(1))) + local buf_chk = lib.tv_get_string_chk(lua2typvalt(int(1))) + neq(buf, buf_chk) + for _, v in ipairs({ + {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, + {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E806: using Float as a String', ''}, + {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: using Funcref as a String', ''}, + {lib.VAR_FUNC, {v_string=NULL}, 'E729: using Funcref as a String', ''}, + {lib.VAR_LIST, {v_list=NULL}, 'E730: using List as a String', ''}, + {lib.VAR_DICT, {v_dict=NULL}, 'E731: using Dictionary as a String', ''}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 'null'}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarTrue}, nil, 'true'}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 'false'}, + {lib.VAR_UNKNOWN, nil, 'E908: using an invalid value as a String', ''}, + }) do + local tv = typvalt(v[1], v[2]) + alloc_log:check({}) + local emsg = v[3] + local ret = v[4] + eq(ret, check_emsg(function() + local res = lib.tv_get_string(tv) + if tv.v_type == lib.VAR_NUMBER or tv.v_type == lib.VAR_SPECIAL then + eq(buf, res) + else + neq(buf, res) + end + if res ~= nil then + return ffi.string(res) + else + return nil + end + end, emsg)) + if emsg then + alloc_log:clear() + else + alloc_log:check({}) + end + end + end) + end) + describe('string_chk()', function() + itp('works', function() + local buf = lib.tv_get_string_chk(lua2typvalt(int(1))) + for _, v in ipairs({ + {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, + {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E806: using Float as a String', nil}, + {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: using Funcref as a String', nil}, + {lib.VAR_FUNC, {v_string=NULL}, 'E729: using Funcref as a String', nil}, + {lib.VAR_LIST, {v_list=NULL}, 'E730: using List as a String', nil}, + {lib.VAR_DICT, {v_dict=NULL}, 'E731: using Dictionary as a String', nil}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 'null'}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarTrue}, nil, 'true'}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 'false'}, + {lib.VAR_UNKNOWN, nil, 'E908: using an invalid value as a String', nil}, + }) do + local tv = typvalt(v[1], v[2]) + alloc_log:check({}) + local emsg = v[3] + local ret = v[4] + eq(ret, check_emsg(function() + local res = lib.tv_get_string_chk(tv) + if tv.v_type == lib.VAR_NUMBER or tv.v_type == lib.VAR_SPECIAL then + eq(buf, res) + else + neq(buf, res) + end + if res ~= nil then + return ffi.string(res) + else + return nil + end + end, emsg)) + if emsg then + alloc_log:clear() + else + alloc_log:check({}) + end + end + end) + end) + describe('string_buf()', function() + itp('works', function() + for _, v in ipairs({ + {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, + {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E806: using Float as a String', ''}, + {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: using Funcref as a String', ''}, + {lib.VAR_FUNC, {v_string=NULL}, 'E729: using Funcref as a String', ''}, + {lib.VAR_LIST, {v_list=NULL}, 'E730: using List as a String', ''}, + {lib.VAR_DICT, {v_dict=NULL}, 'E731: using Dictionary as a String', ''}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 'null'}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarTrue}, nil, 'true'}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 'false'}, + {lib.VAR_UNKNOWN, nil, 'E908: using an invalid value as a String', ''}, + }) do + local tv = typvalt(v[1], v[2]) + alloc_log:check({}) + local emsg = v[3] + local ret = v[4] + eq(ret, check_emsg(function() + local buf = ffi.new('char[?]', lib.NUMBUFLEN, {0}) + local res = lib.tv_get_string_buf(tv, buf) + if tv.v_type == lib.VAR_NUMBER or tv.v_type == lib.VAR_SPECIAL then + eq(buf, res) + else + neq(buf, res) + end + if res ~= nil then + return ffi.string(res) + else + return nil + end + end, emsg)) + if emsg then + alloc_log:clear() + else + alloc_log:check({}) + end + end + end) + end) + describe('string_buf_chk()', function() + itp('works', function() + for _, v in ipairs({ + {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, + {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E806: using Float as a String', nil}, + {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: using Funcref as a String', nil}, + {lib.VAR_FUNC, {v_string=NULL}, 'E729: using Funcref as a String', nil}, + {lib.VAR_LIST, {v_list=NULL}, 'E730: using List as a String', nil}, + {lib.VAR_DICT, {v_dict=NULL}, 'E731: using Dictionary as a String', nil}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 'null'}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarTrue}, nil, 'true'}, + {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 'false'}, + {lib.VAR_UNKNOWN, nil, 'E908: using an invalid value as a String', nil}, + }) do + local tv = typvalt(v[1], v[2]) + alloc_log:check({}) + local emsg = v[3] + local ret = v[4] + eq(ret, check_emsg(function() + local buf = ffi.new('char[?]', lib.NUMBUFLEN, {0}) + local res = lib.tv_get_string_buf_chk(tv, buf) + if tv.v_type == lib.VAR_NUMBER or tv.v_type == lib.VAR_SPECIAL then + eq(buf, res) + else + neq(buf, res) + end + if res ~= nil then + return ffi.string(res) + else + return nil + end + end, emsg)) + if emsg then + alloc_log:clear() + else + alloc_log:check({}) + end + end + end) + end) end) end) end) -- cgit From 8daf756fb6f92bdeb39e473b34364afd5270dd99 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 25 Mar 2017 22:07:41 +0300 Subject: unittests: Fix linter errors --- test/unit/eval/tricks_spec.lua | 2 -- test/unit/eval/typval_spec.lua | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'test') diff --git a/test/unit/eval/tricks_spec.lua b/test/unit/eval/tricks_spec.lua index ae569bed11..7aa0f0f6e6 100644 --- a/test/unit/eval/tricks_spec.lua +++ b/test/unit/eval/tricks_spec.lua @@ -4,8 +4,6 @@ local eval_helpers = require('test.unit.eval.helpers') local itp = helpers.gen_itp(it) local cimport = helpers.cimport -local to_cstr = helpers.to_cstr -local ffi = helpers.ffi local eq = helpers.eq local eval0 = eval_helpers.eval0 diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index d861f81105..7436115945 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -2124,7 +2124,6 @@ describe('typval.c', function() neq(dis.a.di_tv.vval.v_dict, dis_deepcopy1.a.di_tv.vval.v_dict) neq(dis.b.di_tv.vval.v_list, dis_deepcopy1.b.di_tv.vval.v_list) eq(v, dct2tbl(d_deepcopy1)) - local di_deepcopy1 = first_di(dis_deepcopy1.a.di_tv.vval.v_dict) alloc_log:clear() end collectgarbage() @@ -2247,6 +2246,7 @@ describe('typval.c', function() local ll_l = nil ll[1] = ll local dd = {} + local dd_d = nil dd.dd = dd for _, v in ipairs({ {nil_value}, -- cgit From 58e34e8d99b01bf3937824fc50502e39a8c39eba Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 26 Mar 2017 03:42:23 +0300 Subject: eval/typval: Allow NULL dict as tv_dict_get_callback() argument Also removes NULL key input: tv_dict_find() does not allow this. --- test/unit/eval/typval_spec.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 7436115945..3a4ef0cb92 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1736,8 +1736,7 @@ describe('typval.c', function() return cb_lua, ret end itp('works with NULL dict', function() - eq({{type='none'}, true}, - {tv_dict_get_callback(nil, nil, 0)}) + eq({{type='none'}, true}, {tv_dict_get_callback(nil, '')}) end) itp('works', function() local lua_d = { -- cgit From 114eaa15f009cbd3e3deb177a2a67affa430fbb8 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 28 Mar 2017 01:07:34 +0300 Subject: eval/typval,api/buffer: Fix review comments --- test/unit/eval/typval_spec.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 3a4ef0cb92..258b5c4c1f 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -255,6 +255,9 @@ describe('typval.c', function() eq({lis[3], lis[5], nil}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil}) alloc_log:clear() + lib.tv_list_watch_remove(l, lws[2]) + lib.tv_list_watch_remove(l, lws[3]) + lib.tv_list_watch_remove(l, lws[1]) lib.tv_list_free(l) alloc_log:check({ a.freed(lis[3]), -- cgit From 46efe14473fa803f84509592cc1e8fca4eb20640 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 28 Mar 2017 08:18:23 +0300 Subject: functests: Try sleeping a bit more --- test/functional/eval/timer_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/functional/eval/timer_spec.lua b/test/functional/eval/timer_spec.lua index 4353619ff0..b3c4cd07eb 100644 --- a/test/functional/eval/timer_spec.lua +++ b/test/functional/eval/timer_spec.lua @@ -49,7 +49,7 @@ describe('timers', function() it('works with zero timeout', function() -- timer_start does still not invoke the callback immediately eq(0,eval("[timer_start(0, 'MyHandler', {'repeat': 1000}), g:val][1]")) - run(nil, nil, nil, 300) + run(nil, nil, nil, 400) eq(1000,eval("g:val")) end) -- cgit From 1ea9ebf112d6c9d6355038afb4aaee794187cb23 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 29 Mar 2017 20:07:39 +0200 Subject: test: Use workspace-local temp directory. Closes #6291 --- test/functional/core/job_spec.lua | 3 ++- test/helpers.lua | 41 ++++++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 15 deletions(-) (limited to 'test') diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index e442c2a317..9ee91f2fe9 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -8,6 +8,7 @@ local clear, eq, eval, exc_exec, execute, feed, insert, neq, next_msg, nvim, local command = helpers.command local wait = helpers.wait local iswin = helpers.iswin +local get_pathsep = helpers.get_pathsep local Screen = require('test.functional.ui.screen') describe('jobs', function() @@ -65,7 +66,7 @@ describe('jobs', function() end) it('changes to given `cwd` directory', function() - local dir = eval('resolve(tempname())') + local dir = eval("resolve(tempname())"):gsub("/", get_pathsep()) mkdir(dir) nvim('command', "let g:job_opts.cwd = '" .. dir .. "'") if iswin() then diff --git a/test/helpers.lua b/test/helpers.lua index 1a86effa1c..82451bc61d 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -106,20 +106,33 @@ local uname = (function() end) end)() -local function tmpname() - local fname = os.tmpname() - if uname() == 'Windows' and fname:sub(1, 2) == '\\s' then - -- In Windows tmpname() returns a filename starting with - -- special sequence \s, prepend $TEMP path - local tmpdir = os.getenv('TEMP') - return tmpdir..fname - elseif fname:match('^/tmp') and uname() == 'Darwin' then - -- In OS X /tmp links to /private/tmp - return '/private'..fname - else - return fname - end -end +local tmpname = (function() + local seq = 0 + local tmpdir = os.getenv('TMPDIR') and os.getenv('TMPDIR') or os.getenv('TEMP') + -- Is $TMPDIR defined local to the project workspace? + local in_workspace = not not (tmpdir and string.find(tmpdir, 'Xtest')) + return (function() + if in_workspace then + -- Cannot control os.tmpname() dir, so hack our own tmpname() impl. + seq = seq + 1 + local fname = tmpdir..'/nvim-test-lua-'..seq + io.open(fname, 'w'):close() + return fname + else + local fname = os.tmpname() + if uname() == 'Windows' and fname:sub(1, 2) == '\\s' then + -- In Windows tmpname() returns a filename starting with + -- special sequence \s, prepend $TEMP path + return tmpdir..fname + elseif fname:match('^/tmp') and uname() == 'Darwin' then + -- In OS X /tmp links to /private/tmp + return '/private'..fname + else + return fname + end + end + end) +end)() local function map(func, tab) local rettab = {} -- cgit From 66b336d89bd5b45e60587b3c1689c7435019d775 Mon Sep 17 00:00:00 2001 From: Matthew Malcomson Date: Thu, 30 Mar 2017 18:00:34 +0100 Subject: test: set 'nomore' by default (#6360) Escaping from a '-- More --' prompt in tests is awkward as it doesn't take keys from the typebuffer, requiring a call to `feed()` in lua at the correct time. Moreover, it's rarer that a test will want the '-- More --' prompt to be activated than not. --- test/functional/helpers.lua | 2 +- test/functional/legacy/051_highlight_spec.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 7ce95d0b7c..ab36508262 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -23,7 +23,7 @@ local nvim_prog = os.getenv('NVIM_PROG') or os.getenv('NVIM_PRG') or 'build/bin/ -- Default settings for the test session. local nvim_set = 'set shortmess+=I background=light noswapfile noautoindent' ..' laststatus=1 undodir=. directory=. viewdir=. backupdir=.' - ..' belloff= noshowcmd noruler' + ..' belloff= noshowcmd noruler nomore' local nvim_argv = {nvim_prog, '-u', 'NONE', '-i', 'NONE', '-N', '--cmd', nvim_set, '--embed'} diff --git a/test/functional/legacy/051_highlight_spec.lua b/test/functional/legacy/051_highlight_spec.lua index ef392d8c67..d4d9b7d997 100644 --- a/test/functional/legacy/051_highlight_spec.lua +++ b/test/functional/legacy/051_highlight_spec.lua @@ -16,7 +16,7 @@ describe(':highlight', function() local screen = Screen.new(35, 10) screen:attach() -- Basic test if ":highlight" doesn't crash - execute('highlight') + execute('set more', 'highlight') -- FIXME(tarruda): We need to be sure the prompt is displayed before -- continuing, or risk a race condition where some of the following input -- is discarded resulting in test failure -- cgit From eb0e94f71b1f44cebf7ae5c1bcff348264af6cef Mon Sep 17 00:00:00 2001 From: Jakob Schnitzer Date: Thu, 30 Mar 2017 22:03:52 +0200 Subject: api: {get,set}_option should {get,set} global value of local options (#6405) - nvim_get_option should return the global default of a local option. - nvim_set_option should set the global default of a local option. --- test/functional/api/vim_spec.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 3348368a36..8f9f155110 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -153,6 +153,28 @@ describe('api', function() nvim('set_option', 'equalalways', false) ok(not nvim('get_option', 'equalalways')) end) + + it('works to get global value of local options', function() + eq(false, nvim('get_option', 'lisp')) + eq(8, nvim('get_option', 'shiftwidth')) + end) + + it('works to set global value of local options', function() + nvim('set_option', 'lisp', true) + eq(true, nvim('get_option', 'lisp')) + eq(false, helpers.curbuf('get_option', 'lisp')) + eq(nil, nvim('command_output', 'setglobal lisp?'):match('nolisp')) + eq('nolisp', nvim('command_output', 'setlocal lisp?'):match('nolisp')) + nvim('set_option', 'shiftwidth', 20) + eq('20', nvim('command_output', 'setglobal shiftwidth?'):match('%d+')) + eq('8', nvim('command_output', 'setlocal shiftwidth?'):match('%d+')) + end) + + it('most window-local options have no global value', function() + local status, err = pcall(nvim, 'get_option', 'foldcolumn') + eq(false, status) + ok(err:match('Invalid option name') ~= nil) + end) end) describe('nvim_{get,set}_current_buf, nvim_list_bufs', function() -- cgit From 3a9dd13f9e6471215a738cf22bf180e60a2e0bcd Mon Sep 17 00:00:00 2001 From: Matthew Malcomson Date: Fri, 31 Mar 2017 00:21:26 +0100 Subject: fold.c: more edge-cases when updating (#6207) When foldUpdateIEMSRecurse() re-uses an existing fold, it misses the case where the existing fold spans from before startlnum to after firstlnum, the new fold does not span this range, and there is no "forced start" of a fold. We add a case for this in. Ensure that if there was no forced break in folds, we merge folds that now touch each other. Include testing for a tricky foldmethod=expr case that has never been a bug. This case works at the moment because of some effects that are not obvious when reading the code. A test for this could be useful to ensure a regression doesn't happen. vim-patch:8.0.0408 --- test/functional/normal/fold_spec.lua | 112 ++++++++++++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/functional/normal/fold_spec.lua b/test/functional/normal/fold_spec.lua index 5584db20ba..fc055c4e7a 100644 --- a/test/functional/normal/fold_spec.lua +++ b/test/functional/normal/fold_spec.lua @@ -6,12 +6,15 @@ local feed = helpers.feed local expect = helpers.expect local execute = helpers.execute local funcs = helpers.funcs -local foldlevel, foldclosedend = funcs.foldlevel, funcs.foldclosedend +local foldlevel = funcs.foldlevel +local foldclosedend = funcs.foldclosedend local eq = helpers.eq describe('Folds', function() + local tempfname = 'Xtest-fold.txt' clear() before_each(function() execute('enew!') end) + after_each(function() os.remove(tempfname) end) it('manual folding adjusts with filter', function() insert([[ 1 @@ -230,4 +233,111 @@ a]], '2,3m0') eq({1, 2, 0, 0, 0}, get_folds()) end) end) + it('updates correctly on :read', function() + -- luacheck: ignore 621 + helpers.write_file(tempfname, [[ + a + + + a]]) + insert([[ + a + a + a + a + ]]) + execute('set foldmethod=indent', '2', '%foldopen') + execute('read ' .. tempfname) + -- Just to check we have the correct file text. + expect([[ + a + a + a + + + a + a + a + ]]) + for i = 1,2 do + eq(1, funcs.foldlevel(i)) + end + for i = 3,5 do + eq(0, funcs.foldlevel(i)) + end + for i = 6,8 do + eq(1, funcs.foldlevel(i)) + end + end) + it('combines folds when removing separating space', function() + -- luacheck: ignore 621 + insert([[ + a + a + a + a + a + a + a + a + ]]) + execute('set foldmethod=indent', '3,5d') + eq(5, funcs.foldclosedend(1)) + end) + it("doesn't combine folds that have a specified end", function() + insert([[ + {{{ + }}} + + + + {{{ + + }}} + ]]) + execute('set foldmethod=marker', '3,5d', '%foldclose') + eq(2, funcs.foldclosedend(1)) + end) + it('splits folds according to >N and 1' + endif + return 0 + endfunction + ]]) + helpers.write_file(tempfname, [[ + b + b + a + a + d + a + a + c]]) + insert([[ + a + a + a + a + a + a + ]]) + execute('set foldmethod=expr', 'set foldexpr=TestFoldExpr(v:lnum)', '2', 'foldopen') + execute('read ' .. tempfname, '%foldclose') + eq(2, funcs.foldclosedend(1)) + eq(0, funcs.foldlevel(3)) + eq(0, funcs.foldlevel(4)) + eq(6, funcs.foldclosedend(5)) + eq(10, funcs.foldclosedend(7)) + eq(14, funcs.foldclosedend(11)) + end) end) -- cgit From a1c928e70cd995426449ac6ec6df3b5a492580e5 Mon Sep 17 00:00:00 2001 From: Nikolai Aleksandrovich Pavlov Date: Fri, 31 Mar 2017 15:32:58 +0300 Subject: ci: Do not hide ci directory (#6410) --- test/unit/helpers.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 8aad3acd98..f4e6194fc7 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -574,7 +574,7 @@ local function gen_itp(it) if not err then if allow_failure then io.stderr:write('Errorred out:\n' .. tostring(emsg) .. '\n') - os.execute([[sh -c "source .ci/common/test.sh ; check_core_dumps --delete \"]] .. Paths.test_luajit_prg .. [[\""]]) + os.execute([[sh -c "source ci/common/test.sh ; check_core_dumps --delete \"]] .. Paths.test_luajit_prg .. [[\""]]) else error(emsg) end -- cgit From 933d60bc2356c1e22b8dbf8f8847c5323bc1f7a7 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 1 Apr 2017 11:07:08 +0300 Subject: unittests: Do not hang when error message is too long --- test/README.md | 3 +++ test/unit/helpers.lua | 4 ++-- test/unit/testtest_spec.lua | 13 +++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 test/unit/testtest_spec.lua (limited to 'test') diff --git a/test/README.md b/test/README.md index df66f24626..dc83b1ceef 100644 --- a/test/README.md +++ b/test/README.md @@ -99,3 +99,6 @@ get backtrace from). approximately 90% of the tests. Should be used when finding cores is too hard for some reason. Normally (on OS X or when `NVIM_TEST_CORE_GLOB_DIRECTORY` is defined and this variable is not) cores are checked for after each test. + +`NVIM_TEST_RUN_TESTTEST` (U) (1): allows running `test/unit/testtest_spec.lua` +used to check how testing infrastructure works. diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index f4e6194fc7..74b5b4e8bd 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -554,8 +554,6 @@ local function gen_itp(it) end else sc.close(wr) - sc.wait(child_pid) - child_pid = nil local function check() local res = sc.read(rd, 2) eq(2, #res) @@ -570,6 +568,8 @@ local function gen_itp(it) assert.just_fail(err) end local err, emsg = pcall(check) + sc.wait(child_pid) + child_pid = nil sc.close(rd) if not err then if allow_failure then diff --git a/test/unit/testtest_spec.lua b/test/unit/testtest_spec.lua new file mode 100644 index 0000000000..2397081b09 --- /dev/null +++ b/test/unit/testtest_spec.lua @@ -0,0 +1,13 @@ +local helpers = require('test.unit.helpers')(after_each) +local assert = require('luassert') +local itp = helpers.gen_itp(it) + +-- All of the below tests must fail. Check how exactly they fail. +if os.getenv('NVIM_TEST_RUN_TESTTEST') ~= '1' then + return +end +describe('test code', function() + itp('does not hang when working with lengthy errors', function() + assert.just_fail(('x'):rep(65536)) + end) +end) -- cgit From 8f7a48f46a39590dd29c702e00d56fcd7abe0208 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 1 Apr 2017 11:19:41 +0300 Subject: unittests: Split itp implementation into multiple functions --- test/unit/helpers.lua | 110 +++++++++++++++++++++++++------------------- test/unit/testtest_spec.lua | 1 + 2 files changed, 63 insertions(+), 48 deletions(-) (limited to 'test') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 74b5b4e8bd..8f0d3fa429 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -511,6 +511,64 @@ if os.getenv('NVIM_TEST_PRINT_SYSCALLS') == '1' then end end +local function just_fail(_) + return false +end +say:set('assertion.just_fail.positive', '%s') +say:set('assertion.just_fail.negative', '%s') +assert:register('assertion', 'just_fail', just_fail, + 'assertion.just_fail.positive', + 'assertion.just_fail.negative') + +local function itp_child(wr, func) + init() + collectgarbage('stop') + local err, emsg = pcall(func) + collectgarbage('restart') + emsg = tostring(emsg) + if not err then + sc.write(wr, ('-\n%05u\n%s'):format(#emsg, emsg)) + deinit() + sc.close(wr) + sc.exit(1) + else + sc.write(wr, '+\n') + deinit() + sc.close(wr) + sc.exit(0) + end +end + +local function check_child_err(rd) + local res = sc.read(rd, 2) + eq(2, #res) + if res == '+\n' then + return + end + eq('-\n', res) + local len_s = sc.read(rd, 5) + local len = tonumber(len_s) + neq(0, len) + local err = sc.read(rd, len + 1) + assert.just_fail(err) +end + +local function itp_parent(rd, pid, allow_failure) + local err, emsg = pcall(check_child_err, rd) + sc.wait(pid) + sc.close(rd) + if not err then + if allow_failure then + io.stderr:write('Errorred out:\n' .. tostring(emsg) .. '\n') + os.execute([[ + sh -c "source ci/common/test.sh + check_core_dumps --delete \"]] .. Paths.test_luajit_prg .. [[\""]]) + else + error(emsg) + end + end +end + local function gen_itp(it) child_calls_mod = {} child_calls_mod_once = {} @@ -518,14 +576,6 @@ local function gen_itp(it) preprocess_cache_mod = map(function(v) return v end, preprocess_cache_init) previous_defines_mod = previous_defines_init cdefs_mod = cdefs_init:copy() - local function just_fail(_) - return false - end - say:set('assertion.just_fail.positive', '%s') - say:set('assertion.just_fail.negative', '%s') - assert:register('assertion', 'just_fail', just_fail, - 'assertion.just_fail.positive', - 'assertion.just_fail.negative') local function itp(name, func, allow_failure) if allow_failure and os.getenv('NVIM_TEST_RUN_FAILING_TESTS') ~= '1' then -- FIXME Fix tests with this true @@ -535,50 +585,13 @@ local function gen_itp(it) local rd, wr = sc.pipe() child_pid = sc.fork() if child_pid == 0 then - init() sc.close(rd) - collectgarbage('stop') - local err, emsg = pcall(func) - collectgarbage('restart') - emsg = tostring(emsg) - if not err then - sc.write(wr, ('-\n%05u\n%s'):format(#emsg, emsg)) - deinit() - sc.close(wr) - sc.exit(1) - else - sc.write(wr, '+\n') - deinit() - sc.close(wr) - sc.exit(0) - end + itp_child(wr, func) else sc.close(wr) - local function check() - local res = sc.read(rd, 2) - eq(2, #res) - if res == '+\n' then - return - end - eq('-\n', res) - local len_s = sc.read(rd, 5) - local len = tonumber(len_s) - neq(0, len) - local err = sc.read(rd, len + 1) - assert.just_fail(err) - end - local err, emsg = pcall(check) - sc.wait(child_pid) + saved_child_pid = child_pid child_pid = nil - sc.close(rd) - if not err then - if allow_failure then - io.stderr:write('Errorred out:\n' .. tostring(emsg) .. '\n') - os.execute([[sh -c "source ci/common/test.sh ; check_core_dumps --delete \"]] .. Paths.test_luajit_prg .. [[\""]]) - else - error(emsg) - end - end + itp_parent(rd, saved_child_pid, allow_failure) end end) end @@ -610,6 +623,7 @@ local module = { only_separate = only_separate, child_call_once = child_call_once, child_cleanup_once = child_cleanup_once, + sc = sc, } return function(after_each) if after_each then diff --git a/test/unit/testtest_spec.lua b/test/unit/testtest_spec.lua index 2397081b09..b469e7ed44 100644 --- a/test/unit/testtest_spec.lua +++ b/test/unit/testtest_spec.lua @@ -1,5 +1,6 @@ local helpers = require('test.unit.helpers')(after_each) local assert = require('luassert') + local itp = helpers.gen_itp(it) -- All of the below tests must fail. Check how exactly they fail. -- cgit From 046d6a8dfe8ef5b319fdd7139303d46b56b5daa6 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 1 Apr 2017 12:25:10 +0300 Subject: unittests: Collect traces Some benchmarks: MAIN_CDEFS + NO_TRACE: 3.81s user 1.65s system 33% cpu 16.140 total MAIN_CDEFS: 73.61s user 10.98s system 154% cpu 54.690 total NO_TRACE: 18.49s user 4.30s system 73% cpu 30.804 total (default): 77.11s user 14.74s system 126% cpu 1:12.79 total --- test/README.md | 5 +++ test/unit/helpers.lua | 102 +++++++++++++++++++++++++++++++++++++++++++- test/unit/testtest_spec.lua | 5 +++ 3 files changed, 111 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/README.md b/test/README.md index dc83b1ceef..9a8701695a 100644 --- a/test/README.md +++ b/test/README.md @@ -102,3 +102,8 @@ defined and this variable is not) cores are checked for after each test. `NVIM_TEST_RUN_TESTTEST` (U) (1): allows running `test/unit/testtest_spec.lua` used to check how testing infrastructure works. + +`NVIM_TEST_NO_TRACE` (U) (1): omits getting traces from tests. This means that +if tests crashed without core dump you will have no clues regarding where, but +this makes tests run a lot faster. Combine with `NVIM_TEST_MAIN_CDEFS` for +maximal speed. diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 8f0d3fa429..c8296abb2a 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -520,13 +520,92 @@ assert:register('assertion', 'just_fail', just_fail, 'assertion.just_fail.positive', 'assertion.just_fail.negative') +local hook_fnamelen = 30 +local hook_sfnamelen = 30 +local hook_numlen = 5 +local hook_msglen = 1 + 1 + 1 + (1 + hook_fnamelen) + (1 + hook_sfnamelen) + (1 + hook_numlen) + 1 + +local function child_sethook(wr) + if os.getenv('NVIM_TEST_NO_TRACE') == '1' then + return + end + -- Message: + -- |> msg char (1) + -- ||> what char (1) + -- |||> namewhat char (1) + -- ||| |> source file name (30) + -- ||| | |> function name (30) + -- ||| | | |> line number (5) + -- CWN SSSSSSSSSSSSSSSSSSSSSSSSSSSSSS:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF:LLLLL\n + local function hook(reason, lnum) + local msgchar = reason:sub(1, 1) + if reason == 'count' then + msgchar = 'C' + end + local info = nil + if reason ~= 'tail return' then -- tail return + info = debug.getinfo(2, 'nSl') + end + local whatchar = ' ' + local namewhatchar = ' ' + local funcname = '' + local source = '' + if info then + funcname = (info.name or ''):sub(1, hook_fnamelen) + whatchar = info.what:sub(1, 1) + namewhatchar = info.namewhat:sub(1, 1) + if namewhatchar == '' then + namewhatchar = ' ' + end + source = info.source + if source:sub(1, 1) == '@' then + if source:sub(-4, -1) == '.lua' then + source = source:sub(1, -5) + end + source = source:sub(-hook_sfnamelen, -1) + end + lnum = lnum or info.currentline + end + + -- assert(-1 <= lnum and lnum <= 99999) + local lnum_s + if lnum == -1 then + lnum_s = 'nknwn' + else + lnum_s = ('%u'):format(lnum) + end + local msg = ( -- lua does not support %* + '' + .. msgchar + .. whatchar + .. namewhatchar + .. ' ' + .. source .. (' '):rep(hook_sfnamelen - #source) + .. ':' + .. funcname .. (' '):rep(hook_fnamelen - #funcname) + .. ':' + .. ('0'):rep(hook_numlen - #lnum_s) .. lnum_s + .. '\n' + ) + -- eq(hook_msglen, #msg) + sc.write(wr, msg) + end + debug.sethook(hook, 'crl') +end + local function itp_child(wr, func) init() collectgarbage('stop') + child_sethook(wr) local err, emsg = pcall(func) + debug.sethook() collectgarbage('restart') emsg = tostring(emsg) + sc.write(wr, ('E%s\n'):format((' '):rep(hook_msglen - 2))) if not err then + if #emsg > 99999 then + emsg = emsg:sub(1, 99999) + end sc.write(wr, ('-\n%05u\n%s'):format(#emsg, emsg)) deinit() sc.close(wr) @@ -540,8 +619,29 @@ local function itp_child(wr, func) end local function check_child_err(rd) + local trace = {} + while true do + local traceline = sc.read(rd, hook_msglen) + if #traceline ~= hook_msglen then + if #traceline == 0 then + break + else + trace[#trace + 1] = 'Partial read: <' .. trace .. '>\n' + end + end + if traceline:sub(1, 1) == 'E' then + break + end + trace[#trace + 1] = traceline + end local res = sc.read(rd, 2) - eq(2, #res) + if #res ~= 2 then + local error = 'Test crashed, trace:\n' + for i = 1, #trace do + error = error .. trace[i] + end + assert.just_fail(error) + end if res == '+\n' then return end diff --git a/test/unit/testtest_spec.lua b/test/unit/testtest_spec.lua index b469e7ed44..d2f3632b6f 100644 --- a/test/unit/testtest_spec.lua +++ b/test/unit/testtest_spec.lua @@ -3,6 +3,8 @@ local assert = require('luassert') local itp = helpers.gen_itp(it) +local sc = helpers.sc + -- All of the below tests must fail. Check how exactly they fail. if os.getenv('NVIM_TEST_RUN_TESTTEST') ~= '1' then return @@ -11,4 +13,7 @@ describe('test code', function() itp('does not hang when working with lengthy errors', function() assert.just_fail(('x'):rep(65536)) end) + itp('shows trace after exiting abnormally', function() + sc.exit(0) + end) end) -- cgit From 9dd0d4f8b9217f711fff32e9f47674e556a8fab0 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 1 Apr 2017 12:52:28 +0300 Subject: unittests: Add trace description right to the error message --- test/functional/helpers.lua | 23 +---------------------- test/helpers.lua | 23 +++++++++++++++++++++++ test/unit/helpers.lua | 23 ++++++++++++++--------- 3 files changed, 38 insertions(+), 31 deletions(-) (limited to 'test') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index ab36508262..335cf3c3ff 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -16,6 +16,7 @@ local eq = global_helpers.eq local ok = global_helpers.ok local map = global_helpers.map local filter = global_helpers.filter +local dedent = global_helpers.dedent local start_dir = lfs.currentdir() -- XXX: NVIM_PROG takes precedence, QuickBuild sets it. @@ -191,28 +192,6 @@ local function nvim_feed(input) end end -local function dedent(str) - -- find minimum common indent across lines - local indent = nil - for line in str:gmatch('[^\n]+') do - local line_indent = line:match('^%s+') or '' - if indent == nil or #line_indent < #indent then - indent = line_indent - end - end - if indent == nil or #indent == 0 then - -- no minimum common indent - return str - end - -- create a pattern for the indent - indent = indent:gsub('%s', '[ \t]') - -- strip it from the first line - str = str:gsub('^'..indent, '') - -- strip it from the remaining lines - str = str:gsub('[\n]'..indent, '\n') - return str -end - local function feed(...) for _, v in ipairs({...}) do nvim_feed(dedent(v)) diff --git a/test/helpers.lua b/test/helpers.lua index 82451bc61d..3fc10e9e30 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -251,6 +251,28 @@ local function concat_tables(...) return ret end +local function dedent(str) + -- find minimum common indent across lines + local indent = nil + for line in str:gmatch('[^\n]+') do + local line_indent = line:match('^%s+') or '' + if indent == nil or #line_indent < #indent then + indent = line_indent + end + end + if indent == nil or #indent == 0 then + -- no minimum common indent + return str + end + -- create a pattern for the indent + indent = indent:gsub('%s', '[ \t]') + -- strip it from the first line + str = str:gsub('^'..indent, '') + -- strip it from the remaining lines + str = str:gsub('[\n]'..indent, '\n') + return str +end + return { eq = eq, neq = neq, @@ -265,4 +287,5 @@ return { hasenv = hasenv, which = which, concat_tables = concat_tables, + dedent = dedent, } diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index c8296abb2a..048027692a 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -11,6 +11,7 @@ local posix = nil local syscall = nil local check_cores = global_helpers.check_cores +local dedent = global_helpers.dedent local neq = global_helpers.neq local map = global_helpers.map local eq = global_helpers.eq @@ -525,18 +526,22 @@ local hook_sfnamelen = 30 local hook_numlen = 5 local hook_msglen = 1 + 1 + 1 + (1 + hook_fnamelen) + (1 + hook_sfnamelen) + (1 + hook_numlen) + 1 +local tracehelp = dedent([[ + ┌ Trace type: _r_eturn from function , function _c_all, _l_ine executed, + │ _t_ail return, _C_ount (should not actually appear). + │┏ Function type: _L_ua function, _C_ function, _m_ain part of chunk, + │┃ function that did _t_ail call. + │┃┌ Function name type: _g_lobal, _l_ocal, _m_ethod, _f_ield, _u_pvalue, + │┃│ space for unknown. + │┃│ ┏ Source file name ┌ Function name ┏ Line + │┃│ ┃ (trunc to 30 bytes, no .lua) │ (truncated to last 30 bytes) ┃ number + CWN SSSSSSSSSSSSSSSSSSSSSSSSSSSSSS:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF:LLLLL\n +]]) + local function child_sethook(wr) if os.getenv('NVIM_TEST_NO_TRACE') == '1' then return end - -- Message: - -- |> msg char (1) - -- ||> what char (1) - -- |||> namewhat char (1) - -- ||| |> source file name (30) - -- ||| | |> function name (30) - -- ||| | | |> line number (5) - -- CWN SSSSSSSSSSSSSSSSSSSSSSSSSSSSSS:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF:LLLLL\n local function hook(reason, lnum) local msgchar = reason:sub(1, 1) if reason == 'count' then @@ -636,7 +641,7 @@ local function check_child_err(rd) end local res = sc.read(rd, 2) if #res ~= 2 then - local error = 'Test crashed, trace:\n' + local error = '\nTest crashed, trace:\n' .. tracehelp for i = 1, #trace do error = error .. trace[i] end -- cgit From 708a55ee1584c22caadd6b17de8cfc1760b2dba3 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 1 Apr 2017 13:16:25 +0300 Subject: unittests: Disable non-C-calls Some benchmarks: TRACE_EVERYTHING: 79.45s user 12.68s system 124% cpu 1:13.94 total (default): 30.26s user 5.30s system 89% cpu 39.663 total --- test/README.md | 4 ++++ test/unit/helpers.lua | 24 +++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/README.md b/test/README.md index 9a8701695a..d0871711a8 100644 --- a/test/README.md +++ b/test/README.md @@ -107,3 +107,7 @@ used to check how testing infrastructure works. if tests crashed without core dump you will have no clues regarding where, but this makes tests run a lot faster. Combine with `NVIM_TEST_MAIN_CDEFS` for maximal speed. + +`NVIM_TEST_TRACE_EVERYTHING` (U) (1): by default unit test only record C calls +which is faster then recording everything. Set this variable to 1 if you want to +see all traces. diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 048027692a..7ef2fa22fc 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -542,19 +542,27 @@ local function child_sethook(wr) if os.getenv('NVIM_TEST_NO_TRACE') == '1' then return end + local trace_only_c = (os.getenv('NVIM_TEST_TRACE_EVERYTHING') ~= '1') local function hook(reason, lnum) - local msgchar = reason:sub(1, 1) - if reason == 'count' then - msgchar = 'C' - end local info = nil if reason ~= 'tail return' then -- tail return info = debug.getinfo(2, 'nSl') end + + if trace_only_c and (not info or info.what ~= 'C') then + return + end + local whatchar = ' ' local namewhatchar = ' ' local funcname = '' local source = '' + local msgchar = reason:sub(1, 1) + + if reason == 'count' then + msgchar = 'C' + end + if info then funcname = (info.name or ''):sub(1, hook_fnamelen) whatchar = info.what:sub(1, 1) @@ -595,9 +603,11 @@ local function child_sethook(wr) -- eq(hook_msglen, #msg) sc.write(wr, msg) end - debug.sethook(hook, 'crl') + debug.sethook(hook, trace_only_c and 'cr' or 'crl') end +local trace_end_msg = ('E%s\n'):format((' '):rep(hook_msglen - 2)) + local function itp_child(wr, func) init() collectgarbage('stop') @@ -606,7 +616,7 @@ local function itp_child(wr, func) debug.sethook() collectgarbage('restart') emsg = tostring(emsg) - sc.write(wr, ('E%s\n'):format((' '):rep(hook_msglen - 2))) + sc.write(wr, trace_end_msg) if not err then if #emsg > 99999 then emsg = emsg:sub(1, 99999) @@ -634,7 +644,7 @@ local function check_child_err(rd) trace[#trace + 1] = 'Partial read: <' .. trace .. '>\n' end end - if traceline:sub(1, 1) == 'E' then + if traceline == trace_end_msg then break end trace[#trace + 1] = traceline -- cgit From 2d158dde025fc7752c9f52def8384a2fbb698652 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 1 Apr 2017 13:17:25 +0300 Subject: unittests: Fix linter error --- test/unit/helpers.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 7ef2fa22fc..2cea88c8c0 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -704,7 +704,7 @@ local function gen_itp(it) itp_child(wr, func) else sc.close(wr) - saved_child_pid = child_pid + local saved_child_pid = child_pid child_pid = nil itp_parent(rd, saved_child_pid, allow_failure) end -- cgit From ac22238b6af1d37fab09fc2173d5ed2019652c41 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 1 Apr 2017 20:57:23 +0300 Subject: unittests: Replace two environment variables with one TRACE_LEVEL --- test/README.md | 17 +++++++---------- test/unit/helpers.lua | 21 ++++++++++++++++----- 2 files changed, 23 insertions(+), 15 deletions(-) (limited to 'test') diff --git a/test/README.md b/test/README.md index d0871711a8..2857cc0ecf 100644 --- a/test/README.md +++ b/test/README.md @@ -27,8 +27,8 @@ groups by the semantic component they are testing. Test behaviour is affected by environment variables. Currently supported (Functional, Unit, Benchmarks) (when Defined; when set to _1_; when defined, -treated as Integer; when defined, treated as String; !must be defined to -function properly): +treated as Integer; when defined, treated as String; when defined, treated as +Number; !must be defined to function properly): `GDB` (F) (D): makes nvim instances to be run under `gdbserver`. It will be accessible on `localhost:7777`: use `gdb build/bin/nvim`, type `target remote @@ -103,11 +103,8 @@ defined and this variable is not) cores are checked for after each test. `NVIM_TEST_RUN_TESTTEST` (U) (1): allows running `test/unit/testtest_spec.lua` used to check how testing infrastructure works. -`NVIM_TEST_NO_TRACE` (U) (1): omits getting traces from tests. This means that -if tests crashed without core dump you will have no clues regarding where, but -this makes tests run a lot faster. Combine with `NVIM_TEST_MAIN_CDEFS` for -maximal speed. - -`NVIM_TEST_TRACE_EVERYTHING` (U) (1): by default unit test only record C calls -which is faster then recording everything. Set this variable to 1 if you want to -see all traces. +`NVIM_TEST_TRACE_LEVEL` (U) (N): specifies unit tests tracing level: `0` +disables tracing (the fastest, but you get no data if tests crash and there was +no core dump generated), `1` or empty/undefined leaves only C function cals and +returns in the trace (faster then recording everything), `2` records all +function calls, returns and lua source lines exuecuted. diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 2cea88c8c0..93e1e91173 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -539,10 +539,16 @@ local tracehelp = dedent([[ ]]) local function child_sethook(wr) - if os.getenv('NVIM_TEST_NO_TRACE') == '1' then + local trace_level = os.getenv('NVIM_TEST_TRACE_LEVEL') + if not trace_level or trace_level == '' then + trace_level = 1 + else + trace_level = tonumber(trace_level) + end + if trace_level <= 0 then return end - local trace_only_c = (os.getenv('NVIM_TEST_TRACE_EVERYTHING') ~= '1') + local trace_only_c = trace_level <= 1 local function hook(reason, lnum) local info = nil if reason ~= 'tail return' then -- tail return @@ -651,9 +657,14 @@ local function check_child_err(rd) end local res = sc.read(rd, 2) if #res ~= 2 then - local error = '\nTest crashed, trace:\n' .. tracehelp - for i = 1, #trace do - error = error .. trace[i] + local error + if #trace == 0 then + error = '\nTest crashed, no trace available\n' + else + error = '\nTest crashed, trace:\n' .. tracehelp + for i = 1, #trace do + error = error .. trace[i] + end end assert.just_fail(error) end -- cgit From cc4523013f8e693f92de3b96ff36065895c60974 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 1 Apr 2017 21:13:21 +0300 Subject: eval,fileio: Omit additional fsync() call Fixes #6420 --- test/unit/os/fileio_spec.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test') diff --git a/test/unit/os/fileio_spec.lua b/test/unit/os/fileio_spec.lua index 7a738ce85c..5e1b2523fa 100644 --- a/test/unit/os/fileio_spec.lua +++ b/test/unit/os/fileio_spec.lua @@ -80,6 +80,10 @@ local function file_read(fp, size) return ret1, ret2 end +local function file_flush(fp) + return m.file_flush(fp) +end + local function file_fsync(fp) return m.file_fsync(fp) end @@ -244,6 +248,21 @@ describe('file_fsync', function() end) end) +describe('file_flush', function() + itp('can flush writes to disk', function() + local err, fp = file_open(filec, m.kFileCreateOnly, 384) + eq(0, file_flush(fp)) + eq(0, err) + eq(0, lfs.attributes(filec).size) + local wsize = file_write(fp, 'test') + eq(4, wsize) + eq(0, lfs.attributes(filec).size) + eq(0, file_flush(fp)) + eq(wsize, lfs.attributes(filec).size) + eq(0, m.file_close(fp)) + end) +end) + describe('file_read', function() itp('can read small chunks of input until eof', function() local err, fp = file_open(file1, 0, 384) -- cgit From 337b6179df852350b52409fd3806e4b47ab2875b Mon Sep 17 00:00:00 2001 From: Matthew Malcomson Date: Sat, 1 Apr 2017 20:50:29 +0100 Subject: 'pastetoggle': support value >1 char (#6421) If we `set pastetoggle=abcde`, and manually type it, then `vgetorpeek()` sees part of the option before it has all been inserted into the typebuffer. To signify this it sets `keylen = KEYLEN_PART_KEY`, but the condition about whether to return the current key from `vgetorpeek()` only checks for `keylen = KEYLEN_PART_MAP`. Add a check for `KEYLEN_PART_KEY` to account for the `'pastetoggle'` option. --- test/functional/options/pastetoggle_spec.lua | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test/functional/options/pastetoggle_spec.lua (limited to 'test') diff --git a/test/functional/options/pastetoggle_spec.lua b/test/functional/options/pastetoggle_spec.lua new file mode 100644 index 0000000000..e449df31f5 --- /dev/null +++ b/test/functional/options/pastetoggle_spec.lua @@ -0,0 +1,37 @@ +local helpers = require('test.functional.helpers')(after_each) + +local clear = helpers.clear +local feed = helpers.feed +local execute = helpers.execute +local eq = helpers.eq +local eval = helpers.eval +local sleep = helpers.sleep + +describe("'pastetoggle' option", function() + before_each(function() + clear() + execute('set nopaste') + execute('set pastetoggle=a') + end) + it("toggles 'paste'", function() + eq(eval('&paste'), 0) + feed('a') + -- Need another key so that the vgetorpeek() function returns. + feed('j') + eq(eval('&paste'), 1) + end) + it("multiple key 'pastetoggle' is waited for", function() + eq(eval('&paste'), 0) + local pastetoggle = 'lllll' + execute('set pastetoggle=' .. pastetoggle) + execute('set timeoutlen=1', 'set ttimoutlen=10000') + feed(pastetoggle:sub(0, 2)) + -- sleep() for long enough that vgetorpeek() is gotten into, but short + -- enough that ttimeoutlen is not reached. + sleep(200) + feed(pastetoggle:sub(3, -1)) + -- Need another key so that the vgetorpeek() function returns. + feed('j') + eq(eval('&paste'), 1) + end) +end) -- cgit From dd4a5fcbb65ade08b5d2c7951b2924d2d04dc99e Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Mon, 20 Mar 2017 22:56:58 +0100 Subject: tui: 'guicursor' shape #6044 Closes #2583 --- test/functional/ui/screen.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test') diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 54f43387dc..2d04949bb3 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -313,6 +313,8 @@ function Screen:_redraw(updates) if handler ~= nil then handler(self, unpack(update[i])) else + assert(self._on_event, "Either add an Screen:_handle_XXX method ".. + " or call Screen:set_on_event_handler") self._on_event(method, update[i]) end end @@ -343,6 +345,10 @@ function Screen:_handle_resize(width, height) } end +function Screen:_handle_cursor_style_set(styles) + self._cursor_styles = styles +end + function Screen:_handle_clear() self:_clear_block(self._scroll_region.top, self._scroll_region.bot, self._scroll_region.left, self._scroll_region.right) -- cgit From c2826a7830ddba66261afdf45fcf4d0043506342 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 1 Apr 2017 13:08:42 +0200 Subject: 'guicursor': Empty means "block cursor in all modes". Also: update default 'guicursor' to match the documentation. --- test/functional/ui/cursor_spec.lua | 180 +++++++++++++++++++++++++++++++++++++ test/functional/ui/mouse_spec.lua | 2 +- test/functional/ui/screen.lua | 4 +- 3 files changed, 183 insertions(+), 3 deletions(-) create mode 100644 test/functional/ui/cursor_spec.lua (limited to 'test') diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua new file mode 100644 index 0000000000..6f5fd244d5 --- /dev/null +++ b/test/functional/ui/cursor_spec.lua @@ -0,0 +1,180 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') +local clear, feed, meths = helpers.clear, helpers.feed, helpers.meths +local insert, execute = helpers.insert, helpers.execute +local eq, funcs = helpers.eq, helpers.funcs +local command = helpers.command + +if helpers.pending_win32(pending) then return end + +describe('ui/cursor', function() + local screen + + before_each(function() + clear() + screen = Screen.new(25, 5) + screen:attach() + end) + + after_each(function() + screen:detach() + end) + + it("'guicursor' is published as a UI event", function() + command('redraw') + screen:expect('', nil, nil, nil, true) -- Tickle the event-loop. + local expected_cursor_style = { + cmd_insert = { + blinkoff = 250, + blinkon = 400, + blinkwait = 700, + cell_percentage = 25, + cursor_shape = 'vertical', + hl_id = 45, + id_lm = 46, + mouse_shape = 0, + short_name = 'ci' }, + cmd_line = { + mouse_shape = 0, + short_name = 'e' }, + cmd_normal = { + blinkoff = 250, + blinkon = 400, + blinkwait = 700, + cell_percentage = 0, + cursor_shape = 'block', + hl_id = 45, + id_lm = 46, + mouse_shape = 0, + short_name = 'c' }, + cmd_replace = { + blinkoff = 250, + blinkon = 400, + blinkwait = 700, + cell_percentage = 20, + cursor_shape = 'horizontal', + hl_id = 45, + id_lm = 46, + mouse_shape = 0, + short_name = 'cr' }, + drag_statusline = { + mouse_shape = 0, + short_name = 'sd' }, + insert = { + blinkoff = 250, + blinkon = 400, + blinkwait = 700, + cell_percentage = 25, + cursor_shape = 'vertical', + hl_id = 45, + id_lm = 46, + mouse_shape = 0, + short_name = 'i' }, + match_paren = { + blinkoff = 150, + blinkon = 175, + blinkwait = 175, + cell_percentage = 0, + cursor_shape = 'block', + hl_id = 45, + id_lm = 45, + short_name = 'sm' }, + more = { + mouse_shape = 0, + short_name = 'm' }, + more_lastline = { + mouse_shape = 0, + short_name = 'ml' }, + normal = { + blinkoff = 250, + blinkon = 400, + blinkwait = 700, + cell_percentage = 0, + cursor_shape = 'block', + hl_id = 45, + id_lm = 46, + mouse_shape = 0, + short_name = 'n' }, + pending = { + blinkoff = 250, + blinkon = 400, + blinkwait = 700, + cell_percentage = 50, + cursor_shape = 'horizontal', + hl_id = 45, + id_lm = 45, + mouse_shape = 0, + short_name = 'o' }, + replace = { + blinkoff = 250, + blinkon = 400, + blinkwait = 700, + cell_percentage = 20, + cursor_shape = 'horizontal', + hl_id = 45, + id_lm = 46, + mouse_shape = 0, + short_name = 'r' }, + statusline = { + mouse_shape = 0, + short_name = 's' }, + vdrag = { + mouse_shape = 0, + short_name = 'vd' }, + visual = { + blinkoff = 250, + blinkon = 400, + blinkwait = 700, + cell_percentage = 0, + cursor_shape = 'block', + hl_id = 45, + id_lm = 46, + mouse_shape = 0, + short_name = 'v' }, + visual_select = { + blinkoff = 250, + blinkon = 400, + blinkwait = 700, + cell_percentage = 35, + cursor_shape = 'vertical', + hl_id = 45, + id_lm = 45, + mouse_shape = 0, + short_name = 've' }, + vsep = { + mouse_shape = 0, + short_name = 'vs' } + } + -- Default 'guicursor' published on startup. + eq(expected_cursor_style, screen._cursor_style) + eq('normal', screen.mode) + + -- Event is published ONLY if the cursor style changed. + screen._cursor_style = nil + command('redraw') + screen:expect('', nil, nil, nil, true) -- Tickle the event-loop. + eq(nil, screen._cursor_style) + + -- Change the cursor style. + meths.set_option('guicursor', 'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173,ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42') + command('redraw') + screen:expect('', nil, nil, nil, true) -- Tickle the event-loop. + eq('vertical', screen._cursor_style.normal.cursor_shape) + eq('horizontal', screen._cursor_style.visual_select.cursor_shape) + eq('vertical', screen._cursor_style.pending.cursor_shape) + eq('block', screen._cursor_style.insert.cursor_shape) + eq('vertical', screen._cursor_style.match_paren.cursor_shape) + end) + + it("empty 'guicursor' sets cursor_shape=block in all modes", function() + meths.set_option('guicursor', '') + command('redraw') + screen:expect('', nil, nil, nil, true) -- Tickle the event-loop. + for _, m in ipairs({ 'cmd_insert', 'cmd_normal', 'cmd_replace', 'insert', + 'match_paren', 'normal', 'replace', 'visual', + 'visual_select', }) do + eq('block', screen._cursor_style[m].cursor_shape) + end + end) + +end) diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua index b2fbedfb5e..ecbd5642d1 100644 --- a/test/functional/ui/mouse_spec.lua +++ b/test/functional/ui/mouse_spec.lua @@ -6,7 +6,7 @@ local eq, funcs = helpers.eq, helpers.funcs if helpers.pending_win32(pending) then return end -describe('Mouse input', function() +describe('ui/mouse/input', function() local screen before_each(function() diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 2d04949bb3..f67a4abd29 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -345,8 +345,8 @@ function Screen:_handle_resize(width, height) } end -function Screen:_handle_cursor_style_set(styles) - self._cursor_styles = styles +function Screen:_handle_cursor_style_set(style) + self._cursor_style = style end function Screen:_handle_clear() -- cgit From 3a69dbfca6642463ca8e19f814f71791f66332f3 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 1 Apr 2017 22:32:16 +0200 Subject: api/cursor_style_set: mode descriptions --- test/functional/ui/cursor_spec.lua | 62 ++++++++++++++++++++------------------ test/functional/ui/screen.lua | 4 +-- 2 files changed, 34 insertions(+), 32 deletions(-) (limited to 'test') diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index 6f5fd244d5..8b42c193ab 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -5,8 +5,6 @@ local insert, execute = helpers.insert, helpers.execute local eq, funcs = helpers.eq, helpers.funcs local command = helpers.command -if helpers.pending_win32(pending) then return end - describe('ui/cursor', function() local screen @@ -24,7 +22,10 @@ describe('ui/cursor', function() command('redraw') screen:expect('', nil, nil, nil, true) -- Tickle the event-loop. local expected_cursor_style = { - cmd_insert = { + cmdline_hover = { + mouse_shape = 0, + short_name = 'e' }, + cmdline_insert = { blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -34,10 +35,7 @@ describe('ui/cursor', function() id_lm = 46, mouse_shape = 0, short_name = 'ci' }, - cmd_line = { - mouse_shape = 0, - short_name = 'e' }, - cmd_normal = { + cmdline_normal = { blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -47,7 +45,7 @@ describe('ui/cursor', function() id_lm = 46, mouse_shape = 0, short_name = 'c' }, - cmd_replace = { + cmdline_replace = { blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -57,9 +55,6 @@ describe('ui/cursor', function() id_lm = 46, mouse_shape = 0, short_name = 'cr' }, - drag_statusline = { - mouse_shape = 0, - short_name = 'sd' }, insert = { blinkoff = 250, blinkon = 400, @@ -70,15 +65,6 @@ describe('ui/cursor', function() id_lm = 46, mouse_shape = 0, short_name = 'i' }, - match_paren = { - blinkoff = 150, - blinkon = 175, - blinkwait = 175, - cell_percentage = 0, - cursor_shape = 'block', - hl_id = 45, - id_lm = 45, - short_name = 'sm' }, more = { mouse_shape = 0, short_name = 'm' }, @@ -95,7 +81,7 @@ describe('ui/cursor', function() id_lm = 46, mouse_shape = 0, short_name = 'n' }, - pending = { + operator = { blinkoff = 250, blinkon = 400, blinkwait = 700, @@ -115,12 +101,21 @@ describe('ui/cursor', function() id_lm = 46, mouse_shape = 0, short_name = 'r' }, - statusline = { + showmatch = { + blinkoff = 150, + blinkon = 175, + blinkwait = 175, + cell_percentage = 0, + cursor_shape = 'block', + hl_id = 45, + id_lm = 45, + short_name = 'sm' }, + statusline_drag = { mouse_shape = 0, - short_name = 's' }, - vdrag = { + short_name = 'sd' }, + statusline_hover = { mouse_shape = 0, - short_name = 'vd' }, + short_name = 's' }, visual = { blinkoff = 250, blinkon = 400, @@ -141,7 +136,10 @@ describe('ui/cursor', function() id_lm = 45, mouse_shape = 0, short_name = 've' }, - vsep = { + vsep_drag = { + mouse_shape = 0, + short_name = 'vd' }, + vsep_hover = { mouse_shape = 0, short_name = 'vs' } } @@ -161,19 +159,23 @@ describe('ui/cursor', function() screen:expect('', nil, nil, nil, true) -- Tickle the event-loop. eq('vertical', screen._cursor_style.normal.cursor_shape) eq('horizontal', screen._cursor_style.visual_select.cursor_shape) - eq('vertical', screen._cursor_style.pending.cursor_shape) + eq('vertical', screen._cursor_style.operator.cursor_shape) eq('block', screen._cursor_style.insert.cursor_shape) - eq('vertical', screen._cursor_style.match_paren.cursor_shape) + eq('vertical', screen._cursor_style.showmatch.cursor_shape) + eq(171, screen._cursor_style.normal.blinkwait) + eq(172, screen._cursor_style.normal.blinkoff) + eq(173, screen._cursor_style.normal.blinkon) end) it("empty 'guicursor' sets cursor_shape=block in all modes", function() meths.set_option('guicursor', '') command('redraw') screen:expect('', nil, nil, nil, true) -- Tickle the event-loop. - for _, m in ipairs({ 'cmd_insert', 'cmd_normal', 'cmd_replace', 'insert', - 'match_paren', 'normal', 'replace', 'visual', + for _, m in ipairs({ 'cmdline_insert', 'cmdline_normal', 'cmdline_replace', 'insert', + 'showmatch', 'normal', 'replace', 'visual', 'visual_select', }) do eq('block', screen._cursor_style[m].cursor_shape) + eq(0, screen._cursor_style[m].blinkon) end end) diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index f67a4abd29..3f8173c8e2 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -313,8 +313,8 @@ function Screen:_redraw(updates) if handler ~= nil then handler(self, unpack(update[i])) else - assert(self._on_event, "Either add an Screen:_handle_XXX method ".. - " or call Screen:set_on_event_handler") + assert(self._on_event, + "Add Screen:_handle_XXX method or call Screen:set_on_event_handler") self._on_event(method, update[i]) end end -- cgit From ddfa0359c638a4fd5eba5c339dc3e18e2b8aca35 Mon Sep 17 00:00:00 2001 From: Nikolai Aleksandrovich Pavlov Date: Sun, 2 Apr 2017 14:25:47 +0300 Subject: unittests: Make it easier to determine on which _spec line it crashed (#6424) Benchmarks: Before change: 17.78s user 3.48s system 94% cpu 22.525 total After change: 25.38s user 4.46s system 101% cpu 29.317 total --- test/unit/helpers.lua | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 93e1e91173..74f214a231 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -528,7 +528,8 @@ local hook_msglen = 1 + 1 + 1 + (1 + hook_fnamelen) + (1 + hook_sfnamelen) + (1 local tracehelp = dedent([[ ┌ Trace type: _r_eturn from function , function _c_all, _l_ine executed, - │ _t_ail return, _C_ount (should not actually appear). + │ _t_ail return, _C_ount (should not actually appear), + │ _s_aved from previous run for reference. │┏ Function type: _L_ua function, _C_ function, _m_ain part of chunk, │┃ function that did _t_ail call. │┃┌ Function name type: _g_lobal, _l_ocal, _m_ethod, _f_ield, _u_pvalue, @@ -549,15 +550,27 @@ local function child_sethook(wr) return end local trace_only_c = trace_level <= 1 - local function hook(reason, lnum) + local prev_info, prev_reason, prev_lnum + local function hook(reason, lnum, use_prev) local info = nil - if reason ~= 'tail return' then -- tail return + if use_prev then + info = prev_info + elseif reason ~= 'tail return' then -- tail return info = debug.getinfo(2, 'nSl') end - if trace_only_c and (not info or info.what ~= 'C') then + if trace_only_c and (not info or info.what ~= 'C') and not use_prev then + if info.source:sub(-9) == '_spec.lua' then + prev_info = info + prev_reason = 'saved' + prev_lnum = lnum + end return end + if trace_only_c and not use_prev and prev_reason then + hook(prev_reason, prev_lnum, true) + prev_reason = nil + end local whatchar = ' ' local namewhatchar = ' ' @@ -609,7 +622,7 @@ local function child_sethook(wr) -- eq(hook_msglen, #msg) sc.write(wr, msg) end - debug.sethook(hook, trace_only_c and 'cr' or 'crl') + debug.sethook(hook, 'crl') end local trace_end_msg = ('E%s\n'):format((' '):rep(hook_msglen - 2)) -- cgit From b10880dadcbd3b3ad368621f95a0f4be7e30dc0d Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 2 Apr 2017 22:11:35 +0300 Subject: eval: Make writefile() able to disable fsync() --- test/unit/os/fileio_spec.lua | 66 +++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 23 deletions(-) (limited to 'test') diff --git a/test/unit/os/fileio_spec.lua b/test/unit/os/fileio_spec.lua index 5e1b2523fa..6c1ae73847 100644 --- a/test/unit/os/fileio_spec.lua +++ b/test/unit/os/fileio_spec.lua @@ -98,7 +98,7 @@ describe('file_open', function() eq(0, err) local attrs = lfs.attributes(filec) eq('rwx------', attrs.permissions) - eq(0, m.file_close(fp)) + eq(0, m.file_close(fp, false)) end) itp('can create a rw------- file with kFileCreate', function() @@ -106,7 +106,7 @@ describe('file_open', function() eq(0, err) local attrs = lfs.attributes(filec) eq('rw-------', attrs.permissions) - eq(0, m.file_close(fp)) + eq(0, m.file_close(fp, false)) end) itp('can create a rwx------ file with kFileCreateOnly', function() @@ -114,7 +114,7 @@ describe('file_open', function() eq(0, err) local attrs = lfs.attributes(filec) eq('rwx------', attrs.permissions) - eq(0, m.file_close(fp)) + eq(0, m.file_close(fp, false)) end) itp('can create a rw------- file with kFileCreateOnly', function() @@ -122,7 +122,7 @@ describe('file_open', function() eq(0, err) local attrs = lfs.attributes(filec) eq('rw-------', attrs.permissions) - eq(0, m.file_close(fp)) + eq(0, m.file_close(fp, false)) end) itp('fails to open an existing file with kFileCreateOnly', function() @@ -141,35 +141,35 @@ describe('file_open', function() local err, fp = file_open(file1, m.kFileCreate, 384) eq(0, err) eq(true, fp.wr) - eq(0, m.file_close(fp)) + eq(0, m.file_close(fp, false)) end) itp('can open an existing file read-only with zero', function() local err, fp = file_open(file1, 0, 384) eq(0, err) eq(false, fp.wr) - eq(0, m.file_close(fp)) + eq(0, m.file_close(fp, false)) end) itp('can open an existing file read-only with kFileReadOnly', function() local err, fp = file_open(file1, m.kFileReadOnly, 384) eq(0, err) eq(false, fp.wr) - eq(0, m.file_close(fp)) + eq(0, m.file_close(fp, false)) end) itp('can open an existing file read-only with kFileNoSymlink', function() local err, fp = file_open(file1, m.kFileNoSymlink, 384) eq(0, err) eq(false, fp.wr) - eq(0, m.file_close(fp)) + eq(0, m.file_close(fp, false)) end) itp('can truncate an existing file with kFileTruncate', function() local err, fp = file_open(file1, m.kFileTruncate, 384) eq(0, err) eq(true, fp.wr) - eq(0, m.file_close(fp)) + eq(0, m.file_close(fp, false)) local attrs = lfs.attributes(file1) eq(0, attrs.size) end) @@ -178,7 +178,7 @@ describe('file_open', function() local err, fp = file_open(file1, m.kFileWriteOnly, 384) eq(0, err) eq(true, fp.wr) - eq(0, m.file_close(fp)) + eq(0, m.file_close(fp, false)) local attrs = lfs.attributes(file1) eq(4096, attrs.size) end) @@ -195,7 +195,7 @@ describe('file_open', function() local err, fp = file_open(linkf, m.kFileTruncate, 384) eq(0, err) eq(true, fp.wr) - eq(0, m.file_close(fp)) + eq(0, m.file_close(fp, false)) local attrs = lfs.attributes(file1) eq(0, attrs.size) end) @@ -221,7 +221,7 @@ describe('file_open_new', function() local err, fp = file_open_new(file1, 0, 384) eq(0, err) eq(false, fp.wr) - eq(0, m.file_free(fp)) + eq(0, m.file_free(fp, false)) end) itp('fails to open an existing file with kFileCreateOnly', function() @@ -231,7 +231,27 @@ describe('file_open_new', function() end) end) --- file_close is called above, so it is not tested directly +describe('file_close', function() + itp('can flush writes to disk also with true argument', function() + local err, fp = file_open(filec, m.kFileCreateOnly, 384) + local wsize = file_write(fp, 'test') + eq(4, wsize) + eq(0, lfs.attributes(filec).size) + eq(0, m.file_close(fp, true)) + eq(wsize, lfs.attributes(filec).size) + end) +end) + +describe('file_free', function() + itp('can flush writes to disk also with true argument', function() + local err, fp = file_open_new(filec, m.kFileCreateOnly, 384) + local wsize = file_write(fp, 'test') + eq(4, wsize) + eq(0, lfs.attributes(filec).size) + eq(0, m.file_free(fp, true)) + eq(wsize, lfs.attributes(filec).size) + end) +end) describe('file_fsync', function() itp('can flush writes to disk', function() @@ -244,7 +264,7 @@ describe('file_fsync', function() eq(0, lfs.attributes(filec).size) eq(0, file_fsync(fp)) eq(wsize, lfs.attributes(filec).size) - eq(0, m.file_close(fp)) + eq(0, m.file_close(fp, false)) end) end) @@ -259,7 +279,7 @@ describe('file_flush', function() eq(0, lfs.attributes(filec).size) eq(0, file_flush(fp)) eq(wsize, lfs.attributes(filec).size) - eq(0, m.file_close(fp)) + eq(0, m.file_close(fp, false)) end) end) @@ -281,7 +301,7 @@ describe('file_read', function() eq({exp_err, exp_s}, {file_read(fp, size)}) shift = shift + size end - eq(0, m.file_close(fp)) + eq(0, m.file_close(fp, false)) end) itp('can read the whole file at once', function() @@ -290,7 +310,7 @@ describe('file_read', function() eq(false, fp.wr) eq({#fcontents, fcontents}, {file_read(fp, #fcontents)}) eq({0, ('\0'):rep(#fcontents)}, {file_read(fp, #fcontents)}) - eq(0, m.file_close(fp)) + eq(0, m.file_close(fp, false)) end) itp('can read more then 1024 bytes after reading a small chunk', function() @@ -300,7 +320,7 @@ describe('file_read', function() eq({5, fcontents:sub(1, 5)}, {file_read(fp, 5)}) eq({#fcontents - 5, fcontents:sub(6) .. (('\0'):rep(5))}, {file_read(fp, #fcontents)}) - eq(0, m.file_close(fp)) + eq(0, m.file_close(fp, false)) end) itp('can read file by 768-byte-chunks', function() @@ -320,7 +340,7 @@ describe('file_read', function() eq({exp_err, exp_s}, {file_read(fp, size)}) shift = shift + size end - eq(0, m.file_close(fp)) + eq(0, m.file_close(fp, false)) end) end) @@ -331,7 +351,7 @@ describe('file_write', function() eq(true, fp.wr) local wr = file_write(fp, fcontents) eq(#fcontents, wr) - eq(0, m.file_close(fp)) + eq(0, m.file_close(fp, false)) eq(wr, lfs.attributes(filec).size) eq(fcontents, io.open(filec):read('*a')) end) @@ -348,7 +368,7 @@ describe('file_write', function() eq(wr, #s) shift = shift + size end - eq(0, m.file_close(fp)) + eq(0, m.file_close(fp, false)) eq(#fcontents, lfs.attributes(filec).size) eq(fcontents, io.open(filec):read('*a')) end) @@ -365,7 +385,7 @@ describe('file_write', function() eq(wr, #s) shift = shift + size end - eq(0, m.file_close(fp)) + eq(0, m.file_close(fp, false)) eq(#fcontents, lfs.attributes(filec).size) eq(fcontents, io.open(filec):read('*a')) end) @@ -380,6 +400,6 @@ describe('file_skip', function() local rd, s = file_read(fp, 3) eq(3, rd) eq(fcontents:sub(4, 6), s) - eq(0, m.file_close(fp)) + eq(0, m.file_close(fp, false)) end) end) -- cgit From 97a7f4745dd1d75cd176dede1a4430bc4e28f8f7 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 3 Apr 2017 02:11:27 +0300 Subject: eval: Add s flag, use p_fs by default, error out on unknown flag --- test/functional/eval/writefile_spec.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test') diff --git a/test/functional/eval/writefile_spec.lua b/test/functional/eval/writefile_spec.lua index 3052c616e0..2f84114b9b 100644 --- a/test/functional/eval/writefile_spec.lua +++ b/test/functional/eval/writefile_spec.lua @@ -80,6 +80,13 @@ describe('writefile()', function() eq('a\0\0\0b', read_file(fname)) end) + it('writes with s and S', function() + eq(0, funcs.writefile({'\na\nb\n'}, fname, 'bs')) + eq('\0a\0b\0', read_file(fname)) + eq(0, funcs.writefile({'a\n\n\nb'}, fname, 'bS')) + eq('a\0\0\0b', read_file(fname)) + end) + it('correctly overwrites file', function() eq(0, funcs.writefile({'\na\nb\n'}, fname, 'b')) eq('\0a\0b\0', read_file(fname)) @@ -115,6 +122,8 @@ describe('writefile()', function() eq('\nE729: using Funcref as a String', redir_exec(('call writefile(%s)'):format(args:format('function("tr")')))) end + eq('\nE5060: Unknown flag: «»', + redir_exec(('call writefile([], "%s", "bs«»")'):format(fname))) eq('TEST', read_file(fname)) end) -- cgit From 991204310399d4dcaf5f5ee7571eff178c93e793 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 3 Apr 2017 03:04:10 +0300 Subject: functests: Test some :write errors --- test/functional/ex_cmds/write_spec.lua | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'test') diff --git a/test/functional/ex_cmds/write_spec.lua b/test/functional/ex_cmds/write_spec.lua index 4ac9f312ef..9c2687971e 100644 --- a/test/functional/ex_cmds/write_spec.lua +++ b/test/functional/ex_cmds/write_spec.lua @@ -1,15 +1,28 @@ local helpers = require('test.functional.helpers')(after_each) +local lfs = require('lfs') local eq, eval, clear, write_file, execute, source, insert = helpers.eq, helpers.eval, helpers.clear, helpers.write_file, helpers.execute, helpers.source, helpers.insert +local redir_exec = helpers.redir_exec +local exc_exec = helpers.exc_exec +local command = helpers.command +local funcs = helpers.funcs +local meths = helpers.meths if helpers.pending_win32(pending) then return end +local fname = 'Xtest-functional-ex_cmds-write' +local fname_bak = fname .. '~' +local fname_broken = fname_bak .. 'broken' + describe(':write', function() local function cleanup() os.remove('test_bkc_file.txt') os.remove('test_bkc_link.txt') os.remove('test_fifo') + os.remove(fname) + os.remove(fname_bak) + os.remove(fname_broken) end before_each(function() clear() @@ -63,4 +76,34 @@ describe(':write', function() eq(text.."\n", fifo:read("*all")) fifo:close() end) + + it('errors out correctly', function() + command('let $HOME=""') + eq(funcs.fnamemodify('.', ':p:h'), funcs.fnamemodify('.', ':p:h:~')) + -- Message from check_overwrite + eq(('\nE17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'), + redir_exec('write .')) + meths.set_option('writeany', true) + -- Message from buf_write + eq(('\nE502: "." is a directory'), + redir_exec('write .')) + funcs.mkdir(fname_bak) + meths.set_option('backupdir', '.') + meths.set_option('backup', true) + write_file(fname, 'content0') + eq(0, exc_exec('edit ' .. fname)) + funcs.setline(1, 'TTY') + eq('Vim(write):E510: Can\'t make backup file (add ! to override)', + exc_exec('write')) + meths.set_option('backup', false) + funcs.setfperm(fname, 'r--------') + eq('Vim(write):E505: "Xtest-functional-ex_cmds-write" is read-only (add ! to override)', + exc_exec('write')) + os.remove(fname) + os.remove(fname_bak) + write_file(fname_bak, 'TTYX') + lfs.link(fname_bak .. ('/xxxxx'):rep(20), fname, true) + eq('Vim(write):E166: Can\'t open linked file for writing', + exc_exec('write!')) + end) end) -- cgit From dc75766081e143401ae28bea66f970ab005402fc Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 3 Apr 2017 03:07:01 +0300 Subject: tests: Fix testlint errors --- test/functional/ui/cursor_spec.lua | 5 ++--- test/unit/os/fileio_spec.lua | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index 8b42c193ab..56f02e4e7f 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -1,8 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local clear, feed, meths = helpers.clear, helpers.feed, helpers.meths -local insert, execute = helpers.insert, helpers.execute -local eq, funcs = helpers.eq, helpers.funcs +local clear, meths = helpers.clear, helpers.meths +local eq = helpers.eq local command = helpers.command describe('ui/cursor', function() diff --git a/test/unit/os/fileio_spec.lua b/test/unit/os/fileio_spec.lua index 6c1ae73847..e3c8e616ce 100644 --- a/test/unit/os/fileio_spec.lua +++ b/test/unit/os/fileio_spec.lua @@ -234,6 +234,7 @@ end) describe('file_close', function() itp('can flush writes to disk also with true argument', function() local err, fp = file_open(filec, m.kFileCreateOnly, 384) + eq(0, err) local wsize = file_write(fp, 'test') eq(4, wsize) eq(0, lfs.attributes(filec).size) @@ -245,6 +246,7 @@ end) describe('file_free', function() itp('can flush writes to disk also with true argument', function() local err, fp = file_open_new(filec, m.kFileCreateOnly, 384) + eq(0, err) local wsize = file_write(fp, 'test') eq(4, wsize) eq(0, lfs.attributes(filec).size) -- cgit From bc6d868d00a739050b683f33994f7493cf81bd61 Mon Sep 17 00:00:00 2001 From: Yichao Zhou Date: Sun, 26 Mar 2017 03:15:52 -0700 Subject: 'listchars': `Whitespace` highlight group #6367 --- test/functional/ui/cursor_spec.lua | 40 ++++++------- test/functional/ui/highlight_spec.lua | 105 +++++++++++----------------------- 2 files changed, 54 insertions(+), 91 deletions(-) (limited to 'test') diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index 56f02e4e7f..1e3a9fcb60 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -30,8 +30,8 @@ describe('ui/cursor', function() blinkwait = 700, cell_percentage = 25, cursor_shape = 'vertical', - hl_id = 45, - id_lm = 46, + hl_id = 46, + id_lm = 47, mouse_shape = 0, short_name = 'ci' }, cmdline_normal = { @@ -40,8 +40,8 @@ describe('ui/cursor', function() blinkwait = 700, cell_percentage = 0, cursor_shape = 'block', - hl_id = 45, - id_lm = 46, + hl_id = 46, + id_lm = 47, mouse_shape = 0, short_name = 'c' }, cmdline_replace = { @@ -50,8 +50,8 @@ describe('ui/cursor', function() blinkwait = 700, cell_percentage = 20, cursor_shape = 'horizontal', - hl_id = 45, - id_lm = 46, + hl_id = 46, + id_lm = 47, mouse_shape = 0, short_name = 'cr' }, insert = { @@ -60,8 +60,8 @@ describe('ui/cursor', function() blinkwait = 700, cell_percentage = 25, cursor_shape = 'vertical', - hl_id = 45, - id_lm = 46, + hl_id = 46, + id_lm = 47, mouse_shape = 0, short_name = 'i' }, more = { @@ -76,8 +76,8 @@ describe('ui/cursor', function() blinkwait = 700, cell_percentage = 0, cursor_shape = 'block', - hl_id = 45, - id_lm = 46, + hl_id = 46, + id_lm = 47, mouse_shape = 0, short_name = 'n' }, operator = { @@ -86,8 +86,8 @@ describe('ui/cursor', function() blinkwait = 700, cell_percentage = 50, cursor_shape = 'horizontal', - hl_id = 45, - id_lm = 45, + hl_id = 46, + id_lm = 46, mouse_shape = 0, short_name = 'o' }, replace = { @@ -96,8 +96,8 @@ describe('ui/cursor', function() blinkwait = 700, cell_percentage = 20, cursor_shape = 'horizontal', - hl_id = 45, - id_lm = 46, + hl_id = 46, + id_lm = 47, mouse_shape = 0, short_name = 'r' }, showmatch = { @@ -106,8 +106,8 @@ describe('ui/cursor', function() blinkwait = 175, cell_percentage = 0, cursor_shape = 'block', - hl_id = 45, - id_lm = 45, + hl_id = 46, + id_lm = 46, short_name = 'sm' }, statusline_drag = { mouse_shape = 0, @@ -121,8 +121,8 @@ describe('ui/cursor', function() blinkwait = 700, cell_percentage = 0, cursor_shape = 'block', - hl_id = 45, - id_lm = 46, + hl_id = 46, + id_lm = 47, mouse_shape = 0, short_name = 'v' }, visual_select = { @@ -131,8 +131,8 @@ describe('ui/cursor', function() blinkwait = 700, cell_percentage = 35, cursor_shape = 'vertical', - hl_id = 45, - id_lm = 45, + hl_id = 46, + id_lm = 46, mouse_shape = 0, short_name = 've' }, vsep_drag = { diff --git a/test/functional/ui/highlight_spec.lua b/test/functional/ui/highlight_spec.lua index 7a1b8c91e7..05cf3231ea 100644 --- a/test/functional/ui/highlight_spec.lua +++ b/test/functional/ui/highlight_spec.lua @@ -200,57 +200,30 @@ describe('Default highlight groups', function() it('insert mode text', function() feed('i') + screen:try_resize(53, 4) screen:expect([[ ^ | {0:~ }| {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| {1:-- INSERT --} | ]], {[0] = {bold=true, foreground=Screen.colors.Blue}, [1] = {bold = true}}) end) it('end of file markers', function() + screen:try_resize(53, 4) screen:expect([[ ^ | {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| {1:~ }| | ]], {[1] = {bold = true, foreground = Screen.colors.Blue}}) end) it('"wait return" text', function() + screen:try_resize(53, 4) feed(':ls') screen:expect([[ - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| {0:~ }| :ls | 1 %a "[No Name]" line 1 | @@ -259,23 +232,15 @@ describe('Default highlight groups', function() [1] = {bold = true, foreground = Screen.colors.SeaGreen}}) feed('') -- skip the "Press ENTER..." state or tests will hang end) + it('can be cleared and linked to other highlight groups', function() + screen:try_resize(53, 4) execute('highlight clear ModeMsg') feed('i') screen:expect([[ ^ | {0:~ }| {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| -- INSERT -- | ]], {[0] = {bold=true, foreground=Screen.colors.Blue}, [1] = {bold=true}}) @@ -287,37 +252,19 @@ describe('Default highlight groups', function() ^ | {0:~ }| {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| {1:-- INSERT --} | ]], {[0] = {bold=true, foreground=Screen.colors.Blue}, [1] = {foreground = Screen.colors.Red, background = Screen.colors.Green}}) end) + it('can be cleared by assigning NONE', function() + screen:try_resize(53, 4) execute('syn keyword TmpKeyword neovim') execute('hi link TmpKeyword ErrorMsg') insert('neovim') screen:expect([[ {1:neovi^m} | {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| {0:~ }| | ]], { @@ -330,18 +277,34 @@ describe('Default highlight groups', function() neovi^m | {0:~ }| {0:~ }| + | + ]], {[0] = {bold=true, foreground=Screen.colors.Blue}}) + end) + + it('Whitespace highlight', function() + screen:try_resize(53, 4) + execute('highlight NonText gui=NONE guifg=#FF0000') + execute('set listchars=space:.,tab:>-,trail:*,eol:¬ list') + insert(' ne \t o\tv im ') + screen:expect([[ + ne{0:.>----.}o{0:>-----}v{0:..}im{0:*^*¬} | {0:~ }| {0:~ }| + | + ]], { + [0] = {foreground=Screen.colors.Red}, + [1] = {foreground=Screen.colors.Blue}, + }) + execute('highlight Whitespace gui=NONE guifg=#0000FF') + screen:expect([[ + ne{1:.>----.}o{1:>-----}v{1:..}im{1:*^*}{0:¬} | {0:~ }| {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - | - ]], {[0] = {bold=true, foreground=Screen.colors.Blue}}) + :highlight Whitespace gui=NONE guifg=#0000FF | + ]], { + [0] = {foreground=Screen.colors.Red}, + [1] = {foreground=Screen.colors.Blue}, + }) end) end) @@ -510,7 +473,7 @@ describe("'listchars' highlight", function() }, }) execute('highlight clear ModeMsg') - execute('highlight SpecialKey guifg=#FF0000') + execute('highlight Whitespace guifg=#FF0000') execute('set cursorline') execute('set tabstop=8') execute('set listchars=space:.,eol:¬,tab:>-,extends:>,precedes:<,trail:* list') @@ -606,7 +569,7 @@ describe("'listchars' highlight", function() }, }) execute('highlight clear ModeMsg') - execute('highlight SpecialKey guifg=#FF0000') + execute('highlight Whitespace guifg=#FF0000') execute('set cursorline') execute('set tabstop=8') execute('set nowrap') @@ -653,7 +616,7 @@ describe("'listchars' highlight", function() [3] = {foreground=Screen.colors.Green1}, }) execute('highlight clear ModeMsg') - execute('highlight SpecialKey guifg=#FF0000') + execute('highlight Whitespace guifg=#FF0000') execute('highlight Error guifg=#00FF00') execute('set nowrap') feed('ia \t bc \t ') -- cgit From 3ccd59ee8216f3da812c5cf81eb392e6a95b539a Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 3 Apr 2017 16:16:21 +0200 Subject: 'guicursor': enabled=false if 'guicursor' is empty Closes #6429 Closes #6430 --- test/functional/ui/cursor_spec.lua | 1 + test/functional/ui/screen.lua | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index 1e3a9fcb60..c022a5649e 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -144,6 +144,7 @@ describe('ui/cursor', function() } -- Default 'guicursor' published on startup. eq(expected_cursor_style, screen._cursor_style) + eq(true, screen._cursor_style_enabled) eq('normal', screen.mode) -- Event is published ONLY if the cursor style changed. diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 3f8173c8e2..ff71194dab 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -345,7 +345,8 @@ function Screen:_handle_resize(width, height) } end -function Screen:_handle_cursor_style_set(style) +function Screen:_handle_cursor_style_set(enabled, style) + self._cursor_style_enabled = enabled self._cursor_style = style end -- cgit From e348e256f3ed93fe462971447ee79033307b2ddf Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 4 Apr 2017 02:37:43 +0200 Subject: 'guicursor': Disable by default for unknown terminals. User can still set guicursor explicitly in init.vim. Closes #5990 Closes #6403 --- test/functional/ui/cursor_spec.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index c022a5649e..3ec3ffd08c 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -3,6 +3,7 @@ local Screen = require('test.functional.ui.screen') local clear, meths = helpers.clear, helpers.meths local eq = helpers.eq local command = helpers.command +local wait = helpers.wait describe('ui/cursor', function() local screen @@ -18,7 +19,7 @@ describe('ui/cursor', function() end) it("'guicursor' is published as a UI event", function() - command('redraw') + wait() screen:expect('', nil, nil, nil, true) -- Tickle the event-loop. local expected_cursor_style = { cmdline_hover = { @@ -149,13 +150,13 @@ describe('ui/cursor', function() -- Event is published ONLY if the cursor style changed. screen._cursor_style = nil - command('redraw') + wait() screen:expect('', nil, nil, nil, true) -- Tickle the event-loop. eq(nil, screen._cursor_style) -- Change the cursor style. meths.set_option('guicursor', 'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173,ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42') - command('redraw') + wait() screen:expect('', nil, nil, nil, true) -- Tickle the event-loop. eq('vertical', screen._cursor_style.normal.cursor_shape) eq('horizontal', screen._cursor_style.visual_select.cursor_shape) @@ -171,6 +172,8 @@ describe('ui/cursor', function() meths.set_option('guicursor', '') command('redraw') screen:expect('', nil, nil, nil, true) -- Tickle the event-loop. + -- Empty 'guicursor' sets enabled=false. + eq(false, screen._cursor_style_enabled) for _, m in ipairs({ 'cmdline_insert', 'cmdline_normal', 'cmdline_replace', 'insert', 'showmatch', 'normal', 'replace', 'visual', 'visual_select', }) do -- cgit From 3b558e5d7b8c641896a57c5c4e09d9b8f8535fd5 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Tue, 4 Apr 2017 17:47:23 +0200 Subject: tests: short form `screen:except(func)` expects condition only. #6440 - Use this to properly test cursor shape events. - tests: update screen_basic_spec to use `screen:expect` short form. Clearer than using `screen:wait` directy. --- test/functional/ui/cursor_spec.lua | 69 ++++++++++++++++++-------------- test/functional/ui/screen.lua | 32 +++++++++------ test/functional/ui/screen_basic_spec.lua | 50 ++++++++--------------- 3 files changed, 75 insertions(+), 76 deletions(-) (limited to 'test') diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index 3ec3ffd08c..02e9422781 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -3,7 +3,6 @@ local Screen = require('test.functional.ui.screen') local clear, meths = helpers.clear, helpers.meths local eq = helpers.eq local command = helpers.command -local wait = helpers.wait describe('ui/cursor', function() local screen @@ -19,8 +18,6 @@ describe('ui/cursor', function() end) it("'guicursor' is published as a UI event", function() - wait() - screen:expect('', nil, nil, nil, true) -- Tickle the event-loop. local expected_cursor_style = { cmdline_hover = { mouse_shape = 0, @@ -142,44 +139,54 @@ describe('ui/cursor', function() vsep_hover = { mouse_shape = 0, short_name = 'vs' } - } - -- Default 'guicursor' published on startup. - eq(expected_cursor_style, screen._cursor_style) - eq(true, screen._cursor_style_enabled) - eq('normal', screen.mode) + } + + screen:expect(function() + -- Default 'guicursor' published on startup. + eq(expected_cursor_style, screen._cursor_style) + eq(true, screen._cursor_style_enabled) + eq('normal', screen.mode) + end) -- Event is published ONLY if the cursor style changed. screen._cursor_style = nil - wait() - screen:expect('', nil, nil, nil, true) -- Tickle the event-loop. - eq(nil, screen._cursor_style) + command("echo 'test'") + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + test | + ]], nil, nil, function() + eq(nil, screen._cursor_style) + end) -- Change the cursor style. meths.set_option('guicursor', 'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173,ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42') - wait() - screen:expect('', nil, nil, nil, true) -- Tickle the event-loop. - eq('vertical', screen._cursor_style.normal.cursor_shape) - eq('horizontal', screen._cursor_style.visual_select.cursor_shape) - eq('vertical', screen._cursor_style.operator.cursor_shape) - eq('block', screen._cursor_style.insert.cursor_shape) - eq('vertical', screen._cursor_style.showmatch.cursor_shape) - eq(171, screen._cursor_style.normal.blinkwait) - eq(172, screen._cursor_style.normal.blinkoff) - eq(173, screen._cursor_style.normal.blinkon) + screen:expect(function() + eq('vertical', screen._cursor_style.normal.cursor_shape) + eq('horizontal', screen._cursor_style.visual_select.cursor_shape) + eq('vertical', screen._cursor_style.operator.cursor_shape) + eq('block', screen._cursor_style.insert.cursor_shape) + eq('vertical', screen._cursor_style.showmatch.cursor_shape) + eq(171, screen._cursor_style.normal.blinkwait) + eq(172, screen._cursor_style.normal.blinkoff) + eq(173, screen._cursor_style.normal.blinkon) + end) end) it("empty 'guicursor' sets cursor_shape=block in all modes", function() meths.set_option('guicursor', '') - command('redraw') - screen:expect('', nil, nil, nil, true) -- Tickle the event-loop. - -- Empty 'guicursor' sets enabled=false. - eq(false, screen._cursor_style_enabled) - for _, m in ipairs({ 'cmdline_insert', 'cmdline_normal', 'cmdline_replace', 'insert', - 'showmatch', 'normal', 'replace', 'visual', - 'visual_select', }) do - eq('block', screen._cursor_style[m].cursor_shape) - eq(0, screen._cursor_style[m].blinkon) - end + screen:expect(function() + -- Empty 'guicursor' sets enabled=false. + eq(false, screen._cursor_style_enabled) + for _, m in ipairs({ 'cmdline_insert', 'cmdline_normal', 'cmdline_replace', 'insert', + 'showmatch', 'normal', 'replace', 'visual', + 'visual_select', }) do + eq('block', screen._cursor_style[m].cursor_shape) + eq(0, screen._cursor_style[m].blinkon) + end + end) end) end) diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index ff71194dab..2f2cc85dab 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -181,6 +181,7 @@ end -- expected: Expected screen state (string). Each line represents a screen -- row. Last character of each row (typically "|") is stripped. -- Common indentation is stripped. +-- Used as `condition` if NOT a string; must be the ONLY arg then. -- attr_ids: Expected text attributes. Screen rows are transformed according -- to this table, as follows: each substring S composed of -- characters having the same attributes will be substituted by @@ -191,18 +192,23 @@ end -- any: true: Succeed if `expected` matches ANY screen line(s). -- false (default): `expected` must match screen exactly. function Screen:expect(expected, attr_ids, attr_ignore, condition, any) - -- remove the last line and dedent - expected = dedent(expected:gsub('\n[ ]+$', '')) local expected_rows = {} - for row in expected:gmatch('[^\n]+') do - -- the last character should be the screen delimiter - row = row:sub(1, #row - 1) - table.insert(expected_rows, row) - end - if not any then - assert(self._height == #expected_rows, - "Expected screen state's row count(" .. #expected_rows - .. ') differs from configured height(' .. self._height .. ') of Screen.') + if type(expected) ~= "string" then + assert(not (attr_ids or attr_ignore or condition or any)) + condition = expected + expected = nil + else + -- Remove the last line and dedent. + expected = dedent(expected:gsub('\n[ ]+$', '')) + for row in expected:gmatch('[^\n]+') do + row = row:sub(1, #row - 1) -- Last char must be the screen delimiter. + table.insert(expected_rows, row) + end + if not any then + assert(self._height == #expected_rows, + "Expected screen state's row count(" .. #expected_rows + .. ') differs from configured height(' .. self._height .. ') of Screen.') + end end local ids = attr_ids or self._default_attr_ids local ignore = attr_ignore or self._default_attr_ignore @@ -218,7 +224,9 @@ function Screen:expect(expected, attr_ids, attr_ignore, condition, any) actual_rows[i] = self:_row_repr(self._rows[i], ids, ignore) end - if any then + if expected == nil then + return + elseif any then -- Search for `expected` anywhere in the screen lines. local actual_screen_str = table.concat(actual_rows, '\n') if nil == string.find(actual_screen_str, expected) then diff --git a/test/functional/ui/screen_basic_spec.lua b/test/functional/ui/screen_basic_spec.lua index e511234e5e..21953ba294 100644 --- a/test/functional/ui/screen_basic_spec.lua +++ b/test/functional/ui/screen_basic_spec.lua @@ -73,33 +73,29 @@ describe('Screen', function() describe(':suspend', function() it('is forwarded to the UI', function() local function check() - if not screen.suspended then - return 'Screen was not suspended' - end + eq(true, screen.suspended) end execute('suspend') - screen:wait(check) + screen:expect(check) screen.suspended = false feed('') - screen:wait(check) + screen:expect(check) end) end) describe('bell/visual bell', function() it('is forwarded to the UI', function() feed('') - screen:wait(function() - if not screen.bell or screen.visual_bell then - return 'Bell was not sent' - end + screen:expect(function() + eq(true, screen.bell) + eq(false, screen.visual_bell) end) screen.bell = false execute('set visualbell') feed('') - screen:wait(function() - if not screen.visual_bell or screen.bell then - return 'Visual bell was not sent' - end + screen:expect(function() + eq(true, screen.visual_bell) + eq(false, screen.bell) end) end) end) @@ -109,22 +105,16 @@ describe('Screen', function() local expected = 'test-title' execute('set titlestring='..expected) execute('set title') - screen:wait(function() - local actual = screen.title - if actual ~= expected then - return 'Expected title to be "'..expected..'" but was "'..actual..'"' - end + screen:expect(function() + eq(expected, screen.title) end) end) it('has correct default title with unnamed file', function() local expected = '[No Name] - NVIM' execute('set title') - screen:wait(function() - local actual = screen.title - if actual ~= expected then - return 'Expected title to be "'..expected..'" but was "'..actual..'"' - end + screen:expect(function() + eq(expected, screen.title) end) end) @@ -132,11 +122,8 @@ describe('Screen', function() local expected = 'myfile (/mydir) - NVIM' execute('set title') execute('file /mydir/myfile') - screen:wait(function() - local actual = screen.title - if actual ~= expected then - return 'Expected title to be "'..expected..'" but was "'..actual..'"' - end + screen:expect(function() + eq(expected, screen.title) end) end) end) @@ -146,11 +133,8 @@ describe('Screen', function() local expected = 'test-icon' execute('set iconstring='..expected) execute('set icon') - screen:wait(function() - local actual = screen.icon - if actual ~= expected then - return 'Expected title to be "'..expected..'" but was "'..actual..'"' - end + screen:expect(function() + eq(expected, screen.icon) end) end) end) -- cgit From 8863af28b8f756ab0e2063879adeb2b48871b61d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 6 Apr 2017 00:16:15 +0200 Subject: test: retry() works with asserts; error() not required. --- test/functional/autocmd/termclose_spec.lua | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/functional/autocmd/termclose_spec.lua b/test/functional/autocmd/termclose_spec.lua index ecda1bffb7..d4beab22e4 100644 --- a/test/functional/autocmd/termclose_spec.lua +++ b/test/functional/autocmd/termclose_spec.lua @@ -14,17 +14,11 @@ describe('TermClose event', function() nvim('set_option', 'shellcmdflag', 'EXE') end) - local function eq_err(expected, actual) - if expected ~= actual then - error('expected: '..tostring(expected)..', actual: '..tostring(actual)) - end - end - it('triggers when terminal job ends', function() command('autocmd TermClose * let g:test_termclose = 23') command('terminal') command('call jobstop(b:terminal_job_id)') - retry(nil, nil, function() eq_err(23, eval('g:test_termclose')) end) + retry(nil, nil, function() eq(23, eval('g:test_termclose')) end) end) it('reports the correct ', function() @@ -35,12 +29,12 @@ describe('TermClose event', function() eq(2, eval('bufnr("%")')) command('terminal') - retry(nil, nil, function() eq_err(3, eval('bufnr("%")')) end) + retry(nil, nil, function() eq(3, eval('bufnr("%")')) end) command('buffer 1') - retry(nil, nil, function() eq_err(1, eval('bufnr("%")')) end) + retry(nil, nil, function() eq(1, eval('bufnr("%")')) end) command('3bdelete!') - retry(nil, nil, function() eq_err('3', eval('g:abuf')) end) + retry(nil, nil, function() eq('3', eval('g:abuf')) end) end) end) -- cgit From 271df03fa4b507d8ec608abd530616cb4b57616e Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 4 Apr 2017 18:14:09 +0300 Subject: unittests: Force GC, fix GC failures in typval_spec --- test/unit/eval/typval_spec.lua | 37 +++++++++++++++++++++++++++---------- test/unit/helpers.lua | 3 ++- 2 files changed, 29 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 258b5c4c1f..c477683038 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -460,6 +460,10 @@ describe('typval.c', function() eq(empty_list, typvalt2lua(l_tv)) eq({true, true, true}, {lws[1].lw_item == nil, lws[2].lw_item == nil, lws[3].lw_item == nil}) + lib.tv_list_watch_remove(l, lws[1]) + lib.tv_list_watch_remove(l, lws[2]) + lib.tv_list_watch_remove(l, lws[3]) + alloc_log:check({}) end) end) @@ -1090,9 +1094,13 @@ describe('typval.c', function() local function list_join(l, sep, ret) local ga = ga_alloc() eq(ret or OK, lib.tv_list_join(ga, l, sep)) - if ga.ga_data == nil then return '' - else return ffi.string(ga.ga_data) + local ret = '' + if ga.ga_data ~= nil then + ret = ffi.string(ga.ga_data) end + -- For some reason this is not working well in GC + lib.ga_clear(ffi.gc(ga, nil)) + return ret end itp('works', function() local l @@ -2659,7 +2667,8 @@ describe('typval.c', function() {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 0}, {lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', 0}, }) do - local tv = typvalt(v[1], v[2]) + -- Using to_cstr, cannot free with tv_clear + local tv = ffi.gc(typvalt(v[1], v[2]), nil) alloc_log:check({}) local emsg = v[3] local ret = v[4] @@ -2687,7 +2696,8 @@ describe('typval.c', function() {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 0}, {lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', 0}, }) do - local tv = typvalt(v[1], v[2]) + -- Using to_cstr, cannot free with tv_clear + local tv = ffi.gc(typvalt(v[1], v[2]), nil) alloc_log:check({}) local emsg = v[3] local ret = {v[4], not not emsg} @@ -2721,7 +2731,8 @@ describe('typval.c', function() {lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', -1}, }) do lib.curwin.w_cursor.lnum = 46 - local tv = typvalt(v[1], v[2]) + -- Using to_cstr, cannot free with tv_clear + local tv = ffi.gc(typvalt(v[1], v[2]), nil) alloc_log:check({}) local emsg = v[3] local ret = v[4] @@ -2749,7 +2760,8 @@ describe('typval.c', function() {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, 'E907: Using a special value as a Float', 0}, {lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_float(UNKNOWN)', 0}, }) do - local tv = typvalt(v[1], v[2]) + -- Using to_cstr, cannot free with tv_clear + local tv = ffi.gc(typvalt(v[1], v[2]), nil) alloc_log:check({}) local emsg = v[3] local ret = v[4] @@ -2780,7 +2792,9 @@ describe('typval.c', function() {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 'false'}, {lib.VAR_UNKNOWN, nil, 'E908: using an invalid value as a String', ''}, }) do - local tv = typvalt(v[1], v[2]) + -- Using to_cstr in place of Neovim allocated string, cannot + -- tv_clear() that. + local tv = ffi.gc(typvalt(v[1], v[2]), nil) alloc_log:check({}) local emsg = v[3] local ret = v[4] @@ -2821,7 +2835,8 @@ describe('typval.c', function() {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 'false'}, {lib.VAR_UNKNOWN, nil, 'E908: using an invalid value as a String', nil}, }) do - local tv = typvalt(v[1], v[2]) + -- Using to_cstr, cannot free with tv_clear + local tv = ffi.gc(typvalt(v[1], v[2]), nil) alloc_log:check({}) local emsg = v[3] local ret = v[4] @@ -2861,7 +2876,8 @@ describe('typval.c', function() {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 'false'}, {lib.VAR_UNKNOWN, nil, 'E908: using an invalid value as a String', ''}, }) do - local tv = typvalt(v[1], v[2]) + -- Using to_cstr, cannot free with tv_clear + local tv = ffi.gc(typvalt(v[1], v[2]), nil) alloc_log:check({}) local emsg = v[3] local ret = v[4] @@ -2902,7 +2918,8 @@ describe('typval.c', function() {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarFalse}, nil, 'false'}, {lib.VAR_UNKNOWN, nil, 'E908: using an invalid value as a String', nil}, }) do - local tv = typvalt(v[1], v[2]) + -- Using to_cstr, cannot free with tv_clear + local tv = ffi.gc(typvalt(v[1], v[2]), nil) alloc_log:check({}) local emsg = v[3] local ret = v[4] diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 74f214a231..6d0de5c651 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -632,8 +632,9 @@ local function itp_child(wr, func) collectgarbage('stop') child_sethook(wr) local err, emsg = pcall(func) - debug.sethook() collectgarbage('restart') + collectgarbage() + debug.sethook() emsg = tostring(emsg) sc.write(wr, trace_end_msg) if not err then -- cgit From 30e1cda8acb7bd8120348d1812cfd9ecd8be8528 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 6 Apr 2017 21:35:03 +0200 Subject: completion: fix segfault with ignorecase+infercase (#6452) Helped-by: Matthew Malcomson Closes #6451 --- test/functional/viml/completion_spec.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test') diff --git a/test/functional/viml/completion_spec.lua b/test/functional/viml/completion_spec.lua index 3c09d71eb7..5a37cb8f43 100644 --- a/test/functional/viml/completion_spec.lua +++ b/test/functional/viml/completion_spec.lua @@ -850,6 +850,22 @@ describe('completion', function() ]]) end) end) + + it("'ignorecase' 'infercase' CTRL-X CTRL-N #6451", function() + execute('set ignorecase infercase') + execute('edit BACKERS.md') + feed('oX') + screen:expect([[ + # Bountysource Backers | + Xnull^ | + {2:Xnull }{6: } | + {1:Xoxomoon }{6: }ryone who backed our [Bountysource fundraise| + {1:Xu }{6: }ountysource.com/teams/neovim/fundraiser)! | + {1:Xpayn }{2: } | + {1:Xinity }{2: }d URL in BACKERS.md. | + {3:-- Keyword Local completion (^N^P) }{4:match 1 of 7} | + ]]) + end) end) describe('External completion popupmenu', function() -- cgit From 654dd15bb8e82538942b1933b7f69c63d51b6608 Mon Sep 17 00:00:00 2001 From: ZyX Date: Thu, 6 Apr 2017 07:21:00 +0300 Subject: unittests: Fix testlint failure --- test/unit/eval/typval_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index c477683038..4abd51d46d 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1091,9 +1091,9 @@ describe('typval.c', function() end) end) describe('join()', function() - local function list_join(l, sep, ret) + local function list_join(l, sep, join_ret) local ga = ga_alloc() - eq(ret or OK, lib.tv_list_join(ga, l, sep)) + eq(join_ret or OK, lib.tv_list_join(ga, l, sep)) local ret = '' if ga.ga_data ~= nil then ret = ffi.string(ga.ga_data) -- cgit From 13352c00f1909d9296c5f276a3735f5e6f231b39 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 7 Apr 2017 19:46:33 +0200 Subject: win: os_get_hostname() #5416 (#6413) --- test/functional/eval/hostname_spec.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/functional/eval/hostname_spec.lua (limited to 'test') diff --git a/test/functional/eval/hostname_spec.lua b/test/functional/eval/hostname_spec.lua new file mode 100644 index 0000000000..f1867846c4 --- /dev/null +++ b/test/functional/eval/hostname_spec.lua @@ -0,0 +1,17 @@ +local helpers = require('test.functional.helpers')(after_each) +local ok = helpers.ok +local call = helpers.call +local clear = helpers.clear + +describe('hostname()', function() + before_each(clear) + + it('returns hostname string', function() + local actual = call('hostname') + ok(string.len(actual) > 1) + if call('executable', 'hostname') == 1 then + local expected = string.gsub(call('system', 'hostname'), '[\n\r]', '') + helpers.eq(expected, actual) + end + end) +end) -- cgit From a83511d1a19d6277f8258f2c5b970c936f0bc56e Mon Sep 17 00:00:00 2001 From: ZyX Date: Thu, 6 Apr 2017 08:23:33 +0300 Subject: unittests: Move checking cores to check_child_err --- test/helpers.lua | 4 ++-- test/unit/helpers.lua | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/helpers.lua b/test/helpers.lua index 3fc10e9e30..beef53b5a9 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -162,7 +162,7 @@ end local tests_skipped = 0 -local function check_cores(app) +local function check_cores(app, force) app = app or 'build/bin/nvim' local initial_path, re, exc_re local gdb_db_cmd = 'gdb -n -batch -ex "thread apply all bt full" "$_NVIM_TEST_APP" -c "$_NVIM_TEST_CORE"' @@ -188,7 +188,7 @@ local function check_cores(app) random_skip = true end -- Finding cores takes too much time on linux - if random_skip and math.random() < 0.9 then + if not force and random_skip and math.random() < 0.9 then tests_skipped = tests_skipped + 1 return end diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 6d0de5c651..4b9f185156 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -655,6 +655,7 @@ end local function check_child_err(rd) local trace = {} + local did_traceline = false while true do local traceline = sc.read(rd, hook_msglen) if #traceline ~= hook_msglen then @@ -665,6 +666,7 @@ local function check_child_err(rd) end end if traceline == trace_end_msg then + did_traceline = true break end trace[#trace + 1] = traceline @@ -680,6 +682,13 @@ local function check_child_err(rd) error = error .. trace[i] end end + if not did_traceline then + error = error .. '\nNo end of trace occurred' + end + local cc_err, cc_emsg = pcall(check_cores, Paths.test_luajit_prg, true) + if not cc_err then + error = error .. '\ncheck_cores failed: ' .. cc_emsg + end assert.just_fail(error) end if res == '+\n' then @@ -765,11 +774,6 @@ local module = { child_cleanup_once = child_cleanup_once, sc = sc, } -return function(after_each) - if after_each then - after_each(function() - check_cores(Paths.test_luajit_prg) - end) - end +return function() return module end -- cgit From dc9722326e797453094b5d82decb5369b1086139 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 8 Apr 2017 19:06:03 +0300 Subject: unittests: Do not alter p_enc in decode unit test --- test/unit/eval/decode_spec.lua | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'test') diff --git a/test/unit/eval/decode_spec.lua b/test/unit/eval/decode_spec.lua index 0b2a423cd6..6145cf6358 100644 --- a/test/unit/eval/decode_spec.lua +++ b/test/unit/eval/decode_spec.lua @@ -72,7 +72,7 @@ describe('json_decode_string()', function() end itp('does not overflow in error messages', function() - local saved_p_enc = decode.p_enc + collectgarbage('restart') check_failure(']test', 1, 'E474: No container to close: ]') check_failure('[}test', 2, 'E474: Closing list with curly bracket: }') check_failure('{]test', 2, @@ -105,10 +105,6 @@ describe('json_decode_string()', function() check_failure('"\194"test', 3, 'E474: Only UTF-8 strings allowed: \194"') check_failure('"\252\144\128\128\128\128"test', 8, 'E474: Only UTF-8 code points up to U+10FFFF are allowed to appear unescaped: \252\144\128\128\128\128"') check_failure('"test', 1, 'E474: Expected string end: "') - decode.p_enc = to_cstr('latin1') - check_failure('"\\uABCD"test', 8, - 'E474: Failed to convert string "ꯍ" from UTF-8') - decode.p_enc = saved_p_enc check_failure('-test', 1, 'E474: Missing number after minus sign: -') check_failure('-1.test', 3, 'E474: Missing number after decimal dot: -1.') check_failure('-1.0etest', 5, 'E474: Missing exponent: -1.0e') -- cgit From a40a969e9a4776f1e274dcf0e59c8f1ec1770ca0 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 8 Apr 2017 20:33:48 +0300 Subject: api: Rename _vim_id functions to nvim__id --- test/functional/lua/api_spec.lua | 108 +++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 54 deletions(-) (limited to 'test') diff --git a/test/functional/lua/api_spec.lua b/test/functional/lua/api_spec.lua index f6f65cb741..c74dfb90a0 100644 --- a/test/functional/lua/api_spec.lua +++ b/test/functional/lua/api_spec.lua @@ -73,84 +73,84 @@ describe('luaeval(vim.api.…)', function() end) it('correctly converts to API objects', function() - eq(1, funcs.luaeval('vim.api._vim_id(1)')) - eq('1', funcs.luaeval('vim.api._vim_id("1")')) - eq({1}, funcs.luaeval('vim.api._vim_id({1})')) - eq({foo=1}, funcs.luaeval('vim.api._vim_id({foo=1})')) - eq(1.5, funcs.luaeval('vim.api._vim_id(1.5)')) - eq(true, funcs.luaeval('vim.api._vim_id(true)')) - eq(false, funcs.luaeval('vim.api._vim_id(false)')) - eq(NIL, funcs.luaeval('vim.api._vim_id(nil)')) - - eq(0, eval([[type(luaeval('vim.api._vim_id(1)'))]])) - eq(1, eval([[type(luaeval('vim.api._vim_id("1")'))]])) - eq(3, eval([[type(luaeval('vim.api._vim_id({1})'))]])) - eq(4, eval([[type(luaeval('vim.api._vim_id({foo=1})'))]])) - eq(5, eval([[type(luaeval('vim.api._vim_id(1.5)'))]])) - eq(6, eval([[type(luaeval('vim.api._vim_id(true)'))]])) - eq(6, eval([[type(luaeval('vim.api._vim_id(false)'))]])) - eq(7, eval([[type(luaeval('vim.api._vim_id(nil)'))]])) - - eq({foo=1, bar={42, {{baz=true}, 5}}}, funcs.luaeval('vim.api._vim_id({foo=1, bar={42, {{baz=true}, 5}}})')) + eq(1, funcs.luaeval('vim.api.nvim__id(1)')) + eq('1', funcs.luaeval('vim.api.nvim__id("1")')) + eq({1}, funcs.luaeval('vim.api.nvim__id({1})')) + eq({foo=1}, funcs.luaeval('vim.api.nvim__id({foo=1})')) + eq(1.5, funcs.luaeval('vim.api.nvim__id(1.5)')) + eq(true, funcs.luaeval('vim.api.nvim__id(true)')) + eq(false, funcs.luaeval('vim.api.nvim__id(false)')) + eq(NIL, funcs.luaeval('vim.api.nvim__id(nil)')) + + eq(0, eval([[type(luaeval('vim.api.nvim__id(1)'))]])) + eq(1, eval([[type(luaeval('vim.api.nvim__id("1")'))]])) + eq(3, eval([[type(luaeval('vim.api.nvim__id({1})'))]])) + eq(4, eval([[type(luaeval('vim.api.nvim__id({foo=1})'))]])) + eq(5, eval([[type(luaeval('vim.api.nvim__id(1.5)'))]])) + eq(6, eval([[type(luaeval('vim.api.nvim__id(true)'))]])) + eq(6, eval([[type(luaeval('vim.api.nvim__id(false)'))]])) + eq(7, eval([[type(luaeval('vim.api.nvim__id(nil)'))]])) + + eq({foo=1, bar={42, {{baz=true}, 5}}}, funcs.luaeval('vim.api.nvim__id({foo=1, bar={42, {{baz=true}, 5}}})')) end) it('correctly converts container objects with type_idx to API objects', function() - eq(5, eval('type(luaeval("vim.api._vim_id({[vim.type_idx]=vim.types.float, [vim.val_idx]=0})"))')) - eq(4, eval([[type(luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.dictionary})'))]])) - eq(3, eval([[type(luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.array})'))]])) + eq(5, eval('type(luaeval("vim.api.nvim__id({[vim.type_idx]=vim.types.float, [vim.val_idx]=0})"))')) + eq(4, eval([[type(luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.dictionary})'))]])) + eq(3, eval([[type(luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.array})'))]])) - eq({}, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.array})')) + eq({}, funcs.luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.array})')) -- Presence of type_idx makes Vim ignore some keys - eq({42}, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) - eq({foo=2}, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) - eq(10, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) - eq({}, funcs.luaeval('vim.api._vim_id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})')) + eq({42}, funcs.luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) + eq({foo=2}, funcs.luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) + eq(10, funcs.luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) + eq({}, funcs.luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})')) end) it('correctly converts arrays with type_idx to API objects', function() - eq(3, eval([[type(luaeval('vim.api._vim_id_array({[vim.type_idx]=vim.types.array})'))]])) + eq(3, eval([[type(luaeval('vim.api.nvim__id_array({[vim.type_idx]=vim.types.array})'))]])) - eq({}, funcs.luaeval('vim.api._vim_id_array({[vim.type_idx]=vim.types.array})')) + eq({}, funcs.luaeval('vim.api.nvim__id_array({[vim.type_idx]=vim.types.array})')) - eq({42}, funcs.luaeval('vim.api._vim_id_array({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) - eq({{foo=2}}, funcs.luaeval('vim.api._vim_id_array({{[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) - eq({10}, funcs.luaeval('vim.api._vim_id_array({{[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) - eq({}, funcs.luaeval('vim.api._vim_id_array({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})')) + eq({42}, funcs.luaeval('vim.api.nvim__id_array({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) + eq({{foo=2}}, funcs.luaeval('vim.api.nvim__id_array({{[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) + eq({10}, funcs.luaeval('vim.api.nvim__id_array({{[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) + eq({}, funcs.luaeval('vim.api.nvim__id_array({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})')) - eq({}, funcs.luaeval('vim.api._vim_id_array({})')) - eq(3, eval([[type(luaeval('vim.api._vim_id_array({})'))]])) + eq({}, funcs.luaeval('vim.api.nvim__id_array({})')) + eq(3, eval([[type(luaeval('vim.api.nvim__id_array({})'))]])) end) it('correctly converts dictionaries with type_idx to API objects', function() - eq(4, eval([[type(luaeval('vim.api._vim_id_dictionary({[vim.type_idx]=vim.types.dictionary})'))]])) + eq(4, eval([[type(luaeval('vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.dictionary})'))]])) - eq({}, funcs.luaeval('vim.api._vim_id_dictionary({[vim.type_idx]=vim.types.dictionary})')) + eq({}, funcs.luaeval('vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.dictionary})')) - eq({v={42}}, funcs.luaeval('vim.api._vim_id_dictionary({v={[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) - eq({foo=2}, funcs.luaeval('vim.api._vim_id_dictionary({[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) - eq({v=10}, funcs.luaeval('vim.api._vim_id_dictionary({v={[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) - eq({v={}}, funcs.luaeval('vim.api._vim_id_dictionary({v={[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2}})')) + eq({v={42}}, funcs.luaeval('vim.api.nvim__id_dictionary({v={[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) + eq({foo=2}, funcs.luaeval('vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) + eq({v=10}, funcs.luaeval('vim.api.nvim__id_dictionary({v={[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) + eq({v={}}, funcs.luaeval('vim.api.nvim__id_dictionary({v={[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2}})')) -- If API requests dictionary, then empty table will be the one. This is not -- the case normally because empty table is an empty arrray. - eq({}, funcs.luaeval('vim.api._vim_id_dictionary({})')) - eq(4, eval([[type(luaeval('vim.api._vim_id_dictionary({})'))]])) + eq({}, funcs.luaeval('vim.api.nvim__id_dictionary({})')) + eq(4, eval([[type(luaeval('vim.api.nvim__id_dictionary({})'))]])) end) it('errors out correctly when working with API', function() -- Conversion errors eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Cannot convert given lua type', - exc_exec([[call luaeval("vim.api._vim_id(vim.api._vim_id)")]])) + exc_exec([[call luaeval("vim.api.nvim__id(vim.api.nvim__id)")]])) eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Cannot convert given lua table', - exc_exec([[call luaeval("vim.api._vim_id({1, foo=42})")]])) + exc_exec([[call luaeval("vim.api.nvim__id({1, foo=42})")]])) eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Cannot convert given lua type', - exc_exec([[call luaeval("vim.api._vim_id({42, vim.api._vim_id})")]])) + exc_exec([[call luaeval("vim.api.nvim__id({42, vim.api.nvim__id})")]])) -- Errors in number of arguments eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Expected 1 argument', - exc_exec([[call luaeval("vim.api._vim_id()")]])) + exc_exec([[call luaeval("vim.api.nvim__id()")]])) eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Expected 1 argument', - exc_exec([[call luaeval("vim.api._vim_id(1, 2)")]])) + exc_exec([[call luaeval("vim.api.nvim__id(1, 2)")]])) eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Expected 2 arguments', exc_exec([[call luaeval("vim.api.nvim_set_var(1, 2, 3)")]])) -- Error in argument types @@ -163,19 +163,19 @@ describe('luaeval(vim.api.…)', function() exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 1.5, 1, false)")]])) eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Expected lua table', - exc_exec([[call luaeval("vim.api._vim_id_float('test')")]])) + exc_exec([[call luaeval("vim.api.nvim__id_float('test')")]])) eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Unexpected type', - exc_exec([[call luaeval("vim.api._vim_id_float({[vim.type_idx]=vim.types.dictionary})")]])) + exc_exec([[call luaeval("vim.api.nvim__id_float({[vim.type_idx]=vim.types.dictionary})")]])) eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Expected lua table', - exc_exec([[call luaeval("vim.api._vim_id_array(1)")]])) + exc_exec([[call luaeval("vim.api.nvim__id_array(1)")]])) eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Unexpected type', - exc_exec([[call luaeval("vim.api._vim_id_array({[vim.type_idx]=vim.types.dictionary})")]])) + exc_exec([[call luaeval("vim.api.nvim__id_array({[vim.type_idx]=vim.types.dictionary})")]])) eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Expected lua table', - exc_exec([[call luaeval("vim.api._vim_id_dictionary(1)")]])) + exc_exec([[call luaeval("vim.api.nvim__id_dictionary(1)")]])) eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): [string ""]:1: Unexpected type', - exc_exec([[call luaeval("vim.api._vim_id_dictionary({[vim.type_idx]=vim.types.array})")]])) + exc_exec([[call luaeval("vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.array})")]])) -- TODO: check for errors with Tabpage argument -- TODO: check for errors with Window argument -- TODO: check for errors with Buffer argument -- cgit From 1ef98b34b3171452e55d656d26b96d803236bf65 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 8 Apr 2017 21:46:30 +0300 Subject: functests: Refactor 009_bufleave_autocommand_spec It was not testing anything actually: the `e yy` command simply failed because of unsaved changes, BufLeave never run thus. --- .../legacy/009_bufleave_autocommand_spec.lua | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/functional/legacy/009_bufleave_autocommand_spec.lua b/test/functional/legacy/009_bufleave_autocommand_spec.lua index 7481c639cf..e2b3dca685 100644 --- a/test/functional/legacy/009_bufleave_autocommand_spec.lua +++ b/test/functional/legacy/009_bufleave_autocommand_spec.lua @@ -1,19 +1,27 @@ -- Test for Bufleave autocommand that deletes the buffer we are about to edit. local helpers = require('test.functional.helpers')(after_each) -local clear, insert = helpers.clear, helpers.insert -local execute, expect = helpers.execute, helpers.expect + +local eq = helpers.eq +local clear = helpers.clear +local meths = helpers.meths +local expect = helpers.expect +local command = helpers.command +local exc_exec = helpers.exc_exec +local curbufmeths = helpers.curbufmeths describe('BufLeave autocommand', function() setup(clear) it('is working', function() - insert([[ - start of test file xx - end of test file xx]]) + meths.set_option('hidden', true) + curbufmeths.set_lines(0, 1, false, { + 'start of test file xx', + 'end of test file xx'}) - execute('au BufLeave * bwipe yy') - execute('e yy') + command('autocmd BufLeave * bwipeout yy') + eq('Vim(edit):E143: Autocommands unexpectedly deleted new buffer yy', + exc_exec('edit yy')) expect([[ start of test file xx -- cgit From b0731290e89dae0a2957e18cfa9ab11ad7290af8 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 8 Apr 2017 21:50:14 +0300 Subject: functests: Move test from legacy/009 to autocmd/autocmd --- test/functional/autocmd/autocmd_spec.lua | 27 +++++++++++++++++++ .../legacy/009_bufleave_autocommand_spec.lua | 30 ---------------------- 2 files changed, 27 insertions(+), 30 deletions(-) delete mode 100644 test/functional/legacy/009_bufleave_autocommand_spec.lua (limited to 'test') diff --git a/test/functional/autocmd/autocmd_spec.lua b/test/functional/autocmd/autocmd_spec.lua index c38bd75c69..9a0c5c2b0c 100644 --- a/test/functional/autocmd/autocmd_spec.lua +++ b/test/functional/autocmd/autocmd_spec.lua @@ -5,6 +5,15 @@ local command = helpers.command local eq = helpers.eq local eval = helpers.eval +local eq = helpers.eq +local eval = helpers.eval +local clear = helpers.clear +local meths = helpers.meths +local expect = helpers.expect +local command = helpers.command +local exc_exec = helpers.exc_exec +local curbufmeths = helpers.curbufmeths + describe('autocmds:', function() before_each(clear) @@ -33,4 +42,22 @@ describe('autocmds:', function() it('v:vim_did_enter is 1 after VimEnter', function() eq(1, eval('v:vim_did_enter')) end) + + describe('BufLeave autocommand', function() + it('can wipe out the buffer created by :edit which triggered autocmd', + function() + meths.set_option('hidden', true) + curbufmeths.set_lines(0, 1, false, { + 'start of test file xx', + 'end of test file xx'}) + + command('autocmd BufLeave * bwipeout yy') + eq('Vim(edit):E143: Autocommands unexpectedly deleted new buffer yy', + exc_exec('edit yy')) + + expect([[ + start of test file xx + end of test file xx]]) + end) + end) end) diff --git a/test/functional/legacy/009_bufleave_autocommand_spec.lua b/test/functional/legacy/009_bufleave_autocommand_spec.lua deleted file mode 100644 index e2b3dca685..0000000000 --- a/test/functional/legacy/009_bufleave_autocommand_spec.lua +++ /dev/null @@ -1,30 +0,0 @@ --- Test for Bufleave autocommand that deletes the buffer we are about to edit. - -local helpers = require('test.functional.helpers')(after_each) - -local eq = helpers.eq -local clear = helpers.clear -local meths = helpers.meths -local expect = helpers.expect -local command = helpers.command -local exc_exec = helpers.exc_exec -local curbufmeths = helpers.curbufmeths - -describe('BufLeave autocommand', function() - setup(clear) - - it('is working', function() - meths.set_option('hidden', true) - curbufmeths.set_lines(0, 1, false, { - 'start of test file xx', - 'end of test file xx'}) - - command('autocmd BufLeave * bwipeout yy') - eq('Vim(edit):E143: Autocommands unexpectedly deleted new buffer yy', - exc_exec('edit yy')) - - expect([[ - start of test file xx - end of test file xx]]) - end) -end) -- cgit From 47b451c52b105dd4bdb06da82a5bc7359873036c Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 8 Apr 2017 21:58:13 +0300 Subject: functests: Refactor legacy/012_directory_spec --- test/functional/legacy/012_directory_spec.lua | 40 ++++++++++++++++----------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'test') diff --git a/test/functional/legacy/012_directory_spec.lua b/test/functional/legacy/012_directory_spec.lua index cef31ae405..cec4f93737 100644 --- a/test/functional/legacy/012_directory_spec.lua +++ b/test/functional/legacy/012_directory_spec.lua @@ -3,12 +3,19 @@ -- - "./dir", in directory relative to file -- - "dir", in directory relative to current dir -local helpers = require('test.functional.helpers')(after_each) -local lfs = require('lfs') -local insert, eq = helpers.insert, helpers.eq -local neq, eval = helpers.neq, helpers.eval -local clear, execute = helpers.clear, helpers.execute -local wait, write_file = helpers.wait, helpers.write_file +local helpers = require('test.functional.helpers')(after_each) +local lfs = require('lfs') + +local eq = helpers.eq +local neq = helpers.neq +local wait = helpers.wait +local funcs = helpers.funcs +local meths = helpers.meths +local clear = helpers.clear +local insert = helpers.insert +local command = helpers.command +local write_file = helpers.write_file +local curbufmeths = helpers.curbufmeths local function ls_dir_sorted(dirname) local files = {} @@ -36,7 +43,7 @@ describe("'directory' option", function() clear() end) teardown(function() - execute('qall!') + command('qall!') helpers.rmdir('Xtest.je') helpers.rmdir('Xtest2') os.remove('Xtest1') @@ -49,21 +56,22 @@ describe("'directory' option", function() line 3 Abcdefghij end of testfile]]) - execute('set swapfile') - execute('set dir=.,~') + meths.set_option('swapfile', true) + curbufmeths.set_option('swapfile', true) + meths.set_option('directory', '.') -- sanity check: files should not exist yet. eq(nil, lfs.attributes('.Xtest1.swp')) - execute('e! Xtest1') + command('edit! Xtest1') wait() - eq('Xtest1', eval('buffer_name("%")')) + eq('Xtest1', funcs.buffer_name('%')) -- Verify that the swapfile exists. In the legacy test this was done by -- reading the output from :!ls. neq(nil, lfs.attributes('.Xtest1.swp')) - execute('set dir=./Xtest2,.,~') - execute('e Xtest1') + meths.set_option('directory', './Xtest2,.') + command('edit Xtest1') wait() -- swapfile should no longer exist in CWD. @@ -71,9 +79,9 @@ describe("'directory' option", function() eq({ "Xtest1.swp", "Xtest3" }, ls_dir_sorted("Xtest2")) - execute('set dir=Xtest.je,~') - execute('e Xtest2/Xtest3') - eq(1, eval('&swapfile')) + meths.set_option('directory', 'Xtest.je') + command('edit Xtest2/Xtest3') + eq(true, curbufmeths.get_option('swapfile')) wait() eq({ "Xtest3" }, ls_dir_sorted("Xtest2")) -- cgit From e31aab8b61565766bbd411fae38550f9ae802dd9 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 8 Apr 2017 22:00:50 +0300 Subject: functests: Refactor legacy/029_join test --- test/functional/helpers.lua | 5 ++- test/functional/legacy/029_join_spec.lua | 68 +++++++++++++++++--------------- 2 files changed, 39 insertions(+), 34 deletions(-) (limited to 'test') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 335cf3c3ff..7793a9a739 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -304,7 +304,7 @@ end -- Executes an ex-command by user input. Because nvim_input() is used, VimL -- errors will not manifest as client (lua) errors. Use command() for that. -local function execute(...) +local function feed_command(...) for _, v in ipairs({...}) do if v:sub(1, 1) ~= '/' then -- not a search command, prefix with colon @@ -565,7 +565,8 @@ local M = { insert = insert, iswin = iswin, feed = feed, - execute = execute, + feed_command = feed_command, + execute = feed_command, -- FIXME Remove eval = nvim_eval, call = nvim_call, command = nvim_command, diff --git a/test/functional/legacy/029_join_spec.lua b/test/functional/legacy/029_join_spec.lua index 7a183fcbec..460b9291bf 100644 --- a/test/functional/legacy/029_join_spec.lua +++ b/test/functional/legacy/029_join_spec.lua @@ -1,8 +1,12 @@ -- Test for joining lines with marks in them (and with 'joinspaces' set/reset) local helpers = require('test.functional.helpers')(after_each) -local feed, insert = helpers.feed, helpers.insert -local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect + +local feed = helpers.feed +local clear = helpers.clear +local insert = helpers.insert +local expect = helpers.expect +local feed_command = helpers.feed_command describe('joining lines', function() before_each(clear) @@ -46,19 +50,19 @@ describe('joining lines', function() -- Switch off 'joinspaces', then join some lines in the buffer using "J". -- Also set a few marks and record their movement when joining lines. - execute('set nojoinspaces') - execute('/firstline/') + feed_command('set nojoinspaces') + feed_command('/firstline/') feed('j"td/^$/') feed('PJjJjJjJjJjJjJjJjJjJjJjJjJjJ') feed('j05lmx2j06lmy2k4Jy3l$p`xyl$p`yy2l$p') -- Do the same with 'joinspaces' on. - execute('set joinspaces') + feed_command('set joinspaces') feed('j"tp') feed('JjJjJjJjJjJjJjJjJjJjJjJjJjJ') feed('j05lmx2j06lmy2k4Jy3l$p`xyl$p`yy2l$po') - execute('1d') + feed_command('1d') expect([[ asdfasdf. asdf @@ -129,20 +133,20 @@ describe('joining lines', function() } ]]) - execute('/^{/+1') - execute('set comments=s1:/*,mb:*,ex:*/,://') - execute('set nojoinspaces') - execute('set backspace=eol,start') + feed_command('/^{/+1') + feed_command('set comments=s1:/*,mb:*,ex:*/,://') + feed_command('set nojoinspaces') + feed_command('set backspace=eol,start') -- With 'joinspaces' switched off, join lines using both "J" and :join and -- verify that comment leaders are stripped or kept as appropriate. - execute('.,+3join') + feed_command('.,+3join') feed('j4J') - execute('.,+2join') + feed_command('.,+2join') feed('j3J') - execute('.,+2join') + feed_command('.,+2join') feed('j3J') - execute('.,+2join') + feed_command('.,+2join') feed('jj3J') expect([[ @@ -180,22 +184,22 @@ describe('joining lines', function() -- As mentioned above, we mimic the wrong initial cursor position in the old -- test by advancing one line further. - execute([[/^\d\+ this]], '+1') + feed_command([[/^\d\+ this]], '+1') -- Test with the default 'backspace' setting. feed('Avim1') feed('Avim2u') - execute('set cpo-=<') - execute('inoremap ') + feed_command('set cpo-=<') + feed_command('inoremap ') feed('Avim3') - execute('iunmap ') + feed_command('iunmap ') feed('Avim4') -- Test with 'backspace' set to the compatible setting. - execute('set backspace=') + feed_command('set backspace=') feed('A vim5A') feed('A vim6Azweiu') - execute('inoremap ') + feed_command('inoremap ') feed('A vim7') expect([[ @@ -283,29 +287,29 @@ describe('joining lines', function() } ]]) - execute('/^{/+1') - execute([[set comments=sO:*\ -,mO:*\ \ ,exO:*/]]) - execute('set comments+=s1:/*,mb:*,ex:*/,://') - execute('set comments+=s1:>#,mb:#,ex:#<,:<') - execute('set backspace=eol,start') + feed_command('/^{/+1') + feed_command([[set comments=sO:*\ -,mO:*\ \ ,exO:*/]]) + feed_command('set comments+=s1:/*,mb:*,ex:*/,://') + feed_command('set comments+=s1:>#,mb:#,ex:#<,:<') + feed_command('set backspace=eol,start') -- With 'joinspaces' on (the default setting), again join lines and verify -- that comment leaders are stripped or kept as appropriate. - execute('.,+3join') + feed_command('.,+3join') feed('j4J') - execute('.,+8join') + feed_command('.,+8join') feed('j9J') - execute('.,+2join') + feed_command('.,+2join') feed('j3J') - execute('.,+2join') + feed_command('.,+2join') feed('j3J') - execute('.,+2join') + feed_command('.,+2join') feed('jj3J') feed('j') - execute('.,+2join') + feed_command('.,+2join') feed('jj3J') feed('j') - execute('.,+5join') + feed_command('.,+5join') feed('j6J') feed('oSome code!// Make sure backspacing does not remove this comment leader.0i') -- cgit From 7766b24f3cba5eaebbdc2231bfd91a1594c8d209 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 8 Apr 2017 22:02:44 +0300 Subject: functests: Refactor legacy/018_unset_smart_indenting_spec --- test/functional/legacy/018_unset_smart_indenting_spec.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/functional/legacy/018_unset_smart_indenting_spec.lua b/test/functional/legacy/018_unset_smart_indenting_spec.lua index ba1eac02cb..94fbb283f4 100644 --- a/test/functional/legacy/018_unset_smart_indenting_spec.lua +++ b/test/functional/legacy/018_unset_smart_indenting_spec.lua @@ -1,11 +1,15 @@ -- Tests for not doing smart indenting when it isn't set. local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local execute, expect = helpers.execute, helpers.expect + +local feed = helpers.feed +local clear = helpers.clear +local insert = helpers.insert +local expect = helpers.expect +local feed_command = helpers.feed_command describe('unset smart indenting', function() - setup(clear) + before_each(clear) it('is working', function() insert([[ @@ -15,8 +19,8 @@ describe('unset smart indenting', function() test text test text]]) - execute('set nocin nosi ai') - execute('/some') + feed_command('set nocin nosi ai') + feed_command('/some') feed('2cc#test') expect([[ -- cgit From cca029bc8d06fbf2f66719e4b15fd70e26c013d4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 8 Apr 2017 22:17:39 +0300 Subject: functests: Refactor legacy/003_cindent_spec and legacy/increment_spec --- test/functional/legacy/003_cindent_spec.lua | 1134 +++++++++++++-------------- test/functional/legacy/increment_spec.lua | 6 +- 2 files changed, 570 insertions(+), 570 deletions(-) (limited to 'test') diff --git a/test/functional/legacy/003_cindent_spec.lua b/test/functional/legacy/003_cindent_spec.lua index 83388bd1eb..27835fea28 100644 --- a/test/functional/legacy/003_cindent_spec.lua +++ b/test/functional/legacy/003_cindent_spec.lua @@ -5,14 +5,14 @@ local helpers = require('test.functional.helpers')(after_each) local feed, insert = helpers.feed, helpers.insert -local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect +local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect -- Inserts text as usual, and additionally positions the cursor on line 1 and -- sets 'cindent' and tab settings. (In the original "test3.in" the modeline at -- the top of the file takes care of this.) local function insert_(content) insert(content) - execute('1', 'set cin ts=4 sw=4') + feed_command('1', 'set cin ts=4 sw=4') end describe('cindent', function() @@ -20,21 +20,21 @@ describe('cindent', function() it('1 is working', function() insert_([=[ - + /* start of AUTO matically checked vim: set ts=4 : */ { if (test) cmd1; cmd2; } - + { if (test) cmd1; else cmd2; } - + { if (test) { @@ -42,7 +42,7 @@ describe('cindent', function() cmd2; } } - + { if (test) { @@ -50,14 +50,14 @@ describe('cindent', function() else } } - + { while (this) if (test) cmd1; cmd2; } - + { while (this) if (test) @@ -65,25 +65,25 @@ describe('cindent', function() else cmd2; } - + { if (test) { cmd; } - + if (test) cmd; } - + { if (test) { cmd; } - + if (test) cmd; } - + { cmd1; for (blah) @@ -92,7 +92,7 @@ describe('cindent', function() cmd2; cmd3; } - + { cmd1; for (blah) @@ -100,7 +100,7 @@ describe('cindent', function() if (test) cmd2; cmd3; - + if (test) { cmd1; @@ -108,23 +108,23 @@ describe('cindent', function() cmd3; } } - - + + /* Test for 'cindent' do/while mixed with if/else: */ - + { do if (asdf) asdfasd; while (cond); - + do if (asdf) while (asdf) asdf; while (asdf); } - + /* Test for 'cindent' with two ) on a continuation line */ { if (asdfasdf;asldkfj asdlkfj as;ldkfj sal;d @@ -132,14 +132,14 @@ describe('cindent', function() al;sdjfka ;slkdf ) sa;ldkjfsa dlk;) line up here; } - - + + /* C++ tests: */ - + // foo() these three lines should remain in column 0 // { // } - + /* Test for continuation and unterminated lines: */ { i = 99 + 14325 + @@ -151,12 +151,12 @@ describe('cindent', function() 1234; c = 1; } - + /* testje for indent with empty line - + here */ - + { if (testing && not a joke || @@ -171,8 +171,8 @@ describe('cindent', function() line up here)) hay; } - - + + { switch (c) { @@ -191,7 +191,7 @@ describe('cindent', function() testing; } } - + { if (cond) { foo; @@ -201,7 +201,7 @@ describe('cindent', function() bar; } } - + { if (alskdfj ;alsdkfjal;skdjf (;sadlkfsa ;dlkf j;alksdfj ;alskdjf alsdkfj (asldk;fj @@ -210,7 +210,7 @@ describe('cindent', function() asdfasdf;))) asdfasdf; } - + int func(a, b) int a; @@ -223,7 +223,7 @@ describe('cindent', function() (c2 || c3) ) } - + { while (asd) { @@ -245,13 +245,13 @@ describe('cindent', function() asdf; } } - + { s = "/*"; b = ';' s = "/*"; b = ';'; a = b; } - + { switch (a) { @@ -285,7 +285,7 @@ describe('cindent', function() break; } } - + { if (!(vim_strchr(p_cpo, CPO_BUFOPTGLOB) != NULL && entering) && (bp_to->b_p_initialized || @@ -297,57 +297,57 @@ describe('cindent', function() asdf = asdf ? asdf: asdf; } - + /* Special Comments : This function has the added complexity (compared */ /* : to addtolist) of having to check for a detail */ /* : texture and add that to the list first. */ - + char *(array[100]) = { "testje", "foo", "bar", } - + enum soppie { yes = 0, no, maybe }; - + typedef enum soppie { yes = 0, no, maybe }; - + static enum { yes = 0, no, maybe } soppie; - + public static enum { yes = 0, no, maybe } soppie; - + static private enum { yes = 0, no, maybe } soppie; - + { int a, b; } - + { struct Type { @@ -360,7 +360,7 @@ describe('cindent', function() 2, "two", 3, "three" }; - + float matrix[3][3] = { { @@ -380,14 +380,14 @@ describe('cindent', function() } }; } - + { /* blah ( blah */ /* where does this go? */ - + /* blah ( blah */ cmd; - + func(arg1, /* comment */ arg2); @@ -398,7 +398,7 @@ describe('cindent', function() c; /* Hey, NOW it indents?! */ } } - + { func(arg1, arg2, @@ -406,7 +406,7 @@ describe('cindent', function() /* Hey, what am I doing here? Is this coz of the ","? */ } } - + main () { if (cond) @@ -420,7 +420,7 @@ describe('cindent', function() a = d; return; } - + { case 2: if (asdf && asdfasdf) @@ -431,42 +431,42 @@ describe('cindent', function() a = 9; case 4: x = 1; y = 2; - + label: if (asdf) here; - + label: if (asdf && asdfasdf) { } - + label: if (asdf && asdfasdf) { there; } - + label: if (asdf && asdfasdf) there; } - + { /* hello with ":set comments= cino=c5" */ - + /* hello with ":set comments= cino=" */ } - - + + { if (a < b) { a = a + 1; } else a = a + 2; - + if (a) do { testing; @@ -474,7 +474,7 @@ describe('cindent', function() a = b + 1; asdfasdf } - + { for ( int i = 0; i < 10; i++ ) @@ -482,13 +482,13 @@ describe('cindent', function() } i = 0; } - + class bob { int foo() {return 1;} int bar; } - + main() { while(1) @@ -501,32 +501,32 @@ describe('cindent', function() } misplacedline; } - + { if (clipboard.state == SELECT_DONE && ((row == clipboard.start.lnum && col >= clipboard.start.col) || row > clipboard.start.lnum)) } - + { if (1) {i += 4;} where_am_i; return 0; } - + { { } // sdf(asdf if (asdf) asd; } - + { label1: label2: } - + { int fooRet = foo(pBar1, false /*fKB*/, true /*fPTB*/, 3 /*nT*/, false /*fDF*/); @@ -538,12 +538,12 @@ describe('cindent', function() } } } - + { f1(/*comment*/); f2(); } - + { do { if (foo) { @@ -552,25 +552,25 @@ describe('cindent', function() } while (foo); foo(); // was wrong } - + int x; // no extra indent because of the ; void func() { } - + char *tab[] = {"aaa", "};", /* }; */ NULL} int indented; {} - + char *a[] = {"aaa", "bbb", "ccc", NULL}; // here - + char *tab[] = {"aaa", "xx", /* xx */}; /* asdf */ int not_indented; - + { do { switch (bla) @@ -581,23 +581,23 @@ describe('cindent', function() } while (boo); wrong; } - + int foo, bar; int foo; - + #if defined(foo) \ && defined(bar) char * xx = "asdf\ foo\ bor"; int x; - + char *foo = "asdf\ asdf\ asdf", *bar; - + void f() { #if defined(foo) \ @@ -616,19 +616,19 @@ describe('cindent', function() #endif } #endif - + int y; // comment // comment - + // comment - + { Constructor(int a, int b ) : BaseClass(a) { } } - + void foo() { char one, @@ -645,13 +645,13 @@ describe('cindent', function() kees, jan; } - + { t(int f, int d); // ) d(); } - + Constructor::Constructor(int a, int b ) : @@ -661,33 +661,33 @@ describe('cindent', function() mMember(b), { } - + Constructor::Constructor(int a, int b ) : BaseClass(a) { } - + Constructor::Constructor(int a, int b ) /*x*/ : /*x*/ BaseClass(a), member(b) { } - + A::A(int a, int b) : aa(a), bb(b), cc(c) { } - + class CAbc : public BaseClass1, protected BaseClass2 { int Test() { return FALSE; } int Test1() { return TRUE; } - + CAbc(int a, int b ) : BaseClass(a) { @@ -696,24 +696,24 @@ describe('cindent', function() case abc: asdf(); break; - + case 999: baer(); break; } } - + public: // <-- this was incoreectly indented before!! void testfall(); protected: void testfall(); }; - + class CAbc : public BaseClass1, protected BaseClass2 { }; - + static struct { int a; @@ -729,7 +729,7 @@ describe('cindent', function() 456 } }; - + static struct { int a; @@ -739,7 +739,7 @@ describe('cindent', function() { 123, 456 }, { 123, 456 } }; - + void asdf() /* ind_maxparen may cause trouble here */ { if ((0 @@ -769,17 +769,17 @@ describe('cindent', function() && 1 && 1)) break; } - + foo() { a = cond ? foo() : asdf + asdf; - + a = cond ? foo() : asdf + asdf; } - + int main(void) { if (a) @@ -788,7 +788,7 @@ describe('cindent', function() else 3; next_line_of_code(); } - + barry() { Foo::Foo (int one, @@ -796,14 +796,14 @@ describe('cindent', function() : something(4) {} } - + barry() { Foo::Foo (int one, int two) : something(4) {} } - + Constructor::Constructor(int a, int b ) : @@ -822,7 +822,7 @@ describe('cindent', function() && lele); lulu; } - + int main () { switch (c) @@ -832,13 +832,13 @@ describe('cindent', function() } } } - + main() { (void) MyFancyFuasdfadsfnction( argument); } - + main() { char foo[] = "/*"; @@ -846,7 +846,7 @@ describe('cindent', function() df */ hello } - + /* valid namespaces with normal indent */ namespace { @@ -885,7 +885,7 @@ describe('cindent', function() 22222222222222222; } } - + /* invalid namespaces use block indent */ namespace test test2 { 111111111111111111111; @@ -925,7 +925,7 @@ describe('cindent', function() } )foo"; } - + { int a[4] = { [0] = 0, @@ -934,12 +934,12 @@ describe('cindent', function() [3] = 3, }; } - + { a = b[2] + 3; } - + { if (1) /* aaaaa @@ -947,7 +947,7 @@ describe('cindent', function() */ a = 1; } - + void func() { switch (foo) @@ -974,29 +974,29 @@ describe('cindent', function() break; } } - + /* end of AUTO */ ]=]) - execute('/start of AUTO') + feed_command('/start of AUTO') feed('=/end of AUTO') expect([=[ - + /* start of AUTO matically checked vim: set ts=4 : */ { if (test) cmd1; cmd2; } - + { if (test) cmd1; else cmd2; } - + { if (test) { @@ -1004,7 +1004,7 @@ describe('cindent', function() cmd2; } } - + { if (test) { @@ -1012,14 +1012,14 @@ describe('cindent', function() else } } - + { while (this) if (test) cmd1; cmd2; } - + { while (this) if (test) @@ -1027,25 +1027,25 @@ describe('cindent', function() else cmd2; } - + { if (test) { cmd; } - + if (test) cmd; } - + { if (test) { cmd; } - + if (test) cmd; } - + { cmd1; for (blah) @@ -1054,7 +1054,7 @@ describe('cindent', function() cmd2; cmd3; } - + { cmd1; for (blah) @@ -1062,7 +1062,7 @@ describe('cindent', function() if (test) cmd2; cmd3; - + if (test) { cmd1; @@ -1070,23 +1070,23 @@ describe('cindent', function() cmd3; } } - - + + /* Test for 'cindent' do/while mixed with if/else: */ - + { do if (asdf) asdfasd; while (cond); - + do if (asdf) while (asdf) asdf; while (asdf); } - + /* Test for 'cindent' with two ) on a continuation line */ { if (asdfasdf;asldkfj asdlkfj as;ldkfj sal;d @@ -1094,14 +1094,14 @@ describe('cindent', function() al;sdjfka ;slkdf ) sa;ldkjfsa dlk;) line up here; } - - + + /* C++ tests: */ - + // foo() these three lines should remain in column 0 // { // } - + /* Test for continuation and unterminated lines: */ { i = 99 + 14325 + @@ -1113,12 +1113,12 @@ describe('cindent', function() 1234; c = 1; } - + /* testje for indent with empty line - + here */ - + { if (testing && not a joke || @@ -1133,8 +1133,8 @@ describe('cindent', function() line up here)) hay; } - - + + { switch (c) { @@ -1153,7 +1153,7 @@ describe('cindent', function() testing; } } - + { if (cond) { foo; @@ -1163,7 +1163,7 @@ describe('cindent', function() bar; } } - + { if (alskdfj ;alsdkfjal;skdjf (;sadlkfsa ;dlkf j;alksdfj ;alskdjf alsdkfj (asldk;fj @@ -1172,7 +1172,7 @@ describe('cindent', function() asdfasdf;))) asdfasdf; } - + int func(a, b) int a; @@ -1185,7 +1185,7 @@ describe('cindent', function() (c2 || c3) ) } - + { while (asd) { @@ -1207,13 +1207,13 @@ describe('cindent', function() asdf; } } - + { s = "/*"; b = ';' s = "/*"; b = ';'; a = b; } - + { switch (a) { @@ -1247,7 +1247,7 @@ describe('cindent', function() break; } } - + { if (!(vim_strchr(p_cpo, CPO_BUFOPTGLOB) != NULL && entering) && (bp_to->b_p_initialized || @@ -1259,57 +1259,57 @@ describe('cindent', function() asdf = asdf ? asdf: asdf; } - + /* Special Comments : This function has the added complexity (compared */ /* : to addtolist) of having to check for a detail */ /* : texture and add that to the list first. */ - + char *(array[100]) = { "testje", "foo", "bar", } - + enum soppie { yes = 0, no, maybe }; - + typedef enum soppie { yes = 0, no, maybe }; - + static enum { yes = 0, no, maybe } soppie; - + public static enum { yes = 0, no, maybe } soppie; - + static private enum { yes = 0, no, maybe } soppie; - + { int a, b; } - + { struct Type { @@ -1322,7 +1322,7 @@ describe('cindent', function() 2, "two", 3, "three" }; - + float matrix[3][3] = { { @@ -1342,14 +1342,14 @@ describe('cindent', function() } }; } - + { /* blah ( blah */ /* where does this go? */ - + /* blah ( blah */ cmd; - + func(arg1, /* comment */ arg2); @@ -1360,7 +1360,7 @@ describe('cindent', function() c; /* Hey, NOW it indents?! */ } } - + { func(arg1, arg2, @@ -1368,7 +1368,7 @@ describe('cindent', function() /* Hey, what am I doing here? Is this coz of the ","? */ } } - + main () { if (cond) @@ -1382,7 +1382,7 @@ describe('cindent', function() a = d; return; } - + { case 2: if (asdf && asdfasdf) @@ -1393,42 +1393,42 @@ describe('cindent', function() a = 9; case 4: x = 1; y = 2; - + label: if (asdf) here; - + label: if (asdf && asdfasdf) { } - + label: if (asdf && asdfasdf) { there; } - + label: if (asdf && asdfasdf) there; } - + { /* hello with ":set comments= cino=c5" */ - + /* hello with ":set comments= cino=" */ } - - + + { if (a < b) { a = a + 1; } else a = a + 2; - + if (a) do { testing; @@ -1436,7 +1436,7 @@ describe('cindent', function() a = b + 1; asdfasdf } - + { for ( int i = 0; i < 10; i++ ) @@ -1444,13 +1444,13 @@ describe('cindent', function() } i = 0; } - + class bob { int foo() {return 1;} int bar; } - + main() { while(1) @@ -1463,32 +1463,32 @@ describe('cindent', function() } misplacedline; } - + { if (clipboard.state == SELECT_DONE && ((row == clipboard.start.lnum && col >= clipboard.start.col) || row > clipboard.start.lnum)) } - + { if (1) {i += 4;} where_am_i; return 0; } - + { { } // sdf(asdf if (asdf) asd; } - + { label1: label2: } - + { int fooRet = foo(pBar1, false /*fKB*/, true /*fPTB*/, 3 /*nT*/, false /*fDF*/); @@ -1500,12 +1500,12 @@ describe('cindent', function() } } } - + { f1(/*comment*/); f2(); } - + { do { if (foo) { @@ -1514,25 +1514,25 @@ describe('cindent', function() } while (foo); foo(); // was wrong } - + int x; // no extra indent because of the ; void func() { } - + char *tab[] = {"aaa", "};", /* }; */ NULL} int indented; {} - + char *a[] = {"aaa", "bbb", "ccc", NULL}; // here - + char *tab[] = {"aaa", "xx", /* xx */}; /* asdf */ int not_indented; - + { do { switch (bla) @@ -1543,23 +1543,23 @@ describe('cindent', function() } while (boo); wrong; } - + int foo, bar; int foo; - + #if defined(foo) \ && defined(bar) char * xx = "asdf\ foo\ bor"; int x; - + char *foo = "asdf\ asdf\ asdf", *bar; - + void f() { #if defined(foo) \ @@ -1578,19 +1578,19 @@ describe('cindent', function() #endif } #endif - + int y; // comment // comment - + // comment - + { Constructor(int a, int b ) : BaseClass(a) { } } - + void foo() { char one, @@ -1607,13 +1607,13 @@ describe('cindent', function() kees, jan; } - + { t(int f, int d); // ) d(); } - + Constructor::Constructor(int a, int b ) : @@ -1623,33 +1623,33 @@ describe('cindent', function() mMember(b), { } - + Constructor::Constructor(int a, int b ) : BaseClass(a) { } - + Constructor::Constructor(int a, int b ) /*x*/ : /*x*/ BaseClass(a), member(b) { } - + A::A(int a, int b) : aa(a), bb(b), cc(c) { } - + class CAbc : public BaseClass1, protected BaseClass2 { int Test() { return FALSE; } int Test1() { return TRUE; } - + CAbc(int a, int b ) : BaseClass(a) { @@ -1658,24 +1658,24 @@ describe('cindent', function() case abc: asdf(); break; - + case 999: baer(); break; } } - + public: // <-- this was incoreectly indented before!! void testfall(); protected: void testfall(); }; - + class CAbc : public BaseClass1, protected BaseClass2 { }; - + static struct { int a; @@ -1691,7 +1691,7 @@ describe('cindent', function() 456 } }; - + static struct { int a; @@ -1701,7 +1701,7 @@ describe('cindent', function() { 123, 456 }, { 123, 456 } }; - + void asdf() /* ind_maxparen may cause trouble here */ { if ((0 @@ -1731,17 +1731,17 @@ describe('cindent', function() && 1 && 1)) break; } - + foo() { a = cond ? foo() : asdf + asdf; - + a = cond ? foo() : asdf + asdf; } - + int main(void) { if (a) @@ -1750,7 +1750,7 @@ describe('cindent', function() else 3; next_line_of_code(); } - + barry() { Foo::Foo (int one, @@ -1758,14 +1758,14 @@ describe('cindent', function() : something(4) {} } - + barry() { Foo::Foo (int one, int two) : something(4) {} } - + Constructor::Constructor(int a, int b ) : @@ -1784,7 +1784,7 @@ describe('cindent', function() && lele); lulu; } - + int main () { switch (c) @@ -1794,13 +1794,13 @@ describe('cindent', function() } } } - + main() { (void) MyFancyFuasdfadsfnction( argument); } - + main() { char foo[] = "/*"; @@ -1808,7 +1808,7 @@ describe('cindent', function() df */ hello } - + /* valid namespaces with normal indent */ namespace { @@ -1847,7 +1847,7 @@ describe('cindent', function() 22222222222222222; } } - + /* invalid namespaces use block indent */ namespace test test2 { 111111111111111111111; @@ -1887,7 +1887,7 @@ describe('cindent', function() } )foo"; } - + { int a[4] = { [0] = 0, @@ -1896,12 +1896,12 @@ describe('cindent', function() [3] = 3, }; } - + { a = b[2] + 3; } - + { if (1) /* aaaaa @@ -1909,7 +1909,7 @@ describe('cindent', function() */ a = 1; } - + void func() { switch (foo) @@ -1936,16 +1936,16 @@ describe('cindent', function() break; } } - + /* end of AUTO */ ]=]) end) it('2 is working', function() insert_([=[ - + { - + /* this is * a real serious important big * comment @@ -1954,14 +1954,14 @@ describe('cindent', function() } ]=]) - execute('set tw=0 wm=60 columns=80 noai fo=croq') - execute('/serious/e') + feed_command('set tw=0 wm=60 columns=80 noai fo=croq') + feed_command('/serious/e') feed('a about life, the universe, and the rest') expect([=[ - + { - + /* this is * a real serious * about life, the @@ -1976,48 +1976,48 @@ describe('cindent', function() it('3 is working', function() insert_([=[ - + { /* * Testing for comments, without 'cin' set */ - + /* * what happens here? */ - + /* the end of the comment, try inserting a line below */ - + /* how about this one */ } ]=]) - execute('set nocin') - execute('/comments') + feed_command('set nocin') + feed_command('/comments') feed('joabout life/happens') feed('jothere/below') feed('oline/this') feed('Ohello') expect([=[ - + { /* * Testing for comments, without 'cin' set */ about life - + /* * what happens here? */ there - + /* the end of the comment, try inserting a line below */ line - + /* how about hello this one */ @@ -2027,19 +2027,19 @@ describe('cindent', function() it('4 is working', function() insert_([=[ - + { var = this + that + vec[0] * vec[0] + vec[1] * vec[1] + vec2[2] * vec[2]; } ]=]) - execute('set cin') - execute('/vec2') + feed_command('set cin') + feed_command('/vec2') feed('==') expect([=[ - + { var = this + that + vec[0] * vec[0] + vec[1] * vec[1] @@ -2050,7 +2050,7 @@ describe('cindent', function() it('5 is working', function() insert_([=[ - + { asdf asdflkajds f; if (tes & ting) { @@ -2067,14 +2067,14 @@ describe('cindent', function() } ]=]) - execute('set cin') - execute('set cino=}4') - execute('/testing1') + feed_command('set cin') + feed_command('set cino=}4') + feed_command('/testing1') feed('k2==/testing2') feed('k2==') expect([=[ - + { asdf asdflkajds f; if (tes & ting) { @@ -2094,7 +2094,7 @@ describe('cindent', function() it('6 is working', function() insert_([=[ - + main ( int first_par, /* * Comment for * first par @@ -2114,17 +2114,17 @@ describe('cindent', function() * second par */ ); - + } ]=]) - execute('set cin') - execute('set cino=(0,)20') - execute('/main') + feed_command('set cin') + feed_command('set cino=(0,)20') + feed_command('/main') feed('=][') expect([=[ - + main ( int first_par, /* * Comment for * first par @@ -2144,14 +2144,14 @@ describe('cindent', function() * second par */ ); - + } ]=]) end) it('7 is working', function() insert_([=[ - + main(void) { /* Make sure that cino=X0s is not parsed like cino=Xs. */ @@ -2164,13 +2164,13 @@ describe('cindent', function() } ]=]) - execute('set cin') - execute('set cino=es,n0s') - execute('/main') + feed_command('set cin') + feed_command('set cino=es,n0s') + feed_command('/main') feed('=][') expect([=[ - + main(void) { /* Make sure that cino=X0s is not parsed like cino=Xs. */ @@ -2186,7 +2186,7 @@ describe('cindent', function() it('8 is working', function() insert_([=[ - + { do { @@ -2202,12 +2202,12 @@ describe('cindent', function() } ]=]) - execute('set cin') - execute('set cino=') + feed_command('set cin') + feed_command('set cino=') feed(']]=][') expect([=[ - + { do { @@ -2226,16 +2226,16 @@ describe('cindent', function() it('9 is working', function() insert_([=[ - + void f() { if ( k() ) { l(); - + } else { /* Start (two words) end */ m(); } - + n(); } ]=]) @@ -2243,16 +2243,16 @@ describe('cindent', function() feed(']]=][') expect([=[ - + void f() { if ( k() ) { l(); - + } else { /* Start (two words) end */ m(); } - + n(); } ]=]) @@ -2267,7 +2267,7 @@ describe('cindent', function() -- indented properly. And that's why we've had to add one explicitly. insert_([=[ { <= THIS IS THE CURLY BRACKET EXPLAINED IN THE COMMENT. - + void f() { if ( k() ) @@ -2280,12 +2280,12 @@ describe('cindent', function() } ]=]) - execute('set cino={s,e-s') + feed_command('set cino={s,e-s') feed(']]=][') expect([=[ { <= THIS IS THE CURLY BRACKET EXPLAINED IN THE COMMENT. - + void f() { if ( k() ) @@ -2301,7 +2301,7 @@ describe('cindent', function() it('11 is working', function() insert_([=[ - + void bar(void) { static array[2][2] = @@ -2309,12 +2309,12 @@ describe('cindent', function() { 1, 2 }, { 3, 4 }, } - + while (a) { foo(&a); } - + { int a; { @@ -2323,7 +2323,7 @@ describe('cindent', function() } b = a; } - + void func(void) { a = 1; @@ -2336,11 +2336,11 @@ describe('cindent', function() /* foo */ ]=]) - execute('set cino={s,fs') + feed_command('set cino={s,fs') feed(']]=/ foo') expect([=[ - + void bar(void) { static array[2][2] = @@ -2348,12 +2348,12 @@ describe('cindent', function() { 1, 2 }, { 3, 4 }, } - + while (a) { foo(&a); } - + { int a; { @@ -2362,7 +2362,7 @@ describe('cindent', function() } b = a; } - + void func(void) { a = 1; @@ -2378,7 +2378,7 @@ describe('cindent', function() it('12 is working', function() insert_([=[ - + a() { do { @@ -2390,12 +2390,12 @@ describe('cindent', function() } ]=]) - execute('set cino=') - execute('/while') + feed_command('set cino=') + feed_command('/while') feed('ohere') expect([=[ - + a() { do { @@ -2411,7 +2411,7 @@ describe('cindent', function() it('13 is working', function() insert_([=[ - + a() { label1: @@ -2420,12 +2420,12 @@ describe('cindent', function() } ]=]) - execute('set cino= com=') - execute('/comment') + feed_command('set cino= com=') + feed_command('/comment') feed('olabel2: b();label3 /* post */:/* pre */ label4:f(/*com*/);if (/*com*/)cmd();') expect([=[ - + a() { label1: @@ -2443,26 +2443,26 @@ describe('cindent', function() it('14 is working', function() insert_([=[ - + /* * A simple comment */ - + /* ** A different comment */ ]=]) - execute('set comments& comments^=s:/*,m:**,ex:*/') - execute('/simple') + feed_command('set comments& comments^=s:/*,m:**,ex:*/') + feed_command('/simple') feed('=5j') expect([=[ - + /* * A simple comment */ - + /* ** A different comment */ @@ -2471,26 +2471,26 @@ describe('cindent', function() it('15 is working', function() insert_([=[ - - + + void f() { - + /********* A comment. *********/ } ]=]) - execute('set cino=c0') - execute('set comments& comments-=s1:/* comments^=s0:/*') + feed_command('set cino=c0') + feed_command('set comments& comments-=s1:/* comments^=s0:/*') feed('2kdd]]=][') expect([=[ - + void f() { - + /********* A comment. *********/ @@ -2500,26 +2500,26 @@ describe('cindent', function() it('16 is working', function() insert_([=[ - - + + void f() { - + /********* A comment. *********/ } ]=]) - execute('set cino=c0,C1') - execute('set comments& comments-=s1:/* comments^=s0:/*') + feed_command('set cino=c0,C1') + feed_command('set comments& comments-=s1:/* comments^=s0:/*') feed('2kdd]]=][') expect([=[ - + void f() { - + /********* A comment. *********/ @@ -2529,7 +2529,7 @@ describe('cindent', function() it('17 is working', function() insert_([=[ - + void f() { c = c1 && @@ -2540,11 +2540,11 @@ describe('cindent', function() } ]=]) - execute('set cino=') + feed_command('set cino=') feed(']]=][') expect([=[ - + void f() { c = c1 && @@ -2558,8 +2558,8 @@ describe('cindent', function() it('18 is working', function() insert_([=[ - - + + void f() { c = c1 && @@ -2570,11 +2570,11 @@ describe('cindent', function() } ]=]) - execute('set cino=(s') + feed_command('set cino=(s') feed('2kdd]]=][') expect([=[ - + void f() { c = c1 && @@ -2588,8 +2588,8 @@ describe('cindent', function() it('19 is working', function() insert_([=[ - - + + void f() { c = c1 && @@ -2600,11 +2600,11 @@ describe('cindent', function() } ]=]) - execute('set cino=(s,U1 ') + feed_command('set cino=(s,U1 ') feed('2kdd]]=][') expect([=[ - + void f() { c = c1 && @@ -2618,8 +2618,8 @@ describe('cindent', function() it('20 is working', function() insert_([=[ - - + + void f() { if ( c1 @@ -2629,11 +2629,11 @@ describe('cindent', function() } ]=]) - execute('set cino=(0') + feed_command('set cino=(0') feed('2kdd]]=][') expect([=[ - + void f() { if ( c1 @@ -2646,8 +2646,8 @@ describe('cindent', function() it('21 is working', function() insert_([=[ - - + + void f() { if ( c1 @@ -2657,11 +2657,11 @@ describe('cindent', function() } ]=]) - execute('set cino=(0,w1 ') + feed_command('set cino=(0,w1 ') feed('2kdd]]=][') expect([=[ - + void f() { if ( c1 @@ -2674,8 +2674,8 @@ describe('cindent', function() it('22 is working', function() insert_([=[ - - + + void f() { c = c1 && ( @@ -2689,11 +2689,11 @@ describe('cindent', function() } ]=]) - execute('set cino=(s') + feed_command('set cino=(s') feed('2kdd]]=][') expect([=[ - + void f() { c = c1 && ( @@ -2710,8 +2710,8 @@ describe('cindent', function() it('23 is working', function() insert_([=[ - - + + void f() { c = c1 && ( @@ -2725,11 +2725,11 @@ describe('cindent', function() } ]=]) - execute('set cino=(s,m1 ') + feed_command('set cino=(s,m1 ') feed('2kdd]]=][') expect([=[ - + void f() { c = c1 && ( @@ -2746,8 +2746,8 @@ describe('cindent', function() it('24 is working', function() insert_([=[ - - + + void f() { switch (x) @@ -2762,11 +2762,11 @@ describe('cindent', function() } ]=]) - execute('set cino=b1') + feed_command('set cino=b1') feed('2kdd]]=][') expect([=[ - + void f() { switch (x) @@ -2784,8 +2784,8 @@ describe('cindent', function() it('25 is working', function() insert_([=[ - - + + void f() { invokeme( @@ -2801,11 +2801,11 @@ describe('cindent', function() } ]=]) - execute('set cino=(0,W5') + feed_command('set cino=(0,W5') feed('2kdd]]=][') expect([=[ - + void f() { invokeme( @@ -2824,8 +2824,8 @@ describe('cindent', function() it('26 is working', function() insert_([=[ - - + + void f() { statement; @@ -2834,11 +2834,11 @@ describe('cindent', function() } ]=]) - execute('set cino=/6') + feed_command('set cino=/6') feed('2kdd]]=][') expect([=[ - + void f() { statement; @@ -2850,8 +2850,8 @@ describe('cindent', function() it('27 is working', function() insert_([=[ - - + + void f() { statement; @@ -2860,12 +2860,12 @@ describe('cindent', function() } ]=]) - execute('set cino=') + feed_command('set cino=') feed('2kdd]]/comment 1/+1') feed('==') expect([=[ - + void f() { statement; @@ -2877,12 +2877,12 @@ describe('cindent', function() it('28 is working', function() insert_([=[ - - + + class CAbc { int Test() { return FALSE; } - + public: // comment void testfall(); protected: @@ -2890,15 +2890,15 @@ describe('cindent', function() }; ]=]) - execute('set cino=g0') + feed_command('set cino=g0') feed('2kdd]]=][') expect([=[ - + class CAbc { int Test() { return FALSE; } - + public: // comment void testfall(); protected: @@ -2909,8 +2909,8 @@ describe('cindent', function() it('29 is working', function() insert_([=[ - - + + class Foo : public Bar { public: @@ -2921,11 +2921,11 @@ describe('cindent', function() }; ]=]) - execute('set cino=(0,gs,hs') + feed_command('set cino=(0,gs,hs') feed('2kdd]]=][') expect([=[ - + class Foo : public Bar { public: @@ -2939,8 +2939,8 @@ describe('cindent', function() it('30 is working', function() insert_([=[ - - + + void foo() { @@ -2951,11 +2951,11 @@ describe('cindent', function() } ]=]) - execute('set cino=+20') + feed_command('set cino=+20') feed('2kdd]]=][') expect([=[ - + void foo() { @@ -2969,8 +2969,8 @@ describe('cindent', function() it('31 is working', function() insert_([=[ - - + + { averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd( asdasdf, @@ -2978,9 +2978,9 @@ describe('cindent', function() asdfadsf), asdfasdf ); - + /* those are ugly, but consequent */ - + func()->asd(asdasdf, averylongfunctionname( abc, @@ -2994,7 +2994,7 @@ describe('cindent', function() ), asdasdf ); - + averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf( abc, dec)->asdfasdfasdf( @@ -3009,11 +3009,11 @@ describe('cindent', function() } ]=]) - execute('set cino=(0,W2s') + feed_command('set cino=(0,W2s') feed('2kdd]]=][') expect([=[ - + { averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd( asdasdf, @@ -3021,9 +3021,9 @@ describe('cindent', function() asdfadsf), asdfasdf ); - + /* those are ugly, but consequent */ - + func()->asd(asdasdf, averylongfunctionname( abc, @@ -3037,7 +3037,7 @@ describe('cindent', function() ), asdasdf ); - + averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf( abc, dec)->asdfasdfasdf( @@ -3055,8 +3055,8 @@ describe('cindent', function() it('32 is working', function() insert_([=[ - - + + int main () { if (cond1 && @@ -3066,11 +3066,11 @@ describe('cindent', function() } ]=]) - execute('set cino=M1') + feed_command('set cino=M1') feed('2kdd]]=][') expect([=[ - + int main () { if (cond1 && @@ -3083,8 +3083,8 @@ describe('cindent', function() it('33 is working', function() insert_([=[ - - + + void func(int a #if defined(FOO) , int b @@ -3095,11 +3095,11 @@ describe('cindent', function() } ]=]) - execute('set cino=(0,ts') + feed_command('set cino=(0,ts') feed('2kdd2j=][') expect([=[ - + void func(int a #if defined(FOO) , int b @@ -3113,9 +3113,9 @@ describe('cindent', function() it('34 is working', function() insert_([=[ - - - + + + void func(int a #if defined(FOO) @@ -3127,12 +3127,12 @@ describe('cindent', function() } ]=]) - execute('set cino=(0') + feed_command('set cino=(0') feed('2kdd2j=][') expect([=[ - - + + void func(int a #if defined(FOO) @@ -3147,8 +3147,8 @@ describe('cindent', function() it('35 is working', function() insert_([=[ - - + + void func(void) { if(x==y) @@ -3159,7 +3159,7 @@ describe('cindent', function() } printf("Foo!\n"); } - + void func1(void) { char* tab[] = {"foo", "bar", @@ -3167,37 +3167,37 @@ describe('cindent', function() "this line used", "to be indented incorrectly"}; foo(); } - + void func2(void) { int tab[] = {1, 2, 3, 4, 5, 6}; - + printf("This line used to be indented incorrectly.\n"); } - + int foo[] #ifdef BAR - + = { 1, 2, 3, 4, 5, 6 } - + #endif ; int baz; - + void func3(void) { int tab[] = { 1, 2, 3, 4, 5, 6}; - + printf("Don't you dare indent this line incorrectly!\n"); } - + void func4(a, b, c) @@ -3206,14 +3206,14 @@ describe('cindent', function() int c; { } - + void func5( int a, int b) { } - + void func6( int a) @@ -3221,11 +3221,11 @@ describe('cindent', function() } ]=]) - execute('set cino&') + feed_command('set cino&') feed('2kdd2j=7][') expect([=[ - + void func(void) { if(x==y) @@ -3236,7 +3236,7 @@ describe('cindent', function() } printf("Foo!\n"); } - + void func1(void) { char* tab[] = {"foo", "bar", @@ -3244,37 +3244,37 @@ describe('cindent', function() "this line used", "to be indented incorrectly"}; foo(); } - + void func2(void) { int tab[] = {1, 2, 3, 4, 5, 6}; - + printf("This line used to be indented incorrectly.\n"); } - + int foo[] #ifdef BAR - + = { 1, 2, 3, 4, 5, 6 } - + #endif ; int baz; - + void func3(void) { int tab[] = { 1, 2, 3, 4, 5, 6}; - + printf("Don't you dare indent this line incorrectly!\n"); } - + void func4(a, b, c) @@ -3283,14 +3283,14 @@ describe('cindent', function() int c; { } - + void func5( int a, int b) { } - + void func6( int a) @@ -3301,17 +3301,17 @@ describe('cindent', function() it('36 is working', function() insert_([=[ - - + + void func(void) { int tab[] = { 1, 2, 3, 4, 5, 6}; - + printf("Indent this line correctly!\n"); - + switch (foo) { case bar: @@ -3328,21 +3328,21 @@ describe('cindent', function() } ]=]) - execute('set cino&') - execute('set cino+=l1') + feed_command('set cino&') + feed_command('set cino+=l1') feed('2kdd2j=][') expect([=[ - + void func(void) { int tab[] = { 1, 2, 3, 4, 5, 6}; - + printf("Indent this line correctly!\n"); - + switch (foo) { case bar: @@ -3362,8 +3362,8 @@ describe('cindent', function() it('37 is working', function() insert_([=[ - - + + void func(void) { cout << "a" @@ -3373,11 +3373,11 @@ describe('cindent', function() } ]=]) - execute('set cino&') + feed_command('set cino&') feed('2kdd2j=][') expect([=[ - + void func(void) { cout << "a" @@ -3390,7 +3390,7 @@ describe('cindent', function() it('38 is working', function() insert_([=[ - + void func(void) { /* @@ -3399,11 +3399,11 @@ describe('cindent', function() } ]=]) - execute('set com=s1:/*,m:*,ex:*/') + feed_command('set com=s1:/*,m:*,ex:*/') feed(']]3jofoo();') expect([=[ - + void func(void) { /* @@ -3416,8 +3416,8 @@ describe('cindent', function() it('39 is working', function() insert_([=[ - - + + void func(void) { for (int i = 0; i < 10; ++i) @@ -3429,11 +3429,11 @@ describe('cindent', function() } ]=]) - execute('set cino&') + feed_command('set cino&') feed('2kdd2j=][') expect([=[ - + void func(void) { for (int i = 0; i < 10; ++i) @@ -3448,8 +3448,8 @@ describe('cindent', function() it('40 is working', function() insert_([=[ - - + + void func(void) { if (condition1 @@ -3457,7 +3457,7 @@ describe('cindent', function() action(); function(argument1 && argument2); - + if (c1 && (c2 || c3)) foo; @@ -3465,7 +3465,7 @@ describe('cindent', function() (c2 || c3)) { } - + if ( c1 && ( c2 || c3)) @@ -3477,11 +3477,11 @@ describe('cindent', function() } ]=]) - execute('set cino=k2s,(0') + feed_command('set cino=k2s,(0') feed('2kdd3j=][') expect([=[ - + void func(void) { if (condition1 @@ -3489,7 +3489,7 @@ describe('cindent', function() action(); function(argument1 && argument2); - + if (c1 && (c2 || c3)) foo; @@ -3497,7 +3497,7 @@ describe('cindent', function() (c2 || c3)) { } - + if ( c1 && ( c2 || c3)) @@ -3512,8 +3512,8 @@ describe('cindent', function() it('41 is working', function() insert_([=[ - - + + void func(void) { if (condition1 @@ -3521,7 +3521,7 @@ describe('cindent', function() action(); function(argument1 && argument2); - + if (c1 && (c2 || c3)) foo; @@ -3529,7 +3529,7 @@ describe('cindent', function() (c2 || c3)) { } - + if ( c1 && ( c2 || c3)) @@ -3541,11 +3541,11 @@ describe('cindent', function() } ]=]) - execute('set cino=k2s,(s') + feed_command('set cino=k2s,(s') feed('2kdd3j=][') expect([=[ - + void func(void) { if (condition1 @@ -3553,7 +3553,7 @@ describe('cindent', function() action(); function(argument1 && argument2); - + if (c1 && (c2 || c3)) foo; @@ -3561,7 +3561,7 @@ describe('cindent', function() (c2 || c3)) { } - + if ( c1 && ( c2 || c3)) @@ -3576,8 +3576,8 @@ describe('cindent', function() it('42 is working', function() insert_([=[ - - + + void func(void) { if (condition1 @@ -3585,7 +3585,7 @@ describe('cindent', function() action(); function(argument1 && argument2); - + if (c1 && (c2 || c3)) foo; @@ -3597,7 +3597,7 @@ describe('cindent', function() && (c22345 || c3)) printf("foo\n"); - + c = c1 && ( c2 || @@ -3606,11 +3606,11 @@ describe('cindent', function() } ]=]) - execute('set cino=k2s,(s,U1') + feed_command('set cino=k2s,(s,U1') feed('2kdd3j=][') expect([=[ - + void func(void) { if (condition1 @@ -3618,7 +3618,7 @@ describe('cindent', function() action(); function(argument1 && argument2); - + if (c1 && (c2 || c3)) foo; @@ -3630,7 +3630,7 @@ describe('cindent', function() && (c22345 || c3)) printf("foo\n"); - + c = c1 && ( c2 || @@ -3642,8 +3642,8 @@ describe('cindent', function() it('43 is working', function() insert_([=[ - - + + void func(void) { if (condition1 @@ -3651,7 +3651,7 @@ describe('cindent', function() action(); function(argument1 && argument2); - + if (c1 && (c2 || c3)) foo; @@ -3663,12 +3663,12 @@ describe('cindent', function() && (c22345 || c3)) printf("foo\n"); - + if ( c1 && ( c2 || c3)) foo; - + a_long_line( argument, argument); @@ -3677,11 +3677,11 @@ describe('cindent', function() } ]=]) - execute('set cino=k2s,(0,W4') + feed_command('set cino=k2s,(0,W4') feed('2kdd3j=][') expect([=[ - + void func(void) { if (condition1 @@ -3689,7 +3689,7 @@ describe('cindent', function() action(); function(argument1 && argument2); - + if (c1 && (c2 || c3)) foo; @@ -3701,12 +3701,12 @@ describe('cindent', function() && (c22345 || c3)) printf("foo\n"); - + if ( c1 && ( c2 || c3)) foo; - + a_long_line( argument, argument); @@ -3718,8 +3718,8 @@ describe('cindent', function() it('44 is working', function() insert_([=[ - - + + void func(void) { if (condition1 @@ -3727,7 +3727,7 @@ describe('cindent', function() action(); function(argument1 && argument2); - + if (c1 && (c2 || c3)) foo; @@ -3742,11 +3742,11 @@ describe('cindent', function() } ]=]) - execute('set cino=k2s,u2') + feed_command('set cino=k2s,u2') feed('2kdd3j=][') expect([=[ - + void func(void) { if (condition1 @@ -3754,7 +3754,7 @@ describe('cindent', function() action(); function(argument1 && argument2); - + if (c1 && (c2 || c3)) foo; @@ -3772,8 +3772,8 @@ describe('cindent', function() it('45 is working', function() insert_([=[ - - + + void func(void) { if (condition1 @@ -3781,7 +3781,7 @@ describe('cindent', function() action(); function(argument1 && argument2); - + if (c1 && (c2 || c3)) foo; @@ -3793,7 +3793,7 @@ describe('cindent', function() && (c22345 || c3)) printf("foo\n"); - + if ( c1 && ( c2 || c3)) @@ -3805,11 +3805,11 @@ describe('cindent', function() } ]=]) - execute('set cino=k2s,(0,w1') + feed_command('set cino=k2s,(0,w1') feed('2kdd3j=][') expect([=[ - + void func(void) { if (condition1 @@ -3817,7 +3817,7 @@ describe('cindent', function() action(); function(argument1 && argument2); - + if (c1 && (c2 || c3)) foo; @@ -3829,7 +3829,7 @@ describe('cindent', function() && (c22345 || c3)) printf("foo\n"); - + if ( c1 && ( c2 || c3)) @@ -3844,8 +3844,8 @@ describe('cindent', function() it('46 is working', function() insert_([=[ - - + + void func(void) { if (condition1 @@ -3853,7 +3853,7 @@ describe('cindent', function() action(); function(argument1 && argument2); - + if (c1 && (c2 || c3)) foo; @@ -3864,11 +3864,11 @@ describe('cindent', function() } ]=]) - execute('set cino=k2,(s') + feed_command('set cino=k2,(s') feed('2kdd3j=][') expect([=[ - + void func(void) { if (condition1 @@ -3876,7 +3876,7 @@ describe('cindent', function() action(); function(argument1 && argument2); - + if (c1 && (c2 || c3)) foo; @@ -3890,7 +3890,7 @@ describe('cindent', function() it('47 is working', function() insert_([=[ - + NAMESPACESTART /* valid namespaces with normal indent */ namespace @@ -3930,7 +3930,7 @@ describe('cindent', function() 22222222222222222; } } - + /* invalid namespaces use block indent */ namespace test test2 { 111111111111111111111; @@ -3956,12 +3956,12 @@ describe('cindent', function() NAMESPACEEND ]=]) - execute('set cino=N-s') - execute('/^NAMESPACESTART') + feed_command('set cino=N-s') + feed_command('/^NAMESPACESTART') feed('=/^NAMESPACEEND') expect([=[ - + NAMESPACESTART /* valid namespaces with normal indent */ namespace @@ -4001,7 +4001,7 @@ describe('cindent', function() 22222222222222222; } } - + /* invalid namespaces use block indent */ namespace test test2 { 111111111111111111111; @@ -4030,7 +4030,7 @@ describe('cindent', function() it('48 is working', function() insert_([=[ - + JSSTART var bar = { foo: { @@ -4047,12 +4047,12 @@ describe('cindent', function() JSEND ]=]) - execute('set cino=j1,J1') - execute('/^JSSTART') + feed_command('set cino=j1,J1') + feed_command('/^JSSTART') feed('=/^JSEND') expect([=[ - + JSSTART var bar = { foo: { @@ -4072,7 +4072,7 @@ describe('cindent', function() it('49 is working', function() insert_([=[ - + JSSTART var foo = [ 1, @@ -4082,12 +4082,12 @@ describe('cindent', function() JSEND ]=]) - execute('set cino=j1,J1') - execute('/^JSSTART') + feed_command('set cino=j1,J1') + feed_command('/^JSSTART') feed('=/^JSEND') expect([=[ - + JSSTART var foo = [ 1, @@ -4100,7 +4100,7 @@ describe('cindent', function() it('50 is working', function() insert_([=[ - + JSSTART function bar() { var foo = [ @@ -4112,12 +4112,12 @@ describe('cindent', function() JSEND ]=]) - execute('set cino=j1,J1') - execute('/^JSSTART') + feed_command('set cino=j1,J1') + feed_command('/^JSSTART') feed('=/^JSEND') expect([=[ - + JSSTART function bar() { var foo = [ @@ -4132,10 +4132,10 @@ describe('cindent', function() it('51 is working', function() insert_([=[ - + JSSTART (function($){ - + if (cond && cond) { stmt; @@ -4143,18 +4143,18 @@ describe('cindent', function() window.something.left = (width - 50 + offset) + "px"; var class_name='myclass'; - + function private_method() { } - + var public_method={ method: function(options,args){ private_method(); } } - + function init(options) { - + $(this).data(class_name+'_public',$.extend({},{ foo: 'bar', bar: 2, @@ -4168,19 +4168,19 @@ describe('cindent', function() } }, options||{})); } - + $.fn[class_name]=function() { - + var _arguments=arguments; return this.each(function(){ - + var options=$(this).data(class_name+'_public'); if (!options) { init.apply(this,_arguments); - + } else { var method=public_method[_arguments[0]]; - + if (typeof(method)!='function') { console.log(class_name+' has no method "'+_arguments[0]+'"'); return false; @@ -4190,20 +4190,20 @@ describe('cindent', function() } }); } - + })(jQuery); JSEND ]=]) - execute('set cino=j1,J1') - execute('/^JSSTART') + feed_command('set cino=j1,J1') + feed_command('/^JSSTART') feed('=/^JSEND') expect([=[ - + JSSTART (function($){ - + if (cond && cond) { stmt; @@ -4211,18 +4211,18 @@ describe('cindent', function() window.something.left = (width - 50 + offset) + "px"; var class_name='myclass'; - + function private_method() { } - + var public_method={ method: function(options,args){ private_method(); } } - + function init(options) { - + $(this).data(class_name+'_public',$.extend({},{ foo: 'bar', bar: 2, @@ -4236,19 +4236,19 @@ describe('cindent', function() } }, options||{})); } - + $.fn[class_name]=function() { - + var _arguments=arguments; return this.each(function(){ - + var options=$(this).data(class_name+'_public'); if (!options) { init.apply(this,_arguments); - + } else { var method=public_method[_arguments[0]]; - + if (typeof(method)!='function') { console.log(class_name+' has no method "'+_arguments[0]+'"'); return false; @@ -4258,7 +4258,7 @@ describe('cindent', function() } }); } - + })(jQuery); JSEND ]=]) @@ -4266,7 +4266,7 @@ describe('cindent', function() it('52 is working', function() insert_([=[ - + JSSTART function init(options) { $(this).data(class_name+'_public',$.extend({},{ @@ -4285,12 +4285,12 @@ describe('cindent', function() JSEND ]=]) - execute('set cino=j1,J1') - execute('/^JSSTART') + feed_command('set cino=j1,J1') + feed_command('/^JSSTART') feed('=/^JSEND') expect([=[ - + JSSTART function init(options) { $(this).data(class_name+'_public',$.extend({},{ @@ -4312,7 +4312,7 @@ describe('cindent', function() it('53 is working', function() insert_([=[ - + JSSTART (function($){ function init(options) { @@ -4333,12 +4333,12 @@ describe('cindent', function() JSEND ]=]) - execute('set cino=j1,J1') - execute('/^JSSTART') + feed_command('set cino=j1,J1') + feed_command('/^JSSTART') feed('=/^JSEND') expect([=[ - + JSSTART (function($){ function init(options) { @@ -4362,7 +4362,7 @@ describe('cindent', function() it('javascript indent / vim-patch 7.4.670', function() insert_([=[ - + JSSTART // Results of JavaScript indent // 1 @@ -4379,7 +4379,7 @@ describe('cindent', function() 'i' ]; }()) - + // 2 (function(){ var a = [ @@ -4400,7 +4400,7 @@ describe('cindent', function() 'i' ]; }()) - + // 3 (function(){ var a = [ @@ -4423,7 +4423,7 @@ describe('cindent', function() 'i' ]; }()) - + // 4 { var a = [ @@ -4433,7 +4433,7 @@ describe('cindent', function() var b; var c; } - + // 5 { var a = [ @@ -4444,7 +4444,7 @@ describe('cindent', function() 3 ]; } - + // 6 { var a = [ @@ -4456,7 +4456,7 @@ describe('cindent', function() 3 ]; } - + // 7 { var a = [ @@ -4468,7 +4468,7 @@ describe('cindent', function() 3 ]; } - + // 8 var x = [ (function(){ @@ -4483,7 +4483,7 @@ describe('cindent', function() i; }) ]; - + // 9 var a = [ 0 + @@ -4502,7 +4502,7 @@ describe('cindent', function() 'h', 'i' ]; - + // 10 var a, b, @@ -4517,12 +4517,12 @@ describe('cindent', function() ]=]) -- :set cino=j1,J1,+2 - execute('set cino=j1,J1,+2') - execute('/^JSSTART') + feed_command('set cino=j1,J1,+2') + feed_command('/^JSSTART') feed('=/^JSEND') expect([=[ - + JSSTART // Results of JavaScript indent // 1 @@ -4539,7 +4539,7 @@ describe('cindent', function() 'i' ]; }()) - + // 2 (function(){ var a = [ @@ -4560,7 +4560,7 @@ describe('cindent', function() 'i' ]; }()) - + // 3 (function(){ var a = [ @@ -4583,7 +4583,7 @@ describe('cindent', function() 'i' ]; }()) - + // 4 { var a = [ @@ -4593,7 +4593,7 @@ describe('cindent', function() var b; var c; } - + // 5 { var a = [ @@ -4604,7 +4604,7 @@ describe('cindent', function() 3 ]; } - + // 6 { var a = [ @@ -4616,7 +4616,7 @@ describe('cindent', function() 3 ]; } - + // 7 { var a = [ @@ -4628,7 +4628,7 @@ describe('cindent', function() 3 ]; } - + // 8 var x = [ (function(){ @@ -4643,7 +4643,7 @@ describe('cindent', function() i; }) ]; - + // 9 var a = [ 0 + @@ -4662,7 +4662,7 @@ describe('cindent', function() 'h', 'i' ]; - + // 10 var a, b, diff --git a/test/functional/legacy/increment_spec.lua b/test/functional/legacy/increment_spec.lua index a76718ed8e..15273a4ad5 100644 --- a/test/functional/legacy/increment_spec.lua +++ b/test/functional/legacy/increment_spec.lua @@ -1,7 +1,7 @@ -- Tests for using Ctrl-A/Ctrl-X on visual selections local helpers = require('test.functional.helpers')(after_each) -local source, execute = helpers.source, helpers.execute +local source, command = helpers.source, helpers.command local call, clear = helpers.call, helpers.clear local eq, nvim = helpers.eq, helpers.meths @@ -742,14 +742,14 @@ describe('Ctrl-A/Ctrl-X on visual selections', function() local id = string.format('%02d', i) it('works on Test ' .. id, function() - execute('set nrformats&vi') -- &vi makes Vim compatible + command('set nrformats&vi') -- &vi makes Vim compatible call('Test_visual_increment_' .. id) eq({}, nvim.get_vvar('errors')) end) end it('does not drop leading zeroes', function() - execute('set nrformats&vi') -- &vi makes Vim compatible + command('set nrformats&vi') -- &vi makes Vim compatible call('Test_normal_increment_01') eq({}, nvim.get_vvar('errors')) end) -- cgit From dd93733e521d759e9e7c9303b278be28997b3e43 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 8 Apr 2017 22:33:02 +0300 Subject: functests: Refactor legacy/054_buffer_local_autocommands_spec --- .../legacy/054_buffer_local_autocommands_spec.lua | 32 ++++++++++++---------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'test') diff --git a/test/functional/legacy/054_buffer_local_autocommands_spec.lua b/test/functional/legacy/054_buffer_local_autocommands_spec.lua index 1f7c4dee6a..c8b9dfa98f 100644 --- a/test/functional/legacy/054_buffer_local_autocommands_spec.lua +++ b/test/functional/legacy/054_buffer_local_autocommands_spec.lua @@ -1,33 +1,37 @@ -- Some tests for buffer-local autocommands local helpers = require('test.functional.helpers')(after_each) -local clear, execute, eq = helpers.clear, helpers.execute, helpers.eq -local curbuf_contents = helpers.curbuf_contents + +local clear = helpers.clear +local expect = helpers.expect +local command = helpers.command + +local fname = 'Xtest-functional-legacy-054' describe('BufLeave ', function() setup(clear) it('is working', function() - execute('w! xx') - execute('au BufLeave norm Ibuffer-local autocommand') - execute('au BufLeave update') - + command('write! ' .. fname) + command('autocmd BufLeave normal! Ibuffer-local autocommand') + command('autocmd BufLeave update') + -- Here, autocommand for xx shall append a line -- But autocommand shall not apply to buffer named - execute('e somefile') + command('edit somefile') -- Here, autocommand shall be auto-deleted - execute('bwipe xx') - + command('bwipeout ' .. fname) + -- Nothing shall be written - execute('e xx') - execute('e somefile') - execute('e xx') + command('edit ' .. fname) + command('edit somefile') + command('edit ' .. fname) - eq('buffer-local autocommand', curbuf_contents()) + expect('buffer-local autocommand') end) teardown(function() - os.remove('xx') + os.remove(fname) end) end) -- cgit From 9158cc171f46ebae0a0d3d1721aa5b7d829bcba5 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 8 Apr 2017 23:48:22 +0300 Subject: functests: Refactor options/pastetoggle Note: typo, ttimeoutlen not set ever. Mention @hardenedapple --- test/functional/options/pastetoggle_spec.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/functional/options/pastetoggle_spec.lua b/test/functional/options/pastetoggle_spec.lua index e449df31f5..ec3c60fe37 100644 --- a/test/functional/options/pastetoggle_spec.lua +++ b/test/functional/options/pastetoggle_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local feed = helpers.feed -local execute = helpers.execute +local command = helpers.command local eq = helpers.eq local eval = helpers.eval local sleep = helpers.sleep @@ -10,8 +10,8 @@ local sleep = helpers.sleep describe("'pastetoggle' option", function() before_each(function() clear() - execute('set nopaste') - execute('set pastetoggle=a') + command('set nopaste') + command('set pastetoggle=a') end) it("toggles 'paste'", function() eq(eval('&paste'), 0) @@ -23,8 +23,8 @@ describe("'pastetoggle' option", function() it("multiple key 'pastetoggle' is waited for", function() eq(eval('&paste'), 0) local pastetoggle = 'lllll' - execute('set pastetoggle=' .. pastetoggle) - execute('set timeoutlen=1', 'set ttimoutlen=10000') + command('set pastetoggle=' .. pastetoggle) + command('set timeoutlen=1 ttimeoutlen=10000') feed(pastetoggle:sub(0, 2)) -- sleep() for long enough that vgetorpeek() is gotten into, but short -- enough that ttimeoutlen is not reached. -- cgit From a34408ef7f5ce25462beedff44db552f11424f3f Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 9 Apr 2017 02:11:08 +0200 Subject: test: retry(): Report number of retries. (#6475) tui_spec.lua: Retry the terminal-mode test. --- test/functional/helpers.lua | 7 ++- test/functional/terminal/tui_spec.lua | 106 ++++++++++++++++++---------------- 2 files changed, 61 insertions(+), 52 deletions(-) (limited to 'test') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 335cf3c3ff..42ed1800d3 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -246,12 +246,13 @@ local function retry(max, max_ms, fn) return result end if (max and tries >= max) or (luv.now() - start_time > timeout) then - break + if type(result) == "string" then + result = "\nretry() attempts: "..tostring(tries).."\n"..result + end + error(result) end tries = tries + 1 end - -- Do not use pcall() for the final attempt, let the failure bubble up. - return fn() end local function clear(...) diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 90051b8cd5..e56fd2db5c 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -2,9 +2,10 @@ -- as a simple way to send keys and assert screen state. local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') -local feed = thelpers.feed_data +local feed_data = thelpers.feed_data local execute = helpers.execute local nvim_dir = helpers.nvim_dir +local retry = helpers.retry if helpers.pending_win32(pending) then return end @@ -34,7 +35,7 @@ describe('tui', function() end) it('accepts basic utf-8 input', function() - feed('iabc\ntest1\ntest2') + feed_data('iabc\ntest1\ntest2') screen:expect([[ abc | test1 | @@ -44,7 +45,7 @@ describe('tui', function() {3:-- INSERT --} | {3:-- TERMINAL --} | ]]) - feed('\027') + feed_data('\027') screen:expect([[ abc | test1 | @@ -60,7 +61,7 @@ describe('tui', function() local keys = 'dfghjkl' for c in keys:gmatch('.') do execute('nnoremap ialt-'..c..'') - feed('\027'..c) + feed_data('\027'..c) end screen:expect([[ alt-j | @@ -71,7 +72,7 @@ describe('tui', function() | {3:-- TERMINAL --} | ]]) - feed('gg') + feed_data('gg') screen:expect([[ {1:a}lt-d | alt-f | @@ -90,7 +91,7 @@ describe('tui', function() -- Example: for input ALT+j: -- * Vim (Nvim prior to #3982) sets high-bit, inserts "ê". -- * Nvim (after #3982) inserts "j". - feed('i\027j') + feed_data('i\027j') screen:expect([[ j{1: } | {4:~ }| @@ -103,10 +104,10 @@ describe('tui', function() end) it('accepts ascii control sequences', function() - feed('i') - feed('\022\007') -- ctrl+g - feed('\022\022') -- ctrl+v - feed('\022\013') -- ctrl+m + feed_data('i') + feed_data('\022\007') -- ctrl+g + feed_data('\022\022') -- ctrl+v + feed_data('\022\013') -- ctrl+m screen:expect([[ {9:^G^V^M}{1: } | {4:~ }| @@ -119,7 +120,7 @@ describe('tui', function() end) it('automatically sends for bracketed paste sequences', function() - feed('i\027[200~') + feed_data('i\027[200~') screen:expect([[ {1: } | {4:~ }| @@ -129,7 +130,7 @@ describe('tui', function() {3:-- INSERT (paste) --} | {3:-- TERMINAL --} | ]]) - feed('pasted from terminal') + feed_data('pasted from terminal') screen:expect([[ pasted from terminal{1: } | {4:~ }| @@ -139,7 +140,7 @@ describe('tui', function() {3:-- INSERT (paste) --} | {3:-- TERMINAL --} | ]]) - feed('\027[201~') + feed_data('\027[201~') screen:expect([[ pasted from terminal{1: } | {4:~ }| @@ -157,7 +158,7 @@ describe('tui', function() for i = 1, 3000 do t[i] = 'item ' .. tostring(i) end - feed('i\027[200~'..table.concat(t, '\n')..'\027[201~') + feed_data('i\027[200~'..table.concat(t, '\n')..'\027[201~') screen:expect([[ item 2997 | item 2998 | @@ -180,7 +181,7 @@ describe('tui with non-tty file descriptors', function() it('can handle pipes as stdout and stderr', function() local screen = thelpers.screen_setup(0, '"'..helpers.nvim_prog ..' -u NONE -i NONE --cmd \'set noswapfile noshowcmd noruler\' --cmd \'normal iabc\' > /dev/null 2>&1 && cat testF && rm testF"') - feed(':w testF\n:q\n') + feed_data(':w testF\n:q\n') screen:expect([[ :w testF | :q | @@ -200,12 +201,13 @@ describe('tui focus event handling', function() helpers.clear() screen = thelpers.screen_setup(0, '["'..helpers.nvim_prog ..'", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile noshowcmd noruler"]') - execute('autocmd FocusGained * echo "gained"') - execute('autocmd FocusLost * echo "lost"') + feed_data(":autocmd FocusGained * echo 'gained'\n") + feed_data(":autocmd FocusLost * echo 'lost'\n") + feed_data("\034\016") -- CTRL-\ CTRL-N end) it('can handle focus events in normal mode', function() - feed('\027[I') + feed_data('\027[I') screen:expect([[ {1: } | {4:~ }| @@ -216,7 +218,7 @@ describe('tui focus event handling', function() {3:-- TERMINAL --} | ]]) - feed('\027[O') + feed_data('\027[O') screen:expect([[ {1: } | {4:~ }| @@ -230,8 +232,8 @@ describe('tui focus event handling', function() it('can handle focus events in insert mode', function() execute('set noshowmode') - feed('i') - feed('\027[I') + feed_data('i') + feed_data('\027[I') screen:expect([[ {1: } | {4:~ }| @@ -241,7 +243,7 @@ describe('tui focus event handling', function() gained | {3:-- TERMINAL --} | ]]) - feed('\027[O') + feed_data('\027[O') screen:expect([[ {1: } | {4:~ }| @@ -254,8 +256,8 @@ describe('tui focus event handling', function() end) it('can handle focus events in cmdline mode', function() - feed(':') - feed('\027[I') + feed_data(':') + feed_data('\027[I') screen:expect([[ | {4:~ }| @@ -265,7 +267,7 @@ describe('tui focus event handling', function() g{1:a}ined | {3:-- TERMINAL --} | ]]) - feed('\027[O') + feed_data('\027[O') screen:expect([[ | {4:~ }| @@ -278,30 +280,36 @@ describe('tui focus event handling', function() end) it('can handle focus events in terminal mode', function() - execute('set shell='..nvim_dir..'/shell-test') - execute('set laststatus=0') - execute('set noshowmode') - execute('terminal') - feed('\027[I') - screen:expect([[ - ready $ | - [Process exited 0]{1: } | - | - | - | - gained | - {3:-- TERMINAL --} | - ]]) - feed('\027[O') - screen:expect([[ - ready $ | - [Process exited 0]{1: } | - | - | - | - lost | - {3:-- TERMINAL --} | - ]]) + feed_data(':set shell='..nvim_dir..'/shell-test\n') + feed_data(':set noshowmode laststatus=0\n') + + retry(2, 3 * screen.timeout, function() + feed_data(':terminal\n') + feed_data('\027[I') + screen:expect([[ + ready $ | + [Process exited 0]{1: } | + | + | + | + gained | + {3:-- TERMINAL --} | + ]]) + feed_data('\027[O') + screen:expect([[ + ready $ | + [Process exited 0]{1: } | + | + | + | + lost | + {3:-- TERMINAL --} | + ]]) + + -- If retry is needed... + feed_data("\034\016") -- CTRL-\ CTRL-N + feed_data(':bwipeout!\n') + end) end) end) -- cgit 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/api/buffer_spec.lua | 6 +- test/functional/api/server_notifications_spec.lua | 8 +- test/functional/autocmd/bufenter_spec.lua | 4 +- test/functional/autocmd/textyankpost_spec.lua | 30 +- .../clipboard/clipboard_provider_spec.lua | 86 ++--- test/functional/core/job_spec.lua | 12 +- test/functional/eval/api_functions_spec.lua | 22 +- test/functional/eval/glob_spec.lua | 4 +- test/functional/eval/json_functions_spec.lua | 103 +++--- test/functional/eval/modeline_spec.lua | 4 +- test/functional/eval/msgpack_functions_spec.lua | 149 ++++----- test/functional/eval/reltime_spec.lua | 4 +- test/functional/eval/setpos_spec.lua | 9 +- test/functional/eval/special_vars_spec.lua | 6 +- test/functional/eval/system_spec.lua | 16 +- test/functional/eval/timer_spec.lua | 26 +- test/functional/ex_cmds/arg_spec.lua | 8 +- test/functional/ex_cmds/bang_filter_spec.lua | 4 +- test/functional/ex_cmds/cd_spec.lua | 54 ++-- test/functional/ex_cmds/ctrl_c_spec.lua | 4 +- test/functional/ex_cmds/drop_spec.lua | 22 +- test/functional/ex_cmds/edit_spec.lua | 9 +- test/functional/ex_cmds/encoding_spec.lua | 6 +- test/functional/ex_cmds/grep_spec.lua | 10 +- test/functional/ex_cmds/menu_spec.lua | 16 +- test/functional/ex_cmds/oldfiles_spec.lua | 22 +- test/functional/ex_cmds/recover_spec.lua | 18 +- test/functional/ex_cmds/undojoin_spec.lua | 8 +- test/functional/ex_cmds/write_spec.lua | 15 +- test/functional/ex_cmds/wundo_spec.lua | 15 +- test/functional/ex_cmds/wviminfo_spec.lua | 12 +- test/functional/helpers.lua | 1 - .../legacy/002_filename_recognition_spec.lua | 12 +- .../legacy/004_bufenter_with_modelines_spec.lua | 21 +- .../legacy/005_bufleave_delete_buffer_spec.lua | 27 +- test/functional/legacy/006_argument_list_spec.lua | 38 ++- .../legacy/007_ball_buffer_list_spec.lua | 32 +- test/functional/legacy/008_autocommands_spec.lua | 30 +- test/functional/legacy/011_autocommands_spec.lua | 60 ++-- test/functional/legacy/015_alignment_spec.lua | 30 +- .../legacy/019_smarttab_expandtab_spec.lua | 18 +- .../legacy/020_blockwise_visual_spec.lua | 13 +- test/functional/legacy/021_control_wi_spec.lua | 11 +- test/functional/legacy/022_line_ending_spec.lua | 6 +- test/functional/legacy/023_edit_arguments_spec.lua | 34 +- .../functional/legacy/025_jump_tag_hidden_spec.lua | 24 +- .../legacy/026_execute_while_if_spec.lua | 6 +- test/functional/legacy/028_source_ctrl_v_spec.lua | 6 +- test/functional/legacy/030_fileformats_spec.lua | 343 ++++++++++---------- test/functional/legacy/031_close_commands_spec.lua | 66 ++-- test/functional/legacy/033_lisp_indent_spec.lua | 27 +- test/functional/legacy/034_user_function_spec.lua | 22 +- .../legacy/035_increment_and_decrement_spec.lua | 12 +- .../legacy/036_regexp_character_classes_spec.lua | 6 +- .../functional/legacy/038_virtual_replace_spec.lua | 12 +- .../legacy/039_visual_block_mode_commands_spec.lua | 24 +- .../041_writing_and_reading_hundred_kbyte_spec.lua | 25 +- test/functional/legacy/043_magic_settings_spec.lua | 21 +- .../legacy/044_099_regexp_multibyte_magic_spec.lua | 34 +- test/functional/legacy/045_folding_spec.lua | 84 ++--- test/functional/legacy/051_highlight_spec.lua | 75 +++-- .../legacy/055_list_and_dict_types_spec.lua | 146 ++++----- test/functional/legacy/057_sort_spec.lua | 147 +++++---- .../legacy/059_utf8_spell_checking_spec.lua | 242 +++++++------- test/functional/legacy/061_undo_tree_spec.lua | 46 +-- test/functional/legacy/062_tab_pages_spec.lua | 70 ++-- .../legacy/063_match_and_matchadd_spec.lua | 90 +++--- .../legacy/065_float_and_logic_operators_spec.lua | 6 +- .../legacy/066_visual_block_tab_spec.lua | 16 +- test/functional/legacy/067_augroup_exists_spec.lua | 42 +-- .../functional/legacy/068_text_formatting_spec.lua | 154 ++++----- .../legacy/069_multibyte_formatting_spec.lua | 44 +-- test/functional/legacy/072_undo_file_spec.lua | 48 +-- .../legacy/074_global_var_in_viminfo_spec.lua | 12 +- test/functional/legacy/075_maparg_spec.lua | 46 +-- test/functional/legacy/077_mf_hash_grow_spec.lua | 18 +- test/functional/legacy/080_substitute_spec.lua | 28 +- .../legacy/081_coptions_movement_spec.lua | 8 +- .../legacy/082_string_comparison_spec.lua | 10 +- test/functional/legacy/084_curswant_spec.lua | 4 +- test/functional/legacy/088_conceal_tabs_spec.lua | 20 +- .../legacy/092_mksession_cursor_cols_utf8_spec.lua | 22 +- .../093_mksession_cursor_cols_latin1_spec.lua | 22 +- .../legacy/094_visual_mode_operators_spec.lua | 86 ++--- test/functional/legacy/096_location_list_spec.lua | 138 ++++---- test/functional/legacy/097_glob_path_spec.lua | 28 +- test/functional/legacy/101_hlsearch_spec.lua | 74 ++--- test/functional/legacy/102_fnameescape_spec.lua | 12 +- test/functional/legacy/104_let_assignment_spec.lua | 6 +- test/functional/legacy/106_errorformat_spec.lua | 16 +- .../legacy/107_adjust_window_and_contents_spec.lua | 56 ++-- .../legacy/108_backtrace_debug_commands_spec.lua | 48 +-- test/functional/legacy/arglist_spec.lua | 250 +++++++-------- test/functional/legacy/assert_spec.lua | 8 +- test/functional/legacy/autochdir_spec.lua | 8 +- test/functional/legacy/autocmd_option_spec.lua | 74 ++--- test/functional/legacy/autoformat_join_spec.lua | 15 +- test/functional/legacy/breakindent_spec.lua | 254 +++++++-------- test/functional/legacy/changelist_spec.lua | 10 +- test/functional/legacy/charsearch_spec.lua | 18 +- test/functional/legacy/close_count_spec.lua | 206 ++++++------ test/functional/legacy/command_count_spec.lua | 60 ++-- test/functional/legacy/comparators_spec.lua | 4 +- test/functional/legacy/delete_spec.lua | 30 +- test/functional/legacy/eval_spec.lua | 356 +++++++++++---------- test/functional/legacy/fixeol_spec.lua | 40 +-- test/functional/legacy/function_sort_spec.lua | 26 +- test/functional/legacy/getcwd_spec.lua | 46 +-- test/functional/legacy/glob2regpat_spec.lua | 7 +- test/functional/legacy/insertcount_spec.lua | 4 +- test/functional/legacy/join_spec.lua | 14 +- test/functional/legacy/lispwords_spec.lua | 4 +- test/functional/legacy/listchars_spec.lua | 40 +-- test/functional/legacy/listlbr_spec.lua | 178 +++++------ test/functional/legacy/mapping_spec.lua | 62 ++-- test/functional/legacy/marks_spec.lua | 12 +- test/functional/legacy/nested_function_spec.lua | 4 +- test/functional/legacy/packadd_spec.lua | 14 +- test/functional/legacy/search_mbyte_spec.lua | 16 +- test/functional/legacy/searchpos_spec.lua | 4 +- test/functional/legacy/set_spec.lua | 18 +- test/functional/legacy/signs_spec.lua | 14 +- test/functional/legacy/textobjects_spec.lua | 10 +- test/functional/legacy/utf8_spec.lua | 18 +- test/functional/legacy/wordcount_spec.lua | 87 ++--- test/functional/legacy/writefile_spec.lua | 24 +- test/functional/normal/count_spec.lua | 4 +- test/functional/normal/fold_spec.lua | 34 +- test/functional/normal/put_spec.lua | 24 +- test/functional/normal/undo_spec.lua | 4 +- test/functional/options/defaults_spec.lua | 4 +- test/functional/options/shortmess_spec.lua | 8 +- test/functional/plugin/health_spec.lua | 10 +- test/functional/plugin/matchparen_spec.lua | 4 +- test/functional/terminal/buffer_spec.lua | 30 +- test/functional/terminal/cursor_spec.lua | 4 +- test/functional/terminal/ex_terminal_spec.lua | 18 +- test/functional/terminal/helpers.lua | 8 +- test/functional/terminal/highlight_spec.lua | 16 +- test/functional/terminal/scrollback_spec.lua | 6 +- test/functional/terminal/tui_spec.lua | 20 +- test/functional/terminal/window_split_tab_spec.lua | 8 +- test/functional/ui/bufhl_spec.lua | 8 +- test/functional/ui/highlight_spec.lua | 138 ++++---- test/functional/ui/inccommand_spec.lua | 130 ++++---- test/functional/ui/input_spec.lua | 6 +- test/functional/ui/mouse_spec.lua | 72 ++--- test/functional/ui/quickfix_spec.lua | 34 +- test/functional/ui/screen_basic_spec.lua | 46 +-- test/functional/ui/searchhl_spec.lua | 34 +- test/functional/ui/sign_spec.lua | 12 +- test/functional/ui/syntax_conceal_spec.lua | 44 +-- test/functional/ui/wildmode_spec.lua | 14 +- test/functional/viml/completion_spec.lua | 52 +-- test/functional/viml/lang_spec.lua | 5 +- 155 files changed, 3184 insertions(+), 3085 deletions(-) (limited to 'test') diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index 552e3a8564..c3002618b0 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -5,7 +5,7 @@ local curbufmeths, ok = helpers.curbufmeths, helpers.ok local funcs = helpers.funcs local request = helpers.request local exc_exec = helpers.exc_exec -local execute = helpers.execute +local feed_command = helpers.feed_command local insert = helpers.insert local NIL = helpers.NIL local meth_pcall = helpers.meth_pcall @@ -246,7 +246,7 @@ describe('api/buf', function() end) it("set_line on alternate buffer does not access invalid line (E315)", function() - execute('set hidden') + feed_command('set hidden') insert('Initial file') command('enew') insert([[ @@ -257,7 +257,7 @@ describe('api/buf', function() The Other Buffer]]) - execute('$') + feed_command('$') local retval = exc_exec("call nvim_buf_set_lines(1, 0, 1, v:false, ['test'])") eq(0, retval) end) diff --git a/test/functional/api/server_notifications_spec.lua b/test/functional/api/server_notifications_spec.lua index 78639d7ed7..9d7cfb9b78 100644 --- a/test/functional/api/server_notifications_spec.lua +++ b/test/functional/api/server_notifications_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) -local eq, clear, eval, execute, nvim, next_message = - helpers.eq, helpers.clear, helpers.eval, helpers.execute, helpers.nvim, +local eq, clear, eval, command, nvim, next_message = + helpers.eq, helpers.clear, helpers.eval, helpers.command, helpers.nvim, helpers.next_message local meths = helpers.meths @@ -16,8 +16,8 @@ describe('notify', function() it('sends the notification/args to the corresponding channel', function() eval('rpcnotify('..channel..', "test-event", 1, 2, 3)') eq({'notification', 'test-event', {1, 2, 3}}, next_message()) - execute('au FileType lua call rpcnotify('..channel..', "lua!")') - execute('set filetype=lua') + command('au FileType lua call rpcnotify('..channel..', "lua!")') + command('set filetype=lua') eq({'notification', 'lua!', {}}, next_message()) end) end) diff --git a/test/functional/autocmd/bufenter_spec.lua b/test/functional/autocmd/bufenter_spec.lua index ccbcdf5c5e..2758be0b13 100644 --- a/test/functional/autocmd/bufenter_spec.lua +++ b/test/functional/autocmd/bufenter_spec.lua @@ -4,7 +4,7 @@ local clear = helpers.clear local command = helpers.command local eq = helpers.eq local eval = helpers.eval -local execute = helpers.execute +local command = helpers.command local request = helpers.request local source = helpers.source @@ -28,7 +28,7 @@ describe('autocmd BufEnter', function() endtry endfunction ]]) - execute("call Test()") + command("call Test()") eq(1, eval("exists('g:dir_bufenter')")) -- Did BufEnter for the directory. eq(2, eval("bufnr('%')")) -- Switched to the dir buffer. end) diff --git a/test/functional/autocmd/textyankpost_spec.lua b/test/functional/autocmd/textyankpost_spec.lua index bd5f1912c5..a34d7ad53c 100644 --- a/test/functional/autocmd/textyankpost_spec.lua +++ b/test/functional/autocmd/textyankpost_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq -local feed, execute, expect, command = helpers.feed, helpers.execute, helpers.expect, helpers.command +local feed, command, expect, command = helpers.feed, helpers.command, helpers.expect, helpers.command local curbufmeths, funcs, neq = helpers.curbufmeths, helpers.funcs, helpers.neq describe('TextYankPost', function() @@ -8,11 +8,11 @@ describe('TextYankPost', function() clear() -- emulate the clipboard so system clipboard isn't affected - execute('let &rtp = "test/functional/fixtures,".&rtp') + command('let &rtp = "test/functional/fixtures,".&rtp') - execute('let g:count = 0') - execute('autocmd TextYankPost * let g:event = copy(v:event)') - execute('autocmd TextYankPost * let g:count += 1') + command('let g:count = 0') + command('autocmd TextYankPost * let g:event = copy(v:event)') + command('autocmd TextYankPost * let g:count += 1') curbufmeths.set_lines(0, -1, true, { 'foo\0bar', @@ -61,27 +61,27 @@ describe('TextYankPost', function() regtype = 'V' }, eval('g:event')) - execute('set debug=msg') + command('set debug=msg') -- the regcontents should not be changed without copy. local status, err = pcall(command,'call extend(g:event.regcontents, ["more text"])') eq(status,false) neq(nil, string.find(err, ':E742:')) -- can't mutate keys inside the autocommand - execute('autocmd! TextYankPost * let v:event.regcontents = 0') + command('autocmd! TextYankPost * let v:event.regcontents = 0') status, err = pcall(command,'normal yy') eq(status,false) neq(nil, string.find(err, ':E46:')) -- can't add keys inside the autocommand - execute('autocmd! TextYankPost * let v:event.mykey = 0') + command('autocmd! TextYankPost * let v:event.mykey = 0') status, err = pcall(command,'normal yy') eq(status,false) neq(nil, string.find(err, ':E742:')) end) it('is not invoked recursively', function() - execute('autocmd TextYankPost * normal "+yy') + command('autocmd TextYankPost * normal "+yy') feed('yy') eq({ operator = 'y', @@ -134,7 +134,7 @@ describe('TextYankPost', function() feed('"_yy') eq(0, eval('g:count')) - execute('delete _') + command('delete _') eq(0, eval('g:count')) end) @@ -155,7 +155,7 @@ describe('TextYankPost', function() regtype = 'V' }, eval('g:event')) - execute("set clipboard=unnamed") + command("set clipboard=unnamed") -- regname still shows the name the user requested feed('yy') @@ -176,7 +176,7 @@ describe('TextYankPost', function() end) it('works with Ex commands', function() - execute('1delete +') + command('1delete +') eq({ operator = 'd', regcontents = { 'foo\nbar' }, @@ -185,7 +185,7 @@ describe('TextYankPost', function() }, eval('g:event')) eq(1, eval('g:count')) - execute('yank') + command('yank') eq({ operator = 'y', regcontents = { 'baz text' }, @@ -194,7 +194,7 @@ describe('TextYankPost', function() }, eval('g:event')) eq(2, eval('g:count')) - execute('normal yw') + command('normal yw') eq({ operator = 'y', regcontents = { 'baz ' }, @@ -203,7 +203,7 @@ describe('TextYankPost', function() }, eval('g:event')) eq(3, eval('g:count')) - execute('normal! dd') + command('normal! dd') eq({ operator = 'd', regcontents = { 'baz text' }, diff --git a/test/functional/clipboard/clipboard_provider_spec.lua b/test/functional/clipboard/clipboard_provider_spec.lua index d969d4a487..eb2eeee0da 100644 --- a/test/functional/clipboard/clipboard_provider_spec.lua +++ b/test/functional/clipboard/clipboard_provider_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local execute, expect, eq, eval = helpers.execute, helpers.expect, helpers.eq, helpers.eval +local feed_command, expect, eq, eval = helpers.feed_command, helpers.expect, helpers.eq, helpers.eval local function basic_register_test(noblock) insert("some words") @@ -95,7 +95,7 @@ describe('clipboard usage', function() before_each(function() reset() - execute('call getreg("*")') -- force load of provider + feed_command('call getreg("*")') -- force load of provider end) it('has independent "* and unnamed registers per default', function() @@ -140,8 +140,8 @@ describe('clipboard usage', function() end) it('support autodectection of regtype', function() - execute("let g:test_clip['*'] = ['linewise stuff','']") - execute("let g:test_clip['+'] = ['charwise','stuff']") + feed_command("let g:test_clip['*'] = ['linewise stuff','']") + feed_command("let g:test_clip['+'] = ['charwise','stuff']") eq("V", eval("getregtype('*')")) eq("v", eval("getregtype('+')")) insert("just some text") @@ -156,7 +156,7 @@ describe('clipboard usage', function() insert([[ much text]]) - execute("let g:test_clip['*'] = [['very','block'],'b']") + feed_command("let g:test_clip['*'] = [['very','block'],'b']") feed('gg"*P') expect([[ very much @@ -170,15 +170,15 @@ describe('clipboard usage', function() end) it('supports setreg', function() - execute('call setreg("*", "setted\\ntext", "c")') - execute('call setreg("+", "explicitly\\nlines", "l")') + feed_command('call setreg("*", "setted\\ntext", "c")') + feed_command('call setreg("+", "explicitly\\nlines", "l")') feed('"+P"*p') expect([[ esetted textxplicitly lines ]]) - execute('call setreg("+", "blocky\\nindeed", "b")') + feed_command('call setreg("+", "blocky\\nindeed", "b")') feed('"+p') expect([[ esblockyetted @@ -188,13 +188,13 @@ describe('clipboard usage', function() end) it('supports let @+ (issue #1427)', function() - execute("let @+ = 'some'") - execute("let @* = ' other stuff'") + feed_command("let @+ = 'some'") + feed_command("let @* = ' other stuff'") eq({{'some'}, 'v'}, eval("g:test_clip['+']")) eq({{' other stuff'}, 'v'}, eval("g:test_clip['*']")) feed('"+p"*p') expect('some other stuff') - execute("let @+ .= ' more'") + feed_command("let @+ .= ' more'") feed('dd"+p') expect('some more') end) @@ -202,7 +202,7 @@ describe('clipboard usage', function() it('pastes unnamed register if the provider fails', function() insert('the text') feed('yy') - execute("let g:cliperror = 1") + feed_command("let g:cliperror = 1") feed('"*p') expect([[ the text @@ -214,7 +214,7 @@ describe('clipboard usage', function() -- the basic behavior of unnamed register should be the same -- even when handled by clipboard provider before_each(function() - execute('set clipboard=unnamed') + feed_command('set clipboard=unnamed') end) it('works', function() @@ -222,7 +222,7 @@ describe('clipboard usage', function() end) it('works with pure text clipboard', function() - execute("let g:cliplossy = 1") + feed_command("let g:cliplossy = 1") -- expect failure for block mode basic_register_test(true) end) @@ -237,7 +237,7 @@ describe('clipboard usage', function() -- "+ shouldn't have changed eq({''}, eval("g:test_clip['+']")) - execute("let g:test_clip['*'] = ['linewise stuff','']") + feed_command("let g:test_clip['*'] = ['linewise stuff','']") feed('p') expect([[ words @@ -247,7 +247,7 @@ describe('clipboard usage', function() it('does not clobber "0 when pasting', function() insert('a line') feed('yy') - execute("let g:test_clip['*'] = ['b line','']") + feed_command("let g:test_clip['*'] = ['b line','']") feed('"0pp"0p') expect([[ a line @@ -258,20 +258,20 @@ describe('clipboard usage', function() it('supports v:register and getreg() without parameters', function() eq('*', eval('v:register')) - execute("let g:test_clip['*'] = [['some block',''], 'b']") + feed_command("let g:test_clip['*'] = [['some block',''], 'b']") eq('some block', eval('getreg()')) eq('\02210', eval('getregtype()')) end) it('yanks visual selection when pasting', function() insert("indeed visual") - execute("let g:test_clip['*'] = [['clipboard'], 'c']") + feed_command("let g:test_clip['*'] = [['clipboard'], 'c']") feed("viwp") eq({{'visual'}, 'v'}, eval("g:test_clip['*']")) expect("indeed clipboard") -- explicit "* should do the same - execute("let g:test_clip['*'] = [['star'], 'c']") + feed_command("let g:test_clip['*'] = [['star'], 'c']") feed('viw"*p') eq({{'clipboard'}, 'v'}, eval("g:test_clip['*']")) expect("indeed star") @@ -280,7 +280,7 @@ describe('clipboard usage', function() it('unamed operations work even if the provider fails', function() insert('the text') feed('yy') - execute("let g:cliperror = 1") + feed_command("let g:cliperror = 1") feed('p') expect([[ the text @@ -294,11 +294,11 @@ describe('clipboard usage', function() match text ]]) - execute('g/match/d') + feed_command('g/match/d') eq('match\n', eval('getreg("*")')) feed('u') eval('setreg("*", "---")') - execute('g/test/') + feed_command('g/test/') feed('') eq('---', eval('getreg("*")')) end) @@ -307,7 +307,7 @@ describe('clipboard usage', function() describe('with clipboard=unnamedplus', function() before_each(function() - execute('set clipboard=unnamedplus') + feed_command('set clipboard=unnamedplus') end) it('links the "+ and unnamed registers', function() @@ -320,13 +320,13 @@ describe('clipboard usage', function() -- "* shouldn't have changed eq({''}, eval("g:test_clip['*']")) - execute("let g:test_clip['+'] = ['three']") + feed_command("let g:test_clip['+'] = ['three']") feed('p') expect('twothree') end) it('and unnamed, yanks to both', function() - execute('set clipboard=unnamedplus,unnamed') + feed_command('set clipboard=unnamedplus,unnamed') insert([[ really unnamed text]]) @@ -340,8 +340,8 @@ describe('clipboard usage', function() -- unnamedplus takes predecence when pasting eq('+', eval('v:register')) - execute("let g:test_clip['+'] = ['the plus','']") - execute("let g:test_clip['*'] = ['the star','']") + feed_command("let g:test_clip['+'] = ['the plus','']") + feed_command("let g:test_clip['*'] = ['the star','']") feed("p") expect([[ text @@ -356,11 +356,11 @@ describe('clipboard usage', function() match text ]]) - execute('g/match/d') + feed_command('g/match/d') eq('match\n', eval('getreg("+")')) feed('u') eval('setreg("+", "---")') - execute('g/test/') + feed_command('g/test/') feed('') eq('---', eval('getreg("+")')) end) @@ -375,13 +375,13 @@ describe('clipboard usage', function() it('supports :put', function() insert("a line") - execute("let g:test_clip['*'] = ['some text']") - execute("let g:test_clip['+'] = ['more', 'text', '']") - execute(":put *") + feed_command("let g:test_clip['*'] = ['some text']") + feed_command("let g:test_clip['+'] = ['more', 'text', '']") + feed_command(":put *") expect([[ a line some text]]) - execute(":put +") + feed_command(":put +") expect([[ a line some text @@ -392,9 +392,9 @@ describe('clipboard usage', function() it('supports "+ and "* in registers', function() local screen = Screen.new(60, 10) screen:attach() - execute("let g:test_clip['*'] = ['some', 'star data','']") - execute("let g:test_clip['+'] = ['such', 'plus', 'stuff']") - execute("registers") + feed_command("let g:test_clip['*'] = ['some', 'star data','']") + feed_command("let g:test_clip['+'] = ['such', 'plus', 'stuff']") + feed_command("registers") screen:expect([[ ~ | ~ | @@ -418,17 +418,17 @@ describe('clipboard usage', function() insert('s/s/t/') feed('gg"*y$:*') expect('t/s/t/') - execute("let g:test_clip['*'] = ['s/s/u']") + feed_command("let g:test_clip['*'] = ['s/s/u']") feed(':*') expect('t/u/t/') end) it('supports :redir @*>', function() - execute("let g:test_clip['*'] = ['stuff']") - execute('redir @*>') + feed_command("let g:test_clip['*'] = ['stuff']") + feed_command('redir @*>') -- it is made empty eq({{''}, 'v'}, eval("g:test_clip['*']")) - execute('let g:test = doesnotexist') + feed_command('let g:test = doesnotexist') feed('') eq({{ '', @@ -436,7 +436,7 @@ describe('clipboard usage', function() 'E121: Undefined variable: doesnotexist', 'E15: Invalid expression: doesnotexist', }, 'v'}, eval("g:test_clip['*']")) - execute(':echo "Howdy!"') + feed_command(':echo "Howdy!"') eq({{ '', '', @@ -448,7 +448,7 @@ describe('clipboard usage', function() end) it('handles middleclick correctly', function() - execute('set mouse=a') + feed_command('set mouse=a') local screen = Screen.new(30, 5) screen:attach() @@ -471,7 +471,7 @@ describe('clipboard usage', function() the a target]]) -- on error, fall back to unnamed register - execute("let g:cliperror = 1") + feed_command("let g:cliperror = 1") feed('<6,1>') expect([[ the source diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index 9ee91f2fe9..b98169b067 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, eq, eval, exc_exec, execute, feed, insert, neq, next_msg, nvim, +local clear, eq, eval, exc_exec, feed_command, feed, insert, neq, next_msg, nvim, nvim_dir, ok, source, write_file, mkdir, rmdir = helpers.clear, - helpers.eq, helpers.eval, helpers.exc_exec, helpers.execute, helpers.feed, + helpers.eq, helpers.eval, helpers.exc_exec, helpers.feed_command, helpers.feed, helpers.insert, helpers.neq, helpers.next_message, helpers.nvim, helpers.nvim_dir, helpers.ok, helpers.source, helpers.write_file, helpers.mkdir, helpers.rmdir @@ -94,7 +94,7 @@ describe('jobs', function() it('returns 0 when it fails to start', function() eq("", eval("v:errmsg")) - execute("let g:test_jobid = jobstart([])") + feed_command("let g:test_jobid = jobstart([])") eq(0, eval("g:test_jobid")) eq("E474:", string.match(eval("v:errmsg"), "E%d*:")) end) @@ -470,7 +470,7 @@ describe('jobs', function() end) it('will return -2 when interrupted', function() - execute('call rpcnotify(g:channel, "ready") | '.. + feed_command('call rpcnotify(g:channel, "ready") | '.. 'call rpcnotify(g:channel, "wait", '.. 'jobwait([jobstart("sleep 10; exit 55")]))') eq({'notification', 'ready', {}}, next_msg()) @@ -514,7 +514,7 @@ describe('jobs', function() \ ]) endfunction ]]) - execute('call Run()') + feed_command('call Run()') local r for i = 10, 1, -1 do r = next_msg() @@ -668,7 +668,7 @@ describe("pty process teardown", function() it("does not prevent/delay exit. #4798 #4900", function() if helpers.pending_win32(pending) then return end -- Use a nested nvim (in :term) to test without --headless. - execute(":terminal '"..helpers.nvim_prog + feed_command(":terminal '"..helpers.nvim_prog -- Use :term again in the _nested_ nvim to get a PTY process. -- Use `sleep` to simulate a long-running child of the PTY. .."' +terminal +'!(sleep 300 &)' +qa") diff --git a/test/functional/eval/api_functions_spec.lua b/test/functional/eval/api_functions_spec.lua index 21dd228145..7f6f53d226 100644 --- a/test/functional/eval/api_functions_spec.lua +++ b/test/functional/eval/api_functions_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local lfs = require('lfs') -local neq, eq, execute = helpers.neq, helpers.eq, helpers.execute +local neq, eq, command = helpers.neq, helpers.eq, helpers.command local clear, curbufmeths = helpers.clear, helpers.curbufmeths local exc_exec, expect, eval = helpers.exc_exec, helpers.expect, helpers.eval local insert = helpers.insert @@ -10,17 +10,17 @@ describe('api functions', function() before_each(clear) it("work", function() - execute("call nvim_command('let g:test = 1')") + command("call nvim_command('let g:test = 1')") eq(1, eval("nvim_get_var('test')")) local buf = eval("nvim_get_current_buf()") - execute("call nvim_buf_set_lines("..buf..", 0, -1, v:true, ['aa', 'bb'])") + command("call nvim_buf_set_lines("..buf..", 0, -1, v:true, ['aa', 'bb'])") expect([[ aa bb]]) - execute("call nvim_win_set_cursor(0, [1, 1])") - execute("call nvim_input('ax')") + command("call nvim_win_set_cursor(0, [1, 1])") + command("call nvim_input('ax')") expect([[ aax bb]]) @@ -57,7 +57,7 @@ describe('api functions', function() eq(bnr, bhnd) eq(wid, whnd) - execute("new") -- creates new buffer and new window + command("new") -- creates new buffer and new window local bnr2 = eval("bufnr('')") local bhnd2 = eval("nvim_get_current_buf()") local wid2 = eval("win_getid()") @@ -69,7 +69,7 @@ describe('api functions', function() -- 0 is synonymous to the current buffer eq(bnr2, eval("nvim_buf_get_number(0)")) - execute("bn") -- show old buffer in new window + command("bn") -- show old buffer in new window eq(bnr, eval("nvim_get_current_buf()")) eq(bnr, eval("bufnr('')")) eq(bnr, eval("nvim_buf_get_number(0)")) @@ -81,7 +81,7 @@ describe('api functions', function() curbufmeths.set_lines(0, -1, true, {"aa\0", "b\0b"}) eq({'aa\n', 'b\nb'}, eval("nvim_buf_get_lines(0, 0, -1, 1)")) - execute('call nvim_buf_set_lines(0, 1, 2, v:true, ["xx", "\\nyy"])') + command('call nvim_buf_set_lines(0, 1, 2, v:true, ["xx", "\\nyy"])') eq({'aa\0', 'xx', '\0yy'}, curbufmeths.get_lines(0, -1, 1)) end) @@ -124,9 +124,9 @@ describe('api functions', function() [5] = {bold = true, foreground = Screen.colors.Blue}, }) - execute("set ft=vim") - execute("let &rtp='build/runtime/,'.&rtp") - execute("syntax on") + command("set ft=vim") + command("let &rtp='build/runtime/,'.&rtp") + command("syntax on") insert([[ call bufnr('%') call nvim_input('typing...') diff --git a/test/functional/eval/glob_spec.lua b/test/functional/eval/glob_spec.lua index 599b3dcdc3..b8807ecfcc 100644 --- a/test/functional/eval/glob_spec.lua +++ b/test/functional/eval/glob_spec.lua @@ -1,13 +1,13 @@ local lfs = require('lfs') local helpers = require('test.functional.helpers')(after_each) -local clear, execute, eval, eq = helpers.clear, helpers.execute, helpers.eval, helpers.eq +local clear, command, eval, eq = helpers.clear, helpers.command, helpers.eval, helpers.eq before_each(function() clear() lfs.mkdir('test-glob') -- Long path might cause "Press ENTER" prompt; use :silent to avoid it. - execute('silent cd test-glob') + command('silent cd test-glob') end) after_each(function() diff --git a/test/functional/eval/json_functions_spec.lua b/test/functional/eval/json_functions_spec.lua index fc0a19bdfa..4d34cde849 100644 --- a/test/functional/eval/json_functions_spec.lua +++ b/test/functional/eval/json_functions_spec.lua @@ -4,16 +4,17 @@ local funcs = helpers.funcs local meths = helpers.meths local eq = helpers.eq local eval = helpers.eval -local execute = helpers.execute +local command = helpers.command local exc_exec = helpers.exc_exec local redir_exec = helpers.redir_exec local NIL = helpers.NIL +local source = helpers.source describe('json_decode() function', function() local restart = function(...) clear(...) - execute('language C') - execute([[ + source([[ + language C function Eq(exp, act) let act = a:act let exp = a:exp @@ -45,8 +46,6 @@ describe('json_decode() function', function() endif return 1 endfunction - ]]) - execute([[ function EvalEq(exp, act_expr) let act = eval(a:act_expr) if Eq(a:exp, act) @@ -441,7 +440,7 @@ describe('json_decode() function', function() local sp_decode_eq = function(expected, json) meths.set_var('__json', json) speq(expected, 'json_decode(g:__json)') - execute('unlet! g:__json') + command('unlet! g:__json') end it('parses strings with NUL properly', function() @@ -527,7 +526,7 @@ end) describe('json_encode() function', function() before_each(function() clear() - execute('language C') + command('language C') end) it('dumps strings', function() @@ -576,94 +575,94 @@ describe('json_encode() function', function() it('cannot 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('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]]}') + command('let todump = {"_TYPE": v:msgpack_types.ext, "_VAL": [5, ["",""]]}') + command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}') 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]]}') + command('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": [5, [""]]}') + command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}') 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]]}') + command('let todump = {"_TYPE": v:msgpack_types.integer}') + command('let todump._VAL = [1, 3, 0x7FFFFFFF, 0x7FFFFFFF]') + command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}') 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]]}') + command('let todump = {"_TYPE": v:msgpack_types.float, "_VAL": 0.125}') + command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}') 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]]}') + command('let todump = {"_TYPE": v:msgpack_types.string, "_VAL": ["\\n"]}') + command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}') 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]]}') + command('let todump = {"_TYPE": v:msgpack_types.binary, "_VAL": ["\\n"]}') + command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}') 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", ""]}') + command('let todump = {"_TYPE": v:msgpack_types.string, "_VAL": ["\\n", ""]}') 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", ""]}') + command('let todump = {"_TYPE": v:msgpack_types.binary, "_VAL": ["\\n", ""]}') 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, ["",""]]}') + command('let todump = {"_TYPE": v:msgpack_types.ext, "_VAL": [5, ["",""]]}') 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, [""]]}') + command('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": [5, [""]]}') 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]') + command('let todump = {"_TYPE": v:msgpack_types.integer}') + command('let todump._VAL = [1, 3, 0x7FFFFFFF, 0x7FFFFFFF]') 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]') + command('let todump = {"_TYPE": v:msgpack_types.integer}') + command('let todump._VAL = [-1, 2, 0, 0]') 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}') + command('let todump = {"_TYPE": v:msgpack_types.boolean, "_VAL": 1}') 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}') + command('let todump = {"_TYPE": v:msgpack_types.boolean, "_VAL": 0}') eq('false', eval('json_encode(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('null', eval('json_encode(todump)')) end) @@ -673,7 +672,7 @@ describe('json_encode() function', function() end) it('fails to dump a partial', function() - execute('function T() dict\nendfunction') + command('function T() dict\nendfunction') eq('Vim(call):E474: Error while dumping encode_tv2json() argument, itself: attempt to dump function reference', exc_exec('call json_encode(function("T", [1, 2], {}))')) end) @@ -684,56 +683,56 @@ describe('json_encode() function', function() 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):E724: unable to correctly dump variable with self-referencing container', 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})') + command('let todump = {"d": {"d": {}}}') + command('call extend(todump.d.d, {"d": todump})') eq('Vim(call):E724: unable to correctly dump variable with self-referencing container', 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}') + command('let inter = {}') + command('let todump = {"a": inter, "b": inter}') 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]') + command('let inter = []') + command('let todump = [inter, inter]') 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)') + command('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": []}') + command('call add(todump._VAL, todump)') eq('Vim(call):E724: unable to correctly dump variable with self-referencing container', 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])') + command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": []}') + command('call add(todump._VAL, ["", todump])') eq('Vim(call):E724: unable to correctly dump variable with self-referencing container', 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)') + command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [["", []]]}') + command('call add(todump._VAL[0][1], todump._VAL)') eq('Vim(call):E724: unable to correctly dump variable with self-referencing container', exc_exec('call json_encode(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, ["", todump._VAL])') + command('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": []}') + command('call add(todump._VAL, ["", todump._VAL])') eq('Vim(call):E724: unable to correctly dump variable with self-referencing container', exc_exec('call json_encode(todump)')) end) diff --git a/test/functional/eval/modeline_spec.lua b/test/functional/eval/modeline_spec.lua index 0be7210a76..c5bb798f4a 100644 --- a/test/functional/eval/modeline_spec.lua +++ b/test/functional/eval/modeline_spec.lua @@ -1,5 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, execute, write_file = helpers.clear, helpers.execute, helpers.write_file +local clear, command, write_file = helpers.clear, helpers.command, helpers.write_file local eq, eval = helpers.eq, helpers.eval describe("modeline", function() @@ -12,7 +12,7 @@ describe("modeline", function() it('does not crash with a large version number', function() write_file(tempfile, 'vim100000000000000000000000') - execute('e! ' .. tempfile) + command('e! ' .. tempfile) eq(2, eval('1+1')) -- Still alive? end) 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) diff --git a/test/functional/eval/reltime_spec.lua b/test/functional/eval/reltime_spec.lua index 0b19d372ec..0181f09024 100644 --- a/test/functional/eval/reltime_spec.lua +++ b/test/functional/eval/reltime_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local clear, eq, ok = helpers.clear, helpers.eq, helpers.ok -local neq, execute, funcs = helpers.neq, helpers.execute, helpers.funcs +local neq, command, funcs = helpers.neq, helpers.command, helpers.funcs local reltime, reltimestr, reltimefloat = funcs.reltime, funcs.reltimestr, funcs.reltimefloat describe('reltimestr(), reltimefloat()', function() @@ -8,7 +8,7 @@ describe('reltimestr(), reltimefloat()', function() it('Checks', function() local now = reltime() - execute('sleep 10m') + command('sleep 10m') local later = reltime() local elapsed = reltime(now) diff --git a/test/functional/eval/setpos_spec.lua b/test/functional/eval/setpos_spec.lua index 2e27cd8ac0..6a8b3a8732 100644 --- a/test/functional/eval/setpos_spec.lua +++ b/test/functional/eval/setpos_spec.lua @@ -3,7 +3,7 @@ local setpos = helpers.funcs.setpos local getpos = helpers.funcs.getpos local insert = helpers.insert local clear = helpers.clear -local execute = helpers.execute +local command = helpers.command local eval = helpers.eval local eq = helpers.eq local exc_exec = helpers.exc_exec @@ -16,7 +16,7 @@ describe('setpos() function', function() First line of text Second line of text Third line of text]]) - execute('new') + command('new') insert([[ Line of text 1 Line of text 2 @@ -34,7 +34,8 @@ describe('setpos() function', function() it('can set lowercase marks in the current buffer', function() setpos("'d", {0, 2, 1, 0}) eq(getpos("'d"), {0, 2, 1, 0}) - execute('undo', 'call setpos("\'d", [2, 3, 1, 0])') + command('undo') + command('call setpos("\'d", [2, 3, 1, 0])') eq(getpos("'d"), {0, 3, 1, 0}) end) it('can set lowercase marks in other buffers', function() @@ -42,7 +43,7 @@ describe('setpos() function', function() eq(0, retval) setpos("'d", {1, 2, 1, 0}) eq(getpos("'d"), {0, 0, 0, 0}) - execute('wincmd w') + command('wincmd w') eq(eval('bufnr("%")'), 1) eq(getpos("'d"), {0, 2, 1, 0}) end) diff --git a/test/functional/eval/special_vars_spec.lua b/test/functional/eval/special_vars_spec.lua index 4c5d63ce23..3d9358447e 100644 --- a/test/functional/eval/special_vars_spec.lua +++ b/test/functional/eval/special_vars_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local exc_exec = helpers.exc_exec -local execute = helpers.execute +local command = helpers.command local funcs = helpers.funcs local clear = helpers.clear local eval = helpers.eval @@ -12,7 +12,7 @@ describe('Special values', function() before_each(clear) it('do not cause error when freed', function() - execute([[ + command([[ function Test() try return v:true @@ -109,7 +109,7 @@ describe('Special values', function() it('does not work with +=/-=/.=', function() meths.set_var('true', true) meths.set_var('false', false) - execute('let null = v:null') + command('let null = v:null') eq('Vim(let):E734: Wrong variable type for +=', exc_exec('let true += 1')) eq('Vim(let):E734: Wrong variable type for +=', exc_exec('let false += 1')) diff --git a/test/functional/eval/system_spec.lua b/test/functional/eval/system_spec.lua index ee75b593ff..0b7d3dce21 100644 --- a/test/functional/eval/system_spec.lua +++ b/test/functional/eval/system_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) -local eq, call, clear, eval, execute, feed, nvim = - helpers.eq, helpers.call, helpers.clear, helpers.eval, helpers.execute, +local eq, call, clear, eval, feed_command, feed, nvim = + helpers.eq, helpers.call, helpers.clear, helpers.eval, helpers.feed_command, helpers.feed, helpers.nvim local Screen = require('test.functional.ui.screen') @@ -43,10 +43,10 @@ describe('system()', function() it('parameter validation does NOT modify v:shell_error', function() -- 1. Call system() with invalid parameters. -- 2. Assert that v:shell_error was NOT set. - execute('call system({})') + feed_command('call system({})') eq('E475: Invalid argument: expected String or List', eval('v:errmsg')) eq(0, eval('v:shell_error')) - execute('call system([])') + feed_command('call system([])') eq('E474: Invalid argument', eval('v:errmsg')) eq(0, eval('v:shell_error')) @@ -57,9 +57,9 @@ describe('system()', function() -- 1. Call system() with invalid parameters. -- 2. Assert that v:shell_error was NOT modified. - execute('call system({})') + feed_command('call system({})') eq(old_val, eval('v:shell_error')) - execute('call system([])') + feed_command('call system([])') eq(old_val, eval('v:shell_error')) end) @@ -182,7 +182,7 @@ describe('system()', function() end) it('to backgrounded command does not crash', function() -- This is indeterminate, just exercise the codepath. May get E5677. - execute('call system("echo -n echoed &")') + feed_command('call system("echo -n echoed &")') local v_errnum = string.match(eval("v:errmsg"), "^E%d*:") if v_errnum then eq("E5677:", v_errnum) @@ -197,7 +197,7 @@ describe('system()', function() end) it('to backgrounded command does not crash', function() -- This is indeterminate, just exercise the codepath. May get E5677. - execute('call system("cat - &")') + feed_command('call system("cat - &")') local v_errnum = string.match(eval("v:errmsg"), "^E%d*:") if v_errnum then eq("E5677:", v_errnum) diff --git a/test/functional/eval/timer_spec.lua b/test/functional/eval/timer_spec.lua index b3c4cd07eb..2dd9968a01 100644 --- a/test/functional/eval/timer_spec.lua +++ b/test/functional/eval/timer_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local ok, feed, eq, eval = helpers.ok, helpers.feed, helpers.eq, helpers.eval local source, nvim_async, run = helpers.source, helpers.nvim_async, helpers.run -local clear, execute, funcs = helpers.clear, helpers.execute, helpers.funcs +local clear, command, funcs = helpers.clear, helpers.command, helpers.funcs local curbufmeths = helpers.curbufmeths describe('timers', function() @@ -17,14 +17,14 @@ describe('timers', function() end) it('works one-shot', function() - execute("call timer_start(50, 'MyHandler')") + command("call timer_start(50, 'MyHandler')") eq(0,eval("g:val")) run(nil, nil, nil, 200) eq(1,eval("g:val")) end) it('works one-shot when repeat=0', function() - execute("call timer_start(50, 'MyHandler', {'repeat': 0})") + command("call timer_start(50, 'MyHandler', {'repeat': 0})") eq(0,eval("g:val")) run(nil, nil, nil, 200) eq(1,eval("g:val")) @@ -32,14 +32,14 @@ describe('timers', function() it('works with repeat two', function() - execute("call timer_start(50, 'MyHandler', {'repeat': 2})") + command("call timer_start(50, 'MyHandler', {'repeat': 2})") eq(0,eval("g:val")) run(nil, nil, nil, 300) eq(2,eval("g:val")) end) it('are triggered during sleep', function() - execute("call timer_start(50, 'MyHandler', {'repeat': 2})") + command("call timer_start(50, 'MyHandler', {'repeat': 2})") nvim_async("command", "sleep 10") eq(0,eval("g:val")) run(nil, nil, nil, 300) @@ -63,12 +63,12 @@ describe('timers', function() end) it('are paused when event processing is disabled', function() - execute("call timer_start(50, 'MyHandler', {'repeat': -1})") + command("call timer_start(50, 'MyHandler', {'repeat': -1})") run(nil, nil, nil, 100) local count = eval("g:val") -- shows two line error message and thus invokes the return prompt. -- if we start to allow event processing here, we need to change this test. - execute("throw 'fatal error'") + feed(':throw "fatal error"') run(nil, nil, nil, 300) feed("") local diff = eval("g:val") - count @@ -76,7 +76,7 @@ describe('timers', function() end) it('are triggered in blocking getchar() call', function() - execute("call timer_start(50, 'MyHandler', {'repeat': -1})") + command("call timer_start(50, 'MyHandler', {'repeat': -1})") nvim_async("command", "let g:c = getchar()") run(nil, nil, nil, 300) feed("c") @@ -157,7 +157,7 @@ describe('timers', function() endif endfunc ]]) - execute("call timer_start(50, 'MyHandler', {'repeat': -1})") + command("call timer_start(50, 'MyHandler', {'repeat': -1})") eq(0,eval("g:val")) run(nil, nil, nil, 300) eq(3,eval("g:val")) @@ -170,8 +170,8 @@ describe('timers', function() let g:val2 += 1 endfunc ]]) - execute("call timer_start(50, 'MyHandler', {'repeat': 3})") - execute("call timer_start(100, 'MyHandler2', {'repeat': 2})") + command("call timer_start(50, 'MyHandler', {'repeat': 3})") + command("call timer_start(100, 'MyHandler2', {'repeat': 2})") run(nil, nil, nil, 300) eq(3,eval("g:val")) eq(2,eval("g:val2")) @@ -186,7 +186,7 @@ describe('timers', function() let g:val += 1 endfunc ]]) - execute("call timer_start(5, 'MyHandler', {'repeat': 1})") + command("call timer_start(5, 'MyHandler', {'repeat': 1})") run(nil, nil, nil, 300) eq(1,eval("g:val")) end) @@ -201,7 +201,7 @@ describe('timers', function() echo "evil" endfunc ]]) - execute("call timer_start(100, 'MyHandler', {'repeat': 1})") + command("call timer_start(100, 'MyHandler', {'repeat': 1})") feed(":good") screen:sleep(200) screen:expect([[ diff --git a/test/functional/ex_cmds/arg_spec.lua b/test/functional/ex_cmds/arg_spec.lua index e11b90532f..6d31f05c2a 100644 --- a/test/functional/ex_cmds/arg_spec.lua +++ b/test/functional/ex_cmds/arg_spec.lua @@ -1,5 +1,5 @@ local helpers = require("test.functional.helpers")(after_each) -local eq, execute, funcs = helpers.eq, helpers.execute, helpers.funcs +local eq, command, funcs = helpers.eq, helpers.command, helpers.funcs local ok = helpers.ok local clear = helpers.clear @@ -9,15 +9,15 @@ describe(":argument", function() end) it("does not restart :terminal buffer", function() - execute("terminal") + command("terminal") helpers.feed([[]]) - execute("argadd") + command("argadd") helpers.feed([[]]) local bufname_before = funcs.bufname("%") local bufnr_before = funcs.bufnr("%") helpers.ok(nil ~= string.find(bufname_before, "^term://")) -- sanity - execute("argument 1") + command("argument 1") helpers.feed([[]]) local bufname_after = funcs.bufname("%") diff --git a/test/functional/ex_cmds/bang_filter_spec.lua b/test/functional/ex_cmds/bang_filter_spec.lua index a320e6d018..aaec983b73 100644 --- a/test/functional/ex_cmds/bang_filter_spec.lua +++ b/test/functional/ex_cmds/bang_filter_spec.lua @@ -1,7 +1,7 @@ -- Specs for bang/filter commands local helpers = require('test.functional.helpers')(after_each) -local feed, execute, clear = helpers.feed, helpers.execute, helpers.clear +local feed, command, clear = helpers.feed, helpers.command, helpers.clear local mkdir, write_file, rmdir = helpers.mkdir, helpers.write_file, helpers.rmdir if helpers.pending_win32(pending) then return end @@ -28,7 +28,7 @@ describe('issues', function() end) it('#3269 Last line of shell output is not truncated', function() - execute([[nnoremap \l :!ls bang_filter_spec]]) + command([[nnoremap \l :!ls bang_filter_spec]]) feed([[\l]]) screen:expect([[ ~ | diff --git a/test/functional/ex_cmds/cd_spec.lua b/test/functional/ex_cmds/cd_spec.lua index 5bf4d22d0f..059cb26d5d 100644 --- a/test/functional/ex_cmds/cd_spec.lua +++ b/test/functional/ex_cmds/cd_spec.lua @@ -6,7 +6,7 @@ local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq local call = helpers.call local clear = helpers.clear -local execute = helpers.execute +local command = helpers.command local exc_exec = helpers.exc_exec if helpers.pending_win32(pending) then return end @@ -58,7 +58,7 @@ for _, cmd in ipairs {'cd', 'chdir'} do eq(0, lwd(globalwin)) eq(0, lwd(globalwin, tabnr)) - execute('bot split') + command('bot split') local localwin = call('winnr') -- Initial window is still using globalDir eq(globalDir, cwd(localwin)) @@ -66,7 +66,7 @@ for _, cmd in ipairs {'cd', 'chdir'} do eq(0, lwd(globalwin)) eq(0, lwd(globalwin, tabnr)) - execute('silent l' .. cmd .. ' ' .. directories.window) + command('silent l' .. cmd .. ' ' .. directories.window) -- From window with local dir, the original window -- is still reporting the global dir eq(globalDir, cwd(globalwin)) @@ -80,7 +80,7 @@ for _, cmd in ipairs {'cd', 'chdir'} do eq(1, lwd(localwin)) eq(1, lwd(localwin, tabnr)) - execute('tabnew') + command('tabnew') -- From new tab page, original window reports global dir eq(globalDir, cwd(globalwin, tabnr)) eq(0, lwd(globalwin, tabnr)) @@ -100,8 +100,8 @@ for _, cmd in ipairs {'cd', 'chdir'} do eq(0, lwd(-1, 0)) eq(0, lwd(-1, globaltab)) - execute('tabnew') - execute('silent t' .. cmd .. ' ' .. directories.tab) + command('tabnew') + command('silent t' .. cmd .. ' ' .. directories.tab) local localtab = call('tabpagenr') -- From local tab page, original tab reports globalDir @@ -114,7 +114,7 @@ for _, cmd in ipairs {'cd', 'chdir'} do eq(1, lwd(-1, 0)) eq(1, lwd(-1, localtab)) - execute('tabnext') + command('tabnext') -- From original tab page, local reports as such eq(globalDir .. '/' .. directories.tab, cwd(-1, localtab)) eq(1, lwd(-1, localtab)) @@ -128,13 +128,13 @@ for _, cmd in ipairs {'cd', 'chdir'} do end) it('works with tab-local pwd', function() - execute('silent t' .. cmd .. ' ' .. directories.tab) + command('silent t' .. cmd .. ' ' .. directories.tab) eq(directories.start, cwd(-1, -1)) eq(0, lwd(-1, -1)) end) it('works with window-local pwd', function() - execute('silent l' .. cmd .. ' ' .. directories.window) + command('silent l' .. cmd .. ' ' .. directories.window) eq(directories.start, cwd(-1, -1)) eq(0, lwd(-1, -1)) end) @@ -145,18 +145,18 @@ for _, cmd in ipairs {'cd', 'chdir'} do local globalDir = directories.start -- Create a new tab and change directory - execute('tabnew') - execute('silent t' .. cmd .. ' ' .. directories.tab) + command('tabnew') + command('silent t' .. cmd .. ' ' .. directories.tab) eq(globalDir .. '/' .. directories.tab, tcwd()) -- Create a new tab and verify it has inherited the directory - execute('tabnew') + command('tabnew') eq(globalDir .. '/' .. directories.tab, tcwd()) -- Change tab and change back, verify that directories are correct - execute('tabnext') + command('tabnext') eq(globalDir, tcwd()) - execute('tabprevious') + command('tabprevious') eq(globalDir .. '/' .. directories.tab, tcwd()) end) end) @@ -164,7 +164,7 @@ for _, cmd in ipairs {'cd', 'chdir'} do it('works', function() local globalDir = directories.start -- Create a new tab first and verify that is has the same working dir - execute('tabnew') + command('tabnew') eq(globalDir, cwd()) eq(globalDir, tcwd()) -- has no tab-local directory eq(0, tlwd()) @@ -172,7 +172,7 @@ for _, cmd in ipairs {'cd', 'chdir'} do eq(0, wlwd()) -- Change tab-local working directory and verify it is different - execute('silent t' .. cmd .. ' ' .. directories.tab) + command('silent t' .. cmd .. ' ' .. directories.tab) eq(globalDir .. '/' .. directories.tab, cwd()) eq(cwd(), tcwd()) -- working directory maches tab directory eq(1, tlwd()) @@ -180,46 +180,46 @@ for _, cmd in ipairs {'cd', 'chdir'} do eq(0, wlwd()) -- Create a new window in this tab to test `:lcd` - execute('new') + command('new') eq(1, tlwd()) -- Still tab-local working directory eq(0, wlwd()) -- Still no window-local working directory eq(globalDir .. '/' .. directories.tab, cwd()) - execute('silent l' .. cmd .. ' ../' .. directories.window) + command('silent l' .. cmd .. ' ../' .. directories.window) eq(globalDir .. '/' .. directories.window, cwd()) eq(globalDir .. '/' .. directories.tab, tcwd()) eq(1, wlwd()) -- Verify the first window still has the tab local directory - execute('wincmd w') + command('wincmd w') eq(globalDir .. '/' .. directories.tab, cwd()) eq(globalDir .. '/' .. directories.tab, tcwd()) eq(0, wlwd()) -- No window-local directory -- Change back to initial tab and verify working directory has stayed - execute('tabnext') + command('tabnext') eq(globalDir, cwd() ) eq(0, tlwd()) eq(0, wlwd()) -- Verify global changes don't affect local ones - execute('silent ' .. cmd .. ' ' .. directories.global) + command('silent ' .. cmd .. ' ' .. directories.global) eq(globalDir .. '/' .. directories.global, cwd()) - execute('tabnext') + command('tabnext') eq(globalDir .. '/' .. directories.tab, cwd()) eq(globalDir .. '/' .. directories.tab, tcwd()) eq(0, wlwd()) -- Still no window-local directory in this window -- Unless the global change happened in a tab with local directory - execute('silent ' .. cmd .. ' ..') + command('silent ' .. cmd .. ' ..') eq(globalDir, cwd() ) eq(0 , tlwd()) eq(0 , wlwd()) -- Which also affects the first tab - execute('tabnext') + command('tabnext') eq(globalDir, cwd()) -- But not in a window with its own local directory - execute('tabnext | wincmd w') + command('tabnext | wincmd w') eq(globalDir .. '/' .. directories.window, cwd() ) eq(0 , tlwd()) eq(globalDir .. '/' .. directories.window, wcwd()) @@ -280,8 +280,8 @@ describe("getcwd()", function () end) it("returns empty string if working directory does not exist", function() - execute("cd "..directories.global) - execute("call delete('../"..directories.global.."', 'd')") + command("cd "..directories.global) + command("call delete('../"..directories.global.."', 'd')") eq("", helpers.eval("getcwd()")) end) end) diff --git a/test/functional/ex_cmds/ctrl_c_spec.lua b/test/functional/ex_cmds/ctrl_c_spec.lua index 072fd2ad10..33affb26a5 100644 --- a/test/functional/ex_cmds/ctrl_c_spec.lua +++ b/test/functional/ex_cmds/ctrl_c_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear, feed, source = helpers.clear, helpers.feed, helpers.source -local execute = helpers.execute +local command = helpers.command describe("CTRL-C (mapped)", function() before_each(function() @@ -20,7 +20,7 @@ describe("CTRL-C (mapped)", function() nnoremap ]]) - execute("silent edit! test/functional/fixtures/bigfile.txt") + command("silent edit! test/functional/fixtures/bigfile.txt") local screen = Screen.new(52, 6) screen:attach() screen:set_default_attr_ids({ diff --git a/test/functional/ex_cmds/drop_spec.lua b/test/functional/ex_cmds/drop_spec.lua index 99db5ea333..9105b84367 100644 --- a/test/functional/ex_cmds/drop_spec.lua +++ b/test/functional/ex_cmds/drop_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local clear, feed, execute = helpers.clear, helpers.feed, helpers.execute +local clear, feed, feed_command = helpers.clear, helpers.feed, helpers.feed_command describe(":drop", function() local screen @@ -15,7 +15,7 @@ describe(":drop", function() [2] = {reverse = true}, [3] = {bold = true}, }) - execute("set laststatus=2") + feed_command("set laststatus=2") end) after_each(function() @@ -23,7 +23,7 @@ describe(":drop", function() end) it("works like :e when called with only one window open", function() - execute("drop tmp1.vim") + feed_command("drop tmp1.vim") screen:expect([[ ^ | {0:~ }| @@ -39,10 +39,10 @@ describe(":drop", function() end) it("switches to an open window showing the buffer", function() - execute("edit tmp1") - execute("vsplit") - execute("edit tmp2") - execute("drop tmp1") + feed_command("edit tmp1") + feed_command("vsplit") + feed_command("edit tmp2") + feed_command("drop tmp1") screen:expect([[ {2:|}^ | {0:~ }{2:|}{0:~ }| @@ -58,11 +58,11 @@ describe(":drop", function() end) it("splits off a new window when a buffer can't be abandoned", function() - execute("edit tmp1") - execute("vsplit") - execute("edit tmp2") + feed_command("edit tmp1") + feed_command("vsplit") + feed_command("edit tmp2") feed("iABC") - execute("drop tmp3") + feed_command("drop tmp3") screen:expect([[ ^ {2:|} | {0:~ }{2:|}{0:~ }| diff --git a/test/functional/ex_cmds/edit_spec.lua b/test/functional/ex_cmds/edit_spec.lua index 3cc5f5fb95..6ed500a293 100644 --- a/test/functional/ex_cmds/edit_spec.lua +++ b/test/functional/ex_cmds/edit_spec.lua @@ -1,7 +1,8 @@ local helpers = require("test.functional.helpers")(after_each) -local eq, execute, funcs = helpers.eq, helpers.execute, helpers.funcs +local eq, command, funcs = helpers.eq, helpers.command, helpers.funcs local ok = helpers.ok local clear = helpers.clear +local feed = helpers.feed describe(":edit", function() before_each(function() @@ -9,13 +10,13 @@ describe(":edit", function() end) it("without arguments does not restart :terminal buffer", function() - execute("terminal") - helpers.feed([[]]) + command("terminal") + feed([[]]) local bufname_before = funcs.bufname("%") local bufnr_before = funcs.bufnr("%") helpers.ok(nil ~= string.find(bufname_before, "^term://")) -- sanity - execute("edit") + command("edit") local bufname_after = funcs.bufname("%") local bufnr_after = funcs.bufnr("%") diff --git a/test/functional/ex_cmds/encoding_spec.lua b/test/functional/ex_cmds/encoding_spec.lua index 87ed7a2d0a..0769259be4 100644 --- a/test/functional/ex_cmds/encoding_spec.lua +++ b/test/functional/ex_cmds/encoding_spec.lua @@ -1,5 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, execute, feed = helpers.clear, helpers.execute, helpers.feed +local clear, feed_command, feed = helpers.clear, helpers.feed_command, helpers.feed local eq, neq, eval = helpers.eq, helpers.neq, helpers.eval describe('&encoding', function() @@ -12,7 +12,7 @@ describe('&encoding', function() end) it('cannot be changed after setup', function() - execute('set encoding=latin1') + feed_command('set encoding=latin1') -- error message expected feed('') neq(nil, string.find(eval('v:errmsg'), '^E474:')) @@ -31,7 +31,7 @@ describe('&encoding', function() end) it('can be set to utf-8 without error', function() - execute('set encoding=utf-8') + feed_command('set encoding=utf-8') eq("", eval('v:errmsg')) clear('--cmd', 'set enc=utf-8') diff --git a/test/functional/ex_cmds/grep_spec.lua b/test/functional/ex_cmds/grep_spec.lua index 13f88b7e03..43ef1bd424 100644 --- a/test/functional/ex_cmds/grep_spec.lua +++ b/test/functional/ex_cmds/grep_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, execute, feed, ok, eval = - helpers.clear, helpers.execute, helpers.feed, helpers.ok, helpers.eval +local clear, feed_command, feed, ok, eval = + helpers.clear, helpers.feed_command, helpers.feed, helpers.ok, helpers.eval describe(':grep', function() before_each(clear) @@ -11,10 +11,10 @@ describe(':grep', function() return end - execute([[set grepprg=grep\ -r]]) + feed_command([[set grepprg=grep\ -r]]) -- Change to test directory so that the test does not run too long. - execute('cd test') - execute('grep a **/*') + feed_command('cd test') + feed_command('grep a **/*') feed('') -- Press ENTER ok(eval('len(getqflist())') > 9000) -- IT'S OVER 9000!!1 end) diff --git a/test/functional/ex_cmds/menu_spec.lua b/test/functional/ex_cmds/menu_spec.lua index 52df9e1592..8c249d6918 100644 --- a/test/functional/ex_cmds/menu_spec.lua +++ b/test/functional/ex_cmds/menu_spec.lua @@ -1,5 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, execute, nvim = helpers.clear, helpers.execute, helpers.nvim +local clear, command, nvim = helpers.clear, helpers.command, helpers.nvim local expect, feed, command = helpers.expect, helpers.feed, helpers.command local eq, eval = helpers.eq, helpers.eval @@ -7,17 +7,17 @@ describe(':emenu', function() before_each(function() clear() - execute('nnoremenu Test.Test inormal') - execute('inoremenu Test.Test insert') - execute('vnoremenu Test.Test x') - execute('cnoremenu Test.Test cmdmode') + command('nnoremenu Test.Test inormal') + command('inoremenu Test.Test insert') + command('vnoremenu Test.Test x') + command('cnoremenu Test.Test cmdmode') - execute('nnoremenu Edit.Paste p') - execute('cnoremenu Edit.Paste "') + command('nnoremenu Edit.Paste p') + command('cnoremenu Edit.Paste "') end) it('executes correct bindings in normal mode without using API', function() - execute('emenu Test.Test') + command('emenu Test.Test') expect('normal') end) diff --git a/test/functional/ex_cmds/oldfiles_spec.lua b/test/functional/ex_cmds/oldfiles_spec.lua index a161e49fc6..656b3f9bae 100644 --- a/test/functional/ex_cmds/oldfiles_spec.lua +++ b/test/functional/ex_cmds/oldfiles_spec.lua @@ -1,7 +1,7 @@ local Screen = require('test.functional.ui.screen') local helpers = require('test.functional.helpers')(after_each) -local buf, eq, execute = helpers.curbufmeths, helpers.eq, helpers.execute +local buf, eq, feed_command = helpers.curbufmeths, helpers.eq, helpers.feed_command local feed, nvim_prog, wait = helpers.feed, helpers.nvim_prog, helpers.wait local ok, set_session, spawn = helpers.ok, helpers.set_session, helpers.spawn @@ -27,12 +27,12 @@ describe(':oldfiles', function() it('shows most recently used files', function() local screen = Screen.new(100, 5) screen:attach() - execute('edit testfile1') - execute('edit testfile2') - execute('wshada ' .. shada_file) - execute('rshada! ' .. shada_file) + feed_command('edit testfile1') + feed_command('edit testfile2') + feed_command('wshada ' .. shada_file) + feed_command('rshada! ' .. shada_file) local oldfiles = helpers.meths.get_vvar('oldfiles') - execute('oldfiles') + feed_command('oldfiles') screen:expect([[ testfile2 | 1: ]].. add_padding(oldfiles[1]) ..[[ | @@ -50,14 +50,14 @@ describe(':browse oldfiles', function() before_each(function() _clear() - execute('edit testfile1') + feed_command('edit testfile1') filename = buf.get_name() - execute('edit testfile2') + feed_command('edit testfile2') filename2 = buf.get_name() - execute('wshada ' .. shada_file) + feed_command('wshada ' .. shada_file) wait() _clear() - execute('rshada! ' .. shada_file) + feed_command('rshada! ' .. shada_file) -- Ensure nvim is out of "Press ENTER..." prompt. feed('') @@ -70,7 +70,7 @@ describe(':browse oldfiles', function() ok(filename == oldfiles[1] or filename == oldfiles[2]) ok(filename2 == oldfiles[1] or filename2 == oldfiles[2]) - execute('browse oldfiles') + feed_command('browse oldfiles') end) after_each(function() diff --git a/test/functional/ex_cmds/recover_spec.lua b/test/functional/ex_cmds/recover_spec.lua index af1296c94c..36bf85015a 100644 --- a/test/functional/ex_cmds/recover_spec.lua +++ b/test/functional/ex_cmds/recover_spec.lua @@ -2,8 +2,8 @@ local helpers = require('test.functional.helpers')(after_each) local lfs = require('lfs') -local execute, eq, clear, eval, feed, expect, source = - helpers.execute, helpers.eq, helpers.clear, helpers.eval, helpers.feed, +local feed_command, eq, clear, eval, feed, expect, source = + helpers.feed_command, helpers.eq, helpers.clear, helpers.eval, helpers.feed, helpers.expect, helpers.source if helpers.pending_win32(pending) then return end @@ -13,7 +13,7 @@ describe(':recover', function() it('fails if given a non-existent swapfile', function() local swapname = 'bogus-swapfile' - execute('recover '..swapname) -- This should not segfault. #2117 + feed_command('recover '..swapname) -- This should not segfault. #2117 eq('E305: No swap file found for '..swapname, eval('v:errmsg')) end) @@ -40,12 +40,12 @@ describe(':preserve', function() ]] source(init) - execute('set swapfile fileformat=unix undolevels=-1') + feed_command('set swapfile fileformat=unix undolevels=-1') -- Put swapdir at the start of the 'directory' list. #1836 - execute('set directory^='..swapdir..'//') - execute('edit '..testfile) + feed_command('set directory^='..swapdir..'//') + feed_command('edit '..testfile) feed('isometext') - execute('preserve') + feed_command('preserve') source('redir => g:swapname | swapname | redir END') local swappath1 = eval('g:swapname') @@ -59,8 +59,8 @@ describe(':preserve', function() source(init) -- Use the "SwapExists" event to choose the (R)ecover choice at the dialog. - execute('autocmd SwapExists * let v:swapchoice = "r"') - execute('silent edit '..testfile) + feed_command('autocmd SwapExists * let v:swapchoice = "r"') + feed_command('silent edit '..testfile) source('redir => g:swapname | swapname | redir END') local swappath2 = eval('g:swapname') diff --git a/test/functional/ex_cmds/undojoin_spec.lua b/test/functional/ex_cmds/undojoin_spec.lua index ba1e46ceb3..7803906619 100644 --- a/test/functional/ex_cmds/undojoin_spec.lua +++ b/test/functional/ex_cmds/undojoin_spec.lua @@ -5,7 +5,7 @@ local clear = helpers.clear local insert = helpers.insert local feed = helpers.feed local expect = helpers.expect -local execute = helpers.execute +local feed_command = helpers.feed_command local exc_exec = helpers.exc_exec describe(':undojoin command', function() @@ -14,10 +14,10 @@ describe(':undojoin command', function() insert([[ Line of text 1 Line of text 2]]) - execute('goto 1') + feed_command('goto 1') end) it('joins changes in a buffer', function() - execute('undojoin | delete') + feed_command('undojoin | delete') expect([[ Line of text 2]]) feed('u') @@ -26,7 +26,7 @@ describe(':undojoin command', function() end) it('does not corrupt undolist when connected with redo', function() feed('ixx') - execute('undojoin | redo') + feed_command('undojoin | redo') expect([[ xxLine of text 1 Line of text 2]]) diff --git a/test/functional/ex_cmds/write_spec.lua b/test/functional/ex_cmds/write_spec.lua index 9c2687971e..ea8b41a578 100644 --- a/test/functional/ex_cmds/write_spec.lua +++ b/test/functional/ex_cmds/write_spec.lua @@ -1,11 +1,12 @@ local helpers = require('test.functional.helpers')(after_each) local lfs = require('lfs') -local eq, eval, clear, write_file, execute, source, insert = +local eq, eval, clear, write_file, command, source, insert = helpers.eq, helpers.eval, helpers.clear, helpers.write_file, - helpers.execute, helpers.source, helpers.insert + helpers.command, helpers.source, helpers.insert local redir_exec = helpers.redir_exec local exc_exec = helpers.exc_exec local command = helpers.command +local feed_command = helpers.feed_command local funcs = helpers.funcs local meths = helpers.meths @@ -33,9 +34,9 @@ describe(':write', function() end) it('&backupcopy=auto preserves symlinks', function() - execute('set backupcopy=auto') + command('set backupcopy=auto') write_file('test_bkc_file.txt', 'content0') - execute("silent !ln -s test_bkc_file.txt test_bkc_link.txt") + command("silent !ln -s test_bkc_file.txt test_bkc_link.txt") source([[ edit test_bkc_link.txt call setline(1, ['content1']) @@ -46,9 +47,9 @@ describe(':write', function() end) it('&backupcopy=no replaces symlink with new file', function() - execute('set backupcopy=no') + command('set backupcopy=no') write_file('test_bkc_file.txt', 'content0') - execute("silent !ln -s test_bkc_file.txt test_bkc_link.txt") + command("silent !ln -s test_bkc_file.txt test_bkc_link.txt") source([[ edit test_bkc_link.txt call setline(1, ['content1']) @@ -69,7 +70,7 @@ describe(':write', function() insert(text) -- Blocks until a consumer reads the FIFO. - execute("write >> test_fifo") + feed_command("write >> test_fifo") -- Read the FIFO, this will unblock the :write above. local fifo = assert(io.open("test_fifo")) diff --git a/test/functional/ex_cmds/wundo_spec.lua b/test/functional/ex_cmds/wundo_spec.lua index e1216fa5d4..b6fcae0cf4 100644 --- a/test/functional/ex_cmds/wundo_spec.lua +++ b/test/functional/ex_cmds/wundo_spec.lua @@ -1,20 +1,21 @@ -- Specs for :wundo and underlying functions local helpers = require('test.functional.helpers')(after_each) -local execute, clear, eval, feed, spawn, nvim_prog, set_session = - helpers.execute, helpers.clear, helpers.eval, helpers.feed, helpers.spawn, +local command, clear, eval, spawn, nvim_prog, set_session = + helpers.command, helpers.clear, helpers.eval, helpers.spawn, helpers.nvim_prog, helpers.set_session describe(':wundo', function() before_each(clear) + after_each(function() + os.remove(eval('getcwd()') .. '/foo') + end) it('safely fails on new, non-empty buffer', function() - feed('iabc') - execute('wundo foo') -- This should not segfault. #1027 + command('normal! iabc') + command('wundo foo') -- This should not segfault. #1027 --TODO: check messages for error message - - os.remove(eval('getcwd()') .. '/foo') --cleanup end) end) @@ -23,7 +24,7 @@ describe('u_* functions', function() local session = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed', '-c', 'set undodir=. undofile'}) set_session(session) - execute('echo "True"') -- Should not error out due to crashed Neovim + command('echo "True"') -- Should not error out due to crashed Neovim session:close() end) end) diff --git a/test/functional/ex_cmds/wviminfo_spec.lua b/test/functional/ex_cmds/wviminfo_spec.lua index 37f45da2d4..eebbd70f2b 100644 --- a/test/functional/ex_cmds/wviminfo_spec.lua +++ b/test/functional/ex_cmds/wviminfo_spec.lua @@ -1,8 +1,8 @@ local helpers = require('test.functional.helpers')(after_each) local lfs = require('lfs') -local execute, eq, neq, spawn, nvim_prog, set_session, wait, write_file - = helpers.execute, helpers.eq, helpers.neq, helpers.spawn, - helpers.nvim_prog, helpers.set_session, helpers.wait, helpers.write_file +local command, eq, neq, spawn, nvim_prog, set_session, write_file = + helpers.command, helpers.eq, helpers.neq, helpers.spawn, + helpers.nvim_prog, helpers.set_session, helpers.write_file describe(':wshada', function() local shada_file = 'wshada_test' @@ -24,8 +24,7 @@ describe(':wshada', function() it('creates a shada file', function() -- file should _not_ exist eq(nil, lfs.attributes(shada_file)) - execute('wsh! '..shada_file) - wait() + command('wsh! '..shada_file) -- file _should_ exist neq(nil, lfs.attributes(shada_file)) end) @@ -40,8 +39,7 @@ describe(':wshada', function() eq(text, io.open(shada_file):read()) neq(nil, lfs.attributes(shada_file)) - execute('wsh! '..shada_file) - wait() + command('wsh! '..shada_file) -- File should have been overwritten with a shada file. local fp = io.open(shada_file, 'r') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 7793a9a739..adabfde9f7 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -566,7 +566,6 @@ local M = { iswin = iswin, feed = feed, feed_command = feed_command, - execute = feed_command, -- FIXME Remove eval = nvim_eval, call = nvim_call, command = nvim_command, diff --git a/test/functional/legacy/002_filename_recognition_spec.lua b/test/functional/legacy/002_filename_recognition_spec.lua index 5a833281e7..26a62d92fe 100644 --- a/test/functional/legacy/002_filename_recognition_spec.lua +++ b/test/functional/legacy/002_filename_recognition_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local execute, expect = helpers.execute, helpers.expect +local feed_command, expect = helpers.feed_command, helpers.expect describe('filename recognition', function() setup(clear) @@ -17,17 +17,17 @@ describe('filename recognition', function() fourth test for URL:\\machine.name\tmp\vimtest2d, and other text]]) -- Go to the first URL and append it to the beginning - execute('/^first', '/tmp', 'call append(0, expand(""))') + feed_command('/^first', '/tmp', 'call append(0, expand(""))') -- Repeat for the second URL -- this time, navigate to the word "URL" instead of "tmp" - execute('/^second', '/URL', 'call append(1, expand(""))') + feed_command('/^second', '/URL', 'call append(1, expand(""))') -- Repeat for the remaining URLs. This time, the 'isfname' option must be -- set to allow '\' in filenames - execute('set isf=@,48-57,/,.,-,_,+,,,$,:,~,\\') - execute('/^third', '/name', 'call append(2, expand(""))') - execute('/^fourth', '/URL', 'call append(3, expand(""))') + feed_command('set isf=@,48-57,/,.,-,_,+,,,$,:,~,\\') + feed_command('/^third', '/name', 'call append(2, expand(""))') + feed_command('/^fourth', '/URL', 'call append(3, expand(""))') -- Delete the initial text, which now starts at line 5 feed('5GdG') diff --git a/test/functional/legacy/004_bufenter_with_modelines_spec.lua b/test/functional/legacy/004_bufenter_with_modelines_spec.lua index 3e5cdd2ff2..9b0df024c8 100644 --- a/test/functional/legacy/004_bufenter_with_modelines_spec.lua +++ b/test/functional/legacy/004_bufenter_with_modelines_spec.lua @@ -1,10 +1,9 @@ --- vim: set foldmethod=marker foldmarker=[[,]] : -- Test for autocommand that changes current buffer on BufEnter event. -- Check if modelines are interpreted for the correct buffer. local helpers = require('test.functional.helpers')(after_each) local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local execute, expect = helpers.execute, helpers.expect +local feed_command, expect = helpers.feed_command, helpers.expect describe('BufEnter with modelines', function() setup(clear) @@ -20,34 +19,34 @@ describe('BufEnter with modelines', function() this is a test end of test file Xxx]]) - execute('au BufEnter Xxx brew') + feed_command('au BufEnter Xxx brew') -- Write test file Xxx - execute('/start of') - execute('.,/end of/w! Xxx') - execute('set ai modeline modelines=3') + feed_command('/start of') + feed_command('.,/end of/w! Xxx') + feed_command('set ai modeline modelines=3') -- Split to Xxx, autocmd will do :brew - execute('sp Xxx') + feed_command('sp Xxx') -- Append text with autoindent to this file feed('G?this is a') feed('othis should be auto-indented') -- Go to Xxx, no autocmd anymore - execute('au! BufEnter Xxx') - execute('buf Xxx') + feed_command('au! BufEnter Xxx') + feed_command('buf Xxx') -- Append text without autoindent to Xxx feed('G?this is a') feed('othis should be in column 1') - execute('wq') + feed_command('wq') -- Include Xxx in the current file feed('G:r Xxx') -- Vim issue #57 do not move cursor on when autoindent is set - execute('set fo+=r') + feed_command('set fo+=r') feed('G') feed('o# abcdef2hid0') feed('o# abcdef2hid0') diff --git a/test/functional/legacy/005_bufleave_delete_buffer_spec.lua b/test/functional/legacy/005_bufleave_delete_buffer_spec.lua index 895f4ad181..417842c52d 100644 --- a/test/functional/legacy/005_bufleave_delete_buffer_spec.lua +++ b/test/functional/legacy/005_bufleave_delete_buffer_spec.lua @@ -3,7 +3,8 @@ local helpers = require('test.functional.helpers')(after_each) local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local execute, expect = helpers.execute, helpers.expect +local command, expect = helpers.command, helpers.expect +local wait = helpers.wait describe('test5', function() setup(clear) @@ -18,35 +19,37 @@ describe('test5', function() this is a test end of test file Xxx]]) - execute('w! Xxx0') - execute('au BufLeave Xxx bwipe') - execute('/start of') + command('w! Xxx0') + command('au BufLeave Xxx bwipe') + command('/start of') -- Write test file Xxx. - execute('.,/end of/w! Xxx') + command('.,/end of/w! Xxx') -- Split to Xxx. - execute('sp Xxx') + command('sp Xxx') -- Delete buffer Xxx, now we're back here. - execute('bwipe') + command('bwipe') feed('G?this is a') feed('othis is some more text') + wait() -- Append some text to this file. -- Write current file contents. - execute('?start?,$yank A') + command('?start?,$yank A') -- Delete current buffer, get an empty one. - execute('bwipe!') + command('bwipe!') -- Append an extra line to the output register. feed('ithis is another test line:yank A') + wait() -- Output results - execute('%d') - execute('0put a') - execute('$d') + command('%d') + command('0put a') + command('$d') -- Assert buffer contents. expect([[ diff --git a/test/functional/legacy/006_argument_list_spec.lua b/test/functional/legacy/006_argument_list_spec.lua index 764854314f..dac58df8a5 100644 --- a/test/functional/legacy/006_argument_list_spec.lua +++ b/test/functional/legacy/006_argument_list_spec.lua @@ -2,8 +2,9 @@ local helpers = require('test.functional.helpers')(after_each) local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local execute, dedent, eq = helpers.execute, helpers.dedent, helpers.eq +local command, dedent, eq = helpers.command, helpers.dedent, helpers.eq local curbuf_contents = helpers.curbuf_contents +local wait = helpers.wait describe('argument list', function() setup(clear) @@ -16,10 +17,11 @@ describe('argument list', function() this is a test this is a test end of test file Xxx]]) + wait() + + command('au BufReadPost Xxx2 next Xxx2 Xxx1') + command('/^start of') - execute('au BufReadPost Xxx2 next Xxx2 Xxx1') - execute('/^start of') - -- Write test file Xxx1 feed('A1:.,/end of/w! Xxx1') @@ -28,29 +30,31 @@ describe('argument list', function() -- Write test file Xxx3 feed('$r3:.,/end of/w! Xxx3') + wait() -- Redefine arglist; go to Xxx1 - execute('next! Xxx1 Xxx2 Xxx3') - + command('next! Xxx1 Xxx2 Xxx3') + -- Open window for all args - execute('all') - + command('all') + -- Write contents of Xxx1 - execute('%yank A') + command('%yank A') -- Append contents of last window (Xxx1) feed('') - execute('%yank A') - + wait() + command('%yank A') + -- should now be in Xxx2 - execute('rew') - + command('rew') + -- Append contents of Xxx2 - execute('%yank A') + command('%yank A') - execute('%d') - execute('0put=@a') - execute('$d') + command('%d') + command('0put=@a') + command('$d') eq(dedent([[ start of test file Xxx1 diff --git a/test/functional/legacy/007_ball_buffer_list_spec.lua b/test/functional/legacy/007_ball_buffer_list_spec.lua index e54525fd06..8501faabec 100644 --- a/test/functional/legacy/007_ball_buffer_list_spec.lua +++ b/test/functional/legacy/007_ball_buffer_list_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local execute, expect = helpers.execute, helpers.expect +local feed_command, expect = helpers.feed_command, helpers.expect describe(':ball', function() setup(clear) @@ -14,44 +14,44 @@ describe(':ball', function() this is a test end of test file Xxx]]) - execute('w! Xxx0') + feed_command('w! Xxx0') feed('gg') -- Write test file Xxx1 feed('A1:.,/end of/w! Xxx1') - execute('sp Xxx1') - execute('close') + feed_command('sp Xxx1') + feed_command('close') -- Write test file Xxx2 feed('$r2:.,/end of/w! Xxx2') - execute('sp Xxx2') - execute('close') + feed_command('sp Xxx2') + feed_command('close') -- Write test file Xxx3 feed('$r3:.,/end of/w! Xxx3') - execute('sp Xxx3') - execute('close') + feed_command('sp Xxx3') + feed_command('close') - execute('au BufReadPost Xxx2 bwipe') + feed_command('au BufReadPost Xxx2 bwipe') -- Open window for all args, close Xxx2 feed('$r4:ball') -- Write contents of this file - execute('%yank A') + feed_command('%yank A') -- Append contents of second window (Xxx1) feed('') - execute('%yank A') + feed_command('%yank A') -- Append contents of last window (this file) feed('') - execute('%yank A') + feed_command('%yank A') - execute('bf') - execute('%d') - execute('0put=@a') - execute('$d') + feed_command('bf') + feed_command('%d') + feed_command('0put=@a') + feed_command('$d') expect([[ start of test file Xxx4 diff --git a/test/functional/legacy/008_autocommands_spec.lua b/test/functional/legacy/008_autocommands_spec.lua index 2c398d3c73..7474f1e068 100644 --- a/test/functional/legacy/008_autocommands_spec.lua +++ b/test/functional/legacy/008_autocommands_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local feed, source = helpers.feed, helpers.source -local clear, execute, expect, eq, eval = helpers.clear, helpers.execute, helpers.expect, helpers.eq, helpers.eval +local clear, feed_command, expect, eq, eval = helpers.clear, helpers.feed_command, helpers.expect, helpers.eq, helpers.eval local write_file, wait, dedent = helpers.write_file, helpers.wait, helpers.dedent local io = require('io') @@ -25,15 +25,15 @@ describe('autocommands that delete and unload buffers:', function() before_each(clear) it('BufWritePre, BufUnload', function() - execute('au BufWritePre Xxx1 bunload') - execute('au BufWritePre Xxx2 bwipe') - execute('e Xxx2') + feed_command('au BufWritePre Xxx1 bunload') + feed_command('au BufWritePre Xxx2 bwipe') + feed_command('e Xxx2') eq('Xxx2', eval('bufname("%")')) - execute('e Xxx1') + feed_command('e Xxx1') eq('Xxx1', eval('bufname("%")')) -- The legacy test file did not check the error message. - execute('let v:errmsg = "no error"') - execute('write') + feed_command('let v:errmsg = "no error"') + feed_command('write') -- Discard all "hit enter" prompts and messages. feed('') eq('E203: Autocommands deleted or unloaded buffer to be written', @@ -41,11 +41,11 @@ describe('autocommands that delete and unload buffers:', function() eq('Xxx2', eval('bufname("%")')) expect(text2) -- Start editing Xxx2. - execute('e! Xxx2') + feed_command('e! Xxx2') -- The legacy test file did not check the error message. - execute('let v:errmsg = "no error"') + feed_command('let v:errmsg = "no error"') -- Write Xxx2, will delete the buffer and give an error msg. - execute('w') + feed_command('w') -- Discard all "hit enter" prompts and messages. feed('') eq('E203: Autocommands deleted or unloaded buffer to be written', @@ -73,17 +73,17 @@ describe('autocommands that delete and unload buffers:', function() au BufUnload * call CloseAll() au VimLeave * call WriteToOut() ]]) - execute('e Xxx2') + feed_command('e Xxx2') -- Discard all "hit enter" prompts and messages. feed('') - execute('e Xxx1') + feed_command('e Xxx1') -- Discard all "hit enter" prompts and messages. feed('') - execute('e Makefile') -- an existing file + feed_command('e Makefile') -- an existing file feed('') - execute('sp new2') + feed_command('sp new2') feed('') - execute('q') + feed_command('q') wait() eq('VimLeave done', string.match(io.open('test.out', 'r'):read('*all'), "^%s*(.-)%s*$")) diff --git a/test/functional/legacy/011_autocommands_spec.lua b/test/functional/legacy/011_autocommands_spec.lua index ba899f8119..e01af4583b 100644 --- a/test/functional/legacy/011_autocommands_spec.lua +++ b/test/functional/legacy/011_autocommands_spec.lua @@ -14,8 +14,8 @@ local helpers= require('test.functional.helpers')(after_each) local lfs = require('lfs') -local clear, execute, expect, eq, neq, dedent, write_file, feed = - helpers.clear, helpers.execute, helpers.expect, helpers.eq, helpers.neq, +local clear, feed_command, expect, eq, neq, dedent, write_file, feed = + helpers.clear, helpers.feed_command, helpers.expect, helpers.eq, helpers.neq, helpers.dedent, helpers.write_file, helpers.feed if helpers.pending_win32(pending) then return end @@ -66,26 +66,26 @@ describe('file reading, writing and bufnew and filter autocommands', function() it('FileReadPost (using gzip)', function() prepare_gz_file('Xtestfile', text1) - execute('let $GZIP = ""') + feed_command('let $GZIP = ""') --execute('au FileChangedShell * echo "caught FileChangedShell"') - execute('set bin') - execute("au FileReadPost *.gz '[,']!gzip -d") + feed_command('set bin') + feed_command("au FileReadPost *.gz '[,']!gzip -d") -- Read and decompress the testfile. - execute('$r Xtestfile.gz') + feed_command('$r Xtestfile.gz') expect('\n'..text1) end) it('BufReadPre, BufReadPost (using gzip)', function() prepare_gz_file('Xtestfile', text1) local gzip_data = io.open('Xtestfile.gz'):read('*all') - execute('let $GZIP = ""') + feed_command('let $GZIP = ""') -- Setup autocommands to decompress before reading and re-compress afterwards. - execute("au BufReadPre *.gz exe '!gzip -d ' . shellescape(expand(''))") - execute("au BufReadPre *.gz call rename(expand(':r'), expand(''))") - execute("au BufReadPost *.gz call rename(expand(''), expand(':r'))") - execute("au BufReadPost *.gz exe '!gzip ' . shellescape(expand(':r'))") + feed_command("au BufReadPre *.gz exe '!gzip -d ' . shellescape(expand(''))") + feed_command("au BufReadPre *.gz call rename(expand(':r'), expand(''))") + feed_command("au BufReadPost *.gz call rename(expand(''), expand(':r'))") + feed_command("au BufReadPost *.gz exe '!gzip ' . shellescape(expand(':r'))") -- Edit compressed file. - execute('e! Xtestfile.gz') + feed_command('e! Xtestfile.gz') -- Discard all prompts and messages. feed('') -- Expect the decompressed file in the buffer. @@ -96,11 +96,11 @@ describe('file reading, writing and bufnew and filter autocommands', function() it('FileReadPre, FileReadPost', function() prepare_gz_file('Xtestfile', text1) - execute('au! FileReadPre *.gz exe "silent !gzip -d " . shellescape(expand(""))') - execute('au FileReadPre *.gz call rename(expand(":r"), expand(""))') - execute("au! FileReadPost *.gz '[,']s/l/L/") + feed_command('au! FileReadPre *.gz exe "silent !gzip -d " . shellescape(expand(""))') + feed_command('au FileReadPre *.gz call rename(expand(":r"), expand(""))') + feed_command("au! FileReadPost *.gz '[,']s/l/L/") -- Read compressed file. - execute('$r Xtestfile.gz') + feed_command('$r Xtestfile.gz') -- Discard all prompts and messages. feed('') expect([[ @@ -121,17 +121,17 @@ describe('file reading, writing and bufnew and filter autocommands', function() end it('FileAppendPre, FileAppendPost', function() - execute('au BufNewFile *.c read Xtest.c') + feed_command('au BufNewFile *.c read Xtest.c') -- Will load Xtest.c. - execute('e! foo.c') - execute("au FileAppendPre *.out '[,']s/new/NEW/") - execute('au FileAppendPost *.out !cat Xtest.c >>test.out') + feed_command('e! foo.c') + feed_command("au FileAppendPre *.out '[,']s/new/NEW/") + feed_command('au FileAppendPost *.out !cat Xtest.c >>test.out') -- Append it to the output file. - execute('w>>test.out') + feed_command('w>>test.out') -- Discard all prompts and messages. feed('') -- Expect the decompressed file in the buffer. - execute('e test.out') + feed_command('e test.out') expect([[ /* @@ -166,18 +166,18 @@ describe('file reading, writing and bufnew and filter autocommands', function() * Here is a new .c file */]])) -- Need temp files here. - execute('set shelltemp') - execute('au FilterReadPre *.out call rename(expand(""), expand("") . ".t")') - execute('au FilterReadPre *.out exe "silent !sed s/e/E/ " . shellescape(expand("")) . ".t >" . shellescape(expand(""))') - execute('au FilterReadPre *.out exe "silent !rm " . shellescape(expand("")) . ".t"') - execute("au FilterReadPost *.out '[,']s/x/X/g") + feed_command('set shelltemp') + feed_command('au FilterReadPre *.out call rename(expand(""), expand("") . ".t")') + feed_command('au FilterReadPre *.out exe "silent !sed s/e/E/ " . shellescape(expand("")) . ".t >" . shellescape(expand(""))') + feed_command('au FilterReadPre *.out exe "silent !rm " . shellescape(expand("")) . ".t"') + feed_command("au FilterReadPost *.out '[,']s/x/X/g") -- Edit the output file. - execute('e! test.out') - execute('23,$!cat') + feed_command('e! test.out') + feed_command('23,$!cat') -- Discard all prompts and messages. feed('') -- Remove CR for when sed adds them. - execute([[23,$s/\r$//]]) + feed_command([[23,$s/\r$//]]) expect([[ startstart start of testfile diff --git a/test/functional/legacy/015_alignment_spec.lua b/test/functional/legacy/015_alignment_spec.lua index 48d4042ff2..8423aa3d11 100644 --- a/test/functional/legacy/015_alignment_spec.lua +++ b/test/functional/legacy/015_alignment_spec.lua @@ -4,7 +4,7 @@ local helpers = require('test.functional.helpers')(after_each) local feed, insert = helpers.feed, helpers.insert -local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect +local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect describe('alignment', function() setup(clear) @@ -19,7 +19,7 @@ describe('alignment', function() asdfa a xasdfa a asxxdfa a - + test for :center a a fa afd asdf @@ -28,7 +28,7 @@ describe('alignment', function() asdfa a xasdfa asdfasdfasdfasdfasdf asxxdfa a - + test for :right a a fa a @@ -111,34 +111,34 @@ describe('alignment', function() asxxdfa axxxoikey asxa;ofa axxxoikey asdfaqwer axxxoikey - + xxxxx xx xxxxxx xxxxxxx xxxxxxxxx xxx xxxx xxxxx xxxxx xxx xx xxxxxxxxxxxxxxxxxx xxxxx xxxx, xxxx xxxx xxxx xxxx xxx xx xx xx xxxxxxx. xxxx xxxx. - + > xx xx, xxxx xxxx xxx xxxx xxx xxxxx xxx xxx xxxxxxx xxx xxxxx > xxxxxx xxxxxxx: xxxx xxxxxxx, xx xxxxxx xxxx xxxxxxxxxx - + aa aa aa aa bb bb bb bb cc cc cc cc]]) - execute('set tw=65') + feed_command('set tw=65') feed([[:/^\s*test for :left/,/^\s*test for :center/ left]]) feed([[:/^\s*test for :center/,/^\s*test for :right/ center]]) feed([[:/^\s*test for :right/,/^xxx/-1 right]]) - execute('set fo+=tcroql tw=72') + feed_command('set fo+=tcroql tw=72') feed('/xxxxxxxx$') feed('0gq6kk') -- Undo/redo here to make the next undo only work on the following changes. feed('u') - execute('map gg :.,.+2s/^/x/kk:set tw=3gqq') - execute('/^aa') + feed_command('map gg :.,.+2s/^/x/kk:set tw=3gqq') + feed_command('/^aa') feed('ggu') -- Assert buffer contents. @@ -151,7 +151,7 @@ describe('alignment', function() asdfa a xasdfa a asxxdfa a - + test for :center a a fa afd asdf @@ -160,7 +160,7 @@ describe('alignment', function() asdfa a xasdfa asdfasdfasdfasdfasdf asxxdfa a - + test for :right a a fa a @@ -243,14 +243,14 @@ describe('alignment', function() asxxdfa axxxoikey asxa;ofa axxxoikey asdfaqwer axxxoikey - + xxxxx xx xxxxxx xxxxxxx xxxxxxxxx xxx xxxx xxxxx xxxxx xxx xx xxxxxxxxxxxxxxxxxx xxxxx xxxx, xxxx xxxx xxxx xxxx xxx xx xx xx xxxxxxx. xxxx xxxx. - + > xx xx, xxxx xxxx xxx xxxx xxx xxxxx xxx xxx xxxxxxx xxx xxxxx xxxxxx > xxxxxxx: xxxx xxxxxxx, xx xxxxxx xxxx xxxxxxxxxx - + aa aa aa aa bb bb bb bb cc cc cc cc]]) diff --git a/test/functional/legacy/019_smarttab_expandtab_spec.lua b/test/functional/legacy/019_smarttab_expandtab_spec.lua index 2287a9f786..ecb24885bb 100644 --- a/test/functional/legacy/019_smarttab_expandtab_spec.lua +++ b/test/functional/legacy/019_smarttab_expandtab_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local feed, insert = helpers.feed, helpers.insert -local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect +local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect describe([[performing "r" with 'smarttab' and 'expandtab' set/not set, and "dv_"]], function() setup(clear) @@ -19,24 +19,24 @@ describe([[performing "r" with 'smarttab' and 'expandtab' set/not set, and test text Second line beginning with whitespace]]) - execute('set smarttab expandtab ts=8 sw=4') + feed_command('set smarttab expandtab ts=8 sw=4') -- Make sure that backspace works, no matter what termcap is used. - execute('set t_kD=x7f t_kb=x08') + feed_command('set t_kD=x7f t_kb=x08') - execute('/some') + feed_command('/some') feed('r ') - execute('set noexpandtab') - execute('/other') + feed_command('set noexpandtab') + feed_command('/other') feed('r ') -- Test replacing with Tabs and then backspacing to undo it. feed('0wR ') -- Test replacing with Tabs. feed('0wR ') -- Test that copyindent works with expandtab set. - execute('set expandtab smartindent copyindent ts=8 sw=8 sts=8') + feed_command('set expandtab smartindent copyindent ts=8 sw=8 sts=8') feed('o{x') - execute('set nosol') - execute('/Second line/') + feed_command('set nosol') + feed_command('/Second line/') -- Test "dv_" feed('fwdv_') diff --git a/test/functional/legacy/020_blockwise_visual_spec.lua b/test/functional/legacy/020_blockwise_visual_spec.lua index 660348a792..8d90b1c77d 100644 --- a/test/functional/legacy/020_blockwise_visual_spec.lua +++ b/test/functional/legacy/020_blockwise_visual_spec.lua @@ -1,11 +1,10 @@ --- vim: set foldmethod=marker foldmarker=[[,]] : -- Tests Blockwise Visual when there are TABs before the text. -- First test for undo working properly when executing commands from a register. -- Also test this in an empty buffer. local helpers = require('test.functional.helpers')(after_each) local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local execute, expect = helpers.execute, helpers.expect +local feed_command, expect = helpers.feed_command, helpers.expect describe('blockwise visual', function() setup(clear) @@ -26,15 +25,15 @@ Ox jAy kdd]]) feed(":let @a = 'OxjAykdd'") feed('G0k@au') - execute('new') + feed_command('new') feed('@auY') - execute('quit') + feed_command('quit') feed('GP') - execute('/start here') + feed_command('/start here') feed('"by$jjlld') - execute('/456') + feed_command('/456') feed('jj"bP') - execute('$-3,$d') + feed_command('$-3,$d') expect([[ 123start here56 diff --git a/test/functional/legacy/021_control_wi_spec.lua b/test/functional/legacy/021_control_wi_spec.lua index 787a384fca..87d9deed7a 100644 --- a/test/functional/legacy/021_control_wi_spec.lua +++ b/test/functional/legacy/021_control_wi_spec.lua @@ -1,9 +1,8 @@ --- vim: set foldmethod=marker foldmarker=[[,]] : -- Tests for [ CTRL-I with a count and CTRL-W CTRL-I with a count local helpers = require('test.functional.helpers')(after_each) local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local execute, expect = helpers.execute, helpers.expect +local feed_command, expect = helpers.feed_command, helpers.expect describe('CTRL-W CTRL-I', function() setup(clear) @@ -20,18 +19,18 @@ describe('CTRL-W CTRL-I', function() test text]]) -- Search for the second occurence of start and append to register - execute('/start') + feed_command('/start') feed('2[') - execute('yank A') + feed_command('yank A') -- Same as above but using different keystrokes. feed('?start') feed('2') - execute('yank A') + feed_command('yank A') -- Clean buffer and put register feed('ggdG"ap') - execute('1d') + feed_command('1d') -- The buffer should now contain: expect([[ diff --git a/test/functional/legacy/022_line_ending_spec.lua b/test/functional/legacy/022_line_ending_spec.lua index 092440bb16..fb4b782011 100644 --- a/test/functional/legacy/022_line_ending_spec.lua +++ b/test/functional/legacy/022_line_ending_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, feed = helpers.clear, helpers.feed -local execute, expect = helpers.execute, helpers.expect +local feed_command, expect = helpers.feed_command, helpers.expect describe('line ending', function() setup(clear) @@ -14,8 +14,8 @@ describe('line ending', function() this one does and the last one doesn't]], '') - execute('set ta tx') - execute('e!') + feed_command('set ta tx') + feed_command('e!') expect("this lines ends in a\r\n".. "this one doesn't\n".. diff --git a/test/functional/legacy/023_edit_arguments_spec.lua b/test/functional/legacy/023_edit_arguments_spec.lua index 95ab983d24..e705397a2b 100644 --- a/test/functional/legacy/023_edit_arguments_spec.lua +++ b/test/functional/legacy/023_edit_arguments_spec.lua @@ -2,7 +2,8 @@ local helpers = require('test.functional.helpers')(after_each) local clear, insert = helpers.clear, helpers.insert -local execute, expect = helpers.execute, helpers.expect +local command, expect = helpers.command, helpers.expect +local wait = helpers.wait describe(':edit', function() setup(clear) @@ -12,31 +13,32 @@ describe(':edit', function() The result should be in Xfile1: "fooPIPEbar", in Xfile2: "fooSLASHbar" foo|bar foo/bar]]) + wait() -- Prepare some test files - execute('$-1w! Xfile1') - execute('$w! Xfile2') - execute('w! Xfile0') + command('$-1w! Xfile1') + command('$w! Xfile2') + command('w! Xfile0') -- Open Xfile using '+' range - execute('edit +1 Xfile1') - execute('s/|/PIPE/') - execute('yank A') - execute('w! Xfile1') + command('edit +1 Xfile1') + command('s/|/PIPE/') + command('yank A') + command('w! Xfile1') -- Open Xfile2 using '|' range - execute('edit Xfile2|1') - execute("s/\\//SLASH/") - execute('yank A') - execute('w! Xfile2') + command('edit Xfile2|1') + command("s/\\//SLASH/") + command('yank A') + command('w! Xfile2') -- Clean first buffer and put @a - execute('bf') - execute('%d') - execute('0put a') + command('bf') + command('%d') + command('0put a') -- Remove empty line - execute('$d') + command('$d') -- The buffer should now contain expect([[ diff --git a/test/functional/legacy/025_jump_tag_hidden_spec.lua b/test/functional/legacy/025_jump_tag_hidden_spec.lua index 99224f9e08..0d51b4da26 100644 --- a/test/functional/legacy/025_jump_tag_hidden_spec.lua +++ b/test/functional/legacy/025_jump_tag_hidden_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local execute, expect = helpers.execute, helpers.expect +local feed_command, expect = helpers.feed_command, helpers.expect if helpers.pending_win32(pending) then return end @@ -21,30 +21,30 @@ describe('jump to a tag with hidden set', function() SECTION_OFF]]) - execute('w! Xxx') - execute('set hidden') + feed_command('w! Xxx') + feed_command('set hidden') -- Create a link from test25.dir to the current directory. - execute('!rm -f test25.dir') - execute('!ln -s . test25.dir') + feed_command('!rm -f test25.dir') + feed_command('!ln -s . test25.dir') -- Create tags.text, with the current directory name inserted. - execute('/tags line') - execute('r !pwd') + feed_command('/tags line') + feed_command('r !pwd') feed('d$/test') feed('hP:.w! tags.test') -- Try jumping to a tag in the current file, but with a path that contains a -- symbolic link. When wrong, this will give the ATTENTION message. The next -- space will then be eaten by hit-return, instead of moving the cursor to 'd'. - execute('set tags=tags.test') + feed_command('set tags=tags.test') feed('G x:yank a') - execute('!rm -f Xxx test25.dir tags.test') + feed_command('!rm -f Xxx test25.dir tags.test') -- Put @a and remove empty line - execute('%d') - execute('0put a') - execute('$d') + feed_command('%d') + feed_command('0put a') + feed_command('$d') -- Assert buffer contents. expect("#efine SECTION_OFF 3") diff --git a/test/functional/legacy/026_execute_while_if_spec.lua b/test/functional/legacy/026_execute_while_if_spec.lua index 74ef34bb20..ea8abed7ae 100644 --- a/test/functional/legacy/026_execute_while_if_spec.lua +++ b/test/functional/legacy/026_execute_while_if_spec.lua @@ -1,9 +1,11 @@ -- Test for :execute, :while and :if local helpers = require('test.functional.helpers')(after_each) + local clear = helpers.clear -local execute, expect = helpers.execute, helpers.expect +local expect = helpers.expect local source = helpers.source +local command = helpers.command describe(':execute, :while and :if', function() setup(clear) @@ -37,7 +39,7 @@ describe(':execute, :while and :if', function() ]]) -- Remove empty line - execute('1d') + command('1d') -- Assert buffer contents. expect([[ diff --git a/test/functional/legacy/028_source_ctrl_v_spec.lua b/test/functional/legacy/028_source_ctrl_v_spec.lua index a8c43260be..fabf831341 100644 --- a/test/functional/legacy/028_source_ctrl_v_spec.lua +++ b/test/functional/legacy/028_source_ctrl_v_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local execute, expect = helpers.execute, helpers.expect +local feed_command, expect = helpers.feed_command, helpers.expect describe('CTRL-V at the end of the line', function() setup(clear) @@ -24,8 +24,8 @@ describe('CTRL-V at the end of the line', function() feed(':%s/X//g') feed(':/firstline/+1,/lastline/-1w! Xtestfile') - execute('so Xtestfile') - execute('%d') + feed_command('so Xtestfile') + feed_command('%d') feed('Gmm__1__2__3__4__5') feed(":'m,$s//0/g") diff --git a/test/functional/legacy/030_fileformats_spec.lua b/test/functional/legacy/030_fileformats_spec.lua index 5fd78b2c59..aadc6d60c2 100644 --- a/test/functional/legacy/030_fileformats_spec.lua +++ b/test/functional/legacy/030_fileformats_spec.lua @@ -1,8 +1,9 @@ -- Test for a lot of variations of the 'fileformats' option local helpers = require('test.functional.helpers')(after_each) -local feed, clear, execute = helpers.feed, helpers.clear, helpers.execute +local feed, clear, command = helpers.feed, helpers.clear, helpers.command local eq, write_file = helpers.eq, helpers.write_file +local wait = helpers.wait if helpers.pending_win32(pending) then return end @@ -45,198 +46,214 @@ describe('fileformats option', function() it('is working', function() -- Try reading and writing with 'fileformats' empty. - execute('set fileformats=') - execute('set fileformat=unix') - execute('e! XXUnix') - execute('w! test.out') - execute('e! XXDos') - execute('w! XXtt01') - execute('e! XXMac') - execute('w! XXtt02') - execute('bwipe XXUnix XXDos XXMac') - execute('set fileformat=dos') - execute('e! XXUnix') - execute('w! XXtt11') - execute('e! XXDos') - execute('w! XXtt12') - execute('e! XXMac') - execute('w! XXtt13') - execute('bwipe XXUnix XXDos XXMac') - execute('set fileformat=mac') - execute('e! XXUnix') - execute('w! XXtt21') - execute('e! XXDos') - execute('w! XXtt22') - execute('e! XXMac') - execute('w! XXtt23') - execute('bwipe XXUnix XXDos XXMac') + command('set fileformats=') + command('set fileformat=unix') + command('e! XXUnix') + command('w! test.out') + command('e! XXDos') + command('w! XXtt01') + command('e! XXMac') + command('w! XXtt02') + command('bwipe XXUnix XXDos XXMac') + command('set fileformat=dos') + command('e! XXUnix') + command('w! XXtt11') + command('e! XXDos') + command('w! XXtt12') + command('e! XXMac') + command('w! XXtt13') + command('bwipe XXUnix XXDos XXMac') + command('set fileformat=mac') + command('e! XXUnix') + command('w! XXtt21') + command('e! XXDos') + command('w! XXtt22') + command('e! XXMac') + command('w! XXtt23') + command('bwipe XXUnix XXDos XXMac') -- Try reading and writing with 'fileformats' set to one format. - execute('set fileformats=unix') - execute('e! XXUxDsMc') - execute('w! XXtt31') - execute('bwipe XXUxDsMc') - execute('set fileformats=dos') - execute('e! XXUxDsMc') - execute('w! XXtt32') - execute('bwipe XXUxDsMc') - execute('set fileformats=mac') - execute('e! XXUxDsMc') - execute('w! XXtt33') - execute('bwipe XXUxDsMc') + command('set fileformats=unix') + command('e! XXUxDsMc') + command('w! XXtt31') + command('bwipe XXUxDsMc') + command('set fileformats=dos') + command('e! XXUxDsMc') + command('w! XXtt32') + command('bwipe XXUxDsMc') + command('set fileformats=mac') + command('e! XXUxDsMc') + command('w! XXtt33') + command('bwipe XXUxDsMc') -- Try reading and writing with 'fileformats' set to two formats. - execute('set fileformats=unix,dos') - execute('e! XXUxDsMc') - execute('w! XXtt41') - execute('bwipe XXUxDsMc') - execute('e! XXUxMac') - execute('w! XXtt42') - execute('bwipe XXUxMac') - execute('e! XXDosMac') - execute('w! XXtt43') - execute('bwipe XXDosMac') - execute('set fileformats=unix,mac') - execute('e! XXUxDs') - execute('w! XXtt51') - execute('bwipe XXUxDs') - execute('e! XXUxDsMc') - execute('w! XXtt52') - execute('bwipe XXUxDsMc') - execute('e! XXDosMac') - execute('w! XXtt53') - execute('bwipe XXDosMac') - execute('e! XXEol') + command('set fileformats=unix,dos') + command('e! XXUxDsMc') + command('w! XXtt41') + command('bwipe XXUxDsMc') + command('e! XXUxMac') + command('w! XXtt42') + command('bwipe XXUxMac') + command('e! XXDosMac') + command('w! XXtt43') + command('bwipe XXDosMac') + command('set fileformats=unix,mac') + command('e! XXUxDs') + command('w! XXtt51') + command('bwipe XXUxDs') + command('e! XXUxDsMc') + command('w! XXtt52') + command('bwipe XXUxDsMc') + command('e! XXDosMac') + command('w! XXtt53') + command('bwipe XXDosMac') + command('e! XXEol') feed('ggO=&ffs:=&ff') - execute('w! XXtt54') - execute('bwipe XXEol') - execute('set fileformats=dos,mac') - execute('e! XXUxDs') - execute('w! XXtt61') - execute('bwipe XXUxDs') - execute('e! XXUxMac') + wait() + command('w! XXtt54') + command('bwipe XXEol') + command('set fileformats=dos,mac') + command('e! XXUxDs') + command('w! XXtt61') + command('bwipe XXUxDs') + command('e! XXUxMac') feed('ggO=&ffs:=&ff') - execute('w! XXtt62') - execute('bwipe XXUxMac') - execute('e! XXUxDsMc') - execute('w! XXtt63') - execute('bwipe XXUxDsMc') - execute('e! XXMacEol') + wait() + command('w! XXtt62') + command('bwipe XXUxMac') + command('e! XXUxDsMc') + command('w! XXtt63') + command('bwipe XXUxDsMc') + command('e! XXMacEol') feed('ggO=&ffs:=&ff') - execute('w! XXtt64') - execute('bwipe XXMacEol') + wait() + command('w! XXtt64') + command('bwipe XXMacEol') -- Try reading and writing with 'fileformats' set to three formats. - execute('set fileformats=unix,dos,mac') - execute('e! XXUxDsMc') - execute('w! XXtt71') - execute('bwipe XXUxDsMc') - execute('e! XXEol') + command('set fileformats=unix,dos,mac') + command('e! XXUxDsMc') + command('w! XXtt71') + command('bwipe XXUxDsMc') + command('e! XXEol') feed('ggO=&ffs:=&ff') - execute('w! XXtt72') - execute('bwipe XXEol') - execute('set fileformats=mac,dos,unix') - execute('e! XXUxDsMc') - execute('w! XXtt81') - execute('bwipe XXUxDsMc') - execute('e! XXEol') + wait() + command('w! XXtt72') + command('bwipe XXEol') + command('set fileformats=mac,dos,unix') + command('e! XXUxDsMc') + command('w! XXtt81') + command('bwipe XXUxDsMc') + command('e! XXEol') feed('ggO=&ffs:=&ff') - execute('w! XXtt82') - execute('bwipe XXEol') + wait() + command('w! XXtt82') + command('bwipe XXEol') -- Try with 'binary' set. - execute('set fileformats=mac,unix,dos') - execute('set binary') - execute('e! XXUxDsMc') - execute('w! XXtt91') - execute('bwipe XXUxDsMc') - execute('set fileformats=mac') - execute('e! XXUxDsMc') - execute('w! XXtt92') - execute('bwipe XXUxDsMc') - execute('set fileformats=dos') - execute('e! XXUxDsMc') - execute('w! XXtt93') + command('set fileformats=mac,unix,dos') + command('set binary') + command('e! XXUxDsMc') + command('w! XXtt91') + command('bwipe XXUxDsMc') + command('set fileformats=mac') + command('e! XXUxDsMc') + command('w! XXtt92') + command('bwipe XXUxDsMc') + command('set fileformats=dos') + command('e! XXUxDsMc') + command('w! XXtt93') -- Append "END" to each file so that we can see what the last written -- char was. - execute('set fileformat=unix nobin') + command('set fileformat=unix nobin') feed('ggdGaEND') - execute('w >>XXtt01') - execute('w >>XXtt02') - execute('w >>XXtt11') - execute('w >>XXtt12') - execute('w >>XXtt13') - execute('w >>XXtt21') - execute('w >>XXtt22') - execute('w >>XXtt23') - execute('w >>XXtt31') - execute('w >>XXtt32') - execute('w >>XXtt33') - execute('w >>XXtt41') - execute('w >>XXtt42') - execute('w >>XXtt43') - execute('w >>XXtt51') - execute('w >>XXtt52') - execute('w >>XXtt53') - execute('w >>XXtt54') - execute('w >>XXtt61') - execute('w >>XXtt62') - execute('w >>XXtt63') - execute('w >>XXtt64') - execute('w >>XXtt71') - execute('w >>XXtt72') - execute('w >>XXtt81') - execute('w >>XXtt82') - execute('w >>XXtt91') - execute('w >>XXtt92') - execute('w >>XXtt93') + wait() + command('w >>XXtt01') + command('w >>XXtt02') + command('w >>XXtt11') + command('w >>XXtt12') + command('w >>XXtt13') + command('w >>XXtt21') + command('w >>XXtt22') + command('w >>XXtt23') + command('w >>XXtt31') + command('w >>XXtt32') + command('w >>XXtt33') + command('w >>XXtt41') + command('w >>XXtt42') + command('w >>XXtt43') + command('w >>XXtt51') + command('w >>XXtt52') + command('w >>XXtt53') + command('w >>XXtt54') + command('w >>XXtt61') + command('w >>XXtt62') + command('w >>XXtt63') + command('w >>XXtt64') + command('w >>XXtt71') + command('w >>XXtt72') + command('w >>XXtt81') + command('w >>XXtt82') + command('w >>XXtt91') + command('w >>XXtt92') + command('w >>XXtt93') -- Concatenate the results. -- Make fileformat of test.out the native fileformat. -- Add a newline at the end. - execute('set binary') - execute('e! test.out') - execute('$r XXtt01') - execute('$r XXtt02') + command('set binary') + command('e! test.out') + command('$r XXtt01') + command('$r XXtt02') feed('Go1') - execute('$r XXtt11') - execute('$r XXtt12') - execute('$r XXtt13') + wait() + command('$r XXtt11') + command('$r XXtt12') + command('$r XXtt13') feed('Go2') - execute('$r XXtt21') - execute('$r XXtt22') - execute('$r XXtt23') + wait() + command('$r XXtt21') + command('$r XXtt22') + command('$r XXtt23') feed('Go3') - execute('$r XXtt31') - execute('$r XXtt32') - execute('$r XXtt33') + wait() + command('$r XXtt31') + command('$r XXtt32') + command('$r XXtt33') feed('Go4') - execute('$r XXtt41') - execute('$r XXtt42') - execute('$r XXtt43') + wait() + command('$r XXtt41') + command('$r XXtt42') + command('$r XXtt43') feed('Go5') - execute('$r XXtt51') - execute('$r XXtt52') - execute('$r XXtt53') - execute('$r XXtt54') + wait() + command('$r XXtt51') + command('$r XXtt52') + command('$r XXtt53') + command('$r XXtt54') feed('Go6') - execute('$r XXtt61') - execute('$r XXtt62') - execute('$r XXtt63') - execute('$r XXtt64') + wait() + command('$r XXtt61') + command('$r XXtt62') + command('$r XXtt63') + command('$r XXtt64') feed('Go7') - execute('$r XXtt71') - execute('$r XXtt72') + wait() + command('$r XXtt71') + command('$r XXtt72') feed('Go8') - execute('$r XXtt81') - execute('$r XXtt82') + wait() + command('$r XXtt81') + command('$r XXtt82') feed('Go9') - execute('$r XXtt91') - execute('$r XXtt92') - execute('$r XXtt93') + wait() + command('$r XXtt91') + command('$r XXtt92') + command('$r XXtt93') feed('Go10') - execute('$r XXUnix') - execute('set nobinary ff&') + wait() + command('$r XXUnix') + command('set nobinary ff&') -- Assert buffer contents. This has to be done manually as -- helpers.expect() calls helpers.dedent() which messes up the white space diff --git a/test/functional/legacy/031_close_commands_spec.lua b/test/functional/legacy/031_close_commands_spec.lua index d41eadaa00..64c67c9882 100644 --- a/test/functional/legacy/031_close_commands_spec.lua +++ b/test/functional/legacy/031_close_commands_spec.lua @@ -16,7 +16,7 @@ local clear = helpers.clear local source = helpers.source local insert = helpers.insert local expect = helpers.expect -local execute = helpers.execute +local feed_command = helpers.feed_command describe('Commands that close windows and/or buffers', function() local function cleanup() @@ -38,40 +38,40 @@ describe('Commands that close windows and/or buffers', function() feed('GA 1:$w! Xtest1') feed('$r2:$w! Xtest2') feed('$r3:$w! Xtest3') - execute('n! Xtest1 Xtest2') + feed_command('n! Xtest1 Xtest2') feed('A 1:set hidden') -- Test for working :n when hidden set - execute('n') + feed_command('n') expect('testtext 2') -- Test for failing :rew when hidden not set - execute('set nohidden') + feed_command('set nohidden') feed('A 2:rew') expect('testtext 2 2') -- Test for working :rew when hidden set - execute('set hidden') - execute('rew') + feed_command('set hidden') + feed_command('rew') expect('testtext 1 1') -- Test for :all keeping a buffer when it's modified - execute('set nohidden') + feed_command('set nohidden') feed('A 1:sp') - execute('n Xtest2 Xtest3') - execute('all') - execute('1wincmd w') + feed_command('n Xtest2 Xtest3') + feed_command('all') + feed_command('1wincmd w') expect('testtext 1 1 1') -- Test abandoning changed buffer, should be unloaded even when 'hidden' set - execute('set hidden') + feed_command('set hidden') feed('A 1:q!') expect('testtext 2 2') - execute('unhide') + feed_command('unhide') expect('testtext 2 2') -- Test ":hide" hides anyway when 'hidden' not set - execute('set nohidden') + feed_command('set nohidden') feed('A 2:hide') expect('testtext 3') @@ -80,42 +80,42 @@ describe('Commands that close windows and/or buffers', function() expect('testtext 3 3') -- Test ":edit" working in modified buffer when 'hidden' set - execute('set hidden') - execute('e Xtest1') + feed_command('set hidden') + feed_command('e Xtest1') expect('testtext 1') -- Test ":close" not hiding when 'hidden' not set in modified buffer - execute('sp Xtest3') - execute('set nohidden') + feed_command('sp Xtest3') + feed_command('set nohidden') feed('A 3:close') expect('testtext 3 3 3') -- Test ":close!" does hide when 'hidden' not set in modified buffer feed('A 3:close!') - execute('set nohidden') + feed_command('set nohidden') expect('testtext 1') -- Test ":all!" hides changed buffer - execute('sp Xtest4') + feed_command('sp Xtest4') feed('GA 4:all!') - execute('1wincmd w') + feed_command('1wincmd w') expect('testtext 2 2 2') -- Test ":q!" and hidden buffer. - execute('bw! Xtest1 Xtest2 Xtest3 Xtest4') - execute('sp Xtest1') - execute('wincmd w') - execute('bw!') - execute('set modified') - execute('bot sp Xtest2') - execute('set modified') - execute('bot sp Xtest3') - execute('set modified') - execute('wincmd t') - execute('hide') - execute('q!') + feed_command('bw! Xtest1 Xtest2 Xtest3 Xtest4') + feed_command('sp Xtest1') + feed_command('wincmd w') + feed_command('bw!') + feed_command('set modified') + feed_command('bot sp Xtest2') + feed_command('set modified') + feed_command('bot sp Xtest3') + feed_command('set modified') + feed_command('wincmd t') + feed_command('hide') + feed_command('q!') expect('testtext 3') - execute('q!') + feed_command('q!') feed('') expect('testtext 1') source([[ diff --git a/test/functional/legacy/033_lisp_indent_spec.lua b/test/functional/legacy/033_lisp_indent_spec.lua index b4abb02ac2..2b79ee024b 100644 --- a/test/functional/legacy/033_lisp_indent_spec.lua +++ b/test/functional/legacy/033_lisp_indent_spec.lua @@ -1,10 +1,10 @@ --- vim: set foldmethod=marker foldmarker=[[,]] : -- Test for 'lisp' -- If the lisp feature is not enabled, this will fail! local helpers = require('test.functional.helpers')(after_each) local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local execute, expect = helpers.execute, helpers.expect +local command, expect = helpers.command, helpers.expect +local wait = helpers.wait describe('lisp indent', function() setup(clear) @@ -13,7 +13,7 @@ describe('lisp indent', function() insert([[ (defun html-file (base) (format nil "~(~A~).html" base)) - + (defmacro page (name title &rest body) (let ((ti (gensym))) `(with-open-file (*standard-output* @@ -26,29 +26,30 @@ describe('lisp indent', function() (as h2 (string-upcase ,ti))) (brs 3) ,@body)))) - + ;;; Utilities for generating links - + (defmacro with-link (dest &rest body) `(progn (format t "" (html-file ,dest)) ,@body (princ "")))]]) - execute('set lisp') - execute('/^(defun') + command('set lisp') + command('/^(defun') feed('=G:/^(defun/,$yank A') + wait() -- Put @a and clean empty line - execute('%d') - execute('0put a') - execute('$d') + command('%d') + command('0put a') + command('$d') -- Assert buffer contents. expect([[ (defun html-file (base) (format nil "~(~A~).html" base)) - + (defmacro page (name title &rest body) (let ((ti (gensym))) `(with-open-file (*standard-output* @@ -61,9 +62,9 @@ describe('lisp indent', function() (as h2 (string-upcase ,ti))) (brs 3) ,@body)))) - + ;;; Utilities for generating links - + (defmacro with-link (dest &rest body) `(progn (format t "" (html-file ,dest)) diff --git a/test/functional/legacy/034_user_function_spec.lua b/test/functional/legacy/034_user_function_spec.lua index 38989cd982..0b7dfc4f0e 100644 --- a/test/functional/legacy/034_user_function_spec.lua +++ b/test/functional/legacy/034_user_function_spec.lua @@ -5,7 +5,7 @@ local helpers = require('test.functional.helpers')(after_each) local feed, insert, source = helpers.feed, helpers.insert, helpers.source -local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect +local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect describe('user functions, expr-mappings, overwrite protected builtin functions and regression on calling expressions', function() setup(clear) @@ -72,19 +72,19 @@ describe('user functions, expr-mappings, overwrite protected builtin functions a feed('(one') feed('(two') feed('[(one again') - execute('call append(line("$"), max([1, 2, 3]))') - execute('call extend(g:, {"max": function("min")})') - execute('call append(line("$"), max([1, 2, 3]))') - execute('try') + feed_command('call append(line("$"), max([1, 2, 3]))') + feed_command('call extend(g:, {"max": function("min")})') + feed_command('call append(line("$"), max([1, 2, 3]))') + feed_command('try') -- Regression: the first line below used to throw "E110: Missing ')'" -- Second is here just to prove that this line is correct when not -- skipping rhs of &&. - execute([[ $put =(0&&(function('tr'))(1, 2, 3))]]) - execute([[ $put =(1&&(function('tr'))(1, 2, 3))]]) - execute('catch') - execute([[ $put ='!!! Unexpected exception:']]) - execute(' $put =v:exception') - execute('endtry') + feed_command([[ $put =(0&&(function('tr'))(1, 2, 3))]]) + feed_command([[ $put =(1&&(function('tr'))(1, 2, 3))]]) + feed_command('catch') + feed_command([[ $put ='!!! Unexpected exception:']]) + feed_command(' $put =v:exception') + feed_command('endtry') -- Assert buffer contents. expect([[ diff --git a/test/functional/legacy/035_increment_and_decrement_spec.lua b/test/functional/legacy/035_increment_and_decrement_spec.lua index 3b9f7a9d85..84eb9c0eee 100644 --- a/test/functional/legacy/035_increment_and_decrement_spec.lua +++ b/test/functional/legacy/035_increment_and_decrement_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local execute, expect = helpers.execute, helpers.expect +local feed_command, expect = helpers.feed_command, helpers.expect describe('increment and decrement commands', function() setup(clear) @@ -19,25 +19,25 @@ describe('increment and decrement commands', function() -- Increment and decrement numbers in the first row, interpreting the -- numbers as decimal, octal or hexadecimal. - execute('set nrformats=bin,octal,hex', '1') + feed_command('set nrformats=bin,octal,hex', '1') feed('63l102ll64128$') -- For the second row, treat the numbers as decimal or octal. -- 0x100 should be interpreted as decimal 0, the character x, and decimal 100. - execute('set nrformats=octal', '2') + feed_command('set nrformats=octal', '2') feed('0w102l2w65129blx6lD') -- For the third row, treat the numbers as decimal or hexadecimal. -- 077 should be interpreted as decimal 77. - execute('set nrformats=hex', '3') + feed_command('set nrformats=hex', '3') feed('0101l257Txldt   ') -- For the fourth row, interpret all numbers as decimal. - execute('set nrformats=', '4') + feed_command('set nrformats=', '4') feed('0200l100w78') -- For the last row, interpret as binary and hexadecimal. - execute('set nrformats=bin,hex', '5') + feed_command('set nrformats=bin,hex', '5') feed('010065l6432') expect([[ diff --git a/test/functional/legacy/036_regexp_character_classes_spec.lua b/test/functional/legacy/036_regexp_character_classes_spec.lua index 15287b9901..110f7dd852 100644 --- a/test/functional/legacy/036_regexp_character_classes_spec.lua +++ b/test/functional/legacy/036_regexp_character_classes_spec.lua @@ -1,7 +1,7 @@ -- Test character classes in regexp using regexpengine 0, 1, 2. local helpers = require('test.functional.helpers')(after_each) -local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect +local clear, command, expect = helpers.clear, helpers.command, helpers.expect local source, write_file = helpers.source, helpers.write_file local function sixlines(text) @@ -14,7 +14,7 @@ end local function diff(text, nodedent) local fname = helpers.tmpname() - execute('w! '..fname) + command('w! '..fname) helpers.wait() local data = io.open(fname):read('*all') if nodedent then @@ -45,7 +45,7 @@ describe('character classes in regexp', function() end) before_each(function() clear() - execute('e test36.in') + command('e test36.in') end) teardown(function() os.remove('test36.in') diff --git a/test/functional/legacy/038_virtual_replace_spec.lua b/test/functional/legacy/038_virtual_replace_spec.lua index dcbc9c39f7..2dfc959a8c 100644 --- a/test/functional/legacy/038_virtual_replace_spec.lua +++ b/test/functional/legacy/038_virtual_replace_spec.lua @@ -2,31 +2,31 @@ local helpers = require('test.functional.helpers')(after_each) local feed = helpers.feed -local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect +local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect describe('Virtual replace mode', function() setup(clear) it('is working', function() -- Make sure that backspace works, no matter what termcap is used. - execute('set t_kD=x7f t_kb=x08') + feed_command('set t_kD=x7f t_kb=x08') -- Use vi default for 'smarttab' - execute('set nosmarttab') + feed_command('set nosmarttab') feed('ggdGa') feed('abcdefghi') feed('jklmn') feed('opqrst') feed('uvwxyz') feed('gg') - execute('set ai') - execute('set bs=2') + feed_command('set ai') + feed_command('set bs=2') feed('gR0 1') feed('A') feed('BCDEFGHIJ') feed('KL') feed('MNO') feed('PQRG') - execute('ka') + feed_command('ka') feed('o0') feed('abcdefghi') feed('jklmn') diff --git a/test/functional/legacy/039_visual_block_mode_commands_spec.lua b/test/functional/legacy/039_visual_block_mode_commands_spec.lua index 63335985cc..dffef50950 100644 --- a/test/functional/legacy/039_visual_block_mode_commands_spec.lua +++ b/test/functional/legacy/039_visual_block_mode_commands_spec.lua @@ -5,14 +5,14 @@ local helpers = require('test.functional.helpers')(after_each) local nvim, eq = helpers.meths, helpers.eq local insert, feed = helpers.insert, helpers.feed local clear, expect = helpers.clear, helpers.expect -local execute = helpers.execute +local feed_command = helpers.feed_command describe('Visual block mode', function() before_each(function() clear() - execute('set ts&vi sw&vi sts&vi noet') -- Vim compatible + feed_command('set ts&vi sw&vi sts&vi noet') -- Vim compatible end) it('should shift, insert, replace and change a block', function() @@ -55,9 +55,9 @@ describe('Visual block mode', function() cccc dddd]]) - execute('/^aa') + feed_command('/^aa') feed('ljjjlllI ') - execute('/xaaa$') + feed_command('/xaaa$') feed('jjjI>p') expect([[ @@ -84,13 +84,13 @@ describe('Visual block mode', function() 4567]]) -- Test for Visual block was created with the last $. - execute('/^A23$/') + feed_command('/^A23$/') feed('lj$Aab') -- Test for Visual block was created with the middle $ (1). - execute('/^B23$/') + feed_command('/^B23$/') feed('lj$hAab') -- Test for Visual block was created with the middle $ (2). - execute('/^C23$/') + feed_command('/^C23$/') feed('lj$hhAab') expect([[ @@ -112,8 +112,8 @@ describe('Visual block mode', function() ]]) -- Test for Visual block insert when virtualedit=all and utf-8 encoding. - execute('set ve=all') - execute('/\t\tline') + feed_command('set ve=all') + feed_command('/\t\tline') feed('07ljjIx') expect([[ @@ -199,10 +199,10 @@ describe('Visual block mode', function() 98765]]) -- Test cursor position. When virtualedit=block and Visual block mode and $gj. - execute('set ve=block') + feed_command('set ve=block') feed('G2l') feed('2k$gj') - execute([[let cpos=getpos("'>")]]) + feed_command([[let cpos=getpos("'>")]]) local cpos = nvim.get_var('cpos') local expected = { col = 4, @@ -223,7 +223,7 @@ describe('Visual block mode', function() #define BO_CRSR 0x0004]]) -- Block_insert when replacing spaces in front of the block with tabs. - execute('set ts=8 sts=4 sw=4') + feed_command('set ts=8 sts=4 sw=4') feed('ggf02jI') expect([[ diff --git a/test/functional/legacy/041_writing_and_reading_hundred_kbyte_spec.lua b/test/functional/legacy/041_writing_and_reading_hundred_kbyte_spec.lua index b6451eb720..b526d82519 100644 --- a/test/functional/legacy/041_writing_and_reading_hundred_kbyte_spec.lua +++ b/test/functional/legacy/041_writing_and_reading_hundred_kbyte_spec.lua @@ -1,8 +1,10 @@ -- Test for writing and reading a file of over 100 Kbyte local helpers = require('test.functional.helpers')(after_each) + local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local execute, expect = helpers.execute, helpers.expect +local command, expect = helpers.command, helpers.expect +local wait = helpers.wait describe('writing and reading a file of over 100 Kbyte', function() setup(clear) @@ -16,17 +18,18 @@ describe('writing and reading a file of over 100 Kbyte', function() This is the end]]) feed('kY3000p2GY3000p') + wait() - execute('w! test.out') - execute('%d') - execute('e! test.out') - execute('yank A') - execute('3003yank A') - execute('6005yank A') - execute('%d') - execute('0put a') - execute('$d') - execute('w!') + command('w! test.out') + command('%d') + command('e! test.out') + command('yank A') + command('3003yank A') + command('6005yank A') + command('%d') + command('0put a') + command('$d') + command('w!') expect([[ This is the start diff --git a/test/functional/legacy/043_magic_settings_spec.lua b/test/functional/legacy/043_magic_settings_spec.lua index f174751de2..a88ccc2b42 100644 --- a/test/functional/legacy/043_magic_settings_spec.lua +++ b/test/functional/legacy/043_magic_settings_spec.lua @@ -1,9 +1,8 @@ --- vim: set foldmethod=marker foldmarker=[[,]] : -- Tests for regexp with various magic settings. local helpers = require('test.functional.helpers')(after_each) local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local execute, expect = helpers.execute, helpers.expect +local feed_command, expect = helpers.feed_command, helpers.expect describe('regexp with magic settings', function() setup(clear) @@ -21,27 +20,27 @@ describe('regexp with magic settings', function() 9 foobar ]]) - execute('/^1') - execute([[/a*b\{2}c\+/e]]) + feed_command('/^1') + feed_command([[/a*b\{2}c\+/e]]) feed([[x/\Md\*e\{2}f\+/e]]) feed('x:set nomagic') - execute([[/g\*h\{2}i\+/e]]) + feed_command([[/g\*h\{2}i\+/e]]) feed([[x/\mj*k\{2}l\+/e]]) feed([[x/\vm*n{2}o+/e]]) feed([[x/\V^aa$]]) feed('x:set magic') - execute([[/\v(a)(b)\2\1\1/e]]) + feed_command([[/\v(a)(b)\2\1\1/e]]) feed([[x/\V[ab]\(\[xy]\)\1]]) feed('x:$') - execute('set undolevels=100') + feed_command('set undolevels=100') feed('dv?bar?') feed('Yup:') - execute('?^1?,$yank A') + feed_command('?^1?,$yank A') -- Put @a and clean empty line - execute('%d') - execute('0put a') - execute('$d') + feed_command('%d') + feed_command('0put a') + feed_command('$d') -- Assert buffer contents. expect([[ diff --git a/test/functional/legacy/044_099_regexp_multibyte_magic_spec.lua b/test/functional/legacy/044_099_regexp_multibyte_magic_spec.lua index c6883e4902..074ee094b4 100644 --- a/test/functional/legacy/044_099_regexp_multibyte_magic_spec.lua +++ b/test/functional/legacy/044_099_regexp_multibyte_magic_spec.lua @@ -5,7 +5,7 @@ local helpers = require('test.functional.helpers')(after_each) local feed, insert = helpers.feed, helpers.insert -local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect +local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect -- Runs the test protocol with the given 'regexpengine' setting. In the old test -- suite the test protocol was duplicated in test44 and test99, the only @@ -32,19 +32,19 @@ local function run_test_with_regexpengine(regexpengine) k combinations l ä ö ü ᾱ̆́]]) - execute('set re=' .. regexpengine) + feed_command('set re=' .. regexpengine) -- Lines 1-8. Exercise regexp search with various magic settings. On each -- line the character on which the cursor is expected to land is deleted. feed('/^1') feed([[/a*b\{2}c\+/ex]]) feed([[/\Md\*e\{2}f\+/ex]]) - execute('set nomagic') + feed_command('set nomagic') feed([[/g\*h\{2}i\+/ex]]) feed([[/\mj*k\{2}l\+/ex]]) feed([[/\vm*n{2}o+/ex]]) feed([[/\V^aa$x]]) - execute('set magic') + feed_command('set magic') feed([[/\v(a)(b)\2\1\1/ex]]) feed([[/\V[ab]\(\[xy]\)\1x]]) @@ -57,7 +57,7 @@ local function run_test_with_regexpengine(regexpengine) -- Line b. Find word by change of word class. -- (The "<" character in this test step seemed to confuse our "feed" test -- helper, which is why we've resorted to "execute" here.) - execute([[/ち\<カヨ\>は]]) + feed_command([[/ち\<カヨ\>は]]) feed('x') -- Lines c-i. Test \%u, [\u], and friends. @@ -73,28 +73,28 @@ local function run_test_with_regexpengine(regexpengine) -- Line k. Test substitution with combining characters by executing register -- contents. - execute([[let @w=':%s#comb[i]nations#œ̄ṣ́m̥̄ᾱ̆́#g']]) - execute('@w') + feed_command([[let @w=':%s#comb[i]nations#œ̄ṣ́m̥̄ᾱ̆́#g']]) + feed_command('@w') -- Line l. Ex command ":s/ \?/ /g" should NOT split multi-byte characters -- into bytes (fixed by vim-7.3.192). - execute([[/^l]]) - execute([[s/ \?/ /g]]) + feed_command([[/^l]]) + feed_command([[s/ \?/ /g]]) -- Additional tests. Test matchstr() with multi-byte characters. feed('G') - execute([[put =matchstr(\"אבגד\", \".\", 0, 2)]]) -- ב - execute([[put =matchstr(\"אבגד\", \"..\", 0, 2)]]) -- בג - execute([[put =matchstr(\"אבגד\", \".\", 0, 0)]]) -- א - execute([[put =matchstr(\"אבגד\", \".\", 4, -1)]]) -- ג + feed_command([[put =matchstr(\"אבגד\", \".\", 0, 2)]]) -- ב + feed_command([[put =matchstr(\"אבגד\", \"..\", 0, 2)]]) -- בג + feed_command([[put =matchstr(\"אבגד\", \".\", 0, 0)]]) -- א + feed_command([[put =matchstr(\"אבגד\", \".\", 4, -1)]]) -- ג -- Test that a search with "/e" offset wraps around at the end of the buffer. - execute('new') - execute([[$put =['dog(a', 'cat('] ]]) + feed_command('new') + feed_command([[$put =['dog(a', 'cat('] ]]) feed('/(/e+') feed('"ayn') - execute('bd!') - execute([[$put ='']]) + feed_command('bd!') + feed_command([[$put ='']]) feed('G"ap') -- Assert buffer contents. diff --git a/test/functional/legacy/045_folding_spec.lua b/test/functional/legacy/045_folding_spec.lua index 5c8292c324..6ca1176aea 100644 --- a/test/functional/legacy/045_folding_spec.lua +++ b/test/functional/legacy/045_folding_spec.lua @@ -2,8 +2,8 @@ local Screen = require('test.functional.ui.screen') local helpers = require('test.functional.helpers')(after_each) -local feed, insert, execute, expect_any = - helpers.feed, helpers.insert, helpers.execute, helpers.expect_any +local feed, insert, feed_command, expect_any = + helpers.feed, helpers.insert, helpers.feed_command, helpers.expect_any describe('folding', function() local screen @@ -28,15 +28,15 @@ describe('folding', function() -- Basic test if a fold can be created, opened, moving to the end and -- closed. - execute('1') + feed_command('1') feed('zf2j') - execute('call append("$", "manual " . getline(foldclosed(".")))') + feed_command('call append("$", "manual " . getline(foldclosed(".")))') feed('zo') - execute('call append("$", foldclosed("."))') + feed_command('call append("$", foldclosed("."))') feed(']z') - execute('call append("$", getline("."))') + feed_command('call append("$", getline("."))') feed('zc') - execute('call append("$", getline(foldclosed(".")))') + feed_command('call append("$", getline(foldclosed(".")))') expect_any([[ manual 1 aa @@ -52,15 +52,15 @@ describe('folding', function() ee {{{ }}} ff }}} ]]) - execute('set fdm=marker fdl=1') - execute('2') - execute('call append("$", "line 2 foldlevel=" . foldlevel("."))') + feed_command('set fdm=marker fdl=1') + feed_command('2') + feed_command('call append("$", "line 2 foldlevel=" . foldlevel("."))') feed('[z') - execute('call append("$", foldlevel("."))') + feed_command('call append("$", foldlevel("."))') feed('jo{{ r{jj') -- writes '{{{' and moves 2 lines bot - execute('call append("$", foldlevel("."))') + feed_command('call append("$", foldlevel("."))') feed('kYpj') - execute('call append("$", foldlevel("."))') + feed_command('call append("$", foldlevel("."))') helpers.wait() screen:expect([[ @@ -80,15 +80,15 @@ describe('folding', function() it("foldmethod=indent", function() screen:try_resize(20, 8) - execute('set fdm=indent sw=2') + feed_command('set fdm=indent sw=2') insert([[ aa bb cc last ]]) - execute('call append("$", "foldlevel line3=" . foldlevel(3))') - execute('call append("$", foldlevel(2))') + feed_command('call append("$", "foldlevel line3=" . foldlevel(3))') + feed_command('call append("$", foldlevel(2))') feed('zR') helpers.wait() @@ -119,23 +119,23 @@ describe('folding', function() a jj b kk last]]) - execute('set fdm=syntax fdl=0') - execute('syn region Hup start="dd" end="ii" fold contains=Fd1,Fd2,Fd3') - execute('syn region Fd1 start="ee" end="ff" fold contained') - execute('syn region Fd2 start="gg" end="hh" fold contained') - execute('syn region Fd3 start="commentstart" end="commentend" fold contained') + feed_command('set fdm=syntax fdl=0') + feed_command('syn region Hup start="dd" end="ii" fold contains=Fd1,Fd2,Fd3') + feed_command('syn region Fd1 start="ee" end="ff" fold contained') + feed_command('syn region Fd2 start="gg" end="hh" fold contained') + feed_command('syn region Fd3 start="commentstart" end="commentend" fold contained') feed('Gzk') - execute('call append("$", "folding " . getline("."))') + feed_command('call append("$", "folding " . getline("."))') feed('k') - execute('call append("$", getline("."))') + feed_command('call append("$", getline("."))') feed('jAcommentstart Acommentend') - execute('set fdl=1') + feed_command('set fdl=1') feed('3j') - execute('call append("$", getline("."))') - execute('set fdl=0') + feed_command('call append("$", getline("."))') + feed_command('set fdl=0') feed('zOj') -- redraws screen - execute('call append("$", getline("."))') - execute('set fdl=0') + feed_command('call append("$", getline("."))') + feed_command('set fdl=0') expect_any([[ folding 9 ii 3 cc @@ -158,7 +158,7 @@ describe('folding', function() b kk last ]]) - execute([[ + feed_command([[ fun Flvl() let l = getline(v:lnum) if l =~ "bb$" @@ -173,15 +173,15 @@ describe('folding', function() return "=" endfun ]]) - execute('set fdm=expr fde=Flvl()') - execute('/bb$') - execute('call append("$", "expr " . foldlevel("."))') - execute('/hh$') - execute('call append("$", foldlevel("."))') - execute('/ii$') - execute('call append("$", foldlevel("."))') - execute('/kk$') - execute('call append("$", foldlevel("."))') + feed_command('set fdm=expr fde=Flvl()') + feed_command('/bb$') + feed_command('call append("$", "expr " . foldlevel("."))') + feed_command('/hh$') + feed_command('call append("$", foldlevel("."))') + feed_command('/ii$') + feed_command('call append("$", foldlevel("."))') + feed_command('/kk$') + feed_command('call append("$", foldlevel("."))') expect_any([[ expr 2 @@ -199,11 +199,11 @@ describe('folding', function() Test fdm=indent START line3 line4]]) - execute('set noai nosta ') - execute('set fdm=indent') - execute('1m1') + feed_command('set noai nosta ') + feed_command('set fdm=indent') + feed_command('1m1') feed('2jzc') - execute('m0') + feed_command('m0') feed('zR') expect_any([[ diff --git a/test/functional/legacy/051_highlight_spec.lua b/test/functional/legacy/051_highlight_spec.lua index d4d9b7d997..b98c1ac2d5 100644 --- a/test/functional/legacy/051_highlight_spec.lua +++ b/test/functional/legacy/051_highlight_spec.lua @@ -1,10 +1,9 @@ --- vim: set foldmethod=marker foldmarker=[[,]] : -- Tests for ":highlight". local Screen = require('test.functional.ui.screen') local helpers = require('test.functional.helpers')(after_each) local clear, feed = helpers.clear, helpers.feed -local execute, expect = helpers.execute, helpers.expect +local command, expect = helpers.command, helpers.expect local wait = helpers.wait if helpers.pending_win32(pending) then return end @@ -16,7 +15,7 @@ describe(':highlight', function() local screen = Screen.new(35, 10) screen:attach() -- Basic test if ":highlight" doesn't crash - execute('set more', 'highlight') + command('set more', 'highlight') -- FIXME(tarruda): We need to be sure the prompt is displayed before -- continuing, or risk a race condition where some of the following input -- is discarded resulting in test failure @@ -34,64 +33,64 @@ describe(':highlight', function() ]]) feed('q') wait() -- wait until we're back to normal - execute('hi Search') + command('hi Search') -- Test setting colors. -- Test clearing one color and all doesn't generate error or warning - execute('hi NewGroup cterm=italic ctermfg=DarkBlue ctermbg=Grey gui=NONE guifg=#00ff00 guibg=Cyan') - execute('hi Group2 cterm=NONE') - execute('hi Group3 cterm=bold') - execute('redir! @a') - execute('hi NewGroup') - execute('hi Group2') - execute('hi Group3') - execute('hi clear NewGroup') - execute('hi NewGroup') - execute('hi Group2') - execute('hi Group2 NONE') - execute('hi Group2') - execute('hi clear') - execute('hi Group3') - execute([[hi Crash cterm='asdf]]) - execute('redir END') + command('hi NewGroup cterm=italic ctermfg=DarkBlue ctermbg=Grey gui=NONE guifg=#00ff00 guibg=Cyan') + command('hi Group2 cterm=NONE') + command('hi Group3 cterm=bold') + command('redir! @a') + command('hi NewGroup') + command('hi Group2') + command('hi Group3') + command('hi clear NewGroup') + command('hi NewGroup') + command('hi Group2') + command('hi Group2 NONE') + command('hi Group2') + command('hi clear') + command('hi Group3') + command([[hi Crash cterm='asdf]]) + command('redir END') -- Filter ctermfg and ctermbg, the numbers depend on the terminal - execute('0put a') - execute([[%s/ctermfg=\d*/ctermfg=2/]]) - execute([[%s/ctermbg=\d*/ctermbg=3/]]) + command('0put a') + command([[%s/ctermfg=\d*/ctermfg=2/]]) + command([[%s/ctermbg=\d*/ctermbg=3/]]) -- Filter out possibly translated error message - execute('%s/E475: [^:]*:/E475:/') + command('%s/E475: [^:]*:/E475:/') -- Fix the fileformat - execute('set ff&') - execute('$d') + command('set ff&') + command('$d') -- Assert buffer contents. expect([[ - - + + NewGroup xxx cterm=italic ctermfg=2 ctermbg=3 guifg=#00ff00 guibg=Cyan - + Group2 xxx cleared - + Group3 xxx cterm=bold - - + + NewGroup xxx cleared - + Group2 xxx cleared - - + + Group2 xxx cleared - - + + Group3 xxx cleared - + E475: cterm='asdf]]) screen:detach() end) diff --git a/test/functional/legacy/055_list_and_dict_types_spec.lua b/test/functional/legacy/055_list_and_dict_types_spec.lua index dbe9e1bc7f..e84c415eb0 100644 --- a/test/functional/legacy/055_list_and_dict_types_spec.lua +++ b/test/functional/legacy/055_list_and_dict_types_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local feed, source = helpers.feed, helpers.source -local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect +local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect describe('list and dictionary types', function() before_each(clear) @@ -20,7 +20,7 @@ describe('list and dictionary types', function() $put =v:exception[:14] endtry]]) expect([[ - + [1, 'as''d', [1, 2, function('strlen')], {'a': 1}] {'a': 1} 1 @@ -38,7 +38,7 @@ describe('list and dictionary types', function() $put =string(l[0:8]) $put =string(l[8:-1])]]) expect([=[ - + [1, 'as''d', [1, 2, function('strlen')], {'a': 1}] ['as''d', [1, 2, function('strlen')], {'a': 1}] [1, 'as''d', [1, 2, function('strlen')]] @@ -84,7 +84,7 @@ describe('list and dictionary types', function() call filter(d, 'v:key =~ ''[ac391]''') $put =string(d)]]) expect([[ - + {'1': 'asd', 'b': [1, 2, function('strlen')], '-1': {'a': 1}}asd ['-1', '1', 'b'] ['asd', [1, 2, function('strlen')], {'a': 1}] @@ -134,7 +134,7 @@ describe('list and dictionary types', function() unlet d[-1] $put =string(d)]]) expect([[ - + [1, 'as''d', {'a': 1}] [4] {'1': 99, '3': 33}]]) @@ -142,42 +142,42 @@ describe('list and dictionary types', function() it("removing items out of range: silently skip items that don't exist", function() -- We can not use source() here as we want to ignore all errors. - execute('lang C') - execute('let l = [0, 1, 2, 3]') - execute('unlet l[2:1]') - execute('$put =string(l)') - execute('let l = [0, 1, 2, 3]') - execute('unlet l[2:2]') - execute('$put =string(l)') - execute('let l = [0, 1, 2, 3]') - execute('unlet l[2:3]') - execute('$put =string(l)') - execute('let l = [0, 1, 2, 3]') - execute('unlet l[2:4]') - execute('$put =string(l)') - execute('let l = [0, 1, 2, 3]') - execute('unlet l[2:5]') - execute('$put =string(l)') - execute('let l = [0, 1, 2, 3]') - execute('unlet l[-1:2]') - execute('$put =string(l)') - execute('let l = [0, 1, 2, 3]') - execute('unlet l[-2:2]') - execute('$put =string(l)') - execute('let l = [0, 1, 2, 3]') - execute('unlet l[-3:2]') - execute('$put =string(l)') - execute('let l = [0, 1, 2, 3]') - execute('unlet l[-4:2]') - execute('$put =string(l)') - execute('let l = [0, 1, 2, 3]') - execute('unlet l[-5:2]') - execute('$put =string(l)') - execute('let l = [0, 1, 2, 3]') - execute('unlet l[-6:2]') - execute('$put =string(l)') + feed_command('lang C') + feed_command('let l = [0, 1, 2, 3]') + feed_command('unlet l[2:1]') + feed_command('$put =string(l)') + feed_command('let l = [0, 1, 2, 3]') + feed_command('unlet l[2:2]') + feed_command('$put =string(l)') + feed_command('let l = [0, 1, 2, 3]') + feed_command('unlet l[2:3]') + feed_command('$put =string(l)') + feed_command('let l = [0, 1, 2, 3]') + feed_command('unlet l[2:4]') + feed_command('$put =string(l)') + feed_command('let l = [0, 1, 2, 3]') + feed_command('unlet l[2:5]') + feed_command('$put =string(l)') + feed_command('let l = [0, 1, 2, 3]') + feed_command('unlet l[-1:2]') + feed_command('$put =string(l)') + feed_command('let l = [0, 1, 2, 3]') + feed_command('unlet l[-2:2]') + feed_command('$put =string(l)') + feed_command('let l = [0, 1, 2, 3]') + feed_command('unlet l[-3:2]') + feed_command('$put =string(l)') + feed_command('let l = [0, 1, 2, 3]') + feed_command('unlet l[-4:2]') + feed_command('$put =string(l)') + feed_command('let l = [0, 1, 2, 3]') + feed_command('unlet l[-5:2]') + feed_command('$put =string(l)') + feed_command('let l = [0, 1, 2, 3]') + feed_command('unlet l[-6:2]') + feed_command('$put =string(l)') expect([=[ - + [0, 1, 2, 3] [0, 1, 3] [0, 1] @@ -208,7 +208,7 @@ describe('list and dictionary types', function() $put =v:exception[:14] endtry]]) expect([[ - + 2 3 Vim(let):E687: @@ -257,7 +257,7 @@ describe('list and dictionary types', function() " Must be almost empty now. $put =string(d)]]) expect([[ - + 3000 2900 2001 1600 1501 Vim(let):E716: 1500 NONE 2999 @@ -277,7 +277,7 @@ describe('list and dictionary types', function() let Fn = dict.func call Fn('xxx')]]) expect([[ - + len: 3 again: 3 xxx3]]) @@ -324,7 +324,7 @@ describe('list and dictionary types', function() let l3 = deepcopy(l2) $put ='same list: ' . (l3[1] is l3[2])]]) expect([[ - + Vim(let):E698: same list: 1]]) end) @@ -394,7 +394,7 @@ describe('list and dictionary types', function() endfor endfor]=]) expect([[ - + depth is 0 0000-000 ppppppp @@ -499,7 +499,7 @@ describe('list and dictionary types', function() endfor endfor]=]) expect([[ - + depth is 0 0000-000 ppppppp @@ -647,7 +647,7 @@ describe('list and dictionary types', function() $put =string(l)]]) expect([=[ - + Locks and commands or functions: No :unlet after lock on dict: Vim(unlet):E741: @@ -676,7 +676,7 @@ describe('list and dictionary types', function() end) it('locked variables (part 2)', function() - execute( + feed_command( 'let l = [1, 2, 3, 4]', 'lockvar! l', '$put =string(l)', @@ -691,7 +691,7 @@ describe('list and dictionary types', function() 'let l[1:2] = [0, 1]', '$put =string(l)') expect([=[ - + [1, 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4] @@ -708,7 +708,7 @@ describe('list and dictionary types', function() $put ='exists g:footest#x:'.exists('g:footest#x') $put ='g:footest#x: '.g:footest#x]]) expect([[ - + locked g:footest#x:-1 exists g:footest#x:0 g:footest#x: 1]]) @@ -749,9 +749,9 @@ describe('list and dictionary types', function() $put ='caught ' . v:exception endtry endfunction]]) - execute('call Test(1, 2, [3, 4], {5: 6})') + feed_command('call Test(1, 2, [3, 4], {5: 6})') expect([=[ - + caught a:000 caught a:000[0] caught a:000[2] @@ -779,7 +779,7 @@ describe('list and dictionary types', function() $put =string(sort(copy(l), 'i')) $put =string(sort(copy(l)))]=]) expect([=[ - + ['-0', 'A11', 2, 'xaaa', 4, 'foo', 'foo6', 'foo', [0, 1, 2], 'x8', [0, 1, 2], 1.5] [1.5, [0, 1, 2], 'x8', [0, 1, 2], 'foo', 'foo6', 'foo', 4, 'xaaa', 2, 2, 'A11', '-0'] [1.5, [0, 1, 2], 'x8', [0, 1, 2], 'foo', 'foo6', 'foo', 4, 'xaaa', 2, 2, 'A11', '-0'] @@ -805,7 +805,7 @@ describe('list and dictionary types', function() $put =string(split('abc', '\zs')) $put =string(split('abc', '\zs', 1))]]) expect([=[ - + ['aa', 'bb'] ['aa', 'bb'] ['', 'aa', 'bb', ''] @@ -827,7 +827,7 @@ describe('list and dictionary types', function() $put =(l != deepcopy(l)) $put =(d != deepcopy(d))]]) expect([[ - + 1 1 0 @@ -845,7 +845,7 @@ describe('list and dictionary types', function() $put =(l == lcopy) $put =(dict4 == dict4copy)]]) expect([[ - + 1 1]]) end) @@ -856,7 +856,7 @@ describe('list and dictionary types', function() call extend(l, l) $put =string(l)]]) expect([=[ - + [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]]=]) end) @@ -866,7 +866,7 @@ describe('list and dictionary types', function() call extend(d, d) $put =string(d)]]) expect([[ - + {'a': {'b': 'B'}}]]) end) @@ -881,7 +881,7 @@ describe('list and dictionary types', function() endtry $put =string(d)]]) expect([[ - + Vim(call):E737: a {'a': {'b': 'B'}}]]) end) @@ -892,29 +892,29 @@ describe('list and dictionary types', function() let l[:] = [1, 2] $put =string(l)]]) expect([=[ - + [1, 2]]=]) end) it('vim patch 7.3.637', function() - execute('let a = "No error caught"') - execute('try') - execute(' foldopen') - execute('catch') - execute(" let a = matchstr(v:exception,'^[^ ]*')") - execute('endtry') + feed_command('let a = "No error caught"') + feed_command('try') + feed_command(' foldopen') + feed_command('catch') + feed_command(" let a = matchstr(v:exception,'^[^ ]*')") + feed_command('endtry') feed('o=a') - execute('lang C') - execute('redir => a') + feed_command('lang C') + feed_command('redir => a') -- The test failes if this is not in one line. - execute("try|foobar|catch|let a = matchstr(v:exception,'^[^ ]*')|endtry") - execute('redir END') + feed_command("try|foobar|catch|let a = matchstr(v:exception,'^[^ ]*')|endtry") + feed_command('redir END') feed('o=a') expect([[ - + Vim(foldopen):E490: - - + + Error detected while processing : E492: Not an editor command: foobar|catch|let a = matchstr(v:exception,'^[^ ]*')|endtry ]]) diff --git a/test/functional/legacy/057_sort_spec.lua b/test/functional/legacy/057_sort_spec.lua index 6984ad0de2..b3343d3af0 100644 --- a/test/functional/legacy/057_sort_spec.lua +++ b/test/functional/legacy/057_sort_spec.lua @@ -1,9 +1,11 @@ -- Tests for :sort command. local helpers = require('test.functional.helpers')(after_each) -local insert, execute, clear, expect, eq, eval, source = helpers.insert, - helpers.execute, helpers.clear, helpers.expect, helpers.eq, helpers.eval, - helpers.source + +local insert, command, clear, expect, eq, eval, wait = helpers.insert, + helpers.command, helpers.clear, helpers.expect, helpers.eq, helpers.eval, + helpers.wait +local exc_exec = helpers.exc_exec describe(':sort', function() local text = [[ @@ -26,9 +28,10 @@ describe(':sort', function() it('alphabetical', function() insert(text) - execute('sort') + wait() + command('sort') expect([[ - + 123b a a122 @@ -65,12 +68,13 @@ describe(':sort', function() b321 b321b ]]) - execute('sort n') + wait() + command('sort n') expect([[ abc ab a - + -24 x-22 0 @@ -89,9 +93,10 @@ describe(':sort', function() it('hexadecimal', function() insert(text) - execute('sort x') + wait() + command('sort x') expect([[ - + a ab abc @@ -110,9 +115,10 @@ describe(':sort', function() it('alphabetical, unique', function() insert(text) - execute('sort u') + wait() + command('sort u') expect([[ - + 123b a a122 @@ -130,7 +136,8 @@ describe(':sort', function() it('alphabetical, reverse', function() insert(text) - execute('sort!') + wait() + command('sort!') expect([[ c321d c123d @@ -151,7 +158,8 @@ describe(':sort', function() it('numerical, reverse', function() insert(text) - execute('sort! n') + wait() + command('sort! n') expect([[ b322b b321b @@ -164,7 +172,7 @@ describe(':sort', function() b123 a123 a122 - + a ab abc]]) @@ -172,7 +180,8 @@ describe(':sort', function() it('unique, reverse', function() insert(text) - execute('sort! u') + wait() + command('sort! u') expect([[ c321d c123d @@ -192,12 +201,13 @@ describe(':sort', function() it('octal', function() insert(text) - execute('sort o') + wait() + command('sort o') expect([[ abc ab a - + a122 a123 b123 @@ -213,7 +223,8 @@ describe(':sort', function() it('reverse, hexadecimal', function() insert(text) - execute('sort! x') + wait() + command('sort! x') expect([[ c321d c123d @@ -234,10 +245,11 @@ describe(':sort', function() it('alphabetical, skip first character', function() insert(text) - execute('sort/./') + wait() + command('sort/./') expect([[ a - + a122 a123 b123 @@ -255,11 +267,12 @@ describe(':sort', function() it('alphabetical, skip first 2 characters', function() insert(text) - execute('sort/../') + wait() + command('sort/../') expect([[ ab a - + a321 b321 b321 @@ -276,11 +289,12 @@ describe(':sort', function() it('alphabetical, unique, skip first 2 characters', function() insert(text) - execute('sort/../u') + wait() + command('sort/../u') expect([[ ab a - + a321 b321 b321b @@ -296,12 +310,13 @@ describe(':sort', function() it('numerical, skip first character', function() insert(text) - execute('sort/./n') + wait() + command('sort/./n') expect([[ abc ab a - + a122 a123 b123 @@ -317,9 +332,10 @@ describe(':sort', function() it('alphabetical, sort on first character', function() insert(text) - execute('sort/./r') + wait() + command('sort/./r') expect([[ - + 123b abc ab @@ -338,10 +354,11 @@ describe(':sort', function() it('alphabetical, sort on first 2 characters', function() insert(text) - execute('sort/../r') + wait() + command('sort/../r') expect([[ a - + 123b a123 a122 @@ -359,7 +376,8 @@ describe(':sort', function() it('numerical, sort on first character', function() insert(text) - execute('sort/./rn') + wait() + command('sort/./rn') expect([[ abc ab @@ -380,12 +398,13 @@ describe(':sort', function() it('alphabetical, skip past first digit', function() insert(text) - execute([[sort/\d/]]) + wait() + command([[sort/\d/]]) expect([[ abc ab a - + a321 b321 b321 @@ -401,12 +420,13 @@ describe(':sort', function() it('alphabetical, sort on first digit', function() insert(text) - execute([[sort/\d/r]]) + wait() + command([[sort/\d/r]]) expect([[ abc ab a - + a123 a122 b123 @@ -422,12 +442,13 @@ describe(':sort', function() it('numerical, skip past first digit', function() insert(text) - execute([[sort/\d/n]]) + wait() + command([[sort/\d/n]]) expect([[ abc ab a - + a321 b321 c321d @@ -443,12 +464,13 @@ describe(':sort', function() it('numerical, sort on first digit', function() insert(text) - execute([[sort/\d/rn]]) + wait() + command([[sort/\d/rn]]) expect([[ abc ab a - + a123 a122 b123 @@ -464,12 +486,13 @@ describe(':sort', function() it('alphabetical, skip past first 2 digits', function() insert(text) - execute([[sort/\d\d/]]) + wait() + command([[sort/\d\d/]]) expect([[ abc ab a - + a321 b321 b321 @@ -485,12 +508,13 @@ describe(':sort', function() it('numerical, skip past first 2 digits', function() insert(text) - execute([[sort/\d\d/n]]) + wait() + command([[sort/\d\d/n]]) expect([[ abc ab a - + a321 b321 c321d @@ -506,12 +530,13 @@ describe(':sort', function() it('hexadecimal, skip past first 2 digits', function() insert(text) - execute([[sort/\d\d/x]]) + wait() + command([[sort/\d\d/x]]) expect([[ abc ab a - + a321 b321 b321 @@ -527,12 +552,13 @@ describe(':sort', function() it('alpha, on first 2 digits', function() insert(text) - execute([[sort/\d\d/r]]) + wait() + command([[sort/\d\d/r]]) expect([[ abc ab a - + a123 a122 b123 @@ -548,12 +574,13 @@ describe(':sort', function() it('numeric, on first 2 digits', function() insert(text) - execute([[sort/\d\d/rn]]) + wait() + command([[sort/\d\d/rn]]) expect([[ abc ab a - + a123 a122 b123 @@ -569,12 +596,13 @@ describe(':sort', function() it('hexadecimal, on first 2 digits', function() insert(text) - execute([[sort/\d\d/rx]]) + wait() + command([[sort/\d\d/rx]]) expect([[ abc ab a - + a123 a122 b123 @@ -591,13 +619,7 @@ describe(':sort', function() it('fails with wrong arguments', function() insert(text) -- This should fail with "E474: Invalid argument". - source([[ - try - sort no - catch - let tmpvar = v:exception - endtry]]) - eq('Vim(sort):E474: Invalid argument', eval('tmpvar')) + eq('Vim(sort):E474: Invalid argument', exc_exec('sort no')) expect(text) end) @@ -617,7 +639,8 @@ describe(':sort', function() 0b100010 0b100100 0b100010]]) - execute([[sort b]]) + wait() + command([[sort b]]) expect([[ 0b000000 0b001000 @@ -651,7 +674,8 @@ describe(':sort', function() 0b101010 0b000000 b0b111000]]) - execute([[sort b]]) + wait() + command([[sort b]]) expect([[ 0b000000 a0b001000 @@ -677,7 +701,8 @@ describe(':sort', function() 1.15e-6 -1.1e3 -1.01e3]]) - execute([[sort f]]) + wait() + command([[sort f]]) expect([[ -1.1e3 -1.01e3 diff --git a/test/functional/legacy/059_utf8_spell_checking_spec.lua b/test/functional/legacy/059_utf8_spell_checking_spec.lua index 2fb8f3557d..120e469ab2 100644 --- a/test/functional/legacy/059_utf8_spell_checking_spec.lua +++ b/test/functional/legacy/059_utf8_spell_checking_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local feed, insert, source = helpers.feed, helpers.insert, helpers.source -local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect +local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect local write_file, call = helpers.write_file, helpers.call if helpers.pending_win32(pending) then return end @@ -15,44 +15,44 @@ end describe("spell checking with 'encoding' set to utf-8", function() setup(function() clear() - execute("syntax off") + feed_command("syntax off") write_latin1('Xtest1.aff',[[ SET ISO8859-1 TRY esianrtolcdugmphbyfvkwjkqxz-ëéèêïîäàâöüû'ESIANRTOLCDUGMPHBYFVKWJKQXZ - + FOL àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþßÿ LOW àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþßÿ UPP ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßÿ - + SOFOFROM abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþßÿÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ¿ SOFOTO ebctefghejklnnepkrstevvkesebctefghejklnnepkrstevvkeseeeeeeeceeeeeeeedneeeeeeeeeeepseeeeeeeeceeeeeeeedneeeeeeeeeeep? - + MIDWORD '- - + KEP = RAR ? BAD ! - + PFX I N 1 PFX I 0 in . - + PFX O Y 1 PFX O 0 out . - + SFX S Y 2 SFX S 0 s [^s] SFX S 0 es s - + SFX N N 3 SFX N 0 en [^n] SFX N 0 nen n SFX N 0 n . - + REP 3 REP g ch REP ch g REP svp s.v.p. - + MAP 9 MAP aàáâãäå MAP eèéêë @@ -79,39 +79,39 @@ describe("spell checking with 'encoding' set to utf-8", function() ]]) write_latin1('Xtest2.aff', [[ SET ISO8859-1 - + FOL àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþßÿ LOW àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþßÿ UPP ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßÿ - + PFXPOSTPONE - + MIDWORD '- - + KEP = RAR ? BAD ! - + PFX I N 1 PFX I 0 in . - + PFX O Y 1 PFX O 0 out [a-z] - + SFX S Y 2 SFX S 0 s [^s] SFX S 0 es s - + SFX N N 3 SFX N 0 en [^n] SFX N 0 nen n SFX N 0 n . - + REP 3 REP g ch REP ch g REP svp s.v.p. - + MAP 9 MAP aàáâãäå MAP eèéêë @@ -125,7 +125,7 @@ describe("spell checking with 'encoding' set to utf-8", function() ]]) write_latin1('Xtest3.aff', [[ SET ISO8859-1 - + COMPOUNDMIN 3 COMPOUNDRULE m* NEEDCOMPOUND x @@ -139,21 +139,21 @@ describe("spell checking with 'encoding' set to utf-8", function() ]]) write_latin1('Xtest4.aff', [[ SET ISO8859-1 - + FOL àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþßÿ LOW àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþßÿ UPP ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßÿ - + COMPOUNDRULE m+ COMPOUNDRULE sm*e COMPOUNDRULE sm+ COMPOUNDMIN 3 COMPOUNDWORDMAX 3 COMPOUNDFORBIDFLAG t - + COMPOUNDSYLMAX 5 SYLLABLE aáeéiíoóöõuúüûy/aa/au/ea/ee/ei/ie/oa/oe/oo/ou/uu/ui - + MAP 9 MAP aàáâãäå MAP eèéêë @@ -164,23 +164,23 @@ describe("spell checking with 'encoding' set to utf-8", function() MAP cç MAP yÿý MAP sß - + NEEDAFFIX x - + PFXPOSTPONE - + MIDWORD '- - + SFX q N 1 SFX q 0 -ok . - + SFX a Y 2 SFX a 0 s . SFX a 0 ize/t . - + PFX p N 1 PFX p 0 pre . - + PFX P N 1 PFX P 0 nou . ]]) @@ -196,28 +196,28 @@ describe("spell checking with 'encoding' set to utf-8", function() ]]) write_latin1('Xtest5.aff', [[ SET ISO8859-1 - + FLAG long - + NEEDAFFIX !! - + COMPOUNDRULE ssmm*ee - + NEEDCOMPOUND xx COMPOUNDPERMITFLAG pp - + SFX 13 Y 1 SFX 13 0 bork . - + SFX a1 Y 1 SFX a1 0 a1 . - + SFX aé Y 1 SFX aé 0 aé . - + PFX zz Y 1 PFX zz 0 pre/pp . - + PFX yy Y 1 PFX yy 0 nou . ]]) @@ -231,26 +231,26 @@ describe("spell checking with 'encoding' set to utf-8", function() ]]) write_latin1('Xtest6.aff', [[ SET ISO8859-1 - + FLAG caplong - + NEEDAFFIX A! - + COMPOUNDRULE sMm*Ee - + NEEDCOMPOUND Xx - + COMPOUNDPERMITFLAG p - + SFX N3 Y 1 SFX N3 0 bork . - + SFX A1 Y 1 SFX A1 0 a1 . - + SFX Aé Y 1 SFX Aé 0 aé . - + PFX Zz Y 1 PFX Zz 0 pre/p . ]]) @@ -264,29 +264,29 @@ describe("spell checking with 'encoding' set to utf-8", function() ]]) write_latin1('Xtest7.aff', [[ SET ISO8859-1 - + FOL àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþßÿ LOW àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþßÿ UPP ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßÿ - + FLAG num - + NEEDAFFIX 9999 - + COMPOUNDRULE 2,77*123 - + NEEDCOMPOUND 1 COMPOUNDPERMITFLAG 432 - + SFX 61003 Y 1 SFX 61003 0 meat . - + SFX 391 Y 1 SFX 391 0 a1 . - + SFX 111 Y 1 SFX 111 0 aé . - + PFX 17 Y 1 PFX 17 0 pre/432 . ]]) @@ -300,7 +300,7 @@ describe("spell checking with 'encoding' set to utf-8", function() ]]) write_latin1('Xtest8.aff', [[ SET ISO8859-1 - + NOSPLITSUGS ]]) write_latin1('Xtest8.dic', [[ @@ -319,37 +319,37 @@ describe("spell checking with 'encoding' set to utf-8", function() write_latin1('Xtest-sal.aff', [[ SET ISO8859-1 TRY esianrtolcdugmphbyfvkwjkqxz-ëéèêïîäàâöüû'ESIANRTOLCDUGMPHBYFVKWJKQXZ - + FOL àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþßÿ LOW àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþßÿ UPP ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßÿ - + MIDWORD '- - + KEP = RAR ? BAD ! - + PFX I N 1 PFX I 0 in . - + PFX O Y 1 PFX O 0 out . - + SFX S Y 2 SFX S 0 s [^s] SFX S 0 es s - + SFX N N 3 SFX N 0 en [^n] SFX N 0 nen n SFX N 0 n . - + REP 3 REP g ch REP ch g REP svp s.v.p. - + MAP 9 MAP aàáâãäå MAP eèéêë @@ -360,7 +360,7 @@ describe("spell checking with 'encoding' set to utf-8", function() MAP cç MAP yÿý MAP sß - + SAL AH(AEIOUY)-^ *H SAL AR(AEIOUY)-^ *R SAL A(HR)^ * @@ -550,60 +550,60 @@ describe("spell checking with 'encoding' set to utf-8", function() 1good: wrong OK puts. Test the end bad: inputs comment ok Ok. test déôl end the badend - + test2: elequint test elekwint test elekwent asdf ]]) test_one(1, 1) - execute([[$put =soundfold('goobledygoook')]]) - execute([[$put =soundfold('kóopërÿnôven')]]) - execute([[$put =soundfold('oeverloos gezwets edale')]]) + feed_command([[$put =soundfold('goobledygoook')]]) + feed_command([[$put =soundfold('kóopërÿnôven')]]) + feed_command([[$put =soundfold('oeverloos gezwets edale')]]) -- And now with SAL instead of SOFO items; test automatic reloading. os.execute('cp -f Xtest-sal.aff Xtest.aff') - execute('mkspell! Xtest Xtest') - execute([[$put =soundfold('goobledygoook')]]) - execute([[$put =soundfold('kóopërÿnôven')]]) - execute([[$put =soundfold('oeverloos gezwets edale')]]) + feed_command('mkspell! Xtest Xtest') + feed_command([[$put =soundfold('goobledygoook')]]) + feed_command([[$put =soundfold('kóopërÿnôven')]]) + feed_command([[$put =soundfold('oeverloos gezwets edale')]]) -- Also use an addition file. - execute('mkspell! Xtest.utf-8.add.spl Xtest.utf-8.add') - execute('set spellfile=Xtest.utf-8.add') - execute('/^test2:') + feed_command('mkspell! Xtest.utf-8.add.spl Xtest.utf-8.add') + feed_command('set spellfile=Xtest.utf-8.add') + feed_command('/^test2:') feed(']s') - execute('let [str, a] = spellbadword()') - execute('$put =str') - execute('set spl=Xtest_us.utf-8.spl') - execute('/^test2:') + feed_command('let [str, a] = spellbadword()') + feed_command('$put =str') + feed_command('set spl=Xtest_us.utf-8.spl') + feed_command('/^test2:') feed(']smm') - execute('let [str, a] = spellbadword()') - execute('$put =str') + feed_command('let [str, a] = spellbadword()') + feed_command('$put =str') feed('`m]s') - execute('let [str, a] = spellbadword()') - execute('$put =str') - execute('set spl=Xtest_gb.utf-8.spl') - execute('/^test2:') + feed_command('let [str, a] = spellbadword()') + feed_command('$put =str') + feed_command('set spl=Xtest_gb.utf-8.spl') + feed_command('/^test2:') feed(']smm') - execute('let [str, a] = spellbadword()') - execute('$put =str') + feed_command('let [str, a] = spellbadword()') + feed_command('$put =str') feed('`m]s') - execute('let [str, a] = spellbadword()') - execute('$put =str') - execute('set spl=Xtest_nz.utf-8.spl') - execute('/^test2:') + feed_command('let [str, a] = spellbadword()') + feed_command('$put =str') + feed_command('set spl=Xtest_nz.utf-8.spl') + feed_command('/^test2:') feed(']smm') - execute('let [str, a] = spellbadword()') - execute('$put =str') + feed_command('let [str, a] = spellbadword()') + feed_command('$put =str') feed('`m]s') - execute('let [str, a] = spellbadword()') - execute('$put =str') - execute('set spl=Xtest_ca.utf-8.spl') - execute('/^test2:') + feed_command('let [str, a] = spellbadword()') + feed_command('$put =str') + feed_command('set spl=Xtest_ca.utf-8.spl') + feed_command('/^test2:') feed(']smm') - execute('let [str, a] = spellbadword()') - execute('$put =str') + feed_command('let [str, a] = spellbadword()') + feed_command('$put =str') feed('`m]s') - execute('let [str, a] = spellbadword()') - execute('$put =str') - execute('1,/^test 1-1/-1d') + feed_command('let [str, a] = spellbadword()') + feed_command('$put =str') + feed_command('1,/^test 1-1/-1d') expect([[ test 1-1 # file: Xtest.utf-8.spl @@ -667,7 +667,7 @@ describe("spell checking with 'encoding' set to utf-8", function() ]]) -- Postponed prefixes. test_one(2, 1) - execute('1,/^test 2-1/-1d') + feed_command('1,/^test 2-1/-1d') expect([=[ test 2-1 # file: Xtest.utf-8.spl @@ -711,13 +711,13 @@ describe("spell checking with 'encoding' set to utf-8", function() it('part 3-3', function() insert([[ Test rules for compounding. - + 3good: foo mï foobar foofoobar barfoo barbarfoo bad: bar la foomï barmï mïfoo mïbar mïmï lala mïla lamï foola labar badend ]]) test_one(3, 3) - execute('1,/^test 3-3/-1d') + feed_command('1,/^test 3-3/-1d') expect([=[ test 3-3 # file: Xtest.utf-8.spl @@ -755,7 +755,7 @@ describe("spell checking with 'encoding' set to utf-8", function() it('part 4-4', function() insert([[ Tests for compounding. - + 4good: word util bork prebork start end wordutil wordutils pro-ok bork borkbork borkborkbork borkborkborkbork borkborkborkborkbork tomato tomatotomato startend startword startwordword startwordend @@ -770,7 +770,7 @@ describe("spell checking with 'encoding' set to utf-8", function() badend ]]) test_one(4, 4) - execute('1,/^test 4-4/-1d') + feed_command('1,/^test 4-4/-1d') expect([=[ test 4-4 # file: Xtest.utf-8.spl @@ -823,7 +823,7 @@ describe("spell checking with 'encoding' set to utf-8", function() it('part 5-5', function() insert([[ Test affix flags with two characters - + 5good: fooa1 fooaé bar prebar barbork prebarbork startprebar start end startend startmiddleend nouend bad: foo fooa2 prabar probarbirk middle startmiddle middleend endstart @@ -831,7 +831,7 @@ describe("spell checking with 'encoding' set to utf-8", function() badend ]]) test_one(5, 5) - execute('1,/^test 5-5/-1d') + feed_command('1,/^test 5-5/-1d') expect([=[ test 5-5 # file: Xtest.utf-8.spl @@ -878,7 +878,7 @@ describe("spell checking with 'encoding' set to utf-8", function() badend ]]) test_one(6, 6) - execute('1,/^test 6-6/-1d') + feed_command('1,/^test 6-6/-1d') expect([=[ test 6-6 # file: Xtest.utf-8.spl @@ -924,7 +924,7 @@ describe("spell checking with 'encoding' set to utf-8", function() -- Compound words. test_one(7, 7) -- Assert buffer contents. - execute('1,/^test 7-7/-1d') + feed_command('1,/^test 7-7/-1d') expect([=[ test 7-7 # file: Xtest.utf-8.spl @@ -968,7 +968,7 @@ describe("spell checking with 'encoding' set to utf-8", function() -- NOSPLITSUGS test_one(8, 8) -- Assert buffer contents. - execute('1,/^test 8-8/-1d') + feed_command('1,/^test 8-8/-1d') expect([=[ test 8-8 # file: Xtest.utf-8.spl @@ -992,7 +992,7 @@ describe("spell checking with 'encoding' set to utf-8", function() -- NOSPLITSUGS test_one(9, 9) -- Assert buffer contents. - execute('1,/^test 9-9/-1d') + feed_command('1,/^test 9-9/-1d') expect([=[ test 9-9 # file: Xtest.utf-8.spl diff --git a/test/functional/legacy/061_undo_tree_spec.lua b/test/functional/legacy/061_undo_tree_spec.lua index aeb2001d11..1a8ef067d0 100644 --- a/test/functional/legacy/061_undo_tree_spec.lua +++ b/test/functional/legacy/061_undo_tree_spec.lua @@ -1,8 +1,8 @@ -- Tests for undo tree and :earlier and :later. local helpers = require('test.functional.helpers')(after_each) +local feed_command = helpers.feed_command local write_file = helpers.write_file -local execute = helpers.execute local command = helpers.command local source = helpers.source local expect = helpers.expect @@ -44,7 +44,7 @@ describe('undo tree:', function() -- function to allow multiple attempts. local function test_earlier_later() clear() - execute('e Xtest') + feed_command('e Xtest') -- Assert that no undo history is present. eq({}, eval('undotree().entries')) -- Delete three characters and undo. @@ -88,13 +88,13 @@ describe('undo tree:', function() feed('Ab') feed('Ac') expect_line('123456abc') - execute('earlier 1s') + feed_command('earlier 1s') expect_line('123456') - execute('earlier 3s') + feed_command('earlier 3s') expect_line('123456789') - execute('later 1s') + feed_command('later 1s') expect_line('123456') - execute('later 1h') + feed_command('later 1h') expect_line('123456abc') end @@ -103,28 +103,28 @@ describe('undo tree:', function() it('file-write specifications', function() feed('ione one one') - execute('w Xtest') + feed_command('w Xtest') feed('otwo') feed('otwo') - execute('w') + feed_command('w') feed('othree') - execute('earlier 1f') + feed_command('earlier 1f') expect([[ one one one two two]]) - execute('earlier 1f') + feed_command('earlier 1f') expect('one one one') - execute('earlier 1f') + feed_command('earlier 1f') expect_empty_buffer() - execute('later 1f') + feed_command('later 1f') expect('one one one') - execute('later 1f') + feed_command('later 1f') expect([[ one one one two two]]) - execute('later 1f') + feed_command('later 1f') expect([[ one one one two @@ -193,20 +193,20 @@ describe('undo tree:', function() feed('ob') feed([[o1a2=setline('.','1234')]]) expect([[ - + a b 12034]]) feed('uu') expect([[ - + a b 1]]) feed('oc') feed([[o1a2=setline('.','1234')]]) expect([[ - + a b 1 @@ -214,16 +214,16 @@ describe('undo tree:', function() 12034]]) feed('u') expect([[ - + a b 1 c 12]]) feed('od') - execute('so! Xtest.source') + feed_command('so! Xtest.source') expect([[ - + a b 1 @@ -233,7 +233,7 @@ describe('undo tree:', function() 12123]]) feed('u') expect([[ - + a b 1 @@ -246,7 +246,7 @@ describe('undo tree:', function() -- interactive use (even in Vim; see ":help :undojoin"): feed(normal_commands) expect([[ - + a b 1 @@ -256,7 +256,7 @@ describe('undo tree:', function() 12123]]) feed('u') expect([[ - + a b 1 diff --git a/test/functional/legacy/062_tab_pages_spec.lua b/test/functional/legacy/062_tab_pages_spec.lua index 71a0a77354..9435913b53 100644 --- a/test/functional/legacy/062_tab_pages_spec.lua +++ b/test/functional/legacy/062_tab_pages_spec.lua @@ -1,17 +1,17 @@ -- Tests for tab pages local helpers = require('test.functional.helpers')(after_each) -local feed, insert, source, clear, execute, expect, eval, eq = +local feed, insert, source, clear, command, expect, eval, eq = helpers.feed, helpers.insert, helpers.source, helpers.clear, - helpers.execute, helpers.expect, helpers.eval, helpers.eq + helpers.command, helpers.expect, helpers.eval, helpers.eq describe('tab pages', function() before_each(clear) it('can be opened and closed', function() - execute('tabnew') + command('tabnew') eq(2, eval('tabpagenr()')) - execute('quit') + command('quit') eq(1, eval('tabpagenr()')) end) @@ -25,7 +25,7 @@ describe('tab pages', function() tabrewind ]]) eq('this is tab page 1', eval("getline('$')")) - execute('tablast') + command('tablast') eq('this is tab page 4', eval("getline('$')")) end) @@ -44,7 +44,7 @@ describe('tab pages', function() eq(100, eval('gettabvar(2, "val_num")')) eq('SetTabVar test', eval('gettabvar(2, "val_str")')) eq({'red', 'blue', 'green'}, eval('gettabvar(2, "val_list")')) - execute('tabnext 2') + command('tabnext 2') eq(100, eval('t:val_num')) eq('SetTabVar test', eval('t:val_str')) eq({'red', 'blue', 'green'}, eval('t:val_list')) @@ -52,8 +52,8 @@ describe('tab pages', function() it('work together with the drop feature and loaded buffers', function() -- Test for ":tab drop exist-file" to keep current window. - execute('sp test1') - execute('tab drop test1') + command('sp test1') + command('tab drop test1') eq(1, eval('tabpagenr("$")')) eq(2, eval('winnr("$")')) eq(1, eval('winnr()')) @@ -61,8 +61,8 @@ describe('tab pages', function() it('work together with the drop feature and new files', function() -- Test for ":tab drop new-file" to keep current window of tabpage 1. - execute('split') - execute('tab drop newfile') + command('split') + command('tab drop newfile') eq(2, eval('tabpagenr("$")')) eq(2, eval('tabpagewinnr(1, "$")')) eq(1, eval('tabpagewinnr(1)')) @@ -71,52 +71,52 @@ describe('tab pages', function() it('work together with the drop feature and multi loaded buffers', function() -- Test for ":tab drop multi-opend-file" to keep current tabpage and -- window. - execute('new test1') - execute('tabnew') - execute('new test1') - execute('tab drop test1') + command('new test1') + command('tabnew') + command('new test1') + command('tab drop test1') eq(2, eval('tabpagenr()')) eq(2, eval('tabpagewinnr(2, "$")')) eq(1, eval('tabpagewinnr(2)')) end) it('can be navigated with :tabmove', function() - execute('lang C') - execute('for i in range(9) | tabnew | endfor') + command('lang C') + command('for i in range(9) | tabnew | endfor') feed('1gt') eq(1, eval('tabpagenr()')) - execute('tabmove 5') + command('tabmove 5') eq(5, eval('tabpagenr()')) - execute('.tabmove') + command('.tabmove') eq(5, eval('tabpagenr()')) - execute('tabmove -') + command('tabmove -') eq(4, eval('tabpagenr()')) - execute('tabmove +') + command('tabmove +') eq(5, eval('tabpagenr()')) - execute('tabmove -2') + command('tabmove -2') eq(3, eval('tabpagenr()')) - execute('tabmove +4') + command('tabmove +4') eq(7, eval('tabpagenr()')) - execute('tabmove') + command('tabmove') eq(10, eval('tabpagenr()')) - execute('0tabmove') + command('0tabmove') eq(1, eval('tabpagenr()')) - execute('$tabmove') + command('$tabmove') eq(10, eval('tabpagenr()')) - execute('tabmove 0') + command('tabmove 0') eq(1, eval('tabpagenr()')) - execute('tabmove $') + command('tabmove $') eq(10, eval('tabpagenr()')) - execute('3tabmove') + command('3tabmove') eq(4, eval('tabpagenr()')) - execute('7tabmove 5') + command('7tabmove 5') eq(5, eval('tabpagenr()')) - execute('let a="No error caught."') - execute('try') - execute('tabmove foo') - execute('catch E474') - execute('let a="E474 caught."') - execute('endtry') + command('let a="No error caught."') + command('try') + command('tabmove foo') + command('catch E474') + command('let a="E474 caught."') + command('endtry') eq('E474 caught.', eval('a')) end) diff --git a/test/functional/legacy/063_match_and_matchadd_spec.lua b/test/functional/legacy/063_match_and_matchadd_spec.lua index 5818bb6b3a..34163d5a55 100644 --- a/test/functional/legacy/063_match_and_matchadd_spec.lua +++ b/test/functional/legacy/063_match_and_matchadd_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local feed, insert = helpers.feed, helpers.insert -local eval, clear, execute = helpers.eval, helpers.clear, helpers.execute +local eval, clear, command = helpers.eval, helpers.clear, helpers.command local eq, neq = helpers.eq, helpers.neq describe('063: Test for ":match", "matchadd()" and related functions', function() @@ -15,12 +15,12 @@ describe('063: Test for ":match", "matchadd()" and related functions', function( -- Check that "matcharg()" returns the correct group and pattern if a match -- is defined. - execute("highlight MyGroup1 term=bold ctermbg=red guibg=red") - execute("highlight MyGroup2 term=italic ctermbg=green guibg=green") - execute("highlight MyGroup3 term=underline ctermbg=blue guibg=blue") - execute("match MyGroup1 /TODO/") - execute("2match MyGroup2 /FIXME/") - execute("3match MyGroup3 /XXX/") + command("highlight MyGroup1 term=bold ctermbg=red guibg=red") + command("highlight MyGroup2 term=italic ctermbg=green guibg=green") + command("highlight MyGroup3 term=underline ctermbg=blue guibg=blue") + command("match MyGroup1 /TODO/") + command("2match MyGroup2 /FIXME/") + command("3match MyGroup3 /XXX/") eq({'MyGroup1', 'TODO'}, eval('matcharg(1)')) eq({'MyGroup2', 'FIXME'}, eval('matcharg(2)')) eq({'MyGroup3', 'XXX'}, eval('matcharg(3)')) @@ -31,18 +31,18 @@ describe('063: Test for ":match", "matchadd()" and related functions', function( eq({}, eval('matcharg(4)')) -- Check that "matcharg()" returns ['', ''] if a match is not defined. - execute("match") - execute("2match") - execute("3match") + command("match") + command("2match") + command("3match") eq({'', ''}, eval('matcharg(1)')) eq({'', ''}, eval('matcharg(2)')) eq({'', ''}, eval('matcharg(3)')) -- Check that "matchadd()" and "getmatches()" agree on added matches and -- that default values apply. - execute("let m1 = matchadd('MyGroup1', 'TODO')") - execute("let m2 = matchadd('MyGroup2', 'FIXME', 42)") - execute("let m3 = matchadd('MyGroup3', 'XXX', 60, 17)") + command("let m1 = matchadd('MyGroup1', 'TODO')") + command("let m2 = matchadd('MyGroup2', 'FIXME', 42)") + command("let m3 = matchadd('MyGroup3', 'XXX', 60, 17)") eq({{group = 'MyGroup1', pattern = 'TODO', priority = 10, id = 4}, {group = 'MyGroup2', pattern = 'FIXME', priority = 42, id = 5}, {group = 'MyGroup3', pattern = 'XXX', priority = 60, id = 17}}, @@ -50,55 +50,55 @@ describe('063: Test for ":match", "matchadd()" and related functions', function( -- Check that "matchdelete()" deletes the matches defined in the previous -- test correctly. - execute("call matchdelete(m1)") - execute("call matchdelete(m2)") - execute("call matchdelete(m3)") + command("call matchdelete(m1)") + command("call matchdelete(m2)") + command("call matchdelete(m3)") eq({}, eval('getmatches()')) --- Check that "matchdelete()" returns 0 if successful and otherwise -1. - execute("let m = matchadd('MyGroup1', 'TODO')") + command("let m = matchadd('MyGroup1', 'TODO')") eq(0, eval('matchdelete(m)')) -- matchdelete throws error and returns -1 on failure neq(true, pcall(function() eval('matchdelete(42)') end)) - execute("let r2 = matchdelete(42)") + command("let r2 = matchdelete(42)") eq(-1, eval('r2')) -- Check that "clearmatches()" clears all matches defined by ":match" and -- "matchadd()". - execute("let m1 = matchadd('MyGroup1', 'TODO')") - execute("let m2 = matchadd('MyGroup2', 'FIXME', 42)") - execute("let m3 = matchadd('MyGroup3', 'XXX', 60, 17)") - execute("match MyGroup1 /COFFEE/") - execute("2match MyGroup2 /HUMPPA/") - execute("3match MyGroup3 /VIM/") - execute("call clearmatches()") + command("let m1 = matchadd('MyGroup1', 'TODO')") + command("let m2 = matchadd('MyGroup2', 'FIXME', 42)") + command("let m3 = matchadd('MyGroup3', 'XXX', 60, 17)") + command("match MyGroup1 /COFFEE/") + command("2match MyGroup2 /HUMPPA/") + command("3match MyGroup3 /VIM/") + command("call clearmatches()") eq({}, eval('getmatches()')) -- Check that "setmatches()" restores a list of matches saved by -- "getmatches()" without changes. (Matches with equal priority must also -- remain in the same order.) - execute("let m1 = matchadd('MyGroup1', 'TODO')") - execute("let m2 = matchadd('MyGroup2', 'FIXME', 42)") - execute("let m3 = matchadd('MyGroup3', 'XXX', 60, 17)") - execute("match MyGroup1 /COFFEE/") - execute("2match MyGroup2 /HUMPPA/") - execute("3match MyGroup3 /VIM/") - execute("let ml = getmatches()") + command("let m1 = matchadd('MyGroup1', 'TODO')") + command("let m2 = matchadd('MyGroup2', 'FIXME', 42)") + command("let m3 = matchadd('MyGroup3', 'XXX', 60, 17)") + command("match MyGroup1 /COFFEE/") + command("2match MyGroup2 /HUMPPA/") + command("3match MyGroup3 /VIM/") + command("let ml = getmatches()") local ml = eval("ml") - execute("call clearmatches()") - execute("call setmatches(ml)") + command("call clearmatches()") + command("call setmatches(ml)") eq(ml, eval('getmatches()')) -- Check that "setmatches()" can correctly restore the matches from matchaddpos() - execute("call clearmatches()") - execute("call setmatches(ml)") + command("call clearmatches()") + command("call setmatches(ml)") eq(ml, eval('getmatches()')) -- Check that "setmatches()" will not add two matches with the same ID. The -- expected behaviour (for now) is to add the first match but not the -- second and to return -1. - execute("let r1 = setmatches([{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}, {'group': 'MyGroup2', 'pattern': 'FIXME', 'priority': 10, 'id': 1}])") + command("let r1 = setmatches([{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}, {'group': 'MyGroup2', 'pattern': 'FIXME', 'priority': 10, 'id': 1}])") feed("") eq(-1, eval("r1")) eq({{group = 'MyGroup1', pattern = 'TODO', priority = 10, id = 1}}, eval('getmatches()')) @@ -108,18 +108,18 @@ describe('063: Test for ":match", "matchadd()" and related functions', function( -- return values.) eq(0,eval("setmatches([])")) eq(0,eval("setmatches([{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}])")) - execute("call clearmatches()") - execute("let rf1 = setmatches(0)") + command("call clearmatches()") + command("let rf1 = setmatches(0)") eq(-1, eval('rf1')) - execute("let rf2 = setmatches([0])") + command("let rf2 = setmatches([0])") eq(-1, eval('rf2')) - execute("let rf3 = setmatches([{'wrong key': 'wrong value'}])") + command("let rf3 = setmatches([{'wrong key': 'wrong value'}])") feed("") eq(-1, eval('rf3')) -- Check that "matchaddpos()" positions matches correctly insert('abcdefghijklmnopq') - execute("call matchaddpos('MyGroup1', [[1, 5], [1, 8, 3]], 10, 3)") + command("call matchaddpos('MyGroup1', [[1, 5], [1, 8, 3]], 10, 3)") screen:expect([[ abcd{1:e}fg{1:hij}klmnop^q | ~ | @@ -128,9 +128,9 @@ describe('063: Test for ":match", "matchadd()" and related functions', function( | ]], {[1] = {background = Screen.colors.Red}}, {{bold = true, foreground = Screen.colors.Blue}}) - execute("call clearmatches()") - execute("call setline(1, 'abcdΣabcdef')") - execute("call matchaddpos('MyGroup1', [[1, 4, 2], [1, 9, 2]])") + command("call clearmatches()") + command("call setline(1, 'abcdΣabcdef')") + command("call matchaddpos('MyGroup1', [[1, 4, 2], [1, 9, 2]])") screen:expect([[ abc{1:dΣ}ab{1:cd}e^f | ~ | diff --git a/test/functional/legacy/065_float_and_logic_operators_spec.lua b/test/functional/legacy/065_float_and_logic_operators_spec.lua index d12ea502f3..615dff1f3b 100644 --- a/test/functional/legacy/065_float_and_logic_operators_spec.lua +++ b/test/functional/legacy/065_float_and_logic_operators_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local insert, source = helpers.insert, helpers.source -local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect +local clear, command, expect = helpers.clear, helpers.command, helpers.expect describe('floating point and logical operators', function() setup(clear) @@ -49,7 +49,7 @@ describe('floating point and logical operators', function() -- The test will throw an error if this line is included in a source() -- call. The vim expression throws a exception "E745: Using a List as a -- Number" which is fatal in a source() call but not in a execute() call. - execute([[$put =printf('%d', abs([1, 2, 3]))]]) + command([[$put =printf('%d', abs([1, 2, 3]))]]) source([[ $put =printf('%g', abs(14.56)) @@ -104,7 +104,7 @@ describe('floating point and logical operators', function() -- This line can not be included in a source() call. It throws a "E805: -- Using a Float as a Number". Also compare comment above. - execute('$put =invert(1.0)') + command('$put =invert(1.0)') -- Assert buffer contents. expect([=[ diff --git a/test/functional/legacy/066_visual_block_tab_spec.lua b/test/functional/legacy/066_visual_block_tab_spec.lua index 72fa7d881b..7c4984362f 100644 --- a/test/functional/legacy/066_visual_block_tab_spec.lua +++ b/test/functional/legacy/066_visual_block_tab_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local execute, expect = helpers.execute, helpers.expect +local feed_command, expect = helpers.feed_command, helpers.expect describe('visual block shift and tab characters', function() setup(clear) @@ -24,23 +24,23 @@ describe('visual block shift and tab characters', function() feed('gg') feed([[fe4jRugvr1:','>yank A]]) - execute('/^abcdefgh') + feed_command('/^abcdefgh') feed('4jI j11|D') feed('j7|a ') feed('j7|a ') feed('j7|a 4k13|4j') - execute('$-5,$yank A') - execute([[$-4,$s/\s\+//g]]) + feed_command('$-5,$yank A') + feed_command([[$-4,$s/\s\+//g]]) feed('4kI j') feed('j7|a ') feed('j7|a ') feed('j7|a 4k13|4j3') - execute('$-4,$yank A') + feed_command('$-4,$yank A') -- Put @a and clean empty lines - execute('%d') - execute('0put a') - execute('$d') + feed_command('%d') + feed_command('0put a') + feed_command('$d') -- Assert buffer contents. expect([[ diff --git a/test/functional/legacy/067_augroup_exists_spec.lua b/test/functional/legacy/067_augroup_exists_spec.lua index 8f6b881ed8..a0d8d3940b 100644 --- a/test/functional/legacy/067_augroup_exists_spec.lua +++ b/test/functional/legacy/067_augroup_exists_spec.lua @@ -3,32 +3,32 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear -local execute, expect = helpers.execute, helpers.expect +local command, expect = helpers.command, helpers.expect describe('augroup when calling exists()', function() setup(clear) it('is working', function() - execute('let results=[]') - execute('call add(results, "##BufEnter: " . exists("##BufEnter"))') - execute('call add(results, "#BufEnter: " . exists("#BufEnter"))') - execute('au BufEnter * let g:entered=1') - execute('call add(results, "#BufEnter: " . exists("#BufEnter"))') - execute('call add(results, "#auexists#BufEnter: " . exists("#auexists#BufEnter"))') - execute('augroup auexists', 'au BufEnter * let g:entered=1', 'augroup END') - execute('call add(results, "#auexists#BufEnter: " . exists("#auexists#BufEnter"))') - execute('call add(results, "#BufEnter#*.test: " . exists("#BufEnter#*.test"))') - execute('au BufEnter *.test let g:entered=1') - execute('call add(results, "#BufEnter#*.test: " . exists("#BufEnter#*.test"))') - execute('edit testfile.test') - execute('call add(results, "#BufEnter#: " . exists("#BufEnter#"))') - execute('au BufEnter let g:entered=1') - execute('call add(results, "#BufEnter#: " . exists("#BufEnter#"))') - execute('edit testfile2.test') - execute('call add(results, "#BufEnter#: " . exists("#BufEnter#"))') - execute('bf') - execute('call append(0, results)') - execute('$d') + command('let results=[]') + command('call add(results, "##BufEnter: " . exists("##BufEnter"))') + command('call add(results, "#BufEnter: " . exists("#BufEnter"))') + command('au BufEnter * let g:entered=1') + command('call add(results, "#BufEnter: " . exists("#BufEnter"))') + command('call add(results, "#auexists#BufEnter: " . exists("#auexists#BufEnter"))') + command('augroup auexists', 'au BufEnter * let g:entered=1', 'augroup END') + command('call add(results, "#auexists#BufEnter: " . exists("#auexists#BufEnter"))') + command('call add(results, "#BufEnter#*.test: " . exists("#BufEnter#*.test"))') + command('au BufEnter *.test let g:entered=1') + command('call add(results, "#BufEnter#*.test: " . exists("#BufEnter#*.test"))') + command('edit testfile.test') + command('call add(results, "#BufEnter#: " . exists("#BufEnter#"))') + command('au BufEnter let g:entered=1') + command('call add(results, "#BufEnter#: " . exists("#BufEnter#"))') + command('edit testfile2.test') + command('call add(results, "#BufEnter#: " . exists("#BufEnter#"))') + command('bf') + command('call append(0, results)') + command('$d') -- Assert buffer contents. expect([[ diff --git a/test/functional/legacy/068_text_formatting_spec.lua b/test/functional/legacy/068_text_formatting_spec.lua index e232e5073d..772dbc14cf 100644 --- a/test/functional/legacy/068_text_formatting_spec.lua +++ b/test/functional/legacy/068_text_formatting_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local feed = helpers.feed local clear = helpers.clear local insert = helpers.insert -local execute = helpers.execute +local feed_command = helpers.feed_command local expect = helpers.expect describe('text formatting', function() @@ -15,195 +15,195 @@ describe('text formatting', function() -- mode so it has to be escaped with . insert([[ Results of test68: - - + + { - - + + } - - + + { a b - + a } - - + + { a  } - - + + { a b #a b } - - + + { 1 a # 1 a } - - + + { - + x a b c - + } - - + + { # 1 a b } - - + + { # x # a b } - - + + { 1aa 2bb } - - + + /* abc def ghi jkl * mno pqr stu */ - - + + # 1 xxxxx ]]) - execute('/^{/+1') - execute('set noai tw=2 fo=t') + feed_command('/^{/+1') + feed_command('set noai tw=2 fo=t') feed('gRa b') - execute('/^{/+1') - execute('set ai tw=2 fo=tw') + feed_command('/^{/+1') + feed_command('set ai tw=2 fo=tw') feed('gqgqjjllab') - execute('/^{/+1') - execute('set tw=3 fo=t') + feed_command('/^{/+1') + feed_command('set tw=3 fo=t') feed('gqgqo') feed('a ') - execute('/^{/+1') - execute('set tw=2 fo=tcq1 comments=:#') + feed_command('/^{/+1') + feed_command('set tw=2 fo=tcq1 comments=:#') feed('gqgqjgqgqo') feed('a b') feed('#a b') - execute('/^{/+1') - execute('set tw=5 fo=tcn comments=:#') + feed_command('/^{/+1') + feed_command('set tw=5 fo=tcn comments=:#') feed('A bjA b') - execute('/^{/+3') - execute('set tw=5 fo=t2a si') + feed_command('/^{/+3') + feed_command('set tw=5 fo=t2a si') feed('i A_') - execute('/^{/+1') - execute('set tw=5 fo=qn comments=:#') + feed_command('/^{/+1') + feed_command('set tw=5 fo=qn comments=:#') feed('gwap') - execute('/^{/+1') - execute('set tw=5 fo=q2 comments=:#') + feed_command('/^{/+1') + feed_command('set tw=5 fo=q2 comments=:#') feed('gwap') - execute('/^{/+2') - execute('set tw& fo=a') + feed_command('/^{/+2') + feed_command('set tw& fo=a') feed('I^^') - execute('/mno pqr/') - execute('setl tw=20 fo=an12wcq comments=s1:/*,mb:*,ex:*/') + feed_command('/mno pqr/') + feed_command('setl tw=20 fo=an12wcq comments=s1:/*,mb:*,ex:*/') feed('A vwx yz') - execute('/^#/') - execute('setl tw=12 fo=tqnc comments=:#') + feed_command('/^#/') + feed_command('setl tw=12 fo=tqnc comments=:#') feed('A foobar') -- Assert buffer contents. expect([[ Results of test68: - - + + { a b } - - + + { a b - + a b } - - + + { a  - + a  } - - + + { a b #a b - + a b #a b } - - + + { 1 a b # 1 a # b } - - + + { - + x a b_ c - + } - - + + { # 1 a # b } - - + + { # x a # b } - - + + { 1aa ^^2bb } - - + + /* abc def ghi jkl * mno pqr stu * vwx yz */ - - + + # 1 xxxxx # foobar ]]) diff --git a/test/functional/legacy/069_multibyte_formatting_spec.lua b/test/functional/legacy/069_multibyte_formatting_spec.lua index 6edcd8b7f2..38ca25d57a 100644 --- a/test/functional/legacy/069_multibyte_formatting_spec.lua +++ b/test/functional/legacy/069_multibyte_formatting_spec.lua @@ -4,8 +4,8 @@ -- Also test byteidx() and byteidxcomp() local helpers = require('test.functional.helpers')(after_each) -local feed, insert, eq, eval, clear, execute, expect = helpers.feed, - helpers.insert, helpers.eq, helpers.eval, helpers.clear, helpers.execute, +local feed, insert, eq, eval, clear, feed_command, expect = helpers.feed, + helpers.insert, helpers.eq, helpers.eval, helpers.clear, helpers.feed_command, helpers.expect describe('multibyte text', function() @@ -17,8 +17,8 @@ describe('multibyte text', function() XYZ abc XYZ }]]) - execute('/^{/+1') - execute('set tw=2 fo=t') + feed_command('/^{/+1') + feed_command('set tw=2 fo=t') feed('gqgqjgqgqo') feed('XYZ') feed('abc XYZ') @@ -43,8 +43,8 @@ describe('multibyte text', function() XY X Y }]]) - execute('/^{/+1') - execute('set tw=1 fo=tm') + feed_command('/^{/+1') + feed_command('set tw=1 fo=tm') feed('gqgqjgqgqjgqgqjgqgqjgqgqo') feed('X') feed('Xa') @@ -89,8 +89,8 @@ describe('multibyte text', function() abX c abXY }]]) - execute('/^{/+1') - execute('set tw=2 fo=tm') + feed_command('/^{/+1') + feed_command('set tw=2 fo=tm') feed('gqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqo') feed('X') feed('Xa') @@ -156,8 +156,8 @@ describe('multibyte text', function() X Xa }]]) - execute('/^{/+1') - execute('set ai tw=2 fo=tm') + feed_command('/^{/+1') + feed_command('set ai tw=2 fo=tm') feed('gqgqjgqgqo') feed('X') feed('Xa') @@ -179,8 +179,8 @@ describe('multibyte text', function() X Xa }]]) - execute('/^{/+1') - execute('set noai tw=2 fo=tm') + feed_command('/^{/+1') + feed_command('set noai tw=2 fo=tm') feed('gqgqjgqgqo') -- Literal spaces will be trimmed from the by feed(). feed('') @@ -211,8 +211,8 @@ describe('multibyte text', function() XXa XXY }]]) - execute('/^{/+1') - execute('set tw=2 fo=cqm comments=n:X') + feed_command('/^{/+1') + feed_command('set tw=2 fo=cqm comments=n:X') feed('gqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqo') feed('X') feed('Xa') @@ -261,8 +261,8 @@ describe('multibyte text', function() { }]]) - execute('/^{/+1') - execute('set tw=2 fo=tm') + feed_command('/^{/+1') + feed_command('set tw=2 fo=tm') feed('RXa') expect([[ { @@ -276,8 +276,8 @@ describe('multibyte text', function() { ‘ two three ’ four }]]) - execute('/^{/+1') - execute('set mps+=‘:’') + feed_command('/^{/+1') + feed_command('set mps+=‘:’') feed('d%') expect([[ { @@ -299,8 +299,8 @@ describe('multibyte text', function() insert([[ á x]]) - execute('set whichwrap+=h') - execute('/^x') + feed_command('set whichwrap+=h') + feed_command('/^x') feed('dh') expect([[ áx]]) @@ -308,9 +308,9 @@ describe('multibyte text', function() it('can be queried with byteidx() and byteidxcomp()', function() -- One char of two bytes. - execute("let a = '.é.'") + feed_command("let a = '.é.'") -- Normal e with composing char. - execute("let b = '.é.'") + feed_command("let b = '.é.'") eq(0, eval('byteidx(a, 0)')) eq(1, eval('byteidx(a, 1)')) eq(3, eval('byteidx(a, 2)')) diff --git a/test/functional/legacy/072_undo_file_spec.lua b/test/functional/legacy/072_undo_file_spec.lua index 4682a82008..b4927e779e 100644 --- a/test/functional/legacy/072_undo_file_spec.lua +++ b/test/functional/legacy/072_undo_file_spec.lua @@ -4,7 +4,7 @@ local helpers = require('test.functional.helpers')(after_each) local feed, insert = helpers.feed, helpers.insert -local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect +local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect describe('72', function() setup(clear) @@ -13,34 +13,34 @@ describe('72', function() insert([[ 1111 ----- 2222 ----- - + 123456789]]) -- Test 'undofile': first a simple one-line change. - execute('set visualbell') - execute('set ul=100 undofile undodir=. nomore') - execute('e! Xtestfile') + feed_command('set visualbell') + feed_command('set ul=100 undofile undodir=. nomore') + feed_command('e! Xtestfile') feed('ggdGithis is one line:set ul=100') - execute('s/one/ONE/') - execute('set ul=100') - execute('w') - execute('bwipe!') - execute('e Xtestfile') + feed_command('s/one/ONE/') + feed_command('set ul=100') + feed_command('w') + feed_command('bwipe!') + feed_command('e Xtestfile') feed('u:.w! test.out') -- Test 'undofile', change in original file fails check. - execute('set noundofile') - execute('e! Xtestfile') - execute('s/line/Line/') - execute('w') - execute('set undofile') - execute('bwipe!') - execute('e Xtestfile') + feed_command('set noundofile') + feed_command('e! Xtestfile') + feed_command('s/line/Line/') + feed_command('w') + feed_command('set undofile') + feed_command('bwipe!') + feed_command('e Xtestfile') ---- TODO: this beeps. feed('u:.w >>test.out') -- Test 'undofile', add 10 lines, delete 6 lines, undo 3. - execute('set undofile') + feed_command('set undofile') feed('ggdGione') feed('two') feed('three') @@ -57,20 +57,20 @@ describe('72', function() feed('dd:set ul=100') feed('dd:set ul=100') feed('dd:set ul=100') - execute('w') - execute('bwipe!') - execute('e Xtestfile') + feed_command('w') + feed_command('bwipe!') + feed_command('e Xtestfile') feed('uuu:w >>test.out') -- Test that reading the undofiles when setting undofile works. - execute('set noundofile ul=0') + feed_command('set noundofile ul=0') feed('i') feed('u:e! Xtestfile') - execute('set undofile ul=100') + feed_command('set undofile ul=100') feed('uuuuuu:w >>test.out') ---- Open the output to see if it meets the expections - execute('e! test.out') + feed_command('e! test.out') -- Assert buffer contents. expect([[ diff --git a/test/functional/legacy/074_global_var_in_viminfo_spec.lua b/test/functional/legacy/074_global_var_in_viminfo_spec.lua index e8292db8c1..e160f69592 100644 --- a/test/functional/legacy/074_global_var_in_viminfo_spec.lua +++ b/test/functional/legacy/074_global_var_in_viminfo_spec.lua @@ -2,8 +2,8 @@ local helpers = require('test.functional.helpers')(after_each) local lfs = require('lfs') -local clear, execute, eq, neq, eval, wait, spawn = - helpers.clear, helpers.execute, helpers.eq, helpers.neq, helpers.eval, +local clear, command, eq, neq, eval, wait, spawn = + helpers.clear, helpers.command, helpers.eq, helpers.neq, helpers.eval, helpers.wait, helpers.spawn describe('storing global variables in ShaDa files', function() @@ -26,7 +26,7 @@ describe('storing global variables in ShaDa files', function() 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100} - execute( + command( -- This will cause a few errors, do it silently. 'set visualbell', 'set shada+=!', @@ -39,18 +39,18 @@ describe('storing global variables in ShaDa files', function() eq(test_dict, eval('MY_GLOBAL_DICT')) eq(test_list, eval('MY_GLOBAL_LIST')) - execute('wsh! ' .. tempname) + command('wsh! ' .. tempname) wait() -- Assert that the shada file exists. neq(nil, lfs.attributes(tempname)) - execute('unlet MY_GLOBAL_DICT', + command('unlet MY_GLOBAL_DICT', 'unlet MY_GLOBAL_LIST') -- Assert that the variables where deleted. eq(0, eval('exists("MY_GLOBAL_DICT")')) eq(0, eval('exists("MY_GLOBAL_LIST")')) - execute('rsh! ' .. tempname) + command('rsh! ' .. tempname) eq(test_list, eval('MY_GLOBAL_LIST')) eq(test_dict, eval('MY_GLOBAL_DICT')) diff --git a/test/functional/legacy/075_maparg_spec.lua b/test/functional/legacy/075_maparg_spec.lua index e9d2acdaf5..fcfd33ec46 100644 --- a/test/functional/legacy/075_maparg_spec.lua +++ b/test/functional/legacy/075_maparg_spec.lua @@ -3,46 +3,48 @@ local helpers = require('test.functional.helpers')(after_each) local clear, feed = helpers.clear, helpers.feed -local execute, expect = helpers.execute, helpers.expect +local command, expect = helpers.command, helpers.expect +local wait = helpers.wait describe('maparg()', function() setup(clear) it('is working', function() - execute('set cpo-=<') + command('set cpo-=<') -- Test maparg() with a string result - execute('map foo isfoo') - execute('vnoremap