0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.2.0698: insert mode completion not fully tested

Problem:    Insert mode completion not fully tested.
Solution:   Add a few more tests. (Yegappan Lakshmanan, closes #6041)
This commit is contained in:
Bram Moolenaar 2020-05-05 19:57:18 +02:00
parent 221fcc741a
commit f9ab52e155
4 changed files with 134 additions and 9 deletions

View File

@ -328,8 +328,8 @@ func Test_edit_11_indentexpr()
bw!
endfunc
" Test changing indent in replace mode
func Test_edit_12()
" Test changing indent in replace mode
new
call setline(1, ["\tabc", "\tdef"])
call cursor(2, 4)
@ -368,15 +368,15 @@ func Test_edit_12()
call feedkeys("R\<c-t>\<c-t>", 'tnix')
call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$'))
call assert_equal([0, 2, 2, 0], getpos('.'))
set et
set sw& et&
set sw&
" In replace mode, after hitting enter in a line with tab characters,
" pressing backspace should restore the tab characters.
%d
call setline(1, ["\t/*"])
set formatoptions=croql
call cursor(1, 3)
call feedkeys("A\<cr>\<cr>/", 'tnix')
call assert_equal(["\t/*", " *", " */"], getline(1, '$'))
set formatoptions&
setlocal autoindent backspace=2
call setline(1, "\tone\t\ttwo")
exe "normal ggRred\<CR>six" .. repeat("\<BS>", 8)
call assert_equal(["\tone\t\ttwo"], getline(1, '$'))
bw!
endfunc

View File

@ -493,12 +493,43 @@ func Test_completefunc_error()
call setline(1, ['', 'abcd', ''])
call assert_fails('exe "normal 2G$a\<C-X>\<C-U>"', 'E578:')
" Jump to a different window from the complete function
" TODO: The following test causes an ASAN failure. Once this issue is
" addressed, enable the following test.
"func! CompleteFunc(findstart, base)
" if a:findstart == 1
" return col('.') - 1
" endif
" wincmd p
" return ['a', 'b']
"endfunc
"set completefunc=CompleteFunc
"new
"call assert_fails('exe "normal a\<C-X>\<C-U>"', 'E839:')
"close!
set completefunc&
delfunc CompleteFunc
delfunc CompleteFunc2
close!
endfunc
" Test for returning non-string values from 'completefunc'
func Test_completefunc_invalid_data()
new
func! CompleteFunc(findstart, base)
if a:findstart == 1
return col('.') - 1
endif
return [{}, '', 'moon']
endfunc
set completefunc=CompleteFunc
exe "normal i\<C-X>\<C-U>"
call assert_equal('moon', getline(1))
set completefunc&
close!
endfunc
" Test for errors in using complete() function
func Test_complete_func_error()
call assert_fails('call complete(1, ["a"])', 'E785:')
@ -513,6 +544,7 @@ func Test_complete_func_error()
delfunc ListColors
delfunc ListMonths
call assert_fails('call complete_info({})', 'E714:')
call assert_equal([], complete_info(['items']).items)
endfunc
" Test for completing words following a completed word in a line
@ -535,4 +567,71 @@ func Test_complete_wrapscan()
close!
endfunc
" Test for completing special characters
func Test_complete_special_chars()
new
call setline(1, 'int .*[-\^$ func float')
call feedkeys("oin\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>", 'xt')
call assert_equal('int .*[-\^$ func float', getline(2))
close!
endfunc
" Test for completion when text is wrapped across lines.
func Test_complete_across_line()
new
call setline(1, ['red green blue', 'one two three'])
setlocal textwidth=20
exe "normal 2G$a re\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>"
call assert_equal(['one two three red', 'green blue one'], getline(2, '$'))
close!
endfunc
" Test for using CTRL-L to add one character when completing matching
func Test_complete_add_onechar()
new
call setline(1, ['wool', 'woodwork'])
call feedkeys("Gowoo\<C-P>\<C-P>\<C-P>\<C-L>f", 'xt')
call assert_equal('woof', getline(3))
" use 'ignorecase' and backspace to erase characters from the prefix string
" and then add letters using CTRL-L
%d
set ignorecase backspace=2
setlocal complete=.
call setline(1, ['workhorse', 'workload'])
normal Go
exe "normal aWOR\<C-P>\<bs>\<bs>\<bs>\<bs>\<bs>\<bs>\<C-L>r\<C-L>\<C-L>"
call assert_equal('workh', getline(3))
set ignorecase& backspace&
close!
endfunc
" Test insert completion with 'cindent' (adjust the indent)
func Test_complete_with_cindent()
new
setlocal cindent
call setline(1, ['if (i == 1)', " j = 2;"])
exe "normal Go{\<CR>i\<C-X>\<C-L>\<C-X>\<C-L>\<CR>}"
call assert_equal(['{', "\tif (i == 1)", "\t\tj = 2;", '}'], getline(3, '$'))
%d
call setline(1, ['when while', '{', ''])
setlocal cinkeys+==while
exe "normal Giwh\<C-P> "
call assert_equal("\twhile ", getline('$'))
close!
endfunc
" Test for <CTRL-X> <CTRL-V> completion. Complete commands and functions
func Test_complete_cmdline()
new
exe "normal icaddb\<C-X>\<C-V>"
call assert_equal('caddbuffer', getline(1))
exe "normal ocall getqf\<C-X>\<C-V>"
call assert_equal('call getqflist(', getline(2))
exe "normal oabcxyz(\<C-X>\<C-V>"
call assert_equal('abcxyz(', getline(3))
close!
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@ -975,6 +975,30 @@ func Test_whichwrap_multi_byte()
bwipe!
endfunc
" Test for automatically adding comment leaders in insert mode
func Test_threepiece_comment()
new
setlocal expandtab
call setline(1, ["\t/*"])
setlocal formatoptions=croql
call cursor(1, 3)
call feedkeys("A\<cr>\<cr>/", 'tnix')
call assert_equal(["\t/*", " *", " */"], getline(1, '$'))
" If a comment ends in a single line, then don't add it in the next line
%d
call setline(1, '/* line1 */')
call feedkeys("A\<CR>next line", 'xt')
call assert_equal(['/* line1 */', 'next line'], getline(1, '$'))
%d
" Copy the trailing indentation from the leader comment to a new line
setlocal autoindent noexpandtab
call feedkeys("a\t/*\tone\ntwo\n/", 'xt')
call assert_equal(["\t/*\tone", "\t *\ttwo", "\t */"], getline(1, '$'))
close!
endfunc
" Test for the 'f' flag in 'comments' (only the first line has the comment
" string)
func Test_firstline_comment()

View File

@ -746,6 +746,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
698,
/**/
697,
/**/