From 95b1191505a567fd309c16615948479456826c92 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 17 Jul 2022 11:57:42 +0800 Subject: vim-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 vim/vim#6041) https://github.com/vim/vim/commit/f9ab52e155dc13f59b654d754041fe78e17b9074 Cherry-pick test_ins_complete.vim changes from patches 8.2.{0522,0615}. --- src/nvim/testdir/test_edit.vim | 18 ++++---- src/nvim/testdir/test_ins_complete.vim | 82 ++++++++++++++++++++++++++++++++++ src/nvim/testdir/test_textformat.vim | 24 ++++++++++ 3 files changed, 115 insertions(+), 9 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index 69a34a1c51..42c77518e4 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -349,8 +349,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) @@ -389,15 +389,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/nvim/testdir/test_ins_complete.vim b/src/nvim/testdir/test_ins_complete.vim index 4b444d15d8..4fcf35c00f 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -601,6 +601,88 @@ func Test_ins_compl_tag_sft() %bwipe! endfunc +" Test for 'completefunc' deleting text +func Test_completefunc_error() + new + " delete text when called for the first time + func CompleteFunc(findstart, base) + if a:findstart == 1 + normal dd + return col('.') - 1 + endif + return ['a', 'b'] + endfunc + set completefunc=CompleteFunc + call setline(1, ['', 'abcd', '']) + call assert_fails('exe "normal 2G$a\\"', 'E840:') + + " delete text when called for the second time + func CompleteFunc2(findstart, base) + if a:findstart == 1 + return col('.') - 1 + endif + normal dd + return ['a', 'b'] + endfunc + set completefunc=CompleteFunc2 + call setline(1, ['', 'abcd', '']) + call assert_fails('exe "normal 2G$a\\"', 'E565:') + + " 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:') + func ListColors() + call complete(col('.'), "blue") + endfunc + call assert_fails('exe "normal i\=ListColors()\"', 'E474:') + func ListMonths() + call complete(col('.'), test_null_list()) + endfunc + " Nvim allows a NULL list + " call assert_fails('exe "normal i\=ListMonths()\"', 'E474:') + 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 func Test_complete_wrapscan() " complete words from another buffer diff --git a/src/nvim/testdir/test_textformat.vim b/src/nvim/testdir/test_textformat.vim index 35a7887761..970f5ae0d0 100644 --- a/src/nvim/testdir/test_textformat.vim +++ b/src/nvim/testdir/test_textformat.vim @@ -1161,6 +1161,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() -- cgit From 656a1889ee48f5d48d248fb5b6b88e2a113c090f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 17 Jul 2022 13:11:46 +0800 Subject: vim-patch:8.2.1984: cannot use :vimgrep in omni completion Problem: Cannot use :vimgrep in omni completion, causing C completion to fail. Solution: Add the EX_LOCK_OK flag to :vimgrep. (closes vim/vim#7292) https://github.com/vim/vim/commit/33aecb1f2c85711d53858b71f5f3c2cbe076435f Cherry-pick Test_resize_from_copen() indent change from patch 8.2.1432. --- src/nvim/testdir/test_quickfix.vim | 84 ++++++++++++++++++++++++++++++++------ 1 file changed, 72 insertions(+), 12 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index af70b37163..290fc488f1 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -3124,20 +3124,80 @@ func Test_file_from_copen() endfunc func Test_resize_from_copen() + augroup QF_Test + au! + au FileType qf resize 5 + augroup END + try + " This should succeed without any exception. No other buffers are + " involved in the autocmd. + copen + finally augroup QF_Test - au! - au FileType qf resize 5 + au! augroup END - try - " This should succeed without any exception. No other buffers are - " involved in the autocmd. - copen - finally - augroup QF_Test - au! - augroup END - augroup! QF_Test - endtry + augroup! QF_Test + endtry +endfunc + +func Test_vimgrep_with_textlock() + new + + " Simple way to execute something with "textwinlock" set. + " Check that vimgrep without jumping can be executed. + au InsertCharPre * vimgrep /RunTheTest/j runtest.vim + normal ax + let qflist = getqflist() + call assert_true(len(qflist) > 0) + call assert_match('RunTheTest', qflist[0].text) + call setqflist([], 'r') + au! InsertCharPre + + " Check that vimgrepadd without jumping can be executed. + au InsertCharPre * vimgrepadd /RunTheTest/j runtest.vim + normal ax + let qflist = getqflist() + call assert_true(len(qflist) > 0) + call assert_match('RunTheTest', qflist[0].text) + call setqflist([], 'r') + au! InsertCharPre + + " Check that lvimgrep without jumping can be executed. + au InsertCharPre * lvimgrep /RunTheTest/j runtest.vim + normal ax + let qflist = getloclist(0) + call assert_true(len(qflist) > 0) + call assert_match('RunTheTest', qflist[0].text) + call setloclist(0, [], 'r') + au! InsertCharPre + + " Check that lvimgrepadd without jumping can be executed. + au InsertCharPre * lvimgrepadd /RunTheTest/j runtest.vim + normal ax + let qflist = getloclist(0) + call assert_true(len(qflist) > 0) + call assert_match('RunTheTest', qflist[0].text) + call setloclist(0, [], 'r') + au! InsertCharPre + + " trying to jump will give an error + au InsertCharPre * vimgrep /RunTheTest/ runtest.vim + call assert_fails('normal ax', 'E565:') + au! InsertCharPre + + au InsertCharPre * vimgrepadd /RunTheTest/ runtest.vim + call assert_fails('normal ax', 'E565:') + au! InsertCharPre + + au InsertCharPre * lvimgrep /RunTheTest/ runtest.vim + call assert_fails('normal ax', 'E565:') + au! InsertCharPre + + au InsertCharPre * lvimgrepadd /RunTheTest/ runtest.vim + call assert_fails('normal ax', 'E565:') + au! InsertCharPre + + bwipe! endfunc " Tests for the quickfix buffer b:changedtick variable -- cgit From b0bbcfa2392a0b6c58274baf5facadda6cdff10a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 17 Jul 2022 12:13:29 +0800 Subject: vim-patch:8.2.2424: some tests are known to cause an error with ASAN Problem: Some tests are known to cause an error with ASAN. Solution: Add CheckNotAsan. https://github.com/vim/vim/commit/97202d951685fc4d90085da676a90644cbf72571 Move CheckNotMSWindows to the right place. Omit test_memory_usage.vim: a Lua test is used for this file. --- src/nvim/testdir/check.vim | 16 +++++++-------- src/nvim/testdir/test_ex_mode.vim | 3 +++ src/nvim/testdir/test_ins_complete.vim | 36 ++++++++++++++++++++-------------- 3 files changed, 32 insertions(+), 23 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/check.vim b/src/nvim/testdir/check.vim index 8f97d959ce..4107df99d6 100644 --- a/src/nvim/testdir/check.vim +++ b/src/nvim/testdir/check.vim @@ -55,6 +55,14 @@ func CheckMSWindows() endif endfunc +" Command to check for NOT running on MS-Windows +command CheckNotMSWindows call CheckNotMSWindows() +func CheckNotMSWindows() + if has('win32') + throw 'Skipped: does not work on MS-Windows' + endif +endfunc + " Command to check for running on Unix command CheckUnix call CheckUnix() func CheckUnix() @@ -129,14 +137,6 @@ func CheckEnglish() endif endfunc -" Command to check for NOT running on MS-Windows -command CheckNotMSWindows call CheckNotMSWindows() -func CheckNotMSWindows() - if has('win32') - throw 'Skipped: does not work on MS-Windows' - endif -endfunc - " Command to check for not running under ASAN command CheckNotAsan call CheckNotAsan() func CheckNotAsan() diff --git a/src/nvim/testdir/test_ex_mode.vim b/src/nvim/testdir/test_ex_mode.vim index b478332c79..122572f32a 100644 --- a/src/nvim/testdir/test_ex_mode.vim +++ b/src/nvim/testdir/test_ex_mode.vim @@ -191,6 +191,9 @@ func Test_ex_mode_errors() endfunc func Test_ex_mode_count_overflow() + " The multiplication causes an integer overflow + CheckNotAsan + " this used to cause a crash let lines =<< trim END call feedkeys("\gQ\") diff --git a/src/nvim/testdir/test_ins_complete.vim b/src/nvim/testdir/test_ins_complete.vim index 4fcf35c00f..532685b9de 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -628,27 +628,33 @@ func Test_completefunc_error() call setline(1, ['', 'abcd', '']) call assert_fails('exe "normal 2G$a\\"', 'E565:') - " 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 +func Test_completefunc_error_not_asan() + " The following test causes an ASAN failure. + CheckNotAsan + + " Jump to a different window from the complete function + 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 +endfunc + " Test for returning non-string values from 'completefunc' func Test_completefunc_invalid_data() new -- cgit From f72ec959580e44d84d944f1c50852e56eb7fc1ad Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 17 Jul 2022 11:47:34 +0800 Subject: vim-patch:8.2.2426: allowing 'completefunc' to switch windows causes trouble Problem: Allowing 'completefunc' to switch windows causes trouble. Solution: use "textwinlock" instead of "textlock". https://github.com/vim/vim/commit/28976e2accf11591c60e8a658a9e03544f0408b2 Assert E565 instead of E578. vim-patch:8.2.0670: cannot change window when evaluating 'completefunc' Problem: Cannot change window when evaluating 'completefunc'. Solution: Make a difference between not changing text or buffers and also not changing window. https://github.com/vim/vim/commit/6adb9ea0a6ca01414f4b591f379b0f829a8273c0 vim-patch:8.2.5029: "textlock" is always zero Problem: "textlock" is always zero. Solution: Remove "textlock" and rename "textwinlock" to "textlock". (closes vim/vim#10489) https://github.com/vim/vim/commit/cfe456543e840d133399551f8626d985e1fb1958 --- src/nvim/testdir/test_ins_complete.vim | 19 ++++++------------- src/nvim/testdir/test_popup.vim | 4 ++-- src/nvim/testdir/test_quickfix.vim | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_ins_complete.vim b/src/nvim/testdir/test_ins_complete.vim index 532685b9de..563d8812f7 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -628,31 +628,24 @@ func Test_completefunc_error() call setline(1, ['', 'abcd', '']) call assert_fails('exe "normal 2G$a\\"', 'E565:') - set completefunc& - delfunc CompleteFunc - delfunc CompleteFunc2 - close! -endfunc - -func Test_completefunc_error_not_asan() - " The following test causes an ASAN failure. - CheckNotAsan - " Jump to a different window from the complete function - func! CompleteFunc(findstart, base) + func CompleteFunc3(findstart, base) if a:findstart == 1 return col('.') - 1 endif wincmd p return ['a', 'b'] endfunc - set completefunc=CompleteFunc + set completefunc=CompleteFunc3 new - call assert_fails('exe "normal a\\"', 'E839:') + call assert_fails('exe "normal a\\"', 'E565:') close! set completefunc& delfunc CompleteFunc + delfunc CompleteFunc2 + delfunc CompleteFunc3 + close! endfunc " Test for returning non-string values from 'completefunc' diff --git a/src/nvim/testdir/test_popup.vim b/src/nvim/testdir/test_popup.vim index 7afa31a6d1..aef32fc504 100644 --- a/src/nvim/testdir/test_popup.vim +++ b/src/nvim/testdir/test_popup.vim @@ -655,8 +655,8 @@ func Test_complete_func_mess() set completefunc=MessComplete new call setline(1, 'Ju') - call feedkeys("A\\/\", 'tx') - call assert_equal('Oct/Oct', getline(1)) + call assert_fails('call feedkeys("A\\/\", "tx")', 'E565:') + call assert_equal('Jan/', getline(1)) bwipe! set completefunc= endfunc diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 290fc488f1..ddd4229f17 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -3143,7 +3143,7 @@ endfunc func Test_vimgrep_with_textlock() new - " Simple way to execute something with "textwinlock" set. + " Simple way to execute something with "textlock" set. " Check that vimgrep without jumping can be executed. au InsertCharPre * vimgrep /RunTheTest/j runtest.vim normal ax -- cgit From 006334f3a7014d5d23df617ed619377464d4956f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 17 Jul 2022 12:21:39 +0800 Subject: vim-patch:8.2.2427: can still switch windows for 'completefunc' Problem: Can still switch windows for 'completefunc'. Solution: Also disallow switching windows for other completions. https://github.com/vim/vim/commit/3eb6bd9c2b36dcce471bfb543c8d5488f1dc17a4 Assert E565 instead of E578. Need to assert a different string because patch 8.2.1919 hasn't been ported yet. --- src/nvim/testdir/test_ins_complete.vim | 2 +- src/nvim/testdir/test_popup.vim | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_ins_complete.vim b/src/nvim/testdir/test_ins_complete.vim index 563d8812f7..93ab17955d 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -614,7 +614,7 @@ func Test_completefunc_error() endfunc set completefunc=CompleteFunc call setline(1, ['', 'abcd', '']) - call assert_fails('exe "normal 2G$a\\"', 'E840:') + call assert_fails('exe "normal 2G$a\\"', 'E565:') " delete text when called for the second time func CompleteFunc2(findstart, base) diff --git a/src/nvim/testdir/test_popup.vim b/src/nvim/testdir/test_popup.vim index aef32fc504..a5e4be49f4 100644 --- a/src/nvim/testdir/test_popup.vim +++ b/src/nvim/testdir/test_popup.vim @@ -382,11 +382,11 @@ func Test_completefunc_opens_new_window_two() setlocal completefunc=DummyCompleteTwo call setline(1, 'two') /^two - call assert_fails('call feedkeys("A\\\\", "x")', 'E764:') - call assert_notequal(winid, win_getid()) - q! + call assert_fails('call feedkeys("A\\\\", "x")', 'E565:') call assert_equal(winid, win_getid()) - call assert_equal('two', getline(1)) + " v8.2.1919 hasn't been ported yet + " call assert_equal('twodef', getline(1)) + call assert_equal('twoDEF', getline(1)) q! endfunc -- cgit