# HG changeset patch # User Bram Moolenaar # Date 1588701605 -7200 # Node ID bce10d039e06f08d8dacf4dce83db734e1020565 # Parent 7b7c9d3abf7c2216407ae368b76e63c4e11bbde0 patch 8.2.0698: insert mode completion not fully tested Commit: https://github.com/vim/vim/commit/f9ab52e155dc13f59b654d754041fe78e17b9074 Author: Bram Moolenaar Date: Tue May 5 19:57:18 2020 +0200 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 https://github.com/vim/vim/issues/6041) diff --git a/src/testdir/test_edit.vim b/src/testdir/test_edit.vim --- a/src/testdir/test_edit.vim +++ b/src/testdir/test_edit.vim @@ -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\\", '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\\/", 'tnix') - call assert_equal(["\t/*", " *", " */"], getline(1, '$')) - set formatoptions& + setlocal autoindent backspace=2 + call setline(1, "\tone\t\ttwo") + exe "normal ggRred\six" .. repeat("\", 8) + call assert_equal(["\tone\t\ttwo"], getline(1, '$')) bw! endfunc diff --git a/src/testdir/test_ins_complete.vim b/src/testdir/test_ins_complete.vim --- a/src/testdir/test_ins_complete.vim +++ b/src/testdir/test_ins_complete.vim @@ -493,12 +493,43 @@ func Test_completefunc_error() call setline(1, ['', 'abcd', '']) call assert_fails('exe "normal 2G$a\\"', '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\\"', '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\\" + 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\\\\\\", '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\\\\\\\\" + 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\\\\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\\\\\\\\r\\" + 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{\i\\\\\}" + call assert_equal(['{', "\tif (i == 1)", "\t\tj = 2;", '}'], getline(3, '$')) + + %d + call setline(1, ['when while', '{', '']) + setlocal cinkeys+==while + exe "normal Giwh\ " + call assert_equal("\twhile ", getline('$')) + close! +endfunc + +" Test for completion. Complete commands and functions +func Test_complete_cmdline() + new + exe "normal icaddb\\" + call assert_equal('caddbuffer', getline(1)) + exe "normal ocall getqf\\" + call assert_equal('call getqflist(', getline(2)) + exe "normal oabcxyz(\\" + call assert_equal('abcxyz(', getline(3)) + close! +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_textformat.vim b/src/testdir/test_textformat.vim --- a/src/testdir/test_textformat.vim +++ b/src/testdir/test_textformat.vim @@ -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\\/", '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\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() diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -747,6 +747,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 698, +/**/ 697, /**/ 696,