From 41282259ba0d0e4ae97caa4c6e77095b1d935e80 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 9 Dec 2022 06:12:13 +0800 Subject: vim-patch:8.2.4366: not enough tests for command line completion Problem: Not enough tests for command line completion. Solution: Add a few more tests. (Yegappan Lakshmanan, closes vim/vim#9760) https://github.com/vim/vim/commit/4d03d870007c593bce2cfa8d0a6597ca3a20fa35 Co-authored-by: Yegappan Lakshmanan --- src/nvim/cmdexpand.c | 1 + src/nvim/testdir/test_cmdline.vim | 47 +++++++++++++++++++++++++++++++++- src/nvim/testdir/test_usercommands.vim | 11 ++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index ca732c6cd9..933ad93964 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -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; diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 9889e46a06..a259d6d85c 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -515,11 +515,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 +573,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:') @@ -1109,6 +1127,25 @@ func Test_cmdline_complete_various() call feedkeys(":chist\\", '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\\\"\", 'xt') + call assert_equal('"e \~Xtest', @:) + call delete('~Xtest') + endif +endfunc + +" Test for 'wildignorecase' +func Test_cmdline_wildignorecase() + CheckUnix + call writefile([], 'XTEST') + set wildignorecase + call feedkeys(":e xt\\\"\", 'xt') + call assert_equal('"e XTEST', @:) + set wildignorecase& + call delete('XTEST') endfunc func Test_cmdline_write_alternatefile() @@ -1773,6 +1810,14 @@ func Test_wildmode() 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\\"\", 'xt') + call assert_equal('"help a', @:) + set wildmenu& + %argdelete delcommand MyCmd delfunc T diff --git a/src/nvim/testdir/test_usercommands.vim b/src/nvim/testdir/test_usercommands.vim index 5b8b384bae..522be0fd61 100644 --- a/src/nvim/testdir/test_usercommands.vim +++ b/src/nvim/testdir/test_usercommands.vim @@ -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 -- cgit From 98dc445767875acd0e1d24ee5c864c18247be29f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 9 Dec 2022 06:15:03 +0800 Subject: vim-patch:8.2.4376: not enough tests for command line completion Problem: Not enough tests for command line completion. Solution: Add a few more tests. (Yegappan Lakshmanan, closes vim/vim#9771) https://github.com/vim/vim/commit/9773db6f9bce7a6f063e23179976d7825ace4d72 Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_cmdline.vim | 97 +++++++++++++++++++++++++++++----- src/nvim/testdir/test_usercommands.vim | 2 +- 2 files changed, 85 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index a259d6d85c..ebb3d4f0b3 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -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 SaveLastScreenLine() +endfunc + +func TearDown() + delfunc SaveLastScreenLine + cunmap +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 \\\"\", 'xt') call assert_equal("\"chistory \", @:) + + " 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/\\\\"\", '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\\\"\", 'xt') + call assert_equal('"e Xtest\', @:) + set completeslash=slash + call feedkeys(":e Xtest\\\"\", 'xt') + call assert_equal('"e Xtest/', @:) + set completeslash& + endif + + " Test for displaying the tail with wildcards + let g:Sline = '' + call feedkeys(":e Xtes?/\\\\"\", 'xt') + call assert_equal('Xtest/a.c Xtest/a.h', g:Sline) + call assert_equal('"e Xtes?/', @:) + let g:Sline = '' + call feedkeys(":e Xtes*/\\\\"\", 'xt') + call assert_equal('Xtest/a.c Xtest/a.h', g:Sline) + call assert_equal('"e Xtes*/', @:) + let g:Sline = '' + call feedkeys(":e Xtes[/\\\\"\", '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') @@ -1075,7 +1127,7 @@ func Test_cmdline_complete_various() map :ls com -nargs=* -complete=mapping MyCmd call feedkeys(":MyCmd \\"\", 'xt') - call assert_equal('"MyCmd ', @:) + call assert_equal('"MyCmd ', @:) mapclear delcom MyCmd @@ -1135,6 +1187,9 @@ func Test_cmdline_complete_various() call assert_equal('"e \~Xtest', @:) call delete('~Xtest') endif + + call feedkeys(":py3f\\\"\", 'xt') + call assert_equal('"py3file', @:) endfunc " Test for 'wildignorecase' @@ -1144,6 +1199,7 @@ func Test_cmdline_wildignorecase() set wildignorecase call feedkeys(":e xt\\\"\", 'xt') call assert_equal('"e XTEST', @:) + call assert_equal(['XTEST'], getcompletion('xt', 'file')) set wildignorecase& call delete('XTEST') endfunc @@ -1756,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 SaveScreenLine() - set nowildmenu set wildmode=full,list let g:Sline = '' - call feedkeys(":MyCmd \t\t\\\"\", 'xt') + call feedkeys(":MyCmd \t\t\\\"\", 'xt') call assert_equal('oneA oneB oneC', g:Sline) call assert_equal('"MyCmd oneA', @:) @@ -1787,7 +1837,7 @@ func Test_wildmode() set wildmode=list:longest let g:Sline = '' - call feedkeys(":MyCmd \t\\\"\", 'xt') + call feedkeys(":MyCmd \t\\\"\", 'xt') call assert_equal('oneA oneB oneC', g:Sline) call assert_equal('"MyCmd one', @:) @@ -1806,7 +1856,7 @@ func Test_wildmode() " Test for listing files with wildmode=list set wildmode=list let g:Sline = '' - call feedkeys(":b A\t\t\\\"\", 'xt') + call feedkeys(":b A\t\t\\\"\", 'xt') call assert_equal('AAA AAAA AAAAA', g:Sline) call assert_equal('"b A', @:) @@ -1816,17 +1866,29 @@ func Test_wildmode() set wildmenu call feedkeys(":help a*\t\\"\", 'xt') call assert_equal('"help a', @:) + " non existing file + call feedkeys(":e a1b2y3z4\t\\"\", 'xt') + call assert_equal('"e a1b2y3z4', @:) set wildmenu& %argdelete delcommand MyCmd delfunc T - delfunc SaveScreenLine - cunmap 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) @@ -2121,13 +2183,22 @@ func Test_suffixes_opt() set suffixes= call feedkeys(":e Xfi*\\\"\", 'xt') call assert_equal('"e Xfile Xfile.c Xfile.o', @:) + call feedkeys(":e Xfi*\\\\"\", 'xt') + call assert_equal('"e Xfile.c', @:) set suffixes=.c call feedkeys(":e Xfi*\\\"\", 'xt') call assert_equal('"e Xfile Xfile.o Xfile.c', @:) + call feedkeys(":e Xfi*\\\\"\", 'xt') + call assert_equal('"e Xfile.o', @:) set suffixes=,, call feedkeys(":e Xfi*\\\"\", 'xt') call assert_equal('"e Xfile.c Xfile.o Xfile', @:) + call feedkeys(":e Xfi*\\\\"\", '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') diff --git a/src/nvim/testdir/test_usercommands.vim b/src/nvim/testdir/test_usercommands.vim index 522be0fd61..6a985d78aa 100644 --- a/src/nvim/testdir/test_usercommands.vim +++ b/src/nvim/testdir/test_usercommands.vim @@ -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() -- cgit