diff options
Diffstat (limited to 'test/functional/viml')
-rw-r--r-- | test/functional/viml/completion_spec.lua | 104 | ||||
-rw-r--r-- | test/functional/viml/function_spec.lua | 232 | ||||
-rw-r--r-- | test/functional/viml/lang_spec.lua | 5 |
3 files changed, 292 insertions, 49 deletions
diff --git a/test/functional/viml/completion_spec.lua b/test/functional/viml/completion_spec.lua index cd5f4260e0..b70ef724b7 100644 --- a/test/functional/viml/completion_spec.lua +++ b/test/functional/viml/completion_spec.lua @@ -2,7 +2,8 @@ local helpers = require('test.functional.helpers')(after_each) 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 feed_command, source, expect = helpers.feed_command, helpers.source, helpers.expect +local meths = helpers.meths if helpers.pending_win32(pending) then return end @@ -66,25 +67,25 @@ describe('completion', function() it('is readonly', function() screen:try_resize(80, 8) feed('ifoo<ESC>o<C-x><C-n><ESC>') - execute('let v:completed_item.word = "bar"') + feed_command('let v:completed_item.word = "bar"') neq(nil, string.find(eval('v:errmsg'), '^E46: ')) - execute('let v:errmsg = ""') + feed_command('let v:errmsg = ""') - execute('let v:completed_item.abbr = "bar"') + feed_command('let v:completed_item.abbr = "bar"') neq(nil, string.find(eval('v:errmsg'), '^E46: ')) - execute('let v:errmsg = ""') + feed_command('let v:errmsg = ""') - execute('let v:completed_item.menu = "bar"') + feed_command('let v:completed_item.menu = "bar"') neq(nil, string.find(eval('v:errmsg'), '^E46: ')) - execute('let v:errmsg = ""') + feed_command('let v:errmsg = ""') - execute('let v:completed_item.info = "bar"') + feed_command('let v:completed_item.info = "bar"') neq(nil, string.find(eval('v:errmsg'), '^E46: ')) - execute('let v:errmsg = ""') + feed_command('let v:errmsg = ""') - execute('let v:completed_item.kind = "bar"') + feed_command('let v:completed_item.kind = "bar"') neq(nil, string.find(eval('v:errmsg'), '^E46: ')) - execute('let v:errmsg = ""') + feed_command('let v:errmsg = ""') end) it('returns expected dict in omni completion', function() source([[ @@ -124,7 +125,7 @@ describe('completion', function() end) it('inserts the first candidate if default', function() - execute('set completeopt+=menuone') + feed_command('set completeopt+=menuone') feed('ifoo<ESC>o') screen:expect([[ foo | @@ -175,7 +176,7 @@ describe('completion', function() eq('foo', eval('getline(3)')) end) it('selects the first candidate if noinsert', function() - execute('set completeopt+=menuone,noinsert') + feed_command('set completeopt+=menuone,noinsert') feed('ifoo<ESC>o<C-x><C-n>') screen:expect([[ foo | @@ -215,7 +216,7 @@ describe('completion', function() eq('foo', eval('getline(3)')) end) it('does not insert the first candidate if noselect', function() - execute('set completeopt+=menuone,noselect') + feed_command('set completeopt+=menuone,noselect') feed('ifoo<ESC>o<C-x><C-n>') screen:expect([[ foo | @@ -255,7 +256,7 @@ describe('completion', function() eq('bar', eval('getline(3)')) end) it('does not select/insert the first candidate if noselect and noinsert', function() - execute('set completeopt+=menuone,noselect,noinsert') + feed_command('set completeopt+=menuone,noselect,noinsert') feed('ifoo<ESC>o<C-x><C-n>') screen:expect([[ foo | @@ -304,14 +305,14 @@ describe('completion', function() eq('', eval('getline(3)')) end) it('does not change modified state if noinsert', function() - execute('set completeopt+=menuone,noinsert') - execute('setlocal nomodified') + feed_command('set completeopt+=menuone,noinsert') + feed_command('setlocal nomodified') feed('i<C-r>=TestComplete()<CR><ESC>') eq(0, eval('&l:modified')) end) it('does not change modified state if noselect', function() - execute('set completeopt+=menuone,noselect') - execute('setlocal nomodified') + feed_command('set completeopt+=menuone,noselect') + feed_command('setlocal nomodified') feed('i<C-r>=TestComplete()<CR><ESC>') eq(0, eval('&l:modified')) end) @@ -325,8 +326,8 @@ describe('completion', function() return '' endfunction ]]) - execute('set completeopt+=noselect,noinsert') - execute('inoremap <right> <c-r>=TestComplete()<cr>') + feed_command('set completeopt+=noselect,noinsert') + feed_command('inoremap <right> <c-r>=TestComplete()<cr>') end) local tests = { @@ -540,7 +541,7 @@ describe('completion', function() return '' endfunction ]]) - execute("set completeopt=menuone,noselect") + feed_command("set completeopt=menuone,noselect") end) it("works", function() @@ -706,7 +707,7 @@ describe('completion', function() it('disables folding during completion', function () - execute("set foldmethod=indent") + feed_command("set foldmethod=indent") feed('i<Tab>foo<CR><Tab>bar<Esc>gg') screen:expect([[ ^foo | @@ -733,7 +734,7 @@ describe('completion', function() end) it('popupmenu is not interrupted by events', function () - execute("set complete=.") + feed_command("set complete=.") feed('ifoobar fooegg<cr>f<c-p>') screen:expect([[ @@ -814,15 +815,66 @@ 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<C-r>=TestComplete()<CR>') + screen:expect([[ + ^ | + {1:1 3 2 }{0: }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {3:-- INSERT --} | + ]]) + end) + end) + + it("'ignorecase' 'infercase' CTRL-X CTRL-N #6451", function() + feed_command('set ignorecase infercase') + feed_command('edit BACKERS.md') + feed('oX<C-X><C-N>') + 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() +describe('ui/ext_popupmenu', function() local screen local items, selected, anchor before_each(function() clear() screen = Screen.new(60, 8) - screen:attach({rgb=true, popupmenu_external=true}) + screen:attach({rgb=true, ext_popupmenu=true}) screen:set_default_attr_ids({ [1] = {bold=true, foreground=Screen.colors.Blue}, [2] = {bold = true}, diff --git a/test/functional/viml/function_spec.lua b/test/functional/viml/function_spec.lua index 776e760aaf..0cf92f7d40 100644 --- a/test/functional/viml/function_spec.lua +++ b/test/functional/viml/function_spec.lua @@ -1,29 +1,221 @@ local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear local eq = helpers.eq -local exc_exec = helpers.exc_exec +local clear = helpers.clear +local funcs = helpers.funcs +local dedent = helpers.dedent +local redir_exec = helpers.redir_exec -describe('Up to MAX_FUNC_ARGS arguments are handled by', function() - local max_func_args = 20 -- from eval.h - local range = helpers.funcs.range +before_each(clear) - before_each(clear) +local function check_nofunc(fname) + eq(0, funcs.exists('*' .. fname)) +end - it('printf()', function() - local printf = helpers.funcs.printf - local rep = helpers.funcs['repeat'] - local expected = '2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,' - eq(expected, printf(rep('%d,', max_func_args-1), unpack(range(2, max_func_args)))) - local ret = exc_exec('call printf("", 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21)') - eq('Vim(call):E740: Too many arguments for function printf', ret) - end) +local function check_func(fname, body, indent) + if type(body) == 'number' then + body = ('return %i'):format(body) + end + eq(dedent(([[ - it('rpcnotify()', function() - local rpcnotify = helpers.funcs.rpcnotify - local ret = rpcnotify(0, 'foo', unpack(range(3, max_func_args))) - eq(1, ret) - ret = exc_exec('call rpcnotify(0, "foo", 3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21)') - eq('Vim(call):E740: Too many arguments for function rpcnotify', ret) + function %s()%s + endfunction]] + ), 3):format( + fname, + body and ('\n1' .. (' '):rep(2 + (indent or 8)) .. body) or ''), + redir_exec('function ' .. fname)) +end + +describe(':endfunction', function() + it('accepts bang', function() + eq('', redir_exec([[ + function F() + endfunction! + ]])) + check_func('F') + eq('', redir_exec([[ + function! F() + return 1 + endfunction! + ]])) + check_func('F', 1) + end) + it('accepts comments', function() + eq('', redir_exec([[ + function F1() + endfunction " Comment + ]])) + check_func('F1') + eq('', redir_exec([[ + function F2() + endfunction " }}} + ]])) + check_func('F2') + eq('', redir_exec([[ + function F3() + endfunction " F3 + ]])) + check_func('F3') + eq('', redir_exec([[ + function F4() + endfunction! " F4 + ]])) + check_func('F4') + eq('', redir_exec([[ + function! F4() + return 2 + endfunction! " F4 + ]])) + check_func('F4', 2) + end) + it('accepts function name', function() + eq('', redir_exec([[ + function F0() + endfunction F0 + ]])) + check_func('F0') + eq('', redir_exec([[ + function F1() + endfunction! F1 + ]])) + check_func('F1') + eq('', redir_exec([[ + function! F2() + endfunction! F2 + ]])) + check_func('F2') + eq('', redir_exec([[ + function! F2() + return 3 + endfunction! F2 + ]])) + check_func('F2', 3) + end) + it('accepts weird characters', function() + eq('', redir_exec([[ + function F1() + endfunction: }}} + ]])) + check_func('F1') + -- From accurev + eq('', redir_exec([[ + function F2() + endfunction :}}} + ]])) + check_func('F2') + -- From cream-vimabbrev + eq('', redir_exec([[ + function F3() + endfunction 1}}} + ]])) + check_func('F3') + -- From pyunit + eq('', redir_exec([[ + function F4() + endfunction # }}} + ]])) + check_func('F4') + -- From vim-lldb + eq('', redir_exec([[ + function F5() + endfunction() + ]])) + check_func('F5') + -- From vim-mail + eq('', redir_exec([[ + function F6() + endfunction; + ]])) + check_func('F6') + end) + it('accepts commented bar', function() + eq('', redir_exec([[ + function F1() + endfunction " F1 | echo 42 + ]])) + check_func('F1') + eq('', redir_exec([[ + function! F1() + return 42 + endfunction! " F1 | echo 42 + ]])) + check_func('F1', 42) + end) + it('errors out on an uncommented bar', function() + eq('\nE488: Trailing characters: | echo 42', redir_exec([[ + function F1() + endfunction | echo 42 + ]])) + check_nofunc('F1') + end) + it('allows running multiple commands', function() + eq('\n2', redir_exec([[ + function F1() + echo 2 + endfunction + call F1() + ]])) + check_func('F1', 'echo 2') + eq('\n2\n3\n4', redir_exec([[ + function F2() + echo 2 + endfunction F2 + function F3() + echo 3 + endfunction " F3 + function! F4() + echo 4 + endfunction! + call F2() + call F3() + call F4() + ]])) + check_func('F2', 'echo 2') + check_func('F3', 'echo 3') + check_func('F4', 'echo 4') + end) + it('allows running multiple commands with only one character in between', + function() + eq('\n3', redir_exec(dedent([[ + function! F1() + echo 3 + endfunction! + call F1()]]))) + check_func('F1', 'echo 3', 2) + eq('\n4', redir_exec(dedent([[ + function F5() + echo 4 + endfunction + call F5()]]))) + check_func('F5', 'echo 4', 2) + eq('\n5', redir_exec(dedent([[ + function F6() + echo 5 + endfunction " TEST + call F6()]]))) + check_func('F6', 'echo 5', 2) + eq('\n6', redir_exec(dedent([[ + function F7() + echo 6 + endfunction F7 + call F7()]]))) + check_func('F7', 'echo 6', 2) + eq('\n2\n3\n4', redir_exec(dedent([[ + function F2() + echo 2 + endfunction F2 + function F3() + echo 3 + endfunction " F3 + function! F4() + echo 4 + endfunction! + call F2() + call F3() + call F4()]]))) + check_func('F2', 'echo 2', 2) + check_func('F3', 'echo 3', 2) + check_func('F4', 'echo 4', 2) end) end) +-- vim: foldmarker=▶,▲ diff --git a/test/functional/viml/lang_spec.lua b/test/functional/viml/lang_spec.lua index a27e18f695..3ba9221aef 100644 --- a/test/functional/viml/lang_spec.lua +++ b/test/functional/viml/lang_spec.lua @@ -1,13 +1,12 @@ local helpers = require('test.functional.helpers')(after_each) local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq -local execute, source = helpers.execute, helpers.source +local exc_exec, source = helpers.exc_exec, helpers.source describe('viml', function() before_each(clear) it('parses `<SID>` with turkish locale', function() - execute('lang ctype tr_TR.UTF-8') - if string.find(eval('v:errmsg'), '^E197: ') then + if exc_exec('lang ctype tr_TR.UTF-8') ~= 0 then pending("Locale tr_TR.UTF-8 not supported") return end |