summaryrefslogtreecommitdiffstats
path: root/src/testdir/test_ins_complete.vim
diff options
context:
space:
mode:
Diffstat (limited to 'src/testdir/test_ins_complete.vim')
-rw-r--r--src/testdir/test_ins_complete.vim74
1 files changed, 72 insertions, 2 deletions
diff --git a/src/testdir/test_ins_complete.vim b/src/testdir/test_ins_complete.vim
index 61ddcd3..52306e8 100644
--- a/src/testdir/test_ins_complete.vim
+++ b/src/testdir/test_ins_complete.vim
@@ -412,6 +412,62 @@ func Test_completefunc_info()
set completefunc&
endfunc
+func CompleteInfoUserDefinedFn(findstart, query)
+ " User defined function (i_CTRL-X_CTRL-U)
+ if a:findstart
+ return col('.')
+ endif
+ return [{'word': 'foo'}, {'word': 'bar'}, {'word': 'baz'}, {'word': 'qux'}]
+endfunc
+
+func CompleteInfoTestUserDefinedFn(mvmt, idx, noselect)
+ new
+ if a:noselect
+ set completeopt=menuone,popup,noinsert,noselect
+ else
+ set completeopt=menu,preview
+ endif
+ set completefunc=CompleteInfoUserDefinedFn
+ call feedkeys("i\<C-X>\<C-U>" . a:mvmt . "\<C-R>\<C-R>=string(complete_info())\<CR>\<ESC>", "tx")
+ let completed = a:idx != -1 ? ['foo', 'bar', 'baz', 'qux']->get(a:idx) : ''
+ call assert_equal(completed. "{'pum_visible': 1, 'mode': 'function', 'selected': " . a:idx . ", 'items': [" .
+ \ "{'word': 'foo', 'menu': '', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}, " .
+ \ "{'word': 'bar', 'menu': '', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}, " .
+ \ "{'word': 'baz', 'menu': '', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}, " .
+ \ "{'word': 'qux', 'menu': '', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}" .
+ \ "]}", getline(1))
+ bwipe!
+ set completeopt&
+ set completefunc&
+endfunc
+
+func Test_complete_info_user_defined_fn()
+ " forward
+ call CompleteInfoTestUserDefinedFn("\<C-N>\<C-N>", 1, v:true)
+ call CompleteInfoTestUserDefinedFn("\<C-N>\<C-N>\<C-N>", 2, v:true)
+ call CompleteInfoTestUserDefinedFn("\<C-N>\<C-N>", 2, v:false)
+ call CompleteInfoTestUserDefinedFn("\<C-N>\<C-N>\<C-N>", 3, v:false)
+ call CompleteInfoTestUserDefinedFn("\<C-N>\<C-N>\<C-N>\<C-N>", -1, v:false)
+ " backward
+ call CompleteInfoTestUserDefinedFn("\<C-P>\<C-P>", 2, v:true)
+ call CompleteInfoTestUserDefinedFn("\<C-P>\<C-P>\<C-P>", 1, v:true)
+ call CompleteInfoTestUserDefinedFn("\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>", -1, v:true)
+ call CompleteInfoTestUserDefinedFn("\<C-P>\<C-P>", 3, v:false)
+ call CompleteInfoTestUserDefinedFn("\<C-P>\<C-P>\<C-P>", 2, v:false)
+ " forward backward
+ call CompleteInfoTestUserDefinedFn("\<C-N>\<C-N>\<C-N>\<C-P>", 1, v:true)
+ call CompleteInfoTestUserDefinedFn("\<C-N>\<C-N>\<C-P>", 0, v:true)
+ call CompleteInfoTestUserDefinedFn("\<C-N>\<C-N>\<C-N>\<C-P>", 2, v:false)
+ call CompleteInfoTestUserDefinedFn("\<C-N>\<C-N>\<C-N>\<C-N>\<C-P>", 3, v:false)
+ call CompleteInfoTestUserDefinedFn("\<C-N>\<C-N>\<C-P>", 1, v:false)
+ " backward forward
+ call CompleteInfoTestUserDefinedFn("\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>\<C-N>", 0, v:true)
+ call CompleteInfoTestUserDefinedFn("\<C-P>\<C-P>\<C-P>\<C-N>", 2, v:true)
+ call CompleteInfoTestUserDefinedFn("\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>\<C-N>", 1, v:false)
+ call CompleteInfoTestUserDefinedFn("\<C-P>\<C-P>\<C-P>\<C-N>", 3, v:false)
+ call CompleteInfoTestUserDefinedFn("\<C-P>\<C-N>\<C-N>", 1, v:false)
+endfunc
+
" Test that mouse scrolling/movement should not interrupt completion.
func Test_mouse_scroll_move_during_completion()
new
@@ -2345,7 +2401,7 @@ func Test_complete_info_index()
call assert_equal(-1, g:compl_info['selected'])
call feedkeys("Go\<C-X>\<C-N>\<C-P>\<F5>\<Esc>_dd", 'tx')
- call assert_equal(0, g:compl_info['selected'])
+ call assert_equal(5, g:compl_info['selected'])
call assert_equal(6 , len(g:compl_info['items']))
call assert_equal("fff", g:compl_info['items'][g:compl_info['selected']]['word'])
call feedkeys("Go\<C-X>\<C-N>\<C-N>\<C-N>\<C-N>\<C-N>\<C-N>\<C-N>\<C-N>\<C-N>\<F5>\<Esc>_dd", 'tx')
@@ -2359,4 +2415,18 @@ func Test_complete_info_index()
bwipe!
endfunc
-" vim: shiftwidth=2 sts=2 expandtab
+func Test_complete_changed_complete_info()
+ CheckRunVimInTerminal
+ " this used to crash vim, see #13929
+ let lines =<< trim END
+ set completeopt=menuone
+ autocmd CompleteChanged * call complete_info(['items'])
+ call feedkeys("iii\<cr>\<c-p>")
+ END
+ call writefile(lines, 'Xsegfault', 'D')
+ let buf = RunVimInTerminal('-S Xsegfault', #{rows: 5})
+ call WaitForAssert({-> assert_match('^ii', term_getline(buf, 1))}, 1000)
+ call StopVimInTerminal(buf)
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab nofoldenable