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.vim69
1 files changed, 67 insertions, 2 deletions
diff --git a/src/testdir/test_ins_complete.vim b/src/testdir/test_ins_complete.vim
index a4ac26e06c..3e6d8da7da 100644
--- a/src/testdir/test_ins_complete.vim
+++ b/src/testdir/test_ins_complete.vim
@@ -2267,17 +2267,72 @@ func Test_complete_info_index()
" Ensure 'index' in complete_info() is coherent with the 'items' array.
set completeopt=menu,preview
- " Search forward.
+ " Search forward
call feedkeys("Go\<C-X>\<C-N>\<F5>\<Esc>_dd", 'tx')
call assert_equal("aaa", g:compl_info['items'][g:compl_info['selected']]['word'])
+ call assert_equal(6 , len(g:compl_info['items']))
call feedkeys("Go\<C-X>\<C-N>\<C-N>\<F5>\<Esc>_dd", 'tx')
call assert_equal("bbb", g:compl_info['items'][g:compl_info['selected']]['word'])
+ call assert_equal(6 , len(g:compl_info['items']))
+ call feedkeys("Go\<C-X>\<C-N>\<C-N>\<C-N>\<F5>\<Esc>_dd", 'tx')
+ call assert_equal("ccc", g:compl_info['items'][g:compl_info['selected']]['word'])
+ call assert_equal(6 , len(g:compl_info['items']))
+ call feedkeys("Go\<C-X>\<C-N>\<C-N>\<C-N>\<C-N>\<F5>\<Esc>_dd", 'tx')
+ call assert_equal("ddd", g:compl_info['items'][g:compl_info['selected']]['word'])
+ call assert_equal(6 , len(g:compl_info['items']))
+ call feedkeys("Go\<C-X>\<C-N>\<C-N>\<C-N>\<C-N>\<C-N>\<F5>\<Esc>_dd", 'tx')
+ call assert_equal("eee", g:compl_info['items'][g:compl_info['selected']]['word'])
+ call assert_equal(6 , len(g:compl_info['items']))
+ call feedkeys("Go\<C-X>\<C-N>\<C-N>\<C-N>\<C-N>\<C-N>\<C-N>\<F5>\<Esc>_dd", 'tx')
+ call assert_equal("fff", g:compl_info['items'][g:compl_info['selected']]['word'])
+ call assert_equal(6 , len(g:compl_info['items']))
+ " Search forward: unselected item
+ call feedkeys("Go\<C-X>\<C-N>\<C-N>\<C-N>\<C-N>\<C-N>\<C-N>\<C-N>\<F5>\<Esc>_dd", 'tx')
+ call assert_equal(6 , len(g:compl_info['items']))
+ call assert_equal(-1 , g:compl_info['selected'])
- " Search backward.
+ " Search backward
call feedkeys("Go\<C-X>\<C-P>\<F5>\<Esc>_dd", 'tx')
call assert_equal("fff", g:compl_info['items'][g:compl_info['selected']]['word'])
+ call assert_equal(6 , len(g:compl_info['items']))
call feedkeys("Go\<C-X>\<C-P>\<C-P>\<F5>\<Esc>_dd", 'tx')
call assert_equal("eee", g:compl_info['items'][g:compl_info['selected']]['word'])
+ call assert_equal(6 , len(g:compl_info['items']))
+ call feedkeys("Go\<C-X>\<C-P>\<C-P>\<C-P>\<F5>\<Esc>_dd", 'tx')
+ call assert_equal("ddd", g:compl_info['items'][g:compl_info['selected']]['word'])
+ call assert_equal(6 , len(g:compl_info['items']))
+ call feedkeys("Go\<C-X>\<C-P>\<C-P>\<C-P>\<C-P>\<F5>\<Esc>_dd", 'tx')
+ call assert_equal("ccc", g:compl_info['items'][g:compl_info['selected']]['word'])
+ call assert_equal(6 , len(g:compl_info['items']))
+ call feedkeys("Go\<C-X>\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>\<F5>\<Esc>_dd", 'tx')
+ call assert_equal("bbb", g:compl_info['items'][g:compl_info['selected']]['word'])
+ call assert_equal(6 , len(g:compl_info['items']))
+ call feedkeys("Go\<C-X>\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>\<F5>\<Esc>_dd", 'tx')
+ call assert_equal("aaa", g:compl_info['items'][g:compl_info['selected']]['word'])
+ call assert_equal(6 , len(g:compl_info['items']))
+ " search backwards: unselected item
+ call feedkeys("Go\<C-X>\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>\<F5>\<Esc>_dd", 'tx')
+ call assert_equal(6 , len(g:compl_info['items']))
+ call assert_equal(-1 , g:compl_info['selected'])
+
+ " switch direction: forwards, then backwards
+ call feedkeys("Go\<C-X>\<C-N>\<C-P>\<C-P>\<F5>\<Esc>_dd", 'tx')
+ call assert_equal("fff", g:compl_info['items'][g:compl_info['selected']]['word'])
+ call assert_equal(6 , len(g:compl_info['items']))
+ " switch direction: forwards, then backwards, then forwards again
+ call feedkeys("Go\<C-X>\<C-N>\<C-P>\<C-P>\<F5>\<Esc>_dd", 'tx')
+ call feedkeys("Go\<C-X>\<C-N>\<C-N>\<C-P>\<C-P>\<C-N>\<F5>\<Esc>_dd", 'tx')
+ call assert_equal("aaa", g:compl_info['items'][g:compl_info['selected']]['word'])
+ call assert_equal(6 , len(g:compl_info['items']))
+
+ " switch direction: backwards, then forwards
+ call feedkeys("Go\<C-X>\<C-P>\<C-N>\<C-N>\<F5>\<Esc>_dd", 'tx')
+ call assert_equal("aaa", g:compl_info['items'][g:compl_info['selected']]['word'])
+ call assert_equal(6 , len(g:compl_info['items']))
+ " switch direction: backwards, then forwards, then backwards again
+ call feedkeys("Go\<C-X>\<C-P>\<C-P>\<C-N>\<C-N>\<C-P>\<F5>\<Esc>_dd", 'tx')
+ call assert_equal("fff", g:compl_info['items'][g:compl_info['selected']]['word'])
+ call assert_equal(6 , len(g:compl_info['items']))
" Add 'noselect', check that 'selected' is -1 when nothing is selected.
set completeopt+=noselect
@@ -2289,6 +2344,16 @@ func Test_complete_info_index()
call feedkeys("Go\<C-X>\<C-P>\<F5>\<Esc>_dd", 'tx')
call assert_equal(-1, g:compl_info['selected'])
+ " Check if index out of range
+ " https://github.com/vim/vim/pull/12971
+ call feedkeys("Go\<C-X>\<C-N>\<C-P>\<F5>\<Esc>_dd", 'tx')
+ call assert_equal(0, 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')
+ call assert_equal("aaa", g:compl_info['items'][g:compl_info['selected']]['word'])
+ call assert_equal(6 , len(g:compl_info['items']))
+
set completeopt&
bwipe!
endfunc