mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
Merge pull request #21350 from zeertzjq/vim-8.2.4366
vim-patch:8.2.{4366,4376}: cmdline completion tests
This commit is contained in:
@@ -103,6 +103,7 @@ static int sort_func_compare(const void *s1, const void *s2)
|
||||
return strcmp(p1, p2);
|
||||
}
|
||||
|
||||
/// Escape special characters in the cmdline completion matches.
|
||||
static void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char **files, int options)
|
||||
{
|
||||
int i;
|
||||
|
@@ -5,6 +5,19 @@ source screendump.vim
|
||||
source view_util.vim
|
||||
source shared.vim
|
||||
|
||||
func SetUp()
|
||||
func SaveLastScreenLine()
|
||||
let g:Sline = Screenline(&lines - 1)
|
||||
return ''
|
||||
endfunc
|
||||
cnoremap <expr> <F4> SaveLastScreenLine()
|
||||
endfunc
|
||||
|
||||
func TearDown()
|
||||
delfunc SaveLastScreenLine
|
||||
cunmap <F4>
|
||||
endfunc
|
||||
|
||||
func Test_complete_tab()
|
||||
call writefile(['testfile'], 'Xtestfile')
|
||||
call feedkeys(":e Xtest\t\r", "tx")
|
||||
@@ -25,6 +38,43 @@ func Test_complete_list()
|
||||
" used.
|
||||
call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt')
|
||||
call assert_equal("\"chistory \<C-D>", @:)
|
||||
|
||||
" Test for displaying the tail of the completion matches
|
||||
set wildmode=longest,full
|
||||
call mkdir('Xtest')
|
||||
call writefile([], 'Xtest/a.c')
|
||||
call writefile([], 'Xtest/a.h')
|
||||
let g:Sline = ''
|
||||
call feedkeys(":e Xtest/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
|
||||
call assert_equal('a.c a.h', g:Sline)
|
||||
call assert_equal('"e Xtest/', @:)
|
||||
if has('win32')
|
||||
" Test for 'completeslash'
|
||||
set completeslash=backslash
|
||||
call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
|
||||
call assert_equal('"e Xtest\', @:)
|
||||
set completeslash=slash
|
||||
call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
|
||||
call assert_equal('"e Xtest/', @:)
|
||||
set completeslash&
|
||||
endif
|
||||
|
||||
" Test for displaying the tail with wildcards
|
||||
let g:Sline = ''
|
||||
call feedkeys(":e Xtes?/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
|
||||
call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
|
||||
call assert_equal('"e Xtes?/', @:)
|
||||
let g:Sline = ''
|
||||
call feedkeys(":e Xtes*/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
|
||||
call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
|
||||
call assert_equal('"e Xtes*/', @:)
|
||||
let g:Sline = ''
|
||||
call feedkeys(":e Xtes[/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
|
||||
call assert_equal(':e Xtes[/', g:Sline)
|
||||
call assert_equal('"e Xtes[/', @:)
|
||||
|
||||
call delete('Xtest', 'rf')
|
||||
set wildmode&
|
||||
endfunc
|
||||
|
||||
func Test_complete_wildmenu()
|
||||
@@ -386,6 +436,8 @@ func Test_getcompletion()
|
||||
args a.c b.c
|
||||
let l = getcompletion('', 'arglist')
|
||||
call assert_equal(['a.c', 'b.c'], l)
|
||||
let l = getcompletion('a.', 'buffer')
|
||||
call assert_equal(['a.c'], l)
|
||||
%argdelete
|
||||
|
||||
let l = getcompletion('', 'augroup')
|
||||
@@ -515,11 +567,17 @@ func Test_getcompletion()
|
||||
call assert_equal(cmds, l)
|
||||
let l = getcompletion('list ', 'sign')
|
||||
call assert_equal(['Testing'], l)
|
||||
let l = getcompletion('de*', 'sign')
|
||||
call assert_equal(['define'], l)
|
||||
let l = getcompletion('p?', 'sign')
|
||||
call assert_equal(['place'], l)
|
||||
let l = getcompletion('j.', 'sign')
|
||||
call assert_equal(['jump'], l)
|
||||
endif
|
||||
|
||||
" Command line completion tests
|
||||
let l = getcompletion('cd ', 'cmdline')
|
||||
call assert_true(index(l, 'sautest/') >= 0)
|
||||
call assert_true(index(l, 'samples/') >= 0)
|
||||
let l = getcompletion('cd NoMatch', 'cmdline')
|
||||
call assert_equal([], l)
|
||||
let l = getcompletion('let v:n', 'cmdline')
|
||||
@@ -567,6 +625,18 @@ func Test_getcompletion()
|
||||
call delete('Xtags')
|
||||
set tags&
|
||||
|
||||
edit a~b
|
||||
enew
|
||||
call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
|
||||
bw a~b
|
||||
|
||||
if has('unix')
|
||||
edit Xtest\
|
||||
enew
|
||||
call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
|
||||
bw Xtest\
|
||||
endif
|
||||
|
||||
call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:')
|
||||
call assert_fails('call getcompletion("", "burp")', 'E475:')
|
||||
call assert_fails('call getcompletion("abc", [])', 'E475:')
|
||||
@@ -1057,7 +1127,7 @@ func Test_cmdline_complete_various()
|
||||
map <F3> :ls<CR>
|
||||
com -nargs=* -complete=mapping MyCmd
|
||||
call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
|
||||
call assert_equal('"MyCmd <F3>', @:)
|
||||
call assert_equal('"MyCmd <F3> <F4>', @:)
|
||||
mapclear
|
||||
delcom MyCmd
|
||||
|
||||
@@ -1109,6 +1179,29 @@ func Test_cmdline_complete_various()
|
||||
call feedkeys(":chist\<Esc>\<Esc>", 'xt')
|
||||
call assert_equal('"g/a\xb/clearjumps', @:)
|
||||
set wildchar&
|
||||
|
||||
" should be able to complete a file name that starts with a '~'.
|
||||
if has('unix')
|
||||
call writefile([], '~Xtest')
|
||||
call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
|
||||
call assert_equal('"e \~Xtest', @:)
|
||||
call delete('~Xtest')
|
||||
endif
|
||||
|
||||
call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
|
||||
call assert_equal('"py3file', @:)
|
||||
endfunc
|
||||
|
||||
" Test for 'wildignorecase'
|
||||
func Test_cmdline_wildignorecase()
|
||||
CheckUnix
|
||||
call writefile([], 'XTEST')
|
||||
set wildignorecase
|
||||
call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
|
||||
call assert_equal('"e XTEST', @:)
|
||||
call assert_equal(['XTEST'], getcompletion('xt', 'file'))
|
||||
set wildignorecase&
|
||||
call delete('XTEST')
|
||||
endfunc
|
||||
|
||||
func Test_cmdline_write_alternatefile()
|
||||
@@ -1719,22 +1812,16 @@ func Test_cmdline_ctrl_g()
|
||||
endfunc
|
||||
|
||||
" Test for 'wildmode'
|
||||
func Test_wildmode()
|
||||
func Wildmode_tests()
|
||||
func T(a, c, p)
|
||||
return "oneA\noneB\noneC"
|
||||
endfunc
|
||||
command -nargs=1 -complete=custom,T MyCmd
|
||||
|
||||
func SaveScreenLine()
|
||||
let g:Sline = Screenline(&lines - 1)
|
||||
return ''
|
||||
endfunc
|
||||
cnoremap <expr> <F2> SaveScreenLine()
|
||||
|
||||
set nowildmenu
|
||||
set wildmode=full,list
|
||||
let g:Sline = ''
|
||||
call feedkeys(":MyCmd \t\t\<F2>\<C-B>\"\<CR>", 'xt')
|
||||
call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
|
||||
call assert_equal('oneA oneB oneC', g:Sline)
|
||||
call assert_equal('"MyCmd oneA', @:)
|
||||
|
||||
@@ -1750,7 +1837,7 @@ func Test_wildmode()
|
||||
|
||||
set wildmode=list:longest
|
||||
let g:Sline = ''
|
||||
call feedkeys(":MyCmd \t\<F2>\<C-B>\"\<CR>", 'xt')
|
||||
call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
|
||||
call assert_equal('oneA oneB oneC', g:Sline)
|
||||
call assert_equal('"MyCmd one', @:)
|
||||
|
||||
@@ -1769,19 +1856,39 @@ func Test_wildmode()
|
||||
" Test for listing files with wildmode=list
|
||||
set wildmode=list
|
||||
let g:Sline = ''
|
||||
call feedkeys(":b A\t\t\<F2>\<C-B>\"\<CR>", 'xt')
|
||||
call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
|
||||
call assert_equal('AAA AAAA AAAAA', g:Sline)
|
||||
call assert_equal('"b A', @:)
|
||||
|
||||
" when using longest completion match, matches shorter than the argument
|
||||
" should be ignored (happens with :help)
|
||||
set wildmode=longest,full
|
||||
set wildmenu
|
||||
call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
|
||||
call assert_equal('"help a', @:)
|
||||
" non existing file
|
||||
call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
|
||||
call assert_equal('"e a1b2y3z4', @:)
|
||||
set wildmenu&
|
||||
|
||||
%argdelete
|
||||
delcommand MyCmd
|
||||
delfunc T
|
||||
delfunc SaveScreenLine
|
||||
cunmap <F2>
|
||||
set wildmode&
|
||||
%bwipe!
|
||||
endfunc
|
||||
|
||||
func Test_wildmode()
|
||||
" Test with utf-8 encoding
|
||||
call Wildmode_tests()
|
||||
|
||||
" Test with latin1 encoding
|
||||
let save_encoding = &encoding
|
||||
" set encoding=latin1
|
||||
" call Wildmode_tests()
|
||||
let &encoding = save_encoding
|
||||
endfunc
|
||||
|
||||
" Test for interrupting the command-line completion
|
||||
func Test_interrupt_compl()
|
||||
func F(lead, cmdl, p)
|
||||
@@ -2076,13 +2183,22 @@ func Test_suffixes_opt()
|
||||
set suffixes=
|
||||
call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
|
||||
call assert_equal('"e Xfile Xfile.c Xfile.o', @:)
|
||||
call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
|
||||
call assert_equal('"e Xfile.c', @:)
|
||||
set suffixes=.c
|
||||
call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
|
||||
call assert_equal('"e Xfile Xfile.o Xfile.c', @:)
|
||||
call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
|
||||
call assert_equal('"e Xfile.o', @:)
|
||||
set suffixes=,,
|
||||
call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt')
|
||||
call assert_equal('"e Xfile.c Xfile.o Xfile', @:)
|
||||
call feedkeys(":e Xfi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
|
||||
call assert_equal('"e Xfile.o', @:)
|
||||
set suffixes&
|
||||
" Test for getcompletion() with different patterns
|
||||
call assert_equal(['Xfile', 'Xfile.c', 'Xfile.o'], getcompletion('Xfile', 'file'))
|
||||
call assert_equal(['Xfile'], getcompletion('Xfile$', 'file'))
|
||||
call delete('Xfile')
|
||||
call delete('Xfile.c')
|
||||
call delete('Xfile.o')
|
||||
|
@@ -330,7 +330,7 @@ func CustomComplete(A, L, P)
|
||||
endfunc
|
||||
|
||||
func CustomCompleteList(A, L, P)
|
||||
return [ "Monday", "Tuesday", "Wednesday", {}]
|
||||
return [ "Monday", "Tuesday", "Wednesday", {}, v:_null_string]
|
||||
endfunc
|
||||
|
||||
func Test_CmdCompletion()
|
||||
@@ -400,6 +400,17 @@ func Test_CmdCompletion()
|
||||
com! -nargs=? -complete=custom,min DoCmd
|
||||
call assert_fails("call feedkeys(':DoCmd \t', 'tx')", 'E118:')
|
||||
|
||||
" custom completion for a pattern with a backslash
|
||||
let g:ArgLead = ''
|
||||
func! CustCompl(A, L, P)
|
||||
let g:ArgLead = a:A
|
||||
return ['one', 'two', 'three']
|
||||
endfunc
|
||||
com! -nargs=? -complete=customlist,CustCompl DoCmd
|
||||
call feedkeys(":DoCmd a\\\t", 'xt')
|
||||
call assert_equal('a\', g:ArgLead)
|
||||
delfunc CustCompl
|
||||
|
||||
delcom DoCmd
|
||||
endfunc
|
||||
|
||||
|
Reference in New Issue
Block a user