From 0c6b39894f4cac99c3d81857986e4eae533fb59a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Sep 2022 06:19:49 +0800 Subject: feat(mapset): support restoring Lua callback (#20024) vim-patch:9.0.0341: mapset() does not restore mapping properly Problem: mapset() does not restore mapping properly. Solution: Use an empty string for . (closes vim/vim#11022) https://github.com/vim/vim/commit/92a3d20682d46359bb50a452b4f831659e799155 --- src/nvim/testdir/test_maparg.vim | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_maparg.vim b/src/nvim/testdir/test_maparg.vim index 17c5f433ac..f903f5b934 100644 --- a/src/nvim/testdir/test_maparg.vim +++ b/src/nvim/testdir/test_maparg.vim @@ -158,11 +158,11 @@ func Test_range_map() call assert_equal("abcd", getline(1)) endfunc -func One_mapset_test(keys) - exe 'nnoremap ' .. a:keys .. ' original' +func One_mapset_test(keys, rhs) + exe 'nnoremap ' .. a:keys .. ' ' .. a:rhs let orig = maparg(a:keys, 'n', 0, 1) call assert_equal(a:keys, orig.lhs) - call assert_equal('original', orig.rhs) + call assert_equal(a:rhs, orig.rhs) call assert_equal('n', orig.mode) exe 'nunmap ' .. a:keys @@ -172,15 +172,16 @@ func One_mapset_test(keys) call mapset('n', 0, orig) let d = maparg(a:keys, 'n', 0, 1) call assert_equal(a:keys, d.lhs) - call assert_equal('original', d.rhs) + call assert_equal(a:rhs, d.rhs) call assert_equal('n', d.mode) exe 'nunmap ' .. a:keys endfunc func Test_mapset() - call One_mapset_test('K') - call One_mapset_test('') + call One_mapset_test('K', 'original') + call One_mapset_test('', 'original') + call One_mapset_test('', 'Nop>') " Check <> key conversion new @@ -203,6 +204,26 @@ func Test_mapset() iunmap K + " Test that is restored properly + inoremap K + call feedkeys("SK\", 'xt') + call assert_equal('', getline(1)) + + let orig = maparg('K', 'i', 0, 1) + call assert_equal('K', orig.lhs) + call assert_equal('', orig.rhs) + call assert_equal('i', orig.mode) + + inoremap K foo + call feedkeys("SK\", 'xt') + call assert_equal('foo', getline(1)) + + call mapset('i', 0, orig) + call feedkeys("SK\", 'xt') + call assert_equal('', getline(1)) + + iunmap K + " Test literal using a backslash let cpo_save = &cpo set cpo-=B -- cgit From 8740e0bd58c7311826e781591db5d29b4b3ffa73 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Sep 2022 09:12:20 +0800 Subject: vim-patch:9.0.0343: ColorScheme autocommand triggered when colorscheme not found (#20032) Problem: ColorScheme autocommand triggered when colorscheme is not found. (Romain Lafourcade) Solution: Only trigger ColorScheme when loading the colorscheme succeeds. (closes vim/vim#11024) https://github.com/vim/vim/commit/5d09a401ec393dc930e1104ceb38eab34681de64 Most of Test_colorscheme() is applicable to Nvim. --- src/nvim/testdir/test_gui.vim | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/nvim/testdir/test_gui.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_gui.vim b/src/nvim/testdir/test_gui.vim new file mode 100644 index 0000000000..c3f1f3163a --- /dev/null +++ b/src/nvim/testdir/test_gui.vim @@ -0,0 +1,43 @@ + +func Test_colorscheme() + " call assert_equal('16777216', &t_Co) + + let colorscheme_saved = exists('g:colors_name') ? g:colors_name : 'default' + let g:color_count = 0 + augroup TestColors + au! + au ColorScheme * let g:color_count += 1 + \ | let g:after_colors = g:color_count + \ | let g:color_after = expand('') + au ColorSchemePre * let g:color_count += 1 + \ | let g:before_colors = g:color_count + \ | let g:color_pre = expand('') + augroup END + + colorscheme torte + redraw! + call assert_equal('dark', &background) + call assert_equal(1, g:before_colors) + call assert_equal(2, g:after_colors) + call assert_equal('torte', g:color_pre) + call assert_equal('torte', g:color_after) + call assert_equal("\ntorte", execute('colorscheme')) + + let a = substitute(execute('hi Search'), "\n\\s\\+", ' ', 'g') + " FIXME: temporarily check less while the colorscheme changes + " call assert_match("\nSearch xxx term=reverse cterm=reverse ctermfg=196 ctermbg=16 gui=reverse guifg=#ff0000 guibg=#000000", a) + " call assert_match("\nSearch xxx term=reverse ", a) + + call assert_fails('colorscheme does_not_exist', 'E185:') + call assert_equal('does_not_exist', g:color_pre) + call assert_equal('torte', g:color_after) + + exec 'colorscheme' colorscheme_saved + augroup TestColors + au! + augroup END + unlet g:color_count g:after_colors g:before_colors + redraw! +endfunc + +" vim: shiftwidth=2 sts=2 expandtab -- cgit From c65b1f3e15662cd14c443e34862237d3dee30977 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Sep 2022 20:18:17 +0800 Subject: vim-patch:9.0.0342: ":wincmd =" equalizes in two directions Problem: ":wincmd =" equalizes in two directions. Solution: Make ":vertical wincmd =" equalize vertically only and ":horizontal wincmd =" equalize horizontally only. https://github.com/vim/vim/commit/21c3a80a7fd6b7fc250ce5dc287963511f54b86f --- src/nvim/testdir/test_window_cmd.vim | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim index 83a3216534..1f4b9b77c6 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -343,6 +343,46 @@ func Test_window_height() bw Xa Xb Xc endfunc +func Test_wincmd_equal() + edit Xone + below split Xtwo + rightbelow vsplit Xthree + call assert_equal('Xone', bufname(winbufnr(1))) + call assert_equal('Xtwo', bufname(winbufnr(2))) + call assert_equal('Xthree', bufname(winbufnr(3))) + + " Xone and Xtwo should be about the same height + let [wh1, wh2] = [winheight(1), winheight(2)] + call assert_inrange(wh1 - 1, wh1 + 1, wh2) + " Xtwo and Xthree should be about the same width + let [ww2, ww3] = [winwidth(2), winwidth(3)] + call assert_inrange(ww2 - 1, ww2 + 1, ww3) + + 1wincmd w + 10wincmd _ + 2wincmd w + 20wincmd | + call assert_equal(10, winheight(1)) + call assert_equal(20, winwidth(2)) + + " equalizing horizontally doesn't change the heights + hor wincmd = + call assert_equal(10, winheight(1)) + let [ww2, ww3] = [winwidth(2), winwidth(3)] + call assert_inrange(ww2 - 1, ww2 + 1, ww3) + + 2wincmd w + 20wincmd | + call assert_equal(20, winwidth(2)) + " equalizing vertically doesn't change the widths + vert wincmd = + call assert_equal(20, winwidth(2)) + let [wh1, wh2] = [winheight(1), winheight(2)] + call assert_inrange(wh1 - 1, wh1 + 1, wh2) + + bwipe Xone Xtwo Xthree +endfunc + func Test_window_width() e Xa vsplit Xb -- cgit From 56bf026deac8eddb1abc8e1d46fde992cfc67ac2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Sep 2022 20:25:34 +0800 Subject: vim-patch:9.0.0346: :horizontal modifier not fully supported Problem: :horizontal modifier not fully supported. Solution: Also use :horizontal for completion and user commands. (closes vim/vim#11025) https://github.com/vim/vim/commit/d3de178e5352fedf0f30b979f46a2fcbca24ea40 --- src/nvim/testdir/test_cmdline.vim | 4 ++++ src/nvim/testdir/test_usercommands.vim | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 4bfd22cb6c..bc06e70ff4 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -926,6 +926,10 @@ func Test_cmdline_complete_various() call feedkeys(":all abc\\\"\", 'xt') call assert_equal("\"all abc\", @:) + " completion for :wincmd with :horizontal modifier + call feedkeys(":horizontal wincm\\\"\", 'xt') + call assert_equal("\"horizontal wincmd", @:) + " completion for a command with a command modifier call feedkeys(":topleft new\\\"\", 'xt') call assert_equal("\"topleft new", @:) diff --git a/src/nvim/testdir/test_usercommands.vim b/src/nvim/testdir/test_usercommands.vim index e37fe43b22..1065dd16e2 100644 --- a/src/nvim/testdir/test_usercommands.vim +++ b/src/nvim/testdir/test_usercommands.vim @@ -101,6 +101,10 @@ function Test_cmdmods() call assert_equal('vertical', g:mods) vert MyCmd call assert_equal('vertical', g:mods) + horizontal MyCmd + call assert_equal('horizontal', g:mods) + hor MyCmd + call assert_equal('horizontal', g:mods) aboveleft belowright botright browse confirm hide keepalt keepjumps \ keepmarks keeppatterns lockmarks noautocmd noswapfile silent -- cgit From ce80b8f50d7d56ac12aa06a64a65799ec18b69af Mon Sep 17 00:00:00 2001 From: Jonas Strittmatter <40792180+smjonas@users.noreply.github.com> Date: Fri, 2 Sep 2022 08:16:17 +0200 Subject: vim-patch:9.0.0349: filetype of *.sil files not well detected (#20050) Problem: Filetype of *.sil files not well detected. Solution: Inspect the file contents to guess the filetype. https://github.com/vim/vim/commit/be807d582499acbe314ead3891481cba6ca136df --- src/nvim/testdir/test_filetype.vim | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 68ce9148a4..4f5ae830b7 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -1824,6 +1824,44 @@ func Test_sig_file() filetype off endfunc +" Test dist#ft#FTsil() +func Test_sil_file() + filetype on + + split Xfile.sil + call assert_equal('sil', &filetype) + bwipe! + + let lines =<< trim END + // valid + let protoErasedPathA = \ABCProtocol.a + + // also valid + let protoErasedPathA = + \ABCProtocol.a + END + call writefile(lines, 'Xfile.sil') + + split Xfile.sil + call assert_equal('sil', &filetype) + bwipe! + + " SILE + + call writefile(['% some comment'], 'Xfile.sil') + split Xfile.sil + call assert_equal('sile', &filetype) + bwipe! + + call writefile(['\begin[papersize=a6]{document}foo\end{document}'], 'Xfile.sil') + split Xfile.sil + call assert_equal('sile', &filetype) + bwipe! + + call delete('Xfile.sil') + filetype off +endfunc + func Test_inc_file() filetype on -- cgit From 2afcdbd63a5b0cbeaad9d83b096a3af5201c67a9 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 2 Sep 2022 15:20:29 +0100 Subject: feat(Man): port to Lua (#19912) Co-authored-by: zeertzjq --- src/nvim/testdir/test_profile.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_profile.vim b/src/nvim/testdir/test_profile.vim index fdb6f13e2b..4225b91bc4 100644 --- a/src/nvim/testdir/test_profile.vim +++ b/src/nvim/testdir/test_profile.vim @@ -40,8 +40,8 @@ func Test_profile_func() call writefile(lines, 'Xprofile_func.vim') call system(GetVimCommand() \ . ' -es --clean' - \ . ' -c "so Xprofile_func.vim"' - \ . ' -c "qall!"') + \ . ' --cmd "so Xprofile_func.vim"' + \ . ' --cmd "qall!"') call assert_equal(0, v:shell_error) let lines = readfile('Xprofile_func.log') @@ -475,7 +475,7 @@ func Test_profdel_func() call Foo3() [CODE] call writefile(lines, 'Xprofile_file.vim') - call system(GetVimCommandClean() . ' -es -c "so Xprofile_file.vim" -c q') + call system(GetVimCommandClean() . ' -es --cmd "so Xprofile_file.vim" --cmd q') call assert_equal(0, v:shell_error) let lines = readfile('Xprofile_file.log') -- cgit From 05b49ef975664ccdfea4e7b5a0fc09c8ed2cf11a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 3 Sep 2022 06:50:11 +0800 Subject: vim-patch:8.2.1505: not all file read and writecode is tested MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Not all file read and writecode is tested. Solution: Add a few tests. (Dominique Pellé, closes vim/vim#6764) https://github.com/vim/vim/commit/1b04ce2d400fda97410a961288c496bd8f445a9c Cherry-pick Test_glob() from patch 8.2.0634. --- src/nvim/testdir/test_eval_stuff.vim | 25 +++++++++++++++++++------ src/nvim/testdir/test_fnamemodify.vim | 6 ++++++ src/nvim/testdir/test_functions.vim | 19 +++++++++++++++++++ 3 files changed, 44 insertions(+), 6 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_eval_stuff.vim b/src/nvim/testdir/test_eval_stuff.vim index eff1376d3c..351120bf11 100644 --- a/src/nvim/testdir/test_eval_stuff.vim +++ b/src/nvim/testdir/test_eval_stuff.vim @@ -91,18 +91,31 @@ func Test_readfile_binary() new call setline(1, ['one', 'two', 'three']) setlocal ff=dos - silent write XReadfile - let lines = readfile('XReadfile') + silent write XReadfile_bin + let lines = 'XReadfile_bin'->readfile() call assert_equal(['one', 'two', 'three'], lines) - let lines = readfile('XReadfile', '', 2) + let lines = readfile('XReadfile_bin', '', 2) call assert_equal(['one', 'two'], lines) - let lines = readfile('XReadfile', 'b') + let lines = readfile('XReadfile_bin', 'b') call assert_equal(["one\r", "two\r", "three\r", ""], lines) - let lines = readfile('XReadfile', 'b', 2) + let lines = readfile('XReadfile_bin', 'b', 2) call assert_equal(["one\r", "two\r"], lines) bwipe! - call delete('XReadfile') + call delete('XReadfile_bin') +endfunc + +func Test_readfile_bom() + call writefile(["\ufeffFOO", "FOO\ufeffBAR"], 'XReadfile_bom') + call assert_equal(['FOO', 'FOOBAR'], readfile('XReadfile_bom')) + call delete('XReadfile_bom') +endfunc + +func Test_readfile_max() + call writefile(range(1, 4), 'XReadfile_max') + call assert_equal(['1', '2'], readfile('XReadfile_max', '', 2)) + call assert_equal(['3', '4'], readfile('XReadfile_max', '', -2)) + call delete('XReadfile_max') endfunc func Test_let_errmsg() diff --git a/src/nvim/testdir/test_fnamemodify.vim b/src/nvim/testdir/test_fnamemodify.vim index 5ae2a5ee17..258a2093bd 100644 --- a/src/nvim/testdir/test_fnamemodify.vim +++ b/src/nvim/testdir/test_fnamemodify.vim @@ -11,6 +11,7 @@ func Test_fnamemodify() call assert_equal('/', fnamemodify('.', ':p')[-1:]) call assert_equal('r', fnamemodify('.', ':p:h')[-1:]) call assert_equal('t', fnamemodify('test.out', ':p')[-1:]) + call assert_equal($HOME .. "/foo" , fnamemodify('~/foo', ':p')) call assert_equal('test.out', fnamemodify('test.out', ':.')) call assert_equal('a', fnamemodify('../testdir/a', ':.')) call assert_equal('~/testdir/test.out', fnamemodify('test.out', ':~')) @@ -95,4 +96,9 @@ func Test_fnamemodify_er() call assert_equal('', fnamemodify(v:_null_string, v:_null_string)) endfunc +func Test_fnamemodify_fail() + call assert_fails('call fnamemodify({}, ":p")', 'E731:') + call assert_fails('call fnamemodify("x", {})', 'E731:') +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 147eda5b0a..99ac6ae32c 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -2015,6 +2015,25 @@ func Test_getmousepos() bwipe! endfunc +" Test for glob() +func Test_glob() + call assert_equal('', glob(v:_null_string)) + call assert_equal('', globpath(v:_null_string, v:_null_string)) + + call writefile([], 'Xglob1') + call writefile([], 'XGLOB2') + set wildignorecase + " Sort output of glob() otherwise we end up with different + " ordering depending on whether file system is case-sensitive. + call assert_equal(['XGLOB2', 'Xglob1'], sort(glob('Xglob[12]', 0, 1))) + set wildignorecase& + + call delete('Xglob1') + call delete('XGLOB2') + + call assert_fails("call glob('*', 0, {})", 'E728:') +endfunc + func HasDefault(msg = 'msg') return a:msg endfunc -- cgit From 7243b1cbde8a08deab6bf29b452b3383fa4f6d8d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 3 Sep 2022 06:46:30 +0800 Subject: vim-patch:9.0.0360: crash when invalid line number on :for is ignored Problem: Crash when invalid line number on :for is ignored. Solution: Do not check breakpoint for non-existing line. https://github.com/vim/vim/commit/35d21c6830fc2d68aca838424a0e786821c5891c Test does not fail without the fix in Nvim as Nvim uses 0 when line number overflows. If it is changed to MAXLNUM then the test does fail without the fix, but using 0 seems better as E481 is still given. --- src/nvim/testdir/test_eval_stuff.vim | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_eval_stuff.vim b/src/nvim/testdir/test_eval_stuff.vim index 351120bf11..dc110af356 100644 --- a/src/nvim/testdir/test_eval_stuff.vim +++ b/src/nvim/testdir/test_eval_stuff.vim @@ -1,5 +1,8 @@ " Tests for various eval things. +source view_util.vim +source shared.vim + function s:foo() abort try return [] == 0 @@ -87,6 +90,18 @@ func Test_for_over_null_string() let &enc = save_enc endfunc +func Test_for_invalid_line_count() + let lines =<< trim END + 111111111111111111111111 for line in ['one'] + endfor + END + call writefile(lines, 'XinvalidFor') + " only test that this doesn't crash + call RunVim([], [], '-u NONE -e -s -S XinvalidFor -c qa') + + call delete('XinvalidFor') +endfunc + func Test_readfile_binary() new call setline(1, ['one', 'two', 'three']) -- cgit From c62e5b50795d38db68f198a3d1230c047fc0ccfa Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 3 Sep 2022 07:51:51 +0800 Subject: vim-patch:9.0.0362: expanding ":e %" does not work for remote files Problem: Expanding ":e %" does not work for remote files. Solution: If the "%" or "#" file does not exist add the expansion anyway. https://github.com/vim/vim/commit/f5724376ab7362b5a98eaa8a331d663ef722c2a2 --- src/nvim/testdir/test_cmdline.vim | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index bc06e70ff4..e40ff65051 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -1055,6 +1055,18 @@ func Test_cmdline_write_alternatefile() bw! endfunc +func Test_cmdline_expand_cur_alt_file() + enew + file http://some.com/file.txt + call feedkeys(":e %\\\"\", 'xt') + call assert_equal('"e http://some.com/file.txt', @:) + edit another + call feedkeys(":e #\\\"\", 'xt') + call assert_equal('"e http://some.com/file.txt', @:) + bwipe + bwipe http://some.com/file.txt +endfunc + " using a leading backslash here set cpo+=C -- cgit From 9d1d3a67073ab04f29a1e437e90faede764a4313 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Wed, 7 Sep 2022 15:55:39 +0200 Subject: vim-patch:9.0.0402: javascript module files are not recoginzed (#20108) Problem: Javascript module files are not recoginzed. Solution: Recognize "*.jsm" files as Javascript. (Brett Holman, closes vim/vim#11069) https://github.com/vim/vim/commit/bb6c4073e79e86ef69c315338e00c12f0d8d6395 --- src/nvim/testdir/test_filetype.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 4f5ae830b7..703d420847 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -275,7 +275,7 @@ let s:filename_checks = { \ 'jam': ['file.jpl', 'file.jpr', 'JAM-file.file', 'JAM.file', 'Prl-file.file', 'Prl.file'], \ 'java': ['file.java', 'file.jav'], \ 'javacc': ['file.jj', 'file.jjt'], - \ 'javascript': ['file.js', 'file.javascript', 'file.es', 'file.mjs', 'file.cjs'], + \ 'javascript': ['file.js', 'file.jsm', 'file.javascript', 'file.es', 'file.mjs', 'file.cjs'], \ 'javascript.glimmer': ['file.gjs'], \ 'javascriptreact': ['file.jsx'], \ 'jess': ['file.clp'], -- cgit From ead524656dc1664622f80509a983519a190ca48a Mon Sep 17 00:00:00 2001 From: luukvbaal <31730729+luukvbaal@users.noreply.github.com> Date: Wed, 7 Sep 2022 18:08:00 +0200 Subject: vim-patch:9.0.0403: 'equalalways' may be off when 'laststatus' is zero (#20109) Problem: 'equalalways' may be off when 'laststatus' is zero. Solution: call last_status() before win_equal(). (Luuk van Baal, closes https://github.com/vim/vim/pull/11070) https://github.com/vim/vim/commit/fd7e60a33ddd83a82da4eb6267f1c12fa926f32b --- src/nvim/testdir/test_window_cmd.vim | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim index 1f4b9b77c6..1f9d6b59b7 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -1464,4 +1464,19 @@ func Test_win_move_statusline() %bwipe! endfunc +func Test_win_equal_last_status() + let save_lines = &lines + set lines=20 + set splitbelow + set laststatus=0 + + split | split | quit + call assert_equal(winheight(1), winheight(2)) + + let &lines = save_lines + set splitbelow& + set laststatus& +endfunc + + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 93a0c2dd63e369528664037b118ff9b9b38a20d4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 8 Sep 2022 08:12:10 +0800 Subject: vim-patch:8.2.3702: first key in dict is seen as curly expression and fails Problem: First key in dict is seen as curly expression and fails. Solution: Ignore failure of curly expression. (closes vim/vim#9247) https://github.com/vim/vim/commit/98cb90ef865089a5ddd20bc0303d449fb7d97fb2 --- src/nvim/testdir/test_listdict.vim | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_listdict.vim b/src/nvim/testdir/test_listdict.vim index 08c415a069..f0440ae14b 100644 --- a/src/nvim/testdir/test_listdict.vim +++ b/src/nvim/testdir/test_listdict.vim @@ -165,6 +165,9 @@ func Test_dict() call assert_equal({'c': 'ccc', '1': 99, 'b': [1, 2, function('strlen')], '3': 33, '-1': {'a': 1}}, d) call filter(d, 'v:key =~ ''[ac391]''') call assert_equal({'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}}, d) + + " allow key starting with number at the start, not a curly expression + call assert_equal({'1foo': 77}, #{1foo: 77}) endfunc " Dictionary identity -- cgit From 4a67f9d386bb16149eecf32f45a3cb73878f12e7 Mon Sep 17 00:00:00 2001 From: ii14 Date: Wed, 7 Sep 2022 20:45:22 +0200 Subject: vim-patch:9.0.0409: #{g:x} was seen as a curly-braces expression Problem: #{g:x} was seen as a curly-braces expression. Solution: Do never see #{} as a curly-braces expression. (closes vim/vim#11075) https://github.com/vim/vim/commit/7c7e1e9b98d4e5dbe7358c795a635c6f1f36f418 --- src/nvim/testdir/test_listdict.vim | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_listdict.vim b/src/nvim/testdir/test_listdict.vim index f0440ae14b..9cef6905a5 100644 --- a/src/nvim/testdir/test_listdict.vim +++ b/src/nvim/testdir/test_listdict.vim @@ -168,6 +168,10 @@ func Test_dict() " allow key starting with number at the start, not a curly expression call assert_equal({'1foo': 77}, #{1foo: 77}) + + " #{expr} is not a curly expression + let x = 'x' + call assert_equal(#{g: x}, #{g:x}) endfunc " Dictionary identity -- cgit From 08602ec1ab2674385ddda8feaef2d3d9360d834d Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Thu, 8 Sep 2022 16:06:00 +0200 Subject: vim-patch:9.0.0417: Jsonnet files are not recognized (#20119) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Jsonnet files are not recognized. Solution: Add a pattern for Jsonnet files. (Cezary Drożak, closes vim/vim#11073, closes vim/vim#11081) https://github.com/vim/vim/commit/2a4c885d54171f68ec2c2d6eb4ae281c7fefb802 --- src/nvim/testdir/test_filetype.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 703d420847..8448154bfa 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -285,6 +285,7 @@ let s:filename_checks = { \ 'json': ['file.json', 'file.jsonp', 'file.json-patch', 'file.webmanifest', 'Pipfile.lock', 'file.ipynb', '.babelrc', '.eslintrc', '.prettierrc', '.firebaserc', 'file.slnf'], \ 'json5': ['file.json5'], \ 'jsonc': ['file.jsonc'], + \ 'jsonnet': ['file.jsonnet', 'file.libjsonnet'], \ 'jsp': ['file.jsp'], \ 'julia': ['file.jl'], \ 'kconfig': ['Kconfig', 'Kconfig.debug', 'Kconfig.file'], -- cgit From ad2d6a624b10a52cdcfb7fdd9d8b1be24b13ed83 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Fri, 9 Sep 2022 17:53:15 +0200 Subject: vim-patch:9.0.0424: gitattributes files are not recognized (#20134) Problem: gitattributes files are not recognized. Solution: Add patterns to match gitattributes files. (closes vim/vim#11085) https://github.com/vim/vim/commit/7d56cfc861e57145f003315efd835cf5dfd5b145 --- src/nvim/testdir/test_filetype.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 8448154bfa..d983a36840 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -213,6 +213,7 @@ let s:filename_checks = { \ 'gedcom': ['file.ged', 'lltxxxxx.txt', '/tmp/lltmp', '/tmp/lltmp-file', 'any/tmp/lltmp', 'any/tmp/lltmp-file'], \ 'gemtext': ['file.gmi', 'file.gemini'], \ 'gift': ['file.gift'], + \ 'gitattributes': ['file.git/info/attributes', '.gitattributes', '/.config/git/attributes', '/etc/gitattributes', '/usr/local/etc/gitattributes', 'some.git/info/attributes'], \ 'gitcommit': ['COMMIT_EDITMSG', 'MERGE_MSG', 'TAG_EDITMSG', 'NOTES_EDITMSG', 'EDIT_DESCRIPTION'], \ 'gitconfig': ['file.git/config', 'file.git/config.worktree', 'file.git/worktrees/x/config.worktree', '.gitconfig', '.gitmodules', 'file.git/modules//config', '/.config/git/config', '/etc/gitconfig', '/usr/local/etc/gitconfig', '/etc/gitconfig.d/file', 'any/etc/gitconfig.d/file', '/.gitconfig.d/file', 'any/.config/git/config', 'any/.gitconfig.d/file', 'some.git/config', 'some.git/modules/any/config'], \ 'gitolite': ['gitolite.conf', '/gitolite-admin/conf/file', 'any/gitolite-admin/conf/file'], -- cgit From 9b0e1256e25d387bf65cb9baa1edd99fbc128724 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Fri, 9 Sep 2022 18:48:12 +0200 Subject: vim-patch:9.0.0427: Drupal theme files are not recognized (#20138) Problem: Drupal theme files are not recognized. Solution: Use php filetype for Drupl theme files. Remove trailing spaces. (Rodrigo Aguilera, closes vim/vim#11096) https://github.com/vim/vim/commit/8995c4cd4e697141faf74da9a87e0c1221bfb161 --- src/nvim/testdir/test_filetype.vim | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index d983a36840..1cc804117a 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -409,7 +409,7 @@ let s:filename_checks = { \ 'perl': ['file.plx', 'file.al', 'file.psgi', 'gitolite.rc', '.gitolite.rc', 'example.gitolite.rc'], \ 'pf': ['pf.conf'], \ 'pfmain': ['main.cf'], - \ 'php': ['file.php', 'file.php9', 'file.phtml', 'file.ctp', 'file.phpt'], + \ 'php': ['file.php', 'file.php9', 'file.phtml', 'file.ctp', 'file.phpt', 'file.theme'], \ 'pike': ['file.pike', 'file.pmod'], \ 'pilrc': ['file.rcp'], \ 'pine': ['.pinerc', 'pinerc', '.pinercex', 'pinercex'], @@ -534,7 +534,7 @@ let s:filename_checks = { \ 'stata': ['file.ado', 'file.do', 'file.imata', 'file.mata'], \ 'stp': ['file.stp'], \ 'sudoers': ['any/etc/sudoers', 'sudoers.tmp', '/etc/sudoers', 'any/etc/sudoers.d/file'], - \ 'supercollider': ['file.quark'], + \ 'supercollider': ['file.quark'], \ 'surface': ['file.sface'], \ 'svelte': ['file.svelte'], \ 'svg': ['file.svg'], @@ -1352,7 +1352,7 @@ func Test_mod_file() unlet g:filetype_mod bwipe! - " RAPID header start with a line containing only "%%%", + " RAPID header start with a line containing only "%%%", " but is not always present. call writefile(['%%%'], 'modfile.mod') split modfile.mod @@ -1368,7 +1368,7 @@ func Test_mod_file() bwipe! call delete('modfile.Mod') - " RAPID is not case sensitive, embedded spaces, sysmodule, + " RAPID is not case sensitive, embedded spaces, sysmodule, " file starts with empty line(s). call writefile(['', 'MODULE rapidmödüle (SYSMODULE,NOSTEPIN)'], 'modfile.MOD') split modfile.MOD @@ -1496,7 +1496,7 @@ func Test_prg_file() unlet g:filetype_prg bwipe! - " RAPID header start with a line containing only "%%%", + " RAPID header start with a line containing only "%%%", " but is not always present. call writefile(['%%%'], 'prgfile.prg') split prgfile.prg @@ -1512,7 +1512,7 @@ func Test_prg_file() bwipe! call delete('prgfile.Prg') - " RAPID is not case sensitive, embedded spaces, sysmodule, + " RAPID is not case sensitive, embedded spaces, sysmodule, " file starts with empty line(s). call writefile(['', 'MODULE rapidmödüle (SYSMODULE,NOSTEPIN)'], 'prgfile.PRG') split prgfile.PRG @@ -1623,7 +1623,7 @@ func Test_sys_file() unlet g:filetype_sys bwipe! - " RAPID header start with a line containing only "%%%", + " RAPID header start with a line containing only "%%%", " but is not always present. call writefile(['%%%'], 'sysfile.sys') split sysfile.sys @@ -1639,7 +1639,7 @@ func Test_sys_file() bwipe! call delete('sysfile.Sys') - " RAPID is not case sensitive, embedded spaces, sysmodule, + " RAPID is not case sensitive, embedded spaces, sysmodule, " file starts with empty line(s). call writefile(['', 'MODULE rapidmödüle (SYSMODULE,NOSTEPIN)'], 'sysfile.SYS') split sysfile.SYS -- cgit From 40f9f479b746d0f76fbdd4bc0567d593ca7a6070 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 10 Sep 2022 13:30:54 +0200 Subject: vim-patch:9.0.0434: gitignore files are not recognized (#20143) Problem: gitignore files are not recognized. Solution: Add patterns for the gitignore filetype. (closes vim/vim#11102) https://github.com/vim/vim/commit/9ba2786f15f0b53a90fd221832a5bedfc6dbfe20 --- src/nvim/testdir/test_filetype.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 1cc804117a..09fb9556f4 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -216,6 +216,7 @@ let s:filename_checks = { \ 'gitattributes': ['file.git/info/attributes', '.gitattributes', '/.config/git/attributes', '/etc/gitattributes', '/usr/local/etc/gitattributes', 'some.git/info/attributes'], \ 'gitcommit': ['COMMIT_EDITMSG', 'MERGE_MSG', 'TAG_EDITMSG', 'NOTES_EDITMSG', 'EDIT_DESCRIPTION'], \ 'gitconfig': ['file.git/config', 'file.git/config.worktree', 'file.git/worktrees/x/config.worktree', '.gitconfig', '.gitmodules', 'file.git/modules//config', '/.config/git/config', '/etc/gitconfig', '/usr/local/etc/gitconfig', '/etc/gitconfig.d/file', 'any/etc/gitconfig.d/file', '/.gitconfig.d/file', 'any/.config/git/config', 'any/.gitconfig.d/file', 'some.git/config', 'some.git/modules/any/config'], + \ 'gitignore': ['file.git/info/exclude', '.gitignore', '/.config/git/ignore', 'some.git/info/exclude'], \ 'gitolite': ['gitolite.conf', '/gitolite-admin/conf/file', 'any/gitolite-admin/conf/file'], \ 'gitrebase': ['git-rebase-todo'], \ 'gitsendemail': ['.gitsendemail.msg.xxxxxx'], -- cgit From f98cff9575e75a050d2bde01ad950c0c72bcfc3e Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sun, 11 Sep 2022 16:07:54 +0200 Subject: vim-patch:9.0.0443: blueprint files are not recognized (#20155) Problem: Blueprint files are not recognized. Solution: Add a pattern for blueprint files. (Gabriele Musco, closes vim/vim#11107) https://github.com/vim/vim/commit/cce82a55b8105560a2ef724999c856966337b48e --- src/nvim/testdir/test_filetype.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 09fb9556f4..8d7c8f0c87 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -88,6 +88,7 @@ let s:filename_checks = { \ 'bindzone': ['named.root', '/bind/db.file', '/named/db.file', 'any/bind/db.file', 'any/named/db.file'], \ 'bitbake': ['file.bb', 'file.bbappend', 'file.bbclass', 'build/conf/local.conf', 'meta/conf/layer.conf', 'build/conf/bbappend.conf', 'meta-layer/conf/distro/foo.conf'], \ 'blank': ['file.bl'], + \ 'blueprint': ['file.blp'], \ 'bsdl': ['file.bsd', 'file.bsdl'], \ 'bst': ['file.bst'], \ 'bzl': ['file.bazel', 'file.bzl', 'WORKSPACE'], -- cgit From 245ac6f263b6017c050f885212ee80e5738d3b9f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 12 Sep 2022 17:10:31 +0800 Subject: vim-patch:8.2.5034: there is no way to get the byte index from a virtual column Problem: There is no way to get the byte index from a virtual column. Solution: Add virtcol2col(). (Yegappan Lakshmanan, closes vim/vim#10477, closes vim/vim#10098) https://github.com/vim/vim/commit/5a6ec10cc80ab02eeff644ab19b82312630ea855 Cherry-pick tv_check_for_number_arg() from Vim. Cherry-pick pathshorten() doc change. --- src/nvim/testdir/test_cursor_func.vim | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cursor_func.vim b/src/nvim/testdir/test_cursor_func.vim index f13842edc8..2e625f2388 100644 --- a/src/nvim/testdir/test_cursor_func.vim +++ b/src/nvim/testdir/test_cursor_func.vim @@ -373,4 +373,26 @@ func Test_setcursorcharpos() %bw! endfunc +" Test for virtcol2col() +func Test_virtcol2col() + new + call setline(1, ["a\tb\tc"]) + call assert_equal(1, virtcol2col(0, 1, 1)) + call assert_equal(2, virtcol2col(0, 1, 2)) + call assert_equal(2, virtcol2col(0, 1, 8)) + call assert_equal(3, virtcol2col(0, 1, 9)) + call assert_equal(4, virtcol2col(0, 1, 10)) + call assert_equal(4, virtcol2col(0, 1, 16)) + call assert_equal(5, virtcol2col(0, 1, 17)) + call assert_equal(-1, virtcol2col(10, 1, 1)) + call assert_equal(-1, virtcol2col(0, 10, 1)) + call assert_equal(-1, virtcol2col(0, -1, 1)) + call assert_equal(-1, virtcol2col(0, 1, -1)) + call assert_equal(5, virtcol2col(0, 1, 20)) + call assert_fails('echo virtcol2col("0", 1, 20)', 'E1210:') + call assert_fails('echo virtcol2col(0, "1", 20)', 'E1210:') + call assert_fails('echo virtcol2col(0, 1, "1")', 'E1210:') + bw! +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From a48e42a29d2eeef3f3ee0e7e1a89f981efa82d54 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 12 Sep 2022 19:09:23 +0800 Subject: vim-patch:8.2.4671: 'wildignorecase' is sometimes not used for glob() (#20165) Problem: 'wildignorecase' is sometimes not used for glob(). Solution: Also use 'wildignorecase' when there are no wildcards. (closes vim/vim#10066, closes vim/vim#8350) https://github.com/vim/vim/commit/a3157a476bfa8c3077d510cc8400093c0d115df5 --- src/nvim/testdir/test_functions.vim | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 99ac6ae32c..c41884936e 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -2026,6 +2026,8 @@ func Test_glob() " Sort output of glob() otherwise we end up with different " ordering depending on whether file system is case-sensitive. call assert_equal(['XGLOB2', 'Xglob1'], sort(glob('Xglob[12]', 0, 1))) + " wildignorecase shall be applied even when the pattern contains no wildcards. + call assert_equal('XGLOB2', glob('xglob2')) set wildignorecase& call delete('Xglob1') -- cgit From afe01842ef37620e63cab815b84c89454a6b4a87 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Mon, 12 Sep 2022 15:12:39 +0200 Subject: vim-patch:9.0.0448: SubRip files are not recognized (#20167) Problem: SubRip files are not recognized. Solution: Add a pattern for SubRip. (closes vim/vim#11113) https://github.com/vim/vim/commit/5a4eb55122e45444d3a6c56ce108ce29bc8e52ab --- src/nvim/testdir/test_filetype.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 8d7c8f0c87..cf40f6211b 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -530,6 +530,7 @@ let s:filename_checks = { \ 'squid': ['squid.conf'], \ 'squirrel': ['file.nut'], \ 'srec': ['file.s19', 'file.s28', 'file.s37', 'file.mot', 'file.srec'], + \ 'srt': ['file.srt'], \ 'sshconfig': ['ssh_config', '/.ssh/config', '/etc/ssh/ssh_config.d/file.conf', 'any/etc/ssh/ssh_config.d/file.conf', 'any/.ssh/config', 'any/.ssh/file.conf'], \ 'sshdconfig': ['sshd_config', '/etc/ssh/sshd_config.d/file.conf', 'any/etc/ssh/sshd_config.d/file.conf'], \ 'st': ['file.st'], -- cgit From 5bc0964b97a77148292addd62867c93c5db29085 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 12 Sep 2022 21:47:35 +0800 Subject: vim-patch:9.0.0299: error messages for setcmdline() could be better (#20169) Problem: Error messages for setcmdline() could be better. Solution: Use more specific error messages. (Yegappan Lakshmanan, closes vim/vim#10995) https://github.com/vim/vim/commit/25f1e5556259d536c8608185145b0769262873ff Cherry-pick tv_check_for_opt_number_arg() from Vim. --- src/nvim/testdir/test_cmdline.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index e40ff65051..7443ff8fa4 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -2226,8 +2226,8 @@ func Test_setcmdline() call assert_equal(a:pos, getcmdpos()) call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:') - call assert_fails('call setcmdline({}, 0)', 'E928:') - call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E728:') + call assert_fails('call setcmdline({}, 0)', 'E1174:') + call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:') return '' endfunc -- cgit From 907fc8ac373226556b84c2fdc4fe26525bbdb2c4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 13 Sep 2022 06:23:33 +0800 Subject: vim-patch:9.0.0449: there is no easy way to translate a key code into a string (#20168) Problem: There is no easy way to translate a string with a key code into a readable string. Solution: Add the keytrans() function. (closes vim/vim#11114) https://github.com/vim/vim/commit/cdc839353f68ca43db6446e1b727fc7ba657b738 vim-patch:7b2d87220c6c Add missing part of patch https://github.com/vim/vim/commit/7b2d87220c6c974d5cdae672b6f9620a6bcbd1dc --- src/nvim/testdir/test_functions.vim | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index c41884936e..1750a600f3 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1907,6 +1907,32 @@ func Test_eval() call assert_fails("call eval('5 a')", 'E488:') endfunc +" Test for the keytrans() function +func Test_keytrans() + call assert_equal('', keytrans(' ')) + call assert_equal('', keytrans('<')) + call assert_equal('Tab>', keytrans('')) + call assert_equal('', keytrans("\")) + call assert_equal('', keytrans("\")) + call assert_equal('', keytrans("\")) + call assert_equal('', keytrans("\")) + call assert_equal('', keytrans("\")) + call assert_equal('', keytrans("\")) + call assert_equal('', keytrans("\")) + call assert_equal('', keytrans("\<*M-Space>")) + call assert_equal('', "\<*M-x>"->keytrans()) + call assert_equal('', "\<*C-I>"->keytrans()) + call assert_equal('', "\<*S-3>"->keytrans()) + call assert_equal('π', 'π'->keytrans()) + call assert_equal('', "\"->keytrans()) + call assert_equal('ě', 'ě'->keytrans()) + call assert_equal('', "\"->keytrans()) + call assert_equal('', ''->keytrans()) + call assert_equal('', v:_null_string->keytrans()) + call assert_fails('call keytrans(1)', 'E1174:') + call assert_fails('call keytrans()', 'E119:') +endfunc + " Test for the nr2char() function func Test_nr2char() " set encoding=latin1 -- cgit From f19e91acd8b90eaddaaa6070db260acf8de9aa10 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 13 Sep 2022 22:08:01 +0800 Subject: vim-patch:9.0.0457: substitute prompt does not highlight an empty match (#20186) Problem: Substitute prompt does not highlight an empty match. Solution: Highlight at least one character. https://github.com/vim/vim/commit/a04f457a6c071179bac4088c9314007d39d5c5e0 --- src/nvim/testdir/test_substitute.vim | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_substitute.vim b/src/nvim/testdir/test_substitute.vim index b3a80072d9..1667853575 100644 --- a/src/nvim/testdir/test_substitute.vim +++ b/src/nvim/testdir/test_substitute.vim @@ -1,6 +1,8 @@ " Tests for the substitute (:s) command source shared.vim +source check.vim +source screendump.vim func Test_multiline_subst() enew! @@ -668,6 +670,21 @@ func Test_sub_cmd_9() bw! endfunc +func Test_sub_highlight_zero_match() + CheckRunVimInTerminal + + let lines =<< trim END + call setline(1, ['one', 'two', 'three']) + END + call writefile(lines, 'XscriptSubHighlight', 'D') + let buf = RunVimInTerminal('-S XscriptSubHighlight', #{rows: 8, cols: 60}) + call term_sendkeys(buf, ":%s/^/ /c\") + call VerifyScreenDump(buf, 'Test_sub_highlight_zer_match_1', {}) + + call term_sendkeys(buf, "\") + call StopVimInTerminal(buf) +endfunc + func Test_nocatch_sub_failure_handling() " normal error results in all replacements func Foo() -- cgit From 89b9eab638d5e6467156c25f0d54df48d861ca16 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 15 Sep 2022 11:36:13 +0800 Subject: test(old): remove OpenBSD skip (#20201) --- src/nvim/testdir/test_excmd.vim | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_excmd.vim b/src/nvim/testdir/test_excmd.vim index 9a9e5c546b..caa9b76fda 100644 --- a/src/nvim/testdir/test_excmd.vim +++ b/src/nvim/testdir/test_excmd.vim @@ -230,7 +230,6 @@ endfunc " Test for the :language command func Test_language_cmd() CheckNotMSWindows " FIXME: why does this fail on Windows CI? - CheckNotBSD " FIXME: why does this fail on OpenBSD CI? CheckFeature multi_lang call assert_fails('language ctype non_existing_lang', 'E197:') -- cgit From 708bd686516b420c2b65f4bc4d2c58fe43fb945e Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 13 Sep 2022 12:56:30 +0200 Subject: feat(ui): use msg_grid based implementation for cmdheight=0 --- src/nvim/testdir/test_messages.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_messages.vim b/src/nvim/testdir/test_messages.vim index 3a607ff533..a83fcd7138 100644 --- a/src/nvim/testdir/test_messages.vim +++ b/src/nvim/testdir/test_messages.vim @@ -398,7 +398,7 @@ func Test_cmdheight_zero() " Check change/restore cmdheight when macro call feedkeys("qa", "xt") - call assert_equal(1, &cmdheight) + call assert_equal(0, &cmdheight) call feedkeys("q", "xt") call assert_equal(0, &cmdheight) -- cgit From 622968d7b389b8334ee2f2550c3a00018c4f1879 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 16 Sep 2022 19:40:52 +0800 Subject: vim-patch:9.0.0476: varargs does not work for replacement function of substitute() (#20216) Problem: Varargs does not work for replacement function of substitute(). Solution: Check the varargs flag of the function. (closes vim/vim#11142) https://github.com/vim/vim/commit/48db5dafecacced4a9e42de3f92838b2d59beb4c --- src/nvim/testdir/test_substitute.vim | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_substitute.vim b/src/nvim/testdir/test_substitute.vim index 1667853575..88a3c13d65 100644 --- a/src/nvim/testdir/test_substitute.vim +++ b/src/nvim/testdir/test_substitute.vim @@ -639,12 +639,16 @@ endfunc func SubReplacer(text, submatches) return a:text .. a:submatches[0] .. a:text endfunc +func SubReplacerVar(text, ...) + return a:text .. a:1[0] .. a:text +endfunc func SubReplacer20(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, submatches) return a:t3 .. a:submatches[0] .. a:t11 endfunc func Test_substitute_partial() call assert_equal('1foo2foo3', substitute('123', '2', function('SubReplacer', ['foo']), 'g')) + call assert_equal('1foo2foo3', substitute('123', '2', function('SubReplacerVar', ['foo']), 'g')) " 19 arguments plus one is just OK let Replacer = function('SubReplacer20', repeat(['foo'], 19)) -- cgit From e512d3ecf2b6e0104d2df0d863c8d51a2d7e5ab1 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Fri, 16 Sep 2022 17:52:08 +0200 Subject: vim-patch:9.0.0479: in :def function all closures in loop get the sam… (#20220) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit vim-patch:9.0.0479: in :def function all closures in loop get the same variables Problem: In a :def function all closures in a loop get the same variables. Solution: Use a separate list of variables for LOADOUTER and SAVEOUTER. https://github.com/vim/vim/commit/1aea184a0dc558a222cc5bcbaad9ab0fd700c7b9 (note: patch description is wrong) --- src/nvim/testdir/test_filetype.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index cf40f6211b..4657101a41 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -594,6 +594,7 @@ let s:filename_checks = { \ 'usw2kagtlog': ['usw2kagt.log', 'USW2KAGT.LOG', 'usw2kagt.file.log', 'USW2KAGT.FILE.LOG', 'file.usw2kagt.log', 'FILE.USW2KAGT.LOG'], \ 'vala': ['file.vala'], \ 'vb': ['file.sba', 'file.vb', 'file.vbs', 'file.dsm', 'file.ctl'], + \ 'vdf': ['file.vdf'], \ 'vdmpp': ['file.vpp', 'file.vdmpp'], \ 'vdmrt': ['file.vdmrt'], \ 'vdmsl': ['file.vdm', 'file.vdmsl'], -- cgit From 26b54d5c169d7d4afeb5433355b29eee78c12add Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 17 Sep 2022 09:40:19 +0800 Subject: test(old): add a function roughly equivalent to test_setmouse() (#20224) Mouse movement events usually have no effect, so passing "move" to nvim_input_mouse() works in most cases. --- src/nvim/testdir/setup.vim | 5 +++++ src/nvim/testdir/test_assert.vim | 7 +++---- src/nvim/testdir/test_edit.vim | 8 ++------ src/nvim/testdir/test_functions.vim | 41 ++++++++++++------------------------- src/nvim/testdir/test_mapping.vim | 10 ++++----- 5 files changed, 27 insertions(+), 44 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/setup.vim b/src/nvim/testdir/setup.vim index 472ed4ca14..f895287469 100644 --- a/src/nvim/testdir/setup.vim +++ b/src/nvim/testdir/setup.vim @@ -45,6 +45,11 @@ mapclear! aunmenu * tlunmenu * +" roughly equivalent to test_setmouse() in Vim +func Ntest_setmouse(row, col) + call nvim_input_mouse('move', '', '', 0, a:row - 1, a:col - 1) +endfunc + " Prevent Nvim log from writing to stderr. let $NVIM_LOG_FILE = exists($NVIM_LOG_FILE) ? $NVIM_LOG_FILE : 'Xnvim.log' diff --git a/src/nvim/testdir/test_assert.vim b/src/nvim/testdir/test_assert.vim index fdd8b0bef6..8723a0a38d 100644 --- a/src/nvim/testdir/test_assert.vim +++ b/src/nvim/testdir/test_assert.vim @@ -278,19 +278,18 @@ func Test_assert_with_msg() endfunc func Test_mouse_position() - throw 'Skipped: Nvim does not have test_setmouse()' let save_mouse = &mouse set mouse=a new call setline(1, ['line one', 'line two']) call assert_equal([0, 1, 1, 0], getpos('.')) - call test_setmouse(1, 5) + call Ntest_setmouse(1, 5) call feedkeys("\", "xt") call assert_equal([0, 1, 5, 0], getpos('.')) - call test_setmouse(2, 20) + call Ntest_setmouse(2, 20) call feedkeys("\", "xt") call assert_equal([0, 2, 8, 0], getpos('.')) - call test_setmouse(5, 1) + call Ntest_setmouse(5, 1) call feedkeys("\", "xt") call assert_equal([0, 2, 1, 0], getpos('.')) bwipe! diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index 679b877ef6..0025b93dc7 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -1228,15 +1228,11 @@ func Test_edit_MOUSE() call assert_equal(24, line('w0')) call assert_equal([0, 24, 2, 0], getpos('.')) - " call test_setmouse(4, 3) - call nvim_input_mouse('left', 'press', '', 0, 3, 2) " set mouse position - call getchar() " discard mouse event but keep mouse position + call Ntest_setmouse(4, 3) call feedkeys("A\\", 'tnix') call assert_equal([0, 27, 2, 0], getpos('.')) set mousemodel=extend - " call test_setmouse(5, 3) - call nvim_input_mouse('right', 'press', '', 0, 4, 2) " set mouse position - call getchar() " discard mouse event but keep mouse position + call Ntest_setmouse(5, 3) call feedkeys("A\\\", 'tnix') call assert_equal([0, 28, 2, 0], getpos('.')) set mousemodel& diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 1750a600f3..8555e8c866 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1270,15 +1270,11 @@ func Test_inputlist() call assert_equal(2, c) " Use mouse to make a selection - " call test_setmouse(&lines - 3, 2) - call nvim_input_mouse('left', 'press', '', 0, &lines - 4, 1) " set mouse position - call getchar() " discard mouse event but keep mouse position + call Ntest_setmouse(&lines - 3, 2) call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\\", 'tx') call assert_equal(1, c) " Mouse click outside of the list - " call test_setmouse(&lines - 6, 2) - call nvim_input_mouse('left', 'press', '', 0, &lines - 7, 1) " set mouse position - call getchar() " discard mouse event but keep mouse position + call Ntest_setmouse(&lines - 6, 2) call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\\", 'tx') call assert_equal(-2, c) @@ -1537,13 +1533,12 @@ func Test_getchar() call assert_equal(0, getchar(0)) call setline(1, 'xxxx') - " call test_setmouse(1, 3) - " let v:mouse_win = 9 - " let v:mouse_winid = 9 - " let v:mouse_lnum = 9 - " let v:mouse_col = 9 - " call feedkeys("\", '') - call nvim_input_mouse('left', 'press', 'S', 0, 0, 2) + call Ntest_setmouse(1, 3) + let v:mouse_win = 9 + let v:mouse_winid = 9 + let v:mouse_lnum = 9 + let v:mouse_col = 9 + call feedkeys("\", '') call assert_equal("\", getchar()) call assert_equal(1, v:mouse_win) call assert_equal(win_getid(1), v:mouse_winid) @@ -1975,9 +1970,7 @@ endfunc func Test_getmousepos() enew! call setline(1, "\t\t\t1234") - " call test_setmouse(1, 1) - call nvim_input_mouse('left', 'press', '', 0, 0, 0) - call getchar() " wait for and consume the mouse press + call Ntest_setmouse(1, 1) call assert_equal(#{ \ screenrow: 1, \ screencol: 1, @@ -1987,9 +1980,7 @@ func Test_getmousepos() \ line: 1, \ column: 1, \ }, getmousepos()) - " call test_setmouse(1, 25) - call nvim_input_mouse('left', 'press', '', 0, 0, 24) - call getchar() " wait for and consume the mouse press + call Ntest_setmouse(1, 25) call assert_equal(#{ \ screenrow: 1, \ screencol: 25, @@ -1999,9 +1990,7 @@ func Test_getmousepos() \ line: 1, \ column: 4, \ }, getmousepos()) - " call test_setmouse(1, 50) - call nvim_input_mouse('left', 'press', '', 0, 0, 49) - call getchar() " wait for and consume the mouse press + call Ntest_setmouse(1, 50) call assert_equal(#{ \ screenrow: 1, \ screencol: 50, @@ -2014,9 +2003,7 @@ func Test_getmousepos() " If the mouse is positioned past the last buffer line, "line" and "column" " should act like it's positioned on the last buffer line. - " call test_setmouse(2, 25) - call nvim_input_mouse('left', 'press', '', 0, 1, 24) - call getchar() " wait for and consume the mouse press + call Ntest_setmouse(2, 25) call assert_equal(#{ \ screenrow: 2, \ screencol: 25, @@ -2026,9 +2013,7 @@ func Test_getmousepos() \ line: 1, \ column: 4, \ }, getmousepos()) - " call test_setmouse(2, 50) - call nvim_input_mouse('left', 'press', '', 0, 1, 49) - call getchar() " wait for and consume the mouse press + call Ntest_setmouse(2, 50) call assert_equal(#{ \ screenrow: 2, \ screencol: 50, diff --git a/src/nvim/testdir/test_mapping.vim b/src/nvim/testdir/test_mapping.vim index e1d0b9a9ba..72c84b5356 100644 --- a/src/nvim/testdir/test_mapping.vim +++ b/src/nvim/testdir/test_mapping.vim @@ -1006,15 +1006,14 @@ func Test_plug_remap() endfunc func Test_mouse_drag_mapped_start_select() - CheckFunction test_setmouse set mouse=a set selectmode=key,mouse func ClickExpr() - call test_setmouse(1, 1) + call Ntest_setmouse(1, 1) return "\" endfunc func DragExpr() - call test_setmouse(1, 2) + call Ntest_setmouse(1, 2) return "\" endfunc nnoremap ClickExpr() @@ -1036,14 +1035,13 @@ endfunc " Test for mapping in Insert mode func Test_mouse_drag_insert_map() - CheckFunction test_setmouse set mouse=a func ClickExpr() - call test_setmouse(1, 1) + call Ntest_setmouse(1, 1) return "\" endfunc func DragExpr() - call test_setmouse(1, 2) + call Ntest_setmouse(1, 2) return "\" endfunc inoremap ClickExpr() -- cgit From 72e1041429565c3a592dedc36e8b3004a24cdcc4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 17 Sep 2022 10:20:06 +0800 Subject: vim-patch:9.0.0483: illegal memory access when replacing in virtualedit mode (#20225) Problem: Illegal memory access when replacing in virtualedit mode. Solution: Check for replacing NUL after Tab. https://github.com/vim/vim/commit/c249913edc35c0e666d783bfc21595cf9f7d9e0d Cherry-pick Test_virtualedit_mouse() from patch 9.0.0177. --- src/nvim/testdir/test_virtualedit.vim | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_virtualedit.vim b/src/nvim/testdir/test_virtualedit.vim index 522ca17675..e712896562 100644 --- a/src/nvim/testdir/test_virtualedit.vim +++ b/src/nvim/testdir/test_virtualedit.vim @@ -481,4 +481,53 @@ func Test_global_local_virtualedit() set virtualedit& endfunc +func Test_virtualedit_mouse() + let save_mouse = &mouse + set mouse=a + set virtualedit=all + new + + call setline(1, ["text\tword"]) + redraw + call Ntest_setmouse(1, 4) + call feedkeys("\", "xt") + call assert_equal([0, 1, 4, 0, 4], getcurpos()) + call Ntest_setmouse(1, 5) + call feedkeys("\", "xt") + call assert_equal([0, 1, 5, 0, 5], getcurpos()) + call Ntest_setmouse(1, 6) + call feedkeys("\", "xt") + call assert_equal([0, 1, 5, 1, 6], getcurpos()) + call Ntest_setmouse(1, 7) + call feedkeys("\", "xt") + call assert_equal([0, 1, 5, 2, 7], getcurpos()) + call Ntest_setmouse(1, 8) + call feedkeys("\", "xt") + call assert_equal([0, 1, 5, 3, 8], getcurpos()) + call Ntest_setmouse(1, 9) + call feedkeys("\", "xt") + call assert_equal([0, 1, 6, 0, 9], getcurpos()) + call Ntest_setmouse(1, 15) + call feedkeys("\", "xt") + call assert_equal([0, 1, 10, 2, 15], getcurpos()) + + bwipe! + let &mouse = save_mouse + set virtualedit& +endfunc + +" this was replacing the NUL at the end of the line +func Test_virtualedit_replace_after_tab() + new + s/\v/ 0 + set ve=all + let @" = '' + sil! norm vPvr0 + + call assert_equal("\t0", getline(1)) + set ve& + bwipe! +endfunc + + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 18139a69bc048aebe592df7a633793bfb9cbea39 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 17 Sep 2022 15:39:04 +0800 Subject: vim-patch:8.2.0690: line number of option set by modeline is wrong (#20228) Problem: Line number of option set by modeline is wrong. Solution: Do not double the line number. (Ozaki Kiichi, closes vim/vim#6035) https://github.com/vim/vim/commit/5125874951669944a5f6a4163d6e5d437ae6321e --- src/nvim/testdir/test_modeline.vim | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_modeline.vim b/src/nvim/testdir/test_modeline.vim index b3fe79f545..f69c90cb0b 100644 --- a/src/nvim/testdir/test_modeline.vim +++ b/src/nvim/testdir/test_modeline.vim @@ -281,6 +281,62 @@ func Test_modeline_fails_modelineexpr() call s:modeline_fails('titlestring', 'titlestring=Something()', 'E992:') endfunc +func Test_modeline_setoption_verbose() + let modeline = &modeline + set modeline + + let lines =<< trim END + 1 vim:ts=2 + 2 two + 3 three + 4 four + 5 five + 6 six + 7 seven + 8 eight + END + call writefile(lines, 'Xmodeline') + edit Xmodeline + let info = split(execute('verbose set tabstop?'), "\n") + call assert_match('^\s*Last set from modeline line 1$', info[-1]) + bwipe! + + let lines =<< trim END + 1 one + 2 two + 3 three + 4 vim:ts=4 + 5 five + 6 six + 7 seven + 8 eight + END + call writefile(lines, 'Xmodeline') + edit Xmodeline + let info = split(execute('verbose set tabstop?'), "\n") + call assert_match('^\s*Last set from modeline line 4$', info[-1]) + bwipe! + + let lines =<< trim END + 1 one + 2 two + 3 three + 4 four + 5 five + 6 six + 7 seven + 8 vim:ts=8 + END + call writefile(lines, 'Xmodeline') + edit Xmodeline + let info = split(execute('verbose set tabstop?'), "\n") + call assert_match('^\s*Last set from modeline line 8$', info[-1]) + bwipe! + + let &modeline = modeline + call delete('Xmodeline') +endfunc + func Test_modeline_disable() set modeline call writefile(['vim: sw=2', 'vim: nomodeline', 'vim: sw=3'], 'Xmodeline_disable') -- cgit From 8dc61713d9db433dfa2024b45f3bc590dcb58f83 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sun, 18 Sep 2022 14:16:24 +0200 Subject: vim-patch:9.0.0497: LyRiCs files are not recognized (#20239) Problem: LyRiCs files are not recognized. Solution: Add a pattern to detect LyRiCs files. (closes vim/vim#11155) https://github.com/vim/vim/commit/65ee49decf5677690cd695d5d288e39344965fff --- src/nvim/testdir/test_filetype.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 4657101a41..dd91af88b7 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -327,6 +327,7 @@ let s:filename_checks = { \ 'lss': ['file.lss'], \ 'lua': ['file.lua', 'file.rockspec', 'file.nse'], \ 'lynx': ['lynx.cfg'], + \ 'lyrics': ['file.lrc'], \ 'm3build': ['m3makefile', 'm3overrides'], \ 'm3quake': ['file.quake', 'cm3.cfg'], \ 'm4': ['file.at'], -- cgit From 054c27075bdad4d42d19d29f6bc578f777a50208 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 20 Sep 2022 19:49:00 +0800 Subject: vim-patch:9.0.0509: confusing error for "saveas" command with "nofile" buffer (#20258) Problem: Confusing error for "saveas" command with "nofile" buffer. Solution: Give a clearer error message. (closes vim/vim#11171) https://github.com/vim/vim/commit/500a1f9972afa354f0bc77bc535aabf9f5f0116d --- src/nvim/testdir/test_writefile.vim | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_writefile.vim b/src/nvim/testdir/test_writefile.vim index a8735bcaf1..adc05ab979 100644 --- a/src/nvim/testdir/test_writefile.vim +++ b/src/nvim/testdir/test_writefile.vim @@ -216,6 +216,12 @@ func Test_saveas() syntax off %bw! call delete('Xsaveas.pl') + + " :saveas fails for "nofile" buffer + set buftype=nofile + call assert_fails('saveas Xsafile', 'E676: No matching autocommands for buftype=nofile buffer') + + bwipe! endfunc func Test_write_errors() -- cgit From ae30e388dee08e59c08dffc20c2f5122b8c31249 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Tue, 20 Sep 2022 14:10:00 +0200 Subject: vim-patch:9.0.0510: Chatito files are not recognized (#20260) Problem: Chatito files are not recognized. Solution: Add a pattern for Chatito files. (closes vim/vim#11174) https://github.com/vim/vim/commit/7c046ae99ba85a4fdf1a546157e2ed6f12b79ea6 --- src/nvim/testdir/test_filetype.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index dd91af88b7..e3e698aa60 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -108,6 +108,7 @@ let s:filename_checks = { \ 'ch': ['file.chf'], \ 'chaiscript': ['file.chai'], \ 'chaskell': ['file.chs'], + \ 'chatito': ['file.chatito'], \ 'chill': ['file..ch'], \ 'chordpro': ['file.chopro', 'file.crd', 'file.cho', 'file.crdpro', 'file.chordpro'], \ 'cl': ['file.eni'], -- cgit From 9413f7544bcab6951f9a0c26c4b2e1a6dc477c82 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 20 Sep 2022 20:38:44 +0800 Subject: vim-patch:9.0.0507: cmdline cleared when using :redrawstatus in CmdlineChanged Problem: Command line cleared when using :redrawstatus in CmdlineChanged autocommand event. Solution: Postpone the redraw. (closes vim/vim#11162) https://github.com/vim/vim/commit/bcd6924245c0e73d8be256282656c06aaf91f17c Cherry-pick Test_redraw_in_autocmd() from Vim patch 8.2.4789. --- src/nvim/testdir/test_cmdline.vim | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 7443ff8fa4..faf68d038e 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -127,6 +127,46 @@ func Test_wildmenu_screendump() call delete('XTest_wildmenu') endfunc +func Test_redraw_in_autocmd() + CheckScreendump + + let lines =<< trim END + set cmdheight=2 + autocmd CmdlineChanged * redraw + END + call writefile(lines, 'XTest_redraw', 'D') + + let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8}) + call term_sendkeys(buf, ":for i in range(3)\") + call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {}) + + call term_sendkeys(buf, "let i =") + call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {}) + + " clean up + call term_sendkeys(buf, "\") + call StopVimInTerminal(buf) +endfunc + +func Test_redrawstatus_in_autocmd() + CheckScreendump + + let lines =<< trim END + set cmdheight=2 + autocmd CmdlineChanged * if getcmdline() == 'foobar' | redrawstatus | endif + END + call writefile(lines, 'XTest_redrawstatus', 'D') + + let buf = RunVimInTerminal('-S XTest_redrawstatus', {'rows': 8}) + call term_sendkeys(buf, ":echo \"one\\ntwo\\nthree\\nfour\"\") + call term_sendkeys(buf, ":foobar") + call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {}) + + " clean up + call term_sendkeys(buf, "\") + call StopVimInTerminal(buf) +endfunc + func Test_changing_cmdheight() CheckScreendump -- cgit From 2e4532bea50e5f6fb68ebf750c461c5704fc58c2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 20 Sep 2022 20:54:07 +0800 Subject: vim-patch:9.0.0512: cannot redraw the status lines when editing a command Problem: Cannot redraw the status lines when editing a command. Solution: Only postpone the redraw when messages have scrolled. (closes vim/vim#11170) https://github.com/vim/vim/commit/c14bfc31d907cbee6a3636f780561ad1787cdb9b --- src/nvim/testdir/test_cmdline.vim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index faf68d038e..9fc92b8f25 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -152,15 +152,20 @@ func Test_redrawstatus_in_autocmd() CheckScreendump let lines =<< trim END - set cmdheight=2 + set laststatus=2 + set statusline=%=:%{getcmdline()} autocmd CmdlineChanged * if getcmdline() == 'foobar' | redrawstatus | endif END call writefile(lines, 'XTest_redrawstatus', 'D') let buf = RunVimInTerminal('-S XTest_redrawstatus', {'rows': 8}) + " :redrawstatus is postponed if messages have scrolled call term_sendkeys(buf, ":echo \"one\\ntwo\\nthree\\nfour\"\") call term_sendkeys(buf, ":foobar") call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {}) + " it is not postponed if messages have not scrolled + call term_sendkeys(buf, "\:foobar") + call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_2', {}) " clean up call term_sendkeys(buf, "\") -- cgit From cfdc93e8ac3e6c1577f1582c4b9546c118aa7987 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 20 Sep 2022 21:58:39 +0800 Subject: vim-patch:9.0.0511: unnecessary scrolling for message of only one line (#20261) Problem: Unnecessary scrolling for message of only one line. Solution: Only set msg_scroll when needed. (closes vim/vim#11178) https://github.com/vim/vim/commit/bdedd2bcce3a59028c7504a397ff77d901b1b12a --- src/nvim/testdir/test_messages.vim | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_messages.vim b/src/nvim/testdir/test_messages.vim index a83fcd7138..0f348c22cb 100644 --- a/src/nvim/testdir/test_messages.vim +++ b/src/nvim/testdir/test_messages.vim @@ -171,6 +171,38 @@ func Test_echospace() set ruler& showcmd& endfunc +func Test_warning_scroll() + CheckRunVimInTerminal + let lines =<< trim END + call test_override('ui_delay', 50) + set noruler + set readonly + undo + END + call writefile(lines, 'XTestWarningScroll', 'D') + let buf = RunVimInTerminal('', #{rows: 8}) + + " When the warning comes from a script, messages are scrolled so that the + " stacktrace is visible. + call term_sendkeys(buf, ":source XTestWarningScroll\n") + " only match the final colon in the line that shows the source + call WaitForAssert({-> assert_match(':$', term_getline(buf, 5))}) + call WaitForAssert({-> assert_equal('line 4:W10: Warning: Changing a readonly file', term_getline(buf, 6))}) + call WaitForAssert({-> assert_equal('Already at oldest change', term_getline(buf, 7))}) + call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 8))}) + call term_sendkeys(buf, "\n") + + " When the warning does not come from a script, messages are not scrolled. + call term_sendkeys(buf, ":enew\n") + call term_sendkeys(buf, ":set readonly\n") + call term_sendkeys(buf, 'u') + call WaitForAssert({-> assert_equal('W10: Warning: Changing a readonly file', term_getline(buf, 8))}) + call WaitForAssert({-> assert_equal('Already at oldest change', term_getline(buf, 8))}) + + " clean up + call StopVimInTerminal(buf) +endfunc + " Test more-prompt (see :help more-prompt). func Test_message_more() CheckRunVimInTerminal -- cgit From ad1f353fe1aeb54144a34d1a0de8e318bd5113aa Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 21 Sep 2022 06:47:29 +0800 Subject: vim-patch:9.0.0517: when at the command line :redrawstatus does not work well (#20266) Problem: When at the command line :redrawstatus does not work well. Solution: Only update the statuslines instead of the screen. (closes vim/vim#11180) https://github.com/vim/vim/commit/320d910064320f894a09ffdd1cd800ff5371e97f --- src/nvim/testdir/test_cmdline.vim | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 9fc92b8f25..60f6930c35 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -154,7 +154,7 @@ func Test_redrawstatus_in_autocmd() let lines =<< trim END set laststatus=2 set statusline=%=:%{getcmdline()} - autocmd CmdlineChanged * if getcmdline() == 'foobar' | redrawstatus | endif + autocmd CmdlineChanged * redrawstatus END call writefile(lines, 'XTest_redrawstatus', 'D') @@ -164,8 +164,17 @@ func Test_redrawstatus_in_autocmd() call term_sendkeys(buf, ":foobar") call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {}) " it is not postponed if messages have not scrolled - call term_sendkeys(buf, "\:foobar") + call term_sendkeys(buf, "\:for in in range(3)") call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_2', {}) + " with cmdheight=1 messages have scrolled when typing :endfor + call term_sendkeys(buf, "\:endfor") + call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_3', {}) + call term_sendkeys(buf, "\:set cmdheight=2\") + " with cmdheight=2 messages haven't scrolled when typing :for or :endfor + call term_sendkeys(buf, ":for in in range(3)") + call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_4', {}) + call term_sendkeys(buf, "\:endfor") + call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_5', {}) " clean up call term_sendkeys(buf, "\") -- cgit From 37a71d1f28e5d7fd13f0ede69b4d2558157a9e4b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 21 Sep 2022 11:06:39 +0800 Subject: vim-patch:9.0.0018: going over the end of the typahead (#20269) Problem: Going over the end of the typahead. Solution: Put a NUL after the typeahead. https://github.com/vim/vim/commit/27efc62f5d86afcb2ecb7565587fe8dea4b036fe check_termcode() is N/A. --- src/nvim/testdir/test_mapping.vim | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_mapping.vim b/src/nvim/testdir/test_mapping.vim index 72c84b5356..d7bd53e421 100644 --- a/src/nvim/testdir/test_mapping.vim +++ b/src/nvim/testdir/test_mapping.vim @@ -1127,4 +1127,14 @@ func Test_map_after_timed_out_nop() call delete('Xtest_map_after_timed_out_nop') endfunc +func Test_using_past_typeahead() + nnoremap :00 0 + exe "norm :set \x80\xfb0=0\" + exe "sil norm :0\x0f\\" + + exe "norm :set \x80\xfb0=\" + nunmap :00 +endfunc + + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 71e70d0c9919f1ab25fe3940b32ce549f49b30e8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 22 Sep 2022 09:43:37 +0800 Subject: vim-patch:9.0.0537: the do_set() function is much too long (#20274) Problem: The do_set() function is much too long. Solution: Move setting of a string option to a separate function. https://github.com/vim/vim/commit/4740394f230dda09d6e9337465305741d8ee4fa3 Cherry-pick some tests from Vim patch 8.2.0540. --- src/nvim/testdir/test_options.vim | 92 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index 655d537336..f11f3055f0 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -22,6 +22,21 @@ func Test_whichwrap() set whichwrap=h,h,h call assert_equal('h', &whichwrap) + " For compatibility with Vim 3.0 and before, number values are also + " supported for 'whichwrap' + set whichwrap=1 + call assert_equal('b', &whichwrap) + set whichwrap=2 + call assert_equal('s', &whichwrap) + set whichwrap=4 + call assert_equal('h,l', &whichwrap) + set whichwrap=8 + call assert_equal('<,>', &whichwrap) + set whichwrap=16 + call assert_equal('[,]', &whichwrap) + set whichwrap=31 + call assert_equal('b,s,h,l,<,>,[,]', &whichwrap) + set whichwrap& endfunc @@ -362,6 +377,15 @@ func Test_set_errors() call assert_fails('set winminwidth=10 winwidth=9', 'E592:') call assert_fails("set showbreak=\x01", 'E595:') call assert_fails('set t_foo=', 'E846:') + call assert_fails('set tabstop??', 'E488:') + call assert_fails('set wrapscan!!', 'E488:') + call assert_fails('set tabstop&&', 'E488:') + call assert_fails('set wrapscan<<', 'E488:') + call assert_fails('set wrapscan=1', 'E474:') + call assert_fails('set autoindent@', 'E488:') + call assert_fails('set wildchar=', 'E474:') + call assert_fails('set cmdheight=1a', 'E521:') + call assert_fails('set invcmdheight', 'E474:') if has('python') || has('python3') call assert_fails('set pyxversion=6', 'E474:') endif @@ -845,6 +869,74 @@ func Test_debug_option() set debug& endfunc +" Test for the default CDPATH option +func Test_opt_default_cdpath() + CheckFeature file_in_path + let after =<< trim [CODE] + call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath) + call writefile(v:errors, 'Xtestout') + qall + [CODE] + if has('unix') + let $CDPATH='/path/to/dir1:/path/to/dir2' + else + let $CDPATH='/path/to/dir1;/path/to/dir2' + endif + if RunVim([], after, '') + call assert_equal([], readfile('Xtestout')) + call delete('Xtestout') + endif +endfunc + +" Test for setting keycodes using set +func Test_opt_set_keycode() + call assert_fails('set =abcd + " call assert_equal('abcd', &t_k9) + set & + set =xyz + " call assert_equal('xyz', &t_k9) + set & +endfunc + +" Test for changing options in a sandbox +func Test_opt_sandbox() + for opt in ['backupdir', 'cdpath', 'exrc'] + call assert_fails('sandbox set ' .. opt .. '?', 'E48:') + endfor +endfunc + +" Test for setting an option with local value to global value +func Test_opt_local_to_global() + setglobal equalprg=gprg + setlocal equalprg=lprg + call assert_equal('gprg', &g:equalprg) + call assert_equal('lprg', &l:equalprg) + call assert_equal('lprg', &equalprg) + set equalprg< + call assert_equal('', &l:equalprg) + call assert_equal('gprg', &equalprg) + setglobal equalprg=gnewprg + setlocal equalprg=lnewprg + setlocal equalprg< + call assert_equal('gnewprg', &l:equalprg) + call assert_equal('gnewprg', &equalprg) + set equalprg& +endfunc + +" Test for incrementing, decrementing and multiplying a number option value +func Test_opt_num_op() + set shiftwidth=4 + set sw+=2 + call assert_equal(6, &sw) + set sw-=2 + call assert_equal(4, &sw) + set sw^=2 + call assert_equal(8, &sw) + set shiftwidth& +endfunc + " Test for setting option values using v:false and v:true func Test_opt_boolean() set number& -- cgit From 5d1cb73e7f17c29fc9e68ba293f63d8f8e71c264 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 22 Sep 2022 12:07:16 +0800 Subject: vim-patch:8.2.0712: various code not fully tested Problem: Various code not fully tested. Solution: Add a few more tests. (Yegappan Lakshmanan, closes vim/vim#6049) https://github.com/vim/vim/commit/0ff5dedf0f69e56320199db7a2aad46be2a1f9b7 Nvim does not support encoding=latin1 or setting keycodes/termcaps. --- src/nvim/testdir/test_functions.vim | 16 ++++++++++++++++ src/nvim/testdir/test_options.vim | 9 +++++++++ src/nvim/testdir/test_system.vim | 38 +++++++++++++++++++++++++++++++++++++ src/nvim/testdir/test_termcodes.vim | 26 +++++++++++++++++++++++++ 4 files changed, 89 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 8555e8c866..7262d2d71a 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -462,6 +462,12 @@ func Test_tolower() " invalid memory. call tolower("\xC0\x80\xC0") call tolower("123\xC0\x80\xC0") + + " Test in latin1 encoding + let save_enc = &encoding + " set encoding=latin1 + call assert_equal("abc", tolower("ABC")) + let &encoding = save_enc endfunc func Test_toupper() @@ -533,6 +539,12 @@ func Test_toupper() " invalid memory. call toupper("\xC0\x80\xC0") call toupper("123\xC0\x80\xC0") + + " Test in latin1 encoding + let save_enc = &encoding + " set encoding=latin1 + call assert_equal("ABC", toupper("abc")) + let &encoding = save_enc endfunc func Test_tr() @@ -1096,6 +1108,10 @@ func Test_filewritable() call assert_equal(0, filewritable('doesnotexist')) + call mkdir('Xdir') + call assert_equal(2, filewritable('Xdir')) + call delete('Xdir', 'd') + call delete('Xfilewritable') bw! endfunc diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index f11f3055f0..ec02f1f9da 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -282,6 +282,15 @@ func Test_set_completion() call feedkeys(":set fileencodings:\\\"\", 'tx') call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:) + " Expand key codes. + " call feedkeys(":set \\"\", 'tx') + " call assert_equal('"set ', @:) + + " Expand terminal options. + " call feedkeys(":set t_A\\\"\", 'tx') + " call assert_equal('"set t_AB t_AF t_AU t_AL', @:) + " call assert_fails('call feedkeys(":set =\\", "xt")', 'E474:') + " Expand directories. call feedkeys(":set cdpath=./\\\"\", 'tx') call assert_match('./samples/ ', @:) diff --git a/src/nvim/testdir/test_system.vim b/src/nvim/testdir/test_system.vim index 18692f42c9..bfa8a277bd 100644 --- a/src/nvim/testdir/test_system.vim +++ b/src/nvim/testdir/test_system.vim @@ -141,3 +141,41 @@ func Test_system_with_shell_quote() call delete('Xdir with spaces', 'rf') endtry endfunc + +" Test for 'shellxquote' +func Test_Shellxquote() + CheckUnix + + let save_shell = &shell + let save_sxq = &shellxquote + let save_sxe = &shellxescape + + call writefile(['#!/bin/sh', 'echo "Cmd: [$*]" > Xlog'], 'Xtestshell') + call setfperm('Xtestshell', "r-x------") + set shell=./Xtestshell + + set shellxquote=\\" + call feedkeys(":!pwd\\", 'xt') + call assert_equal(['Cmd: [-c "pwd"]'], readfile('Xlog')) + + set shellxquote=( + call feedkeys(":!pwd\\", 'xt') + call assert_equal(['Cmd: [-c (pwd)]'], readfile('Xlog')) + + set shellxquote=\\"( + call feedkeys(":!pwd\\", 'xt') + call assert_equal(['Cmd: [-c "(pwd)"]'], readfile('Xlog')) + + set shellxescape=\"&<<()@^ + set shellxquote=( + call feedkeys(":!pwd\"&<<{}@^\\", 'xt') + call assert_equal(['Cmd: [-c (pwd^"^&^<^<{}^@^^)]'], readfile('Xlog')) + + let &shell = save_shell + let &shellxquote = save_sxq + let &shellxescape = save_sxe + call delete('Xtestshell') + call delete('Xlog') +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_termcodes.vim b/src/nvim/testdir/test_termcodes.vim index eda485c512..99bc2d1d37 100644 --- a/src/nvim/testdir/test_termcodes.vim +++ b/src/nvim/testdir/test_termcodes.vim @@ -1,4 +1,30 @@ +" Test for translation of special key codes (, , etc.) +func Test_Keycode_Translation() + let keycodes = [ + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""]] + for [k1, k2] in keycodes + exe "nnoremap " .. k1 .. " 2wx" + call assert_true(maparg(k1, 'n', 0, 1).lhs == k2) + exe "nunmap " .. k1 + endfor +endfunc + " Test for terminal keycodes that doesn't have termcap entries func Test_special_term_keycodes() new -- cgit From dd2b7586f36ab10232d9024ddf2dfb436518269e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 22 Sep 2022 10:48:46 +0800 Subject: vim-patch:8.2.2979: not all options code is covered by tests Problem: Not all options code is covered by tests. Solution: Add more tests for options. (Yegappan Lakshmanan, closes vim/vim#8369) https://github.com/vim/vim/commit/5958549760652c173b703613b9cbf09b25a4eddb --- src/nvim/testdir/test_edit.vim | 24 ++++++++++++++++++++++++ src/nvim/testdir/test_excmd.vim | 6 ++++++ src/nvim/testdir/test_help.vim | 11 +++++++++++ src/nvim/testdir/test_mksession.vim | 13 +++++++++++++ src/nvim/testdir/test_options.vim | 32 ++++++++++++++++++++++++++++++++ src/nvim/testdir/test_vartabs.vim | 14 ++++++++++++++ src/nvim/testdir/test_window_cmd.vim | 10 +++++++++- 7 files changed, 109 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index 0025b93dc7..51eb89f71d 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -1927,4 +1927,28 @@ func Test_read_invalid() set encoding=utf-8 endfunc +" Test for the 'revins' option +func Test_edit_revins() + CheckFeature rightleft + new + set revins + exe "normal! ione\ttwo three" + call assert_equal("eerht owt\teno", getline(1)) + call setline(1, "one\ttwo three") + normal! gg$bi a + call assert_equal("one\ttwo a three", getline(1)) + exe "normal! $bi\\" + call assert_equal("one\ttwo a ree", getline(1)) + exe "normal! 0wi\" + call assert_equal("one\t a ree", getline(1)) + exe "normal! 0wi\" + call assert_equal("one\t ", getline(1)) + " newline in insert mode starts at the end of the line + call setline(1, 'one two three') + exe "normal! wi\nfour" + call assert_equal(['one two three', 'ruof'], getline(1, '$')) + set revins& + bw! +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_excmd.vim b/src/nvim/testdir/test_excmd.vim index caa9b76fda..f6ff1b5dc9 100644 --- a/src/nvim/testdir/test_excmd.vim +++ b/src/nvim/testdir/test_excmd.vim @@ -662,6 +662,12 @@ func Sandbox_tests() if has('unix') call assert_fails('cd `pwd`', 'E48:') endif + " some options cannot be changed in a sandbox + call assert_fails('set exrc', 'E48:') + call assert_fails('set cdpath', 'E48:') + if has('xim') + call assert_fails('set imstyle', 'E48:') + endif endfunc func Test_sandbox() diff --git a/src/nvim/testdir/test_help.vim b/src/nvim/testdir/test_help.vim index dbb36facee..19c0fcd820 100644 --- a/src/nvim/testdir/test_help.vim +++ b/src/nvim/testdir/test_help.vim @@ -141,6 +141,17 @@ func Test_helptag_cmd() call delete('Xdir', 'rf') endfunc +" Test for setting the 'helpheight' option in the help window +func Test_help_window_height() + let &cmdheight = &lines - 24 + set helpheight=10 + help + set helpheight=14 + call assert_equal(14, winheight(0)) + set helpheight& cmdheight=1 + close +endfunc + func Test_help_long_argument() try exe 'help \%' .. repeat('0', 1021) diff --git a/src/nvim/testdir/test_mksession.vim b/src/nvim/testdir/test_mksession.vim index 8ec408e62e..ccc775560f 100644 --- a/src/nvim/testdir/test_mksession.vim +++ b/src/nvim/testdir/test_mksession.vim @@ -942,6 +942,19 @@ func Test_mkvimrc() endfor call s:ClearMappings() + + " the 'pastetoggle', 'wildchar' and 'wildcharm' option values should be + " stored as key names in the vimrc file + set pastetoggle= + set wildchar= + set wildcharm= + call assert_fails('mkvimrc Xtestvimrc') + mkvimrc! Xtestvimrc + call assert_notequal(-1, index(readfile('Xtestvimrc'), 'set pastetoggle=')) + call assert_notequal(-1, index(readfile('Xtestvimrc'), 'set wildchar=')) + call assert_notequal(-1, index(readfile('Xtestvimrc'), 'set wildcharm=')) + set pastetoggle& wildchar& wildcharm& + call delete('Xtestvimrc') endfunc diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index ec02f1f9da..b19882a2cc 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -418,6 +418,7 @@ func Test_set_errors() set nomodifiable call assert_fails('set fileencoding=latin1', 'E21:') set modifiable& + " call assert_fails('set t_#-&', 'E522:') endfunc func CheckWasSet(name) @@ -932,6 +933,18 @@ func Test_opt_local_to_global() call assert_equal('gnewprg', &l:equalprg) call assert_equal('gnewprg', &equalprg) set equalprg& + + " Test for setting the global/local value of a boolean option + setglobal autoread + setlocal noautoread + call assert_false(&autoread) + set autoread< + call assert_true(&autoread) + setglobal noautoread + setlocal autoread + setlocal autoread< + call assert_false(&autoread) + set autoread& endfunc " Test for incrementing, decrementing and multiplying a number option value @@ -1082,6 +1095,25 @@ func Test_opt_reset_scroll() call delete('Xscroll') endfunc +" Test for setting an option to a Vi or Vim default +func Test_opt_default() + throw 'Skipped: Nvim has different defaults' + set formatoptions&vi + call assert_equal('vt', &formatoptions) + set formatoptions&vim + call assert_equal('tcq', &formatoptions) +endfunc + +" Test for the 'cmdheight' option +func Test_cmdheight() + %bw! + let ht = &lines + set cmdheight=9999 + call assert_equal(1, winheight(0)) + call assert_equal(ht - 1, &cmdheight) + set cmdheight& +endfunc + " Test for the 'cdhome' option func Test_opt_cdhome() if has('unix') || has('vms') diff --git a/src/nvim/testdir/test_vartabs.vim b/src/nvim/testdir/test_vartabs.vim index 68fe15ff93..0acd7fc1e5 100644 --- a/src/nvim/testdir/test_vartabs.vim +++ b/src/nvim/testdir/test_vartabs.vim @@ -429,4 +429,18 @@ func Test_varsofttabstop() close! endfunc +" Setting 'shiftwidth' to a negative value, should set it to either the value +" of 'tabstop' (if 'vartabstop' is not set) or to the first value in +" 'vartabstop' +func Test_shiftwidth_vartabstop() + throw 'Skipped: Nvim removed this behavior in #6377' + setlocal tabstop=7 vartabstop= + call assert_fails('set shiftwidth=-1', 'E487:') + call assert_equal(7, &shiftwidth) + setlocal tabstop=7 vartabstop=5,7,10 + call assert_fails('set shiftwidth=-1', 'E487:') + call assert_equal(5, &shiftwidth) + setlocal shiftwidth& vartabstop& tabstop& +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim index 1f9d6b59b7..b64f44360b 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -433,7 +433,15 @@ func Test_window_width() call assert_inrange(ww1, ww1 + 1, ww2) call assert_inrange(ww3, ww3 + 1, ww2) - bw Xa Xb Xc + " when the current window width is less than the new 'winwidth', the current + " window width should be increased. + enew | only + split + 10vnew + set winwidth=15 + call assert_equal(15, winwidth(0)) + + %bw! endfunc func Test_equalalways_on_close() -- cgit From 88099c11223398b2e7eb96eaa9385d24046db994 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 22 Sep 2022 11:17:41 +0800 Subject: vim-patch:8.2.2994: various code is not fully tested Problem: Various code is not fully tested. Solution: Add a few more tests. (Yegappan Lakshmanan, closes vim/vim#8378) https://github.com/vim/vim/commit/2d6d718dde7163c971d37b8f4f1ed8f2d25de130 Nvim does not support encoding=latin1 or compatible mode. The two paste tests are applicable. --- src/nvim/testdir/test_excmd.vim | 2 +- src/nvim/testdir/test_mapping.vim | 15 ++++++++ src/nvim/testdir/test_modeline.vim | 28 ++++++++++++++ src/nvim/testdir/test_options.vim | 17 +++++++++ src/nvim/testdir/test_paste.vim | 76 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 src/nvim/testdir/test_paste.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_excmd.vim b/src/nvim/testdir/test_excmd.vim index f6ff1b5dc9..7692d4fc55 100644 --- a/src/nvim/testdir/test_excmd.vim +++ b/src/nvim/testdir/test_excmd.vim @@ -665,7 +665,7 @@ func Sandbox_tests() " some options cannot be changed in a sandbox call assert_fails('set exrc', 'E48:') call assert_fails('set cdpath', 'E48:') - if has('xim') + if has('xim') && has('gui_gtk') call assert_fails('set imstyle', 'E48:') endif endfunc diff --git a/src/nvim/testdir/test_mapping.vim b/src/nvim/testdir/test_mapping.vim index d7bd53e421..bde3624adf 100644 --- a/src/nvim/testdir/test_mapping.vim +++ b/src/nvim/testdir/test_mapping.vim @@ -975,6 +975,21 @@ func Test_abbreviate_multi_byte() bwipe! endfunc +" Test for abbreviations with 'latin1' encoding +func Test_abbreviate_latin1_encoding() + " set encoding=latin1 + call assert_fails('abbr ab#$c ABC', 'E474:') + new + iabbr #i #include + iabbr ## #enddef + exe "normal i#i\" + call assert_equal('#include', getline(1)) + exe "normal 0Di##\" + call assert_equal('#enddef', getline(1)) + %bw! + set encoding=utf-8 +endfunc ++ " Test for always being mapped, even when used with "noremap". func Test_plug_remap() let g:foo = 0 diff --git a/src/nvim/testdir/test_modeline.vim b/src/nvim/testdir/test_modeline.vim index f69c90cb0b..613722fdbd 100644 --- a/src/nvim/testdir/test_modeline.vim +++ b/src/nvim/testdir/test_modeline.vim @@ -1,5 +1,7 @@ " Tests for parsing the modeline. +source check.vim + func Test_modeline_invalid() " This was reading allocated memory in the past. call writefile(['vi:0', 'nothing'], 'Xmodeline') @@ -337,6 +339,32 @@ func Test_modeline_setoption_verbose() call delete('Xmodeline') endfunc +" Test for the 'modeline' default value in compatible and non-compatible modes +" for root and non-root accounts +func Test_modeline_default() + " set compatible + " call assert_false(&modeline) + set nocompatible + call assert_equal(IsRoot() ? 0 : 1, &modeline) + " set compatible&vi + " call assert_false(&modeline) + set compatible&vim + call assert_equal(IsRoot() ? 0 : 1, &modeline) + set compatible& modeline& +endfunc + +" Some options cannot be set from the modeline when 'diff' option is set +func Test_modeline_diff_buffer() + call writefile(['vim: diff foldmethod=marker wrap'], 'Xfile') + set foldmethod& nowrap + new Xfile + call assert_equal('manual', &foldmethod) + call assert_false(&wrap) + set wrap& + call delete('Xfile') + bw +endfunc + func Test_modeline_disable() set modeline call writefile(['vim: sw=2', 'vim: nomodeline', 'vim: sw=3'], 'Xmodeline_disable') diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index b19882a2cc..f49d2cdf33 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -1114,6 +1114,23 @@ func Test_cmdheight() set cmdheight& endfunc +" To specify a control character as a option value, '^' can be used +func Test_opt_control_char() + set wildchar=^v + call assert_equal("\", nr2char(&wildchar)) + set wildcharm=^r + call assert_equal("\", nr2char(&wildcharm)) + " Bug: This doesn't work for the 'cedit' and 'termwinkey' options + set wildchar& wildcharm& +endfunc + +" Test for the 'errorbells' option +func Test_opt_errorbells() + set errorbells + call assert_beeps('s/a1b2/x1y2/') + set noerrorbells +endfunc + " Test for the 'cdhome' option func Test_opt_cdhome() if has('unix') || has('vms') diff --git a/src/nvim/testdir/test_paste.vim b/src/nvim/testdir/test_paste.vim new file mode 100644 index 0000000000..dad3c2c6a0 --- /dev/null +++ b/src/nvim/testdir/test_paste.vim @@ -0,0 +1,76 @@ + +" Test for 'pastetoggle' +func Test_pastetoggle() + new + set pastetoggle= + set nopaste + call feedkeys("iHello\", 'xt') + call assert_true(&paste) + call feedkeys("i\", 'xt') + call assert_false(&paste) + call assert_equal('Hello', getline(1)) + " command-line completion for 'pastetoggle' value + call feedkeys(":set pastetoggle=\\\"\", 'xt') + call assert_equal('"set pastetoggle=', @:) + set pastetoggle& + bwipe! +endfunc + +" Test for restoring option values when 'paste' is disabled +func Test_paste_opt_restore() + set autoindent expandtab ruler showmatch + if has('rightleft') + set revins hkmap + endif + set smarttab softtabstop=3 textwidth=27 wrapmargin=12 + if has('vartabs') + set varsofttabstop=10,20 + endif + + " enabling 'paste' should reset the above options + set paste + call assert_false(&autoindent) + call assert_false(&expandtab) + if has('rightleft') + call assert_false(&revins) + call assert_false(&hkmap) + endif + call assert_false(&ruler) + call assert_false(&showmatch) + call assert_false(&smarttab) + call assert_equal(0, &softtabstop) + call assert_equal(0, &textwidth) + call assert_equal(0, &wrapmargin) + if has('vartabs') + call assert_equal('', &varsofttabstop) + endif + + " disabling 'paste' should restore the option values + set nopaste + call assert_true(&autoindent) + call assert_true(&expandtab) + if has('rightleft') + call assert_true(&revins) + call assert_true(&hkmap) + endif + call assert_true(&ruler) + call assert_true(&showmatch) + call assert_true(&smarttab) + call assert_equal(3, &softtabstop) + call assert_equal(27, &textwidth) + call assert_equal(12, &wrapmargin) + if has('vartabs') + call assert_equal('10,20', &varsofttabstop) + endif + + set autoindent& expandtab& ruler& showmatch& + if has('rightleft') + set revins& hkmap& + endif + set smarttab& softtabstop& textwidth& wrapmargin& + if has('vartabs') + set varsofttabstop& + endif +endfunc + +" vim: shiftwidth=2 sts=2 expandtab -- cgit From 800cda21641dab2411c23a95d85ecef2c731d550 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 22 Sep 2022 11:15:35 +0800 Subject: vim-patch:8.2.3155: some option related code not covered by tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Some option related code not covered by tests. Solution: Add a few test cases. (Dominique Pellé, closes vim/vim#8552) https://github.com/vim/vim/commit/042414fa0053388f9a35cad61886405507554068 --- src/nvim/testdir/test_options.vim | 44 +++++++++++++++++++++++++++++++++++++++ src/nvim/testdir/test_set.vim | 19 +++++++++++++++++ 2 files changed, 63 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index f49d2cdf33..952975df32 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -947,6 +947,28 @@ func Test_opt_local_to_global() set autoread& endfunc +func Test_set_in_sandbox() + " Some boolean options cannot be set in sandbox, some can. + call assert_fails('sandbox set modelineexpr', 'E48:') + sandbox set number + call assert_true(&number) + set number& + + " Some boolean options cannot be set in sandbox, some can. + if has('python') || has('python3') + call assert_fails('sandbox set pyxversion=3', 'E48:') + endif + sandbox set tabstop=4 + call assert_equal(4, &tabstop) + set tabstop& + + " Some string options cannot be set in sandbox, some can. + call assert_fails('sandbox set backupdir=/tmp', 'E48:') + sandbox set filetype=perl + call assert_equal('perl', &filetype) + set filetype& +endfunc + " Test for incrementing, decrementing and multiplying a number option value func Test_opt_num_op() set shiftwidth=4 @@ -1131,6 +1153,28 @@ func Test_opt_errorbells() set noerrorbells endfunc +func Test_opt_scrolljump() + help + resize 10 + + " Test with positive 'scrolljump'. + set scrolljump=2 + norm! Lj + call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0, + \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0}, + \ winsaveview()) + + " Test with negative 'scrolljump' (percentage of window height). + set scrolljump=-40 + norm! ggLj + call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0, + \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0}, + \ winsaveview()) + + set scrolljump& + bw +endfunc + " Test for the 'cdhome' option func Test_opt_cdhome() if has('unix') || has('vms') diff --git a/src/nvim/testdir/test_set.vim b/src/nvim/testdir/test_set.vim index 2b1e9eeee0..7215772a00 100644 --- a/src/nvim/testdir/test_set.vim +++ b/src/nvim/testdir/test_set.vim @@ -26,4 +26,23 @@ function Test_set_add() let &wig = wig_save endfunction + +" :set, :setlocal, :setglobal without arguments show values of options. +func Test_set_no_arg() + set textwidth=79 + let a = execute('set') + call assert_match("^\n--- Options ---\n.*textwidth=79\\>", a) + set textwidth& + + setlocal textwidth=78 + let a = execute('setlocal') + call assert_match("^\n--- Local option values ---\n.*textwidth=78\\>", a) + setlocal textwidth& + + setglobal textwidth=77 + let a = execute('setglobal') + call assert_match("^\n--- Global option values ---\n.*textwidth=77\\>", a) + setglobal textwidth& +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 3f4030e1712db64ee398459f2e5fcf2803d253ab Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 22 Sep 2022 13:11:50 +0800 Subject: vim-patch:8.2.3428: using freed memory when replacing Problem: Using freed memory when replacing. (Dhiraj Mishra) Solution: Get the line pointer after calling ins_copychar(). https://github.com/vim/vim/commit/35a9a00afcb20897d462a766793ff45534810dc3 This patch is N/A as it only applies to non-UTF-8 encoding. --- src/nvim/testdir/test_edit.vim | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index 51eb89f71d..dc8e294420 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -1951,4 +1951,16 @@ func Test_edit_revins() bw! endfunc +" Test for getting the character of the line below after "p" +func Test_edit_put_CTRL_E() + " set encoding=latin1 + new + let @" = '' + sil! norm orggRx + sil! norm pr + call assert_equal(['r', 'r'], getline(1, 2)) + bwipe! + set encoding=utf-8 +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 320e56a4e08a118b918fa9c8c916469c6290abec Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 22 Sep 2022 13:14:12 +0800 Subject: vim-patch:8.2.3567: CTRL-I in Insert mode is not tested MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: CTRL-I in Insert mode is not tested Solution: Add a test case. (Dominique Pellé, closes vim/vim#8866) https://github.com/vim/vim/commit/9cd063e3195a4c250c8016fa340922ab21fda252 --- src/nvim/testdir/test_edit.vim | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index dc8e294420..0ee038e2e3 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -1963,4 +1963,21 @@ func Test_edit_put_CTRL_E() set encoding=utf-8 endfunc +" Test toggling of input method. See :help i_CTRL-^ +func Test_edit_CTRL_hat() + CheckFeature xim + CheckNotGui " FIXME: why does this test fail when running in the GUI? + + new + + call assert_equal(0, &iminsert) + call feedkeys("i\", 'xt') + call assert_equal(2, &iminsert) + call feedkeys("i\", 'xt') + call assert_equal(0, &iminsert) + + bwipe! +endfunc + + " vim: shiftwidth=2 sts=2 expandtab -- cgit From a636e24280abdd2cfe0c0ae6a97f8b0dce564f21 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 22 Sep 2022 13:15:26 +0800 Subject: vim-patch:8.2.3568: ctrl-hat test fails with Athena and Motif MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Ctrl-hat test fails with Athena and Motif. (Elimar Riesebieter) Solution: Run the test only with GTK. (Dominique Pellé, closes vim/vim#9069) https://github.com/vim/vim/commit/8753c1dd2c2a5c2c7ff63a9bfb14cd4b9bb9c87f --- src/nvim/testdir/test_edit.vim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index 0ee038e2e3..162f02dd98 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -1966,7 +1966,11 @@ endfunc " Test toggling of input method. See :help i_CTRL-^ func Test_edit_CTRL_hat() CheckFeature xim - CheckNotGui " FIXME: why does this test fail when running in the GUI? + + " FIXME: test fails with Athena and Motif GUI. + " test also fails when running in the GUI. + CheckFeature gui_gtk + CheckNotGui new -- cgit From 1bced9bf94f2767ad5bb91cc902cd58fc126055e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 22 Sep 2022 13:15:52 +0800 Subject: vim-patch:8.2.4074: going over the end of NameBuff Problem: Going over the end of NameBuff. Solution: Check length when appending a space. https://github.com/vim/vim/commit/de05bb25733c3319e18dca44e9b59c6ee389eb26 --- src/nvim/testdir/test_edit.vim | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index 162f02dd98..a386c4264c 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -1983,5 +1983,20 @@ func Test_edit_CTRL_hat() bwipe! endfunc +" Weird long file name was going over the end of NameBuff +func Test_edit_overlong_file_name() + CheckUnix + + file 0000000000000000000000000000 + file %%%%%%%%%%%%%%%%%%%%%%%%%% + file %%%%%% + set readonly + set ls=2 + + redraw! + set noreadonly ls& + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 477cf2a6b1226e77aa0562067d90a5a07dfbdccc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 22 Sep 2022 13:20:41 +0800 Subject: vim-patch:8.2.4677: the Athena GUI support is outdated Problem: The Athena GUI support is outdated. Solution: Remove the Athena GUI code. https://github.com/vim/vim/commit/0b962e5685edd41b55d5427b894797e725707639 --- src/nvim/testdir/test_clientserver.vim | 4 ++-- src/nvim/testdir/test_edit.vim | 2 +- src/nvim/testdir/test_highlight.vim | 2 +- src/nvim/testdir/test_quotestar.vim | 2 +- src/nvim/testdir/test_startup.vim | 14 +++++++------- 5 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_clientserver.vim b/src/nvim/testdir/test_clientserver.vim index 66ee776a90..a4ebce5af9 100644 --- a/src/nvim/testdir/test_clientserver.vim +++ b/src/nvim/testdir/test_clientserver.vim @@ -64,8 +64,8 @@ func Test_client_server() " the GUI and check that the remote command still works. " Need to wait for the GUI to start up, otherwise the send hangs in trying " to send to the terminal window. - if has('gui_athena') || has('gui_motif') - " For those GUIs, ignore the 'failed to create input context' error. + if has('gui_motif') + " For this GUI ignore the 'failed to create input context' error. call remote_send(name, ":call test_ignore_error('E285') | gui -f\") else call remote_send(name, ":gui -f\") diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index a386c4264c..9783ed19a7 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -1967,7 +1967,7 @@ endfunc func Test_edit_CTRL_hat() CheckFeature xim - " FIXME: test fails with Athena and Motif GUI. + " FIXME: test fails with Motif GUI. " test also fails when running in the GUI. CheckFeature gui_gtk CheckNotGui diff --git a/src/nvim/testdir/test_highlight.vim b/src/nvim/testdir/test_highlight.vim index 8e808a00d0..e84c45c635 100644 --- a/src/nvim/testdir/test_highlight.vim +++ b/src/nvim/testdir/test_highlight.vim @@ -722,7 +722,7 @@ func Test_1_highlight_Normalgroup_exists() elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3') " expect is DEFAULT_FONT of gui_gtk_x11.c call assert_match('hi Normal\s*font=Monospace 10', hlNormal) - elseif has('gui_motif') || has('gui_athena') + elseif has('gui_motif') " expect is DEFAULT_FONT of gui_x11.c call assert_match('hi Normal\s*font=7x13', hlNormal) elseif has('win32') diff --git a/src/nvim/testdir/test_quotestar.vim b/src/nvim/testdir/test_quotestar.vim index e3ca141328..6a6719da8b 100644 --- a/src/nvim/testdir/test_quotestar.vim +++ b/src/nvim/testdir/test_quotestar.vim @@ -98,7 +98,7 @@ func Do_test_quotestar_for_x11() " Running in a terminal and the GUI is available: Tell the server to open " the GUI and check that the remote command still works. - if has('gui_athena') || has('gui_motif') + if has('gui_motif') " For those GUIs, ignore the 'failed to create input context' error. call remote_send(name, ":call test_ignore_error('E285') | gui -f\") else diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim index 880ca62685..b30a5e7edb 100644 --- a/src/nvim/testdir/test_startup.vim +++ b/src/nvim/testdir/test_startup.vim @@ -431,7 +431,7 @@ endfunction " Test the -reverse and +reverse arguments (for GUI only). func Test_reverse() CheckCanRunGui - CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena + CheckAnyOf Feature:gui_gtk Feature:gui_motif let after =<< trim [CODE] call writefile([&background], "Xtest_reverse") @@ -452,7 +452,7 @@ endfunc " Test the -background and -foreground arguments (for GUI only). func Test_background_foreground() CheckCanRunGui - CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena + CheckAnyOf Feature:gui_gtk Feature:gui_motif " Is there a better way to check the effect of -background & -foreground " other than merely looking at &background (dark or light)? @@ -479,7 +479,7 @@ func Test_font() if has('gui_gtk') let font = 'Courier 14' - elseif has('gui_motif') || has('gui_athena') + elseif has('gui_motif') let font = '-misc-fixed-bold-*' else throw 'Skipped: test does not set a valid font for this GUI' @@ -501,10 +501,10 @@ endfunc " Test the -geometry argument (for GUI only). func Test_geometry() CheckCanRunGui - CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena + CheckAnyOf Feature:gui_gtk Feature:gui_motif - if has('gui_motif') || has('gui_athena') - " FIXME: With GUI Athena or Motif, the value of getwinposx(), + if has('gui_motif') + " FIXME: With GUI Motif the value of getwinposx(), " getwinposy() and getwinpos() do not match exactly the " value given in -geometry. Why? " So only check &columns and &lines for those GUIs. @@ -533,7 +533,7 @@ endfunc " Test the -iconic argument (for GUI only). func Test_iconic() CheckCanRunGui - CheckAnyOf Feature:gui_gtk Feature:gui_motif Feature:gui_athena + CheckAnyOf Feature:gui_gtk Feature:gui_motif call RunVim([], [], '-f -g -iconic -cq') -- cgit From a7f6f0e2ddf90f9c05838e72ffb8c60148b49109 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 22 Sep 2022 20:18:06 +0800 Subject: vim-patch:9.0.0539: long message test can be flaky (#20282) Problem: Long message test can be flaky. Solution: Wait for more prompt instead of ruler. https://github.com/vim/vim/commit/21d393a12be86126d9326ea0c244d3a101b77151 Comment N/A lines out instead of deleting in buftype tests. --- src/nvim/testdir/test_autocmd.vim | 4 ++++ src/nvim/testdir/test_functions.vim | 2 ++ src/nvim/testdir/test_messages.vim | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 3064b199d9..1be2d11034 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -533,7 +533,9 @@ func Test_BufReadCmdNofile() \ 'acwrite', \ 'quickfix', \ 'help', + "\ 'terminal', \ 'prompt', + "\ 'popup', \ ] new somefile exe 'set buftype=' .. val @@ -650,7 +652,9 @@ func Test_BufEnter() \ 'acwrite', \ 'quickfix', \ 'help', + "\ 'terminal', \ 'prompt', + "\ 'popup', \ ] new somefile exe 'set buftype=' .. val diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 7262d2d71a..7ad0cb5884 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1898,7 +1898,9 @@ func Test_bufadd_bufload() \ ['acwrite', 1], \ ['quickfix', 0], \ ['help', 1], + "\ ['terminal', 0], \ ['prompt', 0], + "\ ['popup', 0], \ ] bwipe! XotherName let buf = bufadd('XotherName') diff --git a/src/nvim/testdir/test_messages.vim b/src/nvim/testdir/test_messages.vim index 0f348c22cb..2672fcb69d 100644 --- a/src/nvim/testdir/test_messages.vim +++ b/src/nvim/testdir/test_messages.vim @@ -358,7 +358,8 @@ func Test_quit_long_message() echom range(9999)->join("\x01") END call writefile(content, 'Xtest_quit_message') - let buf = RunVimInTerminal('-S Xtest_quit_message', #{rows: 6}) + let buf = RunVimInTerminal('-S Xtest_quit_message', #{rows: 6, wait_for_ruler: 0}) + call WaitForAssert({-> assert_match('^-- More --', term_getline(buf, 6))}) call term_sendkeys(buf, "q") call VerifyScreenDump(buf, 'Test_quit_long_message', {}) -- cgit From 4371886293b4956530f8bec49b01c0ee02771434 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 22 Sep 2022 21:08:14 +0800 Subject: vim-patch:9.0.0544: minor issues with setting a string option Problem: Minor issues with setting a string option. Solution: Adjust the code, add a test. (closes vim/vim#11192) https://github.com/vim/vim/commit/fcba86c0316dc0d6341078b50e7967206a1627a0 --- src/nvim/testdir/test_options.vim | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index 952975df32..ada6d2406b 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -1209,4 +1209,18 @@ func Test_switchbuf_reset() only! endfunc +" :set empty string for global 'keywordprg' falls back to ":help" +func Test_keywordprg_empty() + let k = &keywordprg + set keywordprg=man + call assert_equal('man', &keywordprg) + set keywordprg= + call assert_equal(':help', &keywordprg) + set keywordprg=man + call assert_equal('man', &keywordprg) + call assert_equal("\n keywordprg=:help", execute('set kp= kp?')) + let &keywordprg = k +endfunc + + " vim: shiftwidth=2 sts=2 expandtab -- cgit From c28f00b101148d17a640fe2a186b23fbe230fbf3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 23 Sep 2022 07:14:32 +0800 Subject: vim-patch:9.0.0550: crash when closing a tabpage and buffer is NULL Problem: Crash when closing a tabpage and buffer is NULL. Solution: Adjust how autocommands are triggered when closing a window. (closes vim/vim#11198, closes vim/vim#11197) https://github.com/vim/vim/commit/62de54b48d6354d4622ec0b21ffa4cf3cf312505 --- src/nvim/testdir/test_autocmd.vim | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 1be2d11034..d766256d4b 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -447,6 +447,26 @@ func Test_WinClosed_throws_with_tabs() augroup! test-WinClosed endfunc +" This used to trigger WinClosed twice for the same window, and the window's +" buffer was NULL in the second autocommand. +func Test_WinClosed_switch_tab() + edit Xa + split Xb + split Xc + tab split + new + augroup test-WinClosed + autocmd WinClosed * tabprev | bwipe! + augroup END + close + " Check that the tabline has been fully removed + call assert_equal([1, 1], win_screenpos(0)) + + autocmd! test-WinClosed + augroup! test-WinClosed + %bwipe! +endfunc + func s:AddAnAutocmd() augroup vimBarTest au BufReadCmd * echo 'hello' -- cgit From f3c842058ebc0ac475910726581a738d834955f6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 24 Sep 2022 08:10:49 +0800 Subject: vim-patch:9.0.0559: timer test may get stuck at hit-enter prompt (#20312) Problem: Timer test may get stuck at hit-enter prompt. Solution: Feed some more characters. https://github.com/vim/vim/commit/4ecf16bbf951f10fd32c918c9d8bc004b7f8f7c9 --- src/nvim/testdir/test_timers.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index 6adf503f14..b3a22614b0 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -349,11 +349,13 @@ func Test_nocatch_timer_garbage_collect() let a = {'foo', 'bar'} endfunc func FeedChar(id) - call feedkeys('x', 't') + call feedkeys(":\", 't') endfunc call timer_start(300, 'FeedChar') call timer_start(100, 'CauseAnError') - let x = getchar() + let x = getchar() " wait for error in timer + let x = getchar(0) " read any remaining chars + let x = getchar(0) set ut& call test_override('no_wait_return', 1) -- cgit From 24b5449b3d9b39a436bb8fe935116afa15a9473e Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 24 Sep 2022 10:16:30 +0200 Subject: vim-patch:9.0.0562: HSL playlist files are not recognized (#20307) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: HSL playlist files are not recognized. Solution: Add a pattern to recognize HSL palylist files. (Benoît Ryder, closes vim/vim#11204) https://github.com/vim/vim/commit/35fdd9a67d73d4750152c419d4193ebb6b6d6eee --- src/nvim/testdir/test_filetype.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index e3e698aa60..2d71d9b1a6 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -255,6 +255,7 @@ let s:filename_checks = { \ 'hex': ['file.hex', 'file.h32'], \ 'hgcommit': ['hg-editor-file.txt'], \ 'hjson': ['file.hjson'], + \ 'hlsplaylist': ['file.m3u8'], \ 'hog': ['file.hog', 'snort.conf', 'vision.conf'], \ 'hollywood': ['file.hws'], \ 'hoon': ['file.hoon'], -- cgit From f8b656c582c6f0d9cb35523ac2d2f3d0edbcd52b Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 24 Sep 2022 12:59:37 +0200 Subject: vim-patch:9.0.0566: Nim files are not recognized (#20317) Problem: Nim files are not recognized. Solution: Add patterns for Nim files. (Nbiba Bedis, closes vim/vim#11205) https://github.com/vim/vim/commit/9fd1583c839c5e43b0d48ec815a79005a2364776 --- src/nvim/testdir/test_filetype.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 2d71d9b1a6..3067fa439c 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -386,6 +386,7 @@ let s:filename_checks = { \ 'neomuttrc': ['Neomuttrc', '.neomuttrc', '.neomuttrc-file', '/.neomutt/neomuttrc', '/.neomutt/neomuttrc-file', 'Neomuttrc', 'Neomuttrc-file', 'any/.neomutt/neomuttrc', 'any/.neomutt/neomuttrc-file', 'neomuttrc', 'neomuttrc-file'], \ 'netrc': ['.netrc'], \ 'nginx': ['file.nginx', 'nginxfile.conf', 'filenginx.conf', 'any/etc/nginx/file', 'any/usr/local/nginx/conf/file', 'any/nginx/file.conf'], + \ 'nim': ['file.nim', 'file.nims', 'file.nimble'], \ 'ninja': ['file.ninja'], \ 'nix': ['file.nix'], \ 'nqc': ['file.nqc'], -- cgit From 57b731818d3d54dacdace081f6db4a8ce813173d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 24 Sep 2022 21:13:32 +0800 Subject: vim-patch:9.0.0567: 'completeopt' "longest" is not used for complete() Problem: 'completeopt' "longest" is not used for complete(). Solution: Also use "longest" for complete(). (Bjorn Linse, closes vim/vim#11206) https://github.com/vim/vim/commit/87af60c91503e37c9144f8e48022b12994ce2c85 --- src/nvim/testdir/test_ins_complete.vim | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_ins_complete.vim b/src/nvim/testdir/test_ins_complete.vim index 3e563f29f9..0810bd4adc 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -702,6 +702,26 @@ func Test_recursive_complete_func() bw! endfunc +" Test for using complete() with completeopt+=longest +func Test_complete_with_longest() + inoremap call complete(1, ["iaax", "iaay", "iaaz"]) + new + + " default: insert first match + set completeopt& + call setline(1, ['i']) + exe "normal Aa\\" + call assert_equal('iaax', getline(1)) + + " with longest: insert longest prefix + set completeopt+=longest + call setline(1, ['i']) + exe "normal Aa\\" + call assert_equal('iaa', getline(1)) + set completeopt& +endfunc + + " Test for completing words following a completed word in a line func Test_complete_wrapscan() " complete words from another buffer -- cgit From 0c77dba9a46765c7a769090ae21433efea5bda00 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 24 Sep 2022 21:16:50 +0800 Subject: vim-patch:9.0.0572: insert complete tests leave a mapping behind Problem: Insert complete tests leave a mapping behind. Solution: Use a buffer-local mapping. (closes vim/vim#11211) https://github.com/vim/vim/commit/75f4bafabdcc6bce5cf3e09fee29c634bf102c17 --- src/nvim/testdir/test_ins_complete.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 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 0810bd4adc..f706322a85 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -704,8 +704,8 @@ endfunc " Test for using complete() with completeopt+=longest func Test_complete_with_longest() - inoremap call complete(1, ["iaax", "iaay", "iaaz"]) new + inoremap call complete(1, ["iaax", "iaay", "iaaz"]) " default: insert first match set completeopt& @@ -719,6 +719,7 @@ func Test_complete_with_longest() exe "normal Aa\\" call assert_equal('iaa', getline(1)) set completeopt& + bwipe! endfunc @@ -1276,7 +1277,7 @@ endfunc " A mapping is not used for the key after CTRL-X. func Test_no_mapping_for_ctrl_x_key() new - inoremap let was_mapped = 'yes' + inoremap let was_mapped = 'yes' setlocal dictionary=README.txt call feedkeys("aexam\\ ", 'xt') call assert_equal('example ', getline(1)) -- cgit From c7cf1232a71b0db700b818e2ae8e8ebaf40133f2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 25 Sep 2022 09:49:21 +0800 Subject: vim-patch:8.2.4467: running filetype test leaves file behind (#20335) Problem: Running filetype test leaves file behind. Solution: Delete the file. https://github.com/vim/vim/commit/0e71b7d4ce3e1210150ce772e1af6956057a71ed vim-patch:8.2.4466: MS-Windows: illegal memory access in installer Problem: MS-Windows: illegal memory access in installer when using "create-directories" as the final argument. Solution: Check the argument count. (Cam Sinclair, closes vim/vim#9844) https://github.com/vim/vim/commit/5c6edf41f9beffea21ce45d658822cc4c0745fdb --- src/nvim/testdir/test_filetype.vim | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 3067fa439c..516a764f45 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -932,7 +932,9 @@ func Test_d_file() call assert_equal('d', &filetype) bwipe! + " clean up filetype off + call delete('Xfile.d') endfunc func Test_dat_file() -- cgit From 2a5692c64628ee0af3ef4931a774a2eb0a7e046f Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sun, 25 Sep 2022 13:59:11 +0200 Subject: vim-patch:9.0.0583: only recognizing .m3u8 files is inconsistent (#20342) Problem: Only recognizing .m3u8 files is inconsistent. Solution: Also matc .m3u files. (issue vim/vim#11204) https://github.com/vim/vim/commit/b9725bc7f6427654eb4e35874034b0ec1b6b96b3 --- src/nvim/testdir/test_filetype.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 516a764f45..4755d39cd3 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -255,7 +255,7 @@ let s:filename_checks = { \ 'hex': ['file.hex', 'file.h32'], \ 'hgcommit': ['hg-editor-file.txt'], \ 'hjson': ['file.hjson'], - \ 'hlsplaylist': ['file.m3u8'], + \ 'hlsplaylist': ['file.m3u', 'file.m3u8'], \ 'hog': ['file.hog', 'snort.conf', 'vision.conf'], \ 'hollywood': ['file.hws'], \ 'hoon': ['file.hoon'], -- cgit From 9ffa041a9a5fc8cd9acca97cae16f66ba0c82805 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 26 Sep 2022 07:46:58 +0800 Subject: vim-patch:9.0.0586: missing change in test (#20347) Problem: Missing change in test. Solution: Add the test change. https://github.com/vim/vim/commit/124af71a28a633fa655cff41bc21d398481ce45f vim-patch:9.0.0585: when long message test fails the error message is not visible Problem: When long message test fails the error message is not visible. Solution: Dump more lines. https://github.com/vim/vim/commit/6a879878f4e1918a05244e6acd4c73c3135cf941 --- src/nvim/testdir/test_messages.vim | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_messages.vim b/src/nvim/testdir/test_messages.vim index 2672fcb69d..8e66a2c529 100644 --- a/src/nvim/testdir/test_messages.vim +++ b/src/nvim/testdir/test_messages.vim @@ -357,15 +357,14 @@ func Test_quit_long_message() let content =<< trim END echom range(9999)->join("\x01") END - call writefile(content, 'Xtest_quit_message') - let buf = RunVimInTerminal('-S Xtest_quit_message', #{rows: 6, wait_for_ruler: 0}) - call WaitForAssert({-> assert_match('^-- More --', term_getline(buf, 6))}) + call writefile(content, 'Xtest_quit_message', 'D') + let buf = RunVimInTerminal('-S Xtest_quit_message', #{rows: 10, wait_for_ruler: 0}) + call WaitForAssert({-> assert_match('^-- More --', term_getline(buf, 10))}) call term_sendkeys(buf, "q") call VerifyScreenDump(buf, 'Test_quit_long_message', {}) " clean up call StopVimInTerminal(buf) - call delete('Xtest_quit_message') endfunc " this was missing a terminating NUL -- cgit From 1d337d4e2f2265b13ecf19a3bc17ad302d3b0d96 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 27 Sep 2022 08:29:21 +0800 Subject: vim-patch:9.0.0595: extra newline in messages after a verbose shell message (#20359) Problem: Extra newline in messages after a verbose shell message. Solution: Output the newline with msg_putchar_attr(). (closes vim/vim#11233) Make it possible to filter a screendump before comparing it. https://github.com/vim/vim/commit/1190139ed01c27539615beea9559a88b2551daf3 Cherry-pick Test_message_more_scrolledback() from patch 9.0.0592 because Nvim already behaves as intended. --- src/nvim/testdir/test_messages.vim | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_messages.vim b/src/nvim/testdir/test_messages.vim index 8e66a2c529..42a1fdcfe2 100644 --- a/src/nvim/testdir/test_messages.vim +++ b/src/nvim/testdir/test_messages.vim @@ -316,6 +316,66 @@ func Test_message_more() call StopVimInTerminal(buf) endfunc +" Test more-prompt scrollback +func Test_message_more_scrollback() + CheckRunVimInTerminal + + let lines =<< trim END + set t_ut= + hi Normal ctermfg=15 ctermbg=0 + for i in range(100) + echo i + endfor + END + call writefile(lines, 'XmoreScrollback', 'D') + let buf = RunVimInTerminal('-S XmoreScrollback', {'rows': 10}) + call VerifyScreenDump(buf, 'Test_more_scrollback_1', {}) + + call term_sendkeys(buf, 'f') + call TermWait(buf) + call term_sendkeys(buf, 'b') + call VerifyScreenDump(buf, 'Test_more_scrollback_2', {}) + + call term_sendkeys(buf, 'q') + call TermWait(buf) + call StopVimInTerminal(buf) +endfunc + +" Test verbose message before echo command +func Test_echo_verbose_system() + CheckRunVimInTerminal + CheckUnix + + let buf = RunVimInTerminal('', {'rows': 10}) + call term_sendkeys(buf, ":4 verbose echo system('seq 20')\") + " Note that the screendump is filtered to remove the name of the temp file + call VerifyScreenDump(buf, 'Test_verbose_system_1', {}) + + " display a page and go back, results in exactly the same view + call term_sendkeys(buf, ' ') + call TermWait(buf) + call term_sendkeys(buf, 'b') + call VerifyScreenDump(buf, 'Test_verbose_system_1', {}) + + " do the same with 'cmdheight' set to 2 + call term_sendkeys(buf, 'q') + call TermWait(buf) + call term_sendkeys(buf, ":set ch=2\") + call TermWait(buf) + call term_sendkeys(buf, ":4 verbose echo system('seq 20')\") + call VerifyScreenDump(buf, 'Test_verbose_system_2', {}) + + call term_sendkeys(buf, ' ') + call TermWait(buf) + call term_sendkeys(buf, 'b') + call VerifyScreenDump(buf, 'Test_verbose_system_2', {}) + + call term_sendkeys(buf, 'q') + call TermWait(buf) + call StopVimInTerminal(buf) +endfunc + + func Test_ask_yesno() CheckRunVimInTerminal let buf = RunVimInTerminal('', {'rows': 6}) -- cgit From 760a8754c07a62afa4d83f4e254b1d45ae8cfc65 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Tue, 27 Sep 2022 12:36:33 +0200 Subject: vim-patch:9.0.0599: latexmkrc files are not recognized Problem: Latexmkrc files are not recognized. Solution: Use Perl filetype for latexmkrc files. (closes vim/vim#11241) https://github.com/vim/vim/commit/cde031938537970938437cdbb235bc0da755ae4a --- src/nvim/testdir/test_filetype.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 4755d39cd3..6525bb3f62 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -412,7 +412,7 @@ let s:filename_checks = { \ 'pccts': ['file.g'], \ 'pcmk': ['file.pcmk'], \ 'pdf': ['file.pdf'], - \ 'perl': ['file.plx', 'file.al', 'file.psgi', 'gitolite.rc', '.gitolite.rc', 'example.gitolite.rc'], + \ 'perl': ['file.plx', 'file.al', 'file.psgi', 'gitolite.rc', '.gitolite.rc', 'example.gitolite.rc', '.latexmkrc', 'latexmkrc'], \ 'pf': ['pf.conf'], \ 'pfmain': ['main.cf'], \ 'php': ['file.php', 'file.php9', 'file.phtml', 'file.ctp', 'file.phpt', 'file.theme'], -- cgit From e176f9dacf28f56e91fcbc92f392228588a46c85 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Tue, 27 Sep 2022 12:38:31 +0200 Subject: vim-patch:9.0.0600: GYP files are not recognized Problem: GYP files are not recognized. Solution: Recognize GYP files. (closes vim/vim#11242) https://github.com/vim/vim/commit/d32474229213276c64cb293885a975dcb406fbc9 --- src/nvim/testdir/test_filetype.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 6525bb3f62..746ca3318f 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -240,6 +240,7 @@ let s:filename_checks = { \ 'grub': ['/boot/grub/menu.lst', '/boot/grub/grub.conf', '/etc/grub.conf', 'any/boot/grub/grub.conf', 'any/boot/grub/menu.lst', 'any/etc/grub.conf'], \ 'gsp': ['file.gsp'], \ 'gtkrc': ['.gtkrc', 'gtkrc', '.gtkrc-file', 'gtkrc-file'], + \ 'gyp': ['file.gyp', 'file.gypi'], \ 'hack': ['file.hack', 'file.hackpartial'], \ 'haml': ['file.haml'], \ 'hamster': ['file.hsm'], -- cgit From fe0727a1bfebdb8dc27bd8c276566f203b4d6a18 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Tue, 27 Sep 2022 13:03:28 +0200 Subject: vim-patch:9.0.0602: new TypeScript extensions are not recognized Problem: New TypeScript extensions are not recognized. Solution: Recognize .mts and .cts files. (closes vim/vim#11237) https://github.com/vim/vim/commit/7fc6c0e4dab4e80b9806a973936af54276468513 --- src/nvim/testdir/test_filetype.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 746ca3318f..6f7d9f75e6 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -583,6 +583,7 @@ let s:filename_checks = { \ 'tssop': ['file.tssop'], \ 'tsv': ['file.tsv'], \ 'twig': ['file.twig'], + \ 'typescript': ['file.mts', 'file.cts'], \ 'typescript.glimmer': ['file.gts'], \ 'typescriptreact': ['file.tsx'], \ 'uc': ['file.uc'], -- cgit From f46060c4cbc1efe100019075214def53fe4d47b3 Mon Sep 17 00:00:00 2001 From: ObserverOfTime Date: Tue, 27 Sep 2022 17:10:19 +0300 Subject: vim-patch:9.0.0604: luacheckrc file is not recognized (#20371) Problem: Luacheckrc file is not recognized. Solution: Use lua filetype for luacheckrc. (closes vim/vim#11236) https://github.com/vim/vim/commit/49c311c9b18e18c05f93728d1f8a552923a18423 --- src/nvim/testdir/test_filetype.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 6f7d9f75e6..05aee9b31d 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -328,7 +328,7 @@ let s:filename_checks = { \ 'lpc': ['file.lpc', 'file.ulpc'], \ 'lsl': ['file.lsl'], \ 'lss': ['file.lss'], - \ 'lua': ['file.lua', 'file.rockspec', 'file.nse'], + \ 'lua': ['file.lua', 'file.rockspec', 'file.nse', '.luacheckrc'], \ 'lynx': ['lynx.cfg'], \ 'lyrics': ['file.lrc'], \ 'm3build': ['m3makefile', 'm3overrides'], -- cgit From 9353e2f7ef6d0919257548e1a43988404900bf03 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 1 Oct 2022 21:29:54 +0800 Subject: vim-patch:8.2.2542: highlight of char beyond line end is not correct (#20424) Problem: Highlight of char beyond line end is not correct. (Chuan Wei Foo) Solution: Fix counting NUL as one cell. Draw one more character if the EOL is part of the match. (closes vim/vim#7883) https://github.com/vim/vim/commit/41f0895c6e3c7b921e3c102ad42be52b1be48018 Reorder test_search.vim to match Vim. --- src/nvim/testdir/test_search.vim | 76 +++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 28 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index 3d1bbfb726..0cf55c7d0b 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -956,24 +956,24 @@ func Test_incsearch_search_dump() call delete('Xis_search_script') endfunc -func Test_hlsearch_block_visual_match() +func Test_hlsearch_dump() + CheckOption hlsearch CheckScreendump - let lines =<< trim END - set hlsearch - call setline(1, ['aa', 'bbbb', 'cccccc']) - END - call writefile(lines, 'Xhlsearch_block') - let buf = RunVimInTerminal('-S Xhlsearch_block', {'rows': 9, 'cols': 60}) + call writefile([ + \ 'set hlsearch cursorline', + \ 'call setline(1, ["xxx", "xxx", "xxx"])', + \ '/.*', + \ '2', + \ ], 'Xhlsearch_script') + let buf = RunVimInTerminal('-S Xhlsearch_script', {'rows': 6, 'cols': 50}) + call VerifyScreenDump(buf, 'Test_hlsearch_1', {}) - call term_sendkeys(buf, "G\$kk\") - sleep 100m - call term_sendkeys(buf, "/\\%V\") - sleep 100m - call VerifyScreenDump(buf, 'Test_hlsearch_block_visual_match', {}) + call term_sendkeys(buf, "/\\_.*\") + call VerifyScreenDump(buf, 'Test_hlsearch_2', {}) call StopVimInTerminal(buf) - call delete('Xhlsearch_block') + call delete('Xhlsearch_script') endfunc func Test_hlsearch_and_visual() @@ -996,6 +996,26 @@ func Test_hlsearch_and_visual() call delete('Xhlvisual_script') endfunc +func Test_hlsearch_block_visual_match() + CheckScreendump + + let lines =<< trim END + set hlsearch + call setline(1, ['aa', 'bbbb', 'cccccc']) + END + call writefile(lines, 'Xhlsearch_block') + let buf = RunVimInTerminal('-S Xhlsearch_block', {'rows': 9, 'cols': 60}) + + call term_sendkeys(buf, "G\$kk\") + sleep 100m + call term_sendkeys(buf, "/\\%V\") + sleep 100m + call VerifyScreenDump(buf, 'Test_hlsearch_block_visual_match', {}) + + call StopVimInTerminal(buf) + call delete('Xhlsearch_block') +endfunc + func Test_incsearch_substitute() CheckFunction test_override CheckOption incsearch @@ -1017,6 +1037,21 @@ func Test_incsearch_substitute() call Incsearch_cleanup() endfunc +func Test_incsearch_substitute_long_line() + CheckFunction test_override + new + call test_override("char_avail", 1) + set incsearch + + call repeat('x', 100000)->setline(1) + call feedkeys(':s/\%c', 'xt') + redraw + call feedkeys("\", 'xt') + + call Incsearch_cleanup() + bwipe! +endfunc + func Test_hlsearch_cursearch() CheckScreendump @@ -1341,21 +1376,6 @@ func Test_subst_word_under_cursor() set noincsearch endfunc -func Test_incsearch_substitute_long_line() - CheckFunction test_override - new - call test_override("char_avail", 1) - set incsearch - - call repeat('x', 100000)->setline(1) - call feedkeys(':s/\%c', 'xt') - redraw - call feedkeys("\", 'xt') - - call Incsearch_cleanup() - bwipe! -endfunc - func Test_search_undefined_behaviour() CheckFeature terminal -- cgit From 85c7d4f7a92326dcd70317b048bafe96c8051701 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 1 Oct 2022 18:32:08 +0800 Subject: vim-patch:9.0.0620: matchaddpos() can only add up to 8 matches Problem: matchaddpos() can only add up to 8 matches. Solution: Allocate the array of positions. (closes vim/vim#11248) https://github.com/vim/vim/commit/50faf02f43d7f1a56ec2023028fca7c72dbce83e --- src/nvim/testdir/test_match.vim | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_match.vim b/src/nvim/testdir/test_match.vim index 70271aa32f..784c966a5d 100644 --- a/src/nvim/testdir/test_match.vim +++ b/src/nvim/testdir/test_match.vim @@ -2,6 +2,7 @@ " matchaddpos(), matcharg(), matchdelete(), and setmatches(). source screendump.vim +source check.vim function Test_match() highlight MyGroup1 term=bold ctermbg=red guibg=red @@ -219,6 +220,21 @@ func Test_matchaddpos() set hlsearch& endfunc +" Add 12 match positions (previously the limit was 8 positions). +func Test_matchaddpos_dump() + CheckScreendump + + let lines =<< trim END + call setline(1, ['1234567890123']->repeat(14)) + call matchaddpos('Search', range(1, 12)->map({i, v -> [v, v]})) + END + call writefile(lines, 'Xmatchaddpos', 'D') + let buf = RunVimInTerminal('-S Xmatchaddpos', #{rows: 14}) + call VerifyScreenDump(buf, 'Test_matchaddpos_1', {}) + + call StopVimInTerminal(buf) +endfunc + func Test_matchaddpos_otherwin() syntax on new -- cgit From cb310d2901a0eb63721ac5930daaadee91929208 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 1 Oct 2022 21:59:53 +0800 Subject: vim-patch:9.0.0622: matchaddpos() can get slow when adding many matches Problem: matchaddpos() can get slow when adding many matches. Solution: Update the next available match ID when manually picking an ID and remove check if the available ID can be used. (idea by Rick Howe) https://github.com/vim/vim/commit/9f573a8df02d9f699a43d2afbd1d2841d700b9ad --- src/nvim/testdir/test_match.vim | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_match.vim b/src/nvim/testdir/test_match.vim index 784c966a5d..4f22e54563 100644 --- a/src/nvim/testdir/test_match.vim +++ b/src/nvim/testdir/test_match.vim @@ -36,8 +36,8 @@ function Test_match() let m1 = matchadd("MyGroup1", "TODO") let m2 = matchadd("MyGroup2", "FIXME", 42) let m3 = matchadd("MyGroup3", "XXX", 60, 17) - let ans = [{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 4}, - \ {'group': 'MyGroup2', 'pattern': 'FIXME', 'priority': 42, 'id': 5}, + let ans = [{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1000}, + \ {'group': 'MyGroup2', 'pattern': 'FIXME', 'priority': 42, 'id': 1001}, \ {'group': 'MyGroup3', 'pattern': 'XXX', 'priority': 60, 'id': 17}] call assert_equal(ans, getmatches()) @@ -118,7 +118,7 @@ function Test_match() call clearmatches() call setline(1, 'abcdΣabcdef') - eval "MyGroup1"->matchaddpos([[1, 4, 2], [1, 9, 2]]) + eval "MyGroup1"->matchaddpos([[1, 4, 2], [1, 9, 2]], 10, 42) 1 redraw! let v1 = screenattr(1, 1) @@ -129,7 +129,7 @@ function Test_match() let v8 = screenattr(1, 8) let v9 = screenattr(1, 9) let v10 = screenattr(1, 10) - call assert_equal([{'group': 'MyGroup1', 'id': 11, 'priority': 10, 'pos1': [1, 4, 2], 'pos2': [1, 9, 2]}], getmatches()) + call assert_equal([{'group': 'MyGroup1', 'id': 42, 'priority': 10, 'pos1': [1, 4, 2], 'pos2': [1, 9, 2]}], getmatches()) call assert_notequal(v1, v4) call assert_equal(v5, v4) call assert_equal(v6, v1) @@ -143,7 +143,7 @@ function Test_match() let m=getmatches() call clearmatches() call setmatches(m) - call assert_equal([{'group': 'MyGroup1', 'id': 11, 'priority': 10, 'pos1': [1, 4, 2], 'pos2': [1,9, 2]}, {'group': 'MyGroup1', 'pattern': '\%2lmatchadd', 'priority': 10, 'id': 12}], getmatches()) + call assert_equal([{'group': 'MyGroup1', 'id': 42, 'priority': 10, 'pos1': [1, 4, 2], 'pos2': [1,9, 2]}, {'group': 'MyGroup1', 'pattern': '\%2lmatchadd', 'priority': 10, 'id': 1106}], getmatches()) highlight MyGroup1 NONE highlight MyGroup2 NONE @@ -161,7 +161,7 @@ func Test_matchadd_error() call clearmatches() " Nvim: not an error anymore: call matchadd('GroupDoesNotExist', 'X') - call assert_equal([{'group': 'GroupDoesNotExist', 'pattern': 'X', 'priority': 10, 'id': 13}], getmatches()) + call assert_equal([{'group': 'GroupDoesNotExist', 'pattern': 'X', 'priority': 10, 'id': 1206}], getmatches()) call assert_fails("call matchadd('Search', '\\(')", 'E475:') call assert_fails("call matchadd('Search', 'XXX', 1, 123, 1)", 'E715:') call assert_fails("call matchadd('Error', 'XXX', 1, 3)", 'E798:') @@ -253,8 +253,8 @@ func Test_matchaddpos_otherwin() let savematches = getmatches(winid) let expect = [ - \ {'group': 'Search', 'pattern': '4', 'priority': 10, 'id': 4}, - \ {'group': 'Error', 'id': 5, 'priority': 10, 'pos1': [1, 2, 1], 'pos2': [2, 2, 1]}, + \ {'group': 'Search', 'pattern': '4', 'priority': 10, 'id': 1000}, + \ {'group': 'Error', 'id': 1001, 'priority': 10, 'pos1': [1, 2, 1], 'pos2': [2, 2, 1]}, \] call assert_equal(expect, savematches) -- cgit From ddc363dce9020bce7d5bd931929f0d11cc87ad6d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 4 Oct 2022 21:52:01 +0800 Subject: vim-patch:9.0.0656: cannot specify another character to use instead of '@' Problem: Cannot specify another character to use instead of '@' at the end of the window. Solution: Add "lastline" to 'fillchars'. (Martin Tournoij, closes vim/vim#11264, closes vim/vim#10963) https://github.com/vim/vim/commit/4ba5f1dab656103e8f4a4505452d1816b9e83c1e Use latest code in drawscreen.c instead. --- src/nvim/testdir/test_display.vim | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_display.vim b/src/nvim/testdir/test_display.vim index 217bb5d781..0962429f71 100644 --- a/src/nvim/testdir/test_display.vim +++ b/src/nvim/testdir/test_display.vim @@ -407,30 +407,45 @@ func Test_display_linebreak_breakat() let &breakat=_breakat endfunc -func Test_display_lastline() - CheckScreendump - +func Run_Test_display_lastline(euro) let lines =<< trim END - call setline(1, ['aaa', 'b'->repeat(100)]) + call setline(1, ['aaa', 'b'->repeat(200)]) set display=truncate + vsplit 100wincmd < END - call writefile(lines, 'XdispLastline') + if a:euro != '' + let lines[2] = 'set fillchars=vert:\|,lastline:€' + endif + call writefile(lines, 'XdispLastline', 'D') let buf = RunVimInTerminal('-S XdispLastline', #{rows: 10}) - call VerifyScreenDump(buf, 'Test_display_lastline_1', {}) + call VerifyScreenDump(buf, $'Test_display_lastline_{a:euro}1', {}) call term_sendkeys(buf, ":set display=lastline\") - call VerifyScreenDump(buf, 'Test_display_lastline_2', {}) + call VerifyScreenDump(buf, $'Test_display_lastline_{a:euro}2', {}) call term_sendkeys(buf, ":100wincmd >\") - call VerifyScreenDump(buf, 'Test_display_lastline_3', {}) + call VerifyScreenDump(buf, $'Test_display_lastline_{a:euro}3', {}) call term_sendkeys(buf, ":set display=truncate\") - call VerifyScreenDump(buf, 'Test_display_lastline_4', {}) + call VerifyScreenDump(buf, $'Test_display_lastline_{a:euro}4', {}) + + call term_sendkeys(buf, ":close\") + call term_sendkeys(buf, ":3split\") + call VerifyScreenDump(buf, $'Test_display_lastline_{a:euro}5', {}) call StopVimInTerminal(buf) - call delete('XdispLastline') +endfunc + +func Test_display_lastline() + CheckScreendump + + call Run_Test_display_lastline('') + call Run_Test_display_lastline('euro_') + + call assert_fails(':set fillchars=lastline:', 'E474:') + call assert_fails(':set fillchars=lastline:〇', 'E474:') endfunc -- cgit From 98bb2c19309ced1131afce4fc2cdae518d0a2dcd Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 5 Oct 2022 06:48:40 +0800 Subject: vim-patch:9.0.0661: multi-byte "lastline" in 'fillchars' does not work properly Problem: Multi-byte "lastline" item in 'fillchars' does not work properly when the window is two columns wide. Solution: Compute the text length correctly. (closes vim/vim#11280) https://github.com/vim/vim/commit/18b3500b8c517e44c23197e558aa36aed1c6916c --- src/nvim/testdir/test_display.vim | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_display.vim b/src/nvim/testdir/test_display.vim index 0962429f71..13796449ab 100644 --- a/src/nvim/testdir/test_display.vim +++ b/src/nvim/testdir/test_display.vim @@ -435,6 +435,10 @@ func Run_Test_display_lastline(euro) call term_sendkeys(buf, ":3split\") call VerifyScreenDump(buf, $'Test_display_lastline_{a:euro}5', {}) + call term_sendkeys(buf, ":close\") + call term_sendkeys(buf, ":2vsplit\") + call VerifyScreenDump(buf, $'Test_display_lastline_{a:euro}6', {}) + call StopVimInTerminal(buf) endfunc -- cgit From c64acad4e2d4c8c05404f05dd149da9d34960a3d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 5 Oct 2022 21:14:03 +0800 Subject: vim-patch:8.2.2413: crash when using :all while using a cmdline window Problem: Crash when using :all while using a cmdline window. (Zdenek Dohnal) Solution: Disallow :all from the cmdline window. https://github.com/vim/vim/commit/bb4b93ed85726c3921596ca267f531c8c94d819a Use test from lastest Vim instead. --- src/nvim/testdir/test_arglist.vim | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_arglist.vim b/src/nvim/testdir/test_arglist.vim index 521c3fcd57..19b64f996c 100644 --- a/src/nvim/testdir/test_arglist.vim +++ b/src/nvim/testdir/test_arglist.vim @@ -591,4 +591,20 @@ func Test_quit_with_arglist() call delete('.c.swp') endfunc +" Test for ":all" not working when in the cmdline window +func Test_all_not_allowed_from_cmdwin() + au BufEnter * all + next x + " Use try/catch here, somehow assert_fails() doesn't work on MS-Windows + " console. + let caught = 'no' + try + exe ":norm! 7q?apat\" + catch /E11:/ + let caught = 'yes' + endtry + call assert_equal('yes', caught) + au! BufEnter +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 0ae47000e060ad21896c0bb434e99d9a7d8c02b9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 5 Oct 2022 21:18:13 +0800 Subject: vim-patch:8.2.2421: double free when using autocommand with "argdel" Problem: Double free when using autocommand with "argdel". (Houyunsong) Solution: Add the arglist_locked flag. https://github.com/vim/vim/commit/5ed58c7b700fcb9fd03c418300145b616f4bdcdd --- src/nvim/testdir/test_autocmd.vim | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index d766256d4b..07042eab32 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -148,6 +148,12 @@ func Test_autocmd_bufunload_with_tabnext() quit endfunc +func Test_argdelete_in_next() + au BufNew,BufEnter,BufLeave,BufWinEnter * argdel + call assert_fails('next a b', 'E1156:') + au! BufNew,BufEnter,BufLeave,BufWinEnter * +endfunc + func Test_autocmd_bufwinleave_with_tabfirst() tabedit augroup sample -- cgit From a66b12378b1431f886c9b4235160abb171bcb05a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 5 Oct 2022 21:33:08 +0800 Subject: vim-patch:8.2.2463: using :arglocal in an autocommand may use freed memory Problem: Using :arglocal in an autocommand may use freed memory. (houyunsong) Solution: Check if the arglist is locked. https://github.com/vim/vim/commit/6bcb877ec19a647443195a54eeac60cb693fd827 --- src/nvim/testdir/test_autocmd.vim | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 07042eab32..c320d3ca78 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -3010,6 +3010,15 @@ func Test_Visual_doautoall_redraw() %bwipe! endfunc +" This was using freed memory. +func Test_BufNew_arglocal() + arglocal + au BufNew * arglocal + call assert_fails('drop xx', 'E1156:') + + au! BufNew +endfunc + func Test_autocmd_closes_window() au BufNew,BufWinLeave * e %e file yyy -- cgit From dcdb7dca6aa7e335b2e8f339d3bb76da1c9d3b6e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 5 Oct 2022 21:27:58 +0800 Subject: vim-patch:8.2.3884: crash when clearing the argument list while using it Problem: Crash when clearing the argument list while using it. Solution: Lock the argument list for ":all". https://github.com/vim/vim/commit/6f98371532fcff911b462d51bc64f2ce8a6ae682 --- src/nvim/testdir/test_arglist.vim | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_arglist.vim b/src/nvim/testdir/test_arglist.vim index 19b64f996c..b1edb66a02 100644 --- a/src/nvim/testdir/test_arglist.vim +++ b/src/nvim/testdir/test_arglist.vim @@ -607,4 +607,11 @@ func Test_all_not_allowed_from_cmdwin() au! BufEnter endfunc +func Test_clear_arglist_in_all() + n 0 00 000 0000 00000 000000 + au! * 0 n 0 + all + au! * +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 824a31cd0d55752b01a9bdd1f38f756e079e25e8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 5 Oct 2022 21:29:56 +0800 Subject: vim-patch:8.2.3885: arglist test fails Problem: Arglist test fails. Solution: Adjust for locking the arglist for ":all". https://github.com/vim/vim/commit/679140c56bbabf12a199d94f584b1b9dfc9809fd --- src/nvim/testdir/test_arglist.vim | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_arglist.vim b/src/nvim/testdir/test_arglist.vim index b1edb66a02..1fa31b6ecc 100644 --- a/src/nvim/testdir/test_arglist.vim +++ b/src/nvim/testdir/test_arglist.vim @@ -509,18 +509,14 @@ func Test_arglist_autocmd() new " redefine arglist; go to Xxx1 next! Xxx1 Xxx2 Xxx3 - " open window for all args; Reading Xxx2 will change the arglist and the - " third window will get Xxx1: - " win 1: Xxx1 - " win 2: Xxx2 - " win 3: Xxx1 - all + " open window for all args; Reading Xxx2 will try to change the arglist and + " that will fail + call assert_fails("all", "E1156:") call assert_equal('test file Xxx1', getline(1)) wincmd w - wincmd w - call assert_equal('test file Xxx1', getline(1)) - rewind call assert_equal('test file Xxx2', getline(1)) + wincmd w + call assert_equal('test file Xxx3', getline(1)) autocmd! BufReadPost Xxx2 enew! | only @@ -610,7 +606,7 @@ endfunc func Test_clear_arglist_in_all() n 0 00 000 0000 00000 000000 au! * 0 n 0 - all + call assert_fails("all", "E1156") au! * endfunc -- cgit From 42afb9153a8380fdbace81c86f789e7b8af2c65c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 5 Oct 2022 21:30:25 +0800 Subject: vim-patch:8.2.3886: can define autocmd for every event by using "au!" Problem: Can define autocmd for every event by using "au!". Solution: Check if a command is present also for "au!". https://github.com/vim/vim/commit/b6db1467622be046dbf00b2213fd9f49f4f3cccb --- src/nvim/testdir/test_arglist.vim | 2 +- src/nvim/testdir/test_autocmd.vim | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_arglist.vim b/src/nvim/testdir/test_arglist.vim index 1fa31b6ecc..c01ae87fd8 100644 --- a/src/nvim/testdir/test_arglist.vim +++ b/src/nvim/testdir/test_arglist.vim @@ -605,7 +605,7 @@ endfunc func Test_clear_arglist_in_all() n 0 00 000 0000 00000 000000 - au! * 0 n 0 + au WinNew 0 n 0 call assert_fails("all", "E1156") au! * endfunc diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index c320d3ca78..025bda4515 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -2054,6 +2054,7 @@ endfunc func Test_autocommand_all_events() call assert_fails('au * * bwipe', 'E1155:') call assert_fails('au * x bwipe', 'E1155:') + call assert_fails('au! * x bwipe', 'E1155:') endfunc func Test_autocmd_user() -- cgit From bc64aa435b84bb3a43501e101c51507c75fbd349 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 6 Oct 2022 09:03:49 +0800 Subject: vim-patch:9.0.0665: setting 'cmdheight' has no effect if last window was resized (#20500) Problem: Setting 'cmdheight' has no effect if last window was resized. Solution: Do apply 'cmdheight' when told to. Use the frame height instead of the cmdline_row. (closes vim/vim#11286) https://github.com/vim/vim/commit/0816f473ab2f6cf7d8311c0f97371cada7f20d18 --- src/nvim/testdir/test_cmdline.vim | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 60f6930c35..b177a9cc9e 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -186,8 +186,15 @@ func Test_changing_cmdheight() let lines =<< trim END set cmdheight=1 laststatus=2 + func EchoTwo() + set laststatus=2 + set cmdheight=5 + echo 'foo' + echo 'bar' + set cmdheight=1 + endfunc END - call writefile(lines, 'XTest_cmdheight') + call writefile(lines, 'XTest_cmdheight', 'D') let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8}) call term_sendkeys(buf, ":resize -3\") @@ -205,14 +212,17 @@ func Test_changing_cmdheight() call term_sendkeys(buf, ":set cmdheight-=2\") call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {}) - " reducing window size and then setting cmdheight + " reducing window size and then setting cmdheight call term_sendkeys(buf, ":resize -1\") call term_sendkeys(buf, ":set cmdheight=1\") call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {}) + " setting 'cmdheight' works after outputting two messages + call term_sendkeys(buf, ":call EchoTwo()\") + call VerifyScreenDump(buf, 'Test_changing_cmdheight_6', {}) + " clean up call StopVimInTerminal(buf) - call delete('XTest_cmdheight') endfunc func Test_map_completion() -- cgit From 4bfbac05c9d4d923da12a50b3a89161dedc2111b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 6 Oct 2022 12:50:34 +0800 Subject: vim-patch:9.0.0422: not enough testing of the :all command (#20503) Problem: Not enough testing of the :all command. Solution: Add more testing. (Yegappan Lakshmanan, closes vim/vim#11091) https://github.com/vim/vim/commit/0dc2fd307ffc223cf010d1fdea6e3d5c4524d43c --- src/nvim/testdir/test_arglist.vim | 126 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_arglist.vim b/src/nvim/testdir/test_arglist.vim index c01ae87fd8..0fd65e8f5a 100644 --- a/src/nvim/testdir/test_arglist.vim +++ b/src/nvim/testdir/test_arglist.vim @@ -610,4 +610,130 @@ func Test_clear_arglist_in_all() au! * endfunc +" Test for the :all command +func Test_all_command() + %argdelete + + " :all command should not close windows with files in the argument list, + " but can rearrange the windows. + args Xargnew1 Xargnew2 + %bw! + edit Xargold1 + split Xargnew1 + let Xargnew1_winid = win_getid() + split Xargold2 + split Xargnew2 + let Xargnew2_winid = win_getid() + split Xargold3 + all + call assert_equal(2, winnr('$')) + call assert_equal([Xargnew1_winid, Xargnew2_winid], + \ [win_getid(1), win_getid(2)]) + call assert_equal([bufnr('Xargnew1'), bufnr('Xargnew2')], + \ [winbufnr(1), winbufnr(2)]) + + " :all command should close windows for files which are not in the + " argument list in the current tab page. + %bw! + edit Xargold1 + split Xargold2 + tabedit Xargold3 + split Xargold4 + tabedit Xargold5 + tabfirst + all + call assert_equal(3, tabpagenr('$')) + call assert_equal([bufnr('Xargnew1'), bufnr('Xargnew2')], tabpagebuflist(1)) + call assert_equal([bufnr('Xargold4'), bufnr('Xargold3')], tabpagebuflist(2)) + call assert_equal([bufnr('Xargold5')], tabpagebuflist(3)) + + " :tab all command should close windows for files which are not in the + " argument list across all the tab pages. + %bw! + edit Xargold1 + split Xargold2 + tabedit Xargold3 + split Xargold4 + tabedit Xargold5 + tabfirst + args Xargnew1 Xargnew2 + tab all + call assert_equal(2, tabpagenr('$')) + call assert_equal([bufnr('Xargnew1')], tabpagebuflist(1)) + call assert_equal([bufnr('Xargnew2')], tabpagebuflist(2)) + + " If a count is specified, then :all should open only that many windows. + %bw! + args Xargnew1 Xargnew2 Xargnew3 Xargnew4 Xargnew5 + all 3 + call assert_equal(3, winnr('$')) + call assert_equal([bufnr('Xargnew1'), bufnr('Xargnew2'), bufnr('Xargnew3')], + \ [winbufnr(1), winbufnr(2), winbufnr(3)]) + + " The :all command should not open more than 'tabpagemax' tab pages. + " If there are more files, then they should be opened in the last tab page. + %bw! + set tabpagemax=3 + tab all + call assert_equal(3, tabpagenr('$')) + call assert_equal([bufnr('Xargnew1')], tabpagebuflist(1)) + call assert_equal([bufnr('Xargnew2')], tabpagebuflist(2)) + call assert_equal([bufnr('Xargnew3'), bufnr('Xargnew4'), bufnr('Xargnew5')], + \ tabpagebuflist(3)) + set tabpagemax& + + " Without the 'hidden' option, modified buffers should not be closed. + args Xargnew1 Xargnew2 + %bw! + edit Xargtemp1 + call setline(1, 'temp buffer 1') + split Xargtemp2 + call setline(1, 'temp buffer 2') + all + call assert_equal(4, winnr('$')) + call assert_equal([bufnr('Xargtemp2'), bufnr('Xargtemp1'), bufnr('Xargnew1'), + \ bufnr('Xargnew2')], + \ [winbufnr(1), winbufnr(2), winbufnr(3), winbufnr(4)]) + + " With the 'hidden' option set, both modified and unmodified buffers in + " closed windows should be hidden. + set hidden + all + call assert_equal(2, winnr('$')) + call assert_equal([bufnr('Xargnew1'), bufnr('Xargnew2')], + \ [winbufnr(1), winbufnr(2)]) + call assert_equal([1, 1, 0, 0], [getbufinfo('Xargtemp1')[0].hidden, + \ getbufinfo('Xargtemp2')[0].hidden, + \ getbufinfo('Xargnew1')[0].hidden, + \ getbufinfo('Xargnew2')[0].hidden]) + set nohidden + + " When 'winheight' is set to a large value, :all should open only one + " window. + args Xargnew1 Xargnew2 Xargnew3 Xargnew4 Xargnew5 + %bw! + set winheight=9999 + call assert_fails('all', 'E36:') + call assert_equal([1, bufnr('Xargnew1')], [winnr('$'), winbufnr(1)]) + set winheight& + + " When 'winwidth' is set to a large value, :vert all should open only one + " window. + %bw! + set winwidth=9999 + call assert_fails('vert all', 'E36:') + call assert_equal([1, bufnr('Xargnew1')], [winnr('$'), winbufnr(1)]) + set winwidth& + + " empty argument list tests + %bw! + %argdelete + call assert_equal('', execute('args')) + all + call assert_equal(1, winnr('$')) + + %argdelete + %bw! +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 5acf52e19b1f9920fe95b55588eff256a439d816 Mon Sep 17 00:00:00 2001 From: luukvbaal <31730729+luukvbaal@users.noreply.github.com> Date: Thu, 6 Oct 2022 08:57:52 +0200 Subject: feat(window/ui): add splitkeep option (#19243) vim-patch:9.0.0445: when opening/closing window text moves up/down Problem: When opening/closing window text moves up/down. Solution: Add the 'splitscroll' option. When off text will keep its position as much as possible. https://github.com/vim/vim/commit/29ab524358ba429bcf6811710afc97a978641f0b vim-patch:9.0.0455: a few problems with 'splitscroll' Problem: A few problems with 'splitscroll'. Solution: Fix 'splitscroll' problems. (Luuk van Baal, closes vim/vim#11117) https://github.com/vim/vim/commit/5ed391708a62b4ebaa84dd23e32a416e5c3383d9 vim-patch:9.0.0461: 'scroll' is not always updated Problem: 'scroll' is not always updated. Solution: Call win_init_size() at the right place. https://github.com/vim/vim/commit/470a14140bc06f1653edf26ab0b3c9b801080353 vim-patch:9.0.0465: cursor moves when cmdwin is closed when 'splitscroll' is off Problem: Cursor moves when cmdwin is closed when 'splitscroll' is off. Solution: Temporarily set 'splitscroll' when jumping back to the original window. (closes vim/vim#11128) https://github.com/vim/vim/commit/e697d488901b6321ddaad68b553f0a434c97d849 vim-patch:9.0.0469: cursor moves if cmdwin is closed when 'splitscroll' is off Problem: Cursor moves if cmdwin is closed when 'splitscroll' is off. Solution: Skip win_fix_cursor if called when cmdwin is open or closing. (Luuk van Baal, closes vim/vim#11134) https://github.com/vim/vim/commit/3735f11050616652525bf80b4fbcb2b3bfeab113 vim-patch:9.0.0478: test for 'splitscroll' takes too much time Problem: Test for 'splitscroll' takes too much time. Solution: Only test some of the combinations. (Luuk van Baal, closes vim/vim#11139) https://github.com/vim/vim/commit/594f9e09cd68e6277b8aa08094405bc642c5792a vim-patch:9.0.0486: text scrolled with 'nosplitscroll', autocmd win and help Problem: Text scrolled with 'nosplitscroll', autocmd win opened and help window closed. Solution: Skip win_fix_scroll() in more situations. (Luuk van Baal, closes vim/vim#11150) https://github.com/vim/vim/commit/d5bc762dea1fd32fa04342f8149f95ccfc3b9709 vim-patch:9.0.0505: various problems with 'nosplitscroll' Problem: Various problems with 'nosplitscroll'. Solution: Fix 'nosplitscroll' problems. (Luuk van Baal, closes vim/vim#11166) https://github.com/vim/vim/commit/faf1d412f5e3665021500b528c0e7301eb02bf0b vim-patch:9.0.0555: scrolling with 'nosplitscroll' in callback changing curwin Problem: Scrolling with 'nosplitscroll' in callback changing curwin. Solution: Invalidate w_cline_row in the right place. (Luuk van Baal, closes vim/vim#11185) https://github.com/vim/vim/commit/20e58561abc4116f3bfbafaef242d886dd77b303 vim-patch:9.0.0603: with 'nosplitscroll' folds are not handled correctly Problem: With 'nosplitscroll' folds are not handled correctly. Solution: Take care of closed folds when moving the cursor. (Luuk van Baal, closes vim/vim#11234) https://github.com/vim/vim/commit/7c1cbb6cd437c6e0c3ccc05840cc931108b4a60a vim-patch:9.0.0605: dump file missing Problem: Dump file missing. Solution: Add the missing dump file. (issue vim/vim#11234) https://github.com/vim/vim/commit/439a2ba1749463718b6ce1e1375b68c7b7cff808 vim-patch:9.0.0647: the 'splitscroll' option is not a good name Problem: The 'splitscroll' option is not a good name. Solution: Rename 'splitscroll' to 'splitkeep' and make it a string option, also supporting "topline". (Luuk van Baal, closes vim/vim#11258) https://github.com/vim/vim/commit/13ece2ae1d09009d3fb8acf858c288e7848ecdac vim-patch:9.0.0667: ml_get error when 'splitkeep' is "screen" Problem: ml_get error when 'splitkeep' is "screen". (Marius Gedminas) Solution: Check the botline is not too large. (Luuk van Baal, closes vim/vim#11293, closes vim/vim#11292) https://github.com/vim/vim/commit/346823d3e5668b99d2c2fd920e7f215e21ad3ea7 --- src/nvim/testdir/test_window_cmd.vim | 256 +++++++++++++++++++++++++++++++++++ 1 file changed, 256 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim index b64f44360b..c4ce4d638c 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -1,5 +1,8 @@ " Tests for window cmd (:wincmd, :split, :vsplit, :resize and etc...) +source check.vim +source screendump.vim + func Test_window_cmd_ls0_with_split() set ls=0 set splitbelow @@ -1486,5 +1489,258 @@ func Test_win_equal_last_status() set laststatus& endfunc +" Test "screen" and "cursor" values for 'splitkeep' with a sequence of +" split operations for various options: with and without a winbar, +" tabline, for each possible value of 'laststatus', 'scrolloff', +" 'equalalways', and with the cursor at the top, middle and bottom. +func Test_splitkeep_options() + " disallow window resizing + " let save_WS = &t_WS + " set t_WS= + + let gui = has("gui_running") + inoremap c "copenwincmd k" + for run in range(0, 20) + let &splitkeep = run > 10 ? 'topline' : 'screen' + let &scrolloff = (!(run % 4) ? 0 : run) + let &laststatus = (run % 3) + let &splitbelow = (run % 3) + let &equalalways = (run % 2) + " Nvim: both windows have a winbar after splitting + " let wsb = (run % 2) && &splitbelow + let wsb = 0 + let tl = (gui ? 0 : ((run % 5) ? 1 : 0)) + let pos = !(run % 3) ? 'H' : ((run % 2) ? 'M' : 'L') + tabnew | tabonly! | redraw + execute (run % 5) ? 'tabnew' : '' + " execute (run % 2) ? 'nnoremenu 1.10 WinBar.Test :echo' : '' + let &winbar = (run % 2) ? '%f' : '' + call setline(1, range(1, 256)) + " No scroll for restore_snapshot + norm G + try + copen | close | colder + catch /E380/ + endtry + call assert_equal(257 - winheight(0), line("w0")) + + " No scroll for firstwin horizontal split + execute 'norm gg' . pos + split | redraw | wincmd k + call assert_equal(1, line("w0")) + call assert_equal(&scroll, winheight(0) / 2) + wincmd j + call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0")) + + " No scroll when resizing windows + wincmd k | resize +2 | redraw + call assert_equal(1, line("w0")) + wincmd j + call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0")) + + " No scroll when dragging statusline + call win_move_statusline(1, -3) + call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0")) + wincmd k + call assert_equal(1, line("w0")) + + " No scroll when changing shellsize + set lines+=2 + call assert_equal(1, line("w0")) + wincmd j + call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0")) + set lines-=2 + call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0")) + wincmd k + call assert_equal(1, line("w0")) + + " No scroll when equalizing windows + wincmd = + call assert_equal(1, line("w0")) + wincmd j + call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0")) + wincmd k + call assert_equal(1, line("w0")) + + " No scroll in windows split multiple times + vsplit | split | 4wincmd w + call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0")) + 1wincmd w | quit | wincmd l | split + call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0")) + wincmd j + call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0")) + + " No scroll in small window + 2wincmd w | only | 5split | wincmd k + call assert_equal(1, line("w0")) + wincmd j + call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0")) + + " No scroll for vertical split + quit | vsplit | wincmd l + call assert_equal(1, line("w0")) + wincmd h + call assert_equal(1, line("w0")) + + " No scroll in windows split and quit multiple times + quit | redraw | split | split | quit | redraw + call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0")) + + " No scroll for new buffer + 1wincmd w | only | copen | wincmd k + call assert_equal(1, line("w0")) + only + call assert_equal(1, line("w0")) + above copen | wincmd j + call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl, line("w0")) + + " No scroll when opening cmdwin, and no cursor move when closing cmdwin. + only | norm ggL + let curpos = getcurpos() + norm q: + call assert_equal(1, line("w0")) + call assert_equal(curpos, getcurpos()) + + " Scroll when cursor becomes invalid in insert mode + norm Lic + call assert_equal(curpos, getcurpos()) + + " No scroll when topline not equal to 1 + only | execute "norm gg5\" | split | wincmd k + call assert_equal(6, line("w0")) + wincmd j + call assert_equal(&spk == 'topline' ? 6 : 5 + win_screenpos(0)[0] - tl - wsb, line("w0")) + endfor + + tabnew | tabonly! | %bwipeout! + iunmap c + set scrolloff& + set splitbelow& + set laststatus& + set equalalways& + set splitkeep& + " let &t_WS = save_WS +endfunc + +function Test_splitkeep_cmdwin_cursor_position() + set splitkeep=screen + call setline(1, range(&lines)) + + " No scroll when cursor is at near bottom of window and cusor position + " recompution (done by line('w0') in this test) happens while in cmdwin. + normal! G + let firstline = line('w0') + autocmd CmdwinEnter * ++once autocmd WinEnter * ++once call line('w0') + execute "normal! q:\q" + redraw! + call assert_equal(firstline, line('w0')) + + " User script can change cursor position successfully while in cmdwin and it + " shouldn't be changed when closing cmdwin. + execute "normal! Gq:\call win_execute(winnr('#')->win_getid(), 'call cursor(1, 1)')\\q" + call assert_equal(1, line('.')) + call assert_equal(1, col('.')) + + execute "normal! Gq:\autocmd WinEnter * ++once call cursor(1, 1)\\q" + call assert_equal(1, line('.')) + call assert_equal(1, col('.')) + + %bwipeout! + set splitkeep& +endfunction + +function Test_splitkeep_misc() + set splitkeep=screen + set splitbelow + + call setline(1, range(1, &lines)) + norm Gzz + let top = line('w0') + " No scroll when aucmd_win is opened + call setbufvar(bufnr("test", 1) , '&buftype', 'nofile') + call assert_equal(top, line('w0')) + " No scroll when tab is changed/closed + tab help | close + call assert_equal(top, line('w0')) + " No scroll when help is closed and buffer line count < window height + norm ggdG + call setline(1, range(1, &lines - 10)) + norm G + let top = line('w0') + help | quit + call assert_equal(top, line('w0')) + " No error when resizing window in autocmd and buffer length changed + autocmd FileType qf exe "resize" line('$') + cexpr getline(1, '$') + copen + wincmd p + norm dd + cexpr getline(1, '$') + + %bwipeout! + set splitbelow& + set splitkeep& +endfunc + +function Test_splitkeep_callback() + CheckScreendump + let lines =<< trim END + set splitkeep=screen + call setline(1, range(&lines)) + function C1(a, b) + split | wincmd p + endfunction + function C2(a, b) + close | split + endfunction + nn j call job_start([&sh, &shcf, "true"], { 'exit_cb': 'C1' }) + nn t call popup_create(term_start([&sh, &shcf, "true"], + \ { 'hidden': 1, 'exit_cb': 'C2' }), {}) + END + call writefile(lines, 'XTestSplitkeepCallback', 'D') + let buf = RunVimInTerminal('-S XTestSplitkeepCallback', #{rows: 8}) + + call term_sendkeys(buf, "j") + call VerifyScreenDump(buf, 'Test_splitkeep_callback_1', {}) + + call term_sendkeys(buf, ":quit\Ht") + call VerifyScreenDump(buf, 'Test_splitkeep_callback_2', {}) + + call term_sendkeys(buf, ":set sb\:quit\Gj") + call VerifyScreenDump(buf, 'Test_splitkeep_callback_3', {}) + + call term_sendkeys(buf, ":quit\Gt") + call VerifyScreenDump(buf, 'Test_splitkeep_callback_4', {}) +endfunc + +function Test_splitkeep_fold() + CheckScreendump + + let lines =<< trim END + set splitkeep=screen + set foldmethod=marker + set number + let line = 1 + for n in range(1, &lines) + call setline(line, ['int FuncName() {/*{{{*/', 1, 2, 3, 4, 5, '}/*}}}*/', + \ 'after fold']) + let line += 8 + endfor + END + call writefile(lines, 'XTestSplitkeepFold', 'D') + let buf = RunVimInTerminal('-S XTestSplitkeepFold', #{rows: 10}) + + call term_sendkeys(buf, "L:wincmd s\") + call VerifyScreenDump(buf, 'Test_splitkeep_fold_1', {}) + + call term_sendkeys(buf, ":quit\") + call VerifyScreenDump(buf, 'Test_splitkeep_fold_2', {}) + + call term_sendkeys(buf, "H:below split\") + call VerifyScreenDump(buf, 'Test_splitkeep_fold_3', {}) + + call term_sendkeys(buf, ":wincmd k\:quit\") + call VerifyScreenDump(buf, 'Test_splitkeep_fold_4', {}) +endfunction " vim: shiftwidth=2 sts=2 expandtab -- cgit From 25dea99ce54de6a8c4369e28e0db82e1af669f24 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 6 Oct 2022 20:03:59 +0800 Subject: vim-patch:9.0.0670: no space for command line when there is a tabline (#20512) Problem: No space for command line when there is a tabline. Solution: Correct computation of where the command line should be. (closes vim/vim#11295) https://github.com/vim/vim/commit/c9f5f73206272ccad0aa536854debc5f9781978a --- src/nvim/testdir/test_cmdline.vim | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index b177a9cc9e..3f8e141afa 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -225,6 +225,16 @@ func Test_changing_cmdheight() call StopVimInTerminal(buf) endfunc +func Test_cmdheight_tabline() + CheckScreendump + + let buf = RunVimInTerminal('-c "set ls=2" -c "set stal=2" -c "set cmdheight=1"', {'rows': 6}) + call VerifyScreenDump(buf, 'Test_cmdheight_tabline_1', {}) + + " clean up + call StopVimInTerminal(buf) +endfunc + func Test_map_completion() if !has('cmdline_compl') return -- cgit From bcef006da6333e9e9a91ed862f8c1d7a0022f094 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 7 Oct 2022 07:06:38 +0800 Subject: vim-patch:9.0.0678: using exclamation marks on :function (#20518) Problem: Using exclamation marks on :function. Solution: Use :func and :endfunc as usual. https://github.com/vim/vim/commit/97f0eb169bf805c372b13c6bc9a03da2e75e3354 Add a missing change from patch 8.1.1875. --- src/nvim/testdir/script_util.vim | 6 +++--- src/nvim/testdir/test_cursorline.vim | 16 ++++++++-------- src/nvim/testdir/test_popup.vim | 6 +++--- src/nvim/testdir/test_prompt_buffer.vim | 2 +- src/nvim/testdir/test_vimscript.vim | 20 ++++++++++---------- src/nvim/testdir/view_util.vim | 16 ++++++++-------- 6 files changed, 33 insertions(+), 33 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/script_util.vim b/src/nvim/testdir/script_util.vim index 9913b1dfaf..28d6a621d6 100644 --- a/src/nvim/testdir/script_util.vim +++ b/src/nvim/testdir/script_util.vim @@ -48,7 +48,7 @@ endfunc " delete it afterwards. However, if an exception is thrown the file may remain, " the caller should call DeleteTheScript() afterwards. let s:script_name = '' -function! ExecAsScript(funcname) +func ExecAsScript(funcname) " Make a script from the function passed as argument. let s:script_name = MakeScript(a:funcname) @@ -56,9 +56,9 @@ function! ExecAsScript(funcname) exec "source" s:script_name call delete(s:script_name) let s:script_name = '' -endfunction +endfunc -function! DeleteTheScript() +func DeleteTheScript() if s:script_name call delete(s:script_name) let s:script_name = '' diff --git a/src/nvim/testdir/test_cursorline.vim b/src/nvim/testdir/test_cursorline.vim index e85e9304a3..47646125db 100644 --- a/src/nvim/testdir/test_cursorline.vim +++ b/src/nvim/testdir/test_cursorline.vim @@ -3,26 +3,26 @@ source check.vim source screendump.vim -function! s:screen_attr(lnum) abort +func s:screen_attr(lnum) abort return map(range(1, 8), 'screenattr(a:lnum, v:val)') -endfunction +endfunc -function! s:test_windows(h, w) abort +func s:test_windows(h, w) abort call NewWindow(a:h, a:w) -endfunction +endfunc -function! s:close_windows() abort +func s:close_windows() abort call CloseWindow() -endfunction +endfunc -function! s:new_hi() abort +func s:new_hi() abort redir => save_hi silent! hi CursorLineNr redir END let save_hi = join(split(substitute(save_hi, '\s*xxx\s*', ' ', ''), "\n"), '') exe 'hi' save_hi 'ctermbg=0 guibg=Black' return save_hi -endfunction +endfunc func Test_cursorline_highlight1() let save_hi = s:new_hi() diff --git a/src/nvim/testdir/test_popup.vim b/src/nvim/testdir/test_popup.vim index 3d1e3fa6db..067e5d14e5 100644 --- a/src/nvim/testdir/test_popup.vim +++ b/src/nvim/testdir/test_popup.vim @@ -1129,15 +1129,15 @@ func Test_CompleteChanged() autocmd! AAAAA_Group set complete& completeopt& - delfunc! OnPumchange + delfunc! OnPumChange bw! endfunc -function! GetPumPosition() +func GetPumPosition() call assert_true( pumvisible() ) let g:pum_pos = pum_getpos() return '' -endfunction +endfunc func Test_pum_getpos() new diff --git a/src/nvim/testdir/test_prompt_buffer.vim b/src/nvim/testdir/test_prompt_buffer.vim index 8f94a8572b..9b8a776c95 100644 --- a/src/nvim/testdir/test_prompt_buffer.vim +++ b/src/nvim/testdir/test_prompt_buffer.vim @@ -223,7 +223,7 @@ func Test_prompt_buffer_getbufinfo() %bwipe! endfunc -function! Test_prompt_while_writing_to_hidden_buffer() +func Test_prompt_while_writing_to_hidden_buffer() throw 'skipped: TODO' call CanTestPromptBuffer() CheckUnix diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index 97e879c9ef..3487a028ca 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -756,23 +756,23 @@ endfunc XpathINIT -function! NULL() +func NULL() Xpath 'a' return 0 -endfunction +endfunc -function! ZERO() +func ZERO() Xpath 'b' return 0 -endfunction +endfunc -function! F0() +func! F0() Xpath 'c' -endfunction +endfunc -function! F1(arg) +func! F1(arg) Xpath 'e' -endfunction +endfunc let V0 = 1 @@ -1370,10 +1370,10 @@ endfunc " Test 95: lines of :append, :change, :insert {{{1 "------------------------------------------------------------------------------- -function! DefineFunction(name, body) +func DefineFunction(name, body) let func = join(['function! ' . a:name . '()'] + a:body + ['endfunction'], "\n") exec func -endfunction +endfunc func Test_script_lines() " :append diff --git a/src/nvim/testdir/view_util.vim b/src/nvim/testdir/view_util.vim index 1cdce21602..a4d0e56af9 100644 --- a/src/nvim/testdir/view_util.vim +++ b/src/nvim/testdir/view_util.vim @@ -19,7 +19,7 @@ endfunc " Get text on the screen, including composing characters. " ScreenLines(lnum, width) or " ScreenLines([start, end], width) -function! ScreenLines(lnum, width) abort +func ScreenLines(lnum, width) abort redraw! if type(a:lnum) == v:t_list let start = a:lnum[0] @@ -33,9 +33,9 @@ function! ScreenLines(lnum, width) abort let lines += [join(map(range(1, a:width), 'screenstring(l, v:val)'), '')] endfor return lines -endfunction +endfunc -function! ScreenAttrs(lnum, width) abort +func ScreenAttrs(lnum, width) abort redraw! if type(a:lnum) == v:t_list let start = a:lnum[0] @@ -49,16 +49,16 @@ function! ScreenAttrs(lnum, width) abort let attrs += [map(range(1, a:width), 'screenattr(l, v:val)')] endfor return attrs -endfunction +endfunc -function! NewWindow(height, width) abort +func NewWindow(height, width) abort exe a:height . 'new' exe a:width . 'vsp' set winfixwidth winfixheight redraw! -endfunction +endfunc -function! CloseWindow() abort +func CloseWindow() abort bw! redraw! -endfunction +endfunc -- cgit From b05e10ef7265c257be79e6888cbf87bb6ba86845 Mon Sep 17 00:00:00 2001 From: ObserverOfTime Date: Sat, 8 Oct 2022 18:46:31 +0300 Subject: vim-patch:9.0.0692: PoE filter files are not recognized (#20542) Problem: PoE filter files are not recognized. Solution: Add a pattern to detect PoE filter files. (closes vim/vim#11305) https://github.com/vim/vim/commit/b7f52f5659c68b61ccc645ef866f8fd82361cd26 --- src/nvim/testdir/test_filetype.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 05aee9b31d..03ce8e9e8c 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -427,6 +427,7 @@ let s:filename_checks = { \ 'plsql': ['file.pls', 'file.plsql'], \ 'po': ['file.po', 'file.pot'], \ 'pod': ['file.pod'], + \ 'poefilter': ['file.filter'], \ 'poke': ['file.pk'], \ 'postscr': ['file.ps', 'file.pfa', 'file.afm', 'file.eps', 'file.epsf', 'file.epsi', 'file.ai'], \ 'pov': ['file.pov'], -- cgit From c93fd83df206c2438a735d6d99e640db1976f2f0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 9 Oct 2022 18:48:32 +0800 Subject: vim-patch:9.0.0697: cursor in wrong position with Visual substitute Problem: Cursor in wrong position with Visual substitute. Solution: When restoring 'linebreak' mark the virtual column as invalid. (closes vim/vim#11309, closes vim/vim#11311) https://github.com/vim/vim/commit/16dab41537ae206f4cab676ad53edbae5fd5fb45 N/A patches for version.c: vim-patch:9.0.0699: tiny build fails Problem: Tiny build fails. Solution: Add #ifdef. https://github.com/vim/vim/commit/bf499c0e6f30a94fe062f83ea0190f93178d0d74 --- src/nvim/testdir/test_listlbr.vim | 21 +++++++++++++++++++++ src/nvim/testdir/test_visual.vim | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_listlbr.vim b/src/nvim/testdir/test_listlbr.vim index affa0f96fa..8598c0d963 100644 --- a/src/nvim/testdir/test_listlbr.vim +++ b/src/nvim/testdir/test_listlbr.vim @@ -7,6 +7,7 @@ CheckOption linebreak CheckFeature conceal source view_util.vim +source screendump.vim function s:screen_lines(lnum, width) abort return ScreenLines(a:lnum, a:width) @@ -133,6 +134,26 @@ func Test_linebreak_with_visual_operations() call s:close_windows() endfunc +func Test_linebreak_reset_restore() + CheckScreendump + + let lines =<< trim END + vim9script + &linebreak = true + &showcmd = true + &showmode = false + ('a'->repeat(&columns - 10) .. ' ' .. 'b'->repeat(10) .. ' c')->setline(1) + END + call writefile(lines, 'XlbrResetRestore', 'D') + let buf = RunVimInTerminal('-S XlbrResetRestore', {'rows': 8}) + + call term_sendkeys(buf, '$v$s') + call VerifyScreenDump(buf, 'Test_linebreak_reset_restore_1', {}) + + call term_sendkeys(buf, "\") + call StopVimInTerminal(buf) +endfunc + func Test_virtual_block() call s:test_windows('setl sbr=+') call setline(1, [ diff --git a/src/nvim/testdir/test_visual.vim b/src/nvim/testdir/test_visual.vim index 9c1ad0c099..faa6b2c1c3 100644 --- a/src/nvim/testdir/test_visual.vim +++ b/src/nvim/testdir/test_visual.vim @@ -1492,5 +1492,37 @@ func Test_switch_buffer_ends_visual_mode() exe 'bwipe!' buf2 endfunc +" Test that cursor is drawn at correct position after an operator in Visual +" mode when 'linebreak' and 'showcmd' are enabled. +func Test_visual_operator_with_linebreak() + CheckRunVimInTerminal + + let lines =<< trim END + set linebreak showcmd noshowmode + call setline(1, repeat('a', &columns - 10) .. ' bbbbbbbbbb c') + END + call writefile(lines, 'XTest_visual_op_linebreak', 'D') + + let buf = RunVimInTerminal('-S XTest_visual_op_linebreak', {'rows': 6}) + + call term_sendkeys(buf, '$v$') + call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])}) + call term_sendkeys(buf, 'zo') + call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])}) + + call term_sendkeys(buf, "$\$") + call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])}) + call term_sendkeys(buf, 'I') + call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])}) + + call term_sendkeys(buf, "\$v$") + call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])}) + call term_sendkeys(buf, 's') + call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])}) + + " clean up + call term_sendkeys(buf, "\") + call StopVimInTerminal(buf) +endfunc " vim: shiftwidth=2 sts=2 expandtab -- cgit From 7cdaa74b3684d40a6e72bbf3eb4deedb0c5df7bc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 9 Oct 2022 18:57:22 +0800 Subject: vim-patch:9.0.0702: incomplete testing cursor position with 'linebreak' set Problem: Incomplete testing cursor position after change with 'linebreak' set. Solution: Add a test and move test cases together. (closes vim/vim#11313) https://github.com/vim/vim/commit/30c0c467d6cc2a7af960ccb9002b50115b0e55cf --- src/nvim/testdir/test_listlbr.vim | 31 +++++++++++++++++++++++++------ src/nvim/testdir/test_visual.vim | 33 --------------------------------- 2 files changed, 25 insertions(+), 39 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_listlbr.vim b/src/nvim/testdir/test_listlbr.vim index 8598c0d963..1cbdba5d76 100644 --- a/src/nvim/testdir/test_listlbr.vim +++ b/src/nvim/testdir/test_listlbr.vim @@ -134,22 +134,41 @@ func Test_linebreak_with_visual_operations() call s:close_windows() endfunc +" Test that cursor is drawn at correct position after an operator when +" 'linebreak' is enabled. func Test_linebreak_reset_restore() CheckScreendump + " f_wincol() calls validate_cursor() let lines =<< trim END - vim9script - &linebreak = true - &showcmd = true - &showmode = false - ('a'->repeat(&columns - 10) .. ' ' .. 'b'->repeat(10) .. ' c')->setline(1) + set linebreak showcmd noshowmode formatexpr=wincol()-wincol() + call setline(1, repeat('a', &columns - 10) .. ' bbbbbbbbbb c') END call writefile(lines, 'XlbrResetRestore', 'D') let buf = RunVimInTerminal('-S XlbrResetRestore', {'rows': 8}) - call term_sendkeys(buf, '$v$s') + call term_sendkeys(buf, '$v$') + call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])}) + call term_sendkeys(buf, 'zo') + call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])}) + + call term_sendkeys(buf, '$v$') + call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])}) + call term_sendkeys(buf, 'gq') + call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])}) + + call term_sendkeys(buf, "$\$") + call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])}) + call term_sendkeys(buf, 'I') + call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])}) + + call term_sendkeys(buf, "\$v$") + call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])}) + call term_sendkeys(buf, 's') + call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])}) call VerifyScreenDump(buf, 'Test_linebreak_reset_restore_1', {}) + " clean up call term_sendkeys(buf, "\") call StopVimInTerminal(buf) endfunc diff --git a/src/nvim/testdir/test_visual.vim b/src/nvim/testdir/test_visual.vim index faa6b2c1c3..65665d36c0 100644 --- a/src/nvim/testdir/test_visual.vim +++ b/src/nvim/testdir/test_visual.vim @@ -1492,37 +1492,4 @@ func Test_switch_buffer_ends_visual_mode() exe 'bwipe!' buf2 endfunc -" Test that cursor is drawn at correct position after an operator in Visual -" mode when 'linebreak' and 'showcmd' are enabled. -func Test_visual_operator_with_linebreak() - CheckRunVimInTerminal - - let lines =<< trim END - set linebreak showcmd noshowmode - call setline(1, repeat('a', &columns - 10) .. ' bbbbbbbbbb c') - END - call writefile(lines, 'XTest_visual_op_linebreak', 'D') - - let buf = RunVimInTerminal('-S XTest_visual_op_linebreak', {'rows': 6}) - - call term_sendkeys(buf, '$v$') - call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])}) - call term_sendkeys(buf, 'zo') - call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])}) - - call term_sendkeys(buf, "$\$") - call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])}) - call term_sendkeys(buf, 'I') - call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])}) - - call term_sendkeys(buf, "\$v$") - call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])}) - call term_sendkeys(buf, 's') - call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])}) - - " clean up - call term_sendkeys(buf, "\") - call StopVimInTerminal(buf) -endfunc - " vim: shiftwidth=2 sts=2 expandtab -- cgit From d4e749f1b2358f12af3dd2481a0b9c36169cbeef Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 10 Oct 2022 11:34:53 +0800 Subject: vim-patch:9.0.0700: there is no real need for a "big" build (#20563) Problem: There is no real need for a "big" build. Solution: Move common features to "normal" build, less often used features to the "huge" build. (Martin Tournoij, closes vim/vim#11283) https://github.com/vim/vim/commit/25f3a146a0e4c731b8608f4cfbbfdf7a71b2d05e --- src/nvim/testdir/test_regexp_utf8.vim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_regexp_utf8.vim b/src/nvim/testdir/test_regexp_utf8.vim index 14b9724d67..2253242a7c 100644 --- a/src/nvim/testdir/test_regexp_utf8.vim +++ b/src/nvim/testdir/test_regexp_utf8.vim @@ -258,8 +258,7 @@ func Test_multibyte_chars() " When there is no match use only the first two items. let tl = [] - " Multi-byte character tests. These will fail unless vim is compiled - " with Multibyte (FEAT_MBYTE) or BIG/HUGE features. + " Multi-byte character tests. call add(tl, [2, '[[:alpha:][=a=]]\+', '879 aiaãâaiuvna ', 'aiaãâaiuvna']) call add(tl, [2, '[[=a=]]\+', 'ddaãâbcd', 'aãâ']) " equivalence classes call add(tl, [2, '[^ม ]\+', 'มม oijasoifjos ifjoisj f osij j มมมมม abcd', 'oijasoifjos']) -- cgit From 81058119dfa493aa7849b0ad125e9b1d79fb20b9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 10 Oct 2022 21:26:18 +0800 Subject: vim-patch:9.0.0713: of MenuPopup event is expanded like a file name (#20572) Problem: of MenuPopup event is expanded like a file name. Solution: Do not expand for MenuPopup. (closes vim/vim#11328) https://github.com/vim/vim/commit/c601d988b6b1a672f71e3d61f4aaa4f7742a3a21 --- src/nvim/testdir/test_menu.vim | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_menu.vim b/src/nvim/testdir/test_menu.vim index 75992d3313..db7ec92bf8 100644 --- a/src/nvim/testdir/test_menu.vim +++ b/src/nvim/testdir/test_menu.vim @@ -481,6 +481,35 @@ func Test_popup_menu() unmenu PopUp endfunc +" Test for MenuPopup autocommand +func Test_autocmd_MenuPopup() + CheckNotGui + + set mouse=a + set mousemodel=popup + aunmenu * + autocmd MenuPopup * exe printf( + \ 'anoremenu PopUp.Foo let g:res = ["%s", "%s"]', + \ expand(''), expand('')) + + call feedkeys("\\\", 'tnix') + call assert_equal(['n', 'n'], g:res) + + call feedkeys("v\\\\", 'tnix') + call assert_equal(['v', 'v'], g:res) + + call feedkeys("gh\\\\", 'tnix') + call assert_equal(['s', 's'], g:res) + + call feedkeys("i\\\\", 'tnix') + call assert_equal(['i', 'i'], g:res) + + autocmd! MenuPopup + aunmenu PopUp.Foo + unlet g:res + set mouse& mousemodel& +endfunc + " Test for listing the menus using the :menu command func Test_show_menus() " In the GUI, tear-off menu items are present in the output below -- cgit From 8781213f00a22e20abeb4282204e900db799f4b5 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Mon, 10 Oct 2022 17:51:31 +0200 Subject: vim-patch:9.0.0711: SubStation Alpha files are not recognized (#20577) Problem: SubStation Alpha files are not recognized. Solution: Add patterns for SubStation Alpha files. (closes vim/vim#11332) https://github.com/vim/vim/commit/084f2620ec7d08d6043de30436197c002fffe3ec --- src/nvim/testdir/test_filetype.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 03ce8e9e8c..d123d469a6 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -537,6 +537,7 @@ let s:filename_checks = { \ 'squirrel': ['file.nut'], \ 'srec': ['file.s19', 'file.s28', 'file.s37', 'file.mot', 'file.srec'], \ 'srt': ['file.srt'], + \ 'ssa': ['file.ass', 'file.ssa'], \ 'sshconfig': ['ssh_config', '/.ssh/config', '/etc/ssh/ssh_config.d/file.conf', 'any/etc/ssh/ssh_config.d/file.conf', 'any/.ssh/config', 'any/.ssh/file.conf'], \ 'sshdconfig': ['sshd_config', '/etc/ssh/sshd_config.d/file.conf', 'any/etc/ssh/sshd_config.d/file.conf'], \ 'st': ['file.st'], -- cgit From 9c272b75ecf955afe7feedc209f5d9a3b7116650 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 10 Oct 2022 21:11:12 +0800 Subject: vim-patch:8.2.2184: Vim9: no error when using "2" for a line number Problem: Vim9: no error when using "2" for a line number. Solution: Give an error message if the line number is invalid. (closes vim/vim#7492) https://github.com/vim/vim/commit/9a963377b4811e4e0419ec8825856ff4b01331ac N/A patches for version.c: vim-patch:8.2.1465: Vim9: subscript not handled properly Problem: Vim9: subscript not handled properly. Solution: Adjust error message. Remove dead code. Disallow string to number conversion in scripts. https://github.com/vim/vim/commit/56acb0943ede35cd9d2f6667cde2442819ccbf59 --- src/nvim/testdir/test_cursor_func.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cursor_func.vim b/src/nvim/testdir/test_cursor_func.vim index 2e625f2388..e428bf3e23 100644 --- a/src/nvim/testdir/test_cursor_func.vim +++ b/src/nvim/testdir/test_cursor_func.vim @@ -32,7 +32,7 @@ func Test_move_cursor() call cursor(1, 1, 1) call assert_equal([1, 1, 1], getcurpos()[1:3]) - call assert_equal(-1, cursor(-1, -1)) + call assert_fails('call cursor(-1, -1)', 'E475:') quit! endfunc -- cgit From 249cb8345d6e2f9986ad1dfe42d9cde0f9ed7d6a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 10 Oct 2022 21:38:24 +0800 Subject: vim-patch:9.0.0712: wrong column when calling setcursorcharpos() with zero lnum Problem: Wrong column when calling setcursorcharpos() with zero lnum. Solution: Set the line number before calling buf_charidx_to_byteidx(). (closes vim/vim#11329) https://github.com/vim/vim/commit/79f234499b6692cc16970b7455bc9b002242632f --- src/nvim/testdir/test_cursor_func.vim | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cursor_func.vim b/src/nvim/testdir/test_cursor_func.vim index e428bf3e23..9801a45915 100644 --- a/src/nvim/testdir/test_cursor_func.vim +++ b/src/nvim/testdir/test_cursor_func.vim @@ -353,8 +353,14 @@ func Test_setcursorcharpos() normal G call setcursorcharpos([1, 1]) call assert_equal([1, 1], [line('.'), col('.')]) + call setcursorcharpos([2, 7, 0]) call assert_equal([2, 9], [line('.'), col('.')]) + call setcursorcharpos([0, 7, 0]) + call assert_equal([2, 9], [line('.'), col('.')]) + call setcursorcharpos(0, 7, 0) + call assert_equal([2, 9], [line('.'), col('.')]) + call setcursorcharpos(3, 4) call assert_equal([3, 1], [line('.'), col('.')]) call setcursorcharpos([3, 1]) -- cgit From 4f305fba14ec8c1919ed793b6e09e15ca54a8c1d Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Wed, 12 Oct 2022 15:23:42 +0200 Subject: vim-patch:9.0.0731: clang-tidy configuration files are not recognized (#20620) Problem: clang-tidy configuration files are not recognized. Solution: Recognize clang-tidy files as yaml. (closes vim/vim#11350) https://github.com/vim/vim/commit/af40f9af335e0c8b167eac31ceace45b6a2e0565 --- src/nvim/testdir/test_filetype.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index d123d469a6..b637f1a16f 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -641,7 +641,7 @@ let s:filename_checks = { \ 'xsd': ['file.xsd'], \ 'xslt': ['file.xsl', 'file.xslt'], \ 'yacc': ['file.yy', 'file.yxx', 'file.y++'], - \ 'yaml': ['file.yaml', 'file.yml'], + \ 'yaml': ['file.yaml', 'file.yml', '.clang-tidy'], \ 'yang': ['file.yang'], \ 'z8a': ['file.z8a'], \ 'zig': ['file.zig'], -- cgit From 73bdfdd382bf2addd7816571608db6911448b48a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 13 Oct 2022 09:43:06 +0800 Subject: vim-patch:8.2.4453: :helpgrep may free an option that was not allocated Problem: :helpgrep may free an option that was not allocated. (Yegappan Lakshmanan) Solution: Check if the value was allocated. https://github.com/vim/vim/commit/4791fcd82565adcc60b86830e0bb6cd5b6eea0a6 --- src/nvim/testdir/test_quickfix.vim | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 8c9e39570f..51b11b5511 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -714,6 +714,33 @@ func Test_helpgrep() call s:test_xhelpgrep('l') endfunc +func Test_helpgrep_restore_cpo_aucmd() + let save_cpo = &cpo + augroup QF_Test + au! + autocmd BufNew * set cpo=acd + augroup END + + helpgrep quickfix + call assert_equal('acd', &cpo) + %bw! + + set cpo&vim + augroup QF_Test + au! + autocmd BufReadPost * set cpo= + augroup END + + helpgrep buffer + call assert_equal('', &cpo) + + augroup QF_Test + au! + augroup END + %bw! + let &cpo = save_cpo +endfunc + func Test_errortitle() augroup QfBufWinEnter au! -- cgit From cd1e0bb87dc71d51d9e8da097f5822c37e909335 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 13 Oct 2022 10:13:17 +0800 Subject: vim-patch:8.2.4462: not enough testing for quickfix code Problem: Not enough testing for quickfix code. Solution: Add more tests. Fix uncovered problem. (Yegappan Lakshmanan, closes vim/vim#9839) https://github.com/vim/vim/commit/9c9be05b17ececb1515a2f41a4dedbf848d3d8b6 Omit Test_helpgrep_vim9_restore_cpo(). Cherry-pick test_quickfix.vim change from patch 8.2.0644. --- src/nvim/testdir/test_makeencoding.vim | 16 ++++ src/nvim/testdir/test_quickfix.vim | 165 +++++++++++++++++++++++++++++++-- 2 files changed, 174 insertions(+), 7 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_makeencoding.vim b/src/nvim/testdir/test_makeencoding.vim index c53c07d991..e297bdc228 100644 --- a/src/nvim/testdir/test_makeencoding.vim +++ b/src/nvim/testdir/test_makeencoding.vim @@ -107,3 +107,19 @@ func Test_make() lclose endfor endfunc + +" Test for an error file with a long line that needs an encoding conversion +func Test_longline_conversion() + new + call setline(1, ['Xfile:10:' .. repeat("\xe0", 2000)]) + write ++enc=latin1 Xerr.out + bw! + set errorformat& + set makeencoding=latin1 + cfile Xerr.out + call assert_equal(repeat("\u00e0", 2000), getqflist()[0].text) + call delete('Xerr.out') + set makeencoding& +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 51b11b5511..e19766775d 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -261,6 +261,7 @@ func XwindowTests(cchar) " Opening the location list window without any errors should fail if a:cchar == 'l' call assert_fails('lopen', 'E776:') + call assert_fails('lwindow', 'E776:') endif " Create a list with no valid entries @@ -714,6 +715,8 @@ func Test_helpgrep() call s:test_xhelpgrep('l') endfunc +" When running the :helpgrep command, if an autocmd modifies the 'cpoptions' +" value, then Vim crashes. (issue fixed by 7.2b-004 and 8.2.4453) func Test_helpgrep_restore_cpo_aucmd() let save_cpo = &cpo augroup QF_Test @@ -1237,8 +1240,14 @@ func Xinvalid_efm_Tests(cchar) set efm= call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E378:') + " Empty directory name. When there is an error in parsing new entries, make + " sure the previous quickfix list is made the current list. + set efm& + cexpr ["one", "two"] + let qf_id = getqflist(#{id: 0}).id set efm=%DEntering\ dir\ abc,%f:%l:%m call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E379:') + call assert_equal(qf_id, getqflist(#{id: 0}).id) let &efm = save_efm endfunc @@ -1492,7 +1501,7 @@ func XquickfixChangedByAutocmd(cchar) endfunc endif - augroup testgroup + augroup QF_Test au! autocmd BufReadCmd test_changed.txt call ReadFunc() augroup END @@ -1506,7 +1515,24 @@ func XquickfixChangedByAutocmd(cchar) endfor call assert_fails('Xrewind', ErrorNr . ':') - augroup! testgroup + augroup QF_Test + au! + augroup END + + if a:cchar == 'c' + cexpr ["Xtest1:1:Line"] + cwindow + only + augroup QF_Test + au! + autocmd WinEnter * call setqflist([], 'f') + augroup END + call assert_fails('exe "normal \"', 'E925:') + augroup QF_Test + au! + augroup END + endif + %bw! endfunc func Test_quickfix_was_changed_by_autocmd() @@ -1644,6 +1670,9 @@ func SetXlistTests(cchar, bnum) \ " {'bufnr':999, 'lnum':5}])", 'E92:') call g:Xsetlist([[1, 2,3]]) call assert_equal(0, len(g:Xgetlist())) + call assert_fails('call g:Xsetlist([], [])', 'E928:') + call g:Xsetlist([v:_null_dict]) + call assert_equal([], g:Xgetlist()) endfunc func Test_setqflist() @@ -2917,6 +2946,19 @@ func XvimgrepTests(cchar) call assert_equal(0, getbufinfo('Xtestfile1')[0].loaded) call assert_equal([], getbufinfo('Xtestfile2')) + " Test for opening the dummy buffer used by vimgrep in a window. The new + " window should be closed + %bw! + augroup QF_Test + au! + autocmd BufReadPre * exe "sb " .. expand("") + augroup END + call assert_fails("Xvimgrep /sublime/ Xtestfile1", 'E480:') + call assert_equal(1, winnr('$')) + augroup QF_Test + au! + augroup END + call delete('Xtestfile1') call delete('Xtestfile2') endfunc @@ -4088,14 +4130,19 @@ endfunc " The following test used to crash Vim func Test_lhelpgrep_autocmd() lhelpgrep quickfix - autocmd QuickFixCmdPost * call setloclist(0, [], 'f') + augroup QF_Test + au! + autocmd QuickFixCmdPost * call setloclist(0, [], 'f') + augroup END lhelpgrep buffer call assert_equal('help', &filetype) call assert_equal(0, getloclist(0, {'nr' : '$'}).nr) lhelpgrep tabpage call assert_equal('help', &filetype) call assert_equal(1, getloclist(0, {'nr' : '$'}).nr) - au! QuickFixCmdPost + augroup QF_Test + au! + augroup END new | only augroup QF_Test @@ -4108,7 +4155,7 @@ func Test_lhelpgrep_autocmd() wincmd w call assert_fails('helpgrep quickfix', 'E925:') augroup QF_Test - au! BufEnter + au! augroup END new | only @@ -4118,7 +4165,7 @@ func Test_lhelpgrep_autocmd() augroup END call assert_fails('helpgrep quickfix', 'E925:') augroup QF_Test - au! BufEnter + au! augroup END new | only @@ -4128,10 +4175,43 @@ func Test_lhelpgrep_autocmd() augroup END call assert_fails('lhelpgrep quickfix', 'E926:') augroup QF_Test - au! BufEnter + au! augroup END + " Replace the contents of a help window location list when it is still in + " use. new | only + lhelpgrep quickfix + wincmd w + augroup QF_Test + au! + autocmd WinEnter * call setloclist(0, [], 'r') + augroup END + call assert_fails('lhelpgrep win_getid', 'E926:') + augroup QF_Test + au! + augroup END + + %bw! +endfunc + +" The following test used to crash Vim +func Test_lhelpgrep_autocmd_free_loclist() + %bw! + lhelpgrep quickfix + wincmd w + augroup QF_Test + au! + autocmd WinEnter * call setloclist(0, [], 'f') + augroup END + lhelpgrep win_getid + wincmd w + wincmd w + wincmd w + augroup QF_Test + au! + augroup END + %bw! endfunc " Test for shortening/simplifying the file name when opening the @@ -5322,6 +5402,7 @@ func Xtest_getqflist_by_idx(cchar) call assert_equal('L20', l[0].text) call assert_equal([], g:Xgetlist({'idx' : -1, 'items' : 0}).items) call assert_equal([], g:Xgetlist({'idx' : 3, 'items' : 0}).items) + call assert_equal({}, g:Xgetlist(#{idx: "abc"})) %bwipe! endfunc @@ -5380,6 +5461,19 @@ func Xtest_qftextfunc(cchar) call assert_equal('F1|10 col 2-7| green', getline(1)) call assert_equal('F1|20-25 col 4-8| blue', getline(2)) Xclose + + set efm=%f:%l:%c:%m + set quickfixtextfunc=Tqfexpr + " Update the list with only the cwindow + Xwindow + only + call g:Xsetlist([ + \ { 'filename': 'F2', 'lnum': 20, 'col': 2, + \ 'end_col': 7, 'text': 'red'} + \ ]) + call assert_equal(['F2-L20C2-red'], getline(1, '$')) + new + Xclose set efm& set quickfixtextfunc& @@ -5687,5 +5781,62 @@ func Test_lopen_bwipe_all() call delete('Xresult') endfunc +" Test for calling setqflist() function recursively +func Test_recursive_setqflist() + augroup QF_Test + au! + autocmd BufWinEnter quickfix call setqflist([], 'r') + augroup END + + copen + call assert_fails("call setqflist([], 'a')", 'E952:') + + augroup QF_Test + au! + augroup END + %bw! +endfunc + +" Test for failure to create a new window when selecting a file from the +" quickfix window +func Test_cwindow_newwin_fails() + cgetexpr ["Xfile1:10:L10", "Xfile1:20:L20"] + cwindow + only + let qf_wid = win_getid() + " create the maximum number of scratch windows + let hor_win_count = (&lines - 1)/2 + let hor_split_count = hor_win_count - 1 + for s in range(1, hor_split_count) | new | set buftype=nofile | endfor + call win_gotoid(qf_wid) + call assert_fails('exe "normal \"', 'E36:') + %bw! +endfunc + +" Test for updating the location list when only the location list window is +" present and the corresponding file window is closed. +func Test_loclist_update_with_llwin_only() + %bw! + new + wincmd w + lexpr ["Xfile1:1:Line1"] + lopen + wincmd p + close + call setloclist(2, [], 'r', {'lines': ["Xtest2:2:Line2"]}) + call assert_equal(['Xtest2|2| Line2'], getbufline(winbufnr(2), 1, '$')) + %bw! +endfunc + +" Test for getting the quickfix list after a buffer with an error is wiped out +func Test_getqflist_wiped_out_buffer() + %bw! + cexpr ["Xtest1:34:Wiped out"] + let bnum = bufnr('Xtest1') + call assert_equal(bnum, getqflist()[0].bufnr) + bw Xtest1 + call assert_equal(0, getqflist()[0].bufnr) + %bw! +endfunc " vim: shiftwidth=2 sts=2 expandtab -- cgit From 5740b3e076770336a15e88263878546345a3d325 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 13 Oct 2022 11:06:49 +0800 Subject: vim-patch:9.0.0260: using freed memory when using 'quickfixtextfunc' recursively Problem: Using freed memory when using 'quickfixtextfunc' recursively. Solution: Do not allow for recursion. https://github.com/vim/vim/commit/d6c67629ed05aae436164eec474832daf8ba7420 Cherry-pick Test_qflist_statusmsg() from patch 8.2.4617. --- src/nvim/testdir/test_quickfix.vim | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index e19766775d..449904fcb4 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -5839,4 +5839,52 @@ func Test_getqflist_wiped_out_buffer() %bw! endfunc +" Test for the status message that is displayed when opening a new quickfix +" list +func Test_qflist_statusmsg() + cexpr "1\n2" + cexpr "1\n2\n3\ntest_quickfix.vim:1:msg" + call assert_equal('(4 of 4): msg', v:statusmsg) + call setqflist([], 'f') + %bw! + + " When creating a new quickfix list, if an autocmd changes the quickfix list + " in the stack, then an error message should be displayed. + augroup QF_Test + au! + au BufEnter test_quickfix.vim colder + augroup END + cexpr "1\n2" + call assert_fails('cexpr "1\n2\n3\ntest_quickfix.vim:1:msg"', 'E925:') + call setqflist([], 'f') + augroup QF_Test + au! + augroup END + %bw! + + augroup QF_Test + au! + au BufEnter test_quickfix.vim caddexpr "4" + augroup END + call assert_fails('cexpr "1\n2\n3\ntest_quickfix.vim:1:msg"', 'E925:') + call setqflist([], 'f') + augroup QF_Test + au! + augroup END + %bw! +endfunc + +func Test_quickfixtextfunc_recursive() + func s:QFTfunc(o) + cgete '0' + endfunc + copen + let &quickfixtextfunc = 's:QFTfunc' + cex "" + + let &quickfixtextfunc = '' + cclose +endfunc + + " vim: shiftwidth=2 sts=2 expandtab -- cgit From f72ae4514c51bb2a7c0fdfc8e2a469037dd36666 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 13 Oct 2022 11:10:30 +0800 Subject: vim-patch:9.0.0286: using freed memory when location list changed in autocmd Problem: Using freed memory when location list changed in autocmd. Solution: Return QF_ABORT and handle it. (Yegappan Lakshmanan, closes vim/vim#10993) https://github.com/vim/vim/commit/6d24a51b94beb1991cddce221f90b455e2d50db7 --- src/nvim/testdir/test_quickfix.vim | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 449904fcb4..4802d1f188 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -5886,5 +5886,22 @@ func Test_quickfixtextfunc_recursive() cclose endfunc +" Test for replacing the location list from an autocmd. This used to cause a +" read from freed memory. +func Test_loclist_replace_autocmd() + %bw! + call setloclist(0, [], 'f') + let s:bufnr = bufnr() + cal setloclist(0, [{'0': 0, '': ''}]) + au BufEnter * cal setloclist(1, [{'t': ''}, {'bufnr': s:bufnr}], 'r') + lopen + try + exe "norm j\" + catch + endtry + lnext + %bw! + call setloclist(0, [], 'f') +endfunc " vim: shiftwidth=2 sts=2 expandtab -- cgit From 4fbf41dfb4e4c6fd91c5a3d581c771bd1d6839d5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 13 Oct 2022 14:31:10 +0800 Subject: vim-patch:8.2.4735: quickfix tests can be a bit hard to read (#20631) Problem: Quickfix tests can be a bit hard to read. Solution: Use heredoc instead of strings and line continuation. (Yegappan Lakshmanan, closes vim/vim#10145) https://github.com/vim/vim/commit/4a7724a4406f639edd3f93f3542626811cf56719 Cherry-pick a typo fix from patch 8.2.3637. --- src/nvim/testdir/test_quickfix.vim | 492 ++++++++++++++++++++++--------------- 1 file changed, 294 insertions(+), 198 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 4802d1f188..b0e83b7f5f 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -104,9 +104,15 @@ func XlistTests(cchar) call assert_true(v:errmsg ==# 'E42: No Errors') " Populate the list and then try - Xgetexpr ['non-error 1', 'Xtestfile1:1:3:Line1', - \ 'non-error 2', 'Xtestfile2:2:2:Line2', - \ 'non-error| 3', 'Xtestfile3:3:1:Line3'] + let lines =<< trim END + non-error 1 + Xtestfile1:1:3:Line1 + non-error 2 + Xtestfile2:2:2:Line2 + non-error| 3 + Xtestfile3:3:1:Line3 + END + Xgetexpr lines " List only valid entries let l = split(execute('Xlist', ''), "\n") @@ -272,8 +278,12 @@ func XwindowTests(cchar) call assert_true(winnr('$') == 1) " Create a list with valid entries - Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2', - \ 'Xtestfile3:3:1:Line3'] + let lines =<< trim END + Xtestfile1:1:3:Line1 + Xtestfile2:2:2:Line2 + Xtestfile3:3:1:Line3 + END + Xgetexpr lines " Open the window Xwindow @@ -336,8 +346,12 @@ func XwindowTests(cchar) if a:cchar == 'c' " Opening the quickfix window in multiple tab pages should reuse the " quickfix buffer - Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2', - \ 'Xtestfile3:3:1:Line3'] + let lines =<< trim END + Xtestfile1:1:3:Line1 + Xtestfile2:2:2:Line2 + Xtestfile3:3:1:Line3 + END + Xgetexpr lines Xopen let qfbufnum = bufnr('%') tabnew @@ -372,14 +386,16 @@ func Test_copenHeight_tabline() set tabline& showtabline& endfunc - " Tests for the :cfile, :lfile, :caddfile, :laddfile, :cgetfile and :lgetfile " commands. func XfileTests(cchar) call s:setup_commands(a:cchar) - call writefile(['Xtestfile1:700:10:Line 700', - \ 'Xtestfile2:800:15:Line 800'], 'Xqftestfile1') + let lines =<< trim END + Xtestfile1:700:10:Line 700 + Xtestfile2:800:15:Line 800 + END + call writefile(lines, 'Xqftestfile1') enew! Xfile Xqftestfile1 @@ -403,8 +419,11 @@ func XfileTests(cchar) call assert_true(len(l) == 3 && \ l[2].lnum == 900 && l[2].col == 30 && l[2].text ==# 'Line 900') - call writefile(['Xtestfile1:222:77:Line 222', - \ 'Xtestfile2:333:88:Line 333'], 'Xqftestfile1') + let lines =<< trim END + Xtestfile1:222:77:Line 222 + Xtestfile2:333:88:Line 333 + END + call writefile(lines, 'Xqftestfile1') enew! Xgetfile Xqftestfile1 @@ -434,8 +453,11 @@ func XbufferTests(cchar) call s:setup_commands(a:cchar) enew! - silent! call setline(1, ['Xtestfile7:700:10:Line 700', - \ 'Xtestfile8:800:15:Line 800']) + let lines =<< trim END + Xtestfile7:700:10:Line 700 + Xtestfile8:800:15:Line 800 + END + silent! call setline(1, lines) Xbuffer! let l = g:Xgetlist() call assert_true(len(l) == 2 && @@ -443,8 +465,11 @@ func XbufferTests(cchar) \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800') enew! - silent! call setline(1, ['Xtestfile9:900:55:Line 900', - \ 'Xtestfile10:950:66:Line 950']) + let lines =<< trim END + Xtestfile9:900:55:Line 900 + Xtestfile10:950:66:Line 950 + END + silent! call setline(1, lines) Xgetbuffer let l = g:Xgetlist() call assert_true(len(l) == 2 && @@ -452,8 +477,11 @@ func XbufferTests(cchar) \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950') enew! - silent! call setline(1, ['Xtestfile11:700:20:Line 700', - \ 'Xtestfile12:750:25:Line 750']) + let lines =<< trim END + Xtestfile11:700:20:Line 700 + Xtestfile12:750:25:Line 750 + END + silent! call setline(1, lines) Xaddbuffer let l = g:Xgetlist() call assert_true(len(l) == 4 && @@ -523,12 +551,15 @@ func Xtest_browse(cchar) call s:create_test_file('Xqftestfile1') call s:create_test_file('Xqftestfile2') - Xgetexpr ['Xqftestfile1:5:Line5', - \ 'Xqftestfile1:6:Line6', - \ 'Xqftestfile2:10:Line10', - \ 'Xqftestfile2:11:Line11', - \ 'RegularLine1', - \ 'RegularLine2'] + let lines =<< trim END + Xqftestfile1:5:Line5 + Xqftestfile1:6:Line6 + Xqftestfile2:10:Line10 + Xqftestfile2:11:Line11 + RegularLine1 + RegularLine2 + END + Xgetexpr lines Xfirst call assert_fails('-5Xcc', 'E16:') @@ -578,10 +609,13 @@ func Xtest_browse(cchar) call assert_equal(5, line('.')) " Jumping to an error from the error window using cc command - Xgetexpr ['Xqftestfile1:5:Line5', - \ 'Xqftestfile1:6:Line6', - \ 'Xqftestfile2:10:Line10', - \ 'Xqftestfile2:11:Line11'] + let lines =<< trim END + Xqftestfile1:5:Line5 + Xqftestfile1:6:Line6 + Xqftestfile2:10:Line10 + Xqftestfile2:11:Line11 + END + Xgetexpr lines Xopen 10Xcc call assert_equal(11, line('.')) @@ -1109,20 +1143,21 @@ func s:dir_stack_tests(cchar) let save_efm=&efm set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f' - let lines = ["Entering dir 'dir1/a'", - \ 'habits2.txt:1:Nine Healthy Habits', - \ "Entering dir 'b'", - \ 'habits3.txt:2:0 Hours of television', - \ 'habits2.txt:7:5 Small meals', - \ "Entering dir 'dir1/c'", - \ 'habits4.txt:3:1 Hour of exercise', - \ "Leaving dir 'dir1/c'", - \ "Leaving dir 'dir1/a'", - \ 'habits1.txt:4:2 Liters of water', - \ "Entering dir 'dir2'", - \ 'habits5.txt:5:3 Cups of hot green tea', - \ "Leaving dir 'dir2'" - \] + let lines =<< trim END + Entering dir 'dir1/a' + habits2.txt:1:Nine Healthy Habits + Entering dir 'b' + habits3.txt:2:0 Hours of television + habits2.txt:7:5 Small meals + Entering dir 'dir1/c' + habits4.txt:3:1 Hour of exercise + Leaving dir 'dir1/c' + Leaving dir 'dir1/a' + habits1.txt:4:2 Liters of water + Entering dir 'dir2' + habits5.txt:5:3 Cups of hot green tea + Leaving dir 'dir2' + END Xexpr "" for l in lines @@ -1156,19 +1191,19 @@ func Test_efm_dirstack() call mkdir('dir1/c') call mkdir('dir2') - let lines = ["Nine Healthy Habits", - \ "0 Hours of television", - \ "1 Hour of exercise", - \ "2 Liters of water", - \ "3 Cups of hot green tea", - \ "4 Short mental breaks", - \ "5 Small meals", - \ "6 AM wake up time", - \ "7 Minutes of laughter", - \ "8 Hours of sleep (at least)", - \ "9 PM end of the day and off to bed" - \ ] - + let lines =<< trim END + Nine Healthy Habits + 0 Hours of television + 1 Hour of exercise + 2 Liters of water + 3 Cups of hot green tea + 4 Short mental breaks + 5 Small meals + 6 AM wake up time + 7 Minutes of laughter + 8 Hours of sleep (at least) + 9 PM end of the day and off to bed + END call writefile(lines, 'habits1.txt') call writefile(lines, 'dir1/a/habits2.txt') call writefile(lines, 'dir1/a/b/habits3.txt') @@ -1194,7 +1229,13 @@ func Xefm_ignore_continuations(cchar) \ '%-Wignored %m %l,' . \ '%+Cmore ignored %m %l,' . \ '%Zignored end' - Xgetexpr ['ignored warning 1', 'more ignored continuation 2', 'ignored end', 'error resync 4'] + let lines =<< trim END + ignored warning 1 + more ignored continuation 2 + ignored end + error resync 4 + END + Xgetexpr lines let l = map(g:Xgetlist(), '[v:val.text, v:val.valid, v:val.lnum, v:val.type]') call assert_equal([['resync', 1, 4, 'E']], l) @@ -1438,8 +1479,14 @@ func Test_efm_error_type() " error type set efm=%f:%l:%t:%m - cexpr ["Xfile1:10:E:msg1", "Xfile1:20:W:msg2", "Xfile1:30:I:msg3", - \ "Xfile1:40:N:msg4", "Xfile1:50:R:msg5"] + let lines =<< trim END + Xfile1:10:E:msg1 + Xfile1:20:W:msg2 + Xfile1:30:I:msg3 + Xfile1:40:N:msg4 + Xfile1:50:R:msg5 + END + cexpr lines let output = split(execute('clist'), "\n") call assert_equal([ \ ' 1 Xfile1:10 error: msg1', @@ -1450,8 +1497,14 @@ func Test_efm_error_type() " error type and a error number set efm=%f:%l:%t:%n:%m - cexpr ["Xfile1:10:E:2:msg1", "Xfile1:20:W:4:msg2", "Xfile1:30:I:6:msg3", - \ "Xfile1:40:N:8:msg4", "Xfile1:50:R:3:msg5"] + let lines =<< trim END + Xfile1:10:E:2:msg1 + Xfile1:20:W:4:msg2 + Xfile1:30:I:6:msg3 + Xfile1:40:N:8:msg4 + Xfile1:50:R:3:msg5 + END + cexpr lines let output = split(execute('clist'), "\n") call assert_equal([ \ ' 1 Xfile1:10 error 2: msg1', @@ -1476,8 +1529,13 @@ func Test_efm_end_lnum_col() " multiple lines set efm=%A%n)%m,%Z%f:%l-%e:%c-%k - cexpr ["1)msg1", "Xfile1:14-24:1-2", - \ "2)msg2", "Xfile1:24-34:3-4"] + let lines =<< trim END + 1)msg1 + Xfile1:14-24:1-2 + 2)msg2 + Xfile1:24-34:3-4 + END + cexpr lines let output = split(execute('clist'), "\n") call assert_equal([ \ ' 1 Xfile1:14-24 col 1-2 error 1: msg1', @@ -1887,12 +1945,12 @@ func Test_cgetfile_on_long_lines() " Problematic values if the line is longer than 4096 bytes. Then 1024 bytes " are read at a time. for len in [4078, 4079, 4080, 5102, 5103, 5104, 6126, 6127, 6128, 7150, 7151, 7152] - let lines = [ - \ '/tmp/file1:1:1:aaa', - \ '/tmp/file2:1:1:%s', - \ '/tmp/file3:1:1:bbb', - \ '/tmp/file4:1:1:ccc', - \ ] + let lines =<< trim END + /tmp/file1:1:1:aaa + /tmp/file2:1:1:%s + /tmp/file3:1:1:bbb + /tmp/file4:1:1:ccc + END let lines[1] = substitute(lines[1], '%s', repeat('x', len), '') call writefile(lines, 'Xcqetfile.txt') cgetfile Xcqetfile.txt @@ -1919,12 +1977,15 @@ func Test_switchbuf() let file1_winid = win_getid() new Xqftestfile2 let file2_winid = win_getid() - cgetexpr ['Xqftestfile1:5:Line5', - \ 'Xqftestfile1:6:Line6', - \ 'Xqftestfile2:10:Line10', - \ 'Xqftestfile2:11:Line11', - \ 'Xqftestfile3:15:Line15', - \ 'Xqftestfile3:16:Line16'] + let lines =<< trim END + Xqftestfile1:5:Line5 + Xqftestfile1:6:Line6 + Xqftestfile2:10:Line10 + Xqftestfile2:11:Line11 + Xqftestfile3:15:Line15 + Xqftestfile3:16:Line16 + END + cgetexpr lines new let winid = win_getid() @@ -2586,21 +2647,23 @@ func Test_Autocmd() silent! cexpr non_existing_func() silent! caddexpr non_existing_func() silent! cgetexpr non_existing_func() - let l = ['precexpr', - \ 'postcexpr', - \ 'precaddexpr', - \ 'postcaddexpr', - \ 'precgetexpr', - \ 'postcgetexpr', - \ 'precexpr', - \ 'postcexpr', - \ 'precaddexpr', - \ 'postcaddexpr', - \ 'precgetexpr', - \ 'postcgetexpr', - \ 'precexpr', - \ 'precaddexpr', - \ 'precgetexpr'] + let l =<< trim END + precexpr + postcexpr + precaddexpr + postcaddexpr + precgetexpr + postcgetexpr + precexpr + postcexpr + precaddexpr + postcaddexpr + precgetexpr + postcgetexpr + precexpr + precaddexpr + precgetexpr + END call assert_equal(l, g:acmds) let g:acmds = [] @@ -2618,15 +2681,17 @@ func Test_Autocmd() exe 'silent! cgetbuffer ' . bnum exe 'silent! caddbuffer ' . bnum enew! - let l = ['precbuffer', - \ 'postcbuffer', - \ 'precgetbuffer', - \ 'postcgetbuffer', - \ 'precaddbuffer', - \ 'postcaddbuffer', - \ 'precbuffer', - \ 'precgetbuffer', - \ 'precaddbuffer'] + let l =<< trim END + precbuffer + postcbuffer + precgetbuffer + postcgetbuffer + precaddbuffer + postcaddbuffer + precbuffer + precgetbuffer + precaddbuffer + END call assert_equal(l, g:acmds) call writefile(['Xtest:1:Line1'], 'Xtest') @@ -2641,24 +2706,26 @@ func Test_Autocmd() silent! cfile do_not_exist silent! caddfile do_not_exist silent! cgetfile do_not_exist - let l = ['precfile', - \ 'postcfile', - \ 'precaddfile', - \ 'postcaddfile', - \ 'precgetfile', - \ 'postcgetfile', - \ 'precfile', - \ 'postcfile', - \ 'precaddfile', - \ 'postcaddfile', - \ 'precgetfile', - \ 'postcgetfile', - \ 'precfile', - \ 'postcfile', - \ 'precaddfile', - \ 'postcaddfile', - \ 'precgetfile', - \ 'postcgetfile'] + let l =<< trim END + precfile + postcfile + precaddfile + postcaddfile + precgetfile + postcgetfile + precfile + postcfile + precaddfile + postcaddfile + precgetfile + postcgetfile + precfile + postcfile + precaddfile + postcaddfile + precgetfile + postcgetfile + END call assert_equal(l, g:acmds) let g:acmds = [] @@ -2671,20 +2738,22 @@ func Test_Autocmd() set makeprg= silent! make set makeprg& - let l = ['prehelpgrep', - \ 'posthelpgrep', - \ 'prehelpgrep', - \ 'posthelpgrep', - \ 'previmgrep', - \ 'postvimgrep', - \ 'previmgrepadd', - \ 'postvimgrepadd', - \ 'previmgrep', - \ 'postvimgrep', - \ 'previmgrepadd', - \ 'postvimgrepadd', - \ 'premake', - \ 'postmake'] + let l =<< trim END + prehelpgrep + posthelpgrep + prehelpgrep + posthelpgrep + previmgrep + postvimgrep + previmgrepadd + postvimgrepadd + previmgrep + postvimgrep + previmgrepadd + postvimgrepadd + premake + postmake + END call assert_equal(l, g:acmds) if has('unix') @@ -2704,22 +2773,24 @@ func Test_Autocmd() silent lgrep Grep_Autocmd_Text test_quickfix.vim silent lgrepadd GrepAdd_Autocmd_Text test_quickfix.vim set grepprg&vim - let l = ['pregrep', - \ 'postgrep', - \ 'pregrepadd', - \ 'postgrepadd', - \ 'pregrep', - \ 'postgrep', - \ 'pregrepadd', - \ 'postgrepadd', - \ 'pregrep', - \ 'postgrep', - \ 'pregrepadd', - \ 'postgrepadd', - \ 'prelgrep', - \ 'postlgrep', - \ 'prelgrepadd', - \ 'postlgrepadd'] + let l =<< trim END + pregrep + postgrep + pregrepadd + postgrepadd + pregrep + postgrep + pregrepadd + postgrepadd + pregrep + postgrep + pregrepadd + postgrepadd + prelgrep + postlgrep + prelgrepadd + postlgrepadd + END call assert_equal(l, g:acmds) endif @@ -2878,11 +2949,11 @@ func Test_cwindow_highlight() CheckScreendump let lines =<< trim END - call setline(1, ['some', 'text', 'with', 'matches']) - write XCwindow - vimgrep e XCwindow - redraw - cwindow 4 + call setline(1, ['some', 'text', 'with', 'matches']) + write XCwindow + vimgrep e XCwindow + redraw + cwindow 4 END call writefile(lines, 'XtestCwindow') let buf = RunVimInTerminal('-S XtestCwindow', #{rows: 12}) @@ -2899,10 +2970,13 @@ endfunc func XvimgrepTests(cchar) call s:setup_commands(a:cchar) - call writefile(['Editor:VIM vim', - \ 'Editor:Emacs EmAcS', - \ 'Editor:Notepad NOTEPAD'], 'Xtestfile1') - call writefile(['Linux', 'MacOS', 'MS-Windows'], 'Xtestfile2') + let lines =<< trim END + Editor:VIM vim + Editor:Emacs EmAcS + Editor:Notepad NOTEPAD + END + call writefile(lines, 'Xtestfile1') + call writefile(['Linux', 'macOS', 'MS-Windows'], 'Xtestfile2') " Error cases call assert_fails('Xvimgrep /abc *', 'E682:') @@ -2916,7 +2990,7 @@ func XvimgrepTests(cchar) Xexpr "" Xvimgrepadd Notepad Xtestfile1 - Xvimgrepadd MacOS Xtestfile2 + Xvimgrepadd macOS Xtestfile2 let l = g:Xgetlist() call assert_equal(2, len(l)) call assert_equal('Editor:Notepad NOTEPAD', l[0].text) @@ -3412,14 +3486,15 @@ func Xmultifilestack_tests(cchar) " error line ends with a file stack. let efm_val = 'Error\ l%l\ in\ %f,' let efm_val .= '%-P%>(%f%r,Error\ l%l\ in\ %m,%-Q)%r' - let l = g:Xgetlist({'lines' : [ - \ '(one.txt', - \ 'Error l4 in one.txt', - \ ') (two.txt', - \ 'Error l6 in two.txt', - \ ')', - \ 'Error l8 in one.txt' - \ ], 'efm' : efm_val}) + let lines =<< trim END + (one.txt + Error l4 in one.txt + ) (two.txt + Error l6 in two.txt + ) + Error l8 in one.txt + END + let l = g:Xgetlist({'lines': lines, 'efm' : efm_val}) call assert_equal(3, len(l.items)) call assert_equal('one.txt', bufname(l.items[0].bufnr)) call assert_equal(4, l.items[0].lnum) @@ -3697,7 +3772,15 @@ func Xqfjump_tests(cchar) call g:Xsetlist([], 'f') setlocal buftype=nofile new - call g:Xsetlist([], ' ', {'lines' : ['F1:1:1:Line1', 'F1:2:2:Line2', 'F2:1:1:Line1', 'F2:2:2:Line2', 'F3:1:1:Line1', 'F3:2:2:Line2']}) + let lines =<< trim END + F1:1:1:Line1 + F1:2:2:Line2 + F2:1:1:Line1 + F2:2:2:Line2 + F3:1:1:Line1 + F3:2:2:Line2 + END + call g:Xsetlist([], ' ', {'lines': lines}) Xopen let winid = win_getid() wincmd p @@ -4929,9 +5012,20 @@ func Xtest_below(cchar) endif " Test for lines with multiple quickfix entries - Xexpr ["X1:5:L5", "X2:5:1:L5_1", "X2:5:2:L5_2", "X2:5:3:L5_3", - \ "X2:10:1:L10_1", "X2:10:2:L10_2", "X2:10:3:L10_3", - \ "X2:15:1:L15_1", "X2:15:2:L15_2", "X2:15:3:L15_3", "X3:3:L3"] + let lines =<< trim END + X1:5:L5 + X2:5:1:L5_1 + X2:5:2:L5_2 + X2:5:3:L5_3 + X2:10:1:L10_1 + X2:10:2:L10_2 + X2:10:3:L10_3 + X2:15:1:L15_1 + X2:15:2:L15_2 + X2:15:3:L15_3 + X3:3:L3 + END + Xexpr lines edit +1 X2 Xbelow 2 call assert_equal(['X2', 10, 1], [@%, line('.'), col('.')]) @@ -4995,33 +5089,32 @@ func Test_cbelow() endfunc func Test_quickfix_count() - let commands = [ - \ 'cNext', - \ 'cNfile', - \ 'cabove', - \ 'cbelow', - \ 'cfirst', - \ 'clast', - \ 'cnewer', - \ 'cnext', - \ 'cnfile', - \ 'colder', - \ 'cprevious', - \ 'crewind', - \ - \ 'lNext', - \ 'lNfile', - \ 'labove', - \ 'lbelow', - \ 'lfirst', - \ 'llast', - \ 'lnewer', - \ 'lnext', - \ 'lnfile', - \ 'lolder', - \ 'lprevious', - \ 'lrewind', - \ ] + let commands =<< trim END + cNext + cNfile + cabove + cbelow + cfirst + clast + cnewer + cnext + cnfile + colder + cprevious + crewind + lNext + lNfile + labove + lbelow + lfirst + llast + lnewer + lnext + lnfile + lolder + lprevious + lrewind + END for cmd in commands call assert_fails('-1' .. cmd, 'E16:') call assert_fails('.' .. cmd, 'E16:') @@ -5662,9 +5755,12 @@ func Test_locationlist_open_in_newtab() %bwipe! - lgetexpr ['Xqftestfile1:5:Line5', - \ 'Xqftestfile2:10:Line10', - \ 'Xqftestfile3:16:Line16'] + let lines =<< trim END + Xqftestfile1:5:Line5 + Xqftestfile2:10:Line10 + Xqftestfile3:16:Line16 + END + lgetexpr lines silent! llast call assert_equal(1, tabpagenr('$')) -- cgit From 288208257c8d6b3c8dcce7ee6c7b6c7bb7bafb27 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Sat, 8 Oct 2022 15:48:07 +0100 Subject: feat(cscope)!: remove --- src/nvim/testdir/test_cscope.vim | 344 --------------------------------------- 1 file changed, 344 deletions(-) delete mode 100644 src/nvim/testdir/test_cscope.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cscope.vim b/src/nvim/testdir/test_cscope.vim deleted file mode 100644 index 76ea35fa10..0000000000 --- a/src/nvim/testdir/test_cscope.vim +++ /dev/null @@ -1,344 +0,0 @@ -" Test for cscope commands. - -source check.vim -CheckFeature cscope -CheckFeature quickfix - -if !executable('cscope') - throw 'Skipped: cscope program missing' -endif - -func CscopeSetupOrClean(setup) - if a:setup - noa sp samples/memfile_test.c - saveas! Xmemfile_test.c - call system('cscope -bk -fXcscope.out Xmemfile_test.c') - call system('cscope -bk -fXcscope2.out Xmemfile_test.c') - cscope add Xcscope.out - set cscopequickfix=s-,g-,d-,c-,t-,e-,f-,i-,a- - else - cscope kill -1 - for file in ['Xcscope.out', 'Xcscope2.out', 'Xmemfile_test.c'] - call delete(file) - endfo - endif -endfunc - -func Test_cscopeWithCscopeConnections() - call CscopeSetupOrClean(1) - " Test: E568: duplicate cscope database not added - try - set nocscopeverbose - cscope add Xcscope.out - set cscopeverbose - catch - call assert_report('exception thrown') - endtry - call assert_fails('cscope add', 'E560') - call assert_fails('cscope add Xcscope.out', 'E568') - call assert_fails('cscope add doesnotexist.out', 'E563') - if has('unix') - call assert_fails('cscope add /dev/null', 'E564:') - endif - - " Test: Find this C-Symbol - for cmd in ['cs find s main', 'cs find 0 main'] - let a = execute(cmd) - " Test where it moves the cursor - call assert_equal('main(void)', getline('.')) - " Test the output of the :cs command - call assert_match('\n(1 of 1): <
> main(void )', a) - endfor - - " Test: Find this definition - for cmd in ['cs find g test_mf_hash', - \ 'cs find 1 test_mf_hash', - \ 'cs find 1 test_mf_hash'] " leading space ignored. - exe cmd - call assert_equal(['', '/*', ' * Test mf_hash_*() functions.', ' */', ' static void', 'test_mf_hash(void)', '{'], getline(line('.')-5, line('.')+1)) - endfor - - " Test: Find functions called by this function - for cmd in ['cs find d test_mf_hash', 'cs find 2 test_mf_hash'] - let a = execute(cmd) - call assert_match('\n(1 of 42): <> mf_hash_init(&ht);', a) - call assert_equal(' mf_hash_init(&ht);', getline('.')) - endfor - - " Test: Find functions calling this function - for cmd in ['cs find c test_mf_hash', 'cs find 3 test_mf_hash'] - let a = execute(cmd) - call assert_match('\n(1 of 1): <
> test_mf_hash();', a) - call assert_equal(' test_mf_hash();', getline('.')) - endfor - - " Test: Find this text string - for cmd in ['cs find t Bram', 'cs find 4 Bram'] - let a = execute(cmd) - call assert_match('(1 of 1): <<>> \* VIM - Vi IMproved^Iby Bram Moolenaar', a) - call assert_equal(' * VIM - Vi IMproved by Bram Moolenaar', getline('.')) - endfor - - " Test: Find this egrep pattern - " test all matches returned by cscope - for cmd in ['cs find e ^\#includ.', 'cs find 6 ^\#includ.'] - let a = execute(cmd) - call assert_match('\n(1 of 3): <<>> #include ', a) - call assert_equal('#include ', getline('.')) - cnext - call assert_equal('#include "main.c"', getline('.')) - cnext - call assert_equal('#include "memfile.c"', getline('.')) - call assert_fails('cnext', 'E553:') - endfor - - " Test: Find the same egrep pattern using lcscope this time. - let a = execute('lcs find e ^\#includ.') - call assert_match('\n(1 of 3): <<>> #include ', a) - call assert_equal('#include ', getline('.')) - lnext - call assert_equal('#include "main.c"', getline('.')) - lnext - call assert_equal('#include "memfile.c"', getline('.')) - call assert_fails('lnext', 'E553:') - - " Test: Find this file - for cmd in ['cs find f Xmemfile_test.c', 'cs find 7 Xmemfile_test.c'] - enew - let a = execute(cmd) - call assert_true(a =~ '"Xmemfile_test.c" \d\+L, \d\+B') - call assert_equal('Xmemfile_test.c', @%) - endfor - - " Test: Find files #including this file - for cmd in ['cs find i assert.h', 'cs find 8 assert.h'] - enew - let a = execute(cmd) - let alines = split(a, '\n', 1) - call assert_equal('', alines[0]) - call assert_true(alines[1] =~ '"Xmemfile_test.c" \d\+L, \d\+B') - call assert_equal('(1 of 1): <> #include ', alines[2]) - call assert_equal('#include ', getline('.')) - endfor - - " Test: Invalid find command - call assert_fails('cs find', 'E560:') - call assert_fails('cs find x', 'E560:') - - if has('float') - " Test: Find places where this symbol is assigned a value - " this needs a cscope >= 15.8 - " unfortunately, Travis has cscope version 15.7 - let cscope_version = systemlist('cscope --version')[0] - let cs_version = str2float(matchstr(cscope_version, '\d\+\(\.\d\+\)\?')) - if cs_version >= 15.8 - for cmd in ['cs find a item', 'cs find 9 item'] - let a = execute(cmd) - call assert_equal(['', '(1 of 4): <> item = (mf_hashitem_T *)lalloc_clear(sizeof(*item), FALSE);'], split(a, '\n', 1)) - call assert_equal(' item = (mf_hashitem_T *)lalloc_clear(sizeof(*item), FALSE);', getline('.')) - cnext - call assert_equal(' item = mf_hash_find(&ht, key);', getline('.')) - cnext - call assert_equal(' item = mf_hash_find(&ht, key);', getline('.')) - cnext - call assert_equal(' item = mf_hash_find(&ht, key);', getline('.')) - endfor - endif - endif - - " Test: leading whitespace is not removed for cscope find text - let a = execute('cscope find t test_mf_hash') - call assert_equal(['', '(1 of 1): <<>> test_mf_hash();'], split(a, '\n', 1)) - call assert_equal(' test_mf_hash();', getline('.')) - - " Test: test with scscope - let a = execute('scs find t Bram') - call assert_match('(1 of 1): <<>> \* VIM - Vi IMproved^Iby Bram Moolenaar', a) - call assert_equal(' * VIM - Vi IMproved by Bram Moolenaar', getline('.')) - - " Test: cscope help - for cmd in ['cs', 'cs help', 'cs xxx'] - let a = execute(cmd) - call assert_match('^cscope commands:\n', a) - call assert_match('\nadd :', a) - call assert_match('\nfind :', a) - call assert_match('\nhelp : Show this message', a) - call assert_match('\nkill : Kill a connection', a) - call assert_match('\nreset: Reinit all connections', a) - call assert_match('\nshow : Show connections', a) - endfor - let a = execute('scscope help') - call assert_match('This cscope command does not support splitting the window\.', a) - - " Test: reset connections - let a = execute('cscope reset') - call assert_match('\nAdded cscope database.*Xcscope.out (#0)', a) - call assert_match('\nAll cscope databases reset', a) - - " Test: cscope show - let a = execute('cscope show') - call assert_match('\n 0 \d\+.*Xcscope.out\s*', a) - - " Test: cstag and 'csto' option - set csto=0 - let a = execute('cstag TEST_COUNT') - call assert_match('(1 of 1): <> #define TEST_COUNT 50000', a) - call assert_equal('#define TEST_COUNT 50000', getline('.')) - call assert_fails('cstag DOES_NOT_EXIST', 'E257:') - set csto=1 - let a = execute('cstag index_to_key') - call assert_match('(1 of 1): <> #define index_to_key(i) ((i) ^ 15167)', a) - call assert_equal('#define index_to_key(i) ((i) ^ 15167)', getline('.')) - call assert_fails('cstag DOES_NOT_EXIST', 'E257:') - call assert_fails('cstag', 'E562:') - let save_tags = &tags - set tags= - call assert_fails('cstag DOES_NOT_EXIST', 'E257:') - let a = execute('cstag index_to_key') - call assert_match('(1 of 1): <> #define index_to_key(i) ((i) ^ 15167)', a) - let &tags = save_tags - - " Test: 'cst' option - set nocst - call assert_fails('tag TEST_COUNT', 'E426:') - set cst - let a = execute('tag TEST_COUNT') - call assert_match('(1 of 1): <> #define TEST_COUNT 50000', a) - call assert_equal('#define TEST_COUNT 50000', getline('.')) - let a = execute('tags') - call assert_match('1 1 TEST_COUNT\s\+\d\+\s\+#define index_to_key', a) - - " Test: 'cscoperelative' - call mkdir('Xcscoperelative') - cd Xcscoperelative - let a = execute('cs find g test_mf_hash') - call assert_notequal('test_mf_hash(void)', getline('.')) - set cscoperelative - let a = execute('cs find g test_mf_hash') - call assert_equal('test_mf_hash(void)', getline('.')) - set nocscoperelative - cd .. - call delete('Xcscoperelative', 'd') - - " Test: E259: no match found - call assert_fails('cscope find g DOES_NOT_EXIST', 'E259:') - - " Test: this should trigger call to cs_print_tags() - " Unclear how to check result though, we just exercise the code. - set cst cscopequickfix=s0 - call feedkeys(":cs find s main\", 't') - - " Test: cscope kill - call assert_fails('cscope kill', 'E560:') - call assert_fails('cscope kill 2', 'E261:') - call assert_fails('cscope kill xxx', 'E261:') - - let a = execute('cscope kill 0') - call assert_match('cscope connection 0 closed', a) - - cscope add Xcscope.out - let a = execute('cscope kill Xcscope.out') - call assert_match('cscope connection Xcscope.out closed', a) - - cscope add Xcscope.out . - let a = execute('cscope kill -1') - call assert_match('cscope connection .*Xcscope.out closed', a) - let a = execute('cscope kill -1') - call assert_equal('', a) - - " Test: 'csprg' option - call assert_equal('cscope', &csprg) - set csprg=doesnotexist - call assert_fails('cscope add Xcscope2.out', 'E609:') - set csprg=cscope - - " Test: multiple cscope connections - cscope add Xcscope.out - cscope add Xcscope2.out . -C - let a = execute('cscope show') - call assert_match('\n 0 \d\+.*Xcscope.out\s*', a) - call assert_match('\n 1 \d\+.*Xcscope2.out\s*\.', a) - - " Test: test Ex command line completion - call feedkeys(":cs \\\"\", 'tx') - call assert_equal('"cs add find help kill reset show', @:) - - call feedkeys(":scs \\\"\", 'tx') - call assert_equal('"scs find', @:) - - call feedkeys(":cs find \\\"\", 'tx') - call assert_equal('"cs find a c d e f g i s t', @:) - - call feedkeys(":cs kill \\\"\", 'tx') - call assert_equal('"cs kill -1 0 1', @:) - - call feedkeys(":cs add Xcscope\\\"\", 'tx') - call assert_equal('"cs add Xcscope.out Xcscope2.out', @:) - - " Test: cscope_connection() - call assert_equal(cscope_connection(), 1) - call assert_equal(cscope_connection(0, 'out'), 1) - call assert_equal(cscope_connection(0, 'xxx'), 1) - - call assert_equal(cscope_connection(1, 'out'), 1) - call assert_equal(cscope_connection(1, 'xxx'), 0) - - call assert_equal(cscope_connection(2, 'out'), 0) - call assert_equal(cscope_connection(2, getcwd() .. '/Xcscope.out', 1), 1) - - call assert_equal(cscope_connection(3, 'xxx', '..'), 0) - call assert_equal(cscope_connection(3, 'out', 'xxx'), 0) - call assert_equal(cscope_connection(3, 'out', '.'), 1) - - call assert_equal(cscope_connection(4, 'out', '.'), 0) - - call assert_equal(cscope_connection(5, 'out'), 0) - call assert_equal(cscope_connection(-1, 'out'), 0) - - call CscopeSetupOrClean(0) -endfunc - -" Test ":cs add {dir}" (add the {dir}/cscope.out database) -func Test_cscope_add_dir() - call mkdir('Xcscopedir', 'p') - - " Cscope doesn't handle symlinks, so this needs to be resolved in case a - " shadow directory is being used. - let memfile = resolve('./samples/memfile_test.c') - call system('cscope -bk -fXcscopedir/cscope.out ' . memfile) - - cs add Xcscopedir - let a = execute('cscope show') - let lines = split(a, "\n", 1) - call assert_equal(3, len(lines)) - call assert_equal(' # pid database name prepend path', lines[0]) - call assert_equal('', lines[1]) - call assert_match('^ 0 \d\+.*Xcscopedir/cscope.out\s\+$', lines[2]) - - cs kill -1 - call delete('Xcscopedir/cscope.out') - call assert_fails('cs add Xcscopedir', 'E563:') - - call delete('Xcscopedir', 'd') -endfunc - -func Test_cscopequickfix() - set cscopequickfix=s-,g-,d+,c-,t+,e-,f0,i-,a- - call assert_equal('s-,g-,d+,c-,t+,e-,f0,i-,a-', &cscopequickfix) - - call assert_fails('set cscopequickfix=x-', 'E474:') - call assert_fails('set cscopequickfix=s', 'E474:') - call assert_fails('set cscopequickfix=s7', 'E474:') - call assert_fails('set cscopequickfix=s-a', 'E474:') -endfunc - -func Test_withoutCscopeConnection() - call assert_equal(cscope_connection(), 0) - - call assert_fails('cscope find s main', 'E567:') - let a = execute('cscope show') - call assert_match('no cscope connections', a) -endfunc - - -" vim: shiftwidth=2 sts=2 expandtab -- cgit From e26b48bde6e116eb288893454d2876cdad2db1f9 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 15 Oct 2022 10:12:25 +0200 Subject: vim-patch:9.0.0752: Rprofile files are not recognized (#20658) Problem: Rprofile files are not recognized. Solution: Recognize Rprofile files as "r". (closes vim/vim#11369) https://github.com/vim/vim/commit/7e120ffccbf81ae8acac28f11fbd5eab79a1630d --- src/nvim/testdir/test_filetype.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index b637f1a16f..7669b3d82a 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -454,7 +454,7 @@ let s:filename_checks = { \ 'ql': ['file.ql', 'file.qll'], \ 'quake': ['anybaseq2/file.cfg', 'anyid1/file.cfg', 'quake3/file.cfg', 'baseq2/file.cfg', 'id1/file.cfg', 'quake1/file.cfg', 'some-baseq2/file.cfg', 'some-id1/file.cfg', 'some-quake1/file.cfg'], \ 'quarto': ['file.qmd'], - \ 'r': ['file.r'], + \ 'r': ['file.r', '.Rprofile', 'Rprofile', 'Rprofile.site'], \ 'radiance': ['file.rad', 'file.mat'], \ 'raku': ['file.pm6', 'file.p6', 'file.t6', 'file.pod6', 'file.raku', 'file.rakumod', 'file.rakudoc', 'file.rakutest'], \ 'raml': ['file.raml'], -- cgit From 6bc2d6b66b683faedded01128af8ad98b7130fef Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 15 Oct 2022 16:10:56 +0800 Subject: vim-patch:9.0.0614: SpellFileMissing autocmd may delete buffer Problem: SpellFileMissing autocmd may delete buffer. Solution: Disallow deleting the current buffer to avoid using freed memory. https://github.com/vim/vim/commit/ef976323e770315b5fca544efb6b2faa25674d15 --- src/nvim/testdir/test_autocmd.vim | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 025bda4515..63ed3ff435 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -2752,6 +2752,16 @@ func Test_FileType_spell() setglobal spellfile= endfunc +" this was wiping out the current buffer and using freed memory +func Test_SpellFileMissing_bwipe() + next 0 + au SpellFileMissing 0 bwipe + call assert_fails('set spell spelllang=0', 'E937:') + + au! SpellFileMissing + bwipe +endfunc + " Test closing a window or editing another buffer from a FileChangedRO handler " in a readonly buffer func Test_FileChangedRO_winclose() -- cgit From a9452cf3d5e2904ff355daf660e8e56bcb2433eb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 15 Oct 2022 16:17:07 +0800 Subject: vim-patch:9.0.0616: spell test fails because error message changed Problem: Spell test fails because error message changed. Solution: Adjust expected error message. https://github.com/vim/vim/commit/371951d0c34d4f44b50ad8bc8d30a4ef7effade6 --- src/nvim/testdir/test_spell.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_spell.vim b/src/nvim/testdir/test_spell.vim index 8ab8204b10..e421d21de1 100644 --- a/src/nvim/testdir/test_spell.vim +++ b/src/nvim/testdir/test_spell.vim @@ -147,7 +147,7 @@ func Test_spell_file_missing() augroup TestSpellFileMissing autocmd! SpellFileMissing * bwipe augroup END - call assert_fails('set spell spelllang=ab_cd', 'E797:') + call assert_fails('set spell spelllang=ab_cd', 'E937:') " clean up augroup TestSpellFileMissing -- cgit From eaac0958256f2fb3b0fa9d20790bc38ed9eb3005 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 15 Oct 2022 19:25:51 +0800 Subject: vim-patch:partial:9.0.0737: Lisp word only recognized when a space follows Problem: Lisp word only recognized when a space follows. Solution: Also match a word at the end of a line. Rename the test. Use a compiled function to avoid backslashes. https://github.com/vim/vim/commit/d26c5805bcbd630dab0478c2d22503a6e32a83c1 Keep the old Test_lisp_indent(). --- src/nvim/testdir/test_alot.vim | 1 - src/nvim/testdir/test_lispindent.vim | 103 +++++++++++++++++++++++++++++++++++ src/nvim/testdir/test_lispwords.vim | 98 --------------------------------- 3 files changed, 103 insertions(+), 99 deletions(-) create mode 100644 src/nvim/testdir/test_lispindent.vim delete mode 100644 src/nvim/testdir/test_lispwords.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim index a83ef50abc..a3d240f27e 100644 --- a/src/nvim/testdir/test_alot.vim +++ b/src/nvim/testdir/test_alot.vim @@ -15,7 +15,6 @@ source test_fnamemodify.vim source test_ga.vim source test_glob2regpat.vim source test_global.vim -source test_lispwords.vim source test_move.vim source test_put.vim source test_reltime.vim diff --git a/src/nvim/testdir/test_lispindent.vim b/src/nvim/testdir/test_lispindent.vim new file mode 100644 index 0000000000..d4cab6d17e --- /dev/null +++ b/src/nvim/testdir/test_lispindent.vim @@ -0,0 +1,103 @@ +" Tests for 'lispwords' settings being global-local. +" And other lisp indent stuff. + +set nocompatible viminfo+=nviminfo + +func Test_global_local_lispwords() + setglobal lispwords=foo,bar,baz + setlocal lispwords-=foo | setlocal lispwords+=quux + call assert_equal('foo,bar,baz', &g:lispwords) + call assert_equal('bar,baz,quux', &l:lispwords) + call assert_equal('bar,baz,quux', &lispwords) + + setlocal lispwords< + call assert_equal('foo,bar,baz', &g:lispwords) + call assert_equal('foo,bar,baz', &l:lispwords) + call assert_equal('foo,bar,baz', &lispwords) +endfunc + +func Test_lisp_indent() + enew! + + call append(0, [ + \ '(defun html-file (base)', + \ '(format nil "~(~A~).html" base))', + \ '', + \ '(defmacro page (name title &rest body)', + \ '(let ((ti (gensym)))', + \ '`(with-open-file (*standard-output*', + \ '(html-file ,name)', + \ ':direction :output', + \ ':if-exists :supersede)', + \ '(let ((,ti ,title))', + \ '(as title ,ti)', + \ '(with center ', + \ '(as h2 (string-upcase ,ti)))', + \ '(brs 3)', + \ ',@body))))', + \ '', + \ ';;; Utilities for generating links', + \ '', + \ '(defmacro with-link (dest &rest body)', + \ '`(progn', + \ '(format t "" (html-file ,dest))', + \ ',@body', + \ '(princ "")))' + \ ]) + call assert_equal(7, lispindent(2)) + call assert_equal(5, 6->lispindent()) + call assert_equal(-1, lispindent(-1)) + + set lisp + set lispwords& + let save_copt = &cpoptions + set cpoptions+=p + normal 1G=G + + call assert_equal([ + \ '(defun html-file (base)', + \ ' (format nil "~(~A~).html" base))', + \ '', + \ '(defmacro page (name title &rest body)', + \ ' (let ((ti (gensym)))', + \ ' `(with-open-file (*standard-output*', + \ ' (html-file ,name)', + \ ' :direction :output', + \ ' :if-exists :supersede)', + \ ' (let ((,ti ,title))', + \ ' (as title ,ti)', + \ ' (with center ', + \ ' (as h2 (string-upcase ,ti)))', + \ ' (brs 3)', + \ ' ,@body))))', + \ '', + \ ';;; Utilities for generating links', + \ '', + \ '(defmacro with-link (dest &rest body)', + \ ' `(progn', + \ ' (format t "" (html-file ,dest))', + \ ' ,@body', + \ ' (princ "")))', + \ '' + \ ], getline(1, "$")) + + enew! + let &cpoptions=save_copt + set nolisp +endfunc + +func Test_lispindent_negative() + " in legacy script there is no error + call assert_equal(-1, lispindent(-1)) +endfunc + +func Test_lisp_indent_works() + " This was reading beyond the end of the line + new + exe "norm a\tü(\=" + set lisp + norm == + bwipe! +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_lispwords.vim b/src/nvim/testdir/test_lispwords.vim deleted file mode 100644 index 4144fb0521..0000000000 --- a/src/nvim/testdir/test_lispwords.vim +++ /dev/null @@ -1,98 +0,0 @@ -" Tests for 'lispwords' settings being global-local. -" And other lisp indent stuff. - -set nocompatible viminfo+=nviminfo - -func Test_global_local_lispwords() - setglobal lispwords=foo,bar,baz - setlocal lispwords-=foo | setlocal lispwords+=quux - call assert_equal('foo,bar,baz', &g:lispwords) - call assert_equal('bar,baz,quux', &l:lispwords) - call assert_equal('bar,baz,quux', &lispwords) - - setlocal lispwords< - call assert_equal('foo,bar,baz', &g:lispwords) - call assert_equal('foo,bar,baz', &l:lispwords) - call assert_equal('foo,bar,baz', &lispwords) -endfunc - -func Test_lisp_indent() - enew! - - call append(0, [ - \ '(defun html-file (base)', - \ '(format nil "~(~A~).html" base))', - \ '', - \ '(defmacro page (name title &rest body)', - \ '(let ((ti (gensym)))', - \ '`(with-open-file (*standard-output*', - \ '(html-file ,name)', - \ ':direction :output', - \ ':if-exists :supersede)', - \ '(let ((,ti ,title))', - \ '(as title ,ti)', - \ '(with center ', - \ '(as h2 (string-upcase ,ti)))', - \ '(brs 3)', - \ ',@body))))', - \ '', - \ ';;; Utilities for generating links', - \ '', - \ '(defmacro with-link (dest &rest body)', - \ '`(progn', - \ '(format t "" (html-file ,dest))', - \ ',@body', - \ '(princ "")))' - \ ]) - call assert_equal(7, lispindent(2)) - call assert_equal(5, 6->lispindent()) - call assert_equal(-1, lispindent(-1)) - - set lisp - set lispwords& - let save_copt = &cpoptions - set cpoptions+=p - normal 1G=G - - call assert_equal([ - \ '(defun html-file (base)', - \ ' (format nil "~(~A~).html" base))', - \ '', - \ '(defmacro page (name title &rest body)', - \ ' (let ((ti (gensym)))', - \ ' `(with-open-file (*standard-output*', - \ ' (html-file ,name)', - \ ' :direction :output', - \ ' :if-exists :supersede)', - \ ' (let ((,ti ,title))', - \ ' (as title ,ti)', - \ ' (with center ', - \ ' (as h2 (string-upcase ,ti)))', - \ ' (brs 3)', - \ ' ,@body))))', - \ '', - \ ';;; Utilities for generating links', - \ '', - \ '(defmacro with-link (dest &rest body)', - \ ' `(progn', - \ ' (format t "" (html-file ,dest))', - \ ' ,@body', - \ ' (princ "")))', - \ '' - \ ], getline(1, "$")) - - enew! - let &cpoptions=save_copt - set nolisp -endfunc - -func Test_lisp_indent_works() - " This was reading beyond the end of the line - new - exe "norm a\tü(\=" - set lisp - norm == - bwipe! -endfunc - -" vim: shiftwidth=2 sts=2 expandtab -- cgit From 32ced1f08fd551770b4f4a0fd69dfe2d36c417b6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 15 Oct 2022 19:42:38 +0800 Subject: vim-patch:9.0.0754: 'indentexpr' overrules lisp indenting in one situation Problem: 'indentexpr' overrules lisp indenting in one situation. Solution: Add "else" to keep the lisp indent. (issue vim/vim#11327) https://github.com/vim/vim/commit/a79b35b5781ae770334cec781d17fec3875f8108 --- src/nvim/testdir/test_lispindent.vim | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_lispindent.vim b/src/nvim/testdir/test_lispindent.vim index d4cab6d17e..8987f67a80 100644 --- a/src/nvim/testdir/test_lispindent.vim +++ b/src/nvim/testdir/test_lispindent.vim @@ -91,6 +91,17 @@ func Test_lispindent_negative() call assert_equal(-1, lispindent(-1)) endfunc +func Test_lispindent_with_indentexpr() + enew + setl ai lisp nocin indentexpr=11 + exe "normal a(x\1\2)\" + let expected = ['(x', ' 1', ' 2)'] + call assert_equal(expected, getline(1, 3)) + normal 1G=G + call assert_equal(expected, getline(1, 3)) + bwipe! +endfunc + func Test_lisp_indent_works() " This was reading beyond the end of the line new -- cgit From bc798dfd8cea9a5f93461e05dcb8409b6d96afc0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 16 Oct 2022 08:01:44 +0800 Subject: vim-patch:9.0.0765: with a Visual block a put command column may go negative (#20676) Problem: With a Visual block a put command column may go negative. Solution: Check that the column does not become negative. https://github.com/vim/vim/commit/36343ae0fb7247e060abfd35fb8e4337b33abb4b --- src/nvim/testdir/test_visual.vim | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_visual.vim b/src/nvim/testdir/test_visual.vim index 65665d36c0..7fb34ec81f 100644 --- a/src/nvim/testdir/test_visual.vim +++ b/src/nvim/testdir/test_visual.vim @@ -474,6 +474,18 @@ func Test_visual_block_put() bw! endfunc +func Test_visual_block_put_invalid() + enew! + behave mswin + norm yy + norm v)Ps/^/ + " this was causing the column to become negative + silent norm ggv)P + + bwipe! + behave xterm +endfunc + " Visual modes (v V CTRL-V) followed by an operator; count; repeating func Test_visual_mode_op() new -- cgit From 19eb7054ff7b1fbc78e56e7f9ed6537b085147bc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 16 Oct 2022 08:06:07 +0800 Subject: vim-patch:9.0.0761: cannot use 'indentexpr' for Lisp indenting Problem: Cannot use 'indentexpr' for Lisp indenting. Solution: Add the 'lispoptions' option. https://github.com/vim/vim/commit/49846fb1a31de99f49d6a7e70efe685197423c84 vim-patch:9.0.0762: build failure Problem: Build failure. Solution: Add missing change. https://github.com/vim/vim/commit/4b082c4bd05f504fda1acaa9d28fca55a2d04857 --- src/nvim/testdir/test_lispindent.vim | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_lispindent.vim b/src/nvim/testdir/test_lispindent.vim index 8987f67a80..2d6060bba3 100644 --- a/src/nvim/testdir/test_lispindent.vim +++ b/src/nvim/testdir/test_lispindent.vim @@ -97,8 +97,23 @@ func Test_lispindent_with_indentexpr() exe "normal a(x\1\2)\" let expected = ['(x', ' 1', ' 2)'] call assert_equal(expected, getline(1, 3)) + " with Lisp indenting the first line is not indented normal 1G=G call assert_equal(expected, getline(1, 3)) + + %del + setl lispoptions=expr:1 indentexpr=5 + exe "normal a(x\1\2)\" + let expected_expr = ['(x', ' 1', ' 2)'] + call assert_equal(expected_expr, getline(1, 3)) + normal 2G2<<=G + call assert_equal(expected_expr, getline(1, 3)) + + setl lispoptions=expr:0 + " with Lisp indenting the first line is not indented + normal 1G3<<=G + call assert_equal(expected, getline(1, 3)) + bwipe! endfunc -- cgit From d44f088834081ee404db4459fdcfba82d14ef157 Mon Sep 17 00:00:00 2001 From: Jonas Strittmatter <40792180+smjonas@users.noreply.github.com> Date: Mon, 17 Oct 2022 08:18:57 +0200 Subject: vim-patch:9.0.0771: cannot always tell the difference beween tex and … (#20687) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit vim-patch:9.0.0771: cannot always tell the difference beween tex and rexx files Problem: Cannot always tell the difference beween tex and rexx files. Solution: Recognize tex by a leading backslash. (Martin Tournoij, closes vim/vim#11380) https://github.com/vim/vim/commit/bd053f894b0d7652928201faa68c53d1ce2acdc5 --- src/nvim/testdir/test_filetype.vim | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 7669b3d82a..1ceab2a67a 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -1768,6 +1768,11 @@ func Test_cls_file() call assert_equal('tex', &filetype) bwipe! + call writefile(['\NeedsTeXFormat{LaTeX2e}'], 'Xfile.cls') + split Xfile.cls + call assert_equal('tex', &filetype) + bwipe! + " Rexx call writefile(['# rexx'], 'Xfile.cls') -- cgit From 042eb74ff1ed63d79f8a642649cd6be6ec4b0eb9 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Mon, 17 Oct 2022 08:52:40 +0200 Subject: feat(runtime)!: remove filetype.vim (#20428) Made obsolete by now graduated `filetype.lua` (enabled by default). Note that changes or additions to the filetype detection still need to be made through a PR to vim/vim as we port the _logic_ as well as tests. --- src/nvim/testdir/test_legacy_filetype.vim | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 src/nvim/testdir/test_legacy_filetype.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_legacy_filetype.vim b/src/nvim/testdir/test_legacy_filetype.vim deleted file mode 100644 index 772faaadb0..0000000000 --- a/src/nvim/testdir/test_legacy_filetype.vim +++ /dev/null @@ -1,4 +0,0 @@ -let g:do_legacy_filetype = 1 -filetype on - -source test_filetype.vim -- cgit From e4273135455084bca54a484f88fd364af62bf69c Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Mon, 17 Oct 2022 18:36:10 +0200 Subject: vim-patch:9.0.0782: OpenVPN files are not recognized (#20702) Problem: OpenVPN files are not recognized. Solution: Add patterns for OpenVPN files. (closes vim/vim#11391) https://github.com/vim/vim/commit/4bf67ec52e938a3edaa4f452adab42a57505f940 --- src/nvim/testdir/test_filetype.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 1ceab2a67a..cecc112635 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -401,6 +401,7 @@ let s:filename_checks = { \ 'opam': ['opam', 'file.opam', 'file.opam.template'], \ 'openroad': ['file.or'], \ 'openscad': ['file.scad'], + \ 'openvpn': ['file.ovpn', '/etc/openvpn/client/client.conf', '/usr/share/openvpn/examples/server.conf'], \ 'opl': ['file.OPL', 'file.OPl', 'file.OpL', 'file.Opl', 'file.oPL', 'file.oPl', 'file.opL', 'file.opl'], \ 'ora': ['file.ora'], \ 'org': ['file.org', 'file.org_archive'], -- cgit From 4d896be681d9b93ebe34cce38a5e787cd0332261 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 18 Oct 2022 20:46:42 +0800 Subject: vim-patch:9.0.0786: user command does not get number from :tab modifier (#20716) Problem: User command does not get number from :tab modifier. Solution: Include the number. (closes vim/vim#11393, closes vim/vim#6901) https://github.com/vim/vim/commit/208567e9d744ef7b89bed1f62e951ae4ee2f6f5f --- src/nvim/testdir/test_usercommands.vim | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_usercommands.vim b/src/nvim/testdir/test_usercommands.vim index 1065dd16e2..12fe39851d 100644 --- a/src/nvim/testdir/test_usercommands.vim +++ b/src/nvim/testdir/test_usercommands.vim @@ -79,6 +79,19 @@ function Test_cmdmods() call assert_equal('silent!', g:mods) tab MyCmd call assert_equal('tab', g:mods) + 0tab MyCmd + call assert_equal('0tab', g:mods) + tab split + tab MyCmd + call assert_equal('tab', g:mods) + 1tab MyCmd + call assert_equal('1tab', g:mods) + tabprev + tab MyCmd + call assert_equal('tab', g:mods) + 2tab MyCmd + call assert_equal('2tab', g:mods) + 2tabclose topleft MyCmd call assert_equal('topleft', g:mods) to MyCmd -- cgit From 228a04070e94ca31884f304f3a8d34e67654025d Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Tue, 18 Oct 2022 20:05:50 +0200 Subject: vim-patch:9.0.0779: lsl and lm3 file extensions are not recognized (#20704) Problem: lsl and lm3 file extensions are not recognized. Solution: Add *.lsl and *.lm3 patterns. (Doug Kearns, closes vim/vim#11384) https://github.com/vim/vim/commit/4ac8e7948cb3e07bc4598ede8b274891d14dfa7c --- src/nvim/testdir/test_filetype.vim | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index cecc112635..c9ec7771f4 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -366,7 +366,7 @@ let s:filename_checks = { \ 'mmp': ['file.mmp'], \ 'modconf': ['/etc/modules.conf', '/etc/modules', '/etc/conf.modules', '/etc/modprobe.file', 'any/etc/conf.modules', 'any/etc/modprobe.file', 'any/etc/modules', 'any/etc/modules.conf'], \ 'modula2': ['file.m2', 'file.mi'], - \ 'modula3': ['file.m3', 'file.mg', 'file.i3', 'file.ig'], + \ 'modula3': ['file.m3', 'file.mg', 'file.i3', 'file.ig', 'file.lm3'], \ 'monk': ['file.isc', 'file.monk', 'file.ssc', 'file.tsc'], \ 'moo': ['file.moo'], \ 'moonscript': ['file.moon'], @@ -1963,4 +1963,36 @@ func Test_inc_file() filetype off endfunc +func Test_lsl_file() + filetype on + + call writefile(['looks like Linden Scripting Language'], 'Xfile.lsl') + split Xfile.lsl + call assert_equal('lsl', &filetype) + bwipe! + + " Test dist#ft#FTlsl() + + let g:filetype_lsl = 'larch' + split Xfile.lsl + call assert_equal('larch', &filetype) + bwipe! + unlet g:filetype_lsl + + " Larch Shared Language + + call writefile(['% larch comment'], 'Xfile.lsl') + split Xfile.lsl + call assert_equal('larch', &filetype) + bwipe! + + call writefile(['foo: trait'], 'Xfile.lsl') + split Xfile.lsl + call assert_equal('larch', &filetype) + bwipe! + + call delete('Xfile.lsl') + filetype off +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 22473672aa1ce005d3841d0838a21cd6c6b721f7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 19 Oct 2022 07:05:54 +0800 Subject: vim-patch:9.0.0788: ModeChanged autocmd not executed when Visual ends with CTRL-C (#20722) Problem: ModeChanged autocmd not executed when Visual mode is ended with CTRL-C. Solution: Do not trigger the autocmd when got_int is set. (closes vim/vim#11394) https://github.com/vim/vim/commit/61c4b04799bf114cadc3bbf212ae8b2ad22a6980 Cherry-pick removal of cmdwin feature check from patch 9.0.0663. --- src/nvim/testdir/test_autocmd.vim | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 63ed3ff435..f98d7d10ab 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -3198,19 +3198,29 @@ func Test_mode_changes() call assert_equal(5, g:nori_to_any) endif - if has('cmdwin') - let g:n_to_c = 0 - au ModeChanged n:c let g:n_to_c += 1 - let g:c_to_n = 0 - au ModeChanged c:n let g:c_to_n += 1 - let g:mode_seq += ['c', 'n', 'c', 'n'] - call feedkeys("q:\\", 'tnix') - call assert_equal(len(g:mode_seq) - 1, g:index) - call assert_equal(2, g:n_to_c) - call assert_equal(2, g:c_to_n) - unlet g:n_to_c - unlet g:c_to_n - endif + let g:n_to_c = 0 + au ModeChanged n:c let g:n_to_c += 1 + let g:c_to_n = 0 + au ModeChanged c:n let g:c_to_n += 1 + let g:mode_seq += ['c', 'n', 'c', 'n'] + call feedkeys("q:\\", 'tnix') + call assert_equal(len(g:mode_seq) - 1, g:index) + call assert_equal(2, g:n_to_c) + call assert_equal(2, g:c_to_n) + unlet g:n_to_c + unlet g:c_to_n + + let g:n_to_v = 0 + au ModeChanged n:v let g:n_to_v += 1 + let g:v_to_n = 0 + au ModeChanged v:n let g:v_to_n += 1 + let g:mode_seq += ['v', 'n'] + call feedkeys("v\", 'tnix') + call assert_equal(len(g:mode_seq) - 1, g:index) + call assert_equal(1, g:n_to_v) + call assert_equal(1, g:v_to_n) + unlet g:n_to_v + unlet g:v_to_n au! ModeChanged delfunc TestMode -- cgit From 66933b45dcff8cc9f323a71583bca3698566abb9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 19 Oct 2022 07:10:22 +0800 Subject: vim-patch:9.0.0789: dummy buffer ends up in a window Problem: Dummy buffer ends up in a window. Solution: Disallow navigating to a dummy buffer. https://github.com/vim/vim/commit/8f3c3c6cd044e3b5bf08dbfa3b3f04bb3f711bad --- src/nvim/testdir/test_autocmd.vim | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index f98d7d10ab..e869353893 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -3269,4 +3269,24 @@ func Test_noname_autocmd() augroup! test_noname_autocmd_group endfunc +func Test_autocmd_split_dummy() + " Autocommand trying to split a window containing a dummy buffer. + auto BufReadPre * exe "sbuf " .. expand("") + " Avoid the "W11" prompt + au FileChangedShell * let v:fcs_choice = 'reload' + func Xautocmd_changelist() + cal writefile(['Xtestfile2:4:4'], 'Xerr') + edit Xerr + lex 'Xtestfile2:4:4' + endfunc + call Xautocmd_changelist() + call assert_fails('call Xautocmd_changelist()', 'E86:') + + au! BufReadPre + au! FileChangedShell + delfunc Xautocmd_changelist + bwipe! Xerr + call delete('Xerr') +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 88eeb4d941a4ae3f75bbf4faae2882786e44f687 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 19 Oct 2022 07:15:08 +0800 Subject: vim-patch:9.0.0790: test for dummy buffer does not always produce the E86 error Problem: Test for dummy buffer does not always produce the E86 error. Solution: Do not check if the error is produced. https://github.com/vim/vim/commit/53c5c9f50ca68d3ed559eebb2c5f7d23f39a768c --- src/nvim/testdir/test_autocmd.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index e869353893..8c15249f97 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -3280,7 +3280,8 @@ func Test_autocmd_split_dummy() lex 'Xtestfile2:4:4' endfunc call Xautocmd_changelist() - call assert_fails('call Xautocmd_changelist()', 'E86:') + " Should get E86, but it doesn't always happen (timing?) + silent! call Xautocmd_changelist() au! BufReadPre au! FileChangedShell -- cgit From a5d893bebdf13c224b363edace4778a75305c909 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 19 Oct 2022 09:24:18 +0800 Subject: revert: "oldtests: wait 200ms on mac for timer test" (#20728) This reverts commit 3bad76008e1c98724eca7d986a6340eff1de8193. --- src/nvim/testdir/test_timers.vim | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index b3a22614b0..4d450e180b 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -46,9 +46,6 @@ endfunc func Test_timer_repeat_many() let g:val = 0 let timer = timer_start(50, 'MyHandler', {'repeat': -1}) - if has('mac') - sleep 200m - endif sleep 200m call timer_stop(timer) call assert_inrange((has('mac') ? 1 : 2), LoadAdjust(5), g:val) -- cgit From fad558b6affd54075654dd55922348f76a95e338 Mon Sep 17 00:00:00 2001 From: ObserverOfTime Date: Wed, 19 Oct 2022 20:08:01 +0300 Subject: vim-patch:9.0.0798: clang format configuration files are not recognized (#20741) Problem: Clang format configuration files are not recognized. Solution: Use yaml for Clang format configuration files. (Marwin Glaser, closes vim/vim#11398) https://github.com/vim/vim/commit/3c708c43908ba44f075bbaa7daf584c6b46d9723 --- src/nvim/testdir/test_filetype.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index c9ec7771f4..44711e3fcc 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -642,7 +642,7 @@ let s:filename_checks = { \ 'xsd': ['file.xsd'], \ 'xslt': ['file.xsl', 'file.xslt'], \ 'yacc': ['file.yy', 'file.yxx', 'file.y++'], - \ 'yaml': ['file.yaml', 'file.yml', '.clang-tidy'], + \ 'yaml': ['file.yaml', 'file.yml', '.clang-format', '.clang-tidy'], \ 'yang': ['file.yang'], \ 'z8a': ['file.z8a'], \ 'zig': ['file.zig'], -- cgit From be0f284ae1c9e986ac47487ce32e39e318a0d194 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 20 Oct 2022 21:50:27 +0800 Subject: vim-patch:partial:8.2.0418: code in eval.c not sufficiently covered by tests Problem: Code in eval.c not sufficiently covered by tests. Solution: Add more tests. (Yegappan Lakshmanan, closes vim/vim#5815) https://github.com/vim/vim/commit/8b633135106dda8605463b780573c45b00c22afe Only port test_expr.vim and the first hunk of test_cmdline.vim. Add missing test from patch 7.4.1755. Cherry-pick test_expr.vim change from patch 8.2.2060. --- src/nvim/testdir/test_cmdline.vim | 29 ----------- src/nvim/testdir/test_expr.vim | 104 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 29 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 3f8e141afa..f37e8be59a 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -349,35 +349,6 @@ func Test_highlight_completion() call assert_equal([], getcompletion('A', 'highlight')) endfunc -func Test_expr_completion() - if !has('cmdline_compl') - return - endif - for cmd in [ - \ 'let a = ', - \ 'const a = ', - \ 'if', - \ 'elseif', - \ 'while', - \ 'for', - \ 'echo', - \ 'echon', - \ 'execute', - \ 'echomsg', - \ 'echoerr', - \ 'call', - \ 'return', - \ 'cexpr', - \ 'caddexpr', - \ 'cgetexpr', - \ 'lexpr', - \ 'laddexpr', - \ 'lgetexpr'] - call feedkeys(":" . cmd . " getl\\\"\", 'xt') - call assert_equal('"' . cmd . ' getline(', getreg(':')) - endfor -endfunc - func Test_getcompletion() if !has('cmdline_compl') return diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 15622cd6fe..8d3fb88541 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -1,5 +1,7 @@ " Tests for expressions. +source check.vim + func Test_equal() let base = {} func base.method() @@ -76,6 +78,17 @@ func Test_strcharpart() call assert_equal('', strcharpart('axb', -2, 2)) call assert_equal('a', strcharpart('axb', -1, 2)) + + call assert_equal('edit', "editor"[-10:3]) +endfunc + +func Test_getreg_empty_list() + call assert_equal('', getreg('x')) + call assert_equal([], getreg('x', 1, 1)) + let x = getreg('x', 1, 1) + let y = x + call add(x, 'foo') + call assert_equal(['foo'], y) endfunc func Test_loop_over_null_list() @@ -529,6 +542,7 @@ func Test_function_with_funcref() call assert_fails("call function('foo()')", 'E475:') call assert_fails("call function('foo()')", 'foo()') + call assert_fails("function('')", 'E129:') endfunc func Test_funcref() @@ -587,3 +601,93 @@ func Test_eval_after_if() if 0 | eval SetVal('a') | endif | call SetVal('b') call assert_equal('b', s:val) endfunc + +" Test for command-line completion of expressions +func Test_expr_completion() + CheckFeature cmdline_compl + for cmd in [ + \ 'let a = ', + \ 'const a = ', + \ 'if', + \ 'elseif', + \ 'while', + \ 'for', + \ 'echo', + \ 'echon', + \ 'execute', + \ 'echomsg', + \ 'echoerr', + \ 'call', + \ 'return', + \ 'cexpr', + \ 'caddexpr', + \ 'cgetexpr', + \ 'lexpr', + \ 'laddexpr', + \ 'lgetexpr'] + call feedkeys(":" . cmd . " getl\\\"\", 'xt') + call assert_equal('"' . cmd . ' getline(', getreg(':')) + endfor + + " completion for the expression register + call feedkeys(":\"\=float2\t\"\\"\", 'xt') + call assert_equal('"float2nr("', @=) + + " completion for window local variables + let w:wvar1 = 10 + let w:wvar2 = 10 + call feedkeys(":echo w:wvar\\\"\", 'xt') + call assert_equal('"echo w:wvar1 w:wvar2', @:) + unlet w:wvar1 w:wvar2 + + " completion for tab local variables + let t:tvar1 = 10 + let t:tvar2 = 10 + call feedkeys(":echo t:tvar\\\"\", 'xt') + call assert_equal('"echo t:tvar1 t:tvar2', @:) + unlet t:tvar1 t:tvar2 + + " completion for variables + let g:tvar1 = 1 + let g:tvar2 = 2 + call feedkeys(":let g:tv\\\"\", 'xt') + call assert_equal('"let g:tvar1 g:tvar2', @:) + " completion for variables after a || + call feedkeys(":echo 1 || g:tv\\\"\", 'xt') + call assert_equal('"echo 1 || g:tvar1 g:tvar2', @:) + + " completion for options + call feedkeys(":echo &compat\\\"\", 'xt') + call assert_equal('"echo &compatible', @:) + call feedkeys(":echo 1 && &compat\\\"\", 'xt') + call assert_equal('"echo 1 && &compatible', @:) + call feedkeys(":echo &g:equala\\\"\", 'xt') + call assert_equal('"echo &g:equalalways', @:) + + " completion for string + call feedkeys(":echo \"Hello\\ World\"\\\"\", 'xt') + call assert_equal("\"echo \"Hello\\ World\"\", @:) + call feedkeys(":echo 'Hello World'\\\"\", 'xt') + call assert_equal("\"echo 'Hello World'\", @:) + + " completion for command after a | + call feedkeys(":echo 'Hello' | cwin\\\"\", 'xt') + call assert_equal("\"echo 'Hello' | cwindow", @:) + + " completion for environment variable + let $X_VIM_TEST_COMPLETE_ENV = 'foo' + call feedkeys(":let $X_VIM_TEST_COMPLETE_E\\\"\", 'tx') + call assert_match('"let $X_VIM_TEST_COMPLETE_ENV', @:) + unlet $X_VIM_TEST_COMPLETE_ENV +endfunc + +" Test for errors in expression evaluation +func Test_expr_eval_error() + call assert_fails("let i = 'abc' . []", 'E730:') + call assert_fails("let l = [] + 10", 'E745:') + call assert_fails("let v = 10 + []", 'E745:') + call assert_fails("let v = 10 / []", 'E745:') + call assert_fails("let v = -{}", 'E728:') +endfunc + +" vim: shiftwidth=2 sts=2 expandtab -- cgit From d1484b58ae877f1423f37092c7bfdacedccfb455 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 20 Oct 2022 22:05:51 +0800 Subject: vim-patch:9.0.0804: crash when trying to divide a number by -1 Problem: Crash when trying to divice the largest negative number by -1. Solution: Handle this case specifically. https://github.com/vim/vim/commit/cdef1cefa2a440911c727558562f83ed9b00e16b --- src/nvim/testdir/test_expr.vim | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 8d3fb88541..c63a969e50 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -602,6 +602,12 @@ func Test_eval_after_if() call assert_equal('b', s:val) endfunc +func Test_divide_by_zero() + " only tests that this doesn't crash, the result is not important + echo 0 / 0 + echo 0 / 0 / -1 +endfunc + " Test for command-line completion of expressions func Test_expr_completion() CheckFeature cmdline_compl -- cgit From 45ae5c6dc5af63957eb2009e0425d91a3cc79d66 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Thu, 20 Oct 2022 22:49:22 +0200 Subject: vim-patch:9.0.0808: jsonnet filetype detection has a typo (#20753) Problem: jsonnet filetype detection has a typo. Solution: Change "libjsonnet" to "libsonnet". (Maxime Brunet, closes vim/vim#11412) https://github.com/vim/vim/commit/6c8bc37a1083d17447156592f6f52da2d40b4855 --- src/nvim/testdir/test_filetype.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 44711e3fcc..3888a384c7 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -291,7 +291,7 @@ let s:filename_checks = { \ 'json': ['file.json', 'file.jsonp', 'file.json-patch', 'file.webmanifest', 'Pipfile.lock', 'file.ipynb', '.babelrc', '.eslintrc', '.prettierrc', '.firebaserc', 'file.slnf'], \ 'json5': ['file.json5'], \ 'jsonc': ['file.jsonc'], - \ 'jsonnet': ['file.jsonnet', 'file.libjsonnet'], + \ 'jsonnet': ['file.jsonnet', 'file.libsonnet'], \ 'jsp': ['file.jsp'], \ 'julia': ['file.jl'], \ 'kconfig': ['Kconfig', 'Kconfig.debug', 'Kconfig.file'], -- cgit From a288b4f21423efb056061e4da3871a4247a7de79 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 21 Oct 2022 06:32:15 +0800 Subject: vim-patch:9.0.0806: 'langmap' works differently when there are modifiers (#20754) Problem: 'langmap' works differently when there are modifiers. Solution: Only apply 'langmap' to a character where modifiers have no effect. (closes vim/vim#11395, closes vim/vim#11404) https://github.com/vim/vim/commit/49660f5139d3fd55326a54eadf6bb31a3ffec2bf --- src/nvim/testdir/test_langmap.vim | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_langmap.vim b/src/nvim/testdir/test_langmap.vim index 4f831aa40b..2284704603 100644 --- a/src/nvim/testdir/test_langmap.vim +++ b/src/nvim/testdir/test_langmap.vim @@ -49,6 +49,41 @@ func Test_langmap() call feedkeys(';', 'tx') call assert_equal(5, col('.')) + set langmap=RL + let g:counter = 0 + nnoremap L;L let g:counter += 1 + nnoremap throw 'This mapping shoud not be triggered' + + " 'langmap' is applied to keys without modifiers when matching a mapping + call feedkeys('R;R', 'tx') + call assert_equal(1, g:counter) + nunmap L;L + unlet g:counter + + delete + call assert_equal('', getline(1)) + undo + call assert_equal('Hello World', getline(1)) + " 'langmap' does not change Ctrl-R to Ctrl-L for consistency + call feedkeys("\<*C-R>", 'tx') + call assert_equal('', getline(1)) + + set langmap=6L + undo + setlocal bufhidden=hide + let oldbuf = bufnr() + enew + call assert_notequal(oldbuf, bufnr()) + " 'langmap' does not change Ctrl-6 to Ctrl-L for consistency + " Ctrl-6 becomes Ctrl-^ after merging the Ctrl modifier + call feedkeys("\<*C-6>", 'tx') + call assert_equal(oldbuf, bufnr()) + setlocal bufhidden& + + nunmap + set langmap& quit! endfunc + +" vim: shiftwidth=2 sts=2 expandtab -- cgit From 837190720310deca0231fc42aa3023957ff79a3a Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Fri, 21 Oct 2022 16:36:43 +0200 Subject: vim-patch:9.0.0814: aws config files are not recognized (#20769) vim-patch:436e5d395fd6 (since upstream tagged the wrong commit) Problem: Aws config files are not recognized. Solution: Use "confini" for aws config files. (Justin M. Keyes, closes vim/vim#11416) https://github.com/vim/vim/commit/436e5d395fd629c8d33b5cf7b373aad007f16851 --- src/nvim/testdir/test_filetype.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 3888a384c7..c6f90604e5 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -122,7 +122,7 @@ let s:filename_checks = { \ 'conaryrecipe': ['file.recipe'], \ 'conf': ['auto.master'], \ 'config': ['configure.in', 'configure.ac', '/etc/hostname.file', 'any/etc/hostname.file'], - \ 'confini': ['/etc/pacman.conf', 'any/etc/pacman.conf', 'mpv.conf'], + \ 'confini': ['/etc/pacman.conf', 'any/etc/pacman.conf', 'mpv.conf', 'any/.aws/config', 'any/.aws/credentials'], \ 'context': ['tex/context/any/file.tex', 'file.mkii', 'file.mkiv', 'file.mkvi', 'file.mkxl', 'file.mklx'], \ 'cook': ['file.cook'], \ 'cpp': ['file.cxx', 'file.c++', 'file.hh', 'file.hxx', 'file.hpp', 'file.ipp', 'file.moc', 'file.tcc', 'file.inl', 'file.tlh'], -- cgit From 1887d8d7d0dd619fa90fe11182c436bc3c71c9d5 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 23 Oct 2022 03:45:39 +0200 Subject: docs: fix typos (#20724) Co-authored-by: Marco Lehmann --- src/nvim/testdir/test_arglist.vim | 2 +- src/nvim/testdir/test_langmap.vim | 2 +- src/nvim/testdir/test_menu.vim | 2 +- src/nvim/testdir/test_quickfix.vim | 2 +- src/nvim/testdir/test_vartabs.vim | 2 +- src/nvim/testdir/test_visual.vim | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_arglist.vim b/src/nvim/testdir/test_arglist.vim index 0fd65e8f5a..443a217143 100644 --- a/src/nvim/testdir/test_arglist.vim +++ b/src/nvim/testdir/test_arglist.vim @@ -550,7 +550,7 @@ func Test_argdo() bwipe Xa.c Xb.c Xc.c endfunc -" Test for quiting Vim with unedited files in the argument list +" Test for quitting Vim with unedited files in the argument list func Test_quit_with_arglist() if !CanRunVimInTerminal() throw 'Skipped: cannot run vim in terminal' diff --git a/src/nvim/testdir/test_langmap.vim b/src/nvim/testdir/test_langmap.vim index 2284704603..aaed77e109 100644 --- a/src/nvim/testdir/test_langmap.vim +++ b/src/nvim/testdir/test_langmap.vim @@ -52,7 +52,7 @@ func Test_langmap() set langmap=RL let g:counter = 0 nnoremap L;L let g:counter += 1 - nnoremap throw 'This mapping shoud not be triggered' + nnoremap throw 'This mapping should not be triggered' " 'langmap' is applied to keys without modifiers when matching a mapping call feedkeys('R;R', 'tx') diff --git a/src/nvim/testdir/test_menu.vim b/src/nvim/testdir/test_menu.vim index db7ec92bf8..2e149ad5a5 100644 --- a/src/nvim/testdir/test_menu.vim +++ b/src/nvim/testdir/test_menu.vim @@ -429,7 +429,7 @@ func Test_menu_special() nunmenu Test.Sign endfunc -" Test for "icon=filname" in a toolbar +" Test for "icon=filename" in a toolbar func Test_menu_icon() CheckFeature toolbar nmenu icon=myicon.xpm Toolbar.Foo :echo "Foo" diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index b0e83b7f5f..dcedfe26a2 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -3251,7 +3251,7 @@ func Test_cclose_in_autocmd() " call test_override('starting', 0) endfunc -" Check that ":file" without an argument is possible even when curbuf is locked +" Check that ":file" without an argument is possible even when "curbuf->b_ro_locked" " is set. func Test_file_from_copen() " Works without argument. diff --git a/src/nvim/testdir/test_vartabs.vim b/src/nvim/testdir/test_vartabs.vim index 0acd7fc1e5..32ad64cda4 100644 --- a/src/nvim/testdir/test_vartabs.vim +++ b/src/nvim/testdir/test_vartabs.vim @@ -97,7 +97,7 @@ func Test_vartabs() .retab! call assert_equal("\t\t\t\tl", getline(1)) - " Test for 'retab' with same vlaues as vts + " Test for 'retab' with same values as vts set ts=8 sts=0 vts=5,3,6,2 vsts= exe "norm! S l" .retab! 5,3,6,2 diff --git a/src/nvim/testdir/test_visual.vim b/src/nvim/testdir/test_visual.vim index 7fb34ec81f..a9c057088d 100644 --- a/src/nvim/testdir/test_visual.vim +++ b/src/nvim/testdir/test_visual.vim @@ -1281,7 +1281,7 @@ func Test_visual_block_with_virtualedit() endfunc func Test_visual_block_ctrl_w_f() - " Emtpy block selected in new buffer should not result in an error. + " Empty block selected in new buffer should not result in an error. au! BufNew foo sil norm f edit foo -- cgit From c5f280c522d77b14e3f138797b6628f50fa80c14 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 24 Oct 2022 13:48:51 +0800 Subject: vim-patch:8.2.0908: crash when changing the function table while listing it Problem: Crash when changing the function table while listing it. Solution: Bail out when the function table changes. (closes vim/vim#6209) https://github.com/vim/vim/commit/3fffa97159a427067b60c80ed4645e168cc5c4bd Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_timers.vim | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index 4d450e180b..771f61442d 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -3,6 +3,7 @@ source check.vim CheckFeature timers +source screendump.vim source shared.vim source term_util.vim source load.vim @@ -408,6 +409,30 @@ func Test_timer_invalid_callback() call assert_fails('call timer_start(0, "0")', 'E921') endfunc +func Test_timer_changing_function_list() + CheckRunVimInTerminal + + " Create a large number of functions. Should get the "more" prompt. + " The typing "G" triggers the timer, which changes the function table. + let lines =<< trim END + for func in map(range(1,99), "'Func' .. v:val") + exe "func " .. func .. "()" + endfunc + endfor + au CmdlineLeave : call timer_start(0, {-> 0}) + END + call writefile(lines, 'XTest_timerchange') + let buf = RunVimInTerminal('-S XTest_timerchange', #{rows: 10}) + call term_sendkeys(buf, ":fu\") + call WaitForAssert({-> assert_match('-- More --', term_getline(buf, 10))}) + call term_sendkeys(buf, "G") + call WaitForAssert({-> assert_match('E454', term_getline(buf, 9))}) + call term_sendkeys(buf, "\") + + call StopVimInTerminal(buf) + call delete('XTest_timerchange') +endfunc + func Test_timer_using_win_execute_undo_sync() let bufnr1 = bufnr() new -- cgit From 3c5b43580163340209aa13c731e5a34ff3c5deb4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 26 Oct 2022 08:42:28 +0800 Subject: vim-patch:8.2.0179: still a few places where range() does not work Problem: Still a few places where range() does not work. Solution: Fix using range() causing problems. https://github.com/vim/vim/commit/b09920203a0f2b202497ef9632f8447f73d0f1fb Code is mostly N/A. Cherry-pick all of Test_range() from patch 8.2.0159. - Use nvim_input() instead of test_feedinput() - Assert a different result from json_encode() - Assert a different error for sign_undefine() Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_functions.vim | 262 ++++++++++++++++++++++++++++++++++++ 1 file changed, 262 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 7ad0cb5884..b9446a7a87 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1915,6 +1915,268 @@ func Test_bufadd_bufload() call delete('XotherName') endfunc +func Test_range() + " destructuring + let [x, y] = range(2) + call assert_equal([0, 1], [x, y]) + + " index + call assert_equal(4, range(1, 10)[3]) + + " add() + call assert_equal([0, 1, 2, 3], add(range(3), 3)) + call assert_equal([0, 1, 2, [0, 1, 2]], add([0, 1, 2], range(3))) + call assert_equal([0, 1, 2, [0, 1, 2]], add(range(3), range(3))) + + " append() + new + call append('.', range(5)) + call assert_equal(['', '0', '1', '2', '3', '4'], getline(1, '$')) + bwipe! + + " appendbufline() + new + call appendbufline(bufnr(''), '.', range(5)) + call assert_equal(['0', '1', '2', '3', '4', ''], getline(1, '$')) + bwipe! + + " call() + func TwoArgs(a, b) + return [a:a, a:b] + endfunc + call assert_equal([0, 1], call('TwoArgs', range(2))) + + " col() + new + call setline(1, ['foo', 'bar']) + call assert_equal(2, col(range(1, 2))) + bwipe! + + " complete() + execute "normal! a\=[complete(col('.'), range(10)), ''][1]\" + " complete_info() + execute "normal! a\=[complete(col('.'), range(10)), ''][1]\\=[complete_info(range(5)), ''][1]\" + + " copy() + call assert_equal([1, 2, 3], copy(range(1, 3))) + + " count() + call assert_equal(0, count(range(0), 3)) + call assert_equal(0, count(range(2), 3)) + call assert_equal(1, count(range(5), 3)) + + " cursor() + new + call setline(1, ['aaa', 'bbb', 'ccc']) + call cursor(range(1, 2)) + call assert_equal([2, 1], [col('.'), line('.')]) + bwipe! + + " deepcopy() + call assert_equal([1, 2, 3], deepcopy(range(1, 3))) + + " empty() + call assert_true(empty(range(0))) + call assert_false(empty(range(2))) + + " execute() + new + call setline(1, ['aaa', 'bbb', 'ccc']) + call execute(range(3)) + call assert_equal(2, line('.')) + bwipe! + + " extend() + call assert_equal([1, 2, 3, 4], extend([1], range(2, 4))) + call assert_equal([1, 2, 3, 4], extend(range(1, 1), range(2, 4))) + call assert_equal([1, 2, 3, 4], extend(range(1, 1), [2, 3, 4])) + + " filter() + call assert_equal([1, 3], filter(range(5), 'v:val % 2')) + + " funcref() + call assert_equal([0, 1], funcref('TwoArgs', range(2))()) + + " function() + call assert_equal([0, 1], function('TwoArgs', range(2))()) + + " garbagecollect() + let thelist = [1, range(2), 3] + let otherlist = range(3) + call test_garbagecollect_now() + + " get() + call assert_equal(4, get(range(1, 10), 3)) + call assert_equal(-1, get(range(1, 10), 42, -1)) + + " index() + call assert_equal(1, index(range(1, 5), 2)) + + " inputlist() + " call test_feedinput("1\") + call nvim_input('1') + call assert_equal(1, inputlist(range(10))) + " call test_feedinput("1\") + call nvim_input('1') + call assert_equal(1, inputlist(range(3, 10))) + + " call assert_equal('[0,1,2,3]', json_encode(range(4))) + call assert_equal('[0, 1, 2, 3]', json_encode(range(4))) + + " insert() + call assert_equal([42, 1, 2, 3, 4, 5], insert(range(1, 5), 42)) + call assert_equal([42, 1, 2, 3, 4, 5], insert(range(1, 5), 42, 0)) + call assert_equal([1, 42, 2, 3, 4, 5], insert(range(1, 5), 42, 1)) + call assert_equal([1, 2, 3, 4, 42, 5], insert(range(1, 5), 42, 4)) + call assert_equal([1, 2, 3, 4, 42, 5], insert(range(1, 5), 42, -1)) + call assert_equal([1, 2, 3, 4, 5, 42], insert(range(1, 5), 42, 5)) + + " join() + call assert_equal('0 1 2 3 4', join(range(5))) + + " len() + call assert_equal(0, len(range(0))) + call assert_equal(2, len(range(2))) + call assert_equal(5, len(range(0, 12, 3))) + call assert_equal(4, len(range(3, 0, -1))) + + " list2str() + call assert_equal('ABC', list2str(range(65, 67))) + + " lock() + let thelist = range(5) + lockvar thelist + + " map() + call assert_equal([0, 2, 4, 6, 8], map(range(5), 'v:val * 2')) + + " match() + call assert_equal(3, match(range(5), 3)) + + " matchaddpos() + highlight MyGreenGroup ctermbg=green guibg=green + call matchaddpos('MyGreenGroup', range(line('.'), line('.'))) + + " matchend() + call assert_equal(4, matchend(range(5), '4')) + call assert_equal(3, matchend(range(1, 5), '4')) + call assert_equal(-1, matchend(range(1, 5), '42')) + + " matchstrpos() + call assert_equal(['4', 4, 0, 1], matchstrpos(range(5), '4')) + call assert_equal(['4', 3, 0, 1], matchstrpos(range(1, 5), '4')) + call assert_equal(['', -1, -1, -1], matchstrpos(range(1, 5), '42')) + + " max() reverse() + call assert_equal(0, max(range(0))) + call assert_equal(0, max(range(10, 9))) + call assert_equal(9, max(range(10))) + call assert_equal(18, max(range(0, 20, 3))) + call assert_equal(20, max(range(20, 0, -3))) + call assert_equal(99999, max(range(100000))) + call assert_equal(99999, max(range(99999, 0, -1))) + call assert_equal(99999, max(reverse(range(100000)))) + call assert_equal(99999, max(reverse(range(99999, 0, -1)))) + + " min() reverse() + call assert_equal(0, min(range(0))) + call assert_equal(0, min(range(10, 9))) + call assert_equal(5, min(range(5, 10))) + call assert_equal(5, min(range(5, 10, 3))) + call assert_equal(2, min(range(20, 0, -3))) + call assert_equal(0, min(range(100000))) + call assert_equal(0, min(range(99999, 0, -1))) + call assert_equal(0, min(reverse(range(100000)))) + call assert_equal(0, min(reverse(range(99999, 0, -1)))) + + " remove() + call assert_equal(1, remove(range(1, 10), 0)) + call assert_equal(2, remove(range(1, 10), 1)) + call assert_equal(9, remove(range(1, 10), 8)) + call assert_equal(10, remove(range(1, 10), 9)) + call assert_equal(10, remove(range(1, 10), -1)) + call assert_equal([3, 4, 5], remove(range(1, 10), 2, 4)) + + " repeat() + call assert_equal([0, 1, 2, 0, 1, 2], repeat(range(3), 2)) + call assert_equal([0, 1, 2], repeat(range(3), 1)) + call assert_equal([], repeat(range(3), 0)) + call assert_equal([], repeat(range(5, 4), 2)) + call assert_equal([], repeat(range(5, 4), 0)) + + " reverse() + call assert_equal([2, 1, 0], reverse(range(3))) + call assert_equal([0, 1, 2, 3], reverse(range(3, 0, -1))) + call assert_equal([9, 8, 7, 6, 5, 4, 3, 2, 1, 0], reverse(range(10))) + call assert_equal([20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10], reverse(range(10, 20))) + call assert_equal([16, 13, 10], reverse(range(10, 18, 3))) + call assert_equal([19, 16, 13, 10], reverse(range(10, 19, 3))) + call assert_equal([19, 16, 13, 10], reverse(range(10, 20, 3))) + call assert_equal([11, 14, 17, 20], reverse(range(20, 10, -3))) + call assert_equal([], reverse(range(0))) + + " TODO: setpos() + " new + " call setline(1, repeat([''], bufnr(''))) + " call setline(bufnr('') + 1, repeat('x', bufnr('') * 2 + 6)) + " call setpos('x', range(bufnr(''), bufnr('') + 3)) + " bwipe! + + " setreg() + call setreg('a', range(3)) + call assert_equal("0\n1\n2\n", getreg('a')) + + " settagstack() + call settagstack(1, #{items : range(4)}) + + " sign_define() + call assert_fails("call sign_define(range(5))", "E715:") + call assert_fails("call sign_placelist(range(5))", "E715:") + + " sign_undefine() + " call assert_fails("call sign_undefine(range(5))", "E908:") + call assert_fails("call sign_undefine(range(5))", "E155:") + + " sign_unplacelist() + call assert_fails("call sign_unplacelist(range(5))", "E715:") + + " sort() + call assert_equal([0, 1, 2, 3, 4, 5], sort(range(5, 0, -1))) + + " 'spellsuggest' + func MySuggest() + return range(3) + endfunc + set spell spellsuggest=expr:MySuggest() + call assert_equal([], spellsuggest('baord', 3)) + set nospell spellsuggest& + + " string() + call assert_equal('[0, 1, 2, 3, 4]', string(range(5))) + + " taglist() with 'tagfunc' + func TagFunc(pattern, flags, info) + return range(10) + endfunc + set tagfunc=TagFunc + call assert_fails("call taglist('asdf')", 'E987:') + set tagfunc= + + " term_start() + if has('terminal') + call assert_fails('call term_start(range(3, 4))', 'E474:') + let g:terminal_ansi_colors = range(16) + call assert_fails('call term_start("ls", #{term_finish: "close"})', 'E475:') + unlet g:terminal_ansi_colors + endif + + " type() + call assert_equal(v:t_list, type(range(5))) + + " uniq() + call assert_equal([0, 1, 2, 3, 4], uniq(range(5))) +endfunc + " Test for the eval() function func Test_eval() call assert_fails("call eval('5 a')", 'E488:') -- cgit From 0aaef07224eb4243c944765cfc6692b08cbe8750 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 26 Oct 2022 08:57:59 +0800 Subject: vim-patch:8.2.0211: test for ANSI colors fails without an "ls" command Problem: Test for ANSI colors fails without an "ls" command. Solution: Use "dir". (Ken Takata, closes vim/vim#5582) https://github.com/vim/vim/commit/94255df057afa0b7dde77612f3274d4440871bd1 Cherry-pick test_functions.vim change from patch 8.2.0186. --- src/nvim/testdir/test_functions.vim | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index b9446a7a87..871aab7ff1 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -2128,7 +2128,7 @@ func Test_range() " settagstack() call settagstack(1, #{items : range(4)}) - + " sign_define() call assert_fails("call sign_define(range(5))", "E715:") call assert_fails("call sign_placelist(range(5))", "E715:") @@ -2161,12 +2161,17 @@ func Test_range() set tagfunc=TagFunc call assert_fails("call taglist('asdf')", 'E987:') set tagfunc= - + " term_start() - if has('terminal') + if has('terminal') && has('termguicolors') call assert_fails('call term_start(range(3, 4))', 'E474:') let g:terminal_ansi_colors = range(16) - call assert_fails('call term_start("ls", #{term_finish: "close"})', 'E475:') + if has('win32') + let cmd = "cmd /c dir" + else + let cmd = "ls" + endif + call assert_fails('call term_start("' .. cmd .. '", #{term_finish: "close"})', 'E475:') unlet g:terminal_ansi_colors endif -- cgit From 0fb08f353948016c8ad6e4a13a9a128208f4dcc5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 26 Oct 2022 13:38:51 +0800 Subject: vim-patch:7.4.1081 Problem: No test for what previously caused a crash. Solution: Add test for unletting errmsg. https://github.com/vim/vim/commit/254b105b755d9736ece5f7f28db92acaf3e7bf76 Use v:errmsg instead of errmsg. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_unlet.vim | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_unlet.vim b/src/nvim/testdir/test_unlet.vim index b02bdaab3b..db064b5e9b 100644 --- a/src/nvim/testdir/test_unlet.vim +++ b/src/nvim/testdir/test_unlet.vim @@ -7,6 +7,12 @@ func Test_read_only() catch call assert_true(v:exception =~ ':E795:') endtry + try + " this caused a crash + unlet v:errmsg + catch + call assert_true(v:exception =~ ':E795:') + endtry endfunc func Test_existing() -- cgit From b4c250d37b7b53312b734f1dae6d9aed3942c563 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 26 Oct 2022 13:40:04 +0800 Subject: vim-patch:7.4.1097 Problem: Looking up the alloc ID for tests fails. Solution: Fix the line computation. Use assert_fails() for unlet test. https://github.com/vim/vim/commit/065ee9aebf9abe08ae8c0dba7d05cbdcc423c8e0 Use v:count and v:errmsg instead of count and errmsg. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_unlet.vim | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_unlet.vim b/src/nvim/testdir/test_unlet.vim index db064b5e9b..873cd066a9 100644 --- a/src/nvim/testdir/test_unlet.vim +++ b/src/nvim/testdir/test_unlet.vim @@ -1,18 +1,9 @@ " Tests for :unlet func Test_read_only() - try - " this caused a crash - unlet v:count - catch - call assert_true(v:exception =~ ':E795:') - endtry - try - " this caused a crash - unlet v:errmsg - catch - call assert_true(v:exception =~ ':E795:') - endtry + " these caused a crash + call assert_fails('unlet v:count', 'E795:') + call assert_fails('unlet v:errmsg', 'E795:') endfunc func Test_existing() @@ -24,11 +15,7 @@ endfunc func Test_not_existing() unlet! does_not_exist - try - unlet does_not_exist - catch - call assert_true(v:exception =~ ':E108:') - endtry + call assert_fails('unlet does_not_exist', 'E108:') endfunc func Test_unlet_fails() -- cgit From d40739843cf9a160587032bf381c440079e5a8ce Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 26 Oct 2022 13:05:33 +0800 Subject: vim-patch:8.2.0401: not enough test coverage for evalvars.c Problem: Not enough test coverage for evalvars.c. Solution: Add more tests. (Yegappan Lakshmanan, closes vim/vim#5804) https://github.com/vim/vim/commit/8dfcce3a78ccb520cc9d09081f998091494c50bf Assert E475 instead of E474 in :redir test because a later patch changed the error number. Comment out the test for :echo with a deeply nested container as Nvim implements :echo very differently. --- src/nvim/testdir/test_cmdline.vim | 42 ++++++++++++++++-- src/nvim/testdir/test_const.vim | 10 +++++ src/nvim/testdir/test_diffmode.vim | 27 ++++++++++++ src/nvim/testdir/test_excmd.vim | 9 ++++ src/nvim/testdir/test_functions.vim | 16 +++---- src/nvim/testdir/test_let.vim | 88 +++++++++++++++++++++++++++++++++++++ src/nvim/testdir/test_listdict.vim | 54 +++++++++++++++++++++++ src/nvim/testdir/test_spell.vim | 29 ++++++++++++ src/nvim/testdir/test_unlet.vim | 3 ++ src/nvim/testdir/test_user_func.vim | 3 ++ src/nvim/testdir/test_vimscript.vim | 3 ++ 11 files changed, 272 insertions(+), 12 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index f37e8be59a..c8b8c88d75 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -1077,6 +1077,40 @@ func Test_cmdline_complete_various() " completion for the expression register call feedkeys(":\"\=float2\t\"\\"\", 'xt') call assert_equal('"float2nr("', @=) + + " completion for :language command with an invalid argument + call feedkeys(":language dummy \t\\"\", 'xt') + call assert_equal("\"language dummy \t", @:) + + " completion for commands after a :global command + call feedkeys(":g/a\\xb/call float2\t\\"\", 'xt') + call assert_equal('"g/a\xb/call float2nr(', @:) + + " completion with ambiguous user defined commands + com TCmd1 echo 'TCmd1' + com TCmd2 echo 'TCmd2' + call feedkeys(":TCmd \t\\"\", 'xt') + call assert_equal('"TCmd ', @:) + delcom TCmd1 + delcom TCmd2 + + " completion after a range followed by a pipe (|) character + call feedkeys(":1,10 | chist\t\\"\", 'xt') + call assert_equal('"1,10 | chistory', @:) + + " completion for window local variables + let w:wvar1 = 10 + let w:wvar2 = 10 + call feedkeys(":echo w:wvar\\\"\", 'xt') + call assert_equal('"echo w:wvar1 w:wvar2', @:) + unlet w:wvar1 w:wvar2 + + " completion for tab local variables + let t:tvar1 = 10 + let t:tvar2 = 10 + call feedkeys(":echo t:tvar\\\"\", 'xt') + call assert_equal('"echo t:tvar1 t:tvar2', @:) + unlet t:tvar1 t:tvar2 endfunc func Test_cmdline_write_alternatefile() @@ -1682,16 +1716,16 @@ func Test_wildmode() " Test for wildmode=longest with 'fileignorecase' set set wildmode=longest set fileignorecase - argadd AA AAA AAAA - call feedkeys(":buffer \t\\"\", 'xt') - call assert_equal('"buffer AA', @:) + argadd AAA AAAA AAAAA + call feedkeys(":buffer a\t\\"\", 'xt') + call assert_equal('"buffer AAA', @:) set fileignorecase& " Test for listing files with wildmode=list set wildmode=list let g:Sline = '' call feedkeys(":b A\t\t\\\"\", 'xt') - call assert_equal('AA AAA AAAA', g:Sline) + call assert_equal('AAA AAAA AAAAA', g:Sline) call assert_equal('"b A', @:) %argdelete diff --git a/src/nvim/testdir/test_const.vim b/src/nvim/testdir/test_const.vim index 0d064617a5..7f19085b16 100644 --- a/src/nvim/testdir/test_const.vim +++ b/src/nvim/testdir/test_const.vim @@ -231,6 +231,14 @@ func Test_const_with_special_variables() call assert_fails('const &filetype = "vim"', 'E996:') call assert_fails('const &l:filetype = "vim"', 'E996:') call assert_fails('const &g:encoding = "utf-8"', 'E996:') + + call assert_fails('const [a, $CONST_FOO] = [369, "abc"]', 'E996:') + call assert_equal(369, a) + call assert_equal(v:null, getenv("CONST_FOO")) + + call assert_fails('const [b; $CONST_FOO] = [246, 2, "abc"]', 'E996:') + call assert_equal(246, b) + call assert_equal(v:null, getenv("CONST_FOO")) endfunc func Test_const_with_eval_name() @@ -274,3 +282,5 @@ func Test_lock_depth_is_2() const d2 = #{a: 0, b: lvar, c: 4} let d2.b[1] = 'd' endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_diffmode.vim b/src/nvim/testdir/test_diffmode.vim index 1cb71664bd..831efdbfc2 100644 --- a/src/nvim/testdir/test_diffmode.vim +++ b/src/nvim/testdir/test_diffmode.vim @@ -1198,6 +1198,33 @@ func Test_diff_maintains_change_mark() delfunc DiffMaintainsChangeMark endfunc +" Test for 'patchexpr' +func Test_patchexpr() + let g:patch_args = [] + func TPatch() + call add(g:patch_args, readfile(v:fname_in)) + call add(g:patch_args, readfile(v:fname_diff)) + call writefile(['output file'], v:fname_out) + endfunc + set patchexpr=TPatch() + + call writefile(['input file'], 'Xinput') + call writefile(['diff file'], 'Xdiff') + %bwipe! + edit Xinput + diffpatch Xdiff + call assert_equal('output file', getline(1)) + call assert_equal('Xinput.new', bufname()) + call assert_equal(2, winnr('$')) + call assert_true(&diff) + + call delete('Xinput') + call delete('Xdiff') + set patchexpr& + delfunc TPatch + %bwipe! +endfunc + func Test_diff_rnu() CheckScreendump diff --git a/src/nvim/testdir/test_excmd.vim b/src/nvim/testdir/test_excmd.vim index 7692d4fc55..acf23fbc3c 100644 --- a/src/nvim/testdir/test_excmd.vim +++ b/src/nvim/testdir/test_excmd.vim @@ -479,12 +479,21 @@ endfunc func Test_redir_cmd() call assert_fails('redir @@', 'E475:') call assert_fails('redir abc', 'E475:') + call assert_fails('redir => 1abc', 'E474:') + call assert_fails('redir => a b', 'E488:') + call assert_fails('redir => abc[1]', 'E475:') + let b=0zFF + call assert_fails('redir =>> b', 'E734:') + unlet b + if has('unix') + " Redirecting to a directory name call mkdir('Xdir') call assert_fails('redir > Xdir', 'E17:') call delete('Xdir', 'd') endif if !has('bsd') + " Redirecting to a read-only file call writefile([], 'Xfile') call setfperm('Xfile', 'r--r--r--') call assert_fails('redir! > Xfile', 'E190:') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 871aab7ff1..27aab6330f 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -804,6 +804,10 @@ func Test_getbufvar() call assert_equal(0, getbufvar(bnr, '&autoindent')) call assert_equal(0, getbufvar(bnr, '&autoindent', 1)) + " Set and get a buffer-local variable + call setbufvar(bnr, 'bufvar_test', ['one', 'two']) + call assert_equal(['one', 'two'], getbufvar(bnr, 'bufvar_test')) + " Open new window with forced option values set fileformats=unix,dos new ++ff=dos ++bin ++enc=iso-8859-2 @@ -1633,6 +1637,10 @@ func Test_func_sandbox() call assert_fails('call Fsandbox()', 'E48:') delfunc Fsandbox + + " From a sandbox try to set a predefined variable (which cannot be modified + " from a sandbox) + call assert_fails('sandbox let v:lnum = 10', 'E794:') endfunc func EditAnotherFile() @@ -2143,14 +2151,6 @@ func Test_range() " sort() call assert_equal([0, 1, 2, 3, 4, 5], sort(range(5, 0, -1))) - " 'spellsuggest' - func MySuggest() - return range(3) - endfunc - set spell spellsuggest=expr:MySuggest() - call assert_equal([], spellsuggest('baord', 3)) - set nospell spellsuggest& - " string() call assert_equal('[0, 1, 2, 3, 4]', string(range(5))) diff --git a/src/nvim/testdir/test_let.vim b/src/nvim/testdir/test_let.vim index 6cb736a38a..009735e004 100644 --- a/src/nvim/testdir/test_let.vim +++ b/src/nvim/testdir/test_let.vim @@ -25,9 +25,62 @@ func Test_let() let s = "\na #1\nb #2" call assert_equal(s, out) + " Test for displaying a string variable + let s = 'vim' + let out = execute('let s') + let s = "\ns vim" + call assert_equal(s, out) + + " Test for displaying a list variable + let l = [1, 2] + let out = execute('let l') + let s = "\nl [1, 2]" + call assert_equal(s, out) + + " Test for displaying a dict variable + let d = {'k' : 'v'} + let out = execute('let d') + let s = "\nd {'k': 'v'}" + call assert_equal(s, out) + + " Test for displaying a function reference variable + let F = function('min') + let out = execute('let F') + let s = "\nF *min()" + call assert_equal(s, out) + let x = 0 if 0 | let x = 1 | endif call assert_equal(0, x) + + " Display a list item using an out of range index + let l = [10] + call assert_fails('let l[1]', 'E684:') + + " List special variable dictionaries + let g:Test_Global_Var = 5 + call assert_match("\nTest_Global_Var #5", execute('let g:')) + unlet g:Test_Global_Var + + let b:Test_Buf_Var = 8 + call assert_match("\nb:Test_Buf_Var #8", execute('let b:')) + unlet b:Test_Buf_Var + + let w:Test_Win_Var = 'foo' + call assert_equal("\nw:Test_Win_Var foo", execute('let w:')) + unlet w:Test_Win_Var + + let t:Test_Tab_Var = 'bar' + call assert_equal("\nt:Test_Tab_Var bar", execute('let t:')) + unlet t:Test_Tab_Var + + let s:Test_Script_Var = [7] + call assert_match("\ns:Test_Script_Var \\[7]", execute('let s:')) + unlet s:Test_Script_Var + + let l:Test_Local_Var = {'k' : 5} + call assert_match("\nl:Test_Local_Var {'k': 5}", execute('let l:')) + call assert_match("v:errors []", execute('let v:')) endfunc func s:set_arg1(a) abort @@ -201,16 +254,45 @@ func Test_let_option_error() let &fillchars = _w endfunc +" Errors with the :let statement func Test_let_errors() let s = 'abcd' call assert_fails('let s[1] = 5', 'E689:') let l = [1, 2, 3] call assert_fails('let l[:] = 5', 'E709:') + + call assert_fails('let x:lnum=5', 'E488:') + call assert_fails('let v:=5', 'E461:') + call assert_fails('let [a]', 'E474:') + call assert_fails('let [a, b] = [', 'E697:') + call assert_fails('let [a, b] = [10, 20', 'E696:') + call assert_fails('let [a, b] = 10', 'E714:') + call assert_fails('let [a, , b] = [10, 20]', 'E475:') + call assert_fails('let [a, b&] = [10, 20]', 'E475:') + call assert_fails('let $ = 10', 'E475:') + call assert_fails('let $FOO[1] = "abc"', 'E18:') + call assert_fails('let &buftype[1] = "nofile"', 'E18:') + let s = "var" + let var = 1 + call assert_fails('let {s}.1 = 2', 'E18:') + + " This test works only when the language is English + if v:lang == "C" || v:lang =~ '^[Ee]n' + call assert_fails('let [a ; b;] = [10, 20]', + \ 'Double ; in list of variables') + endif endfunc func Test_let_heredoc_fails() call assert_fails('let v =<< marker', 'E991:') + try + exe "let v =<< TEXT | abc | TEXT" + call assert_report('No exception thrown') + catch /E488:/ + catch + call assert_report("Caught exception: " .. v:exception) + endtry let text =<< trim END func WrongSyntax() @@ -243,6 +325,10 @@ func Test_let_heredoc_fails() call writefile(text, 'XheredocBadMarker') call assert_fails('source XheredocBadMarker', 'E221:') call delete('XheredocBadMarker') + + call writefile(['let v =<< TEXT', 'abc'], 'XheredocMissingMarker') + call assert_fails('source XheredocMissingMarker', 'E990:') + call delete('XheredocMissingMarker') endfunc func Test_let_heredoc_trim_no_indent_marker() @@ -361,3 +447,5 @@ E END call assert_equal([' x', ' \y', ' z'], [a, b, c]) endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_listdict.vim b/src/nvim/testdir/test_listdict.vim index 9cef6905a5..8c182ee445 100644 --- a/src/nvim/testdir/test_listdict.vim +++ b/src/nvim/testdir/test_listdict.vim @@ -574,6 +574,18 @@ func Test_let_lock_list() unlet l endfunc +" Locking part of the list +func Test_let_lock_list_items() + let l = [1, 2, 3, 4] + lockvar l[2:] + call assert_equal(0, islocked('l[0]')) + call assert_equal(1, islocked('l[2]')) + call assert_equal(1, islocked('l[3]')) + call assert_fails('let l[2] = 10', 'E741:') + call assert_fails('let l[3] = 20', 'E741:') + unlet l +endfunc + " lockvar/islocked() triggering script autoloading func Test_lockvar_script_autoload() let old_rtp = &rtp @@ -870,6 +882,46 @@ func Test_scope_dict() call s:check_scope_dict('v', v:true) endfunc +" Test for deep nesting of lists (> 100) +func Test_deep_nested_list() + let deep_list = [] + let l = deep_list + for i in range(102) + let newlist = [] + call add(l, newlist) + let l = newlist + endfor + call add(l, 102) + + call assert_fails('let m = deepcopy(deep_list)', 'E698:') + call assert_fails('lockvar 110 deep_list', 'E743:') + call assert_fails('unlockvar 110 deep_list', 'E743:') + " Nvim implements :echo very differently + " call assert_fails('let x = execute("echo deep_list")', 'E724:') + call test_garbagecollect_now() + unlet deep_list +endfunc + +" Test for deep nesting of dicts (> 100) +func Test_deep_nested_dict() + let deep_dict = {} + let d = deep_dict + for i in range(102) + let newdict = {} + let d.k = newdict + let d = newdict + endfor + let d.k = 'v' + + call assert_fails('let m = deepcopy(deep_dict)', 'E698:') + call assert_fails('lockvar 110 deep_dict', 'E743:') + call assert_fails('unlockvar 110 deep_dict', 'E743:') + " Nvim implements :echo very differently + " call assert_fails('let x = execute("echo deep_dict")', 'E724:') + call test_garbagecollect_now() + unlet deep_dict +endfunc + " Test for a null list func Test_null_list() let l = v:_null_list @@ -906,3 +958,5 @@ func Test_null_list() call assert_equal(1, islocked('l')) unlockvar l endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_spell.vim b/src/nvim/testdir/test_spell.vim index e421d21de1..4af02d3d31 100644 --- a/src/nvim/testdir/test_spell.vim +++ b/src/nvim/testdir/test_spell.vim @@ -474,6 +474,35 @@ func Test_spellsuggest_option_expr() bwipe! endfunc +" Test for 'spellsuggest' expr errrors +func Test_spellsuggest_expr_errors() + " 'spellsuggest' + func MySuggest() + return range(3) + endfunc + set spell spellsuggest=expr:MySuggest() + call assert_equal([], spellsuggest('baord', 3)) + + " Test for 'spellsuggest' expression returning a non-list value + func! MySuggest2() + return 'good' + endfunc + set spellsuggest=expr:MySuggest2() + call assert_equal([], spellsuggest('baord')) + + " Test for 'spellsuggest' expression returning a list with dict values + func! MySuggest3() + return [[{}, {}]] + endfunc + set spellsuggest=expr:MySuggest3() + call assert_fails("call spellsuggest('baord')", 'E728:') + + set nospell spellsuggest& + delfunc MySuggest + delfunc MySuggest2 + delfunc MySuggest3 +endfunc + func Test_spellsuggest_timeout() set spellsuggest=timeout:30 set spellsuggest=timeout:-123 diff --git a/src/nvim/testdir/test_unlet.vim b/src/nvim/testdir/test_unlet.vim index 873cd066a9..ed80c91277 100644 --- a/src/nvim/testdir/test_unlet.vim +++ b/src/nvim/testdir/test_unlet.vim @@ -20,6 +20,7 @@ endfunc func Test_unlet_fails() call assert_fails('unlet v:["count"]', 'E46:') + call assert_fails('unlet $', 'E475:') endfunc func Test_unlet_env() @@ -55,3 +56,5 @@ func Test_unlet_complete() call feedkeys(":unlet $FOO\t\n", 'tx') call assert_true(!exists('$FOOBAR') || empty($FOOBAR)) endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_user_func.vim b/src/nvim/testdir/test_user_func.vim index c14624f5b4..13a0334cd3 100644 --- a/src/nvim/testdir/test_user_func.vim +++ b/src/nvim/testdir/test_user_func.vim @@ -87,6 +87,9 @@ func Test_user_func() call assert_fails("call extend(g:, {'max': function('min')})", 'E704') call assert_equal(3, max([1, 2, 3])) + " Try to overwrite an user defined function with a function reference + call assert_fails("let Expr1 = function('min')", 'E705:') + " Regression: the first line below used to throw ?E110: Missing ')'? " Second is here just to prove that this line is correct when not skipping " rhs of &&. diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index 3487a028ca..ea3d15915a 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -1542,6 +1542,9 @@ func Test_delfunction_force() endfunc delfunc! Xtest delfunc! Xtest + + " Try deleting the current function + call assert_fails('delfunc Test_delfunction_force', 'E131:') endfunc " Test using bang after user command {{{1 -- cgit From 7b39ce36a4599539cd5cb07dad6bd980d30a3180 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 26 Oct 2022 13:41:43 +0800 Subject: vim-patch:8.2.0418: code in eval.c not sufficiently covered by tests Problem: Code in eval.c not sufficiently covered by tests. Solution: Add more tests. (Yegappan Lakshmanan, closes vim/vim#5815) https://github.com/vim/vim/commit/8b633135106dda8605463b780573c45b00c22afe Nvim does not have v:none, so comment out test for it. --- src/nvim/testdir/test_blob.vim | 1 + src/nvim/testdir/test_cmdline.vim | 26 +++----------------------- src/nvim/testdir/test_functions.vim | 14 ++++++++++++++ src/nvim/testdir/test_lambda.vim | 1 + src/nvim/testdir/test_let.vim | 11 +++++++++++ src/nvim/testdir/test_listdict.vim | 22 ++++++++++++++++++++++ src/nvim/testdir/test_marks.vim | 9 +++++++++ src/nvim/testdir/test_method.vim | 1 + src/nvim/testdir/test_normal.vim | 1 + src/nvim/testdir/test_unlet.vim | 6 ++++++ src/nvim/testdir/test_usercommands.vim | 21 +++++++++++++++++++++ src/nvim/testdir/test_vimscript.vim | 16 ++++++++++++++++ src/nvim/testdir/test_window_cmd.vim | 5 +++++ 13 files changed, 111 insertions(+), 23 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_blob.vim b/src/nvim/testdir/test_blob.vim index 70529c14d5..513877580f 100644 --- a/src/nvim/testdir/test_blob.vim +++ b/src/nvim/testdir/test_blob.vim @@ -88,6 +88,7 @@ func Test_blob_get_range() call assert_equal(0z0011223344, b[:]) call assert_equal(0z0011223344, b[:-1]) call assert_equal(0z, b[5:6]) + call assert_equal(0z0011, b[-10:1]) endfunc func Test_blob_get() diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index c8b8c88d75..00bfadec93 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -854,7 +854,7 @@ func Test_cmdline_complete_bang() endif endfunc -funct Test_cmdline_complete_languages() +func Test_cmdline_complete_languages() let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '') call assert_equal(lang, v:lc_time) @@ -891,10 +891,8 @@ endfunc func Test_cmdline_complete_env_variable() let $X_VIM_TEST_COMPLETE_ENV = 'foo' - call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\\\"\", 'tx') call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:) - unlet $X_VIM_TEST_COMPLETE_ENV endfunc @@ -1074,17 +1072,13 @@ func Test_cmdline_complete_various() call feedkeys(":e `a1b2c\t\\"\", 'xt') call assert_equal('"e `a1b2c', @:) - " completion for the expression register - call feedkeys(":\"\=float2\t\"\\"\", 'xt') - call assert_equal('"float2nr("', @=) - " completion for :language command with an invalid argument call feedkeys(":language dummy \t\\"\", 'xt') call assert_equal("\"language dummy \t", @:) " completion for commands after a :global command - call feedkeys(":g/a\\xb/call float2\t\\"\", 'xt') - call assert_equal('"g/a\xb/call float2nr(', @:) + call feedkeys(":g/a\\xb/clearj\t\\"\", 'xt') + call assert_equal('"g/a\xb/clearjumps', @:) " completion with ambiguous user defined commands com TCmd1 echo 'TCmd1' @@ -1097,20 +1091,6 @@ func Test_cmdline_complete_various() " completion after a range followed by a pipe (|) character call feedkeys(":1,10 | chist\t\\"\", 'xt') call assert_equal('"1,10 | chistory', @:) - - " completion for window local variables - let w:wvar1 = 10 - let w:wvar2 = 10 - call feedkeys(":echo w:wvar\\\"\", 'xt') - call assert_equal('"echo w:wvar1 w:wvar2', @:) - unlet w:wvar1 w:wvar2 - - " completion for tab local variables - let t:tvar1 = 10 - let t:tvar2 = 10 - call feedkeys(":echo t:tvar\\\"\", 'xt') - call assert_equal('"echo t:tvar1 t:tvar2', @:) - unlet t:tvar1 t:tvar2 endfunc func Test_cmdline_write_alternatefile() diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 27aab6330f..7049602d98 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1199,6 +1199,7 @@ func Test_col() norm gg4|mx6|mY2| call assert_equal(2, col('.')) call assert_equal(7, col('$')) + call assert_equal(2, col('v')) call assert_equal(4, col("'x")) call assert_equal(6, col("'Y")) call assert_equal(2, [1, 2]->col()) @@ -1209,6 +1210,19 @@ func Test_col() call assert_equal(0, col([2, '$'])) call assert_equal(0, col([1, 100])) call assert_equal(0, col([1])) + + " test for getting the visual start column + func T() + let g:Vcol = col('v') + return '' + endfunc + let g:Vcol = 0 + xmap T() + exe "normal gg3|ve\" + call assert_equal(3, g:Vcol) + xunmap + delfunc T + bw! endfunc diff --git a/src/nvim/testdir/test_lambda.vim b/src/nvim/testdir/test_lambda.vim index c178c87d3e..997c3dcd3a 100644 --- a/src/nvim/testdir/test_lambda.vim +++ b/src/nvim/testdir/test_lambda.vim @@ -63,6 +63,7 @@ function Test_lambda_fails() call assert_equal(3, {a, b -> a + b}(1, 2)) call assert_fails('echo {a, a -> a + a}(1, 2)', 'E853:') call assert_fails('echo {a, b -> a + b)}(1, 2)', 'E15:') + echo assert_fails('echo 10->{a -> a + 2}', 'E107:') endfunc func Test_not_lambda() diff --git a/src/nvim/testdir/test_let.vim b/src/nvim/testdir/test_let.vim index 009735e004..89cf4b5498 100644 --- a/src/nvim/testdir/test_let.vim +++ b/src/nvim/testdir/test_let.vim @@ -276,6 +276,17 @@ func Test_let_errors() let s = "var" let var = 1 call assert_fails('let {s}.1 = 2', 'E18:') + call assert_fails('let a[1] = 5', 'E121:') + let l = [[1,2]] + call assert_fails('let l[:][0] = [5]', 'E708:') + let d = {'k' : 4} + call assert_fails('let d.# = 5', 'E713:') + call assert_fails('let d.m += 5', 'E734:') + let l = [1, 2] + call assert_fails('let l[2] = 0', 'E684:') + call assert_fails('let l[0:1] = [1, 2, 3]', 'E710:') + call assert_fails('let l[-2:-3] = [3, 4]', 'E684:') + call assert_fails('let l[0:4] = [5, 6]', 'E711:') " This test works only when the language is English if v:lang == "C" || v:lang =~ '^[Ee]n' diff --git a/src/nvim/testdir/test_listdict.vim b/src/nvim/testdir/test_listdict.vim index 8c182ee445..3b5ed27f5e 100644 --- a/src/nvim/testdir/test_listdict.vim +++ b/src/nvim/testdir/test_listdict.vim @@ -31,6 +31,7 @@ func Test_list_slice() call assert_equal([1, 'as''d', [1, 2, function('strlen')]], l[:-2]) call assert_equal([1, 'as''d', [1, 2, function('strlen')], {'a': 1}], l[0:8]) call assert_equal([], l[8:-1]) + call assert_equal([], l[0:-10]) endfunc " List identity @@ -104,6 +105,8 @@ func Test_list_range_assign() let l = [0] let l[:] = [1, 2] call assert_equal([1, 2], l) + let l[-4:-1] = [5, 6] + call assert_equal([5, 6], l) endfunc " Test removing items in list @@ -709,6 +712,12 @@ func Test_listdict_compare() call assert_true(d == d) call assert_false(l != deepcopy(l)) call assert_false(d != deepcopy(d)) + + " comparison errors + call assert_fails('echo [1, 2] =~ {}', 'E691:') + call assert_fails('echo [1, 2] =~ [1, 2]', 'E692:') + call assert_fails('echo {} =~ 5', 'E735:') + call assert_fails('echo {} =~ {}', 'E736:') endfunc " compare complex recursively linked list and dict @@ -922,6 +931,19 @@ func Test_deep_nested_dict() unlet deep_dict endfunc +" List and dict indexing tests +func Test_listdict_index() + call assert_fails('echo function("min")[0]', 'E695:') + call assert_fails('echo v:true[0]', 'E909:') + let d = {'k' : 10} + call assert_fails('echo d.', 'E15:') + call assert_fails('echo d[1:2]', 'E719:') + call assert_fails("let v = [4, 6][{-> 1}]", 'E729:') + call assert_fails("let v = range(5)[2:[]]", 'E730:') + call assert_fails("let v = range(5)[2:{-> 2}(]", 'E116:') + call assert_fails("let v = range(5)[2:3", 'E111:') +endfunc + " Test for a null list func Test_null_list() let l = v:_null_list diff --git a/src/nvim/testdir/test_marks.vim b/src/nvim/testdir/test_marks.vim index 74e63d9d69..054ebf1218 100644 --- a/src/nvim/testdir/test_marks.vim +++ b/src/nvim/testdir/test_marks.vim @@ -91,6 +91,15 @@ func Test_setpos() call assert_equal([0, 1, 21341234, 0], getpos("'a")) call assert_equal(4, virtcol("'a")) + " Test with invalid buffer number, line number and column number + call cursor(2, 2) + call setpos('.', [-1, 1, 1, 0]) + call assert_equal([2, 2], [line('.'), col('.')]) + call setpos('.', [0, -1, 1, 0]) + call assert_equal([2, 2], [line('.'), col('.')]) + call setpos('.', [0, 1, -1, 0]) + call assert_equal([2, 2], [line('.'), col('.')]) + bwipe! call win_gotoid(twowin) bwipe! diff --git a/src/nvim/testdir/test_method.vim b/src/nvim/testdir/test_method.vim index cdf688b857..e035b3ef50 100644 --- a/src/nvim/testdir/test_method.vim +++ b/src/nvim/testdir/test_method.vim @@ -35,6 +35,7 @@ func Test_list_method() call assert_equal(v:t_list, l->type()) call assert_equal([1, 2, 3], [1, 1, 2, 3, 3]->uniq()) call assert_fails('eval l->values()', 'E715:') + call assert_fails('echo []->len', 'E107:') endfunc func Test_dict_method() diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index 4f842189b6..5730085c78 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -514,6 +514,7 @@ func Test_normal10_expand() " Test expand(`=...`) i.e. backticks expression expansion call assert_equal('5', expand('`=2+3`')) + call assert_equal('3.14', expand('`=3.14`')) " clean up bw! diff --git a/src/nvim/testdir/test_unlet.vim b/src/nvim/testdir/test_unlet.vim index ed80c91277..acf98bb1fc 100644 --- a/src/nvim/testdir/test_unlet.vim +++ b/src/nvim/testdir/test_unlet.vim @@ -21,6 +21,12 @@ endfunc func Test_unlet_fails() call assert_fails('unlet v:["count"]', 'E46:') call assert_fails('unlet $', 'E475:') + let v = {} + call assert_fails('unlet v[:]', 'E719:') + let l = [] + call assert_fails("unlet l['k'", 'E111:') + let d = {'k' : 1} + call assert_fails("unlet d.k2", 'E716:') endfunc func Test_unlet_env() diff --git a/src/nvim/testdir/test_usercommands.vim b/src/nvim/testdir/test_usercommands.vim index 12fe39851d..a3070d6517 100644 --- a/src/nvim/testdir/test_usercommands.vim +++ b/src/nvim/testdir/test_usercommands.vim @@ -617,6 +617,27 @@ func Test_command_list() call assert_equal("\nNo user-defined commands found", execute('command')) endfunc +" Test for a custom user completion returning the wrong value type +func Test_usercmd_custom() + func T1(a, c, p) + return "a\nb\n" + endfunc + command -nargs=* -complete=customlist,T1 TCmd1 + call feedkeys(":T1 \\\"\", 'xt') + call assert_equal('"T1 ', @:) + delcommand TCmd1 + delfunc T1 + + func T2(a, c, p) + return ['a', 'b', 'c'] + endfunc + command -nargs=* -complete=customlist,T2 TCmd2 + call feedkeys(":T2 \\\"\", 'xt') + call assert_equal('"T2 ', @:) + delcommand TCmd2 + delfunc T2 +endfunc + func Test_delcommand_buffer() command Global echo 'global' command -buffer OneBuffer echo 'one' diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index ea3d15915a..7a75d0e88a 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -1656,6 +1656,8 @@ func Test_compound_assignment_operators() call assert_equal(4.2, x) call assert_fails('let x %= 0.5', 'E734') call assert_fails('let x .= "f"', 'E734') + let x = !3.14 + call assert_equal(0.0, x) endif " Test for environment variable @@ -1942,6 +1944,20 @@ func Test_sfile_in_function() delfunc Xfunc endfunc +" Test for errors in converting to float from various types {{{1 +func Test_float_conversion_errors() + if has('float') + call assert_fails('let x = 4.0 % 2.0', 'E804') + call assert_fails('echo 1.1[0]', 'E806') + call assert_fails('echo sort([function("min"), 1], "f")', 'E891:') + call assert_fails('echo 3.2 == "vim"', 'E892:') + call assert_fails('echo sort([[], 1], "f")', 'E893:') + call assert_fails('echo sort([{}, 1], "f")', 'E894:') + call assert_fails('echo 3.2 == v:true', 'E362:') + " call assert_fails('echo 3.2 == v:none', 'E907:') + endif +endfunc + func Test_for_over_string() let res = '' for c in 'aéc̀d' diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim index c4ce4d638c..e01993b99c 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -592,6 +592,11 @@ func Test_window_contents() call assert_equal(59, line("w0")) call assert_equal('59 ', s3) + %d + call setline(1, ['one', 'two', 'three']) + call assert_equal(1, line('w0')) + call assert_equal(3, line('w$')) + bwipeout! call test_garbagecollect_now() endfunc -- cgit From a0ade77353f23a41e04ef20064577e14814fb386 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 26 Oct 2022 18:21:52 +0800 Subject: vim-patch:8.2.0162: balloon test fails in the GUI Problem: Balloon test fails in the GUI. Solution: Skip test in the GUI. https://github.com/vim/vim/commit/7d8ea0b24191d64155fcf9e8d2d2eefff91ae549 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_functions.vim | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 7049602d98..50005c6c37 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1320,6 +1320,9 @@ func Test_balloon_show() " This won't do anything but must not crash either. call balloon_show('hi!') + if !has('gui_running') + call balloon_show(range(3)) + endif endfunc func Test_shellescape() -- cgit From 19eca77af434a609d60ea1e3d9594100df74f301 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 26 Oct 2022 18:12:16 +0800 Subject: vim-patch:8.2.0163: test hangs on MS-Windows console Problem: Test hangs on MS-Windows console. Solution: use feedkeys() instead of test_feedinput(). (Ken Takata) https://github.com/vim/vim/commit/272ca95fc3d21ae1e2626a7aec38a6990e88ad6b Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_functions.vim | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 50005c6c37..8b30c53178 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -2038,15 +2038,10 @@ func Test_range() call assert_equal(1, index(range(1, 5), 2)) " inputlist() - " call test_feedinput("1\") - call nvim_input('1') - call assert_equal(1, inputlist(range(10))) - " call test_feedinput("1\") - call nvim_input('1') - call assert_equal(1, inputlist(range(3, 10))) - - " call assert_equal('[0,1,2,3]', json_encode(range(4))) - call assert_equal('[0, 1, 2, 3]', json_encode(range(4))) + call feedkeys(":let result = inputlist(range(10))\1\", 'x') + call assert_equal(1, result) + call feedkeys(":let result = inputlist(range(3, 10))\1\", 'x') + call assert_equal(1, result) " insert() call assert_equal([42, 1, 2, 3, 4, 5], insert(range(1, 5), 42)) @@ -2059,6 +2054,10 @@ func Test_range() " join() call assert_equal('0 1 2 3 4', join(range(5))) + " json_encode() + " call assert_equal('[0,1,2,3]', json_encode(range(4))) + call assert_equal('[0, 1, 2, 3]', json_encode(range(4))) + " len() call assert_equal(0, len(range(0))) call assert_equal(2, len(range(2))) -- cgit From cfccae95844db21aad773c9a8f8b636f53d6c8c4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 26 Oct 2022 19:04:38 +0800 Subject: vim-patch:8.2.0610: some tests are still old style Problem: Some tests are still old style. Solution: Convert to new style tests. (Yegappan Lakshmanan, closes vim/vim#5957) https://github.com/vim/vim/commit/08f4157c5cabc55bcb22f04dd7c717aba40caa34 Fix missing error message when sort() compare function fails. Cherry-pick a line in test_utf8.vim from patch 8.2.0448. Cherry-pick builtin_function() change from patch 8.2.0595. --- src/nvim/testdir/test_blob.vim | 3 ++ src/nvim/testdir/test_expr.vim | 1 + src/nvim/testdir/test_filter_map.vim | 4 ++ src/nvim/testdir/test_functions.vim | 6 +++ src/nvim/testdir/test_listdict.vim | 34 ++++++++++++++- src/nvim/testdir/test_sort.vim | 2 +- src/nvim/testdir/test_syntax.vim | 4 ++ src/nvim/testdir/test_utf8.vim | 6 ++- src/nvim/testdir/test_vimscript.vim | 80 ++++++++++++++++++++++++++++++++++++ 9 files changed, 137 insertions(+), 3 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_blob.vim b/src/nvim/testdir/test_blob.vim index 513877580f..f2b32c06d4 100644 --- a/src/nvim/testdir/test_blob.vim +++ b/src/nvim/testdir/test_blob.vim @@ -314,6 +314,9 @@ func Test_blob_insert() call assert_fails('call insert(b, -1)', 'E475:') call assert_fails('call insert(b, 257)', 'E475:') call assert_fails('call insert(b, 0, [9])', 'E745:') + call assert_fails('call insert(b, 0, -20)', 'E475:') + call assert_fails('call insert(b, 0, 20)', 'E475:') + call assert_fails('call insert(b, [])', 'E745:') call assert_equal(0, insert(v:_null_blob, 0x33)) " Translated from v8.2.3284 diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index c63a969e50..f6e6004a31 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -46,6 +46,7 @@ func Test_dict() call assert_equal('zero', d[0]) call assert_true(has_key(d, '')) call assert_true(has_key(d, 'a')) + call assert_fails("let i = has_key([], 'a')", 'E715:') let d[''] = 'none' let d['a'] = 'aaa' diff --git a/src/nvim/testdir/test_filter_map.vim b/src/nvim/testdir/test_filter_map.vim index 1cd3a2287b..54f6e269e0 100644 --- a/src/nvim/testdir/test_filter_map.vim +++ b/src/nvim/testdir/test_filter_map.vim @@ -86,6 +86,10 @@ func Test_map_filter_fails() call assert_fails('call filter([1], "42 +")', 'E15:') call assert_fails("let l = map('abc', '\"> \" . v:val')", 'E896:') call assert_fails("let l = filter('abc', '\"> \" . v:val')", 'E896:') + call assert_fails("let l = filter([1, 2, 3], '{}')", 'E728:') + call assert_fails("let l = filter({'k' : 10}, '{}')", 'E728:') + call assert_equal(0, map(v:_null_list, '"> " .. v:val')) + call assert_equal(0, map(v:_null_dict, '"> " .. v:val')) endfunc func Test_map_and_modify() diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 8b30c53178..8f2a61e399 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -67,9 +67,11 @@ func Test_len() call assert_equal(2, len('ab')) call assert_equal(0, len([])) + call assert_equal(0, len(v:_null_list)) call assert_equal(2, len([2, 1])) call assert_equal(0, len({})) + call assert_equal(0, len(v:_null_dict)) call assert_equal(2, len({'a': 1, 'b': 2})) " call assert_fails('call len(v:none)', 'E701:') @@ -771,6 +773,9 @@ func Test_append() split only undo + + " Using $ instead of '$' must give an error + call assert_fails("call append($, 'foobar')", 'E116:') endfunc func Test_getbufvar() @@ -2066,6 +2071,7 @@ func Test_range() " list2str() call assert_equal('ABC', list2str(range(65, 67))) + call assert_fails('let s = list2str(5)', 'E474:') " lock() let thelist = range(5) diff --git a/src/nvim/testdir/test_listdict.vim b/src/nvim/testdir/test_listdict.vim index 3b5ed27f5e..d92563a451 100644 --- a/src/nvim/testdir/test_listdict.vim +++ b/src/nvim/testdir/test_listdict.vim @@ -32,6 +32,7 @@ func Test_list_slice() call assert_equal([1, 'as''d', [1, 2, function('strlen')], {'a': 1}], l[0:8]) call assert_equal([], l[8:-1]) call assert_equal([], l[0:-10]) + call assert_equal([], v:_null_list[:2]) endfunc " List identity @@ -169,6 +170,19 @@ func Test_dict() call filter(d, 'v:key =~ ''[ac391]''') call assert_equal({'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}}, d) + " duplicate key + call assert_fails("let d = {'k' : 10, 'k' : 20}", 'E721:') + " missing comma + call assert_fails("let d = {'k' : 10 'k' : 20}", 'E722:') + " missing curly brace + call assert_fails("let d = {'k' : 10,", 'E723:') + " invalid key + call assert_fails('let d = #{++ : 10}', 'E15:') + " wrong type for key + call assert_fails('let d={[] : 10}', 'E730:') + " undefined variable as value + call assert_fails("let d={'k' : i}", 'E121:') + " allow key starting with number at the start, not a curly expression call assert_equal({'1foo': 77}, #{1foo: 77}) @@ -269,7 +283,7 @@ func Test_script_local_dict_func() unlet g:dict endfunc -" Test removing items in la dictionary +" Test removing items in a dictionary func Test_dict_func_remove() let d = {1:'a', 2:'b', 3:'c'} call assert_equal('b', remove(d, 2)) @@ -643,6 +657,11 @@ func Test_reverse_sort_uniq() call assert_fails('call reverse("")', 'E899:') call assert_fails('call uniq([1, 2], {x, y -> []})', 'E882:') + call assert_fails("call sort([1, 2], function('min'), 1)", "E715:") + call assert_fails("call sort([1, 2], function('invalid_func'))", "E700:") + call assert_fails("call sort([1, 2], function('min'))", "E702:") + call assert_equal(0, sort(v:_null_list)) + call assert_equal(0, uniq(v:_null_list)) endfunc " reduce a list or a blob @@ -942,6 +961,9 @@ func Test_listdict_index() call assert_fails("let v = range(5)[2:[]]", 'E730:') call assert_fails("let v = range(5)[2:{-> 2}(]", 'E116:') call assert_fails("let v = range(5)[2:3", 'E111:') + call assert_fails("let l = insert([1,2,3], 4, 10)", 'E684:') + call assert_fails("let l = insert([1,2,3], 4, -10)", 'E684:') + call assert_fails("let l = insert([1,2,3], 4, [])", 'E745:') endfunc " Test for a null list @@ -981,4 +1003,14 @@ func Test_null_list() unlockvar l endfunc +" Test for a null dict +func Test_null_dict() + call assert_equal(0, items(v:_null_dict)) + call assert_equal(0, keys(v:_null_dict)) + call assert_equal(0, values(v:_null_dict)) + call assert_false(has_key(v:_null_dict, 'k')) + call assert_fails("let l = [] + v:_null_list", 'E15:') + call assert_fails("let l = v:_null_list + []", 'E15:') +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_sort.vim b/src/nvim/testdir/test_sort.vim index 9895ad754c..c3e7788164 100644 --- a/src/nvim/testdir/test_sort.vim +++ b/src/nvim/testdir/test_sort.vim @@ -80,7 +80,7 @@ func Test_sort_default() call assert_equal(['2', 'A', 'AA', 'a', 1, 3.3], sort([3.3, 1, "2", "A", "a", "AA"], '')) call assert_equal(['2', 'A', 'AA', 'a', 1, 3.3], sort([3.3, 1, "2", "A", "a", "AA"], 0)) call assert_equal(['2', 'A', 'a', 'AA', 1, 3.3], sort([3.3, 1, "2", "A", "a", "AA"], 1)) - call assert_fails('call sort([3.3, 1, "2"], 3)', "E474") + call assert_fails('call sort([3.3, 1, "2"], 3)', "E474:") endfunc " Tests for the ":sort" command. diff --git a/src/nvim/testdir/test_syntax.vim b/src/nvim/testdir/test_syntax.vim index ccff01486e..9b4293764d 100644 --- a/src/nvim/testdir/test_syntax.vim +++ b/src/nvim/testdir/test_syntax.vim @@ -171,6 +171,10 @@ func Test_syntax_list() let a = execute('syntax list') call assert_equal("\nNo Syntax items defined for this buffer", a) + syntax keyword Type int containedin=g1 skipwhite skipempty skipnl nextgroup=Abc + let exp = "Type xxx containedin=g1 nextgroup=Abc skipnl skipwhite skipempty int" + call assert_equal(exp, split(execute("syntax list"), "\n")[1]) + bd endfunc diff --git a/src/nvim/testdir/test_utf8.vim b/src/nvim/testdir/test_utf8.vim index ab3503c282..7145d303cc 100644 --- a/src/nvim/testdir/test_utf8.vim +++ b/src/nvim/testdir/test_utf8.vim @@ -131,9 +131,13 @@ func Test_list2str_str2list_latin1() let save_encoding = &encoding " set encoding=latin1 - + let lres = str2list(s, 1) let sres = list2str(l, 1) + call assert_equal([65, 66, 67], str2list("ABC")) + + " Try converting a list to a string in latin-1 encoding + call assert_equal([1, 2, 3], str2list(list2str([1, 2, 3]))) let &encoding = save_encoding call assert_equal(l, lres) diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index 7a75d0e88a..3d3f0a8839 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -1958,6 +1958,86 @@ func Test_float_conversion_errors() endif endfunc +func Test_invalid_function_names() + " function name not starting with capital + let caught_e128 = 0 + try + func! g:test() + echo "test" + endfunc + catch /E128:/ + let caught_e128 = 1 + endtry + call assert_equal(1, caught_e128) + + " function name includes a colon + let caught_e884 = 0 + try + func! b:test() + echo "test" + endfunc + catch /E884:/ + let caught_e884 = 1 + endtry + call assert_equal(1, caught_e884) + + " function name folowed by # + let caught_e128 = 0 + try + func! test2() "# + echo "test2" + endfunc + catch /E128:/ + let caught_e128 = 1 + endtry + call assert_equal(1, caught_e128) + + " function name starting with/without "g:", buffer-local funcref. + function! g:Foo(n) + return 'called Foo(' . a:n . ')' + endfunction + let b:my_func = function('Foo') + call assert_equal('called Foo(1)', b:my_func(1)) + call assert_equal('called Foo(2)', g:Foo(2)) + call assert_equal('called Foo(3)', Foo(3)) + delfunc g:Foo + + " script-local function used in Funcref must exist. + let lines =<< trim END + func s:Testje() + return "foo" + endfunc + let Bar = function('s:Testje') + call assert_equal(0, exists('s:Testje')) + call assert_equal(1, exists('*s:Testje')) + call assert_equal(1, exists('Bar')) + call assert_equal(1, exists('*Bar')) + END + call writefile(lines, 'Xscript') + source Xscript + call delete('Xscript') +endfunc + +" substring and variable name +func Test_substring_var() + let str = 'abcdef' + let n = 3 + call assert_equal('def', str[n:]) + call assert_equal('abcd', str[:n]) + call assert_equal('d', str[n:n]) + unlet n + let nn = 3 + call assert_equal('def', str[nn:]) + call assert_equal('abcd', str[:nn]) + call assert_equal('d', str[nn:nn]) + unlet nn + let b:nn = 4 + call assert_equal('ef', str[b:nn:]) + call assert_equal('abcde', str[:b:nn]) + call assert_equal('e', str[b:nn:b:nn]) + unlet b:nn +endfunc + func Test_for_over_string() let res = '' for c in 'aéc̀d' -- cgit From ef363ed37cdf5c460cca840aebc825011e0294ee Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 26 Oct 2022 19:53:54 +0800 Subject: vim-patch:8.2.0619: null dict is not handled like an empty dict Problem: Null dict is not handled like an empty dict. Solution: Fix the code and add tests. (Yegappan Lakshmanan, closes vim/vim#5968) https://github.com/vim/vim/commit/ea04a6e8baff2f27da7cdd54bf70a5525994f76d Nvim doesn't support modifying NULL list, so comment out a line. --- src/nvim/testdir/test_blob.vim | 1 + src/nvim/testdir/test_expr.vim | 7 ----- src/nvim/testdir/test_filter_map.vim | 1 + src/nvim/testdir/test_let.vim | 3 +++ src/nvim/testdir/test_listdict.vim | 47 ++++++++++++++++++++++++++-------- src/nvim/testdir/test_unlet.vim | 1 + src/nvim/testdir/test_usercommands.vim | 10 ++++---- src/nvim/testdir/test_vimscript.vim | 17 ++++++++++++ 8 files changed, 65 insertions(+), 22 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_blob.vim b/src/nvim/testdir/test_blob.vim index f2b32c06d4..c5a217f36f 100644 --- a/src/nvim/testdir/test_blob.vim +++ b/src/nvim/testdir/test_blob.vim @@ -209,6 +209,7 @@ func Test_blob_add() call assert_equal(0z001122, b) call add(b, '51') call assert_equal(0z00112233, b) + call assert_equal(1, add(v:_null_blob, 0x22)) call assert_fails('call add(b, [9])', 'E745:') call assert_fails('call add("", 0x01)', 'E897:') diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index f6e6004a31..66660ab75e 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -99,13 +99,6 @@ func Test_loop_over_null_list() endfor endfunc -func Test_compare_null_dict() - call assert_fails('let x = v:_null_dict[10]') - call assert_equal({}, {}) - call assert_equal(v:_null_dict, v:_null_dict) - call assert_notequal({}, v:_null_dict) -endfunc - func Test_set_reg_null_list() call setreg('x', v:_null_list) endfunc diff --git a/src/nvim/testdir/test_filter_map.vim b/src/nvim/testdir/test_filter_map.vim index 54f6e269e0..ebcb6699c6 100644 --- a/src/nvim/testdir/test_filter_map.vim +++ b/src/nvim/testdir/test_filter_map.vim @@ -88,6 +88,7 @@ func Test_map_filter_fails() call assert_fails("let l = filter('abc', '\"> \" . v:val')", 'E896:') call assert_fails("let l = filter([1, 2, 3], '{}')", 'E728:') call assert_fails("let l = filter({'k' : 10}, '{}')", 'E728:') + call assert_fails("let l = filter([1, 2], {})", 'E731:') call assert_equal(0, map(v:_null_list, '"> " .. v:val')) call assert_equal(0, map(v:_null_dict, '"> " .. v:val')) endfunc diff --git a/src/nvim/testdir/test_let.vim b/src/nvim/testdir/test_let.vim index 89cf4b5498..937076aa2a 100644 --- a/src/nvim/testdir/test_let.vim +++ b/src/nvim/testdir/test_let.vim @@ -275,6 +275,7 @@ func Test_let_errors() call assert_fails('let &buftype[1] = "nofile"', 'E18:') let s = "var" let var = 1 + call assert_fails('let var += [1,2]', 'E734:') call assert_fails('let {s}.1 = 2', 'E18:') call assert_fails('let a[1] = 5', 'E121:') let l = [[1,2]] @@ -287,6 +288,8 @@ func Test_let_errors() call assert_fails('let l[0:1] = [1, 2, 3]', 'E710:') call assert_fails('let l[-2:-3] = [3, 4]', 'E684:') call assert_fails('let l[0:4] = [5, 6]', 'E711:') + call assert_fails('let g:["a;b"] = 10', 'E461:') + call assert_fails('let g:.min = function("max")', 'E704:') " This test works only when the language is English if v:lang == "C" || v:lang =~ '^[Ee]n' diff --git a/src/nvim/testdir/test_listdict.vim b/src/nvim/testdir/test_listdict.vim index d92563a451..f7261b2055 100644 --- a/src/nvim/testdir/test_listdict.vim +++ b/src/nvim/testdir/test_listdict.vim @@ -32,7 +32,11 @@ func Test_list_slice() call assert_equal([1, 'as''d', [1, 2, function('strlen')], {'a': 1}], l[0:8]) call assert_equal([], l[8:-1]) call assert_equal([], l[0:-10]) - call assert_equal([], v:_null_list[:2]) + " perform an operation on a list slice + let l = [1, 2, 3] + let l[:1] += [1, 2] + let l[2:] -= [1] + call assert_equal([2, 4, 2], l) endfunc " List identity @@ -147,6 +151,20 @@ func Test_list_func_remove() call assert_fails("call remove(l, l)", 'E745:') endfunc +" List add() function +func Test_list_add() + let l = [] + call add(l, 1) + call add(l, [2, 3]) + call add(l, []) + call add(l, v:_null_list) + call add(l, {'k' : 3}) + call add(l, {}) + call add(l, v:_null_dict) + call assert_equal([1, [2, 3], [], [], {'k' : 3}, {}, {}], l) + " call assert_equal(1, add(v:_null_list, 4)) +endfunc + " Tests for Dictionary type func Test_dict() @@ -660,8 +678,6 @@ func Test_reverse_sort_uniq() call assert_fails("call sort([1, 2], function('min'), 1)", "E715:") call assert_fails("call sort([1, 2], function('invalid_func'))", "E700:") call assert_fails("call sort([1, 2], function('min'))", "E702:") - call assert_equal(0, sort(v:_null_list)) - call assert_equal(0, uniq(v:_null_list)) endfunc " reduce a list or a blob @@ -709,7 +725,7 @@ func Test_reduce() call assert_equal(42, reduce(v:_null_blob, function('add'), 42)) endfunc -" splitting a string to a List +" splitting a string to a List using split() func Test_str_split() call assert_equal(['aa', 'bb'], split(' aa bb ')) call assert_equal(['aa', 'bb'], split(' aa bb ', '\W\+', 0)) @@ -964,6 +980,11 @@ func Test_listdict_index() call assert_fails("let l = insert([1,2,3], 4, 10)", 'E684:') call assert_fails("let l = insert([1,2,3], 4, -10)", 'E684:') call assert_fails("let l = insert([1,2,3], 4, [])", 'E745:') + let l = [1, 2, 3] + call assert_fails("let l[i] = 3", 'E121:') + call assert_fails("let l[1.1] = 4", 'E806:') + call assert_fails("let l[:i] = [4, 5]", 'E121:') + call assert_fails("let l[:3.2] = [4, 5]", 'E806:') endfunc " Test for a null list @@ -1005,12 +1026,18 @@ endfunc " Test for a null dict func Test_null_dict() - call assert_equal(0, items(v:_null_dict)) - call assert_equal(0, keys(v:_null_dict)) - call assert_equal(0, values(v:_null_dict)) - call assert_false(has_key(v:_null_dict, 'k')) - call assert_fails("let l = [] + v:_null_list", 'E15:') - call assert_fails("let l = v:_null_list + []", 'E15:') + call assert_equal(v:_null_dict, v:_null_dict) + let d = v:_null_dict + call assert_equal({}, d) + call assert_equal(0, len(d)) + call assert_equal(1, empty(d)) + call assert_equal(0, items(d)) + call assert_equal(0, keys(d)) + call assert_equal(0, values(d)) + call assert_false(has_key(d, 'k')) + call assert_equal('{}', string(d)) + call assert_fails('let x = v:_null_dict[10]') + call assert_equal({}, {}) endfunc " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_unlet.vim b/src/nvim/testdir/test_unlet.vim index acf98bb1fc..4779d17906 100644 --- a/src/nvim/testdir/test_unlet.vim +++ b/src/nvim/testdir/test_unlet.vim @@ -27,6 +27,7 @@ func Test_unlet_fails() call assert_fails("unlet l['k'", 'E111:') let d = {'k' : 1} call assert_fails("unlet d.k2", 'E716:') + call assert_fails("unlet {a};", 'E488:') endfunc func Test_unlet_env() diff --git a/src/nvim/testdir/test_usercommands.vim b/src/nvim/testdir/test_usercommands.vim index a3070d6517..5b8b384bae 100644 --- a/src/nvim/testdir/test_usercommands.vim +++ b/src/nvim/testdir/test_usercommands.vim @@ -623,17 +623,17 @@ func Test_usercmd_custom() return "a\nb\n" endfunc command -nargs=* -complete=customlist,T1 TCmd1 - call feedkeys(":T1 \\\"\", 'xt') - call assert_equal('"T1 ', @:) + call feedkeys(":TCmd1 \\\"\", 'xt') + call assert_equal('"TCmd1 ', @:) delcommand TCmd1 delfunc T1 func T2(a, c, p) - return ['a', 'b', 'c'] + return {} endfunc command -nargs=* -complete=customlist,T2 TCmd2 - call feedkeys(":T2 \\\"\", 'xt') - call assert_equal('"T2 ', @:) + call feedkeys(":TCmd2 \\\"\", 'xt') + call assert_equal('"TCmd2 ', @:) delcommand TCmd2 delfunc T2 endfunc diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index 3d3f0a8839..a9fd7a4bef 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -1658,6 +1658,20 @@ func Test_compound_assignment_operators() call assert_fails('let x .= "f"', 'E734') let x = !3.14 call assert_equal(0.0, x) + + " integer and float operations + let x = 1 + let x *= 2.1 + call assert_equal(2.1, x) + let x = 1 + let x /= 0.25 + call assert_equal(4.0, x) + let x = 1 + call assert_fails('let x %= 0.25', 'E734:') + let x = 1 + call assert_fails('let x .= 0.25', 'E734:') + let x = 1.0 + call assert_fails('let x += [1.1]', 'E734:') endif " Test for environment variable @@ -1839,6 +1853,9 @@ func Test_missing_end() " Missing 'in' in a :for statement call assert_fails('for i range(1) | endfor', 'E690:') + + " Incorrect number of variables in for + call assert_fails('for [i,] in range(3) | endfor', 'E475:') endfunc " Test for deep nesting of if/for/while/try statements {{{1 -- cgit From 46a54dd6a03f51ba08142abe0aa5710705917987 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 26 Oct 2022 20:10:41 +0800 Subject: vim-patch:8.2.1852: map() returing zero for NULL list is unexpected Problem: map() returing zero for NULL list is unexpected. Solution: Return the empty list. (closes vim/vim#7133) https://github.com/vim/vim/commit/ffdf8adfa8108d4765fdc68abbd2fe49a4292b25 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_blob.vim | 1 + src/nvim/testdir/test_filter_map.vim | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_blob.vim b/src/nvim/testdir/test_blob.vim index c5a217f36f..770b2d16ef 100644 --- a/src/nvim/testdir/test_blob.vim +++ b/src/nvim/testdir/test_blob.vim @@ -274,6 +274,7 @@ endfunc " filter() item in blob func Test_blob_filter() + call assert_equal(v:_null_blob, filter(v:_null_blob, '0')) call assert_equal(0z, filter(0zDEADBEEF, '0')) call assert_equal(0zADBEEF, filter(0zDEADBEEF, 'v:val != 0xDE')) call assert_equal(0zDEADEF, filter(0zDEADBEEF, 'v:val != 0xBE')) diff --git a/src/nvim/testdir/test_filter_map.vim b/src/nvim/testdir/test_filter_map.vim index ebcb6699c6..c75177ea39 100644 --- a/src/nvim/testdir/test_filter_map.vim +++ b/src/nvim/testdir/test_filter_map.vim @@ -89,8 +89,10 @@ func Test_map_filter_fails() call assert_fails("let l = filter([1, 2, 3], '{}')", 'E728:') call assert_fails("let l = filter({'k' : 10}, '{}')", 'E728:') call assert_fails("let l = filter([1, 2], {})", 'E731:') - call assert_equal(0, map(v:_null_list, '"> " .. v:val')) - call assert_equal(0, map(v:_null_dict, '"> " .. v:val')) + call assert_equal(v:_null_list, filter(v:_null_list, 0)) + call assert_equal(v:_null_dict, filter(v:_null_dict, 0)) + call assert_equal(v:_null_list, map(v:_null_list, '"> " .. v:val')) + call assert_equal(v:_null_dict, map(v:_null_dict, '"> " .. v:val')) endfunc func Test_map_and_modify() -- cgit From 157baef02636fed4a99ef401e470fee8c51ce852 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 26 Oct 2022 21:53:11 +0800 Subject: vim-patch:8.1.1826: tests use hand coded feature and option checks Problem: Tests use hand coded feature and option checks. Solution: Use the commands from check.vim in more tests. https://github.com/vim/vim/commit/8c5a278fc508da6dfe50e69b6ee734451aa4eafb Omit Test_wincolor(): there are later patches that touch that function. Omit test_memory_usage.vim: a Lua test is used for that file. Cherry-pick Test_issue_3969() from patch 8.1.0969. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/check.vim | 16 +++++++++++++++ src/nvim/testdir/test_breakindent.vim | 5 ++--- src/nvim/testdir/test_bufline.vim | 6 +++--- src/nvim/testdir/test_fold.vim | 5 ++--- src/nvim/testdir/test_functions.vim | 5 ++--- src/nvim/testdir/test_highlight.vim | 8 ++------ src/nvim/testdir/test_mapping.vim | 4 +++- src/nvim/testdir/test_match.vim | 5 ++--- src/nvim/testdir/test_options.vim | 5 ++--- src/nvim/testdir/test_popup.vim | 12 ++++++------ src/nvim/testdir/test_signals.vim | 5 +++-- src/nvim/testdir/test_startup.vim | 37 ++++++++++++++++++++--------------- src/nvim/testdir/test_syntax.vim | 5 ++--- src/nvim/testdir/test_timers.vim | 9 ++++----- src/nvim/testdir/test_vimscript.vim | 5 +---- 15 files changed, 71 insertions(+), 61 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/check.vim b/src/nvim/testdir/check.vim index 4107df99d6..92a51d4371 100644 --- a/src/nvim/testdir/check.vim +++ b/src/nvim/testdir/check.vim @@ -39,6 +39,22 @@ func CheckFunction(name) endif endfunc +" Command to check for the presence of an Ex command +command -nargs=1 CheckCommand call CheckCommand() +func CheckCommand(name) + if !exists(':' .. a:name) + throw 'Skipped: ' .. a:name .. ' command not supported' + endif +endfunc + +" Command to check for the presence of a shell command +command -nargs=1 CheckExecutable call CheckExecutable() +func CheckExecutable(name) + if !executable(a:name) + throw 'Skipped: ' .. a:name .. ' program not executable' + endif +endfunc + " Command to check for the presence of python. Argument should have been " obtained with PythonProg() func CheckPython(name) diff --git a/src/nvim/testdir/test_breakindent.vim b/src/nvim/testdir/test_breakindent.vim index a37751e748..ed4d886fd1 100644 --- a/src/nvim/testdir/test_breakindent.vim +++ b/src/nvim/testdir/test_breakindent.vim @@ -4,9 +4,8 @@ " while the test is run, the breakindent caching gets in its way. " It helps to change the tabstop setting and force a redraw (e.g. see " Test_breakindent08()) -if !exists('+breakindent') - throw 'Skipped: breakindent option not supported' -endif +source check.vim +CheckOption breakindent source view_util.vim diff --git a/src/nvim/testdir/test_bufline.vim b/src/nvim/testdir/test_bufline.vim index 3b5bcbce89..8f853fe44e 100644 --- a/src/nvim/testdir/test_bufline.vim +++ b/src/nvim/testdir/test_bufline.vim @@ -2,6 +2,7 @@ source shared.vim source screendump.vim +source check.vim func Test_setbufline_getbufline() new @@ -130,9 +131,8 @@ func Test_deletebufline() endfunc func Test_appendbufline_redraw() - if !CanRunVimInTerminal() - throw 'Skipped: cannot make screendumps' - endif + CheckScreendump + let lines =<< trim END new foo let winnr = 'foo'->bufwinnr() diff --git a/src/nvim/testdir/test_fold.vim b/src/nvim/testdir/test_fold.vim index 327f0f73f2..0a9be310ff 100644 --- a/src/nvim/testdir/test_fold.vim +++ b/src/nvim/testdir/test_fold.vim @@ -1,5 +1,6 @@ " Test for folding +source check.vim source view_util.vim source screendump.vim @@ -727,9 +728,7 @@ func Test_fold_last_line_with_pagedown() endfunc func Test_folds_with_rnu() - if !CanRunVimInTerminal() - throw 'Skipped: cannot make screendumps' - endif + CheckScreendump call writefile([ \ 'set fdm=marker rnu foldcolumn=2', diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 8f2a61e399..6ef20107d8 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1745,9 +1745,8 @@ endfunc func Test_confirm() " requires a UI to be active throw 'Skipped: use test/functional/vimscript/input_spec.lua' - if !has('unix') || has('gui_running') - return - endif + CheckUnix + CheckNotGui call feedkeys('o', 'L') let a = confirm('Press O to proceed') diff --git a/src/nvim/testdir/test_highlight.vim b/src/nvim/testdir/test_highlight.vim index e84c45c635..2be82f4e3c 100644 --- a/src/nvim/testdir/test_highlight.vim +++ b/src/nvim/testdir/test_highlight.vim @@ -536,9 +536,7 @@ func Test_termguicolors() endfunc func Test_cursorline_after_yank() - if !CanRunVimInTerminal() - throw 'Skipped: cannot make screendumps' - endif + CheckScreendump call writefile([ \ 'set cul rnu', @@ -578,9 +576,7 @@ func Test_put_before_cursorline() endfunc func Test_cursorline_with_visualmode() - if !CanRunVimInTerminal() - throw 'Skipped: cannot make screendumps' - endif + CheckScreendump call writefile([ \ 'set cul', diff --git a/src/nvim/testdir/test_mapping.vim b/src/nvim/testdir/test_mapping.vim index bde3624adf..2d8c45210b 100644 --- a/src/nvim/testdir/test_mapping.vim +++ b/src/nvim/testdir/test_mapping.vim @@ -395,7 +395,9 @@ func Test_motionforce_omap() endfunc func Test_error_in_map_expr() - if !has('terminal') || (has('win32') && has('gui_running')) + " Unlike CheckRunVimInTerminal this does work in a win32 console + CheckFeature terminal + if has('win32') && has('gui_running') throw 'Skipped: cannot run Vim in a terminal window' endif diff --git a/src/nvim/testdir/test_match.vim b/src/nvim/testdir/test_match.vim index 4f22e54563..fe931fefb2 100644 --- a/src/nvim/testdir/test_match.vim +++ b/src/nvim/testdir/test_match.vim @@ -322,9 +322,8 @@ func OtherWindowCommon() endfunc func Test_matchdelete_other_window() - if !CanRunVimInTerminal() - throw 'Skipped: cannot make screendumps' - endif + CheckScreendump + let buf = OtherWindowCommon() call term_sendkeys(buf, ":call matchdelete(mid, winid)\") call VerifyScreenDump(buf, 'Test_matchdelete_1', {}) diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index ada6d2406b..8fc4968ad9 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -432,9 +432,8 @@ endfunc " Must be executed before other tests that set 'term'. func Test_000_term_option_verbose() - if has('nvim') || has('gui_running') - return - endif + throw "Skipped: Nvim does not support setting 'term'" + CheckNotGui call CheckWasNotSet('t_cm') diff --git a/src/nvim/testdir/test_popup.vim b/src/nvim/testdir/test_popup.vim index 067e5d14e5..7f183f0849 100644 --- a/src/nvim/testdir/test_popup.vim +++ b/src/nvim/testdir/test_popup.vim @@ -677,9 +677,9 @@ func Test_complete_CTRLN_startofbuffer() endfunc func Test_popup_and_window_resize() - if !has('terminal') || has('gui_running') - return - endif + CheckFeature terminal + CheckNotGui + let h = winheight(0) if h < 15 return @@ -948,9 +948,9 @@ func Test_complete_o_tab() endfunc func Test_menu_only_exists_in_terminal() - if !exists(':tlmenu') || has('gui_running') - return - endif + CheckCommand tlmenu + CheckNotGui + tlnoremenu &Edit.&Paste"+gP "+ aunmenu * try diff --git a/src/nvim/testdir/test_signals.vim b/src/nvim/testdir/test_signals.vim index 338c0d79ff..719f90c808 100644 --- a/src/nvim/testdir/test_signals.vim +++ b/src/nvim/testdir/test_signals.vim @@ -16,8 +16,9 @@ endfunc " Test signal WINCH (window resize signal) func Test_signal_WINCH() throw 'skipped: Nvim cannot avoid terminal resize' - if has('gui_running') || !HasSignal('WINCH') - return + CheckNotGui + if !HasSignal('WINCH') + throw 'Skipped: WINCH signal not supported' endif " We do not actually want to change the size of the terminal. diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim index b30a5e7edb..e267d3f972 100644 --- a/src/nvim/testdir/test_startup.vim +++ b/src/nvim/testdir/test_startup.vim @@ -267,10 +267,9 @@ endfunc " Test the -V[N] argument to set the 'verbose' option to [N] func Test_V_arg() - if has('gui_running') - " Can't catch the output of gvim. - return - endif + " Can't catch the output of gvim. + CheckNotGui + let out = system(GetVimCommand() . ' --clean -es -X -V0 -c "set verbose?" -cq') call assert_equal(" verbose=0\n", out) @@ -543,10 +542,9 @@ endfunc func Test_invalid_args() - if !has('unix') || has('gui_running') - " can't get output of Vim. - return - endif + " must be able to get the output of Vim. + CheckUnix + CheckNotGui for opt in ['-Y', '--does-not-exist'] let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") @@ -747,10 +745,9 @@ func Test_progpath() endfunc func Test_silent_ex_mode() - if !has('unix') || has('gui_running') - " can't get output of Vim. - return - endif + " must be able to get the output of Vim. + CheckUnix + CheckNotGui " This caused an ml_get error. let out = system(GetVimCommand() . ' -u NONE -es -c''set verbose=1|h|exe "%norm\\"'' -c cq') @@ -758,10 +755,9 @@ func Test_silent_ex_mode() endfunc func Test_default_term() - if !has('unix') || has('gui_running') - " can't get output of Vim. - return - endif + " must be able to get the output of Vim. + CheckUnix + CheckNotGui let save_term = $TERM let $TERM = 'unknownxxx' @@ -796,6 +792,15 @@ func Test_zzz_startinsert() call delete('Xtestout') endfunc +func Test_issue_3969() + " Can't catch the output of gvim. + CheckNotGui + + " Check that message is not truncated. + let out = system(GetVimCommand() . ' -es -X -V1 -c "echon ''hello''" -cq') + call assert_equal('hello', out) +endfunc + func Test_start_with_tabs() if !CanRunVimInTerminal() return diff --git a/src/nvim/testdir/test_syntax.vim b/src/nvim/testdir/test_syntax.vim index 9b4293764d..1402f0b9ad 100644 --- a/src/nvim/testdir/test_syntax.vim +++ b/src/nvim/testdir/test_syntax.vim @@ -489,9 +489,8 @@ func Test_conceal() endfunc func Test_bg_detection() - if has('gui_running') - return - endif + CheckNotGui + " auto-detection of &bg, make sure sure it isn't set anywhere before " this test hi Normal ctermbg=0 diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index 771f61442d..135bd2bcdd 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -263,9 +263,9 @@ func Interrupt(timer) endfunc func Test_timer_peek_and_get_char() - if !has('unix') && !has('gui_running') - return - endif + CheckUnix + CheckGui + call timer_start(0, 'FeedAndPeek') let intr = timer_start(100, 'Interrupt') let c = getchar() @@ -275,8 +275,7 @@ endfunc func Test_timer_getchar_zero() if has('win32') && !has('gui_running') - " Console: no low-level input - return + throw 'Skipped: cannot get low-level input' endif " Measure the elapsed time to avoid a hang when it fails. diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index a9fd7a4bef..c47c3672c4 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -1747,10 +1747,7 @@ func Test_funccall_garbage_collect() endfunc func Test_function_defined_line() - if has('gui_running') - " Can't catch the output of gvim. - return - endif + CheckNotGui let lines =<< trim [CODE] " F1 -- cgit From 8f8205ffe43541ccd475835a06fc89c8d19299f5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 26 Oct 2022 22:13:12 +0800 Subject: vim-patch:9.0.0019: timers test not run where possible Problem: Timers test not run where possible. Solution: Adjust platform checks. (closes vim/vim#10645) https://github.com/vim/vim/commit/eb273cd7b036c35ae9070bd6352101914f273e71 Cherry-pick a line from patch 8.2.0183. --- src/nvim/testdir/test_timers.vim | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index 135bd2bcdd..3a6abb3968 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -263,8 +263,9 @@ func Interrupt(timer) endfunc func Test_timer_peek_and_get_char() - CheckUnix - CheckGui + if !has('unix') && !has('gui_running') + throw 'Skipped: cannot feed low-level input' + endif call timer_start(0, 'FeedAndPeek') let intr = timer_start(100, 'Interrupt') @@ -275,8 +276,9 @@ endfunc func Test_timer_getchar_zero() if has('win32') && !has('gui_running') - throw 'Skipped: cannot get low-level input' + throw 'Skipped: cannot feed low-level input' endif + CheckFunction reltimefloat " Measure the elapsed time to avoid a hang when it fails. let start = reltime() -- cgit From 5559cabf4d851edb94cc2f09d50bcf0a04bd0819 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 26 Oct 2022 22:38:47 +0800 Subject: vim-patch:8.2.0531: various errors not tested Problem: Various errors not tested. Solution: Add tests. (Yegappan Lakshmanan, closes vim/vim#5895) https://github.com/vim/vim/commit/476a613135bdc94e61c1dce8a9cbb4ab0b6dc2d1 Need to remove "F" flag from 'shortmess' as early as possible. --- src/nvim/testdir/Makefile | 2 +- src/nvim/testdir/test_source.vim | 6 + src/nvim/testdir/test_syntax.vim | 58 ++++++++ src/nvim/testdir/test_user_func.vim | 256 ++++++++++++++++++++++++++++++++++++ src/nvim/testdir/test_vimscript.vim | 160 ---------------------- 5 files changed, 321 insertions(+), 161 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 4641408069..a6d1cf1003 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -179,4 +179,4 @@ newtestssilent: $(NEW_TESTS_RES) @echo "[OLDTEST] Running" $* @rm -rf $*.failed test.ok $(RM_ON_RUN) @mkdir -p $(TMPDIR) - @/bin/sh runnvim.sh $(ROOT) $(NVIM_PRG) $* $(RUN_VIMTEST) $(NO_INITS) -u NONE -S runtest.vim $*.vim + @/bin/sh runnvim.sh $(ROOT) $(NVIM_PRG) $* $(RUN_VIMTEST) $(NO_INITS) -u NONE --cmd "set shortmess-=F" -S runtest.vim $*.vim diff --git a/src/nvim/testdir/test_source.vim b/src/nvim/testdir/test_source.vim index ba6fd5ad95..0fd923abf2 100644 --- a/src/nvim/testdir/test_source.vim +++ b/src/nvim/testdir/test_source.vim @@ -87,4 +87,10 @@ func Test_source_autocmd_sfile() call delete('Xscript.vim') endfunc +func Test_source_error() + call assert_fails('scriptencoding utf-8', 'E167:') + call assert_fails('finish', 'E168:') + " call assert_fails('scriptversion 2', 'E984:') +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_syntax.vim b/src/nvim/testdir/test_syntax.vim index 1402f0b9ad..52510843a3 100644 --- a/src/nvim/testdir/test_syntax.vim +++ b/src/nvim/testdir/test_syntax.vim @@ -363,6 +363,64 @@ func Test_syntax_invalid_arg() call assert_fails('syntax sync x', 'E404:') call assert_fails('syntax keyword Abc a[', 'E789:') call assert_fails('syntax keyword Abc a[bc]d', 'E890:') + + let caught_393 = 0 + try + syntax keyword cMyItem grouphere G1 + catch /E393:/ + let caught_393 = 1 + endtry + call assert_equal(1, caught_393) + + let caught_394 = 0 + try + syntax sync match Abc grouphere MyItem "abc"' + catch /E394:/ + let caught_394 = 1 + endtry + call assert_equal(1, caught_394) + + " Test for too many \z\( and unmatched \z\( + " Not able to use assert_fails() here because both E50:/E879: and E475: + " messages are emitted. + set regexpengine=1 + let caught_52 = 0 + try + syntax region MyRegion start='\z\(' end='\*/' + catch /E52:/ + let caught_52 = 1 + endtry + call assert_equal(1, caught_52) + + let caught_50 = 0 + try + let cmd = "syntax region MyRegion start='" + let cmd ..= repeat("\\z\\(.\\)", 10) .. "' end='\*/'" + exe cmd + catch /E50:/ + let caught_50 = 1 + endtry + call assert_equal(1, caught_50) + + set regexpengine=2 + let caught_54 = 0 + try + syntax region MyRegion start='\z\(' end='\*/' + catch /E54:/ + let caught_54 = 1 + endtry + call assert_equal(1, caught_54) + + let caught_879 = 0 + try + let cmd = "syntax region MyRegion start='" + let cmd ..= repeat("\\z\\(.\\)", 10) .. "' end='\*/'" + exe cmd + catch /E879:/ + let caught_879 = 1 + endtry + call assert_equal(1, caught_879) + set regexpengine& endfunc func Test_syn_sync() diff --git a/src/nvim/testdir/test_user_func.vim b/src/nvim/testdir/test_user_func.vim index 13a0334cd3..c517d1133a 100644 --- a/src/nvim/testdir/test_user_func.vim +++ b/src/nvim/testdir/test_user_func.vim @@ -3,6 +3,9 @@ " Also test that a builtin function cannot be replaced. " Also test for regression when calling arbitrary expression. +source check.vim +source shared.vim + func Table(title, ...) let ret = a:title let idx = 1 @@ -83,6 +86,7 @@ func Test_user_func() normal o[(one again call assert_equal('1. one again', getline('.')) + " Try to overwrite a function in the global (g:) scope call assert_equal(3, max([1, 2, 3])) call assert_fails("call extend(g:, {'max': function('min')})", 'E704') call assert_equal(3, max([1, 2, 3])) @@ -178,4 +182,256 @@ func Test_function_list() call assert_fails("function Xabc", 'E123:') endfunc +" Test for , in a function +func Test_sfile_in_function() + func Xfunc() + call assert_match('..Test_sfile_in_function\[5]..Xfunc', expand('')) + call assert_equal('2', expand('')) + endfunc + call Xfunc() + delfunc Xfunc +endfunc + +" Test trailing text after :endfunction {{{1 +func Test_endfunction_trailing() + call assert_false(exists('*Xtest')) + + exe "func Xtest()\necho 'hello'\nendfunc\nlet done = 'yes'" + call assert_true(exists('*Xtest')) + call assert_equal('yes', done) + delfunc Xtest + unlet done + + exe "func Xtest()\necho 'hello'\nendfunc|let done = 'yes'" + call assert_true(exists('*Xtest')) + call assert_equal('yes', done) + delfunc Xtest + unlet done + + " trailing line break + exe "func Xtest()\necho 'hello'\nendfunc\n" + call assert_true(exists('*Xtest')) + delfunc Xtest + + set verbose=1 + exe "func Xtest()\necho 'hello'\nendfunc \" garbage" + call assert_notmatch('W22:', split(execute('1messages'), "\n")[0]) + call assert_true(exists('*Xtest')) + delfunc Xtest + + exe "func Xtest()\necho 'hello'\nendfunc garbage" + call assert_match('W22:', split(execute('1messages'), "\n")[0]) + call assert_true(exists('*Xtest')) + delfunc Xtest + set verbose=0 + + function Foo() + echo 'hello' + endfunction | echo 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' + delfunc Foo +endfunc + +func Test_delfunction_force() + delfunc! Xtest + delfunc! Xtest + func Xtest() + echo 'nothing' + endfunc + delfunc! Xtest + delfunc! Xtest + + " Try deleting the current function + call assert_fails('delfunc Test_delfunction_force', 'E131:') +endfunc + +func Test_function_defined_line() + CheckNotGui + + let lines =<< trim [CODE] + " F1 + func F1() + " F2 + func F2() + " + " + " + return + endfunc + " F3 + execute "func F3()\n\n\n\nreturn\nendfunc" + " F4 + execute "func F4()\n + \\n + \\n + \\n + \return\n + \endfunc" + endfunc + " F5 + execute "func F5()\n\n\n\nreturn\nendfunc" + " F6 + execute "func F6()\n + \\n + \\n + \\n + \return\n + \endfunc" + call F1() + verbose func F1 + verbose func F2 + verbose func F3 + verbose func F4 + verbose func F5 + verbose func F6 + qall! + [CODE] + + call writefile(lines, 'Xtest.vim') + let res = system(GetVimCommandClean() .. ' -es -X -S Xtest.vim') + call assert_equal(0, v:shell_error) + + let m = matchstr(res, 'function F1()[^[:print:]]*[[:print:]]*') + call assert_match(' line 2$', m) + + let m = matchstr(res, 'function F2()[^[:print:]]*[[:print:]]*') + call assert_match(' line 4$', m) + + let m = matchstr(res, 'function F3()[^[:print:]]*[[:print:]]*') + call assert_match(' line 11$', m) + + let m = matchstr(res, 'function F4()[^[:print:]]*[[:print:]]*') + call assert_match(' line 13$', m) + + let m = matchstr(res, 'function F5()[^[:print:]]*[[:print:]]*') + call assert_match(' line 21$', m) + + let m = matchstr(res, 'function F6()[^[:print:]]*[[:print:]]*') + call assert_match(' line 23$', m) + + call delete('Xtest.vim') +endfunc + +" Test for defining a function reference in the global scope +func Test_add_funcref_to_global_scope() + let x = g: + let caught_E862 = 0 + try + func x.Xfunc() + return 1 + endfunc + catch /E862:/ + let caught_E862 = 1 + endtry + call assert_equal(1, caught_E862) +endfunc + +func Test_funccall_garbage_collect() + func Func(x, ...) + call add(a:x, a:000) + endfunc + call Func([], []) + " Must not crash cause by invalid freeing + call test_garbagecollect_now() + call assert_true(v:true) + delfunc Func +endfunc + +" Test for script-local function +func DoLast() + call append(line('$'), "last line") +endfunc + +func s:DoNothing() + call append(line('$'), "nothing line") +endfunc + +func Test_script_local_func() + set nocp nomore viminfo+=nviminfo + new + nnoremap _x :call DoNothing()call DoLast()delfunc DoNothingdelfunc DoLast + + normal _x + call assert_equal('nothing line', getline(2)) + call assert_equal('last line', getline(3)) + close! + + " Try to call a script local function in global scope + let lines =<< trim [CODE] + :call assert_fails('call s:Xfunc()', 'E81:') + :call assert_fails('let x = call("Xfunc", [])', 'E120:') + :call writefile(v:errors, 'Xresult') + :qall + + [CODE] + call writefile(lines, 'Xscript') + if RunVim([], [], '-s Xscript') + call assert_equal([], readfile('Xresult')) + endif + call delete('Xresult') + call delete('Xscript') +endfunc + +" Test for errors in defining new functions +func Test_func_def_error() + call assert_fails('func Xfunc abc ()', 'E124:') + call assert_fails('func Xfunc(', 'E125:') + call assert_fails('func xfunc()', 'E128:') + + " Try to redefine a function that is in use + let caught_E127 = 0 + try + func! Test_func_def_error() + endfunc + catch /E127:/ + let caught_E127 = 1 + endtry + call assert_equal(1, caught_E127) + + " Try to define a function in a dict twice + let d = {} + let lines =<< trim END + func d.F1() + return 1 + endfunc + END + let l = join(lines, "\n") . "\n" + exe l + call assert_fails('exe l', 'E717:') + + " Define an autoload function with an incorrect file name + call writefile(['func foo#Bar()', 'return 1', 'endfunc'], 'Xscript') + call assert_fails('source Xscript', 'E746:') + call delete('Xscript') +endfunc + +" Test for deleting a function +func Test_del_func() + call assert_fails('delfunction Xabc', 'E130:') + let d = {'a' : 10} + call assert_fails('delfunc d.a', 'E718:') +endfunc + +" Test for calling return outside of a function +func Test_return_outside_func() + call writefile(['return 10'], 'Xscript') + call assert_fails('source Xscript', 'E133:') + call delete('Xscript') +endfunc + +" Test for errors in calling a function +func Test_func_arg_error() + " Too many arguments + call assert_fails("call call('min', range(1,20))", 'E118:') + call assert_fails("call call('min', range(1,21))", 'E699:') + call assert_fails('echo min(0,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,0,1)', + \ 'E740:') + + " Missing dict argument + func Xfunc() dict + return 1 + endfunc + call assert_fails('call Xfunc()', 'E725:') + delfunc Xfunc +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index c47c3672c4..f20fd12ed3 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -1495,58 +1495,6 @@ func Test_bitwise_functions() call assert_fails("call invert({})", 'E728:') endfunc -" Test trailing text after :endfunction {{{1 -func Test_endfunction_trailing() - call assert_false(exists('*Xtest')) - - exe "func Xtest()\necho 'hello'\nendfunc\nlet done = 'yes'" - call assert_true(exists('*Xtest')) - call assert_equal('yes', done) - delfunc Xtest - unlet done - - exe "func Xtest()\necho 'hello'\nendfunc|let done = 'yes'" - call assert_true(exists('*Xtest')) - call assert_equal('yes', done) - delfunc Xtest - unlet done - - " trailing line break - exe "func Xtest()\necho 'hello'\nendfunc\n" - call assert_true(exists('*Xtest')) - delfunc Xtest - - set verbose=1 - exe "func Xtest()\necho 'hello'\nendfunc \" garbage" - call assert_notmatch('W22:', split(execute('1messages'), "\n")[0]) - call assert_true(exists('*Xtest')) - delfunc Xtest - - exe "func Xtest()\necho 'hello'\nendfunc garbage" - call assert_match('W22:', split(execute('1messages'), "\n")[0]) - call assert_true(exists('*Xtest')) - delfunc Xtest - set verbose=0 - - function Foo() - echo 'hello' - endfunction | echo 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' - delfunc Foo -endfunc - -func Test_delfunction_force() - delfunc! Xtest - delfunc! Xtest - func Xtest() - echo 'nothing' - endfunc - delfunc! Xtest - delfunc! Xtest - - " Try deleting the current function - call assert_fails('delfunc Test_delfunction_force', 'E131:') -endfunc - " Test using bang after user command {{{1 func Test_user_command_with_bang() command -bang Nieuw let nieuw = 1 @@ -1556,26 +1504,6 @@ func Test_user_command_with_bang() delcommand Nieuw endfunc -" Test for script-local function -func DoLast() - call append(line('$'), "last line") -endfunc - -func s:DoNothing() - call append(line('$'), "nothing line") -endfunc - -func Test_script_local_func() - set nocp nomore viminfo+=nviminfo - new - nnoremap _x :call DoNothing()call DoLast()delfunc DoNothingdelfunc DoLast - - normal _x - call assert_equal('nothing line', getline(2)) - call assert_equal('last line', getline(3)) - enew! | close -endfunc - func Test_script_expand_sfile() let lines =<< trim END func s:snr() @@ -1735,84 +1663,6 @@ func Test_unlet_env() call assert_equal('', $TESTVAR) endfunc -func Test_funccall_garbage_collect() - func Func(x, ...) - call add(a:x, a:000) - endfunc - call Func([], []) - " Must not crash cause by invalid freeing - call test_garbagecollect_now() - call assert_true(v:true) - delfunc Func -endfunc - -func Test_function_defined_line() - CheckNotGui - - let lines =<< trim [CODE] - " F1 - func F1() - " F2 - func F2() - " - " - " - return - endfunc - " F3 - execute "func F3()\n\n\n\nreturn\nendfunc" - " F4 - execute "func F4()\n - \\n - \\n - \\n - \return\n - \endfunc" - endfunc - " F5 - execute "func F5()\n\n\n\nreturn\nendfunc" - " F6 - execute "func F6()\n - \\n - \\n - \\n - \return\n - \endfunc" - call F1() - verbose func F1 - verbose func F2 - verbose func F3 - verbose func F4 - verbose func F5 - verbose func F6 - qall! - [CODE] - - call writefile(lines, 'Xtest.vim') - let res = system(GetVimCommandClean() .. ' -es -X -S Xtest.vim') - call assert_equal(0, v:shell_error) - - let m = matchstr(res, 'function F1()[^[:print:]]*[[:print:]]*') - call assert_match(' line 2$', m) - - let m = matchstr(res, 'function F2()[^[:print:]]*[[:print:]]*') - call assert_match(' line 4$', m) - - let m = matchstr(res, 'function F3()[^[:print:]]*[[:print:]]*') - call assert_match(' line 11$', m) - - let m = matchstr(res, 'function F4()[^[:print:]]*[[:print:]]*') - call assert_match(' line 13$', m) - - let m = matchstr(res, 'function F5()[^[:print:]]*[[:print:]]*') - call assert_match(' line 21$', m) - - let m = matchstr(res, 'function F6()[^[:print:]]*[[:print:]]*') - call assert_match(' line 23$', m) - - call delete('Xtest.vim') -endfunc - " Test for missing :endif, :endfor, :endwhile and :endtry {{{1 func Test_missing_end() call writefile(['if 2 > 1', 'echo ">"'], 'Xscript') @@ -1948,16 +1798,6 @@ func Test_deep_nest() call delete('Xscript') endfunc -" Test for , in a function {{{1 -func Test_sfile_in_function() - func Xfunc() - call assert_match('..Test_sfile_in_function\[5]..Xfunc', expand('')) - call assert_equal('2', expand('')) - endfunc - call Xfunc() - delfunc Xfunc -endfunc - " Test for errors in converting to float from various types {{{1 func Test_float_conversion_errors() if has('float') -- cgit From 31758d032ffeaf746eaae99f79c6b4e4e35dfebe Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 26 Oct 2022 23:22:37 +0800 Subject: vim-patch:8.2.0534: client-server test fails under valgrind Problem: Client-server test fails under valgrind. Solution: Use WaitForAssert(). https://github.com/vim/vim/commit/25d57009520f0e590920b9f953b1cbbb358e72a2 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_clientserver.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_clientserver.vim b/src/nvim/testdir/test_clientserver.vim index a4ebce5af9..943f79d98f 100644 --- a/src/nvim/testdir/test_clientserver.vim +++ b/src/nvim/testdir/test_clientserver.vim @@ -147,7 +147,7 @@ func Test_client_server() " Edit files in separate tab pages call system(cmd .. ' --remote-tab Xfile1 Xfile2 Xfile3') - call assert_equal('3', remote_expr(name, 'tabpagenr("$")')) + call WaitForAssert({-> assert_equal('3', remote_expr(name, 'tabpagenr("$")'))}) call assert_equal('Xfile2', remote_expr(name, 'bufname(tabpagebuflist(2)[0])')) eval name->remote_send(":%bw!\") -- cgit From 27436b733fb1bc60e78f7fb5a0274b54b87fb04e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 26 Oct 2022 23:24:43 +0800 Subject: vim-patch:8.2.0606: several syntax HL errors not checked Problem: Several syntax HL errors not checked. Solution: Add tests. (Yegappan Lakshmanan, closes vim/vim#5954) https://github.com/vim/vim/commit/fbf2122cf920a89274ffbefaaeb6c5eeacf5187b --- src/nvim/testdir/test_syntax.vim | 95 +++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 50 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_syntax.vim b/src/nvim/testdir/test_syntax.vim index 52510843a3..2a173916d0 100644 --- a/src/nvim/testdir/test_syntax.vim +++ b/src/nvim/testdir/test_syntax.vim @@ -351,6 +351,18 @@ func Test_syntax_arg_skipped() syn clear endfunc +" Check for an error. Used when multiple errors are thrown and we are checking +" for an earliest error. +func AssertFails(cmd, errcode) + let save_exception = '' + try + exe a:cmd + catch + let save_exception = v:exception + endtry + call assert_match(a:errcode, save_exception) +endfunc + func Test_syntax_invalid_arg() call assert_fails('syntax case asdf', 'E390:') if has('conceal') @@ -358,69 +370,49 @@ func Test_syntax_invalid_arg() endif call assert_fails('syntax spell asdf', 'E390:') call assert_fails('syntax clear @ABCD', 'E391:') - call assert_fails('syntax include @Xxx', 'E397:') - call assert_fails('syntax region X start="{"', 'E399:') + call assert_fails('syntax include random_file', 'E484:') + call assert_fails('syntax include ', 'E495:') call assert_fails('syntax sync x', 'E404:') call assert_fails('syntax keyword Abc a[', 'E789:') call assert_fails('syntax keyword Abc a[bc]d', 'E890:') - - let caught_393 = 0 - try - syntax keyword cMyItem grouphere G1 - catch /E393:/ - let caught_393 = 1 - endtry - call assert_equal(1, caught_393) - - let caught_394 = 0 - try - syntax sync match Abc grouphere MyItem "abc"' - catch /E394:/ - let caught_394 = 1 - endtry - call assert_equal(1, caught_394) + call assert_fails('syntax cluster Abc add=A add=', 'E475:') " Test for too many \z\( and unmatched \z\( " Not able to use assert_fails() here because both E50:/E879: and E475: " messages are emitted. set regexpengine=1 - let caught_52 = 0 - try - syntax region MyRegion start='\z\(' end='\*/' - catch /E52:/ - let caught_52 = 1 - endtry - call assert_equal(1, caught_52) + call AssertFails("syntax region MyRegion start='\\z\\(' end='\\*/'", 'E52:') - let caught_50 = 0 - try - let cmd = "syntax region MyRegion start='" - let cmd ..= repeat("\\z\\(.\\)", 10) .. "' end='\*/'" - exe cmd - catch /E50:/ - let caught_50 = 1 - endtry - call assert_equal(1, caught_50) + let cmd = "syntax region MyRegion start='" + let cmd ..= repeat("\\z\\(.\\)", 10) .. "' end='\*/'" + call AssertFails(cmd, 'E50:') set regexpengine=2 - let caught_54 = 0 - try - syntax region MyRegion start='\z\(' end='\*/' - catch /E54:/ - let caught_54 = 1 - endtry - call assert_equal(1, caught_54) + call AssertFails("syntax region MyRegion start='\\z\\(' end='\\*/'", 'E54:') - let caught_879 = 0 - try - let cmd = "syntax region MyRegion start='" - let cmd ..= repeat("\\z\\(.\\)", 10) .. "' end='\*/'" - exe cmd - catch /E879:/ - let caught_879 = 1 - endtry - call assert_equal(1, caught_879) + let cmd = "syntax region MyRegion start='" + let cmd ..= repeat("\\z\\(.\\)", 10) .. "' end='\*/'" + call AssertFails(cmd, 'E879:') set regexpengine& + + call AssertFails('syntax keyword cMyItem grouphere G1', 'E393:') + call AssertFails('syntax sync match Abc grouphere MyItem "abc"', 'E394:') + call AssertFails('syn keyword Type contains int', 'E395:') + call assert_fails('syntax include @Xxx', 'E397:') + call AssertFails('syntax region X start', 'E398:') + call assert_fails('syntax region X start="{"', 'E399:') + call AssertFails('syntax cluster contains=Abc', 'E400:') + call AssertFails("syntax match Character /'.'", 'E401:') + call AssertFails("syntax match Character /'.'/a", 'E402:') + call assert_fails('syntax sync linecont /pat', 'E404:') + call assert_fails('syntax sync linecont', 'E404:') + call assert_fails('syntax sync linecont /pat1/ linecont /pat2/', 'E403:') + call assert_fails('syntax sync minlines=a', 'E404:') + call AssertFails('syntax match ABC /x/ contains=', 'E406:') + call AssertFails("syntax match Character contains /'.'/", 'E405:') + call AssertFails('syntax match ccFoo "Foo" nextgroup=ALLBUT,F', 'E407:') + call AssertFails('syntax region Block start="{" contains=F,ALLBUT', 'E408:') + call AssertFails("syntax match Characters contains=a.*x /'.'/", 'E409:') endfunc func Test_syn_sync() @@ -448,6 +440,7 @@ func Test_syn_clear() hi clear Foo call assert_equal('Foo', synIDattr(hlID("Foo"), "name")) hi clear Bar + call assert_fails('syntax clear invalid_syngroup', 'E28:') endfunc func Test_invalid_name() @@ -541,6 +534,8 @@ func Test_conceal() call assert_match('16 ', ScreenLines(2, 7)[0]) call assert_equal([[0, '', 0], [1, '', 1], [1, '', 1], [1, '', 2], [1, '', 2], [0, '', 0]], map(range(1, 6), 'synconcealed(2, v:val)')) + call AssertFails("syntax match Entity '&' conceal cchar=\", 'E844:') + syn clear set conceallevel& bw! -- cgit From 514e6bf07b6b0fe08019906b56d1226a70d14119 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 26 Oct 2022 23:26:12 +0800 Subject: vim-patch:8.2.1113: no test for verbose output of :call Problem: No test for verbose output of :call. Solution: Add a test. https://github.com/vim/vim/commit/a0d072ef8203b225bd46bcd826cb3d2e3c3b941a Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_user_func.vim | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_user_func.vim b/src/nvim/testdir/test_user_func.vim index c517d1133a..8b5ee72bf1 100644 --- a/src/nvim/testdir/test_user_func.vim +++ b/src/nvim/testdir/test_user_func.vim @@ -225,6 +225,17 @@ func Test_endfunction_trailing() delfunc Xtest set verbose=0 + func Xtest(a1, a2) + echo a:a1 .. a:a2 + endfunc + set verbose=15 + redir @a + call Xtest(123, repeat('x', 100)) + redir END + call assert_match('calling Xtest(123, ''xxxxxxx.*x\.\.\.x.*xxxx'')', getreg('a')) + delfunc Xtest + set verbose=0 + function Foo() echo 'hello' endfunction | echo 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' -- cgit From 624f6a8ca012dd6d27f1e67ace6ef10d04c5625f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 27 Oct 2022 07:53:54 +0800 Subject: vim-patch:8.2.2837: various code lines not covered by tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Various code lines not covered by tests. Solution: Add test cases. (Dominique Pellé, closes vim/vim#8178) https://github.com/vim/vim/commit/6d37e8e3baafba460bd2d051170d213c1ba9a523 Co-authored-by: Dominique Pelle --- src/nvim/testdir/test_excmd.vim | 6 ++++++ src/nvim/testdir/test_functions.vim | 2 ++ src/nvim/testdir/test_options.vim | 29 +++++++++++++++++++++++++++++ src/nvim/testdir/test_startup.vim | 7 +++++++ src/nvim/testdir/test_syntax.vim | 3 +++ 5 files changed, 47 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_excmd.vim b/src/nvim/testdir/test_excmd.vim index acf23fbc3c..04ab8e288f 100644 --- a/src/nvim/testdir/test_excmd.vim +++ b/src/nvim/testdir/test_excmd.vim @@ -683,6 +683,12 @@ func Test_sandbox() sandbox call Sandbox_tests() endfunc +func Test_command_not_implemented_E319() + if !has('mzscheme') + call assert_fails('mzscheme', 'E319:') + endif +endfunc + func Test_not_break_expression_register() call setreg('=', '1+1') if 0 diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 6ef20107d8..1b9b9abd91 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1018,7 +1018,9 @@ func Test_charidx() call assert_equal(2, charidx(a, 4)) call assert_equal(3, charidx(a, 7)) call assert_equal(-1, charidx(a, 8)) + call assert_equal(-1, charidx(a, -1)) call assert_equal(-1, charidx('', 0)) + call assert_equal(-1, charidx(v:_null_string, 0)) " count composing characters call assert_equal(0, charidx(a, 0, 1)) diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index 8fc4968ad9..2836e81c4a 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -1116,6 +1116,35 @@ func Test_opt_reset_scroll() call delete('Xscroll') endfunc +" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm' +func Test_VIM_POSIX() + throw 'Skipped: Nvim does not support $VIM_POSIX' + let saved_VIM_POSIX = getenv("VIM_POSIX") + + call setenv('VIM_POSIX', "1") + let after =<< trim [CODE] + call writefile([&cpo, &shm], 'X_VIM_POSIX') + qall + [CODE] + if RunVim([], after, '') + call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\.;', + \ 'AS'], readfile('X_VIM_POSIX')) + endif + + call setenv('VIM_POSIX', v:null) + let after =<< trim [CODE] + call writefile([&cpo, &shm], 'X_VIM_POSIX') + qall + [CODE] + if RunVim([], after, '') + call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;', + \ 'S'], readfile('X_VIM_POSIX')) + endif + + call delete('X_VIM_POSIX') + call setenv('VIM_POSIX', saved_VIM_POSIX) +endfunc + " Test for setting an option to a Vi or Vim default func Test_opt_default() throw 'Skipped: Nvim has different defaults' diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim index e267d3f972..b8aad1bc46 100644 --- a/src/nvim/testdir/test_startup.vim +++ b/src/nvim/testdir/test_startup.vim @@ -620,6 +620,12 @@ func Test_invalid_args() endfor if has('gui_gtk') + let out = split(system(GetVimCommand() .. ' --socketid'), "\n") + call assert_equal(1, v:shell_error) + call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) + call assert_equal('Argument missing after: "--socketid"', out[1]) + call assert_equal('More info with: "vim -h"', out[2]) + for opt in ['--socketid x', '--socketid 0xg'] let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") call assert_equal(1, v:shell_error) @@ -627,6 +633,7 @@ func Test_invalid_args() call assert_equal('Invalid argument for: "--socketid"', out[1]) call assert_equal('More info with: "vim -h"', out[2]) endfor + endif endfunc diff --git a/src/nvim/testdir/test_syntax.vim b/src/nvim/testdir/test_syntax.vim index 2a173916d0..9d617e145c 100644 --- a/src/nvim/testdir/test_syntax.vim +++ b/src/nvim/testdir/test_syntax.vim @@ -113,6 +113,9 @@ func Test_syntime() let a = execute('syntime report') call assert_equal("\nNo Syntax items defined for this buffer", a) + let a = execute('syntime clear') + call assert_equal("\nNo Syntax items defined for this buffer", a) + view samples/memfile_test.c setfiletype cpp redraw -- cgit From c031547c8d39c5fc99c6f1fab31b50ba6fb32cbc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 27 Oct 2022 07:58:51 +0800 Subject: vim-patch:8.2.3839: using \z() with \z1 not tested for syntax highlighting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Using \z() with \z1 not tested for syntax highlighting. Solution: Add a test. (Dominique Pellé, closes vim/vim#9365) https://github.com/vim/vim/commit/354b23a9f87fd8c5aec457d88320a0a5bce4b985 Co-authored-by: Dominique Pelle --- src/nvim/testdir/test_syntax.vim | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_syntax.vim b/src/nvim/testdir/test_syntax.vim index 9d617e145c..d686ad7e96 100644 --- a/src/nvim/testdir/test_syntax.vim +++ b/src/nvim/testdir/test_syntax.vim @@ -666,6 +666,24 @@ func Test_syntax_c() call delete('Xtest.c') endfun +" Test \z(...) along with \z1 +func Test_syn_zsub() + new + syntax on + call setline(1, 'xxx start foo xxx not end foo xxx end foo xxx') + let l:expected = ' ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ ' + + for l:re in [0, 1, 2] + " Example taken from :help :syn-ext-match + syntax region Z start="start \z(\I\i*\)" skip="not end \z1" end="end \z1" + eval AssertHighlightGroups(1, 1, l:expected, 1, 'regexp=' .. l:re) + syntax clear Z + endfor + + set re& + bw! +endfunc + " Using \z() in a region with NFA failing should not crash. func Test_syn_wrong_z_one() new -- cgit From 245e6c5b305a0f32c39c88df8c0bf3c38505cc60 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 27 Oct 2022 08:25:28 +0800 Subject: test(old): test_lambda.vim garbagecollect() -> test_garbagecollect_now() --- src/nvim/testdir/test_lambda.vim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_lambda.vim b/src/nvim/testdir/test_lambda.vim index 997c3dcd3a..3c12c7b02e 100644 --- a/src/nvim/testdir/test_lambda.vim +++ b/src/nvim/testdir/test_lambda.vim @@ -126,7 +126,7 @@ func Test_lambda_closure_counter() endfunc let l:F = s:foo() - call garbagecollect() + call test_garbagecollect_now() call assert_equal(1, l:F()) call assert_equal(2, l:F()) call assert_equal(3, l:F()) @@ -209,9 +209,9 @@ func Test_lambda_circular_reference() endfunc call s:Foo() - call garbagecollect() + call test_garbagecollect_now() let i = 0 | while i < 10000 | call s:Foo() | let i+= 1 | endwhile - call garbagecollect() + call test_garbagecollect_now() endfunc func Test_lambda_combination() @@ -240,7 +240,7 @@ func Test_closure_counter() endfunc let l:F = s:foo() - call garbagecollect() + call test_garbagecollect_now() call assert_equal(1, l:F()) call assert_equal(2, l:F()) call assert_equal(3, l:F()) @@ -258,7 +258,7 @@ func Test_closure_unlet() endfunc call assert_false(has_key(s:foo(), 'x')) - call garbagecollect() + call test_garbagecollect_now() endfunc func LambdaFoo() @@ -295,7 +295,7 @@ func Test_named_function_closure() endfunc call Afoo() call assert_equal(14, s:Abar()) - call garbagecollect() + call test_garbagecollect_now() call assert_equal(14, s:Abar()) endfunc -- cgit From bd122494cc3012a4885a55663e7c158c7a402878 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 27 Oct 2022 08:26:09 +0800 Subject: vim-patch:8.2.2100: insufficient testing for function range and dict MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Insufficient testing for function range and dict. Solution: Add a few tests. (Dominique Pellé, closes vim/vim#7428) https://github.com/vim/vim/commit/67322bf74a106b6476b093e75da87d61e2181b76 --- src/nvim/testdir/test_functions.vim | 1 + src/nvim/testdir/test_lambda.vim | 5 +++++ src/nvim/testdir/test_signals.vim | 3 +-- src/nvim/testdir/test_user_func.vim | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 1b9b9abd91..b751215b79 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1865,6 +1865,7 @@ func Test_call() let mydict = {'data': [0, 1, 2, 3], 'len': function("Mylen")} eval mydict.len->call([], mydict)->assert_equal(4) call assert_fails("call call('Mylen', [], 0)", 'E715:') + call assert_fails('call foo', 'E107:') endfunc func Test_char2nr() diff --git a/src/nvim/testdir/test_lambda.vim b/src/nvim/testdir/test_lambda.vim index 3c12c7b02e..ce15243993 100644 --- a/src/nvim/testdir/test_lambda.vim +++ b/src/nvim/testdir/test_lambda.vim @@ -245,6 +245,11 @@ func Test_closure_counter() call assert_equal(2, l:F()) call assert_equal(3, l:F()) call assert_equal(4, l:F()) + + call assert_match("^\n function \\d\\+_bar() closure" + \ .. "\n1 let x += 1" + \ .. "\n2 return x" + \ .. "\n endfunction$", execute('func s:bar')) endfunc func Test_closure_unlet() diff --git a/src/nvim/testdir/test_signals.vim b/src/nvim/testdir/test_signals.vim index 719f90c808..e1c6e5d11f 100644 --- a/src/nvim/testdir/test_signals.vim +++ b/src/nvim/testdir/test_signals.vim @@ -129,8 +129,7 @@ func Test_deadly_signal_TERM() call assert_equal(['foo'], getline(1, '$')) let result = readfile('XautoOut') - call assert_match('VimLeavePre triggered', result[0]) - call assert_match('VimLeave triggered', result[1]) + call assert_equal(["VimLeavePre triggered", "VimLeave triggered"], result) %bwipe! call delete('.Xsig_TERM.swp') diff --git a/src/nvim/testdir/test_user_func.vim b/src/nvim/testdir/test_user_func.vim index 8b5ee72bf1..5041fa9ad4 100644 --- a/src/nvim/testdir/test_user_func.vim +++ b/src/nvim/testdir/test_user_func.vim @@ -445,4 +445,36 @@ func Test_func_arg_error() delfunc Xfunc endfunc +func Test_func_dict() + let mydict = {'a': 'b'} + function mydict.somefunc() dict + return len(self) + endfunc + + call assert_equal("{'a': 'b', 'somefunc': function('2')}", string(mydict)) + call assert_equal(2, mydict.somefunc()) + call assert_match("^\n function \\d\\\+() dict" + \ .. "\n1 return len(self)" + \ .. "\n endfunction$", execute('func mydict.somefunc')) +endfunc + +func Test_func_range() + new + call setline(1, range(1, 8)) + func FuncRange() range + echo a:firstline + echo a:lastline + endfunc + 3 + call assert_equal("\n3\n3", execute('call FuncRange()')) + call assert_equal("\n4\n6", execute('4,6 call FuncRange()')) + call assert_equal("\n function FuncRange() range" + \ .. "\n1 echo a:firstline" + \ .. "\n2 echo a:lastline" + \ .. "\n endfunction", + \ execute('function FuncRange')) + + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 905bef7bd9cd5d1751fc09aad3c6fb78e2c60ff8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 27 Oct 2022 08:34:01 +0800 Subject: vim-patch:8.2.2727: function test fails Problem: Function test fails. Solution: Adjust expected error number. https://github.com/vim/vim/commit/e9b8b78e046b40b877c999432c4698edb3413d5d Cherry-pick colons from patch 8.2.1593. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_user_func.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_user_func.vim b/src/nvim/testdir/test_user_func.vim index 5041fa9ad4..01bf2e1d0f 100644 --- a/src/nvim/testdir/test_user_func.vim +++ b/src/nvim/testdir/test_user_func.vim @@ -149,8 +149,8 @@ func Test_default_arg() call assert_equal(res.optional, 2) call assert_equal(res['0'], 1) - call assert_fails("call MakeBadFunc()", 'E989') - call assert_fails("fu F(a=1 ,) | endf", 'E475') + call assert_fails("call MakeBadFunc()", 'E989:') + call assert_fails("fu F(a=1 ,) | endf", 'E1068:') " Since neovim does not have v:none, the ability to use the default " argument with the intermediate argument set to v:none has been omitted. -- cgit From 9eaae3d56b8d44907da3286084d3ee7b50fe7a07 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 27 Oct 2022 09:36:54 +0800 Subject: vim-patch:partial:8.2.2881: various pieces of code not covered by tests Problem: Various pieces of code not covered by tests. Solution: Add a few more tests. (Yegappan Lakshmanan, closes vim/vim#8245) https://github.com/vim/vim/commit/611728f80604dd56960e8c197e5749d203c8feb1 Only port the last two hunks of test_user_func.vim. Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_user_func.vim | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_user_func.vim b/src/nvim/testdir/test_user_func.vim index 01bf2e1d0f..98c2fdd531 100644 --- a/src/nvim/testdir/test_user_func.vim +++ b/src/nvim/testdir/test_user_func.vim @@ -420,6 +420,11 @@ func Test_del_func() call assert_fails('delfunction Xabc', 'E130:') let d = {'a' : 10} call assert_fails('delfunc d.a', 'E718:') + func d.fn() + return 1 + endfunc + delfunc d.fn + call assert_equal({'a' : 10}, d) endfunc " Test for calling return outside of a function @@ -451,11 +456,12 @@ func Test_func_dict() return len(self) endfunc - call assert_equal("{'a': 'b', 'somefunc': function('2')}", string(mydict)) + call assert_equal("{'a': 'b', 'somefunc': function('3')}", string(mydict)) call assert_equal(2, mydict.somefunc()) call assert_match("^\n function \\d\\\+() dict" \ .. "\n1 return len(self)" \ .. "\n endfunction$", execute('func mydict.somefunc')) + call assert_fails('call mydict.nonexist()', 'E716:') endfunc func Test_func_range() -- cgit From acbfbbb649c39694c3a6a92160984db2fcb6f3ec Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 27 Oct 2022 09:44:13 +0800 Subject: vim-patch:8.2.3408: can delete a numbered function Problem: Can delete a numbered function. (Naohiro Ono) Solution: Disallow deleting a numbered function. (closes vim/vim#8760) https://github.com/vim/vim/commit/ddfc05100a29263a682dd96bb924dfde4354a654 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_user_func.vim | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_user_func.vim b/src/nvim/testdir/test_user_func.vim index 98c2fdd531..7aa21d7816 100644 --- a/src/nvim/testdir/test_user_func.vim +++ b/src/nvim/testdir/test_user_func.vim @@ -423,6 +423,11 @@ func Test_del_func() func d.fn() return 1 endfunc + + " cannot delete the dict function by number + let nr = substitute(execute('echo d'), '.*function(''\(\d\+\)'').*', '\1', '') + call assert_fails('delfunction g:' .. nr, 'E475: Invalid argument: g:') + delfunc d.fn call assert_equal({'a' : 10}, d) endfunc -- cgit From b793395019333127e085997b7ced4ea02053697e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 27 Oct 2022 11:43:10 +0800 Subject: vim-patch:8.2.4070: using uninitialized memory when reading empty file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Using uninitialized memory when reading empty file. Solution: Check for empty file before checking for NL. (Dominique Pellé, closes vim/vim#9511) https://github.com/vim/vim/commit/f5d639a8af719eb8ecb141b5c0890627e4d83134 Co-authored-by: Dominique Pelle --- src/nvim/testdir/test_eval_stuff.vim | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_eval_stuff.vim b/src/nvim/testdir/test_eval_stuff.vim index dc110af356..5c60b64c22 100644 --- a/src/nvim/testdir/test_eval_stuff.vim +++ b/src/nvim/testdir/test_eval_stuff.vim @@ -120,6 +120,13 @@ func Test_readfile_binary() call delete('XReadfile_bin') endfunc +func Test_readfile_binary_empty() + call writefile([], 'Xempty-file') + " This used to compare uninitialized memory in Vim <= 8.2.4065 + call assert_equal([''], readfile('Xempty-file', 'b')) + call delete('Xempty-file') +endfunc + func Test_readfile_bom() call writefile(["\ufeffFOO", "FOO\ufeffBAR"], 'XReadfile_bom') call assert_equal(['FOO', 'FOOBAR'], readfile('XReadfile_bom')) -- cgit From 807c6bb909806b5abc3e46a9677bedfdddf2a7f0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 27 Oct 2022 11:40:38 +0800 Subject: vim-patch:8.2.4206: condition with many "(" causes a crash Problem: Condition with many "(" causes a crash. Solution: Limit recursion to 1000. https://github.com/vim/vim/commit/fe6fb267e6ee5c5da2f41889e4e0e0ac5bf4b89d Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_eval_stuff.vim | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_eval_stuff.vim b/src/nvim/testdir/test_eval_stuff.vim index 5c60b64c22..851048ec5b 100644 --- a/src/nvim/testdir/test_eval_stuff.vim +++ b/src/nvim/testdir/test_eval_stuff.vim @@ -367,6 +367,11 @@ func Test_curly_assignment() unlet g:gvar endfunc +func Test_deep_recursion() + " this was running out of stack + call assert_fails("exe 'if ' .. repeat('(', 1002)", 'E1169: Expression too recursive: ((') +endfunc + " K_SPECIAL in the modified character used be escaped, which causes " double-escaping with feedkeys() or as the return value of an mapping, " and doesn't match what getchar() returns, -- cgit From 762ca67091d13336f90350a15e0a1b965d6d5c01 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 27 Oct 2022 13:08:01 +0800 Subject: vim-patch:8.2.4234: test_garbagecollect_now() does not check v:testing Problem: test_garbagecollect_now() does not check v:testing as documented. Solution: Give an error if v:testing is not set. https://github.com/vim/vim/commit/b3d83980d2ac0f7a25314270416f17af874ca269 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_functions.vim | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index b751215b79..fa79aaf6d7 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -2206,6 +2206,12 @@ func Test_range() call assert_equal([0, 1, 2, 3, 4], uniq(range(5))) endfunc +func Test_garbagecollect_now_fails() + let v:testing = 0 + call assert_fails('call test_garbagecollect_now()', 'E1142:') + let v:testing = 1 +endfunc + " Test for the eval() function func Test_eval() call assert_fails("call eval('5 a')", 'E488:') -- cgit From feabc1c98cb077f60fde1a14e8540f2cf99eb8d2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 29 Oct 2022 09:03:15 +0800 Subject: vim-patch:9.0.0816: CTRL-Z at end of file is always dropped Problem: CTRL-Z at end of file is always dropped. Solution: Add the 'endoffile' option, like the 'endofline' option. (closes vim/vim#11408, closes vim/vim#11397) Cherry-pick test_fixeol.vim changes from patch 8.2.1432. Cherry-pick 'endoffile' changes from latest Vim runtime update. https://github.com/vim/vim/commit/fb0cf2357e0c85bbfd9f9178705ad8d77b6b3b4e vim-patch:f0b567e32a46 Revert unintended Makefile change https://github.com/vim/vim/commit/f0b567e32a462fe838170a202919d18b53eff987 vim-patch:72c8e3c070b3 Fix wrong struct access for member. https://github.com/vim/vim/commit/72c8e3c070b30f82bc0d203a62c168e43a13e99b vim-patch:3f68a4136eb9 Add missing entry for the 'endoffile' option. https://github.com/vim/vim/commit/3f68a4136eb99840d739af5133ab31948f273f63 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_fixeol.vim | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_fixeol.vim b/src/nvim/testdir/test_fixeol.vim index 32cb059e26..3ede84f49e 100644 --- a/src/nvim/testdir/test_fixeol.vim +++ b/src/nvim/testdir/test_fixeol.vim @@ -1,16 +1,17 @@ -" Tests for 'fixeol' and 'eol' +" Tests for 'fixeol', 'eof' and 'eol' + func Test_fixeol() " first write two test files – with and without trailing EOL " use Unix fileformat for consistency set ff=unix enew! - call setline('.', 'with eol') + call setline('.', 'with eol or eof') w! XXEol enew! - set noeol nofixeol - call setline('.', 'without eol') + set noeof noeol nofixeol + call setline('.', 'without eol or eof') w! XXNoEol - set eol fixeol + set eol eof fixeol bwipe XXEol XXNoEol " try editing files with 'fixeol' disabled @@ -43,6 +44,8 @@ func Test_fixeol() call delete('XXNoEol') call delete('XXTestEol') call delete('XXTestNoEol') - set ff& fixeol& eol& + set ff& fixeol& eof& eol& enew! endfunc + +" vim: shiftwidth=2 sts=2 expandtab -- cgit From 4158ad38ecb107cfe3d1dd7472cc9e17039f6ee2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 30 Oct 2022 07:56:10 +0800 Subject: vim-patch:9.0.0819: still a build error, tests are failing Problem: Still a build error, tests are failing. Solution: Correct recent changes. Add missing init for 'eof'. https://github.com/vim/vim/commit/1577537f109d97a975fda9a899cacfb598617767 vim-patch:1577537f109d Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_fixeol.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_fixeol.vim b/src/nvim/testdir/test_fixeol.vim index 3ede84f49e..9d6c900bdb 100644 --- a/src/nvim/testdir/test_fixeol.vim +++ b/src/nvim/testdir/test_fixeol.vim @@ -34,10 +34,10 @@ func Test_fixeol() w >>XXTestEol w >>XXTestNoEol - call assert_equal(['with eol', 'END'], readfile('XXEol')) - call assert_equal(['without eolEND'], readfile('XXNoEol')) - call assert_equal(['with eol', 'stays eol', 'END'], readfile('XXTestEol')) - call assert_equal(['without eol', 'stays withoutEND'], + call assert_equal(['with eol or eof', 'END'], readfile('XXEol')) + call assert_equal(['without eol or eofEND'], readfile('XXNoEol')) + call assert_equal(['with eol or eof', 'stays eol', 'END'], readfile('XXTestEol')) + call assert_equal(['without eol or eof', 'stays withoutEND'], \ readfile('XXTestNoEol')) call delete('XXEol') -- cgit From d8dbf58b4372d1415e3ca69541fc6fe71890ba53 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 1 Nov 2022 07:29:55 +0800 Subject: vim-patch:9.0.0821: crash with win_move_statusline() in another tabpage (#20894) vim-patch:86e6717ace4f Problem: Crash when using win_move_statusline() in another tab page. Solution: Check for valid window pointer. (issue vim/vim#11427) https://github.com/vim/vim/commit/86e6717ace4f5e00eaeb84b59e3fc92bca548155 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_window_cmd.vim | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim index e01993b99c..902a3791d4 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -1459,17 +1459,20 @@ func Test_win_move_statusline() call assert_true(id->win_move_statusline(-offset)) call assert_equal(h, winheight(id)) endfor + " check that win_move_statusline doesn't error with offsets beyond moving " possibility call assert_true(win_move_statusline(id, 5000)) call assert_true(winheight(id) > h) call assert_true(win_move_statusline(id, -5000)) call assert_true(winheight(id) < h) + " check that win_move_statusline returns false for an invalid window wincmd = let h = winheight(0) call assert_false(win_move_statusline(-1, 1)) call assert_equal(h, winheight(0)) + " check that win_move_statusline returns false for a floating window let id = nvim_open_win( \ 0, 0, #{relative: 'editor', row: 2, col: 2, width: 5, height: 3}) @@ -1477,6 +1480,13 @@ func Test_win_move_statusline() call assert_false(win_move_statusline(id, 1)) call assert_equal(h, winheight(id)) call nvim_win_close(id, 1) + + " check that using another tabpage fails without crash + let id = win_getid() + tabnew + call assert_fails('call win_move_statusline(id, -1)', 'E1308:') + tabclose + %bwipe! endfunc -- cgit From c46d46e9f11a9960fcf9c498ecc72be4c416cfa5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 1 Nov 2022 20:21:48 +0800 Subject: vim-patch:8.2.2343: Vim9: return type of readfile() is any (#20896) Problem: Vim9: return type of readfile() is any. Solution: Add readblob() so that readfile() can be expected to always return a list of strings. (closes vim/vim#7671) https://github.com/vim/vim/commit/c423ad77ed763c11ba67729bbf63c1cf0915231f Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_mksession.vim | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_mksession.vim b/src/nvim/testdir/test_mksession.vim index ccc775560f..9cf80f631c 100644 --- a/src/nvim/testdir/test_mksession.vim +++ b/src/nvim/testdir/test_mksession.vim @@ -851,9 +851,7 @@ func Test_mksession_shortmess_with_A() edit Xtestfile write let fname = swapname('%') - " readblob() needs patch 8.2.2343 - " let cont = readblob(fname) - let cont = readfile(fname, 'B') + let cont = readblob(fname) set sessionoptions-=options mksession Xtestsession bwipe! -- cgit From 41f308feab35007534f0c213947701174d60c548 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 2 Nov 2022 08:02:52 +0800 Subject: vim-patch:9.0.0826: if 'endofline' is set CTRL-Z may be written in a wrong place (#20903) Problem: If 'endofline' is set the CTRL-Z may be written in the wrong place. Solution: Write CTRL-Z at the end of the file. Update the help to explain the possibilities better. (Ken Takata, closes vim/vim#11486) https://github.com/vim/vim/commit/3af982196b1b973e953c35351961f2a96fe34172 Co-authored-by: K.Takata --- src/nvim/testdir/test_fixeol.vim | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_fixeol.vim b/src/nvim/testdir/test_fixeol.vim index 9d6c900bdb..41d47d6a06 100644 --- a/src/nvim/testdir/test_fixeol.vim +++ b/src/nvim/testdir/test_fixeol.vim @@ -48,4 +48,71 @@ func Test_fixeol() enew! endfunc +func Test_eof() + let data = 0z68656c6c6f.0d0a.776f726c64 " "hello\r\nworld" + + " 1. Eol, Eof + " read + call writefile(data + 0z0d0a.1a, 'XXEolEof') + e! XXEolEof + call assert_equal(['hello', 'world'], getline(1, 2)) + call assert_equal([1, 1], [&eol, &eof]) + " write + set fixeol + w! + call assert_equal(data + 0z0d0a, readblob('XXEolEof')) + set nofixeol + w! + call assert_equal(data + 0z0d0a.1a, readblob('XXEolEof')) + + " 2. NoEol, Eof + " read + call writefile(data + 0z1a, 'XXNoEolEof') + e! XXNoEolEof + call assert_equal(['hello', 'world'], getline(1, 2)) + call assert_equal([0, 1], [&eol, &eof]) + " write + set fixeol + w! + call assert_equal(data + 0z0d0a, readblob('XXNoEolEof')) + set nofixeol + w! + call assert_equal(data + 0z1a, readblob('XXNoEolEof')) + + " 3. Eol, NoEof + " read + call writefile(data + 0z0d0a, 'XXEolNoEof') + e! XXEolNoEof + call assert_equal(['hello', 'world'], getline(1, 2)) + call assert_equal([1, 0], [&eol, &eof]) + " write + set fixeol + w! + call assert_equal(data + 0z0d0a, readblob('XXEolNoEof')) + set nofixeol + w! + call assert_equal(data + 0z0d0a, readblob('XXEolNoEof')) + + " 4. NoEol, NoEof + " read + call writefile(data, 'XXNoEolNoEof') + e! XXNoEolNoEof + call assert_equal(['hello', 'world'], getline(1, 2)) + call assert_equal([0, 0], [&eol, &eof]) + " write + set fixeol + w! + call assert_equal(data + 0z0d0a, readblob('XXNoEolNoEof')) + set nofixeol + w! + call assert_equal(data, readblob('XXNoEolNoEof')) + + call delete('XXEolEof') + call delete('XXNoEolEof') + call delete('XXEolNoEof') + call delete('XXNoEolNoEof') + set ff& fixeol& eof& eol& + enew! +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From a600e73007a2cc9ced7eeaeb5f8c05ac454d080e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 1 Nov 2022 07:13:02 +0800 Subject: vim-patch:9.0.0822: crash when dragging the statusline with a mapping Problem: Crash when dragging the statusline with a mapping. Solution: Check for valid window pointer. (issue vim/vim#11427) https://github.com/vim/vim/commit/8ab9ca93eea32b318235384720200771863ecaee Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_mapping.vim | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_mapping.vim b/src/nvim/testdir/test_mapping.vim index 2d8c45210b..a286774d56 100644 --- a/src/nvim/testdir/test_mapping.vim +++ b/src/nvim/testdir/test_mapping.vim @@ -1050,6 +1050,24 @@ func Test_mouse_drag_mapped_start_select() set mouse& endfunc +func Test_mouse_drag_statusline() + set laststatus=2 + set mouse=a + func ClickExpr() + call Ntest_setmouse(&lines - 1, 1) + return "\" + endfunc + func DragExpr() + call Ntest_setmouse(&lines - 2, 1) + return "\" + endfunc + nnoremap ClickExpr() + nnoremap DragExpr() + + " this was causing a crash in win_drag_status_line() + call feedkeys("\:tabnew\\", 'tx') +endfunc + " Test for mapping in Insert mode func Test_mouse_drag_insert_map() set mouse=a -- cgit From 39f85cdf6b40cbdd26256260d0d6d4e071b631a2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 1 Nov 2022 20:22:48 +0800 Subject: vim-patch:9.0.0824: crash when using win_move_separator() in other tab page Problem: Crash when using win_move_separator() in other tab page. Solution: Check for valid window in current tab page. (closes vim/vim#11479, closes vim/vim#11427) https://github.com/vim/vim/commit/873f41a0187e81a22aa4622fbf938de72a54abba --- src/nvim/testdir/test_mapping.vim | 14 ++++++++++---- src/nvim/testdir/test_window_cmd.vim | 10 ++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_mapping.vim b/src/nvim/testdir/test_mapping.vim index a286774d56..560883ba5d 100644 --- a/src/nvim/testdir/test_mapping.vim +++ b/src/nvim/testdir/test_mapping.vim @@ -1054,18 +1054,24 @@ func Test_mouse_drag_statusline() set laststatus=2 set mouse=a func ClickExpr() - call Ntest_setmouse(&lines - 1, 1) - return "\" + call Ntest_setmouse(&lines - 1, 1) + return "\" endfunc func DragExpr() - call Ntest_setmouse(&lines - 2, 1) - return "\" + call Ntest_setmouse(&lines - 2, 1) + return "\" endfunc nnoremap ClickExpr() nnoremap DragExpr() " this was causing a crash in win_drag_status_line() call feedkeys("\:tabnew\\", 'tx') + + nunmap + nunmap + delfunc ClickExpr + delfunc DragExpr + set laststatus& mouse& endfunc " Test for mapping in Insert mode diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim index 902a3791d4..f38eaaf318 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -1393,17 +1393,20 @@ func Test_win_move_separator() call assert_equal(w0, winwidth(0)) call assert_true(win_move_separator(0, -1)) call assert_equal(w0, winwidth(0)) + " check that win_move_separator doesn't error with offsets beyond moving " possibility call assert_true(win_move_separator(id, 5000)) call assert_true(winwidth(id) > w) call assert_true(win_move_separator(id, -5000)) call assert_true(winwidth(id) < w) + " check that win_move_separator returns false for an invalid window wincmd = let w = winwidth(0) call assert_false(win_move_separator(-1, 1)) call assert_equal(w, winwidth(0)) + " check that win_move_separator returns false for a floating window let id = nvim_open_win( \ 0, 0, #{relative: 'editor', row: 2, col: 2, width: 5, height: 3}) @@ -1411,6 +1414,13 @@ func Test_win_move_separator() call assert_false(win_move_separator(id, 1)) call assert_equal(w, winwidth(id)) call nvim_win_close(id, 1) + + " check that using another tabpage fails without crash + let id = win_getid() + tabnew + call assert_fails('call win_move_separator(id, -1)', 'E1308:') + tabclose + %bwipe! endfunc -- cgit From 4716a578ae0c3516d685495bb55e40c939a4ac87 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 23 Oct 2022 10:17:45 +0200 Subject: docs: fix typos --- src/nvim/testdir/test_options.vim | 2 +- src/nvim/testdir/test_vimscript.vim | 2 +- src/nvim/testdir/test_window_cmd.vim | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index 2836e81c4a..3916d7c554 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -263,7 +263,7 @@ func Test_set_completion() call feedkeys(":setglobal di\\\"\", 'tx') call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:) - " Expand boolan options. When doing :set no + " Expand boolean options. When doing :set no " vim displays the options names without "no" but completion uses "no...". call feedkeys(":set nodi\\\"\", 'tx') call assert_equal('"set nodiff digraph', @:) diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index f20fd12ed3..bd60dcb707 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -1443,7 +1443,7 @@ endfunc " Undefined behavior was detected by ubsan with line continuation " after an empty line. "------------------------------------------------------------------------------- -func Test_script_emty_line_continuation() +func Test_script_empty_line_continuation() \ endfunc diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim index f38eaaf318..909db3a1bb 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -1214,7 +1214,7 @@ endfunc " Test for jumping to a vertical/horizontal neighbor window based on the " current cursor position -func Test_window_goto_neightbor() +func Test_window_goto_neighbor() %bw! " Vertical window movement -- cgit From 24fa5f70edd4cc3b613237283ee7d63af1948c16 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 4 Nov 2022 18:17:26 +0800 Subject: vim-patch:8.2.0448: various functions not properly tested (#20926) Problem: Various functions not properly tested. Solution: Add more tests, especially for failures. (Yegappan Lakshmanan, closes vim/vim#5843) https://github.com/vim/vim/commit/0e05de46226eb4e5ea580beefa71831f92d613d3 Cherry-pick test changes from patch 8.2.0427 and skip Test_has(). Cherry-pick Test_complete_wildmenu() change from patch 8.2.4339. --- src/nvim/testdir/check.vim | 3 ++ src/nvim/testdir/test_blob.vim | 2 + src/nvim/testdir/test_breakindent.vim | 1 + src/nvim/testdir/test_cmdline.vim | 7 ++++ src/nvim/testdir/test_exists.vim | 6 +++ src/nvim/testdir/test_expand_func.vim | 1 + src/nvim/testdir/test_expr.vim | 5 +++ src/nvim/testdir/test_functions.vim | 76 ++++++++++++++++++++++++++++++++++- src/nvim/testdir/test_listdict.vim | 8 ++++ src/nvim/testdir/test_marks.vim | 2 + src/nvim/testdir/test_partial.vim | 5 +++ src/nvim/testdir/test_registers.vim | 14 +++++++ src/nvim/testdir/test_spell.vim | 2 + src/nvim/testdir/test_substitute.vim | 5 +++ src/nvim/testdir/test_syntax.vim | 2 + src/nvim/testdir/test_taglist.vim | 2 + src/nvim/testdir/test_utf8.vim | 2 + src/nvim/testdir/test_vartabs.vim | 2 + src/nvim/testdir/test_window_cmd.vim | 1 + 19 files changed, 145 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/check.vim b/src/nvim/testdir/check.vim index 92a51d4371..1459b70243 100644 --- a/src/nvim/testdir/check.vim +++ b/src/nvim/testdir/check.vim @@ -4,6 +4,9 @@ source term_util.vim " Command to check for the presence of a feature. command -nargs=1 CheckFeature call CheckFeature() func CheckFeature(name) + " if !has(a:name, 1) + " throw 'Checking for non-existent feature ' .. a:name + " endif if !has(a:name) throw 'Skipped: ' .. a:name .. ' feature missing' endif diff --git a/src/nvim/testdir/test_blob.vim b/src/nvim/testdir/test_blob.vim index 770b2d16ef..151de71312 100644 --- a/src/nvim/testdir/test_blob.vim +++ b/src/nvim/testdir/test_blob.vim @@ -300,6 +300,8 @@ func Test_blob_index() call assert_equal(3, 0z11110111->index(0x11, 2)) call assert_equal(2, index(0z11111111, 0x11, -2)) call assert_equal(3, index(0z11110111, 0x11, -2)) + call assert_equal(0, index(0z11110111, 0x11, -10)) + call assert_fails("echo index(0z11110111, 0x11, [])", 'E745:') call assert_fails('call index("asdf", 0)', 'E897:') endfunc diff --git a/src/nvim/testdir/test_breakindent.vim b/src/nvim/testdir/test_breakindent.vim index ed4d886fd1..69c98f1f05 100644 --- a/src/nvim/testdir/test_breakindent.vim +++ b/src/nvim/testdir/test_breakindent.vim @@ -421,6 +421,7 @@ func Test_breakindent11() let width = strlen(text[1:]) + indent(2) + strlen(&sbr) * 3 " text wraps 3 times call assert_equal(width, strdisplaywidth(text)) call s:close_windows('set sbr=') + call assert_equal(4, strdisplaywidth("\t", 4)) endfunc func Test_breakindent11_vartabs() diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 00bfadec93..27ac91e49f 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -89,6 +89,13 @@ func Test_complete_wildmenu() call assert_equal('"e Xtestfile3 Xtestfile4', @:) cd - + cnoremap wildmenumode() + call feedkeys(":cd Xdir\\\\"\", 'tx') + call assert_equal('"cd Xdir1/0', @:) + call feedkeys(":e Xdir1/\\\\"\", 'tx') + call assert_equal('"e Xdir1/Xdir2/1', @:) + cunmap + " cleanup %bwipe call delete('Xdir1/Xdir2/Xtestfile4') diff --git a/src/nvim/testdir/test_exists.vim b/src/nvim/testdir/test_exists.vim index 471c77853d..62c66192ef 100644 --- a/src/nvim/testdir/test_exists.vim +++ b/src/nvim/testdir/test_exists.vim @@ -68,6 +68,10 @@ func Test_exists() " Existing environment variable let $EDITOR_NAME = 'Vim Editor' call assert_equal(1, exists('$EDITOR_NAME')) + if has('unix') + " ${name} environment variables are supported only on Unix-like systems + call assert_equal(1, exists('${VIM}')) + endif " Non-existing environment variable call assert_equal(0, exists('$NON_ENV_VAR')) @@ -323,3 +327,5 @@ endfunc func Test_exists_funcarg() call FuncArg_Tests("arg1", "arg2") endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_expand_func.vim b/src/nvim/testdir/test_expand_func.vim index 80bfdb8553..454d76f0aa 100644 --- a/src/nvim/testdir/test_expand_func.vim +++ b/src/nvim/testdir/test_expand_func.vim @@ -139,6 +139,7 @@ func Test_expand_wildignore() call assert_equal('test_expand_func.vim', expand('test_expand_func.vim', 1)) call assert_equal(['test_expand_func.vim'], \ expand('test_expand_func.vim', 1, 1)) + call assert_fails("call expand('*', [])", 'E745:') set wildignore& endfunc diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 66660ab75e..00ea4275ab 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -65,6 +65,8 @@ func Test_strgetchar() call assert_equal(-1, strgetchar('axb', -1)) call assert_equal(-1, strgetchar('axb', 3)) call assert_equal(-1, strgetchar('', 0)) + call assert_fails("let c=strgetchar([], 1)", 'E730:') + call assert_fails("let c=strgetchar('axb', [])", 'E745:') endfunc func Test_strcharpart() @@ -502,6 +504,9 @@ func Test_substitute_expr() endfunc " recursive call works call assert_equal('-y-x-', substitute('xxx', 'x\(.\)x', {-> '-' . Recurse() . '-' . submatch(1) . '-'}, '')) + + call assert_fails("let s=submatch([])", 'E745:') + call assert_fails("let s=submatch(2, [])", 'E745:') endfunc func Test_invalid_submatch() diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index fa79aaf6d7..f6c16a366b 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -19,6 +19,25 @@ func Test_00_bufexists() call assert_equal(0, bufexists('Xfoo')) endfunc +func Test_has() + throw 'Skipped: Nvim has removed some features' + call assert_equal(1, has('eval')) + call assert_equal(1, has('eval', 1)) + + if has('unix') + call assert_equal(1, or(has('ttyin'), 1)) + call assert_equal(0, and(has('ttyout'), 0)) + call assert_equal(1, has('multi_byte_encoding')) + endif + + call assert_equal(0, has('nonexistent')) + call assert_equal(0, has('nonexistent', 1)) + + " Will we ever have patch 9999? + let ver = 'patch-' .. v:version / 100 .. '.' .. v:version % 100 .. '.9999' + call assert_equal(0, has(ver)) +endfunc + func Test_empty() call assert_equal(1, empty('')) call assert_equal(0, empty('a')) @@ -383,6 +402,8 @@ func Test_strpart() call assert_equal('abcdefg', 'abcdefg'->strpart(-2)) call assert_equal('fg', strpart('abcdefg', 5, 4)) call assert_equal('defg', strpart('abcdefg', 3)) + call assert_equal('', strpart('abcdefg', 10)) + call assert_fails("let s=strpart('abcdef', [])", 'E745:') call assert_equal('lép', strpart('éléphant', 2, 4)) call assert_equal('léphant', strpart('éléphant', 2)) @@ -552,6 +573,15 @@ endfunc func Test_tr() call assert_equal('foo', tr('bar', 'bar', 'foo')) call assert_equal('zxy', 'cab'->tr('abc', 'xyz')) + call assert_fails("let s=tr([], 'abc', 'def')", 'E730:') + call assert_fails("let s=tr('abc', [], 'def')", 'E730:') + call assert_fails("let s=tr('abc', 'abc', [])", 'E730:') + call assert_fails("let s=tr('abcd', 'abcd', 'def')", 'E475:') + " set encoding=latin1 + call assert_fails("let s=tr('abcd', 'abcd', 'def')", 'E475:') + call assert_equal('hEllO', tr('hello', 'eo', 'EO')) + call assert_equal('hello', tr('hello', 'xy', 'ab')) + set encoding=utf8 endfunc " Tests for the mode() function @@ -851,6 +881,8 @@ func Test_stridx() call assert_equal(-1, stridx('hello', 'l', 10)) call assert_equal(2, stridx('hello', 'll')) call assert_equal(-1, stridx('hello', 'hello world')) + call assert_fails("let n=stridx('hello', [])", 'E730:') + call assert_fails("let n=stridx([], 'l')", 'E730:') endfunc func Test_strridx() @@ -867,6 +899,8 @@ func Test_strridx() call assert_equal(-1, strridx('hello', 'l', -1)) call assert_equal(2, strridx('hello', 'll')) call assert_equal(-1, strridx('hello', 'hello world')) + call assert_fails("let n=strridx('hello', [])", 'E730:') + call assert_fails("let n=strridx([], 'l')", 'E730:') endfunc func Test_match_func() @@ -876,6 +910,11 @@ func Test_match_func() call assert_equal(-1, match('testing', 'ing', 8)) call assert_equal(1, match(['vim', 'testing', 'execute'], 'ing')) call assert_equal(-1, match(['vim', 'testing', 'execute'], 'img')) + call assert_fails("let x=match('vim', [])", 'E730:') + call assert_equal(3, match(['a', 'b', 'c', 'a'], 'a', 1)) + call assert_equal(-1, match(['a', 'b', 'c', 'a'], 'a', 5)) + call assert_equal(4, match('testing', 'ing', -1)) + call assert_fails("let x=match('testing', 'ing', 0, [])", 'E745:') endfunc func Test_matchend() @@ -982,6 +1021,7 @@ func Test_byte2line_line2byte() bw! endfunc +" Test for byteidx() and byteidxcomp() functions func Test_byteidx() let a = '.é.' " one char of two bytes call assert_equal(0, byteidx(a, 0)) @@ -1001,6 +1041,7 @@ func Test_byteidx() call assert_equal(4, b->byteidx(2)) call assert_equal(5, b->byteidx(3)) call assert_equal(-1, b->byteidx(4)) + call assert_fails("call byteidx([], 0)", 'E730:') call assert_equal(0, b->byteidxcomp(0)) call assert_equal(1, b->byteidxcomp(1)) @@ -1008,6 +1049,7 @@ func Test_byteidx() call assert_equal(4, b->byteidxcomp(3)) call assert_equal(5, b->byteidxcomp(4)) call assert_equal(-1, b->byteidxcomp(5)) + call assert_fails("call byteidxcomp([], 0)", 'E730:') endfunc " Test for charidx() @@ -1230,6 +1272,22 @@ func Test_col() xunmap delfunc T + " Test for the visual line start and end marks '< and '> + call setline(1, ['one', 'one two', 'one two three']) + "normal! ggVG + call feedkeys("ggVG\", 'xt') + call assert_equal(1, col("'<")) + call assert_equal(14, col("'>")) + " Delete the last line of the visually selected region + $d + call assert_notequal(14, col("'>")) + + " Test with 'virtualedit' + set virtualedit=all + call cursor(1, 10) + call assert_equal(4, col('.')) + set virtualedit& + bw! endfunc @@ -1763,7 +1821,7 @@ func Test_confirm() call assert_equal(2, a) " confirm() should return 0 when pressing CTRL-C. - call feedkeys("\", 'L') + call feedkeys("\", 'L') let a = confirm('Are you sure?', "&Yes\n&No") call assert_equal(0, a) @@ -1871,6 +1929,9 @@ endfunc func Test_char2nr() call assert_equal(12354, char2nr('あ', 1)) call assert_equal(120, 'x'->char2nr()) + " set encoding=latin1 + call assert_equal(120, 'x'->char2nr()) + set encoding=utf-8 endfunc func Test_charclass() @@ -2043,6 +2104,7 @@ func Test_range() " index() call assert_equal(1, index(range(1, 5), 2)) + call assert_fails("echo index([1, 2], 1, [])", 'E745:') " inputlist() call feedkeys(":let result = inputlist(range(10))\1\", 'x') @@ -2204,6 +2266,11 @@ func Test_range() " uniq() call assert_equal([0, 1, 2, 3, 4], uniq(range(5))) + + " errors + call assert_fails('let x=range(2, 8, 0)', 'E726:') + call assert_fails('let x=range(3, 1)', 'E727:') + call assert_fails('let x=range(1, 3, -2)', 'E727:') endfunc func Test_garbagecollect_now_fails() @@ -2255,6 +2322,13 @@ func Test_nr2char() call assert_equal("\x80\xfc\b" .. nr2char(0x40000000), eval('"\"')) endfunc +" Test for screenattr(), screenchar() and screenchars() functions +func Test_screen_functions() + call assert_equal(-1, screenattr(-1, -1)) + call assert_equal(-1, screenchar(-1, -1)) + call assert_equal([], screenchars(-1, -1)) +endfunc + " Test for getcurpos() and setpos() func Test_getcurpos_setpos() new diff --git a/src/nvim/testdir/test_listdict.vim b/src/nvim/testdir/test_listdict.vim index f7261b2055..1ecdcd2157 100644 --- a/src/nvim/testdir/test_listdict.vim +++ b/src/nvim/testdir/test_listdict.vim @@ -341,6 +341,7 @@ func Test_dict_deepcopy() let l[1] = l2 let l3 = deepcopy(l2) call assert_true(l3[1] is l3[2]) + call assert_fails("call deepcopy([1, 2], 2)", 'E474:') endfunc " Locked variables @@ -420,6 +421,11 @@ func Test_list_locked_var() call assert_equal(expected[depth][u][1], ps) endfor endfor + call assert_fails("let x=islocked('a b')", 'E488:') + let mylist = [1, 2, 3] + call assert_fails("let x = islocked('mylist[1:2]')", 'E786:') + let mydict = {'k' : 'v'} + call assert_fails("let x = islocked('mydict.a')", 'E716:') endfunc " Unletting locked variables @@ -736,6 +742,8 @@ func Test_str_split() call assert_equal(['aa', '', 'bb', 'cc', ''], split('aa,,bb, cc,', ',\s*', 1)) call assert_equal(['a', 'b', 'c'], split('abc', '\zs')) call assert_equal(['', 'a', '', 'b', '', 'c', ''], split('abc', '\zs', 1)) + call assert_fails("call split('abc', [])", 'E730:') + call assert_fails("call split('abc', 'b', [])", 'E745:') endfunc " compare recursively linked list and dict diff --git a/src/nvim/testdir/test_marks.vim b/src/nvim/testdir/test_marks.vim index 054ebf1218..b432b7bbbc 100644 --- a/src/nvim/testdir/test_marks.vim +++ b/src/nvim/testdir/test_marks.vim @@ -100,6 +100,8 @@ func Test_setpos() call setpos('.', [0, 1, -1, 0]) call assert_equal([2, 2], [line('.'), col('.')]) + call assert_fails("call setpos('ab', [0, 1, 1, 0])", 'E474:') + bwipe! call win_gotoid(twowin) bwipe! diff --git a/src/nvim/testdir/test_partial.vim b/src/nvim/testdir/test_partial.vim index 8c90f21600..3020668f1b 100644 --- a/src/nvim/testdir/test_partial.vim +++ b/src/nvim/testdir/test_partial.vim @@ -82,6 +82,9 @@ func Test_partial_dict() let dict = {"tr": function('tr', ['hello', 'h', 'H'])} call assert_equal("Hello", dict.tr()) + + call assert_fails("let F=function('setloclist', 10)", "E923:") + call assert_fails("let F=function('setloclist', [], [])", "E922:") endfunc func Test_partial_implicit() @@ -354,3 +357,5 @@ func Test_compare_partials() call assert_true(F1 isnot# F1d1) " Partial /= non-partial call assert_true(d1.f1 isnot# d1.f1) " handle_subscript creates new partial each time endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_registers.vim b/src/nvim/testdir/test_registers.vim index 11dd3badb6..40320c6405 100644 --- a/src/nvim/testdir/test_registers.vim +++ b/src/nvim/testdir/test_registers.vim @@ -263,8 +263,16 @@ func Test_get_register() call assert_equal('', getreg("\")) call assert_equal('', getreg("\")) call assert_equal('', getreg("\")) + " Change the last used register to '"' for the next test + normal! ""yy + let @" = 'happy' + call assert_equal('happy', getreg()) + call assert_equal('happy', getreg('')) call assert_equal('', getregtype('!')) + call assert_fails('echo getregtype([])', 'E730:') + call assert_equal('v', getregtype()) + call assert_equal('v', getregtype('')) " Test for inserting an invalid register content call assert_beeps('exe "normal i\!"') @@ -349,6 +357,12 @@ func Test_set_register() normal 0".gP call assert_equal('abcabcabc', getline(1)) + let @"='' + call setreg('', '1') + call assert_equal('1', @") + call setreg('@', '2') + call assert_equal('2', @") + enew! endfunc diff --git a/src/nvim/testdir/test_spell.vim b/src/nvim/testdir/test_spell.vim index 4af02d3d31..f7144bbc7e 100644 --- a/src/nvim/testdir/test_spell.vim +++ b/src/nvim/testdir/test_spell.vim @@ -1430,3 +1430,5 @@ let g:test_data_aff_sal = [ \"SAL ZZ- _", \"SAL Z S", \ ] + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_substitute.vim b/src/nvim/testdir/test_substitute.vim index 88a3c13d65..2a8a925fdb 100644 --- a/src/nvim/testdir/test_substitute.vim +++ b/src/nvim/testdir/test_substitute.vim @@ -453,6 +453,11 @@ func Test_substitute_errors() setl nomodifiable call assert_fails('s/foo/bar/', 'E21:') + call assert_fails("let s=substitute([], 'a', 'A', 'g')", 'E730:') + call assert_fails("let s=substitute('abcda', [], 'A', 'g')", 'E730:') + call assert_fails("let s=substitute('abcda', 'a', [], 'g')", 'E730:') + call assert_fails("let s=substitute('abcda', 'a', 'A', [])", 'E730:') + bwipe! endfunc diff --git a/src/nvim/testdir/test_syntax.vim b/src/nvim/testdir/test_syntax.vim index d686ad7e96..9903b48dbe 100644 --- a/src/nvim/testdir/test_syntax.vim +++ b/src/nvim/testdir/test_syntax.vim @@ -623,6 +623,8 @@ func Test_synstack_synIDtrans() call assert_equal(['cComment', 'cTodo'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")')) call assert_equal(['Comment', 'Todo'], map(synstack(line("."), col(".")), 'synIDattr(synIDtrans(v:val), "name")')) + call assert_fails("let n=synIDtrans([])", 'E745:') + syn clear bw! endfunc diff --git a/src/nvim/testdir/test_taglist.vim b/src/nvim/testdir/test_taglist.vim index be46773256..0c47fc9445 100644 --- a/src/nvim/testdir/test_taglist.vim +++ b/src/nvim/testdir/test_taglist.vim @@ -36,6 +36,8 @@ func Test_taglist() call assert_equal('d', cmd[0]['kind']) call assert_equal('call cursor(3, 4)', cmd[0]['cmd']) + call assert_fails("let l=taglist([])", 'E730:') + call delete('Xtags') set tags& bwipe diff --git a/src/nvim/testdir/test_utf8.vim b/src/nvim/testdir/test_utf8.vim index 7145d303cc..2fced0dd2f 100644 --- a/src/nvim/testdir/test_utf8.vim +++ b/src/nvim/testdir/test_utf8.vim @@ -21,6 +21,8 @@ func Test_strchars() call assert_equal(exp[i][1], inp[i]->strchars(0)) call assert_equal(exp[i][2], strchars(inp[i], 1)) endfor + call assert_fails("let v=strchars('abc', [])", 'E474:') + call assert_fails("let v=strchars('abc', 2)", 'E474:') endfunc " Test for customlist completion diff --git a/src/nvim/testdir/test_vartabs.vim b/src/nvim/testdir/test_vartabs.vim index 32ad64cda4..e12c71d521 100644 --- a/src/nvim/testdir/test_vartabs.vim +++ b/src/nvim/testdir/test_vartabs.vim @@ -379,6 +379,8 @@ func Test_vartabs_shiftwidth() let lines = ScreenLines([1, 3], winwidth(0)) call s:compare_lines(expect4, lines) + call assert_fails('call shiftwidth([])', 'E745:') + " cleanup bw! bw! diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim index 909db3a1bb..2ed537c601 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -542,6 +542,7 @@ func Test_window_newtab() call assert_equal(2, tabpagenr('$')) call assert_equal(['Xb', 'Xa'], map(tabpagebuflist(1), 'bufname(v:val)')) call assert_equal(['Xc' ], map(2->tabpagebuflist(), 'bufname(v:val)')) + call assert_equal(['Xc' ], map(tabpagebuflist(), 'bufname(v:val)')) %bw! endfunc -- cgit From dce3fc3e9a455426a45db072f28604b1bc63680a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 4 Nov 2022 19:31:58 +0800 Subject: vim-patch:8.2.0540: regexp and other code not tested (#20930) Problem: Regexp and other code not tested. Solution: Add more tests. (Yegappan Lakshmanan, closes vim/vim#5904) https://github.com/vim/vim/commit/004a6781b3cf15ca5dd632c38cc09bb3b253d1f8 --- src/nvim/testdir/samples/re.freeze.txt | 6 ++ src/nvim/testdir/test_expr.vim | 46 -------------- src/nvim/testdir/test_increment.vim | 18 ++++-- src/nvim/testdir/test_normal.vim | 111 ++++++++++++++++++++++----------- src/nvim/testdir/test_regexp_latin.vim | 6 ++ src/nvim/testdir/test_search.vim | 19 ++++++ src/nvim/testdir/test_substitute.vim | 75 ++++++++++++++++++++++ src/nvim/testdir/test_virtualedit.vim | 11 ++++ 8 files changed, 207 insertions(+), 85 deletions(-) create mode 100644 src/nvim/testdir/samples/re.freeze.txt (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/samples/re.freeze.txt b/src/nvim/testdir/samples/re.freeze.txt new file mode 100644 index 0000000000..d768c23c5e --- /dev/null +++ b/src/nvim/testdir/samples/re.freeze.txt @@ -0,0 +1,6 @@ +:set re=0 or 2 +Search for the pattern: /\s\+\%#\@55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555 + diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 00ea4275ab..dc8401003d 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -487,52 +487,6 @@ function Test_max_min_errors() call assert_fails('call min(v:true)', 'min()') endfunc -func Test_substitute_expr() - let g:val = 'XXX' - call assert_equal('XXX', substitute('yyy', 'y*', '\=g:val', '')) - call assert_equal('XXX', substitute('yyy', 'y*', {-> g:val}, '')) - call assert_equal("-\u1b \uf2-", substitute("-%1b %f2-", '%\(\x\x\)', - \ '\=nr2char("0x" . submatch(1))', 'g')) - call assert_equal("-\u1b \uf2-", substitute("-%1b %f2-", '%\(\x\x\)', - \ {-> nr2char("0x" . submatch(1))}, 'g')) - - call assert_equal('231', substitute('123', '\(.\)\(.\)\(.\)', - \ {-> submatch(2) . submatch(3) . submatch(1)}, '')) - - func Recurse() - return substitute('yyy', 'y\(.\)y', {-> submatch(1)}, '') - endfunc - " recursive call works - call assert_equal('-y-x-', substitute('xxx', 'x\(.\)x', {-> '-' . Recurse() . '-' . submatch(1) . '-'}, '')) - - call assert_fails("let s=submatch([])", 'E745:') - call assert_fails("let s=submatch(2, [])", 'E745:') -endfunc - -func Test_invalid_submatch() - " This was causing invalid memory access in Vim-7.4.2232 and older - call assert_fails("call substitute('x', '.', {-> submatch(10)}, '')", 'E935:') -endfunc - -func Test_substitute_expr_arg() - call assert_equal('123456789-123456789=', substitute('123456789', - \ '\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', - \ {m -> m[0] . '-' . m[1] . m[2] . m[3] . m[4] . m[5] . m[6] . m[7] . m[8] . m[9] . '='}, '')) - - call assert_equal('123456-123456=789', substitute('123456789', - \ '\(.\)\(.\)\(.\)\(a*\)\(n*\)\(.\)\(.\)\(.\)\(x*\)', - \ {m -> m[0] . '-' . m[1] . m[2] . m[3] . m[4] . m[5] . m[6] . m[7] . m[8] . m[9] . '='}, '')) - - call assert_equal('123456789-123456789x=', substitute('123456789', - \ '\(.\)\(.\)\(.*\)', - \ {m -> m[0] . '-' . m[1] . m[2] . m[3] . 'x' . m[4] . m[5] . m[6] . m[7] . m[8] . m[9] . '='}, '')) - - call assert_fails("call substitute('xxx', '.', {m -> string(add(m, 'x'))}, '')", 'E742:') - call assert_fails("call substitute('xxx', '.', {m -> string(insert(m, 'x'))}, '')", 'E742:') - call assert_fails("call substitute('xxx', '.', {m -> string(extend(m, ['x']))}, '')", 'E742:') - call assert_fails("call substitute('xxx', '.', {m -> string(remove(m, 1))}, '')", 'E742:') -endfunc - func Test_function_with_funcref() let s:f = function('type') let s:fref = function(s:f) diff --git a/src/nvim/testdir/test_increment.vim b/src/nvim/testdir/test_increment.vim index 2559654f25..52355d86fb 100644 --- a/src/nvim/testdir/test_increment.vim +++ b/src/nvim/testdir/test_increment.vim @@ -476,6 +476,10 @@ func Test_visual_increment_20() exec "norm! \" call assert_equal(["b"], getline(1, '$')) call assert_equal([0, 1, 1, 0], getpos('.')) + " decrement a and A and increment z and Z + call setline(1, ['a', 'A', 'z', 'Z']) + exe "normal 1G\2G\3G\4G\" + call assert_equal(['a', 'A', 'z', 'Z'], getline(1, '$')) endfunc " 21) block-wise increment on part of hexadecimal @@ -566,12 +570,14 @@ endfunc " 1) " 0b11111111111111111111111111111111 func Test_visual_increment_26() - set nrformats+=alpha + set nrformats+=bin call setline(1, ["0b11111111111111111111111111111110"]) exec "norm! \$\" call assert_equal(["0b11111111111111111111111111111111"], getline(1, '$')) call assert_equal([0, 1, 1, 0], getpos('.')) - set nrformats-=alpha + exec "norm! \$\" + call assert_equal(["0b11111111111111111111111111111110"], getline(1, '$')) + set nrformats-=bin endfunc " 27) increment with 'rightreft', if supported @@ -772,7 +778,6 @@ func Test_normal_increment_03() endfunc func Test_increment_empty_line() - new call setline(1, ['0', '0', '0', '0', '0', '0', '']) exe "normal Gvgg\" call assert_equal(['1', '1', '1', '1', '1', '1', ''], getline(1, 7)) @@ -783,8 +788,13 @@ func Test_increment_empty_line() exe "normal! c\l" exe "normal! c\l" call assert_equal('one two', getline(1)) +endfunc - bwipe! +" Try incrementing/decrementing a non-digit/alpha character +func Test_increment_special_char() + call setline(1, '!') + call assert_beeps("normal \") + call assert_beeps("normal \") endfunc " Try incrementing/decrementing a number when nrformats contains unsigned diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index 5730085c78..32bb755584 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -140,16 +140,15 @@ func Test_normal03_join() $ :j 10 call assert_equal('100', getline('.')) + call assert_beeps('normal GVJ') " clean up bw! endfunc +" basic filter test func Test_normal04_filter() - " basic filter test " only test on non windows platform - if has('win32') - return - endif + CheckNotMSWindows call Setup_NewWindow() 1 call feedkeys("!!sed -e 's/^/| /'\n", 'tx') @@ -222,12 +221,10 @@ func Test_normal_formatexpr_returns_nonzero() close! endfunc +" basic test for formatprg func Test_normal06_formatprg() - " basic test for formatprg " only test on non windows platform - if has('win32') - return - endif + CheckNotMSWindows " uses sed to number non-empty lines call writefile(['#!/bin/sh', 'sed ''/./=''|sed ''/./{', 'N', 's/\n/ /', '}'''], 'Xsed_format.sh') @@ -240,16 +237,24 @@ func Test_normal06_formatprg() set formatprg=./Xsed_format.sh norm! gggqG call assert_equal(expected, getline(1, '$')) - bw! + %d - 10new call setline(1, text) set formatprg=donothing setlocal formatprg=./Xsed_format.sh norm! gggqG call assert_equal(expected, getline(1, '$')) - bw! + %d + " Check for the command-line ranges added to 'formatprg' + set formatprg=cat + call setline(1, ['one', 'two', 'three', 'four', 'five']) + call feedkeys('gggqG', 'xt') + call assert_equal('.,$!cat', @:) + call feedkeys('2Ggq2j', 'xt') + call assert_equal('.,.+2!cat', @:) + + bw! " clean up set formatprg= setlocal formatprg= @@ -263,18 +268,16 @@ func Test_normal07_internalfmt() 10new call setline(1, list) set tw=12 - norm! gggqG + norm! ggVGgq call assert_equal(['1 2 3', '4 5 6', '7 8 9', '10 11 '], getline(1, '$')) " clean up set tw=0 bw! endfunc +" basic tests for foldopen/folddelete func Test_normal08_fold() - " basic tests for foldopen/folddelete - if !has("folding") - return - endif + CheckFeature folding call Setup_NewWindow() 50 setl foldenable fdm=marker @@ -1432,10 +1435,8 @@ func Test_normal18_z_fold() endfunc func Test_normal20_exmode() - if !has("unix") - " Reading from redirected file doesn't work on MS-Windows - return - endif + " Reading from redirected file doesn't work on MS-Windows + CheckNotMSWindows call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript') call writefile(['1', '2'], 'Xfile') call system(GetVimCommand() .. ' -e -s < Xscript Xfile') @@ -2154,6 +2155,12 @@ func Test_normal31_r_cmd() " r command should fail in operator pending mode call assert_beeps('normal! cr') + " replace a tab character in visual mode + %d + call setline(1, ["a\tb", "c\td", "e\tf"]) + normal gglvjjrx + call assert_equal(['axx', 'xxx', 'xxf'], getline(1, '$')) + " clean up set noautoindent bw! @@ -2178,9 +2185,7 @@ endfunc " Test for g`, g;, g,, g&, gv, gk, gj, gJ, g0, g^, g_, gm, g$, gM, g CTRL-G, " gi and gI commands func Test_normal33_g_cmd2() - if !has("jumplist") - return - endif + CheckFeature jumplist call Setup_NewWindow() " Test for g` clearjumps @@ -2849,9 +2854,8 @@ func Test_normal49_counts() endfunc func Test_normal50_commandline() - if !has("timers") || !has("cmdline_hist") - return - endif + CheckFeature timers + CheckFeature cmdline_hist func! DoTimerWork(id) call assert_equal('[Command Line]', bufname('')) " should fail, with E11, but does fail with E23? @@ -2880,9 +2884,7 @@ func Test_normal50_commandline() endfunc func Test_normal51_FileChangedRO() - if !has("autocmd") - return - endif + CheckFeature autocmd call writefile(['foo'], 'Xreadonly.log') new Xreadonly.log setl ro @@ -2897,9 +2899,7 @@ func Test_normal51_FileChangedRO() endfunc func Test_normal52_rl() - if !has("rightleft") - return - endif + CheckFeature rightleft new call setline(1, 'abcde fghij klmnopq') norm! 1gg$ @@ -2932,9 +2932,7 @@ func Test_normal52_rl() endfunc func Test_normal53_digraph() - if !has('digraphs') - return - endif + CheckFeature digraphs new call setline(1, 'abcdefgh|') exe "norm! 1gg0f\!!" @@ -3371,6 +3369,49 @@ func Test_normal_colon_op() close! endfunc +" Test for d and D commands +func Test_normal_delete_cmd() + new + " D in an empty line + call setline(1, '') + normal D + call assert_equal('', getline(1)) + " D in an empty line in virtualedit mode + set virtualedit=all + normal D + call assert_equal('', getline(1)) + set virtualedit& + " delete to a readonly register + call setline(1, ['abcd']) + call assert_beeps('normal ":d2l') + close! +endfunc + +" Test for the 'E' flag in 'cpo' with yank, change, delete, etc. operators +func Test_empty_region_error() + new + call setline(1, '') + set cpo+=E + " yank an empty line + call assert_beeps('normal "ayl') + " change an empty line + call assert_beeps('normal lcTa') + " delete an empty line + call assert_beeps('normal D') + call assert_beeps('normal dl') + call assert_equal('', getline(1)) + " change case of an empty line + call assert_beeps('normal gul') + call assert_beeps('normal gUl') + " replace a character + call assert_beeps('normal vrx') + " increment and decrement + call assert_beeps('exe "normal v\"') + call assert_beeps('exe "normal v\"') + set cpo-=E + close! +endfunc + " Test for deleting or changing characters across lines with 'whichwrap' " containing 's'. Should count as one character. func Test_normal_op_across_lines() diff --git a/src/nvim/testdir/test_regexp_latin.vim b/src/nvim/testdir/test_regexp_latin.vim index d08a980787..2520273e55 100644 --- a/src/nvim/testdir/test_regexp_latin.vim +++ b/src/nvim/testdir/test_regexp_latin.vim @@ -146,6 +146,10 @@ func Test_regexp_single_line_pat() call add(tl, [2, 'c*', 'abdef', '']) call add(tl, [2, 'bc\+', 'abccccdef', 'bcccc']) call add(tl, [2, 'bc\+', 'abdef']) " no match + " match escape character in a string + call add(tl, [2, '.\e.', "one\two", "e\t"]) + " match backspace character in a string + call add(tl, [2, '.\b.', "one\two", "e\t"]) " match newline character in a string call add(tl, [2, 'o\nb', "foo\nbar", "o\nb"]) @@ -895,6 +899,8 @@ func Test_regexp_error() call assert_fails("call matchlist('x x', '\\%#=2 \\zs*')", 'E888:') call assert_fails("call matchlist('x x', '\\%#=2 \\ze*')", 'E888:') call assert_fails('exe "normal /\\%#=1\\%[x\\%[x]]\"', 'E369:') + call assert_fails("call matchstr('abcd', '\\%o841\\%o142')", 'E678:') + call assert_equal('', matchstr('abcd', '\%o181\%o142')) endfunc " Test for using the last substitute string pattern (~) diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index 0cf55c7d0b..d79910fbc1 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -1752,6 +1752,25 @@ func Test_invalid_regexp() call assert_fails("call search('\\%#=3ab')", 'E864:') endfunc +" Test for searching a very complex pattern in a string. Should switch the +" regexp engine from NFA to the old engine. +func Test_regexp_switch_engine() + let l = readfile('samples/re.freeze.txt') + let v = substitute(l[4], '..\@\" + call assert_equal([2, 5], [line('.'), col('.')]) + exe "normal 2GVj$?\\%Vbar\\" + call assert_equal([3, 5], [line('.'), col('.')]) + close! +endfunc + " Test for searching with 'smartcase' and 'ignorecase' func Test_search_smartcase() new diff --git a/src/nvim/testdir/test_substitute.vim b/src/nvim/testdir/test_substitute.vim index 2a8a925fdb..9b90205c3d 100644 --- a/src/nvim/testdir/test_substitute.vim +++ b/src/nvim/testdir/test_substitute.vim @@ -493,6 +493,9 @@ func Test_sub_replace_1() call assert_equal("x\x", substitute('xXx', 'X', "\r", '')) call assert_equal("YyyY", substitute('Y', 'Y', '\L\uyYy\l\EY', '')) call assert_equal("zZZz", substitute('Z', 'Z', '\U\lZzZ\u\Ez', '')) + " \v or \V after $ + call assert_equal('abxx', substitute('abcd', 'xy$\v|cd$', 'xx', '')) + call assert_equal('abxx', substitute('abcd', 'xy$\V\|cd\$', 'xx', '')) endfunc func Test_sub_replace_2() @@ -867,6 +870,40 @@ endfunc func Test_substitute() call assert_equal('a1a2a3a', substitute('123', '\zs', 'a', 'g')) + " Substitute with special keys + call assert_equal("a\c", substitute('abc', "a.c", "a\c", '')) +endfunc + +func Test_substitute_expr() + let g:val = 'XXX' + call assert_equal('XXX', substitute('yyy', 'y*', '\=g:val', '')) + call assert_equal('XXX', substitute('yyy', 'y*', {-> g:val}, '')) + call assert_equal("-\u1b \uf2-", substitute("-%1b %f2-", '%\(\x\x\)', + \ '\=nr2char("0x" . submatch(1))', 'g')) + call assert_equal("-\u1b \uf2-", substitute("-%1b %f2-", '%\(\x\x\)', + \ {-> nr2char("0x" . submatch(1))}, 'g')) + + call assert_equal('231', substitute('123', '\(.\)\(.\)\(.\)', + \ {-> submatch(2) . submatch(3) . submatch(1)}, '')) + + func Recurse() + return substitute('yyy', 'y\(.\)y', {-> submatch(1)}, '') + endfunc + " recursive call works + call assert_equal('-y-x-', substitute('xxx', 'x\(.\)x', {-> '-' . Recurse() . '-' . submatch(1) . '-'}, '')) + + call assert_fails("let s=submatch([])", 'E745:') + call assert_fails("let s=submatch(2, [])", 'E745:') +endfunc + +func Test_invalid_submatch() + " This was causing invalid memory access in Vim-7.4.2232 and older + call assert_fails("call substitute('x', '.', {-> submatch(10)}, '')", 'E935:') + call assert_fails('eval submatch(-1)', 'E935:') + call assert_equal('', submatch(0)) + call assert_equal('', submatch(1)) + call assert_equal([], submatch(0, 1)) + call assert_equal([], submatch(1, 1)) endfunc func Test_submatch_list_concatenate() @@ -875,6 +912,44 @@ func Test_submatch_list_concatenate() call substitute('A1', pat, Rep, '')->assert_equal("[['A1'], ['1']]") endfunc +func Test_substitute_expr_arg() + call assert_equal('123456789-123456789=', substitute('123456789', + \ '\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', + \ {m -> m[0] . '-' . m[1] . m[2] . m[3] . m[4] . m[5] . m[6] . m[7] . m[8] . m[9] . '='}, '')) + + call assert_equal('123456-123456=789', substitute('123456789', + \ '\(.\)\(.\)\(.\)\(a*\)\(n*\)\(.\)\(.\)\(.\)\(x*\)', + \ {m -> m[0] . '-' . m[1] . m[2] . m[3] . m[4] . m[5] . m[6] . m[7] . m[8] . m[9] . '='}, '')) + + call assert_equal('123456789-123456789x=', substitute('123456789', + \ '\(.\)\(.\)\(.*\)', + \ {m -> m[0] . '-' . m[1] . m[2] . m[3] . 'x' . m[4] . m[5] . m[6] . m[7] . m[8] . m[9] . '='}, '')) + + call assert_fails("call substitute('xxx', '.', {m -> string(add(m, 'x'))}, '')", 'E742:') + call assert_fails("call substitute('xxx', '.', {m -> string(insert(m, 'x'))}, '')", 'E742:') + call assert_fails("call substitute('xxx', '.', {m -> string(extend(m, ['x']))}, '')", 'E742:') + call assert_fails("call substitute('xxx', '.', {m -> string(remove(m, 1))}, '')", 'E742:') +endfunc + +" Test for using a function to supply the substitute string +func Test_substitute_using_func() + func Xfunc() + return '1234' + endfunc + call assert_equal('a1234f', substitute('abcdef', 'b..e', + \ function("Xfunc"), '')) + delfunc Xfunc +endfunc + +" Test for using submatch() with a multiline match +func Test_substitute_multiline_submatch() + new + call setline(1, ['line1', 'line2', 'line3', 'line4']) + %s/^line1\(\_.\+\)line4$/\=submatch(1)/ + call assert_equal(['', 'line2', 'line3', ''], getline(1, '$')) + close! +endfunc + func Test_substitute_skipped_range() new if 0 diff --git a/src/nvim/testdir/test_virtualedit.vim b/src/nvim/testdir/test_virtualedit.vim index e712896562..ddc7c20637 100644 --- a/src/nvim/testdir/test_virtualedit.vim +++ b/src/nvim/testdir/test_virtualedit.vim @@ -346,6 +346,17 @@ func Test_yank_paste_small_del_reg() set virtualedit= endfunc +" Test for delete that breaks a tab into spaces +func Test_delete_break_tab() + new + call setline(1, "one\ttwo") + set virtualedit=all + normal v3ld + call assert_equal(' two', getline(1)) + set virtualedit& + close! +endfunc + " After calling s:TryVirtualeditReplace(), line 1 will contain one of these " two strings, depending on whether virtual editing is on or off. let s:result_ve_on = 'a x' -- cgit From 32a2c556ab3697111f01c9ef50447ec5d78070f7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 4 Nov 2022 19:42:10 +0800 Subject: vim-patch:8.2.0968: no proper testing of the 'cpoptions' flags Problem: No proper testing of the 'cpoptions' flags. Solution: Add tests. (Yegappan Lakshmanan, closes vim/vim#6251) https://github.com/vim/vim/commit/c9630d2658af9dcaa01913e899b201bfdef7b536 --- src/nvim/testdir/test_cpoptions.vim | 631 ++++++++++++++++++++++++++++++++++++ src/nvim/testdir/test_edit.vim | 34 -- src/nvim/testdir/test_normal.vim | 79 ----- 3 files changed, 631 insertions(+), 113 deletions(-) create mode 100644 src/nvim/testdir/test_cpoptions.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cpoptions.vim b/src/nvim/testdir/test_cpoptions.vim new file mode 100644 index 0000000000..ceaa728018 --- /dev/null +++ b/src/nvim/testdir/test_cpoptions.vim @@ -0,0 +1,631 @@ +" Test for various 'cpoptions' (cpo) flags + +source check.vim +source view_util.vim + +" Test for the 'a' flag in 'cpo'. Reading a file should set the alternate +" file name. +func Test_cpo_a() + let save_cpo = &cpo + call writefile(['one'], 'Xfile') + " Wipe out all the buffers, so that the alternate file is empty + edit Xfoo | %bw + set cpo-=a + new + read Xfile + call assert_equal('', @#) + %d + set cpo+=a + read Xfile + call assert_equal('Xfile', @#) + close! + call delete('Xfile') + let &cpo = save_cpo +endfunc + +" Test for the 'A' flag in 'cpo'. Writing a file should set the alternate +" file name. +func Test_cpo_A() + let save_cpo = &cpo + " Wipe out all the buffers, so that the alternate file is empty + edit Xfoo | %bw + set cpo-=A + new Xfile1 + write Xfile2 + call assert_equal('', @#) + %bw + call delete('Xfile2') + new Xfile1 + set cpo+=A + write Xfile2 + call assert_equal('Xfile2', @#) + close! + call delete('Xfile2') + let &cpo = save_cpo +endfunc + +" Test for the 'b' flag in 'cpo'. "\|" at the end of a map command is +" recognized as the end of the map. +func Test_cpo_b() + let save_cpo = &cpo + set cpo+=b + nnoremap :pwd\\|let i = 1 + call assert_equal(':pwd\\', maparg('')) + nunmap + exe "nnoremap :pwd\|let i = 1" + call assert_equal(':pwd|let i = 1', maparg('')) + nunmap + set cpo-=b + nnoremap :pwd\\|let i = 1 + call assert_equal(':pwd\|let i = 1', maparg('')) + let &cpo = save_cpo + nunmap +endfunc + +" Test for the 'c' flag in 'cpo'. +func Test_cpo_c() + let save_cpo = &cpo + set cpo+=c + new + call setline(1, ' abababababab') + exe "normal gg/abab\" + call assert_equal(3, searchcount().total) + set cpo-=c + exe "normal gg/abab\" + call assert_equal(5, searchcount().total) + close! + let &cpo = save_cpo +endfunc + +" Test for the 'C' flag in 'cpo' (line continuation) +func Test_cpo_C() + let save_cpo = &cpo + call writefile(['let l = [', '\ 1,', '\ 2]'], 'Xfile') + set cpo-=C + source Xfile + call assert_equal([1, 2], g:l) + set cpo+=C + call assert_fails('source Xfile', 'E10:') + call delete('Xfile') + let &cpo = save_cpo +endfunc + +" Test for the 'd' flag in 'cpo' (tags relative to the current file) +func Test_cpo_d() + let save_cpo = &cpo + call mkdir('Xdir') + call writefile(["one\tXfile1\t/^one$/"], 'tags') + call writefile(["two\tXfile2\t/^two$/"], 'Xdir/tags') + set tags=./tags + set cpo-=d + edit Xdir/Xfile + call assert_equal('two', taglist('.*')[0].name) + set cpo+=d + call assert_equal('one', taglist('.*')[0].name) + %bw! + call delete('tags') + call delete('Xdir', 'rf') + set tags& + let &cpo = save_cpo +endfunc + +" Test for the 'D' flag in 'cpo' (digraph after a r, f or t) +func Test_cpo_D() + CheckFeature digraphs + let save_cpo = &cpo + new + set cpo-=D + call setline(1, 'abcdefgh|') + exe "norm! 1gg0f\!!" + call assert_equal(9, col('.')) + set cpo+=D + exe "norm! 1gg0f\!!" + call assert_equal(1, col('.')) + set cpo-=D + close! + let &cpo = save_cpo +endfunc + +" Test for the 'e' flag in 'cpo' +func Test_cpo_e() + let save_cpo = &cpo + let @a='let i = 45' + set cpo+=e + call feedkeys(":@a\", 'xt') + call assert_equal(45, i) + set cpo-=e + call feedkeys(":@a\6\", 'xt') + call assert_equal(456, i) + let &cpo = save_cpo +endfunc + +" Test for the 'E' flag in 'cpo' with yank, change, delete, etc. operators +func Test_cpo_E() + new + call setline(1, '') + set cpo+=E + " yank an empty line + call assert_beeps('normal "ayl') + " change an empty line + call assert_beeps('normal lcTa') + " delete an empty line + call assert_beeps('normal D') + call assert_beeps('normal dl') + call assert_equal('', getline(1)) + " change case of an empty line + call assert_beeps('normal gul') + call assert_beeps('normal gUl') + " replace a character + call assert_beeps('normal vrx') + " increment and decrement + call assert_beeps('exe "normal v\"') + call assert_beeps('exe "normal v\"') + set cpo-=E + close! +endfunc + +" Test for the 'f' flag in 'cpo' (read in an empty buffer sets the file name) +func Test_cpo_f() + let save_cpo = &cpo + new + set cpo-=f + read test_cpoptions.vim + call assert_equal('', @%) + %d + set cpo+=f + read test_cpoptions.vim + call assert_equal('test_cpoptions.vim', @%) + close! + let &cpo = save_cpo +endfunc + +" Test for the 'F' flag in 'cpo' (write in an empty buffer sets the file name) +func Test_cpo_F() + let save_cpo = &cpo + new + set cpo-=F + write Xfile + call assert_equal('', @%) + call delete('Xfile') + set cpo+=F + write Xfile + call assert_equal('Xfile', @%) + close! + call delete('Xfile') + let &cpo = save_cpo +endfunc + +" Test for the 'g' flag in 'cpo' (jump to line 1 when re-editing a file) +func Test_cpo_g() + throw 'Skipped: Nvim does not support cpoptions flag "g"' + let save_cpo = &cpo + new test_cpoptions.vim + set cpo-=g + normal 20G + edit + call assert_equal(20, line('.')) + set cpo+=g + edit + call assert_equal(1, line('.')) + close! + let &cpo = save_cpo +endfunc + +" Test for inserting text in a line with only spaces ('H' flag in 'cpoptions') +func Test_cpo_H() + throw 'Skipped: Nvim does not support cpoptions flag "H"' + let save_cpo = &cpo + new + set cpo-=H + call setline(1, ' ') + normal! Ia + call assert_equal(' a', getline(1)) + set cpo+=H + call setline(1, ' ') + normal! Ia + call assert_equal(' a ', getline(1)) + close! + let &cpo = save_cpo +endfunc + +" Test for the 'I' flag in 'cpo' (deleting autoindent when using arrow keys) +func Test_cpo_I() + let save_cpo = &cpo + new + setlocal autoindent + set cpo+=I + exe "normal i one\\" + call assert_equal(' ', getline(2)) + set cpo-=I + %d + exe "normal i one\\" + call assert_equal('', getline(2)) + close! + let &cpo = save_cpo +endfunc + +" Test for the 'J' flag in 'cpo' (two spaces after a sentence) +func Test_cpo_J() + let save_cpo = &cpo + new + set cpo-=J + call setline(1, 'one. two! three? four."'' five.)]') + normal 0 + for colnr in [6, 12, 19, 28, 34] + normal ) + call assert_equal(colnr, col('.')) + endfor + for colnr in [28, 19, 12, 6, 1] + normal ( + call assert_equal(colnr, col('.')) + endfor + set cpo+=J + normal 0 + for colnr in [12, 28, 34] + normal ) + call assert_equal(colnr, col('.')) + endfor + for colnr in [28, 12, 1] + normal ( + call assert_equal(colnr, col('.')) + endfor + close! + let &cpo = save_cpo +endfunc + +" TODO: Add a test for 'k' in 'cpo' + +" TODO: Add a test for 'K' in 'cpo' + +" Test for the 'l' flag in 'cpo' (backslash in a [] range) +func Test_cpo_l() + let save_cpo = &cpo + new + call setline(1, ['', "a\tc" .. '\t']) + set cpo-=l + exe 'normal gg/[\t]' .. "\" + call assert_equal([2, 8], [col('.'), virtcol('.')]) + set cpo+=l + exe 'normal gg/[\t]' .. "\" + call assert_equal([4, 10], [col('.'), virtcol('.')]) + close! + let &cpo = save_cpo +endfunc + +" Test for inserting tab in virtual replace mode ('L' flag in 'cpoptions') +func Test_cpo_L() + let save_cpo = &cpo + new + set cpo-=L + call setline(1, 'abcdefghijklmnopqr') + exe "normal 0gR\" + call assert_equal("\ijklmnopqr", getline(1)) + set cpo+=L + set list + call setline(1, 'abcdefghijklmnopqr') + exe "normal 0gR\" + call assert_equal("\cdefghijklmnopqr", getline(1)) + set nolist + call setline(1, 'abcdefghijklmnopqr') + exe "normal 0gR\" + call assert_equal("\ijklmnopqr", getline(1)) + close! + let &cpo = save_cpo +endfunc + +" TODO: This test doesn't work. + +" Test for the 'M' flag in 'cpo' (% with escape parenthesis) +func Test_cpo_M() + let save_cpo = &cpo + new + call setline(1, ['( \( )', '\( ( \)']) + + set cpo-=M + call cursor(1, 1) + normal % + call assert_equal(6, col('.')) + call cursor(1, 4) + call assert_beeps('normal %') + call cursor(2, 2) + normal % + call assert_equal(7, col('.')) + call cursor(2, 4) + call assert_beeps('normal %') + + set cpo+=M + call cursor(1, 4) + normal % + call assert_equal(6, col('.')) + call cursor(1, 1) + call assert_beeps('normal %') + call cursor(2, 4) + normal % + call assert_equal(7, col('.')) + call cursor(2, 1) + call assert_beeps('normal %') + + close! + let &cpo = save_cpo +endfunc + +" Test for the 'n' flag in 'cpo' (using number column for wrapped lines) +func Test_cpo_n() + let save_cpo = &cpo + new + call setline(1, repeat('a', &columns)) + setlocal number + set cpo-=n + redraw! + call assert_equal(' aaaa', Screenline(2)) + set cpo+=n + redraw! + call assert_equal('aaaa', Screenline(2)) + close! + let &cpo = save_cpo +endfunc + +" Test for the 'o' flag in 'cpo' (line offset to search command) +func Test_cpo_o() + let save_cpo = &cpo + new + call setline(1, ['', 'one', 'two', 'three', 'one', 'two', 'three']) + set cpo-=o + exe "normal /one/+2\" + normal n + call assert_equal(7, line('.')) + set cpo+=o + exe "normal /one/+2\" + normal n + call assert_equal(5, line('.')) + close! + let &cpo = save_cpo +endfunc + +" Test for the 'O' flag in 'cpo' (overwriting an existing file) +func Test_cpo_O() + let save_cpo = &cpo + new Xfile + call setline(1, 'one') + call writefile(['two'], 'Xfile') + set cpo-=O + call assert_fails('write', 'E13:') + set cpo+=O + write + call assert_equal(['one'], readfile('Xfile')) + close! + call delete('Xfile') + let &cpo = save_cpo +endfunc + +" Test for the 'P' flag in 'cpo' (appending to a file sets the current file +" name) +func Test_cpo_P() + let save_cpo = &cpo + call writefile([], 'Xfile') + new + call setline(1, 'one') + set cpo+=F + set cpo-=P + write >> Xfile + call assert_equal('', @%) + set cpo+=P + write >> Xfile + call assert_equal('Xfile', @%) + close! + call delete('Xfile') + let &cpo = save_cpo +endfunc + +" Test for the 'q' flag in 'cpo' (joining multiple lines) +func Test_cpo_q() + let save_cpo = &cpo + new + call setline(1, ['one', 'two', 'three', 'four', 'five']) + set cpo-=q + normal gg4J + call assert_equal(14, col('.')) + %d + call setline(1, ['one', 'two', 'three', 'four', 'five']) + set cpo+=q + normal gg4J + call assert_equal(4, col('.')) + close! + let &cpo = save_cpo +endfunc + +" Test for the 'r' flag in 'cpo' (redo command with a search motion) +func Test_cpo_r() + let save_cpo = &cpo + new + call setline(1, repeat(['one two three four'], 2)) + set cpo-=r + exe "normal ggc/two\abc " + let @/ = 'three' + normal 2G. + call assert_equal('abc two three four', getline(2)) + %d + call setline(1, repeat(['one two three four'], 2)) + set cpo+=r + exe "normal ggc/two\abc " + let @/ = 'three' + normal 2G. + call assert_equal('abc three four', getline(2)) + close! + let &cpo = save_cpo +endfunc + +" Test for the 'R' flag in 'cpo' (clear marks after a filter command) +func Test_cpo_R() + CheckUnix + let save_cpo = &cpo + new + call setline(1, ['three', 'one', 'two']) + set cpo-=R + 3mark r + %!sort + call assert_equal(3, line("'r")) + %d + call setline(1, ['three', 'one', 'two']) + set cpo+=R + 3mark r + %!sort + call assert_equal(0, line("'r")) + close! + let &cpo = save_cpo +endfunc + +" Test for the 'S' flag in 'cpo' (copying buffer options) +func Test_cpo_S() + let save_cpo = &cpo + new Xfile1 + set noautoindent + new Xfile2 + set cpo-=S + set autoindent + wincmd p + call assert_equal(0, &autoindent) + wincmd p + call assert_equal(1, &autoindent) + set cpo+=S + wincmd p + call assert_equal(1, &autoindent) + set noautoindent + wincmd p + call assert_equal(0, &autoindent) + wincmd t + close! + close! + let &cpo = save_cpo +endfunc + +" Test for the 'u' flag in 'cpo' (Vi-compatible undo) +func Test_cpo_u() + let save_cpo = &cpo + new + set cpo-=u + exe "normal iabc\udef\ughi" + normal uu + call assert_equal('abc', getline(1)) + %d + set cpo+=u + exe "normal iabc\udef\ughi" + normal uu + call assert_equal('abcdefghi', getline(1)) + close! + let &cpo = save_cpo +endfunc + +" Test for the 'x' flag in 'cpo' (Esc on command-line executes command) +func Test_cpo_x() + let save_cpo = &cpo + set cpo-=x + let i = 1 + call feedkeys(":let i=10\", 'xt') + call assert_equal(1, i) + set cpo+=x + call feedkeys(":let i=10\", 'xt') + call assert_equal(10, i) + let &cpo = save_cpo +endfunc + +" Test for the 'X' flag in 'cpo' ('R' with a count) +func Test_cpo_X() + let save_cpo = &cpo + new + call setline(1, 'aaaaaa') + set cpo-=X + normal gg4Rx + call assert_equal('xxxxaa', getline(1)) + normal ggRy + normal 4. + call assert_equal('yyyyaa', getline(1)) + call setline(1, 'aaaaaa') + set cpo+=X + normal gg4Rx + call assert_equal('xxxxaaaaa', getline(1)) + normal ggRy + normal 4. + call assert_equal('yyyyxxxaaaaa', getline(1)) + close! + let &cpo = save_cpo +endfunc + +" Test for the 'y' flag in 'cpo' (repeating a yank command) +func Test_cpo_y() + let save_cpo = &cpo + new + call setline(1, ['one', 'two']) + set cpo-=y + normal ggyy + normal 2G. + call assert_equal("one\n", @") + %d + call setline(1, ['one', 'two']) + set cpo+=y + normal ggyy + normal 2G. + call assert_equal("two\n", @") + close! + let &cpo = save_cpo +endfunc + +" Test for the 'Z' flag in 'cpo' (write! resets 'readonly') +func Test_cpo_Z() + let save_cpo = &cpo + call writefile([], 'Xfile') + new Xfile + setlocal readonly + set cpo-=Z + write! + call assert_equal(0, &readonly) + set cpo+=Z + setlocal readonly + write! + call assert_equal(1, &readonly) + close! + call delete('Xfile') + let &cpo = save_cpo +endfunc + +" Test for cursor movement with '-' in 'cpoptions' +func Test_cpo_minus() + throw 'Skipped: Nvim does not support cpoptions flag "-"' + new + call setline(1, ['foo', 'bar', 'baz']) + let save_cpo = &cpo + set cpo+=- + call assert_beeps('normal 10j') + call assert_equal(1, line('.')) + normal G + call assert_beeps('normal 10k') + call assert_equal(3, line('.')) + call assert_fails(10, 'E16:') + let &cpo = save_cpo + close! +endfunc + +" Test for displaying dollar when changing text ('$' flag in 'cpoptions') +func Test_cpo_dollar() + throw 'Skipped: use test/functional/legacy/cpoptions_spec.lua' + new + let g:Line = '' + func SaveFirstLine() + let g:Line = Screenline(1) + return '' + endfunc + inoremap SaveFirstLine() + call test_override('redraw_flag', 1) + set cpo+=$ + call setline(1, 'one two three') + redraw! + exe "normal c2w\vim" + call assert_equal('one tw$ three', g:Line) + call assert_equal('vim three', getline(1)) + set cpo-=$ + call test_override('ALL', 0) + delfunc SaveFirstLine + %bw! +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index 9783ed19a7..d19826f5b9 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -1724,40 +1724,6 @@ func Test_edit_illegal_filename() close! endfunc -" Test for inserting text in a line with only spaces ('H' flag in 'cpoptions') -func Test_edit_cpo_H() - throw 'Skipped: Nvim does not support cpoptions flag "H"' - new - call setline(1, ' ') - normal! Ia - call assert_equal(' a', getline(1)) - set cpo+=H - call setline(1, ' ') - normal! Ia - call assert_equal(' a ', getline(1)) - set cpo-=H - close! -endfunc - -" Test for inserting tab in virtual replace mode ('L' flag in 'cpoptions') -func Test_edit_cpo_L() - new - call setline(1, 'abcdefghijklmnopqr') - exe "normal 0gR\" - call assert_equal("\ijklmnopqr", getline(1)) - set cpo+=L - set list - call setline(1, 'abcdefghijklmnopqr') - exe "normal 0gR\" - call assert_equal("\cdefghijklmnopqr", getline(1)) - set nolist - call setline(1, 'abcdefghijklmnopqr') - exe "normal 0gR\" - call assert_equal("\ijklmnopqr", getline(1)) - set cpo-=L - %bw! -endfunc - " Test for editing a directory func Test_edit_is_a_directory() CheckEnglish diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index 32bb755584..3c9a7a3986 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -2931,20 +2931,6 @@ func Test_normal52_rl() bw! endfunc -func Test_normal53_digraph() - CheckFeature digraphs - new - call setline(1, 'abcdefgh|') - exe "norm! 1gg0f\!!" - call assert_equal(9, col('.')) - set cpo+=D - exe "norm! 1gg0f\!!" - call assert_equal(1, col('.')) - - set cpo-=D - bw! -endfunc - func Test_normal54_Ctrl_bsl() new call setline(1, 'abcdefghijklmn') @@ -3265,46 +3251,6 @@ func Test_normal_gk_gj() set cpoptions& number& numberwidth& wrap& endfunc -" Test for cursor movement with '-' in 'cpoptions' -func Test_normal_cpo_minus() - throw 'Skipped: Nvim does not support cpoptions flag "-"' - new - call setline(1, ['foo', 'bar', 'baz']) - let save_cpo = &cpo - set cpo+=- - call assert_beeps('normal 10j') - call assert_equal(1, line('.')) - normal G - call assert_beeps('normal 10k') - call assert_equal(3, line('.')) - call assert_fails(10, 'E16:') - let &cpo = save_cpo - close! -endfunc - -" Test for displaying dollar when changing text ('$' flag in 'cpoptions') -func Test_normal_cpo_dollar() - throw 'Skipped: use test/functional/legacy/cpoptions_spec.lua' - new - let g:Line = '' - func SaveFirstLine() - let g:Line = Screenline(1) - return '' - endfunc - inoremap SaveFirstLine() - call test_override('redraw_flag', 1) - set cpo+=$ - call setline(1, 'one two three') - redraw! - exe "normal c2w\vim" - call assert_equal('one tw$ three', g:Line) - call assert_equal('vim three', getline(1)) - set cpo-=$ - call test_override('ALL', 0) - delfunc SaveFirstLine - %bw! -endfunc - " Test for using : to run a multi-line Ex command in operator pending mode func Test_normal_yank_with_excmd() new @@ -3387,31 +3333,6 @@ func Test_normal_delete_cmd() close! endfunc -" Test for the 'E' flag in 'cpo' with yank, change, delete, etc. operators -func Test_empty_region_error() - new - call setline(1, '') - set cpo+=E - " yank an empty line - call assert_beeps('normal "ayl') - " change an empty line - call assert_beeps('normal lcTa') - " delete an empty line - call assert_beeps('normal D') - call assert_beeps('normal dl') - call assert_equal('', getline(1)) - " change case of an empty line - call assert_beeps('normal gul') - call assert_beeps('normal gUl') - " replace a character - call assert_beeps('normal vrx') - " increment and decrement - call assert_beeps('exe "normal v\"') - call assert_beeps('exe "normal v\"') - set cpo-=E - close! -endfunc - " Test for deleting or changing characters across lines with 'whichwrap' " containing 's'. Should count as one character. func Test_normal_op_across_lines() -- cgit From 2b86ca81b400b1311379f3258cc6c38be94fcf36 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 4 Nov 2022 19:51:54 +0800 Subject: vim-patch:8.2.0976: some 'cpoptions' not tested Problem: Some 'cpoptions' not tested. Solution: Add more tests. (Yegappan Lakshmanan, closes vim/vim#6253) https://github.com/vim/vim/commit/df7df59d85e7e56a796912dc865488a75d3f0e53 --- src/nvim/testdir/test_cd.vim | 24 --- src/nvim/testdir/test_charsearch.vim | 30 ---- src/nvim/testdir/test_cpoptions.vim | 327 ++++++++++++++++++++++++++++++++--- src/nvim/testdir/test_normal.vim | 9 - 4 files changed, 307 insertions(+), 83 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cd.vim b/src/nvim/testdir/test_cd.vim index d6d44d1901..43c4e09d40 100644 --- a/src/nvim/testdir/test_cd.vim +++ b/src/nvim/testdir/test_cd.vim @@ -68,30 +68,6 @@ func Test_cd_minus() call delete('Xresult') endfunc -func Test_cd_with_cpo_chdir() - e Xfoo - call setline(1, 'foo') - let path = getcwd() - " set cpo+=. - - " :cd should fail when buffer is modified and 'cpo' contains dot. - " call assert_fails('cd ..', 'E747:') - call assert_equal(path, getcwd()) - - " :cd with exclamation mark should succeed. - cd! .. - call assert_notequal(path, getcwd()) - - " :cd should succeed when buffer has been written. - w! - exe 'cd ' .. fnameescape(path) - call assert_equal(path, getcwd()) - - call delete('Xfoo') - set cpo& - bw! -endfunc - " Test for chdir() func Test_chdir_func() let topdir = getcwd() diff --git a/src/nvim/testdir/test_charsearch.vim b/src/nvim/testdir/test_charsearch.vim index d386d74f8d..4e6a75c3a0 100644 --- a/src/nvim/testdir/test_charsearch.vim +++ b/src/nvim/testdir/test_charsearch.vim @@ -43,36 +43,6 @@ func Test_charsearch() enew! endfunc -" Test for t,f,F,T movement commands and 'cpo-;' setting -func Test_search_cmds() - enew! - call append(0, ["aaa two three four", " zzz", "yyy ", - \ "bbb yee yoo four", "ccc two three four", - \ "ddd yee yoo four"]) - set cpo-=; - 1 - normal! 0tt;D - 2 - normal! 0fz;D - 3 - normal! $Fy;D - 4 - normal! $Ty;D - set cpo+=; - 5 - normal! 0tt;;D - 6 - normal! $Ty;;D - - call assert_equal('aaa two', getline(1)) - call assert_equal(' z', getline(2)) - call assert_equal('y', getline(3)) - call assert_equal('bbb y', getline(4)) - call assert_equal('ccc', getline(5)) - call assert_equal('ddd yee y', getline(6)) - enew! -endfunc - " Test for character search in virtual edit mode with func Test_csearch_virtualedit() new diff --git a/src/nvim/testdir/test_cpoptions.vim b/src/nvim/testdir/test_cpoptions.vim index ceaa728018..f0732934d4 100644 --- a/src/nvim/testdir/test_cpoptions.vim +++ b/src/nvim/testdir/test_cpoptions.vim @@ -1,6 +1,7 @@ -" Test for various 'cpoptions' (cpo) flags +" Test for the various 'cpoptions' (cpo) flags source check.vim +source shared.vim source view_util.vim " Test for the 'a' flag in 'cpo'. Reading a file should set the alternate @@ -62,6 +63,24 @@ func Test_cpo_b() nunmap endfunc +" Test for the 'B' flag in 'cpo'. A backslash in mappings, abbreviations, user +" commands and menu commands has no special meaning. +func Test_cpo_B() + let save_cpo = &cpo + new + set cpo-=B + iabbr abc ab\d + exe "normal iabc " + call assert_equal('abd ', getline(1)) + %d + set cpo+=B + iabbr abc ab\d + exe "normal iabc " + call assert_equal('abd ', getline(1)) + close! + let &cpo = save_cpo +endfunc + " Test for the 'c' flag in 'cpo'. func Test_cpo_c() let save_cpo = &cpo @@ -228,6 +247,8 @@ func Test_cpo_H() let &cpo = save_cpo endfunc +" TODO: Add a test for the 'i' flag in 'cpo' + " Test for the 'I' flag in 'cpo' (deleting autoindent when using arrow keys) func Test_cpo_I() let save_cpo = &cpo @@ -244,6 +265,8 @@ func Test_cpo_I() let &cpo = save_cpo endfunc +" Test for the 'j' flag in 'cpo' is in the test_join.vim file. + " Test for the 'J' flag in 'cpo' (two spaces after a sentence) func Test_cpo_J() let save_cpo = &cpo @@ -273,9 +296,9 @@ func Test_cpo_J() let &cpo = save_cpo endfunc -" TODO: Add a test for 'k' in 'cpo' +" TODO: Add a test for the 'k' flag in 'cpo' -" TODO: Add a test for 'K' in 'cpo' +" TODO: Add a test for the 'K' flag in 'cpo' " Test for the 'l' flag in 'cpo' (backslash in a [] range) func Test_cpo_l() @@ -313,7 +336,7 @@ func Test_cpo_L() let &cpo = save_cpo endfunc -" TODO: This test doesn't work. +" TODO: Add a test for the 'm' flag in 'cpo' " Test for the 'M' flag in 'cpo' (% with escape parenthesis) func Test_cpo_M() @@ -398,6 +421,8 @@ func Test_cpo_O() let &cpo = save_cpo endfunc +" Test for the 'p' flag in 'cpo' is in the test_lispwords.vim file. + " Test for the 'P' flag in 'cpo' (appending to a file sets the current file " name) func Test_cpo_P() @@ -475,6 +500,8 @@ func Test_cpo_R() let &cpo = save_cpo endfunc +" TODO: Add a test for the 's' flag in 'cpo' + " Test for the 'S' flag in 'cpo' (copying buffer options) func Test_cpo_S() let save_cpo = &cpo @@ -499,6 +526,8 @@ func Test_cpo_S() let &cpo = save_cpo endfunc +" Test for the 't' flag in 'cpo' is in the test_tagjump.vim file. + " Test for the 'u' flag in 'cpo' (Vi-compatible undo) func Test_cpo_u() let save_cpo = &cpo @@ -516,6 +545,33 @@ func Test_cpo_u() let &cpo = save_cpo endfunc +" TODO: Add a test for the 'v' flag in 'cpo' (backspace doesn't remove +" characters from the screen) + +" Test for the 'w' flag in 'cpo' ('cw' on a blank character changes only one +" character) +func Test_cpo_w() + throw 'Skipped: Nvim does not support cpoptions flag "w"' + let save_cpo = &cpo + new + set cpo+=w + call setline(1, 'here are some words') + norm! 1gg0elcwZZZ + call assert_equal('hereZZZ are some words', getline('.')) + norm! 1gg2elcWYYY + call assert_equal('hereZZZ areYYY some words', getline('.')) + set cpo-=w + call setline(1, 'here are some words') + norm! 1gg0elcwZZZ + call assert_equal('hereZZZare some words', getline('.')) + norm! 1gg2elcWYYY + call assert_equal('hereZZZare someYYYwords', getline('.')) + close! + let &cpo = save_cpo +endfunc + +" Test for the 'W' flag in 'cpo' is in the test_writefile.vim file + " Test for the 'x' flag in 'cpo' (Esc on command-line executes command) func Test_cpo_x() let save_cpo = &cpo @@ -588,22 +644,7 @@ func Test_cpo_Z() let &cpo = save_cpo endfunc -" Test for cursor movement with '-' in 'cpoptions' -func Test_cpo_minus() - throw 'Skipped: Nvim does not support cpoptions flag "-"' - new - call setline(1, ['foo', 'bar', 'baz']) - let save_cpo = &cpo - set cpo+=- - call assert_beeps('normal 10j') - call assert_equal(1, line('.')) - normal G - call assert_beeps('normal 10k') - call assert_equal(3, line('.')) - call assert_fails(10, 'E16:') - let &cpo = save_cpo - close! -endfunc +" Test for the '!' flag in 'cpo' is in the test_normal.vim file " Test for displaying dollar when changing text ('$' flag in 'cpoptions') func Test_cpo_dollar() @@ -628,4 +669,250 @@ func Test_cpo_dollar() %bw! endfunc +" Test for the '%' flag in 'cpo' (parenthesis matching inside strings) +func Test_cpo_percent() + let save_cpo = &cpo + new + call setline(1, ' if (strcmp("ab)cd(", s))') + set cpo-=% + normal 8|% + call assert_equal(28, col('.')) + normal 15|% + call assert_equal(27, col('.')) + normal 27|% + call assert_equal(15, col('.')) + call assert_beeps("normal 19|%") + call assert_beeps("normal 22|%") + set cpo+=% + normal 8|% + call assert_equal(28, col('.')) + normal 15|% + call assert_equal(19, col('.')) + normal 27|% + call assert_equal(22, col('.')) + normal 19|% + call assert_equal(15, col('.')) + normal 22|% + call assert_equal(27, col('.')) + close! + let &cpo = save_cpo +endfunc + +" Test for cursor movement with '-' in 'cpoptions' +func Test_cpo_minus() + throw 'Skipped: Nvim does not support cpoptions flag "-"' + new + call setline(1, ['foo', 'bar', 'baz']) + let save_cpo = &cpo + set cpo+=- + call assert_beeps('normal 10j') + call assert_equal(1, line('.')) + normal G + call assert_beeps('normal 10k') + call assert_equal(3, line('.')) + call assert_fails(10, 'E16:') + close! + let &cpo = save_cpo +endfunc + +" Test for the '+' flag in 'cpo' ('write file' command resets the 'modified' +" flag) +func Test_cpo_plus() + let save_cpo = &cpo + call writefile([], 'Xfile') + new Xfile + call setline(1, 'foo') + write X1 + call assert_equal(1, &modified) + set cpo+=+ + write X2 + call assert_equal(0, &modified) + close! + call delete('Xfile') + call delete('X1') + call delete('X2') + let &cpo = save_cpo +endfunc + +" Test for the '*' flag in 'cpo' (':*' is same as ':@') +func Test_cpo_star() + throw 'Skipped: Nvim does not support cpoptions flag "*"' + let save_cpo = &cpo + let x = 0 + new + set cpo-=* + let @a = 'let x += 1' + call assert_fails('*a', 'E20:') + set cpo+=* + *a + call assert_equal(1, x) + close! + let &cpo = save_cpo +endfunc + +" Test for the '<' flag in 'cpo' is in the test_mapping.vim file + +" Test for the '>' flag in 'cpo' (use a new line when appending to a register) +func Test_cpo_gt() + let save_cpo = &cpo + new + call setline(1, 'one two') + set cpo-=> + let @r = '' + normal gg"Rye + normal "Rye + call assert_equal("oneone", @r) + set cpo+=> + let @r = '' + normal gg"Rye + normal "Rye + call assert_equal("\none\none", @r) + close! + let &cpo = save_cpo +endfunc + +" Test for the ';' flag in 'cpo' +" Test for t,f,F,T movement commands and 'cpo-;' setting +func Test_cpo_semicolon() + let save_cpo = &cpo + new + call append(0, ["aaa two three four", " zzz", "yyy ", + \ "bbb yee yoo four", "ccc two three four", + \ "ddd yee yoo four"]) + set cpo-=; + 1 + normal! 0tt;D + 2 + normal! 0fz;D + 3 + normal! $Fy;D + 4 + normal! $Ty;D + set cpo+=; + 5 + normal! 0tt;;D + 6 + normal! $Ty;;D + + call assert_equal('aaa two', getline(1)) + call assert_equal(' z', getline(2)) + call assert_equal('y', getline(3)) + call assert_equal('bbb y', getline(4)) + call assert_equal('ccc', getline(5)) + call assert_equal('ddd yee y', getline(6)) + close! + let &cpo = save_cpo +endfunc + +" Test for the '#' flag in 'cpo' (count before 'D', 'o' and 'O' operators) +func Test_cpo_hash() + throw 'Skipped: Nvim does not support cpoptions flag "#"' + let save_cpo = &cpo + new + set cpo-=# + call setline(1, ['one', 'two', 'three']) + normal gg2D + call assert_equal(['three'], getline(1, '$')) + normal gg2ofour + call assert_equal(['three', 'four', 'four'], getline(1, '$')) + normal gg2Otwo + call assert_equal(['two', 'two', 'three', 'four', 'four'], getline(1, '$')) + %d + set cpo+=# + call setline(1, ['one', 'two', 'three']) + normal gg2D + call assert_equal(['', 'two', 'three'], getline(1, '$')) + normal gg2oone + call assert_equal(['', 'one', 'two', 'three'], getline(1, '$')) + normal gg2Ozero + call assert_equal(['zero', '', 'one', 'two', 'three'], getline(1, '$')) + close! + let &cpo = save_cpo +endfunc + +" Test for the '&' flag in 'cpo'. The swap file is kept when a buffer is still +" loaded and ':preserve' is used. +func Test_cpo_ampersand() + throw 'Skipped: Nvim does not support cpoptions flag "&"' + call writefile(['one'], 'Xfile') + let after =<< trim [CODE] + set cpo+=& + preserve + qall + [CODE] + if RunVim([], after, 'Xfile') + call assert_equal(1, filereadable('.Xfile.swp')) + call delete('.Xfile.swp') + endif + call delete('Xfile') +endfunc + +" Test for the '\' flag in 'cpo' (backslash in a [] range in a search pattern) +func Test_cpo_backslash() + throw 'Skipped: Nvim does not support cpoptions flag "\"' + let save_cpo = &cpo + new + call setline(1, ['', " \\-string"]) + set cpo-=\ + exe 'normal gg/[ \-]' .. "\n" + call assert_equal(3, col('.')) + set cpo+=\ + exe 'normal gg/[ \-]' .. "\n" + call assert_equal(2, col('.')) + close! + let &cpo = save_cpo +endfunc + +" Test for the '/' flag in 'cpo' is in the test_substitute.vim file + +" Test for the '{' flag in 'cpo' (the "{" and "}" commands stop at a { +" character at the start of a line) +func Test_cpo_brace() + throw 'Skipped: Nvim does not support cpoptions flag "{"' + let save_cpo = &cpo + new + call setline(1, ['', '{', ' int i;', '}', '']) + set cpo-={ + normal gg} + call assert_equal(5, line('.')) + normal G{ + call assert_equal(1, line('.')) + set cpo+={ + normal gg} + call assert_equal(2, line('.')) + normal G{ + call assert_equal(2, line('.')) + close! + let &cpo = save_cpo +endfunc + +" Test for the '.' flag in 'cpo' (:cd command fails if the current buffer is +" modified) +func Test_cpo_dot() + throw 'Skipped: Nvim does not support cpoptions flag "."' + let save_cpo = &cpo + new Xfoo + call setline(1, 'foo') + let save_dir = getcwd() + set cpo+=. + + " :cd should fail when buffer is modified and 'cpo' contains dot. + call assert_fails('cd ..', 'E747:') + call assert_equal(save_dir, getcwd()) + + " :cd with exclamation mark should succeed. + cd! .. + call assert_notequal(save_dir, getcwd()) + + " :cd should succeed when buffer has been written. + w! + exe 'cd ' .. fnameescape(save_dir) + call assert_equal(save_dir, getcwd()) + + call delete('Xfoo') + set cpo& + close! + let &cpo = save_cpo +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index 3c9a7a3986..04faeca455 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -2644,7 +2644,6 @@ endfunc " Test for cw cW ce func Test_normal39_cw() " Test for cw and cW on whitespace - " and cpo+=w setting new set tw=0 call append(0, 'here are some words') @@ -2652,14 +2651,6 @@ func Test_normal39_cw() call assert_equal('hereZZZare some words', getline('.')) norm! 1gg0elcWYYY call assert_equal('hereZZZareYYYsome words', getline('.')) - " Nvim: no "w" flag in 'cpoptions'. - " set cpo+=w - " call setline(1, 'here are some words') - " norm! 1gg0elcwZZZ - " call assert_equal('hereZZZ are some words', getline('.')) - " norm! 1gg2elcWYYY - " call assert_equal('hereZZZ areYYY some words', getline('.')) - set cpo-=w norm! 2gg0cwfoo call assert_equal('foo', getline('.')) -- cgit From 2476f41a4a4dcf940bce9ea9ae48a6017a35fbc2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 4 Nov 2022 19:49:23 +0800 Subject: vim-patch:8.2.1022: various parts of code not covered by tests Problem: Various parts of code not covered by tests. Solution: Add more tests. (Yegappan Lakshmanan, closes vim/vim#6300) https://github.com/vim/vim/commit/845e0ee59430eac07e74b6cb92020e420d17953d Omit test_iminsert.vim: the commit that created this file was N/A. Omit test_viminfo.vim: the added tests are N/A. --- src/nvim/testdir/test_blob.vim | 1 + src/nvim/testdir/test_cpoptions.vim | 20 ++++-- src/nvim/testdir/test_edit.vim | 112 +++++++++++++++++++++++++++++++++- src/nvim/testdir/test_selectmode.vim | 3 + src/nvim/testdir/test_tabpage.vim | 11 ++++ src/nvim/testdir/test_tagjump.vim | 55 ++++++++++++++++- src/nvim/testdir/test_textformat.vim | 14 +++++ src/nvim/testdir/test_virtualedit.vim | 18 ++++++ src/nvim/testdir/test_visual.vim | 9 +++ 9 files changed, 233 insertions(+), 10 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_blob.vim b/src/nvim/testdir/test_blob.vim index 151de71312..1c0261933f 100644 --- a/src/nvim/testdir/test_blob.vim +++ b/src/nvim/testdir/test_blob.vim @@ -252,6 +252,7 @@ func Test_blob_func_remove() call assert_fails("call remove(b, 3, 2)", 'E979:') call assert_fails("call remove(1, 0)", 'E896:') call assert_fails("call remove(b, b)", 'E974:') + call assert_fails("call remove(b, 1, [])", 'E745:') call assert_fails("call remove(v:_null_blob, 1, 2)", 'E979:') " Translated from v8.2.3284 diff --git a/src/nvim/testdir/test_cpoptions.vim b/src/nvim/testdir/test_cpoptions.vim index f0732934d4..cc281ef521 100644 --- a/src/nvim/testdir/test_cpoptions.vim +++ b/src/nvim/testdir/test_cpoptions.vim @@ -248,6 +248,7 @@ func Test_cpo_H() endfunc " TODO: Add a test for the 'i' flag in 'cpo' +" Interrupting the reading of a file will leave it modified. " Test for the 'I' flag in 'cpo' (deleting autoindent when using arrow keys) func Test_cpo_I() @@ -296,9 +297,12 @@ func Test_cpo_J() let &cpo = save_cpo endfunc -" TODO: Add a test for the 'k' flag in 'cpo' +" TODO: Add a test for the 'k' flag in 'cpo'. +" Disable the recognition of raw key codes in mappings, abbreviations, and the +" "to" part of menu commands. -" TODO: Add a test for the 'K' flag in 'cpo' +" TODO: Add a test for the 'K' flag in 'cpo'. +" Don't wait for a key code to complete when it is halfway a mapping. " Test for the 'l' flag in 'cpo' (backslash in a [] range) func Test_cpo_l() @@ -336,7 +340,9 @@ func Test_cpo_L() let &cpo = save_cpo endfunc -" TODO: Add a test for the 'm' flag in 'cpo' +" TODO: Add a test for the 'm' flag in 'cpo'. +" When included, a showmatch will always wait half a second. When not +" included, a showmatch will wait half a second or until a character is typed. " Test for the 'M' flag in 'cpo' (% with escape parenthesis) func Test_cpo_M() @@ -500,7 +506,9 @@ func Test_cpo_R() let &cpo = save_cpo endfunc -" TODO: Add a test for the 's' flag in 'cpo' +" TODO: Add a test for the 's' flag in 'cpo'. +" Set buffer options when entering the buffer for the first time. If not +" present the options are set when the buffer is created. " Test for the 'S' flag in 'cpo' (copying buffer options) func Test_cpo_S() @@ -545,8 +553,8 @@ func Test_cpo_u() let &cpo = save_cpo endfunc -" TODO: Add a test for the 'v' flag in 'cpo' (backspace doesn't remove -" characters from the screen) +" TODO: Add a test for the 'v' flag in 'cpo'. +" Backspaced characters remain visible on the screen in Insert mode. " Test for the 'w' flag in 'cpo' ('cw' on a blank character changes only one " character) diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index d19826f5b9..89fd73351d 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -1433,9 +1433,7 @@ endfunc func Test_edit_rightleft() " Cursor in rightleft mode moves differently - if !exists("+rightleft") - return - endif + CheckFeature rightleft call NewWindow(10, 20) call setline(1, ['abc', 'def', 'ghi']) call cursor(1, 2) @@ -1480,6 +1478,13 @@ func Test_edit_rightleft() \" ihg", \" ~"] call assert_equal(join(expect, "\n"), join(lines, "\n")) + %d _ + " call test_override('redraw_flag', 1) + " call test_override('char_avail', 1) + call feedkeys("a\x41", "xt") + redraw! + call assert_equal(repeat(' ', 19) .. 'A', Screenline(1)) + " call test_override('ALL', 0) set norightleft bw! endfunc @@ -1868,6 +1873,107 @@ func Test_edit_insertmode_ex_edit() call delete('Xtest_edit_insertmode_ex_edit') endfunc +" Pressing escape in 'insertmode' should beep +func Test_edit_insertmode_esc_beeps() + throw "Skipped: Nvim does not support 'insertmode'" + new + set insertmode + call assert_beeps("call feedkeys(\"one\\", 'xt')") + set insertmode& + " unsupported CTRL-G command should beep in insert mode. + call assert_beeps("normal i\l") + close! +endfunc + +" Test for 'hkmap' and 'hkmapp' +func Test_edit_hkmap() + CheckFeature rightleft + if has('win32') && !has('gui') + " Test fails on the MS-Windows terminal version + return + endif + new + + set revins hkmap + let str = 'abcdefghijklmnopqrstuvwxyz' + let str ..= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + let str ..= '`/'',.;' + call feedkeys('i' .. str, 'xt') + let expected = "óõú,.;" + let expected ..= "ZYXWVUTSRQPONMLKJIHGFEDCBA" + let expected ..= "æèñ'äåàãø/ôíîöêìçïéòë÷âáðù" + call assert_equal(expected, getline(1)) + + %d + set revins hkmap hkmapp + let str = 'abcdefghijklmnopqrstuvwxyz' + let str ..= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + call feedkeys('i' .. str, 'xt') + let expected = "õYXWVUTSRQóOïíLKJIHGFEDêBA" + let expected ..= "öòXùåèúæø'ôñðîì÷çéäâóǟãëáà" + call assert_equal(expected, getline(1)) + + set revins& hkmap& hkmapp& + close! +endfunc + +" Test for 'allowrevins' and using CTRL-_ in insert mode +func Test_edit_allowrevins() + CheckFeature rightleft + new + set allowrevins + call feedkeys("iABC\DEF\GHI", 'xt') + call assert_equal('ABCFEDGHI', getline(1)) + set allowrevins& + close! +endfunc + +" Test for inserting a register in insert mode using CTRL-R +func Test_edit_insert_reg() + throw 'Skipped: use test/functional/legacy/edit_spec.lua' + new + let g:Line = '' + func SaveFirstLine() + let g:Line = Screenline(1) + return 'r' + endfunc + inoremap SaveFirstLine() + call test_override('redraw_flag', 1) + call test_override('char_avail', 1) + let @r = 'sample' + call feedkeys("a\=SaveFirstLine()\", "xt") + call assert_equal('"', g:Line) + call test_override('ALL', 0) + close! +endfunc + +" When a character is inserted at the last position of the last line in a +" window, the window contents should be scrolled one line up. If the top line +" is part of a fold, then the entire fold should be scrolled up. +func Test_edit_lastline_scroll() + new + let h = winheight(0) + let lines = ['one', 'two', 'three'] + let lines += repeat(['vim'], h - 4) + call setline(1, lines) + call setline(h, repeat('x', winwidth(0) - 1)) + call feedkeys("GAx", 'xt') + redraw! + call assert_equal(h - 1, winline()) + call assert_equal(2, line('w0')) + + " scroll with a fold + 1,2fold + normal gg + call setline(h + 1, repeat('x', winwidth(0) - 1)) + call feedkeys("GAx", 'xt') + redraw! + call assert_equal(h - 1, winline()) + call assert_equal(3, line('w0')) + + close! +endfunc + func Test_edit_browse() " in the GUI this opens a file picker, we only test the terminal behavior CheckNotGui diff --git a/src/nvim/testdir/test_selectmode.vim b/src/nvim/testdir/test_selectmode.vim index f2cab45450..041f0592f1 100644 --- a/src/nvim/testdir/test_selectmode.vim +++ b/src/nvim/testdir/test_selectmode.vim @@ -34,6 +34,9 @@ func Test_selectmode_start() set selectmode=cmd call feedkeys('gvabc', 'xt') call assert_equal('abctdef', getline(1)) + " arrow keys without shift should not start selection + call feedkeys("A\\\ro", 'xt') + call assert_equal('roabctdef', getline(1)) set selectmode= keymodel= bw! endfunc diff --git a/src/nvim/testdir/test_tabpage.vim b/src/nvim/testdir/test_tabpage.vim index 6d468ec9de..4ada48d56c 100644 --- a/src/nvim/testdir/test_tabpage.vim +++ b/src/nvim/testdir/test_tabpage.vim @@ -623,6 +623,17 @@ func Test_tabpage_close_cmdwin() tabonly endfunc +" Pressing in insert mode should go to the previous tab page +" and should go to the next tab page +func Test_tabpage_Ctrl_Pageup() + tabnew + call feedkeys("i\", 'xt') + call assert_equal(1, tabpagenr()) + call feedkeys("i\", 'xt') + call assert_equal(2, tabpagenr()) + %bw! +endfunc + " Return the terminal key code for selecting a tab page from the tabline. This " sequence contains the following codes: a CSI (0x9b), KS_TABLINE (0xf0), " KS_FILLER (0x58) and then the tab page number. diff --git a/src/nvim/testdir/test_tagjump.vim b/src/nvim/testdir/test_tagjump.vim index 04c0218f74..592e13e340 100644 --- a/src/nvim/testdir/test_tagjump.vim +++ b/src/nvim/testdir/test_tagjump.vim @@ -282,6 +282,7 @@ func Test_tag_file_encoding() call delete('Xtags1') endfunc +" Test for emacs-style tags file (TAGS) func Test_tagjump_etags() if !has('emacs_tags') return @@ -1099,7 +1100,7 @@ func Test_tselect_listing() call writefile([ \ "!_TAG_FILE_ENCODING\tutf-8\t//", \ "first\tXfoo\t1" .. ';"' .. "\tv\ttyperef:typename:int\tfile:", - \ "first\tXfoo\t2" .. ';"' .. "\tv\ttyperef:typename:char\tfile:"], + \ "first\tXfoo\t2" .. ';"' .. "\tkind:v\ttyperef:typename:char\tfile:"], \ 'Xtags') set tags=Xtags @@ -1422,4 +1423,56 @@ func Test_tag_length() set tags& taglength& endfunc +" Tests for errors in a tags file +func Test_tagfile_errors() + set tags=Xtags + + " missing search pattern or line number for a tag + call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", + \ "foo\tXfile\t"], 'Xtags', 'b') + call writefile(['foo'], 'Xfile') + + enew + tag foo + call assert_equal('', @%) + let caught_431 = v:false + try + eval taglist('.*') + catch /:E431:/ + let caught_431 = v:true + endtry + call assert_equal(v:true, caught_431) + + call delete('Xtags') + call delete('Xfile') + set tags& +endfunc + +" When :stag fails to open the file, should close the new window +func Test_stag_close_window_on_error() + new | only + set tags=Xtags + call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", + \ "foo\tXfile\t1"], 'Xtags') + call writefile(['foo'], 'Xfile') + call writefile([], '.Xfile.swp') + " Remove the catch-all that runtest.vim adds + au! SwapExists + augroup StagTest + au! + autocmd SwapExists Xfile let v:swapchoice='q' + augroup END + + stag foo + call assert_equal(1, winnr('$')) + call assert_equal('', @%) + + augroup StagTest + au! + augroup END + call delete('Xfile') + call delete('.Xfile.swp') + set tags& +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_textformat.vim b/src/nvim/testdir/test_textformat.vim index 4eb6e69adf..3bce2eb24d 100644 --- a/src/nvim/testdir/test_textformat.vim +++ b/src/nvim/testdir/test_textformat.vim @@ -1096,6 +1096,20 @@ func Test_fo_a_w() call feedkeys("iabc abc a abc\k0weade", 'xt') call assert_equal(['abc abcde ', 'a abc'], getline(1, '$')) + " when a line ends with space, it is not broken up. + %d + call feedkeys("ione two to ", 'xt') + call assert_equal('one two to ', getline(1)) + + " when a line ends with spaces and backspace is used in the next line, the + " last space in the previous line should be removed. + %d + set backspace=indent,eol,start + call setline(1, ['one ', 'two']) + exe "normal 2Gi\" + call assert_equal(['one two'], getline(1, '$')) + set backspace& + " Test for 'a', 'w' and '1' options. setlocal textwidth=0 setlocal fo=1aw diff --git a/src/nvim/testdir/test_virtualedit.vim b/src/nvim/testdir/test_virtualedit.vim index ddc7c20637..edf68e6482 100644 --- a/src/nvim/testdir/test_virtualedit.vim +++ b/src/nvim/testdir/test_virtualedit.vim @@ -357,6 +357,24 @@ func Test_delete_break_tab() close! endfunc +" Test for using , and in virtual edit mode +" to erase character, word and line. +func Test_ve_backspace() + new + call setline(1, 'sample') + set virtualedit=all + set backspace=indent,eol,start + exe "normal 15|i\\" + call assert_equal([0, 1, 7, 5], getpos('.')) + exe "normal 15|i\" + call assert_equal([0, 1, 6, 0], getpos('.')) + exe "normal 15|i\" + call assert_equal([0, 1, 1, 0], getpos('.')) + set backspace& + set virtualedit& + close! +endfunc + " After calling s:TryVirtualeditReplace(), line 1 will contain one of these " two strings, depending on whether virtual editing is on or off. let s:result_ve_on = 'a x' diff --git a/src/nvim/testdir/test_visual.vim b/src/nvim/testdir/test_visual.vim index a9c057088d..712ea343ed 100644 --- a/src/nvim/testdir/test_visual.vim +++ b/src/nvim/testdir/test_visual.vim @@ -225,6 +225,15 @@ func Test_virtual_replace() exe "normal iabcdefghijklmnopqrst\0gRAB\tIJKLMNO\tQR" call assert_equal(['AB......CDEFGHI.Jkl', \ 'AB IJKLMNO QRst'], getline(12, 13)) + + " Test inserting Tab with 'noexpandtab' and 'softabstop' set to 4 + %d + call setline(1, 'aaaaaaaaaaaaa') + set softtabstop=4 + exe "normal gggR\\x" + call assert_equal("\txaaaa", getline(1)) + set softtabstop& + enew! set noai bs&vim if exists('save_t_kD') -- cgit From 26a9f786c41bc8fa383e3ffe55a1fe77b50fb320 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 4 Nov 2022 20:31:25 +0800 Subject: vim-patch:8.2.1810: some code in normal.c not covered by tests Problem: Some code in normal.c not covered by tests. Solution: Add normal mode tests. (Yegappan Lakshmanan, closes vim/vim#7086) https://github.com/vim/vim/commit/d7e5e9430ae192c76f1f03c3ac53fae823d94c33 --- src/nvim/testdir/test_charsearch.vim | 31 ++++++++++++++-- src/nvim/testdir/test_normal.vim | 68 ++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_charsearch.vim b/src/nvim/testdir/test_charsearch.vim index 4e6a75c3a0..54e0a62ce5 100644 --- a/src/nvim/testdir/test_charsearch.vim +++ b/src/nvim/testdir/test_charsearch.vim @@ -51,7 +51,7 @@ func Test_csearch_virtualedit() normal! tb call assert_equal([0, 1, 2, 6], getpos('.')) set virtualedit& - close! + bw! endfunc " Test for character search failure in latin1 encoding @@ -65,7 +65,34 @@ func Test_charsearch_latin1() call assert_beeps('normal $Fz') call assert_beeps('normal $Tx') let &encoding = save_enc - close! + bw! +endfunc + +" Test for using character search to find a multibyte character with composing +" characters. +func Test_charsearch_composing_char() + new + call setline(1, "one two thq\u0328\u0301r\u0328\u0301ree") + call feedkeys("fr\u0328\u0301", 'xt') + call assert_equal([0, 1, 16, 0, 12], getcurpos()) + + " use character search with a multi-byte character followed by a + " non-composing character + call setline(1, "abc deȉf ghi") + call feedkeys("ggcf\u0209\u0210", 'xt') + call assert_equal("\u0210f ghi", getline(1)) + bw! +endfunc + +" Test for character search with 'hkmap' +func Test_charsearch_hkmap() + new + set hkmap + call setline(1, "ùðáâ÷ëòéïçìêöî") + call feedkeys("fë", 'xt') + call assert_equal([0, 1, 11, 0, 6], getcurpos()) + set hkmap& + bw! endfunc " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index 04faeca455..6804d549c6 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -120,6 +120,39 @@ func Test_normal01_keymodel() call feedkeys("Vkk\yy", 'tx') call assert_equal(['47', '48', '49', '50'], getreg(0, 0, 1)) + " Test for using special keys to start visual selection + %d + call setline(1, ['red fox tail', 'red fox tail', 'red fox tail']) + set keymodel=startsel + " Test for and + call cursor(1, 1) + call feedkeys("\y", 'xt') + call assert_equal([0, 1, 1, 0], getpos("'<")) + call assert_equal([0, 3, 1, 0], getpos("'>")) + call feedkeys("Gz\8|\y", 'xt') + call assert_equal([0, 2, 1, 0], getpos("'<")) + call assert_equal([0, 3, 8, 0], getpos("'>")) + " Test for and + call cursor(2, 12) + call feedkeys("\y", 'xt') + call assert_equal([0, 1, 1, 0], getpos("'<")) + call assert_equal([0, 2, 12, 0], getpos("'>")) + call cursor(1, 4) + call feedkeys("\y", 'xt') + call assert_equal([0, 1, 4, 0], getpos("'<")) + call assert_equal([0, 3, 13, 0], getpos("'>")) + " Test for and + call cursor(2, 5) + call feedkeys("\y", 'xt') + call assert_equal([0, 2, 5, 0], getpos("'<")) + call assert_equal([0, 2, 9, 0], getpos("'>")) + call cursor(2, 9) + call feedkeys("\y", 'xt') + call assert_equal([0, 2, 5, 0], getpos("'<")) + call assert_equal([0, 2, 9, 0], getpos("'>")) + + set keymodel& + " clean up bw! endfunc @@ -509,6 +542,14 @@ func Test_normal10_expand() call assert_equal(expected[i], expand(''), 'i == ' . i) endfor + " Test for in state.val and ptr->val + call setline(1, 'x = state.val;') + call cursor(1, 10) + call assert_equal('state.val', expand('')) + call setline(1, 'x = ptr->val;') + call cursor(1, 9) + call assert_equal('ptr->val', expand('')) + if executable('echo') " Test expand(`...`) i.e. backticks command expansion. " MS-Windows has a trailing space. @@ -523,6 +564,19 @@ func Test_normal10_expand() bw! endfunc +" Test for expand() in latin1 encoding +func Test_normal_expand_latin1() + new + let save_enc = &encoding + " set encoding=latin1 + call setline(1, 'val = item->color;') + call cursor(1, 11) + call assert_equal('color', expand("")) + call assert_equal('item->color', expand("")) + let &encoding = save_enc + bw! +endfunc + func Test_normal11_showcmd() " test for 'showcmd' 10new @@ -547,6 +601,13 @@ func Test_normal11_showcmd() redraw! call assert_match('1-3$', Screenline(&lines)) call feedkeys("v", 'xt') + " test for visually selecting the end of line + call setline(1, ["foobar"]) + call feedkeys("$vl", 'xt') + redraw! + call assert_match('2$', Screenline(&lines)) + call feedkeys("y", 'xt') + call assert_equal("r\n", @") bw! endfunc @@ -2161,6 +2222,13 @@ func Test_normal31_r_cmd() normal gglvjjrx call assert_equal(['axx', 'xxx', 'xxf'], getline(1, '$')) + " replace with a multibyte character (with multiple composing characters) + %d + new + call setline(1, 'aaa') + exe "normal $ra\u0328\u0301" + call assert_equal("aaa\u0328\u0301", getline(1)) + " clean up set noautoindent bw! -- cgit From 2aafaa59928e17fd7858a89d203e2b2a07707601 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 4 Nov 2022 20:41:53 +0800 Subject: vim-patch:8.2.2901: some operators not fully tested Problem: Some operators not fully tested. Solution: Add a few test cases. (Yegappan Lakshmanan, closes vim/vim#8282) https://github.com/vim/vim/commit/3e72dcad8b752a42b6eaf71213e3f5d534175256 --- src/nvim/testdir/test_cpoptions.vim | 1 + src/nvim/testdir/test_increment.vim | 17 +++++++++++++++++ src/nvim/testdir/test_normal.vim | 31 +++++++++++++++++++++++++++++++ src/nvim/testdir/test_virtualedit.vim | 27 +++++++++++++++++++++++++++ 4 files changed, 76 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cpoptions.vim b/src/nvim/testdir/test_cpoptions.vim index cc281ef521..76d2c9542d 100644 --- a/src/nvim/testdir/test_cpoptions.vim +++ b/src/nvim/testdir/test_cpoptions.vim @@ -167,6 +167,7 @@ func Test_cpo_E() call assert_beeps('normal "ayl') " change an empty line call assert_beeps('normal lcTa') + call assert_beeps('normal 0c0') " delete an empty line call assert_beeps('normal D') call assert_beeps('normal dl') diff --git a/src/nvim/testdir/test_increment.vim b/src/nvim/testdir/test_increment.vim index 52355d86fb..3c2b88ef9f 100644 --- a/src/nvim/testdir/test_increment.vim +++ b/src/nvim/testdir/test_increment.vim @@ -877,4 +877,21 @@ func Test_normal_increment_with_virtualedit() set virtualedit& endfunc +" Test for incrementing a signed hexadecimal and octal number +func Test_normal_increment_signed_hexoct_nr() + new + " negative sign before a hex number should be ignored + call setline(1, ["-0x9"]) + exe "norm \" + call assert_equal(["-0xa"], getline(1, '$')) + exe "norm \" + call assert_equal(["-0x9"], getline(1, '$')) + call setline(1, ["-007"]) + exe "norm \" + call assert_equal(["-010"], getline(1, '$')) + exe "norm \" + call assert_equal(["-007"], getline(1, '$')) + bw! +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index 6804d549c6..5fc670e422 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -2125,6 +2125,16 @@ func Test_normal30_changecase() call assert_equal(['aaaaaa', 'AAAAaa'], getline(1, 2)) set whichwrap& + " try changing the case with a double byte encoding (DBCS) + %bw! + let enc = &enc + " set encoding=cp932 + call setline(1, "\u8470") + normal ~ + normal gU$gu$gUgUg~g~gugu + call assert_equal("\u8470", getline(1)) + let &encoding = enc + " clean up bw! endfunc @@ -3499,6 +3509,27 @@ func Test_normal_percent_jump() close! endfunc +" Test for << and >> commands to shift text by 'shiftwidth' +func Test_normal_shift_rightleft() + new + call setline(1, ['one', '', "\t", ' two', "\tthree", ' four']) + set shiftwidth=2 tabstop=8 + normal gg6>> + call assert_equal([' one', '', "\t ", ' two', "\t three", "\tfour"], + \ getline(1, '$')) + normal ggVG2>> + call assert_equal([' one', '', "\t ", "\ttwo", + \ "\t three", "\t four"], getline(1, '$')) + normal gg6<< + call assert_equal([' one', '', "\t ", ' two', "\t three", + \ "\t four"], getline(1, '$')) + normal ggVG2<< + call assert_equal(['one', '', "\t", ' two', "\tthree", ' four'], + \ getline(1, '$')) + set shiftwidth& tabstop& + bw! +endfunc + " Some commands like yy, cc, dd, >>, << and !! accept a count after " typing the first letter of the command. func Test_normal_count_after_operator() diff --git a/src/nvim/testdir/test_virtualedit.vim b/src/nvim/testdir/test_virtualedit.vim index edf68e6482..2bf8c3fc77 100644 --- a/src/nvim/testdir/test_virtualedit.vim +++ b/src/nvim/testdir/test_virtualedit.vim @@ -80,6 +80,10 @@ func Test_edit_change() call setline(1, "\t⒌") normal Cx call assert_equal('x', getline(1)) + " Do a visual block change + call setline(1, ['a', 'b', 'c']) + exe "normal gg3l\2jcx" + call assert_equal(['a x', 'b x', 'c x'], getline(1, '$')) bwipe! set virtualedit= endfunc @@ -289,6 +293,16 @@ func Test_replace_after_eol() call append(0, '"r"') normal gg$5lrxa call assert_equal('"r" x', getline(1)) + " visual block replace + %d _ + call setline(1, ['a', '', 'b']) + exe "normal 2l\2jrx" + call assert_equal(['a x', ' x', 'b x'], getline(1, '$')) + " visual characterwise selection replace after eol + %d _ + call setline(1, 'a') + normal 4lv2lrx + call assert_equal('a xxx', getline(1)) bwipe! set virtualedit= endfunc @@ -375,6 +389,19 @@ func Test_ve_backspace() close! endfunc +" Test for delete (x) on EOL character and after EOL +func Test_delete_past_eol() + new + call setline(1, "ab") + set virtualedit=all + exe "normal 2lx" + call assert_equal('ab', getline(1)) + exe "normal 10lx" + call assert_equal('ab', getline(1)) + set virtualedit& + bw! +endfunc + " After calling s:TryVirtualeditReplace(), line 1 will contain one of these " two strings, depending on whether virtual editing is on or off. let s:result_ve_on = 'a x' -- cgit From b7b4914fe44b4a192379659dbcb958c63b82327c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 08:03:34 +0800 Subject: vim-patch:8.2.0433: INT signal not properly tested Problem: INT signal not properly tested. Solution: Add a test. Also clean up some unnecessary lines. (Dominique Pelle, closes vim/vim#5828) https://github.com/vim/vim/commit/bad8804cdd739a5a7321b8411ad7fd4f45741b54 --- src/nvim/testdir/test_display.vim | 2 -- src/nvim/testdir/test_ex_mode.vim | 1 - src/nvim/testdir/test_signals.vim | 31 ++++++++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 4 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_display.vim b/src/nvim/testdir/test_display.vim index 13796449ab..679fe89628 100644 --- a/src/nvim/testdir/test_display.vim +++ b/src/nvim/testdir/test_display.vim @@ -195,8 +195,6 @@ func Test_edit_long_file_name() call VerifyScreenDump(buf, 'Test_long_file_name_1', {}) - call term_sendkeys(buf, ":q\") - " clean up call StopVimInTerminal(buf) call delete(longName) diff --git a/src/nvim/testdir/test_ex_mode.vim b/src/nvim/testdir/test_ex_mode.vim index 2f734cba26..93100732ed 100644 --- a/src/nvim/testdir/test_ex_mode.vim +++ b/src/nvim/testdir/test_ex_mode.vim @@ -97,7 +97,6 @@ func Test_Ex_substitute() call term_sendkeys(buf, ":vi\") call WaitForAssert({-> assert_match('foo bar', term_getline(buf, 1))}, 1000) - call term_sendkeys(buf, ":q!\n") call StopVimInTerminal(buf) endfunc diff --git a/src/nvim/testdir/test_signals.vim b/src/nvim/testdir/test_signals.vim index e1c6e5d11f..31b76919e1 100644 --- a/src/nvim/testdir/test_signals.vim +++ b/src/nvim/testdir/test_signals.vim @@ -53,7 +53,7 @@ endfunc " Test signal PWR, which should update the swap file. func Test_signal_PWR() if !HasSignal('PWR') - return + throw 'Skipped: PWR signal not supported' endif " Set a very large 'updatetime' and 'updatecount', so that we can be sure @@ -79,6 +79,35 @@ func Test_signal_PWR() set updatetime& updatecount& endfunc +" Test signal INT. Handler sets got_int. It should be like typing CTRL-C. +func Test_signal_INT() + if !HasSignal('INT') + throw 'Skipped: INT signal not supported' + endif + + " Skip the rest of the test when running with valgrind as signal INT is not + " received somehow by Vim when running with valgrind. + let cmd = GetVimCommand() + if cmd =~ 'valgrind' + throw 'Skipped: cannot test signal INT with valgrind' + endif + + if !CanRunVimInTerminal() + throw 'Skipped: cannot run vim in terminal' + endif + let buf = RunVimInTerminal('', {'rows': 6}) + let pid_vim = term_getjob(buf)->job_info().process + + " Check that an endless loop in Vim is interrupted by signal INT. + call term_sendkeys(buf, ":while 1 | endwhile\n") + call WaitForAssert({-> assert_equal(':while 1 | endwhile', term_getline(buf, 6))}) + exe 'silent !kill -s INT ' .. pid_vim + call term_sendkeys(buf, ":call setline(1, 'INTERUPTED')\n") + call WaitForAssert({-> assert_equal('INTERUPTED', term_getline(buf, 1))}) + + call StopVimInTerminal(buf) +endfunc + " Test a deadly signal. " " There are several deadly signals: SISEGV, SIBUS, SIGTERM... -- cgit From e30929cda5cad8afb384cdb5b1ce62758dca6bde Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 07:34:06 +0800 Subject: vim-patch:8.2.0644: insufficient testing for invalid function arguments Problem: Insufficient testing for invalid function arguments. Solution: Add more tests. (Yegappan Lakshmanan, closes vim/vim#5988) https://github.com/vim/vim/commit/99fa721944dda9d07c53c907c33466728df5c271 Omit test_listener.vim: changed again in patch 8.2.1183. Omit test_textprop.vim: changed again in patch 8.2.1183. Cherry-pick quickfix feature checks from patch 8.1.2373. Omit Test_saveas() change: duplicate and removed in patch 8.2.0866. --- src/nvim/testdir/test_bufline.vim | 1 + src/nvim/testdir/test_clientserver.vim | 1 + src/nvim/testdir/test_expr.vim | 1 + src/nvim/testdir/test_functions.vim | 21 +++++++++++++++------ src/nvim/testdir/test_match.vim | 6 +++++- src/nvim/testdir/test_menu.vim | 1 + src/nvim/testdir/test_registers.vim | 4 +++- src/nvim/testdir/test_reltime.vim | 4 ++++ src/nvim/testdir/test_window_cmd.vim | 12 ++++++++++++ src/nvim/testdir/test_window_id.vim | 12 ++++++++++++ src/nvim/testdir/test_writefile.vim | 7 +++++++ 11 files changed, 62 insertions(+), 8 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_bufline.vim b/src/nvim/testdir/test_bufline.vim index 8f853fe44e..5a47f8ef25 100644 --- a/src/nvim/testdir/test_bufline.vim +++ b/src/nvim/testdir/test_bufline.vim @@ -26,6 +26,7 @@ func Test_setbufline_getbufline() call assert_equal(['d'], getbufline(b, 4)) call assert_equal(['e'], getbufline(b, 5)) call assert_equal([], getbufline(b, 6)) + call assert_equal([], getbufline(b, 2, 1)) exe "bwipe! " . b endfunc diff --git a/src/nvim/testdir/test_clientserver.vim b/src/nvim/testdir/test_clientserver.vim index 943f79d98f..301dad8341 100644 --- a/src/nvim/testdir/test_clientserver.vim +++ b/src/nvim/testdir/test_clientserver.vim @@ -182,6 +182,7 @@ func Test_client_server() endif endtry + call assert_fails('call remote_startserver([])', 'E730:') call assert_fails("let x = remote_peek([])", 'E730:') call assert_fails("let x = remote_read('vim10')", 'E277:') call assert_fails("call server2client('abc', 'xyz')", 'E258:') diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index dc8401003d..0579ce7dcb 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -528,6 +528,7 @@ func Test_setmatches() endif eval set->setmatches() call assert_equal(exp, getmatches()) + call assert_fails('let m = setmatches([], [])', 'E957:') endfunc func Test_empty_concatenate() diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index f6c16a366b..5718266dae 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -29,6 +29,8 @@ func Test_has() call assert_equal(0, and(has('ttyout'), 0)) call assert_equal(1, has('multi_byte_encoding')) endif + call assert_equal(1, has('vcon', 1)) + call assert_equal(1, has('mouse_gpm_enabled', 1)) call assert_equal(0, has('nonexistent')) call assert_equal(0, has('nonexistent', 1)) @@ -1331,12 +1333,15 @@ endfunc " Test for the inputdialog() function func Test_inputdialog() - CheckNotGui - - call feedkeys(":let v=inputdialog('Q:', 'xx', 'yy')\\", 'xt') - call assert_equal('xx', v) - call feedkeys(":let v=inputdialog('Q:', 'xx', 'yy')\\", 'xt') - call assert_equal('yy', v) + if has('gui_running') + call assert_fails('let v=inputdialog([], "xx")', 'E730:') + call assert_fails('let v=inputdialog("Q", [])', 'E730:') + else + call feedkeys(":let v=inputdialog('Q:', 'xx', 'yy')\\", 'xt') + call assert_equal('xx', v) + call feedkeys(":let v=inputdialog('Q:', 'xx', 'yy')\\", 'xt') + call assert_equal('yy', v) + endif endfunc " Test for inputlist() @@ -1387,6 +1392,7 @@ func Test_balloon_show() call balloon_show('hi!') if !has('gui_running') call balloon_show(range(3)) + call balloon_show([]) endif endfunc @@ -2271,6 +2277,9 @@ func Test_range() call assert_fails('let x=range(2, 8, 0)', 'E726:') call assert_fails('let x=range(3, 1)', 'E727:') call assert_fails('let x=range(1, 3, -2)', 'E727:') + call assert_fails('let x=range([])', 'E745:') + call assert_fails('let x=range(1, [])', 'E745:') + call assert_fails('let x=range(1, 4, [])', 'E745:') endfunc func Test_garbagecollect_now_fails() diff --git a/src/nvim/testdir/test_match.vim b/src/nvim/testdir/test_match.vim index fe931fefb2..352493de9c 100644 --- a/src/nvim/testdir/test_match.vim +++ b/src/nvim/testdir/test_match.vim @@ -160,12 +160,14 @@ endfunc func Test_matchadd_error() call clearmatches() " Nvim: not an error anymore: + " call assert_fails("call matchadd('GroupDoesNotExist', 'X')", 'E28:') call matchadd('GroupDoesNotExist', 'X') call assert_equal([{'group': 'GroupDoesNotExist', 'pattern': 'X', 'priority': 10, 'id': 1206}], getmatches()) call assert_fails("call matchadd('Search', '\\(')", 'E475:') call assert_fails("call matchadd('Search', 'XXX', 1, 123, 1)", 'E715:') call assert_fails("call matchadd('Error', 'XXX', 1, 3)", 'E798:') call assert_fails("call matchadd('Error', 'XXX', 1, 0)", 'E799:') + call assert_fails("call matchadd('Error', 'XXX', [], 0)", 'E745:') endfunc func Test_matchaddpos() @@ -305,7 +307,10 @@ func Test_matchaddpos_error() call assert_fails("call matchaddpos('Error', [1], 1, 123, 1)", 'E715:') call assert_fails("call matchaddpos('Error', [1], 1, 5, {'window':12345})", 'E957:') " Why doesn't the following error have an error code E...? + " call assert_fails("call matchaddpos('Error', [{}])", 'E290:') call assert_fails("call matchaddpos('Error', [{}])", 'E5031:') + call assert_equal(-1, matchaddpos('Error', v:_null_list)) + call assert_fails("call matchaddpos('Error', [1], [], 1)", 'E745:') endfunc func OtherWindowCommon() @@ -362,5 +367,4 @@ func Test_matchadd_other_window() call delete('XscriptMatchCommon') endfunc - " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_menu.vim b/src/nvim/testdir/test_menu.vim index 2e149ad5a5..58da0ed382 100644 --- a/src/nvim/testdir/test_menu.vim +++ b/src/nvim/testdir/test_menu.vim @@ -252,6 +252,7 @@ func Test_menu_info() nmenu Test.abc call assert_equal('', menu_info('Test.abc').rhs) call assert_fails('call menu_info([])', 'E730:') + call assert_fails('call menu_info("", [])', 'E730:') nunmenu Test " Test for defining menus in different modes diff --git a/src/nvim/testdir/test_registers.vim b/src/nvim/testdir/test_registers.vim index 40320c6405..5bdbbe7a22 100644 --- a/src/nvim/testdir/test_registers.vim +++ b/src/nvim/testdir/test_registers.vim @@ -285,7 +285,9 @@ func Test_get_register() " Test for inserting a multi-line register in the command line call feedkeys(":\r\", 'xt') - call assert_equal("a\rb", histget(':', -1)) " Modified because of #6137 + " Nvim: no trailing CR because of #6137 + " call assert_equal("a\rb\r", histget(':', -1)) + call assert_equal("a\rb", histget(':', -1)) call assert_fails('let r = getreg("=", [])', 'E745:') call assert_fails('let r = getreg("=", 1, [])', 'E745:') diff --git a/src/nvim/testdir/test_reltime.vim b/src/nvim/testdir/test_reltime.vim index b381f1ddbb..f4ce5de118 100644 --- a/src/nvim/testdir/test_reltime.vim +++ b/src/nvim/testdir/test_reltime.vim @@ -24,4 +24,8 @@ func Test_reltime() call assert_true(reltimefloat(differs) < 0.1) call assert_true(reltimefloat(differs) > 0.0) + call assert_equal(0, reltime({})) + call assert_equal(0, reltime({}, {})) endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim index 2ed537c601..c7b5896082 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -501,10 +501,13 @@ func Test_win_screenpos() call assert_equal([1, 32], win_screenpos(2)) call assert_equal([12, 1], win_screenpos(3)) call assert_equal([0, 0], win_screenpos(4)) + call assert_fails('let l = win_screenpos([])', 'E745:') only endfunc func Test_window_jump_tag() + CheckFeature quickfix + help /iccf call assert_match('^|iccf|', getline('.')) @@ -734,6 +737,7 @@ func Test_relative_cursor_position_in_one_line_window() only! bwipe! + call assert_fails('call winrestview(v:_null_dict)', 'E474:') endfunc func Test_relative_cursor_position_after_move_and_resize() @@ -910,6 +914,10 @@ func Test_winnr() call assert_fails("echo winnr('ll')", 'E15:') call assert_fails("echo winnr('5')", 'E15:') call assert_equal(4, winnr('0h')) + call assert_fails("let w = winnr([])", 'E730:') + call assert_equal('unknown', win_gettype(-1)) + call assert_equal(-1, winheight(-1)) + call assert_equal(-1, winwidth(-1)) tabnew call assert_equal(8, tabpagewinnr(1, 'j')) @@ -930,9 +938,12 @@ func Test_winrestview() call assert_equal(view, winsaveview()) bwipe! + call assert_fails('call winrestview(v:_null_dict)', 'E474:') endfunc func Test_win_splitmove() + CheckFeature quickfix + edit a leftabove split b leftabove vsplit c @@ -958,6 +969,7 @@ func Test_win_splitmove() call assert_equal(bufname(winbufnr(2)), 'b') call assert_equal(bufname(winbufnr(3)), 'a') call assert_equal(bufname(winbufnr(4)), 'd') + call assert_fails('call win_splitmove(winnr(), winnr("k"), v:_null_dict)', 'E474:') only | bd call assert_fails('call win_splitmove(winnr(), 123)', 'E957:') diff --git a/src/nvim/testdir/test_window_id.vim b/src/nvim/testdir/test_window_id.vim index 8bf4ede350..396a49b55f 100644 --- a/src/nvim/testdir/test_window_id.vim +++ b/src/nvim/testdir/test_window_id.vim @@ -1,5 +1,7 @@ " Test using the window ID. +source check.vim + func Test_win_getid() edit one let id1 = win_getid() @@ -90,10 +92,16 @@ func Test_win_getid() split call assert_equal(sort([id5, win_getid()]), sort(win_findbuf(bufnr5))) + call assert_fails('let w = win_getid([])', 'E745:') + call assert_equal(0, win_getid(-1)) + call assert_equal(-1, win_getid(1, -1)) + only! endfunc func Test_win_getid_curtab() + CheckFeature quickfix + tabedit X tabfirst copen @@ -127,4 +135,8 @@ func Test_winlayout() let w2 = win_getid() call assert_equal(['leaf', w2], 2->winlayout()) tabclose + + call assert_equal([], winlayout(-1)) endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_writefile.vim b/src/nvim/testdir/test_writefile.vim index adc05ab979..7dfcaaedeb 100644 --- a/src/nvim/testdir/test_writefile.vim +++ b/src/nvim/testdir/test_writefile.vim @@ -260,6 +260,13 @@ func Test_write_errors() close call delete('Xfile') + + " Nvim treats NULL list/blob more like empty list/blob + " call writefile(v:_null_list, 'Xfile') + " call assert_false(filereadable('Xfile')) + " call writefile(v:_null_blob, 'Xfile') + " call assert_false(filereadable('Xfile')) + call assert_fails('call writefile([], "")', 'E482:') endfunc " Test for writing a file using invalid file encoding -- cgit From 40ca9b9528e5a4f043f0e6858786bf0c3d992a90 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 08:07:06 +0800 Subject: vim-patch:8.2.0866: not enough tests for buffer writing Problem: Not enough tests for buffer writing. Solution: Add more tests. Use CheckRunVimInTerminal in more places. (Yegappan Lakshmanan, closes vim/vim#6167) https://github.com/vim/vim/commit/494e9069cb32620f7688a7cb128a3feff827639e --- src/nvim/testdir/test_arglist.vim | 5 +- src/nvim/testdir/test_match.vim | 8 +- src/nvim/testdir/test_search.vim | 4 +- src/nvim/testdir/test_signals.vim | 8 +- src/nvim/testdir/test_signs.vim | 4 +- src/nvim/testdir/test_startup.vim | 8 +- src/nvim/testdir/test_startup_utf8.vim | 4 +- src/nvim/testdir/test_syntax.vim | 4 +- src/nvim/testdir/test_tabpage.vim | 4 +- src/nvim/testdir/test_timers.vim | 4 +- src/nvim/testdir/test_vimscript.vim | 4 +- src/nvim/testdir/test_writefile.vim | 132 +++++++++++++++++++++++++++++++++ 12 files changed, 147 insertions(+), 42 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_arglist.vim b/src/nvim/testdir/test_arglist.vim index 443a217143..cae71e10f3 100644 --- a/src/nvim/testdir/test_arglist.vim +++ b/src/nvim/testdir/test_arglist.vim @@ -1,5 +1,6 @@ " Test argument list commands +source check.vim source shared.vim source term_util.vim @@ -552,9 +553,7 @@ endfunc " Test for quitting Vim with unedited files in the argument list func Test_quit_with_arglist() - if !CanRunVimInTerminal() - throw 'Skipped: cannot run vim in terminal' - endif + CheckRunVimInTerminal let buf = RunVimInTerminal('', {'rows': 6}) call term_sendkeys(buf, ":set nomore\n") call term_sendkeys(buf, ":args a b c\n") diff --git a/src/nvim/testdir/test_match.vim b/src/nvim/testdir/test_match.vim index 352493de9c..29d087bc23 100644 --- a/src/nvim/testdir/test_match.vim +++ b/src/nvim/testdir/test_match.vim @@ -343,9 +343,7 @@ func Test_matchdelete_error() endfunc func Test_matchclear_other_window() - if !CanRunVimInTerminal() - throw 'Skipped: cannot make screendumps' - endif + CheckRunVimInTerminal let buf = OtherWindowCommon() call term_sendkeys(buf, ":call clearmatches(winid)\") call VerifyScreenDump(buf, 'Test_matchclear_1', {}) @@ -355,9 +353,7 @@ func Test_matchclear_other_window() endfunc func Test_matchadd_other_window() - if !CanRunVimInTerminal() - throw 'Skipped: cannot make screendumps' - endif + CheckRunVimInTerminal let buf = OtherWindowCommon() call term_sendkeys(buf, ":call matchadd('Search', 'Hello', 1, -1, #{window: winid})\") call term_sendkeys(buf, ":\") diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index d79910fbc1..cb35868b47 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -897,9 +897,7 @@ func Test_incsearch_cmdline_modifier() endfunc func Test_incsearch_scrolling() - if !CanRunVimInTerminal() - throw 'Skipped: cannot make screendumps' - endif + CheckRunVimInTerminal call assert_equal(0, &scrolloff) call writefile([ \ 'let dots = repeat(".", 120)', diff --git a/src/nvim/testdir/test_signals.vim b/src/nvim/testdir/test_signals.vim index 31b76919e1..c291c68e0d 100644 --- a/src/nvim/testdir/test_signals.vim +++ b/src/nvim/testdir/test_signals.vim @@ -81,6 +81,7 @@ endfunc " Test signal INT. Handler sets got_int. It should be like typing CTRL-C. func Test_signal_INT() + CheckRunVimInTerminal if !HasSignal('INT') throw 'Skipped: INT signal not supported' endif @@ -92,9 +93,6 @@ func Test_signal_INT() throw 'Skipped: cannot test signal INT with valgrind' endif - if !CanRunVimInTerminal() - throw 'Skipped: cannot run vim in terminal' - endif let buf = RunVimInTerminal('', {'rows': 6}) let pid_vim = term_getjob(buf)->job_info().process @@ -121,9 +119,7 @@ func Test_deadly_signal_TERM() if !HasSignal('TERM') throw 'Skipped: TERM signal not supported' endif - if !CanRunVimInTerminal() - throw 'Skipped: cannot run vim in terminal' - endif + CheckRunVimInTerminal let cmd = GetVimCommand() if cmd =~ 'valgrind' throw 'Skipped: cannot test signal TERM with valgrind' diff --git a/src/nvim/testdir/test_signs.vim b/src/nvim/testdir/test_signs.vim index ff9ba3d8ed..aa43477c5f 100644 --- a/src/nvim/testdir/test_signs.vim +++ b/src/nvim/testdir/test_signs.vim @@ -1741,9 +1741,7 @@ endfunc " Test for correct cursor position after the sign column appears or disappears. func Test_sign_cursor_position() - if !CanRunVimInTerminal() - throw 'Skipped: cannot make screendumps' - endif + CheckRunVimInTerminal let lines =<< trim END call setline(1, [repeat('x', 75), 'mmmm', 'yyyy']) diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim index b8aad1bc46..30bbd355df 100644 --- a/src/nvim/testdir/test_startup.vim +++ b/src/nvim/testdir/test_startup.vim @@ -809,9 +809,7 @@ func Test_issue_3969() endfunc func Test_start_with_tabs() - if !CanRunVimInTerminal() - return - endif + CheckRunVimInTerminal let buf = RunVimInTerminal('-p a b c', {}) call VerifyScreenDump(buf, 'Test_start_with_tabs', {}) @@ -968,9 +966,7 @@ endfunc " Test for specifying a non-existing vimrc file using "-u" func Test_missing_vimrc() - if !CanRunVimInTerminal() - throw 'Skipped: cannot run vim in terminal' - endif + CheckRunVimInTerminal let after =<< trim [CODE] call assert_match('^E282:', v:errmsg) call writefile(v:errors, 'Xtestout') diff --git a/src/nvim/testdir/test_startup_utf8.vim b/src/nvim/testdir/test_startup_utf8.vim index bb4304396e..2ee6ecc41d 100644 --- a/src/nvim/testdir/test_startup_utf8.vim +++ b/src/nvim/testdir/test_startup_utf8.vim @@ -63,9 +63,7 @@ func Test_read_fifo_utf8() endfunc func Test_detect_ambiwidth() - if !CanRunVimInTerminal() - throw 'Skipped: cannot run Vim in a terminal window' - endif + CheckRunVimInTerminal " Use the title termcap entries to output the escape sequence. call writefile([ diff --git a/src/nvim/testdir/test_syntax.vim b/src/nvim/testdir/test_syntax.vim index 9903b48dbe..29ebe141f7 100644 --- a/src/nvim/testdir/test_syntax.vim +++ b/src/nvim/testdir/test_syntax.vim @@ -631,9 +631,7 @@ endfunc " Check highlighting for a small piece of C code with a screen dump. func Test_syntax_c() - if !CanRunVimInTerminal() - throw 'Skipped: cannot make screendumps' - endif + CheckRunVimInTerminal call writefile([ \ '/* comment line at the top */', \ 'int main(int argc, char **argv) { // another comment', diff --git a/src/nvim/testdir/test_tabpage.vim b/src/nvim/testdir/test_tabpage.vim index 4ada48d56c..b97aa409d8 100644 --- a/src/nvim/testdir/test_tabpage.vim +++ b/src/nvim/testdir/test_tabpage.vim @@ -591,9 +591,7 @@ func Test_tabs() endfunc func Test_tabpage_cmdheight() - if !CanRunVimInTerminal() - throw 'Skipped: cannot make screendumps' - endif + CheckRunVimInTerminal call writefile([ \ 'set laststatus=2', \ 'set cmdheight=2', diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index 3a6abb3968..f94ee6c9f3 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -304,9 +304,7 @@ func Test_timer_ex_mode() endfunc func Test_timer_restore_count() - if !CanRunVimInTerminal() - throw 'Skipped: cannot run Vim in a terminal window' - endif + CheckRunVimInTerminal " Check that v:count is saved and restored, not changed by a timer. call writefile([ \ 'nnoremap L v:count ? v:count . "l" : "l"', diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index bd60dcb707..3a6baaf1f0 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -1707,9 +1707,7 @@ endfunc " Test for deep nesting of if/for/while/try statements {{{1 func Test_deep_nest() - if !CanRunVimInTerminal() - throw 'Skipped: cannot run vim in terminal' - endif + CheckRunVimInTerminal let lines =<< trim [SCRIPT] " Deep nesting of if ... endif diff --git a/src/nvim/testdir/test_writefile.vim b/src/nvim/testdir/test_writefile.vim index 7dfcaaedeb..59214d1aab 100644 --- a/src/nvim/testdir/test_writefile.vim +++ b/src/nvim/testdir/test_writefile.vim @@ -267,6 +267,138 @@ func Test_write_errors() " call writefile(v:_null_blob, 'Xfile') " call assert_false(filereadable('Xfile')) call assert_fails('call writefile([], "")', 'E482:') + + " very long file name + let long_fname = repeat('n', 5000) + call assert_fails('exe "w " .. long_fname', 'E75:') + call assert_fails('call writefile([], long_fname)', 'E482:') +endfunc + +" Test for writing to a file which is modified after Vim read it +func Test_write_file_mtime() + CheckEnglish + CheckRunVimInTerminal + + " First read the file into a buffer + call writefile(["Line1", "Line2"], 'Xfile') + let old_ftime = getftime('Xfile') + let buf = RunVimInTerminal('Xfile', #{rows : 10}) + call term_wait(buf) + call term_sendkeys(buf, ":set noswapfile\") + call term_wait(buf) + + " Modify the file directly. Make sure the file modification time is + " different. Note that on Linux/Unix, the file is considered modified + " outside, only if the difference is 2 seconds or more + sleep 1 + call writefile(["Line3", "Line4"], 'Xfile') + let new_ftime = getftime('Xfile') + while new_ftime - old_ftime < 2 + sleep 100m + call writefile(["Line3", "Line4"], 'Xfile') + let new_ftime = getftime('Xfile') + endwhile + + " Try to overwrite the file and check for the prompt + call term_sendkeys(buf, ":w\") + call term_wait(buf) + call WaitForAssert({-> assert_equal("WARNING: The file has been changed since reading it!!!", term_getline(buf, 9))}) + call assert_equal("Do you really want to write to it (y/n)?", + \ term_getline(buf, 10)) + call term_sendkeys(buf, "n\") + call term_wait(buf) + call assert_equal(new_ftime, getftime('Xfile')) + call term_sendkeys(buf, ":w\") + call term_wait(buf) + call term_sendkeys(buf, "y\") + call term_wait(buf) + call WaitForAssert({-> assert_equal('Line2', readfile('Xfile')[1])}) + + " clean up + call StopVimInTerminal(buf) + call delete('Xfile') +endfunc + +" Test for an autocmd unloading a buffer during a write command +func Test_write_autocmd_unloadbuf_lockmark() + augroup WriteTest + autocmd BufWritePre Xfile enew | write + augroup END + e Xfile + call assert_fails('lockmarks write', 'E203:') + augroup WriteTest + au! + augroup END + augroup! WriteTest +endfunc + +" Test for writing a buffer with 'acwrite' but without autocmds +func Test_write_acwrite_error() + new Xfile + call setline(1, ['line1', 'line2', 'line3']) + set buftype=acwrite + call assert_fails('write', 'E676:') + call assert_fails('1,2write!', 'E676:') + call assert_fails('w >>', 'E676:') + close! +endfunc + +" Test for adding and removing lines from an autocmd when writing a buffer +func Test_write_autocmd_add_remove_lines() + new Xfile + call setline(1, ['aaa', 'bbb', 'ccc', 'ddd']) + + " Autocmd deleting lines from the file when writing a partial file + augroup WriteTest2 + au! + autocmd FileWritePre Xfile 1,2d + augroup END + call assert_fails('2,3w!', 'E204:') + + " Autocmd adding lines to a file when writing a partial file + augroup WriteTest2 + au! + autocmd FileWritePre Xfile call append(0, ['xxx', 'yyy']) + augroup END + %d + call setline(1, ['aaa', 'bbb', 'ccc', 'ddd']) + 1,2w! + call assert_equal(['xxx', 'yyy', 'aaa', 'bbb'], readfile('Xfile')) + + " Autocmd deleting lines from the file when writing the whole file + augroup WriteTest2 + au! + autocmd BufWritePre Xfile 1,2d + augroup END + %d + call setline(1, ['aaa', 'bbb', 'ccc', 'ddd']) + w + call assert_equal(['ccc', 'ddd'], readfile('Xfile')) + + augroup WriteTest2 + au! + augroup END + augroup! WriteTest2 + + close! + call delete('Xfile') +endfunc + +" Test for writing to a readonly file +func Test_write_readonly() + " In Cirrus-CI, the freebsd tests are run under a root account. So this test + " doesn't fail. + CheckNotBSD + call writefile([], 'Xfile') + call setfperm('Xfile', "r--------") + edit Xfile + set noreadonly + call assert_fails('write', 'E505:') + let save_cpo = &cpo + set cpo+=W + call assert_fails('write!', 'E504:') + let &cpo = save_cpo + call delete('Xfile') endfunc " Test for writing a file using invalid file encoding -- cgit From b002499c1978c98cc4dfc3a3f2326997720d571a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 08:22:46 +0800 Subject: vim-patch:8.2.0958: not sufficient testing for buffer writing Problem: Not sufficient testing for buffer writing. Solution: Add a few tests. (Yegappan Lakshmanan, closes vim/vim#6238) https://github.com/vim/vim/commit/1de5f7c81d5e78fb4d612134bd2dfa6ee9183fae --- src/nvim/testdir/test_backup.vim | 18 ++++++++++++++ src/nvim/testdir/test_writefile.vim | 48 +++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_backup.vim b/src/nvim/testdir/test_backup.vim index ce2bfe72bc..7eff818732 100644 --- a/src/nvim/testdir/test_backup.vim +++ b/src/nvim/testdir/test_backup.vim @@ -1,5 +1,7 @@ " Tests for the backup function +source check.vim + func Test_backup() set backup backupdir=. backupskip= new @@ -56,3 +58,19 @@ func Test_backup2_backupcopy() call delete(f) set backup&vim backupdir&vim backupcopy&vim backupskip&vim endfunc + +" Test for using a non-existing directory as a backup directory +func Test_non_existing_backupdir() + throw 'Skipped: Nvim auto-creates backup directory' + CheckNotBSD + let save_backup = &backupdir + set backupdir=./non_existing_dir + call writefile(['line1'], 'Xfile') + new Xfile + " TODO: write doesn't fail in Cirrus FreeBSD CI test + call assert_fails('write', 'E510:') + let &backupdir = save_backup + call delete('Xfile') +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_writefile.vim b/src/nvim/testdir/test_writefile.vim index 59214d1aab..5ee13ef144 100644 --- a/src/nvim/testdir/test_writefile.vim +++ b/src/nvim/testdir/test_writefile.vim @@ -398,9 +398,57 @@ func Test_write_readonly() set cpo+=W call assert_fails('write!', 'E504:') let &cpo = save_cpo + call setline(1, ['line1']) + write! + call assert_equal(['line1'], readfile('Xfile')) call delete('Xfile') endfunc +" Test for 'patchmode' +func Test_patchmode() + CheckNotBSD + call writefile(['one'], 'Xfile') + set patchmode=.orig nobackup writebackup + new Xfile + call setline(1, 'two') + " first write should create the .orig file + write + " TODO: Xfile.orig is not created in Cirrus FreeBSD CI test + call assert_equal(['one'], readfile('Xfile.orig')) + call setline(1, 'three') + " subsequent writes should not create/modify the .orig file + write + call assert_equal(['one'], readfile('Xfile.orig')) + set patchmode& backup& writebackup& + call delete('Xfile') + call delete('Xfile.orig') +endfunc + +" Test for writing to a file in a readonly directory +func Test_write_readonly_dir() + if !has('unix') || has('bsd') + " On MS-Windows, modifying files in a read-only directory is allowed. + " In Cirrus-CI for Freebsd, tests are run under a root account where + " modifying files in a read-only directory are allowed. + return + endif + call mkdir('Xdir') + call writefile(['one'], 'Xdir/Xfile1') + call setfperm('Xdir', 'r-xr--r--') + " try to create a new file in the directory + new Xdir/Xfile2 + call setline(1, 'two') + call assert_fails('write', 'E212:') + " try to create a backup file in the directory + edit! Xdir/Xfile1 + set backupdir=./Xdir + set patchmode=.orig + call assert_fails('write', 'E509:') + call setfperm('Xdir', 'rwxr--r--') + call delete('Xdir', 'rf') + set backupdir& patchmode& +endfunc + " Test for writing a file using invalid file encoding func Test_write_invalid_encoding() new -- cgit From 199c7c28989a3c36447ef56b71c7b84756950a11 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 11:27:28 +0800 Subject: vim-patch:8.2.0612: Vim9: no check for space before #comment Problem: Vim9: no check for space before #comment. Solution: Add space checks. https://github.com/vim/vim/commit/2c5ed4e3300378ce76c8d9c3818d6f73e5119f68 Omit ends_excmd2(): the same as ends_excmd() in legacy Vim script. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_sort.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_sort.vim b/src/nvim/testdir/test_sort.vim index c3e7788164..f9cbcbb55f 100644 --- a/src/nvim/testdir/test_sort.vim +++ b/src/nvim/testdir/test_sort.vim @@ -1360,7 +1360,7 @@ func Test_sort_cmd() call setline(1, ['line1', 'line2']) call assert_fails('sort no', 'E474:') call assert_fails('sort c', 'E475:') - call assert_fails('sort #pat%', 'E682:') + call assert_fails('sort #pat%', 'E654:') enew! endfunc -- cgit From a86295cd5c2bf15a11eb05e226fd8e226154f6a6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 12:26:17 +0800 Subject: vim-patch:8.2.0615: regexp benchmark stest is old style (#20940) Problem: Regexp benchmark stest is old style. Solution: Make it a new style test. Fix using a NULL list. Add more tests. (Yegappan Lakshmanan, closes vim/vim#5963) https://github.com/vim/vim/commit/ad48e6c1590842ab6d48e6caba3e9250734dae27 N/A patches: vim-patch:9.0.0829: wrong counts in macro comment --- src/nvim/testdir/test_autocmd.vim | 2 ++ src/nvim/testdir/test_blob.vim | 1 + src/nvim/testdir/test_bufline.vim | 31 +++++++++++++++++++++++++++++++ src/nvim/testdir/test_cmdline.vim | 5 +++++ src/nvim/testdir/test_functions.vim | 25 +++++++++++++++++++++++++ src/nvim/testdir/test_tagjump.vim | 1 + src/nvim/testdir/test_window_cmd.vim | 12 ++++++++++++ 7 files changed, 77 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 8c15249f97..a3534cea87 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -533,6 +533,8 @@ func Test_augroup_warning() redir END call assert_notmatch("W19:", res) au! VimEnter + + call assert_fails('augroup!', 'E471:') endfunc func Test_BufReadCmdHelp() diff --git a/src/nvim/testdir/test_blob.vim b/src/nvim/testdir/test_blob.vim index 1c0261933f..046acb81e1 100644 --- a/src/nvim/testdir/test_blob.vim +++ b/src/nvim/testdir/test_blob.vim @@ -303,6 +303,7 @@ func Test_blob_index() call assert_equal(3, index(0z11110111, 0x11, -2)) call assert_equal(0, index(0z11110111, 0x11, -10)) call assert_fails("echo index(0z11110111, 0x11, [])", 'E745:') + call assert_equal(-1, index(v:_null_blob, 1)) call assert_fails('call index("asdf", 0)', 'E897:') endfunc diff --git a/src/nvim/testdir/test_bufline.vim b/src/nvim/testdir/test_bufline.vim index 5a47f8ef25..2867f13cbc 100644 --- a/src/nvim/testdir/test_bufline.vim +++ b/src/nvim/testdir/test_bufline.vim @@ -19,8 +19,19 @@ func Test_setbufline_getbufline() call setline(1, ['a', 'b', 'c']) let b = bufnr('%') wincmd w + + call assert_equal(1, setbufline(b, 5, 'x')) call assert_equal(1, setbufline(b, 5, ['x'])) + call assert_equal(1, setbufline(b, 5, [])) + call assert_equal(1, setbufline(b, 5, v:_null_list)) + + call assert_equal(1, 'x'->setbufline(bufnr('$') + 1, 1)) call assert_equal(1, ['x']->setbufline(bufnr('$') + 1, 1)) + call assert_equal(1, []->setbufline(bufnr('$') + 1, 1)) + call assert_equal(1, v:_null_list->setbufline(bufnr('$') + 1, 1)) + + call assert_equal(['a', 'b', 'c'], getbufline(b, 1, '$')) + call assert_equal(0, setbufline(b, 4, ['d', 'e'])) call assert_equal(['c'], b->getbufline(3)) call assert_equal(['d'], getbufline(b, 4)) @@ -84,9 +95,29 @@ func Test_appendbufline() call setline(1, ['a', 'b', 'c']) let b = bufnr('%') wincmd w + + call assert_equal(1, appendbufline(b, -1, 'x')) call assert_equal(1, appendbufline(b, -1, ['x'])) + call assert_equal(1, appendbufline(b, -1, [])) + call assert_equal(1, appendbufline(b, -1, v:_null_list)) + + call assert_equal(1, appendbufline(b, 4, 'x')) call assert_equal(1, appendbufline(b, 4, ['x'])) + call assert_equal(1, appendbufline(b, 4, [])) + call assert_equal(1, appendbufline(b, 4, v:_null_list)) + + call assert_equal(1, appendbufline(1234, 1, 'x')) call assert_equal(1, appendbufline(1234, 1, ['x'])) + call assert_equal(1, appendbufline(1234, 1, [])) + call assert_equal(1, appendbufline(1234, 1, v:_null_list)) + + call assert_equal(0, appendbufline(b, 1, [])) + call assert_equal(0, appendbufline(b, 1, v:_null_list)) + call assert_equal(1, appendbufline(b, 3, [])) + call assert_equal(1, appendbufline(b, 3, v:_null_list)) + + call assert_equal(['a', 'b', 'c'], getbufline(b, 1, '$')) + call assert_equal(0, appendbufline(b, 3, ['d', 'e'])) call assert_equal(['c'], getbufline(b, 3)) call assert_equal(['d'], getbufline(b, 4)) diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 27ac91e49f..3e5fe06c90 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -1270,6 +1270,11 @@ func Test_verbosefile() let log = readfile('Xlog') call assert_match("foo\nbar", join(log, "\n")) call delete('Xlog') + call mkdir('Xdir') + if !has('win32') " FIXME: no error on Windows, libuv bug? + call assert_fails('set verbosefile=Xdir', 'E474:') + endif + call delete('Xdir', 'd') endfunc func Test_verbose_option() diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 5718266dae..1ba0cf9080 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -798,18 +798,41 @@ func Test_mode() delfunction OperatorFunc endfunc +" Test for append() func Test_append() enew! split call append(0, ["foo"]) + call append(1, []) + call append(1, v:_null_list) + call assert_equal(['foo', ''], getline(1, '$')) split only undo + undo " Using $ instead of '$' must give an error call assert_fails("call append($, 'foobar')", 'E116:') endfunc +" Test for setline() +func Test_setline() + new + call setline(0, ["foo"]) + call setline(0, []) + call setline(0, v:_null_list) + call setline(1, ["bar"]) + call setline(1, []) + call setline(1, v:_null_list) + call setline(2, []) + call setline(2, v:_null_list) + call setline(3, []) + call setline(3, v:_null_list) + call setline(2, ["baz"]) + call assert_equal(['bar', 'baz'], getline(1, '$')) + close! +endfunc + func Test_getbufvar() let bnr = bufnr('%') let b:var_num = '1234' @@ -917,6 +940,7 @@ func Test_match_func() call assert_equal(-1, match(['a', 'b', 'c', 'a'], 'a', 5)) call assert_equal(4, match('testing', 'ing', -1)) call assert_fails("let x=match('testing', 'ing', 0, [])", 'E745:') + call assert_equal(-1, match(v:_null_list, 2)) endfunc func Test_matchend() @@ -1922,6 +1946,7 @@ func Test_call() call assert_equal(3, 'len'->call([123])) call assert_fails("call call('len', 123)", 'E714:') call assert_equal(0, call('', [])) + call assert_equal(0, call('len', v:_null_list)) function Mylen() dict return len(self.data) diff --git a/src/nvim/testdir/test_tagjump.vim b/src/nvim/testdir/test_tagjump.vim index 592e13e340..f3ca5e306b 100644 --- a/src/nvim/testdir/test_tagjump.vim +++ b/src/nvim/testdir/test_tagjump.vim @@ -372,6 +372,7 @@ func Test_getsettagstack() call assert_fails("call settagstack(1, {'items' : 10})", 'E714') call assert_fails("call settagstack(1, {'items' : []}, 10)", 'E928') call assert_fails("call settagstack(1, {'items' : []}, 'b')", 'E962') + call assert_equal(-1, settagstack(0, v:_null_dict)) set tags=Xtags call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim index c7b5896082..20564fed66 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -1142,6 +1142,18 @@ func Test_split_cmds_with_no_room() call Run_noroom_for_newwindow_test('v') endfunc +" Test for various wincmd failures +func Test_wincmd_fails() + only! + call assert_beeps("normal \w") + call assert_beeps("normal \p") + call assert_beeps("normal \gk") + call assert_beeps("normal \r") + call assert_beeps("normal \K") + call assert_beeps("normal \H") + call assert_beeps("normal \2gt") +endfunc + func Test_window_resize() " Vertical :resize (absolute, relative, min and max size). vsplit -- cgit From 8b0c5de4e0964109326a0befb1b3bff6aac4d0db Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 07:24:06 +0800 Subject: vim-patch:partial:8.2.1183: assert_fails() checks the last error message Problem: assert_fails() checks the last error message. Solution: Check the first error, it is more relevant. Fix all the tests that rely on the old behavior. https://github.com/vim/vim/commit/9b7bf9e98f06ece595fed7a3ff53ecce89797a53 Skip test_listener.vim, test_textprop.vim, test_viminfo.vim. Skip test_python2.vim: affected line fails and hasn't been ported. Skip test_python3.vim: affected lines fail and haven't been ported. Skip CHECK_LIST_MATERIALIZE. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_autochdir.vim | 4 +--- src/nvim/testdir/test_autocmd.vim | 6 ++---- src/nvim/testdir/test_buffer.vim | 4 ++-- src/nvim/testdir/test_cd.vim | 8 +++----- src/nvim/testdir/test_clientserver.vim | 6 +++--- src/nvim/testdir/test_cmdline.vim | 14 ++++---------- src/nvim/testdir/test_cpoptions.vim | 2 +- src/nvim/testdir/test_excmd.vim | 4 ++-- src/nvim/testdir/test_expr.vim | 2 +- src/nvim/testdir/test_functions.vim | 10 +++++----- src/nvim/testdir/test_global.vim | 2 +- src/nvim/testdir/test_let.vim | 2 +- src/nvim/testdir/test_listdict.vim | 6 +++--- src/nvim/testdir/test_match.vim | 2 +- src/nvim/testdir/test_matchfuzzy.vim | 18 +++++------------- src/nvim/testdir/test_menu.vim | 2 +- src/nvim/testdir/test_method.vim | 4 ++-- src/nvim/testdir/test_normal.vim | 2 +- src/nvim/testdir/test_quickfix.vim | 6 +++--- src/nvim/testdir/test_random.vim | 10 +++++----- src/nvim/testdir/test_regexp_latin.vim | 2 +- src/nvim/testdir/test_search.vim | 8 ++++---- src/nvim/testdir/test_signs.vim | 6 +++--- src/nvim/testdir/test_spell.vim | 2 +- src/nvim/testdir/test_substitute.vim | 8 ++++---- src/nvim/testdir/test_syntax.vim | 2 +- src/nvim/testdir/test_tagfunc.vim | 2 +- src/nvim/testdir/test_tagjump.vim | 4 ++-- src/nvim/testdir/test_taglist.vim | 4 +--- src/nvim/testdir/test_trycatch.vim | 6 ++---- src/nvim/testdir/test_utf8.vim | 2 +- src/nvim/testdir/test_winbuf_close.vim | 2 +- src/nvim/testdir/test_writefile.vim | 2 +- 33 files changed, 70 insertions(+), 94 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autochdir.vim b/src/nvim/testdir/test_autochdir.vim index 4229095f9f..a8810047a0 100644 --- a/src/nvim/testdir/test_autochdir.vim +++ b/src/nvim/testdir/test_autochdir.vim @@ -122,9 +122,7 @@ endfunc func Test_multibyte() " using an invalid character should not cause a crash set wic - " Except on Windows, E472 is also thrown last, but v8.1.1183 isn't ported yet - " call assert_fails('tc *', has('win32') ? 'E480:' : 'E344:') - call assert_fails('tc *', has('win32') ? 'E480:' : 'E472:') + call assert_fails('tc *', has('win32') ? 'E480:' : 'E344:') set nowic endfunc diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index a3534cea87..50904bab34 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -175,9 +175,7 @@ func Test_autocmd_bufunload_avoiding_SEGV_01() exe 'autocmd BufUnload ' . (lastbuf + 1) . 'bwipeout!' augroup END - " Todo: check for E937 generated first - " call assert_fails('edit bb.txt', 'E937:') - call assert_fails('edit bb.txt', 'E517:') + call assert_fails('edit bb.txt', ['E937:', 'E517:']) autocmd! test_autocmd_bufunload augroup! test_autocmd_bufunload @@ -2933,7 +2931,7 @@ func Test_BufDelete_changebuf() augroup END let save_cpo = &cpo set cpo+=f - call assert_fails('r Xfile', 'E484:') + call assert_fails('r Xfile', ['E812:', 'E484:']) call assert_equal('somefile', @%) let &cpo = save_cpo augroup TestAuCmd diff --git a/src/nvim/testdir/test_buffer.vim b/src/nvim/testdir/test_buffer.vim index 4def3b5df9..27c2d5d442 100644 --- a/src/nvim/testdir/test_buffer.vim +++ b/src/nvim/testdir/test_buffer.vim @@ -76,7 +76,7 @@ func Test_bunload_with_offset() let caught_E90 = 1 endtry call assert_equal(1, caught_E90) - call assert_fails('$bunload', 'E515:') + call assert_fails('$bunload', 'E90:') endfunc " Test for :buffer, :bnext, :bprevious, :brewind, :blast and :bmodified @@ -282,7 +282,7 @@ func Test_goto_buf_with_confirm() call assert_equal(1, &modified) call assert_equal('', @%) call feedkeys('y', 'L') - call assert_fails('confirm b Xfile', 'E37:') + call assert_fails('confirm b Xfile', ['', 'E37:']) call assert_equal(1, &modified) call assert_equal('', @%) call feedkeys('n', 'L') diff --git a/src/nvim/testdir/test_cd.vim b/src/nvim/testdir/test_cd.vim index 43c4e09d40..2a2437f542 100644 --- a/src/nvim/testdir/test_cd.vim +++ b/src/nvim/testdir/test_cd.vim @@ -5,7 +5,7 @@ source check.vim func Test_cd_large_path() " This used to crash with a heap write overflow. - call assert_fails('cd ' . repeat('x', 5000), 'E472:') + call assert_fails('cd ' . repeat('x', 5000), 'E344:') endfunc func Test_cd_up_and_down() @@ -45,9 +45,7 @@ func Test_cd_minus() call assert_equal(path, getcwd()) " Test for :cd - after a failed :cd - " v8.2.1183 is not ported yet - " call assert_fails('cd /nonexistent', 'E344:') - call assert_fails('cd /nonexistent', 'E472:') + call assert_fails('cd /nonexistent', 'E344:') call assert_equal(path, getcwd()) cd - call assert_equal(path_dotdot, getcwd()) @@ -103,7 +101,7 @@ func Test_chdir_func() call assert_equal('testdir', fnamemodify(getcwd(1, 1), ':t')) " Error case - call assert_fails("call chdir('dir-abcd')", 'E472:') + call assert_fails("call chdir('dir-abcd')", 'E344:') silent! let d = chdir("dir_abcd") call assert_equal("", d) " Should not crash diff --git a/src/nvim/testdir/test_clientserver.vim b/src/nvim/testdir/test_clientserver.vim index 301dad8341..19a92dce3c 100644 --- a/src/nvim/testdir/test_clientserver.vim +++ b/src/nvim/testdir/test_clientserver.vim @@ -102,7 +102,7 @@ func Test_client_server() call remote_send(v:servername, ":let g:testvar2 = 75\") call feedkeys('', 'x') call assert_equal(75, g:testvar2) - call assert_fails('let v = remote_expr(v:servername, "/2")', 'E449:') + call assert_fails('let v = remote_expr(v:servername, "/2")', ['E15:.*/2']) call remote_send(name, ":call server2client(expand(''), 'got it')\", 'g:myserverid') call assert_equal('got it', g:myserverid->remote_read(2)) @@ -184,8 +184,8 @@ func Test_client_server() call assert_fails('call remote_startserver([])', 'E730:') call assert_fails("let x = remote_peek([])", 'E730:') - call assert_fails("let x = remote_read('vim10')", 'E277:') - call assert_fails("call server2client('abc', 'xyz')", 'E258:') + call assert_fails("let x = remote_read('vim10')", ['E573:.*vim10']) + call assert_fails("call server2client('abc', 'xyz')", ['E573:.*abc']) endfunc " Uncomment this line to get a debugging log diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 3e5fe06c90..c00172ed68 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -1154,7 +1154,7 @@ func Test_cmdline_search_range() call assert_equal('B', getline(2)) let @/ = 'apple' - call assert_fails('\/print', 'E486:') + call assert_fails('\/print', ['E486:.*apple']) bwipe! endfunc @@ -1272,7 +1272,7 @@ func Test_verbosefile() call delete('Xlog') call mkdir('Xdir') if !has('win32') " FIXME: no error on Windows, libuv bug? - call assert_fails('set verbosefile=Xdir', 'E474:') + call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:']) endif call delete('Xdir', 'd') endfunc @@ -1525,7 +1525,7 @@ func Test_cmdwin_jump_to_win() call assert_fails('call feedkeys("q:\\\", "xt")', 'E11:') new set modified - call assert_fails('call feedkeys("q/:qall\", "xt")', 'E162:') + call assert_fails('call feedkeys("q/:qall\", "xt")', ['E37:', 'E162:']) close! call feedkeys("q/:close\", "xt") call assert_equal(1, winnr('$')) @@ -1539,13 +1539,7 @@ endfunc func Test_cmdwin_tabpage() tabedit - " v8.2.1919 isn't ported yet, so E492 is thrown after E11 here. - " v8.2.1183 also isn't ported yet, so we also can't assert E11 directly. - " For now, assert E11 and E492 separately. When v8.2.1183 is ported, the - " assert for E492 will fail and this workaround should be removed. - " call assert_fails("silent norm q/g :I\", 'E11:') - call assert_fails("silent norm q/g ", 'E11:') - call assert_fails("silent norm q/g :I\", 'E492:') + call assert_fails("silent norm q/g :I\", 'E11:') tabclose! endfunc diff --git a/src/nvim/testdir/test_cpoptions.vim b/src/nvim/testdir/test_cpoptions.vim index 76d2c9542d..ef51d955f1 100644 --- a/src/nvim/testdir/test_cpoptions.vim +++ b/src/nvim/testdir/test_cpoptions.vim @@ -104,7 +104,7 @@ func Test_cpo_C() source Xfile call assert_equal([1, 2], g:l) set cpo+=C - call assert_fails('source Xfile', 'E10:') + call assert_fails('source Xfile', ['E697:', 'E10:']) call delete('Xfile') let &cpo = save_cpo endfunc diff --git a/src/nvim/testdir/test_excmd.vim b/src/nvim/testdir/test_excmd.vim index 04ab8e288f..582dcaac2c 100644 --- a/src/nvim/testdir/test_excmd.vim +++ b/src/nvim/testdir/test_excmd.vim @@ -481,8 +481,8 @@ func Test_redir_cmd() call assert_fails('redir abc', 'E475:') call assert_fails('redir => 1abc', 'E474:') call assert_fails('redir => a b', 'E488:') - call assert_fails('redir => abc[1]', 'E475:') - let b=0zFF + call assert_fails('redir => abc[1]', 'E121:') + let b = 0zFF call assert_fails('redir =>> b', 'E734:') unlet b diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 0579ce7dcb..ea874cc398 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -528,7 +528,7 @@ func Test_setmatches() endif eval set->setmatches() call assert_equal(exp, getmatches()) - call assert_fails('let m = setmatches([], [])', 'E957:') + call assert_fails('let m = setmatches([], [])', 'E745:') endfunc func Test_empty_concatenate() diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 1ba0cf9080..06c995db86 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -211,7 +211,7 @@ func Test_str2nr() if has('float') call assert_fails('call str2nr(1.2)', 'E806:') endif - call assert_fails('call str2nr(10, [])', 'E474:') + call assert_fails('call str2nr(10, [])', 'E745:') endfunc func Test_strftime() @@ -1728,11 +1728,11 @@ func Test_libcall_libcallnr() call assert_equal(4, 'abcd'->libcallnr(libc, 'strlen')) call assert_equal(char2nr('A'), char2nr('a')->libcallnr(libc, 'toupper')) - call assert_fails("call libcall(libc, 'Xdoesnotexist_', '')", 'E364:') - call assert_fails("call libcallnr(libc, 'Xdoesnotexist_', '')", 'E364:') + call assert_fails("call libcall(libc, 'Xdoesnotexist_', '')", ['', 'E364:']) + call assert_fails("call libcallnr(libc, 'Xdoesnotexist_', '')", ['', 'E364:']) - call assert_fails("call libcall('Xdoesnotexist_', 'getenv', 'HOME')", 'E364:') - call assert_fails("call libcallnr('Xdoesnotexist_', 'strlen', 'abcd')", 'E364:') + call assert_fails("call libcall('Xdoesnotexist_', 'getenv', 'HOME')", ['', 'E364:']) + call assert_fails("call libcallnr('Xdoesnotexist_', 'strlen', 'abcd')", ['', 'E364:']) endfunc sandbox function Fsandbox() diff --git a/src/nvim/testdir/test_global.vim b/src/nvim/testdir/test_global.vim index cb6851250c..bbfe374f51 100644 --- a/src/nvim/testdir/test_global.vim +++ b/src/nvim/testdir/test_global.vim @@ -39,7 +39,7 @@ endfunc func Test_global_error() call assert_fails('g\\a', 'E10:') call assert_fails('g', 'E148:') - call assert_fails('g/\(/y', 'E476:') + call assert_fails('g/\(/y', 'E54:') endfunc " Test for printing lines using :g with different search patterns diff --git a/src/nvim/testdir/test_let.vim b/src/nvim/testdir/test_let.vim index 937076aa2a..f05e06f774 100644 --- a/src/nvim/testdir/test_let.vim +++ b/src/nvim/testdir/test_let.vim @@ -262,7 +262,7 @@ func Test_let_errors() let l = [1, 2, 3] call assert_fails('let l[:] = 5', 'E709:') - call assert_fails('let x:lnum=5', 'E488:') + call assert_fails('let x:lnum=5', ['E121:', 'E488:']) call assert_fails('let v:=5', 'E461:') call assert_fails('let [a]', 'E474:') call assert_fails('let [a, b] = [', 'E697:') diff --git a/src/nvim/testdir/test_listdict.vim b/src/nvim/testdir/test_listdict.vim index 1ecdcd2157..7cb48876e8 100644 --- a/src/nvim/testdir/test_listdict.vim +++ b/src/nvim/testdir/test_listdict.vim @@ -680,10 +680,10 @@ func Test_reverse_sort_uniq() endif call assert_fails('call reverse("")', 'E899:') - call assert_fails('call uniq([1, 2], {x, y -> []})', 'E882:') + call assert_fails('call uniq([1, 2], {x, y -> []})', 'E745:') call assert_fails("call sort([1, 2], function('min'), 1)", "E715:") call assert_fails("call sort([1, 2], function('invalid_func'))", "E700:") - call assert_fails("call sort([1, 2], function('min'))", "E702:") + call assert_fails("call sort([1, 2], function('min'))", "E118:") endfunc " reduce a list or a blob @@ -983,7 +983,7 @@ func Test_listdict_index() call assert_fails('echo d[1:2]', 'E719:') call assert_fails("let v = [4, 6][{-> 1}]", 'E729:') call assert_fails("let v = range(5)[2:[]]", 'E730:') - call assert_fails("let v = range(5)[2:{-> 2}(]", 'E116:') + call assert_fails("let v = range(5)[2:{-> 2}(]", ['E15:', 'E116:']) call assert_fails("let v = range(5)[2:3", 'E111:') call assert_fails("let l = insert([1,2,3], 4, 10)", 'E684:') call assert_fails("let l = insert([1,2,3], 4, -10)", 'E684:') diff --git a/src/nvim/testdir/test_match.vim b/src/nvim/testdir/test_match.vim index 29d087bc23..5d9be99444 100644 --- a/src/nvim/testdir/test_match.vim +++ b/src/nvim/testdir/test_match.vim @@ -163,7 +163,7 @@ func Test_matchadd_error() " call assert_fails("call matchadd('GroupDoesNotExist', 'X')", 'E28:') call matchadd('GroupDoesNotExist', 'X') call assert_equal([{'group': 'GroupDoesNotExist', 'pattern': 'X', 'priority': 10, 'id': 1206}], getmatches()) - call assert_fails("call matchadd('Search', '\\(')", 'E475:') + call assert_fails("call matchadd('Search', '\\(')", 'E54:') call assert_fails("call matchadd('Search', 'XXX', 1, 123, 1)", 'E715:') call assert_fails("call matchadd('Error', 'XXX', 1, 3)", 'E798:') call assert_fails("call matchadd('Error', 'XXX', 1, 0)", 'E799:') diff --git a/src/nvim/testdir/test_matchfuzzy.vim b/src/nvim/testdir/test_matchfuzzy.vim index c836bc87aa..b46550fbc3 100644 --- a/src/nvim/testdir/test_matchfuzzy.vim +++ b/src/nvim/testdir/test_matchfuzzy.vim @@ -6,9 +6,7 @@ source check.vim " Test for matchfuzzy() func Test_matchfuzzy() call assert_fails('call matchfuzzy(10, "abc")', 'E686:') - " Needs v8.2.1183; match the final error that's thrown for now - " call assert_fails('call matchfuzzy(["abc"], [])', 'E730:') - call assert_fails('call matchfuzzy(["abc"], [])', 'E475:') + call assert_fails('call matchfuzzy(["abc"], [])', 'E730:') call assert_fails("let x = matchfuzzy(v:_null_list, 'foo')", 'E686:') call assert_fails('call matchfuzzy(["abc"], v:_null_string)', 'E475:') call assert_equal([], matchfuzzy([], 'abc')) @@ -75,12 +73,9 @@ func Test_matchfuzzy() call assert_fails("let x = matchfuzzy(l, 'day', {'text_cb' : {a, b -> 1}})", 'E119:') call assert_equal([], matchfuzzy(l, 'cam')) " Nvim's callback implementation is different, so E6000 is expected instead, - " but we need v8.2.1183 to assert it " call assert_fails("let x = matchfuzzy(l, 'cam', {'text_cb' : []})", 'E921:') - " call assert_fails("let x = matchfuzzy(l, 'cam', {'text_cb' : []})", 'E6000:') - call assert_fails("let x = matchfuzzy(l, 'cam', {'text_cb' : []})", 'E475:') - " call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : []})", 'E730:') - call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : []})", 'E475:') + call assert_fails("let x = matchfuzzy(l, 'cam', {'text_cb' : []})", 'E6000:') + call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : []})", 'E730:') call assert_fails("let x = matchfuzzy(l, 'cam', v:_null_dict)", 'E715:') call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : v:_null_string})", 'E475:') " Nvim doesn't have null functions @@ -155,12 +150,9 @@ func Test_matchfuzzypos() call assert_fails("let x = matchfuzzypos(l, 'day', {'text_cb' : {a, b -> 1}})", 'E119:') call assert_equal([[], [], []], matchfuzzypos(l, 'cam')) " Nvim's callback implementation is different, so E6000 is expected instead, - " but we need v8.2.1183 to assert it " call assert_fails("let x = matchfuzzypos(l, 'cam', {'text_cb' : []})", 'E921:') - " call assert_fails("let x = matchfuzzypos(l, 'cam', {'text_cb' : []})", 'E6000:') - call assert_fails("let x = matchfuzzypos(l, 'cam', {'text_cb' : []})", 'E475:') - " call assert_fails("let x = matchfuzzypos(l, 'foo', {'key' : []})", 'E730:') - call assert_fails("let x = matchfuzzypos(l, 'foo', {'key' : []})", 'E475:') + call assert_fails("let x = matchfuzzypos(l, 'cam', {'text_cb' : []})", 'E6000:') + call assert_fails("let x = matchfuzzypos(l, 'foo', {'key' : []})", 'E730:') call assert_fails("let x = matchfuzzypos(l, 'cam', v:_null_dict)", 'E715:') call assert_fails("let x = matchfuzzypos(l, 'foo', {'key' : v:_null_string})", 'E475:') " Nvim doesn't have null functions diff --git a/src/nvim/testdir/test_menu.vim b/src/nvim/testdir/test_menu.vim index 58da0ed382..a1121632e6 100644 --- a/src/nvim/testdir/test_menu.vim +++ b/src/nvim/testdir/test_menu.vim @@ -153,7 +153,7 @@ func Test_menu_errors() call assert_fails('menu Test.Foo.Bar', 'E327:') call assert_fails('cmenu Test.Foo', 'E328:') call assert_fails('emenu x Test.Foo', 'E475:') - call assert_fails('emenu Test.Foo.Bar', 'E334:') + call assert_fails('emenu Test.Foo.Bar', 'E327:') call assert_fails('menutranslate Test', 'E474:') silent! unmenu Foo diff --git a/src/nvim/testdir/test_method.vim b/src/nvim/testdir/test_method.vim index e035b3ef50..057f4a1bea 100644 --- a/src/nvim/testdir/test_method.vim +++ b/src/nvim/testdir/test_method.vim @@ -131,9 +131,9 @@ func Test_method_syntax() eval [1, 2, 3] \ ->sort( \ ) - call assert_fails('eval [1, 2, 3]-> sort()', 'E260:') + call assert_fails('eval [1, 2, 3]-> sort()', 'E15:') call assert_fails('eval [1, 2, 3]->sort ()', 'E274:') - call assert_fails('eval [1, 2, 3]-> sort ()', 'E260:') + call assert_fails('eval [1, 2, 3]-> sort ()', 'E15:') endfunc func Test_method_lambda() diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index 5fc670e422..84929e2be3 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -1650,7 +1650,7 @@ func Test_normal23_K() call setline(1, '---') call assert_fails('normal! ggv2lK', 'E349:') call setline(1, ['abc', 'xyz']) - call assert_fails("normal! gg2lv2h\", 'E426:') + call assert_fails("normal! gg2lv2h\", 'E433:') call assert_beeps("normal! ggVjK") " clean up diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index dcedfe26a2..99d9c9c1fa 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -740,7 +740,7 @@ func s:test_xhelpgrep(cchar) " Search for non existing help string call assert_fails('Xhelpgrep a1b2c3', 'E480:') " Invalid regular expression - call assert_fails('Xhelpgrep \@"', 'E33:') call assert_fails('exe "normal ?~\"', 'E33:') set regexpengine=2 - call assert_fails('exe "normal /~\"', 'E383:') - call assert_fails('exe "normal ?~\"', 'E383:') + call assert_fails('exe "normal /~\"', ['E33:', 'E383:']) + call assert_fails('exe "normal ?~\"', ['E33:', 'E383:']) set regexpengine& call writefile(v:errors, 'Xresult') qall! diff --git a/src/nvim/testdir/test_signs.vim b/src/nvim/testdir/test_signs.vim index aa43477c5f..1f1b3097b1 100644 --- a/src/nvim/testdir/test_signs.vim +++ b/src/nvim/testdir/test_signs.vim @@ -483,13 +483,13 @@ func Test_sign_funcs() call assert_fails('call sign_place(5, "", "sign1", "@", {"lnum" : 10})', \ 'E158:') call assert_fails('call sign_place(5, "", "sign1", [], {"lnum" : 10})', - \ 'E158:') + \ 'E730:') call assert_fails('call sign_place(21, "", "sign1", "Xsign", \ {"lnum" : -1})', 'E474:') call assert_fails('call sign_place(22, "", "sign1", "Xsign", \ {"lnum" : 0})', 'E474:') call assert_fails('call sign_place(22, "", "sign1", "Xsign", - \ {"lnum" : []})', 'E474:') + \ {"lnum" : []})', 'E745:') call assert_equal(-1, sign_place(1, "*", "sign1", "Xsign", {"lnum" : 10})) " Tests for sign_getplaced() @@ -1731,7 +1731,7 @@ func Test_sign_jump_func() call assert_fails("call sign_jump(5, 'g5', 'foo')", 'E157:') call assert_fails('call sign_jump([], "", "foo")', 'E745:') call assert_fails('call sign_jump(2, [], "foo")', 'E730:') - call assert_fails('call sign_jump(2, "", {})', 'E158:') + call assert_fails('call sign_jump(2, "", {})', 'E731:') call assert_fails('call sign_jump(2, "", "baz")', 'E158:') sign unplace * group=* diff --git a/src/nvim/testdir/test_spell.vim b/src/nvim/testdir/test_spell.vim index f7144bbc7e..d8495fdb9b 100644 --- a/src/nvim/testdir/test_spell.vim +++ b/src/nvim/testdir/test_spell.vim @@ -495,7 +495,7 @@ func Test_spellsuggest_expr_errors() return [[{}, {}]] endfunc set spellsuggest=expr:MySuggest3() - call assert_fails("call spellsuggest('baord')", 'E728:') + call assert_fails("call spellsuggest('baord')", 'E731:') set nospell spellsuggest& delfunc MySuggest diff --git a/src/nvim/testdir/test_substitute.vim b/src/nvim/testdir/test_substitute.vim index 9b90205c3d..5b476ddd7f 100644 --- a/src/nvim/testdir/test_substitute.vim +++ b/src/nvim/testdir/test_substitute.vim @@ -446,7 +446,7 @@ func Test_substitute_errors() call assert_fails('s/FOO/bar/', 'E486:') call assert_fails('s/foo/bar/@', 'E488:') - call assert_fails('s/\(/bar/', 'E476:') + call assert_fails('s/\(/bar/', 'E54:') call assert_fails('s afooabara', 'E146:') call assert_fails('s\\a', 'E10:') @@ -841,9 +841,9 @@ endfunc func Test_sub_with_no_last_pat() let lines =<< trim [SCRIPT] call assert_fails('~', 'E33:') - call assert_fails('s//abc/g', 'E476:') - call assert_fails('s\/bar', 'E476:') - call assert_fails('s\&bar&', 'E476:') + call assert_fails('s//abc/g', 'E35:') + call assert_fails('s\/bar', 'E35:') + call assert_fails('s\&bar&', 'E33:') call writefile(v:errors, 'Xresult') qall! [SCRIPT] diff --git a/src/nvim/testdir/test_syntax.vim b/src/nvim/testdir/test_syntax.vim index 29ebe141f7..9d108c6ca2 100644 --- a/src/nvim/testdir/test_syntax.vim +++ b/src/nvim/testdir/test_syntax.vim @@ -378,7 +378,7 @@ func Test_syntax_invalid_arg() call assert_fails('syntax sync x', 'E404:') call assert_fails('syntax keyword Abc a[', 'E789:') call assert_fails('syntax keyword Abc a[bc]d', 'E890:') - call assert_fails('syntax cluster Abc add=A add=', 'E475:') + call assert_fails('syntax cluster Abc add=A add=', 'E406:') " Test for too many \z\( and unmatched \z\( " Not able to use assert_fails() here because both E50:/E879: and E475: diff --git a/src/nvim/testdir/test_tagfunc.vim b/src/nvim/testdir/test_tagfunc.vim index ffc1d63b90..bdf5afa5b2 100644 --- a/src/nvim/testdir/test_tagfunc.vim +++ b/src/nvim/testdir/test_tagfunc.vim @@ -85,7 +85,7 @@ func Test_tagfunc() return v:null endfunc set tags= tfu=NullTagFunc - call assert_fails('tag nothing', 'E426') + call assert_fails('tag nothing', 'E433') delf NullTagFunc bwipe! diff --git a/src/nvim/testdir/test_tagjump.vim b/src/nvim/testdir/test_tagjump.vim index f3ca5e306b..61bf9e6d0d 100644 --- a/src/nvim/testdir/test_tagjump.vim +++ b/src/nvim/testdir/test_tagjump.vim @@ -8,7 +8,7 @@ func Test_ptag_with_notagstack() CheckFeature quickfix set notagstack - call assert_fails('ptag does_not_exist_tag_name', 'E426') + call assert_fails('ptag does_not_exist_tag_name', 'E433') set tagstack&vim endfunc @@ -346,7 +346,7 @@ func Test_tagjump_etags() \ "Xmain.c,64", \ ";;;;\x7f1,0", \ ], 'Xtags') - call assert_fails('tag foo', 'E426:') + call assert_fails('tag foo', 'E431:') call delete('Xtags') call delete('Xtags2') diff --git a/src/nvim/testdir/test_taglist.vim b/src/nvim/testdir/test_taglist.vim index 0c47fc9445..658485582c 100644 --- a/src/nvim/testdir/test_taglist.vim +++ b/src/nvim/testdir/test_taglist.vim @@ -84,13 +84,11 @@ func Test_taglist_ctags_etags() endfunc func Test_tags_too_long() - call assert_fails('tag ' . repeat('x', 1020), 'E426') + call assert_fails('tag ' . repeat('x', 1020), ['E433', 'E426']) tags endfunc func Test_tagfiles() - " Nvim: different default for 'tags'. - set tags=./tags,tags call assert_equal([], tagfiles()) call writefile(["FFoo\tXfoo\t1"], 'Xtags1') diff --git a/src/nvim/testdir/test_trycatch.vim b/src/nvim/testdir/test_trycatch.vim index d71bb5bbb8..3dff8fa2d8 100644 --- a/src/nvim/testdir/test_trycatch.vim +++ b/src/nvim/testdir/test_trycatch.vim @@ -2000,13 +2000,11 @@ endfunc func Test_try_catch_errors() call assert_fails('throw |', 'E471:') call assert_fails("throw \n ", 'E471:') - call assert_fails('catch abc', 'E603:') + call assert_fails('catch abc', 'E654:') call assert_fails('try | let i = 1| finally | catch | endtry', 'E604:') call assert_fails('finally', 'E606:') call assert_fails('try | finally | finally | endtry', 'E607:') - " v8.2.3486 has been ported, but v8.2.1183 hasn't, so E170 appears here. - " call assert_fails('try | for i in range(5) | endif | endtry', 'E580:') - call assert_fails('try | for i in range(5) | endif | endtry', 'E170:') + call assert_fails('try | for i in range(5) | endif | endtry', 'E580:') call assert_fails('try | while v:true | endtry', 'E170:') call assert_fails('try | if v:true | endtry', 'E171:') endfunc diff --git a/src/nvim/testdir/test_utf8.vim b/src/nvim/testdir/test_utf8.vim index 2fced0dd2f..8e13ed778f 100644 --- a/src/nvim/testdir/test_utf8.vim +++ b/src/nvim/testdir/test_utf8.vim @@ -21,7 +21,7 @@ func Test_strchars() call assert_equal(exp[i][1], inp[i]->strchars(0)) call assert_equal(exp[i][2], strchars(inp[i], 1)) endfor - call assert_fails("let v=strchars('abc', [])", 'E474:') + call assert_fails("let v=strchars('abc', [])", 'E745:') call assert_fails("let v=strchars('abc', 2)", 'E474:') endfunc diff --git a/src/nvim/testdir/test_winbuf_close.vim b/src/nvim/testdir/test_winbuf_close.vim index f4878c2397..643c1068bd 100644 --- a/src/nvim/testdir/test_winbuf_close.vim +++ b/src/nvim/testdir/test_winbuf_close.vim @@ -115,7 +115,7 @@ func Test_winbuf_close() call assert_equal('Xtest2', bufname('%')) quit! call assert_equal('Xtest3', bufname('%')) - call assert_fails('silent! quit!', 'E162') + call assert_fails('silent! quit!', 'E37') call assert_equal('Xtest1', bufname('%')) call delete('Xtest1') diff --git a/src/nvim/testdir/test_writefile.vim b/src/nvim/testdir/test_writefile.vim index 5ee13ef144..8fb4c8fa4c 100644 --- a/src/nvim/testdir/test_writefile.vim +++ b/src/nvim/testdir/test_writefile.vim @@ -325,7 +325,7 @@ func Test_write_autocmd_unloadbuf_lockmark() autocmd BufWritePre Xfile enew | write augroup END e Xfile - call assert_fails('lockmarks write', 'E203:') + call assert_fails('lockmarks write', ['E32', 'E203:']) augroup WriteTest au! augroup END -- cgit From 159d52b433055e957fec6dee5da20f23fabf10d4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 11:08:40 +0800 Subject: vim-patch:8.2.1184: some tests fail Problem: Some tests fail. Solution: Adjust tests for different assert_fails() behavior. Remove unused variable. https://github.com/vim/vim/commit/2b6ef856fb89f703714f3f1f567d9bd7c81079f3 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_eval_stuff.vim | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_eval_stuff.vim b/src/nvim/testdir/test_eval_stuff.vim index 851048ec5b..46482c34a1 100644 --- a/src/nvim/testdir/test_eval_stuff.vim +++ b/src/nvim/testdir/test_eval_stuff.vim @@ -20,13 +20,8 @@ func Test_nocatch_restore_silent_emsg() throw 1 catch endtry - echoerr 'wrong' - let c1 = nr2char(screenchar(&lines, 1)) - let c2 = nr2char(screenchar(&lines, 2)) - let c3 = nr2char(screenchar(&lines, 3)) - let c4 = nr2char(screenchar(&lines, 4)) - let c5 = nr2char(screenchar(&lines, 5)) - call assert_equal('wrong', c1 . c2 . c3 . c4 . c5) + echoerr 'wrong again' + call assert_equal('wrong again', ScreenLine(&lines)) endfunc func Test_mkdir_p() -- cgit From b33de61cc3e14cc6160a972205f6543e82b843aa Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 12:28:19 +0800 Subject: vim-patch:8.2.1199: not all assert functions are fully tested Problem: Not all assert functions are fully tested. Solution: Test more assert functions. https://github.com/vim/vim/commit/7177da9dd4d9a521c6141c6fbf7e9a4d6296ab05 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_assert.vim | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_assert.vim b/src/nvim/testdir/test_assert.vim index 8723a0a38d..0ba45d0b13 100644 --- a/src/nvim/testdir/test_assert.vim +++ b/src/nvim/testdir/test_assert.vim @@ -48,6 +48,11 @@ func Test_assert_equal() call assert_equal('XxxxxxxxxxxxxxxxxxxxxxX', 'XyyyyyyyyyyyyyyyyyyyyyyyyyX') call assert_match("Expected 'X\\\\\\[x occurs 21 times]X' but got 'X\\\\\\[y occurs 25 times]X'", v:errors[0]) call remove(v:errors, 0) + + " special characters are escaped + call assert_equal("\b\e\f\n\t\r\\\x01\x7f", 'x') + call assert_match('Expected ''\\b\\e\\f\\n\\t\\r\\\\\\x01\\x7f'' but got ''x''', v:errors[0]) + call remove(v:errors, 0) endfunc func Test_assert_equal_dict() @@ -143,6 +148,14 @@ func Test_assert_exception() call assert_equal(0, assert_exception('E492:')) endtry + try + nocommand + catch + call assert_equal(1, assert_exception('E12345:')) + endtry + call assert_match("Expected 'E12345:' but got 'Vim:E492: ", v:errors[0]) + call remove(v:errors, 0) + try nocommand catch @@ -153,6 +166,10 @@ func Test_assert_exception() call assert_equal(0, assert_exception('E730:')) endtry endtry + + call assert_equal(1, assert_exception('E492:')) + call assert_match('v:exception is not set', v:errors[0]) + call remove(v:errors, 0) endfunc func Test_wrong_error_type() @@ -202,6 +219,14 @@ func Test_assert_fail_fails() call assert_match("stupid: Expected 'E9876' but got 'E492:", v:errors[0]) call remove(v:errors, 0) + call assert_equal(1, assert_fails('xxx', ['E9876'])) + call assert_match("Expected \\['E9876'\\] but got 'E492:", v:errors[0]) + call remove(v:errors, 0) + + call assert_equal(1, assert_fails('xxx', ['E492:', 'E9876'])) + call assert_match("Expected \\['E492:', 'E9876'\\] but got 'E492:", v:errors[0]) + call remove(v:errors, 0) + call assert_equal(1, assert_fails('echo', '', 'echo command')) call assert_match("command did not fail: echo command", v:errors[0]) call remove(v:errors, 0) @@ -209,6 +234,27 @@ func Test_assert_fail_fails() call assert_equal(1, 'echo'->assert_fails('', 'echo command')) call assert_match("command did not fail: echo command", v:errors[0]) call remove(v:errors, 0) + + try + call assert_equal(1, assert_fails('xxx', [])) + catch + let exp = v:exception + endtry + call assert_match("E856: assert_fails() second argument", exp) + + try + call assert_equal(1, assert_fails('xxx', ['1', '2', '3'])) + catch + let exp = v:exception + endtry + call assert_match("E856: assert_fails() second argument", exp) + + try + call assert_equal(1, assert_fails('xxx', #{one: 1})) + catch + let exp = v:exception + endtry + call assert_match("E856: assert_fails() second argument", exp) endfunc func Test_assert_fails_in_try_block() -- cgit From 6956971ec790e636b16eeaec798c826515da9834 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 12:33:10 +0800 Subject: vim-patch:8.2.1632: not checking the context of test_fails() Problem: Not checking the context of test_fails(). Solution: Add the line number and context arguments. Give error if assert_fails() argument types are wrong. https://github.com/vim/vim/commit/44d6652d561d628d12e3ff7f6636ea7d1f805ced Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_assert.vim | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_assert.vim b/src/nvim/testdir/test_assert.vim index 0ba45d0b13..431908e95c 100644 --- a/src/nvim/testdir/test_assert.vim +++ b/src/nvim/testdir/test_assert.vim @@ -255,6 +255,20 @@ func Test_assert_fail_fails() let exp = v:exception endtry call assert_match("E856: assert_fails() second argument", exp) + + try + call assert_equal(1, assert_fails('xxx', 'E492', '', 'burp')) + catch + let exp = v:exception + endtry + call assert_match("E1115: assert_fails() fourth argument must be a number", exp) + + try + call assert_equal(1, assert_fails('xxx', 'E492', '', 54, 123)) + catch + let exp = v:exception + endtry + call assert_match("E1116: assert_fails() fifth argument must be a string", exp) endfunc func Test_assert_fails_in_try_block() -- cgit From 30cfdd0ea1f67afed6732ecbcdda9dda72a2b0a0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 14:26:28 +0800 Subject: vim-patch:8.2.5027: error for missing :endif when an exception was thrown Problem: Error for missing :endif when an exception was thrown. (Dani Dickstein) Solution: Do not give an error when aborting. (closes vim/vim#10490) https://github.com/vim/vim/commit/bf79a4e48d09a5ae08645592885d54230fed30b8 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_trycatch.vim | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_trycatch.vim b/src/nvim/testdir/test_trycatch.vim index 3dff8fa2d8..8a1d2d3fa7 100644 --- a/src/nvim/testdir/test_trycatch.vim +++ b/src/nvim/testdir/test_trycatch.vim @@ -2221,6 +2221,23 @@ func Test_user_command_throw_in_function_call() unlet g:caught endfunc +" Test that after reporting an uncaught exception there is no error for a +" missing :endif +func Test_after_exception_no_endif_error() + function Throw() + throw "Failure" + endfunction + + function Foo() + if 1 + call Throw() + endif + endfunction + call assert_fails('call Foo()', ['E605:', 'E605:']) + delfunc Throw + delfunc Foo +endfunc + " Test for using throw in a called function with following endtry {{{1 func Test_user_command_function_call_with_endtry() let lines =<< trim END -- cgit From 78e69412acb481c7ad56e68c541f5c5383992d5b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 15:51:26 +0800 Subject: vim-patch:8.2.4688: new regexp engine does not give an error for "\%v" Problem: New regexp engine does not give an error for "\%v". Solution: Check for a value argument. (issue vim/vim#10079) https://github.com/vim/vim/commit/91ff3d4f52a55a7c37a52aaad524cd9dd12efae4 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_regexp_latin.vim | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_regexp_latin.vim b/src/nvim/testdir/test_regexp_latin.vim index 2a9a0e9d50..2671313997 100644 --- a/src/nvim/testdir/test_regexp_latin.vim +++ b/src/nvim/testdir/test_regexp_latin.vim @@ -105,6 +105,18 @@ func Test_multi_failure() set re=0 endfunc +func Test_column_failure() + set re=1 + call assert_fails('/\%v', 'E71:') + call assert_fails('/\%c', 'E71:') + call assert_fails('/\%l', 'E71:') + set re=2 + call assert_fails('/\%v', 'E1273:') + call assert_fails('/\%c', 'E1273:') + call assert_fails('/\%l', 'E1273:') + set re=0 +endfunc + func Test_recursive_addstate() throw 'skipped: TODO: ' " This will call addstate() recursively until it runs into the limit. -- cgit From 77e25e56d8ccc0c174305f9fe64ad06f0223ab2d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 15:56:15 +0800 Subject: vim-patch:8.2.4693: new regexp does not accept pattern "\%>0v" Problem: new regexp does not accept pattern "\%>0v". Solution: Do accept digit zero. https://github.com/vim/vim/commit/72bb10df1fb3eb69bc91f5babfb8881ce098cba1 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_regexp_latin.vim | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_regexp_latin.vim b/src/nvim/testdir/test_regexp_latin.vim index 2671313997..5312c6f26a 100644 --- a/src/nvim/testdir/test_regexp_latin.vim +++ b/src/nvim/testdir/test_regexp_latin.vim @@ -105,16 +105,29 @@ func Test_multi_failure() set re=0 endfunc -func Test_column_failure() +func Test_column_success_failure() + new + call setline(1, 'xbar') + set re=1 + %s/\%>0v./A/ + call assert_equal('Abar', getline(1)) call assert_fails('/\%v', 'E71:') + call assert_fails('/\%>v', 'E71:') call assert_fails('/\%c', 'E71:') + call assert_fails('/\%0v./B/ + call assert_equal('Bbar', getline(1)) call assert_fails('/\%v', 'E1273:') + call assert_fails('/\%>v', 'E1273:') call assert_fails('/\%c', 'E1273:') + call assert_fails('/\% Date: Sat, 5 Nov 2022 15:59:17 +0800 Subject: vim-patch:8.2.4978: no error if engine selection atom is not at the start Problem: No error if engine selection atom is not at the start. Solution: Give an error. (Christian Brabandt, closes vim/vim#10439) https://github.com/vim/vim/commit/360da40b47a84ee8586c3b5d062f8c64a2ac9cc6 Co-authored-by: Christian Brabandt --- src/nvim/testdir/test_regexp_latin.vim | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_regexp_latin.vim b/src/nvim/testdir/test_regexp_latin.vim index 5312c6f26a..3a4a7ad910 100644 --- a/src/nvim/testdir/test_regexp_latin.vim +++ b/src/nvim/testdir/test_regexp_latin.vim @@ -1058,6 +1058,24 @@ func Test_using_invalid_visual_position() bwipe! endfunc +func Test_using_two_engines_pattern() + new + call setline(1, ['foobar=0', 'foobar=1', 'foobar=2']) + " \%#= at the end of the pattern + for i in range(0, 2) + call cursor( (i+1), 7) + call assert_fails("%s/foobar\\%#=" .. i, 'E1281:') + endfor + + " \%#= at the start of the pattern + for i in range(0, 2) + call cursor( (i+1), 7) + exe ":%s/\\%#=" .. i .. "foobar=" .. i .. "/xx" + endfor + call assert_equal(['xx', 'xx', 'xx'], getline(1, '$')) + bwipe! +endfunc + func Test_recursive_substitute_expr() new func Repl() -- cgit From e33ffab1a776518dbf59ba5fe82453fa019569eb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 16:03:00 +0800 Subject: vim-patch:9.0.0053: E1281 not tested with the old regexp engine MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: E1281 not tested with the old regexp engine. Solution: Loop over the values of 'regexp'. (Dominique Pellé, closes vim/vim#10695) https://github.com/vim/vim/commit/3a393790a4fd7a5edcafbb55cd79438b6e641714 Co-authored-by: Dominique Pelle --- src/nvim/testdir/test_regexp_latin.vim | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_regexp_latin.vim b/src/nvim/testdir/test_regexp_latin.vim index 3a4a7ad910..ece6ae518e 100644 --- a/src/nvim/testdir/test_regexp_latin.vim +++ b/src/nvim/testdir/test_regexp_latin.vim @@ -1063,13 +1063,17 @@ func Test_using_two_engines_pattern() call setline(1, ['foobar=0', 'foobar=1', 'foobar=2']) " \%#= at the end of the pattern for i in range(0, 2) - call cursor( (i+1), 7) - call assert_fails("%s/foobar\\%#=" .. i, 'E1281:') + for j in range(0, 2) + exe "set re=" .. i + call cursor(j + 1, 7) + call assert_fails("%s/foobar\\%#=" .. j, 'E1281:') + endfor endfor + set re=0 " \%#= at the start of the pattern for i in range(0, 2) - call cursor( (i+1), 7) + call cursor(i + 1, 7) exe ":%s/\\%#=" .. i .. "foobar=" .. i .. "/xx" endfor call assert_equal(['xx', 'xx', 'xx'], getline(1, '$')) -- cgit From e25193143bca3a48920322634120a442854bb891 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 14:59:45 +0800 Subject: vim-patch:8.2.1751: using 2 where bool is expected may throw an error Problem: Using 2 where bool is expected may throw an error. Solution: Make this backwards compatible. https://github.com/vim/vim/commit/bade44e5cad1b08c85d4a8ba08d94a30458dddfb In legacy Vim script get_bool functions do the same thing as get_number functions, so just add aliases using #define. N/A patches for version.c: vim-patch:8.2.1506: Vim9: no error when using a number other than 0 or 1 as bool Problem: Vim9: no error when using a number other than 0 or 1 as bool. Solution: Check the number is 0 or 1. https://github.com/vim/vim/commit/d70840ed68296c1144d743e6335003c81c558c24 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_search.vim | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index e77a022d11..96ed35718f 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -294,6 +294,9 @@ func Test_searchpair() new call setline(1, ['other code', 'here [', ' [', ' " cursor here', ' ]]']) + " should not give an error for using "42" + call assert_equal(0, searchpair('a', 'b', 'c', '', 42)) + 4 call assert_equal(3, searchpair('\[', '', ']', 'bW')) call assert_equal([0, 3, 2, 0], getpos('.')) -- cgit From 38c113ae842aa8c42ad66bba15f16cf401637ab8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 17:43:38 +0800 Subject: vim-patch:8.2.1600: Vim9: cannot use "true" with deepcopy() Problem: Vim9: cannot use "true" with deepcopy(). Solution: Use tv_get_bool_chk(). (closes vim/vim#6867) https://github.com/vim/vim/commit/44b4a246b62e0622550b963bcf3034dce3bcfc0c Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_listdict.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_listdict.vim b/src/nvim/testdir/test_listdict.vim index 7cb48876e8..ecf95ba8c0 100644 --- a/src/nvim/testdir/test_listdict.vim +++ b/src/nvim/testdir/test_listdict.vim @@ -336,12 +336,12 @@ func Test_dict_deepcopy() let l = [4, d, 6] let d[3] = l let dc = deepcopy(d) - call assert_fails('call deepcopy(d, 1)', 'E698') + call assert_fails('call deepcopy(d, 1)', 'E698:') let l2 = [0, l, l, 3] let l[1] = l2 let l3 = deepcopy(l2) call assert_true(l3[1] is l3[2]) - call assert_fails("call deepcopy([1, 2], 2)", 'E474:') + call assert_fails("call deepcopy([1, 2], 2)", 'E1023:') endfunc " Locked variables -- cgit From 451850920b361059ba99bbde4b90b7730327eebb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 15:06:39 +0800 Subject: vim-patch:8.2.1626: test for strchars() fails with different error number Problem: Test for strchars() fails with different error number. Solution: Adjust the error number. https://github.com/vim/vim/commit/707be5f3524accb8b36e80bd2532e00b8246df55 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_utf8.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_utf8.vim b/src/nvim/testdir/test_utf8.vim index 8e13ed778f..3d29d38231 100644 --- a/src/nvim/testdir/test_utf8.vim +++ b/src/nvim/testdir/test_utf8.vim @@ -22,7 +22,7 @@ func Test_strchars() call assert_equal(exp[i][2], strchars(inp[i], 1)) endfor call assert_fails("let v=strchars('abc', [])", 'E745:') - call assert_fails("let v=strchars('abc', 2)", 'E474:') + call assert_fails("let v=strchars('abc', 2)", 'E1023:') endfunc " Test for customlist completion -- cgit From 781616bee5e319fdfa034484c026222b50926ebf Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 17:16:49 +0800 Subject: vim-patch:8.2.2606: strchars() defaults to counting composing characters Problem: strchars() defaults to counting composing characters. Solution: Add strcharlen() which ignores composing characters. https://github.com/vim/vim/commit/70ce8a1561c5396e4c4381f76a005cbb97646f80 Use docs from latest Vim instead. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_utf8.vim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_utf8.vim b/src/nvim/testdir/test_utf8.vim index 3d29d38231..aa3b02b575 100644 --- a/src/nvim/testdir/test_utf8.vim +++ b/src/nvim/testdir/test_utf8.vim @@ -12,7 +12,7 @@ func Test_visual_block_insert() bwipeout! endfunc -" Test for built-in function strchars() +" Test for built-in functions strchars() and strcharlen() func Test_strchars() let inp = ["a", "あいa", "A\u20dd", "A\u20dd\u20dd", "\u20dd"] let exp = [[1, 1, 1], [3, 3, 3], [2, 2, 1], [3, 3, 1], [1, 1, 1]] @@ -21,6 +21,13 @@ func Test_strchars() call assert_equal(exp[i][1], inp[i]->strchars(0)) call assert_equal(exp[i][2], strchars(inp[i], 1)) endfor + + let exp = [1, 3, 1, 1, 1] + for i in range(len(inp)) + call assert_equal(exp[i], inp[i]->strcharlen()) + call assert_equal(exp[i], strcharlen(inp[i])) + endfor + call assert_fails("let v=strchars('abc', [])", 'E745:') call assert_fails("let v=strchars('abc', 2)", 'E1023:') endfunc -- cgit From 8e868d699a9d0b68342d8d460a8f6dd9c075d7a8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 22 Oct 2022 09:32:01 +0800 Subject: vim-patch:8.2.4679: cannot have expandcmd() give an error message for mistakes Problem: Cannot have expandcmd() give an error message for mistakes. Solution: Add an optional argument to give errors. Fix memory leak when expanding files fails. (Yegappan Lakshmanan, closes vim/vim#10071) https://github.com/vim/vim/commit/2b74b6805b5c8c4836b66df5d949f5ff6a77f8c7 Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_expand.vim | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_expand.vim b/src/nvim/testdir/test_expand.vim index aa131a49ff..4f5bb67d21 100644 --- a/src/nvim/testdir/test_expand.vim +++ b/src/nvim/testdir/test_expand.vim @@ -90,14 +90,26 @@ func Test_expandcmd() " Test for expression expansion `= let $FOO= "blue" call assert_equal("blue sky", expandcmd("`=$FOO .. ' sky'`")) + let x = expandcmd("`=axbycz`") + call assert_equal('`=axbycz`', x) + call assert_fails('let x = expandcmd("`=axbycz`", #{errmsg: 1})', 'E121:') + let x = expandcmd("`=axbycz`", #{abc: []}) + call assert_equal('`=axbycz`', x) " Test for env variable with spaces let $FOO= "foo bar baz" call assert_equal("e foo bar baz", expandcmd("e $FOO")) - if has('unix') - " test for using the shell to expand a command argument - call assert_equal('{1..4}', expandcmd('{1..4}')) + if has('unix') && executable('bash') + " test for using the shell to expand a command argument. + " only bash supports the {..} syntax + set shell=bash + let x = expandcmd('{1..4}') + call assert_equal('{1..4}', x) + call assert_fails("let x = expandcmd('{1..4}', #{errmsg: v:true})", 'E77:') + let x = expandcmd('{1..4}', #{error: v:true}) + call assert_equal('{1..4}', x) + set shell& endif unlet $FOO -- cgit From 3c0651fb459189f5be6165454810e4476296cb7c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 18:02:05 +0800 Subject: fix(eval): make error number of charidx() same as Vim --- src/nvim/testdir/test_functions.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 06c995db86..d2603809b9 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1101,8 +1101,8 @@ func Test_charidx() call assert_fails('let x = charidx([], 1)', 'E474:') call assert_fails('let x = charidx("abc", [])', 'E474:') call assert_fails('let x = charidx("abc", 1, [])', 'E474:') - call assert_fails('let x = charidx("abc", 1, -1)', 'E474:') - call assert_fails('let x = charidx("abc", 1, 2)', 'E474:') + call assert_fails('let x = charidx("abc", 1, -1)', 'E1023:') + call assert_fails('let x = charidx("abc", 1, 2)', 'E1023:') endfunc func Test_count() -- cgit From b92ed35a0bb873589bba9b51fdb92ffd00dc3e57 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 1 Apr 2022 18:12:55 +0800 Subject: vim-patch:8.2.4093: cached breakindent values not initialized properly Problem: Cached breakindent values not initialized properly. Solution: Initialize and cache formatlistpat. (Christian Brabandt, closes vim/vim#9526, closes vim/vim#9512) https://github.com/vim/vim/commit/c53b467473160b5cfce77277fbae414bf43e66ce Co-authored-by: Christian Brabandt --- src/nvim/testdir/test_breakindent.vim | 57 +++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_breakindent.vim b/src/nvim/testdir/test_breakindent.vim index 69c98f1f05..a665ee5b28 100644 --- a/src/nvim/testdir/test_breakindent.vim +++ b/src/nvim/testdir/test_breakindent.vim @@ -889,4 +889,61 @@ func Test_window_resize_with_linebreak() %bw! endfunc +func Test_no_spurious_match() + let s:input = printf('- y %s y %s', repeat('x', 50), repeat('x', 50)) + call s:test_windows('setl breakindent breakindentopt=list:-1 formatlistpat=^- hls') + let @/ = '\%>3v[y]' + redraw! + call searchcount().total->assert_equal(1) + " cleanup + set hls&vim + let s:input = "\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP" + bwipeout! +endfunc + +func Test_no_extra_indent() + call s:test_windows('setl breakindent breakindentopt=list:-1,min:10') + %d + let &l:formatlistpat='^\s*\d\+\.\s\+' + let text = 'word ' + let len = text->strcharlen() + let line1 = text->repeat((winwidth(0) / len) * 2) + let line2 = repeat(' ', 2) .. '1. ' .. line1 + call setline(1, [line2]) + redraw! + " 1) matches formatlist pattern, so indent + let expect = [ + \ " 1. word word word ", + \ " word word word ", + \ " word word ", + \ "~ ", + \ ] + let lines = s:screen_lines2(1, 4, 20) + call s:compare_lines(expect, lines) + " 2) change formatlist pattern + " -> indent adjusted + let &l:formatlistpat='^\s*\d\+\.' + let expect = [ + \ " 1. word word word ", + \ " word word word ", + \ " word word ", + \ "~ ", + \ ] + let lines = s:screen_lines2(1, 4, 20) + " 3) add something in front, no additional indent + norm! gg0 + exe ":norm! 5iword \" + redraw! + let expect = [ + \ "word word word word ", + \ "word 1. word word ", + \ "word word word word ", + \ "word word ", + \ "~ ", + \ ] + let lines = s:screen_lines2(1, 5, 20) + call s:compare_lines(expect, lines) + bwipeout! +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 8b43091392ec895c77b83ff5964cd37b54976089 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 1 Apr 2022 18:31:19 +0800 Subject: vim-patch:8.2.4100: early return when getting the 'formatlistpat' value Problem: Early return when getting the 'formatlistpat' value. Solution: Remove the first line. (Christian Brabandt) https://github.com/vim/vim/commit/04b871da800768287a8a432de568b11297db8686 --- src/nvim/testdir/test_breakindent.vim | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_breakindent.vim b/src/nvim/testdir/test_breakindent.vim index a665ee5b28..8bbac2d237 100644 --- a/src/nvim/testdir/test_breakindent.vim +++ b/src/nvim/testdir/test_breakindent.vim @@ -930,7 +930,22 @@ func Test_no_extra_indent() \ "~ ", \ ] let lines = s:screen_lines2(1, 4, 20) - " 3) add something in front, no additional indent + " 3) no local formatlist pattern, + " so use global one -> indent + let g_flp = &g:flp + let &g:formatlistpat='^\s*\d\+\.\s\+' + let &l:formatlistpat='' + let expect = [ + \ " 1. word word word ", + \ " word word word ", + \ " word word ", + \ "~ ", + \ ] + let lines = s:screen_lines2(1, 4, 20) + call s:compare_lines(expect, lines) + let &g:flp = g_flp + let &l:formatlistpat='^\s*\d\+\.' + " 4) add something in front, no additional indent norm! gg0 exe ":norm! 5iword \" redraw! -- cgit From 6374120558476b9ab0ec4dc1df0523c73756e4ae Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 19:08:25 +0800 Subject: vim-patch:8.2.4501: with 'showbreak' set cursor displayed in wrong position Problem: With 'showbreak' set and after the end of the line the cursor may be displayed in the wrong position. Solution: Do not apply 'showbreak' after the end of the line. (closes vim/vim#9884) https://github.com/vim/vim/commit/21efafe4c25373929979c72dc8aafa119f12dd8b Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_breakindent.vim | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_breakindent.vim b/src/nvim/testdir/test_breakindent.vim index 8bbac2d237..934dca4793 100644 --- a/src/nvim/testdir/test_breakindent.vim +++ b/src/nvim/testdir/test_breakindent.vim @@ -8,6 +8,7 @@ source check.vim CheckOption breakindent source view_util.vim +source screendump.vim let s:input ="\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP" @@ -889,6 +890,27 @@ func Test_window_resize_with_linebreak() %bw! endfunc +func Test_cursor_position_with_showbreak() + CheckScreendump + + let lines =<< trim END + vim9script + &signcolumn = 'yes' + &showbreak = '+ ' + var leftcol: number = win_getid()->getwininfo()->get(0, {})->get('textoff') + repeat('x', &columns - leftcol - 1)->setline(1) + 'second line'->setline(2) + END + call writefile(lines, 'XscriptShowbreak') + let buf = RunVimInTerminal('-S XscriptShowbreak', #{rows: 6}) + + call term_sendkeys(buf, "AX") + call VerifyScreenDump(buf, 'Test_cursor_position_with_showbreak', {}) + + call StopVimInTerminal(buf) + call delete('XscriptShowbreak') +endfunc + func Test_no_spurious_match() let s:input = printf('- y %s y %s', repeat('x', 50), repeat('x', 50)) call s:test_windows('setl breakindent breakindentopt=list:-1 formatlistpat=^- hls') -- cgit From e0ec83a9701ffd9b30a41763ad2e2326d85d8480 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 19:19:55 +0800 Subject: vim-patch:8.2.4882: cannot make 'breakindent' use a specific column Problem: Cannot make 'breakindent' use a specific column. Solution: Add the "column" entry in 'breakindentopt'. (Christian Brabandt, closes vim/vim#10362, closes vim/vim#10325) https://github.com/vim/vim/commit/e7d6dbc5721342e3d6b04cf285e4510b5569e707 Co-authored-by: Christian Brabandt --- src/nvim/testdir/test_breakindent.vim | 62 ++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 4 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_breakindent.vim b/src/nvim/testdir/test_breakindent.vim index 934dca4793..995683c68c 100644 --- a/src/nvim/testdir/test_breakindent.vim +++ b/src/nvim/testdir/test_breakindent.vim @@ -877,16 +877,17 @@ endfunc func Test_window_resize_with_linebreak() new 53vnew - set linebreak - set showbreak=>> - set breakindent - set breakindentopt=shift:4 + setl linebreak + setl showbreak=>> + setl breakindent + setl breakindentopt=shift:4 call setline(1, "\naaaaaaaaa\n\na\naaaaa\n¯aaaaaaaaaa\naaaaaaaaaaaa\naaa\n\"a:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - aaaaaaaa\"\naaaaaaaa\n\"a") redraw! call assert_equal([" >>aa^@\"a: "], ScreenLines(2, 14)) vertical resize 52 redraw! call assert_equal([" >>aaa^@\"a:"], ScreenLines(2, 14)) + set linebreak& showbreak& breakindent& breakindentopt& %bw! endfunc @@ -983,4 +984,57 @@ func Test_no_extra_indent() bwipeout! endfunc +func Test_breakindent_column() + " restore original + let s:input ="\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP" + call s:test_windows('setl breakindent breakindentopt=column:10') + redraw! + " 1) default: does not indent, too wide :( + let expect = [ + \ " ", + \ " abcdefghijklmnop", + \ "qrstuvwxyzABCDEFGHIJ", + \ "KLMNOP " + \ ] + let lines = s:screen_lines2(1, 4, 20) + call s:compare_lines(expect, lines) + " 2) lower min value, so that breakindent works + setl breakindentopt+=min:5 + redraw! + let expect = [ + \ " ", + \ " abcdefghijklmnop", + \ " qrstuvwxyz", + \ " ABCDEFGHIJ", + \ " KLMNOP " + \ ] + let lines = s:screen_lines2(1, 5, 20) + " 3) set shift option -> no influence + setl breakindentopt+=shift:5 + redraw! + let expect = [ + \ " ", + \ " abcdefghijklmnop", + \ " qrstuvwxyz", + \ " ABCDEFGHIJ", + \ " KLMNOP " + \ ] + let lines = s:screen_lines2(1, 5, 20) + call s:compare_lines(expect, lines) + " 4) add showbreak value + setl showbreak=++ + redraw! + let expect = [ + \ " ", + \ " abcdefghijklmnop", + \ " ++qrstuvwx", + \ " ++yzABCDEF", + \ " ++GHIJKLMN", + \ " ++OP " + \ ] + let lines = s:screen_lines2(1, 6, 20) + call s:compare_lines(expect, lines) + bwipeout! +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 01ccfb40e3ac678829f301aec1d10f5fc06548c6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 20:16:29 +0800 Subject: vim-patch:8.2.1106: crash when trying to use s: variable in typed command Problem: Crash when trying to use s: variable in typed command. Solution: Don't use the script index when not set. (Ken Takata, closes vim/vim#6366) https://github.com/vim/vim/commit/8e6cbb72324b6fb25d1a9abd6cc4d102d0e5f14e --- src/nvim/testdir/test_vimscript.vim | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index 3a6baaf1f0..a7ab78d87a 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -1810,6 +1810,7 @@ func Test_float_conversion_errors() endif endfunc +" invalid function names {{{1 func Test_invalid_function_names() " function name not starting with capital let caught_e128 = 0 @@ -1870,7 +1871,7 @@ func Test_invalid_function_names() call delete('Xscript') endfunc -" substring and variable name +" substring and variable name {{{1 func Test_substring_var() let str = 'abcdef' let n = 3 @@ -1890,6 +1891,20 @@ func Test_substring_var() unlet b:nn endfunc +" Test using s: with a typed command {{{1 +func Test_typed_script_var() + CheckRunVimInTerminal + + let buf = RunVimInTerminal('', {'rows': 6}) + + " Deep nesting of if ... endif + call term_sendkeys(buf, ":echo get(s:, 'foo', 'x')\n") + call TermWait(buf) + call WaitForAssert({-> assert_match('^E116:', term_getline(buf, 5))}) + + call StopVimInTerminal(buf) +endfunc + func Test_for_over_string() let res = '' for c in 'aéc̀d' -- cgit From 42e7c7fc9c50394bd9fc4e56b0487b47f2931531 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 20:23:29 +0800 Subject: vim-patch:8.2.1366: test 49 is old style Problem: Test 49 is old style. Solution: Convert several tests to new style. (Yegappan Lakshmanan, closes vim/vim#6629) https://github.com/vim/vim/commit/a6296200bd5191bab7efcdcc16c9e79eb498e8e0 --- src/nvim/testdir/test49.ok | 21 - src/nvim/testdir/test49.vim | 1643 +------------------------------ src/nvim/testdir/test_vimscript.vim | 1852 +++++++++++++++++++++++++++++++++-- 3 files changed, 1764 insertions(+), 1752 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test49.ok b/src/nvim/testdir/test49.ok index 9f283e808b..50696fd643 100644 --- a/src/nvim/testdir/test49.ok +++ b/src/nvim/testdir/test49.ok @@ -1,25 +1,4 @@ Results of test49.vim: -*** Test 18: OK (67224583) -*** Test 19: OK (69275973) -*** Test 20: OK (1874575085) -*** Test 21: OK (147932225) -*** Test 22: OK (4161) -*** Test 23: OK (49) -*** Test 24: OK (41) -*** Test 27: OK (1996459) -*** Test 28: OK (1996459) -*** Test 29: OK (170428555) -*** Test 30: OK (190905173) -*** Test 31: OK (190905173) -*** Test 34: OK (2146584868) -*** Test 35: OK (2146584868) -*** Test 36: OK (1071644672) -*** Test 37: OK (1071644672) -*** Test 38: OK (357908480) -*** Test 39: OK (357908480) -*** Test 40: OK (357908480) -*** Test 49: OK (179000669) -*** Test 50: OK (363550045) *** Test 52: OK (1247112011) *** Test 53: OK (131071) *** Test 54: OK (2047) diff --git a/src/nvim/testdir/test49.vim b/src/nvim/testdir/test49.vim index 3ee5e9ff7c..d51ba24153 100644 --- a/src/nvim/testdir/test49.vim +++ b/src/nvim/testdir/test49.vim @@ -1,6 +1,6 @@ " Vim script language tests " Author: Servatius Brandt -" Last Change: 2019 Nov 03 +" Last Change: 2020 Jun 07 "------------------------------------------------------------------------------- " Test environment {{{1 @@ -607,1647 +607,10 @@ com! -nargs=1 -bar ExecAsScript call ExecAsScript() " END_OF_TEST_ENVIRONMENT - do not change or remove this line. - -" Tests 1 to 17 were moved to test_vimscript.vim -let Xtest = 18 - -"------------------------------------------------------------------------------- -" Test 18: Interrupt (Ctrl-C pressed) {{{1 -" -" On an interrupt, the script processing is terminated immediately. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - if 1 - Xpath 1 " X: 1 - while 1 - Xpath 2 " X: 2 - if 1 - Xpath 4 " X: 4 - "INTERRUPT - Xpath 8 " X: 0 - break - finish - endif | Xpath 16 " X: 0 - Xpath 32 " X: 0 - endwhile | Xpath 64 " X: 0 - Xpath 128 " X: 0 - endif | Xpath 256 " X: 0 - Xpath 512 " X: 0 -endif - -if ExtraVim() - try - Xpath 1024 " X: 1024 - "INTERRUPT - Xpath 2048 " X: 0 - endtry | Xpath 4096 " X: 0 - Xpath 8192 " X: 0 -endif - -if ExtraVim() - function! F() - if 1 - Xpath 16384 " X: 16384 - while 1 - Xpath 32768 " X: 32768 - if 1 - Xpath 65536 " X: 65536 - "INTERRUPT - Xpath 131072 " X: 0 - break - return - endif | Xpath 262144 " X: 0 - Xpath Xpath 524288 " X: 0 - endwhile | Xpath 1048576 " X: 0 - Xpath Xpath 2097152 " X: 0 - endif | Xpath Xpath 4194304 " X: 0 - Xpath Xpath 8388608 " X: 0 - endfunction - - call F() | Xpath 16777216 " X: 0 - Xpath 33554432 " X: 0 -endif - -if ExtraVim() - function! G() - try - Xpath 67108864 " X: 67108864 - "INTERRUPT - Xpath 134217728 " X: 0 - endtry | Xpath 268435456 " X: 0 - Xpath 536870912 " X: 0 - endfunction - - call G() | Xpath 1073741824 " X: 0 - " The Xpath command does not accept 2^31 (negative); display explicitly: - exec "!echo 2147483648 >>" . g:ExtraVimResult - " X: 0 -endif - -Xcheck 67224583 - - -"------------------------------------------------------------------------------- -" Test 19: Aborting on errors inside :try/:endtry {{{1 -" -" An error in a command dynamically enclosed in a :try/:endtry region -" aborts script processing immediately. It does not matter whether -" the failing command is outside or inside a function and whether a -" function has an "abort" attribute. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - function! F() abort - Xpath 1 " X: 1 - asdf - Xpath 2 " X: 0 - endfunction - - try - Xpath 4 " X: 4 - call F() - Xpath 8 " X: 0 - endtry | Xpath 16 " X: 0 - Xpath 32 " X: 0 -endif - -if ExtraVim() - function! G() - Xpath 64 " X: 64 - asdf - Xpath 128 " X: 0 - endfunction - - try - Xpath 256 " X: 256 - call G() - Xpath 512 " X: 0 - endtry | Xpath 1024 " X: 0 - Xpath 2048 " X: 0 -endif - -if ExtraVim() - try - Xpath 4096 " X: 4096 - asdf - Xpath 8192 " X: 0 - endtry | Xpath 16384 " X: 0 - Xpath 32768 " X: 0 -endif - -if ExtraVim() - if 1 - try - Xpath 65536 " X: 65536 - asdf - Xpath 131072 " X: 0 - endtry | Xpath 262144 " X: 0 - endif | Xpath 524288 " X: 0 - Xpath 1048576 " X: 0 -endif - -if ExtraVim() - let p = 1 - while p - let p = 0 - try - Xpath 2097152 " X: 2097152 - asdf - Xpath 4194304 " X: 0 - endtry | Xpath 8388608 " X: 0 - endwhile | Xpath 16777216 " X: 0 - Xpath 33554432 " X: 0 -endif - -if ExtraVim() - let p = 1 - while p - let p = 0 -" try - Xpath 67108864 " X: 67108864 - endwhile | Xpath 134217728 " X: 0 - Xpath 268435456 " X: 0 -endif - -Xcheck 69275973 -"------------------------------------------------------------------------------- -" Test 20: Aborting on errors after :try/:endtry {{{1 -" -" When an error occurs after the last active :try/:endtry region has -" been left, termination behavior is as if no :try/:endtry has been -" seen. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - let p = 1 - while p - let p = 0 - try - Xpath 1 " X: 1 - endtry - asdf - endwhile | Xpath 2 " X: 0 - Xpath 4 " X: 4 -endif - -if ExtraVim() - while 1 - try - Xpath 8 " X: 8 - break - Xpath 16 " X: 0 - endtry - endwhile - Xpath 32 " X: 32 - asdf - Xpath 64 " X: 64 -endif - -if ExtraVim() - while 1 - try - Xpath 128 " X: 128 - break - Xpath 256 " X: 0 - finally - Xpath 512 " X: 512 - endtry - endwhile - Xpath 1024 " X: 1024 - asdf - Xpath 2048 " X: 2048 -endif - -if ExtraVim() - while 1 - try - Xpath 4096 " X: 4096 - finally - Xpath 8192 " X: 8192 - break - Xpath 16384 " X: 0 - endtry - endwhile - Xpath 32768 " X: 32768 - asdf - Xpath 65536 " X: 65536 -endif - -if ExtraVim() - let p = 1 - while p - let p = 0 - try - Xpath 131072 " X: 131072 - continue - Xpath 262144 " X: 0 - endtry - endwhile - Xpath 524288 " X: 524288 - asdf - Xpath 1048576 " X: 1048576 -endif - -if ExtraVim() - let p = 1 - while p - let p = 0 - try - Xpath 2097152 " X: 2097152 - continue - Xpath 4194304 " X: 0 - finally - Xpath 8388608 " X: 8388608 - endtry - endwhile - Xpath 16777216 " X: 16777216 - asdf - Xpath 33554432 " X: 33554432 -endif - -if ExtraVim() - let p = 1 - while p - let p = 0 - try - Xpath 67108864 " X: 67108864 - finally - Xpath 134217728 " X: 134217728 - continue - Xpath 268435456 " X: 0 - endtry - endwhile - Xpath 536870912 " X: 536870912 - asdf - Xpath 1073741824 " X: 1073741824 -endif - -Xcheck 1874575085 - - -"------------------------------------------------------------------------------- -" Test 21: :finally for :try after :continue/:break/:return/:finish {{{1 -" -" If a :try conditional stays inactive due to a preceding :continue, -" :break, :return, or :finish, its :finally clause should not be -" executed. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - function F() - let loops = 2 - XloopINIT! 1 256 - while loops > 0 - XloopNEXT - let loops = loops - 1 - try - if loops == 1 - Xloop 1 " X: 1 - continue - Xloop 2 " X: 0 - elseif loops == 0 - Xloop 4 " X: 4*256 - break - Xloop 8 " X: 0 - endif - - try " inactive - Xloop 16 " X: 0 - finally - Xloop 32 " X: 0 - endtry - finally - Xloop 64 " X: 64 + 64*256 - endtry - Xloop 128 " X: 0 - endwhile - - try - Xpath 65536 " X: 65536 - return - Xpath 131072 " X: 0 - try " inactive - Xpath 262144 " X: 0 - finally - Xpath 524288 " X: 0 - endtry - finally - Xpath 1048576 " X: 1048576 - endtry - Xpath 2097152 " X: 0 - endfunction - - try - Xpath 4194304 " X: 4194304 - call F() - Xpath 8388608 " X: 8388608 - finish - Xpath 16777216 " X: 0 - try " inactive - Xpath 33554432 " X: 0 - finally - Xpath 67108864 " X: 0 - endtry - finally - Xpath 134217728 " X: 134217728 - endtry - Xpath 268435456 " X: 0 -endif - -Xcheck 147932225 - - -"------------------------------------------------------------------------------- -" Test 22: :finally for a :try after an error/interrupt/:throw {{{1 -" -" If a :try conditional stays inactive due to a preceding error or -" interrupt or :throw, its :finally clause should not be executed. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - function! Error() - try - asdf " aborting error, triggering error exception - endtry - endfunction - - Xpath 1 " X: 1 - call Error() - Xpath 2 " X: 0 - - if 1 " not active due to error - try " not active since :if inactive - Xpath 4 " X: 0 - finally - Xpath 8 " X: 0 - endtry - endif - - try " not active due to error - Xpath 16 " X: 0 - finally - Xpath 32 " X: 0 - endtry -endif - -if ExtraVim() - function! Interrupt() - try - "INTERRUPT " triggering interrupt exception - endtry - endfunction - - Xpath 64 " X: 64 - call Interrupt() - Xpath 128 " X: 0 - - if 1 " not active due to interrupt - try " not active since :if inactive - Xpath 256 " X: 0 - finally - Xpath 512 " X: 0 - endtry - endif - - try " not active due to interrupt - Xpath 1024 " X: 0 - finally - Xpath 2048 " X: 0 - endtry -endif - -if ExtraVim() - function! Throw() - throw "xyz" - endfunction - - Xpath 4096 " X: 4096 - call Throw() - Xpath 8192 " X: 0 - - if 1 " not active due to :throw - try " not active since :if inactive - Xpath 16384 " X: 0 - finally - Xpath 32768 " X: 0 - endtry - endif - - try " not active due to :throw - Xpath 65536 " X: 0 - finally - Xpath 131072 " X: 0 - endtry -endif - -Xcheck 4161 - - -"------------------------------------------------------------------------------- -" Test 23: :catch clauses for a :try after a :throw {{{1 -" -" If a :try conditional stays inactive due to a preceding :throw, -" none of its :catch clauses should be executed. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - try - Xpath 1 " X: 1 - throw "xyz" - Xpath 2 " X: 0 - - if 1 " not active due to :throw - try " not active since :if inactive - Xpath 4 " X: 0 - catch /xyz/ - Xpath 8 " X: 0 - endtry - endif - catch /xyz/ - Xpath 16 " X: 16 - endtry - - Xpath 32 " X: 32 - throw "abc" - Xpath 64 " X: 0 - - try " not active due to :throw - Xpath 128 " X: 0 - catch /abc/ - Xpath 256 " X: 0 - endtry -endif - -Xcheck 49 - - -"------------------------------------------------------------------------------- -" Test 24: :endtry for a :try after a :throw {{{1 -" -" If a :try conditional stays inactive due to a preceding :throw, -" its :endtry should not rethrow the exception to the next surrounding -" active :try conditional. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - try " try 1 - try " try 2 - Xpath 1 " X: 1 - throw "xyz" " makes try 2 inactive - Xpath 2 " X: 0 - - try " try 3 - Xpath 4 " X: 0 - endtry " no rethrow to try 1 - catch /xyz/ " should catch although try 2 inactive - Xpath 8 " X: 8 - endtry - catch /xyz/ " try 1 active, but exception already caught - Xpath 16 " X: 0 - endtry - Xpath 32 " X: 32 -endif - -Xcheck 41 - -" Tests 25 and 26 were moved to test_trycatch.vim -let Xtest = 27 - - -"------------------------------------------------------------------------------- -" Test 27: Executing :finally clauses after :return {{{1 -" -" For a :return command dynamically enclosed in a :try/:endtry region, -" :finally clauses are executed and the called function is ended. -"------------------------------------------------------------------------------- - -XpathINIT - -function! F() - try - Xpath 1 " X: 1 - try - Xpath 2 " X: 2 - return - Xpath 4 " X: 0 - finally - Xpath 8 " X: 8 - endtry - Xpath 16 " X: 0 - finally - Xpath 32 " X: 32 - endtry - Xpath 64 " X: 0 -endfunction - -function! G() - try - Xpath 128 " X: 128 - return - Xpath 256 " X: 0 - finally - Xpath 512 " X: 512 - call F() - Xpath 1024 " X: 1024 - endtry - Xpath 2048 " X: 0 -endfunction - -function! H() - try - Xpath 4096 " X: 4096 - call G() - Xpath 8192 " X: 8192 - finally - Xpath 16384 " X: 16384 - return - Xpath 32768 " X: 0 - endtry - Xpath 65536 " X: 0 -endfunction - -try - Xpath 131072 " X: 131072 - call H() - Xpath 262144 " X: 262144 -finally - Xpath 524288 " X: 524288 -endtry -Xpath 1048576 " X: 1048576 - -Xcheck 1996459 - -" Leave F, G, and H for execution as scripts in the next test. - - -"------------------------------------------------------------------------------- -" Test 28: Executing :finally clauses after :finish {{{1 -" -" For a :finish command dynamically enclosed in a :try/:endtry region, -" :finally clauses are executed and the sourced file is finished. -" -" This test executes the bodies of the functions F, G, and H from the -" previous test as script files (:return replaced by :finish). -"------------------------------------------------------------------------------- - -XpathINIT - -let scriptF = MakeScript("F") " X: 1 + 2 + 8 + 32 -let scriptG = MakeScript("G", scriptF) " X: 128 + 512 + 1024 -let scriptH = MakeScript("H", scriptG) " X: 4096 + 8192 + 16384 - -try - Xpath 131072 " X: 131072 - exec "source" scriptH - Xpath 262144 " X: 262144 -finally - Xpath 524288 " X: 524288 -endtry -Xpath 1048576 " X: 1048576 - -call delete(scriptF) -call delete(scriptG) -call delete(scriptH) -unlet scriptF scriptG scriptH -delfunction F -delfunction G -delfunction H - -Xcheck 1996459 - - -"------------------------------------------------------------------------------- -" Test 29: Executing :finally clauses on errors {{{1 -" -" After an error in a command dynamically enclosed in a :try/:endtry -" region, :finally clauses are executed and the script processing is -" terminated. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - function! F() - while 1 - try - Xpath 1 " X: 1 - while 1 - try - Xpath 2 " X: 2 - asdf " error - Xpath 4 " X: 0 - finally - Xpath 8 " X: 8 - endtry | Xpath 16 " X: 0 - Xpath 32 " X: 0 - break - endwhile - Xpath 64 " X: 0 - finally - Xpath 128 " X: 128 - endtry | Xpath 256 " X: 0 - Xpath 512 " X: 0 - break - endwhile - Xpath 1024 " X: 0 - endfunction - - while 1 - try - Xpath 2048 " X: 2048 - while 1 - call F() - Xpath 4096 " X: 0 - break - endwhile | Xpath 8192 " X: 0 - Xpath 16384 " X: 0 - finally - Xpath 32768 " X: 32768 - endtry | Xpath 65536 " X: 0 - endwhile | Xpath 131072 " X: 0 - Xpath 262144 " X: 0 -endif - -if ExtraVim() - function! G() abort - if 1 - try - Xpath 524288 " X: 524288 - asdf " error - Xpath 1048576 " X: 0 - finally - Xpath 2097152 " X: 2097152 - endtry | Xpath 4194304 " X: 0 - endif | Xpath 8388608 " X: 0 - Xpath 16777216 " X: 0 - endfunction - - if 1 - try - Xpath 33554432 " X: 33554432 - call G() - Xpath 67108864 " X: 0 - finally - Xpath 134217728 " X: 134217728 - endtry | Xpath 268435456 " X: 0 - endif | Xpath 536870912 " X: 0 - Xpath 1073741824 " X: 0 -endif - -Xcheck 170428555 - - -"------------------------------------------------------------------------------- -" Test 30: Executing :finally clauses on interrupt {{{1 -" -" After an interrupt in a command dynamically enclosed in -" a :try/:endtry region, :finally clauses are executed and the -" script processing is terminated. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - XloopINIT 1 16 - - function! F() - try - Xloop 1 " X: 1 + 1*16 - "INTERRUPT - Xloop 2 " X: 0 - finally - Xloop 4 " X: 4 + 4*16 - endtry - Xloop 8 " X: 0 - endfunction - - try - Xpath 256 " X: 256 - try - Xpath 512 " X: 512 - "INTERRUPT - Xpath 1024 " X: 0 - finally - Xpath 2048 " X: 2048 - try - Xpath 4096 " X: 4096 - try - Xpath 8192 " X: 8192 - finally - Xpath 16384 " X: 16384 - try - Xpath 32768 " X: 32768 - "INTERRUPT - Xpath 65536 " X: 0 - endtry - Xpath 131072 " X: 0 - endtry - Xpath 262144 " X: 0 - endtry - Xpath 524288 " X: 0 - endtry - Xpath 1048576 " X: 0 - finally - Xpath 2097152 " X: 2097152 - try - Xpath 4194304 " X: 4194304 - call F() - Xpath 8388608 " X: 0 - finally - Xpath 16777216 " X: 16777216 - try - Xpath 33554432 " X: 33554432 - XloopNEXT - ExecAsScript F - Xpath 67108864 " X: 0 - finally - Xpath 134217728 " X: 134217728 - endtry - Xpath 268435456 " X: 0 - endtry - Xpath 536870912 " X: 0 - endtry - Xpath 1073741824 " X: 0 -endif - -Xcheck 190905173 - - -"------------------------------------------------------------------------------- -" Test 31: Executing :finally clauses after :throw {{{1 -" -" After a :throw dynamically enclosed in a :try/:endtry region, -" :finally clauses are executed and the script processing is -" terminated. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - XloopINIT 1 16 - - function! F() - try - Xloop 1 " X: 1 + 1*16 - throw "exception" - Xloop 2 " X: 0 - finally - Xloop 4 " X: 4 + 4*16 - endtry - Xloop 8 " X: 0 - endfunction - - try - Xpath 256 " X: 256 - try - Xpath 512 " X: 512 - throw "exception" - Xpath 1024 " X: 0 - finally - Xpath 2048 " X: 2048 - try - Xpath 4096 " X: 4096 - try - Xpath 8192 " X: 8192 - finally - Xpath 16384 " X: 16384 - try - Xpath 32768 " X: 32768 - throw "exception" - Xpath 65536 " X: 0 - endtry - Xpath 131072 " X: 0 - endtry - Xpath 262144 " X: 0 - endtry - Xpath 524288 " X: 0 - endtry - Xpath 1048576 " X: 0 - finally - Xpath 2097152 " X: 2097152 - try - Xpath 4194304 " X: 4194304 - call F() - Xpath 8388608 " X: 0 - finally - Xpath 16777216 " X: 16777216 - try - Xpath 33554432 " X: 33554432 - XloopNEXT - ExecAsScript F - Xpath 67108864 " X: 0 - finally - Xpath 134217728 " X: 134217728 - endtry - Xpath 268435456 " X: 0 - endtry - Xpath 536870912 " X: 0 - endtry - Xpath 1073741824 " X: 0 -endif - -Xcheck 190905173 - -" Tests 32 and 33 were moved to test_trycatch.vim -let Xtest = 34 - - -"------------------------------------------------------------------------------- -" Test 34: :finally reason discarded by :continue {{{1 -" -" When a :finally clause is executed due to a :continue, :break, -" :return, :finish, error, interrupt or :throw, the jump reason is -" discarded by a :continue in the finally clause. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - - XloopINIT! 1 8 - - function! C(jump) - XloopNEXT - let loop = 0 - while loop < 2 - let loop = loop + 1 - if loop == 1 - try - if a:jump == "continue" - continue - elseif a:jump == "break" - break - elseif a:jump == "return" || a:jump == "finish" - return - elseif a:jump == "error" - asdf - elseif a:jump == "interrupt" - "INTERRUPT - let dummy = 0 - elseif a:jump == "throw" - throw "abc" - endif - finally - continue " discards jump that caused the :finally - Xloop 1 " X: 0 - endtry - Xloop 2 " X: 0 - elseif loop == 2 - Xloop 4 " X: 4*(1+8+64+512+4096+32768+262144) - endif - endwhile - endfunction - - call C("continue") - Xpath 2097152 " X: 2097152 - call C("break") - Xpath 4194304 " X: 4194304 - call C("return") - Xpath 8388608 " X: 8388608 - let g:jump = "finish" - ExecAsScript C - unlet g:jump - Xpath 16777216 " X: 16777216 - try - call C("error") - Xpath 33554432 " X: 33554432 - finally - Xpath 67108864 " X: 67108864 - try - call C("interrupt") - Xpath 134217728 " X: 134217728 - finally - Xpath 268435456 " X: 268435456 - call C("throw") - Xpath 536870912 " X: 536870912 - endtry - endtry - Xpath 1073741824 " X: 1073741824 - - delfunction C - -endif - -Xcheck 2146584868 - - -"------------------------------------------------------------------------------- -" Test 35: :finally reason discarded by :break {{{1 -" -" When a :finally clause is executed due to a :continue, :break, -" :return, :finish, error, interrupt or :throw, the jump reason is -" discarded by a :break in the finally clause. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - - XloopINIT! 1 8 - - function! B(jump) - XloopNEXT - let loop = 0 - while loop < 2 - let loop = loop + 1 - if loop == 1 - try - if a:jump == "continue" - continue - elseif a:jump == "break" - break - elseif a:jump == "return" || a:jump == "finish" - return - elseif a:jump == "error" - asdf - elseif a:jump == "interrupt" - "INTERRUPT - let dummy = 0 - elseif a:jump == "throw" - throw "abc" - endif - finally - break " discards jump that caused the :finally - Xloop 1 " X: 0 - endtry - elseif loop == 2 - Xloop 2 " X: 0 - endif - endwhile - Xloop 4 " X: 4*(1+8+64+512+4096+32768+262144) - endfunction - - call B("continue") - Xpath 2097152 " X: 2097152 - call B("break") - Xpath 4194304 " X: 4194304 - call B("return") - Xpath 8388608 " X: 8388608 - let g:jump = "finish" - ExecAsScript B - unlet g:jump - Xpath 16777216 " X: 16777216 - try - call B("error") - Xpath 33554432 " X: 33554432 - finally - Xpath 67108864 " X: 67108864 - try - call B("interrupt") - Xpath 134217728 " X: 134217728 - finally - Xpath 268435456 " X: 268435456 - call B("throw") - Xpath 536870912 " X: 536870912 - endtry - endtry - Xpath 1073741824 " X: 1073741824 - - delfunction B - -endif - -Xcheck 2146584868 - - -"------------------------------------------------------------------------------- -" Test 36: :finally reason discarded by :return {{{1 -" -" When a :finally clause is executed due to a :continue, :break, -" :return, :finish, error, interrupt or :throw, the jump reason is -" discarded by a :return in the finally clause. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - - XloopINIT! 1 8 - - function! R(jump, retval) abort - XloopNEXT - let loop = 0 - while loop < 2 - let loop = loop + 1 - if loop == 1 - try - if a:jump == "continue" - continue - elseif a:jump == "break" - break - elseif a:jump == "return" - return - elseif a:jump == "error" - asdf - elseif a:jump == "interrupt" - "INTERRUPT - let dummy = 0 - elseif a:jump == "throw" - throw "abc" - endif - finally - return a:retval " discards jump that caused the :finally - Xloop 1 " X: 0 - endtry - elseif loop == 2 - Xloop 2 " X: 0 - endif - endwhile - Xloop 4 " X: 0 - endfunction - - let sum = -R("continue", -8) - Xpath 2097152 " X: 2097152 - let sum = sum - R("break", -16) - Xpath 4194304 " X: 4194304 - let sum = sum - R("return", -32) - Xpath 8388608 " X: 8388608 - try - let sum = sum - R("error", -64) - Xpath 16777216 " X: 16777216 - finally - Xpath 33554432 " X: 33554432 - try - let sum = sum - R("interrupt", -128) - Xpath 67108864 " X: 67108864 - finally - Xpath 134217728 " X: 134217728 - let sum = sum - R("throw", -256) - Xpath 268435456 " X: 268435456 - endtry - endtry - Xpath 536870912 " X: 536870912 - - let expected = 8 + 16 + 32 + 64 + 128 + 256 - if sum != expected - Xpath 1073741824 " X: 0 - Xout "sum =" . sum . ", expected: " . expected - endif - - unlet sum expected - delfunction R - -endif - -Xcheck 1071644672 - - -"------------------------------------------------------------------------------- -" Test 37: :finally reason discarded by :finish {{{1 -" -" When a :finally clause is executed due to a :continue, :break, -" :return, :finish, error, interrupt or :throw, the jump reason is -" discarded by a :finish in the finally clause. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - - XloopINIT! 1 8 - - function! F(jump) " not executed as function, transformed to a script - XloopNEXT - let loop = 0 - while loop < 2 - let loop = loop + 1 - if loop == 1 - try - if a:jump == "continue" - continue - elseif a:jump == "break" - break - elseif a:jump == "finish" - finish - elseif a:jump == "error" - asdf - elseif a:jump == "interrupt" - "INTERRUPT - let dummy = 0 - elseif a:jump == "throw" - throw "abc" - endif - finally - finish " discards jump that caused the :finally - Xloop 1 " X: 0 - endtry - elseif loop == 2 - Xloop 2 " X: 0 - endif - endwhile - Xloop 4 " X: 0 - endfunction - - let scriptF = MakeScript("F") - delfunction F - - let g:jump = "continue" - exec "source" scriptF - Xpath 2097152 " X: 2097152 - let g:jump = "break" - exec "source" scriptF - Xpath 4194304 " X: 4194304 - let g:jump = "finish" - exec "source" scriptF - Xpath 8388608 " X: 8388608 - try - let g:jump = "error" - exec "source" scriptF - Xpath 16777216 " X: 16777216 - finally - Xpath 33554432 " X: 33554432 - try - let g:jump = "interrupt" - exec "source" scriptF - Xpath 67108864 " X: 67108864 - finally - Xpath 134217728 " X: 134217728 - try - let g:jump = "throw" - exec "source" scriptF - Xpath 268435456 " X: 268435456 - finally - Xpath 536870912 " X: 536870912 - endtry - endtry - endtry - unlet g:jump - - call delete(scriptF) - unlet scriptF - -endif - -Xcheck 1071644672 - - -"------------------------------------------------------------------------------- -" Test 38: :finally reason discarded by an error {{{1 -" -" When a :finally clause is executed due to a :continue, :break, -" :return, :finish, error, interrupt or :throw, the jump reason is -" discarded by an error in the finally clause. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - - XloopINIT! 1 4 - - function! E(jump) - XloopNEXT - let loop = 0 - while loop < 2 - let loop = loop + 1 - if loop == 1 - try - if a:jump == "continue" - continue - elseif a:jump == "break" - break - elseif a:jump == "return" || a:jump == "finish" - return - elseif a:jump == "error" - asdf - elseif a:jump == "interrupt" - "INTERRUPT - let dummy = 0 - elseif a:jump == "throw" - throw "abc" - endif - finally - asdf " error; discards jump that caused the :finally - endtry - elseif loop == 2 - Xloop 1 " X: 0 - endif - endwhile - Xloop 2 " X: 0 - endfunction - - try - Xpath 16384 " X: 16384 - call E("continue") - Xpath 32768 " X: 0 - finally - try - Xpath 65536 " X: 65536 - call E("break") - Xpath 131072 " X: 0 - finally - try - Xpath 262144 " X: 262144 - call E("return") - Xpath 524288 " X: 0 - finally - try - Xpath 1048576 " X: 1048576 - let g:jump = "finish" - ExecAsScript E - Xpath 2097152 " X: 0 - finally - unlet g:jump - try - Xpath 4194304 " X: 4194304 - call E("error") - Xpath 8388608 " X: 0 - finally - try - Xpath 16777216 " X: 16777216 - call E("interrupt") - Xpath 33554432 " X: 0 - finally - try - Xpath 67108864 " X: 67108864 - call E("throw") - Xpath 134217728 " X: 0 - finally - Xpath 268435456 " X: 268435456 - delfunction E - endtry - endtry - endtry - endtry - endtry - endtry - endtry - Xpath 536870912 " X: 0 - -endif - -Xcheck 357908480 - - -"------------------------------------------------------------------------------- -" Test 39: :finally reason discarded by an interrupt {{{1 -" -" When a :finally clause is executed due to a :continue, :break, -" :return, :finish, error, interrupt or :throw, the jump reason is -" discarded by an interrupt in the finally clause. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - - XloopINIT! 1 4 - - function! I(jump) - XloopNEXT - let loop = 0 - while loop < 2 - let loop = loop + 1 - if loop == 1 - try - if a:jump == "continue" - continue - elseif a:jump == "break" - break - elseif a:jump == "return" || a:jump == "finish" - return - elseif a:jump == "error" - asdf - elseif a:jump == "interrupt" - "INTERRUPT - let dummy = 0 - elseif a:jump == "throw" - throw "abc" - endif - finally - "INTERRUPT - discards jump that caused the :finally - let dummy = 0 - endtry - elseif loop == 2 - Xloop 1 " X: 0 - endif - endwhile - Xloop 2 " X: 0 - endfunction - - try - Xpath 16384 " X: 16384 - call I("continue") - Xpath 32768 " X: 0 - finally - try - Xpath 65536 " X: 65536 - call I("break") - Xpath 131072 " X: 0 - finally - try - Xpath 262144 " X: 262144 - call I("return") - Xpath 524288 " X: 0 - finally - try - Xpath 1048576 " X: 1048576 - let g:jump = "finish" - ExecAsScript I - Xpath 2097152 " X: 0 - finally - unlet g:jump - try - Xpath 4194304 " X: 4194304 - call I("error") - Xpath 8388608 " X: 0 - finally - try - Xpath 16777216 " X: 16777216 - call I("interrupt") - Xpath 33554432 " X: 0 - finally - try - Xpath 67108864 " X: 67108864 - call I("throw") - Xpath 134217728 " X: 0 - finally - Xpath 268435456 " X: 268435456 - delfunction I - endtry - endtry - endtry - endtry - endtry - endtry - endtry - Xpath 536870912 " X: 0 - -endif - -Xcheck 357908480 - - -"------------------------------------------------------------------------------- -" Test 40: :finally reason discarded by :throw {{{1 -" -" When a :finally clause is executed due to a :continue, :break, -" :return, :finish, error, interrupt or :throw, the jump reason is -" discarded by a :throw in the finally clause. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - - XloopINIT! 1 4 - - function! T(jump) - XloopNEXT - let loop = 0 - while loop < 2 - let loop = loop + 1 - if loop == 1 - try - if a:jump == "continue" - continue - elseif a:jump == "break" - break - elseif a:jump == "return" || a:jump == "finish" - return - elseif a:jump == "error" - asdf - elseif a:jump == "interrupt" - "INTERRUPT - let dummy = 0 - elseif a:jump == "throw" - throw "abc" - endif - finally - throw "xyz" " discards jump that caused the :finally - endtry - elseif loop == 2 - Xloop 1 " X: 0 - endif - endwhile - Xloop 2 " X: 0 - endfunction - - try - Xpath 16384 " X: 16384 - call T("continue") - Xpath 32768 " X: 0 - finally - try - Xpath 65536 " X: 65536 - call T("break") - Xpath 131072 " X: 0 - finally - try - Xpath 262144 " X: 262144 - call T("return") - Xpath 524288 " X: 0 - finally - try - Xpath 1048576 " X: 1048576 - let g:jump = "finish" - ExecAsScript T - Xpath 2097152 " X: 0 - finally - unlet g:jump - try - Xpath 4194304 " X: 4194304 - call T("error") - Xpath 8388608 " X: 0 - finally - try - Xpath 16777216 " X: 16777216 - call T("interrupt") - Xpath 33554432 " X: 0 - finally - try - Xpath 67108864 " X: 67108864 - call T("throw") - Xpath 134217728 " X: 0 - finally - Xpath 268435456 " X: 268435456 - delfunction T - endtry - endtry - endtry - endtry - endtry - endtry - endtry - Xpath 536870912 " X: 0 - -endif - -Xcheck 357908480 - -" Tests 41 to 48 were moved to test_trycatch.vim -let Xtest = 49 - - -"------------------------------------------------------------------------------- -" Test 49: Throwing exceptions across functions {{{1 -" -" When an exception is thrown but not caught inside a function, the -" caller is checked for a matching :catch clause. -"------------------------------------------------------------------------------- - -XpathINIT - -function! C() - try - Xpath 1 " X: 1 - throw "arrgh" - Xpath 2 " X: 0 - catch /arrgh/ - Xpath 4 " X: 4 - endtry - Xpath 8 " X: 8 -endfunction - -XloopINIT! 16 16 - -function! T1() - XloopNEXT - try - Xloop 1 " X: 16 + 16*16 - throw "arrgh" - Xloop 2 " X: 0 - finally - Xloop 4 " X: 64 + 64*16 - endtry - Xloop 8 " X: 0 -endfunction - -function! T2() - try - Xpath 4096 " X: 4096 - call T1() - Xpath 8192 " X: 0 - finally - Xpath 16384 " X: 16384 - endtry - Xpath 32768 " X: 0 -endfunction - -try - Xpath 65536 " X: 65536 - call C() " throw and catch - Xpath 131072 " X: 131072 -catch /.*/ - Xpath 262144 " X: 0 - Xout v:exception "in" v:throwpoint -endtry - -try - Xpath 524288 " X: 524288 - call T1() " throw, one level - Xpath 1048576 " X: 0 -catch /arrgh/ - Xpath 2097152 " X: 2097152 -catch /.*/ - Xpath 4194304 " X: 0 - Xout v:exception "in" v:throwpoint -endtry - -try - Xpath 8388608 " X: 8388608 - call T2() " throw, two levels - Xpath 16777216 " X: 0 -catch /arrgh/ - Xpath 33554432 " X: 33554432 -catch /.*/ - Xpath 67108864 " X: 0 - Xout v:exception "in" v:throwpoint -endtry -Xpath 134217728 " X: 134217728 - -Xcheck 179000669 - -" Leave C, T1, and T2 for execution as scripts in the next test. - - -"------------------------------------------------------------------------------- -" Test 50: Throwing exceptions across script files {{{1 -" -" When an exception is thrown but not caught inside a script file, -" the sourcing script or function is checked for a matching :catch -" clause. -" -" This test executes the bodies of the functions C, T1, and T2 from -" the previous test as script files (:return replaced by :finish). -"------------------------------------------------------------------------------- - -XpathINIT - -let scriptC = MakeScript("C") " X: 1 + 4 + 8 -delfunction C - -XloopINIT! 16 16 - -let scriptT1 = MakeScript("T1") " X: 16 + 64 + 16*16 + 64*16 -delfunction T1 - -let scriptT2 = MakeScript("T2", scriptT1) " X: 4096 + 16384 -delfunction T2 - -function! F() - try - Xpath 65536 " X: 65536 - exec "source" g:scriptC - Xpath 131072 " X: 131072 - catch /.*/ - Xpath 262144 " X: 0 - Xout v:exception "in" v:throwpoint - endtry - - try - Xpath 524288 " X: 524288 - exec "source" g:scriptT1 - Xpath 1048576 " X: 0 - catch /arrgh/ - Xpath 2097152 " X: 2097152 - catch /.*/ - Xpath 4194304 " X: 0 - Xout v:exception "in" v:throwpoint - endtry -endfunction - -try - Xpath 8388608 " X: 8388608 - call F() - Xpath 16777216 " X: 16777216 - exec "source" scriptT2 - Xpath 33554432 " X: 0 -catch /arrgh/ - Xpath 67108864 " X: 67108864 -catch /.*/ - Xpath 134217728 " X: 0 - Xout v:exception "in" v:throwpoint -endtry -Xpath 268435456 " X: 268435456 - -call delete(scriptC) -call delete(scriptT1) -call delete(scriptT2) -unlet scriptC scriptT1 scriptT2 -delfunction F - -Xcheck 363550045 - -" Test 51 was moved to test_trycatch.vim +" Tests 1 to 50, 87 were moved to test_vimscript.vim +" Tests 25, 26, 32, 33, 41-48, 51, 69-75 were moved to test_trycatch.vim let Xtest = 52 - "------------------------------------------------------------------------------- " Test 52: Uncaught exceptions {{{1 " diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index a7ab78d87a..d49681974e 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -3,14 +3,12 @@ source check.vim source shared.vim +source script_util.vim "------------------------------------------------------------------------------- " Test environment {{{1 "------------------------------------------------------------------------------- -com! XpathINIT let g:Xpath = '' -com! -nargs=1 -bar Xpath let g:Xpath = g:Xpath . - " Append a message to the "messages" file func Xout(text) split messages @@ -20,67 +18,30 @@ endfunc com! -nargs=1 Xout call Xout() -" MakeScript() - Make a script file from a function. {{{2 -" -" Create a script that consists of the body of the function a:funcname. -" Replace any ":return" by a ":finish", any argument variable by a global -" variable, and every ":call" by a ":source" for the next following argument -" in the variable argument list. This function is useful if similar tests are -" to be made for a ":return" from a function call or a ":finish" in a script -" file. -func MakeScript(funcname, ...) - let script = tempname() - execute "redir! >" . script - execute "function" a:funcname - redir END - execute "edit" script - " Delete the "function" and the "endfunction" lines. Do not include the - " word "function" in the pattern since it might be translated if LANG is - " set. When MakeScript() is being debugged, this deletes also the debugging - " output of its line 3 and 4. - exec '1,/.*' . a:funcname . '(.*)/d' - /^\d*\s*endfunction\>/,$d - %s/^\d*//e - %s/return/finish/e - %s/\ 0 - let cnt = cnt + 1 - s/\) - - "------------------------------------------------------------------------------- " Test 1: :endwhile in function {{{1 " @@ -90,7 +51,7 @@ com! -nargs=1 -bar ExecAsScript call ExecAsScript() " tests will hang. "------------------------------------------------------------------------------- -function! T1_F() +func T1_F() Xpath 'a' let first = 1 while 1 @@ -104,9 +65,9 @@ function! T1_F() return endif endwhile -endfunction +endfunc -function! T1_G() +func T1_G() Xpath 'h' let first = 1 while 1 @@ -121,7 +82,7 @@ function! T1_G() endif if 1 " unmatched :if endwhile -endfunction +endfunc func Test_endwhile_function() XpathINIT @@ -175,7 +136,7 @@ endfunc " Test 3: :if, :elseif, :while, :continue, :break {{{1 "------------------------------------------------------------------------------- -function Test_if_while() +func Test_if_while() XpathINIT if 1 Xpath 'a' @@ -235,7 +196,7 @@ endfunc " Test 4: :return {{{1 "------------------------------------------------------------------------------- -function! T4_F() +func T4_F() if 1 Xpath 'a' let loops = 3 @@ -253,15 +214,15 @@ function! T4_F() else Xpath 'g' endif -endfunction +endfunc -function Test_return() +func Test_return() XpathINIT call T4_F() Xpath '4' call assert_equal('ab3e3b2c24', g:Xpath) -endfunction +endfunc "------------------------------------------------------------------------------- @@ -271,14 +232,14 @@ endfunction " test as a script file (:return replaced by :finish). "------------------------------------------------------------------------------- -function Test_finish() +func Test_finish() XpathINIT ExecAsScript T4_F Xpath '5' call DeleteTheScript() call assert_equal('ab3e3b2c25', g:Xpath) -endfunction +endfunc @@ -412,7 +373,7 @@ delfunction G31 delfunction G32 delfunction G33 -function Test_defining_functions() +func Test_defining_functions() call assert_equal('ade2ie3ibcg0h1g1h2g2h3fg0h1g1h2g2h3m', g:test6_result) call assert_equal('F1G1F2G21G22G23F3G31G32G33', g:test6_calls) endfunc @@ -476,7 +437,7 @@ endfunc XpathINIT -function! T8_F() +func T8_F() if 1 Xpath 'a' while 1 @@ -508,9 +469,9 @@ function! T8_F() return novar " returns (default return value 0) Xpath 'q' return 1 " not reached -endfunction +endfunc -function! T8_G() abort +func T8_G() abort if 1 Xpath 'r' while 1 @@ -524,9 +485,9 @@ function! T8_G() abort Xpath 'x' return -4 " not reached -endfunction +endfunc -function! T8_H() abort +func T8_H() abort while 1 Xpath 'A' if 1 @@ -540,7 +501,7 @@ function! T8_H() abort Xpath 'F' return -4 " not reached -endfunction +endfunc " Aborted functions (T8_G and T8_H) return -1. let g:test8_sum = (T8_F() + 1) - 4 * T8_G() - 8 * T8_H() @@ -567,7 +528,7 @@ endfunc XpathINIT -function! F() abort +func F() abort Xpath 'a' let result = G() " not aborted Xpath 'b' @@ -575,30 +536,30 @@ function! F() abort Xpath 'c' endif return 1 -endfunction +endfunc -function! G() " no abort attribute +func G() " no abort attribute Xpath 'd' if H() != -1 " aborted Xpath 'e' endif Xpath 'f' return 2 -endfunction +endfunc -function! H() abort +func H() abort Xpath 'g' call I() " aborted Xpath 'h' return 4 -endfunction +endfunc -function! I() abort +func I() abort Xpath 'i' asdf " error Xpath 'j' return 8 -endfunction +endfunc if F() != 1 Xpath 'k' @@ -626,7 +587,7 @@ endfunc XpathINIT -function! MSG(enr, emsg) +func MSG(enr, emsg) let english = v:lang == "C" || v:lang =~ '^[Ee]n' if a:enr == "" Xout "TODO: Add message number for:" a:emsg @@ -710,10 +671,10 @@ XpathINIT let calls = 0 -function! P(num) +func P(num) let g:calls = g:calls + a:num " side effect on call return 0 -endfunction +endfunc if 1 Xpath 'a' @@ -1092,7 +1053,1716 @@ func Test_unmatched_if_in_while() endfunc "------------------------------------------------------------------------------- +" Test 18: Interrupt (Ctrl-C pressed) {{{1 +" +" On an interrupt, the script processing is terminated immediately. +"------------------------------------------------------------------------------- + +func Test_interrupt_while_if() + let test =<< trim [CODE] + try + if 1 + Xpath 'a' + while 1 + Xpath 'b' + if 1 + Xpath 'c' + call interrupt() + call assert_report('should not get here') + break + finish + endif | call assert_report('should not get here') + call assert_report('should not get here') + endwhile | call assert_report('should not get here') + call assert_report('should not get here') + endif | call assert_report('should not get here') + call assert_report('should not get here') + catch /^Vim:Interrupt$/ + Xpath 'd' + endtry | Xpath 'e' + Xpath 'f' + [CODE] + let verify =<< trim [CODE] + call assert_equal('abcdef', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_interrupt_try() + let test =<< trim [CODE] + try + try + Xpath 'a' + call interrupt() + call assert_report('should not get here') + endtry | call assert_report('should not get here') + call assert_report('should not get here') + catch /^Vim:Interrupt$/ + Xpath 'b' + endtry | Xpath 'c' + Xpath 'd' + [CODE] + let verify =<< trim [CODE] + call assert_equal('abcd', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_interrupt_func_while_if() + let test =<< trim [CODE] + func F() + if 1 + Xpath 'a' + while 1 + Xpath 'b' + if 1 + Xpath 'c' + call interrupt() + call assert_report('should not get here') + break + return + endif | call assert_report('should not get here') + call assert_report('should not get here') + endwhile | call assert_report('should not get here') + call assert_report('should not get here') + endif | call assert_report('should not get here') + call assert_report('should not get here') + endfunc + + Xpath 'd' + try + call F() | call assert_report('should not get here') + catch /^Vim:Interrupt$/ + Xpath 'e' + endtry | Xpath 'f' + Xpath 'g' + [CODE] + let verify =<< trim [CODE] + call assert_equal('dabcefg', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_interrupt_func_try() + let test =<< trim [CODE] + func G() + try + Xpath 'a' + call interrupt() + call assert_report('should not get here') + endtry | call assert_report('should not get here') + call assert_report('should not get here') + endfunc + + Xpath 'b' + try + call G() | call assert_report('should not get here') + catch /^Vim:Interrupt$/ + Xpath 'c' + endtry | Xpath 'd' + Xpath 'e' + [CODE] + let verify =<< trim [CODE] + call assert_equal('bacde', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 19: Aborting on errors inside :try/:endtry {{{1 +" +" An error in a command dynamically enclosed in a :try/:endtry region +" aborts script processing immediately. It does not matter whether +" the failing command is outside or inside a function and whether a +" function has an "abort" attribute. +"------------------------------------------------------------------------------- + +func Test_try_error_abort_1() + let test =<< trim [CODE] + func F() abort + Xpath 'a' + asdf + call assert_report('should not get here') + endfunc + + try + Xpath 'b' + call F() + call assert_report('should not get here') + endtry | call assert_report('should not get here') + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('ba', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_try_error_abort_2() + let test =<< trim [CODE] + func G() + Xpath 'a' + asdf + call assert_report('should not get here') + endfunc + + try + Xpath 'b' + call G() + call assert_report('should not get here') + endtry | call assert_report('should not get here') + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('ba', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_try_error_abort_3() + let test =<< trim [CODE] + try + Xpath 'a' + asdf + call assert_report('should not get here') + endtry | call assert_report('should not get here') + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('a', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_try_error_abort_4() + let test =<< trim [CODE] + if 1 + try + Xpath 'a' + asdf + call assert_report('should not get here') + endtry | call assert_report('should not get here') + endif | call assert_report('should not get here') + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('a', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_try_error_abort_5() + let test =<< trim [CODE] + let p = 1 + while p + let p = 0 + try + Xpath 'a' + asdf + call assert_report('should not get here') + endtry | call assert_report('should not get here') + endwhile | call assert_report('should not get here') + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('a', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_try_error_abort_6() + let test =<< trim [CODE] + let p = 1 + Xpath 'a' + while p + Xpath 'b' + let p = 0 + try + Xpath 'c' + endwhile | call assert_report('should not get here') + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('abc', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 20: Aborting on errors after :try/:endtry {{{1 +" +" When an error occurs after the last active :try/:endtry region has +" been left, termination behavior is as if no :try/:endtry has been +" seen. +"------------------------------------------------------------------------------- + +func Test_error_after_try_1() + let test =<< trim [CODE] + let p = 1 + while p + let p = 0 + Xpath 'a' + try + Xpath 'b' + endtry + asdf + call assert_report('should not get here') + endwhile | call assert_report('should not get here') + Xpath 'c' + [CODE] + let verify =<< trim [CODE] + call assert_equal('abc', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_error_after_try_2() + let test =<< trim [CODE] + while 1 + try + Xpath 'a' + break + call assert_report('should not get here') + endtry + endwhile + Xpath 'b' + asdf + Xpath 'c' + [CODE] + let verify =<< trim [CODE] + call assert_equal('abc', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_error_after_try_3() + let test =<< trim [CODE] + while 1 + try + Xpath 'a' + break + call assert_report('should not get here') + finally + Xpath 'b' + endtry + endwhile + Xpath 'c' + asdf + Xpath 'd' + [CODE] + let verify =<< trim [CODE] + call assert_equal('abcd', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_error_after_try_4() + let test =<< trim [CODE] + while 1 + try + Xpath 'a' + finally + Xpath 'b' + break + call assert_report('should not get here') + endtry + endwhile + Xpath 'c' + asdf + Xpath 'd' + [CODE] + let verify =<< trim [CODE] + call assert_equal('abcd', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_error_after_try_5() + let test =<< trim [CODE] + let p = 1 + while p + let p = 0 + try + Xpath 'a' + continue + call assert_report('should not get here') + endtry + endwhile + Xpath 'b' + asdf + Xpath 'c' + [CODE] + let verify =<< trim [CODE] + call assert_equal('abc', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_error_after_try_6() + let test =<< trim [CODE] + let p = 1 + while p + let p = 0 + try + Xpath 'a' + continue + call assert_report('should not get here') + finally + Xpath 'b' + endtry + endwhile + Xpath 'c' + asdf + Xpath 'd' + [CODE] + let verify =<< trim [CODE] + call assert_equal('abcd', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_error_after_try_7() + let test =<< trim [CODE] + let p = 1 + while p + let p = 0 + try + Xpath 'a' + finally + Xpath 'b' + continue + call assert_report('should not get here') + endtry + endwhile + Xpath 'c' + asdf + Xpath 'd' + [CODE] + let verify =<< trim [CODE] + call assert_equal('abcd', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 21: :finally for :try after :continue/:break/:return/:finish {{{1 +" +" If a :try conditional stays inactive due to a preceding :continue, +" :break, :return, or :finish, its :finally clause should not be +" executed. +"------------------------------------------------------------------------------- + +func Test_finally_after_loop_ctrl_statement() + let test =<< trim [CODE] + func F() + let loops = 2 + while loops > 0 + XloopNEXT + let loops = loops - 1 + try + if loops == 1 + Xloop 'a' + continue + call assert_report('should not get here') + elseif loops == 0 + Xloop 'b' + break + call assert_report('should not get here') + endif + + try " inactive + call assert_report('should not get here') + finally + call assert_report('should not get here') + endtry + finally + Xloop 'c' + endtry + call assert_report('should not get here') + endwhile + + try + Xpath 'd' + return + call assert_report('should not get here') + try " inactive + call assert_report('should not get here') + finally + call assert_report('should not get here') + endtry + finally + Xpath 'e' + endtry + call assert_report('should not get here') + endfunc + + try + Xpath 'f' + call F() + Xpath 'g' + finish + call assert_report('should not get here') + try " inactive + call assert_report('should not get here') + finally + call assert_report('should not get here') + endtry + finally + Xpath 'h' + endtry + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('fa2c2b3c3degh', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 22: :finally for a :try after an error/interrupt/:throw {{{1 +" +" If a :try conditional stays inactive due to a preceding error or +" interrupt or :throw, its :finally clause should not be executed. +"------------------------------------------------------------------------------- + +func Test_finally_after_error_in_func() + let test =<< trim [CODE] + func Error() + try + Xpath 'b' + asdf " aborting error, triggering error exception + call assert_report('should not get here') + endtry + call assert_report('should not get here') + endfunc + + Xpath 'a' + call Error() + call assert_report('should not get here') + + if 1 " not active due to error + try " not active since :if inactive + call assert_report('should not get here') + finally + call assert_report('should not get here') + endtry + endif + + try " not active due to error + call assert_report('should not get here') + finally + call assert_report('should not get here') + endtry + [CODE] + let verify =<< trim [CODE] + call assert_equal('ab', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_finally_after_interrupt() + let test =<< trim [CODE] + func Interrupt() + try + Xpath 'a' + call interrupt() " triggering interrupt exception + call assert_report('should not get here') + endtry + endfunc + + Xpath 'b' + try + call Interrupt() + catch /^Vim:Interrupt$/ + Xpath 'c' + finish + endtry + call assert_report('should not get here') + + if 1 " not active due to interrupt + try " not active since :if inactive + call assert_report('should not get here') + finally + call assert_report('should not get here') + endtry + endif + + try " not active due to interrupt + call assert_report('should not get here') + finally + call assert_report('should not get here') + endtry + [CODE] + let verify =<< trim [CODE] + call assert_equal('bac', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_finally_after_throw() + let test =<< trim [CODE] + func Throw() + Xpath 'a' + throw 'xyz' + endfunc + + Xpath 'b' + call Throw() + call assert_report('should not get here') + + if 1 " not active due to :throw + try " not active since :if inactive + call assert_report('should not get here') + finally + call assert_report('should not get here') + endtry + endif + + try " not active due to :throw + call assert_report('should not get here') + finally + call assert_report('should not get here') + endtry + [CODE] + let verify =<< trim [CODE] + call assert_equal('ba', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 23: :catch clauses for a :try after a :throw {{{1 +" +" If a :try conditional stays inactive due to a preceding :throw, +" none of its :catch clauses should be executed. +"------------------------------------------------------------------------------- + +func Test_catch_after_throw() + let test =<< trim [CODE] + try + Xpath 'a' + throw "xyz" + call assert_report('should not get here') + + if 1 " not active due to :throw + try " not active since :if inactive + call assert_report('should not get here') + catch /xyz/ + call assert_report('should not get here') + endtry + endif + catch /xyz/ + Xpath 'b' + endtry + + Xpath 'c' + throw "abc" + call assert_report('should not get here') + + try " not active due to :throw + call assert_report('should not get here') + catch /abc/ + call assert_report('should not get here') + endtry + [CODE] + let verify =<< trim [CODE] + call assert_equal('abc', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 24: :endtry for a :try after a :throw {{{1 +" +" If a :try conditional stays inactive due to a preceding :throw, +" its :endtry should not rethrow the exception to the next surrounding +" active :try conditional. "------------------------------------------------------------------------------- + +func Test_endtry_after_throw() + let test =<< trim [CODE] + try " try 1 + try " try 2 + Xpath 'a' + throw "xyz" " makes try 2 inactive + call assert_report('should not get here') + + try " try 3 + call assert_report('should not get here') + endtry " no rethrow to try 1 + catch /xyz/ " should catch although try 2 inactive + Xpath 'b' + endtry + catch /xyz/ " try 1 active, but exception already caught + call assert_report('should not get here') + endtry + Xpath 'c' + [CODE] + let verify =<< trim [CODE] + call assert_equal('abc', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 27: Executing :finally clauses after :return {{{1 +" +" For a :return command dynamically enclosed in a :try/:endtry region, +" :finally clauses are executed and the called function is ended. +"------------------------------------------------------------------------------- + +func T27_F() + try + Xpath 'a' + try + Xpath 'b' + return + call assert_report('should not get here') + finally + Xpath 'c' + endtry + Xpath 'd' + finally + Xpath 'e' + endtry + call assert_report('should not get here') +endfunc + +func T27_G() + try + Xpath 'f' + return + call assert_report('should not get here') + finally + Xpath 'g' + call T27_F() + Xpath 'h' + endtry + call assert_report('should not get here') +endfunc + +func T27_H() + try + Xpath 'i' + call T27_G() + Xpath 'j' + finally + Xpath 'k' + return + call assert_report('should not get here') + endtry + call assert_report('should not get here') +endfunction + +func Test_finally_after_return() + XpathINIT + try + Xpath 'l' + call T27_H() + Xpath 'm' + finally + Xpath 'n' + endtry + call assert_equal('lifgabcehjkmn', g:Xpath) +endfunc + +"------------------------------------------------------------------------------- +" Test 28: Executing :finally clauses after :finish {{{1 +" +" For a :finish command dynamically enclosed in a :try/:endtry region, +" :finally clauses are executed and the sourced file is finished. +" +" This test executes the bodies of the functions F, G, and H from the +" previous test as script files (:return replaced by :finish). +"------------------------------------------------------------------------------- + +func Test_finally_after_finish() + XpathINIT + + let scriptF = MakeScript("T27_F") + let scriptG = MakeScript("T27_G", scriptF) + let scriptH = MakeScript("T27_H", scriptG) + + try + Xpath 'A' + exec "source" scriptH + Xpath 'B' + finally + Xpath 'C' + endtry + Xpath 'D' + call assert_equal('AifgabcehjkBCD', g:Xpath) + call delete(scriptF) + call delete(scriptG) + call delete(scriptH) +endfunc + +"------------------------------------------------------------------------------- +" Test 29: Executing :finally clauses on errors {{{1 +" +" After an error in a command dynamically enclosed in a :try/:endtry +" region, :finally clauses are executed and the script processing is +" terminated. +"------------------------------------------------------------------------------- + +func Test_finally_after_error_1() + let test =<< trim [CODE] + func F() + while 1 + try + Xpath 'a' + while 1 + try + Xpath 'b' + asdf " error + call assert_report('should not get here') + finally + Xpath 'c' + endtry | call assert_report('should not get here') + call assert_report('should not get here') + break + endwhile + call assert_report('should not get here') + finally + Xpath 'd' + endtry | call assert_report('should not get here') + call assert_report('should not get here') + break + endwhile + call assert_report('should not get here') + endfunc + + while 1 + try + Xpath 'e' + while 1 + call F() + call assert_report('should not get here') + break + endwhile | call assert_report('should not get here') + call assert_report('should not get here') + finally + Xpath 'f' + endtry | call assert_report('should not get here') + endwhile | call assert_report('should not get here') + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('eabcdf', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_finally_after_error_2() + let test =<< trim [CODE] + func G() abort + if 1 + try + Xpath 'a' + asdf " error + call assert_report('should not get here') + finally + Xpath 'b' + endtry | Xpath 'c' + endif | Xpath 'd' + call assert_report('should not get here') + endfunc + + if 1 + try + Xpath 'e' + call G() + call assert_report('should not get here') + finally + Xpath 'f' + endtry | call assert_report('should not get here') + endif | call assert_report('should not get here') + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('eabf', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 30: Executing :finally clauses on interrupt {{{1 +" +" After an interrupt in a command dynamically enclosed in +" a :try/:endtry region, :finally clauses are executed and the +" script processing is terminated. +"------------------------------------------------------------------------------- + +func Test_finally_on_interrupt() + let test =<< trim [CODE] + func F() + try + Xloop 'a' + call interrupt() + call assert_report('should not get here') + finally + Xloop 'b' + endtry + call assert_report('should not get here') + endfunc + + try + try + Xpath 'c' + try + Xpath 'd' + call interrupt() + call assert_report('should not get here') + finally + Xpath 'e' + try + Xpath 'f' + try + Xpath 'g' + finally + Xpath 'h' + try + Xpath 'i' + call interrupt() + call assert_report('should not get here') + endtry + call assert_report('should not get here') + endtry + call assert_report('should not get here') + endtry + call assert_report('should not get here') + endtry + call assert_report('should not get here') + finally + Xpath 'j' + try + Xpath 'k' + call F() + call assert_report('should not get here') + finally + Xpath 'l' + try + Xpath 'm' + XloopNEXT + ExecAsScript F + call assert_report('should not get here') + finally + Xpath 'n' + endtry + call assert_report('should not get here') + endtry + call assert_report('should not get here') + endtry + call assert_report('should not get here') + catch /^Vim:Interrupt$/ + Xpath 'o' + endtry + [CODE] + let verify =<< trim [CODE] + call assert_equal('cdefghijka1b1lma2b2no', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 31: Executing :finally clauses after :throw {{{1 +" +" After a :throw dynamically enclosed in a :try/:endtry region, +" :finally clauses are executed and the script processing is +" terminated. +"------------------------------------------------------------------------------- + +func Test_finally_after_throw_2() + let test =<< trim [CODE] + func F() + try + Xloop 'a' + throw "exception" + call assert_report('should not get here') + finally + Xloop 'b' + endtry + call assert_report('should not get here') + endfunc + + try + Xpath 'c' + try + Xpath 'd' + throw "exception" + call assert_report('should not get here') + finally + Xpath 'e' + try + Xpath 'f' + try + Xpath 'g' + finally + Xpath 'h' + try + Xpath 'i' + throw "exception" + call assert_report('should not get here') + endtry + call assert_report('should not get here') + endtry + call assert_report('should not get here') + endtry + call assert_report('should not get here') + endtry + call assert_report('should not get here') + finally + Xpath 'j' + try + Xpath 'k' + call F() + call assert_report('should not get here') + finally + Xpath 'l' + try + Xpath 'm' + XloopNEXT + ExecAsScript F + call assert_report('should not get here') + finally + Xpath 'n' + endtry + call assert_report('should not get here') + endtry + call assert_report('should not get here') + endtry + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('cdefghijka1b1lma2b2n', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 34: :finally reason discarded by :continue {{{1 +" +" When a :finally clause is executed due to a :continue, :break, +" :return, :finish, error, interrupt or :throw, the jump reason is +" discarded by a :continue in the finally clause. +"------------------------------------------------------------------------------- + +func Test_finally_after_continue() + let test =<< trim [CODE] + func C(jump) + XloopNEXT + let loop = 0 + while loop < 2 + let loop = loop + 1 + if loop == 1 + try + if a:jump == "continue" + continue + elseif a:jump == "break" + break + elseif a:jump == "return" || a:jump == "finish" + return + elseif a:jump == "error" + asdf + elseif a:jump == "interrupt" + call interrupt() + let dummy = 0 + elseif a:jump == "throw" + throw "abc" + endif + finally + continue " discards jump that caused the :finally + call assert_report('should not get here') + endtry + call assert_report('should not get here') + elseif loop == 2 + Xloop 'a' + endif + endwhile + endfunc + + call C("continue") + Xpath 'b' + call C("break") + Xpath 'c' + call C("return") + Xpath 'd' + let g:jump = "finish" + ExecAsScript C + unlet g:jump + Xpath 'e' + try + call C("error") + Xpath 'f' + finally + Xpath 'g' + try + call C("interrupt") + Xpath 'h' + finally + Xpath 'i' + call C("throw") + Xpath 'j' + endtry + endtry + Xpath 'k' + [CODE] + let verify =<< trim [CODE] + call assert_equal('a2ba3ca4da5ea6fga7hia8jk', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 35: :finally reason discarded by :break {{{1 +" +" When a :finally clause is executed due to a :continue, :break, +" :return, :finish, error, interrupt or :throw, the jump reason is +" discarded by a :break in the finally clause. +"------------------------------------------------------------------------------- + +func Test_finally_discard_by_break() + let test =<< trim [CODE] + func B(jump) + XloopNEXT + let loop = 0 + while loop < 2 + let loop = loop + 1 + if loop == 1 + try + if a:jump == "continue" + continue + elseif a:jump == "break" + break + elseif a:jump == "return" || a:jump == "finish" + return + elseif a:jump == "error" + asdf + elseif a:jump == "interrupt" + call interrupt() + let dummy = 0 + elseif a:jump == "throw" + throw "abc" + endif + finally + break " discards jump that caused the :finally + call assert_report('should not get here') + endtry + elseif loop == 2 + call assert_report('should not get here') + endif + endwhile + Xloop 'a' + endfunc + + call B("continue") + Xpath 'b' + call B("break") + Xpath 'c' + call B("return") + Xpath 'd' + let g:jump = "finish" + ExecAsScript B + unlet g:jump + Xpath 'e' + try + call B("error") + Xpath 'f' + finally + Xpath 'g' + try + call B("interrupt") + Xpath 'h' + finally + Xpath 'i' + call B("throw") + Xpath 'j' + endtry + endtry + Xpath 'k' + [CODE] + let verify =<< trim [CODE] + call assert_equal('a2ba3ca4da5ea6fga7hia8jk', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 36: :finally reason discarded by :return {{{1 +" +" When a :finally clause is executed due to a :continue, :break, +" :return, :finish, error, interrupt or :throw, the jump reason is +" discarded by a :return in the finally clause. +"------------------------------------------------------------------------------- + +func Test_finally_discard_by_return() + let test =<< trim [CODE] + func R(jump, retval) abort + let loop = 0 + while loop < 2 + let loop = loop + 1 + if loop == 1 + try + if a:jump == "continue" + continue + elseif a:jump == "break" + break + elseif a:jump == "return" + return + elseif a:jump == "error" + asdf + elseif a:jump == "interrupt" + call interrupt() + let dummy = 0 + elseif a:jump == "throw" + throw "abc" + endif + finally + return a:retval " discards jump that caused the :finally + call assert_report('should not get here') + endtry + elseif loop == 2 + call assert_report('should not get here') + endif + endwhile + call assert_report('should not get here') + endfunc + + let sum = -R("continue", -8) + Xpath 'a' + let sum = sum - R("break", -16) + Xpath 'b' + let sum = sum - R("return", -32) + Xpath 'c' + try + let sum = sum - R("error", -64) + Xpath 'd' + finally + Xpath 'e' + try + let sum = sum - R("interrupt", -128) + Xpath 'f' + finally + Xpath 'g' + let sum = sum - R("throw", -256) + Xpath 'h' + endtry + endtry + Xpath 'i' + + let expected = 8 + 16 + 32 + 64 + 128 + 256 + call assert_equal(sum, expected) + [CODE] + let verify =<< trim [CODE] + call assert_equal('abcdefghi', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 37: :finally reason discarded by :finish {{{1 +" +" When a :finally clause is executed due to a :continue, :break, +" :return, :finish, error, interrupt or :throw, the jump reason is +" discarded by a :finish in the finally clause. +"------------------------------------------------------------------------------- + +func Test_finally_discard_by_finish() + let test =<< trim [CODE] + func F(jump) " not executed as function, transformed to a script + let loop = 0 + while loop < 2 + let loop = loop + 1 + if loop == 1 + try + if a:jump == "continue" + continue + elseif a:jump == "break" + break + elseif a:jump == "finish" + finish + elseif a:jump == "error" + asdf + elseif a:jump == "interrupt" + call interrupt() + let dummy = 0 + elseif a:jump == "throw" + throw "abc" + endif + finally + finish " discards jump that caused the :finally + call assert_report('should not get here') + endtry + elseif loop == 2 + call assert_report('should not get here') + endif + endwhile + call assert_report('should not get here') + endfunc + + let scriptF = MakeScript("F") + delfunction F + + let g:jump = "continue" + exec "source" scriptF + Xpath 'a' + let g:jump = "break" + exec "source" scriptF + Xpath 'b' + let g:jump = "finish" + exec "source" scriptF + Xpath 'c' + try + let g:jump = "error" + exec "source" scriptF + Xpath 'd' + finally + Xpath 'e' + try + let g:jump = "interrupt" + exec "source" scriptF + Xpath 'f' + finally + Xpath 'g' + try + let g:jump = "throw" + exec "source" scriptF + Xpath 'h' + finally + Xpath 'i' + endtry + endtry + endtry + unlet g:jump + call delete(scriptF) + [CODE] + let verify =<< trim [CODE] + call assert_equal('abcdefghi', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 38: :finally reason discarded by an error {{{1 +" +" When a :finally clause is executed due to a :continue, :break, +" :return, :finish, error, interrupt or :throw, the jump reason is +" discarded by an error in the finally clause. +"------------------------------------------------------------------------------- + +func Test_finally_discard_by_error() + let test =<< trim [CODE] + func E(jump) + let loop = 0 + while loop < 2 + let loop = loop + 1 + if loop == 1 + try + if a:jump == "continue" + continue + elseif a:jump == "break" + break + elseif a:jump == "return" || a:jump == "finish" + return + elseif a:jump == "error" + asdf + elseif a:jump == "interrupt" + call interrupt() + let dummy = 0 + elseif a:jump == "throw" + throw "abc" + endif + finally + asdf " error; discards jump that caused the :finally + endtry + elseif loop == 2 + call assert_report('should not get here') + endif + endwhile + call assert_report('should not get here') + endfunc + + try + Xpath 'a' + call E("continue") + call assert_report('should not get here') + finally + try + Xpath 'b' + call E("break") + call assert_report('should not get here') + finally + try + Xpath 'c' + call E("return") + call assert_report('should not get here') + finally + try + Xpath 'd' + let g:jump = "finish" + ExecAsScript E + call assert_report('should not get here') + finally + unlet g:jump + try + Xpath 'e' + call E("error") + call assert_report('should not get here') + finally + try + Xpath 'f' + call E("interrupt") + call assert_report('should not get here') + finally + try + Xpath 'g' + call E("throw") + call assert_report('should not get here') + finally + Xpath 'h' + delfunction E + endtry + endtry + endtry + endtry + endtry + endtry + endtry + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('abcdefgh', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 39: :finally reason discarded by an interrupt {{{1 +" +" When a :finally clause is executed due to a :continue, :break, +" :return, :finish, error, interrupt or :throw, the jump reason is +" discarded by an interrupt in the finally clause. +"------------------------------------------------------------------------------- + +func Test_finally_discarded_by_interrupt() + let test =<< trim [CODE] + func I(jump) + let loop = 0 + while loop < 2 + let loop = loop + 1 + if loop == 1 + try + if a:jump == "continue" + continue + elseif a:jump == "break" + break + elseif a:jump == "return" || a:jump == "finish" + return + elseif a:jump == "error" + asdf + elseif a:jump == "interrupt" + call interrupt() + let dummy = 0 + elseif a:jump == "throw" + throw "abc" + endif + finally + call interrupt() + let dummy = 0 + endtry + elseif loop == 2 + call assert_report('should not get here') + endif + endwhile + call assert_report('should not get here') + endfunc + + try + try + Xpath 'a' + call I("continue") + call assert_report('should not get here') + finally + try + Xpath 'b' + call I("break") + call assert_report('should not get here') + finally + try + Xpath 'c' + call I("return") + call assert_report('should not get here') + finally + try + Xpath 'd' + let g:jump = "finish" + ExecAsScript I + call assert_report('should not get here') + finally + unlet g:jump + try + Xpath 'e' + call I("error") + call assert_report('should not get here') + finally + try + Xpath 'f' + call I("interrupt") + call assert_report('should not get here') + finally + try + Xpath 'g' + call I("throw") + call assert_report('should not get here') + finally + Xpath 'h' + delfunction I + endtry + endtry + endtry + endtry + endtry + endtry + endtry + call assert_report('should not get here') + catch /^Vim:Interrupt$/ + Xpath 'A' + endtry + [CODE] + let verify =<< trim [CODE] + call assert_equal('abcdefghA', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 40: :finally reason discarded by :throw {{{1 +" +" When a :finally clause is executed due to a :continue, :break, +" :return, :finish, error, interrupt or :throw, the jump reason is +" discarded by a :throw in the finally clause. +"------------------------------------------------------------------------------- + +func Test_finally_discard_by_throw() + let test =<< trim [CODE] + func T(jump) + let loop = 0 + while loop < 2 + let loop = loop + 1 + if loop == 1 + try + if a:jump == "continue" + continue + elseif a:jump == "break" + break + elseif a:jump == "return" || a:jump == "finish" + return + elseif a:jump == "error" + asdf + elseif a:jump == "interrupt" + call interrupt() + let dummy = 0 + elseif a:jump == "throw" + throw "abc" + endif + finally + throw "xyz" " discards jump that caused the :finally + endtry + elseif loop == 2 + call assert_report('should not get here') + endif + endwhile + call assert_report('should not get here') + endfunc + + try + Xpath 'a' + call T("continue") + call assert_report('should not get here') + finally + try + Xpath 'b' + call T("break") + call assert_report('should not get here') + finally + try + Xpath 'c' + call T("return") + call assert_report('should not get here') + finally + try + Xpath 'd' + let g:jump = "finish" + ExecAsScript T + call assert_report('should not get here') + finally + unlet g:jump + try + Xpath 'e' + call T("error") + call assert_report('should not get here') + finally + try + Xpath 'f' + call T("interrupt") + call assert_report('should not get here') + finally + try + Xpath 'g' + call T("throw") + call assert_report('should not get here') + finally + Xpath 'h' + delfunction T + endtry + endtry + endtry + endtry + endtry + endtry + endtry + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('abcdefgh', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 49: Throwing exceptions across functions {{{1 +" +" When an exception is thrown but not caught inside a function, the +" caller is checked for a matching :catch clause. +"------------------------------------------------------------------------------- + +func T49_C() + try + Xpath 'a' + throw "arrgh" + call assert_report('should not get here') + catch /arrgh/ + Xpath 'b' + endtry + Xpath 'c' +endfunc + +func T49_T1() + XloopNEXT + try + Xloop 'd' + throw "arrgh" + call assert_report('should not get here') + finally + Xloop 'e' + endtry + Xloop 'f' +endfunc + +func T49_T2() + try + Xpath 'g' + call T49_T1() + call assert_report('should not get here') + finally + Xpath 'h' + endtry + call assert_report('should not get here') +endfunc + +func Test_throw_exception_across_funcs() + XpathINIT + XloopINIT + try + Xpath 'i' + call T49_C() " throw and catch + Xpath 'j' + catch /.*/ + call assert_report('should not get here') + endtry + + try + Xpath 'k' + call T49_T1() " throw, one level + call assert_report('should not get here') + catch /arrgh/ + Xpath 'l' + catch /.*/ + call assert_report('should not get here') + endtry + + try + Xpath 'm' + call T49_T2() " throw, two levels + call assert_report('should not get here') + catch /arrgh/ + Xpath 'n' + catch /.*/ + call assert_report('should not get here') + endtry + Xpath 'o' + + call assert_equal('iabcjkd2e2lmgd3e3hno', g:Xpath) +endfunc + +"------------------------------------------------------------------------------- +" Test 50: Throwing exceptions across script files {{{1 +" +" When an exception is thrown but not caught inside a script file, +" the sourcing script or function is checked for a matching :catch +" clause. +" +" This test executes the bodies of the functions C, T1, and T2 from +" the previous test as script files (:return replaced by :finish). +"------------------------------------------------------------------------------- + +func T50_F() + try + Xpath 'A' + exec "source" g:scriptC + Xpath 'B' + catch /.*/ + call assert_report('should not get here') + endtry + + try + Xpath 'C' + exec "source" g:scriptT1 + call assert_report('should not get here') + catch /arrgh/ + Xpath 'D' + catch /.*/ + call assert_report('should not get here') + endtry +endfunc + +func Test_throw_across_script() + XpathINIT + XloopINIT + let g:scriptC = MakeScript("T49_C") + let g:scriptT1 = MakeScript("T49_T1") + let scriptT2 = MakeScript("T49_T2", g:scriptT1) + + try + Xpath 'E' + call T50_F() + Xpath 'F' + exec "source" scriptT2 + call assert_report('should not get here') + catch /arrgh/ + Xpath 'G' + catch /.*/ + call assert_report('should not get here') + endtry + Xpath 'H' + call assert_equal('EAabcBCd2e2DFgd3e3hGH', g:Xpath) + + call delete(g:scriptC) + call delete(g:scriptT1) + call delete(scriptT2) + unlet g:scriptC g:scriptT1 scriptT2 +endfunc + "------------------------------------------------------------------------------- " Test 87 using (expr) ? funcref : funcref {{{1 " -- cgit From 8d6a217b9a1c3db6ed4ee8fabee20ca75a515857 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 20:25:07 +0800 Subject: vim-patch:8.2.1383: test 49 is old style Problem: Test 49 is old style. Solution: Convert test cases to new style. (Yegappan Lakshmanan, closes vim/vim#6638) https://github.com/vim/vim/commit/9470a4d88acf948af1596101527b3a505f8c14e9 Cherry-pick AssertException() from patch 8.2.1146. --- src/nvim/testdir/shared.vim | 15 + src/nvim/testdir/test49.ok | 9 - src/nvim/testdir/test49.vim | 1254 ++--------------------------------- src/nvim/testdir/test_vimscript.vim | 1147 ++++++++++++++++++++++++++++++++ 4 files changed, 1201 insertions(+), 1224 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/shared.vim b/src/nvim/testdir/shared.vim index c2809844ac..ef7cc4ac5f 100644 --- a/src/nvim/testdir/shared.vim +++ b/src/nvim/testdir/shared.vim @@ -364,4 +364,19 @@ func GetMessages() return msg_list endfunc +" Run the list of commands in 'cmds' and look for 'errstr' in exception. +" Note that assert_fails() cannot be used in some places and this function +" can be used. +func AssertException(cmds, errstr) + let save_exception = '' + try + for cmd in a:cmds + exe cmd + endfor + catch + let save_exception = v:exception + endtry + call assert_match(a:errstr, save_exception) +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test49.ok b/src/nvim/testdir/test49.ok index 50696fd643..8ca8a564c3 100644 --- a/src/nvim/testdir/test49.ok +++ b/src/nvim/testdir/test49.ok @@ -1,18 +1,9 @@ Results of test49.vim: -*** Test 52: OK (1247112011) -*** Test 53: OK (131071) -*** Test 54: OK (2047) -*** Test 55: OK (1023) -*** Test 56: OK (511) -*** Test 57: OK (2147450880) -*** Test 58: OK (624945) *** Test 59: OK (2038431743) *** Test 60: OK (311511339) -*** Test 61: OK (374889517) *** Test 62: OK (286331153) *** Test 63: OK (236978127) *** Test 64: OK (1499645335) -*** Test 65: OK (70187) *** Test 66: OK (5464) *** Test 67: OK (212514423) *** Test 68: OK (212514423) diff --git a/src/nvim/testdir/test49.vim b/src/nvim/testdir/test49.vim index d51ba24153..6133f410ac 100644 --- a/src/nvim/testdir/test49.vim +++ b/src/nvim/testdir/test49.vim @@ -456,7 +456,7 @@ function ExtraVim(...) " messing up the user's viminfo file. let redirect = a:0 ? \ " -c 'au VimLeave * redir END' -c 'redir\\! >" . a:1 . "'" : "" - exec "!echo '" . debug_quits . "q' | " .. v:progpath .. " -u NONE -N -es" . redirect . + exec "!echo '" . debug_quits . "q' | " .. v:progpath .. " -u NONE -N -Xes" . redirect . \ " -c 'debuggreedy|set viminfo+=nviminfo'" . \ " -c 'let ExtraVimBegin = " . extra_begin . "'" . \ " -c 'let ExtraVimResult = \"" . resultfile . "\"'" . breakpoints . @@ -607,1002 +607,52 @@ com! -nargs=1 -bar ExecAsScript call ExecAsScript() " END_OF_TEST_ENVIRONMENT - do not change or remove this line. -" Tests 1 to 50, 87 were moved to test_vimscript.vim -" Tests 25, 26, 32, 33, 41-48, 51, 69-75 were moved to test_trycatch.vim -let Xtest = 52 - -"------------------------------------------------------------------------------- -" Test 52: Uncaught exceptions {{{1 -" -" When an exception is thrown but not caught, an error message is -" displayed when the script is terminated. In case of an interrupt -" or error exception, the normal interrupt or error message(s) are -" displayed. -"------------------------------------------------------------------------------- - -XpathINIT - -let msgfile = tempname() - function! MESSAGES(...) try exec "edit" g:msgfile catch /^Vim(edit):/ return 0 - endtry - - let english = v:lang == "C" || v:lang =~ '^[Ee]n' - let match = 1 - norm gg - - let num = a:0 / 2 - let cnt = 1 - while cnt <= num - let enr = a:{2*cnt - 1} - let emsg= a:{2*cnt} - let cnt = cnt + 1 - - if enr == "" - Xout "TODO: Add message number for:" emsg - elseif enr == "INT" - let enr = "" - endif - if enr == "" && !english - continue - endif - let pattern = (enr != "") ? enr . ':.*' : '' - if english - let pattern = pattern . emsg - endif - if !search(pattern, "W") - let match = 0 - Xout "No match for:" pattern - endif - norm $ - endwhile - - bwipeout! - return match -endfunction - -if ExtraVim(msgfile) - Xpath 1 " X: 1 - throw "arrgh" -endif - -Xpath 2 " X: 2 -if !MESSAGES('E605', "Exception not caught") - Xpath 4 " X: 0 -endif - -if ExtraVim(msgfile) - try - Xpath 8 " X: 8 - throw "oops" - catch /arrgh/ - Xpath 16 " X: 0 - endtry - Xpath 32 " X: 0 -endif - -Xpath 64 " X: 64 -if !MESSAGES('E605', "Exception not caught") - Xpath 128 " X: 0 -endif - -if ExtraVim(msgfile) - function! T() - throw "brrr" - endfunction - - try - Xpath 256 " X: 256 - throw "arrgh" - catch /.*/ - Xpath 512 " X: 512 - call T() - endtry - Xpath 1024 " X: 0 -endif - -Xpath 2048 " X: 2048 -if !MESSAGES('E605', "Exception not caught") - Xpath 4096 " X: 0 -endif - -if ExtraVim(msgfile) - try - Xpath 8192 " X: 8192 - throw "arrgh" - finally - Xpath 16384 " X: 16384 - throw "brrr" - endtry - Xpath 32768 " X: 0 -endif - -Xpath 65536 " X: 65536 -if !MESSAGES('E605', "Exception not caught") - Xpath 131072 " X: 0 -endif - -if ExtraVim(msgfile) - try - Xpath 262144 " X: 262144 - "INTERRUPT - endtry - Xpath 524288 " X: 0 -endif - -Xpath 1048576 " X: 1048576 -if !MESSAGES('INT', "Interrupted") - Xpath 2097152 " X: 0 -endif - -if ExtraVim(msgfile) - try - Xpath 4194304 " X: 4194304 - let x = novar " error E121/E15; exception: E121 - catch /E15:/ " should not catch - Xpath 8388608 " X: 0 - endtry - Xpath 16777216 " X: 0 -endif - -Xpath 33554432 " X: 33554432 -if !MESSAGES('E121', "Undefined variable", 'E15', "Invalid expression") - Xpath 67108864 " X: 0 -endif - -if ExtraVim(msgfile) - try - Xpath 134217728 " X: 134217728 -" unlet novar # " error E108/E488; exception: E488 - catch /E108:/ " should not catch - Xpath 268435456 " X: 0 - endtry - Xpath 536870912 " X: 0 -endif - -Xpath 1073741824 " X: 1073741824 -if !MESSAGES('E108', "No such variable", 'E488', "Trailing characters") - " The Xpath command does not accept 2^31 (negative); add explicitly: - let Xpath = Xpath + 2147483648 " X: 0 -endif - -call delete(msgfile) -unlet msgfile - -Xcheck 1247112011 - -" Leave MESSAGES() for the next tests. - - -"------------------------------------------------------------------------------- -" Test 53: Nesting errors: :endif/:else/:elseif {{{1 -" -" For nesting errors of :if conditionals the correct error messages -" should be given. -" -" This test reuses the function MESSAGES() from the previous test. -" This functions checks the messages in g:msgfile. -"------------------------------------------------------------------------------- - -XpathINIT - -let msgfile = tempname() - -if ExtraVim(msgfile) -" endif -endif -if MESSAGES('E580', ":endif without :if") - Xpath 1 " X: 1 -endif - -if ExtraVim(msgfile) -" while 1 -" endif -" endwhile -endif -if MESSAGES('E580', ":endif without :if") - Xpath 2 " X: 2 -endif - -if ExtraVim(msgfile) -" try -" finally -" endif -" endtry -endif -if MESSAGES('E580', ":endif without :if") - Xpath 4 " X: 4 -endif - -if ExtraVim(msgfile) -" try -" endif -" endtry -endif -if MESSAGES('E580', ":endif without :if") - Xpath 8 " X: 8 -endif - -if ExtraVim(msgfile) -" try -" throw "a" -" catch /a/ -" endif -" endtry -endif -if MESSAGES('E580', ":endif without :if") - Xpath 16 " X: 16 -endif - -if ExtraVim(msgfile) -" else -endif -if MESSAGES('E581', ":else without :if") - Xpath 32 " X: 32 -endif - -if ExtraVim(msgfile) -" while 1 -" else -" endwhile -endif -if MESSAGES('E581', ":else without :if") - Xpath 64 " X: 64 -endif - -if ExtraVim(msgfile) -" try -" finally -" else -" endtry -endif -if MESSAGES('E581', ":else without :if") - Xpath 128 " X: 128 -endif - -if ExtraVim(msgfile) -" try -" else -" endtry -endif -if MESSAGES('E581', ":else without :if") - Xpath 256 " X: 256 -endif - -if ExtraVim(msgfile) -" try -" throw "a" -" catch /a/ -" else -" endtry -endif -if MESSAGES('E581', ":else without :if") - Xpath 512 " X: 512 -endif - -if ExtraVim(msgfile) -" elseif -endif -if MESSAGES('E582', ":elseif without :if") - Xpath 1024 " X: 1024 -endif - -if ExtraVim(msgfile) -" while 1 -" elseif -" endwhile -endif -if MESSAGES('E582', ":elseif without :if") - Xpath 2048 " X: 2048 -endif - -if ExtraVim(msgfile) -" try -" finally -" elseif -" endtry -endif -if MESSAGES('E582', ":elseif without :if") - Xpath 4096 " X: 4096 -endif - -if ExtraVim(msgfile) -" try -" elseif -" endtry -endif -if MESSAGES('E582', ":elseif without :if") - Xpath 8192 " X: 8192 -endif - -if ExtraVim(msgfile) -" try -" throw "a" -" catch /a/ -" elseif -" endtry -endif -if MESSAGES('E582', ":elseif without :if") - Xpath 16384 " X: 16384 -endif - -if ExtraVim(msgfile) -" if 1 -" else -" else -" endif -endif -if MESSAGES('E583', "multiple :else") - Xpath 32768 " X: 32768 -endif - -if ExtraVim(msgfile) -" if 1 -" else -" elseif 1 -" endif -endif -if MESSAGES('E584', ":elseif after :else") - Xpath 65536 " X: 65536 -endif - -call delete(msgfile) -unlet msgfile - -Xcheck 131071 - -" Leave MESSAGES() for the next test. - - -"------------------------------------------------------------------------------- -" Test 54: Nesting errors: :while/:endwhile {{{1 -" -" For nesting errors of :while conditionals the correct error messages -" should be given. -" -" This test reuses the function MESSAGES() from the previous test. -" This functions checks the messages in g:msgfile. -"------------------------------------------------------------------------------- - -XpathINIT - -let msgfile = tempname() - -if ExtraVim(msgfile) -" endwhile -endif -if MESSAGES('E588', ":endwhile without :while") - Xpath 1 " X: 1 -endif - -if ExtraVim(msgfile) -" if 1 -" endwhile -" endif -endif -if MESSAGES('E588', ":endwhile without :while") - Xpath 2 " X: 2 -endif - -if ExtraVim(msgfile) -" while 1 -" if 1 -" endwhile -endif -if MESSAGES('E171', "Missing :endif") - Xpath 4 " X: 4 -endif - -if ExtraVim(msgfile) -" try -" finally -" endwhile -" endtry -endif -if MESSAGES('E588', ":endwhile without :while") - Xpath 8 " X: 8 -endif - -if ExtraVim(msgfile) -" while 1 -" try -" finally -" endwhile -endif -if MESSAGES('E600', "Missing :endtry") - Xpath 16 " X: 16 -endif - -if ExtraVim(msgfile) -" while 1 -" if 1 -" try -" finally -" endwhile -endif -if MESSAGES('E600', "Missing :endtry") - Xpath 32 " X: 32 -endif - -if ExtraVim(msgfile) -" while 1 -" try -" finally -" if 1 -" endwhile -endif -if MESSAGES('E171', "Missing :endif") - Xpath 64 " X: 64 -endif - -if ExtraVim(msgfile) -" try -" endwhile -" endtry -endif -if MESSAGES('E588', ":endwhile without :while") - Xpath 128 " X: 128 -endif - -if ExtraVim(msgfile) -" while 1 -" try -" endwhile -" endtry -" endwhile -endif -if MESSAGES('E588', ":endwhile without :while") - Xpath 256 " X: 256 -endif - -if ExtraVim(msgfile) -" try -" throw "a" -" catch /a/ -" endwhile -" endtry -endif -if MESSAGES('E588', ":endwhile without :while") - Xpath 512 " X: 512 -endif - -if ExtraVim(msgfile) -" while 1 -" try -" throw "a" -" catch /a/ -" endwhile -" endtry -" endwhile -endif -if MESSAGES('E588', ":endwhile without :while") - Xpath 1024 " X: 1024 -endif - - -call delete(msgfile) -unlet msgfile - -Xcheck 2047 - -" Leave MESSAGES() for the next test. - - -"------------------------------------------------------------------------------- -" Test 55: Nesting errors: :continue/:break {{{1 -" -" For nesting errors of :continue and :break commands the correct -" error messages should be given. -" -" This test reuses the function MESSAGES() from the previous test. -" This functions checks the messages in g:msgfile. -"------------------------------------------------------------------------------- - -XpathINIT - -let msgfile = tempname() - -if ExtraVim(msgfile) -" continue -endif -if MESSAGES('E586', ":continue without :while") - Xpath 1 " X: 1 -endif - -if ExtraVim(msgfile) -" if 1 -" continue -" endif -endif -if MESSAGES('E586', ":continue without :while") - Xpath 2 " X: 2 -endif - -if ExtraVim(msgfile) -" try -" finally -" continue -" endtry -endif -if MESSAGES('E586', ":continue without :while") - Xpath 4 " X: 4 -endif - -if ExtraVim(msgfile) -" try -" continue -" endtry -endif -if MESSAGES('E586', ":continue without :while") - Xpath 8 " X: 8 -endif - -if ExtraVim(msgfile) -" try -" throw "a" -" catch /a/ -" continue -" endtry -endif -if MESSAGES('E586', ":continue without :while") - Xpath 16 " X: 16 -endif - -if ExtraVim(msgfile) -" break -endif -if MESSAGES('E587', ":break without :while") - Xpath 32 " X: 32 -endif - -if ExtraVim(msgfile) -" if 1 -" break -" endif -endif -if MESSAGES('E587', ":break without :while") - Xpath 64 " X: 64 -endif - -if ExtraVim(msgfile) -" try -" finally -" break -" endtry -endif -if MESSAGES('E587', ":break without :while") - Xpath 128 " X: 128 -endif - -if ExtraVim(msgfile) -" try -" break -" endtry -endif -if MESSAGES('E587', ":break without :while") - Xpath 256 " X: 256 -endif - -if ExtraVim(msgfile) -" try -" throw "a" -" catch /a/ -" break -" endtry -endif -if MESSAGES('E587', ":break without :while") - Xpath 512 " X: 512 -endif - -call delete(msgfile) -unlet msgfile - -Xcheck 1023 - -" Leave MESSAGES() for the next test. - - -"------------------------------------------------------------------------------- -" Test 56: Nesting errors: :endtry {{{1 -" -" For nesting errors of :try conditionals the correct error messages -" should be given. -" -" This test reuses the function MESSAGES() from the previous test. -" This functions checks the messages in g:msgfile. -"------------------------------------------------------------------------------- - -XpathINIT - -let msgfile = tempname() - -if ExtraVim(msgfile) -" endtry -endif -if MESSAGES('E602', ":endtry without :try") - Xpath 1 " X: 1 -endif - -if ExtraVim(msgfile) -" if 1 -" endtry -" endif -endif -if MESSAGES('E602', ":endtry without :try") - Xpath 2 " X: 2 -endif - -if ExtraVim(msgfile) -" while 1 -" endtry -" endwhile -endif -if MESSAGES('E602', ":endtry without :try") - Xpath 4 " X: 4 -endif - -if ExtraVim(msgfile) -" try -" if 1 -" endtry -endif -if MESSAGES('E171', "Missing :endif") - Xpath 8 " X: 8 -endif - -if ExtraVim(msgfile) -" try -" while 1 -" endtry -endif -if MESSAGES('E170', "Missing :endwhile") - Xpath 16 " X: 16 -endif - -if ExtraVim(msgfile) -" try -" finally -" if 1 -" endtry -endif -if MESSAGES('E171', "Missing :endif") - Xpath 32 " X: 32 -endif - -if ExtraVim(msgfile) -" try -" finally -" while 1 -" endtry -endif -if MESSAGES('E170', "Missing :endwhile") - Xpath 64 " X: 64 -endif - -if ExtraVim(msgfile) - try - Xpath 4194304 " X: 4194304 - let x = novar " error E121; exception: E121 - catch /E15:/ " should not catch - Xpath 8388608 " X: 0 - endtry - Xpath 16777216 " X: 0 -endif - -Xpath 33554432 " X: 33554432 -if !MESSAGES('E121', "Undefined variable") - Xpath 67108864 " X: 0 -endif - -if ExtraVim(msgfile) -" try -" throw "a" -" catch /a/ -" while 1 -" endtry -endif -if MESSAGES('E170', "Missing :endwhile") - Xpath 256 " X: 256 -endif - -call delete(msgfile) -unlet msgfile - -delfunction MESSAGES - -Xcheck 511 - - -"------------------------------------------------------------------------------- -" Test 57: v:exception and v:throwpoint for user exceptions {{{1 -" -" v:exception evaluates to the value of the exception that was caught -" most recently and is not finished. (A caught exception is finished -" when the next ":catch", ":finally", or ":endtry" is reached.) -" v:throwpoint evaluates to the script/function name and line number -" where that exception has been thrown. -"------------------------------------------------------------------------------- - -XpathINIT - -function! FuncException() - let g:exception = v:exception -endfunction - -function! FuncThrowpoint() - let g:throwpoint = v:throwpoint -endfunction - -let scriptException = MakeScript("FuncException") -let scriptThrowPoint = MakeScript("FuncThrowpoint") - -command! CmdException let g:exception = v:exception -command! CmdThrowpoint let g:throwpoint = v:throwpoint - -XloopINIT! 1 2 - -function! CHECK(n, exception, throwname, throwline) - XloopNEXT - let error = 0 - if v:exception != a:exception - Xout a:n.": v:exception is" v:exception "instead of" a:exception - let error = 1 - endif - if v:throwpoint !~ a:throwname - let name = escape(a:throwname, '\') - Xout a:n.": v:throwpoint (".v:throwpoint.") does not match" name - let error = 1 - endif - if v:throwpoint !~ a:throwline - let line = escape(a:throwline, '\') - Xout a:n.": v:throwpoint (".v:throwpoint.") does not match" line - let error = 1 - endif - if error - Xloop 1 " X: 0 - endif -endfunction - -function! T(arg, line) - if a:line == 2 - throw a:arg " in line 2 - elseif a:line == 4 - throw a:arg " in line 4 - elseif a:line == 6 - throw a:arg " in line 6 - elseif a:line == 8 - throw a:arg " in line 8 - endif -endfunction - -function! G(arg, line) - call T(a:arg, a:line) -endfunction - -function! F(arg, line) - call G(a:arg, a:line) -endfunction - -let scriptT = MakeScript("T") -let scriptG = MakeScript("G", scriptT) -let scriptF = MakeScript("F", scriptG) - -try - Xpath 32768 " X: 32768 - call F("oops", 2) -catch /.*/ - Xpath 65536 " X: 65536 - let exception = v:exception - let throwpoint = v:throwpoint - call CHECK(1, "oops", '\', '\<2\>') - exec "let exception = v:exception" - exec "let throwpoint = v:throwpoint" - call CHECK(2, "oops", '\', '\<2\>') - CmdException - CmdThrowpoint - call CHECK(3, "oops", '\', '\<2\>') - call FuncException() - call FuncThrowpoint() - call CHECK(4, "oops", '\', '\<2\>') - exec "source" scriptException - exec "source" scriptThrowPoint - call CHECK(5, "oops", '\', '\<2\>') - try - Xpath 131072 " X: 131072 - call G("arrgh", 4) - catch /.*/ - Xpath 262144 " X: 262144 - let exception = v:exception - let throwpoint = v:throwpoint - call CHECK(6, "arrgh", '\', '\<4\>') - try - Xpath 524288 " X: 524288 - let g:arg = "autsch" - let g:line = 6 - exec "source" scriptF - catch /.*/ - Xpath 1048576 " X: 1048576 - let exception = v:exception - let throwpoint = v:throwpoint - " Symbolic links in tempname()s are not resolved, whereas resolving - " is done for v:throwpoint. Resolve the temporary file name for - " scriptT, so that it can be matched against v:throwpoint. - call CHECK(7, "autsch", resolve(scriptT), '\<6\>') - finally - Xpath 2097152 " X: 2097152 - let exception = v:exception - let throwpoint = v:throwpoint - call CHECK(8, "arrgh", '\', '\<4\>') - try - Xpath 4194304 " X: 4194304 - let g:arg = "brrrr" - let g:line = 8 - exec "source" scriptG - catch /.*/ - Xpath 8388608 " X: 8388608 - let exception = v:exception - let throwpoint = v:throwpoint - " Resolve scriptT for matching it against v:throwpoint. - call CHECK(9, "brrrr", resolve(scriptT), '\<8\>') - finally - Xpath 16777216 " X: 16777216 - let exception = v:exception - let throwpoint = v:throwpoint - call CHECK(10, "arrgh", '\', '\<4\>') - endtry - Xpath 33554432 " X: 33554432 - let exception = v:exception - let throwpoint = v:throwpoint - call CHECK(11, "arrgh", '\', '\<4\>') - endtry - Xpath 67108864 " X: 67108864 - let exception = v:exception - let throwpoint = v:throwpoint - call CHECK(12, "arrgh", '\', '\<4\>') - finally - Xpath 134217728 " X: 134217728 - let exception = v:exception - let throwpoint = v:throwpoint - call CHECK(13, "oops", '\', '\<2\>') - endtry - Xpath 268435456 " X: 268435456 - let exception = v:exception - let throwpoint = v:throwpoint - call CHECK(14, "oops", '\', '\<2\>') -finally - Xpath 536870912 " X: 536870912 - let exception = v:exception - let throwpoint = v:throwpoint - call CHECK(15, "", '^$', '^$') -endtry - -Xpath 1073741824 " X: 1073741824 - -unlet exception throwpoint -delfunction FuncException -delfunction FuncThrowpoint -call delete(scriptException) -call delete(scriptThrowPoint) -unlet scriptException scriptThrowPoint -delcommand CmdException -delcommand CmdThrowpoint -delfunction T -delfunction G -delfunction F -call delete(scriptT) -call delete(scriptG) -call delete(scriptF) -unlet scriptT scriptG scriptF - -Xcheck 2147450880 - - -"------------------------------------------------------------------------------- -" -" Test 58: v:exception and v:throwpoint for error/interrupt exceptions {{{1 -" -" v:exception and v:throwpoint work also for error and interrupt -" exceptions. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - - function! T(line) - if a:line == 2 - delfunction T " error (function in use) in line 2 - elseif a:line == 4 - let dummy = 0 " INTERRUPT1 - interrupt in line 4 - endif - endfunction + endtry - while 1 - try - Xpath 1 " X: 1 - let caught = 0 - call T(2) - catch /.*/ - let caught = 1 - if v:exception !~ 'Vim(delfunction):' - Xpath 2 " X: 0 - endif - if v:throwpoint !~ '\' - Xpath 4 " X: 0 - endif - if v:throwpoint !~ '\<2\>' - Xpath 8 " X: 0 - endif - finally - Xpath 16 " X: 16 - if caught || $VIMNOERRTHROW - Xpath 32 " X: 32 - endif - if v:exception != "" - Xpath 64 " X: 0 - endif - if v:throwpoint != "" - Xpath 128 " X: 0 - endif - break " discard error for $VIMNOERRTHROW - endtry - endwhile + let english = v:lang == "C" || v:lang =~ '^[Ee]n' + let match = 1 + norm gg - Xpath 256 " X: 256 - if v:exception != "" - Xpath 512 " X: 0 - endif - if v:throwpoint != "" - Xpath 1024 " X: 0 - endif + let num = a:0 / 2 + let cnt = 1 + while cnt <= num + let enr = a:{2*cnt - 1} + let emsg= a:{2*cnt} + let cnt = cnt + 1 - while 1 - try - Xpath 2048 " X: 2048 - let caught = 0 - call T(4) - catch /.*/ - let caught = 1 - if v:exception != 'Vim:Interrupt' - Xpath 4096 " X: 0 - endif - if v:throwpoint !~ '\' - Xpath 8192 " X: 0 - endif - if v:throwpoint !~ '\<4\>' - Xpath 16384 " X: 0 - endif - finally - Xpath 32768 " X: 32768 - if caught || $VIMNOINTTHROW - Xpath 65536 " X: 65536 - endif - if v:exception != "" - Xpath 131072 " X: 0 - endif - if v:throwpoint != "" - Xpath 262144 " X: 0 - endif - break " discard error for $VIMNOERRTHROW - endtry + if enr == "" + Xout "TODO: Add message number for:" emsg + elseif enr == "INT" + let enr = "" + endif + if enr == "" && !english + continue + endif + let pattern = (enr != "") ? enr . ':.*' : '' + if english + let pattern = pattern . emsg + endif + if !search(pattern, "W") + let match = 0 + Xout "No match for:" pattern + endif + norm $ endwhile - Xpath 524288 " X: 524288 - if v:exception != "" - Xpath 1048576 " X: 0 - endif - if v:throwpoint != "" - Xpath 2097152 " X: 0 - endif - -endif + bwipeout! + return match +endfunction -Xcheck 624945 +" Leave MESSAGES() for the next tests. +" Tests 1 to 50, 52 to 57, 87 were moved to test_vimscript.vim +" Tests 25, 26, 32, 33, 41-48, 51, 69-75 were moved to test_trycatch.vim +let Xtest = 59 "------------------------------------------------------------------------------- " @@ -2071,142 +1121,8 @@ endif Xcheck 311511339 - -"------------------------------------------------------------------------------- -" Test 61: Catching interrupt exceptions {{{1 -" -" When an interrupt occurs inside a :try/:endtry region, an -" interrupt exception is thrown and can be caught. Its value is -" "Vim:Interrupt". If the interrupt occurs after an error or a :throw -" but before a matching :catch is reached, all following :catches of -" that try block are ignored, but the interrupt exception can be -" caught by the next surrounding try conditional. An interrupt is -" ignored when there is a previous interrupt that has not been caught -" or causes a :finally clause to be executed. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - - while 1 - try - try - Xpath 1 " X: 1 - let caught = 0 - "INTERRUPT - Xpath 2 " X: 0 - catch /^Vim:Interrupt$/ - let caught = 1 - finally - Xpath 4 " X: 4 - if caught || $VIMNOINTTHROW - Xpath 8 " X: 8 - endif - endtry - catch /.*/ - Xpath 16 " X: 0 - Xout v:exception "in" v:throwpoint - finally - break " discard interrupt for $VIMNOINTTHROW - endtry - endwhile - - while 1 - try - try - let caught = 0 - try - Xpath 32 " X: 32 - asdf - Xpath 64 " X: 0 - catch /do_not_catch/ - Xpath 128 " X: 0 - catch /.*/ "INTERRUPT - throw interrupt if !$VIMNOERRTHROW - Xpath 256 " X: 0 - catch /.*/ - Xpath 512 " X: 0 - finally "INTERRUPT - throw interrupt if $VIMNOERRTHROW - Xpath 1024 " X: 1024 - endtry - catch /^Vim:Interrupt$/ - let caught = 1 - finally - Xpath 2048 " X: 2048 - if caught || $VIMNOINTTHROW - Xpath 4096 " X: 4096 - endif - endtry - catch /.*/ - Xpath 8192 " X: 0 - Xout v:exception "in" v:throwpoint - finally - break " discard interrupt for $VIMNOINTTHROW - endtry - endwhile - - while 1 - try - try - let caught = 0 - try - Xpath 16384 " X: 16384 - throw "x" - Xpath 32768 " X: 0 - catch /do_not_catch/ - Xpath 65536 " X: 0 - catch /x/ "INTERRUPT - Xpath 131072 " X: 0 - catch /.*/ - Xpath 262144 " X: 0 - endtry - catch /^Vim:Interrupt$/ - let caught = 1 - finally - Xpath 524288 " X: 524288 - if caught || $VIMNOINTTHROW - Xpath 1048576 " X: 1048576 - endif - endtry - catch /.*/ - Xpath 2097152 " X: 0 - Xout v:exception "in" v:throwpoint - finally - break " discard interrupt for $VIMNOINTTHROW - endtry - endwhile - - while 1 - try - let caught = 0 - try - Xpath 4194304 " X: 4194304 - "INTERRUPT - Xpath 8388608 " X: 0 - catch /do_not_catch/ "INTERRUPT - Xpath 16777216 " X: 0 - catch /^Vim:Interrupt$/ - let caught = 1 - finally - Xpath 33554432 " X: 33554432 - if caught || $VIMNOINTTHROW - Xpath 67108864 " X: 67108864 - endif - endtry - catch /.*/ - Xpath 134217728 " X: 0 - Xout v:exception "in" v:throwpoint - finally - break " discard interrupt for $VIMNOINTTHROW - endtry - endwhile - - Xpath 268435456 " X: 268435456 - -endif - -Xcheck 374889517 - +" Test 61 was moved to test_vimscript.vim +let Xtest = 62 "------------------------------------------------------------------------------- " Test 62: Catching error exceptions {{{1 @@ -2729,100 +1645,8 @@ endif Xcheck 1499645335 - -"------------------------------------------------------------------------------- -" Test 65: Errors in the /pattern/ argument of a :catch {{{1 -" -" On an error in the /pattern/ argument of a :catch, the :catch does -" not match. Any following :catches of the same :try/:endtry don't -" match either. Finally clauses are executed. -"------------------------------------------------------------------------------- - -XpathINIT - -function! MSG(enr, emsg) - let english = v:lang == "C" || v:lang =~ '^[Ee]n' - if a:enr == "" - Xout "TODO: Add message number for:" a:emsg - let v:errmsg = ":" . v:errmsg - endif - let match = 1 - if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg) - let match = 0 - if v:errmsg == "" - Xout "Message missing." - else - let v:errmsg = escape(v:errmsg, '"') - Xout "Unexpected message:" v:errmsg - endif - endif - return match -endfunction - -try - try - Xpath 1 " X: 1 - throw "oops" - catch /^oops$/ - Xpath 2 " X: 2 - catch /\)/ " not checked; exception has already been caught - Xpath 4 " X: 0 - endtry - Xpath 8 " X: 8 -catch /.*/ - Xpath 16 " X: 0 - Xout v:exception "in" v:throwpoint -endtry - -function! F() - try - let caught = 0 - try - try - Xpath 32 " X: 32 - throw "ab" - catch /abc/ " does not catch - Xpath 64 " X: 0 - catch /\)/ " error; discards exception - Xpath 128 " X: 0 - catch /.*/ " not checked - Xpath 256 " X: 0 - finally - Xpath 512 " X: 512 - endtry - Xpath 1024 " X: 0 - catch /^ab$/ " checked, but original exception is discarded - Xpath 2048 " X: 0 - catch /^Vim(catch):/ - let caught = 1 - let v:errmsg = substitute(v:exception, '^Vim(catch):', '', "") - finally - Xpath 4096 " X: 4096 - if !caught && !$VIMNOERRTHROW - Xpath 8192 " X: 0 - endif - if !MSG('E475', "Invalid argument") - Xpath 16384 " X: 0 - endif - if !caught - return | " discard error - endif - endtry - catch /.*/ - Xpath 32768 " X: 0 - Xout v:exception "in" v:throwpoint - endtry -endfunction - -call F() -Xpath 65536 " X: 65536 - -delfunction MSG -delfunction F -unlet! caught - -Xcheck 70187 - +" Test 65 was moved to test_vimscript.vim +let Xtest = 66 "------------------------------------------------------------------------------- " Test 66: Stop range :call on error, interrupt, or :throw {{{1 diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index d49681974e..5e112e05f9 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -2763,6 +2763,1153 @@ func Test_throw_across_script() unlet g:scriptC g:scriptT1 scriptT2 endfunc +"------------------------------------------------------------------------------- +" Test 52: Uncaught exceptions {{{1 +" +" When an exception is thrown but not caught, an error message is +" displayed when the script is terminated. In case of an interrupt +" or error exception, the normal interrupt or error message(s) are +" displayed. +"------------------------------------------------------------------------------- + +func Test_uncaught_exception_1() + CheckEnglish + + let test =<< trim [CODE] + Xpath 'a' + throw "arrgh" + call assert_report('should not get here')` + [CODE] + let verify =<< trim [CODE] + call assert_equal('E605: Exception not caught: arrgh', v:errmsg) + call assert_equal('a', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_uncaught_exception_2() + CheckEnglish + + let test =<< trim [CODE] + try + Xpath 'a' + throw "oops" + call assert_report('should not get here')` + catch /arrgh/ + call assert_report('should not get here')` + endtry + call assert_report('should not get here')` + [CODE] + let verify =<< trim [CODE] + call assert_equal('E605: Exception not caught: oops', v:errmsg) + call assert_equal('a', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_uncaught_exception_3() + CheckEnglish + + let test =<< trim [CODE] + func T() + Xpath 'c' + throw "brrr" + call assert_report('should not get here')` + endfunc + + try + Xpath 'a' + throw "arrgh" + call assert_report('should not get here')` + catch /.*/ + Xpath 'b' + call T() + call assert_report('should not get here')` + endtry + call assert_report('should not get here')` + [CODE] + let verify =<< trim [CODE] + call assert_equal('E605: Exception not caught: brrr', v:errmsg) + call assert_equal('abc', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_uncaught_exception_4() + CheckEnglish + + let test =<< trim [CODE] + try + Xpath 'a' + throw "arrgh" + call assert_report('should not get here')` + finally + Xpath 'b' + throw "brrr" + call assert_report('should not get here')` + endtry + call assert_report('should not get here')` + [CODE] + let verify =<< trim [CODE] + call assert_equal('E605: Exception not caught: brrr', v:errmsg) + call assert_equal('ab', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_uncaught_exception_5() + CheckEnglish + + " Need to catch and handle interrupt, otherwise the test will wait for the + " user to press to continue + let test =<< trim [CODE] + try + try + Xpath 'a' + call interrupt() + call assert_report('should not get here') + endtry + call assert_report('should not get here') + catch /^Vim:Interrupt$/ + Xpath 'b' + endtry + [CODE] + let verify =<< trim [CODE] + call assert_equal('ab', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_uncaught_exception_6() + CheckEnglish + + let test =<< trim [CODE] + try + Xpath 'a' + let x = novar " error E121; exception: E121 + catch /E15:/ " should not catch + call assert_report('should not get here') + endtry + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('a', g:Xpath) + call assert_equal('E121: Undefined variable: novar', v:errmsg) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_uncaught_exception_7() + CheckEnglish + + let test =<< trim [CODE] + try + Xpath 'a' + " error E108/E488; exception: E488 + unlet novar # + catch /E108:/ " should not catch + call assert_report('should not get here') + endtry + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('a', g:Xpath) + call assert_equal('E488: Trailing characters: #', v:errmsg) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 53: Nesting errors: :endif/:else/:elseif {{{1 +" +" For nesting errors of :if conditionals the correct error messages +" should be given. +"------------------------------------------------------------------------------- + +func Test_nested_if_else_errors() + CheckEnglish + + " :endif without :if + let code =<< trim END + endif + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endif):E580: :endif without :if') + + " :endif without :if + let code =<< trim END + while 1 + endif + endwhile + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endif):E580: :endif without :if') + + " :endif without :if + let code =<< trim END + try + finally + endif + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endif):E580: :endif without :if') + + " :endif without :if + let code =<< trim END + try + endif + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endif):E580: :endif without :if') + + " :endif without :if + let code =<< trim END + try + throw "a" + catch /a/ + endif + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endif):E580: :endif without :if') + + " :else without :if + let code =<< trim END + else + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(else):E581: :else without :if') + + " :else without :if + let code =<< trim END + while 1 + else + endwhile + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(else):E581: :else without :if') + + " :else without :if + let code =<< trim END + try + finally + else + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(else):E581: :else without :if') + + " :else without :if + let code =<< trim END + try + else + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(else):E581: :else without :if') + + " :else without :if + let code =<< trim END + try + throw "a" + catch /a/ + else + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(else):E581: :else without :if') + + " :elseif without :if + let code =<< trim END + elseif + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(elseif):E582: :elseif without :if') + + " :elseif without :if + let code =<< trim END + while 1 + elseif + endwhile + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(elseif):E582: :elseif without :if') + + " :elseif without :if + let code =<< trim END + try + finally + elseif + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(elseif):E582: :elseif without :if') + + " :elseif without :if + let code =<< trim END + try + elseif + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(elseif):E582: :elseif without :if') + + " :elseif without :if + let code =<< trim END + try + throw "a" + catch /a/ + elseif + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(elseif):E582: :elseif without :if') + + " multiple :else + let code =<< trim END + if 1 + else + else + endif + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(else):E583: multiple :else') + + " :elseif after :else + let code =<< trim END + if 1 + else + elseif 1 + endif + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(elseif):E584: :elseif after :else') + + call delete('Xtest') +endfunc + +"------------------------------------------------------------------------------- +" Test 54: Nesting errors: :while/:endwhile {{{1 +" +" For nesting errors of :while conditionals the correct error messages +" should be given. +" +" This test reuses the function MESSAGES() from the previous test. +" This functions checks the messages in g:msgfile. +"------------------------------------------------------------------------------- + +func Test_nested_while_error() + CheckEnglish + + " :endwhile without :while + let code =<< trim END + endwhile + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endwhile):E588: :endwhile without :while') + + " :endwhile without :while + let code =<< trim END + if 1 + endwhile + endif + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endwhile):E588: :endwhile without :while') + + " Missing :endif + let code =<< trim END + while 1 + if 1 + endwhile + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endwhile):E171: Missing :endif') + + " :endwhile without :while + let code =<< trim END + try + finally + endwhile + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endwhile):E588: :endwhile without :while') + + " Missing :endtry + let code =<< trim END + while 1 + try + finally + endwhile + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endwhile):E600: Missing :endtry') + + " Missing :endtry + let code =<< trim END + while 1 + if 1 + try + finally + endwhile + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endwhile):E600: Missing :endtry') + + " Missing :endif + let code =<< trim END + while 1 + try + finally + if 1 + endwhile + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endwhile):E171: Missing :endif') + + " :endwhile without :while + let code =<< trim END + try + endwhile + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endwhile):E588: :endwhile without :while') + + " :endwhile without :while + let code =<< trim END + while 1 + try + endwhile + endtry + endwhile + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endwhile):E588: :endwhile without :while') + + " :endwhile without :while + let code =<< trim END + try + throw "a" + catch /a/ + endwhile + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endwhile):E588: :endwhile without :while') + + " :endwhile without :while + let code =<< trim END + while 1 + try + throw "a" + catch /a/ + endwhile + endtry + endwhile + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endwhile):E588: :endwhile without :while') + + call delete('Xtest') +endfunc + +"------------------------------------------------------------------------------- +" Test 55: Nesting errors: :continue/:break {{{1 +" +" For nesting errors of :continue and :break commands the correct +" error messages should be given. +" +" This test reuses the function MESSAGES() from the previous test. +" This functions checks the messages in g:msgfile. +"------------------------------------------------------------------------------- + +func Test_nested_cont_break_error() + CheckEnglish + + " :continue without :while + let code =<< trim END + continue + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(continue):E586: :continue without :while or :for') + + " :continue without :while + let code =<< trim END + if 1 + continue + endif + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(continue):E586: :continue without :while or :for') + + " :continue without :while + let code =<< trim END + try + finally + continue + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(continue):E586: :continue without :while or :for') + + " :continue without :while + let code =<< trim END + try + continue + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(continue):E586: :continue without :while or :for') + + " :continue without :while + let code =<< trim END + try + throw "a" + catch /a/ + continue + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(continue):E586: :continue without :while or :for') + + " :break without :while + let code =<< trim END + break + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(break):E587: :break without :while or :for') + + " :break without :while + let code =<< trim END + if 1 + break + endif + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(break):E587: :break without :while or :for') + + " :break without :while + let code =<< trim END + try + finally + break + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(break):E587: :break without :while or :for') + + " :break without :while + let code =<< trim END + try + break + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(break):E587: :break without :while or :for') + + " :break without :while + let code =<< trim END + try + throw "a" + catch /a/ + break + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(break):E587: :break without :while or :for') + + call delete('Xtest') +endfunc + +"------------------------------------------------------------------------------- +" Test 56: Nesting errors: :endtry {{{1 +" +" For nesting errors of :try conditionals the correct error messages +" should be given. +" +" This test reuses the function MESSAGES() from the previous test. +" This functions checks the messages in g:msgfile. +"------------------------------------------------------------------------------- + +func Test_nested_endtry_error() + CheckEnglish + + " :endtry without :try + let code =<< trim END + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endtry):E602: :endtry without :try') + + " :endtry without :try + let code =<< trim END + if 1 + endtry + endif + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endtry):E602: :endtry without :try') + + " :endtry without :try + let code =<< trim END + while 1 + endtry + endwhile + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endtry):E602: :endtry without :try') + + " Missing :endif + let code =<< trim END + try + if 1 + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endtry):E171: Missing :endif') + + " Missing :endwhile + let code =<< trim END + try + while 1 + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endtry):E170: Missing :endwhile') + + " Missing :endif + let code =<< trim END + try + finally + if 1 + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endtry):E171: Missing :endif') + + " Missing :endwhile + let code =<< trim END + try + finally + while 1 + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endtry):E170: Missing :endwhile') + + " Missing :endif + let code =<< trim END + try + throw "a" + catch /a/ + if 1 + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endtry):E171: Missing :endif') + + " Missing :endwhile + let code =<< trim END + try + throw "a" + catch /a/ + while 1 + endtry + END + call writefile(code, 'Xtest') + call AssertException(['source Xtest'], 'Vim(endtry):E170: Missing :endwhile') + + call delete('Xtest') +endfunc + +"------------------------------------------------------------------------------- +" Test 57: v:exception and v:throwpoint for user exceptions {{{1 +" +" v:exception evaluates to the value of the exception that was caught +" most recently and is not finished. (A caught exception is finished +" when the next ":catch", ":finally", or ":endtry" is reached.) +" v:throwpoint evaluates to the script/function name and line number +" where that exception has been thrown. +"------------------------------------------------------------------------------- + +func Test_user_exception_info() + CheckEnglish + + XpathINIT + XloopINIT + + func FuncException() + let g:exception = v:exception + endfunc + + func FuncThrowpoint() + let g:throwpoint = v:throwpoint + endfunc + + let scriptException = MakeScript("FuncException") + let scriptThrowPoint = MakeScript("FuncThrowpoint") + + command! CmdException let g:exception = v:exception + command! CmdThrowpoint let g:throwpoint = v:throwpoint + + func T(arg, line) + if a:line == 2 + throw a:arg " in line 2 + elseif a:line == 4 + throw a:arg " in line 4 + elseif a:line == 6 + throw a:arg " in line 6 + elseif a:line == 8 + throw a:arg " in line 8 + endif + endfunc + + func G(arg, line) + call T(a:arg, a:line) + endfunc + + func F(arg, line) + call G(a:arg, a:line) + endfunc + + let scriptT = MakeScript("T") + let scriptG = MakeScript("G", scriptT) + let scriptF = MakeScript("F", scriptG) + + try + Xpath 'a' + call F("oops", 2) + catch /.*/ + Xpath 'b' + let exception = v:exception + let throwpoint = v:throwpoint + call assert_equal("oops", v:exception) + call assert_match('\', v:throwpoint) + call assert_match('\<2\>', v:throwpoint) + + exec "let exception = v:exception" + exec "let throwpoint = v:throwpoint" + call assert_equal("oops", v:exception) + call assert_match('\', v:throwpoint) + call assert_match('\<2\>', v:throwpoint) + + CmdException + CmdThrowpoint + call assert_equal("oops", v:exception) + call assert_match('\', v:throwpoint) + call assert_match('\<2\>', v:throwpoint) + + call FuncException() + call FuncThrowpoint() + call assert_equal("oops", v:exception) + call assert_match('\', v:throwpoint) + call assert_match('\<2\>', v:throwpoint) + + exec "source" scriptException + exec "source" scriptThrowPoint + call assert_equal("oops", v:exception) + call assert_match('\', v:throwpoint) + call assert_match('\<2\>', v:throwpoint) + + try + Xpath 'c' + call G("arrgh", 4) + catch /.*/ + Xpath 'd' + let exception = v:exception + let throwpoint = v:throwpoint + call assert_equal("arrgh", v:exception) + call assert_match('\', v:throwpoint) + call assert_match('\<4\>', v:throwpoint) + + try + Xpath 'e' + let g:arg = "autsch" + let g:line = 6 + exec "source" scriptF + catch /.*/ + Xpath 'f' + let exception = v:exception + let throwpoint = v:throwpoint + call assert_equal("autsch", v:exception) + call assert_match(fnamemodify(scriptT, ':t'), v:throwpoint) + call assert_match('\<6\>', v:throwpoint) + finally + Xpath 'g' + let exception = v:exception + let throwpoint = v:throwpoint + call assert_equal("arrgh", v:exception) + call assert_match('\', v:throwpoint) + call assert_match('\<4\>', v:throwpoint) + try + Xpath 'h' + let g:arg = "brrrr" + let g:line = 8 + exec "source" scriptG + catch /.*/ + Xpath 'i' + let exception = v:exception + let throwpoint = v:throwpoint + " Resolve scriptT for matching it against v:throwpoint. + call assert_equal("brrrr", v:exception) + call assert_match(fnamemodify(scriptT, ':t'), v:throwpoint) + call assert_match('\<8\>', v:throwpoint) + finally + Xpath 'j' + let exception = v:exception + let throwpoint = v:throwpoint + call assert_equal("arrgh", v:exception) + call assert_match('\', v:throwpoint) + call assert_match('\<4\>', v:throwpoint) + endtry + Xpath 'k' + let exception = v:exception + let throwpoint = v:throwpoint + call assert_equal("arrgh", v:exception) + call assert_match('\', v:throwpoint) + call assert_match('\<4\>', v:throwpoint) + endtry + Xpath 'l' + let exception = v:exception + let throwpoint = v:throwpoint + call assert_equal("arrgh", v:exception) + call assert_match('\', v:throwpoint) + call assert_match('\<4\>', v:throwpoint) + finally + Xpath 'm' + let exception = v:exception + let throwpoint = v:throwpoint + call assert_equal("oops", v:exception) + call assert_match('\', v:throwpoint) + call assert_match('\<2\>', v:throwpoint) + endtry + Xpath 'n' + let exception = v:exception + let throwpoint = v:throwpoint + call assert_equal("oops", v:exception) + call assert_match('\', v:throwpoint) + call assert_match('\<2\>', v:throwpoint) + finally + Xpath 'o' + let exception = v:exception + let throwpoint = v:throwpoint + call assert_equal("", v:exception) + call assert_match('^$', v:throwpoint) + call assert_match('^$', v:throwpoint) + endtry + + call assert_equal('abcdefghijklmno', g:Xpath) + + unlet exception throwpoint + delfunction FuncException + delfunction FuncThrowpoint + call delete(scriptException) + call delete(scriptThrowPoint) + unlet scriptException scriptThrowPoint + delcommand CmdException + delcommand CmdThrowpoint + delfunction T + delfunction G + delfunction F + call delete(scriptT) + call delete(scriptG) + call delete(scriptF) + unlet scriptT scriptG scriptF +endfunc + +"------------------------------------------------------------------------------- +" +" Test 58: v:exception and v:throwpoint for error/interrupt exceptions {{{1 +" +" v:exception and v:throwpoint work also for error and interrupt +" exceptions. +"------------------------------------------------------------------------------- + +func Test_execption_info_for_error() + CheckEnglish + + let test =<< trim [CODE] + func T(line) + if a:line == 2 + delfunction T " error (function in use) in line 2 + elseif a:line == 4 + call interrupt() + endif + endfunc + + while 1 + try + Xpath 'a' + call T(2) + call assert_report('should not get here') + catch /.*/ + Xpath 'b' + if v:exception !~ 'Vim(delfunction):' + call assert_report('should not get here') + endif + if v:throwpoint !~ '\' + call assert_report('should not get here') + endif + if v:throwpoint !~ '\<2\>' + call assert_report('should not get here') + endif + finally + Xpath 'c' + if v:exception != "" + call assert_report('should not get here') + endif + if v:throwpoint != "" + call assert_report('should not get here') + endif + break + endtry + endwhile + + Xpath 'd' + if v:exception != "" + call assert_report('should not get here') + endif + if v:throwpoint != "" + call assert_report('should not get here') + endif + + while 1 + try + Xpath 'e' + call T(4) + call assert_report('should not get here') + catch /.*/ + Xpath 'f' + if v:exception != 'Vim:Interrupt' + call assert_report('should not get here') + endif + if v:throwpoint !~ 'function T' + call assert_report('should not get here') + endif + if v:throwpoint !~ '\<4\>' + call assert_report('should not get here') + endif + finally + Xpath 'g' + if v:exception != "" + call assert_report('should not get here') + endif + if v:throwpoint != "" + call assert_report('should not get here') + endif + break + endtry + endwhile + + Xpath 'h' + if v:exception != "" + call assert_report('should not get here') + endif + if v:throwpoint != "" + call assert_report('should not get here') + endif + [CODE] + let verify =<< trim [CODE] + call assert_equal('abcdefgh', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 61: Catching interrupt exceptions {{{1 +" +" When an interrupt occurs inside a :try/:endtry region, an +" interrupt exception is thrown and can be caught. Its value is +" "Vim:Interrupt". If the interrupt occurs after an error or a :throw +" but before a matching :catch is reached, all following :catches of +" that try block are ignored, but the interrupt exception can be +" caught by the next surrounding try conditional. An interrupt is +" ignored when there is a previous interrupt that has not been caught +" or causes a :finally clause to be executed. +"------------------------------------------------------------------------------- + +func Test_catch_intr_exception() + let test =<< trim [CODE] + while 1 + try + try + Xpath 'a' + call interrupt() + call assert_report('should not get here') + catch /^Vim:Interrupt$/ + Xpath 'b' + finally + Xpath 'c' + endtry + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'd' + break + endtry + endwhile + + while 1 + try + try + try + Xpath 'e' + asdf + call assert_report('should not get here') + catch /do_not_catch/ + call assert_report('should not get here') + catch /.*/ + Xpath 'f' + call interrupt() + call assert_report('should not get here') + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'g' + call interrupt() + call assert_report('should not get here') + endtry + catch /^Vim:Interrupt$/ + Xpath 'h' + finally + Xpath 'i' + endtry + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'j' + break + endtry + endwhile + + while 1 + try + try + try + Xpath 'k' + throw "x" + call assert_report('should not get here') + catch /do_not_catch/ + call assert_report('should not get here') + catch /x/ + Xpath 'l' + call interrupt() + call assert_report('should not get here') + catch /.*/ + call assert_report('should not get here') + endtry + catch /^Vim:Interrupt$/ + Xpath 'm' + finally + Xpath 'n' + endtry + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'o' + break + endtry + endwhile + + while 1 + try + try + Xpath 'p' + call interrupt() + call assert_report('should not get here') + catch /do_not_catch/ + call interrupt() + call assert_report('should not get here') + catch /^Vim:Interrupt$/ + Xpath 'q' + finally + Xpath 'r' + endtry + catch /.*/ + call assert_report('should not get here') + finally + Xpath 's' + break + endtry + endwhile + + Xpath 't' + [CODE] + let verify =<< trim [CODE] + call assert_equal('abcdefghijklmnopqrst', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 65: Errors in the /pattern/ argument of a :catch {{{1 +" +" On an error in the /pattern/ argument of a :catch, the :catch does +" not match. Any following :catches of the same :try/:endtry don't +" match either. Finally clauses are executed. +"------------------------------------------------------------------------------- + +func Test_catch_pattern_error() + CheckEnglish + XpathINIT + + try + try + Xpath 'a' + throw "oops" + catch /^oops$/ + Xpath 'b' + catch /\)/ " not checked; exception has already been caught + call assert_report('should not get here') + endtry + Xpath 'c' + catch /.*/ + call assert_report('should not get here') + endtry + call assert_equal('abc', g:Xpath) + + XpathINIT + func F() + try + try + try + Xpath 'a' + throw "ab" + catch /abc/ " does not catch + call assert_report('should not get here') + catch /\)/ " error; discards exception + call assert_report('should not get here') + catch /.*/ " not checked + call assert_report('should not get here') + finally + Xpath 'b' + endtry + call assert_report('should not get here') + catch /^ab$/ " checked, but original exception is discarded + call assert_report('should not get here') + catch /^Vim(catch):/ + Xpath 'c' + call assert_match('Vim(catch):E475: Invalid argument:', v:exception) + finally + Xpath 'd' + endtry + Xpath 'e' + catch /.*/ + call assert_report('should not get here') + endtry + Xpath 'f' + endfunc + + call F() + call assert_equal('abcdef', g:Xpath) + + delfunc F +endfunc + "------------------------------------------------------------------------------- " Test 87 using (expr) ? funcref : funcref {{{1 " -- cgit From 13381692cd191fe003e77215f01483bb34b3917e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 20:35:54 +0800 Subject: vim-patch:8.2.1417: test 49 is old style Problem: Test 49 is old style. Solution: Convert more parts to new style test. (Yegappan Lakshmanan, closes vim/vim#6682) https://github.com/vim/vim/commit/efb6482949580ab89e6d7c5e1cb8d744ddd6ef80 --- src/nvim/testdir/test49.ok | 14 - src/nvim/testdir/test49.vim | 2467 +---------------------------------- src/nvim/testdir/test_vimscript.vim | 2055 ++++++++++++++++++++++++++++- 3 files changed, 2023 insertions(+), 2513 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test49.ok b/src/nvim/testdir/test49.ok index 8ca8a564c3..d687f5bc77 100644 --- a/src/nvim/testdir/test49.ok +++ b/src/nvim/testdir/test49.ok @@ -1,18 +1,4 @@ Results of test49.vim: -*** Test 59: OK (2038431743) -*** Test 60: OK (311511339) -*** Test 62: OK (286331153) -*** Test 63: OK (236978127) -*** Test 64: OK (1499645335) -*** Test 66: OK (5464) -*** Test 67: OK (212514423) -*** Test 68: OK (212514423) -*** Test 76: OK (1610087935) -*** Test 77: OK (1388671) -*** Test 78: OK (134217728) -*** Test 79: OK (70288929) -*** Test 80: OK (17895765) -*** Test 81: OK (387) *** Test 82: OK (8454401) *** Test 83: OK (2835) *** Test 84: OK (934782101) diff --git a/src/nvim/testdir/test49.vim b/src/nvim/testdir/test49.vim index 6133f410ac..d5f8cd3b60 100644 --- a/src/nvim/testdir/test49.vim +++ b/src/nvim/testdir/test49.vim @@ -648,2468 +648,11 @@ function! MESSAGES(...) return match endfunction -" Leave MESSAGES() for the next tests. - -" Tests 1 to 50, 52 to 57, 87 were moved to test_vimscript.vim -" Tests 25, 26, 32, 33, 41-48, 51, 69-75 were moved to test_trycatch.vim -let Xtest = 59 - -"------------------------------------------------------------------------------- -" -" Test 59: v:exception and v:throwpoint when discarding exceptions {{{1 -" -" When a :catch clause is left by a ":break" etc or an error or -" interrupt exception, v:exception and v:throwpoint are reset. They -" are not affected by an exception that is discarded before being -" caught. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - - XloopINIT! 1 2 - - let sfile = expand("") - - function! LineNumber() - return substitute(substitute(v:throwpoint, g:sfile, '', ""), - \ '\D*\(\d*\).*', '\1', "") - endfunction - - command! -nargs=1 SetLineNumber - \ try | throw "line" | catch /.*/ | let = LineNumber() | endtry - - " Check v:exception/v:throwpoint against second/fourth parameter if - " specified, check for being empty else. - function! CHECK(n, ...) - XloopNEXT - let exception = a:0 != 0 ? a:1 : "" " second parameter (optional) - let emsg = a:0 != 0 ? a:2 : "" " third parameter (optional) - let line = a:0 != 0 ? a:3 : 0 " fourth parameter (optional) - let error = 0 - if emsg != "" - " exception is the error number, emsg the English error message text - if exception !~ '^E\d\+$' - Xout "TODO: Add message number for:" emsg - elseif v:lang == "C" || v:lang =~ '^[Ee]n' - if exception == "E492" && emsg == "Not an editor command" - let exception = '^Vim:' . exception . ': ' . emsg - else - let exception = '^Vim(\a\+):' . exception . ': ' . emsg - endif - else - if exception == "E492" - let exception = '^Vim:' . exception - else - let exception = '^Vim(\a\+):' . exception - endif - endif - endif - if exception == "" && v:exception != "" - Xout a:n.": v:exception is set:" v:exception - let error = 1 - elseif exception != "" && v:exception !~ exception - Xout a:n.": v:exception (".v:exception.") does not match" exception - let error = 1 - endif - if line == 0 && v:throwpoint != "" - Xout a:n.": v:throwpoint is set:" v:throwpoint - let error = 1 - elseif line != 0 && v:throwpoint !~ '\<' . line . '\>' - Xout a:n.": v:throwpoint (".v:throwpoint.") does not match" line - let error = 1 - endif - if !error - Xloop 1 " X: 2097151 - endif - endfunction - - while 1 - try - throw "x1" - catch /.*/ - break - endtry - endwhile - call CHECK(1) - - while 1 - try - throw "x2" - catch /.*/ - break - finally - call CHECK(2) - endtry - break - endwhile - call CHECK(3) - - while 1 - try - let errcaught = 0 - try - try - throw "x3" - catch /.*/ - SetLineNumber line_before_error - asdf - endtry - catch /.*/ - let errcaught = 1 - call CHECK(4, 'E492', "Not an editor command", - \ line_before_error + 1) - endtry - finally - if !errcaught && $VIMNOERRTHROW - call CHECK(4) - endif - break " discard error for $VIMNOERRTHROW - endtry - endwhile - call CHECK(5) - - Xpath 2097152 " X: 2097152 - - while 1 - try - let intcaught = 0 - try - try - throw "x4" - catch /.*/ - SetLineNumber two_lines_before_interrupt - "INTERRUPT - let dummy = 0 - endtry - catch /.*/ - let intcaught = 1 - call CHECK(6, "Vim:Interrupt", '', - \ two_lines_before_interrupt + 2) - endtry - finally - if !intcaught && $VIMNOINTTHROW - call CHECK(6) - endif - break " discard interrupt for $VIMNOINTTHROW - endtry - endwhile - call CHECK(7) - - Xpath 4194304 " X: 4194304 - - while 1 - try - let errcaught = 0 - try - try -" if 1 - SetLineNumber line_before_throw - throw "x5" - " missing endif - catch /.*/ - Xpath 8388608 " X: 0 - endtry - catch /.*/ - let errcaught = 1 - call CHECK(8, 'E171', "Missing :endif", line_before_throw + 3) - endtry - finally - if !errcaught && $VIMNOERRTHROW - call CHECK(8) - endif - break " discard error for $VIMNOERRTHROW - endtry - endwhile - call CHECK(9) - - Xpath 16777216 " X: 16777216 - - try - while 1 - try - throw "x6" - finally - break - endtry - break - endwhile - catch /.*/ - Xpath 33554432 " X: 0 - endtry - call CHECK(10) - - try - while 1 - try - throw "x7" - finally - break - endtry - break - endwhile - catch /.*/ - Xpath 67108864 " X: 0 - finally - call CHECK(11) - endtry - call CHECK(12) - - while 1 - try - let errcaught = 0 - try - try - throw "x8" - finally - SetLineNumber line_before_error - asdf - endtry - catch /.*/ - let errcaught = 1 - call CHECK(13, 'E492', "Not an editor command", - \ line_before_error + 1) - endtry - finally - if !errcaught && $VIMNOERRTHROW - call CHECK(13) - endif - break " discard error for $VIMNOERRTHROW - endtry - endwhile - call CHECK(14) - - Xpath 134217728 " X: 134217728 - - while 1 - try - let intcaught = 0 - try - try - throw "x9" - finally - SetLineNumber two_lines_before_interrupt - "INTERRUPT - endtry - catch /.*/ - let intcaught = 1 - call CHECK(15, "Vim:Interrupt", '', - \ two_lines_before_interrupt + 2) - endtry - finally - if !intcaught && $VIMNOINTTHROW - call CHECK(15) - endif - break " discard interrupt for $VIMNOINTTHROW - endtry - endwhile - call CHECK(16) - - Xpath 268435456 " X: 268435456 - - while 1 - try - let errcaught = 0 - try - try -" if 1 - SetLineNumber line_before_throw - throw "x10" - " missing endif - finally - call CHECK(17) - endtry - catch /.*/ - let errcaught = 1 - call CHECK(18, 'E171', "Missing :endif", line_before_throw + 3) - endtry - finally - if !errcaught && $VIMNOERRTHROW - call CHECK(18) - endif - break " discard error for $VIMNOERRTHROW - endtry - endwhile - call CHECK(19) - - Xpath 536870912 " X: 536870912 - - while 1 - try - let errcaught = 0 - try - try -" if 1 - SetLineNumber line_before_throw - throw "x11" - " missing endif - endtry - catch /.*/ - let errcaught = 1 - call CHECK(20, 'E171', "Missing :endif", line_before_throw + 3) - endtry - finally - if !errcaught && $VIMNOERRTHROW - call CHECK(20) - endif - break " discard error for $VIMNOERRTHROW - endtry - endwhile - call CHECK(21) - - Xpath 1073741824 " X: 1073741824 - -endif - -Xcheck 2038431743 - - -"------------------------------------------------------------------------------- -" -" Test 60: (Re)throwing v:exception; :echoerr. {{{1 -" -" A user exception can be rethrown after catching by throwing -" v:exception. An error or interrupt exception cannot be rethrown -" because Vim exceptions cannot be faked. A Vim exception using the -" value of v:exception can, however, be triggered by the :echoerr -" command. -"------------------------------------------------------------------------------- - -XpathINIT - -try - try - Xpath 1 " X: 1 - throw "oops" - catch /oops/ - Xpath 2 " X: 2 - throw v:exception " rethrow user exception - catch /.*/ - Xpath 4 " X: 0 - endtry -catch /^oops$/ " catches rethrown user exception - Xpath 8 " X: 8 -catch /.*/ - Xpath 16 " X: 0 -endtry - -function! F() - try - let caught = 0 - try - Xpath 32 " X: 32 - write /n/o/n/w/r/i/t/a/b/l/e/_/f/i/l/e - Xpath 64 " X: 0 - Xout "did_emsg was reset before executing " . - \ "BufWritePost autocommands." - catch /^Vim(write):/ - let caught = 1 - throw v:exception " throw error: cannot fake Vim exception - catch /.*/ - Xpath 128 " X: 0 - finally - Xpath 256 " X: 256 - if !caught && !$VIMNOERRTHROW - Xpath 512 " X: 0 - endif - endtry - catch /^Vim(throw):/ " catches throw error - let caught = caught + 1 - catch /.*/ - Xpath 1024 " X: 0 - finally - Xpath 2048 " X: 2048 - if caught != 2 - if !caught && !$VIMNOERRTHROW - Xpath 4096 " X: 0 - elseif caught - Xpath 8192 " X: 0 - endif - return | " discard error for $VIMNOERRTHROW - endif - endtry -endfunction - -call F() -delfunction F - -function! G() - try - let caught = 0 - try - Xpath 16384 " X: 16384 - asdf - catch /^Vim/ " catch error exception - let caught = 1 - " Trigger Vim error exception with value specified after :echoerr - let value = substitute(v:exception, '^Vim\((.*)\)\=:', '', "") - echoerr value - catch /.*/ - Xpath 32768 " X: 0 - finally - Xpath 65536 " X: 65536 - if !caught - if !$VIMNOERRTHROW - Xpath 131072 " X: 0 - else - let value = "Error" - echoerr value - endif - endif - endtry - catch /^Vim(echoerr):/ - let caught = caught + 1 - if v:exception !~ value - Xpath 262144 " X: 0 - endif - catch /.*/ - Xpath 524288 " X: 0 - finally - Xpath 1048576 " X: 1048576 - if caught != 2 - if !caught && !$VIMNOERRTHROW - Xpath 2097152 " X: 0 - elseif caught - Xpath 4194304 " X: 0 - endif - return | " discard error for $VIMNOERRTHROW - endif - endtry -endfunction - -call G() -delfunction G - -unlet! value caught - -if ExtraVim() - try - let errcaught = 0 - try - Xpath 8388608 " X: 8388608 - let intcaught = 0 - "INTERRUPT - catch /^Vim:/ " catch interrupt exception - let intcaught = 1 - " Trigger Vim error exception with value specified after :echoerr - echoerr substitute(v:exception, '^Vim\((.*)\)\=:', '', "") - catch /.*/ - Xpath 16777216 " X: 0 - finally - Xpath 33554432 " X: 33554432 - if !intcaught - if !$VIMNOINTTHROW - Xpath 67108864 " X: 0 - else - echoerr "Interrupt" - endif - endif - endtry - catch /^Vim(echoerr):/ - let errcaught = 1 - if v:exception !~ "Interrupt" - Xpath 134217728 " X: 0 - endif - finally - Xpath 268435456 " X: 268435456 - if !errcaught && !$VIMNOERRTHROW - Xpath 536870912 " X: 0 - endif - endtry -endif - -Xcheck 311511339 - -" Test 61 was moved to test_vimscript.vim -let Xtest = 62 - -"------------------------------------------------------------------------------- -" Test 62: Catching error exceptions {{{1 -" -" An error inside a :try/:endtry region is converted to an exception -" and can be caught. The error exception has a "Vim(cmdname):" prefix -" where cmdname is the name of the failing command, or a "Vim:" prefix -" if no command name is known. The "Vim" prefixes cannot be faked. -"------------------------------------------------------------------------------- - -XpathINIT - -function! MSG(enr, emsg) - let english = v:lang == "C" || v:lang =~ '^[Ee]n' - if a:enr == "" - Xout "TODO: Add message number for:" a:emsg - let v:errmsg = ":" . v:errmsg - endif - let match = 1 - if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg) - let match = 0 - if v:errmsg == "" - Xout "Message missing." - else - let v:errmsg = escape(v:errmsg, '"') - Xout "Unexpected message:" v:errmsg - endif - endif - return match -endfunction - -while 1 - try - try - let caught = 0 - unlet novar - catch /^Vim(unlet):/ - let caught = 1 - let v:errmsg = substitute(v:exception, '^Vim(unlet):', '', "") - finally - Xpath 1 " X: 1 - if !caught && !$VIMNOERRTHROW - Xpath 2 " X: 0 - endif - if !MSG('E108', "No such variable") - Xpath 4 " X: 0 - endif - endtry - catch /.*/ - Xpath 8 " X: 0 - Xout v:exception "in" v:throwpoint - finally - break " discard error for $VIMNOERRTHROW - endtry -endwhile - -while 1 - try - try - let caught = 0 - throw novar " error in :throw - catch /^Vim(throw):/ - let caught = 1 - let v:errmsg = substitute(v:exception, '^Vim(throw):', '', "") - finally - Xpath 16 " X: 16 - if !caught && !$VIMNOERRTHROW - Xpath 32 " X: 0 - endif - if caught ? !MSG('E121', "Undefined variable") - \ : !MSG('E15', "Invalid expression") - Xpath 64 " X: 0 - endif - endtry - catch /.*/ - Xpath 128 " X: 0 - Xout v:exception "in" v:throwpoint - finally - break " discard error for $VIMNOERRTHROW - endtry -endwhile - -while 1 - try - try - let caught = 0 - throw "Vim:faked" " error: cannot fake Vim exception - catch /^Vim(throw):/ - let caught = 1 - let v:errmsg = substitute(v:exception, '^Vim(throw):', '', "") - finally - Xpath 256 " X: 256 - if !caught && !$VIMNOERRTHROW - Xpath 512 " X: 0 - endif - if !MSG('E608', "Cannot :throw exceptions with 'Vim' prefix") - Xpath 1024 " X: 0 - endif - endtry - catch /.*/ - Xpath 2048 " X: 0 - Xout v:exception "in" v:throwpoint - finally - break " discard error for $VIMNOERRTHROW - endtry -endwhile - -function! F() - while 1 - " Missing :endwhile -endfunction - -while 1 - try - try - let caught = 0 - call F() - catch /^Vim(endfunction):/ - let caught = 1 - let v:errmsg = substitute(v:exception, '^Vim(endfunction):', '', "") - finally - Xpath 4096 " X: 4096 - if !caught && !$VIMNOERRTHROW - Xpath 8192 " X: 0 - endif - if !MSG('E170', "Missing :endwhile") - Xpath 16384 " X: 0 - endif - endtry - catch /.*/ - Xpath 32768 " X: 0 - Xout v:exception "in" v:throwpoint - finally - break " discard error for $VIMNOERRTHROW - endtry -endwhile - -while 1 - try - try - let caught = 0 - ExecAsScript F - catch /^Vim:/ - let caught = 1 - let v:errmsg = substitute(v:exception, '^Vim:', '', "") - finally - Xpath 65536 " X: 65536 - if !caught && !$VIMNOERRTHROW - Xpath 131072 " X: 0 - endif - if !MSG('E170', "Missing :endwhile") - Xpath 262144 " X: 0 - endif - endtry - catch /.*/ - Xpath 524288 " X: 0 - Xout v:exception "in" v:throwpoint - finally - break " discard error for $VIMNOERRTHROW - endtry -endwhile - -function! G() - call G() -endfunction - -while 1 - try - let mfd_save = &mfd - set mfd=3 - try - let caught = 0 - call G() - catch /^Vim(call):/ - let caught = 1 - let v:errmsg = substitute(v:exception, '^Vim(call):', '', "") - finally - Xpath 1048576 " X: 1048576 - if !caught && !$VIMNOERRTHROW - Xpath 2097152 " X: 0 - endif - if !MSG('E132', "Function call depth is higher than 'maxfuncdepth'") - Xpath 4194304 " X: 0 - endif - endtry - catch /.*/ - Xpath 8388608 " X: 0 - Xout v:exception "in" v:throwpoint - finally - let &mfd = mfd_save - break " discard error for $VIMNOERRTHROW - endtry -endwhile - -function! H() - return H() -endfunction - -while 1 - try - let mfd_save = &mfd - set mfd=3 - try - let caught = 0 - call H() - catch /^Vim(return):/ - let caught = 1 - let v:errmsg = substitute(v:exception, '^Vim(return):', '', "") - finally - Xpath 16777216 " X: 16777216 - if !caught && !$VIMNOERRTHROW - Xpath 33554432 " X: 0 - endif - if !MSG('E132', "Function call depth is higher than 'maxfuncdepth'") - Xpath 67108864 " X: 0 - endif - endtry - catch /.*/ - Xpath 134217728 " X: 0 - Xout v:exception "in" v:throwpoint - finally - let &mfd = mfd_save - break " discard error for $VIMNOERRTHROW - endtry -endwhile - -unlet! caught mfd_save -delfunction F -delfunction G -delfunction H -Xpath 268435456 " X: 268435456 - -Xcheck 286331153 - -" Leave MSG() for the next test. - - -"------------------------------------------------------------------------------- -" Test 63: Suppressing error exceptions by :silent!. {{{1 -" -" A :silent! command inside a :try/:endtry region suppresses the -" conversion of errors to an exception and the immediate abortion on -" error. When the commands executed by the :silent! themselves open -" a new :try/:endtry region, conversion of errors to exception and -" immediate abortion is switched on again - until the next :silent! -" etc. The :silent! has the effect of setting v:errmsg to the error -" message text (without displaying it) and continuing with the next -" script line. -" -" When a command triggering autocommands is executed by :silent! -" inside a :try/:endtry, the autocommand execution is not suppressed -" on error. -" -" This test reuses the function MSG() from the previous test. -"------------------------------------------------------------------------------- - -XpathINIT - -XloopINIT! 1 4 - -let taken = "" - -function! S(n) abort - XloopNEXT - let g:taken = g:taken . "E" . a:n - let v:errmsg = "" - exec "asdf" . a:n - - " Check that ":silent!" continues: - Xloop 1 - - " Check that ":silent!" sets "v:errmsg": - if MSG('E492', "Not an editor command") - Xloop 2 - endif -endfunction - -function! Foo() - while 1 - try - try - let caught = 0 - " This is not silent: - call S(3) " X: 0 * 16 - catch /^Vim:/ - let caught = 1 - let errmsg3 = substitute(v:exception, '^Vim:', '', "") - silent! call S(4) " X: 3 * 64 - finally - if !caught - let errmsg3 = v:errmsg - " Do call S(4) here if not executed in :catch. - silent! call S(4) - endif - Xpath 1048576 " X: 1048576 - if !caught && !$VIMNOERRTHROW - Xpath 2097152 " X: 0 - endif - let v:errmsg = errmsg3 - if !MSG('E492', "Not an editor command") - Xpath 4194304 " X: 0 - endif - silent! call S(5) " X: 3 * 256 - " Break out of try conditionals that cover ":silent!". This also - " discards the aborting error when $VIMNOERRTHROW is non-zero. - break - endtry - catch /.*/ - Xpath 8388608 " X: 0 - Xout v:exception "in" v:throwpoint - endtry - endwhile - " This is a double ":silent!" (see caller). - silent! call S(6) " X: 3 * 1024 -endfunction - -function! Bar() - try - silent! call S(2) " X: 3 * 4 - " X: 3 * 4096 - silent! execute "call Foo() | call S(7)" - silent! call S(8) " X: 3 * 16384 - endtry " normal end of try cond that covers ":silent!" - " This has a ":silent!" from the caller: - call S(9) " X: 3 * 65536 -endfunction - -silent! call S(1) " X: 3 * 1 -silent! call Bar() -silent! call S(10) " X: 3 * 262144 - -let expected = "E1E2E3E4E5E6E7E8E9E10" -if taken != expected - Xpath 16777216 " X: 0 - Xout "'taken' is" taken "instead of" expected -endif - -augroup TMP - autocmd BufWritePost * Xpath 33554432 " X: 33554432 -augroup END - -Xpath 67108864 " X: 67108864 -write /i/m/p/o/s/s/i/b/l/e -Xpath 134217728 " X: 134217728 - -autocmd! TMP -unlet! caught errmsg3 taken expected -delfunction S -delfunction Foo -delfunction Bar -delfunction MSG - -Xcheck 236978127 - - -"------------------------------------------------------------------------------- -" Test 64: Error exceptions after error, interrupt or :throw {{{1 -" -" When an error occurs after an interrupt or a :throw but before -" a matching :catch is reached, all following :catches of that try -" block are ignored, but the error exception can be caught by the next -" surrounding try conditional. Any previous error exception is -" discarded. An error is ignored when there is a previous error that -" has not been caught. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - - while 1 - try - try - Xpath 1 " X: 1 - let caught = 0 - while 1 -" if 1 - " Missing :endif - endwhile " throw error exception - catch /^Vim(/ - let caught = 1 - finally - Xpath 2 " X: 2 - if caught || $VIMNOERRTHROW - Xpath 4 " X: 4 - endif - endtry - catch /.*/ - Xpath 8 " X: 0 - Xout v:exception "in" v:throwpoint - finally - break " discard error for $VIMNOERRTHROW - endtry - endwhile - - while 1 - try - try - Xpath 16 " X: 16 - let caught = 0 - try -" if 1 - " Missing :endif - catch /.*/ " throw error exception - Xpath 32 " X: 0 - catch /.*/ - Xpath 64 " X: 0 - endtry - catch /^Vim(/ - let caught = 1 - finally - Xpath 128 " X: 128 - if caught || $VIMNOERRTHROW - Xpath 256 " X: 256 - endif - endtry - catch /.*/ - Xpath 512 " X: 0 - Xout v:exception "in" v:throwpoint - finally - break " discard error for $VIMNOERRTHROW - endtry - endwhile - - while 1 - try - try - let caught = 0 - try - Xpath 1024 " X: 1024 - "INTERRUPT - catch /do_not_catch/ - Xpath 2048 " X: 0 -" if 1 - " Missing :endif - catch /.*/ " throw error exception - Xpath 4096 " X: 0 - catch /.*/ - Xpath 8192 " X: 0 - endtry - catch /^Vim(/ - let caught = 1 - finally - Xpath 16384 " X: 16384 - if caught || $VIMNOERRTHROW - Xpath 32768 " X: 32768 - endif - endtry - catch /.*/ - Xpath 65536 " X: 0 - Xout v:exception "in" v:throwpoint - finally - break " discard error for $VIMNOERRTHROW - endtry - endwhile - - while 1 - try - try - let caught = 0 - try - Xpath 131072 " X: 131072 - throw "x" - catch /do_not_catch/ - Xpath 262144 " X: 0 -" if 1 - " Missing :endif - catch /x/ " throw error exception - Xpath 524288 " X: 0 - catch /.*/ - Xpath 1048576 " X: 0 - endtry - catch /^Vim(/ - let caught = 1 - finally - Xpath 2097152 " X: 2097152 - if caught || $VIMNOERRTHROW - Xpath 4194304 " X: 4194304 - endif - endtry - catch /.*/ - Xpath 8388608 " X: 0 - Xout v:exception "in" v:throwpoint - finally - break " discard error for $VIMNOERRTHROW - endtry - endwhile - - while 1 - try - try - let caught = 0 - Xpath 16777216 " X: 16777216 -" endif " :endif without :if; throw error exception -" if 1 - " Missing :endif - catch /do_not_catch/ " ignore new error - Xpath 33554432 " X: 0 - catch /^Vim(endif):/ - let caught = 1 - catch /^Vim(/ - Xpath 67108864 " X: 0 - finally - Xpath 134217728 " X: 134217728 - if caught || $VIMNOERRTHROW - Xpath 268435456 " X: 268435456 - endif - endtry - catch /.*/ - Xpath 536870912 " X: 0 - Xout v:exception "in" v:throwpoint - finally - break " discard error for $VIMNOERRTHROW - endtry - endwhile - - Xpath 1073741824 " X: 1073741824 - -endif - -Xcheck 1499645335 - -" Test 65 was moved to test_vimscript.vim -let Xtest = 66 - -"------------------------------------------------------------------------------- -" Test 66: Stop range :call on error, interrupt, or :throw {{{1 -" -" When a function which is multiply called for a range since it -" doesn't handle the range itself has an error in a command -" dynamically enclosed by :try/:endtry or gets an interrupt or -" executes a :throw, no more calls for the remaining lines in the -" range are made. On an error in a command not dynamically enclosed -" by :try/:endtry, the function is executed again for the remaining -" lines in the range. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - - let file = tempname() - exec "edit" file - - insert -line 1 -line 2 -line 3 -. - - XloopINIT! 1 2 - - let taken = "" - let expected = "G1EF1E(1)F1E(2)F1E(3)G2EF2E(1)G3IF3I(1)G4TF4T(1)G5AF5A(1)" - - function! F(reason, n) abort - let g:taken = g:taken . "F" . a:n . - \ substitute(a:reason, '\(\l\).*', '\u\1', "") . - \ "(" . line(".") . ")" - - if a:reason == "error" - asdf - elseif a:reason == "interrupt" - "INTERRUPT - let dummy = 0 - elseif a:reason == "throw" - throw "xyz" - elseif a:reason == "aborting error" - XloopNEXT - if g:taken != g:expected - Xloop 1 " X: 0 - Xout "'taken' is" g:taken "instead of" g:expected - endif - try - bwipeout! - call delete(file) - asdf - endtry - endif - endfunction - - function! G(reason, n) - let g:taken = g:taken . "G" . a:n . - \ substitute(a:reason, '\(\l\).*', '\u\1', "") - 1,3call F(a:reason, a:n) - endfunction - - Xpath 8 " X: 8 - call G("error", 1) - try - Xpath 16 " X: 16 - try - call G("error", 2) - Xpath 32 " X: 0 - finally - Xpath 64 " X: 64 - try - call G("interrupt", 3) - Xpath 128 " X: 0 - finally - Xpath 256 " X: 256 - try - call G("throw", 4) - Xpath 512 " X: 0 - endtry - endtry - endtry - catch /xyz/ - Xpath 1024 " X: 1024 - catch /.*/ - Xpath 2048 " X: 0 - Xout v:exception "in" ExtraVimThrowpoint() - endtry - Xpath 4096 " X: 4096 - call G("aborting error", 5) - Xpath 8192 " X: 0 - Xout "'taken' is" taken "instead of" expected - -endif - -Xcheck 5464 - - -"------------------------------------------------------------------------------- -" Test 67: :throw across :call command {{{1 -" -" On a call command, an exception might be thrown when evaluating the -" function name, during evaluation of the arguments, or when the -" function is being executed. The exception can be caught by the -" caller. -"------------------------------------------------------------------------------- - -XpathINIT - -function! THROW(x, n) - if a:n == 1 - Xpath 1 " X: 1 - elseif a:n == 2 - Xpath 2 " X: 2 - elseif a:n == 3 - Xpath 4 " X: 4 - endif - throw a:x -endfunction - -function! NAME(x, n) - if a:n == 1 - Xpath 8 " X: 0 - elseif a:n == 2 - Xpath 16 " X: 16 - elseif a:n == 3 - Xpath 32 " X: 32 - elseif a:n == 4 - Xpath 64 " X: 64 - endif - return a:x -endfunction - -function! ARG(x, n) - if a:n == 1 - Xpath 128 " X: 0 - elseif a:n == 2 - Xpath 256 " X: 0 - elseif a:n == 3 - Xpath 512 " X: 512 - elseif a:n == 4 - Xpath 1024 " X: 1024 - endif - return a:x -endfunction - -function! F(x, n) - if a:n == 2 - Xpath 2048 " X: 0 - elseif a:n == 4 - Xpath 4096 " X: 4096 - endif -endfunction - -while 1 - try - let error = 0 - let v:errmsg = "" - - while 1 - try - Xpath 8192 " X: 8192 - call {NAME(THROW("name", 1), 1)}(ARG(4711, 1), 1) - Xpath 16384 " X: 0 - catch /^name$/ - Xpath 32768 " X: 32768 - catch /.*/ - let error = 1 - Xout "1:" v:exception "in" v:throwpoint - finally - if !error && $VIMNOERRTHROW && v:errmsg != "" - let error = 1 - Xout "1:" v:errmsg - endif - if error - Xpath 65536 " X: 0 - endif - let error = 0 - let v:errmsg = "" - break " discard error for $VIMNOERRTHROW - endtry - endwhile - - while 1 - try - Xpath 131072 " X: 131072 - call {NAME("F", 2)}(ARG(THROW("arg", 2), 2), 2) - Xpath 262144 " X: 0 - catch /^arg$/ - Xpath 524288 " X: 524288 - catch /.*/ - let error = 1 - Xout "2:" v:exception "in" v:throwpoint - finally - if !error && $VIMNOERRTHROW && v:errmsg != "" - let error = 1 - Xout "2:" v:errmsg - endif - if error - Xpath 1048576 " X: 0 - endif - let error = 0 - let v:errmsg = "" - break " discard error for $VIMNOERRTHROW - endtry - endwhile - - while 1 - try - Xpath 2097152 " X: 2097152 - call {NAME("THROW", 3)}(ARG("call", 3), 3) - Xpath 4194304 " X: 0 - catch /^call$/ - Xpath 8388608 " X: 8388608 - catch /^0$/ " default return value - Xpath 16777216 " X: 0 - Xout "3:" v:throwpoint - catch /.*/ - let error = 1 - Xout "3:" v:exception "in" v:throwpoint - finally - if !error && $VIMNOERRTHROW && v:errmsg != "" - let error = 1 - Xout "3:" v:errmsg - endif - if error - Xpath 33554432 " X: 0 - endif - let error = 0 - let v:errmsg = "" - break " discard error for $VIMNOERRTHROW - endtry - endwhile - - while 1 - try - Xpath 67108864 " X: 67108864 - call {NAME("F", 4)}(ARG(4711, 4), 4) - Xpath 134217728 " X: 134217728 - catch /.*/ - let error = 1 - Xout "4:" v:exception "in" v:throwpoint - finally - if !error && $VIMNOERRTHROW && v:errmsg != "" - let error = 1 - Xout "4:" v:errmsg - endif - if error - Xpath 268435456 " X: 0 - endif - let error = 0 - let v:errmsg = "" - break " discard error for $VIMNOERRTHROW - endtry - endwhile - - catch /^0$/ " default return value - Xpath 536870912 " X: 0 - Xout v:throwpoint - catch /.*/ - let error = 1 - Xout v:exception "in" v:throwpoint - finally - if !error && $VIMNOERRTHROW && v:errmsg != "" - let error = 1 - Xout v:errmsg - endif - if error - Xpath 1073741824 " X: 0 - endif - break " discard error for $VIMNOERRTHROW - endtry -endwhile - -unlet error -delfunction F - -Xcheck 212514423 - -" Leave THROW(), NAME(), and ARG() for the next test. - - -"------------------------------------------------------------------------------- -" Test 68: :throw across function calls in expressions {{{1 -" -" On a function call within an expression, an exception might be -" thrown when evaluating the function name, during evaluation of the -" arguments, or when the function is being executed. The exception -" can be caught by the caller. -" -" This test reuses the functions THROW(), NAME(), and ARG() from the -" previous test. -"------------------------------------------------------------------------------- - -XpathINIT - -function! F(x, n) - if a:n == 2 - Xpath 2048 " X: 0 - elseif a:n == 4 - Xpath 4096 " X: 4096 - endif - return a:x -endfunction - -unlet! var1 var2 var3 var4 - -while 1 - try - let error = 0 - let v:errmsg = "" - - while 1 - try - Xpath 8192 " X: 8192 - let var1 = {NAME(THROW("name", 1), 1)}(ARG(4711, 1), 1) - Xpath 16384 " X: 0 - catch /^name$/ - Xpath 32768 " X: 32768 - catch /.*/ - let error = 1 - Xout "1:" v:exception "in" v:throwpoint - finally - if !error && $VIMNOERRTHROW && v:errmsg != "" - let error = 1 - Xout "1:" v:errmsg - endif - if error - Xpath 65536 " X: 0 - endif - let error = 0 - let v:errmsg = "" - break " discard error for $VIMNOERRTHROW - endtry - endwhile - - while 1 - try - Xpath 131072 " X: 131072 - let var2 = {NAME("F", 2)}(ARG(THROW("arg", 2), 2), 2) - Xpath 262144 " X: 0 - catch /^arg$/ - Xpath 524288 " X: 524288 - catch /.*/ - let error = 1 - Xout "2:" v:exception "in" v:throwpoint - finally - if !error && $VIMNOERRTHROW && v:errmsg != "" - let error = 1 - Xout "2:" v:errmsg - endif - if error - Xpath 1048576 " X: 0 - endif - let error = 0 - let v:errmsg = "" - break " discard error for $VIMNOERRTHROW - endtry - endwhile - - while 1 - try - Xpath 2097152 " X: 2097152 - let var3 = {NAME("THROW", 3)}(ARG("call", 3), 3) - Xpath 4194304 " X: 0 - catch /^call$/ - Xpath 8388608 " X: 8388608 - catch /^0$/ " default return value - Xpath 16777216 " X: 0 - Xout "3:" v:throwpoint - catch /.*/ - let error = 1 - Xout "3:" v:exception "in" v:throwpoint - finally - if !error && $VIMNOERRTHROW && v:errmsg != "" - let error = 1 - Xout "3:" v:errmsg - endif - if error - Xpath 33554432 " X: 0 - endif - let error = 0 - let v:errmsg = "" - break " discard error for $VIMNOERRTHROW - endtry - endwhile - - while 1 - try - Xpath 67108864 " X: 67108864 - let var4 = {NAME("F", 4)}(ARG(4711, 4), 4) - Xpath 134217728 " X: 134217728 - catch /.*/ - let error = 1 - Xout "4:" v:exception "in" v:throwpoint - finally - if !error && $VIMNOERRTHROW && v:errmsg != "" - let error = 1 - Xout "4:" v:errmsg - endif - if error - Xpath 268435456 " X: 0 - endif - let error = 0 - let v:errmsg = "" - break " discard error for $VIMNOERRTHROW - endtry - endwhile - - catch /^0$/ " default return value - Xpath 536870912 " X: 0 - Xout v:throwpoint - catch /.*/ - let error = 1 - Xout v:exception "in" v:throwpoint - finally - if !error && $VIMNOERRTHROW && v:errmsg != "" - let error = 1 - Xout v:errmsg - endif - if error - Xpath 1073741824 " X: 0 - endif - break " discard error for $VIMNOERRTHROW - endtry -endwhile - -if exists("var1") || exists("var2") || exists("var3") || - \ !exists("var4") || var4 != 4711 - " The Xpath command does not accept 2^31 (negative); add explicitly: - let Xpath = Xpath + 2147483648 " X: 0 - if exists("var1") - Xout "var1 =" var1 - endif - if exists("var2") - Xout "var2 =" var2 - endif - if exists("var3") - Xout "var3 =" var3 - endif - if !exists("var4") - Xout "var4 unset" - elseif var4 != 4711 - Xout "var4 =" var4 - endif -endif - -unlet! error var1 var2 var3 var4 -delfunction THROW -delfunction NAME -delfunction ARG -delfunction F - -Xcheck 212514423 - -" Tests 69 to 75 were moved to test_trycatch.vim -let Xtest = 76 - - -"------------------------------------------------------------------------------- -" Test 76: Errors, interrupts, :throw during expression evaluation {{{1 -" -" When a function call made during expression evaluation is aborted -" due to an error inside a :try/:endtry region or due to an interrupt -" or a :throw, the expression evaluation is aborted as well. No -" message is displayed for the cancelled expression evaluation. On an -" error not inside :try/:endtry, the expression evaluation continues. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - - let taken = "" - - function! ERR(n) - let g:taken = g:taken . "E" . a:n - asdf - endfunction - - function! ERRabort(n) abort - let g:taken = g:taken . "A" . a:n - asdf - endfunction " returns -1; may cause follow-up msg for illegal var/func name - - function! WRAP(n, arg) - let g:taken = g:taken . "W" . a:n - let g:saved_errmsg = v:errmsg - return arg - endfunction - - function! INT(n) - let g:taken = g:taken . "I" . a:n - "INTERRUPT9 - let dummy = 0 - endfunction - - function! THR(n) - let g:taken = g:taken . "T" . a:n - throw "should not be caught" - endfunction - - function! CONT(n) - let g:taken = g:taken . "C" . a:n - endfunction - - function! MSG(n) - let g:taken = g:taken . "M" . a:n - let errmsg = (a:n >= 37 && a:n <= 44) ? g:saved_errmsg : v:errmsg - let msgptn = (a:n >= 10 && a:n <= 27) ? "^$" : "asdf" - if errmsg !~ msgptn - let g:taken = g:taken . "x" - Xout "Expr" a:n.": Unexpected message:" v:errmsg - endif - let v:errmsg = "" - let g:saved_errmsg = "" - endfunction - - let v:errmsg = "" - - try - let t = 1 - XloopINIT 1 2 - while t <= 9 - Xloop 1 " X: 511 - try - if t == 1 - let v{ERR(t) + CONT(t)} = 0 - elseif t == 2 - let v{ERR(t) + CONT(t)} - elseif t == 3 - let var = exists('v{ERR(t) + CONT(t)}') - elseif t == 4 - unlet v{ERR(t) + CONT(t)} - elseif t == 5 - function F{ERR(t) + CONT(t)}() - endfunction - elseif t == 6 - function F{ERR(t) + CONT(t)} - elseif t == 7 - let var = exists('*F{ERR(t) + CONT(t)}') - elseif t == 8 - delfunction F{ERR(t) + CONT(t)} - elseif t == 9 - let var = ERR(t) + CONT(t) - endif - catch /asdf/ - " v:errmsg is not set when the error message is converted to an - " exception. Set it to the original error message. - let v:errmsg = substitute(v:exception, '^Vim:', '', "") - catch /^Vim\((\a\+)\)\=:/ - " An error exception has been thrown after the original error. - let v:errmsg = "" - finally - call MSG(t) - let t = t + 1 - XloopNEXT - continue " discard an aborting error - endtry - endwhile - catch /.*/ - Xpath 512 " X: 0 - Xout v:exception "in" ExtraVimThrowpoint() - endtry - - try - let t = 10 - XloopINIT 1024 2 - while t <= 18 - Xloop 1 " X: 1024 * 511 - try - if t == 10 - let v{INT(t) + CONT(t)} = 0 - elseif t == 11 - let v{INT(t) + CONT(t)} - elseif t == 12 - let var = exists('v{INT(t) + CONT(t)}') - elseif t == 13 - unlet v{INT(t) + CONT(t)} - elseif t == 14 - function F{INT(t) + CONT(t)}() - endfunction - elseif t == 15 - function F{INT(t) + CONT(t)} - elseif t == 16 - let var = exists('*F{INT(t) + CONT(t)}') - elseif t == 17 - delfunction F{INT(t) + CONT(t)} - elseif t == 18 - let var = INT(t) + CONT(t) - endif - catch /^Vim\((\a\+)\)\=:\(Interrupt\)\@!/ - " An error exception has been triggered after the interrupt. - let v:errmsg = substitute(v:exception, - \ '^Vim\((\a\+)\)\=:', '', "") - finally - call MSG(t) - let t = t + 1 - XloopNEXT - continue " discard interrupt - endtry - endwhile - catch /.*/ - Xpath 524288 " X: 0 - Xout v:exception "in" ExtraVimThrowpoint() - endtry - - try - let t = 19 - XloopINIT 1048576 2 - while t <= 27 - Xloop 1 " X: 1048576 * 511 - try - if t == 19 - let v{THR(t) + CONT(t)} = 0 - elseif t == 20 - let v{THR(t) + CONT(t)} - elseif t == 21 - let var = exists('v{THR(t) + CONT(t)}') - elseif t == 22 - unlet v{THR(t) + CONT(t)} - elseif t == 23 - function F{THR(t) + CONT(t)}() - endfunction - elseif t == 24 - function F{THR(t) + CONT(t)} - elseif t == 25 - let var = exists('*F{THR(t) + CONT(t)}') - elseif t == 26 - delfunction F{THR(t) + CONT(t)} - elseif t == 27 - let var = THR(t) + CONT(t) - endif - catch /^Vim\((\a\+)\)\=:/ - " An error exception has been triggered after the :throw. - let v:errmsg = substitute(v:exception, - \ '^Vim\((\a\+)\)\=:', '', "") - finally - call MSG(t) - let t = t + 1 - XloopNEXT - continue " discard exception - endtry - endwhile - catch /.*/ - Xpath 536870912 " X: 0 - Xout v:exception "in" ExtraVimThrowpoint() - endtry - - let v{ERR(28) + CONT(28)} = 0 - call MSG(28) - let v{ERR(29) + CONT(29)} - call MSG(29) - let var = exists('v{ERR(30) + CONT(30)}') - call MSG(30) - unlet v{ERR(31) + CONT(31)} - call MSG(31) - function F{ERR(32) + CONT(32)}() - endfunction - call MSG(32) - function F{ERR(33) + CONT(33)} - call MSG(33) - let var = exists('*F{ERR(34) + CONT(34)}') - call MSG(34) - delfunction F{ERR(35) + CONT(35)} - call MSG(35) - let var = ERR(36) + CONT(36) - call MSG(36) - - let saved_errmsg = "" - - let v{WRAP(37, ERRabort(37)) + CONT(37)} = 0 - call MSG(37) - let v{WRAP(38, ERRabort(38)) + CONT(38)} - call MSG(38) - let var = exists('v{WRAP(39, ERRabort(39)) + CONT(39)}') - call MSG(39) - unlet v{WRAP(40, ERRabort(40)) + CONT(40)} - call MSG(40) - function F{WRAP(41, ERRabort(41)) + CONT(41)}() - endfunction - call MSG(41) - function F{WRAP(42, ERRabort(42)) + CONT(42)} - call MSG(42) - let var = exists('*F{WRAP(43, ERRabort(43)) + CONT(43)}') - call MSG(43) - delfunction F{WRAP(44, ERRabort(44)) + CONT(44)} - call MSG(44) - let var = ERRabort(45) + CONT(45) - call MSG(45) - - Xpath 1073741824 " X: 1073741824 - - let expected = "" - \ . "E1M1E2M2E3M3E4M4E5M5E6M6E7M7E8M8E9M9" - \ . "I10M10I11M11I12M12I13M13I14M14I15M15I16M16I17M17I18M18" - \ . "T19M19T20M20T21M21T22M22T23M23T24M24T25M25T26M26T27M27" - \ . "E28C28M28E29C29M29E30C30M30E31C31M31E32C32M32E33C33M33" - \ . "E34C34M34E35C35M35E36C36M36" - \ . "A37W37C37M37A38W38C38M38A39W39C39M39A40W40C40M40A41W41C41M41" - \ . "A42W42C42M42A43W43C43M43A44W44C44M44A45C45M45" - - if taken != expected - " The Xpath command does not accept 2^31 (negative); display explicitly: - exec "!echo 2147483648 >>" . g:ExtraVimResult - " X: 0 - Xout "'taken' is" taken "instead of" expected - if substitute(taken, - \ '\(.*\)E3C3M3x\(.*\)E30C30M30x\(.*\)A39C39M39x\(.*\)', - \ '\1E3M3\2E30C30M30\3A39C39M39\4', - \ "") == expected - Xout "Is ++emsg_skip for var with expr_start non-NULL" - \ "in f_exists ok?" - endif - endif - - unlet! v var saved_errmsg taken expected - call delete(WA_t5) - call delete(WA_t14) - call delete(WA_t23) - unlet! WA_t5 WA_t14 WA_t23 - delfunction WA_t5 - delfunction WA_t14 - delfunction WA_t23 - -endif - -Xcheck 1610087935 - - -"------------------------------------------------------------------------------- -" Test 77: Errors, interrupts, :throw in name{brace-expression} {{{1 -" -" When a function call made during evaluation of an expression in -" braces as part of a function name after ":function" is aborted due -" to an error inside a :try/:endtry region or due to an interrupt or -" a :throw, the expression evaluation is aborted as well, and the -" function definition is ignored, skipping all commands to the -" ":endfunction". On an error not inside :try/:endtry, the expression -" evaluation continues and the function gets defined, and can be -" called and deleted. -"------------------------------------------------------------------------------- - -XpathINIT - -XloopINIT 1 4 - -function! ERR() abort - Xloop 1 " X: 1 + 4 + 16 + 64 - asdf -endfunction " returns -1 - -function! OK() - Xloop 2 " X: 2 * (1 + 4 + 16) - let v:errmsg = "" - return 0 -endfunction - -let v:errmsg = "" - -Xpath 4096 " X: 4096 -function! F{1 + ERR() + OK()}(arg) - " F0 should be defined. - if exists("a:arg") && a:arg == "calling" - Xpath 8192 " X: 8192 - else - Xpath 16384 " X: 0 - endif -endfunction -if v:errmsg != "" - Xpath 32768 " X: 0 -endif -XloopNEXT - -Xpath 65536 " X: 65536 -call F{1 + ERR() + OK()}("calling") -if v:errmsg != "" - Xpath 131072 " X: 0 -endif -XloopNEXT - -Xpath 262144 " X: 262144 -delfunction F{1 + ERR() + OK()} -if v:errmsg != "" - Xpath 524288 " X: 0 -endif -XloopNEXT - -try - while 1 - let caught = 0 - try - Xpath 1048576 " X: 1048576 - function! G{1 + ERR() + OK()}(arg) - " G0 should not be defined, and the function body should be - " skipped. - if exists("a:arg") && a:arg == "calling" - Xpath 2097152 " X: 0 - else - Xpath 4194304 " X: 0 - endif - " Use an unmatched ":finally" to check whether the body is - " skipped when an error occurs in ERR(). This works whether or - " not the exception is converted to an exception. - finally - Xpath 8388608 " X: 0 - Xout "Body of G{1 + ERR() + OK()}() not skipped" - " Discard the aborting error or exception, and break the - " while loop. - break - " End the try conditional and start a new one to avoid - " ":catch after :finally" errors. - endtry - try - Xpath 16777216 " X: 0 - endfunction - - " When the function was not defined, this won't be reached - whether - " the body was skipped or not. When the function was defined, it - " can be called and deleted here. - Xpath 33554432 " X: 0 - Xout "G0() has been defined" - XloopNEXT - try - call G{1 + ERR() + OK()}("calling") - catch /.*/ - Xpath 67108864 " X: 0 - endtry - Xpath 134217728 " X: 0 - XloopNEXT - try - delfunction G{1 + ERR() + OK()} - catch /.*/ - Xpath 268435456 " X: 0 - endtry - catch /asdf/ - " Jumped to when the function is not defined and the body is - " skipped. - let caught = 1 - catch /.*/ - Xpath 536870912 " X: 0 - finally - if !caught && !$VIMNOERRTHROW - Xpath 1073741824 " X: 0 - endif - break " discard error for $VIMNOERRTHROW - endtry " jumped to when the body is not skipped - endwhile -catch /.*/ - " The Xpath command does not accept 2^31 (negative); add explicitly: - let Xpath = Xpath + 2147483648 " X: 0 - Xout "Body of G{1 + ERR() + OK()}() not skipped, exception caught" - Xout v:exception "in" v:throwpoint -endtry - -Xcheck 1388671 - - -"------------------------------------------------------------------------------- -" Test 78: Messages on parsing errors in expression evaluation {{{1 -" -" When an expression evaluation detects a parsing error, an error -" message is given and converted to an exception, and the expression -" evaluation is aborted. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - - let taken = "" - - function! F(n) - let g:taken = g:taken . "F" . a:n - endfunction - - function! MSG(n, enr, emsg) - let g:taken = g:taken . "M" . a:n - let english = v:lang == "C" || v:lang =~ '^[Ee]n' - if a:enr == "" - Xout "TODO: Add message number for:" a:emsg - let v:errmsg = ":" . v:errmsg - endif - if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg) - if v:errmsg == "" - Xout "Expr" a:n.": Message missing." - let g:taken = g:taken . "x" - else - let v:errmsg = escape(v:errmsg, '"') - Xout "Expr" a:n.": Unexpected message:" v:errmsg - Xout "Expected: " . a:enr . ': ' . a:emsg - let g:taken = g:taken . "X" - endif - endif - endfunction - - function! CONT(n) - let g:taken = g:taken . "C" . a:n - endfunction - - let v:errmsg = "" - XloopINIT 1 2 - - try - let t = 1 - while t <= 14 - let g:taken = g:taken . "T" . t - let v:errmsg = "" - try - let caught = 0 - if t == 1 - let v{novar + CONT(t)} = 0 - elseif t == 2 - let v{novar + CONT(t)} - elseif t == 3 - let var = exists('v{novar + CONT(t)}') - elseif t == 4 - unlet v{novar + CONT(t)} - elseif t == 5 - function F{novar + CONT(t)}() - endfunction - elseif t == 6 - function F{novar + CONT(t)} - elseif t == 7 - let var = exists('*F{novar + CONT(t)}') - elseif t == 8 - delfunction F{novar + CONT(t)} - elseif t == 9 - echo novar + CONT(t) - elseif t == 10 - echo v{novar + CONT(t)} - elseif t == 11 - echo F{novar + CONT(t)} - elseif t == 12 - let var = novar + CONT(t) - elseif t == 13 - let var = v{novar + CONT(t)} - elseif t == 14 - let var = F{novar + CONT(t)}() - endif - catch /^Vim\((\a\+)\)\=:/ - " v:errmsg is not set when the error message is converted to an - " exception. Set it to the original error message. - let v:errmsg = substitute(v:exception, - \ '^Vim\((\a\+)\)\=:', '', "") - let caught = 1 - finally - if t <= 8 && t != 3 && t != 7 - call MSG(t, 'E475', 'Invalid argument\>') - else - if !caught " no error exceptions ($VIMNOERRTHROW set) - call MSG(t, 'E15', "Invalid expression") - else - call MSG(t, 'E121', "Undefined variable") - endif - endif - let t = t + 1 - XloopNEXT - continue " discard an aborting error - endtry - endwhile - catch /.*/ - Xloop 1 " X: 0 - Xout t.":" v:exception "in" ExtraVimThrowpoint() - endtry - - function! T(n, expr, enr, emsg) - try - let g:taken = g:taken . "T" . a:n - let v:errmsg = "" - try - let caught = 0 - execute "let var = " . a:expr - catch /^Vim\((\a\+)\)\=:/ - " v:errmsg is not set when the error message is converted to an - " exception. Set it to the original error message. - let v:errmsg = substitute(v:exception, - \ '^Vim\((\a\+)\)\=:', '', "") - let caught = 1 - finally - if !caught " no error exceptions ($VIMNOERRTHROW set) - call MSG(a:n, 'E15', "Invalid expression") - else - call MSG(a:n, a:enr, a:emsg) - endif - XloopNEXT - " Discard an aborting error: - return - endtry - catch /.*/ - Xloop 1 " X: 0 - Xout a:n.":" v:exception "in" ExtraVimThrowpoint() - endtry - endfunction - - call T(15, 'Nofunc() + CONT(15)', 'E117', "Unknown function") - call T(16, 'F(1 2 + CONT(16))', 'E116', "Invalid arguments") - call T(17, 'F(1, 2) + CONT(17)', 'E118', "Too many arguments") - call T(18, 'F() + CONT(18)', 'E119', "Not enough arguments") - call T(19, '{(1} + CONT(19)', 'E110', "Missing ')'") - call T(20, '("abc"[1) + CONT(20)', 'E111', "Missing ']'") - call T(21, '(1 +) + CONT(21)', 'E15', "Invalid expression") - call T(22, '1 2 + CONT(22)', 'E15', "Invalid expression") - call T(23, '(1 ? 2) + CONT(23)', 'E109', "Missing ':' after '?'") - call T(24, '("abc) + CONT(24)', 'E114', "Missing quote") - call T(25, "('abc) + CONT(25)", 'E115', "Missing quote") - call T(26, '& + CONT(26)', 'E112', "Option name missing") - call T(27, '&asdf + CONT(27)', 'E113', "Unknown option") - - Xpath 134217728 " X: 134217728 - - let expected = "" - \ . "T1M1T2M2T3M3T4M4T5M5T6M6T7M7T8M8T9M9T10M10T11M11T12M12T13M13T14M14" - \ . "T15M15T16M16T17M17T18M18T19M19T20M20T21M21T22M22T23M23T24M24T25M25" - \ . "T26M26T27M27" - - if taken != expected - Xpath 268435456 " X: 0 - Xout "'taken' is" taken "instead of" expected - if substitute(taken, '\(.*\)T3M3x\(.*\)', '\1T3M3\2', "") == expected - Xout "Is ++emsg_skip for var with expr_start non-NULL" - \ "in f_exists ok?" - endif - endif - - unlet! var caught taken expected - call delete(WA_t5) - unlet! WA_t5 - delfunction WA_t5 - -endif - -Xcheck 134217728 - - -"------------------------------------------------------------------------------- -" Test 79: Throwing one of several errors for the same command {{{1 -" -" When several errors appear in a row (for instance during expression -" evaluation), the first as the most specific one is used when -" throwing an error exception. If, however, a syntax error is -" detected afterwards, this one is used for the error exception. -" On a syntax error, the next command is not executed, on a normal -" error, however, it is (relevant only in a function without the -" "abort" flag). v:errmsg is not set. -" -" If throwing error exceptions is configured off, v:errmsg is always -" set to the latest error message, that is, to the more general -" message or the syntax error, respectively. -"------------------------------------------------------------------------------- - -XpathINIT - -XloopINIT 1 2 - -function! NEXT(cmd) - exec a:cmd . " | Xloop 1" -endfunction - -call NEXT('echo novar') " X: 1 * 1 (checks nextcmd) -XloopNEXT -call NEXT('let novar #') " X: 0 * 2 (skips nextcmd) -XloopNEXT -call NEXT('unlet novar #') " X: 0 * 4 (skips nextcmd) -XloopNEXT -call NEXT('let {novar}') " X: 0 * 8 (skips nextcmd) -XloopNEXT -call NEXT('unlet{ novar}') " X: 0 * 16 (skips nextcmd) - -function! EXEC(cmd) - exec a:cmd -endfunction - -function! MATCH(expected, msg, enr, emsg) - let msg = a:msg - if a:enr == "" - Xout "TODO: Add message number for:" a:emsg - let msg = ":" . msg - endif - let english = v:lang == "C" || v:lang =~ '^[Ee]n' - if msg !~ '^'.a:enr.':' || (english && msg !~ a:emsg) - let match = 0 - if a:expected " no match although expected - if a:msg == "" - Xout "Message missing." - else - let msg = escape(msg, '"') - Xout "Unexpected message:" msg - Xout "Expected:" a:enr . ": " . a:emsg - endif - endif - else - let match = 1 - if !a:expected " match although not expected - let msg = escape(msg, '"') - Xout "Unexpected message:" msg - Xout "Expected none." - endif - endif - return match -endfunction - -try - - while 1 " dummy loop - try - let v:errmsg = "" - let caught = 0 - let thrmsg = "" - call EXEC('echo novar') " normal error - catch /^Vim\((\a\+)\)\=:/ - let caught = 1 - let thrmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "") - finally - Xpath 32 " X: 32 - if !caught - if !$VIMNOERRTHROW - Xpath 64 " X: 0 - endif - elseif !MATCH(1, thrmsg, 'E121', "Undefined variable") - \ || v:errmsg != "" - Xpath 128 " X: 0 - endif - if !caught && !MATCH(1, v:errmsg, 'E15', "Invalid expression") - Xpath 256 " X: 0 - endif - break " discard error if $VIMNOERRTHROW == 1 - endtry - endwhile - - Xpath 512 " X: 512 - let cmd = "let" - XloopINIT 1024 32 - while cmd != "" - try - let v:errmsg = "" - let caught = 0 - let thrmsg = "" - call EXEC(cmd . ' novar #') " normal plus syntax error - catch /^Vim\((\a\+)\)\=:/ - let caught = 1 - let thrmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "") - finally - Xloop 1 " X: 1024 * (1 + 32) - if !caught - if !$VIMNOERRTHROW - Xloop 2 " X: 0 - endif - else - if cmd == "let" - let match = MATCH(0, thrmsg, 'E121', "Undefined variable") - elseif cmd == "unlet" - let match = MATCH(0, thrmsg, 'E108', "No such variable") - endif - if match " normal error - Xloop 4 " X: 0 - endif - if !MATCH(1, thrmsg, 'E488', "Trailing characters") - \|| v:errmsg != "" - " syntax error - Xloop 8 " X: 0 - endif - endif - if !caught && !MATCH(1, v:errmsg, 'E488', "Trailing characters") - " last error - Xloop 16 " X: 0 - endif - if cmd == "let" - let cmd = "unlet" - else - let cmd = "" - endif - XloopNEXT - continue " discard error if $VIMNOERRTHROW == 1 - endtry - endwhile - - Xpath 1048576 " X: 1048576 - let cmd = "let" - XloopINIT 2097152 32 - while cmd != "" - try - let v:errmsg = "" - let caught = 0 - let thrmsg = "" - call EXEC(cmd . ' {novar}') " normal plus syntax error - catch /^Vim\((\a\+)\)\=:/ - let caught = 1 - let thrmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "") - finally - Xloop 1 " X: 2097152 * (1 + 32) - if !caught - if !$VIMNOERRTHROW - Xloop 2 " X: 0 - endif - else - if MATCH(0, thrmsg, 'E121', "Undefined variable") " normal error - Xloop 4 " X: 0 - endif - if !MATCH(1, thrmsg, 'E475', 'Invalid argument\>') - \ || v:errmsg != "" " syntax error - Xloop 8 " X: 0 - endif - endif - if !caught && !MATCH(1, v:errmsg, 'E475', 'Invalid argument\>') - " last error - Xloop 16 " X: 0 - endif - if cmd == "let" - let cmd = "unlet" - else - let cmd = "" - endif - XloopNEXT - continue " discard error if $VIMNOERRTHROW == 1 - endtry - endwhile - -catch /.*/ - " The Xpath command does not accept 2^31 (negative); add explicitly: - let Xpath = Xpath + 2147483648 " X: 0 - Xout v:exception "in" v:throwpoint -endtry - -unlet! next_command thrmsg match -delfunction NEXT -delfunction EXEC -delfunction MATCH - -Xcheck 70288929 - - -"------------------------------------------------------------------------------- -" Test 80: Syntax error in expression for illegal :elseif {{{1 -" -" If there is a syntax error in the expression after an illegal -" :elseif, an error message is given (or an error exception thrown) -" for the illegal :elseif rather than the expression error. -"------------------------------------------------------------------------------- - -XpathINIT - -function! MSG(enr, emsg) - let english = v:lang == "C" || v:lang =~ '^[Ee]n' - if a:enr == "" - Xout "TODO: Add message number for:" a:emsg - let v:errmsg = ":" . v:errmsg - endif - let match = 1 - if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg) - let match = 0 - if v:errmsg == "" - Xout "Message missing." - else - let v:errmsg = escape(v:errmsg, '"') - Xout "Unexpected message:" v:errmsg - endif - endif - return match -endfunction - -let v:errmsg = "" -if 0 -else -elseif 1 ||| 2 -endif -Xpath 1 " X: 1 -if !MSG('E584', ":elseif after :else") - Xpath 2 " X: 0 -endif - -let v:errmsg = "" -if 1 -else -elseif 1 ||| 2 -endif -Xpath 4 " X: 4 -if !MSG('E584', ":elseif after :else") - Xpath 8 " X: 0 -endif - -let v:errmsg = "" -elseif 1 ||| 2 -Xpath 16 " X: 16 -if !MSG('E582', ":elseif without :if") - Xpath 32 " X: 0 -endif - -let v:errmsg = "" -while 1 - elseif 1 ||| 2 -endwhile -Xpath 64 " X: 64 -if !MSG('E582', ":elseif without :if") - Xpath 128 " X: 0 -endif - -while 1 - try - try - let v:errmsg = "" - let caught = 0 - if 0 - else - elseif 1 ||| 2 - endif - catch /^Vim\((\a\+)\)\=:/ - let caught = 1 - let v:errmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "") - finally - Xpath 256 " X: 256 - if !caught && !$VIMNOERRTHROW - Xpath 512 " X: 0 - endif - if !MSG('E584', ":elseif after :else") - Xpath 1024 " X: 0 - endif - endtry - catch /.*/ - Xpath 2048 " X: 0 - Xout v:exception "in" v:throwpoint - finally - break " discard error for $VIMNOERRTHROW - endtry -endwhile - -while 1 - try - try - let v:errmsg = "" - let caught = 0 - if 1 - else - elseif 1 ||| 2 - endif - catch /^Vim\((\a\+)\)\=:/ - let caught = 1 - let v:errmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "") - finally - Xpath 4096 " X: 4096 - if !caught && !$VIMNOERRTHROW - Xpath 8192 " X: 0 - endif - if !MSG('E584', ":elseif after :else") - Xpath 16384 " X: 0 - endif - endtry - catch /.*/ - Xpath 32768 " X: 0 - Xout v:exception "in" v:throwpoint - finally - break " discard error for $VIMNOERRTHROW - endtry -endwhile - -while 1 - try - try - let v:errmsg = "" - let caught = 0 - elseif 1 ||| 2 - catch /^Vim\((\a\+)\)\=:/ - let caught = 1 - let v:errmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "") - finally - Xpath 65536 " X: 65536 - if !caught && !$VIMNOERRTHROW - Xpath 131072 " X: 0 - endif - if !MSG('E582', ":elseif without :if") - Xpath 262144 " X: 0 - endif - endtry - catch /.*/ - Xpath 524288 " X: 0 - Xout v:exception "in" v:throwpoint - finally - break " discard error for $VIMNOERRTHROW - endtry -endwhile - -while 1 - try - try - let v:errmsg = "" - let caught = 0 - while 1 - elseif 1 ||| 2 - endwhile - catch /^Vim\((\a\+)\)\=:/ - let caught = 1 - let v:errmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "") - finally - Xpath 1048576 " X: 1048576 - if !caught && !$VIMNOERRTHROW - Xpath 2097152 " X: 0 - endif - if !MSG('E582', ":elseif without :if") - Xpath 4194304 " X: 0 - endif - endtry - catch /.*/ - Xpath 8388608 " X: 0 - Xout v:exception "in" v:throwpoint - finally - break " discard error for $VIMNOERRTHROW - endtry -endwhile - -Xpath 16777216 " X: 16777216 - -unlet! caught -delfunction MSG - -Xcheck 17895765 - - -"------------------------------------------------------------------------------- -" Test 81: Discarding exceptions after an error or interrupt {{{1 -" -" When an exception is thrown from inside a :try conditional without -" :catch and :finally clauses and an error or interrupt occurs before -" the :endtry is reached, the exception is discarded. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - try - Xpath 1 " X: 1 - try - Xpath 2 " X: 2 - throw "arrgh" - Xpath 4 " X: 0 -" if 1 - Xpath 8 " X: 0 - " error after :throw: missing :endif - endtry - Xpath 16 " X: 0 - catch /arrgh/ - Xpath 32 " X: 0 - endtry - Xpath 64 " X: 0 -endif - -if ExtraVim() - try - Xpath 128 " X: 128 - try - Xpath 256 " X: 256 - throw "arrgh" - Xpath 512 " X: 0 - endtry " INTERRUPT - Xpath 1024 " X: 0 - catch /arrgh/ - Xpath 2048 " X: 0 - endtry - Xpath 4096 " X: 0 -endif - -Xcheck 387 - +" Following tests were moved to test_vimscript.vim: +" 1-24, 27-31, 34-40, 49-50, 52-68, 76-81, 87 +" Following tests were moved to test_trycatch.vim: +" 25-26, 32-33, 41-48, 51, 69-75 +let Xtest = 82 "------------------------------------------------------------------------------- " Test 82: Ignoring :catch clauses after an error or interrupt {{{1 diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index 5e112e05f9..8faa9135e5 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -23,6 +23,7 @@ com! -nargs=1 Xout call Xout() " file. If the test passes successfully, then Xtest.out should be empty. func RunInNewVim(test, verify) let init =<< trim END + set cpo-=C " support line-continuation in sourced script source script_util.vim XpathINIT XloopINIT @@ -3719,6 +3720,381 @@ func Test_execption_info_for_error() call RunInNewVim(test, verify) endfunc +"------------------------------------------------------------------------------- +" +" Test 59: v:exception and v:throwpoint when discarding exceptions {{{1 +" +" When a :catch clause is left by a ":break" etc or an error or +" interrupt exception, v:exception and v:throwpoint are reset. They +" are not affected by an exception that is discarded before being +" caught. +"------------------------------------------------------------------------------- +func Test_exception_info_on_discard() + CheckEnglish + + let test =<< trim [CODE] + let sfile = expand("") + + while 1 + try + throw "x1" + catch /.*/ + break + endtry + endwhile + call assert_equal('', v:exception) + call assert_equal('', v:throwpoint) + + while 1 + try + throw "x2" + catch /.*/ + break + finally + call assert_equal('', v:exception) + call assert_equal('', v:throwpoint) + endtry + break + endwhile + call assert_equal('', v:exception) + call assert_equal('', v:throwpoint) + + while 1 + try + let errcaught = 0 + try + try + throw "x3" + catch /.*/ + let lnum = expand("") + asdf + endtry + catch /.*/ + let errcaught = 1 + call assert_match('Vim:E492: Not an editor command:', v:exception) + call assert_match('line ' .. (lnum + 1), v:throwpoint) + endtry + finally + call assert_equal(1, errcaught) + break + endtry + endwhile + call assert_equal('', v:exception) + call assert_equal('', v:throwpoint) + + Xpath 'a' + + while 1 + try + let intcaught = 0 + try + try + throw "x4" + catch /.*/ + let lnum = expand("") + call interrupt() + endtry + catch /.*/ + let intcaught = 1 + call assert_match('Vim:Interrupt', v:exception) + call assert_match('line ' .. (lnum + 1), v:throwpoint) + endtry + finally + call assert_equal(1, intcaught) + break + endtry + endwhile + call assert_equal('', v:exception) + call assert_equal('', v:throwpoint) + + Xpath 'b' + + while 1 + try + let errcaught = 0 + try + try + if 1 + let lnum = expand("") + throw "x5" + " missing endif + catch /.*/ + call assert_report('should not get here') + endtry + catch /.*/ + let errcaught = 1 + call assert_match('Vim(catch):E171: Missing :endif:', v:exception) + call assert_match('line ' .. (lnum + 3), v:throwpoint) + endtry + finally + call assert_equal(1, errcaught) + break + endtry + endwhile + call assert_equal('', v:exception) + call assert_equal('', v:throwpoint) + + Xpath 'c' + + try + while 1 + try + throw "x6" + finally + break + endtry + break + endwhile + catch /.*/ + call assert_report('should not get here') + endtry + call assert_equal('', v:exception) + call assert_equal('', v:throwpoint) + + try + while 1 + try + throw "x7" + finally + break + endtry + break + endwhile + catch /.*/ + call assert_report('should not get here') + finally + call assert_equal('', v:exception) + call assert_equal('', v:throwpoint) + endtry + call assert_equal('', v:exception) + call assert_equal('', v:throwpoint) + + while 1 + try + let errcaught = 0 + try + try + throw "x8" + finally + let lnum = expand("") + asdf + endtry + catch /.*/ + let errcaught = 1 + call assert_match('Vim:E492: Not an editor command:', v:exception) + call assert_match('line ' .. (lnum + 1), v:throwpoint) + endtry + finally + call assert_equal(1, errcaught) + break + endtry + endwhile + call assert_equal('', v:exception) + call assert_equal('', v:throwpoint) + + Xpath 'd' + + while 1 + try + let intcaught = 0 + try + try + throw "x9" + finally + let lnum = expand("") + call interrupt() + endtry + catch /.*/ + let intcaught = 1 + call assert_match('Vim:Interrupt', v:exception) + call assert_match('line ' .. (lnum + 1), v:throwpoint) + endtry + finally + call assert_equal(1, intcaught) + break + endtry + endwhile + call assert_equal('', v:exception) + call assert_equal('', v:throwpoint) + + Xpath 'e' + + while 1 + try + let errcaught = 0 + try + try + if 1 + let lnum = expand("") + throw "x10" + " missing endif + finally + call assert_equal('', v:exception) + call assert_equal('', v:throwpoint) + endtry + catch /.*/ + let errcaught = 1 + call assert_match('Vim(finally):E171: Missing :endif:', v:exception) + call assert_match('line ' .. (lnum + 3), v:throwpoint) + endtry + finally + call assert_equal(1, errcaught) + break + endtry + endwhile + call assert_equal('', v:exception) + call assert_equal('', v:throwpoint) + + Xpath 'f' + + while 1 + try + let errcaught = 0 + try + try + if 1 + let lnum = expand("") + throw "x11" + " missing endif + endtry + catch /.*/ + let errcaught = 1 + call assert_match('Vim(endtry):E171: Missing :endif:', v:exception) + call assert_match('line ' .. (lnum + 3), v:throwpoint) + endtry + finally + call assert_equal(1, errcaught) + break + endtry + endwhile + call assert_equal('', v:exception) + call assert_equal('', v:throwpoint) + + Xpath 'g' + [CODE] + let verify =<< trim [CODE] + call assert_equal('abcdefg', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" +" Test 60: (Re)throwing v:exception; :echoerr. {{{1 +" +" A user exception can be rethrown after catching by throwing +" v:exception. An error or interrupt exception cannot be rethrown +" because Vim exceptions cannot be faked. A Vim exception using the +" value of v:exception can, however, be triggered by the :echoerr +" command. +"------------------------------------------------------------------------------- + +func Test_rethrow_exception_1() + XpathINIT + try + try + Xpath 'a' + throw "oops" + catch /oops/ + Xpath 'b' + throw v:exception " rethrow user exception + catch /.*/ + call assert_report('should not get here') + endtry + catch /^oops$/ " catches rethrown user exception + Xpath 'c' + catch /.*/ + call assert_report('should not get here') + endtry + call assert_equal('abc', g:Xpath) +endfunc + +func Test_rethrow_exception_2() + XpathINIT + try + let caught = 0 + try + Xpath 'a' + write /n/o/n/w/r/i/t/a/b/l/e/_/f/i/l/e + call assert_report('should not get here') + catch /^Vim(write):/ + let caught = 1 + throw v:exception " throw error: cannot fake Vim exception + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'b' + call assert_equal(1, caught) + endtry + catch /^Vim(throw):/ " catches throw error + let caught = caught + 1 + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'c' + call assert_equal(2, caught) + endtry + call assert_equal('abc', g:Xpath) +endfunc + +func Test_rethrow_exception_3() + XpathINIT + try + let caught = 0 + try + Xpath 'a' + asdf + catch /^Vim/ " catch error exception + let caught = 1 + " Trigger Vim error exception with value specified after :echoerr + let value = substitute(v:exception, '^Vim\((.*)\)\=:', '', "") + echoerr value + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'b' + call assert_equal(1, caught) + endtry + catch /^Vim(echoerr):/ + let caught = caught + 1 + call assert_match(value, v:exception) + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'c' + call assert_equal(2, caught) + endtry + call assert_equal('abc', g:Xpath) +endfunc + +func Test_rethrow_exception_3() + XpathINIT + try + let errcaught = 0 + try + Xpath 'a' + let intcaught = 0 + call interrupt() + catch /^Vim:/ " catch interrupt exception + let intcaught = 1 + " Trigger Vim error exception with value specified after :echoerr + echoerr substitute(v:exception, '^Vim\((.*)\)\=:', '', "") + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'b' + call assert_equal(1, intcaught) + endtry + catch /^Vim(echoerr):/ + let errcaught = 1 + call assert_match('Interrupt', v:exception) + finally + Xpath 'c' + call assert_equal(1, errcaught) + endtry + call assert_equal('abc', g:Xpath) +endfunc + "------------------------------------------------------------------------------- " Test 61: Catching interrupt exceptions {{{1 " @@ -3846,68 +4222,1673 @@ func Test_catch_intr_exception() endfunc "------------------------------------------------------------------------------- -" Test 65: Errors in the /pattern/ argument of a :catch {{{1 +" Test 62: Catching error exceptions {{{1 " -" On an error in the /pattern/ argument of a :catch, the :catch does -" not match. Any following :catches of the same :try/:endtry don't -" match either. Finally clauses are executed. +" An error inside a :try/:endtry region is converted to an exception +" and can be caught. The error exception has a "Vim(cmdname):" prefix +" where cmdname is the name of the failing command, or a "Vim:" prefix +" if no command name is known. The "Vim" prefixes cannot be faked. "------------------------------------------------------------------------------- -func Test_catch_pattern_error() - CheckEnglish +func Test_catch_err_exception_1() XpathINIT - - try + while 1 try - Xpath 'a' - throw "oops" - catch /^oops$/ - Xpath 'b' - catch /\)/ " not checked; exception has already been caught + try + let caught = 0 + unlet novar + catch /^Vim(unlet):/ + Xpath 'a' + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim(unlet):', '', "") + finally + Xpath 'b' + call assert_equal(1, caught) + call assert_match('E108: No such variable: "novar"', v:errmsg) + endtry + catch /.*/ call assert_report('should not get here') - endtry - Xpath 'c' - catch /.*/ + finally + Xpath 'c' + break + endtry call assert_report('should not get here') - endtry + endwhile + call assert_equal('abc', g:Xpath) +endfunc + +func Test_catch_err_exception_2() + XpathINIT + while 1 + try + try + let caught = 0 + throw novar " error in :throw + catch /^Vim(throw):/ + Xpath 'a' + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim(throw):', '', "") + finally + Xpath 'b' + call assert_equal(1, caught) + call assert_match('E121: Undefined variable: novar', v:errmsg) + endtry + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'c' + break + endtry + call assert_report('should not get here') + endwhile + call assert_equal('abc', g:Xpath) +endfunc + +func Test_catch_err_exception_3() + XpathINIT + while 1 + try + try + let caught = 0 + throw "Vim:faked" " error: cannot fake Vim exception + catch /^Vim(throw):/ + Xpath 'a' + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim(throw):', '', "") + finally + Xpath 'b' + call assert_equal(1, caught) + call assert_match("E608: Cannot :throw exceptions with 'Vim' prefix", + \ v:errmsg) + endtry + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'c' + break + endtry + call assert_report('should not get here') + endwhile + call assert_equal('abc', g:Xpath) +endfunc + +func Test_catch_err_exception_4() + XpathINIT + func F() + while 1 + " Missing :endwhile + endfunc + + while 1 + try + try + let caught = 0 + call F() + catch /^Vim(endfunction):/ + Xpath 'a' + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim(endfunction):', '', "") + finally + Xpath 'b' + call assert_equal(1, caught) + call assert_match("E170: Missing :endwhile", v:errmsg) + endtry + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'c' + break + endtry + call assert_report('should not get here') + endwhile call assert_equal('abc', g:Xpath) + delfunc F +endfunc +func Test_catch_err_exception_5() XpathINIT func F() + while 1 + " Missing :endwhile + endfunc + + while 1 + try + try + let caught = 0 + ExecAsScript F + catch /^Vim:/ + Xpath 'a' + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim:', '', "") + finally + Xpath 'b' + call assert_equal(1, caught) + call assert_match("E170: Missing :endwhile", v:errmsg) + endtry + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'c' + break + endtry + call assert_report('should not get here') + endwhile + call assert_equal('abc', g:Xpath) + delfunc F +endfunc + +func Test_catch_err_exception_6() + XpathINIT + func G() + call G() + endfunc + + while 1 + try + let mfd_save = &mfd + set mfd=3 + try + let caught = 0 + call G() + catch /^Vim(call):/ + Xpath 'a' + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim(call):', '', "") + finally + Xpath 'b' + call assert_equal(1, caught) + call assert_match("E132: Function call depth is higher than 'maxfuncdepth'", v:errmsg) + endtry + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'c' + let &mfd = mfd_save + break + endtry + call assert_report('should not get here') + endwhile + call assert_equal('abc', g:Xpath) + delfunc G +endfunc + +func Test_catch_err_exception_7() + XpathINIT + func H() + return H() + endfunc + + while 1 + try + let mfd_save = &mfd + set mfd=3 + try + let caught = 0 + call H() + catch /^Vim(return):/ + Xpath 'a' + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim(return):', '', "") + finally + Xpath 'b' + call assert_equal(1, caught) + call assert_match("E132: Function call depth is higher than 'maxfuncdepth'", v:errmsg) + endtry + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'c' + let &mfd = mfd_save + break " discard error for $VIMNOERRTHROW + endtry + call assert_report('should not get here') + endwhile + + call assert_equal('abc', g:Xpath) + delfunc H +endfunc + +"------------------------------------------------------------------------------- +" Test 63: Suppressing error exceptions by :silent!. {{{1 +" +" A :silent! command inside a :try/:endtry region suppresses the +" conversion of errors to an exception and the immediate abortion on +" error. When the commands executed by the :silent! themselves open +" a new :try/:endtry region, conversion of errors to exception and +" immediate abortion is switched on again - until the next :silent! +" etc. The :silent! has the effect of setting v:errmsg to the error +" message text (without displaying it) and continuing with the next +" script line. +" +" When a command triggering autocommands is executed by :silent! +" inside a :try/:endtry, the autocommand execution is not suppressed +" on error. +" +" This test reuses the function MSG() from the previous test. +"------------------------------------------------------------------------------- + +func Test_silent_exception() + XpathINIT + XloopINIT + let g:taken = "" + + func S(n) abort + XloopNEXT + let g:taken = g:taken . "E" . a:n + let v:errmsg = "" + exec "asdf" . a:n + + " Check that ":silent!" continues: + Xloop 'a' + + " Check that ":silent!" sets "v:errmsg": + call assert_match("E492: Not an editor command", v:errmsg) + endfunc + + func Foo() + while 1 + try + try + let caught = 0 + " This is not silent: + call S(3) + catch /^Vim:/ + Xpath 'b' + let caught = 1 + let errmsg3 = substitute(v:exception, '^Vim:', '', "") + silent! call S(4) + finally + call assert_equal(1, caught) + Xpath 'c' + call assert_match("E492: Not an editor command", errmsg3) + silent! call S(5) + " Break out of try conditionals that cover ":silent!". This also + " discards the aborting error when $VIMNOERRTHROW is non-zero. + break + endtry + catch /.*/ + call assert_report('should not get here') + endtry + endwhile + " This is a double ":silent!" (see caller). + silent! call S(6) + endfunc + + func Bar() + try + silent! call S(2) + silent! execute "call Foo() | call S(7)" + silent! call S(8) + endtry " normal end of try cond that covers ":silent!" + " This has a ":silent!" from the caller: + call S(9) + endfunc + + silent! call S(1) + silent! call Bar() + silent! call S(10) + + call assert_equal("E1E2E3E4E5E6E7E8E9E10", g:taken) + + augroup TMP + au! + autocmd BufWritePost * Xpath 'd' + augroup END + + Xpath 'e' + silent! write /i/m/p/o/s/s/i/b/l/e + Xpath 'f' + + call assert_equal('a2a3ba5ca6a7a8a9a10a11edf', g:Xpath) + + augroup TMP + au! + augroup END + augroup! TMP + delfunction S + delfunction Foo + delfunction Bar +endfunc + +"------------------------------------------------------------------------------- +" Test 64: Error exceptions after error, interrupt or :throw {{{1 +" +" When an error occurs after an interrupt or a :throw but before +" a matching :catch is reached, all following :catches of that try +" block are ignored, but the error exception can be caught by the next +" surrounding try conditional. Any previous error exception is +" discarded. An error is ignored when there is a previous error that +" has not been caught. +"------------------------------------------------------------------------------- + +func Test_exception_after_error_1() + XpathINIT + while 1 + try + try + Xpath 'a' + let caught = 0 + while 1 + if 1 + " Missing :endif + endwhile " throw error exception + catch /^Vim(/ + Xpath 'b' + let caught = 1 + finally + Xpath 'c' + call assert_equal(1, caught) + endtry + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'd' + break + endtry + call assert_report('should not get here') + endwhile + call assert_equal('abcd', g:Xpath) +endfunc + +func Test_exception_after_error_2() + XpathINIT + while 1 + try + try + Xpath 'a' + let caught = 0 + try + if 1 + " Missing :endif + catch /.*/ " throw error exception + call assert_report('should not get here') + catch /.*/ + call assert_report('should not get here') + endtry + catch /^Vim(/ + Xpath 'b' + let caught = 1 + finally + Xpath 'c' + call assert_equal(1, caught) + endtry + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'd' + break + endtry + call assert_report('should not get here') + endwhile + call assert_equal('abcd', g:Xpath) +endfunc + +func Test_exception_after_error_3() + XpathINIT + while 1 try try + let caught = 0 try Xpath 'a' - throw "ab" - catch /abc/ " does not catch + call interrupt() + catch /do_not_catch/ call assert_report('should not get here') - catch /\)/ " error; discards exception + if 1 + " Missing :endif + catch /.*/ " throw error exception call assert_report('should not get here') - catch /.*/ " not checked + catch /.*/ call assert_report('should not get here') - finally - Xpath 'b' endtry - call assert_report('should not get here') - catch /^ab$/ " checked, but original exception is discarded - call assert_report('should not get here') - catch /^Vim(catch):/ - Xpath 'c' - call assert_match('Vim(catch):E475: Invalid argument:', v:exception) + catch /^Vim(/ + Xpath 'b' + let caught = 1 finally - Xpath 'd' + Xpath 'c' + call assert_equal(1, caught) endtry - Xpath 'e' catch /.*/ call assert_report('should not get here') + finally + Xpath 'd' + break endtry - Xpath 'f' - endfunc - - call F() - call assert_equal('abcdef', g:Xpath) + call assert_report('should not get here') + endwhile + call assert_equal('abcd', g:Xpath) +endfunc - delfunc F +func Test_exception_after_error_4() + XpathINIT + while 1 + try + try + let caught = 0 + try + Xpath 'a' + throw "x" + catch /do_not_catch/ + call assert_report('should not get here') + if 1 + " Missing :endif + catch /x/ " throw error exception + call assert_report('should not get here') + catch /.*/ + call assert_report('should not get here') + endtry + catch /^Vim(/ + Xpath 'b' + let caught = 1 + finally + Xpath 'c' + call assert_equal(1, caught) + endtry + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'd' + break + endtry + call assert_report('should not get here') + endwhile + call assert_equal('abcd', g:Xpath) +endfunc + +func Test_exception_after_error_5() + XpathINIT + while 1 + try + try + let caught = 0 + Xpath 'a' + endif " :endif without :if; throw error exception + if 1 + " Missing :endif + catch /do_not_catch/ " ignore new error + call assert_report('should not get here') + catch /^Vim(endif):/ + Xpath 'b' + let caught = 1 + catch /^Vim(/ + call assert_report('should not get here') + finally + Xpath 'c' + call assert_equal(1, caught) + endtry + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'd' + break + endtry + call assert_report('should not get here') + endwhile + call assert_equal('abcd', g:Xpath) +endfunc + +"------------------------------------------------------------------------------- +" Test 65: Errors in the /pattern/ argument of a :catch {{{1 +" +" On an error in the /pattern/ argument of a :catch, the :catch does +" not match. Any following :catches of the same :try/:endtry don't +" match either. Finally clauses are executed. +"------------------------------------------------------------------------------- + +func Test_catch_pattern_error() + CheckEnglish + XpathINIT + + try + try + Xpath 'a' + throw "oops" + catch /^oops$/ + Xpath 'b' + catch /\)/ " not checked; exception has already been caught + call assert_report('should not get here') + endtry + Xpath 'c' + catch /.*/ + call assert_report('should not get here') + endtry + call assert_equal('abc', g:Xpath) + + XpathINIT + func F() + try + try + try + Xpath 'a' + throw "ab" + catch /abc/ " does not catch + call assert_report('should not get here') + catch /\)/ " error; discards exception + call assert_report('should not get here') + catch /.*/ " not checked + call assert_report('should not get here') + finally + Xpath 'b' + endtry + call assert_report('should not get here') + catch /^ab$/ " checked, but original exception is discarded + call assert_report('should not get here') + catch /^Vim(catch):/ + Xpath 'c' + call assert_match('Vim(catch):E475: Invalid argument:', v:exception) + finally + Xpath 'd' + endtry + Xpath 'e' + catch /.*/ + call assert_report('should not get here') + endtry + Xpath 'f' + endfunc + + call F() + call assert_equal('abcdef', g:Xpath) + + delfunc F +endfunc + +"------------------------------------------------------------------------------- +" Test 66: Stop range :call on error, interrupt, or :throw {{{1 +" +" When a function which is multiply called for a range since it +" doesn't handle the range itself has an error in a command +" dynamically enclosed by :try/:endtry or gets an interrupt or +" executes a :throw, no more calls for the remaining lines in the +" range are made. On an error in a command not dynamically enclosed +" by :try/:endtry, the function is executed again for the remaining +" lines in the range. +"------------------------------------------------------------------------------- + +func Test_stop_range_on_error() + let test =<< trim [CODE] + let file = tempname() + exec "edit" file + call setline(1, ['line 1', 'line 2', 'line 3']) + let taken = "" + let expected = "G1EF1E(1)F1E(2)F1E(3)G2EF2E(1)G3IF3I(1)G4TF4T(1)G5AF5A(1)" + + func F(reason, n) abort + let g:taken = g:taken .. "F" .. a:n .. + \ substitute(a:reason, '\(\l\).*', '\u\1', "") .. + \ "(" .. line(".") .. ")" + + if a:reason == "error" + asdf + elseif a:reason == "interrupt" + call interrupt() + elseif a:reason == "throw" + throw "xyz" + elseif a:reason == "aborting error" + XloopNEXT + call assert_equal(g:taken, g:expected) + try + bwipeout! + call delete(g:file) + asdf + endtry + endif + endfunc + + func G(reason, n) + let g:taken = g:taken .. "G" .. a:n .. + \ substitute(a:reason, '\(\l\).*', '\u\1', "") + 1,3call F(a:reason, a:n) + endfunc + + Xpath 'a' + call G("error", 1) + try + Xpath 'b' + try + call G("error", 2) + call assert_report('should not get here') + finally + Xpath 'c' + try + call G("interrupt", 3) + call assert_report('should not get here') + finally + Xpath 'd' + try + call G("throw", 4) + call assert_report('should not get here') + endtry + endtry + endtry + catch /xyz/ + Xpath 'e' + catch /.*/ + call assert_report('should not get here') + endtry + Xpath 'f' + call G("aborting error", 5) + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('abcdef', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 67: :throw across :call command {{{1 +" +" On a call command, an exception might be thrown when evaluating the +" function name, during evaluation of the arguments, or when the +" function is being executed. The exception can be caught by the +" caller. +"------------------------------------------------------------------------------- + +func THROW(x, n) + if a:n == 1 + Xpath 'A' + elseif a:n == 2 + Xpath 'B' + elseif a:n == 3 + Xpath 'C' + endif + throw a:x +endfunc + +func NAME(x, n) + if a:n == 1 + call assert_report('should not get here') + elseif a:n == 2 + Xpath 'D' + elseif a:n == 3 + Xpath 'E' + elseif a:n == 4 + Xpath 'F' + endif + return a:x +endfunc + +func ARG(x, n) + if a:n == 1 + call assert_report('should not get here') + elseif a:n == 2 + call assert_report('should not get here') + elseif a:n == 3 + Xpath 'G' + elseif a:n == 4 + Xpath 'I' + endif + return a:x +endfunc + +func Test_throw_across_call_cmd() + XpathINIT + + func F(x, n) + if a:n == 2 + call assert_report('should not get here') + elseif a:n == 4 + Xpath 'a' + endif + endfunc + + while 1 + try + let v:errmsg = "" + + while 1 + try + Xpath 'b' + call {NAME(THROW("name", 1), 1)}(ARG(4711, 1), 1) + call assert_report('should not get here') + catch /^name$/ + Xpath 'c' + catch /.*/ + call assert_report('should not get here') + finally + call assert_equal("", v:errmsg) + let v:errmsg = "" + break + endtry + endwhile + + while 1 + try + Xpath 'd' + call {NAME("F", 2)}(ARG(THROW("arg", 2), 2), 2) + call assert_report('should not get here') + catch /^arg$/ + Xpath 'e' + catch /.*/ + call assert_report('should not get here') + finally + call assert_equal("", v:errmsg) + let v:errmsg = "" + break + endtry + endwhile + + while 1 + try + Xpath 'f' + call {NAME("THROW", 3)}(ARG("call", 3), 3) + call assert_report('should not get here') + catch /^call$/ + Xpath 'g' + catch /^0$/ " default return value + call assert_report('should not get here') + catch /.*/ + call assert_report('should not get here') + finally + call assert_equal("", v:errmsg) + let v:errmsg = "" + break + endtry + endwhile + + while 1 + try + Xpath 'h' + call {NAME("F", 4)}(ARG(4711, 4), 4) + Xpath 'i' + catch /.*/ + call assert_report('should not get here') + finally + call assert_equal("", v:errmsg) + let v:errmsg = "" + break + endtry + endwhile + + catch /^0$/ " default return value + call assert_report('should not get here') + catch /.*/ + call assert_report('should not get here') + finally + call assert_equal("", v:errmsg) + let v:errmsg = "" + break + endtry + endwhile + + call assert_equal('bAcdDBefEGCghFIai', g:Xpath) + delfunction F +endfunc + +"------------------------------------------------------------------------------- +" Test 68: :throw across function calls in expressions {{{1 +" +" On a function call within an expression, an exception might be +" thrown when evaluating the function name, during evaluation of the +" arguments, or when the function is being executed. The exception +" can be caught by the caller. +" +" This test reuses the functions THROW(), NAME(), and ARG() from the +" previous test. +"------------------------------------------------------------------------------- + +func Test_throw_across_call_expr() + XpathINIT + + func F(x, n) + if a:n == 2 + call assert_report('should not get here') + elseif a:n == 4 + Xpath 'a' + endif + return a:x + endfunction + + while 1 + try + let error = 0 + let v:errmsg = "" + + while 1 + try + Xpath 'b' + let var1 = {NAME(THROW("name", 1), 1)}(ARG(4711, 1), 1) + call assert_report('should not get here') + catch /^name$/ + Xpath 'c' + catch /.*/ + call assert_report('should not get here') + finally + call assert_equal("", v:errmsg) + let v:errmsg = "" + break + endtry + endwhile + call assert_true(!exists('var1')) + + while 1 + try + Xpath 'd' + let var2 = {NAME("F", 2)}(ARG(THROW("arg", 2), 2), 2) + call assert_report('should not get here') + catch /^arg$/ + Xpath 'e' + catch /.*/ + call assert_report('should not get here') + finally + call assert_equal("", v:errmsg) + let v:errmsg = "" + break + endtry + endwhile + call assert_true(!exists('var2')) + + while 1 + try + Xpath 'f' + let var3 = {NAME("THROW", 3)}(ARG("call", 3), 3) + call assert_report('should not get here') + catch /^call$/ + Xpath 'g' + catch /^0$/ " default return value + call assert_report('should not get here') + catch /.*/ + call assert_report('should not get here') + finally + call assert_equal("", v:errmsg) + let v:errmsg = "" + break + endtry + endwhile + call assert_true(!exists('var3')) + + while 1 + try + Xpath 'h' + let var4 = {NAME("F", 4)}(ARG(4711, 4), 4) + Xpath 'i' + catch /.*/ + call assert_report('should not get here') + finally + call assert_equal("", v:errmsg) + let v:errmsg = "" + break + endtry + endwhile + call assert_true(exists('var4') && var4 == 4711) + + catch /^0$/ " default return value + call assert_report('should not get here') + catch /.*/ + call assert_report('should not get here') + finally + call assert_equal("", v:errmsg) + break + endtry + endwhile + + call assert_equal('bAcdDBefEGCghFIai', g:Xpath) + delfunc F +endfunc + +"------------------------------------------------------------------------------- +" Test 76: Errors, interrupts, :throw during expression evaluation {{{1 +" +" When a function call made during expression evaluation is aborted +" due to an error inside a :try/:endtry region or due to an interrupt +" or a :throw, the expression evaluation is aborted as well. No +" message is displayed for the cancelled expression evaluation. On an +" error not inside :try/:endtry, the expression evaluation continues. +"------------------------------------------------------------------------------- + +func Test_expr_eval_error() + let test =<< trim [CODE] + let taken = "" + + func ERR(n) + let g:taken = g:taken .. "E" .. a:n + asdf + endfunc + + func ERRabort(n) abort + let g:taken = g:taken .. "A" .. a:n + asdf + endfunc " returns -1; may cause follow-up msg for illegal var/func name + + func WRAP(n, arg) + let g:taken = g:taken .. "W" .. a:n + let g:saved_errmsg = v:errmsg + return arg + endfunc + + func INT(n) + let g:taken = g:taken .. "I" .. a:n + call interrupt() + endfunc + + func THR(n) + let g:taken = g:taken .. "T" .. a:n + throw "should not be caught" + endfunc + + func CONT(n) + let g:taken = g:taken .. "C" .. a:n + endfunc + + func MSG(n) + let g:taken = g:taken .. "M" .. a:n + let errmsg = (a:n >= 37 && a:n <= 44) ? g:saved_errmsg : v:errmsg + let msgptn = (a:n >= 10 && a:n <= 27) ? "^$" : "asdf" + call assert_match(msgptn, errmsg) + let v:errmsg = "" + let g:saved_errmsg = "" + endfunc + + let v:errmsg = "" + + try + let t = 1 + while t <= 9 + Xloop 'a' + try + if t == 1 + let v{ERR(t) + CONT(t)} = 0 + elseif t == 2 + let v{ERR(t) + CONT(t)} + elseif t == 3 + let var = exists('v{ERR(t) + CONT(t)}') + elseif t == 4 + unlet v{ERR(t) + CONT(t)} + elseif t == 5 + function F{ERR(t) + CONT(t)}() + endfunction + elseif t == 6 + function F{ERR(t) + CONT(t)} + elseif t == 7 + let var = exists('*F{ERR(t) + CONT(t)}') + elseif t == 8 + delfunction F{ERR(t) + CONT(t)} + elseif t == 9 + let var = ERR(t) + CONT(t) + endif + catch /asdf/ + " v:errmsg is not set when the error message is converted to an + " exception. Set it to the original error message. + let v:errmsg = substitute(v:exception, '^Vim:', '', "") + catch /^Vim\((\a\+)\)\=:/ + " An error exception has been thrown after the original error. + let v:errmsg = "" + finally + call MSG(t) + let t = t + 1 + XloopNEXT + continue " discard an aborting error + endtry + endwhile + catch /.*/ + call assert_report('should not get here') + endtry + + try + let t = 10 + while t <= 18 + Xloop 'b' + try + if t == 10 + let v{INT(t) + CONT(t)} = 0 + elseif t == 11 + let v{INT(t) + CONT(t)} + elseif t == 12 + let var = exists('v{INT(t) + CONT(t)}') + elseif t == 13 + unlet v{INT(t) + CONT(t)} + elseif t == 14 + function F{INT(t) + CONT(t)}() + endfunction + elseif t == 15 + function F{INT(t) + CONT(t)} + elseif t == 16 + let var = exists('*F{INT(t) + CONT(t)}') + elseif t == 17 + delfunction F{INT(t) + CONT(t)} + elseif t == 18 + let var = INT(t) + CONT(t) + endif + catch /^Vim\((\a\+)\)\=:\(Interrupt\)\@!/ + " An error exception has been triggered after the interrupt. + let v:errmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "") + finally + call MSG(t) + let t = t + 1 + XloopNEXT + continue " discard interrupt + endtry + endwhile + catch /.*/ + call assert_report('should not get here') + endtry + + try + let t = 19 + while t <= 27 + Xloop 'c' + try + if t == 19 + let v{THR(t) + CONT(t)} = 0 + elseif t == 20 + let v{THR(t) + CONT(t)} + elseif t == 21 + let var = exists('v{THR(t) + CONT(t)}') + elseif t == 22 + unlet v{THR(t) + CONT(t)} + elseif t == 23 + function F{THR(t) + CONT(t)}() + endfunction + elseif t == 24 + function F{THR(t) + CONT(t)} + elseif t == 25 + let var = exists('*F{THR(t) + CONT(t)}') + elseif t == 26 + delfunction F{THR(t) + CONT(t)} + elseif t == 27 + let var = THR(t) + CONT(t) + endif + catch /^Vim\((\a\+)\)\=:/ + " An error exception has been triggered after the :throw. + let v:errmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "") + finally + call MSG(t) + let t = t + 1 + XloopNEXT + continue " discard exception + endtry + endwhile + catch /.*/ + call assert_report('should not get here') + endtry + + let v{ERR(28) + CONT(28)} = 0 + call MSG(28) + let v{ERR(29) + CONT(29)} + call MSG(29) + let var = exists('v{ERR(30) + CONT(30)}') + call MSG(30) + unlet v{ERR(31) + CONT(31)} + call MSG(31) + function F{ERR(32) + CONT(32)}() + endfunction + call MSG(32) + function F{ERR(33) + CONT(33)} + call MSG(33) + let var = exists('*F{ERR(34) + CONT(34)}') + call MSG(34) + delfunction F{ERR(35) + CONT(35)} + call MSG(35) + let var = ERR(36) + CONT(36) + call MSG(36) + + let saved_errmsg = "" + + let v{WRAP(37, ERRabort(37)) + CONT(37)} = 0 + call MSG(37) + let v{WRAP(38, ERRabort(38)) + CONT(38)} + call MSG(38) + let var = exists('v{WRAP(39, ERRabort(39)) + CONT(39)}') + call MSG(39) + unlet v{WRAP(40, ERRabort(40)) + CONT(40)} + call MSG(40) + function F{WRAP(41, ERRabort(41)) + CONT(41)}() + endfunction + call MSG(41) + function F{WRAP(42, ERRabort(42)) + CONT(42)} + call MSG(42) + let var = exists('*F{WRAP(43, ERRabort(43)) + CONT(43)}') + call MSG(43) + delfunction F{WRAP(44, ERRabort(44)) + CONT(44)} + call MSG(44) + let var = ERRabort(45) + CONT(45) + call MSG(45) + Xpath 'd' + + let expected = "" + \ .. "E1M1E2M2E3M3E4M4E5M5E6M6E7M7E8M8E9M9" + \ .. "I10M10I11M11I12M12I13M13I14M14I15M15I16M16I17M17I18M18" + \ .. "T19M19T20M20T21M21T22M22T23M23T24M24T25M25T26M26T27M27" + \ .. "E28C28M28E29C29M29E30C30M30E31C31M31E32C32M32E33C33M33" + \ .. "E34C34M34E35C35M35E36C36M36" + \ .. "A37W37C37M37A38W38C38M38A39W39C39M39A40W40C40M40A41W41C41M41" + \ .. "A42W42C42M42A43W43C43M43A44W44C44M44A45C45M45" + call assert_equal(expected, taken) + [CODE] + let verify =<< trim [CODE] + let expected = "a1a2a3a4a5a6a7a8a9" + \ .. "b10b11b12b13b14b15b16b17b18" + \ .. "c19c20c21c22c23c24c25c26c27d" + call assert_equal(expected, g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 77: Errors, interrupts, :throw in name{brace-expression} {{{1 +" +" When a function call made during evaluation of an expression in +" braces as part of a function name after ":function" is aborted due +" to an error inside a :try/:endtry region or due to an interrupt or +" a :throw, the expression evaluation is aborted as well, and the +" function definition is ignored, skipping all commands to the +" ":endfunction". On an error not inside :try/:endtry, the expression +" evaluation continues and the function gets defined, and can be +" called and deleted. +"------------------------------------------------------------------------------- +func Test_brace_expr_error() + let test =<< trim [CODE] + func ERR() abort + Xloop 'a' + asdf + endfunc " returns -1 + + func OK() + Xloop 'b' + let v:errmsg = "" + return 0 + endfunc + + let v:errmsg = "" + + Xpath 'c' + func F{1 + ERR() + OK()}(arg) + " F0 should be defined. + if exists("a:arg") && a:arg == "calling" + Xpath 'd' + else + call assert_report('should not get here') + endif + endfunction + call assert_equal("", v:errmsg) + XloopNEXT + + Xpath 'e' + call F{1 + ERR() + OK()}("calling") + call assert_equal("", v:errmsg) + XloopNEXT + + Xpath 'f' + delfunction F{1 + ERR() + OK()} + call assert_equal("", v:errmsg) + XloopNEXT + + try + while 1 + try + Xpath 'g' + func G{1 + ERR() + OK()}(arg) + " G0 should not be defined, and the function body should be + " skipped. + call assert_report('should not get here') + " Use an unmatched ":finally" to check whether the body is + " skipped when an error occurs in ERR(). This works whether or + " not the exception is converted to an exception. + finally + call assert_report('should not get here') + endtry + try + call assert_report('should not get here') + endfunction + + call assert_report('should not get here') + catch /asdf/ + " Jumped to when the function is not defined and the body is + " skipped. + Xpath 'h' + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'i' + break + endtry " jumped to when the body is not skipped + endwhile + catch /.*/ + call assert_report('should not get here') + endtry + [CODE] + let verify =<< trim [CODE] + call assert_equal('ca1b1ea2b2dfa3b3ga4hi', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 78: Messages on parsing errors in expression evaluation {{{1 +" +" When an expression evaluation detects a parsing error, an error +" message is given and converted to an exception, and the expression +" evaluation is aborted. +"------------------------------------------------------------------------------- +func Test_expr_eval_error_msg() + CheckEnglish + + let test =<< trim [CODE] + let taken = "" + + func F(n) + let g:taken = g:taken . "F" . a:n + endfunc + + func MSG(n, enr, emsg) + let g:taken = g:taken . "M" . a:n + call assert_match('^' .. a:enr .. ':', v:errmsg) + call assert_match(a:emsg, v:errmsg) + endfunc + + func CONT(n) + let g:taken = g:taken . "C" . a:n + endfunc + + let v:errmsg = "" + try + let t = 1 + while t <= 14 + let g:taken = g:taken . "T" . t + let v:errmsg = "" + try + if t == 1 + let v{novar + CONT(t)} = 0 + elseif t == 2 + let v{novar + CONT(t)} + elseif t == 3 + let var = exists('v{novar + CONT(t)}') + elseif t == 4 + unlet v{novar + CONT(t)} + elseif t == 5 + function F{novar + CONT(t)}() + endfunction + elseif t == 6 + function F{novar + CONT(t)} + elseif t == 7 + let var = exists('*F{novar + CONT(t)}') + elseif t == 8 + delfunction F{novar + CONT(t)} + elseif t == 9 + echo novar + CONT(t) + elseif t == 10 + echo v{novar + CONT(t)} + elseif t == 11 + echo F{novar + CONT(t)} + elseif t == 12 + let var = novar + CONT(t) + elseif t == 13 + let var = v{novar + CONT(t)} + elseif t == 14 + let var = F{novar + CONT(t)}() + endif + catch /^Vim\((\a\+)\)\=:/ + Xloop 'a' + " v:errmsg is not set when the error message is converted to an + " exception. Set it to the original error message. + let v:errmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "") + finally + Xloop 'b' + if t <= 8 && t != 3 && t != 7 + call MSG(t, 'E475', 'Invalid argument\>') + else + call MSG(t, 'E121', "Undefined variable") + endif + let t = t + 1 + XloopNEXT + continue " discard an aborting error + endtry + endwhile + catch /.*/ + call assert_report('should not get here') + endtry + + func T(n, expr, enr, emsg) + try + let g:taken = g:taken . "T" . a:n + let v:errmsg = "" + try + execute "let var = " . a:expr + catch /^Vim\((\a\+)\)\=:/ + Xloop 'c' + " v:errmsg is not set when the error message is converted to an + " exception. Set it to the original error message. + let v:errmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "") + finally + Xloop 'd' + call MSG(a:n, a:enr, a:emsg) + XloopNEXT + " Discard an aborting error: + return + endtry + catch /.*/ + call assert_report('should not get here') + endtry + endfunc + + call T(15, 'Nofunc() + CONT(15)', 'E117', "Unknown function") + call T(16, 'F(1 2 + CONT(16))', 'E116', "Invalid arguments") + call T(17, 'F(1, 2) + CONT(17)', 'E118', "Too many arguments") + call T(18, 'F() + CONT(18)', 'E119', "Not enough arguments") + call T(19, '{(1} + CONT(19)', 'E110', "Missing ')'") + call T(20, '("abc"[1) + CONT(20)', 'E111', "Missing ']'") + call T(21, '(1 +) + CONT(21)', 'E15', "Invalid expression") + call T(22, '1 2 + CONT(22)', 'E15', "Invalid expression") + call T(23, '(1 ? 2) + CONT(23)', 'E109', "Missing ':' after '?'") + call T(24, '("abc) + CONT(24)', 'E114', "Missing quote") + call T(25, "('abc) + CONT(25)", 'E115', "Missing quote") + call T(26, '& + CONT(26)', 'E112', "Option name missing") + call T(27, '&asdf + CONT(27)', 'E113', "Unknown option") + + let expected = "" + \ .. "T1M1T2M2T3M3T4M4T5M5T6M6T7M7T8M8T9M9T10M10T11M11T12M12T13M13T14M14" + \ .. "T15M15T16M16T17M17T18M18T19M19T20M20T21M21T22M22T23M23T24M24T25M25" + \ .. "T26M26T27M27" + + call assert_equal(expected, taken) + [CODE] + let verify =<< trim [CODE] + let expected = "a1b1a2b2a3b3a4b4a5b5a6b6a7b7a8b8a9b9a10b10a11b11a12b12" + \ .. "a13b13a14b14c15d15c16d16c17d17c18d18c19d19c20d20" + \ .. "c21d21c22d22c23d23c24d24c25d25c26d26c27d27" + call assert_equal(expected, g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 79: Throwing one of several errors for the same command {{{1 +" +" When several errors appear in a row (for instance during expression +" evaluation), the first as the most specific one is used when +" throwing an error exception. If, however, a syntax error is +" detected afterwards, this one is used for the error exception. +" On a syntax error, the next command is not executed, on a normal +" error, however, it is (relevant only in a function without the +" "abort" flag). v:errmsg is not set. +" +" If throwing error exceptions is configured off, v:errmsg is always +" set to the latest error message, that is, to the more general +" message or the syntax error, respectively. +"------------------------------------------------------------------------------- +func Test_throw_multi_error() + CheckEnglish + + let test =<< trim [CODE] + func NEXT(cmd) + exec a:cmd . " | Xloop 'a'" + endfun + + call NEXT('echo novar') " (checks nextcmd) + XloopNEXT + call NEXT('let novar #') " (skips nextcmd) + XloopNEXT + call NEXT('unlet novar #') " (skips nextcmd) + XloopNEXT + call NEXT('let {novar}') " (skips nextcmd) + XloopNEXT + call NEXT('unlet{ novar}') " (skips nextcmd) + + call assert_equal('a1', g:Xpath) + XpathINIT + XloopINIT + + func EXEC(cmd) + exec a:cmd + endfunc + + try + while 1 " dummy loop + try + let v:errmsg = "" + call EXEC('echo novar') " normal error + catch /^Vim\((\a\+)\)\=:/ + Xpath 'b' + call assert_match('E121: Undefined variable: novar', v:exception) + finally + Xpath 'c' + call assert_equal("", v:errmsg) + break + endtry + endwhile + + Xpath 'd' + let cmd = "let" + while cmd != "" + try + let v:errmsg = "" + call EXEC(cmd . ' novar #') " normal plus syntax error + catch /^Vim\((\a\+)\)\=:/ + Xloop 'e' + call assert_match('E488: Trailing characters', v:exception) + finally + Xloop 'f' + call assert_equal("", v:errmsg) + if cmd == "let" + let cmd = "unlet" + else + let cmd = "" + endif + XloopNEXT + continue + endtry + endwhile + + Xpath 'g' + let cmd = "let" + while cmd != "" + try + let v:errmsg = "" + call EXEC(cmd . ' {novar}') " normal plus syntax error + catch /^Vim\((\a\+)\)\=:/ + Xloop 'h' + call assert_match('E475: Invalid argument: {novar}', v:exception) + finally + Xloop 'i' + call assert_equal("", v:errmsg) + if cmd == "let" + let cmd = "unlet" + else + let cmd = "" + endif + XloopNEXT + continue + endtry + endwhile + catch /.*/ + call assert_report('should not get here') + endtry + Xpath 'j' + [CODE] + let verify =<< trim [CODE] + call assert_equal('bcde1f1e2f2gh3i3h4i4j', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 80: Syntax error in expression for illegal :elseif {{{1 +" +" If there is a syntax error in the expression after an illegal +" :elseif, an error message is given (or an error exception thrown) +" for the illegal :elseif rather than the expression error. +"------------------------------------------------------------------------------- +func Test_if_syntax_error() + CheckEnglish + + let test =<< trim [CODE] + let v:errmsg = "" + if 0 + else + elseif 1 ||| 2 + endif + Xpath 'a' + call assert_match('E584: :elseif after :else', v:errmsg) + + let v:errmsg = "" + if 1 + else + elseif 1 ||| 2 + endif + Xpath 'b' + call assert_match('E584: :elseif after :else', v:errmsg) + + let v:errmsg = "" + elseif 1 ||| 2 + Xpath 'c' + call assert_match('E582: :elseif without :if', v:errmsg) + + let v:errmsg = "" + while 1 + elseif 1 ||| 2 + endwhile + Xpath 'd' + call assert_match('E582: :elseif without :if', v:errmsg) + + while 1 + try + try + let v:errmsg = "" + if 0 + else + elseif 1 ||| 2 + endif + catch /^Vim\((\a\+)\)\=:/ + Xpath 'e' + call assert_match('E584: :elseif after :else', v:exception) + finally + Xpath 'f' + call assert_equal("", v:errmsg) + endtry + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'g' + break + endtry + endwhile + + while 1 + try + try + let v:errmsg = "" + if 1 + else + elseif 1 ||| 2 + endif + catch /^Vim\((\a\+)\)\=:/ + Xpath 'h' + call assert_match('E584: :elseif after :else', v:exception) + finally + Xpath 'i' + call assert_equal("", v:errmsg) + endtry + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'j' + break + endtry + endwhile + + while 1 + try + try + let v:errmsg = "" + elseif 1 ||| 2 + catch /^Vim\((\a\+)\)\=:/ + Xpath 'k' + call assert_match('E582: :elseif without :if', v:exception) + finally + Xpath 'l' + call assert_equal("", v:errmsg) + endtry + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'm' + break + endtry + endwhile + + while 1 + try + try + let v:errmsg = "" + while 1 + elseif 1 ||| 2 + endwhile + catch /^Vim\((\a\+)\)\=:/ + Xpath 'n' + call assert_match('E582: :elseif without :if', v:exception) + finally + Xpath 'o' + call assert_equal("", v:errmsg) + endtry + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'p' + break + endtry + endwhile + Xpath 'q' + [CODE] + let verify =<< trim [CODE] + call assert_equal('abcdefghijklmnopq', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 81: Discarding exceptions after an error or interrupt {{{1 +" +" When an exception is thrown from inside a :try conditional without +" :catch and :finally clauses and an error or interrupt occurs before +" the :endtry is reached, the exception is discarded. +"------------------------------------------------------------------------------- + +func Test_discard_exception_after_error_1() + let test =<< trim [CODE] + try + Xpath 'a' + try + Xpath 'b' + throw "arrgh" + call assert_report('should not get here') + if 1 + call assert_report('should not get here') + " error after :throw: missing :endif + endtry + call assert_report('should not get here') + catch /arrgh/ + call assert_report('should not get here') + endtry + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('ab', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +" TODO: Not able inject an interrupt after throwing an exception +func Disable_Test_discard_exception_after_error_2() + let test =<< trim [CODE] + try + Xpath 'a' + try + Xpath 'b' + throw "arrgh" + call interrupt() " FIXME: throw is not interrupted here + call assert_report('should not get here') + endtry + call assert_report('should not get here') + catch /arrgh/ + call assert_report('should not get here') + endtry + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('ab', g:Xpath) + [CODE] + call RunInNewVim(test, verify) endfunc "------------------------------------------------------------------------------- -- cgit From d5dd7573f32411746867b935b8db2165d14018ec Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Nov 2022 05:02:57 +0800 Subject: vim-patch:8.2.3713: MS-Windows: no error if vimgrep pattern is not matching (#20947) Problem: MS-Windows: No error message if vimgrep pattern is not matching. Solution: Give an error message. (Christian Brabandt, closes vim/vim#9245, closes vim/vim#8762) https://github.com/vim/vim/commit/0b226f60be5c30c32fb01fc0b6dc11286e7e2313 Co-authored-by: Christian Brabandt --- src/nvim/testdir/test_quickfix.vim | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 99d9c9c1fa..9d9fc5e77b 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -5801,6 +5801,21 @@ func Test_win_gettype() lclose endfunc +fun Test_vimgrep_nomatch() + call XexprTests('c') + call g:Xsetlist([{'lnum':10,'text':'Line1'}]) + copen + if has("win32") + call assert_fails('vimgrep foo *.zzz', 'E479:') + let expected = [{'lnum': 10, 'bufnr': 0, 'end_lnum': 0, 'pattern': '', 'valid': 0, 'vcol': 0, 'nr': 0, 'module': '', 'type': '', 'end_col': 0, 'col': 0, 'text': 'Line1'}] + else + call assert_fails('vimgrep foo *.zzz', 'E480:') + let expected = [] + endif + call assert_equal(expected, getqflist()) + cclose +endfunc + " Test for opening the quickfix window in two tab pages and then closing one " of the quickfix windows. This should not make the quickfix buffer unlisted. " (github issue #9300). -- cgit From e03f23189d765ade07b21d2f50c047f84741a133 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Nov 2022 06:31:00 +0800 Subject: vim-patch:8.2.1274: Vim9: no error for missing white space at script level Problem: Vim9: no error for missing white space in assignment at script level. Solution: Check for white space. (closes vim/vim#6495) https://github.com/vim/vim/commit/63be3d4ba01d565e645d8bf7f4dc900fc9011534 Cherry-pick Test_let_errors() change from patch 8.2.0633. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_let.vim | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_let.vim b/src/nvim/testdir/test_let.vim index f05e06f774..79619b0f1e 100644 --- a/src/nvim/testdir/test_let.vim +++ b/src/nvim/testdir/test_let.vim @@ -276,20 +276,27 @@ func Test_let_errors() let s = "var" let var = 1 call assert_fails('let var += [1,2]', 'E734:') - call assert_fails('let {s}.1 = 2', 'E18:') + call assert_fails('let {s}.1 = 2', 'E15:') call assert_fails('let a[1] = 5', 'E121:') let l = [[1,2]] call assert_fails('let l[:][0] = [5]', 'E708:') let d = {'k' : 4} - call assert_fails('let d.# = 5', 'E713:') + call assert_fails('let d.# = 5', 'E488:') call assert_fails('let d.m += 5', 'E734:') + call assert_fails('let m = d[{]', 'E15:') let l = [1, 2] call assert_fails('let l[2] = 0', 'E684:') call assert_fails('let l[0:1] = [1, 2, 3]', 'E710:') call assert_fails('let l[-2:-3] = [3, 4]', 'E684:') call assert_fails('let l[0:4] = [5, 6]', 'E711:') + call assert_fails('let l -= 2', 'E734:') + call assert_fails('let l += 2', 'E734:') call assert_fails('let g:["a;b"] = 10', 'E461:') call assert_fails('let g:.min = function("max")', 'E704:') + if has('channel') + let ch = test_null_channel() + call assert_fails('let ch += 1', 'E734:') + endif " This test works only when the language is English if v:lang == "C" || v:lang =~ '^[Ee]n' -- cgit From 1f0bf65ad6ce6df3eedfb013cf9b95aed2a90781 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Nov 2022 06:35:34 +0800 Subject: vim-patch:8.2.1306: checking for first character of dict key is inconsistent Problem: Checking for first character of dict key is inconsistent. Solution: Add eval_isdictc(). (closes vim/vim#6546) https://github.com/vim/vim/commit/b13ab99908097d54e21ab5adad22f4ad2a8ec688 Omit handle_subscript() change: only affects Vim9 script. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_let.vim | 2 +- src/nvim/testdir/test_listdict.vim | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_let.vim b/src/nvim/testdir/test_let.vim index 79619b0f1e..e8bc2ac155 100644 --- a/src/nvim/testdir/test_let.vim +++ b/src/nvim/testdir/test_let.vim @@ -276,7 +276,7 @@ func Test_let_errors() let s = "var" let var = 1 call assert_fails('let var += [1,2]', 'E734:') - call assert_fails('let {s}.1 = 2', 'E15:') + call assert_fails('let {s}.1 = 2', 'E18:') call assert_fails('let a[1] = 5', 'E121:') let l = [[1,2]] call assert_fails('let l[:][0] = [5]', 'E708:') diff --git a/src/nvim/testdir/test_listdict.vim b/src/nvim/testdir/test_listdict.vim index ecf95ba8c0..21d21ce428 100644 --- a/src/nvim/testdir/test_listdict.vim +++ b/src/nvim/testdir/test_listdict.vim @@ -289,6 +289,13 @@ func Test_dict_func() call assert_equal('xxx3', Fn('xxx')) endfunc +func Test_dict_assign() + let d = {} + let d.1 = 1 + let d._ = 2 + call assert_equal({'1': 1, '_': 2}, d) +endfunc + " Function in script-local List or Dict func Test_script_local_dict_func() let g:dict = {} -- cgit From fa2ed8ca1fbf98053e8273d814322018895d6b9b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Nov 2022 06:47:08 +0800 Subject: vim-patch:8.2.2723: assignment test fails Problem: Assignment test fails. Solution: Adjust error number. https://github.com/vim/vim/commit/58fb7c39a04aabfa399ae4f2142ee0728bc22483 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_let.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_let.vim b/src/nvim/testdir/test_let.vim index e8bc2ac155..3ef3d961a7 100644 --- a/src/nvim/testdir/test_let.vim +++ b/src/nvim/testdir/test_let.vim @@ -282,7 +282,7 @@ func Test_let_errors() call assert_fails('let l[:][0] = [5]', 'E708:') let d = {'k' : 4} call assert_fails('let d.# = 5', 'E488:') - call assert_fails('let d.m += 5', 'E734:') + call assert_fails('let d.m += 5', 'E716:') call assert_fails('let m = d[{]', 'E15:') let l = [1, 2] call assert_fails('let l[2] = 0', 'E684:') -- cgit From 7d7208a88b2bb078c9c2727e93ef390f2a564027 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Nov 2022 06:47:54 +0800 Subject: vim-patch:8.2.3016: confusing error when expression is followed by comma Problem: Confusing error when expression is followed by comma. Solution: Give a different error for trailing text. (closes vim/vim#8395) https://github.com/vim/vim/commit/fae55a9cb0838e4c2e634e55a3468af4a75fbdf2 Omit test_eval_stuff.vim and test_viminfo.vim: changes tests are N/A. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_let.vim | 1 + src/nvim/testdir/test_vimscript.vim | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_let.vim b/src/nvim/testdir/test_let.vim index 3ef3d961a7..48c5699093 100644 --- a/src/nvim/testdir/test_let.vim +++ b/src/nvim/testdir/test_let.vim @@ -297,6 +297,7 @@ func Test_let_errors() let ch = test_null_channel() call assert_fails('let ch += 1', 'E734:') endif + call assert_fails('let name = "a" .. "b",', 'E488: Trailing characters: ,') " This test works only when the language is English if v:lang == "C" || v:lang =~ '^[Ee]n' diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index 8faa9135e5..44904af160 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -5569,7 +5569,7 @@ func Test_expr_eval_error_msg() call T(19, '{(1} + CONT(19)', 'E110', "Missing ')'") call T(20, '("abc"[1) + CONT(20)', 'E111', "Missing ']'") call T(21, '(1 +) + CONT(21)', 'E15', "Invalid expression") - call T(22, '1 2 + CONT(22)', 'E15', "Invalid expression") + call T(22, '1 2 + CONT(22)', 'E488', "Trailing characters: 2 +") call T(23, '(1 ? 2) + CONT(23)', 'E109', "Missing ':' after '?'") call T(24, '("abc) + CONT(24)', 'E114', "Missing quote") call T(25, "('abc) + CONT(25)", 'E115', "Missing quote") -- cgit From 7683199a9bf5d84745a10222feddc43343410068 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 28 Oct 2022 11:53:22 +0800 Subject: vim-patch:8.2.2918: builtin function can be shadowed by global variable Problem: Builtin function can be shadowed by global variable. Solution: Check for builtin function before variable. (Yasuhiro Matsumoto, closes vim/vim#8302) https://github.com/vim/vim/commit/3d9c4eefe656ee8bf58c0496a48bd56bac180056 Cherry-pick Test_gettext() from patch 8.2.2886. --- src/nvim/testdir/test_functions.vim | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index d2603809b9..afeea20f2d 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -2478,4 +2478,17 @@ func Test_default_arg_value() call assert_equal('msg', HasDefault()) endfunc +" Test for gettext() +func Test_gettext() + call assert_fails('call gettext(1)', 'E475:') +endfunc + +func Test_builtin_check() + call assert_fails('let g:["trim"] = {x -> " " .. x}', 'E704:') + call assert_fails('let g:.trim = {x -> " " .. x}', 'E704:') + call assert_fails('let s:["trim"] = {x -> " " .. x}', 'E704:') + call assert_fails('let s:.trim = {x -> " " .. x}', 'E704:') +endfunc + + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 6b3db3f92906b1c155b11f177c9378d9ff4d7d6b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 28 Oct 2022 11:56:29 +0800 Subject: vim-patch:8.2.2920: still a way to shadow a builtin function Problem: Still a way to shadow a builtin function. (Yasuhiro Matsumoto) Solution: Check the key when using extend(). (issue vim/vim#8302) https://github.com/vim/vim/commit/6f1d2aa437744a7cb0206fdaa543a788c5a56c79 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_functions.vim | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index afeea20f2d..011e9e000e 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -2488,6 +2488,11 @@ func Test_builtin_check() call assert_fails('let g:.trim = {x -> " " .. x}', 'E704:') call assert_fails('let s:["trim"] = {x -> " " .. x}', 'E704:') call assert_fails('let s:.trim = {x -> " " .. x}', 'E704:') + + call assert_fails('call extend(g:, #{foo: { -> "foo" }})', 'E704:') + let g:bar = 123 + call extend(g:, #{bar: { -> "foo" }}, "keep") + call assert_fails('call extend(g:, #{bar: { -> "foo" }}, "force")', 'E704:') endfunc -- cgit From 4740672b37612004d559e9577ca87223ed49ec64 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 28 Oct 2022 12:08:18 +0800 Subject: vim-patch:8.2.2921: E704 for script local variable is not backwards compatible Problem: E704 for script local variable is not backwards compatible. (Yasuhiro Matsumoto) Solution: Only give the error in Vim9 script. Also check for function-local variable. https://github.com/vim/vim/commit/b54abeeafb074248597878a874fed9a66b114c06 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_functions.vim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 011e9e000e..dbb39d0f23 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -2486,8 +2486,13 @@ endfunc func Test_builtin_check() call assert_fails('let g:["trim"] = {x -> " " .. x}', 'E704:') call assert_fails('let g:.trim = {x -> " " .. x}', 'E704:') - call assert_fails('let s:["trim"] = {x -> " " .. x}', 'E704:') - call assert_fails('let s:.trim = {x -> " " .. x}', 'E704:') + call assert_fails('let l:["trim"] = {x -> " " .. x}', 'E704:') + call assert_fails('let l:.trim = {x -> " " .. x}', 'E704:') + let lines =<< trim END + vim9script + var s:trim = (x) => " " .. x + END + " call CheckScriptFailure(lines, 'E704:') call assert_fails('call extend(g:, #{foo: { -> "foo" }})', 'E704:') let g:bar = 123 -- cgit From d4353c3645f294b67f5b30dae9f39de8f99c7413 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Nov 2022 07:01:45 +0800 Subject: vim-patch:9.0.0836: wrong error when using extend() with funcref Problem: Wrong error when using extend() with funcref. Solution: Better check the variable type. (closes vim/vim#11468, closes vim/vim#11455) https://github.com/vim/vim/commit/91c75d18d9cdc32df57e648640de7476fbcb4d76 --- src/nvim/testdir/test_functions.vim | 19 +++++++++++++++++++ src/nvim/testdir/test_let.vim | 1 + 2 files changed, 20 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index dbb39d0f23..743022ece4 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -2498,6 +2498,25 @@ func Test_builtin_check() let g:bar = 123 call extend(g:, #{bar: { -> "foo" }}, "keep") call assert_fails('call extend(g:, #{bar: { -> "foo" }}, "force")', 'E704:') + unlet g:bar + + call assert_fails('call extend(l:, #{foo: { -> "foo" }})', 'E704:') + let bar = 123 + call extend(l:, #{bar: { -> "foo" }}, "keep") + call assert_fails('call extend(l:, #{bar: { -> "foo" }}, "force")', 'E704:') + unlet bar + + call assert_fails('call extend(g:, #{foo: function("extend")})', 'E704:') + let g:bar = 123 + call extend(g:, #{bar: function("extend")}, "keep") + call assert_fails('call extend(g:, #{bar: function("extend")}, "force")', 'E704:') + unlet g:bar + + call assert_fails('call extend(l:, #{foo: function("extend")})', 'E704:') + let bar = 123 + call extend(l:, #{bar: function("extend")}, "keep") + call assert_fails('call extend(l:, #{bar: function("extend")}, "force")', 'E704:') + unlet bar endfunc diff --git a/src/nvim/testdir/test_let.vim b/src/nvim/testdir/test_let.vim index 48c5699093..cb883fc238 100644 --- a/src/nvim/testdir/test_let.vim +++ b/src/nvim/testdir/test_let.vim @@ -293,6 +293,7 @@ func Test_let_errors() call assert_fails('let l += 2', 'E734:') call assert_fails('let g:["a;b"] = 10', 'E461:') call assert_fails('let g:.min = function("max")', 'E704:') + call assert_fails('let g:cos = "" | let g:.cos = {-> 42}', 'E704:') if has('channel') let ch = test_null_channel() call assert_fails('let ch += 1', 'E734:') -- cgit From 7404c6010dd7abd4339a4ffd6961f2a420fe7ddb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Nov 2022 14:50:09 +0800 Subject: vim-patch:8.2.3055: strange error for assigning to "x.key" on non-dictionary Problem: Strange error for assigning to "x.key" on non-dictionary. Solution: Add a specific error message. (closes vim/vim#8451) https://github.com/vim/vim/commit/3a3b10e87a10dd0bc355618dbfc4a0a6c828aad7 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_let.vim | 2 +- src/nvim/testdir/test_listdict.vim | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_let.vim b/src/nvim/testdir/test_let.vim index cb883fc238..49f656c787 100644 --- a/src/nvim/testdir/test_let.vim +++ b/src/nvim/testdir/test_let.vim @@ -276,7 +276,7 @@ func Test_let_errors() let s = "var" let var = 1 call assert_fails('let var += [1,2]', 'E734:') - call assert_fails('let {s}.1 = 2', 'E18:') + call assert_fails('let {s}.1 = 2', 'E1203:') call assert_fails('let a[1] = 5', 'E121:') let l = [[1,2]] call assert_fails('let l[:][0] = [5]', 'E708:') diff --git a/src/nvim/testdir/test_listdict.vim b/src/nvim/testdir/test_listdict.vim index 21d21ce428..3d90222b90 100644 --- a/src/nvim/testdir/test_listdict.vim +++ b/src/nvim/testdir/test_listdict.vim @@ -294,6 +294,9 @@ func Test_dict_assign() let d.1 = 1 let d._ = 2 call assert_equal({'1': 1, '_': 2}, d) + + let n = 0 + call assert_fails('let n.key = 3', 'E1203: Dot can only be used on a dictionary: n.key = 3') endfunc " Function in script-local List or Dict -- cgit From ed01ef7fa5c2611748f90acfdc2145b22629dc36 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Nov 2022 15:11:48 +0800 Subject: vim-patch:9.0.0355: check for uppercase char in autoload name is wrong Problem: Check for uppercase char in autoload name is wrong, it checks the name of the script. Solution: Remove the check. (closes vim/vim#11031) https://github.com/vim/vim/commit/6c667bdc9489963102bd6c46b1b73e4d43c034ce Co-authored-by: thinca --- src/nvim/testdir/test_let.vim | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_let.vim b/src/nvim/testdir/test_let.vim index 49f656c787..35745e9c6a 100644 --- a/src/nvim/testdir/test_let.vim +++ b/src/nvim/testdir/test_let.vim @@ -6,6 +6,10 @@ func Test_let() let Test104#numvar = function('tr') call assert_equal("function('tr')", string(Test104#numvar)) + let foo#tr = function('tr') + call assert_equal("function('tr')", string(foo#tr)) + unlet foo#tr + let a = 1 let b = 2 -- cgit From cac576322d4b22c0fa7ba7564ba7ca9656fc96b9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Nov 2022 15:52:42 +0800 Subject: vim-patch:8.2.1736: failure to compile a pattern not tested much Problem: Failure to compile a pattern not tested much. Solution: Add tests where a pattern fails to compile. (Yegappan Lakshmanan, closes vim/vim#7004) https://github.com/vim/vim/commit/531be47ac5522807b265c6287021a01c9b895ac9 --- src/nvim/testdir/test_autocmd.vim | 1 + src/nvim/testdir/test_buffer.vim | 1 + src/nvim/testdir/test_checkpath.vim | 17 +++++++++++++++++ src/nvim/testdir/test_cmdline.vim | 2 ++ src/nvim/testdir/test_functions.vim | 1 + src/nvim/testdir/test_listdict.vim | 1 + src/nvim/testdir/test_options.vim | 1 + src/nvim/testdir/test_search_stat.vim | 8 ++++++++ src/nvim/testdir/test_sort.vim | 1 + src/nvim/testdir/test_substitute.vim | 1 + src/nvim/testdir/test_syntax.vim | 2 ++ src/nvim/testdir/test_tagjump.vim | 4 ++++ src/nvim/testdir/test_user_func.vim | 3 +++ 13 files changed, 43 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 50904bab34..1488fe8431 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -2865,6 +2865,7 @@ func Test_autocmd_invalid_args() call assert_fails('doautocmd * BufEnter', 'E217:') call assert_fails('augroup! x1a2b3', 'E367:') call assert_fails('autocmd BufNew pwd', 'E680:') + call assert_fails('autocmd BufNew \) set ff=unix', 'E55:') endfunc " Test for deep nesting of autocmds diff --git a/src/nvim/testdir/test_buffer.vim b/src/nvim/testdir/test_buffer.vim index 27c2d5d442..f4aa3b5238 100644 --- a/src/nvim/testdir/test_buffer.vim +++ b/src/nvim/testdir/test_buffer.vim @@ -147,6 +147,7 @@ func Test_bdelete_cmd() %bwipe! call assert_fails('bdelete 5', 'E516:') call assert_fails('1,1bdelete 1 2', 'E488:') + call assert_fails('bdelete \)', 'E55:') " Deleting a unlisted and unloaded buffer edit Xfile1 diff --git a/src/nvim/testdir/test_checkpath.vim b/src/nvim/testdir/test_checkpath.vim index eff30cf205..f6a3bbce08 100644 --- a/src/nvim/testdir/test_checkpath.vim +++ b/src/nvim/testdir/test_checkpath.vim @@ -102,3 +102,20 @@ func Test_checkpath3() set include& set includeexpr& endfunc + +" Test for invalid regex in 'include' and 'define' options +func Test_checkpath_errors() + let save_include = &include + set include=\\%( + call assert_fails('checkpath', 'E53:') + let &include = save_include + + let save_define = &define + set define=\\%( + call assert_fails('dsearch abc', 'E53:') + let &define = save_define + + call assert_fails('psearch \%(', 'E53:') +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index c00172ed68..7cef3117c2 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -316,6 +316,8 @@ func Test_map_completion() unmap " set cpo-=k + call assert_fails('call feedkeys(":map \\\\%(\\\"\", "xt")', 'E53:') + unmap x set cpo&vim endfunc diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 743022ece4..b464f6591d 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -941,6 +941,7 @@ func Test_match_func() call assert_equal(4, match('testing', 'ing', -1)) call assert_fails("let x=match('testing', 'ing', 0, [])", 'E745:') call assert_equal(-1, match(v:_null_list, 2)) + call assert_equal(-1, match('abc', '\\%(')) endfunc func Test_matchend() diff --git a/src/nvim/testdir/test_listdict.vim b/src/nvim/testdir/test_listdict.vim index 3d90222b90..7ea488f41d 100644 --- a/src/nvim/testdir/test_listdict.vim +++ b/src/nvim/testdir/test_listdict.vim @@ -754,6 +754,7 @@ func Test_str_split() call assert_equal(['', 'a', '', 'b', '', 'c', ''], split('abc', '\zs', 1)) call assert_fails("call split('abc', [])", 'E730:') call assert_fails("call split('abc', 'b', [])", 'E745:') + call assert_equal(['abc'], split('abc', '\\%(')) endfunc " compare recursively linked list and dict diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index 3916d7c554..80569bde03 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -399,6 +399,7 @@ func Test_set_errors() call assert_fails('set pyxversion=6', 'E474:') endif call assert_fails("let &tabstop='ab'", 'E521:') + call assert_fails('set spellcapcheck=%\\(', 'E54:') call assert_fails('set sessionoptions=curdir,sesdir', 'E474:') call assert_fails('set foldmarker={{{,', 'E474:') call assert_fails('set sessionoptions=sesdir,curdir', 'E474:') diff --git a/src/nvim/testdir/test_search_stat.vim b/src/nvim/testdir/test_search_stat.vim index 89e09cf85b..77bd50ada2 100644 --- a/src/nvim/testdir/test_search_stat.vim +++ b/src/nvim/testdir/test_search_stat.vim @@ -260,6 +260,14 @@ endfunc func Test_searchcount_fails() call assert_fails('echo searchcount("boo!")', 'E715:') + call assert_fails('echo searchcount({"timeout" : []})', 'E745:') + call assert_fails('echo searchcount({"maxcount" : []})', 'E745:') + call assert_fails('echo searchcount({"pattern" : []})', 'E730:') + call assert_fails('echo searchcount({"pos" : 1})', 'E475:') + call assert_fails('echo searchcount({"pos" : [1]})', 'E475:') + call assert_fails('echo searchcount({"pos" : [[], 2, 3]})', 'E745:') + call assert_fails('echo searchcount({"pos" : [1, [], 3]})', 'E745:') + call assert_fails('echo searchcount({"pos" : [1, 2, []]})', 'E745:') endfunc func Test_searchcount_in_statusline() diff --git a/src/nvim/testdir/test_sort.vim b/src/nvim/testdir/test_sort.vim index f9cbcbb55f..534393b724 100644 --- a/src/nvim/testdir/test_sort.vim +++ b/src/nvim/testdir/test_sort.vim @@ -1361,6 +1361,7 @@ func Test_sort_cmd() call assert_fails('sort no', 'E474:') call assert_fails('sort c', 'E475:') call assert_fails('sort #pat%', 'E654:') + call assert_fails('sort /\%(/', 'E53:') enew! endfunc diff --git a/src/nvim/testdir/test_substitute.vim b/src/nvim/testdir/test_substitute.vim index 5b476ddd7f..5fd30c7da7 100644 --- a/src/nvim/testdir/test_substitute.vim +++ b/src/nvim/testdir/test_substitute.vim @@ -457,6 +457,7 @@ func Test_substitute_errors() call assert_fails("let s=substitute('abcda', [], 'A', 'g')", 'E730:') call assert_fails("let s=substitute('abcda', 'a', [], 'g')", 'E730:') call assert_fails("let s=substitute('abcda', 'a', 'A', [])", 'E730:') + call assert_fails("let s=substitute('abc', '\\%(', 'A', 'g')", 'E53:') bwipe! endfunc diff --git a/src/nvim/testdir/test_syntax.vim b/src/nvim/testdir/test_syntax.vim index 9d108c6ca2..45230c4208 100644 --- a/src/nvim/testdir/test_syntax.vim +++ b/src/nvim/testdir/test_syntax.vim @@ -407,6 +407,7 @@ func Test_syntax_invalid_arg() call AssertFails('syntax cluster contains=Abc', 'E400:') call AssertFails("syntax match Character /'.'", 'E401:') call AssertFails("syntax match Character /'.'/a", 'E402:') + call assert_fails('syntax sync linecont /\%(/', 'E53:') call assert_fails('syntax sync linecont /pat', 'E404:') call assert_fails('syntax sync linecont', 'E404:') call assert_fails('syntax sync linecont /pat1/ linecont /pat2/', 'E403:') @@ -416,6 +417,7 @@ func Test_syntax_invalid_arg() call AssertFails('syntax match ccFoo "Foo" nextgroup=ALLBUT,F', 'E407:') call AssertFails('syntax region Block start="{" contains=F,ALLBUT', 'E408:') call AssertFails("syntax match Characters contains=a.*x /'.'/", 'E409:') + call assert_fails('syntax match Search /abc/ contains=ALLBUT,/\%(/', 'E53:') endfunc func Test_syn_sync() diff --git a/src/nvim/testdir/test_tagjump.vim b/src/nvim/testdir/test_tagjump.vim index 61bf9e6d0d..bfc61e7b48 100644 --- a/src/nvim/testdir/test_tagjump.vim +++ b/src/nvim/testdir/test_tagjump.vim @@ -184,6 +184,10 @@ function Test_keyword_jump() call search("start") exe "normal! 5\\" call assert_equal(" start OK if found this line", getline('.')) + + " invalid tag search pattern + call assert_fails('tag /\%(/', 'E426:') + enew! | only call delete('Xtestfile') call delete('Xinclude') diff --git a/src/nvim/testdir/test_user_func.vim b/src/nvim/testdir/test_user_func.vim index 7aa21d7816..f13c082814 100644 --- a/src/nvim/testdir/test_user_func.vim +++ b/src/nvim/testdir/test_user_func.vim @@ -413,6 +413,9 @@ func Test_func_def_error() call writefile(['func foo#Bar()', 'return 1', 'endfunc'], 'Xscript') call assert_fails('source Xscript', 'E746:') call delete('Xscript') + + " Try to list functions using an invalid search pattern + call assert_fails('function /\%(/', 'E53:') endfunc " Test for deleting a function -- cgit From 7add38233e53f9813b50558b00644db669b6b309 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Nov 2022 16:31:33 +0800 Subject: vim-patch:8.2.3719: MS-Windows: test sometimes runs into existing swap file Problem: MS-Windows: test sometimes runs into existing swap file. Solution: Use a different file name. https://github.com/vim/vim/commit/f8bc0ce2671d7f7f73760f665b52e4f00a1bbcac Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_buffer.vim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_buffer.vim b/src/nvim/testdir/test_buffer.vim index f4aa3b5238..d8d22ff872 100644 --- a/src/nvim/testdir/test_buffer.vim +++ b/src/nvim/testdir/test_buffer.vim @@ -402,12 +402,12 @@ func Test_buffer_scheme() set noshellslash %bwipe! let bufnames = [ - \ #{id: 'b0', name: 'test://xyz/foo/b0' , match: 1}, - \ #{id: 'b1', name: 'test+abc://xyz/foo/b1', match: 0}, - \ #{id: 'b2', name: 'test_abc://xyz/foo/b2', match: 0}, - \ #{id: 'b3', name: 'test-abc://xyz/foo/b3', match: 1}, - \ #{id: 'b4', name: '-test://xyz/foo/b4' , match: 0}, - \ #{id: 'b5', name: 'test-://xyz/foo/b5' , match: 0}, + \ #{id: 'ssb0', name: 'test://xyz/foo/ssb0' , match: 1}, + \ #{id: 'ssb1', name: 'test+abc://xyz/foo/ssb1', match: 0}, + \ #{id: 'ssb2', name: 'test_abc://xyz/foo/ssb2', match: 0}, + \ #{id: 'ssb3', name: 'test-abc://xyz/foo/ssb3', match: 1}, + \ #{id: 'ssb4', name: '-test://xyz/foo/ssb4' , match: 0}, + \ #{id: 'ssb5', name: 'test-://xyz/foo/ssb5' , match: 0}, \] for buf in bufnames new `=buf.name` -- cgit From 70843631fe8d2e8e93e6ecf7d08c7824352938b7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Nov 2022 16:46:23 +0800 Subject: vim-patch:8.2.3744: E854 is not tested; some spelling suggestions are not tested MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: E854 is not tested; some spelling suggestions are not tested. Solution: Add a couple of tests. (Dominique Pellé, closes vim/vim#9279) https://github.com/vim/vim/commit/f645ee47c85940d05f492a1b3932fbcdfd4204b3 Add missing Test_signcolumn() from patch 7.4.2201. Co-authored-by: Dominique Pelle --- src/nvim/testdir/test_options.vim | 14 ++++++++++++++ src/nvim/testdir/test_spell.vim | 5 +++++ 2 files changed, 19 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index 80569bde03..d689ece70d 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -157,6 +157,20 @@ func Test_path_keep_commas() set path& endfunc +func Test_path_too_long() + exe 'set path=' .. repeat('x', 10000) + call assert_fails('find x', 'E854:') + set path& +endfunc + +func Test_signcolumn() + CheckFeature signs + call assert_equal("auto", &signcolumn) + set signcolumn=yes + set signcolumn=no + call assert_fails('set signcolumn=nope') +endfunc + func Test_filetype_valid() set ft=valid_name call assert_equal("valid_name", &filetype) diff --git a/src/nvim/testdir/test_spell.vim b/src/nvim/testdir/test_spell.vim index d8495fdb9b..ea18fc5194 100644 --- a/src/nvim/testdir/test_spell.vim +++ b/src/nvim/testdir/test_spell.vim @@ -329,6 +329,11 @@ func Test_spellsuggest() call assert_equal(['Third'], spellsuggest('THird', 1)) call assert_equal(['All'], spellsuggest('ALl', 1)) + " Special suggestion for repeated 'the the'. + call assert_inrange(0, 2, index(spellsuggest('the the', 3), 'the')) + call assert_inrange(0, 2, index(spellsuggest('the the', 3), 'the')) + call assert_inrange(0, 2, index(spellsuggest('The the', 3), 'The')) + call assert_fails("call spellsuggest('maxch', [])", 'E745:') call assert_fails("call spellsuggest('maxch', 2, [])", 'E745:') -- cgit From a79d28e4d7939c13f38cf4ce63ff240011bca96d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Nov 2022 17:58:13 +0800 Subject: vim-patch:9.0.0265: no good reason why the "gf" command isn't in the tiny version (#20964) Problem: No good reason why the "gf" command is not in the tiny version. Solution: Graduate the file_in_path feature. https://github.com/vim/vim/commit/f80f40a55ccff0a4331c5fbd1ac446511f622ed0 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_options.vim | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index d689ece70d..db544e47b8 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -895,7 +895,6 @@ endfunc " Test for the default CDPATH option func Test_opt_default_cdpath() - CheckFeature file_in_path let after =<< trim [CODE] call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath) call writefile(v:errors, 'Xtestout') -- cgit From f3cea06d0114f2bcd2176b4a026d2bd4b68871d8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Nov 2022 20:22:37 +0800 Subject: test(old): remove stray test42 files (#20966) Forgot to remove in #17350. --- src/nvim/testdir/Makefile | 3 +-- src/nvim/testdir/test42.in | Bin 2387 -> 0 bytes src/nvim/testdir/test42.ok | Bin 409 -> 0 bytes 3 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 src/nvim/testdir/test42.in delete mode 100644 src/nvim/testdir/test42.ok (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index a6d1cf1003..2d2853ead7 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -13,8 +13,7 @@ export SHELL := sh export NVIM_PRG := $(NVIM_PRG) export TMPDIR := $(abspath Xtest-tmpdir) -SCRIPTS_DEFAULT = \ - test42.out \ +SCRIPTS_DEFAULT = ifneq ($(OS),Windows_NT) SCRIPTS_DEFAULTS := $(SCRIPTS_DEFAULT) \ diff --git a/src/nvim/testdir/test42.in b/src/nvim/testdir/test42.in deleted file mode 100644 index 456f9ddb07..0000000000 Binary files a/src/nvim/testdir/test42.in and /dev/null differ diff --git a/src/nvim/testdir/test42.ok b/src/nvim/testdir/test42.ok deleted file mode 100644 index 183430d71c..0000000000 Binary files a/src/nvim/testdir/test42.ok and /dev/null differ -- cgit From 728c69bc8d52a3f2281a76e4142b2d766dc45da0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Nov 2022 22:13:36 +0800 Subject: vim-patch:8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD (#20967) Problem: Some tests fail on Cirrus CI and/or with FreeBSD. Solution: Make 'backupskip' empty. Do not run tests as root. Check for directory when using viminfo. (Ozaki Kiichi, closes vim/vim#6596) https://github.com/vim/vim/commit/b86abadf87bd0f85f800077171ec4b98aefff776 --- src/nvim/testdir/test_backup.vim | 27 ++++++++++++++++++++------- src/nvim/testdir/test_edit.vim | 1 - src/nvim/testdir/test_writefile.vim | 28 +++++++++------------------- 3 files changed, 29 insertions(+), 27 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_backup.vim b/src/nvim/testdir/test_backup.vim index 7eff818732..d304773da4 100644 --- a/src/nvim/testdir/test_backup.vim +++ b/src/nvim/testdir/test_backup.vim @@ -19,6 +19,22 @@ func Test_backup() call delete('Xbackup.txt~') endfunc +func Test_backup_backupskip() + set backup backupdir=. backupskip=*.txt + new + call setline(1, ['line1', 'line2']) + :f Xbackup.txt + :w! Xbackup.txt + " backup file is only created after + " writing a second time (before overwriting) + :w! Xbackup.txt + call assert_false(filereadable('Xbackup.txt~')) + bw! + set backup&vim backupdir&vim backupskip&vim + call delete('Xbackup.txt') + call delete('Xbackup.txt~') +endfunc + func Test_backup2() set backup backupdir=.// backupskip= new @@ -30,7 +46,7 @@ func Test_backup2() :w! Xbackup.txt sp *Xbackup.txt~ call assert_equal(['line1', 'line2', 'line3'], getline(1,'$')) - let f=expand('%') + let f = expand('%') call assert_match('%testdir%Xbackup.txt\~', f) bw! bw! @@ -50,7 +66,7 @@ func Test_backup2_backupcopy() :w! Xbackup.txt sp *Xbackup.txt~ call assert_equal(['line1', 'line2', 'line3'], getline(1,'$')) - let f=expand('%') + let f = expand('%') call assert_match('%testdir%Xbackup.txt\~', f) bw! bw! @@ -62,14 +78,11 @@ endfunc " Test for using a non-existing directory as a backup directory func Test_non_existing_backupdir() throw 'Skipped: Nvim auto-creates backup directory' - CheckNotBSD - let save_backup = &backupdir - set backupdir=./non_existing_dir + set backupdir=./non_existing_dir backupskip= call writefile(['line1'], 'Xfile') new Xfile - " TODO: write doesn't fail in Cirrus FreeBSD CI test call assert_fails('write', 'E510:') - let &backupdir = save_backup + set backupdir&vim backupskip&vim call delete('Xfile') endfunc diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index 89fd73351d..4994e7af8f 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -1836,7 +1836,6 @@ endfunc " Test for editing a file without read permission func Test_edit_file_no_read_perm() CheckUnix - CheckNotBSD call writefile(['one', 'two'], 'Xfile') call setfperm('Xfile', '-w-------') new diff --git a/src/nvim/testdir/test_writefile.vim b/src/nvim/testdir/test_writefile.vim index 8fb4c8fa4c..e4950de658 100644 --- a/src/nvim/testdir/test_writefile.vim +++ b/src/nvim/testdir/test_writefile.vim @@ -136,9 +136,7 @@ func Test_writefile_sync_arg() endfunc func Test_writefile_sync_dev_stdout() - if !has('unix') - return - endif + CheckUnix if filewritable('/dev/stdout') " Just check that this doesn't cause an error. call writefile(['one'], '/dev/stdout', 's') @@ -386,13 +384,10 @@ endfunc " Test for writing to a readonly file func Test_write_readonly() - " In Cirrus-CI, the freebsd tests are run under a root account. So this test - " doesn't fail. - CheckNotBSD call writefile([], 'Xfile') call setfperm('Xfile', "r--------") edit Xfile - set noreadonly + set noreadonly backupskip= call assert_fails('write', 'E505:') let save_cpo = &cpo set cpo+=W @@ -401,37 +396,32 @@ func Test_write_readonly() call setline(1, ['line1']) write! call assert_equal(['line1'], readfile('Xfile')) + set backupskip& call delete('Xfile') endfunc " Test for 'patchmode' func Test_patchmode() - CheckNotBSD call writefile(['one'], 'Xfile') - set patchmode=.orig nobackup writebackup + set patchmode=.orig nobackup backupskip= writebackup new Xfile call setline(1, 'two') " first write should create the .orig file write - " TODO: Xfile.orig is not created in Cirrus FreeBSD CI test call assert_equal(['one'], readfile('Xfile.orig')) call setline(1, 'three') " subsequent writes should not create/modify the .orig file write call assert_equal(['one'], readfile('Xfile.orig')) - set patchmode& backup& writebackup& + set patchmode& backup& backupskip& writebackup& call delete('Xfile') call delete('Xfile.orig') endfunc " Test for writing to a file in a readonly directory func Test_write_readonly_dir() - if !has('unix') || has('bsd') - " On MS-Windows, modifying files in a read-only directory is allowed. - " In Cirrus-CI for Freebsd, tests are run under a root account where - " modifying files in a read-only directory are allowed. - return - endif + " On MS-Windows, modifying files in a read-only directory is allowed. + CheckUnix call mkdir('Xdir') call writefile(['one'], 'Xdir/Xfile1') call setfperm('Xdir', 'r-xr--r--') @@ -441,12 +431,12 @@ func Test_write_readonly_dir() call assert_fails('write', 'E212:') " try to create a backup file in the directory edit! Xdir/Xfile1 - set backupdir=./Xdir + set backupdir=./Xdir backupskip= set patchmode=.orig call assert_fails('write', 'E509:') call setfperm('Xdir', 'rwxr--r--') call delete('Xdir', 'rf') - set backupdir& patchmode& + set backupdir& backupskip& patchmode& endfunc " Test for writing a file using invalid file encoding -- cgit From de500095b1adc675999315e70307b3425dca089c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Nov 2022 23:07:57 +0800 Subject: vim-patch:8.2.2592: code coverage could be improved (#20969) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Code coverage could be improved. Solution: Add a few more tests. (Dominique Pellé, closes vim/vim#7957) https://github.com/vim/vim/commit/6fd367a97c8653a2d734a38252c7d68d4b2ebaa7 Test case in test_viminfo.vim is applicable. --- src/nvim/testdir/test_fileformat.vim | 9 +++++++++ src/nvim/testdir/test_normal.vim | 7 +++++++ src/nvim/testdir/test_sleep.vim | 1 + src/nvim/testdir/test_textformat.vim | 16 ++++++++++++++++ src/nvim/testdir/test_viminfo.vim | 5 +++++ 5 files changed, 38 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_fileformat.vim b/src/nvim/testdir/test_fileformat.vim index 81127ea59a..8d727a68c4 100644 --- a/src/nvim/testdir/test_fileformat.vim +++ b/src/nvim/testdir/test_fileformat.vim @@ -31,6 +31,15 @@ func Test_fileformat_autocommand() bw! endfunc +func Test_fileformat_nomodifiable() + new + setlocal nomodifiable + + call assert_fails('set fileformat=latin1', 'E21:') + + bw +endfunc + " Convert the contents of a file into a literal string func s:file2str(fname) let b = readfile(a:fname, 'B') diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index 84929e2be3..6160352052 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -3399,6 +3399,13 @@ func Test_normal_delete_cmd() " delete to a readonly register call setline(1, ['abcd']) call assert_beeps('normal ":d2l') + + " D and d with 'nomodifiable' + call setline(1, ['abcd']) + setlocal nomodifiable + call assert_fails('normal D', 'E21:') + call assert_fails('normal d$', 'E21:') + close! endfunc diff --git a/src/nvim/testdir/test_sleep.vim b/src/nvim/testdir/test_sleep.vim index f71855fd4b..a428f380b0 100644 --- a/src/nvim/testdir/test_sleep.vim +++ b/src/nvim/testdir/test_sleep.vim @@ -21,6 +21,7 @@ func! Test_sleep_bang() call s:assert_takes_longer('sl 50m', 50) call s:assert_takes_longer('sl! 50m', 50) call s:assert_takes_longer('1sleep', 1000) + call s:assert_takes_longer('normal 1gs', 1000) endfunc " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_textformat.vim b/src/nvim/testdir/test_textformat.vim index 3bce2eb24d..7a13de12f4 100644 --- a/src/nvim/testdir/test_textformat.vim +++ b/src/nvim/testdir/test_textformat.vim @@ -1044,6 +1044,22 @@ func Test_empty_matchpairs() bwipe! endfunc +func Test_mps_error() + let encoding_save = &encoding + + " for e in ['utf-8', 'latin1'] + for e in ['utf-8'] + exe 'set encoding=' .. e + + call assert_fails('set mps=<:', 'E474:', e) + call assert_fails('set mps=:>', 'E474:', e) + call assert_fails('set mps=<>', 'E474:', e) + call assert_fails('set mps=<:>_', 'E474:', e) + endfor + + let &encoding = encoding_save +endfunc + " Test for ra on multi-byte characters func Test_ra_multibyte() new diff --git a/src/nvim/testdir/test_viminfo.vim b/src/nvim/testdir/test_viminfo.vim index 2d6d598011..e792db90ab 100644 --- a/src/nvim/testdir/test_viminfo.vim +++ b/src/nvim/testdir/test_viminfo.vim @@ -18,4 +18,9 @@ func Test_viminfo_option_error() call assert_fails('set viminfo=%10', 'E528:') endfunc +func Test_viminfo_oldfiles_newfile() + let v:oldfiles = v:_null_list + call assert_equal("\nNo old files", execute('oldfiles')) +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From df71537a12e454075e02824bb8f570e1e838ee64 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Nov 2022 22:15:33 +0800 Subject: vim-patch:8.2.2570: tests fail when run as root Problem: Tests fail when run as root. Solution: Add a comment mentioning the expected failure. (issue vim/vim#7919) https://github.com/vim/vim/commit/f9a65505d1d93f3e67e5b8646bde3bbc44c70f7d Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_edit.vim | 1 + src/nvim/testdir/test_excmd.vim | 1 + src/nvim/testdir/test_help.vim | 1 + src/nvim/testdir/test_writefile.vim | 1 + 4 files changed, 4 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index 4994e7af8f..bd7b5609a5 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -1834,6 +1834,7 @@ func Test_edit_charconvert() endfunc " Test for editing a file without read permission +" NOTE: if you run tests as root this will fail. Don't run tests as root! func Test_edit_file_no_read_perm() CheckUnix call writefile(['one', 'two'], 'Xfile') diff --git a/src/nvim/testdir/test_excmd.vim b/src/nvim/testdir/test_excmd.vim index 582dcaac2c..91fdb23a63 100644 --- a/src/nvim/testdir/test_excmd.vim +++ b/src/nvim/testdir/test_excmd.vim @@ -476,6 +476,7 @@ func Test_winsize_cmd() endfunc " Test for the :redir command +" NOTE: if you run tests as root this will fail. Don't run tests as root! func Test_redir_cmd() call assert_fails('redir @@', 'E475:') call assert_fails('redir abc', 'E475:') diff --git a/src/nvim/testdir/test_help.vim b/src/nvim/testdir/test_help.vim index 19c0fcd820..5779cc6d11 100644 --- a/src/nvim/testdir/test_help.vim +++ b/src/nvim/testdir/test_help.vim @@ -98,6 +98,7 @@ func Test_help_completion() endfunc " Test for the :helptags command +" NOTE: if you run tests as root this will fail. Don't run tests as root! func Test_helptag_cmd() call mkdir('Xdir/a/doc', 'p') diff --git a/src/nvim/testdir/test_writefile.vim b/src/nvim/testdir/test_writefile.vim index e4950de658..738e66ea27 100644 --- a/src/nvim/testdir/test_writefile.vim +++ b/src/nvim/testdir/test_writefile.vim @@ -419,6 +419,7 @@ func Test_patchmode() endfunc " Test for writing to a file in a readonly directory +" NOTE: if you run tests as root this will fail. Don't run tests as root! func Test_write_readonly_dir() " On MS-Windows, modifying files in a read-only directory is allowed. CheckUnix -- cgit From fbe2761b20afaf25a02c06decaf543d211e997f0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Nov 2022 22:15:59 +0800 Subject: vim-patch:8.2.2623: some tests fail when run as root Problem: Some tests fail when run as root. Solution: Use CheckNotRoot. https://github.com/vim/vim/commit/17709e280ac5ba234b04641cde88d38e3522cedf Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_edit.vim | 3 ++- src/nvim/testdir/test_excmd.vim | 18 ++++++++----- src/nvim/testdir/test_help.vim | 53 +++++++++++++++++++++---------------- src/nvim/testdir/test_writefile.vim | 3 +++ 4 files changed, 46 insertions(+), 31 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index bd7b5609a5..dc850515b0 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -1834,9 +1834,10 @@ func Test_edit_charconvert() endfunc " Test for editing a file without read permission -" NOTE: if you run tests as root this will fail. Don't run tests as root! func Test_edit_file_no_read_perm() CheckUnix + CheckNotRoot + call writefile(['one', 'two'], 'Xfile') call setfperm('Xfile', '-w-------') new diff --git a/src/nvim/testdir/test_excmd.vim b/src/nvim/testdir/test_excmd.vim index 91fdb23a63..0e8af08b4b 100644 --- a/src/nvim/testdir/test_excmd.vim +++ b/src/nvim/testdir/test_excmd.vim @@ -493,13 +493,6 @@ func Test_redir_cmd() call assert_fails('redir > Xdir', 'E17:') call delete('Xdir', 'd') endif - if !has('bsd') - " Redirecting to a read-only file - call writefile([], 'Xfile') - call setfperm('Xfile', 'r--r--r--') - call assert_fails('redir! > Xfile', 'E190:') - call delete('Xfile') - endif " Test for redirecting to a register redir @q> | echon 'clean ' | redir END @@ -512,6 +505,17 @@ func Test_redir_cmd() call assert_equal('blue sky', color) endfunc +func Test_redir_cmd_readonly() + CheckNotRoot + CheckNotBSD + + " Redirecting to a read-only file + call writefile([], 'Xfile') + call setfperm('Xfile', 'r--r--r--') + call assert_fails('redir! > Xfile', 'E190:') + call delete('Xfile') +endfunc + " Test for the :filetype command func Test_filetype_cmd() call assert_fails('filetype abc', 'E475:') diff --git a/src/nvim/testdir/test_help.vim b/src/nvim/testdir/test_help.vim index 5779cc6d11..787f673991 100644 --- a/src/nvim/testdir/test_help.vim +++ b/src/nvim/testdir/test_help.vim @@ -1,5 +1,7 @@ " Tests for :help +source check.vim + func Test_help_restore_snapshot() help set buftype= @@ -112,29 +114,6 @@ func Test_helptag_cmd() call assert_equal(["help-tags\ttags\t1"], readfile('Xdir/tags')) call delete('Xdir/tags') - " The following tests fail on FreeBSD for some reason - if has('unix') && !has('bsd') - " Read-only tags file - call mkdir('Xdir/doc', 'p') - call writefile([''], 'Xdir/doc/tags') - call writefile([], 'Xdir/doc/sample.txt') - call setfperm('Xdir/doc/tags', 'r-xr--r--') - call assert_fails('helptags Xdir/doc', 'E152:', getfperm('Xdir/doc/tags')) - - let rtp = &rtp - let &rtp = 'Xdir' - helptags ALL - let &rtp = rtp - - call delete('Xdir/doc/tags') - - " No permission to read the help file - call setfperm('Xdir/a/doc/sample.txt', '-w-------') - call assert_fails('helptags Xdir', 'E153:', getfperm('Xdir/a/doc/sample.txt')) - call delete('Xdir/a/doc/sample.txt') - call delete('Xdir/tags') - endif - " Duplicate tags in the help file call writefile(['*tag1*', '*tag1*', '*tag2*'], 'Xdir/a/doc/sample.txt') call assert_fails('helptags Xdir', 'E154:') @@ -142,6 +121,34 @@ func Test_helptag_cmd() call delete('Xdir', 'rf') endfunc +func Test_helptag_cmd_readonly() + CheckUnix + CheckNotRoot + " The following tests fail on FreeBSD for some reason + CheckNotBSD + + " Read-only tags file + call mkdir('Xdir/doc', 'p') + call writefile([''], 'Xdir/doc/tags') + call writefile([], 'Xdir/doc/sample.txt') + call setfperm('Xdir/doc/tags', 'r-xr--r--') + call assert_fails('helptags Xdir/doc', 'E152:', getfperm('Xdir/doc/tags')) + + let rtp = &rtp + let &rtp = 'Xdir' + helptags ALL + let &rtp = rtp + + call delete('Xdir/doc/tags') + + " No permission to read the help file + call mkdir('Xdir/b/doc', 'p') + call writefile([], 'Xdir/b/doc/sample.txt') + call setfperm('Xdir/b/doc/sample.txt', '-w-------') + call assert_fails('helptags Xdir', 'E153:', getfperm('Xdir/b/doc/sample.txt')) + call delete('Xdir', 'rf') +endfunc + " Test for setting the 'helpheight' option in the help window func Test_help_window_height() let &cmdheight = &lines - 24 diff --git a/src/nvim/testdir/test_writefile.vim b/src/nvim/testdir/test_writefile.vim index 738e66ea27..a7ebe8cde6 100644 --- a/src/nvim/testdir/test_writefile.vim +++ b/src/nvim/testdir/test_writefile.vim @@ -423,6 +423,9 @@ endfunc func Test_write_readonly_dir() " On MS-Windows, modifying files in a read-only directory is allowed. CheckUnix + " Root can do it too. + CheckNotRoot + call mkdir('Xdir') call writefile(['one'], 'Xdir/Xfile1') call setfperm('Xdir', 'r-xr--r--') -- cgit From bfa0be49ed07d1e576c6452bb7e82956df7b19d5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Nov 2022 22:28:39 +0800 Subject: vim-patch:8.2.2627: no need to check for BSD after checking for not root Problem: No need to check for BSD after checking for not root. Solution: Remove CheckNotBSD. (Ozaki Kiichi, closes vim/vim#7989) https://github.com/vim/vim/commit/4355894869355c185e7810e67d52802453576e81 --- src/nvim/testdir/check.vim | 9 --------- src/nvim/testdir/test_excmd.vim | 1 - src/nvim/testdir/test_help.vim | 2 -- 3 files changed, 12 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/check.vim b/src/nvim/testdir/check.vim index 1459b70243..8a1080a2f3 100644 --- a/src/nvim/testdir/check.vim +++ b/src/nvim/testdir/check.vim @@ -90,15 +90,6 @@ func CheckUnix() endif endfunc -" Command to check for not running on a BSD system. -" TODO: using this checks should not be needed -command CheckNotBSD call CheckNotBSD() -func CheckNotBSD() - if has('bsd') - throw 'Skipped: does not work on BSD' - endif -endfunc - " Command to check that making screendumps is supported. " Caller must source screendump.vim command CheckScreendump call CheckScreendump() diff --git a/src/nvim/testdir/test_excmd.vim b/src/nvim/testdir/test_excmd.vim index 0e8af08b4b..42b1f8ca48 100644 --- a/src/nvim/testdir/test_excmd.vim +++ b/src/nvim/testdir/test_excmd.vim @@ -507,7 +507,6 @@ endfunc func Test_redir_cmd_readonly() CheckNotRoot - CheckNotBSD " Redirecting to a read-only file call writefile([], 'Xfile') diff --git a/src/nvim/testdir/test_help.vim b/src/nvim/testdir/test_help.vim index 787f673991..6478ae5dbf 100644 --- a/src/nvim/testdir/test_help.vim +++ b/src/nvim/testdir/test_help.vim @@ -124,8 +124,6 @@ endfunc func Test_helptag_cmd_readonly() CheckUnix CheckNotRoot - " The following tests fail on FreeBSD for some reason - CheckNotBSD " Read-only tags file call mkdir('Xdir/doc', 'p') -- cgit From 8c454776f8a1d030b326347e1dd2d4e1fd6d7f7f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Nov 2022 22:32:47 +0800 Subject: vim-patch:8.2.4495: help test fails in 24 line terminal Problem: Help test fails in 24 line terminal. Solution: Use up to 23 lines for text. https://github.com/vim/vim/commit/e4e1a1e1c8a2bc6efd806e379b5fc80998318830 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_help.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_help.vim b/src/nvim/testdir/test_help.vim index 6478ae5dbf..e30d305703 100644 --- a/src/nvim/testdir/test_help.vim +++ b/src/nvim/testdir/test_help.vim @@ -149,7 +149,7 @@ endfunc " Test for setting the 'helpheight' option in the help window func Test_help_window_height() - let &cmdheight = &lines - 24 + let &cmdheight = &lines - 23 set helpheight=10 help set helpheight=14 -- cgit From 3b3611a3d0f1e13e277360d6bacf97a0fb7eb6de Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 7 Nov 2022 07:03:31 +0800 Subject: vim-patch:9.0.0841: deletebufline() does not always return 1 on failure (#20980) Problem: deletebufline() does not always return 1 on failure. Solution: Refactor the code to make it work more predictable. (closes vim/vim#11511) https://github.com/vim/vim/commit/7af3ee2b83545169d78a28ab1cd89aff1127f8b3 --- src/nvim/testdir/test_bufline.vim | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_bufline.vim b/src/nvim/testdir/test_bufline.vim index 2867f13cbc..fae6b1dab7 100644 --- a/src/nvim/testdir/test_bufline.vim +++ b/src/nvim/testdir/test_bufline.vim @@ -239,4 +239,20 @@ func Test_setbufline_startup_nofile() call delete('Xresult') endfunc +" Test that setbufline(), appendbufline() and deletebufline() should fail and +" return 1 when "textlock" is active. +func Test_change_bufline_with_textlock() + new + inoremap setbufline('', 1, '') + call assert_fails("normal a\", 'E565:') + call assert_equal('1', getline(1)) + inoremap appendbufline('', 1, '') + call assert_fails("normal a\", 'E565:') + call assert_equal('11', getline(1)) + inoremap deletebufline('', 1) + call assert_fails("normal a\", 'E565:') + call assert_equal('111', getline(1)) + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From b0190f4543397d6f3485e1eb03f30f80e358c201 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 7 Nov 2022 07:04:49 +0800 Subject: vim-patch:8.2.2849: bufwrite not sufficiently tested Problem: Bufwrite not sufficiently tested. Solution: Add a few more tests. (Yegappan Lakshmanan, closes vim/vim#8192) https://github.com/vim/vim/commit/36f96a515109dc1fad279571a645c0f0d65f2de4 Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_startup.vim | 15 +++ src/nvim/testdir/test_writefile.vim | 197 ++++++++++++++++++++++++++++++++++++ 2 files changed, 212 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim index 30bbd355df..f9f7c5b492 100644 --- a/src/nvim/testdir/test_startup.vim +++ b/src/nvim/testdir/test_startup.vim @@ -1279,4 +1279,19 @@ func Test_progname() call delete('Xprogname', 'd') endfunc +" Test for doing a write from .vimrc +func Test_write_in_vimrc() + call writefile(['silent! write'], 'Xvimrc') + let after =<< trim [CODE] + call assert_match('E32: ', v:errmsg) + call writefile(v:errors, 'Xtestout') + qall + [CODE] + if RunVim([], after, '-u Xvimrc') + call assert_equal([], readfile('Xtestout')) + call delete('Xtestout') + endif + call delete('Xvimrc') +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_writefile.vim b/src/nvim/testdir/test_writefile.vim index a7ebe8cde6..0ecb25d3e4 100644 --- a/src/nvim/testdir/test_writefile.vim +++ b/src/nvim/testdir/test_writefile.vim @@ -57,7 +57,29 @@ func Test_writefile_fails_conversion() call assert_fails('write ++enc=cp932', 'E513:') call assert_equal(contents, readfile('Xfile')) + " With 'backupcopy' set, if there is a conversion error, the backup file is + " still created. + set backupcopy=yes writebackup& backup& + call delete('Xfile' .. &backupext) + call assert_fails('write ++enc=cp932', 'E513:') + call assert_equal(contents, readfile('Xfile')) + call assert_equal(contents, readfile('Xfile' .. &backupext)) + set backupcopy& + %bw! + + " Conversion error during write + new + call setline(1, ["\U10000000"]) + let output = execute('write! ++enc=utf-16 Xfile') + call assert_match('CONVERSION ERROR', output) + let output = execute('write! ++enc=ucs-2 Xfile') + call assert_match('CONVERSION ERROR', output) + call delete('Xfilz~') + call delete('Xfily~') + %bw! + call delete('Xfile') + call delete('Xfile' .. &backupext) bwipe! set backup& writebackup& backupdir&vim backupskip&vim endfunc @@ -270,6 +292,16 @@ func Test_write_errors() let long_fname = repeat('n', 5000) call assert_fails('exe "w " .. long_fname', 'E75:') call assert_fails('call writefile([], long_fname)', 'E482:') + + " Test for writing to a block device on Unix-like systems + if has('unix') && getfperm('/dev/loop0') != '' + \ && getftype('/dev/loop0') == 'bdev' && !IsRoot() + new + edit /dev/loop0 + call assert_fails('write', 'E505: ') + call assert_fails('write!', 'E503: ') + close! + endif endfunc " Test for writing to a file which is modified after Vim read it @@ -396,8 +428,21 @@ func Test_write_readonly() call setline(1, ['line1']) write! call assert_equal(['line1'], readfile('Xfile')) + + " Auto-saving a readonly file should fail with 'autowriteall' + %bw! + e Xfile + set noreadonly autowriteall + call setline(1, ['aaaa']) + call assert_fails('n', 'E505:') + set cpo+=W + call assert_fails('n', 'E504:') + set cpo-=W + set autowriteall& + set backupskip& call delete('Xfile') + %bw! endfunc " Test for 'patchmode' @@ -413,6 +458,19 @@ func Test_patchmode() " subsequent writes should not create/modify the .orig file write call assert_equal(['one'], readfile('Xfile.orig')) + + " use 'patchmode' with 'nobackup' and 'nowritebackup' to create an empty + " original file + call delete('Xfile') + call delete('Xfile.orig') + %bw! + set patchmode=.orig nobackup nowritebackup + edit Xfile + call setline(1, ['xxx']) + write + call assert_equal(['xxx'], readfile('Xfile')) + call assert_equal([], readfile('Xfile.orig')) + set patchmode& backup& backupskip& writebackup& call delete('Xfile') call delete('Xfile.orig') @@ -714,6 +772,145 @@ func Test_read_write_bin() bwipe! XNoEolSetEol endfunc +" Test for the 'backupcopy' option when writing files +func Test_backupcopy() + CheckUnix + set backupskip= + " With the default 'backupcopy' setting, saving a symbolic link file + " should not break the link. + set backupcopy& + call writefile(['1111'], 'Xfile1') + silent !ln -s Xfile1 Xfile2 + new Xfile2 + call setline(1, ['2222']) + write + close + call assert_equal(['2222'], readfile('Xfile1')) + call assert_equal('Xfile1', resolve('Xfile2')) + call assert_equal('link', getftype('Xfile2')) + call delete('Xfile1') + call delete('Xfile2') + + " With the 'backupcopy' set to 'breaksymlink', saving a symbolic link file + " should break the link. + set backupcopy=yes,breaksymlink + call writefile(['1111'], 'Xfile1') + silent !ln -s Xfile1 Xfile2 + new Xfile2 + call setline(1, ['2222']) + write + close + call assert_equal(['1111'], readfile('Xfile1')) + call assert_equal(['2222'], readfile('Xfile2')) + call assert_equal('Xfile2', resolve('Xfile2')) + call assert_equal('file', getftype('Xfile2')) + call delete('Xfile1') + call delete('Xfile2') + set backupcopy& + + " With the default 'backupcopy' setting, saving a hard link file + " should not break the link. + set backupcopy& + call writefile(['1111'], 'Xfile1') + silent !ln Xfile1 Xfile2 + new Xfile2 + call setline(1, ['2222']) + write + close + call assert_equal(['2222'], readfile('Xfile1')) + call delete('Xfile1') + call delete('Xfile2') + + " With the 'backupcopy' set to 'breaksymlink', saving a hard link file + " should break the link. + set backupcopy=yes,breakhardlink + call writefile(['1111'], 'Xfile1') + silent !ln Xfile1 Xfile2 + new Xfile2 + call setline(1, ['2222']) + write + call assert_equal(['1111'], readfile('Xfile1')) + call assert_equal(['2222'], readfile('Xfile2')) + call delete('Xfile1') + call delete('Xfile2') + + " If a backup file is already present, then a slightly modified filename + " should be used as the backup file. Try with 'backupcopy' set to 'yes' and + " 'no'. + %bw + call writefile(['aaaa'], 'Xfile') + call writefile(['bbbb'], 'Xfile.bak') + set backupcopy=yes backupext=.bak + new Xfile + call setline(1, ['cccc']) + write + close + call assert_equal(['cccc'], readfile('Xfile')) + call assert_equal(['bbbb'], readfile('Xfile.bak')) + set backupcopy=no backupext=.bak + new Xfile + call setline(1, ['dddd']) + write + close + call assert_equal(['dddd'], readfile('Xfile')) + call assert_equal(['bbbb'], readfile('Xfile.bak')) + call delete('Xfile') + call delete('Xfile.bak') + + " Write to a device file (in Unix-like systems) which cannot be backed up. + if has('unix') + set writebackup backupcopy=yes nobackup + new + call setline(1, ['aaaa']) + let output = execute('write! /dev/null') + call assert_match('"/dev/null" \[Device]', output) + close + set writebackup backupcopy=no nobackup + new + call setline(1, ['aaaa']) + let output = execute('write! /dev/null') + call assert_match('"/dev/null" \[Device]', output) + close + set backup writebackup& backupcopy& + new + call setline(1, ['aaaa']) + let output = execute('write! /dev/null') + call assert_match('"/dev/null" \[Device]', output) + close + endif + + set backupcopy& backupskip& backupext& backup& +endfunc + +" Test for writing a file with 'encoding' set to 'utf-16' +func Test_write_utf16() + new + call setline(1, ["\U00010001"]) + write ++enc=utf-16 Xfile + bw! + call assert_equal(0zD800DC01, readfile('Xfile', 'B')[0:3]) + call delete('Xfile') +endfunc + +" Test for trying to save a backup file when the backup file is a symbolic +" link to the original file. The backup file should not be modified. +func Test_write_backup_symlink() + CheckUnix + call writefile(['1111'], 'Xfile') + silent !ln -s Xfile Xfile.bak + + new Xfile + set backup backupcopy=yes backupext=.bak + write + call assert_equal('link', getftype('Xfile.bak')) + call assert_equal('Xfile', resolve('Xfile.bak')) + set backup& backupcopy& backupext& + close + + call delete('Xfile') + call delete('Xfile.bak') +endfunc + " Check that buffer is written before triggering QuitPre func Test_wq_quitpre_autocommand() edit Xsomefile -- cgit From bdf87efeb523aecffde7dbf3c17806f7ca98471f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 7 Nov 2022 07:06:49 +0800 Subject: vim-patch:8.2.2856: get readonly error for device that can't be written to Problem: Get readonly error for device that can't be written to. Solution: Check for being able to write first. (closes vim/vim#8205) https://github.com/vim/vim/commit/50157ef1c2e36d8696e79fd688bdd08312196bc6 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_writefile.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_writefile.vim b/src/nvim/testdir/test_writefile.vim index 0ecb25d3e4..b80519f316 100644 --- a/src/nvim/testdir/test_writefile.vim +++ b/src/nvim/testdir/test_writefile.vim @@ -298,7 +298,7 @@ func Test_write_errors() \ && getftype('/dev/loop0') == 'bdev' && !IsRoot() new edit /dev/loop0 - call assert_fails('write', 'E505: ') + call assert_fails('write', 'E503: ') call assert_fails('write!', 'E503: ') close! endif -- cgit From 7e1d9c560b09cacb78b2fc8f9428a77d6fca66e1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 7 Nov 2022 07:21:46 +0800 Subject: vim-patch:8.2.2873: not enough tests for writing buffers Problem: Not enough tests for writing buffers. Solution: Add a few more tests. (Yegappan Lakshmanan, closes vim/vim#8229) https://github.com/vim/vim/commit/46aa6f93acb5d932d2893606d980a6b4b8a9594c Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_buffer.vim | 20 ++++++++++++++++++++ src/nvim/testdir/test_cmdline.vim | 21 +++++++++++++++++++++ src/nvim/testdir/test_functions.vim | 1 + src/nvim/testdir/test_writefile.vim | 22 ++++++++++++++++++++-- 4 files changed, 62 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_buffer.vim b/src/nvim/testdir/test_buffer.vim index d8d22ff872..3300278802 100644 --- a/src/nvim/testdir/test_buffer.vim +++ b/src/nvim/testdir/test_buffer.vim @@ -434,4 +434,24 @@ func Test_buf_pattern_invalid() bwipe! endfunc +" Test for the 'maxmem' and 'maxmemtot' options +func Test_buffer_maxmem() + " use 1KB per buffer and 2KB for all the buffers + " set maxmem=1 maxmemtot=2 + new + let v:errmsg = '' + " try opening some files + edit test_arglist.vim + call assert_equal('test_arglist.vim', bufname()) + edit test_eval_stuff.vim + call assert_equal('test_eval_stuff.vim', bufname()) + b test_arglist.vim + call assert_equal('test_arglist.vim', bufname()) + b test_eval_stuff.vim + call assert_equal('test_eval_stuff.vim', bufname()) + close + call assert_equal('', v:errmsg) + " set maxmem& maxmemtot& +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 7cef3117c2..b0be7ab396 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -1513,6 +1513,7 @@ func Test_cmdline_expand_special() call assert_fails('e ', 'E495:') call assert_fails('e ', 'E496:') call assert_fails('e ', 'E497:') + call writefile([], 'Xfile.cpp') call writefile([], 'Xfile.java') new Xfile.cpp @@ -2006,6 +2007,26 @@ func Test_recalling_cmdline() cunmap (save-cmdline) endfunc +" Test for the 'suffixes' option +func Test_suffixes_opt() + call writefile([], 'Xfile') + call writefile([], 'Xfile.c') + call writefile([], 'Xfile.o') + set suffixes= + call feedkeys(":e Xfi*\\\"\", 'xt') + call assert_equal('"e Xfile Xfile.c Xfile.o', @:) + set suffixes=.c + call feedkeys(":e Xfi*\\\"\", 'xt') + call assert_equal('"e Xfile Xfile.o Xfile.c', @:) + set suffixes=,, + call feedkeys(":e Xfi*\\\"\", 'xt') + call assert_equal('"e Xfile.c Xfile.o Xfile', @:) + set suffixes& + call delete('Xfile') + call delete('Xfile.c') + call delete('Xfile.o') +endfunc + " Test for using a popup menu for the command line completion matches " (wildoptions=pum) func Test_wildmenu_pum() diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index b464f6591d..0f2066b7c1 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -2454,6 +2454,7 @@ endfunc func Test_glob() call assert_equal('', glob(v:_null_string)) call assert_equal('', globpath(v:_null_string, v:_null_string)) + call assert_fails("let x = globpath(&rtp, 'syntax/c.vim', [])", 'E745:') call writefile([], 'Xglob1') call writefile([], 'XGLOB2') diff --git a/src/nvim/testdir/test_writefile.vim b/src/nvim/testdir/test_writefile.vim index b80519f316..81615b5963 100644 --- a/src/nvim/testdir/test_writefile.vim +++ b/src/nvim/testdir/test_writefile.vim @@ -484,7 +484,7 @@ func Test_write_readonly_dir() " Root can do it too. CheckNotRoot - call mkdir('Xdir') + call mkdir('Xdir/') call writefile(['one'], 'Xdir/Xfile1') call setfperm('Xdir', 'r-xr--r--') " try to create a new file in the directory @@ -768,7 +768,7 @@ func Test_read_write_bin() call assert_equal(0z6E6F656F6C0A, readfile('XNoEolSetEol', 'B')) call delete('XNoEolSetEol') - set ff& + set ff& fixeol& bwipe! XNoEolSetEol endfunc @@ -911,6 +911,24 @@ func Test_write_backup_symlink() call delete('Xfile.bak') endfunc +" Test for ':write ++bin' and ':write ++nobin' +func Test_write_binary_file() + " create a file without an eol/eof character + call writefile(0z616161, 'Xfile1', 'b') + new Xfile1 + write ++bin Xfile2 + write ++nobin Xfile3 + call assert_equal(0z616161, readblob('Xfile2')) + if has('win32') + call assert_equal(0z6161610D.0A, readblob('Xfile3')) + else + call assert_equal(0z6161610A, readblob('Xfile3')) + endif + call delete('Xfile1') + call delete('Xfile2') + call delete('Xfile3') +endfunc + " Check that buffer is written before triggering QuitPre func Test_wq_quitpre_autocommand() edit Xsomefile -- cgit From 900dd2bdab85b25237cec638265d44c2174154ed Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 20 Aug 2022 08:27:10 +0800 Subject: vim-patch:8.2.3665: cannot use a lambda for 'tagfunc' Problem: Cannot use a lambda for 'tagfunc'. Solution: Use 'tagfunc' like 'opfunc'. (Yegappan Lakshmanan, closes vim/vim#9204) https://github.com/vim/vim/commit/19916a8c8920b6a1fd737ffa6d4e363fc7a96319 Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_tagfunc.vim | 50 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_tagfunc.vim b/src/nvim/testdir/test_tagfunc.vim index bdf5afa5b2..92c2f2d6a1 100644 --- a/src/nvim/testdir/test_tagfunc.vim +++ b/src/nvim/testdir/test_tagfunc.vim @@ -117,4 +117,54 @@ func Test_tagfunc_settagstack() delfunc Mytagfunc2 endfunc +" Test for different ways of setting the 'tagfunc' option +func Test_tagfunc_callback() + " Test for using a function() + func MytagFunc1(pat, flags, info) + let g:MytagFunc1_args = [a:pat, a:flags, a:info] + return v:null + endfunc + let g:MytagFunc1_args = [] + set tagfunc=function('MytagFunc1') + call assert_fails('tag abc', 'E433:') + call assert_equal(['abc', '', {}], g:MytagFunc1_args) + + " Test for using a funcref() + new + func MytagFunc2(pat, flags, info) + let g:MytagFunc2_args = [a:pat, a:flags, a:info] + return v:null + endfunc + let g:MytagFunc2_args = [] + set tagfunc=funcref('MytagFunc2') + call assert_fails('tag def', 'E433:') + call assert_equal(['def', '', {}], g:MytagFunc2_args) + + " Test for using a lambda function + new + func MytagFunc3(pat, flags, info) + let g:MytagFunc3_args = [a:pat, a:flags, a:info] + return v:null + endfunc + let g:MytagFunc3_args = [] + let &tagfunc= '{a, b, c -> MytagFunc3(a, b, c)}' + call assert_fails('tag ghi', 'E433:') + call assert_equal(['ghi', '', {}], g:MytagFunc3_args) + + " Test for clearing the 'tagfunc' option + set tagfunc='' + set tagfunc& + + call assert_fails("set tagfunc=function('abc')", "E700:") + call assert_fails("set tagfunc=funcref('abc')", "E700:") + let &tagfunc = "{a -> 'abc'}" + call assert_fails("echo taglist('a')", "E987:") + + " cleanup + delfunc MytagFunc1 + delfunc MytagFunc2 + delfunc MytagFunc3 + %bw! +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From b3e9010f4783a51407ec5a5ad9fda1216d4db3fe Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 15:30:54 +0800 Subject: vim-patch:8.2.3705: cannot pass a lambda name to function() or funcref() Problem: Cannot pass a lambda name to function() or funcref(). (Yegappan Lakshmanan) Solution: Handle a lambda name differently. https://github.com/vim/vim/commit/eba3b7f6645c8f856132b4c06a009a3b0a44e21c Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_expr.vim | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index ea874cc398..9dbc923b96 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -496,6 +496,13 @@ func Test_function_with_funcref() call assert_fails("call function('foo()')", 'E475:') call assert_fails("call function('foo()')", 'foo()') call assert_fails("function('')", 'E129:') + + let Len = {s -> strlen(s)} + call assert_equal(6, Len('foobar')) + let name = string(Len) + " can evaluate "function('99')" + call execute('let Ref = ' .. name) + call assert_equal(4, Ref('text')) endfunc func Test_funcref() -- cgit From 1508618d4c35dafee2b82726d2d27fae4e314386 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 20 Aug 2022 09:35:09 +0800 Subject: vim-patch:8.2.3712: cannot use Vim9 lambda for 'tagfunc' Problem: Cannot use Vim9 lambda for 'tagfunc'. Solution: Make it work, add more tests. (Yegappan Lakshmanan, closes vim/vim#9250) https://github.com/vim/vim/commit/05e59e3a9ffddbf93c7af02cd2ba1d0f822d4625 Omit Vim9 script in code and comment out in tests. Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_tagfunc.vim | 107 ++++++++++++++++++++++++++++++++++---- 1 file changed, 96 insertions(+), 11 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_tagfunc.vim b/src/nvim/testdir/test_tagfunc.vim index 92c2f2d6a1..29ca69278d 100644 --- a/src/nvim/testdir/test_tagfunc.vim +++ b/src/nvim/testdir/test_tagfunc.vim @@ -124,32 +124,73 @@ func Test_tagfunc_callback() let g:MytagFunc1_args = [a:pat, a:flags, a:info] return v:null endfunc - let g:MytagFunc1_args = [] set tagfunc=function('MytagFunc1') - call assert_fails('tag abc', 'E433:') - call assert_equal(['abc', '', {}], g:MytagFunc1_args) + new | only + let g:MytagFunc1_args = [] + call assert_fails('tag a11', 'E433:') + call assert_equal(['a11', '', {}], g:MytagFunc1_args) + + " Using a funcref variable to set 'tagfunc' + let Fn = function('MytagFunc1') + let &tagfunc = string(Fn) + new | only + let g:MytagFunc1_args = [] + call assert_fails('tag a12', 'E433:') + call assert_equal(['a12', '', {}], g:MytagFunc1_args) + call assert_fails('let &tagfunc = Fn', 'E729:') " Test for using a funcref() - new func MytagFunc2(pat, flags, info) let g:MytagFunc2_args = [a:pat, a:flags, a:info] return v:null endfunc - let g:MytagFunc2_args = [] set tagfunc=funcref('MytagFunc2') - call assert_fails('tag def', 'E433:') - call assert_equal(['def', '', {}], g:MytagFunc2_args) + new | only + let g:MytagFunc2_args = [] + call assert_fails('tag a13', 'E433:') + call assert_equal(['a13', '', {}], g:MytagFunc2_args) + + " Using a funcref variable to set 'tagfunc' + let Fn = funcref('MytagFunc2') + let &tagfunc = string(Fn) + new | only + let g:MytagFunc2_args = [] + call assert_fails('tag a14', 'E433:') + call assert_equal(['a14', '', {}], g:MytagFunc2_args) + call assert_fails('let &tagfunc = Fn', 'E729:') " Test for using a lambda function - new func MytagFunc3(pat, flags, info) let g:MytagFunc3_args = [a:pat, a:flags, a:info] return v:null endfunc + set tagfunc={a,\ b,\ c\ ->\ MytagFunc3(a,\ b,\ c)} + new | only let g:MytagFunc3_args = [] - let &tagfunc= '{a, b, c -> MytagFunc3(a, b, c)}' - call assert_fails('tag ghi', 'E433:') - call assert_equal(['ghi', '', {}], g:MytagFunc3_args) + call assert_fails('tag a15', 'E433:') + call assert_equal(['a15', '', {}], g:MytagFunc3_args) + + " Set 'tagfunc' to a lambda expression + let &tagfunc = '{a, b, c -> MytagFunc3(a, b, c)}' + new | only + let g:MytagFunc3_args = [] + call assert_fails('tag a16', 'E433:') + call assert_equal(['a16', '', {}], g:MytagFunc3_args) + + " Set 'tagfunc' to a variable with a lambda expression + let Lambda = {a, b, c -> MytagFunc3(a, b, c)} + let &tagfunc = string(Lambda) + new | only + let g:MytagFunc3_args = [] + call assert_fails("tag a17", "E433:") + call assert_equal(['a17', '', {}], g:MytagFunc3_args) + call assert_fails('let &tagfunc = Lambda', 'E729:') + + " Test for using a lambda function with incorrect return value + let Lambda = {s -> strlen(s)} + let &tagfunc = string(Lambda) + new | only + call assert_fails("tag a17", "E987:") " Test for clearing the 'tagfunc' option set tagfunc='' @@ -160,10 +201,54 @@ func Test_tagfunc_callback() let &tagfunc = "{a -> 'abc'}" call assert_fails("echo taglist('a')", "E987:") + " Vim9 tests + let lines =<< trim END + vim9script + + # Test for using function() + def MytagFunc1(pat: string, flags: string, info: dict): any + g:MytagFunc1_args = [pat, flags, info] + return null + enddef + set tagfunc=function('MytagFunc1') + new | only + g:MytagFunc1_args = [] + assert_fails('tag a10', 'E433:') + assert_equal(['a10', '', {}], g:MytagFunc1_args) + + # Test for using a lambda + def MytagFunc2(pat: string, flags: string, info: dict): any + g:MytagFunc2_args = [pat, flags, info] + return null + enddef + &tagfunc = '(a, b, c) => MytagFunc2(a, b, c)' + new | only + g:MytagFunc2_args = [] + assert_fails('tag a20', 'E433:') + assert_equal(['a20', '', {}], g:MytagFunc2_args) + + # Test for using a variable with a lambda expression + var Fn: func = (a, b, c) => MytagFunc2(a, b, c) + &tagfunc = string(Fn) + new | only + g:MytagFunc2_args = [] + assert_fails('tag a30', 'E433:') + assert_equal(['a30', '', {}], g:MytagFunc2_args) + END + " call CheckScriptSuccess(lines) + + " Using Vim9 lambda expression in legacy context should fail + " set tagfunc=(a,\ b,\ c)\ =>\ g:MytagFunc2(a,\ b,\ c) + " new | only + " let g:MytagFunc3_args = [] + " call assert_fails("tag a17", "E117:") + " call assert_equal([], g:MytagFunc3_args) + " cleanup delfunc MytagFunc1 delfunc MytagFunc2 delfunc MytagFunc3 + set tagfunc& %bw! endfunc -- cgit From 1e4adf4b56cb7a360d16c4d04290c50ae7e80fbc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 20 Aug 2022 08:45:15 +0800 Subject: vim-patch:8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc' Problem: Cannot use a lambda for 'completefunc' and 'omnifunc'. Solution: Implement lambda support. (Yegappan Lakshmanan, closes vim/vim#9257) https://github.com/vim/vim/commit/8658c759f05b317707d56e3b65a5ef63930c7498 Comment out Vim9 script in tests. Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_ins_complete.vim | 499 +++++++++++++++++++++++++++++++++ src/nvim/testdir/test_tagfunc.vim | 35 ++- 2 files changed, 527 insertions(+), 7 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 f706322a85..fc612dcbe2 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -1285,6 +1285,505 @@ func Test_no_mapping_for_ctrl_x_key() bwipe! endfunc +" Test for different ways of setting the 'completefunc' option +func Test_completefunc_callback() + " Test for using a function() + func MycompleteFunc1(findstart, base) + call add(g:MycompleteFunc1_args, [a:findstart, a:base]) + return a:findstart ? 0 : [] + endfunc + set completefunc=function('MycompleteFunc1') + new | only + call setline(1, 'one') + let g:MycompleteFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'one']], g:MycompleteFunc1_args) + bw! + + " Using a funcref variable to set 'completefunc' + let Fn = function('MycompleteFunc1') + let &completefunc = string(Fn) + new | only + call setline(1, 'two') + let g:MycompleteFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'two']], g:MycompleteFunc1_args) + call assert_fails('let &completefunc = Fn', 'E729:') + bw! + + " Test for using a funcref() + func MycompleteFunc2(findstart, base) + call add(g:MycompleteFunc2_args, [a:findstart, a:base]) + return a:findstart ? 0 : [] + endfunc + set completefunc=funcref('MycompleteFunc2') + new | only + call setline(1, 'three') + let g:MycompleteFunc2_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'three']], g:MycompleteFunc2_args) + bw! + + " Using a funcref variable to set 'completefunc' + let Fn = funcref('MycompleteFunc2') + let &completefunc = string(Fn) + new | only + call setline(1, 'four') + let g:MycompleteFunc2_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'four']], g:MycompleteFunc2_args) + call assert_fails('let &completefunc = Fn', 'E729:') + bw! + + " Test for using a lambda function + func MycompleteFunc3(findstart, base) + call add(g:MycompleteFunc3_args, [a:findstart, a:base]) + return a:findstart ? 0 : [] + endfunc + set completefunc={a,\ b,\ ->\ MycompleteFunc3(a,\ b,)} + new | only + call setline(1, 'five') + let g:MycompleteFunc3_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'five']], g:MycompleteFunc3_args) + bw! + + " Set 'completefunc' to a lambda expression + let &completefunc = '{a, b -> MycompleteFunc3(a, b)}' + new | only + call setline(1, 'six') + let g:MycompleteFunc3_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'six']], g:MycompleteFunc3_args) + bw! + + " Set 'completefunc' to a variable with a lambda expression + let Lambda = {a, b -> MycompleteFunc3(a, b)} + let &completefunc = string(Lambda) + new | only + call setline(1, 'seven') + let g:MycompleteFunc3_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'seven']], g:MycompleteFunc3_args) + call assert_fails('let &completefunc = Lambda', 'E729:') + bw! + + " Test for using a lambda function with incorrect return value + let Lambda = {s -> strlen(s)} + let &completefunc = string(Lambda) + new | only + call setline(1, 'eight') + call feedkeys("A\\\", 'x') + bw! + + " Test for clearing the 'completefunc' option + set completefunc='' + set completefunc& + + call assert_fails("set completefunc=function('abc')", "E700:") + call assert_fails("set completefunc=funcref('abc')", "E700:") + let &completefunc = "{a -> 'abc'}" + call feedkeys("A\\\", 'x') + + " Vim9 tests + let lines =<< trim END + vim9script + + # Test for using function() + def MycompleteFunc1(findstart: number, base: string): any + add(g:MycompleteFunc1_args, [findstart, base]) + return findstart ? 0 : [] + enddef + set completefunc=function('MycompleteFunc1') + new | only + setline(1, 'one') + g:MycompleteFunc1_args = [] + feedkeys("A\\\", 'x') + assert_equal([[1, ''], [0, 'one']], g:MycompleteFunc1_args) + bw! + + # Test for using a lambda + def MycompleteFunc2(findstart: number, base: string): any + add(g:MycompleteFunc2_args, [findstart, base]) + return findstart ? 0 : [] + enddef + &completefunc = '(a, b) => MycompleteFunc2(a, b)' + new | only + setline(1, 'two') + g:MycompleteFunc2_args = [] + feedkeys("A\\\", 'x') + assert_equal([[1, ''], [0, 'two']], g:MycompleteFunc2_args) + bw! + + # Test for using a variable with a lambda expression + var Fn: func = (a, b) => MycompleteFunc2(a, b) + &completefunc = string(Fn) + new | only + setline(1, 'three') + g:MycompleteFunc2_args = [] + feedkeys("A\\\", 'x') + assert_equal([[1, ''], [0, 'three']], g:MycompleteFunc2_args) + bw! + END + " call CheckScriptSuccess(lines) + + " Using Vim9 lambda expression in legacy context should fail + " set completefunc=(a,\ b)\ =>\ g:MycompleteFunc2(a,\ b) + " new | only + " let g:MycompleteFunc2_args = [] + " call assert_fails('call feedkeys("A\\\", "x")', 'E117:') + " call assert_equal([], g:MycompleteFunc2_args) + + " cleanup + delfunc MycompleteFunc1 + delfunc MycompleteFunc2 + delfunc MycompleteFunc3 + set completefunc& + %bw! +endfunc + +" Test for different ways of setting the 'omnifunc' option +func Test_omnifunc_callback() + " Test for using a function() + func MyomniFunc1(findstart, base) + call add(g:MyomniFunc1_args, [a:findstart, a:base]) + return a:findstart ? 0 : [] + endfunc + set omnifunc=function('MyomniFunc1') + new | only + call setline(1, 'one') + let g:MyomniFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'one']], g:MyomniFunc1_args) + bw! + + " Using a funcref variable to set 'omnifunc' + let Fn = function('MyomniFunc1') + let &omnifunc = string(Fn) + new | only + call setline(1, 'two') + let g:MyomniFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'two']], g:MyomniFunc1_args) + call assert_fails('let &omnifunc = Fn', 'E729:') + bw! + + " Test for using a funcref() + func MyomniFunc2(findstart, base) + call add(g:MyomniFunc2_args, [a:findstart, a:base]) + return a:findstart ? 0 : [] + endfunc + set omnifunc=funcref('MyomniFunc2') + new | only + call setline(1, 'three') + let g:MyomniFunc2_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'three']], g:MyomniFunc2_args) + bw! + + " Using a funcref variable to set 'omnifunc' + let Fn = funcref('MyomniFunc2') + let &omnifunc = string(Fn) + new | only + call setline(1, 'four') + let g:MyomniFunc2_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'four']], g:MyomniFunc2_args) + call assert_fails('let &omnifunc = Fn', 'E729:') + bw! + + " Test for using a lambda function + func MyomniFunc3(findstart, base) + call add(g:MyomniFunc3_args, [a:findstart, a:base]) + return a:findstart ? 0 : [] + endfunc + set omnifunc={a,\ b,\ ->\ MyomniFunc3(a,\ b,)} + new | only + call setline(1, 'five') + let g:MyomniFunc3_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'five']], g:MyomniFunc3_args) + bw! + + " Set 'omnifunc' to a lambda expression + let &omnifunc = '{a, b -> MyomniFunc3(a, b)}' + new | only + call setline(1, 'six') + let g:MyomniFunc3_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'six']], g:MyomniFunc3_args) + bw! + + " Set 'omnifunc' to a variable with a lambda expression + let Lambda = {a, b -> MyomniFunc3(a, b)} + let &omnifunc = string(Lambda) + new | only + call setline(1, 'seven') + let g:MyomniFunc3_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'seven']], g:MyomniFunc3_args) + call assert_fails('let &omnifunc = Lambda', 'E729:') + bw! + + " Test for using a lambda function with incorrect return value + let Lambda = {s -> strlen(s)} + let &omnifunc = string(Lambda) + new | only + call setline(1, 'eight') + call feedkeys("A\\\", 'x') + bw! + + " Test for clearing the 'omnifunc' option + set omnifunc='' + set omnifunc& + + call assert_fails("set omnifunc=function('abc')", "E700:") + call assert_fails("set omnifunc=funcref('abc')", "E700:") + let &omnifunc = "{a -> 'abc'}" + call feedkeys("A\\\", 'x') + + " Vim9 tests + let lines =<< trim END + vim9script + + # Test for using function() + def MyomniFunc1(findstart: number, base: string): any + add(g:MyomniFunc1_args, [findstart, base]) + return findstart ? 0 : [] + enddef + set omnifunc=function('MyomniFunc1') + new | only + setline(1, 'one') + g:MyomniFunc1_args = [] + feedkeys("A\\\", 'x') + assert_equal([[1, ''], [0, 'one']], g:MyomniFunc1_args) + bw! + + # Test for using a lambda + def MyomniFunc2(findstart: number, base: string): any + add(g:MyomniFunc2_args, [findstart, base]) + return findstart ? 0 : [] + enddef + &omnifunc = '(a, b) => MyomniFunc2(a, b)' + new | only + setline(1, 'two') + g:MyomniFunc2_args = [] + feedkeys("A\\\", 'x') + assert_equal([[1, ''], [0, 'two']], g:MyomniFunc2_args) + bw! + + # Test for using a variable with a lambda expression + var Fn: func = (a, b) => MyomniFunc2(a, b) + &omnifunc = string(Fn) + new | only + setline(1, 'three') + g:MyomniFunc2_args = [] + feedkeys("A\\\", 'x') + assert_equal([[1, ''], [0, 'three']], g:MyomniFunc2_args) + bw! + END + " call CheckScriptSuccess(lines) + + " Using Vim9 lambda expression in legacy context should fail + " set omnifunc=(a,\ b)\ =>\ g:MyomniFunc2(a,\ b) + " new | only + " let g:MyomniFunc2_args = [] + " call assert_fails('call feedkeys("A\\\", "x")', 'E117:') + " call assert_equal([], g:MyomniFunc2_args) + + " cleanup + delfunc MyomniFunc1 + delfunc MyomniFunc2 + delfunc MyomniFunc3 + set omnifunc& + %bw! +endfunc + +" Test for different ways of setting the 'thesaurusfunc' option +func Test_thesaurusfunc_callback() + " Test for using a function() + func MytsrFunc1(findstart, base) + call add(g:MytsrFunc1_args, [a:findstart, a:base]) + return a:findstart ? 0 : [] + endfunc + set thesaurusfunc=function('MytsrFunc1') + new | only + call setline(1, 'one') + let g:MytsrFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'one']], g:MytsrFunc1_args) + bw! + + " Using a funcref variable to set 'thesaurusfunc' + let Fn = function('MytsrFunc1') + let &thesaurusfunc = string(Fn) + new | only + call setline(1, 'two') + let g:MytsrFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'two']], g:MytsrFunc1_args) + call assert_fails('let &thesaurusfunc = Fn', 'E729:') + bw! + + " Test for using a funcref() + func MytsrFunc2(findstart, base) + call add(g:MytsrFunc2_args, [a:findstart, a:base]) + return a:findstart ? 0 : [] + endfunc + set thesaurusfunc=funcref('MytsrFunc2') + new | only + call setline(1, 'three') + let g:MytsrFunc2_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'three']], g:MytsrFunc2_args) + bw! + + " Using a funcref variable to set 'thesaurusfunc' + let Fn = funcref('MytsrFunc2') + let &thesaurusfunc = string(Fn) + new | only + call setline(1, 'four') + let g:MytsrFunc2_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'four']], g:MytsrFunc2_args) + call assert_fails('let &thesaurusfunc = Fn', 'E729:') + bw! + + " Test for using a lambda function + func MytsrFunc3(findstart, base) + call add(g:MytsrFunc3_args, [a:findstart, a:base]) + return a:findstart ? 0 : [] + endfunc + set thesaurusfunc={a,\ b,\ ->\ MytsrFunc3(a,\ b,)} + new | only + call setline(1, 'five') + let g:MytsrFunc3_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'five']], g:MytsrFunc3_args) + bw! + + " Set 'thesaurusfunc' to a lambda expression + let &thesaurusfunc = '{a, b -> MytsrFunc3(a, b)}' + new | only + call setline(1, 'six') + let g:MytsrFunc3_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'six']], g:MytsrFunc3_args) + bw! + + " Set 'thesaurusfunc' to a variable with a lambda expression + let Lambda = {a, b -> MytsrFunc3(a, b)} + let &thesaurusfunc = string(Lambda) + new | only + call setline(1, 'seven') + let g:MytsrFunc3_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'seven']], g:MytsrFunc3_args) + call assert_fails('let &thesaurusfunc = Lambda', 'E729:') + bw! + + " Test for using a lambda function with incorrect return value + let Lambda = {s -> strlen(s)} + let &thesaurusfunc = string(Lambda) + new | only + call setline(1, 'eight') + call feedkeys("A\\\", 'x') + bw! + + " Test for clearing the 'thesaurusfunc' option + set thesaurusfunc='' + set thesaurusfunc& + + call assert_fails("set thesaurusfunc=function('abc')", "E700:") + call assert_fails("set thesaurusfunc=funcref('abc')", "E700:") + let &thesaurusfunc = "{a -> 'abc'}" + call feedkeys("A\\\", 'x') + + " Vim9 tests + let lines =<< trim END + vim9script + + # Test for using function() + def MytsrFunc1(findstart: number, base: string): any + add(g:MytsrFunc1_args, [findstart, base]) + return findstart ? 0 : [] + enddef + set thesaurusfunc=function('MytsrFunc1') + new | only + setline(1, 'one') + g:MytsrFunc1_args = [] + feedkeys("A\\\", 'x') + assert_equal([[1, ''], [0, 'one']], g:MytsrFunc1_args) + bw! + + # Test for using a lambda + def MytsrFunc2(findstart: number, base: string): any + add(g:MytsrFunc2_args, [findstart, base]) + return findstart ? 0 : [] + enddef + &thesaurusfunc = '(a, b) => MytsrFunc2(a, b)' + new | only + setline(1, 'two') + g:MytsrFunc2_args = [] + feedkeys("A\\\", 'x') + assert_equal([[1, ''], [0, 'two']], g:MytsrFunc2_args) + bw! + + # Test for using a variable with a lambda expression + var Fn: func = (a, b) => MytsrFunc2(a, b) + &thesaurusfunc = string(Fn) + new | only + setline(1, 'three') + g:MytsrFunc2_args = [] + feedkeys("A\\\", 'x') + assert_equal([[1, ''], [0, 'three']], g:MytsrFunc2_args) + bw! + END + " call CheckScriptSuccess(lines) + + " Using Vim9 lambda expression in legacy context should fail + " set thesaurusfunc=(a,\ b)\ =>\ g:MytsrFunc2(a,\ b) + " new | only + " let g:MytsrFunc2_args = [] + " call assert_fails('call feedkeys("A\\\", "x")', 'E117:') + " call assert_equal([], g:MytsrFunc2_args) + " bw! + + " Use a buffer-local value and a global value + func MytsrFunc4(findstart, base) + call add(g:MytsrFunc4_args, [a:findstart, a:base]) + return a:findstart ? 0 : ['sunday'] + endfunc + set thesaurusfunc& + setlocal thesaurusfunc=function('MytsrFunc4') + call setline(1, 'sun') + let g:MytsrFunc4_args = [] + call feedkeys("A\\\", "x") + call assert_equal('sunday', getline(1)) + call assert_equal([[1, ''], [0, 'sun']], g:MytsrFunc4_args) + new + call setline(1, 'sun') + let g:MytsrFunc4_args = [] + call feedkeys("A\\\", "x") + call assert_equal('sun', getline(1)) + call assert_equal([], g:MytsrFunc4_args) + set thesaurusfunc=function('MytsrFunc1') + wincmd w + call setline(1, 'sun') + let g:MytsrFunc4_args = [] + call feedkeys("A\\\", "x") + call assert_equal('sunday', getline(1)) + call assert_equal([[1, ''], [0, 'sun']], g:MytsrFunc4_args) + + " cleanup + set thesaurusfunc& + delfunc MytsrFunc1 + delfunc MytsrFunc2 + delfunc MytsrFunc3 + delfunc MytsrFunc4 + %bw! +endfunc + func FooBarComplete(findstart, base) if a:findstart return col('.') - 1 diff --git a/src/nvim/testdir/test_tagfunc.vim b/src/nvim/testdir/test_tagfunc.vim index 29ca69278d..e3085b9395 100644 --- a/src/nvim/testdir/test_tagfunc.vim +++ b/src/nvim/testdir/test_tagfunc.vim @@ -117,6 +117,12 @@ func Test_tagfunc_settagstack() delfunc Mytagfunc2 endfunc +" Script local tagfunc callback function +func s:ScriptLocalTagFunc(pat, flags, info) + let g:ScriptLocalFuncArgs = [a:pat, a:flags, a:info] + return v:null +endfunc + " Test for different ways of setting the 'tagfunc' option func Test_tagfunc_callback() " Test for using a function() @@ -159,6 +165,21 @@ func Test_tagfunc_callback() call assert_equal(['a14', '', {}], g:MytagFunc2_args) call assert_fails('let &tagfunc = Fn', 'E729:') + " Test for using a script local function + set tagfunc=ScriptLocalTagFunc + new | only + let g:ScriptLocalFuncArgs = [] + call assert_fails('tag a15', 'E433:') + call assert_equal(['a15', '', {}], g:ScriptLocalFuncArgs) + + " Test for using a script local funcref variable + let Fn = function("s:ScriptLocalTagFunc") + let &tagfunc= string(Fn) + new | only + let g:ScriptLocalFuncArgs = [] + call assert_fails('tag a16', 'E433:') + call assert_equal(['a16', '', {}], g:ScriptLocalFuncArgs) + " Test for using a lambda function func MytagFunc3(pat, flags, info) let g:MytagFunc3_args = [a:pat, a:flags, a:info] @@ -167,30 +188,30 @@ func Test_tagfunc_callback() set tagfunc={a,\ b,\ c\ ->\ MytagFunc3(a,\ b,\ c)} new | only let g:MytagFunc3_args = [] - call assert_fails('tag a15', 'E433:') - call assert_equal(['a15', '', {}], g:MytagFunc3_args) + call assert_fails('tag a17', 'E433:') + call assert_equal(['a17', '', {}], g:MytagFunc3_args) " Set 'tagfunc' to a lambda expression let &tagfunc = '{a, b, c -> MytagFunc3(a, b, c)}' new | only let g:MytagFunc3_args = [] - call assert_fails('tag a16', 'E433:') - call assert_equal(['a16', '', {}], g:MytagFunc3_args) + call assert_fails('tag a18', 'E433:') + call assert_equal(['a18', '', {}], g:MytagFunc3_args) " Set 'tagfunc' to a variable with a lambda expression let Lambda = {a, b, c -> MytagFunc3(a, b, c)} let &tagfunc = string(Lambda) new | only let g:MytagFunc3_args = [] - call assert_fails("tag a17", "E433:") - call assert_equal(['a17', '', {}], g:MytagFunc3_args) + call assert_fails("tag a19", "E433:") + call assert_equal(['a19', '', {}], g:MytagFunc3_args) call assert_fails('let &tagfunc = Lambda', 'E729:') " Test for using a lambda function with incorrect return value let Lambda = {s -> strlen(s)} let &tagfunc = string(Lambda) new | only - call assert_fails("tag a17", "E987:") + call assert_fails("tag a20", "E987:") " Test for clearing the 'tagfunc' option set tagfunc='' -- cgit From 595f7f37a98f3af12fe94ba4332b8f33004b7e4b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 16:59:07 +0800 Subject: vim-patch:9.0.0246: using freed memory when 'tagfunc' deletes the buffer Problem: Using freed memory when 'tagfunc' deletes the buffer. Solution: Make a copy of the tag name. https://github.com/vim/vim/commit/adce965162dd89bf29ee0e5baf53652e7515762c Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_tagfunc.vim | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_tagfunc.vim b/src/nvim/testdir/test_tagfunc.vim index e3085b9395..ad761f1b23 100644 --- a/src/nvim/testdir/test_tagfunc.vim +++ b/src/nvim/testdir/test_tagfunc.vim @@ -273,4 +273,16 @@ func Test_tagfunc_callback() %bw! endfunc +func Test_tagfunc_wipes_buffer() + func g:Tag0unc0(t,f,o) + bwipe + endfunc + set tagfunc=g:Tag0unc0 + new + cal assert_fails('tag 0', 'E987:') + + delfunc g:Tag0unc0 + set tagfunc= +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 84881674fd702cad5b7572ac868f6d40965a2806 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 17:01:39 +0800 Subject: vim-patch:9.0.0389: crash when 'tagfunc' closes the window Problem: Crash when 'tagfunc' closes the window. Solution: Bail out when the window was closed. https://github.com/vim/vim/commit/ccfde4d028e891a41e3548323c3d47b06fb0b83e Add docs for E1299 from Vim runtime. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_tagfunc.vim | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_tagfunc.vim b/src/nvim/testdir/test_tagfunc.vim index ad761f1b23..8690e30e77 100644 --- a/src/nvim/testdir/test_tagfunc.vim +++ b/src/nvim/testdir/test_tagfunc.vim @@ -285,4 +285,17 @@ func Test_tagfunc_wipes_buffer() set tagfunc= endfunc +func Test_tagfunc_closes_window() + split any + func MytagfuncClose(pat, flags, info) + close + return [{'name' : 'mytag', 'filename' : 'Xtest', 'cmd' : '1'}] + endfunc + set tagfunc=MytagfuncClose + call assert_fails('tag xyz', 'E1299:') + + set tagfunc= +endfunc + + " vim: shiftwidth=2 sts=2 expandtab -- cgit From f91d200c056940e92277e59ffd6507c4db1973d8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 7 Nov 2022 10:24:55 +0800 Subject: vim-patch:8.2.3735: cannot use a lambda for 'imactivatefunc' Problem: Cannot use a lambda for 'imactivatefunc'. Solution: Add lambda support for 'imactivatefunc' and 'imstatusfunc'. (Yegappan Lakshmanan, closes vim/vim#9275) https://github.com/vim/vim/commit/7645da568c5e3b4ee339a2e99c3b3af790619787 Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_ins_complete.vim | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 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 fc612dcbe2..0478ad1516 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -1340,7 +1340,7 @@ func Test_completefunc_callback() call add(g:MycompleteFunc3_args, [a:findstart, a:base]) return a:findstart ? 0 : [] endfunc - set completefunc={a,\ b,\ ->\ MycompleteFunc3(a,\ b,)} + set completefunc={a,\ b\ ->\ MycompleteFunc3(a,\ b)} new | only call setline(1, 'five') let g:MycompleteFunc3_args = [] @@ -1403,26 +1403,29 @@ func Test_completefunc_callback() bw! # Test for using a lambda - def MycompleteFunc2(findstart: number, base: string): any - add(g:MycompleteFunc2_args, [findstart, base]) + def LambdaComplete1(findstart: number, base: string): any + add(g:LambdaComplete1_args, [findstart, base]) return findstart ? 0 : [] enddef - &completefunc = '(a, b) => MycompleteFunc2(a, b)' + &completefunc = '(a, b) => LambdaComplete1(a, b)' new | only setline(1, 'two') - g:MycompleteFunc2_args = [] + g:LambdaComplete1_args = [] feedkeys("A\\\", 'x') - assert_equal([[1, ''], [0, 'two']], g:MycompleteFunc2_args) + assert_equal([[1, ''], [0, 'two']], g:LambdaComplete1_args) bw! # Test for using a variable with a lambda expression - var Fn: func = (a, b) => MycompleteFunc2(a, b) + var Fn: func = (findstart, base) => { + add(g:LambdaComplete2_args, [findstart, base]) + return findstart ? 0 : [] + } &completefunc = string(Fn) new | only setline(1, 'three') - g:MycompleteFunc2_args = [] + g:LambdaComplete2_args = [] feedkeys("A\\\", 'x') - assert_equal([[1, ''], [0, 'three']], g:MycompleteFunc2_args) + assert_equal([[1, ''], [0, 'three']], g:LambdaComplete2_args) bw! END " call CheckScriptSuccess(lines) @@ -1497,7 +1500,7 @@ func Test_omnifunc_callback() call add(g:MyomniFunc3_args, [a:findstart, a:base]) return a:findstart ? 0 : [] endfunc - set omnifunc={a,\ b,\ ->\ MyomniFunc3(a,\ b,)} + set omnifunc={a,\ b\ ->\ MyomniFunc3(a,\ b)} new | only call setline(1, 'five') let g:MyomniFunc3_args = [] @@ -1654,7 +1657,7 @@ func Test_thesaurusfunc_callback() call add(g:MytsrFunc3_args, [a:findstart, a:base]) return a:findstart ? 0 : [] endfunc - set thesaurusfunc={a,\ b,\ ->\ MytsrFunc3(a,\ b,)} + set thesaurusfunc={a,\ b\ ->\ MytsrFunc3(a,\ b)} new | only call setline(1, 'five') let g:MytsrFunc3_args = [] -- cgit From 42e44d6d334bda8b97afe9e34a819ab293e5e10a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 7 Nov 2022 10:26:54 +0800 Subject: vim-patch:8.2.3751: cannot assign a lambda to an option that takes a function Problem: Cannot assign a lambda to an option that takes a function. Solution: Automatically convert the lambda to a string. (Yegappan Lakshmanan, closes vim/vim#9286) https://github.com/vim/vim/commit/6409553b6e3b4de4e1d72b8ee5445595214581ff Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_ins_complete.vim | 192 ++++++++++++++++++++++++++++++--- src/nvim/testdir/test_tagfunc.vim | 56 +++++++++- 2 files changed, 230 insertions(+), 18 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 0478ad1516..8b5f9a189f 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -1302,13 +1302,22 @@ func Test_completefunc_callback() " Using a funcref variable to set 'completefunc' let Fn = function('MycompleteFunc1') + let &completefunc = Fn + new | only + call setline(1, 'two') + let g:MycompleteFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'two']], g:MycompleteFunc1_args) + bw! + + " Using string(funcref_variable) to set 'completefunc' + let Fn = function('MycompleteFunc1') let &completefunc = string(Fn) new | only call setline(1, 'two') let g:MycompleteFunc1_args = [] call feedkeys("A\\\", 'x') call assert_equal([[1, ''], [0, 'two']], g:MycompleteFunc1_args) - call assert_fails('let &completefunc = Fn', 'E729:') bw! " Test for using a funcref() @@ -1326,13 +1335,22 @@ func Test_completefunc_callback() " Using a funcref variable to set 'completefunc' let Fn = funcref('MycompleteFunc2') + let &completefunc = Fn + new | only + call setline(1, 'four') + let g:MycompleteFunc2_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'four']], g:MycompleteFunc2_args) + bw! + + " Using a string(funcref_variable) to set 'completefunc' + let Fn = funcref('MycompleteFunc2') let &completefunc = string(Fn) new | only call setline(1, 'four') let g:MycompleteFunc2_args = [] call feedkeys("A\\\", 'x') call assert_equal([[1, ''], [0, 'four']], g:MycompleteFunc2_args) - call assert_fails('let &completefunc = Fn', 'E729:') bw! " Test for using a lambda function @@ -1349,6 +1367,15 @@ func Test_completefunc_callback() bw! " Set 'completefunc' to a lambda expression + let &completefunc = {a, b -> MycompleteFunc3(a, b)} + new | only + call setline(1, 'six') + let g:MycompleteFunc3_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'six']], g:MycompleteFunc3_args) + bw! + + " Set 'completefunc' to string(lambda_expression) let &completefunc = '{a, b -> MycompleteFunc3(a, b)}' new | only call setline(1, 'six') @@ -1359,18 +1386,27 @@ func Test_completefunc_callback() " Set 'completefunc' to a variable with a lambda expression let Lambda = {a, b -> MycompleteFunc3(a, b)} + let &completefunc = Lambda + new | only + call setline(1, 'seven') + let g:MycompleteFunc3_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'seven']], g:MycompleteFunc3_args) + bw! + + " Set 'completefunc' to a string(variable with a lambda expression) + let Lambda = {a, b -> MycompleteFunc3(a, b)} let &completefunc = string(Lambda) new | only call setline(1, 'seven') let g:MycompleteFunc3_args = [] call feedkeys("A\\\", 'x') call assert_equal([[1, ''], [0, 'seven']], g:MycompleteFunc3_args) - call assert_fails('let &completefunc = Lambda', 'E729:') bw! " Test for using a lambda function with incorrect return value let Lambda = {s -> strlen(s)} - let &completefunc = string(Lambda) + let &completefunc = Lambda new | only call setline(1, 'eight') call feedkeys("A\\\", 'x') @@ -1382,7 +1418,7 @@ func Test_completefunc_callback() call assert_fails("set completefunc=function('abc')", "E700:") call assert_fails("set completefunc=funcref('abc')", "E700:") - let &completefunc = "{a -> 'abc'}" + let &completefunc = {a -> 'abc'} call feedkeys("A\\\", 'x') " Vim9 tests @@ -1407,6 +1443,15 @@ func Test_completefunc_callback() add(g:LambdaComplete1_args, [findstart, base]) return findstart ? 0 : [] enddef + &completefunc = (a, b) => LambdaComplete1(a, b) + new | only + setline(1, 'two') + g:LambdaComplete1_args = [] + feedkeys("A\\\", 'x') + assert_equal([[1, ''], [0, 'two']], g:LambdaComplete1_args) + bw! + + # Test for using a string(lambda) &completefunc = '(a, b) => LambdaComplete1(a, b)' new | only setline(1, 'two') @@ -1420,6 +1465,15 @@ func Test_completefunc_callback() add(g:LambdaComplete2_args, [findstart, base]) return findstart ? 0 : [] } + &completefunc = Fn + new | only + setline(1, 'three') + g:LambdaComplete2_args = [] + feedkeys("A\\\", 'x') + assert_equal([[1, ''], [0, 'three']], g:LambdaComplete2_args) + bw! + + # Test for using a string(variable with a lambda expression) &completefunc = string(Fn) new | only setline(1, 'three') @@ -1462,13 +1516,22 @@ func Test_omnifunc_callback() " Using a funcref variable to set 'omnifunc' let Fn = function('MyomniFunc1') + let &omnifunc = Fn + new | only + call setline(1, 'two') + let g:MyomniFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'two']], g:MyomniFunc1_args) + bw! + + " Using a string(funcref_variable) to set 'omnifunc' + let Fn = function('MyomniFunc1') let &omnifunc = string(Fn) new | only call setline(1, 'two') let g:MyomniFunc1_args = [] call feedkeys("A\\\", 'x') call assert_equal([[1, ''], [0, 'two']], g:MyomniFunc1_args) - call assert_fails('let &omnifunc = Fn', 'E729:') bw! " Test for using a funcref() @@ -1486,13 +1549,22 @@ func Test_omnifunc_callback() " Using a funcref variable to set 'omnifunc' let Fn = funcref('MyomniFunc2') + let &omnifunc = Fn + new | only + call setline(1, 'four') + let g:MyomniFunc2_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'four']], g:MyomniFunc2_args) + bw! + + " Using a string(funcref_variable) to set 'omnifunc' + let Fn = funcref('MyomniFunc2') let &omnifunc = string(Fn) new | only call setline(1, 'four') let g:MyomniFunc2_args = [] call feedkeys("A\\\", 'x') call assert_equal([[1, ''], [0, 'four']], g:MyomniFunc2_args) - call assert_fails('let &omnifunc = Fn', 'E729:') bw! " Test for using a lambda function @@ -1509,6 +1581,15 @@ func Test_omnifunc_callback() bw! " Set 'omnifunc' to a lambda expression + let &omnifunc = {a, b -> MyomniFunc3(a, b)} + new | only + call setline(1, 'six') + let g:MyomniFunc3_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'six']], g:MyomniFunc3_args) + bw! + + " Set 'omnifunc' to a string(lambda_expression) let &omnifunc = '{a, b -> MyomniFunc3(a, b)}' new | only call setline(1, 'six') @@ -1519,18 +1600,27 @@ func Test_omnifunc_callback() " Set 'omnifunc' to a variable with a lambda expression let Lambda = {a, b -> MyomniFunc3(a, b)} + let &omnifunc = Lambda + new | only + call setline(1, 'seven') + let g:MyomniFunc3_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'seven']], g:MyomniFunc3_args) + bw! + + " Set 'omnifunc' to a string(variable with a lambda expression) + let Lambda = {a, b -> MyomniFunc3(a, b)} let &omnifunc = string(Lambda) new | only call setline(1, 'seven') let g:MyomniFunc3_args = [] call feedkeys("A\\\", 'x') call assert_equal([[1, ''], [0, 'seven']], g:MyomniFunc3_args) - call assert_fails('let &omnifunc = Lambda', 'E729:') bw! " Test for using a lambda function with incorrect return value let Lambda = {s -> strlen(s)} - let &omnifunc = string(Lambda) + let &omnifunc = Lambda new | only call setline(1, 'eight') call feedkeys("A\\\", 'x') @@ -1542,7 +1632,7 @@ func Test_omnifunc_callback() call assert_fails("set omnifunc=function('abc')", "E700:") call assert_fails("set omnifunc=funcref('abc')", "E700:") - let &omnifunc = "{a -> 'abc'}" + let &omnifunc = {a -> 'abc'} call feedkeys("A\\\", 'x') " Vim9 tests @@ -1567,6 +1657,15 @@ func Test_omnifunc_callback() add(g:MyomniFunc2_args, [findstart, base]) return findstart ? 0 : [] enddef + &omnifunc = (a, b) => MyomniFunc2(a, b) + new | only + setline(1, 'two') + g:MyomniFunc2_args = [] + feedkeys("A\\\", 'x') + assert_equal([[1, ''], [0, 'two']], g:MyomniFunc2_args) + bw! + + # Test for using a string(lambda) &omnifunc = '(a, b) => MyomniFunc2(a, b)' new | only setline(1, 'two') @@ -1577,6 +1676,15 @@ func Test_omnifunc_callback() # Test for using a variable with a lambda expression var Fn: func = (a, b) => MyomniFunc2(a, b) + &omnifunc = Fn + new | only + setline(1, 'three') + g:MyomniFunc2_args = [] + feedkeys("A\\\", 'x') + assert_equal([[1, ''], [0, 'three']], g:MyomniFunc2_args) + bw! + + # Test for using a string(variable with a lambda expression) &omnifunc = string(Fn) new | only setline(1, 'three') @@ -1619,13 +1727,22 @@ func Test_thesaurusfunc_callback() " Using a funcref variable to set 'thesaurusfunc' let Fn = function('MytsrFunc1') + let &thesaurusfunc = Fn + new | only + call setline(1, 'two') + let g:MytsrFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'two']], g:MytsrFunc1_args) + bw! + + " Using a string(funcref_variable) to set 'thesaurusfunc' + let Fn = function('MytsrFunc1') let &thesaurusfunc = string(Fn) new | only call setline(1, 'two') let g:MytsrFunc1_args = [] call feedkeys("A\\\", 'x') call assert_equal([[1, ''], [0, 'two']], g:MytsrFunc1_args) - call assert_fails('let &thesaurusfunc = Fn', 'E729:') bw! " Test for using a funcref() @@ -1643,13 +1760,22 @@ func Test_thesaurusfunc_callback() " Using a funcref variable to set 'thesaurusfunc' let Fn = funcref('MytsrFunc2') + let &thesaurusfunc = Fn + new | only + call setline(1, 'four') + let g:MytsrFunc2_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'four']], g:MytsrFunc2_args) + bw! + + " Using a string(funcref_variable) to set 'thesaurusfunc' + let Fn = funcref('MytsrFunc2') let &thesaurusfunc = string(Fn) new | only call setline(1, 'four') let g:MytsrFunc2_args = [] call feedkeys("A\\\", 'x') call assert_equal([[1, ''], [0, 'four']], g:MytsrFunc2_args) - call assert_fails('let &thesaurusfunc = Fn', 'E729:') bw! " Test for using a lambda function @@ -1666,6 +1792,15 @@ func Test_thesaurusfunc_callback() bw! " Set 'thesaurusfunc' to a lambda expression + let &thesaurusfunc = {a, b -> MytsrFunc3(a, b)} + new | only + call setline(1, 'six') + let g:MytsrFunc3_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'six']], g:MytsrFunc3_args) + bw! + + " Set 'thesaurusfunc' to a string(lambda expression) let &thesaurusfunc = '{a, b -> MytsrFunc3(a, b)}' new | only call setline(1, 'six') @@ -1676,18 +1811,27 @@ func Test_thesaurusfunc_callback() " Set 'thesaurusfunc' to a variable with a lambda expression let Lambda = {a, b -> MytsrFunc3(a, b)} + let &thesaurusfunc = Lambda + new | only + call setline(1, 'seven') + let g:MytsrFunc3_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'seven']], g:MytsrFunc3_args) + bw! + + " Set 'thesaurusfunc' to a string(variable with a lambda expression) + let Lambda = {a, b -> MytsrFunc3(a, b)} let &thesaurusfunc = string(Lambda) new | only call setline(1, 'seven') let g:MytsrFunc3_args = [] call feedkeys("A\\\", 'x') call assert_equal([[1, ''], [0, 'seven']], g:MytsrFunc3_args) - call assert_fails('let &thesaurusfunc = Lambda', 'E729:') bw! " Test for using a lambda function with incorrect return value let Lambda = {s -> strlen(s)} - let &thesaurusfunc = string(Lambda) + let &thesaurusfunc = Lambda new | only call setline(1, 'eight') call feedkeys("A\\\", 'x') @@ -1699,7 +1843,7 @@ func Test_thesaurusfunc_callback() call assert_fails("set thesaurusfunc=function('abc')", "E700:") call assert_fails("set thesaurusfunc=funcref('abc')", "E700:") - let &thesaurusfunc = "{a -> 'abc'}" + let &thesaurusfunc = {a -> 'abc'} call feedkeys("A\\\", 'x') " Vim9 tests @@ -1724,6 +1868,15 @@ func Test_thesaurusfunc_callback() add(g:MytsrFunc2_args, [findstart, base]) return findstart ? 0 : [] enddef + &thesaurusfunc = (a, b) => MytsrFunc2(a, b) + new | only + setline(1, 'two') + g:MytsrFunc2_args = [] + feedkeys("A\\\", 'x') + assert_equal([[1, ''], [0, 'two']], g:MytsrFunc2_args) + bw! + + # Test for using a string(lambda) &thesaurusfunc = '(a, b) => MytsrFunc2(a, b)' new | only setline(1, 'two') @@ -1734,6 +1887,15 @@ func Test_thesaurusfunc_callback() # Test for using a variable with a lambda expression var Fn: func = (a, b) => MytsrFunc2(a, b) + &thesaurusfunc = Fn + new | only + setline(1, 'three') + g:MytsrFunc2_args = [] + feedkeys("A\\\", 'x') + assert_equal([[1, ''], [0, 'three']], g:MytsrFunc2_args) + bw! + + # Test for using a string(variable with a lambda expression) &thesaurusfunc = string(Fn) new | only setline(1, 'three') diff --git a/src/nvim/testdir/test_tagfunc.vim b/src/nvim/testdir/test_tagfunc.vim index 8690e30e77..06d074c261 100644 --- a/src/nvim/testdir/test_tagfunc.vim +++ b/src/nvim/testdir/test_tagfunc.vim @@ -138,12 +138,19 @@ func Test_tagfunc_callback() " Using a funcref variable to set 'tagfunc' let Fn = function('MytagFunc1') + let &tagfunc = Fn + new | only + let g:MytagFunc1_args = [] + call assert_fails('tag a12', 'E433:') + call assert_equal(['a12', '', {}], g:MytagFunc1_args) + + " Using a string(funcref_variable) to set 'tagfunc' + let Fn = function('MytagFunc1') let &tagfunc = string(Fn) new | only let g:MytagFunc1_args = [] call assert_fails('tag a12', 'E433:') call assert_equal(['a12', '', {}], g:MytagFunc1_args) - call assert_fails('let &tagfunc = Fn', 'E729:') " Test for using a funcref() func MytagFunc2(pat, flags, info) @@ -158,12 +165,19 @@ func Test_tagfunc_callback() " Using a funcref variable to set 'tagfunc' let Fn = funcref('MytagFunc2') + let &tagfunc = Fn + new | only + let g:MytagFunc2_args = [] + call assert_fails('tag a14', 'E433:') + call assert_equal(['a14', '', {}], g:MytagFunc2_args) + + " Using a string(funcref_variable) to set 'tagfunc' + let Fn = funcref('MytagFunc2') let &tagfunc = string(Fn) new | only let g:MytagFunc2_args = [] call assert_fails('tag a14', 'E433:') call assert_equal(['a14', '', {}], g:MytagFunc2_args) - call assert_fails('let &tagfunc = Fn', 'E729:') " Test for using a script local function set tagfunc=ScriptLocalTagFunc @@ -174,6 +188,14 @@ func Test_tagfunc_callback() " Test for using a script local funcref variable let Fn = function("s:ScriptLocalTagFunc") + let &tagfunc= Fn + new | only + let g:ScriptLocalFuncArgs = [] + call assert_fails('tag a16', 'E433:') + call assert_equal(['a16', '', {}], g:ScriptLocalFuncArgs) + + " Test for using a string(script local funcref variable) + let Fn = function("s:ScriptLocalTagFunc") let &tagfunc= string(Fn) new | only let g:ScriptLocalFuncArgs = [] @@ -192,6 +214,13 @@ func Test_tagfunc_callback() call assert_equal(['a17', '', {}], g:MytagFunc3_args) " Set 'tagfunc' to a lambda expression + let &tagfunc = {a, b, c -> MytagFunc3(a, b, c)} + new | only + let g:MytagFunc3_args = [] + call assert_fails('tag a18', 'E433:') + call assert_equal(['a18', '', {}], g:MytagFunc3_args) + + " Set 'tagfunc' to a string(lambda expression) let &tagfunc = '{a, b, c -> MytagFunc3(a, b, c)}' new | only let g:MytagFunc3_args = [] @@ -200,12 +229,19 @@ func Test_tagfunc_callback() " Set 'tagfunc' to a variable with a lambda expression let Lambda = {a, b, c -> MytagFunc3(a, b, c)} + let &tagfunc = Lambda + new | only + let g:MytagFunc3_args = [] + call assert_fails("tag a19", "E433:") + call assert_equal(['a19', '', {}], g:MytagFunc3_args) + + " Set 'tagfunc' to a string(variable with a lambda expression) + let Lambda = {a, b, c -> MytagFunc3(a, b, c)} let &tagfunc = string(Lambda) new | only let g:MytagFunc3_args = [] call assert_fails("tag a19", "E433:") call assert_equal(['a19', '', {}], g:MytagFunc3_args) - call assert_fails('let &tagfunc = Lambda', 'E729:') " Test for using a lambda function with incorrect return value let Lambda = {s -> strlen(s)} @@ -242,6 +278,13 @@ func Test_tagfunc_callback() g:MytagFunc2_args = [pat, flags, info] return null enddef + &tagfunc = (a, b, c) => MytagFunc2(a, b, c) + new | only + g:MytagFunc2_args = [] + assert_fails('tag a20', 'E433:') + assert_equal(['a20', '', {}], g:MytagFunc2_args) + + # Test for using a string(lambda) &tagfunc = '(a, b, c) => MytagFunc2(a, b, c)' new | only g:MytagFunc2_args = [] @@ -250,6 +293,13 @@ func Test_tagfunc_callback() # Test for using a variable with a lambda expression var Fn: func = (a, b, c) => MytagFunc2(a, b, c) + &tagfunc = Fn + new | only + g:MytagFunc2_args = [] + assert_fails('tag a30', 'E433:') + assert_equal(['a30', '', {}], g:MytagFunc2_args) + + # Test for using a variable with a lambda expression &tagfunc = string(Fn) new | only g:MytagFunc2_args = [] -- cgit From d7bd7f13a8f026b8b95fdc49b4754f6199105891 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 7 Nov 2022 11:04:33 +0800 Subject: vim-patch:8.2.3756: might crash when callback is not valid Problem: might crash when callback is not valid. Solution: Check for valid callback. (Yegappan Lakshmanan, closes vim/vim#9293) https://github.com/vim/vim/commit/4dc24eb5adbcc76838fae1e900936dd230209d96 Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_ins_complete.vim | 28 ++++++++++++++++++++++++++++ src/nvim/testdir/test_tagfunc.vim | 5 +++++ 2 files changed, 33 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_ins_complete.vim b/src/nvim/testdir/test_ins_complete.vim index 8b5f9a189f..05a67e7956 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -1491,6 +1491,15 @@ func Test_completefunc_callback() " call assert_fails('call feedkeys("A\\\", "x")', 'E117:') " call assert_equal([], g:MycompleteFunc2_args) + " set 'completefunc' to a non-existing function + set completefunc=MycompleteFunc2 + call setline(1, 'five') + call assert_fails("set completefunc=function('NonExistingFunc')", 'E700:') + call assert_fails("let &completefunc = function('NonExistingFunc')", 'E700:') + let g:MycompleteFunc2_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'five']], g:MycompleteFunc2_args) + " cleanup delfunc MycompleteFunc1 delfunc MycompleteFunc2 @@ -1702,6 +1711,15 @@ func Test_omnifunc_callback() " call assert_fails('call feedkeys("A\\\", "x")', 'E117:') " call assert_equal([], g:MyomniFunc2_args) + " set 'omnifunc' to a non-existing function + set omnifunc=MyomniFunc2 + call setline(1, 'nine') + call assert_fails("set omnifunc=function('NonExistingFunc')", 'E700:') + call assert_fails("let &omnifunc = function('NonExistingFunc')", 'E700:') + let g:MyomniFunc2_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'nine']], g:MyomniFunc2_args) + " cleanup delfunc MyomniFunc1 delfunc MyomniFunc2 @@ -1939,6 +1957,16 @@ func Test_thesaurusfunc_callback() call feedkeys("A\\\", "x") call assert_equal('sunday', getline(1)) call assert_equal([[1, ''], [0, 'sun']], g:MytsrFunc4_args) + %bw! + + " set 'thesaurusfunc' to a non-existing function + set thesaurusfunc=MytsrFunc2 + call setline(1, 'ten') + call assert_fails("set thesaurusfunc=function('NonExistingFunc')", 'E700:') + call assert_fails("let &thesaurusfunc = function('NonExistingFunc')", 'E700:') + let g:MytsrFunc2_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'ten']], g:MytsrFunc2_args) " cleanup set thesaurusfunc& diff --git a/src/nvim/testdir/test_tagfunc.vim b/src/nvim/testdir/test_tagfunc.vim index 06d074c261..88500db269 100644 --- a/src/nvim/testdir/test_tagfunc.vim +++ b/src/nvim/testdir/test_tagfunc.vim @@ -315,6 +315,11 @@ func Test_tagfunc_callback() " call assert_fails("tag a17", "E117:") " call assert_equal([], g:MytagFunc3_args) + " set 'tagfunc' to a non-existing function + call assert_fails("set tagfunc=function('NonExistingFunc')", 'E700:') + call assert_fails("let &tagfunc = function('NonExistingFunc')", 'E700:') + call assert_fails("tag axb123", 'E426:') + " cleanup delfunc MytagFunc1 delfunc MytagFunc2 -- cgit From 8f9ae5278464205004c421e49dad640808b2256f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 7 Nov 2022 11:20:42 +0800 Subject: vim-patch:8.2.3758: options that take a function insufficiently tested Problem: Options that take a function insufficiently tested. Solution: Add additional tests and enhance existing tests. (Yegappan Lakshmanan, closes vim/vim#9298) https://github.com/vim/vim/commit/2172bff36417ddd90653531edc65897411c83b3f Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_ins_complete.vim | 506 ++++++++++++++++----------------- src/nvim/testdir/test_normal.vim | 240 +++++++++++----- src/nvim/testdir/test_tagfunc.vim | 134 +++++---- 3 files changed, 480 insertions(+), 400 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 05a67e7956..eaac66dae0 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -1287,121 +1287,114 @@ endfunc " Test for different ways of setting the 'completefunc' option func Test_completefunc_callback() - " Test for using a function() - func MycompleteFunc1(findstart, base) - call add(g:MycompleteFunc1_args, [a:findstart, a:base]) + func MycompleteFunc1(val, findstart, base) + call add(g:MycompleteFunc1_args, [a:val, a:findstart, a:base]) return a:findstart ? 0 : [] endfunc - set completefunc=function('MycompleteFunc1') + + " Test for using a function() + set completefunc=function('MycompleteFunc1',[10]) new | only call setline(1, 'one') let g:MycompleteFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'one']], g:MycompleteFunc1_args) + call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MycompleteFunc1_args) bw! " Using a funcref variable to set 'completefunc' - let Fn = function('MycompleteFunc1') + let Fn = function('MycompleteFunc1', [11]) let &completefunc = Fn new | only call setline(1, 'two') let g:MycompleteFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'two']], g:MycompleteFunc1_args) + call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MycompleteFunc1_args) bw! " Using string(funcref_variable) to set 'completefunc' - let Fn = function('MycompleteFunc1') + let Fn = function('MycompleteFunc1', [12]) let &completefunc = string(Fn) new | only call setline(1, 'two') let g:MycompleteFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'two']], g:MycompleteFunc1_args) + call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MycompleteFunc1_args) bw! " Test for using a funcref() - func MycompleteFunc2(findstart, base) - call add(g:MycompleteFunc2_args, [a:findstart, a:base]) - return a:findstart ? 0 : [] - endfunc - set completefunc=funcref('MycompleteFunc2') + set completefunc=funcref('MycompleteFunc1',\ [13]) new | only call setline(1, 'three') - let g:MycompleteFunc2_args = [] + let g:MycompleteFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'three']], g:MycompleteFunc2_args) + call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MycompleteFunc1_args) bw! " Using a funcref variable to set 'completefunc' - let Fn = funcref('MycompleteFunc2') + let Fn = funcref('MycompleteFunc1', [14]) let &completefunc = Fn new | only call setline(1, 'four') - let g:MycompleteFunc2_args = [] + let g:MycompleteFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'four']], g:MycompleteFunc2_args) + call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MycompleteFunc1_args) bw! " Using a string(funcref_variable) to set 'completefunc' - let Fn = funcref('MycompleteFunc2') + let Fn = funcref('MycompleteFunc1', [15]) let &completefunc = string(Fn) new | only call setline(1, 'four') - let g:MycompleteFunc2_args = [] + let g:MycompleteFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'four']], g:MycompleteFunc2_args) + call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MycompleteFunc1_args) bw! " Test for using a lambda function - func MycompleteFunc3(findstart, base) - call add(g:MycompleteFunc3_args, [a:findstart, a:base]) - return a:findstart ? 0 : [] - endfunc - set completefunc={a,\ b\ ->\ MycompleteFunc3(a,\ b)} + set completefunc={a,\ b\ ->\ MycompleteFunc1(16,\ a,\ b)} new | only call setline(1, 'five') - let g:MycompleteFunc3_args = [] + let g:MycompleteFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'five']], g:MycompleteFunc3_args) + call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MycompleteFunc1_args) bw! " Set 'completefunc' to a lambda expression - let &completefunc = {a, b -> MycompleteFunc3(a, b)} + let &completefunc = {a, b -> MycompleteFunc1(17, a, b)} new | only call setline(1, 'six') - let g:MycompleteFunc3_args = [] + let g:MycompleteFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'six']], g:MycompleteFunc3_args) + call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MycompleteFunc1_args) bw! " Set 'completefunc' to string(lambda_expression) - let &completefunc = '{a, b -> MycompleteFunc3(a, b)}' + let &completefunc = '{a, b -> MycompleteFunc1(18, a, b)}' new | only call setline(1, 'six') - let g:MycompleteFunc3_args = [] + let g:MycompleteFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'six']], g:MycompleteFunc3_args) + call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MycompleteFunc1_args) bw! " Set 'completefunc' to a variable with a lambda expression - let Lambda = {a, b -> MycompleteFunc3(a, b)} + let Lambda = {a, b -> MycompleteFunc1(19, a, b)} let &completefunc = Lambda new | only call setline(1, 'seven') - let g:MycompleteFunc3_args = [] + let g:MycompleteFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'seven']], g:MycompleteFunc3_args) + call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MycompleteFunc1_args) bw! " Set 'completefunc' to a string(variable with a lambda expression) - let Lambda = {a, b -> MycompleteFunc3(a, b)} + let Lambda = {a, b -> MycompleteFunc1(20, a, b)} let &completefunc = string(Lambda) new | only call setline(1, 'seven') - let g:MycompleteFunc3_args = [] + let g:MycompleteFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'seven']], g:MycompleteFunc3_args) + call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MycompleteFunc1_args) bw! " Test for using a lambda function with incorrect return value @@ -1421,210 +1414,201 @@ func Test_completefunc_callback() let &completefunc = {a -> 'abc'} call feedkeys("A\\\", 'x') + " Using Vim9 lambda expression in legacy context should fail + " set completefunc=(a,\ b)\ =>\ g:MycompleteFunc1(21,\ a,\ b) + new | only + let g:MycompleteFunc1_args = [] + " call assert_fails('call feedkeys("A\\\", "x")', 'E117:') + call assert_equal([], g:MycompleteFunc1_args) + + " set 'completefunc' to a non-existing function + func MycompleteFunc2(findstart, base) + call add(g:MycompleteFunc2_args, [a:findstart, a:base]) + return a:findstart ? 0 : [] + endfunc + set completefunc=MycompleteFunc2 + call setline(1, 'five') + call assert_fails("set completefunc=function('NonExistingFunc')", 'E700:') + call assert_fails("let &completefunc = function('NonExistingFunc')", 'E700:') + let g:MycompleteFunc2_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'five']], g:MycompleteFunc2_args) + bw! + " Vim9 tests let lines =<< trim END vim9script # Test for using function() - def MycompleteFunc1(findstart: number, base: string): any - add(g:MycompleteFunc1_args, [findstart, base]) + def Vim9CompleteFunc(val: number, findstart: number, base: string): any + add(g:Vim9completeFuncArgs, [val, findstart, base]) return findstart ? 0 : [] enddef - set completefunc=function('MycompleteFunc1') + set completefunc=function('Vim9CompleteFunc',\ [60]) new | only setline(1, 'one') - g:MycompleteFunc1_args = [] + g:Vim9completeFuncArgs = [] feedkeys("A\\\", 'x') - assert_equal([[1, ''], [0, 'one']], g:MycompleteFunc1_args) + assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9completeFuncArgs) bw! # Test for using a lambda - def LambdaComplete1(findstart: number, base: string): any - add(g:LambdaComplete1_args, [findstart, base]) - return findstart ? 0 : [] - enddef - &completefunc = (a, b) => LambdaComplete1(a, b) + &completefunc = (a, b) => Vim9CompleteFunc(61, a, b) new | only setline(1, 'two') - g:LambdaComplete1_args = [] + g:Vim9completeFuncArgs = [] feedkeys("A\\\", 'x') - assert_equal([[1, ''], [0, 'two']], g:LambdaComplete1_args) + assert_equal([[61, 1, ''], [61, 0, 'two']], g:Vim9completeFuncArgs) bw! # Test for using a string(lambda) - &completefunc = '(a, b) => LambdaComplete1(a, b)' + &completefunc = '(a, b) => Vim9CompleteFunc(62, a, b)' new | only setline(1, 'two') - g:LambdaComplete1_args = [] + g:Vim9completeFuncArgs = [] feedkeys("A\\\", 'x') - assert_equal([[1, ''], [0, 'two']], g:LambdaComplete1_args) + assert_equal([[62, 1, ''], [62, 0, 'two']], g:Vim9completeFuncArgs) bw! # Test for using a variable with a lambda expression - var Fn: func = (findstart, base) => { - add(g:LambdaComplete2_args, [findstart, base]) - return findstart ? 0 : [] - } + var Fn: func = (a, b) => Vim9CompleteFunc(63, a, b) &completefunc = Fn new | only setline(1, 'three') - g:LambdaComplete2_args = [] + g:Vim9completeFuncArgs = [] feedkeys("A\\\", 'x') - assert_equal([[1, ''], [0, 'three']], g:LambdaComplete2_args) + assert_equal([[63, 1, ''], [63, 0, 'three']], g:Vim9completeFuncArgs) bw! # Test for using a string(variable with a lambda expression) + Fn = (a, b) => Vim9CompleteFunc(64, a, b) &completefunc = string(Fn) new | only setline(1, 'three') - g:LambdaComplete2_args = [] + g:Vim9completeFuncArgs = [] feedkeys("A\\\", 'x') - assert_equal([[1, ''], [0, 'three']], g:LambdaComplete2_args) + assert_equal([[64, 1, ''], [64, 0, 'three']], g:Vim9completeFuncArgs) bw! END " call CheckScriptSuccess(lines) - " Using Vim9 lambda expression in legacy context should fail - " set completefunc=(a,\ b)\ =>\ g:MycompleteFunc2(a,\ b) - " new | only - " let g:MycompleteFunc2_args = [] - " call assert_fails('call feedkeys("A\\\", "x")', 'E117:') - " call assert_equal([], g:MycompleteFunc2_args) - - " set 'completefunc' to a non-existing function - set completefunc=MycompleteFunc2 - call setline(1, 'five') - call assert_fails("set completefunc=function('NonExistingFunc')", 'E700:') - call assert_fails("let &completefunc = function('NonExistingFunc')", 'E700:') - let g:MycompleteFunc2_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'five']], g:MycompleteFunc2_args) - " cleanup delfunc MycompleteFunc1 delfunc MycompleteFunc2 - delfunc MycompleteFunc3 set completefunc& %bw! endfunc " Test for different ways of setting the 'omnifunc' option func Test_omnifunc_callback() - " Test for using a function() - func MyomniFunc1(findstart, base) - call add(g:MyomniFunc1_args, [a:findstart, a:base]) + func MyomniFunc1(val, findstart, base) + call add(g:MyomniFunc1_args, [a:val, a:findstart, a:base]) return a:findstart ? 0 : [] endfunc - set omnifunc=function('MyomniFunc1') + + " Test for using a function() + set omnifunc=function('MyomniFunc1',[10]) new | only call setline(1, 'one') let g:MyomniFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'one']], g:MyomniFunc1_args) + call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MyomniFunc1_args) bw! " Using a funcref variable to set 'omnifunc' - let Fn = function('MyomniFunc1') + let Fn = function('MyomniFunc1', [11]) let &omnifunc = Fn new | only call setline(1, 'two') let g:MyomniFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'two']], g:MyomniFunc1_args) + call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MyomniFunc1_args) bw! " Using a string(funcref_variable) to set 'omnifunc' - let Fn = function('MyomniFunc1') + let Fn = function('MyomniFunc1', [12]) let &omnifunc = string(Fn) new | only call setline(1, 'two') let g:MyomniFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'two']], g:MyomniFunc1_args) + call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MyomniFunc1_args) bw! " Test for using a funcref() - func MyomniFunc2(findstart, base) - call add(g:MyomniFunc2_args, [a:findstart, a:base]) - return a:findstart ? 0 : [] - endfunc - set omnifunc=funcref('MyomniFunc2') + set omnifunc=funcref('MyomniFunc1',\ [13]) new | only call setline(1, 'three') - let g:MyomniFunc2_args = [] + let g:MyomniFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'three']], g:MyomniFunc2_args) + call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MyomniFunc1_args) bw! " Using a funcref variable to set 'omnifunc' - let Fn = funcref('MyomniFunc2') + let Fn = funcref('MyomniFunc1', [14]) let &omnifunc = Fn new | only call setline(1, 'four') - let g:MyomniFunc2_args = [] + let g:MyomniFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'four']], g:MyomniFunc2_args) + call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MyomniFunc1_args) bw! " Using a string(funcref_variable) to set 'omnifunc' - let Fn = funcref('MyomniFunc2') + let Fn = funcref('MyomniFunc1', [15]) let &omnifunc = string(Fn) new | only call setline(1, 'four') - let g:MyomniFunc2_args = [] + let g:MyomniFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'four']], g:MyomniFunc2_args) + call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MyomniFunc1_args) bw! " Test for using a lambda function - func MyomniFunc3(findstart, base) - call add(g:MyomniFunc3_args, [a:findstart, a:base]) - return a:findstart ? 0 : [] - endfunc - set omnifunc={a,\ b\ ->\ MyomniFunc3(a,\ b)} + set omnifunc={a,\ b\ ->\ MyomniFunc1(16,\ a,\ b)} new | only call setline(1, 'five') - let g:MyomniFunc3_args = [] + let g:MyomniFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'five']], g:MyomniFunc3_args) + call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MyomniFunc1_args) bw! " Set 'omnifunc' to a lambda expression - let &omnifunc = {a, b -> MyomniFunc3(a, b)} + let &omnifunc = {a, b -> MyomniFunc1(17, a, b)} new | only call setline(1, 'six') - let g:MyomniFunc3_args = [] + let g:MyomniFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'six']], g:MyomniFunc3_args) + call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MyomniFunc1_args) bw! " Set 'omnifunc' to a string(lambda_expression) - let &omnifunc = '{a, b -> MyomniFunc3(a, b)}' + let &omnifunc = '{a, b -> MyomniFunc1(18, a, b)}' new | only call setline(1, 'six') - let g:MyomniFunc3_args = [] + let g:MyomniFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'six']], g:MyomniFunc3_args) + call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MyomniFunc1_args) bw! " Set 'omnifunc' to a variable with a lambda expression - let Lambda = {a, b -> MyomniFunc3(a, b)} + let Lambda = {a, b -> MyomniFunc1(19, a, b)} let &omnifunc = Lambda new | only call setline(1, 'seven') - let g:MyomniFunc3_args = [] + let g:MyomniFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'seven']], g:MyomniFunc3_args) + call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MyomniFunc1_args) bw! " Set 'omnifunc' to a string(variable with a lambda expression) - let Lambda = {a, b -> MyomniFunc3(a, b)} + let Lambda = {a, b -> MyomniFunc1(20, a, b)} let &omnifunc = string(Lambda) new | only call setline(1, 'seven') - let g:MyomniFunc3_args = [] + let g:MyomniFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'seven']], g:MyomniFunc3_args) + call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MyomniFunc1_args) bw! " Test for using a lambda function with incorrect return value @@ -1644,207 +1628,201 @@ func Test_omnifunc_callback() let &omnifunc = {a -> 'abc'} call feedkeys("A\\\", 'x') + " Using Vim9 lambda expression in legacy context should fail + " set omnifunc=(a,\ b)\ =>\ g:MyomniFunc1(21,\ a,\ b) + new | only + let g:MyomniFunc1_args = [] + " call assert_fails('call feedkeys("A\\\", "x")', 'E117:') + call assert_equal([], g:MyomniFunc1_args) + + " set 'omnifunc' to a non-existing function + func MyomniFunc2(findstart, base) + call add(g:MyomniFunc2_args, [a:findstart, a:base]) + return a:findstart ? 0 : [] + endfunc + set omnifunc=MyomniFunc2 + call setline(1, 'nine') + call assert_fails("set omnifunc=function('NonExistingFunc')", 'E700:') + call assert_fails("let &omnifunc = function('NonExistingFunc')", 'E700:') + let g:MyomniFunc2_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'nine']], g:MyomniFunc2_args) + bw! + " Vim9 tests let lines =<< trim END vim9script # Test for using function() - def MyomniFunc1(findstart: number, base: string): any - add(g:MyomniFunc1_args, [findstart, base]) + def Vim9omniFunc(val: number, findstart: number, base: string): any + add(g:Vim9omniFunc_Args, [val, findstart, base]) return findstart ? 0 : [] enddef - set omnifunc=function('MyomniFunc1') + set omnifunc=function('Vim9omniFunc',\ [60]) new | only setline(1, 'one') - g:MyomniFunc1_args = [] + g:Vim9omniFunc_Args = [] feedkeys("A\\\", 'x') - assert_equal([[1, ''], [0, 'one']], g:MyomniFunc1_args) + assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9omniFunc_Args) bw! # Test for using a lambda - def MyomniFunc2(findstart: number, base: string): any - add(g:MyomniFunc2_args, [findstart, base]) - return findstart ? 0 : [] - enddef - &omnifunc = (a, b) => MyomniFunc2(a, b) + &omnifunc = (a, b) => Vim9omniFunc(61, a, b) new | only setline(1, 'two') - g:MyomniFunc2_args = [] + g:Vim9omniFunc_Args = [] feedkeys("A\\\", 'x') - assert_equal([[1, ''], [0, 'two']], g:MyomniFunc2_args) + assert_equal([[61, 1, ''], [61, 0, 'two']], g:Vim9omniFunc_Args) bw! # Test for using a string(lambda) - &omnifunc = '(a, b) => MyomniFunc2(a, b)' + &omnifunc = '(a, b) => Vim9omniFunc(62, a, b)' new | only setline(1, 'two') - g:MyomniFunc2_args = [] + g:Vim9omniFunc_Args = [] feedkeys("A\\\", 'x') - assert_equal([[1, ''], [0, 'two']], g:MyomniFunc2_args) + assert_equal([[62, 1, ''], [62, 0, 'two']], g:Vim9omniFunc_Args) bw! # Test for using a variable with a lambda expression - var Fn: func = (a, b) => MyomniFunc2(a, b) + var Fn: func = (a, b) => Vim9omniFunc(63, a, b) &omnifunc = Fn new | only setline(1, 'three') - g:MyomniFunc2_args = [] + g:Vim9omniFunc_Args = [] feedkeys("A\\\", 'x') - assert_equal([[1, ''], [0, 'three']], g:MyomniFunc2_args) + assert_equal([[63, 1, ''], [63, 0, 'three']], g:Vim9omniFunc_Args) bw! # Test for using a string(variable with a lambda expression) + Fn = (a, b) => Vim9omniFunc(64, a, b) &omnifunc = string(Fn) new | only setline(1, 'three') - g:MyomniFunc2_args = [] + g:Vim9omniFunc_Args = [] feedkeys("A\\\", 'x') - assert_equal([[1, ''], [0, 'three']], g:MyomniFunc2_args) + assert_equal([[64, 1, ''], [64, 0, 'three']], g:Vim9omniFunc_Args) bw! END " call CheckScriptSuccess(lines) - " Using Vim9 lambda expression in legacy context should fail - " set omnifunc=(a,\ b)\ =>\ g:MyomniFunc2(a,\ b) - " new | only - " let g:MyomniFunc2_args = [] - " call assert_fails('call feedkeys("A\\\", "x")', 'E117:') - " call assert_equal([], g:MyomniFunc2_args) - - " set 'omnifunc' to a non-existing function - set omnifunc=MyomniFunc2 - call setline(1, 'nine') - call assert_fails("set omnifunc=function('NonExistingFunc')", 'E700:') - call assert_fails("let &omnifunc = function('NonExistingFunc')", 'E700:') - let g:MyomniFunc2_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'nine']], g:MyomniFunc2_args) - " cleanup delfunc MyomniFunc1 delfunc MyomniFunc2 - delfunc MyomniFunc3 set omnifunc& %bw! endfunc " Test for different ways of setting the 'thesaurusfunc' option func Test_thesaurusfunc_callback() - " Test for using a function() - func MytsrFunc1(findstart, base) - call add(g:MytsrFunc1_args, [a:findstart, a:base]) + func MytsrFunc1(val, findstart, base) + call add(g:MytsrFunc1_args, [a:val, a:findstart, a:base]) return a:findstart ? 0 : [] endfunc - set thesaurusfunc=function('MytsrFunc1') + + " Test for using a function() + set thesaurusfunc=function('MytsrFunc1',[10]) new | only call setline(1, 'one') let g:MytsrFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'one']], g:MytsrFunc1_args) + call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MytsrFunc1_args) bw! " Using a funcref variable to set 'thesaurusfunc' - let Fn = function('MytsrFunc1') + let Fn = function('MytsrFunc1', [11]) let &thesaurusfunc = Fn new | only call setline(1, 'two') let g:MytsrFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'two']], g:MytsrFunc1_args) + call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MytsrFunc1_args) bw! " Using a string(funcref_variable) to set 'thesaurusfunc' - let Fn = function('MytsrFunc1') + let Fn = function('MytsrFunc1', [12]) let &thesaurusfunc = string(Fn) new | only call setline(1, 'two') let g:MytsrFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'two']], g:MytsrFunc1_args) + call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MytsrFunc1_args) bw! " Test for using a funcref() - func MytsrFunc2(findstart, base) - call add(g:MytsrFunc2_args, [a:findstart, a:base]) - return a:findstart ? 0 : [] - endfunc - set thesaurusfunc=funcref('MytsrFunc2') + set thesaurusfunc=funcref('MytsrFunc1',[13]) new | only call setline(1, 'three') - let g:MytsrFunc2_args = [] + let g:MytsrFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'three']], g:MytsrFunc2_args) + call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MytsrFunc1_args) bw! " Using a funcref variable to set 'thesaurusfunc' - let Fn = funcref('MytsrFunc2') + let Fn = funcref('MytsrFunc1', [14]) let &thesaurusfunc = Fn new | only call setline(1, 'four') - let g:MytsrFunc2_args = [] + let g:MytsrFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'four']], g:MytsrFunc2_args) + call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MytsrFunc1_args) bw! " Using a string(funcref_variable) to set 'thesaurusfunc' - let Fn = funcref('MytsrFunc2') + let Fn = funcref('MytsrFunc1', [15]) let &thesaurusfunc = string(Fn) new | only call setline(1, 'four') - let g:MytsrFunc2_args = [] + let g:MytsrFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'four']], g:MytsrFunc2_args) + call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MytsrFunc1_args) bw! " Test for using a lambda function - func MytsrFunc3(findstart, base) - call add(g:MytsrFunc3_args, [a:findstart, a:base]) - return a:findstart ? 0 : [] - endfunc - set thesaurusfunc={a,\ b\ ->\ MytsrFunc3(a,\ b)} + set thesaurusfunc={a,\ b\ ->\ MytsrFunc1(16,\ a,\ b)} new | only call setline(1, 'five') - let g:MytsrFunc3_args = [] + let g:MytsrFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'five']], g:MytsrFunc3_args) + call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MytsrFunc1_args) bw! " Set 'thesaurusfunc' to a lambda expression - let &thesaurusfunc = {a, b -> MytsrFunc3(a, b)} + let &thesaurusfunc = {a, b -> MytsrFunc1(17, a, b)} new | only call setline(1, 'six') - let g:MytsrFunc3_args = [] + let g:MytsrFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'six']], g:MytsrFunc3_args) + call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MytsrFunc1_args) bw! " Set 'thesaurusfunc' to a string(lambda expression) - let &thesaurusfunc = '{a, b -> MytsrFunc3(a, b)}' + let &thesaurusfunc = '{a, b -> MytsrFunc1(18, a, b)}' new | only call setline(1, 'six') - let g:MytsrFunc3_args = [] + let g:MytsrFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'six']], g:MytsrFunc3_args) + call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MytsrFunc1_args) bw! " Set 'thesaurusfunc' to a variable with a lambda expression - let Lambda = {a, b -> MytsrFunc3(a, b)} + let Lambda = {a, b -> MytsrFunc1(19, a, b)} let &thesaurusfunc = Lambda new | only call setline(1, 'seven') - let g:MytsrFunc3_args = [] + let g:MytsrFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'seven']], g:MytsrFunc3_args) + call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MytsrFunc1_args) bw! " Set 'thesaurusfunc' to a string(variable with a lambda expression) - let Lambda = {a, b -> MytsrFunc3(a, b)} + let Lambda = {a, b -> MytsrFunc1(20, a, b)} let &thesaurusfunc = string(Lambda) new | only call setline(1, 'seven') - let g:MytsrFunc3_args = [] + let g:MytsrFunc1_args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'seven']], g:MytsrFunc3_args) + call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MytsrFunc1_args) bw! " Test for using a lambda function with incorrect return value @@ -1864,116 +1842,112 @@ func Test_thesaurusfunc_callback() let &thesaurusfunc = {a -> 'abc'} call feedkeys("A\\\", 'x') + " Using Vim9 lambda expression in legacy context should fail + " set thesaurusfunc=(a,\ b)\ =>\ g:MytsrFunc1(21,\ a,\ b) + new | only + let g:MytsrFunc1_args = [] + " call assert_fails('call feedkeys("A\\\", "x")', 'E117:') + call assert_equal([], g:MytsrFunc1_args) + bw! + + " Use a buffer-local value and a global value + set thesaurusfunc& + setlocal thesaurusfunc=function('MytsrFunc1',[22]) + call setline(1, 'sun') + let g:MytsrFunc1_args = [] + call feedkeys("A\\\", "x") + call assert_equal('sun', getline(1)) + call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:MytsrFunc1_args) + new + call setline(1, 'sun') + let g:MytsrFunc1_args = [] + call feedkeys("A\\\", "x") + call assert_equal('sun', getline(1)) + call assert_equal([], g:MytsrFunc1_args) + set thesaurusfunc=function('MytsrFunc1',[23]) + wincmd w + call setline(1, 'sun') + let g:MytsrFunc1_args = [] + call feedkeys("A\\\", "x") + call assert_equal('sun', getline(1)) + call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:MytsrFunc1_args) + %bw! + + " set 'thesaurusfunc' to a non-existing function + func MytsrFunc2(findstart, base) + call add(g:MytsrFunc2_args, [a:findstart, a:base]) + return a:findstart ? 0 : ['sunday'] + endfunc + set thesaurusfunc=MytsrFunc2 + call setline(1, 'ten') + call assert_fails("set thesaurusfunc=function('NonExistingFunc')", 'E700:') + call assert_fails("let &thesaurusfunc = function('NonExistingFunc')", 'E700:') + let g:MytsrFunc2_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'ten']], g:MytsrFunc2_args) + bw! + " Vim9 tests let lines =<< trim END vim9script # Test for using function() - def MytsrFunc1(findstart: number, base: string): any - add(g:MytsrFunc1_args, [findstart, base]) + def Vim9tsrFunc(val: number, findstart: number, base: string): any + add(g:Vim9tsrFunc_Args, [val, findstart, base]) return findstart ? 0 : [] enddef - set thesaurusfunc=function('MytsrFunc1') + set thesaurusfunc=function('Vim9tsrFunc',\ [60]) new | only setline(1, 'one') - g:MytsrFunc1_args = [] + g:Vim9tsrFunc_Args = [] feedkeys("A\\\", 'x') - assert_equal([[1, ''], [0, 'one']], g:MytsrFunc1_args) + assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9tsrFunc_Args) bw! # Test for using a lambda - def MytsrFunc2(findstart: number, base: string): any - add(g:MytsrFunc2_args, [findstart, base]) - return findstart ? 0 : [] - enddef - &thesaurusfunc = (a, b) => MytsrFunc2(a, b) + &thesaurusfunc = (a, b) => Vim9tsrFunc(61, a, b) new | only setline(1, 'two') - g:MytsrFunc2_args = [] + g:Vim9tsrFunc_Args = [] feedkeys("A\\\", 'x') - assert_equal([[1, ''], [0, 'two']], g:MytsrFunc2_args) + assert_equal([[61, 1, ''], [61, 0, 'two']], g:Vim9tsrFunc_Args) bw! # Test for using a string(lambda) - &thesaurusfunc = '(a, b) => MytsrFunc2(a, b)' + &thesaurusfunc = '(a, b) => Vim9tsrFunc(62, a, b)' new | only setline(1, 'two') - g:MytsrFunc2_args = [] + g:Vim9tsrFunc_Args = [] feedkeys("A\\\", 'x') - assert_equal([[1, ''], [0, 'two']], g:MytsrFunc2_args) + assert_equal([[62, 1, ''], [62, 0, 'two']], g:Vim9tsrFunc_Args) bw! # Test for using a variable with a lambda expression - var Fn: func = (a, b) => MytsrFunc2(a, b) + var Fn: func = (a, b) => Vim9tsrFunc(63, a, b) &thesaurusfunc = Fn new | only setline(1, 'three') - g:MytsrFunc2_args = [] + g:Vim9tsrFunc_Args = [] feedkeys("A\\\", 'x') - assert_equal([[1, ''], [0, 'three']], g:MytsrFunc2_args) + assert_equal([[63, 1, ''], [63, 0, 'three']], g:Vim9tsrFunc_Args) bw! # Test for using a string(variable with a lambda expression) + Fn = (a, b) => Vim9tsrFunc(64, a, b) &thesaurusfunc = string(Fn) new | only setline(1, 'three') - g:MytsrFunc2_args = [] + g:Vim9tsrFunc_Args = [] feedkeys("A\\\", 'x') - assert_equal([[1, ''], [0, 'three']], g:MytsrFunc2_args) + assert_equal([[64, 1, ''], [64, 0, 'three']], g:Vim9tsrFunc_Args) bw! END " call CheckScriptSuccess(lines) - " Using Vim9 lambda expression in legacy context should fail - " set thesaurusfunc=(a,\ b)\ =>\ g:MytsrFunc2(a,\ b) - " new | only - " let g:MytsrFunc2_args = [] - " call assert_fails('call feedkeys("A\\\", "x")', 'E117:') - " call assert_equal([], g:MytsrFunc2_args) - " bw! - - " Use a buffer-local value and a global value - func MytsrFunc4(findstart, base) - call add(g:MytsrFunc4_args, [a:findstart, a:base]) - return a:findstart ? 0 : ['sunday'] - endfunc - set thesaurusfunc& - setlocal thesaurusfunc=function('MytsrFunc4') - call setline(1, 'sun') - let g:MytsrFunc4_args = [] - call feedkeys("A\\\", "x") - call assert_equal('sunday', getline(1)) - call assert_equal([[1, ''], [0, 'sun']], g:MytsrFunc4_args) - new - call setline(1, 'sun') - let g:MytsrFunc4_args = [] - call feedkeys("A\\\", "x") - call assert_equal('sun', getline(1)) - call assert_equal([], g:MytsrFunc4_args) - set thesaurusfunc=function('MytsrFunc1') - wincmd w - call setline(1, 'sun') - let g:MytsrFunc4_args = [] - call feedkeys("A\\\", "x") - call assert_equal('sunday', getline(1)) - call assert_equal([[1, ''], [0, 'sun']], g:MytsrFunc4_args) - %bw! - - " set 'thesaurusfunc' to a non-existing function - set thesaurusfunc=MytsrFunc2 - call setline(1, 'ten') - call assert_fails("set thesaurusfunc=function('NonExistingFunc')", 'E700:') - call assert_fails("let &thesaurusfunc = function('NonExistingFunc')", 'E700:') - let g:MytsrFunc2_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'ten']], g:MytsrFunc2_args) - " cleanup set thesaurusfunc& delfunc MytsrFunc1 delfunc MytsrFunc2 - delfunc MytsrFunc3 - delfunc MytsrFunc4 %bw! endfunc diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index 6160352052..b9cc858cdb 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -388,70 +388,6 @@ func Test_normal09a_operatorfunc() norm V10j,, call assert_equal(22, g:a) - " Use a lambda function for 'opfunc' - unmap ,, - call cursor(1, 1) - let g:a=0 - nmap ,, :set opfunc={type\ ->\ CountSpaces(type)}g@ - vmap ,, :call CountSpaces(visualmode(), 1) - 50 - norm V2j,, - call assert_equal(6, g:a) - norm V,, - call assert_equal(2, g:a) - norm ,,l - call assert_equal(0, g:a) - 50 - exe "norm 0\10j2l,," - call assert_equal(11, g:a) - 50 - norm V10j,, - call assert_equal(22, g:a) - - " use a partial function for 'opfunc' - let g:OpVal = 0 - func! Test_opfunc1(x, y, type) - let g:OpVal = a:x + a:y - endfunc - set opfunc=function('Test_opfunc1',\ [5,\ 7]) - normal! g@l - call assert_equal(12, g:OpVal) - " delete the function and try to use g@ - delfunc Test_opfunc1 - call test_garbagecollect_now() - call assert_fails('normal! g@l', 'E117:') - set opfunc= - - " use a funcref for 'opfunc' - let g:OpVal = 0 - func! Test_opfunc2(x, y, type) - let g:OpVal = a:x + a:y - endfunc - set opfunc=funcref('Test_opfunc2',\ [4,\ 3]) - normal! g@l - call assert_equal(7, g:OpVal) - " delete the function and try to use g@ - delfunc Test_opfunc2 - call test_garbagecollect_now() - call assert_fails('normal! g@l', 'E933:') - set opfunc= - - " Try to use a function with two arguments for 'operatorfunc' - let g:OpVal = 0 - func! Test_opfunc3(x, y) - let g:OpVal = 4 - endfunc - set opfunc=Test_opfunc3 - call assert_fails('normal! g@l', 'E119:') - call assert_equal(0, g:OpVal) - set opfunc= - delfunc Test_opfunc3 - unlet g:OpVal - - " Try to use a lambda function with two arguments for 'operatorfunc' - set opfunc={x,\ y\ ->\ 'done'} - call assert_fails('normal! g@l', 'E119:') - " clean up unmap ,, set opfunc= @@ -520,6 +456,182 @@ func Test_normal09c_operatorfunc() set operatorfunc= endfunc +" Test for different ways of setting the 'operatorfunc' option +func Test_opfunc_callback() + new + func MyopFunc(val, type) + let g:OpFuncArgs = [a:val, a:type] + endfunc + + " Test for using a function() + set opfunc=function('MyopFunc',\ [11]) + let g:OpFuncArgs = [] + normal! g@l + call assert_equal([11, 'char'], g:OpFuncArgs) + + " Using a funcref variable to set 'operatorfunc' + let Fn = function('MyopFunc', [12]) + let &opfunc = Fn + let g:OpFuncArgs = [] + normal! g@l + call assert_equal([12, 'char'], g:OpFuncArgs) + + " Using a string(funcref_variable) to set 'operatorfunc' + let Fn = function('MyopFunc', [13]) + let &operatorfunc = string(Fn) + let g:OpFuncArgs = [] + normal! g@l + call assert_equal([13, 'char'], g:OpFuncArgs) + + " Test for using a funcref() + set operatorfunc=funcref('MyopFunc',\ [14]) + let g:OpFuncArgs = [] + normal! g@l + call assert_equal([14, 'char'], g:OpFuncArgs) + + " Using a funcref variable to set 'operatorfunc' + let Fn = funcref('MyopFunc', [15]) + let &opfunc = Fn + let g:OpFuncArgs = [] + normal! g@l + call assert_equal([15, 'char'], g:OpFuncArgs) + + " Using a string(funcref_variable) to set 'operatorfunc' + let Fn = funcref('MyopFunc', [16]) + let &opfunc = string(Fn) + let g:OpFuncArgs = [] + normal! g@l + call assert_equal([16, 'char'], g:OpFuncArgs) + + " Test for using a lambda function using set + set opfunc={a\ ->\ MyopFunc(17,\ a)} + let g:OpFuncArgs = [] + normal! g@l + call assert_equal([17, 'char'], g:OpFuncArgs) + + " Test for using a lambda function using let + let &opfunc = {a -> MyopFunc(18, a)} + let g:OpFuncArgs = [] + normal! g@l + call assert_equal([18, 'char'], g:OpFuncArgs) + + " Set 'operatorfunc' to a string(lambda expression) + let &opfunc = '{a -> MyopFunc(19, a)}' + let g:OpFuncArgs = [] + normal! g@l + call assert_equal([19, 'char'], g:OpFuncArgs) + + " Set 'operatorfunc' to a variable with a lambda expression + let Lambda = {a -> MyopFunc(20, a)} + let &opfunc = Lambda + let g:OpFuncArgs = [] + normal! g@l + call assert_equal([20, 'char'], g:OpFuncArgs) + + " Set 'operatorfunc' to a string(variable with a lambda expression) + let Lambda = {a -> MyopFunc(21, a)} + let &opfunc = string(Lambda) + let g:OpFuncArgs = [] + normal! g@l + call assert_equal([21, 'char'], g:OpFuncArgs) + + " Try to use 'operatorfunc' after the function is deleted + func TmpOpFunc(type) + let g:OpFuncArgs = [22, a:type] + endfunc + let &opfunc = function('TmpOpFunc') + delfunc TmpOpFunc + call test_garbagecollect_now() + let g:OpFuncArgs = [] + call assert_fails('normal! g@l', 'E117:') + call assert_equal([], g:OpFuncArgs) + + " Try to use a function with two arguments for 'operatorfunc' + func! MyopFunc2(x, y) + let g:OpFuncArgs = [a:x, a:y] + endfunc + set opfunc=MyopFunc2 + let g:OpFuncArgs = [] + call assert_fails('normal! g@l', 'E119:') + call assert_equal([], g:OpFuncArgs) + + " Try to use a lambda function with two arguments for 'operatorfunc' + let &opfunc = {a, b -> MyopFunc(23, b)} + let g:OpFuncArgs = [] + call assert_fails('normal! g@l', 'E119:') + call assert_equal([], g:OpFuncArgs) + + " Test for clearing the 'operatorfunc' option + set opfunc='' + set opfunc& + + call assert_fails("set opfunc=function('abc')", "E700:") + call assert_fails("set opfunc=funcref('abc')", "E700:") + + " Using Vim9 lambda expression in legacy context should fail + " set opfunc=(a)\ =>\ MyopFunc(24,\ a) + let g:OpFuncArgs = [] + " call assert_fails('normal! g@l', 'E117:') + call assert_equal([], g:OpFuncArgs) + + " set 'operatorfunc' to a non-existing function + let &opfunc = function('MyopFunc', [25]) + call assert_fails("set opfunc=function('NonExistingFunc')", 'E700:') + call assert_fails("let &opfunc = function('NonExistingFunc')", 'E700:') + let g:OpFuncArgs = [] + normal! g@l + call assert_equal([25, 'char'], g:OpFuncArgs) + + " Vim9 tests + let lines =<< trim END + vim9script + + # Test for using function() + def g:Vim9opFunc(val: number, type: string): void + g:OpFuncArgs = [val, type] + enddef + set opfunc=function('g:Vim9opFunc',\ [60]) + g:OpFuncArgs = [] + normal! g@l + assert_equal([60, 'char'], g:OpFuncArgs) + + # Test for using a lambda + &opfunc = (a) => Vim9opFunc(61, a) + g:OpFuncArgs = [] + normal! g@l + assert_equal([61, 'char'], g:OpFuncArgs) + + # Test for using a string(lambda) + &opfunc = '(a) => Vim9opFunc(62, a)' + g:OpFuncArgs = [] + normal! g@l + assert_equal([62, 'char'], g:OpFuncArgs) + + # Test for using a variable with a lambda expression + var Fn: func = (a) => Vim9opFunc(63, a) + &opfunc = Fn + g:OpFuncArgs = [] + normal! g@l + assert_equal([63, 'char'], g:OpFuncArgs) + + # Test for using a string(variable with a lambda expression) + Fn = (a) => Vim9opFunc(64, a) + &opfunc = string(Fn) + g:OpFuncArgs = [] + normal! g@l + assert_equal([64, 'char'], g:OpFuncArgs) + bw! + END + " call CheckScriptSuccess(lines) + + " cleanup + set opfunc& + delfunc MyopFunc + delfunc MyopFunc2 + unlet g:OpFuncArgs + %bw! +endfunc + func Test_normal10_expand() " Test for expand() 10new diff --git a/src/nvim/testdir/test_tagfunc.vim b/src/nvim/testdir/test_tagfunc.vim index 88500db269..79b1110b43 100644 --- a/src/nvim/testdir/test_tagfunc.vim +++ b/src/nvim/testdir/test_tagfunc.vim @@ -125,59 +125,60 @@ endfunc " Test for different ways of setting the 'tagfunc' option func Test_tagfunc_callback() - " Test for using a function() - func MytagFunc1(pat, flags, info) - let g:MytagFunc1_args = [a:pat, a:flags, a:info] + func MytagFunc1(val, pat, flags, info) + let g:MytagFunc1_args = [a:val, a:pat, a:flags, a:info] return v:null endfunc - set tagfunc=function('MytagFunc1') + + " Test for using a function() + set tagfunc=function('MytagFunc1',[10]) new | only let g:MytagFunc1_args = [] call assert_fails('tag a11', 'E433:') - call assert_equal(['a11', '', {}], g:MytagFunc1_args) + call assert_equal([10, 'a11', '', {}], g:MytagFunc1_args) " Using a funcref variable to set 'tagfunc' - let Fn = function('MytagFunc1') + let Fn = function('MytagFunc1', [11]) let &tagfunc = Fn new | only let g:MytagFunc1_args = [] call assert_fails('tag a12', 'E433:') - call assert_equal(['a12', '', {}], g:MytagFunc1_args) + call assert_equal([11, 'a12', '', {}], g:MytagFunc1_args) " Using a string(funcref_variable) to set 'tagfunc' - let Fn = function('MytagFunc1') + let Fn = function('MytagFunc1', [12]) let &tagfunc = string(Fn) new | only let g:MytagFunc1_args = [] call assert_fails('tag a12', 'E433:') - call assert_equal(['a12', '', {}], g:MytagFunc1_args) + call assert_equal([12, 'a12', '', {}], g:MytagFunc1_args) " Test for using a funcref() func MytagFunc2(pat, flags, info) let g:MytagFunc2_args = [a:pat, a:flags, a:info] return v:null endfunc - set tagfunc=funcref('MytagFunc2') + set tagfunc=funcref('MytagFunc1',[13]) new | only - let g:MytagFunc2_args = [] + let g:MytagFunc1_args = [] call assert_fails('tag a13', 'E433:') - call assert_equal(['a13', '', {}], g:MytagFunc2_args) + call assert_equal([13, 'a13', '', {}], g:MytagFunc1_args) " Using a funcref variable to set 'tagfunc' - let Fn = funcref('MytagFunc2') + let Fn = funcref('MytagFunc1', [14]) let &tagfunc = Fn new | only - let g:MytagFunc2_args = [] + let g:MytagFunc1_args = [] call assert_fails('tag a14', 'E433:') - call assert_equal(['a14', '', {}], g:MytagFunc2_args) + call assert_equal([14, 'a14', '', {}], g:MytagFunc1_args) " Using a string(funcref_variable) to set 'tagfunc' - let Fn = funcref('MytagFunc2') + let Fn = funcref('MytagFunc1', [15]) let &tagfunc = string(Fn) new | only - let g:MytagFunc2_args = [] + let g:MytagFunc1_args = [] call assert_fails('tag a14', 'E433:') - call assert_equal(['a14', '', {}], g:MytagFunc2_args) + call assert_equal([15, 'a14', '', {}], g:MytagFunc1_args) " Test for using a script local function set tagfunc=ScriptLocalTagFunc @@ -203,45 +204,41 @@ func Test_tagfunc_callback() call assert_equal(['a16', '', {}], g:ScriptLocalFuncArgs) " Test for using a lambda function - func MytagFunc3(pat, flags, info) - let g:MytagFunc3_args = [a:pat, a:flags, a:info] - return v:null - endfunc - set tagfunc={a,\ b,\ c\ ->\ MytagFunc3(a,\ b,\ c)} + set tagfunc={a,\ b,\ c\ ->\ MytagFunc1(16,\ a,\ b,\ c)} new | only - let g:MytagFunc3_args = [] + let g:MytagFunc1_args = [] call assert_fails('tag a17', 'E433:') - call assert_equal(['a17', '', {}], g:MytagFunc3_args) + call assert_equal([16, 'a17', '', {}], g:MytagFunc1_args) " Set 'tagfunc' to a lambda expression - let &tagfunc = {a, b, c -> MytagFunc3(a, b, c)} + let &tagfunc = {a, b, c -> MytagFunc1(17, a, b, c)} new | only - let g:MytagFunc3_args = [] + let g:MytagFunc1_args = [] call assert_fails('tag a18', 'E433:') - call assert_equal(['a18', '', {}], g:MytagFunc3_args) + call assert_equal([17, 'a18', '', {}], g:MytagFunc1_args) " Set 'tagfunc' to a string(lambda expression) - let &tagfunc = '{a, b, c -> MytagFunc3(a, b, c)}' + let &tagfunc = '{a, b, c -> MytagFunc1(18, a, b, c)}' new | only - let g:MytagFunc3_args = [] + let g:MytagFunc1_args = [] call assert_fails('tag a18', 'E433:') - call assert_equal(['a18', '', {}], g:MytagFunc3_args) + call assert_equal([18, 'a18', '', {}], g:MytagFunc1_args) " Set 'tagfunc' to a variable with a lambda expression - let Lambda = {a, b, c -> MytagFunc3(a, b, c)} + let Lambda = {a, b, c -> MytagFunc1(19, a, b, c)} let &tagfunc = Lambda new | only - let g:MytagFunc3_args = [] + let g:MytagFunc1_args = [] call assert_fails("tag a19", "E433:") - call assert_equal(['a19', '', {}], g:MytagFunc3_args) + call assert_equal([19, 'a19', '', {}], g:MytagFunc1_args) " Set 'tagfunc' to a string(variable with a lambda expression) - let Lambda = {a, b, c -> MytagFunc3(a, b, c)} + let Lambda = {a, b, c -> MytagFunc1(20, a, b, c)} let &tagfunc = string(Lambda) new | only - let g:MytagFunc3_args = [] + let g:MytagFunc1_args = [] call assert_fails("tag a19", "E433:") - call assert_equal(['a19', '', {}], g:MytagFunc3_args) + call assert_equal([20, 'a19', '', {}], g:MytagFunc1_args) " Test for using a lambda function with incorrect return value let Lambda = {s -> strlen(s)} @@ -258,72 +255,69 @@ func Test_tagfunc_callback() let &tagfunc = "{a -> 'abc'}" call assert_fails("echo taglist('a')", "E987:") + " Using Vim9 lambda expression in legacy context should fail + " set tagfunc=(a,\ b,\ c)\ =>\ g:MytagFunc1(21,\ a,\ b,\ c) + new | only + let g:MytagFunc1_args = [] + " call assert_fails("tag a17", "E117:") + call assert_equal([], g:MytagFunc1_args) + + " set 'tagfunc' to a non-existing function + call assert_fails("set tagfunc=function('NonExistingFunc')", 'E700:') + call assert_fails("let &tagfunc = function('NonExistingFunc')", 'E700:') + call assert_fails("tag axb123", 'E426:') + bw! + " Vim9 tests let lines =<< trim END vim9script # Test for using function() - def MytagFunc1(pat: string, flags: string, info: dict): any - g:MytagFunc1_args = [pat, flags, info] + def Vim9tagFunc(val: number, pat: string, flags: string, info: dict): any + g:Vim9tagFuncArgs = [val, pat, flags, info] return null enddef - set tagfunc=function('MytagFunc1') + set tagfunc=function('Vim9tagFunc',\ [60]) new | only - g:MytagFunc1_args = [] + g:Vim9tagFuncArgs = [] assert_fails('tag a10', 'E433:') - assert_equal(['a10', '', {}], g:MytagFunc1_args) + assert_equal([60, 'a10', '', {}], g:Vim9tagFuncArgs) # Test for using a lambda - def MytagFunc2(pat: string, flags: string, info: dict): any - g:MytagFunc2_args = [pat, flags, info] - return null - enddef - &tagfunc = (a, b, c) => MytagFunc2(a, b, c) + &tagfunc = (a, b, c) => MytagFunc1(61, a, b, c) new | only - g:MytagFunc2_args = [] + g:MytagFunc1_args = [] assert_fails('tag a20', 'E433:') - assert_equal(['a20', '', {}], g:MytagFunc2_args) + assert_equal([61, 'a20', '', {}], g:MytagFunc1_args) # Test for using a string(lambda) - &tagfunc = '(a, b, c) => MytagFunc2(a, b, c)' + &tagfunc = '(a, b, c) => MytagFunc1(62, a, b, c)' new | only - g:MytagFunc2_args = [] + g:MytagFunc1_args = [] assert_fails('tag a20', 'E433:') - assert_equal(['a20', '', {}], g:MytagFunc2_args) + assert_equal([62, 'a20', '', {}], g:MytagFunc1_args) # Test for using a variable with a lambda expression - var Fn: func = (a, b, c) => MytagFunc2(a, b, c) + var Fn: func = (a, b, c) => MytagFunc1(63, a, b, c) &tagfunc = Fn new | only - g:MytagFunc2_args = [] + g:MytagFunc1_args = [] assert_fails('tag a30', 'E433:') - assert_equal(['a30', '', {}], g:MytagFunc2_args) + assert_equal([63, 'a30', '', {}], g:MytagFunc1_args) # Test for using a variable with a lambda expression + Fn = (a, b, c) => MytagFunc1(64, a, b, c) &tagfunc = string(Fn) new | only - g:MytagFunc2_args = [] + g:MytagFunc1_args = [] assert_fails('tag a30', 'E433:') - assert_equal(['a30', '', {}], g:MytagFunc2_args) + assert_equal([64, 'a30', '', {}], g:MytagFunc1_args) END " call CheckScriptSuccess(lines) - " Using Vim9 lambda expression in legacy context should fail - " set tagfunc=(a,\ b,\ c)\ =>\ g:MytagFunc2(a,\ b,\ c) - " new | only - " let g:MytagFunc3_args = [] - " call assert_fails("tag a17", "E117:") - " call assert_equal([], g:MytagFunc3_args) - - " set 'tagfunc' to a non-existing function - call assert_fails("set tagfunc=function('NonExistingFunc')", 'E700:') - call assert_fails("let &tagfunc = function('NonExistingFunc')", 'E700:') - call assert_fails("tag axb123", 'E426:') - " cleanup delfunc MytagFunc1 delfunc MytagFunc2 - delfunc MytagFunc3 set tagfunc& %bw! endfunc -- cgit From c00d241981f292a6529242bb98ed16cfc8c53ae4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 7 Nov 2022 13:37:22 +0800 Subject: vim-patch:8.2.3788: lambda for option that is a function may be freed Problem: Lambda for option that is a function may be garbage collected. Solution: Set a reference in the funcref. (Yegappan Lakshmanan, closes vim/vim#9330) https://github.com/vim/vim/commit/6ae8fae8696623b527c7fb22567f6a3705b2f0dd Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_ins_complete.vim | 960 ++++++++++++++++----------------- src/nvim/testdir/test_normal.vim | 249 +++++---- src/nvim/testdir/test_quickfix.vim | 126 +++++ src/nvim/testdir/test_tagfunc.vim | 266 +++++---- src/nvim/testdir/vim9.vim | 80 +++ 5 files changed, 923 insertions(+), 758 deletions(-) create mode 100644 src/nvim/testdir/vim9.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_ins_complete.vim b/src/nvim/testdir/test_ins_complete.vim index eaac66dae0..db2bb2e2a0 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -1,5 +1,8 @@ +" Test for insert completion + source screendump.vim source check.vim +source vim9.vim " Test for insert expansion func Test_ins_complete() @@ -1292,154 +1295,179 @@ func Test_completefunc_callback() return a:findstart ? 0 : [] endfunc - " Test for using a function() - set completefunc=function('MycompleteFunc1',[10]) - new | only - call setline(1, 'one') - let g:MycompleteFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MycompleteFunc1_args) - bw! + let lines =<< trim END + #" Test for using a function() + set completefunc=function('g:MycompleteFunc1',\ [10]) + new | only + call setline(1, 'one') + LET g:MycompleteFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MycompleteFunc1_args) + bw! - " Using a funcref variable to set 'completefunc' - let Fn = function('MycompleteFunc1', [11]) - let &completefunc = Fn - new | only - call setline(1, 'two') - let g:MycompleteFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MycompleteFunc1_args) - bw! + #" Using a funcref variable to set 'completefunc' + VAR Fn = function('g:MycompleteFunc1', [11]) + LET &completefunc = Fn + new | only + call setline(1, 'two') + LET g:MycompleteFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MycompleteFunc1_args) + bw! - " Using string(funcref_variable) to set 'completefunc' - let Fn = function('MycompleteFunc1', [12]) - let &completefunc = string(Fn) - new | only - call setline(1, 'two') - let g:MycompleteFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MycompleteFunc1_args) - bw! + #" Using string(funcref_variable) to set 'completefunc' + LET Fn = function('g:MycompleteFunc1', [12]) + LET &completefunc = string(Fn) + new | only + call setline(1, 'two') + LET g:MycompleteFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MycompleteFunc1_args) + bw! - " Test for using a funcref() - set completefunc=funcref('MycompleteFunc1',\ [13]) - new | only - call setline(1, 'three') - let g:MycompleteFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MycompleteFunc1_args) - bw! + #" Test for using a funcref() + set completefunc=funcref('g:MycompleteFunc1',\ [13]) + new | only + call setline(1, 'three') + LET g:MycompleteFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MycompleteFunc1_args) + bw! - " Using a funcref variable to set 'completefunc' - let Fn = funcref('MycompleteFunc1', [14]) - let &completefunc = Fn - new | only - call setline(1, 'four') - let g:MycompleteFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MycompleteFunc1_args) - bw! + #" Using a funcref variable to set 'completefunc' + LET Fn = funcref('g:MycompleteFunc1', [14]) + LET &completefunc = Fn + new | only + call setline(1, 'four') + LET g:MycompleteFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MycompleteFunc1_args) + bw! - " Using a string(funcref_variable) to set 'completefunc' - let Fn = funcref('MycompleteFunc1', [15]) - let &completefunc = string(Fn) - new | only - call setline(1, 'four') - let g:MycompleteFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MycompleteFunc1_args) - bw! + #" Using a string(funcref_variable) to set 'completefunc' + LET Fn = funcref('g:MycompleteFunc1', [15]) + LET &completefunc = string(Fn) + new | only + call setline(1, 'four') + LET g:MycompleteFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MycompleteFunc1_args) + bw! - " Test for using a lambda function - set completefunc={a,\ b\ ->\ MycompleteFunc1(16,\ a,\ b)} - new | only - call setline(1, 'five') - let g:MycompleteFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MycompleteFunc1_args) - bw! + #" Test for using a lambda function with set + VAR optval = "LSTART a, b LMIDDLE MycompleteFunc1(16, a, b) LEND" + LET optval = substitute(optval, ' ', '\\ ', 'g') + exe "set completefunc=" .. optval + new | only + call setline(1, 'five') + LET g:MycompleteFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MycompleteFunc1_args) + bw! - " Set 'completefunc' to a lambda expression - let &completefunc = {a, b -> MycompleteFunc1(17, a, b)} - new | only - call setline(1, 'six') - let g:MycompleteFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MycompleteFunc1_args) - bw! + #" Set 'completefunc' to a lambda expression + LET &completefunc = LSTART a, b LMIDDLE MycompleteFunc1(17, a, b) LEND + new | only + call setline(1, 'six') + LET g:MycompleteFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MycompleteFunc1_args) + bw! - " Set 'completefunc' to string(lambda_expression) - let &completefunc = '{a, b -> MycompleteFunc1(18, a, b)}' - new | only - call setline(1, 'six') - let g:MycompleteFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MycompleteFunc1_args) - bw! + #" Set 'completefunc' to string(lambda_expression) + LET &completefunc = 'LSTART a, b LMIDDLE MycompleteFunc1(18, a, b) LEND' + new | only + call setline(1, 'six') + LET g:MycompleteFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MycompleteFunc1_args) + bw! - " Set 'completefunc' to a variable with a lambda expression - let Lambda = {a, b -> MycompleteFunc1(19, a, b)} - let &completefunc = Lambda - new | only - call setline(1, 'seven') - let g:MycompleteFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MycompleteFunc1_args) - bw! + #" Set 'completefunc' to a variable with a lambda expression + VAR Lambda = LSTART a, b LMIDDLE MycompleteFunc1(19, a, b) LEND + LET &completefunc = Lambda + new | only + call setline(1, 'seven') + LET g:MycompleteFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MycompleteFunc1_args) + bw! - " Set 'completefunc' to a string(variable with a lambda expression) - let Lambda = {a, b -> MycompleteFunc1(20, a, b)} - let &completefunc = string(Lambda) - new | only - call setline(1, 'seven') - let g:MycompleteFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MycompleteFunc1_args) - bw! + #" Set 'completefunc' to a string(variable with a lambda expression) + LET Lambda = LSTART a, b LMIDDLE MycompleteFunc1(20, a, b) LEND + LET &completefunc = string(Lambda) + new | only + call setline(1, 'seven') + LET g:MycompleteFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MycompleteFunc1_args) + bw! - " Test for using a lambda function with incorrect return value - let Lambda = {s -> strlen(s)} - let &completefunc = Lambda - new | only - call setline(1, 'eight') - call feedkeys("A\\\", 'x') - bw! + #" Test for using a lambda function with incorrect return value + LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND + LET &completefunc = Lambda + new | only + call setline(1, 'eight') + call feedkeys("A\\\", 'x') + bw! - " Test for clearing the 'completefunc' option - set completefunc='' - set completefunc& + #" Test for clearing the 'completefunc' option + set completefunc='' + set completefunc& + call assert_fails("set completefunc=function('abc')", "E700:") + call assert_fails("set completefunc=funcref('abc')", "E700:") + + #" set 'completefunc' to a non-existing function + func MycompleteFunc2(findstart, base) + call add(g:MycompleteFunc2_args, [a:findstart, a:base]) + return a:findstart ? 0 : [] + endfunc + set completefunc=MycompleteFunc2 + call setline(1, 'five') + call assert_fails("set completefunc=function('NonExistingFunc')", 'E700:') + call assert_fails("LET &completefunc = function('NonExistingFunc')", 'E700:') + LET g:MycompleteFunc2_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'five']], g:MycompleteFunc2_args) + bw! + END + call CheckLegacyAndVim9Success(lines) - call assert_fails("set completefunc=function('abc')", "E700:") - call assert_fails("set completefunc=funcref('abc')", "E700:") let &completefunc = {a -> 'abc'} call feedkeys("A\\\", 'x') " Using Vim9 lambda expression in legacy context should fail - " set completefunc=(a,\ b)\ =>\ g:MycompleteFunc1(21,\ a,\ b) + " set completefunc=(a,\ b)\ =>\ MycompleteFunc1(21,\ a,\ b) new | only let g:MycompleteFunc1_args = [] " call assert_fails('call feedkeys("A\\\", "x")', 'E117:') call assert_equal([], g:MycompleteFunc1_args) - " set 'completefunc' to a non-existing function - func MycompleteFunc2(findstart, base) - call add(g:MycompleteFunc2_args, [a:findstart, a:base]) - return a:findstart ? 0 : [] + " set 'completefunc' to a partial with dict. This used to cause a crash. + func SetCompleteFunc() + let params = {'complete': function('g:DictCompleteFunc')} + let &completefunc = params.complete endfunc - set completefunc=MycompleteFunc2 - call setline(1, 'five') - call assert_fails("set completefunc=function('NonExistingFunc')", 'E700:') - call assert_fails("let &completefunc = function('NonExistingFunc')", 'E700:') - let g:MycompleteFunc2_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'five']], g:MycompleteFunc2_args) - bw! + func g:DictCompleteFunc(_) dict + endfunc + call SetCompleteFunc() + new + call SetCompleteFunc() + bw + call test_garbagecollect_now() + new + set completefunc= + wincmd w + set completefunc= + %bw! + delfunc g:DictCompleteFunc + delfunc SetCompleteFunc " Vim9 tests let lines =<< trim END vim9script - # Test for using function() + # Test for using a def function with completefunc def Vim9CompleteFunc(val: number, findstart: number, base: string): any add(g:Vim9completeFuncArgs, [val, findstart, base]) return findstart ? 0 : [] @@ -1451,44 +1479,6 @@ func Test_completefunc_callback() feedkeys("A\\\", 'x') assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9completeFuncArgs) bw! - - # Test for using a lambda - &completefunc = (a, b) => Vim9CompleteFunc(61, a, b) - new | only - setline(1, 'two') - g:Vim9completeFuncArgs = [] - feedkeys("A\\\", 'x') - assert_equal([[61, 1, ''], [61, 0, 'two']], g:Vim9completeFuncArgs) - bw! - - # Test for using a string(lambda) - &completefunc = '(a, b) => Vim9CompleteFunc(62, a, b)' - new | only - setline(1, 'two') - g:Vim9completeFuncArgs = [] - feedkeys("A\\\", 'x') - assert_equal([[62, 1, ''], [62, 0, 'two']], g:Vim9completeFuncArgs) - bw! - - # Test for using a variable with a lambda expression - var Fn: func = (a, b) => Vim9CompleteFunc(63, a, b) - &completefunc = Fn - new | only - setline(1, 'three') - g:Vim9completeFuncArgs = [] - feedkeys("A\\\", 'x') - assert_equal([[63, 1, ''], [63, 0, 'three']], g:Vim9completeFuncArgs) - bw! - - # Test for using a string(variable with a lambda expression) - Fn = (a, b) => Vim9CompleteFunc(64, a, b) - &completefunc = string(Fn) - new | only - setline(1, 'three') - g:Vim9completeFuncArgs = [] - feedkeys("A\\\", 'x') - assert_equal([[64, 1, ''], [64, 0, 'three']], g:Vim9completeFuncArgs) - bw! END " call CheckScriptSuccess(lines) @@ -1506,154 +1496,179 @@ func Test_omnifunc_callback() return a:findstart ? 0 : [] endfunc - " Test for using a function() - set omnifunc=function('MyomniFunc1',[10]) - new | only - call setline(1, 'one') - let g:MyomniFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MyomniFunc1_args) - bw! + let lines =<< trim END + #" Test for using a function() + set omnifunc=function('g:MyomniFunc1',\ [10]) + new | only + call setline(1, 'one') + LET g:MyomniFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MyomniFunc1_args) + bw! - " Using a funcref variable to set 'omnifunc' - let Fn = function('MyomniFunc1', [11]) - let &omnifunc = Fn - new | only - call setline(1, 'two') - let g:MyomniFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MyomniFunc1_args) - bw! + #" Using a funcref variable to set 'omnifunc' + VAR Fn = function('g:MyomniFunc1', [11]) + LET &omnifunc = Fn + new | only + call setline(1, 'two') + LET g:MyomniFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MyomniFunc1_args) + bw! - " Using a string(funcref_variable) to set 'omnifunc' - let Fn = function('MyomniFunc1', [12]) - let &omnifunc = string(Fn) - new | only - call setline(1, 'two') - let g:MyomniFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MyomniFunc1_args) - bw! + #" Using a string(funcref_variable) to set 'omnifunc' + LET Fn = function('g:MyomniFunc1', [12]) + LET &omnifunc = string(Fn) + new | only + call setline(1, 'two') + LET g:MyomniFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MyomniFunc1_args) + bw! - " Test for using a funcref() - set omnifunc=funcref('MyomniFunc1',\ [13]) - new | only - call setline(1, 'three') - let g:MyomniFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MyomniFunc1_args) - bw! + #" Test for using a funcref() + set omnifunc=funcref('g:MyomniFunc1',\ [13]) + new | only + call setline(1, 'three') + LET g:MyomniFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MyomniFunc1_args) + bw! - " Using a funcref variable to set 'omnifunc' - let Fn = funcref('MyomniFunc1', [14]) - let &omnifunc = Fn - new | only - call setline(1, 'four') - let g:MyomniFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MyomniFunc1_args) - bw! + #" Use let to set 'omnifunc' to a funcref + LET Fn = funcref('g:MyomniFunc1', [14]) + LET &omnifunc = Fn + new | only + call setline(1, 'four') + LET g:MyomniFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MyomniFunc1_args) + bw! - " Using a string(funcref_variable) to set 'omnifunc' - let Fn = funcref('MyomniFunc1', [15]) - let &omnifunc = string(Fn) - new | only - call setline(1, 'four') - let g:MyomniFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MyomniFunc1_args) - bw! + #" Using a string(funcref) to set 'omnifunc' + LET Fn = funcref("g:MyomniFunc1", [15]) + LET &omnifunc = string(Fn) + new | only + call setline(1, 'four') + LET g:MyomniFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MyomniFunc1_args) + bw! - " Test for using a lambda function - set omnifunc={a,\ b\ ->\ MyomniFunc1(16,\ a,\ b)} - new | only - call setline(1, 'five') - let g:MyomniFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MyomniFunc1_args) - bw! + #" Test for using a lambda function with set + VAR optval = "LSTART a, b LMIDDLE MyomniFunc1(16, a, b) LEND" + LET optval = substitute(optval, ' ', '\\ ', 'g') + exe "set omnifunc=" .. optval + new | only + call setline(1, 'five') + LET g:MyomniFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MyomniFunc1_args) + bw! - " Set 'omnifunc' to a lambda expression - let &omnifunc = {a, b -> MyomniFunc1(17, a, b)} - new | only - call setline(1, 'six') - let g:MyomniFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MyomniFunc1_args) - bw! + #" Set 'omnifunc' to a lambda expression + LET &omnifunc = LSTART a, b LMIDDLE MyomniFunc1(17, a, b) LEND + new | only + call setline(1, 'six') + LET g:MyomniFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MyomniFunc1_args) + bw! - " Set 'omnifunc' to a string(lambda_expression) - let &omnifunc = '{a, b -> MyomniFunc1(18, a, b)}' - new | only - call setline(1, 'six') - let g:MyomniFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MyomniFunc1_args) - bw! + #" Set 'omnifunc' to a string(lambda_expression) + LET &omnifunc = 'LSTART a, b LMIDDLE MyomniFunc1(18, a, b) LEND' + new | only + call setline(1, 'six') + LET g:MyomniFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MyomniFunc1_args) + bw! - " Set 'omnifunc' to a variable with a lambda expression - let Lambda = {a, b -> MyomniFunc1(19, a, b)} - let &omnifunc = Lambda - new | only - call setline(1, 'seven') - let g:MyomniFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MyomniFunc1_args) - bw! + #" Set 'omnifunc' to a variable with a lambda expression + VAR Lambda = LSTART a, b LMIDDLE MyomniFunc1(19, a, b) LEND + LET &omnifunc = Lambda + new | only + call setline(1, 'seven') + LET g:MyomniFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MyomniFunc1_args) + bw! - " Set 'omnifunc' to a string(variable with a lambda expression) - let Lambda = {a, b -> MyomniFunc1(20, a, b)} - let &omnifunc = string(Lambda) - new | only - call setline(1, 'seven') - let g:MyomniFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MyomniFunc1_args) - bw! + #" Set 'omnifunc' to a string(variable with a lambda expression) + LET Lambda = LSTART a, b LMIDDLE MyomniFunc1(20, a, b) LEND + LET &omnifunc = string(Lambda) + new | only + call setline(1, 'seven') + LET g:MyomniFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MyomniFunc1_args) + bw! - " Test for using a lambda function with incorrect return value - let Lambda = {s -> strlen(s)} - let &omnifunc = Lambda - new | only - call setline(1, 'eight') - call feedkeys("A\\\", 'x') - bw! + #" Test for using a lambda function with incorrect return value + LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND + LET &omnifunc = Lambda + new | only + call setline(1, 'eight') + call feedkeys("A\\\", 'x') + bw! - " Test for clearing the 'omnifunc' option - set omnifunc='' - set omnifunc& + #" Test for clearing the 'omnifunc' option + set omnifunc='' + set omnifunc& + call assert_fails("set omnifunc=function('abc')", "E700:") + call assert_fails("set omnifunc=funcref('abc')", "E700:") + + #" set 'omnifunc' to a non-existing function + func MyomniFunc2(findstart, base) + call add(g:MyomniFunc2_args, [a:findstart, a:base]) + return a:findstart ? 0 : [] + endfunc + set omnifunc=MyomniFunc2 + call setline(1, 'nine') + call assert_fails("set omnifunc=function('NonExistingFunc')", 'E700:') + call assert_fails("LET &omnifunc = function('NonExistingFunc')", 'E700:') + LET g:MyomniFunc2_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'nine']], g:MyomniFunc2_args) + bw! + END + call CheckLegacyAndVim9Success(lines) - call assert_fails("set omnifunc=function('abc')", "E700:") - call assert_fails("set omnifunc=funcref('abc')", "E700:") let &omnifunc = {a -> 'abc'} call feedkeys("A\\\", 'x') " Using Vim9 lambda expression in legacy context should fail - " set omnifunc=(a,\ b)\ =>\ g:MyomniFunc1(21,\ a,\ b) + " set omnifunc=(a,\ b)\ =>\ MyomniFunc1(21,\ a,\ b) new | only let g:MyomniFunc1_args = [] " call assert_fails('call feedkeys("A\\\", "x")', 'E117:') call assert_equal([], g:MyomniFunc1_args) - " set 'omnifunc' to a non-existing function - func MyomniFunc2(findstart, base) - call add(g:MyomniFunc2_args, [a:findstart, a:base]) - return a:findstart ? 0 : [] + " set 'omnifunc' to a partial with dict. This used to cause a crash. + func SetOmniFunc() + let params = {'omni': function('g:DictOmniFunc')} + let &omnifunc = params.omni endfunc - set omnifunc=MyomniFunc2 - call setline(1, 'nine') - call assert_fails("set omnifunc=function('NonExistingFunc')", 'E700:') - call assert_fails("let &omnifunc = function('NonExistingFunc')", 'E700:') - let g:MyomniFunc2_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'nine']], g:MyomniFunc2_args) - bw! + func g:DictOmniFunc(_) dict + endfunc + call SetOmniFunc() + new + call SetOmniFunc() + bw + call test_garbagecollect_now() + new + set omnifunc= + wincmd w + set omnifunc= + %bw! + delfunc g:DictOmniFunc + delfunc SetOmniFunc " Vim9 tests let lines =<< trim END vim9script - # Test for using function() + # Test for using a def function with omnifunc def Vim9omniFunc(val: number, findstart: number, base: string): any add(g:Vim9omniFunc_Args, [val, findstart, base]) return findstart ? 0 : [] @@ -1665,44 +1680,6 @@ func Test_omnifunc_callback() feedkeys("A\\\", 'x') assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9omniFunc_Args) bw! - - # Test for using a lambda - &omnifunc = (a, b) => Vim9omniFunc(61, a, b) - new | only - setline(1, 'two') - g:Vim9omniFunc_Args = [] - feedkeys("A\\\", 'x') - assert_equal([[61, 1, ''], [61, 0, 'two']], g:Vim9omniFunc_Args) - bw! - - # Test for using a string(lambda) - &omnifunc = '(a, b) => Vim9omniFunc(62, a, b)' - new | only - setline(1, 'two') - g:Vim9omniFunc_Args = [] - feedkeys("A\\\", 'x') - assert_equal([[62, 1, ''], [62, 0, 'two']], g:Vim9omniFunc_Args) - bw! - - # Test for using a variable with a lambda expression - var Fn: func = (a, b) => Vim9omniFunc(63, a, b) - &omnifunc = Fn - new | only - setline(1, 'three') - g:Vim9omniFunc_Args = [] - feedkeys("A\\\", 'x') - assert_equal([[63, 1, ''], [63, 0, 'three']], g:Vim9omniFunc_Args) - bw! - - # Test for using a string(variable with a lambda expression) - Fn = (a, b) => Vim9omniFunc(64, a, b) - &omnifunc = string(Fn) - new | only - setline(1, 'three') - g:Vim9omniFunc_Args = [] - feedkeys("A\\\", 'x') - assert_equal([[64, 1, ''], [64, 0, 'three']], g:Vim9omniFunc_Args) - bw! END " call CheckScriptSuccess(lines) @@ -1720,178 +1697,215 @@ func Test_thesaurusfunc_callback() return a:findstart ? 0 : [] endfunc - " Test for using a function() - set thesaurusfunc=function('MytsrFunc1',[10]) - new | only - call setline(1, 'one') - let g:MytsrFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MytsrFunc1_args) - bw! + let lines =<< trim END + #" Test for using a function() + set thesaurusfunc=function('g:MytsrFunc1',\ [10]) + new | only + call setline(1, 'one') + LET g:MytsrFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MytsrFunc1_args) + bw! - " Using a funcref variable to set 'thesaurusfunc' - let Fn = function('MytsrFunc1', [11]) - let &thesaurusfunc = Fn - new | only - call setline(1, 'two') - let g:MytsrFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MytsrFunc1_args) - bw! + #" Using a funcref variable to set 'thesaurusfunc' + VAR Fn = function('g:MytsrFunc1', [11]) + LET &thesaurusfunc = Fn + new | only + call setline(1, 'two') + LET g:MytsrFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MytsrFunc1_args) + bw! - " Using a string(funcref_variable) to set 'thesaurusfunc' - let Fn = function('MytsrFunc1', [12]) - let &thesaurusfunc = string(Fn) - new | only - call setline(1, 'two') - let g:MytsrFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MytsrFunc1_args) - bw! + #" Using a string(funcref_variable) to set 'thesaurusfunc' + LET Fn = function('g:MytsrFunc1', [12]) + LET &thesaurusfunc = string(Fn) + new | only + call setline(1, 'two') + LET g:MytsrFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MytsrFunc1_args) + bw! - " Test for using a funcref() - set thesaurusfunc=funcref('MytsrFunc1',[13]) - new | only - call setline(1, 'three') - let g:MytsrFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MytsrFunc1_args) - bw! + #" Test for using a funcref() + set thesaurusfunc=funcref('g:MytsrFunc1',\ [13]) + new | only + call setline(1, 'three') + LET g:MytsrFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MytsrFunc1_args) + bw! - " Using a funcref variable to set 'thesaurusfunc' - let Fn = funcref('MytsrFunc1', [14]) - let &thesaurusfunc = Fn - new | only - call setline(1, 'four') - let g:MytsrFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MytsrFunc1_args) - bw! + #" Using a funcref variable to set 'thesaurusfunc' + LET Fn = funcref('g:MytsrFunc1', [14]) + LET &thesaurusfunc = Fn + new | only + call setline(1, 'four') + LET g:MytsrFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MytsrFunc1_args) + bw! - " Using a string(funcref_variable) to set 'thesaurusfunc' - let Fn = funcref('MytsrFunc1', [15]) - let &thesaurusfunc = string(Fn) - new | only - call setline(1, 'four') - let g:MytsrFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MytsrFunc1_args) - bw! + #" Using a string(funcref_variable) to set 'thesaurusfunc' + LET Fn = funcref('g:MytsrFunc1', [15]) + LET &thesaurusfunc = string(Fn) + new | only + call setline(1, 'four') + LET g:MytsrFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MytsrFunc1_args) + bw! - " Test for using a lambda function - set thesaurusfunc={a,\ b\ ->\ MytsrFunc1(16,\ a,\ b)} - new | only - call setline(1, 'five') - let g:MytsrFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MytsrFunc1_args) - bw! + #" Test for using a lambda function + VAR optval = "LSTART a, b LMIDDLE MytsrFunc1(16, a, b) LEND" + LET optval = substitute(optval, ' ', '\\ ', 'g') + exe "set thesaurusfunc=" .. optval + new | only + call setline(1, 'five') + LET g:MytsrFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MytsrFunc1_args) + bw! - " Set 'thesaurusfunc' to a lambda expression - let &thesaurusfunc = {a, b -> MytsrFunc1(17, a, b)} - new | only - call setline(1, 'six') - let g:MytsrFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MytsrFunc1_args) - bw! + #" Test for using a lambda function with set + LET &thesaurusfunc = LSTART a, b LMIDDLE MytsrFunc1(17, a, b) LEND + new | only + call setline(1, 'six') + LET g:MytsrFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MytsrFunc1_args) + bw! - " Set 'thesaurusfunc' to a string(lambda expression) - let &thesaurusfunc = '{a, b -> MytsrFunc1(18, a, b)}' - new | only - call setline(1, 'six') - let g:MytsrFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MytsrFunc1_args) - bw! + #" Set 'thesaurusfunc' to a string(lambda expression) + LET &thesaurusfunc = 'LSTART a, b LMIDDLE MytsrFunc1(18, a, b) LEND' + new | only + call setline(1, 'six') + LET g:MytsrFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MytsrFunc1_args) + bw! - " Set 'thesaurusfunc' to a variable with a lambda expression - let Lambda = {a, b -> MytsrFunc1(19, a, b)} - let &thesaurusfunc = Lambda - new | only - call setline(1, 'seven') - let g:MytsrFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MytsrFunc1_args) - bw! + #" Set 'thesaurusfunc' to a variable with a lambda expression + VAR Lambda = LSTART a, b LMIDDLE MytsrFunc1(19, a, b) LEND + LET &thesaurusfunc = Lambda + new | only + call setline(1, 'seven') + LET g:MytsrFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MytsrFunc1_args) + bw! - " Set 'thesaurusfunc' to a string(variable with a lambda expression) - let Lambda = {a, b -> MytsrFunc1(20, a, b)} - let &thesaurusfunc = string(Lambda) - new | only - call setline(1, 'seven') - let g:MytsrFunc1_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MytsrFunc1_args) - bw! + #" Set 'thesaurusfunc' to a string(variable with a lambda expression) + LET Lambda = LSTART a, b LMIDDLE MytsrFunc1(20, a, b) LEND + LET &thesaurusfunc = string(Lambda) + new | only + call setline(1, 'seven') + LET g:MytsrFunc1_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MytsrFunc1_args) + bw! - " Test for using a lambda function with incorrect return value - let Lambda = {s -> strlen(s)} - let &thesaurusfunc = Lambda - new | only - call setline(1, 'eight') - call feedkeys("A\\\", 'x') - bw! + #" Test for using a lambda function with incorrect return value + LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND + LET &thesaurusfunc = Lambda + new | only + call setline(1, 'eight') + call feedkeys("A\\\", 'x') + bw! - " Test for clearing the 'thesaurusfunc' option - set thesaurusfunc='' - set thesaurusfunc& + #" Test for clearing the 'thesaurusfunc' option + set thesaurusfunc='' + set thesaurusfunc& + call assert_fails("set thesaurusfunc=function('abc')", "E700:") + call assert_fails("set thesaurusfunc=funcref('abc')", "E700:") + + #" set 'thesaurusfunc' to a non-existing function + func MytsrFunc2(findstart, base) + call add(g:MytsrFunc2_args, [a:findstart, a:base]) + return a:findstart ? 0 : ['sunday'] + endfunc + set thesaurusfunc=MytsrFunc2 + call setline(1, 'ten') + call assert_fails("set thesaurusfunc=function('NonExistingFunc')", 'E700:') + call assert_fails("LET &thesaurusfunc = function('NonExistingFunc')", 'E700:') + LET g:MytsrFunc2_args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'ten']], g:MytsrFunc2_args) + bw! + + #" Use a buffer-local value and a global value + set thesaurusfunc& + setlocal thesaurusfunc=function('g:MytsrFunc1',\ [22]) + call setline(1, 'sun') + LET g:MytsrFunc1_args = [] + call feedkeys("A\\\", "x") + call assert_equal('sun', getline(1)) + call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:MytsrFunc1_args) + new + call setline(1, 'sun') + LET g:MytsrFunc1_args = [] + call feedkeys("A\\\", "x") + call assert_equal('sun', getline(1)) + call assert_equal([], g:MytsrFunc1_args) + set thesaurusfunc=function('g:MytsrFunc1',\ [23]) + wincmd w + call setline(1, 'sun') + LET g:MytsrFunc1_args = [] + call feedkeys("A\\\", "x") + call assert_equal('sun', getline(1)) + call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:MytsrFunc1_args) + :%bw! + END + call CheckLegacyAndVim9Success(lines) - call assert_fails("set thesaurusfunc=function('abc')", "E700:") - call assert_fails("set thesaurusfunc=funcref('abc')", "E700:") let &thesaurusfunc = {a -> 'abc'} call feedkeys("A\\\", 'x') " Using Vim9 lambda expression in legacy context should fail - " set thesaurusfunc=(a,\ b)\ =>\ g:MytsrFunc1(21,\ a,\ b) + " set thesaurusfunc=(a,\ b)\ =>\ MytsrFunc1(21,\ a,\ b) new | only let g:MytsrFunc1_args = [] " call assert_fails('call feedkeys("A\\\", "x")', 'E117:') call assert_equal([], g:MytsrFunc1_args) bw! - " Use a buffer-local value and a global value - set thesaurusfunc& - setlocal thesaurusfunc=function('MytsrFunc1',[22]) - call setline(1, 'sun') - let g:MytsrFunc1_args = [] - call feedkeys("A\\\", "x") - call assert_equal('sun', getline(1)) - call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:MytsrFunc1_args) + " set 'thesaurusfunc' to a partial with dict. This used to cause a crash. + func SetTsrFunc() + let params = {'thesaurus': function('g:DictTsrFunc')} + let &thesaurusfunc = params.thesaurus + endfunc + func g:DictTsrFunc(_) dict + endfunc + call SetTsrFunc() new - call setline(1, 'sun') - let g:MytsrFunc1_args = [] - call feedkeys("A\\\", "x") - call assert_equal('sun', getline(1)) - call assert_equal([], g:MytsrFunc1_args) - set thesaurusfunc=function('MytsrFunc1',[23]) + call SetTsrFunc() + bw + call test_garbagecollect_now() + new + set thesaurusfunc= wincmd w - call setline(1, 'sun') - let g:MytsrFunc1_args = [] - call feedkeys("A\\\", "x") - call assert_equal('sun', getline(1)) - call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:MytsrFunc1_args) %bw! + delfunc SetTsrFunc - " set 'thesaurusfunc' to a non-existing function - func MytsrFunc2(findstart, base) - call add(g:MytsrFunc2_args, [a:findstart, a:base]) - return a:findstart ? 0 : ['sunday'] + " set buffer-local 'thesaurusfunc' to a partial with dict. This used to + " cause a crash. + func SetLocalTsrFunc() + let params = {'thesaurus': function('g:DictTsrFunc')} + let &l:thesaurusfunc = params.thesaurus endfunc - set thesaurusfunc=MytsrFunc2 - call setline(1, 'ten') - call assert_fails("set thesaurusfunc=function('NonExistingFunc')", 'E700:') - call assert_fails("let &thesaurusfunc = function('NonExistingFunc')", 'E700:') - let g:MytsrFunc2_args = [] - call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'ten']], g:MytsrFunc2_args) + call SetLocalTsrFunc() + call test_garbagecollect_now() + call SetLocalTsrFunc() + set thesaurusfunc= bw! + delfunc g:DictTsrFunc + delfunc SetLocalTsrFunc " Vim9 tests let lines =<< trim END vim9script - # Test for using function() + # Test for using a def function with thesaurusfunc def Vim9tsrFunc(val: number, findstart: number, base: string): any add(g:Vim9tsrFunc_Args, [val, findstart, base]) return findstart ? 0 : [] @@ -1903,44 +1917,6 @@ func Test_thesaurusfunc_callback() feedkeys("A\\\", 'x') assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9tsrFunc_Args) bw! - - # Test for using a lambda - &thesaurusfunc = (a, b) => Vim9tsrFunc(61, a, b) - new | only - setline(1, 'two') - g:Vim9tsrFunc_Args = [] - feedkeys("A\\\", 'x') - assert_equal([[61, 1, ''], [61, 0, 'two']], g:Vim9tsrFunc_Args) - bw! - - # Test for using a string(lambda) - &thesaurusfunc = '(a, b) => Vim9tsrFunc(62, a, b)' - new | only - setline(1, 'two') - g:Vim9tsrFunc_Args = [] - feedkeys("A\\\", 'x') - assert_equal([[62, 1, ''], [62, 0, 'two']], g:Vim9tsrFunc_Args) - bw! - - # Test for using a variable with a lambda expression - var Fn: func = (a, b) => Vim9tsrFunc(63, a, b) - &thesaurusfunc = Fn - new | only - setline(1, 'three') - g:Vim9tsrFunc_Args = [] - feedkeys("A\\\", 'x') - assert_equal([[63, 1, ''], [63, 0, 'three']], g:Vim9tsrFunc_Args) - bw! - - # Test for using a string(variable with a lambda expression) - Fn = (a, b) => Vim9tsrFunc(64, a, b) - &thesaurusfunc = string(Fn) - new | only - setline(1, 'three') - g:Vim9tsrFunc_Args = [] - feedkeys("A\\\", 'x') - assert_equal([[64, 1, ''], [64, 0, 'three']], g:Vim9tsrFunc_Args) - bw! END " call CheckScriptSuccess(lines) diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index b9cc858cdb..b3e0be8f77 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -3,6 +3,7 @@ source shared.vim source check.vim source view_util.vim +source vim9.vim source screendump.vim func Setup_NewWindow() @@ -463,110 +464,122 @@ func Test_opfunc_callback() let g:OpFuncArgs = [a:val, a:type] endfunc - " Test for using a function() - set opfunc=function('MyopFunc',\ [11]) - let g:OpFuncArgs = [] - normal! g@l - call assert_equal([11, 'char'], g:OpFuncArgs) - - " Using a funcref variable to set 'operatorfunc' - let Fn = function('MyopFunc', [12]) - let &opfunc = Fn - let g:OpFuncArgs = [] - normal! g@l - call assert_equal([12, 'char'], g:OpFuncArgs) - - " Using a string(funcref_variable) to set 'operatorfunc' - let Fn = function('MyopFunc', [13]) - let &operatorfunc = string(Fn) - let g:OpFuncArgs = [] - normal! g@l - call assert_equal([13, 'char'], g:OpFuncArgs) - - " Test for using a funcref() - set operatorfunc=funcref('MyopFunc',\ [14]) - let g:OpFuncArgs = [] - normal! g@l - call assert_equal([14, 'char'], g:OpFuncArgs) - - " Using a funcref variable to set 'operatorfunc' - let Fn = funcref('MyopFunc', [15]) - let &opfunc = Fn - let g:OpFuncArgs = [] - normal! g@l - call assert_equal([15, 'char'], g:OpFuncArgs) - - " Using a string(funcref_variable) to set 'operatorfunc' - let Fn = funcref('MyopFunc', [16]) - let &opfunc = string(Fn) - let g:OpFuncArgs = [] - normal! g@l - call assert_equal([16, 'char'], g:OpFuncArgs) + let lines =<< trim END + #" Test for using a function() + set opfunc=function('g:MyopFunc',\ [10]) + LET g:OpFuncArgs = [] + normal! g@l + call assert_equal([10, 'char'], g:OpFuncArgs) - " Test for using a lambda function using set - set opfunc={a\ ->\ MyopFunc(17,\ a)} - let g:OpFuncArgs = [] - normal! g@l - call assert_equal([17, 'char'], g:OpFuncArgs) + #" Using a funcref variable to set 'operatorfunc' + VAR Fn = function('g:MyopFunc', [11]) + LET &opfunc = Fn + LET g:OpFuncArgs = [] + normal! g@l + call assert_equal([11, 'char'], g:OpFuncArgs) - " Test for using a lambda function using let - let &opfunc = {a -> MyopFunc(18, a)} - let g:OpFuncArgs = [] - normal! g@l - call assert_equal([18, 'char'], g:OpFuncArgs) + #" Using a string(funcref_variable) to set 'operatorfunc' + LET Fn = function('g:MyopFunc', [12]) + LET &operatorfunc = string(Fn) + LET g:OpFuncArgs = [] + normal! g@l + call assert_equal([12, 'char'], g:OpFuncArgs) - " Set 'operatorfunc' to a string(lambda expression) - let &opfunc = '{a -> MyopFunc(19, a)}' - let g:OpFuncArgs = [] - normal! g@l - call assert_equal([19, 'char'], g:OpFuncArgs) + #" Test for using a funcref() + set operatorfunc=funcref('g:MyopFunc',\ [13]) + LET g:OpFuncArgs = [] + normal! g@l + call assert_equal([13, 'char'], g:OpFuncArgs) - " Set 'operatorfunc' to a variable with a lambda expression - let Lambda = {a -> MyopFunc(20, a)} - let &opfunc = Lambda - let g:OpFuncArgs = [] - normal! g@l - call assert_equal([20, 'char'], g:OpFuncArgs) + #" Using a funcref variable to set 'operatorfunc' + LET Fn = funcref('g:MyopFunc', [14]) + LET &opfunc = Fn + LET g:OpFuncArgs = [] + normal! g@l + call assert_equal([14, 'char'], g:OpFuncArgs) - " Set 'operatorfunc' to a string(variable with a lambda expression) - let Lambda = {a -> MyopFunc(21, a)} - let &opfunc = string(Lambda) - let g:OpFuncArgs = [] - normal! g@l - call assert_equal([21, 'char'], g:OpFuncArgs) + #" Using a string(funcref_variable) to set 'operatorfunc' + LET Fn = funcref('g:MyopFunc', [15]) + LET &opfunc = string(Fn) + LET g:OpFuncArgs = [] + normal! g@l + call assert_equal([15, 'char'], g:OpFuncArgs) - " Try to use 'operatorfunc' after the function is deleted - func TmpOpFunc(type) - let g:OpFuncArgs = [22, a:type] - endfunc - let &opfunc = function('TmpOpFunc') - delfunc TmpOpFunc - call test_garbagecollect_now() - let g:OpFuncArgs = [] - call assert_fails('normal! g@l', 'E117:') - call assert_equal([], g:OpFuncArgs) + #" Test for using a lambda function using set + VAR optval = "LSTART a LMIDDLE MyopFunc(16, a) LEND" + LET optval = substitute(optval, ' ', '\\ ', 'g') + exe "set opfunc=" .. optval + LET g:OpFuncArgs = [] + normal! g@l + call assert_equal([16, 'char'], g:OpFuncArgs) - " Try to use a function with two arguments for 'operatorfunc' - func! MyopFunc2(x, y) - let g:OpFuncArgs = [a:x, a:y] - endfunc - set opfunc=MyopFunc2 - let g:OpFuncArgs = [] - call assert_fails('normal! g@l', 'E119:') - call assert_equal([], g:OpFuncArgs) + #" Test for using a lambda function using LET + LET &opfunc = LSTART a LMIDDLE MyopFunc(17, a) LEND + LET g:OpFuncArgs = [] + normal! g@l + call assert_equal([17, 'char'], g:OpFuncArgs) - " Try to use a lambda function with two arguments for 'operatorfunc' - let &opfunc = {a, b -> MyopFunc(23, b)} - let g:OpFuncArgs = [] - call assert_fails('normal! g@l', 'E119:') - call assert_equal([], g:OpFuncArgs) + #" Set 'operatorfunc' to a string(lambda expression) + LET &opfunc = 'LSTART a LMIDDLE MyopFunc(18, a) LEND' + LET g:OpFuncArgs = [] + normal! g@l + call assert_equal([18, 'char'], g:OpFuncArgs) - " Test for clearing the 'operatorfunc' option - set opfunc='' - set opfunc& + #" Set 'operatorfunc' to a variable with a lambda expression + VAR Lambda = LSTART a LMIDDLE MyopFunc(19, a) LEND + LET &opfunc = Lambda + LET g:OpFuncArgs = [] + normal! g@l + call assert_equal([19, 'char'], g:OpFuncArgs) - call assert_fails("set opfunc=function('abc')", "E700:") - call assert_fails("set opfunc=funcref('abc')", "E700:") + #" Set 'operatorfunc' to a string(variable with a lambda expression) + LET Lambda = LSTART a LMIDDLE MyopFunc(20, a) LEND + LET &opfunc = string(Lambda) + LET g:OpFuncArgs = [] + normal! g@l + call assert_equal([20, 'char'], g:OpFuncArgs) + + #" Try to use 'operatorfunc' after the function is deleted + func g:TmpOpFunc(type) + LET g:OpFuncArgs = [21, a:type] + endfunc + LET &opfunc = function('g:TmpOpFunc') + delfunc g:TmpOpFunc + call test_garbagecollect_now() + LET g:OpFuncArgs = [] + call assert_fails('normal! g@l', 'E117:') + call assert_equal([], g:OpFuncArgs) + + #" Try to use a function with two arguments for 'operatorfunc' + func MyopFunc2(x, y) + LET g:OpFuncArgs = [a:x, a:y] + endfunc + set opfunc=MyopFunc2 + LET g:OpFuncArgs = [] + call assert_fails('normal! g@l', 'E119:') + call assert_equal([], g:OpFuncArgs) + + #" Try to use a lambda function with two arguments for 'operatorfunc' + LET &opfunc = LSTART a, b LMIDDLE MyopFunc(22, b) LEND + LET g:OpFuncArgs = [] + call assert_fails('normal! g@l', 'E119:') + call assert_equal([], g:OpFuncArgs) + + #" Test for clearing the 'operatorfunc' option + set opfunc='' + set opfunc& + call assert_fails("set opfunc=function('abc')", "E700:") + call assert_fails("set opfunc=funcref('abc')", "E700:") + + #" set 'operatorfunc' to a non-existing function + LET &opfunc = function('g:MyopFunc', [23]) + call assert_fails("set opfunc=function('NonExistingFunc')", 'E700:') + call assert_fails("LET &opfunc = function('NonExistingFunc')", 'E700:') + LET g:OpFuncArgs = [] + normal! g@l + call assert_equal([23, 'char'], g:OpFuncArgs) + END + call CheckTransLegacySuccess(lines) " Using Vim9 lambda expression in legacy context should fail " set opfunc=(a)\ =>\ MyopFunc(24,\ a) @@ -574,19 +587,24 @@ func Test_opfunc_callback() " call assert_fails('normal! g@l', 'E117:') call assert_equal([], g:OpFuncArgs) - " set 'operatorfunc' to a non-existing function - let &opfunc = function('MyopFunc', [25]) - call assert_fails("set opfunc=function('NonExistingFunc')", 'E700:') - call assert_fails("let &opfunc = function('NonExistingFunc')", 'E700:') - let g:OpFuncArgs = [] - normal! g@l - call assert_equal([25, 'char'], g:OpFuncArgs) + " set 'operatorfunc' to a partial with dict. This used to cause a crash. + func SetOpFunc() + let operator = {'execute': function('OperatorExecute')} + let &opfunc = operator.execute + endfunc + func OperatorExecute(_) dict + endfunc + call SetOpFunc() + call test_garbagecollect_now() + set operatorfunc= + delfunc SetOpFunc + delfunc OperatorExecute " Vim9 tests let lines =<< trim END vim9script - # Test for using function() + # Test for using a def function with opfunc def g:Vim9opFunc(val: number, type: string): void g:OpFuncArgs = [val, type] enddef @@ -594,33 +612,6 @@ func Test_opfunc_callback() g:OpFuncArgs = [] normal! g@l assert_equal([60, 'char'], g:OpFuncArgs) - - # Test for using a lambda - &opfunc = (a) => Vim9opFunc(61, a) - g:OpFuncArgs = [] - normal! g@l - assert_equal([61, 'char'], g:OpFuncArgs) - - # Test for using a string(lambda) - &opfunc = '(a) => Vim9opFunc(62, a)' - g:OpFuncArgs = [] - normal! g@l - assert_equal([62, 'char'], g:OpFuncArgs) - - # Test for using a variable with a lambda expression - var Fn: func = (a) => Vim9opFunc(63, a) - &opfunc = Fn - g:OpFuncArgs = [] - normal! g@l - assert_equal([63, 'char'], g:OpFuncArgs) - - # Test for using a string(variable with a lambda expression) - Fn = (a) => Vim9opFunc(64, a) - &opfunc = string(Fn) - g:OpFuncArgs = [] - normal! g@l - assert_equal([64, 'char'], g:OpFuncArgs) - bw! END " call CheckScriptSuccess(lines) diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 9d9fc5e77b..a18d6fd6ab 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -1,6 +1,7 @@ " Test for the quickfix feature. source check.vim +source vim9.vim CheckFeature quickfix source screendump.vim @@ -5690,6 +5691,131 @@ func Test_qftextfunc() call Xtest_qftextfunc('l') endfunc +func Test_qftextfunc_callback() + let lines =<< trim END + set efm=%f:%l:%c:%m + + #" Test for using a function() + set qftf=function('g:Tqfexpr') + cexpr "F1:1:1:L1" + copen + call assert_equal('F1-L1C1-L1', getline(1)) + cclose + + #" Using a funcref variable to set 'quickfixtextfunc' + VAR Fn = function('g:Tqfexpr') + LET &qftf = Fn + cexpr "F2:2:2:L2" + copen + call assert_equal('F2-L2C2-L2', getline(1)) + cclose + + #" Using string(funcref_variable) to set 'quickfixtextfunc' + LET Fn = function('g:Tqfexpr') + LET &qftf = string(Fn) + cexpr "F3:3:3:L3" + copen + call assert_equal('F3-L3C3-L3', getline(1)) + cclose + + #" Test for using a funcref() + set qftf=funcref('g:Tqfexpr') + cexpr "F4:4:4:L4" + copen + call assert_equal('F4-L4C4-L4', getline(1)) + cclose + + #" Using a funcref variable to set 'quickfixtextfunc' + LET Fn = funcref('g:Tqfexpr') + LET &qftf = Fn + cexpr "F5:5:5:L5" + copen + call assert_equal('F5-L5C5-L5', getline(1)) + cclose + + #" Using a string(funcref_variable) to set 'quickfixtextfunc' + LET Fn = funcref('g:Tqfexpr') + LET &qftf = string(Fn) + cexpr "F5:5:5:L5" + copen + call assert_equal('F5-L5C5-L5', getline(1)) + cclose + + #" Test for using a lambda function with set + VAR optval = "LSTART a LMIDDLE Tqfexpr(a) LEND" + LET optval = substitute(optval, ' ', '\\ ', 'g') + exe "set qftf=" .. optval + cexpr "F6:6:6:L6" + copen + call assert_equal('F6-L6C6-L6', getline(1)) + cclose + + #" Set 'quickfixtextfunc' to a lambda expression + LET &qftf = LSTART a LMIDDLE Tqfexpr(a) LEND + cexpr "F7:7:7:L7" + copen + call assert_equal('F7-L7C7-L7', getline(1)) + cclose + + #" Set 'quickfixtextfunc' to string(lambda_expression) + LET &qftf = "LSTART a LMIDDLE Tqfexpr(a) LEND" + cexpr "F8:8:8:L8" + copen + call assert_equal('F8-L8C8-L8', getline(1)) + cclose + + #" Set 'quickfixtextfunc' to a variable with a lambda expression + VAR Lambda = LSTART a LMIDDLE Tqfexpr(a) LEND + LET &qftf = Lambda + cexpr "F9:9:9:L9" + copen + call assert_equal('F9-L9C9-L9', getline(1)) + cclose + + #" Set 'quickfixtextfunc' to a string(variable with a lambda expression) + LET Lambda = LSTART a LMIDDLE Tqfexpr(a) LEND + LET &qftf = string(Lambda) + cexpr "F9:9:9:L9" + copen + call assert_equal('F9-L9C9-L9', getline(1)) + cclose + END + call CheckLegacyAndVim9Success(lines) + + " set 'quickfixtextfunc' to a partial with dict. This used to cause a crash. + func SetQftfFunc() + let params = {'qftf': function('g:DictQftfFunc')} + let &quickfixtextfunc = params.qftf + endfunc + func g:DictQftfFunc(_) dict + endfunc + call SetQftfFunc() + new + call SetQftfFunc() + bw + call test_garbagecollect_now() + new + set qftf= + wincmd w + set qftf= + :%bw! + + " set per-quickfix list 'quickfixtextfunc' to a partial with dict. This used + " to cause a crash. + let &qftf = '' + func SetLocalQftfFunc() + let params = {'qftf': function('g:DictQftfFunc')} + call setqflist([], 'a', {'quickfixtextfunc' : params.qftf}) + endfunc + call SetLocalQftfFunc() + call test_garbagecollect_now() + call setqflist([], 'a', {'quickfixtextfunc' : ''}) + delfunc g:DictQftfFunc + delfunc SetQftfFunc + delfunc SetLocalQftfFunc + set efm& +endfunc + " Test for updating a location list for some other window and check that " 'qftextfunc' uses the correct location list. func Test_qftextfunc_other_loclist() diff --git a/src/nvim/testdir/test_tagfunc.vim b/src/nvim/testdir/test_tagfunc.vim index 79b1110b43..827159e3c8 100644 --- a/src/nvim/testdir/test_tagfunc.vim +++ b/src/nvim/testdir/test_tagfunc.vim @@ -1,5 +1,7 @@ " Test 'tagfunc' +source vim9.vim + func TagFunc(pat, flag, info) let g:tagfunc_args = [a:pat, a:flag, a:info] let tags = [] @@ -130,55 +132,121 @@ func Test_tagfunc_callback() return v:null endfunc - " Test for using a function() - set tagfunc=function('MytagFunc1',[10]) - new | only - let g:MytagFunc1_args = [] - call assert_fails('tag a11', 'E433:') - call assert_equal([10, 'a11', '', {}], g:MytagFunc1_args) + let lines =<< trim END + #" Test for using a function() + set tagfunc=function('g:MytagFunc1',\ [10]) + new | only + LET g:MytagFunc1_args = [] + call assert_fails('tag a11', 'E433:') + call assert_equal([10, 'a11', '', {}], g:MytagFunc1_args) - " Using a funcref variable to set 'tagfunc' - let Fn = function('MytagFunc1', [11]) - let &tagfunc = Fn - new | only - let g:MytagFunc1_args = [] - call assert_fails('tag a12', 'E433:') - call assert_equal([11, 'a12', '', {}], g:MytagFunc1_args) + #" Using a funcref variable to set 'tagfunc' + VAR Fn = function('g:MytagFunc1', [11]) + LET &tagfunc = Fn + new | only + LET g:MytagFunc1_args = [] + call assert_fails('tag a12', 'E433:') + call assert_equal([11, 'a12', '', {}], g:MytagFunc1_args) - " Using a string(funcref_variable) to set 'tagfunc' - let Fn = function('MytagFunc1', [12]) - let &tagfunc = string(Fn) - new | only - let g:MytagFunc1_args = [] - call assert_fails('tag a12', 'E433:') - call assert_equal([12, 'a12', '', {}], g:MytagFunc1_args) + #" Using a string(funcref_variable) to set 'tagfunc' + LET Fn = function('g:MytagFunc1', [12]) + LET &tagfunc = string(Fn) + new | only + LET g:MytagFunc1_args = [] + call assert_fails('tag a12', 'E433:') + call assert_equal([12, 'a12', '', {}], g:MytagFunc1_args) - " Test for using a funcref() - func MytagFunc2(pat, flags, info) - let g:MytagFunc2_args = [a:pat, a:flags, a:info] - return v:null - endfunc - set tagfunc=funcref('MytagFunc1',[13]) - new | only - let g:MytagFunc1_args = [] - call assert_fails('tag a13', 'E433:') - call assert_equal([13, 'a13', '', {}], g:MytagFunc1_args) + #" Test for using a funcref() + set tagfunc=funcref('g:MytagFunc1',\ [13]) + new | only + LET g:MytagFunc1_args = [] + call assert_fails('tag a13', 'E433:') + call assert_equal([13, 'a13', '', {}], g:MytagFunc1_args) - " Using a funcref variable to set 'tagfunc' - let Fn = funcref('MytagFunc1', [14]) - let &tagfunc = Fn - new | only - let g:MytagFunc1_args = [] - call assert_fails('tag a14', 'E433:') - call assert_equal([14, 'a14', '', {}], g:MytagFunc1_args) + #" Using a funcref variable to set 'tagfunc' + LET Fn = funcref('g:MytagFunc1', [14]) + LET &tagfunc = Fn + new | only + LET g:MytagFunc1_args = [] + call assert_fails('tag a14', 'E433:') + call assert_equal([14, 'a14', '', {}], g:MytagFunc1_args) + + #" Using a string(funcref_variable) to set 'tagfunc' + LET Fn = funcref('g:MytagFunc1', [15]) + LET &tagfunc = string(Fn) + new | only + LET g:MytagFunc1_args = [] + call assert_fails('tag a14', 'E433:') + call assert_equal([15, 'a14', '', {}], g:MytagFunc1_args) + + #" Test for using a lambda function + VAR optval = "LSTART a, b, c LMIDDLE MytagFunc1(16, a, b, c) LEND" + LET optval = substitute(optval, ' ', '\\ ', 'g') + exe "set tagfunc=" .. optval + new | only + LET g:MytagFunc1_args = [] + call assert_fails('tag a17', 'E433:') + call assert_equal([16, 'a17', '', {}], g:MytagFunc1_args) + + #" Set 'tagfunc' to a lambda expression + LET &tagfunc = LSTART a, b, c LMIDDLE MytagFunc1(17, a, b, c) LEND + new | only + LET g:MytagFunc1_args = [] + call assert_fails('tag a18', 'E433:') + call assert_equal([17, 'a18', '', {}], g:MytagFunc1_args) - " Using a string(funcref_variable) to set 'tagfunc' - let Fn = funcref('MytagFunc1', [15]) - let &tagfunc = string(Fn) + #" Set 'tagfunc' to a string(lambda expression) + LET &tagfunc = 'LSTART a, b, c LMIDDLE MytagFunc1(18, a, b, c) LEND' + new | only + LET g:MytagFunc1_args = [] + call assert_fails('tag a18', 'E433:') + call assert_equal([18, 'a18', '', {}], g:MytagFunc1_args) + + #" Set 'tagfunc' to a variable with a lambda expression + VAR Lambda = LSTART a, b, c LMIDDLE MytagFunc1(19, a, b, c) LEND + LET &tagfunc = Lambda + new | only + LET g:MytagFunc1_args = [] + call assert_fails("tag a19", "E433:") + call assert_equal([19, 'a19', '', {}], g:MytagFunc1_args) + + #" Set 'tagfunc' to a string(variable with a lambda expression) + LET Lambda = LSTART a, b, c LMIDDLE MytagFunc1(20, a, b, c) LEND + LET &tagfunc = string(Lambda) + new | only + LET g:MytagFunc1_args = [] + call assert_fails("tag a19", "E433:") + call assert_equal([20, 'a19', '', {}], g:MytagFunc1_args) + + #" Test for using a lambda function with incorrect return value + LET Lambda = LSTART a, b, c LMIDDLE strlen(a) LEND + LET &tagfunc = string(Lambda) + new | only + call assert_fails("tag a20", "E987:") + + #" Test for clearing the 'tagfunc' option + set tagfunc='' + set tagfunc& + call assert_fails("set tagfunc=function('abc')", "E700:") + call assert_fails("set tagfunc=funcref('abc')", "E700:") + + #" set 'tagfunc' to a non-existing function + LET &tagfunc = function('g:MytagFunc1', [21]) + call assert_fails("set tagfunc=function('NonExistingFunc')", 'E700:') + call assert_fails("LET &tagfunc = function('NonExistingFunc')", 'E700:') + call assert_fails("tag axb123", 'E426:') + END + call CheckLegacyAndVim9Success(lines) + + let &tagfunc = "{a -> 'abc'}" + call assert_fails("echo taglist('a')", "E987:") + + " Using Vim9 lambda expression in legacy context should fail + " set tagfunc=(a,\ b,\ c)\ =>\ g:MytagFunc1(21,\ a,\ b,\ c) new | only let g:MytagFunc1_args = [] - call assert_fails('tag a14', 'E433:') - call assert_equal([15, 'a14', '', {}], g:MytagFunc1_args) + " call assert_fails("tag a17", "E117:") + call assert_equal([], g:MytagFunc1_args) " Test for using a script local function set tagfunc=ScriptLocalTagFunc @@ -203,70 +271,25 @@ func Test_tagfunc_callback() call assert_fails('tag a16', 'E433:') call assert_equal(['a16', '', {}], g:ScriptLocalFuncArgs) - " Test for using a lambda function - set tagfunc={a,\ b,\ c\ ->\ MytagFunc1(16,\ a,\ b,\ c)} - new | only - let g:MytagFunc1_args = [] - call assert_fails('tag a17', 'E433:') - call assert_equal([16, 'a17', '', {}], g:MytagFunc1_args) - - " Set 'tagfunc' to a lambda expression - let &tagfunc = {a, b, c -> MytagFunc1(17, a, b, c)} - new | only - let g:MytagFunc1_args = [] - call assert_fails('tag a18', 'E433:') - call assert_equal([17, 'a18', '', {}], g:MytagFunc1_args) - - " Set 'tagfunc' to a string(lambda expression) - let &tagfunc = '{a, b, c -> MytagFunc1(18, a, b, c)}' - new | only - let g:MytagFunc1_args = [] - call assert_fails('tag a18', 'E433:') - call assert_equal([18, 'a18', '', {}], g:MytagFunc1_args) - - " Set 'tagfunc' to a variable with a lambda expression - let Lambda = {a, b, c -> MytagFunc1(19, a, b, c)} - let &tagfunc = Lambda - new | only - let g:MytagFunc1_args = [] - call assert_fails("tag a19", "E433:") - call assert_equal([19, 'a19', '', {}], g:MytagFunc1_args) - - " Set 'tagfunc' to a string(variable with a lambda expression) - let Lambda = {a, b, c -> MytagFunc1(20, a, b, c)} - let &tagfunc = string(Lambda) - new | only - let g:MytagFunc1_args = [] - call assert_fails("tag a19", "E433:") - call assert_equal([20, 'a19', '', {}], g:MytagFunc1_args) - - " Test for using a lambda function with incorrect return value - let Lambda = {s -> strlen(s)} - let &tagfunc = string(Lambda) - new | only - call assert_fails("tag a20", "E987:") - - " Test for clearing the 'tagfunc' option - set tagfunc='' - set tagfunc& - - call assert_fails("set tagfunc=function('abc')", "E700:") - call assert_fails("set tagfunc=funcref('abc')", "E700:") - let &tagfunc = "{a -> 'abc'}" - call assert_fails("echo taglist('a')", "E987:") - - " Using Vim9 lambda expression in legacy context should fail - " set tagfunc=(a,\ b,\ c)\ =>\ g:MytagFunc1(21,\ a,\ b,\ c) - new | only - let g:MytagFunc1_args = [] - " call assert_fails("tag a17", "E117:") - call assert_equal([], g:MytagFunc1_args) - - " set 'tagfunc' to a non-existing function - call assert_fails("set tagfunc=function('NonExistingFunc')", 'E700:') - call assert_fails("let &tagfunc = function('NonExistingFunc')", 'E700:') - call assert_fails("tag axb123", 'E426:') - bw! + " set 'tagfunc' to a partial with dict. This used to cause a crash. + func SetTagFunc() + let params = {'tagfn': function('g:DictTagFunc')} + let &tagfunc = params.tagfn + endfunc + func g:DictTagFunc(_) dict + endfunc + call SetTagFunc() + new + call SetTagFunc() + bw + call test_garbagecollect_now() + new + set tagfunc= + wincmd w + set tagfunc= + :%bw! + delfunc g:DictTagFunc + delfunc SetTagFunc " Vim9 tests let lines =<< trim END @@ -282,42 +305,11 @@ func Test_tagfunc_callback() g:Vim9tagFuncArgs = [] assert_fails('tag a10', 'E433:') assert_equal([60, 'a10', '', {}], g:Vim9tagFuncArgs) - - # Test for using a lambda - &tagfunc = (a, b, c) => MytagFunc1(61, a, b, c) - new | only - g:MytagFunc1_args = [] - assert_fails('tag a20', 'E433:') - assert_equal([61, 'a20', '', {}], g:MytagFunc1_args) - - # Test for using a string(lambda) - &tagfunc = '(a, b, c) => MytagFunc1(62, a, b, c)' - new | only - g:MytagFunc1_args = [] - assert_fails('tag a20', 'E433:') - assert_equal([62, 'a20', '', {}], g:MytagFunc1_args) - - # Test for using a variable with a lambda expression - var Fn: func = (a, b, c) => MytagFunc1(63, a, b, c) - &tagfunc = Fn - new | only - g:MytagFunc1_args = [] - assert_fails('tag a30', 'E433:') - assert_equal([63, 'a30', '', {}], g:MytagFunc1_args) - - # Test for using a variable with a lambda expression - Fn = (a, b, c) => MytagFunc1(64, a, b, c) - &tagfunc = string(Fn) - new | only - g:MytagFunc1_args = [] - assert_fails('tag a30', 'E433:') - assert_equal([64, 'a30', '', {}], g:MytagFunc1_args) END " call CheckScriptSuccess(lines) " cleanup delfunc MytagFunc1 - delfunc MytagFunc2 set tagfunc& %bw! endfunc diff --git a/src/nvim/testdir/vim9.vim b/src/nvim/testdir/vim9.vim new file mode 100644 index 0000000000..db74ce3b11 --- /dev/null +++ b/src/nvim/testdir/vim9.vim @@ -0,0 +1,80 @@ + +" Use a different file name for each run. +let s:sequence = 1 + +" Check that "lines" inside a legacy function has no error. +func CheckLegacySuccess(lines) + let cwd = getcwd() + let fname = 'XlegacySuccess' .. s:sequence + let s:sequence += 1 + call writefile(['func Func()'] + a:lines + ['endfunc'], fname) + try + exe 'so ' .. fname + call Func() + finally + delfunc! Func + call chdir(cwd) + call delete(fname) + endtry +endfunc + +" Check that "lines" inside a legacy function results in the expected error +func CheckLegacyFailure(lines, error) + let cwd = getcwd() + let fname = 'XlegacyFails' .. s:sequence + let s:sequence += 1 + call writefile(['func Func()'] + a:lines + ['endfunc', 'call Func()'], fname) + try + call assert_fails('so ' .. fname, a:error) + finally + delfunc! Func + call chdir(cwd) + call delete(fname) + endtry +endfunc + +" Execute "lines" in a legacy function, translated as in +" CheckLegacyAndVim9Success() +func CheckTransLegacySuccess(lines) + let legacylines = a:lines->deepcopy()->map({_, v -> + \ v->substitute('\', 'let', 'g') + \ ->substitute('\', 'let', 'g') + \ ->substitute('\', '{', 'g') + \ ->substitute('\', '->', 'g') + \ ->substitute('\', '}', 'g') + \ ->substitute('\', '1', 'g') + \ ->substitute('\', '0', 'g') + \ ->substitute('#"', ' "', 'g') + \ }) + call CheckLegacySuccess(legacylines) +endfunc + +" Execute "lines" in a legacy function +" Use 'VAR' for a declaration. +" Use 'LET' for an assignment +" Use ' #"' for a comment +" Use LSTART arg LMIDDLE expr LEND for lambda +" Use 'TRUE' for 1 +" Use 'FALSE' for 0 +func CheckLegacyAndVim9Success(lines) + call CheckTransLegacySuccess(a:lines) +endfunc + +" Execute "lines" in a legacy function +" Use 'VAR' for a declaration. +" Use 'LET' for an assignment +" Use ' #"' for a comment +func CheckLegacyAndVim9Failure(lines, error) + if type(a:error) == type('string') + let legacyError = error + else + let legacyError = error[0] + endif + + let legacylines = a:lines->deepcopy()->map({_, v -> + \ v->substitute('\', 'let', 'g') + \ ->substitute('\', 'let', 'g') + \ ->substitute('#"', ' "', 'g') + \ }) + call CheckLegacyFailure(legacylines, legacyError) +endfunc -- cgit From be19990f30ed004f7f363f79ed05f23039bdfd07 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 7 Nov 2022 14:08:29 +0800 Subject: vim-patch:8.2.3792: setting *func options insufficiently tested Problem: Setting *func options insufficiently tested. Solution: Impove tests. (Yegappan Lakshmanan, closes vim/vim#9337) https://github.com/vim/vim/commit/04ef1fb13d200f770952e670357dddadb6210dd4 Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_ins_complete.vim | 400 ++++++++++++++++++--------------- src/nvim/testdir/test_normal.vim | 132 ++++++----- src/nvim/testdir/test_quickfix.vim | 7 + src/nvim/testdir/test_tagfunc.vim | 132 ++++++----- 4 files changed, 373 insertions(+), 298 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 db2bb2e2a0..d788841833 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -1290,123 +1290,136 @@ endfunc " Test for different ways of setting the 'completefunc' option func Test_completefunc_callback() - func MycompleteFunc1(val, findstart, base) - call add(g:MycompleteFunc1_args, [a:val, a:findstart, a:base]) + func CompleteFunc1(callnr, findstart, base) + call add(g:CompleteFunc1Args, [a:callnr, a:findstart, a:base]) + return a:findstart ? 0 : [] + endfunc + func CompleteFunc2(findstart, base) + call add(g:CompleteFunc2Args, [a:findstart, a:base]) return a:findstart ? 0 : [] endfunc let lines =<< trim END + #" Test for using a function name + LET &completefunc = 'g:CompleteFunc2' + new + call setline(1, 'zero') + LET g:CompleteFunc2Args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'zero']], g:CompleteFunc2Args) + bw! + #" Test for using a function() - set completefunc=function('g:MycompleteFunc1',\ [10]) - new | only + set completefunc=function('g:CompleteFunc1',\ [10]) + new call setline(1, 'one') - LET g:MycompleteFunc1_args = [] + LET g:CompleteFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MycompleteFunc1_args) + call assert_equal([[10, 1, ''], [10, 0, 'one']], g:CompleteFunc1Args) bw! #" Using a funcref variable to set 'completefunc' - VAR Fn = function('g:MycompleteFunc1', [11]) + VAR Fn = function('g:CompleteFunc1', [11]) LET &completefunc = Fn - new | only + new call setline(1, 'two') - LET g:MycompleteFunc1_args = [] + LET g:CompleteFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MycompleteFunc1_args) + call assert_equal([[11, 1, ''], [11, 0, 'two']], g:CompleteFunc1Args) bw! #" Using string(funcref_variable) to set 'completefunc' - LET Fn = function('g:MycompleteFunc1', [12]) + LET Fn = function('g:CompleteFunc1', [12]) LET &completefunc = string(Fn) - new | only + new call setline(1, 'two') - LET g:MycompleteFunc1_args = [] + LET g:CompleteFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MycompleteFunc1_args) + call assert_equal([[12, 1, ''], [12, 0, 'two']], g:CompleteFunc1Args) bw! #" Test for using a funcref() - set completefunc=funcref('g:MycompleteFunc1',\ [13]) - new | only + set completefunc=funcref('g:CompleteFunc1',\ [13]) + new call setline(1, 'three') - LET g:MycompleteFunc1_args = [] + LET g:CompleteFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MycompleteFunc1_args) + call assert_equal([[13, 1, ''], [13, 0, 'three']], g:CompleteFunc1Args) bw! #" Using a funcref variable to set 'completefunc' - LET Fn = funcref('g:MycompleteFunc1', [14]) + LET Fn = funcref('g:CompleteFunc1', [14]) LET &completefunc = Fn - new | only + new call setline(1, 'four') - LET g:MycompleteFunc1_args = [] + LET g:CompleteFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MycompleteFunc1_args) + call assert_equal([[14, 1, ''], [14, 0, 'four']], g:CompleteFunc1Args) bw! #" Using a string(funcref_variable) to set 'completefunc' - LET Fn = funcref('g:MycompleteFunc1', [15]) + LET Fn = funcref('g:CompleteFunc1', [15]) LET &completefunc = string(Fn) - new | only + new call setline(1, 'four') - LET g:MycompleteFunc1_args = [] + LET g:CompleteFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MycompleteFunc1_args) + call assert_equal([[15, 1, ''], [15, 0, 'four']], g:CompleteFunc1Args) bw! #" Test for using a lambda function with set - VAR optval = "LSTART a, b LMIDDLE MycompleteFunc1(16, a, b) LEND" + VAR optval = "LSTART a, b LMIDDLE CompleteFunc1(16, a, b) LEND" LET optval = substitute(optval, ' ', '\\ ', 'g') exe "set completefunc=" .. optval - new | only + new call setline(1, 'five') - LET g:MycompleteFunc1_args = [] + LET g:CompleteFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MycompleteFunc1_args) + call assert_equal([[16, 1, ''], [16, 0, 'five']], g:CompleteFunc1Args) bw! #" Set 'completefunc' to a lambda expression - LET &completefunc = LSTART a, b LMIDDLE MycompleteFunc1(17, a, b) LEND - new | only + LET &completefunc = LSTART a, b LMIDDLE CompleteFunc1(17, a, b) LEND + new call setline(1, 'six') - LET g:MycompleteFunc1_args = [] + LET g:CompleteFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MycompleteFunc1_args) + call assert_equal([[17, 1, ''], [17, 0, 'six']], g:CompleteFunc1Args) bw! #" Set 'completefunc' to string(lambda_expression) - LET &completefunc = 'LSTART a, b LMIDDLE MycompleteFunc1(18, a, b) LEND' - new | only + LET &completefunc = 'LSTART a, b LMIDDLE CompleteFunc1(18, a, b) LEND' + new call setline(1, 'six') - LET g:MycompleteFunc1_args = [] + LET g:CompleteFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MycompleteFunc1_args) + call assert_equal([[18, 1, ''], [18, 0, 'six']], g:CompleteFunc1Args) bw! #" Set 'completefunc' to a variable with a lambda expression - VAR Lambda = LSTART a, b LMIDDLE MycompleteFunc1(19, a, b) LEND + VAR Lambda = LSTART a, b LMIDDLE CompleteFunc1(19, a, b) LEND LET &completefunc = Lambda - new | only + new call setline(1, 'seven') - LET g:MycompleteFunc1_args = [] + LET g:CompleteFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MycompleteFunc1_args) + call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:CompleteFunc1Args) bw! #" Set 'completefunc' to a string(variable with a lambda expression) - LET Lambda = LSTART a, b LMIDDLE MycompleteFunc1(20, a, b) LEND + LET Lambda = LSTART a, b LMIDDLE CompleteFunc1(20, a, b) LEND LET &completefunc = string(Lambda) - new | only + new call setline(1, 'seven') - LET g:MycompleteFunc1_args = [] + LET g:CompleteFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MycompleteFunc1_args) + call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:CompleteFunc1Args) bw! #" Test for using a lambda function with incorrect return value LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND LET &completefunc = Lambda - new | only + new call setline(1, 'eight') call feedkeys("A\\\", 'x') bw! @@ -1418,17 +1431,13 @@ func Test_completefunc_callback() call assert_fails("set completefunc=funcref('abc')", "E700:") #" set 'completefunc' to a non-existing function - func MycompleteFunc2(findstart, base) - call add(g:MycompleteFunc2_args, [a:findstart, a:base]) - return a:findstart ? 0 : [] - endfunc - set completefunc=MycompleteFunc2 + set completefunc=CompleteFunc2 call setline(1, 'five') call assert_fails("set completefunc=function('NonExistingFunc')", 'E700:') call assert_fails("LET &completefunc = function('NonExistingFunc')", 'E700:') - LET g:MycompleteFunc2_args = [] + LET g:CompleteFunc2Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'five']], g:MycompleteFunc2_args) + call assert_equal([[1, ''], [0, 'five']], g:CompleteFunc2Args) bw! END call CheckLegacyAndVim9Success(lines) @@ -1437,11 +1446,11 @@ func Test_completefunc_callback() call feedkeys("A\\\", 'x') " Using Vim9 lambda expression in legacy context should fail - " set completefunc=(a,\ b)\ =>\ MycompleteFunc1(21,\ a,\ b) + " set completefunc=(a,\ b)\ =>\ CompleteFunc1(21,\ a,\ b) new | only - let g:MycompleteFunc1_args = [] + let g:CompleteFunc1Args = [] " call assert_fails('call feedkeys("A\\\", "x")', 'E117:') - call assert_equal([], g:MycompleteFunc1_args) + call assert_equal([], g:CompleteFunc1Args) " set 'completefunc' to a partial with dict. This used to cause a crash. func SetCompleteFunc() @@ -1483,131 +1492,145 @@ func Test_completefunc_callback() " call CheckScriptSuccess(lines) " cleanup - delfunc MycompleteFunc1 - delfunc MycompleteFunc2 set completefunc& + delfunc CompleteFunc1 + delfunc CompleteFunc2 + unlet g:CompleteFunc1Args g:CompleteFunc2Args %bw! endfunc " Test for different ways of setting the 'omnifunc' option func Test_omnifunc_callback() - func MyomniFunc1(val, findstart, base) - call add(g:MyomniFunc1_args, [a:val, a:findstart, a:base]) + func OmniFunc1(callnr, findstart, base) + call add(g:OmniFunc1Args, [a:callnr, a:findstart, a:base]) + return a:findstart ? 0 : [] + endfunc + func OmniFunc2(findstart, base) + call add(g:OmniFunc2Args, [a:findstart, a:base]) return a:findstart ? 0 : [] endfunc let lines =<< trim END + #" Test for using a function name + LET &omnifunc = 'g:OmniFunc2' + new + call setline(1, 'zero') + LET g:OmniFunc2Args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'zero']], g:OmniFunc2Args) + bw! + #" Test for using a function() - set omnifunc=function('g:MyomniFunc1',\ [10]) - new | only + set omnifunc=function('g:OmniFunc1',\ [10]) + new call setline(1, 'one') - LET g:MyomniFunc1_args = [] + LET g:OmniFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MyomniFunc1_args) + call assert_equal([[10, 1, ''], [10, 0, 'one']], g:OmniFunc1Args) bw! #" Using a funcref variable to set 'omnifunc' - VAR Fn = function('g:MyomniFunc1', [11]) + VAR Fn = function('g:OmniFunc1', [11]) LET &omnifunc = Fn - new | only + new call setline(1, 'two') - LET g:MyomniFunc1_args = [] + LET g:OmniFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MyomniFunc1_args) + call assert_equal([[11, 1, ''], [11, 0, 'two']], g:OmniFunc1Args) bw! #" Using a string(funcref_variable) to set 'omnifunc' - LET Fn = function('g:MyomniFunc1', [12]) + LET Fn = function('g:OmniFunc1', [12]) LET &omnifunc = string(Fn) - new | only + new call setline(1, 'two') - LET g:MyomniFunc1_args = [] + LET g:OmniFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MyomniFunc1_args) + call assert_equal([[12, 1, ''], [12, 0, 'two']], g:OmniFunc1Args) bw! #" Test for using a funcref() - set omnifunc=funcref('g:MyomniFunc1',\ [13]) - new | only + set omnifunc=funcref('g:OmniFunc1',\ [13]) + new call setline(1, 'three') - LET g:MyomniFunc1_args = [] + LET g:OmniFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MyomniFunc1_args) + call assert_equal([[13, 1, ''], [13, 0, 'three']], g:OmniFunc1Args) bw! #" Use let to set 'omnifunc' to a funcref - LET Fn = funcref('g:MyomniFunc1', [14]) + LET Fn = funcref('g:OmniFunc1', [14]) LET &omnifunc = Fn - new | only + new call setline(1, 'four') - LET g:MyomniFunc1_args = [] + LET g:OmniFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MyomniFunc1_args) + call assert_equal([[14, 1, ''], [14, 0, 'four']], g:OmniFunc1Args) bw! #" Using a string(funcref) to set 'omnifunc' - LET Fn = funcref("g:MyomniFunc1", [15]) + LET Fn = funcref("g:OmniFunc1", [15]) LET &omnifunc = string(Fn) - new | only + new call setline(1, 'four') - LET g:MyomniFunc1_args = [] + LET g:OmniFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MyomniFunc1_args) + call assert_equal([[15, 1, ''], [15, 0, 'four']], g:OmniFunc1Args) bw! #" Test for using a lambda function with set - VAR optval = "LSTART a, b LMIDDLE MyomniFunc1(16, a, b) LEND" + VAR optval = "LSTART a, b LMIDDLE OmniFunc1(16, a, b) LEND" LET optval = substitute(optval, ' ', '\\ ', 'g') exe "set omnifunc=" .. optval - new | only + new call setline(1, 'five') - LET g:MyomniFunc1_args = [] + LET g:OmniFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MyomniFunc1_args) + call assert_equal([[16, 1, ''], [16, 0, 'five']], g:OmniFunc1Args) bw! #" Set 'omnifunc' to a lambda expression - LET &omnifunc = LSTART a, b LMIDDLE MyomniFunc1(17, a, b) LEND - new | only + LET &omnifunc = LSTART a, b LMIDDLE OmniFunc1(17, a, b) LEND + new call setline(1, 'six') - LET g:MyomniFunc1_args = [] + LET g:OmniFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MyomniFunc1_args) + call assert_equal([[17, 1, ''], [17, 0, 'six']], g:OmniFunc1Args) bw! #" Set 'omnifunc' to a string(lambda_expression) - LET &omnifunc = 'LSTART a, b LMIDDLE MyomniFunc1(18, a, b) LEND' - new | only + LET &omnifunc = 'LSTART a, b LMIDDLE OmniFunc1(18, a, b) LEND' + new call setline(1, 'six') - LET g:MyomniFunc1_args = [] + LET g:OmniFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MyomniFunc1_args) + call assert_equal([[18, 1, ''], [18, 0, 'six']], g:OmniFunc1Args) bw! #" Set 'omnifunc' to a variable with a lambda expression - VAR Lambda = LSTART a, b LMIDDLE MyomniFunc1(19, a, b) LEND + VAR Lambda = LSTART a, b LMIDDLE OmniFunc1(19, a, b) LEND LET &omnifunc = Lambda - new | only + new call setline(1, 'seven') - LET g:MyomniFunc1_args = [] + LET g:OmniFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MyomniFunc1_args) + call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:OmniFunc1Args) bw! #" Set 'omnifunc' to a string(variable with a lambda expression) - LET Lambda = LSTART a, b LMIDDLE MyomniFunc1(20, a, b) LEND + LET Lambda = LSTART a, b LMIDDLE OmniFunc1(20, a, b) LEND LET &omnifunc = string(Lambda) - new | only + new call setline(1, 'seven') - LET g:MyomniFunc1_args = [] + LET g:OmniFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MyomniFunc1_args) + call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:OmniFunc1Args) bw! #" Test for using a lambda function with incorrect return value LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND LET &omnifunc = Lambda - new | only + new call setline(1, 'eight') call feedkeys("A\\\", 'x') bw! @@ -1619,17 +1642,13 @@ func Test_omnifunc_callback() call assert_fails("set omnifunc=funcref('abc')", "E700:") #" set 'omnifunc' to a non-existing function - func MyomniFunc2(findstart, base) - call add(g:MyomniFunc2_args, [a:findstart, a:base]) - return a:findstart ? 0 : [] - endfunc - set omnifunc=MyomniFunc2 + set omnifunc=OmniFunc2 call setline(1, 'nine') call assert_fails("set omnifunc=function('NonExistingFunc')", 'E700:') call assert_fails("LET &omnifunc = function('NonExistingFunc')", 'E700:') - LET g:MyomniFunc2_args = [] + LET g:OmniFunc2Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'nine']], g:MyomniFunc2_args) + call assert_equal([[1, ''], [0, 'nine']], g:OmniFunc2Args) bw! END call CheckLegacyAndVim9Success(lines) @@ -1638,11 +1657,11 @@ func Test_omnifunc_callback() call feedkeys("A\\\", 'x') " Using Vim9 lambda expression in legacy context should fail - " set omnifunc=(a,\ b)\ =>\ MyomniFunc1(21,\ a,\ b) + " set omnifunc=(a,\ b)\ =>\ OmniFunc1(21,\ a,\ b) new | only - let g:MyomniFunc1_args = [] + let g:OmniFunc1Args = [] " call assert_fails('call feedkeys("A\\\", "x")', 'E117:') - call assert_equal([], g:MyomniFunc1_args) + call assert_equal([], g:OmniFunc1Args) " set 'omnifunc' to a partial with dict. This used to cause a crash. func SetOmniFunc() @@ -1684,131 +1703,145 @@ func Test_omnifunc_callback() " call CheckScriptSuccess(lines) " cleanup - delfunc MyomniFunc1 - delfunc MyomniFunc2 set omnifunc& + delfunc OmniFunc1 + delfunc OmniFunc2 + unlet g:OmniFunc1Args g:OmniFunc2Args %bw! endfunc " Test for different ways of setting the 'thesaurusfunc' option func Test_thesaurusfunc_callback() - func MytsrFunc1(val, findstart, base) - call add(g:MytsrFunc1_args, [a:val, a:findstart, a:base]) + func TsrFunc1(callnr, findstart, base) + call add(g:TsrFunc1Args, [a:callnr, a:findstart, a:base]) return a:findstart ? 0 : [] endfunc + func TsrFunc2(findstart, base) + call add(g:TsrFunc2Args, [a:findstart, a:base]) + return a:findstart ? 0 : ['sunday'] + endfunc let lines =<< trim END + #" Test for using a function name + LET &thesaurusfunc = 'g:TsrFunc2' + new + call setline(1, 'zero') + LET g:TsrFunc2Args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'zero']], g:TsrFunc2Args) + bw! + #" Test for using a function() - set thesaurusfunc=function('g:MytsrFunc1',\ [10]) - new | only + set thesaurusfunc=function('g:TsrFunc1',\ [10]) + new call setline(1, 'one') - LET g:MytsrFunc1_args = [] + LET g:TsrFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MytsrFunc1_args) + call assert_equal([[10, 1, ''], [10, 0, 'one']], g:TsrFunc1Args) bw! #" Using a funcref variable to set 'thesaurusfunc' - VAR Fn = function('g:MytsrFunc1', [11]) + VAR Fn = function('g:TsrFunc1', [11]) LET &thesaurusfunc = Fn - new | only + new call setline(1, 'two') - LET g:MytsrFunc1_args = [] + LET g:TsrFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MytsrFunc1_args) + call assert_equal([[11, 1, ''], [11, 0, 'two']], g:TsrFunc1Args) bw! #" Using a string(funcref_variable) to set 'thesaurusfunc' - LET Fn = function('g:MytsrFunc1', [12]) + LET Fn = function('g:TsrFunc1', [12]) LET &thesaurusfunc = string(Fn) - new | only + new call setline(1, 'two') - LET g:MytsrFunc1_args = [] + LET g:TsrFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MytsrFunc1_args) + call assert_equal([[12, 1, ''], [12, 0, 'two']], g:TsrFunc1Args) bw! #" Test for using a funcref() - set thesaurusfunc=funcref('g:MytsrFunc1',\ [13]) - new | only + set thesaurusfunc=funcref('g:TsrFunc1',\ [13]) + new call setline(1, 'three') - LET g:MytsrFunc1_args = [] + LET g:TsrFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MytsrFunc1_args) + call assert_equal([[13, 1, ''], [13, 0, 'three']], g:TsrFunc1Args) bw! #" Using a funcref variable to set 'thesaurusfunc' - LET Fn = funcref('g:MytsrFunc1', [14]) + LET Fn = funcref('g:TsrFunc1', [14]) LET &thesaurusfunc = Fn - new | only + new call setline(1, 'four') - LET g:MytsrFunc1_args = [] + LET g:TsrFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MytsrFunc1_args) + call assert_equal([[14, 1, ''], [14, 0, 'four']], g:TsrFunc1Args) bw! #" Using a string(funcref_variable) to set 'thesaurusfunc' - LET Fn = funcref('g:MytsrFunc1', [15]) + LET Fn = funcref('g:TsrFunc1', [15]) LET &thesaurusfunc = string(Fn) - new | only + new call setline(1, 'four') - LET g:MytsrFunc1_args = [] + LET g:TsrFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MytsrFunc1_args) + call assert_equal([[15, 1, ''], [15, 0, 'four']], g:TsrFunc1Args) bw! #" Test for using a lambda function - VAR optval = "LSTART a, b LMIDDLE MytsrFunc1(16, a, b) LEND" + VAR optval = "LSTART a, b LMIDDLE TsrFunc1(16, a, b) LEND" LET optval = substitute(optval, ' ', '\\ ', 'g') exe "set thesaurusfunc=" .. optval - new | only + new call setline(1, 'five') - LET g:MytsrFunc1_args = [] + LET g:TsrFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MytsrFunc1_args) + call assert_equal([[16, 1, ''], [16, 0, 'five']], g:TsrFunc1Args) bw! #" Test for using a lambda function with set - LET &thesaurusfunc = LSTART a, b LMIDDLE MytsrFunc1(17, a, b) LEND - new | only + LET &thesaurusfunc = LSTART a, b LMIDDLE TsrFunc1(17, a, b) LEND + new call setline(1, 'six') - LET g:MytsrFunc1_args = [] + LET g:TsrFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MytsrFunc1_args) + call assert_equal([[17, 1, ''], [17, 0, 'six']], g:TsrFunc1Args) bw! #" Set 'thesaurusfunc' to a string(lambda expression) - LET &thesaurusfunc = 'LSTART a, b LMIDDLE MytsrFunc1(18, a, b) LEND' - new | only + LET &thesaurusfunc = 'LSTART a, b LMIDDLE TsrFunc1(18, a, b) LEND' + new call setline(1, 'six') - LET g:MytsrFunc1_args = [] + LET g:TsrFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MytsrFunc1_args) + call assert_equal([[18, 1, ''], [18, 0, 'six']], g:TsrFunc1Args) bw! #" Set 'thesaurusfunc' to a variable with a lambda expression - VAR Lambda = LSTART a, b LMIDDLE MytsrFunc1(19, a, b) LEND + VAR Lambda = LSTART a, b LMIDDLE TsrFunc1(19, a, b) LEND LET &thesaurusfunc = Lambda - new | only + new call setline(1, 'seven') - LET g:MytsrFunc1_args = [] + LET g:TsrFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MytsrFunc1_args) + call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:TsrFunc1Args) bw! #" Set 'thesaurusfunc' to a string(variable with a lambda expression) - LET Lambda = LSTART a, b LMIDDLE MytsrFunc1(20, a, b) LEND + LET Lambda = LSTART a, b LMIDDLE TsrFunc1(20, a, b) LEND LET &thesaurusfunc = string(Lambda) - new | only + new call setline(1, 'seven') - LET g:MytsrFunc1_args = [] + LET g:TsrFunc1Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MytsrFunc1_args) + call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:TsrFunc1Args) bw! #" Test for using a lambda function with incorrect return value LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND LET &thesaurusfunc = Lambda - new | only + new call setline(1, 'eight') call feedkeys("A\\\", 'x') bw! @@ -1820,40 +1853,36 @@ func Test_thesaurusfunc_callback() call assert_fails("set thesaurusfunc=funcref('abc')", "E700:") #" set 'thesaurusfunc' to a non-existing function - func MytsrFunc2(findstart, base) - call add(g:MytsrFunc2_args, [a:findstart, a:base]) - return a:findstart ? 0 : ['sunday'] - endfunc - set thesaurusfunc=MytsrFunc2 + set thesaurusfunc=TsrFunc2 call setline(1, 'ten') call assert_fails("set thesaurusfunc=function('NonExistingFunc')", 'E700:') call assert_fails("LET &thesaurusfunc = function('NonExistingFunc')", 'E700:') - LET g:MytsrFunc2_args = [] + LET g:TsrFunc2Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'ten']], g:MytsrFunc2_args) + call assert_equal([[1, ''], [0, 'ten']], g:TsrFunc2Args) bw! #" Use a buffer-local value and a global value set thesaurusfunc& - setlocal thesaurusfunc=function('g:MytsrFunc1',\ [22]) + setlocal thesaurusfunc=function('g:TsrFunc1',\ [22]) call setline(1, 'sun') - LET g:MytsrFunc1_args = [] + LET g:TsrFunc1Args = [] call feedkeys("A\\\", "x") call assert_equal('sun', getline(1)) - call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:MytsrFunc1_args) + call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:TsrFunc1Args) new call setline(1, 'sun') - LET g:MytsrFunc1_args = [] + LET g:TsrFunc1Args = [] call feedkeys("A\\\", "x") call assert_equal('sun', getline(1)) - call assert_equal([], g:MytsrFunc1_args) - set thesaurusfunc=function('g:MytsrFunc1',\ [23]) + call assert_equal([], g:TsrFunc1Args) + set thesaurusfunc=function('g:TsrFunc1',\ [23]) wincmd w call setline(1, 'sun') - LET g:MytsrFunc1_args = [] + LET g:TsrFunc1Args = [] call feedkeys("A\\\", "x") call assert_equal('sun', getline(1)) - call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:MytsrFunc1_args) + call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:TsrFunc1Args) :%bw! END call CheckLegacyAndVim9Success(lines) @@ -1862,11 +1891,11 @@ func Test_thesaurusfunc_callback() call feedkeys("A\\\", 'x') " Using Vim9 lambda expression in legacy context should fail - " set thesaurusfunc=(a,\ b)\ =>\ MytsrFunc1(21,\ a,\ b) + " set thesaurusfunc=(a,\ b)\ =>\ TsrFunc1(21,\ a,\ b) new | only - let g:MytsrFunc1_args = [] + let g:TsrFunc1Args = [] " call assert_fails('call feedkeys("A\\\", "x")', 'E117:') - call assert_equal([], g:MytsrFunc1_args) + call assert_equal([], g:TsrFunc1Args) bw! " set 'thesaurusfunc' to a partial with dict. This used to cause a crash. @@ -1922,8 +1951,9 @@ func Test_thesaurusfunc_callback() " cleanup set thesaurusfunc& - delfunc MytsrFunc1 - delfunc MytsrFunc2 + delfunc TsrFunc1 + delfunc TsrFunc2 + unlet g:TsrFunc1Args g:TsrFunc2Args %bw! endfunc diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index b3e0be8f77..0d75644920 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -460,110 +460,120 @@ endfunc " Test for different ways of setting the 'operatorfunc' option func Test_opfunc_callback() new - func MyopFunc(val, type) - let g:OpFuncArgs = [a:val, a:type] + func OpFunc1(callnr, type) + let g:OpFunc1Args = [a:callnr, a:type] + endfunc + func OpFunc2(type) + let g:OpFunc2Args = [a:type] endfunc let lines =<< trim END + #" Test for using a function name + LET &opfunc = 'g:OpFunc2' + LET g:OpFunc2Args = [] + normal! g@l + call assert_equal(['char'], g:OpFunc2Args) + #" Test for using a function() - set opfunc=function('g:MyopFunc',\ [10]) - LET g:OpFuncArgs = [] + set opfunc=function('g:OpFunc1',\ [10]) + LET g:OpFunc1Args = [] normal! g@l - call assert_equal([10, 'char'], g:OpFuncArgs) + call assert_equal([10, 'char'], g:OpFunc1Args) #" Using a funcref variable to set 'operatorfunc' - VAR Fn = function('g:MyopFunc', [11]) + VAR Fn = function('g:OpFunc1', [11]) LET &opfunc = Fn - LET g:OpFuncArgs = [] + LET g:OpFunc1Args = [] normal! g@l - call assert_equal([11, 'char'], g:OpFuncArgs) + call assert_equal([11, 'char'], g:OpFunc1Args) #" Using a string(funcref_variable) to set 'operatorfunc' - LET Fn = function('g:MyopFunc', [12]) + LET Fn = function('g:OpFunc1', [12]) LET &operatorfunc = string(Fn) - LET g:OpFuncArgs = [] + LET g:OpFunc1Args = [] normal! g@l - call assert_equal([12, 'char'], g:OpFuncArgs) + call assert_equal([12, 'char'], g:OpFunc1Args) #" Test for using a funcref() - set operatorfunc=funcref('g:MyopFunc',\ [13]) - LET g:OpFuncArgs = [] + set operatorfunc=funcref('g:OpFunc1',\ [13]) + LET g:OpFunc1Args = [] normal! g@l - call assert_equal([13, 'char'], g:OpFuncArgs) + call assert_equal([13, 'char'], g:OpFunc1Args) #" Using a funcref variable to set 'operatorfunc' - LET Fn = funcref('g:MyopFunc', [14]) + LET Fn = funcref('g:OpFunc1', [14]) LET &opfunc = Fn - LET g:OpFuncArgs = [] + LET g:OpFunc1Args = [] normal! g@l - call assert_equal([14, 'char'], g:OpFuncArgs) + call assert_equal([14, 'char'], g:OpFunc1Args) #" Using a string(funcref_variable) to set 'operatorfunc' - LET Fn = funcref('g:MyopFunc', [15]) + LET Fn = funcref('g:OpFunc1', [15]) LET &opfunc = string(Fn) - LET g:OpFuncArgs = [] + LET g:OpFunc1Args = [] normal! g@l - call assert_equal([15, 'char'], g:OpFuncArgs) + call assert_equal([15, 'char'], g:OpFunc1Args) #" Test for using a lambda function using set - VAR optval = "LSTART a LMIDDLE MyopFunc(16, a) LEND" + VAR optval = "LSTART a LMIDDLE OpFunc1(16, a) LEND" LET optval = substitute(optval, ' ', '\\ ', 'g') exe "set opfunc=" .. optval - LET g:OpFuncArgs = [] + LET g:OpFunc1Args = [] normal! g@l - call assert_equal([16, 'char'], g:OpFuncArgs) + call assert_equal([16, 'char'], g:OpFunc1Args) #" Test for using a lambda function using LET - LET &opfunc = LSTART a LMIDDLE MyopFunc(17, a) LEND - LET g:OpFuncArgs = [] + LET &opfunc = LSTART a LMIDDLE OpFunc1(17, a) LEND + LET g:OpFunc1Args = [] normal! g@l - call assert_equal([17, 'char'], g:OpFuncArgs) + call assert_equal([17, 'char'], g:OpFunc1Args) #" Set 'operatorfunc' to a string(lambda expression) - LET &opfunc = 'LSTART a LMIDDLE MyopFunc(18, a) LEND' - LET g:OpFuncArgs = [] + LET &opfunc = 'LSTART a LMIDDLE OpFunc1(18, a) LEND' + LET g:OpFunc1Args = [] normal! g@l - call assert_equal([18, 'char'], g:OpFuncArgs) + call assert_equal([18, 'char'], g:OpFunc1Args) #" Set 'operatorfunc' to a variable with a lambda expression - VAR Lambda = LSTART a LMIDDLE MyopFunc(19, a) LEND + VAR Lambda = LSTART a LMIDDLE OpFunc1(19, a) LEND LET &opfunc = Lambda - LET g:OpFuncArgs = [] + LET g:OpFunc1Args = [] normal! g@l - call assert_equal([19, 'char'], g:OpFuncArgs) + call assert_equal([19, 'char'], g:OpFunc1Args) #" Set 'operatorfunc' to a string(variable with a lambda expression) - LET Lambda = LSTART a LMIDDLE MyopFunc(20, a) LEND + LET Lambda = LSTART a LMIDDLE OpFunc1(20, a) LEND LET &opfunc = string(Lambda) - LET g:OpFuncArgs = [] + LET g:OpFunc1Args = [] normal! g@l - call assert_equal([20, 'char'], g:OpFuncArgs) + call assert_equal([20, 'char'], g:OpFunc1Args) #" Try to use 'operatorfunc' after the function is deleted - func g:TmpOpFunc(type) - LET g:OpFuncArgs = [21, a:type] + func g:TmpOpFunc1(type) + let g:TmpOpFunc1Args = [21, a:type] endfunc - LET &opfunc = function('g:TmpOpFunc') - delfunc g:TmpOpFunc + LET &opfunc = function('g:TmpOpFunc1') + delfunc g:TmpOpFunc1 call test_garbagecollect_now() - LET g:OpFuncArgs = [] + LET g:TmpOpFunc1Args = [] call assert_fails('normal! g@l', 'E117:') - call assert_equal([], g:OpFuncArgs) + call assert_equal([], g:TmpOpFunc1Args) #" Try to use a function with two arguments for 'operatorfunc' - func MyopFunc2(x, y) - LET g:OpFuncArgs = [a:x, a:y] + func g:TmpOpFunc2(x, y) + let g:TmpOpFunc2Args = [a:x, a:y] endfunc - set opfunc=MyopFunc2 - LET g:OpFuncArgs = [] + set opfunc=TmpOpFunc2 + LET g:TmpOpFunc2Args = [] call assert_fails('normal! g@l', 'E119:') - call assert_equal([], g:OpFuncArgs) + call assert_equal([], g:TmpOpFunc2Args) + delfunc TmpOpFunc2 #" Try to use a lambda function with two arguments for 'operatorfunc' - LET &opfunc = LSTART a, b LMIDDLE MyopFunc(22, b) LEND - LET g:OpFuncArgs = [] + LET &opfunc = LSTART a, b LMIDDLE OpFunc1(22, b) LEND + LET g:OpFunc1Args = [] call assert_fails('normal! g@l', 'E119:') - call assert_equal([], g:OpFuncArgs) + call assert_equal([], g:OpFunc1Args) #" Test for clearing the 'operatorfunc' option set opfunc='' @@ -572,20 +582,20 @@ func Test_opfunc_callback() call assert_fails("set opfunc=funcref('abc')", "E700:") #" set 'operatorfunc' to a non-existing function - LET &opfunc = function('g:MyopFunc', [23]) + LET &opfunc = function('g:OpFunc1', [23]) call assert_fails("set opfunc=function('NonExistingFunc')", 'E700:') call assert_fails("LET &opfunc = function('NonExistingFunc')", 'E700:') - LET g:OpFuncArgs = [] + LET g:OpFunc1Args = [] normal! g@l - call assert_equal([23, 'char'], g:OpFuncArgs) + call assert_equal([23, 'char'], g:OpFunc1Args) END call CheckTransLegacySuccess(lines) " Using Vim9 lambda expression in legacy context should fail - " set opfunc=(a)\ =>\ MyopFunc(24,\ a) - let g:OpFuncArgs = [] + " set opfunc=(a)\ =>\ OpFunc1(24,\ a) + let g:OpFunc1Args = [] " call assert_fails('normal! g@l', 'E117:') - call assert_equal([], g:OpFuncArgs) + call assert_equal([], g:OpFunc1Args) " set 'operatorfunc' to a partial with dict. This used to cause a crash. func SetOpFunc() @@ -606,20 +616,20 @@ func Test_opfunc_callback() # Test for using a def function with opfunc def g:Vim9opFunc(val: number, type: string): void - g:OpFuncArgs = [val, type] + g:OpFunc1Args = [val, type] enddef set opfunc=function('g:Vim9opFunc',\ [60]) - g:OpFuncArgs = [] + g:OpFunc1Args = [] normal! g@l - assert_equal([60, 'char'], g:OpFuncArgs) + assert_equal([60, 'char'], g:OpFunc1Args) END " call CheckScriptSuccess(lines) " cleanup set opfunc& - delfunc MyopFunc - delfunc MyopFunc2 - unlet g:OpFuncArgs + delfunc OpFunc1 + delfunc OpFunc2 + unlet g:OpFunc1Args g:OpFunc2Args %bw! endfunc diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index a18d6fd6ab..42bdb7bad1 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -5695,6 +5695,13 @@ func Test_qftextfunc_callback() let lines =<< trim END set efm=%f:%l:%c:%m + #" Test for using a function name + LET &qftf = 'g:Tqfexpr' + cexpr "F0:0:0:L0" + copen + call assert_equal('F0-L0C0-L0', getline(1)) + cclose + #" Test for using a function() set qftf=function('g:Tqfexpr') cexpr "F1:1:1:L1" diff --git a/src/nvim/testdir/test_tagfunc.vim b/src/nvim/testdir/test_tagfunc.vim index 827159e3c8..7a88723bc0 100644 --- a/src/nvim/testdir/test_tagfunc.vim +++ b/src/nvim/testdir/test_tagfunc.vim @@ -127,102 +127,126 @@ endfunc " Test for different ways of setting the 'tagfunc' option func Test_tagfunc_callback() - func MytagFunc1(val, pat, flags, info) - let g:MytagFunc1_args = [a:val, a:pat, a:flags, a:info] + func TagFunc1(callnr, pat, flags, info) + let g:TagFunc1Args = [a:callnr, a:pat, a:flags, a:info] + return v:null + endfunc + func TagFunc2(pat, flags, info) + let g:TagFunc2Args = [a:pat, a:flags, a:info] return v:null endfunc let lines =<< trim END + #" Test for using a function name + LET &tagfunc = 'g:TagFunc2' + new + LET g:TagFunc2Args = [] + call assert_fails('tag a10', 'E433:') + call assert_equal(['a10', '', {}], g:TagFunc2Args) + bw! + #" Test for using a function() - set tagfunc=function('g:MytagFunc1',\ [10]) - new | only - LET g:MytagFunc1_args = [] + set tagfunc=function('g:TagFunc1',\ [10]) + new + LET g:TagFunc1Args = [] call assert_fails('tag a11', 'E433:') - call assert_equal([10, 'a11', '', {}], g:MytagFunc1_args) + call assert_equal([10, 'a11', '', {}], g:TagFunc1Args) + bw! #" Using a funcref variable to set 'tagfunc' - VAR Fn = function('g:MytagFunc1', [11]) + VAR Fn = function('g:TagFunc1', [11]) LET &tagfunc = Fn - new | only - LET g:MytagFunc1_args = [] + new + LET g:TagFunc1Args = [] call assert_fails('tag a12', 'E433:') - call assert_equal([11, 'a12', '', {}], g:MytagFunc1_args) + call assert_equal([11, 'a12', '', {}], g:TagFunc1Args) + bw! #" Using a string(funcref_variable) to set 'tagfunc' - LET Fn = function('g:MytagFunc1', [12]) + LET Fn = function('g:TagFunc1', [12]) LET &tagfunc = string(Fn) - new | only - LET g:MytagFunc1_args = [] + new + LET g:TagFunc1Args = [] call assert_fails('tag a12', 'E433:') - call assert_equal([12, 'a12', '', {}], g:MytagFunc1_args) + call assert_equal([12, 'a12', '', {}], g:TagFunc1Args) + bw! #" Test for using a funcref() - set tagfunc=funcref('g:MytagFunc1',\ [13]) - new | only - LET g:MytagFunc1_args = [] + set tagfunc=funcref('g:TagFunc1',\ [13]) + new + LET g:TagFunc1Args = [] call assert_fails('tag a13', 'E433:') - call assert_equal([13, 'a13', '', {}], g:MytagFunc1_args) + call assert_equal([13, 'a13', '', {}], g:TagFunc1Args) + bw! #" Using a funcref variable to set 'tagfunc' - LET Fn = funcref('g:MytagFunc1', [14]) + LET Fn = funcref('g:TagFunc1', [14]) LET &tagfunc = Fn - new | only - LET g:MytagFunc1_args = [] + new + LET g:TagFunc1Args = [] call assert_fails('tag a14', 'E433:') - call assert_equal([14, 'a14', '', {}], g:MytagFunc1_args) + call assert_equal([14, 'a14', '', {}], g:TagFunc1Args) + bw! #" Using a string(funcref_variable) to set 'tagfunc' - LET Fn = funcref('g:MytagFunc1', [15]) + LET Fn = funcref('g:TagFunc1', [15]) LET &tagfunc = string(Fn) - new | only - LET g:MytagFunc1_args = [] + new + LET g:TagFunc1Args = [] call assert_fails('tag a14', 'E433:') - call assert_equal([15, 'a14', '', {}], g:MytagFunc1_args) + call assert_equal([15, 'a14', '', {}], g:TagFunc1Args) + bw! #" Test for using a lambda function - VAR optval = "LSTART a, b, c LMIDDLE MytagFunc1(16, a, b, c) LEND" + VAR optval = "LSTART a, b, c LMIDDLE TagFunc1(16, a, b, c) LEND" LET optval = substitute(optval, ' ', '\\ ', 'g') exe "set tagfunc=" .. optval - new | only - LET g:MytagFunc1_args = [] + new + LET g:TagFunc1Args = [] call assert_fails('tag a17', 'E433:') - call assert_equal([16, 'a17', '', {}], g:MytagFunc1_args) + call assert_equal([16, 'a17', '', {}], g:TagFunc1Args) + bw! #" Set 'tagfunc' to a lambda expression - LET &tagfunc = LSTART a, b, c LMIDDLE MytagFunc1(17, a, b, c) LEND - new | only - LET g:MytagFunc1_args = [] + LET &tagfunc = LSTART a, b, c LMIDDLE TagFunc1(17, a, b, c) LEND + new + LET g:TagFunc1Args = [] call assert_fails('tag a18', 'E433:') - call assert_equal([17, 'a18', '', {}], g:MytagFunc1_args) + call assert_equal([17, 'a18', '', {}], g:TagFunc1Args) + bw! #" Set 'tagfunc' to a string(lambda expression) - LET &tagfunc = 'LSTART a, b, c LMIDDLE MytagFunc1(18, a, b, c) LEND' - new | only - LET g:MytagFunc1_args = [] + LET &tagfunc = 'LSTART a, b, c LMIDDLE TagFunc1(18, a, b, c) LEND' + new + LET g:TagFunc1Args = [] call assert_fails('tag a18', 'E433:') - call assert_equal([18, 'a18', '', {}], g:MytagFunc1_args) + call assert_equal([18, 'a18', '', {}], g:TagFunc1Args) + bw! #" Set 'tagfunc' to a variable with a lambda expression - VAR Lambda = LSTART a, b, c LMIDDLE MytagFunc1(19, a, b, c) LEND + VAR Lambda = LSTART a, b, c LMIDDLE TagFunc1(19, a, b, c) LEND LET &tagfunc = Lambda - new | only - LET g:MytagFunc1_args = [] + new + LET g:TagFunc1Args = [] call assert_fails("tag a19", "E433:") - call assert_equal([19, 'a19', '', {}], g:MytagFunc1_args) + call assert_equal([19, 'a19', '', {}], g:TagFunc1Args) + bw! #" Set 'tagfunc' to a string(variable with a lambda expression) - LET Lambda = LSTART a, b, c LMIDDLE MytagFunc1(20, a, b, c) LEND + LET Lambda = LSTART a, b, c LMIDDLE TagFunc1(20, a, b, c) LEND LET &tagfunc = string(Lambda) - new | only - LET g:MytagFunc1_args = [] + new + LET g:TagFunc1Args = [] call assert_fails("tag a19", "E433:") - call assert_equal([20, 'a19', '', {}], g:MytagFunc1_args) + call assert_equal([20, 'a19', '', {}], g:TagFunc1Args) + bw! #" Test for using a lambda function with incorrect return value LET Lambda = LSTART a, b, c LMIDDLE strlen(a) LEND LET &tagfunc = string(Lambda) - new | only + new call assert_fails("tag a20", "E987:") + bw! #" Test for clearing the 'tagfunc' option set tagfunc='' @@ -231,10 +255,13 @@ func Test_tagfunc_callback() call assert_fails("set tagfunc=funcref('abc')", "E700:") #" set 'tagfunc' to a non-existing function - LET &tagfunc = function('g:MytagFunc1', [21]) + LET &tagfunc = function('g:TagFunc2', [21]) + LET g:TagFunc2Args = [] call assert_fails("set tagfunc=function('NonExistingFunc')", 'E700:') call assert_fails("LET &tagfunc = function('NonExistingFunc')", 'E700:') call assert_fails("tag axb123", 'E426:') + call assert_equal([], g:TagFunc2Args) + bw! END call CheckLegacyAndVim9Success(lines) @@ -242,11 +269,11 @@ func Test_tagfunc_callback() call assert_fails("echo taglist('a')", "E987:") " Using Vim9 lambda expression in legacy context should fail - " set tagfunc=(a,\ b,\ c)\ =>\ g:MytagFunc1(21,\ a,\ b,\ c) + " set tagfunc=(a,\ b,\ c)\ =>\ g:TagFunc1(21,\ a,\ b,\ c) new | only - let g:MytagFunc1_args = [] + let g:TagFunc1Args = [] " call assert_fails("tag a17", "E117:") - call assert_equal([], g:MytagFunc1_args) + call assert_equal([], g:TagFunc1Args) " Test for using a script local function set tagfunc=ScriptLocalTagFunc @@ -309,7 +336,8 @@ func Test_tagfunc_callback() " call CheckScriptSuccess(lines) " cleanup - delfunc MytagFunc1 + delfunc TagFunc1 + delfunc TagFunc2 set tagfunc& %bw! endfunc -- cgit From a6f972cb6a5ad47613374570d88df2570ae92b9a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 7 Nov 2022 19:40:30 +0800 Subject: vim-patch:8.2.2060: check for features implemented with "if" Problem: Check for features implemented with "if". Solution: Use the Check commands. (Ken Takata, closes vim/vim#7383) https://github.com/vim/vim/commit/aeb313f355cd67638e3c611354ce401d86f56afe Cherry-pick test_compiler.vim changes from patch 8.1.2373. --- src/nvim/testdir/test_autocmd.vim | 4 +--- src/nvim/testdir/test_compiler.vim | 8 +++++--- src/nvim/testdir/test_delete.vim | 14 +++++--------- src/nvim/testdir/test_diffmode.vim | 4 +--- src/nvim/testdir/test_fold.vim | 4 +--- 5 files changed, 13 insertions(+), 21 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 1488fe8431..454fb2bdae 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -1975,9 +1975,7 @@ func Test_change_mark_in_autocmds() endfunc func Test_Filter_noshelltemp() - if !executable('cat') - return - endif + CheckExecutable cat enew! call setline(1, ['a', 'b', 'c', 'd']) diff --git a/src/nvim/testdir/test_compiler.vim b/src/nvim/testdir/test_compiler.vim index 3dc8710d63..ec7d143030 100644 --- a/src/nvim/testdir/test_compiler.vim +++ b/src/nvim/testdir/test_compiler.vim @@ -1,9 +1,11 @@ " Test the :compiler command +source check.vim +source shared.vim + func Test_compiler() - if !executable('perl') - return - endif + CheckExecutable perl + CheckFeature quickfix " $LANG changes the output of Perl. if $LANG != '' diff --git a/src/nvim/testdir/test_delete.vim b/src/nvim/testdir/test_delete.vim index b23a3bd025..6b49f153c6 100644 --- a/src/nvim/testdir/test_delete.vim +++ b/src/nvim/testdir/test_delete.vim @@ -1,5 +1,7 @@ " Test for delete(). +source check.vim + func Test_file_delete() split Xfile call setline(1, ['a', 'b']) @@ -41,9 +43,7 @@ func Test_recursive_delete() endfunc func Test_symlink_delete() - if !has('unix') - return - endif + CheckUnix split Xfile call setline(1, ['a', 'b']) wq @@ -56,9 +56,7 @@ func Test_symlink_delete() endfunc func Test_symlink_dir_delete() - if !has('unix') - return - endif + CheckUnix call mkdir('Xdir1') silent !ln -s Xdir1 Xlink call assert_true(isdirectory('Xdir1')) @@ -70,9 +68,7 @@ func Test_symlink_dir_delete() endfunc func Test_symlink_recursive_delete() - if !has('unix') - return - endif + CheckUnix call mkdir('Xdir3') call mkdir('Xdir3/subdir') call mkdir('Xdir4') diff --git a/src/nvim/testdir/test_diffmode.vim b/src/nvim/testdir/test_diffmode.vim index 831efdbfc2..0de5310735 100644 --- a/src/nvim/testdir/test_diffmode.vim +++ b/src/nvim/testdir/test_diffmode.vim @@ -621,9 +621,7 @@ func Test_diff_move_to() endfunc func Test_diffexpr() - if !executable('diff') - return - endif + CheckExecutable diff func DiffExpr() " Prepend some text to check diff type detection diff --git a/src/nvim/testdir/test_fold.vim b/src/nvim/testdir/test_fold.vim index 0a9be310ff..832dd43b65 100644 --- a/src/nvim/testdir/test_fold.vim +++ b/src/nvim/testdir/test_fold.vim @@ -95,9 +95,7 @@ func Test_indent_fold2() endfunc func Test_manual_fold_with_filter() - if !executable('cat') - return - endif + CheckExecutable cat for type in ['manual', 'marker'] exe 'set foldmethod=' . type new -- cgit From 609c0513cac7898782c55f5fb20275733cc566e9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 7 Nov 2022 19:50:51 +0800 Subject: vim-patch:8.2.3626: "au! event" cannot be followed by another command Problem: "au!" and "au! event" cannot be followed by another command as documented. Solution: When a bar is found set nextcmd. https://github.com/vim/vim/commit/b8e642f7ace5382b4dacb7a8effd86f22b828cc1 Cherry-pick do_autocmd() "eap" argument from patch 8.2.3268. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_autocmd.vim | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 454fb2bdae..1e9406eb87 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -481,17 +481,20 @@ endfunc func Test_early_bar() " test that a bar is recognized before the {event} call s:AddAnAutocmd() - augroup vimBarTest | au! | augroup END + augroup vimBarTest | au! | let done = 77 | augroup END call assert_equal(1, len(split(execute('au vimBarTest'), "\n"))) + call assert_equal(77, done) call s:AddAnAutocmd() - augroup vimBarTest| au!| augroup END + augroup vimBarTest| au!| let done = 88 | augroup END call assert_equal(1, len(split(execute('au vimBarTest'), "\n"))) + call assert_equal(88, done) " test that a bar is recognized after the {event} call s:AddAnAutocmd() - augroup vimBarTest| au!BufReadCmd| augroup END + augroup vimBarTest| au!BufReadCmd| let done = 99 | augroup END call assert_equal(1, len(split(execute('au vimBarTest'), "\n"))) + call assert_equal(99, done) " test that a bar is recognized after the {group} call s:AddAnAutocmd() -- cgit From 894c59ec1f39fde259d5b6959c35549a0281943d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 7 Nov 2022 21:08:47 +0800 Subject: test(old): make Test_help_tagjump() test order match upstream --- src/nvim/testdir/test_help_tagjump.vim | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_help_tagjump.vim b/src/nvim/testdir/test_help_tagjump.vim index e84726bbfc..f81e4fb1ef 100644 --- a/src/nvim/testdir/test_help_tagjump.vim +++ b/src/nvim/testdir/test_help_tagjump.vim @@ -38,18 +38,18 @@ func Test_help_tagjump() call assert_true(getline('.') =~ '\*quotestar\*') helpclose - " The test result is different in vim. There ":help ??" will jump to the - " falsy operator ??, which hasn't been ported to neovim yet. Instead, neovim - " jumps to the tag "g??". This test result needs to be changed if neovim - " ports the falsy operator. - help ?? + " help sm?le + help ch?ckhealth call assert_equal("help", &filetype) - call assert_true(getline('.') =~ '\*g??\*') + " call assert_true(getline('.') =~ '\*:smile\*') + call assert_true(getline('.') =~ '\*:checkhealth\*') helpclose - help ch?ckhealth + help ?? call assert_equal("help", &filetype) - call assert_true(getline('.') =~ '\*:checkhealth\*') + " *??* tag needs patch 8.2.1794 + " call assert_true(getline('.') =~ '\*??\*') + call assert_true(getline('.') =~ '\*g??\*') helpclose help :? -- cgit From 050b0e30b9d8a073a3b421a6cebd878226249ab6 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Mon, 7 Nov 2022 22:28:28 +0100 Subject: vim-patch:9.0.0843: VHS tape files are not recognized (#20995) Problem: VHS tape files are not recognized. Solution: Add a filetype pattern. (Carlos Alexandro Becker, closes vim/vim#11452) https://github.com/vim/vim/commit/1756f4b21837e8596241ecd668f4abbbab4bc7e5 Co-authored-by: Carlos A Becker --- src/nvim/testdir/test_filetype.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index c6f90604e5..69508cb19e 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -612,6 +612,7 @@ let s:filename_checks = { \ 'verilogams': ['file.va', 'file.vams'], \ 'vgrindefs': ['vgrindefs'], \ 'vhdl': ['file.hdl', 'file.vhd', 'file.vhdl', 'file.vbe', 'file.vst', 'file.vhdl_123', 'file.vho', 'some.vhdl_1', 'some.vhdl_1-file'], + \ 'vhs': ['file.tape'], \ 'vim': ['file.vim', 'file.vba', '.exrc', '_exrc', 'some-vimrc', 'some-vimrc-file', 'vimrc', 'vimrc-file'], \ 'viminfo': ['.viminfo', '_viminfo'], \ 'vmasm': ['file.mar'], -- cgit From 04c73dbedb8a82ed68ff0b0be32c2bee930fe529 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 10 Nov 2022 13:38:17 +0800 Subject: revert: "oldtests: win: fix buffer pathsep" (#21017) This reverts commit 40e894f59570a6192aabbe4fe34c456bd00ae871. No longer needed after #10679 --- src/nvim/testdir/test_quickfix.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 42bdb7bad1..5edcf9ce0e 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -3441,9 +3441,9 @@ func Xmultidirstack_tests(cchar) let l1 = g:Xgetlist({'nr':1, 'items':1}) let l2 = g:Xgetlist({'nr':2, 'items':1}) - call assert_equal(expand('Xone/a/one.txt'), bufname(l1.items[1].bufnr)) + call assert_equal('Xone/a/one.txt', bufname(l1.items[1].bufnr)) call assert_equal(3, l1.items[1].lnum) - call assert_equal(expand('Xtwo/a/two.txt'), bufname(l2.items[1].bufnr)) + call assert_equal('Xtwo/a/two.txt', bufname(l2.items[1].bufnr)) call assert_equal(5, l2.items[1].lnum) endfunc -- cgit From ae67706535b23233d2d6f5a81b7c7284c3cc16f9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 11 Nov 2022 10:16:26 +0800 Subject: vim-patch:9.0.0858: "!!sort" in a closed fold sorts too many lines (#21022) Problem: "!!sort" in a closed fold sorts too many lines. Solution: Round to end of fold after adding the line count. (closes vim/vim#11487) https://github.com/vim/vim/commit/f00112d558eb9a7d1d5413c096960ddcc52c9f66 N/A patches for version.c: vim-patch:9.0.0855: comment not located above the code it refers to Problem: Comment not located above the code it refers to. Solution: Move the comment. (closes vim/vim#11527) https://github.com/vim/vim/commit/09a93e3e66689c691a00fce25e4ce310d81edaee vim-patch:9.0.0859: compiler warning for unused variable Problem: Compiler warning for unused variable. Solution: Add #ifdef. https://github.com/vim/vim/commit/fd3084b6e298477dec4979515c6b4a8a3c3beeb2 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_fold.vim | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_fold.vim b/src/nvim/testdir/test_fold.vim index 832dd43b65..1ee9165308 100644 --- a/src/nvim/testdir/test_fold.vim +++ b/src/nvim/testdir/test_fold.vim @@ -986,4 +986,40 @@ func Test_indent_append_blank_small_fold_close() bw! endfunc +func Test_sort_closed_fold() + CheckExecutable sort + + call setline(1, [ + \ 'Section 1', + \ ' how', + \ ' now', + \ ' brown', + \ ' cow', + \ 'Section 2', + \ ' how', + \ ' now', + \ ' brown', + \ ' cow', + \]) + setlocal foldmethod=indent sw=3 + normal 2G + + " The "!!" expands to ".,.+3" and must only sort four lines + call feedkeys("!!sort\", 'xt') + call assert_equal([ + \ 'Section 1', + \ ' brown', + \ ' cow', + \ ' how', + \ ' now', + \ 'Section 2', + \ ' how', + \ ' now', + \ ' brown', + \ ' cow', + \ ], getline(1, 10)) + + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 0d8e8d36ec7d3f4967f27389b4b94edf3ba57433 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 11 Nov 2022 17:50:52 +0800 Subject: vim-patch:8.2.1919: assert_fails() setting emsg_silent changes normal execution (#20998) Problem: Assert_fails() setting emsg_silent changes normal execution. Solution: Use a separate flag in_assert_fails. https://github.com/vim/vim/commit/28ee892ac4197421b3317f195512ca64cc56a5b4 Cherry-pick no_wait_return from patch 9.0.0846. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_autocmd.vim | 2 +- src/nvim/testdir/test_mapping.vim | 2 +- src/nvim/testdir/test_popup.vim | 6 ++---- 3 files changed, 4 insertions(+), 6 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 1e9406eb87..f4c32599f1 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -175,7 +175,7 @@ func Test_autocmd_bufunload_avoiding_SEGV_01() exe 'autocmd BufUnload ' . (lastbuf + 1) . 'bwipeout!' augroup END - call assert_fails('edit bb.txt', ['E937:', 'E517:']) + call assert_fails('edit bb.txt', 'E937:') autocmd! test_autocmd_bufunload augroup! test_autocmd_bufunload diff --git a/src/nvim/testdir/test_mapping.vim b/src/nvim/testdir/test_mapping.vim index 560883ba5d..522a51589f 100644 --- a/src/nvim/testdir/test_mapping.vim +++ b/src/nvim/testdir/test_mapping.vim @@ -779,7 +779,7 @@ func Test_expr_abbr() " invalid abbreviation abbr hte GetAbbr() call assert_fails('normal ihte ', 'E117:') - call assert_equal(' ', getline(1)) + call assert_equal('', getline(1)) unabbr hte close! diff --git a/src/nvim/testdir/test_popup.vim b/src/nvim/testdir/test_popup.vim index 7f183f0849..0981329320 100644 --- a/src/nvim/testdir/test_popup.vim +++ b/src/nvim/testdir/test_popup.vim @@ -359,7 +359,7 @@ func Test_completefunc_opens_new_window_one() /^one call assert_fails('call feedkeys("A\\\\", "x")', 'E565:') call assert_equal(winid, win_getid()) - call assert_equal('oneDEF', getline(1)) + call assert_equal('onedef', getline(1)) q! endfunc @@ -384,9 +384,7 @@ func Test_completefunc_opens_new_window_two() /^two call assert_fails('call feedkeys("A\\\\", "x")', 'E565:') call assert_equal(winid, win_getid()) - " v8.2.1919 hasn't been ported yet - " call assert_equal('twodef', getline(1)) - call assert_equal('twoDEF', getline(1)) + call assert_equal('twodef', getline(1)) q! endfunc -- cgit From 0d7cc5ee85c2722ab68e276a2bfda336ef9429d5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 11 Nov 2022 18:18:38 +0800 Subject: vim-patch:9.0.0715: wrong argument for append() gives two error messages (#21023) Problem: Wrong argument for append() gives two error messages. Solution: When getting an error for a number argument don't try using it as a string. (closes vim/vim#11335) https://github.com/vim/vim/commit/801cd35e7e3b21e519e12a1610ee1d721e40893e Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_functions.vim | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 0f2066b7c1..aaef01bdf5 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -813,6 +813,8 @@ func Test_append() " Using $ instead of '$' must give an error call assert_fails("call append($, 'foobar')", 'E116:') + + call assert_fails("call append({}, '')", ['E728:', 'E728:']) endfunc " Test for setline() -- cgit From eee956051637a5dff02ba6c6083fbffc87c0c96e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 12 Nov 2022 07:43:36 +0800 Subject: vim-patch:9.0.0861: solution for "!!sort" in closed fold is not optimal (#21027) Problem: Solution for "!!sort" in closed fold is not optimal. Solution: Use a different range instead of the subtle difference in handling a range with an offset. (issue vim/vim#11487) https://github.com/vim/vim/commit/9954dc39ea090cee6bf41c888c41e60d9f52c3b8 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_fold.vim | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_fold.vim b/src/nvim/testdir/test_fold.vim index 1ee9165308..1b979dbc03 100644 --- a/src/nvim/testdir/test_fold.vim +++ b/src/nvim/testdir/test_fold.vim @@ -72,6 +72,54 @@ func Test_address_fold() quit! endfunc +func Test_address_offsets() + " check the help for :range-closed-fold + enew + call setline(1, [ + \ '1 one', + \ '2 two', + \ '3 three', + \ '4 four FOLDED', + \ '5 five FOLDED', + \ '6 six', + \ '7 seven', + \ '8 eight', + \]) + set foldmethod=manual + normal 4Gvjzf + 3,4+2yank + call assert_equal([ + \ '3 three', + \ '4 four FOLDED', + \ '5 five FOLDED', + \ '6 six', + \ '7 seven', + \ ], getreg(0,1,1)) + + enew! + call setline(1, [ + \ '1 one', + \ '2 two', + \ '3 three FOLDED', + \ '4 four FOLDED', + \ '5 five FOLDED', + \ '6 six FOLDED', + \ '7 seven', + \ '8 eight', + \]) + normal 3Gv3jzf + 2,4-1yank + call assert_equal([ + \ '2 two', + \ '3 three FOLDED', + \ '4 four FOLDED', + \ '5 five FOLDED', + \ '6 six FOLDED', + \ ], getreg(0,1,1)) + + bwipe! +endfunc + func Test_indent_fold() new call setline(1, ['', 'a', ' b', ' c']) -- cgit From 2425fe2dc5e5985779912319433ddf914a20dd6a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 12 Nov 2022 09:57:29 +0800 Subject: vim-patch:8.2.2207: illegal memory access if popup menu items are changed (#21028) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Illegal memory access if popup menu items are changed while the menu is visible. (Tomáš Janoušek) Solution: Make a copy of the text. (closes vim/vim#7537) https://github.com/vim/vim/commit/38455a921395a56690790c8c1d28c1c43ca04c8a Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_popup.vim | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_popup.vim b/src/nvim/testdir/test_popup.vim index 0981329320..a9b258c5f5 100644 --- a/src/nvim/testdir/test_popup.vim +++ b/src/nvim/testdir/test_popup.vim @@ -871,18 +871,30 @@ func Test_popup_command() call assert_fails('popup Foo', 'E337:') unmenu Test.Foo + let script =<< trim END + func StartTimer() + call timer_start(100, {-> ChangeMenu()}) + endfunc + func ChangeMenu() + nunmenu PopUp.&Paste + nnoremenu 1.40 PopUp.&Paste :echomsg "pasted" + echomsg 'changed' + endfunc + END + call writefile(script, 'XtimerScript') + let lines =<< trim END one two three four five and one two Xthree four five one more two three four five END call writefile(lines, 'Xtest') - let buf = RunVimInTerminal('Xtest', {}) + let buf = RunVimInTerminal('-S XtimerScript Xtest', {}) call term_sendkeys(buf, ":source $VIMRUNTIME/menu.vim\") call term_sendkeys(buf, "/X\:popup PopUp\") call VerifyScreenDump(buf, 'Test_popup_command_01', {}) - " Select a word + " go to the Paste entry in the menu call term_sendkeys(buf, "jj") call VerifyScreenDump(buf, 'Test_popup_command_02', {}) @@ -891,8 +903,20 @@ func Test_popup_command() call VerifyScreenDump(buf, 'Test_popup_command_03', {}) call term_sendkeys(buf, "\") + + " Set a timer to change a menu entry while it's displayed. The text should + " not change but the command does. Making the screendump also verifies that + " "changed" shows up, which means the timer triggered + call term_sendkeys(buf, "/X\:call StartTimer() | popup PopUp\") + call VerifyScreenDump(buf, 'Test_popup_command_04', {}) + + " Select the Paste entry, executes the changed menu item. + call term_sendkeys(buf, "jj\") + call VerifyScreenDump(buf, 'Test_popup_command_05', {}) + call StopVimInTerminal(buf) call delete('Xtest') + call delete('XtimerScript') endfunc func Test_popup_complete_backwards() -- cgit From 7335a67b5754255f0e892303a0f4e3521035e7d8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 12 Nov 2022 12:29:16 +0800 Subject: vim-patch:9.0.0845: shell command with just space gives strange error (#21029) Problem: Shell command with just space gives strange error. Solution: Skip white space at start of the argument. (Christian Brabandt, Shane-XB-Qian, closes vim/vim#11515, closes vim/vim#11495) https://github.com/vim/vim/commit/4e7590ec00483077daaa567aa2220bc8df912f3c Co-authored-by: shane.xb.qian --- src/nvim/testdir/test_cmdline.vim | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index b0be7ab396..2921c8b41a 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -1628,6 +1628,53 @@ func Test_cmd_bang_E135() %bwipe! endfunc +func Test_cmd_bang_args() + new + :.! + call assert_equal(0, v:shell_error) + + " Note that below there is one space char after the '!'. This caused a + " shell error in the past, see https://github.com/vim/vim/issues/11495. + :.! + call assert_equal(0, v:shell_error) + bwipe! + + CheckUnix + :.!pwd + call assert_equal(0, v:shell_error) + :.! pwd + call assert_equal(0, v:shell_error) + + " Note there is one space after 'pwd'. + :.! pwd + call assert_equal(0, v:shell_error) + + " Note there are two spaces after 'pwd'. + :.! pwd + call assert_equal(0, v:shell_error) + :.!ls ~ + call assert_equal(0, v:shell_error) + + " Note there is one space char after '~'. + :.!ls ~ + call assert_equal(0, v:shell_error) + + " Note there are two spaces after '~'. + :.!ls ~ + call assert_equal(0, v:shell_error) + + :.!echo "foo" + call assert_equal(getline('.'), "foo") + :.!echo "foo " + call assert_equal(getline('.'), "foo ") + :.!echo " foo " + call assert_equal(getline('.'), " foo ") + :.!echo " foo " + call assert_equal(getline('.'), " foo ") + + %bwipe! +endfunc + " Test for using ~ for home directory in cmdline completion matches func Test_cmdline_expand_home() call mkdir('Xdir') -- cgit From 7abe8ef42267db861e84ce12023b296d49de6f25 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 12 Nov 2022 23:31:17 +0800 Subject: vim-patch:9.0.0862: default value of 'endoffile' is wrong (#21032) Problem: Default value of 'endoffile' is wrong. Solution: The default must be 'noendoffile'. https://github.com/vim/vim/commit/0aad88f073602849d1623122eb3c323f8e252def Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_options.vim | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index db544e47b8..11c2977a4e 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -1264,5 +1264,17 @@ func Test_keywordprg_empty() let &keywordprg = k endfunc +" check that the very first buffer created does not have 'endoffile' set +func Test_endoffile_default() + let after =<< trim [CODE] + call writefile([execute('set eof?')], 'Xtestout') + qall! + [CODE] + if RunVim([], after, '') + call assert_equal(["\nnoendoffile"], readfile('Xtestout')) + endif + call delete('Xtestout') +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 47ad4c8701b4233aa302c1c21ff08a5f223596c7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 13 Nov 2022 07:06:37 +0800 Subject: vim-patch:9.0.0866: no test for what patch 8.2.2207 fixes (#21034) Problem: No test for what patch 8.2.2207 fixes. Solution: Add a test case. (closes vim/vim#11531) https://github.com/vim/vim/commit/f7570f2107d91f35dc67dd0e400fc638585b226c --- src/nvim/testdir/test_popup.vim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_popup.vim b/src/nvim/testdir/test_popup.vim index a9b258c5f5..791cce4431 100644 --- a/src/nvim/testdir/test_popup.vim +++ b/src/nvim/testdir/test_popup.vim @@ -862,7 +862,6 @@ func Test_popup_position() endfunc func Test_popup_command() - CheckScreendump CheckFeature menu menu Test.Foo Foo @@ -870,13 +869,18 @@ func Test_popup_command() call assert_fails('popup Test.Foo.X', 'E327:') call assert_fails('popup Foo', 'E337:') unmenu Test.Foo +endfunc + +func Test_popup_command_dump() + CheckFeature menu + CheckScreendump let script =<< trim END func StartTimer() call timer_start(100, {-> ChangeMenu()}) endfunc func ChangeMenu() - nunmenu PopUp.&Paste + aunmenu PopUp.&Paste nnoremenu 1.40 PopUp.&Paste :echomsg "pasted" echomsg 'changed' endfunc -- cgit From bc1dbebe1f18df719b9e357f4d8b9bea3a3581b8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 13 Nov 2022 07:29:05 +0800 Subject: vim-patch:8.2.4676: test fails with different error Problem: Test fails with different error. Solution: Add argument for :elseif. https://github.com/vim/vim/commit/292e1b9f681054a1de8fa22315ae6eedd7acb205 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_vimscript.vim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index 44904af160..0fce52f88c 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -3024,7 +3024,7 @@ func Test_nested_if_else_errors() " :elseif without :if let code =<< trim END - elseif + elseif 1 END call writefile(code, 'Xtest') call AssertException(['source Xtest'], 'Vim(elseif):E582: :elseif without :if') @@ -3032,7 +3032,7 @@ func Test_nested_if_else_errors() " :elseif without :if let code =<< trim END while 1 - elseif + elseif 1 endwhile END call writefile(code, 'Xtest') @@ -3042,7 +3042,7 @@ func Test_nested_if_else_errors() let code =<< trim END try finally - elseif + elseif 1 endtry END call writefile(code, 'Xtest') @@ -3051,7 +3051,7 @@ func Test_nested_if_else_errors() " :elseif without :if let code =<< trim END try - elseif + elseif 1 endtry END call writefile(code, 'Xtest') @@ -3062,7 +3062,7 @@ func Test_nested_if_else_errors() try throw "a" catch /a/ - elseif + elseif 1 endtry END call writefile(code, 'Xtest') -- cgit From b25197258086faa94ddfaa2a74e1d0eb3695d9b3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 13 Nov 2022 07:24:44 +0800 Subject: vim-patch:9.0.0869: bogus error when string used after :elseif Problem: Bogus error when string used after :elseif. Solution: Do not consider a double quote the start of a comment. (closes vim/vim#11534) https://github.com/vim/vim/commit/28c56d501352bd98472d23667bade683877cadcc Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_vimscript.vim | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index 0fce52f88c..c93ba9dcfc 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -193,6 +193,16 @@ func Test_if_while() call assert_equal('ab3j3b2c2b1f1h1km', g:Xpath) endfunc +" Check double quote after skipped "elseif" does not give error E15 +func Test_skipped_elseif() + if "foo" ==? "foo" + let result = "first" + elseif "foo" ==? "foo" + let result = "second" + endif + call assert_equal('first', result) +endfunc + "------------------------------------------------------------------------------- " Test 4: :return {{{1 "------------------------------------------------------------------------------- -- cgit From 849394e4e26f487586761a3640475c27ceca30b9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 13 Nov 2022 08:29:05 +0800 Subject: vim-patch:9.0.0863: col() and charcol() only work for the current window (#21038) Problem: col() and charcol() only work for the current window. Solution: Add an optional winid argument. (Yegappan Lakshmanan, closes vim/vim#11466, closes vim/vim#11461) https://github.com/vim/vim/commit/4c8d2f02b3ce037bbe1d5ee12887e343c6bde88f Cherry-pick test_functions.vim change from patch 8.2.0633. Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_cursor_func.vim | 24 ++++++++++++++++++++++-- src/nvim/testdir/test_functions.vim | 12 ++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cursor_func.vim b/src/nvim/testdir/test_cursor_func.vim index 9801a45915..7f9e74e94b 100644 --- a/src/nvim/testdir/test_cursor_func.vim +++ b/src/nvim/testdir/test_cursor_func.vim @@ -241,8 +241,9 @@ endfunc " Test for the charcol() function func Test_charcol() - call assert_fails('call charcol({})', 'E731:') - call assert_equal(0, charcol(0)) + call assert_fails('call charcol({})', 'E1222:') + call assert_fails('call charcol(".", [])', 'E1210:') + call assert_fails('call charcol(0)', 'E1222:') new call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678']) @@ -298,6 +299,25 @@ func Test_charcol() call assert_equal([1, 10, 2, 10, 7], g:InsertCurrentCol) iunmap + " Test for getting the column number in another window. + let winid = win_getid() + new + call win_execute(winid, 'normal 1G') + call assert_equal(1, charcol('.', winid)) + call assert_equal(1, charcol('$', winid)) + call win_execute(winid, 'normal 2G6l') + call assert_equal(7, charcol('.', winid)) + call assert_equal(10, charcol('$', winid)) + + " calling from another tab page also works + tabnew + call assert_equal(7, charcol('.', winid)) + call assert_equal(10, charcol('$', winid)) + tabclose + + " unknown window ID + call assert_equal(0, charcol('.', 10001)) + %bw! endfunc diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index aaef01bdf5..5ff544ab55 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1288,6 +1288,9 @@ func Test_col() call assert_equal(0, col([2, '$'])) call assert_equal(0, col([1, 100])) call assert_equal(0, col([1])) + call assert_equal(0, col(v:_null_list)) + call assert_fails('let c = col({})', 'E1222:') + call assert_fails('let c = col(".", [])', 'E1210:') " test for getting the visual start column func T() @@ -1317,6 +1320,15 @@ func Test_col() call assert_equal(4, col('.')) set virtualedit& + " Test for getting the column number in another window + let winid = win_getid() + new + call win_execute(winid, 'normal 1G$') + call assert_equal(3, col('.', winid)) + call win_execute(winid, 'normal 2G') + call assert_equal(8, col('$', winid)) + call assert_equal(0, col('.', 5001)) + bw! endfunc -- cgit From 9d7dc5062877bd7e035f1f7a74e2462c2e942864 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 13 Nov 2022 08:35:15 +0800 Subject: vim-patch:9.0.0865: duplicate arguments are not always detected (#21036) Problem: Duplicate arguments are not always detected. Solution: Expand to full path before comparing arguments. (Nir Lichtman, closes vim/vim#11505, closes vim/vim#9402) https://github.com/vim/vim/commit/b3052aa1b555ab5a81b1459a4972290381b0e7e4 Co-authored-by: Nir Lichtman --- src/nvim/testdir/test_arglist.vim | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_arglist.vim b/src/nvim/testdir/test_arglist.vim index cae71e10f3..fb8b17cd16 100644 --- a/src/nvim/testdir/test_arglist.vim +++ b/src/nvim/testdir/test_arglist.vim @@ -418,15 +418,19 @@ func Test_argdedupe() call Reset_arglist() argdedupe call assert_equal([], argv()) + args a a a aa b b a b aa argdedupe call assert_equal(['a', 'aa', 'b'], argv()) + args a b c argdedupe call assert_equal(['a', 'b', 'c'], argv()) + args a argdedupe call assert_equal(['a'], argv()) + args a A b B argdedupe if has('fname_case') @@ -434,11 +438,17 @@ func Test_argdedupe() else call assert_equal(['a', 'b'], argv()) endif + args a b a c a b last argdedupe next call assert_equal('c', expand('%:t')) + + args a ./a + argdedupe + call assert_equal(['a'], argv()) + %argd endfunc -- cgit From f2695919bbc4ffea894a54c1d48632ebf0d543a9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 14 Nov 2022 08:16:29 +0800 Subject: test(old): add missing lines from Vim patch 8.2.0522 (#21048) --- src/nvim/testdir/test_highlight.vim | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_highlight.vim b/src/nvim/testdir/test_highlight.vim index 2be82f4e3c..d618637d63 100644 --- a/src/nvim/testdir/test_highlight.vim +++ b/src/nvim/testdir/test_highlight.vim @@ -741,8 +741,18 @@ endfunc " Test for :highlight command errors func Test_highlight_cmd_errors() if has('gui_running') || has('nvim') + " This test doesn't fail in the MS-Windows console version. + call assert_fails('hi Xcomment ctermfg=fg', 'E419:') + call assert_fails('hi Xcomment ctermfg=bg', 'E420:') call assert_fails('hi ' .. repeat('a', 201) .. ' ctermfg=black', 'E1249:') endif + + " Try using a very long terminal code. Define a dummy terminal code for this + " test. + let &t_fo = "\1;" + let c = repeat("t_fo,", 100) . "t_fo" + " call assert_fails('exe "hi Xgroup1 start=" . c', 'E422:') + let &t_fo = "" endfunc " Test for using RGB color values in a highlight group -- cgit From 74399738510cb880507cba14f71acc0a96e14327 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 15 Nov 2022 07:58:22 +0800 Subject: vim-patch:9.0.0882: using freed memory after SpellFileMissing autocmd uses bwipe (#21060) Problem: Using freed memory after SpellFileMissing autocmd uses bwipe. Solution: Bail out if the window no longer exists. https://github.com/vim/vim/commit/c3d27ada14acd02db357f2d16347acc22cb17e93 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_spell.vim | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_spell.vim b/src/nvim/testdir/test_spell.vim index ea18fc5194..a919156066 100644 --- a/src/nvim/testdir/test_spell.vim +++ b/src/nvim/testdir/test_spell.vim @@ -159,6 +159,19 @@ func Test_spell_file_missing() %bwipe! endfunc +func Test_spell_file_missing_bwipe() + " this was using a window that was wiped out in a SpellFileMissing autocmd + set spelllang=xy + au SpellFileMissing * n0 + set spell + au SpellFileMissing * bw + snext somefile + + au! SpellFileMissing + bwipe! + set nospell spelllang=en +endfunc + func Test_spelldump() " In case the spell file is not found avoid getting the download dialog, we " would get stuck at the prompt. -- cgit From c70d90dbfdf67bb009d2976a5d0760be4010e533 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 15 Nov 2022 23:02:48 +0800 Subject: vim-patch:9.0.0884: mouse shape remains in op-pending mode after failed change (#21066) Problem: Mouse shape remains in op-pending mode after failed change. Solution: Reset finish_op and restore it. (closes vim/vim#11545) https://github.com/vim/vim/commit/cdeb65729d96c90320b9009e583ade305c396f29 --- src/nvim/testdir/test_normal.vim | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index 0d75644920..e5756bd505 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -3713,4 +3713,37 @@ func Test_normal_count_out_of_range() bwipe! endfunc +" Test that mouse shape is restored to Normal mode after failed "c" operation. +func Test_mouse_shape_after_failed_change() + CheckFeature mouseshape + CheckCanRunGui + + let lines =<< trim END + set mouseshape+=o:busy + setlocal nomodifiable + let g:mouse_shapes = [] + + func SaveMouseShape(timer) + let g:mouse_shapes += [getmouseshape()] + endfunc + + func SaveAndQuit(timer) + call writefile(g:mouse_shapes, 'Xmouseshapes') + quit + endfunc + + call timer_start(50, {_ -> feedkeys('c')}) + call timer_start(100, 'SaveMouseShape') + call timer_start(150, {_ -> feedkeys('c')}) + call timer_start(200, 'SaveMouseShape') + call timer_start(250, 'SaveAndQuit') + END + call writefile(lines, 'Xmouseshape.vim', 'D') + call RunVim([], [], "-g -S Xmouseshape.vim") + sleep 300m + call assert_equal(['busy', 'arrow'], readfile('Xmouseshapes')) + + call delete('Xmouseshapes') +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From ed27f0e93e177ffca1def9c64fdfc8c390a2dadd Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 07:51:04 +0800 Subject: vim-patch:9.0.0300: 'cpoptions' tests are flaky (#21081) Problem: 'cpoptions' tests are flaky. Solution: Use a different file name for each test. https://github.com/vim/vim/commit/a85e4db9780a4cf7a72cbb98c7127922f668cdf6 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_cpoptions.vim | 76 ++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 38 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cpoptions.vim b/src/nvim/testdir/test_cpoptions.vim index ef51d955f1..b9307ab30b 100644 --- a/src/nvim/testdir/test_cpoptions.vim +++ b/src/nvim/testdir/test_cpoptions.vim @@ -8,19 +8,19 @@ source view_util.vim " file name. func Test_cpo_a() let save_cpo = &cpo - call writefile(['one'], 'Xfile') + call writefile(['one'], 'XfileCpoA') " Wipe out all the buffers, so that the alternate file is empty edit Xfoo | %bw set cpo-=a new - read Xfile + read XfileCpoA call assert_equal('', @#) %d set cpo+=a - read Xfile - call assert_equal('Xfile', @#) + read XfileCpoA + call assert_equal('XfileCpoA', @#) close! - call delete('Xfile') + call delete('XfileCpoA') let &cpo = save_cpo endfunc @@ -99,31 +99,31 @@ endfunc " Test for the 'C' flag in 'cpo' (line continuation) func Test_cpo_C() let save_cpo = &cpo - call writefile(['let l = [', '\ 1,', '\ 2]'], 'Xfile') + call writefile(['let l = [', '\ 1,', '\ 2]'], 'XfileCpoC') set cpo-=C - source Xfile + source XfileCpoC call assert_equal([1, 2], g:l) set cpo+=C - call assert_fails('source Xfile', ['E697:', 'E10:']) - call delete('Xfile') + call assert_fails('source XfileCpoC', ['E697:', 'E10:']) + call delete('XfileCpoC') let &cpo = save_cpo endfunc " Test for the 'd' flag in 'cpo' (tags relative to the current file) func Test_cpo_d() let save_cpo = &cpo - call mkdir('Xdir') + call mkdir('XdirCpoD') call writefile(["one\tXfile1\t/^one$/"], 'tags') - call writefile(["two\tXfile2\t/^two$/"], 'Xdir/tags') + call writefile(["two\tXfile2\t/^two$/"], 'XdirCpoD/tags') set tags=./tags set cpo-=d - edit Xdir/Xfile + edit XdirCpoD/Xfile call assert_equal('two', taglist('.*')[0].name) set cpo+=d call assert_equal('one', taglist('.*')[0].name) %bw! call delete('tags') - call delete('Xdir', 'rf') + call delete('XdirCpoD', 'rf') set tags& let &cpo = save_cpo endfunc @@ -204,14 +204,14 @@ func Test_cpo_F() let save_cpo = &cpo new set cpo-=F - write Xfile + write XfileCpoF call assert_equal('', @%) - call delete('Xfile') + call delete('XfileCpoF') set cpo+=F - write Xfile - call assert_equal('Xfile', @%) + write XfileCpoF + call assert_equal('XfileCpoF', @%) close! - call delete('Xfile') + call delete('XfileCpoF') let &cpo = save_cpo endfunc @@ -415,16 +415,16 @@ endfunc " Test for the 'O' flag in 'cpo' (overwriting an existing file) func Test_cpo_O() let save_cpo = &cpo - new Xfile + new XfileCpoO call setline(1, 'one') - call writefile(['two'], 'Xfile') + call writefile(['two'], 'XfileCpoO') set cpo-=O call assert_fails('write', 'E13:') set cpo+=O write - call assert_equal(['one'], readfile('Xfile')) + call assert_equal(['one'], readfile('XfileCpoO')) close! - call delete('Xfile') + call delete('XfileCpoO') let &cpo = save_cpo endfunc @@ -434,18 +434,18 @@ endfunc " name) func Test_cpo_P() let save_cpo = &cpo - call writefile([], 'Xfile') + call writefile([], 'XfileCpoP') new call setline(1, 'one') set cpo+=F set cpo-=P - write >> Xfile + write >> XfileCpoP call assert_equal('', @%) set cpo+=P - write >> Xfile - call assert_equal('Xfile', @%) + write >> XfileCpoP + call assert_equal('XfileCpoP', @%) close! - call delete('Xfile') + call delete('XfileCpoP') let &cpo = save_cpo endfunc @@ -638,8 +638,8 @@ endfunc " Test for the 'Z' flag in 'cpo' (write! resets 'readonly') func Test_cpo_Z() let save_cpo = &cpo - call writefile([], 'Xfile') - new Xfile + call writefile([], 'XfileCpoZ') + new XfileCpoZ setlocal readonly set cpo-=Z write! @@ -649,7 +649,7 @@ func Test_cpo_Z() write! call assert_equal(1, &readonly) close! - call delete('Xfile') + call delete('XfileCpoZ') let &cpo = save_cpo endfunc @@ -728,8 +728,8 @@ endfunc " flag) func Test_cpo_plus() let save_cpo = &cpo - call writefile([], 'Xfile') - new Xfile + call writefile([], 'XfileCpoPlus') + new XfileCpoPlus call setline(1, 'foo') write X1 call assert_equal(1, &modified) @@ -737,7 +737,7 @@ func Test_cpo_plus() write X2 call assert_equal(0, &modified) close! - call delete('Xfile') + call delete('XfileCpoPlus') call delete('X1') call delete('X2') let &cpo = save_cpo @@ -843,17 +843,17 @@ endfunc " loaded and ':preserve' is used. func Test_cpo_ampersand() throw 'Skipped: Nvim does not support cpoptions flag "&"' - call writefile(['one'], 'Xfile') + call writefile(['one'], 'XfileCpoAmp') let after =<< trim [CODE] set cpo+=& preserve qall [CODE] - if RunVim([], after, 'Xfile') - call assert_equal(1, filereadable('.Xfile.swp')) - call delete('.Xfile.swp') + if RunVim([], after, 'XfileCpoAmp') + call assert_equal(1, filereadable('.XfileCpoAmp.swp')) + call delete('.XfileCpoAmp.swp') endif - call delete('Xfile') + call delete('XfileCpoAmp') endfunc " Test for the '\' flag in 'cpo' (backslash in a [] range in a search pattern) -- cgit From 98bcf49d2692af1f2c21f6d10fd056855d4ea238 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 17:34:13 +0800 Subject: vim-patch:8.2.1260: there is no good test for CursorHold (#21086) Problem: There is no good test for CursorHold. Solution: Add a test. Remove duplicated test. (Yegappan Lakshmanan, closes vim/vim#6503 https://github.com/vim/vim/commit/7591116acffc45b5880c49244646651badac1629 --- src/nvim/testdir/test_autocmd.vim | 31 ++++++++++++++++++++++++++++++- src/nvim/testdir/test_buffer.vim | 9 --------- src/nvim/testdir/test_normal.vim | 18 ------------------ 3 files changed, 30 insertions(+), 28 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index f4c32599f1..fb8adbb3a6 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -4,6 +4,7 @@ source shared.vim source check.vim source term_util.vim source screendump.vim +source load.vim func s:cleanup_buffers() abort for bnr in range(1, bufnr('$')) @@ -20,8 +21,36 @@ func Test_vim_did_enter() " becomes one. endfunc +" Test for the CursorHold autocmd +func Test_CursorHold_autocmd() + CheckRunVimInTerminal + call writefile(['one', 'two', 'three'], 'Xfile') + let before =<< trim END + set updatetime=10 + au CursorHold * call writefile([line('.')], 'Xoutput', 'a') + END + call writefile(before, 'Xinit') + let buf = RunVimInTerminal('-S Xinit Xfile', {}) + call term_wait(buf) + call term_sendkeys(buf, "gg") + call term_wait(buf) + sleep 50m + call term_sendkeys(buf, "j") + call term_wait(buf) + sleep 50m + call term_sendkeys(buf, "j") + call term_wait(buf) + sleep 50m + call StopVimInTerminal(buf) + + call assert_equal(['1', '2', '3'], readfile('Xoutput')[-3:-1]) + + call delete('Xinit') + call delete('Xoutput') + call delete('Xfile') +endfunc + if has('timers') - source load.vim func ExitInsertMode(id) call feedkeys("\") diff --git a/src/nvim/testdir/test_buffer.vim b/src/nvim/testdir/test_buffer.vim index 3300278802..549aa691c8 100644 --- a/src/nvim/testdir/test_buffer.vim +++ b/src/nvim/testdir/test_buffer.vim @@ -67,15 +67,6 @@ func Test_bunload_with_offset() call assert_fails('1,4bunload', 'E16:') call assert_fails(',100bunload', 'E16:') - " Use a try-catch for this test. When assert_fails() is used for this - " test, the command fails with E515: instead of E90: - let caught_E90 = 0 - try - $bunload - catch /E90:/ - let caught_E90 = 1 - endtry - call assert_equal(1, caught_E90) call assert_fails('$bunload', 'E90:') endfunc diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index e5756bd505..83709420bf 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -3001,24 +3001,6 @@ func Test_normal47_visual_buf_wipe() set nomodified endfunc -func Test_normal47_autocmd() - " disabled, does not seem to be possible currently - throw "Skipped: not possible to test cursorhold autocmd while waiting for input in normal_cmd" - new - call append(0, repeat('-',20)) - au CursorHold * call feedkeys('2l', '') - 1 - set updatetime=20 - " should delete 12 chars (d12l) - call feedkeys('d1', '!') - call assert_equal('--------', getline(1)) - - " clean up - au! CursorHold - set updatetime=4000 - bw! -endfunc - func Test_normal48_wincmd() new exe "norm! \c" -- cgit From abe1dd308e1f37bb9b06a85da82e066135b86ff9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 18:13:13 +0800 Subject: vim-patch:8.2.1970: it is easy to make mistakes when cleaning up swap files Problem: It is easy to make mistakes when cleaning up swap files after the system crashed. Solution: Warn for the process still running after recovery. Do not automatically delete a swap file created on another system. (David Fries, closes vim/vim#7273) https://github.com/vim/vim/commit/f883508e36c209d60388b944e04e22a3fcf603cf --- src/nvim/testdir/test_swap.vim | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_swap.vim b/src/nvim/testdir/test_swap.vim index 34d1d585ce..7941f78ced 100644 --- a/src/nvim/testdir/test_swap.vim +++ b/src/nvim/testdir/test_swap.vim @@ -421,6 +421,52 @@ func Test_swap_symlink() call delete('Xswapdir', 'rf') endfunc +func Test_swap_auto_delete() + " Create a valid swapfile by editing a file with a special extension. + split Xtest.scr + call setline(1, ['one', 'two', 'three']) + write " file is written, not modified + write " write again to make sure the swapfile is created + " read the swapfile as a Blob + let swapfile_name = swapname('%') + let swapfile_bytes = readfile(swapfile_name, 'B') + + " Forget about the file, recreate the swap file, then edit it again. The + " swap file should be automatically deleted. + bwipe! + " change the process ID to avoid the "still running" warning + let swapfile_bytes[24] = 0x99 + call writefile(swapfile_bytes, swapfile_name) + edit Xtest.scr + " will end up using the same swap file after deleting the existing one + call assert_equal(swapfile_name, swapname('%')) + bwipe! + + " create the swap file again, but change the host name so that it won't be + " deleted + autocmd! SwapExists + augroup test_swap_recover_ext + autocmd! + autocmd SwapExists * let v:swapchoice = 'e' + augroup END + + " change the host name + let swapfile_bytes[28 + 40] = 0x89 + call writefile(swapfile_bytes, swapfile_name) + edit Xtest.scr + call assert_equal(1, filereadable(swapfile_name)) + " will use another same swap file name + call assert_notequal(swapfile_name, swapname('%')) + bwipe! + + call delete('Xtest.scr') + call delete(swapfile_name) + augroup test_swap_recover_ext + autocmd! + augroup END + augroup! test_swap_recover_ext +endfunc + func Test_no_swap_file() call assert_equal("\nNo swap file", execute('swapname')) endfunc -- cgit From f97d88a58a2d3e010d9de75815fb89b9cc7b8a3c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 18:20:54 +0800 Subject: vim-patch:8.2.2016: swap file test is a little flaky Problem: Swap file test is a little flaky. Solution: Don't set a byte to a fixed value, increment it. https://github.com/vim/vim/commit/c6ca9f3a29bfd6f5269749036f79f63ce6289692 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_swap.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_swap.vim b/src/nvim/testdir/test_swap.vim index 7941f78ced..4ab2e0df10 100644 --- a/src/nvim/testdir/test_swap.vim +++ b/src/nvim/testdir/test_swap.vim @@ -435,7 +435,7 @@ func Test_swap_auto_delete() " swap file should be automatically deleted. bwipe! " change the process ID to avoid the "still running" warning - let swapfile_bytes[24] = 0x99 + let swapfile_bytes[24] = swapfile_bytes[24] + 1 call writefile(swapfile_bytes, swapfile_name) edit Xtest.scr " will end up using the same swap file after deleting the existing one @@ -451,7 +451,7 @@ func Test_swap_auto_delete() augroup END " change the host name - let swapfile_bytes[28 + 40] = 0x89 + let swapfile_bytes[28 + 40] = swapfile_bytes[28 + 40] + 2 call writefile(swapfile_bytes, swapfile_name) edit Xtest.scr call assert_equal(1, filereadable(swapfile_name)) -- cgit From 1b95eaf84bdc5189b435fe98b365b5f120d99c2d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 18:23:38 +0800 Subject: vim-patch:8.2.2019: swap file test fails on MS-Windows Problem: Swap file test fails on MS-Windows. Solution: Add four to the process ID. (Ken Takata, closes vim/vim#7333) https://github.com/vim/vim/commit/80d868ec25094615f2531a1e01ed1e729366c3bc --- src/nvim/testdir/test_swap.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_swap.vim b/src/nvim/testdir/test_swap.vim index 4ab2e0df10..22a4a17c39 100644 --- a/src/nvim/testdir/test_swap.vim +++ b/src/nvim/testdir/test_swap.vim @@ -434,8 +434,9 @@ func Test_swap_auto_delete() " Forget about the file, recreate the swap file, then edit it again. The " swap file should be automatically deleted. bwipe! - " change the process ID to avoid the "still running" warning - let swapfile_bytes[24] = swapfile_bytes[24] + 1 + " Change the process ID to avoid the "still running" warning. Must add four + " for MS-Windows to see it as a different one. + let swapfile_bytes[24] = swapfile_bytes[24] + 4 call writefile(swapfile_bytes, swapfile_name) edit Xtest.scr " will end up using the same swap file after deleting the existing one -- cgit From 1fe526184f155bbda5d0d3037d683fd935b57c35 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 18:24:50 +0800 Subject: vim-patch:8.2.2044: MS-Windows: swap file test sometimes fails Problem: MS-Windows: swap file test sometimes fails. Solution: Use a more reliable way to change the process ID. When "timeout" fails use "ping" to wait up to ten minutes. (Ken Takata, closes vim/vim#7365) https://github.com/vim/vim/commit/5ee0981fb5259f94900ab25207caddf1fa61010d --- src/nvim/testdir/test_swap.vim | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_swap.vim b/src/nvim/testdir/test_swap.vim index 22a4a17c39..958e4f814f 100644 --- a/src/nvim/testdir/test_swap.vim +++ b/src/nvim/testdir/test_swap.vim @@ -421,6 +421,39 @@ func Test_swap_symlink() call delete('Xswapdir', 'rf') endfunc +func s:get_unused_pid(base) + if has('job') + " Execute 'echo' as a temporary job, and return its pid as an unused pid. + if has('win32') + let cmd = 'cmd /c echo' + else + let cmd = 'echo' + endif + let j = job_start(cmd) + while job_status(j) ==# 'run' + sleep 10m + endwhile + if job_status(j) ==# 'dead' + return job_info(j).process + endif + endif + " Must add four for MS-Windows to see it as a different one. + return a:base + 4 +endfunc + +func s:blob_to_pid(b) + return a:b[3] * 16777216 + a:b[2] * 65536 + a:b[1] * 256 + a:b[0] +endfunc + +func s:pid_to_blob(i) + let b = 0z + let b[0] = and(a:i, 0xff) + let b[1] = and(a:i / 256, 0xff) + let b[2] = and(a:i / 65536, 0xff) + let b[3] = and(a:i / 16777216, 0xff) + return b +endfunc + func Test_swap_auto_delete() " Create a valid swapfile by editing a file with a special extension. split Xtest.scr @@ -434,9 +467,9 @@ func Test_swap_auto_delete() " Forget about the file, recreate the swap file, then edit it again. The " swap file should be automatically deleted. bwipe! - " Change the process ID to avoid the "still running" warning. Must add four - " for MS-Windows to see it as a different one. - let swapfile_bytes[24] = swapfile_bytes[24] + 4 + " Change the process ID to avoid the "still running" warning. + let swapfile_bytes[24:27] = s:pid_to_blob(s:get_unused_pid( + \ s:blob_to_pid(swapfile_bytes[24:27]))) call writefile(swapfile_bytes, swapfile_name) edit Xtest.scr " will end up using the same swap file after deleting the existing one -- cgit From 78998bc6c6dcd6945e39f427520f6851707eb344 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 18:44:13 +0800 Subject: vim-patch:8.2.3042: swap file test fails Problem: Swap file test fails. Solution: Check for a very high process ID instead of one, which should be running. https://github.com/vim/vim/commit/6738fd2000f0bea4d40f4a8651e0e1f4b0503bb3 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_swap.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_swap.vim b/src/nvim/testdir/test_swap.vim index 958e4f814f..284579b084 100644 --- a/src/nvim/testdir/test_swap.vim +++ b/src/nvim/testdir/test_swap.vim @@ -203,8 +203,8 @@ func Test_swapfile_delete() " This test won't work as root because root can successfully run kill(1, 0) if !IsRoot() " Write the swapfile with a modified PID, now it will be automatically - " deleted. Process one should never be Vim. - let swapfile_bytes[24:27] = 0z01000000 + " deleted. Process 0x3fffffff most likely does not exist. + let swapfile_bytes[24:27] = 0zffffff3f call writefile(swapfile_bytes, swapfile_name) let s:swapname = '' split XswapfileText -- cgit From ec5c1c35c2b2477d79c20594a6fe64fe1d18ed36 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 19:57:16 +0800 Subject: vim-patch:8.2.2586: process id may be invalid Problem: Process id may be invalid. Solution: Use sysinfo.uptime to check for recent reboot. (suggested by Hugo van der Sanden, closes vim/vim#7947) https://github.com/vim/vim/commit/f52f0606ed9ea19bcfc3a8343af9958f2d99eaf7 test_override() is N/A. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_recover.vim | 79 ++++++++++++++++++++++++++++++++++----- 1 file changed, 70 insertions(+), 9 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_recover.vim b/src/nvim/testdir/test_recover.vim index fc073cacd2..c3bdde0d71 100644 --- a/src/nvim/testdir/test_recover.vim +++ b/src/nvim/testdir/test_recover.vim @@ -1,5 +1,7 @@ " Test :recover +source check.vim + func Test_recover_root_dir() " This used to access invalid memory. split Xtest @@ -23,6 +25,21 @@ func Test_recover_root_dir() set dir& endfunc +" Make a copy of the current swap file to "Xswap". +" Return the name of the swap file. +func CopySwapfile() + preserve + " get the name of the swap file + let swname = split(execute("swapname"))[0] + let swname = substitute(swname, '[[:blank:][:cntrl:]]*\(.\{-}\)[[:blank:][:cntrl:]]*$', '\1', '') + " make a copy of the swap file in Xswap + set binary + exe 'sp ' . swname + w! Xswap + set nobinary + return swname +endfunc + " Inserts 10000 lines with text to fill the swap file with two levels of pointer " blocks. Then recovers from the swap file and checks all text is restored. " @@ -40,15 +57,9 @@ func Test_swap_file() let i += 1 endwhile $delete - preserve - " get the name of the swap file - let swname = split(execute("swapname"))[0] - let swname = substitute(swname, '[[:blank:][:cntrl:]]*\(.\{-}\)[[:blank:][:cntrl:]]*$', '\1', '') - " make a copy of the swap file in Xswap - set binary - exe 'sp ' . swname - w! Xswap - set nobinary + + let swname = CopySwapfile() + new only! bwipe! Xtest @@ -69,3 +80,53 @@ func Test_swap_file() set undolevels& enew! | only endfunc + +func Test_nocatch_process_still_running() + " assume Unix means sysinfo.uptime can be used + CheckUnix + CheckNotGui + + " don't intercept existing swap file here + au! SwapExists + + " Edit a file and grab its swapfile. + edit Xswaptest + call setline(1, ['a', 'b', 'c']) + let swname = CopySwapfile() + + " Forget we edited this file + new + only! + bwipe! Xswaptest + + call rename('Xswap', swname) + call feedkeys('e', 'tL') + redir => editOutput + edit Xswaptest + redir END + call assert_match('E325: ATTENTION', editOutput) + call assert_match('file name: .*Xswaptest', editOutput) + call assert_match('process ID: \d* (STILL RUNNING)', editOutput) + + " Forget we edited this file + new + only! + bwipe! Xswaptest + + " pretend we rebooted + call test_override("uptime", 0) + sleep 1 + + call rename('Xswap', swname) + call feedkeys('e', 'tL') + redir => editOutput + edit Xswaptest + redir END + call assert_match('E325: ATTENTION', editOutput) + call assert_notmatch('(STILL RUNNING)', editOutput) + + call test_override("ALL", 0) + call delete(swname) +endfunc + +" vim: shiftwidth=2 sts=2 expandtab -- cgit From 1ab08e23b3ba8fed10323ef5572c48413cfa7d96 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 20:18:20 +0800 Subject: vim-patch:8.2.2587: recover test fails on FreeBSD Problem: Recover test fails on FreeBSD. Solution: Check for Linux. https://github.com/vim/vim/commit/6635ae1437e6e343c0514524a8dfb19d9525b908 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/check.vim | 8 ++++++++ src/nvim/testdir/test_recover.vim | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/check.vim b/src/nvim/testdir/check.vim index 8a1080a2f3..61d3a99a67 100644 --- a/src/nvim/testdir/check.vim +++ b/src/nvim/testdir/check.vim @@ -90,6 +90,14 @@ func CheckUnix() endif endfunc +" Command to check for running on Linux +command CheckLinux call CheckLinux() +func CheckLinux() + if !has('linux') + throw 'Skipped: only works on Linux' + endif +endfunc + " Command to check that making screendumps is supported. " Caller must source screendump.vim command CheckScreendump call CheckScreendump() diff --git a/src/nvim/testdir/test_recover.vim b/src/nvim/testdir/test_recover.vim index c3bdde0d71..60e0fde29e 100644 --- a/src/nvim/testdir/test_recover.vim +++ b/src/nvim/testdir/test_recover.vim @@ -82,8 +82,9 @@ func Test_swap_file() endfunc func Test_nocatch_process_still_running() - " assume Unix means sysinfo.uptime can be used - CheckUnix + " sysinfo.uptime probably only works on Linux + CheckLinux + " the GUI dialog can't be handled CheckNotGui " don't intercept existing swap file here -- cgit From 5176ed88f675e839a87dab0a2d20c3bd0269514b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 20:21:10 +0800 Subject: vim-patch:8.2.2589: recover test hangs in the GUI Problem: Recover test hangs in the GUI. Solution: Add g:skipped_reason to skip a _nocatch_ test. https://github.com/vim/vim/commit/776b954622b45125dfdcb4a61243ca90956b0825 Now always skip the test as test_override() is N/A. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/runtest.vim | 5 +++++ src/nvim/testdir/test_recover.vim | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim index ce23141c7a..a1b04a4601 100644 --- a/src/nvim/testdir/runtest.vim +++ b/src/nvim/testdir/runtest.vim @@ -174,7 +174,12 @@ func RunTheTest(test) if a:test =~ 'Test_nocatch_' " Function handles errors itself. This avoids skipping commands after the " error. + let g:skipped_reason = '' exe 'call ' . a:test + if g:skipped_reason != '' + call add(s:messages, ' Skipped') + call add(s:skipped, 'SKIPPED ' . a:test . ': ' . g:skipped_reason) + endif else try let s:test = a:test diff --git a/src/nvim/testdir/test_recover.vim b/src/nvim/testdir/test_recover.vim index 60e0fde29e..9de4ddc546 100644 --- a/src/nvim/testdir/test_recover.vim +++ b/src/nvim/testdir/test_recover.vim @@ -82,10 +82,18 @@ func Test_swap_file() endfunc func Test_nocatch_process_still_running() + let g:skipped_reason = 'test_override() is N/A' + return " sysinfo.uptime probably only works on Linux - CheckLinux + if !has('linux') + let g:skipped_reason = 'only works on Linux' + return + endif " the GUI dialog can't be handled - CheckNotGui + if has('gui_running') + let g:skipped_reason = 'only works in the terminal' + return + endif " don't intercept existing swap file here au! SwapExists -- cgit From 3f75f25f9c077a284aedab09c5813d887a62f464 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 22:40:10 +0800 Subject: vim-patch:8.2.2945: some buffer related code is not tested Problem: Some buffer related code is not tested. Solution: Add a few more tests. (Yegappan Lakshmanan, closes vim/vim#8320) https://github.com/vim/vim/commit/59b262362f26b3aaea1eeb0078adc33eed59863e Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_excmd.vim | 8 +++ src/nvim/testdir/test_recover.vim | 127 ++++++++++++++++++++++++++++++++++++++ src/nvim/testdir/test_swap.vim | 75 ++++++++++++++++++++++ 3 files changed, 210 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_excmd.vim b/src/nvim/testdir/test_excmd.vim index 42b1f8ca48..44bed890f5 100644 --- a/src/nvim/testdir/test_excmd.vim +++ b/src/nvim/testdir/test_excmd.vim @@ -78,6 +78,14 @@ func Test_file_cmd() call assert_fails('3file', 'E474:') call assert_fails('0,0file', 'E474:') call assert_fails('0file abc', 'E474:') + if !has('win32') + " Change the name of the buffer to the same name + new Xfile1 + file Xfile1 + call assert_equal('Xfile1', @%) + call assert_equal('Xfile1', @#) + bw! + endif endfunc " Test for the :drop command diff --git a/src/nvim/testdir/test_recover.vim b/src/nvim/testdir/test_recover.vim index 9de4ddc546..61d8684033 100644 --- a/src/nvim/testdir/test_recover.vim +++ b/src/nvim/testdir/test_recover.vim @@ -138,4 +138,131 @@ func Test_nocatch_process_still_running() call delete(swname) endfunc +" Test for :recover with multiple swap files +func Test_recover_multiple_swap_files() + CheckUnix + new Xfile1 + call setline(1, ['a', 'b', 'c']) + preserve + let b = readblob('.Xfile1.swp') + call writefile(b, '.Xfile1.swm') + call writefile(b, '.Xfile1.swn') + call writefile(b, '.Xfile1.swo') + %bw! + call feedkeys(":recover Xfile1\3\q", 'xt') + call assert_equal(['a', 'b', 'c'], getline(1, '$')) + + call delete('.Xfile1.swm') + call delete('.Xfile1.swn') + call delete('.Xfile1.swo') +endfunc + +" Test for :recover using an empty swap file +func Test_recover_empty_swap_file() + CheckUnix + call writefile([], '.Xfile1.swp') + let msg = execute('recover Xfile1') + call assert_match('Unable to read block 0 from .Xfile1.swp', msg) + call assert_equal('Xfile1', @%) + bw! + " :recover from an empty buffer + call assert_fails('recover', 'E305:') + call delete('.Xfile1.swp') +endfunc + +" Test for :recover using a corrupted swap file +func Test_recover_corrupted_swap_file() + CheckUnix + " recover using a partial swap file + call writefile(0z1234, '.Xfile1.swp') + call assert_fails('recover Xfile1', 'E295:') + bw! + + " recover using invalid content in the swap file + call writefile([repeat('1', 2*1024)], '.Xfile1.swp') + call assert_fails('recover Xfile1', 'E307:') + call delete('.Xfile1.swp') + + " :recover using a swap file with a corrupted header + edit Xfile1 + preserve + let sn = swapname('') + let b = readblob(sn) + bw! + " clear the B0_MAGIC_LONG field + let b[1008:1011] = 0z00000000 + call writefile(b, sn) + let msg = execute('recover Xfile1') + call assert_match('the file has been damaged', msg) + bw! + call delete(sn) +endfunc + +" Test for :recover using an encrypted swap file +func Test_recover_encrypted_swap_file() + CheckUnix + + " Recover an encrypted file from the swap file without the original file + new Xfile1 + call feedkeys(":X\vim\vim\", 'xt') + call setline(1, ['aaa', 'bbb', 'ccc']) + preserve + let b = readblob('.Xfile1.swp') + call writefile(b, '.Xfile1.swm') + bw! + call feedkeys(":recover Xfile1\vim\\", 'xt') + call assert_equal(['aaa', 'bbb', 'ccc'], getline(1, '$')) + bw! + call delete('.Xfile1.swm') + + " Recover an encrypted file from the swap file with the original file + new Xfile1 + call feedkeys(":X\vim\vim\", 'xt') + call setline(1, ['aaa', 'bbb', 'ccc']) + update + call setline(1, ['111', '222', '333']) + preserve + let b = readblob('.Xfile1.swp') + call writefile(b, '.Xfile1.swm') + bw! + call feedkeys(":recover Xfile1\vim\\", 'xt') + call assert_equal(['111', '222', '333'], getline(1, '$')) + call assert_true(&modified) + bw! + call delete('.Xfile1.swm') + call delete('Xfile1') +endfunc + +" Test for :recover using a unreadable swap file +func Test_recover_unreadble_swap_file() + CheckUnix + CheckNotRoot + new Xfile1 + let b = readblob('.Xfile1.swp') + call writefile(b, '.Xfile1.swm') + bw! + call setfperm('.Xfile1.swm', '-w-------') + call assert_fails('recover Xfile1', 'E306:') + call delete('.Xfile1.swm') +endfunc + +" Test for using :recover when the original file and the swap file have the +" same contents. +func Test_recover_unmodified_file() + CheckUnix + call writefile(['aaa', 'bbb', 'ccc'], 'Xfile1') + edit Xfile1 + preserve + let b = readblob('.Xfile1.swp') + %bw! + call writefile(b, '.Xfile1.swz') + let msg = execute('recover Xfile1') + call assert_equal(['aaa', 'bbb', 'ccc'], getline(1, '$')) + call assert_false(&modified) + call assert_match('Buffer contents equals file contents', msg) + bw! + call delete('Xfile1') + call delete('.Xfile1.swz') +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_swap.vim b/src/nvim/testdir/test_swap.vim index 284579b084..10c0fed783 100644 --- a/src/nvim/testdir/test_swap.vim +++ b/src/nvim/testdir/test_swap.vim @@ -501,6 +501,81 @@ func Test_swap_auto_delete() augroup! test_swap_recover_ext endfunc +" Test for renaming a buffer when the swap file is deleted out-of-band +func Test_missing_swap_file() + CheckUnix + new Xfile1 + call delete('.Xfile1.swp') + call assert_fails('file Xfile2', 'E301:') + call assert_equal('Xfile2', bufname()) + call assert_true(bufexists('Xfile1')) + call assert_true(bufexists('Xfile2')) + %bw! +endfunc + +" Test for :preserve command +func Test_preserve() + new Xfile1 + setlocal noswapfile + call assert_fails('preserve', 'E313:') + bw! +endfunc + +" Test for the v:swapchoice variable +func Test_swapchoice() + call writefile(['aaa', 'bbb'], 'Xfile1') + edit Xfile1 + preserve + let swapfname = swapname('') + let b = readblob(swapfname) + bw! + call writefile(b, swapfname) + + autocmd! SwapExists + + " Test for v:swapchoice = 'o' (readonly) + augroup test_swapchoice + autocmd! + autocmd SwapExists * let v:swapchoice = 'o' + augroup END + edit Xfile1 + call assert_true(&readonly) + call assert_equal(['aaa', 'bbb'], getline(1, '$')) + %bw! + call assert_true(filereadable(swapfname)) + + " Test for v:swapchoice = 'a' (abort) + augroup test_swapchoice + autocmd! + autocmd SwapExists * let v:swapchoice = 'a' + augroup END + try + edit Xfile1 + catch /^Vim:Interrupt$/ + endtry + call assert_equal('', @%) + call assert_true(bufexists('Xfile1')) + %bw! + call assert_true(filereadable(swapfname)) + + " Test for v:swapchoice = 'd' (delete) + augroup test_swapchoice + autocmd! + autocmd SwapExists * let v:swapchoice = 'd' + augroup END + edit Xfile1 + call assert_equal('Xfile1', @%) + %bw! + call assert_false(filereadable(swapfname)) + + call delete('Xfile1') + call delete(swapfname) + augroup test_swapchoice + autocmd! + augroup END + augroup! test_swapchoice +endfunc + func Test_no_swap_file() call assert_equal("\nNo swap file", execute('swapname')) endfunc -- cgit From 442a7e89b8de0959c41007f42b1a59cf52b814fe Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 22:52:58 +0800 Subject: vim-patch:8.2.2952: recover test fails on big endian systems Problem: Recover test fails on big endian systems. Solution: Disable the failing test on big endian systems. (Yegappan Lakshmanan, closes vim/vim#8335) https://github.com/vim/vim/commit/99285550a9957e2c8669f183557944c6513c4875 Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_recover.vim | 42 +++++++++++++++++++++++++++++++++------ src/nvim/testdir/test_swap.vim | 2 +- 2 files changed, 37 insertions(+), 7 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_recover.vim b/src/nvim/testdir/test_recover.vim index 61d8684033..ce9de8b87d 100644 --- a/src/nvim/testdir/test_recover.vim +++ b/src/nvim/testdir/test_recover.vim @@ -144,7 +144,7 @@ func Test_recover_multiple_swap_files() new Xfile1 call setline(1, ['a', 'b', 'c']) preserve - let b = readblob('.Xfile1.swp') + let b = readblob(swapname('')) call writefile(b, '.Xfile1.swm') call writefile(b, '.Xfile1.swn') call writefile(b, '.Xfile1.swo') @@ -173,6 +173,7 @@ endfunc " Test for :recover using a corrupted swap file func Test_recover_corrupted_swap_file() CheckUnix + " recover using a partial swap file call writefile(0z1234, '.Xfile1.swp') call assert_fails('recover Xfile1', 'E295:') @@ -188,12 +189,41 @@ func Test_recover_corrupted_swap_file() preserve let sn = swapname('') let b = readblob(sn) + let save_b = copy(b) bw! - " clear the B0_MAGIC_LONG field - let b[1008:1011] = 0z00000000 - call writefile(b, sn) - let msg = execute('recover Xfile1') - call assert_match('the file has been damaged', msg) + " Run these tests only on little-endian systems. These tests fail on a + " big-endian system (IBM S390x system). + if b[1008:1011] == 0z33323130 + \ && b[4096:4097] == 0z7470 + \ && b[8192:8193] == 0z6164 + + " clear the B0_MAGIC_LONG field + let b[1008:1011] = 0z00000000 + call writefile(b, sn) + let msg = execute('recover Xfile1') + call assert_match('the file has been damaged', msg) + bw! + + " clear the pointer ID + let b = copy(save_b) + let b[4096:4097] = 0z0000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E310:') + bw! + + " clear the data block ID + let b = copy(save_b) + let b[8192:8193] = 0z0000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + bw! + + " remove the data block + let b = copy(save_b) + call writefile(b[:8191], sn) + call assert_fails('recover Xfile1', 'E312:') + endif + bw! call delete(sn) endfunc diff --git a/src/nvim/testdir/test_swap.vim b/src/nvim/testdir/test_swap.vim index 10c0fed783..024a3b02bc 100644 --- a/src/nvim/testdir/test_swap.vim +++ b/src/nvim/testdir/test_swap.vim @@ -505,7 +505,7 @@ endfunc func Test_missing_swap_file() CheckUnix new Xfile1 - call delete('.Xfile1.swp') + call delete(swapname('')) call assert_fails('file Xfile2', 'E301:') call assert_equal('Xfile2', bufname()) call assert_true(bufexists('Xfile1')) -- cgit From a8f54a94c11d8ff3da299e54de4cbbcfec1fd4ac Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 22:53:40 +0800 Subject: vim-patch:8.2.2960: swap file recovery not sufficiently tested Problem: Swap file recovery not sufficiently tested. Solution: Add a few more tests. (Yegappan Lakshmanan, closes vim/vim#8339) https://github.com/vim/vim/commit/8cf02e5cf8fb14a5009f12e7af0a47617a0ce88d Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_recover.vim | 100 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_recover.vim b/src/nvim/testdir/test_recover.vim index ce9de8b87d..89f894a4bb 100644 --- a/src/nvim/testdir/test_recover.vim +++ b/src/nvim/testdir/test_recover.vim @@ -151,6 +151,16 @@ func Test_recover_multiple_swap_files() %bw! call feedkeys(":recover Xfile1\3\q", 'xt') call assert_equal(['a', 'b', 'c'], getline(1, '$')) + " try using out-of-range number to select a swap file + bw! + call feedkeys(":recover Xfile1\4\q", 'xt') + call assert_equal('Xfile1', @%) + call assert_equal([''], getline(1, '$')) + bw! + call feedkeys(":recover Xfile1\0\q", 'xt') + call assert_equal('Xfile1', @%) + call assert_equal([''], getline(1, '$')) + bw! call delete('.Xfile1.swm') call delete('.Xfile1.swn') @@ -171,6 +181,8 @@ func Test_recover_empty_swap_file() endfunc " Test for :recover using a corrupted swap file +" Refer to the comments in the memline.c file for the swap file headers +" definition. func Test_recover_corrupted_swap_file() CheckUnix @@ -202,6 +214,18 @@ func Test_recover_corrupted_swap_file() call writefile(b, sn) let msg = execute('recover Xfile1') call assert_match('the file has been damaged', msg) + call assert_equal('Xfile1', @%) + call assert_equal([''], getline(1, '$')) + bw! + + " reduce the page size + let b = copy(save_b) + let b[12:15] = 0z00010000 + call writefile(b, sn) + let msg = execute('recover Xfile1') + call assert_match('page size is smaller than minimum value', msg) + call assert_equal('Xfile1', @%) + call assert_equal([''], getline(1, '$')) bw! " clear the pointer ID @@ -209,6 +233,26 @@ func Test_recover_corrupted_swap_file() let b[4096:4097] = 0z0000 call writefile(b, sn) call assert_fails('recover Xfile1', 'E310:') + call assert_equal('Xfile1', @%) + call assert_equal([''], getline(1, '$')) + bw! + + " set the number of pointers in a pointer block to zero + let b = copy(save_b) + let b[4098:4099] = 0z0000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['???EMPTY BLOCK'], getline(1, '$')) + bw! + + " set the block number in a pointer entry to a negative number + let b = copy(save_b) + let b[4104:4111] = 0z00000000.00000080 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['???LINES MISSING'], getline(1, '$')) bw! " clear the data block ID @@ -216,12 +260,45 @@ func Test_recover_corrupted_swap_file() let b[8192:8193] = 0z0000 call writefile(b, sn) call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['???BLOCK MISSING'], getline(1, '$')) + bw! + + " set the number of lines in the data block to zero + let b = copy(save_b) + let b[8208:8211] = 0z00000000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['??? from here until ???END lines may have been inserted/deleted', + \ '???END'], getline(1, '$')) + bw! + + " use an invalid text start for the lines in a data block + let b = copy(save_b) + let b[8216:8219] = 0z00000000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['???'], getline(1, '$')) + bw! + + " use an incorrect text end (db_txt_end) for the data block + let b = copy(save_b) + let b[8204:8207] = 0z80000000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['??? from here until ???END lines may be messed up', '', + \ '???END'], getline(1, '$')) bw! " remove the data block let b = copy(save_b) call writefile(b[:8191], sn) call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['???MANY LINES MISSING'], getline(1, '$')) endif bw! @@ -295,4 +372,27 @@ func Test_recover_unmodified_file() call delete('.Xfile1.swz') endfunc +" Test for recovering a file when editing a symbolically linked file +func Test_recover_symbolic_link() + CheckUnix + call writefile(['aaa', 'bbb', 'ccc'], 'Xfile1') + silent !ln -s Xfile1 Xfile2 + edit Xfile2 + call assert_equal('.Xfile1.swp', fnamemodify(swapname(''), ':t')) + preserve + let b = readblob('.Xfile1.swp') + %bw! + call writefile([], 'Xfile1') + call writefile(b, '.Xfile1.swp') + silent! recover Xfile2 + call assert_equal(['aaa', 'bbb', 'ccc'], getline(1, '$')) + call assert_true(&modified) + update + %bw! + call assert_equal(['aaa', 'bbb', 'ccc'], readfile('Xfile1')) + call delete('Xfile1') + call delete('Xfile2') + call delete('.Xfile1.swp') +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From f12a45c45eab75578fa18b1c6395f80b8749f7ef Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 22:57:08 +0800 Subject: vim-patch:8.2.2973: fix for recovery and diff mode not tested Problem: Fix for recovery and diff mode not tested. Solution: Add a few more tests. (Yegappan Lakshmanan, closes vim/vim#8352) https://github.com/vim/vim/commit/3044324e8dccd470bd854cf7d9457232cc9c220e Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_diffmode.vim | 117 ++++++++++++++++++++++++++++++++ src/nvim/testdir/test_prompt_buffer.vim | 2 + src/nvim/testdir/test_recover.vim | 44 ++++++++++++ 3 files changed, 163 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_diffmode.vim b/src/nvim/testdir/test_diffmode.vim index 0de5310735..d83cd505a6 100644 --- a/src/nvim/testdir/test_diffmode.vim +++ b/src/nvim/testdir/test_diffmode.vim @@ -243,6 +243,36 @@ func Test_diffput_two() bwipe! b endfunc +" Test for :diffget/:diffput with a range that is inside a diff chunk +func Test_diffget_diffput_range() + call setline(1, range(1, 10)) + new + call setline(1, range(11, 20)) + windo diffthis + 3,5diffget + call assert_equal(['13', '14', '15'], getline(3, 5)) + call setline(1, range(1, 10)) + 4,8diffput + wincmd p + call assert_equal(['13', '4', '5', '6', '7', '8', '19'], getline(3, 9)) + %bw! +endfunc + +" Test for :diffget/:diffput with an empty buffer and a non-empty buffer +func Test_diffget_diffput_empty_buffer() + %d _ + new + call setline(1, 'one') + windo diffthis + diffget + call assert_equal(['one'], getline(1, '$')) + %d _ + diffput + wincmd p + call assert_equal([''], getline(1, '$')) + %bw! +endfunc + " :diffput and :diffget completes names of buffers which " are in diff mode and which are different then current buffer. " No completion when the current window is not in diff mode. @@ -645,7 +675,11 @@ func Test_diffexpr() call assert_equal(normattr, screenattr(1, 1)) call assert_equal(normattr, screenattr(2, 1)) call assert_notequal(normattr, screenattr(3, 1)) + diffoff! + " Try using an non-existing function for 'diffexpr'. + set diffexpr=NewDiffFunc() + call assert_fails('windo diffthis', ['E117:', 'E97:']) diffoff! %bwipe! set diffexpr& diffopt& @@ -1316,6 +1350,89 @@ func Test_diff_filler_cursorcolumn() call delete('Xtest_diff_cuc') endfunc +" Test for adding/removing lines inside diff chunks, between diff chunks +" and before diff chunks +func Test_diff_modify_chunks() + enew! + let w2_id = win_getid() + call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']) + new + let w1_id = win_getid() + call setline(1, ['a', '2', '3', 'd', 'e', 'f', '7', '8', 'i']) + windo diffthis + + " remove a line between two diff chunks and create a new diff chunk + call win_gotoid(w2_id) + 5d + call win_gotoid(w1_id) + call diff_hlID(5, 1)->synIDattr('name')->assert_equal('DiffAdd') + + " add a line between two diff chunks + call win_gotoid(w2_id) + normal! 4Goe + call win_gotoid(w1_id) + call diff_hlID(4, 1)->synIDattr('name')->assert_equal('') + call diff_hlID(5, 1)->synIDattr('name')->assert_equal('') + + " remove all the lines in a diff chunk. + call win_gotoid(w2_id) + 7,8d + call win_gotoid(w1_id) + let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')}) + call assert_equal(['', 'DiffText', 'DiffText', '', '', '', 'DiffAdd', + \ 'DiffAdd', ''], hl) + + " remove lines from one diff chunk to just before the next diff chunk + call win_gotoid(w2_id) + call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']) + 2,6d + call win_gotoid(w1_id) + let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')}) + call assert_equal(['', 'DiffText', 'DiffText', 'DiffAdd', 'DiffAdd', + \ 'DiffAdd', 'DiffAdd', 'DiffAdd', ''], hl) + + " remove lines just before the top of a diff chunk + call win_gotoid(w2_id) + call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']) + 5,6d + call win_gotoid(w1_id) + let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')}) + call assert_equal(['', 'DiffText', 'DiffText', '', 'DiffText', 'DiffText', + \ 'DiffAdd', 'DiffAdd', ''], hl) + + " remove line after the end of a diff chunk + call win_gotoid(w2_id) + call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']) + 4d + call win_gotoid(w1_id) + let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')}) + call assert_equal(['', 'DiffText', 'DiffText', 'DiffAdd', '', '', 'DiffText', + \ 'DiffText', ''], hl) + + " remove lines starting from the end of one diff chunk and ending inside + " another diff chunk + call win_gotoid(w2_id) + call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']) + 4,7d + call win_gotoid(w1_id) + let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')}) + call assert_equal(['', 'DiffText', 'DiffText', 'DiffText', 'DiffAdd', + \ 'DiffAdd', 'DiffAdd', 'DiffAdd', ''], hl) + + " removing the only remaining diff chunk should make the files equal + call win_gotoid(w2_id) + call setline(1, ['a', '2', '3', 'x', 'd', 'e', 'f', 'x', '7', '8', 'i']) + 8d + let hl = range(1, 10)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')}) + call assert_equal(['', '', '', 'DiffAdd', '', '', '', '', '', ''], hl) + call win_gotoid(w2_id) + 4d + call win_gotoid(w1_id) + let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')}) + call assert_equal(['', '', '', '', '', '', '', '', ''], hl) + + %bw! +endfunc func Test_diff_binary() CheckScreendump diff --git a/src/nvim/testdir/test_prompt_buffer.vim b/src/nvim/testdir/test_prompt_buffer.vim index 9b8a776c95..b8f6c5240c 100644 --- a/src/nvim/testdir/test_prompt_buffer.vim +++ b/src/nvim/testdir/test_prompt_buffer.vim @@ -180,6 +180,8 @@ func Test_prompt_buffer_edit() call assert_beeps('normal! S') call assert_beeps("normal! \") call assert_beeps("normal! \") + call assert_beeps("normal! dp") + call assert_beeps("normal! do") " pressing CTRL-W in the prompt buffer should trigger the window commands call assert_equal(1, winnr()) exe "normal A\\" diff --git a/src/nvim/testdir/test_recover.vim b/src/nvim/testdir/test_recover.vim index 89f894a4bb..90ee10704c 100644 --- a/src/nvim/testdir/test_recover.vim +++ b/src/nvim/testdir/test_recover.vim @@ -395,4 +395,48 @@ func Test_recover_symbolic_link() call delete('.Xfile1.swp') endfunc +" Test for recovering a file when an autocmd moves the cursor to an invalid +" line. This used to result in an internal error (E315) which is fixed +" by 8.2.2966. +func Test_recover_invalid_cursor_pos() + call writefile([], 'Xfile1') + edit Xfile1 + preserve + let b = readblob('.Xfile1.swp') + bw! + augroup Test + au! + au BufReadPost Xfile1 normal! 3G + augroup END + call writefile(range(1, 3), 'Xfile1') + call writefile(b, '.Xfile1.swp') + try + recover Xfile1 + catch /E308:/ + " this test is for the :E315 internal error. + " ignore the 'E308: Original file may have been changed' error + endtry + redraw! + augroup Test + au! + augroup END + augroup! Test + call delete('Xfile1') + call delete('.Xfile1.swp') +endfunc + +" Test for recovering a buffer without a name +func Test_noname_buffer() + new + call setline(1, ['one', 'two']) + preserve + let sn = swapname('') + let b = readblob(sn) + bw! + call writefile(b, sn) + exe "recover " .. sn + call assert_equal(['one', 'two'], getline(1, '$')) + call delete(sn) +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From fa17dc1e1b893db3320b9b7ae50698c05280df92 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 23:00:25 +0800 Subject: vim-patch:8.2.2981: recovery test is not run on big-endian systems Problem: Recovery test is not run on big-endian systems. Solution: Make it work on big-endian systems. (James McCoy, closes vim/vim#8368) https://github.com/vim/vim/commit/6654ca702ca64c99965efcad3243ea5f95473252 Co-authored-by: James McCoy --- src/nvim/testdir/test_recover.vim | 193 +++++++++++++++++++------------------- 1 file changed, 96 insertions(+), 97 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_recover.vim b/src/nvim/testdir/test_recover.vim index 90ee10704c..10a9e7b4f3 100644 --- a/src/nvim/testdir/test_recover.vim +++ b/src/nvim/testdir/test_recover.vim @@ -203,103 +203,102 @@ func Test_recover_corrupted_swap_file() let b = readblob(sn) let save_b = copy(b) bw! - " Run these tests only on little-endian systems. These tests fail on a - " big-endian system (IBM S390x system). - if b[1008:1011] == 0z33323130 - \ && b[4096:4097] == 0z7470 - \ && b[8192:8193] == 0z6164 - - " clear the B0_MAGIC_LONG field - let b[1008:1011] = 0z00000000 - call writefile(b, sn) - let msg = execute('recover Xfile1') - call assert_match('the file has been damaged', msg) - call assert_equal('Xfile1', @%) - call assert_equal([''], getline(1, '$')) - bw! - - " reduce the page size - let b = copy(save_b) - let b[12:15] = 0z00010000 - call writefile(b, sn) - let msg = execute('recover Xfile1') - call assert_match('page size is smaller than minimum value', msg) - call assert_equal('Xfile1', @%) - call assert_equal([''], getline(1, '$')) - bw! - - " clear the pointer ID - let b = copy(save_b) - let b[4096:4097] = 0z0000 - call writefile(b, sn) - call assert_fails('recover Xfile1', 'E310:') - call assert_equal('Xfile1', @%) - call assert_equal([''], getline(1, '$')) - bw! - - " set the number of pointers in a pointer block to zero - let b = copy(save_b) - let b[4098:4099] = 0z0000 - call writefile(b, sn) - call assert_fails('recover Xfile1', 'E312:') - call assert_equal('Xfile1', @%) - call assert_equal(['???EMPTY BLOCK'], getline(1, '$')) - bw! - - " set the block number in a pointer entry to a negative number - let b = copy(save_b) - let b[4104:4111] = 0z00000000.00000080 - call writefile(b, sn) - call assert_fails('recover Xfile1', 'E312:') - call assert_equal('Xfile1', @%) - call assert_equal(['???LINES MISSING'], getline(1, '$')) - bw! - - " clear the data block ID - let b = copy(save_b) - let b[8192:8193] = 0z0000 - call writefile(b, sn) - call assert_fails('recover Xfile1', 'E312:') - call assert_equal('Xfile1', @%) - call assert_equal(['???BLOCK MISSING'], getline(1, '$')) - bw! - - " set the number of lines in the data block to zero - let b = copy(save_b) - let b[8208:8211] = 0z00000000 - call writefile(b, sn) - call assert_fails('recover Xfile1', 'E312:') - call assert_equal('Xfile1', @%) - call assert_equal(['??? from here until ???END lines may have been inserted/deleted', - \ '???END'], getline(1, '$')) - bw! - - " use an invalid text start for the lines in a data block - let b = copy(save_b) - let b[8216:8219] = 0z00000000 - call writefile(b, sn) - call assert_fails('recover Xfile1', 'E312:') - call assert_equal('Xfile1', @%) - call assert_equal(['???'], getline(1, '$')) - bw! - - " use an incorrect text end (db_txt_end) for the data block - let b = copy(save_b) - let b[8204:8207] = 0z80000000 - call writefile(b, sn) - call assert_fails('recover Xfile1', 'E312:') - call assert_equal('Xfile1', @%) - call assert_equal(['??? from here until ???END lines may be messed up', '', - \ '???END'], getline(1, '$')) - bw! - - " remove the data block - let b = copy(save_b) - call writefile(b[:8191], sn) - call assert_fails('recover Xfile1', 'E312:') - call assert_equal('Xfile1', @%) - call assert_equal(['???MANY LINES MISSING'], getline(1, '$')) - endif + + " Not all fields are written in a system-independent manner. Detect whether + " the test is running on a little or big-endian system, so the correct + " corruption values can be set. + let little_endian = b[1008:1015] == 0z33323130.00000000 + + " clear the B0_MAGIC_LONG field + let b[1008:1015] = 0z0000000000000000 + call writefile(b, sn) + let msg = execute('recover Xfile1') + call assert_match('the file has been damaged', msg) + call assert_equal('Xfile1', @%) + call assert_equal([''], getline(1, '$')) + bw! + + " reduce the page size + let b = copy(save_b) + let b[12:15] = 0z00010000 + call writefile(b, sn) + let msg = execute('recover Xfile1') + call assert_match('page size is smaller than minimum value', msg) + call assert_equal('Xfile1', @%) + call assert_equal([''], getline(1, '$')) + bw! + + " clear the pointer ID + let b = copy(save_b) + let b[4096:4097] = 0z0000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E310:') + call assert_equal('Xfile1', @%) + call assert_equal([''], getline(1, '$')) + bw! + + " set the number of pointers in a pointer block to zero + let b = copy(save_b) + let b[4098:4099] = 0z0000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['???EMPTY BLOCK'], getline(1, '$')) + bw! + + " set the block number in a pointer entry to a negative number + let b = copy(save_b) + let b[4104:4111] = little_endian ? 0z00000000.00000080 : 0z80000000.00000000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['???LINES MISSING'], getline(1, '$')) + bw! + + " clear the data block ID + let b = copy(save_b) + let b[8192:8193] = 0z0000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['???BLOCK MISSING'], getline(1, '$')) + bw! + + " set the number of lines in the data block to zero + let b = copy(save_b) + let b[8208:8215] = 0z00000000.00000000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['??? from here until ???END lines may have been inserted/deleted', + \ '???END'], getline(1, '$')) + bw! + + " use an invalid text start for the lines in a data block + let b = copy(save_b) + let b[8216:8219] = 0z00000000 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['???'], getline(1, '$')) + bw! + + " use an incorrect text end (db_txt_end) for the data block + let b = copy(save_b) + let b[8204:8207] = little_endian ? 0z80000000 : 0z00000080 + call writefile(b, sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['??? from here until ???END lines may be messed up', '', + \ '???END'], getline(1, '$')) + bw! + + " remove the data block + let b = copy(save_b) + call writefile(b[:8191], sn) + call assert_fails('recover Xfile1', 'E312:') + call assert_equal('Xfile1', @%) + call assert_equal(['???MANY LINES MISSING'], getline(1, '$')) bw! call delete(sn) -- cgit From c1c2c7b3163490b5e4374ee370616ea2581d4fe1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 23:00:50 +0800 Subject: vim-patch:8.2.3080: recover test fails on 32bit systems MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Recover test fails on 32bit systems. (Ondřej Súkup) Solution: Detect 32/64 bit systems. (Yegappan Lakshmanan, closes vim/vim#8485, closes vim/vim#8479) https://github.com/vim/vim/commit/576cb75ceb38ed077938d4a1c1265095050f6105 Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_recover.vim | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_recover.vim b/src/nvim/testdir/test_recover.vim index 10a9e7b4f3..137c73a194 100644 --- a/src/nvim/testdir/test_recover.vim +++ b/src/nvim/testdir/test_recover.vim @@ -207,10 +207,16 @@ func Test_recover_corrupted_swap_file() " Not all fields are written in a system-independent manner. Detect whether " the test is running on a little or big-endian system, so the correct " corruption values can be set. - let little_endian = b[1008:1015] == 0z33323130.00000000 + let little_endian = b[1008:1011] == 0z33323130 + " The swap file header fields can be either 32-bit or 64-bit. + let system_64bit = b[1012:1015] == 0z00000000 " clear the B0_MAGIC_LONG field - let b[1008:1015] = 0z0000000000000000 + if system_64bit + let b[1008:1015] = 0z00000000.00000000 + else + let b[1008:1011] = 0z00000000 + endif call writefile(b, sn) let msg = execute('recover Xfile1') call assert_match('the file has been damaged', msg) @@ -248,7 +254,11 @@ func Test_recover_corrupted_swap_file() " set the block number in a pointer entry to a negative number let b = copy(save_b) - let b[4104:4111] = little_endian ? 0z00000000.00000080 : 0z80000000.00000000 + if system_64bit + let b[4104:4111] = little_endian ? 0z00000000.00000080 : 0z80000000.00000000 + else + let b[4104:4107] = little_endian ? 0z00000080 : 0z80000000 + endif call writefile(b, sn) call assert_fails('recover Xfile1', 'E312:') call assert_equal('Xfile1', @%) @@ -266,7 +276,11 @@ func Test_recover_corrupted_swap_file() " set the number of lines in the data block to zero let b = copy(save_b) - let b[8208:8215] = 0z00000000.00000000 + if system_64bit + let b[8208:8215] = 0z00000000.00000000 + else + let b[8208:8211] = 0z00000000 + endif call writefile(b, sn) call assert_fails('recover Xfile1', 'E312:') call assert_equal('Xfile1', @%) @@ -276,7 +290,11 @@ func Test_recover_corrupted_swap_file() " use an invalid text start for the lines in a data block let b = copy(save_b) - let b[8216:8219] = 0z00000000 + if system_64bit + let b[8216:8219] = 0z00000000 + else + let b[8212:8215] = 0z00000000 + endif call writefile(b, sn) call assert_fails('recover Xfile1', 'E312:') call assert_equal('Xfile1', @%) -- cgit From acfc3d54c6fc5b22adab057962c493b059a91fe7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 23:02:10 +0800 Subject: vim-patch:8.2.3103: swap test may fail on some systems Problem: Swap test may fail on some systems when jobs take longer to exit. Solution: Use different file names. https://github.com/vim/vim/commit/f33cae605064c8bdb908a8069d936f752572cd76 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_swap.vim | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_swap.vim b/src/nvim/testdir/test_swap.vim index 024a3b02bc..cf46b4c5bd 100644 --- a/src/nvim/testdir/test_swap.vim +++ b/src/nvim/testdir/test_swap.vim @@ -504,18 +504,18 @@ endfunc " Test for renaming a buffer when the swap file is deleted out-of-band func Test_missing_swap_file() CheckUnix - new Xfile1 + new Xfile2 call delete(swapname('')) - call assert_fails('file Xfile2', 'E301:') - call assert_equal('Xfile2', bufname()) - call assert_true(bufexists('Xfile1')) + call assert_fails('file Xfile3', 'E301:') + call assert_equal('Xfile3', bufname()) call assert_true(bufexists('Xfile2')) + call assert_true(bufexists('Xfile3')) %bw! endfunc " Test for :preserve command func Test_preserve() - new Xfile1 + new Xfile4 setlocal noswapfile call assert_fails('preserve', 'E313:') bw! @@ -523,8 +523,8 @@ endfunc " Test for the v:swapchoice variable func Test_swapchoice() - call writefile(['aaa', 'bbb'], 'Xfile1') - edit Xfile1 + call writefile(['aaa', 'bbb'], 'Xfile5') + edit Xfile5 preserve let swapfname = swapname('') let b = readblob(swapfname) @@ -538,7 +538,7 @@ func Test_swapchoice() autocmd! autocmd SwapExists * let v:swapchoice = 'o' augroup END - edit Xfile1 + edit Xfile5 call assert_true(&readonly) call assert_equal(['aaa', 'bbb'], getline(1, '$')) %bw! @@ -550,11 +550,11 @@ func Test_swapchoice() autocmd SwapExists * let v:swapchoice = 'a' augroup END try - edit Xfile1 + edit Xfile5 catch /^Vim:Interrupt$/ endtry call assert_equal('', @%) - call assert_true(bufexists('Xfile1')) + call assert_true(bufexists('Xfile5')) %bw! call assert_true(filereadable(swapfname)) @@ -563,12 +563,12 @@ func Test_swapchoice() autocmd! autocmd SwapExists * let v:swapchoice = 'd' augroup END - edit Xfile1 - call assert_equal('Xfile1', @%) + edit Xfile5 + call assert_equal('Xfile5', @%) %bw! call assert_false(filereadable(swapfname)) - call delete('Xfile1') + call delete('Xfile5') call delete(swapfname) augroup test_swapchoice autocmd! -- cgit From d8fc390bd04a69f43983fc355026a2f216410318 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 23:02:47 +0800 Subject: vim-patch:8.2.3440: recover test fails if there is an old swap file Problem: Recover test fails if there is an old swap file. Solution: Delete old swap files. https://github.com/vim/vim/commit/f2a8bafa4b815e5b4e50a25c2b3a8a24fbe8aa11 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_recover.vim | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_recover.vim b/src/nvim/testdir/test_recover.vim index 137c73a194..9d38b0ebea 100644 --- a/src/nvim/testdir/test_recover.vim +++ b/src/nvim/testdir/test_recover.vim @@ -175,6 +175,12 @@ func Test_recover_empty_swap_file() call assert_match('Unable to read block 0 from .Xfile1.swp', msg) call assert_equal('Xfile1', @%) bw! + + " make sure there are no old swap files laying around + for f in glob('.sw?', 0, 1) + call delete(f) + endfor + " :recover from an empty buffer call assert_fails('recover', 'E305:') call delete('.Xfile1.swp') -- cgit From c269b8dcae08221f1752faf1ecc7dae4d7eed40c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 23:03:10 +0800 Subject: vim-patch:8.2.3498: recover test may fail on some systems Problem: Recover test may fail on some systems. Solution: Adjust the little endian and 64 bit detection. (James McCoy, closes vim/vim#8941) https://github.com/vim/vim/commit/37f341d7236ff8a1e886bbb0f0ba0700ad589373 Co-authored-by: James McCoy --- src/nvim/testdir/test_recover.vim | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_recover.vim b/src/nvim/testdir/test_recover.vim index 9d38b0ebea..f4710c4357 100644 --- a/src/nvim/testdir/test_recover.vim +++ b/src/nvim/testdir/test_recover.vim @@ -213,9 +213,11 @@ func Test_recover_corrupted_swap_file() " Not all fields are written in a system-independent manner. Detect whether " the test is running on a little or big-endian system, so the correct " corruption values can be set. - let little_endian = b[1008:1011] == 0z33323130 - " The swap file header fields can be either 32-bit or 64-bit. - let system_64bit = b[1012:1015] == 0z00000000 + " The B0_MAGIC_LONG field may be 32-bit or 64-bit, depending on the system, + " even though the value stored is only 32-bits. Therefore, need to check + " both the high and low 32-bits to compute these values. + let little_endian = (b[1008:1011] == 0z33323130) || (b[1012:1015] == 0z33323130) + let system_64bit = little_endian ? (b[1012:1015] == 0z00000000) : (b[1008:1011] == 0z00000000) " clear the B0_MAGIC_LONG field if system_64bit -- cgit From 294910a1ffd11bea0081c2b92632628ef0462eb1 Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Sat, 5 Nov 2022 19:30:48 -0600 Subject: feat(exrc): use vim.secure.read() for 'exrc' option --- src/nvim/testdir/test_startup.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim index f9f7c5b492..42467c5508 100644 --- a/src/nvim/testdir/test_startup.vim +++ b/src/nvim/testdir/test_startup.vim @@ -1024,6 +1024,7 @@ endfunc " Test for using the 'exrc' option func Test_exrc() + throw 'Skipped: Nvim requires user input for the exrc option' let after =<< trim [CODE] call assert_equal(1, &exrc) call assert_equal(1, &secure) -- cgit From 7139035bfd90698ce7214b507b2f8a7766398a68 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Nov 2022 23:30:30 +0800 Subject: vim-patch:9.0.0895: file renamed twice in test, missing feature check Problem: File renamed twice in test; missing feature check. Solution: Remove a rename() call. Add check for cryptv feature. (closes vim/vim#11564) https://github.com/vim/vim/commit/780154bf7a07813e474105837c2b5998009d9c71 Co-authored-by: zeertzjq --- src/nvim/testdir/test_recover.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_recover.vim b/src/nvim/testdir/test_recover.vim index f4710c4357..92e22687af 100644 --- a/src/nvim/testdir/test_recover.vim +++ b/src/nvim/testdir/test_recover.vim @@ -126,7 +126,6 @@ func Test_nocatch_process_still_running() call test_override("uptime", 0) sleep 1 - call rename('Xswap', swname) call feedkeys('e', 'tL') redir => editOutput edit Xswaptest @@ -332,6 +331,7 @@ endfunc " Test for :recover using an encrypted swap file func Test_recover_encrypted_swap_file() + CheckFeature cryptv CheckUnix " Recover an encrypted file from the swap file without the original file -- cgit From 510429fc5cc010afa54036d16e049b177cce2e3e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 18 Nov 2022 06:47:51 +0800 Subject: vim-patch:8.2.1497: CursorHold test is flaky (#21095) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: CursorHold test is flaky. (Jakub Kądziołka) Solution: Use WaitForAssert() (closes vim/vim#6754) https://github.com/vim/vim/commit/17f67547f36a06220ea4667aaee7bb130108f568 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_autocmd.vim | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index fb8adbb3a6..70da0a9ba2 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -31,20 +31,19 @@ func Test_CursorHold_autocmd() END call writefile(before, 'Xinit') let buf = RunVimInTerminal('-S Xinit Xfile', {}) - call term_wait(buf) + call term_sendkeys(buf, "G") + call term_wait(buf, 20) call term_sendkeys(buf, "gg") call term_wait(buf) - sleep 50m + call WaitForAssert({-> assert_equal(['1'], readfile('Xoutput')[-1:-1])}) call term_sendkeys(buf, "j") call term_wait(buf) - sleep 50m + call WaitForAssert({-> assert_equal(['1', '2'], readfile('Xoutput')[-2:-1])}) call term_sendkeys(buf, "j") call term_wait(buf) - sleep 50m + call WaitForAssert({-> assert_equal(['1', '2', '3'], readfile('Xoutput')[-3:-1])}) call StopVimInTerminal(buf) - call assert_equal(['1', '2', '3'], readfile('Xoutput')[-3:-1]) - call delete('Xinit') call delete('Xoutput') call delete('Xfile') -- cgit From 523b1943c359cf79f29229a3d882c55ea407a237 Mon Sep 17 00:00:00 2001 From: Matthew Gramigna Date: Thu, 17 Nov 2022 18:39:31 -0500 Subject: vim-patch:9.0.0897: Clinical Quality Language files are not recognized (#21094) Problem: Clinical Quality Language files are not recognized. Solution: Add the "*.cql" pattern. (Matthew Gramigna, closes vim/vim#11452) https://github.com/vim/vim/commit/12babe45a389cd1ea8befd5b06239e877b4abbba Co-authored-by: mgramigna --- src/nvim/testdir/test_filetype.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 69508cb19e..c8d8239757 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -126,6 +126,7 @@ let s:filename_checks = { \ 'context': ['tex/context/any/file.tex', 'file.mkii', 'file.mkiv', 'file.mkvi', 'file.mkxl', 'file.mklx'], \ 'cook': ['file.cook'], \ 'cpp': ['file.cxx', 'file.c++', 'file.hh', 'file.hxx', 'file.hpp', 'file.ipp', 'file.moc', 'file.tcc', 'file.inl', 'file.tlh'], + \ 'cqlang': ['file.cql'], \ 'crm': ['file.crm'], \ 'crontab': ['crontab', 'crontab.file', '/etc/cron.d/file', 'any/etc/cron.d/file'], \ 'cs': ['file.cs', 'file.csx'], -- cgit From 282cbc2350986c3fc1edb507c4facc8d8fe8cd97 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 18 Nov 2022 11:16:11 +0800 Subject: vim-patch:8.2.3776: when a tags file line is long a tag may not be found (#21099) Problem: When a tags file line is long a tag may not be found. Solution: When increasing the buffer size read the same line again. https://github.com/vim/vim/commit/f8e9eb8e173bf0ff9560192ae888941ef8302269 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_taglist.vim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_taglist.vim b/src/nvim/testdir/test_taglist.vim index 658485582c..68f9982e36 100644 --- a/src/nvim/testdir/test_taglist.vim +++ b/src/nvim/testdir/test_taglist.vim @@ -241,4 +241,23 @@ func Test_tag_complete_wildoptions() set tags& endfunc +func Test_tag_complete_with_overlong_line() + let tagslines =<< trim END + !_TAG_FILE_FORMAT 2 // + !_TAG_FILE_SORTED 1 // + !_TAG_FILE_ENCODING utf-8 // + inboundGSV a 1;" r + inboundGovernor a 2;" kind:⊢ type:forall (muxMode :: MuxMode) socket peerAddr versionNumber m a b. (MonadAsync m, MonadCatch m, MonadEvaluate m, MonadThrow m, MonadThrow (STM m), MonadTime m, MonadTimer m, MonadMask m, Ord peerAddr, HasResponder muxMode ~ True) => Tracer m (RemoteTransitionTrace peerAddr) -> Tracer m (InboundGovernorTrace peerAddr) -> ServerControlChannel muxMode peerAddr ByteString m a b -> DiffTime -> MuxConnectionManager muxMode socket peerAddr versionNumber ByteString m a b -> StrictTVar m InboundGovernorObservableState -> m Void + inboundGovernorCounters a 3;" kind:⊢ type:InboundGovernorState muxMode peerAddr m a b -> InboundGovernorCounters + END + call writefile(tagslines, 'Xtags') + set tags=Xtags + + call feedkeys(":tag inbou\\\"\", 'xt') + call assert_equal('"tag inboundGSV inboundGovernor inboundGovernorCounters', @:) + + call delete('Xtags') + set tags& +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 245035d6db7399cc077de0eaa8e97e2eecc08a9b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 18 Nov 2022 13:25:21 +0800 Subject: vim-patch:8.2.4494: the find_tags() function is much too long Problem: The find_tags() function is much too long. Solution: Refactor the function. (Yegappan Lakshmanan, closes vim/vim#9869) https://github.com/vim/vim/commit/2f87a99b6e9b559d51e130769e7f8377db6749f8 Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_tagjump.vim | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_tagjump.vim b/src/nvim/testdir/test_tagjump.vim index bfc61e7b48..361aa23291 100644 --- a/src/nvim/testdir/test_tagjump.vim +++ b/src/nvim/testdir/test_tagjump.vim @@ -1448,6 +1448,11 @@ func Test_tagfile_errors() endtry call assert_equal(v:true, caught_431) + " tag name and file name are not separated by a tab + call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", + \ "foo Xfile 1"], 'Xtags') + call assert_fails('tag foo', 'E431:') + call delete('Xtags') call delete('Xfile') set tags& -- cgit From 6f08ea013137d396a3610251d641800c5b0a6510 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 18 Nov 2022 15:32:55 +0800 Subject: vim-patch:8.2.4512: the find_tags_in_file() function is much too long Problem: The find_tags_in_file() function is much too long. Solution: Refactor into multiple smaller functions. (Yegappan Lakshmanan, closes vim/vim#9892) https://github.com/vim/vim/commit/df1bbea436636ac227d33dd79f77e07f4fffb028 Cherry-pick Test_tag_file_encoding() changes from patch 8.2.1432. Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_tagjump.vim | 50 ++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 6 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_tagjump.vim b/src/nvim/testdir/test_tagjump.vim index 361aa23291..231d006da7 100644 --- a/src/nvim/testdir/test_tagjump.vim +++ b/src/nvim/testdir/test_tagjump.vim @@ -231,15 +231,13 @@ func Test_tag_symbolic() endfunc " Tests for tag search with !_TAG_FILE_ENCODING. -" Depends on the test83-tags2 and test83-tags3 files. func Test_tag_file_encoding() - throw 'skipped: Nvim removed test83-tags2, test83-tags3' if has('vms') - return + throw 'Skipped: does not work on VMS' endif if !has('iconv') || iconv("\x82\x60", "cp932", "utf-8") != "\uff21" - return + throw 'Skipped: iconv does not work' endif let save_enc = &encoding @@ -264,18 +262,31 @@ func Test_tag_file_encoding() " case2: new - set tags=test83-tags2 + let content = ['!_TAG_FILE_ENCODING cp932 //', + \ "\x82`\x82a\x82b Xtags2.txt /\x82`\x82a\x82b"] + call writefile(content, 'Xtags') + set tags=Xtags tag /.BC call assert_equal('Xtags2.txt', expand('%:t')) call assert_equal('ABC', getline('.')) + call delete('Xtags') close " case3: new - set tags=test83-tags3 + let contents = [ + \ "!_TAG_FILE_SORTED 1 //", + \ "!_TAG_FILE_ENCODING cp932 //"] + for i in range(1, 100) + call add(contents, 'abc' .. i + \ .. " Xtags3.txt /\x82`\x82a\x82b") + endfor + call writefile(contents, 'Xtags') + set tags=Xtags tag abc50 call assert_equal('Xtags3.txt', expand('%:t')) call assert_equal('ABC', getline('.')) + call delete('Xtags') close set tags& @@ -327,6 +338,7 @@ func Test_tagjump_etags() \ ], 'Xtags2') tag main call assert_equal(2, line('.')) + call assert_fails('tag bar', 'E426:') " corrupted tag line call writefile([ @@ -352,6 +364,27 @@ func Test_tagjump_etags() \ ], 'Xtags') call assert_fails('tag foo', 'E431:') + " end of file after a CTRL-L line + call writefile([ + \ "\x0c", + \ "Xmain.c,64", + \ "void foo() {}\x7ffoo\x011,0", + \ "\x0c", + \ ], 'Xtags') + call assert_fails('tag main', 'E426:') + + " error in an included tags file + call writefile([ + \ "\x0c", + \ "Xtags2,include" + \ ], 'Xtags') + call writefile([ + \ "\x0c", + \ "Xmain.c,64", + \ "void foo() {}", + \ ], 'Xtags2') + call assert_fails('tag foo', 'E431:') + call delete('Xtags') call delete('Xtags2') call delete('Xmain.c') @@ -1453,6 +1486,11 @@ func Test_tagfile_errors() \ "foo Xfile 1"], 'Xtags') call assert_fails('tag foo', 'E431:') + " file name and search pattern are not separated by a tab + call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", + \ "foo\tXfile 1;"], 'Xtags') + call assert_fails('tag foo', 'E431:') + call delete('Xtags') call delete('Xfile') set tags& -- cgit From e41469a5b501390e9e8d1ed22ffdb4cf103cf99e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 18 Nov 2022 16:16:39 +0800 Subject: vim-patch:8.2.4518: the binary tag search feature is always enabled Problem: The binary tag search feature is always enabled. Solution: Remove the #ifdefs. Add a few more tests. (Yegappan Lakshmanan, closes vim/vim#9893) https://github.com/vim/vim/commit/655b734ee858e90dd8d28549b7704a71b25d30e7 Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_tagjump.vim | 73 +++++++++++++++++++++++++++++++++++++++ src/nvim/testdir/test_taglist.vim | 11 ++++++ 2 files changed, 84 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_tagjump.vim b/src/nvim/testdir/test_tagjump.vim index 231d006da7..7a1a0132b3 100644 --- a/src/nvim/testdir/test_tagjump.vim +++ b/src/nvim/testdir/test_tagjump.vim @@ -1523,4 +1523,77 @@ func Test_stag_close_window_on_error() set tags& endfunc +" Test for 'tagbsearch' (binary search) +func Test_tagbsearch() + " If a tags file header says the tags are sorted, but the tags are actually + " unsorted, then binary search should fail and linear search should work. + call writefile([ + \ "!_TAG_FILE_ENCODING\tutf-8\t//", + \ "!_TAG_FILE_SORTED\t1\t/0=unsorted, 1=sorted, 2=foldcase/", + \ "third\tXfoo\t3", + \ "second\tXfoo\t2", + \ "first\tXfoo\t1"], + \ 'Xtags') + set tags=Xtags + let code =<< trim [CODE] + int first() {} + int second() {} + int third() {} + [CODE] + call writefile(code, 'Xfoo') + + enew + set tagbsearch + call assert_fails('tag first', 'E426:') + call assert_equal('', bufname()) + call assert_fails('tag second', 'E426:') + call assert_equal('', bufname()) + tag third + call assert_equal('Xfoo', bufname()) + call assert_equal(3, line('.')) + %bw! + + set notagbsearch + tag first + call assert_equal('Xfoo', bufname()) + call assert_equal(1, line('.')) + enew + tag second + call assert_equal('Xfoo', bufname()) + call assert_equal(2, line('.')) + enew + tag third + call assert_equal('Xfoo', bufname()) + call assert_equal(3, line('.')) + %bw! + + " If a tags file header says the tags are unsorted, but the tags are + " actually sorted, then binary search should work. + call writefile([ + \ "!_TAG_FILE_ENCODING\tutf-8\t//", + \ "!_TAG_FILE_SORTED\t0\t/0=unsorted, 1=sorted, 2=foldcase/", + \ "first\tXfoo\t1", + \ "second\tXfoo\t2", + \ "third\tXfoo\t3"], + \ 'Xtags') + + set tagbsearch + tag first + call assert_equal('Xfoo', bufname()) + call assert_equal(1, line('.')) + enew + tag second + call assert_equal('Xfoo', bufname()) + call assert_equal(2, line('.')) + enew + tag third + call assert_equal('Xfoo', bufname()) + call assert_equal(3, line('.')) + %bw! + + call delete('Xtags') + call delete('Xfoo') + set tags& tagbsearch& +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_taglist.vim b/src/nvim/testdir/test_taglist.vim index 68f9982e36..1a3d1986bf 100644 --- a/src/nvim/testdir/test_taglist.vim +++ b/src/nvim/testdir/test_taglist.vim @@ -36,6 +36,12 @@ func Test_taglist() call assert_equal('d', cmd[0]['kind']) call assert_equal('call cursor(3, 4)', cmd[0]['cmd']) + " Use characters with value > 127 in the tag extra field. + call writefile([ + \ "vFoo\tXfoo\t4" .. ';"' .. "\ttypename:int\ta£££\tv", + \ ], 'Xtags') + call assert_equal('v', taglist('vFoo')[0].kind) + call assert_fails("let l=taglist([])", 'E730:') call delete('Xtags') @@ -221,6 +227,11 @@ func Test_format_error() endtry call assert_true(caught_exception) + " no field after the filename for a tag + call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", + \ "foo\tXfile"], 'Xtags') + call assert_fails("echo taglist('foo')", 'E431:') + set tags& call delete('Xtags') endfunc -- cgit From 136112a869e6f94f34627a2902eb83c8ee526273 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 18 Nov 2022 16:20:32 +0800 Subject: vim-patch:8.2.4538: the find_tags_in_file() function is too long Problem: The find_tags_in_file() function is too long. Solution: Refactor into smaller functions. (Yegappan Lakshmanan, closes vim/vim#9920) https://github.com/vim/vim/commit/bf40e90dfeb1d3d0280077e65782beb3fee31c9f Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_tagjump.vim | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_tagjump.vim b/src/nvim/testdir/test_tagjump.vim index 7a1a0132b3..c981bfc26c 100644 --- a/src/nvim/testdir/test_tagjump.vim +++ b/src/nvim/testdir/test_tagjump.vim @@ -805,11 +805,11 @@ endfunc " Test for an unsorted tags file func Test_tag_sort() - call writefile([ + let l = [ \ "first\tXfoo\t1", \ "ten\tXfoo\t3", - \ "six\tXfoo\t2"], - \ 'Xtags') + \ "six\tXfoo\t2"] + call writefile(l, 'Xtags') set tags=Xtags let code =<< trim [CODE] int first() {} @@ -820,7 +820,14 @@ func Test_tag_sort() call assert_fails('tag first', 'E432:') + " When multiple tag files are not sorted, then message should be displayed + " multiple times + call writefile(l, 'Xtags2') + set tags=Xtags,Xtags2 + call assert_fails('tag first', ['E432:', 'E432:']) + call delete('Xtags') + call delete('Xtags2') call delete('Xfoo') set tags& %bwipe -- cgit From b2345ddbf33ab4941839ac0976a9e8261b284c40 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 18 Nov 2022 17:37:33 +0800 Subject: vim-patch:8.2.4543: Coverity warning for refactored tag search code Problem: Coverity warning for refactored tag search code. Solution: Avoid the warnings. Update comments. Add one more test case. (Yegappan Lakshmanan, closes vim/vim#9928) https://github.com/vim/vim/commit/20fb28b1dcc092787e1a7b22dcfcfe1e46e29813 Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_tagjump.vim | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_tagjump.vim b/src/nvim/testdir/test_tagjump.vim index c981bfc26c..be60a3535c 100644 --- a/src/nvim/testdir/test_tagjump.vim +++ b/src/nvim/testdir/test_tagjump.vim @@ -1598,6 +1598,15 @@ func Test_tagbsearch() call assert_equal(3, line('.')) %bw! + " Binary search fails on EOF + call writefile([ + \ "!_TAG_FILE_ENCODING\tutf-8\t//", + \ "!_TAG_FILE_SORTED\t1\t/0=unsorted, 1=sorted, 2=foldcase/", + \ "bar\tXfoo\t1", + \ "foo\tXfoo\t2"], + \ 'Xtags') + call assert_fails('tag bbb', 'E426:') + call delete('Xtags') call delete('Xfoo') set tags& tagbsearch& -- cgit From 6a5fbabe485e673ffb4c7e8aaba77534ad3c671a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 18 Nov 2022 20:03:29 +0800 Subject: vim-patch:8.2.4553: linear tag search is a bit slow Problem: Linear tag search is a bit slow. Solution: Remove a vim_ftell() call. (Yegappan Lakshmanan, closes vim/vim#9937) https://github.com/vim/vim/commit/8b530b3158cbd3aee2ad9cad8e7b7964faabb51e Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_taglist.vim | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_taglist.vim b/src/nvim/testdir/test_taglist.vim index 1a3d1986bf..0387ef2bd8 100644 --- a/src/nvim/testdir/test_taglist.vim +++ b/src/nvim/testdir/test_taglist.vim @@ -264,8 +264,15 @@ func Test_tag_complete_with_overlong_line() call writefile(tagslines, 'Xtags') set tags=Xtags + " try with binary search + set tagbsearch call feedkeys(":tag inbou\\\"\", 'xt') call assert_equal('"tag inboundGSV inboundGovernor inboundGovernorCounters', @:) + " try with linear search + set notagbsearch + call feedkeys(":tag inbou\\\"\", 'xt') + call assert_equal('"tag inboundGSV inboundGovernor inboundGovernorCounters', @:) + set tagbsearch& call delete('Xtags') set tags& -- cgit From fdeb20ddde627ea99521a2c4c1525a91ffcd763c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 18 Nov 2022 22:26:39 +0800 Subject: vim-patch:8.2.0450: not enough testing for restricted mode and function calls Problem: Not enough testing for restricted mode and function calls. Solution: Add more tests. (Yegappan Lakshmanan, closes vim/vim#5847) https://github.com/vim/vim/commit/7d941ee032c02a4b682201881eb5c1f1958f17ee --- src/nvim/testdir/test_method.vim | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_method.vim b/src/nvim/testdir/test_method.vim index 057f4a1bea..ca3b736429 100644 --- a/src/nvim/testdir/test_method.vim +++ b/src/nvim/testdir/test_method.vim @@ -153,6 +153,22 @@ endfunc func Test_method_not_supported() call assert_fails('eval 123->changenr()', 'E276:') + call assert_fails('echo "abc"->invalidfunc()', 'E117:') + " Test for too many or too few arguments to a method + call assert_fails('let n="abc"->len(2)', 'E118:') + call assert_fails('let n=10->setwinvar()', 'E119:') endfunc -" vim: shiftwidth=2 sts=2 expandtab +" Test for passing optional arguments to methods +func Test_method_args() + let v:errors = [] + let n = 10->assert_inrange(1, 5, "Test_assert_inrange") + if v:errors[0] !~ 'Test_assert_inrange' + call assert_report(v:errors[0]) + else + " Test passed + let v:errors = [] + endif +endfunc + +" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker -- cgit From a4114f16bf0867bc93ef2c1cc47f01383c9820ee Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 18 Nov 2022 22:19:14 +0800 Subject: vim-patch:8.2.0469: Vim9: no error for missing ] after list Problem: Vim9: no error for missing ] after list. Solution: Add error message. Add more tests. https://github.com/vim/vim/commit/ee619e5bc0992e818f2d9540b093b769b9c27651 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_lambda.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_lambda.vim b/src/nvim/testdir/test_lambda.vim index ce15243993..025eb016a8 100644 --- a/src/nvim/testdir/test_lambda.vim +++ b/src/nvim/testdir/test_lambda.vim @@ -62,7 +62,7 @@ endfunc function Test_lambda_fails() call assert_equal(3, {a, b -> a + b}(1, 2)) call assert_fails('echo {a, a -> a + a}(1, 2)', 'E853:') - call assert_fails('echo {a, b -> a + b)}(1, 2)', 'E15:') + call assert_fails('echo {a, b -> a + b)}(1, 2)', 'E451:') echo assert_fails('echo 10->{a -> a + 2}', 'E107:') endfunc -- cgit From 92e51d7e4b79913434c7b74a275babcf65098b97 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 19 Nov 2022 12:47:44 +0800 Subject: vim-patch:8.2.5167: get(Fn, 'name') on funcref returns special byte code (#21112) Problem: get(Fn, 'name') on funcref returns special byte code. Solution: Use the printable name. https://github.com/vim/vim/commit/1ae8c262df7083dfb4b41485508951c50eccc84c Cherry-pick printable_func_name() from patch 8.2.0149. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_getvar.vim | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_getvar.vim b/src/nvim/testdir/test_getvar.vim index 5a96548893..e6b6341fce 100644 --- a/src/nvim/testdir/test_getvar.vim +++ b/src/nvim/testdir/test_getvar.vim @@ -133,11 +133,20 @@ func Test_get_lambda() call assert_equal([], get(l:L, 'args')) endfunc +func s:FooBar() +endfunc + " get({func}, {what} [, {default}]) func Test_get_func() let l:F = function('tr') call assert_equal('tr', get(l:F, 'name')) call assert_equal(l:F, get(l:F, 'func')) + + let Fb_func = function('s:FooBar') + call assert_match('\d\+_FooBar', get(Fb_func, 'name')) + let Fb_ref = funcref('s:FooBar') + call assert_match('\d\+_FooBar', get(Fb_ref, 'name')) + call assert_equal({'func has': 'no dict'}, get(l:F, 'dict', {'func has': 'no dict'})) call assert_equal(0, get(l:F, 'dict')) call assert_equal([], get(l:F, 'args')) -- cgit From c011747b5fc33eb7d9955c21d85085131ffaac0d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 19 Nov 2022 14:12:45 +0800 Subject: vim-patch:8.2.5148: invalid memory access when using expression on command line (#21113) Problem: Invalid memory access when using an expression on the command line. Solution: Make sure the position does not go negative. https://github.com/vim/vim/commit/6046aded8da002b08d380db29de2ba0268b6616e N/A patches for version.c: vim-patch:8.2.5149: cannot build without the +eval feature Problem: Cannot build without the +eval feature. (Tony Mechelynck) Solution: Add #ifdefs. https://github.com/vim/vim/commit/6689df024bce4309ec5884e445738fe07ee4ffcc Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_cmdline.vim | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 2921c8b41a..b9da4ca7bb 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -1850,6 +1850,11 @@ func Test_cmdline_expr() call assert_equal("\"e \\", @:) endfunc +" This was making the insert position negative +func Test_cmdline_expr_register() + exe "sil! norm! ?\e0\0\?\e0\" +endfunc + " Test for 'imcmdline' and 'imsearch' " This test doesn't actually test the input method functionality. func Test_cmdline_inputmethod() -- cgit From 0958dccc6ddeca2e4ab36c1a0f444d2d5995ae99 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 19 Nov 2022 16:39:30 +0800 Subject: vim-patch:8.2.5130: edit test for mode message fails when using valgrind (#21118) Problem: Edit test for mode message fails when using valgrind. Solution: Use WaitForAssert(). Run beep test later. https://github.com/vim/vim/commit/c5382b667ac4b69ddff5b5bc562386843bc9c07b Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_edit.vim | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index dc850515b0..89e597f401 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -1863,11 +1863,9 @@ func Test_edit_insertmode_ex_edit() call writefile(lines, 'Xtest_edit_insertmode_ex_edit') let buf = RunVimInTerminal('-S Xtest_edit_insertmode_ex_edit', #{rows: 6}) - call TermWait(buf, 50) - call assert_match('^-- INSERT --\s*$', term_getline(buf, 6)) + call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, 6))}) call term_sendkeys(buf, "\\") - call TermWait(buf, 50) - call assert_notmatch('^-- INSERT --\s*$', term_getline(buf, 6)) + call WaitForAssert({-> assert_notmatch('^-- INSERT --\s*$', term_getline(buf, 6))}) " clean up call StopVimInTerminal(buf) @@ -1875,15 +1873,16 @@ func Test_edit_insertmode_ex_edit() endfunc " Pressing escape in 'insertmode' should beep -func Test_edit_insertmode_esc_beeps() - throw "Skipped: Nvim does not support 'insertmode'" +" FIXME: Execute this later, when using valgrind it makes the next test +" Test_edit_insertmode_ex_edit() fail. +func Test_z_edit_insertmode_esc_beeps() new - set insertmode - call assert_beeps("call feedkeys(\"one\\", 'xt')") + " set insertmode + " call assert_beeps("call feedkeys(\"one\\", 'xt')") set insertmode& - " unsupported CTRL-G command should beep in insert mode. + " unsupported "CTRL-G l" command should beep in insert mode. call assert_beeps("normal i\l") - close! + bwipe! endfunc " Test for 'hkmap' and 'hkmapp' -- cgit From 035d41ac5e5fcbb49eb64b72a924c4d6f89f0579 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 20 Nov 2022 08:38:46 +0800 Subject: vim-patch:partial:9.0.0913: only change in current window triggers the WinScrolled event Problem: Only a change in the current window triggers the WinScrolled event. Solution: Trigger WinScrolled if any window scrolled or changed size. (issue vim/vim#11576) https://github.com/vim/vim/commit/0a60f79fd0c328b47b36279a95282e9f8d9e7512 Skip locking of window layout and E1312. Copy the latest version of all WinScrolled tests from Vim. Note: patch 9.0.0915 is needed for the Lua tests to pass. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_autocmd.vim | 70 ++++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 8 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 70da0a9ba2..bfb4a23f42 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -311,7 +311,7 @@ func Test_WinScrolled() au WinScrolled * let g:amatch = str2nr(expand('')) au WinScrolled * let g:afile = str2nr(expand('')) END - call writefile(lines, 'Xtest_winscrolled') + call writefile(lines, 'Xtest_winscrolled', 'D') let buf = RunVimInTerminal('-S Xtest_winscrolled', {'rows': 6}) call term_sendkeys(buf, ":echo g:scrolled\") @@ -346,7 +346,36 @@ func Test_WinScrolled() call WaitForAssert({-> assert_match('^v:true ', term_getline(buf, 6))}, 1000) call StopVimInTerminal(buf) - call delete('Xtest_winscrolled') +endfunc + +func Test_WinScrolled_mouse() + CheckRunVimInTerminal + + let lines =<< trim END + set nowrap scrolloff=0 + set mouse=a term=xterm ttymouse=sgr mousetime=200 clipboard= + call setline(1, ['foo']->repeat(32)) + split + let g:scrolled = 0 + au WinScrolled * let g:scrolled += 1 + END + call writefile(lines, 'Xtest_winscrolled_mouse', 'D') + let buf = RunVimInTerminal('-S Xtest_winscrolled_mouse', {'rows': 10}) + + " With the upper split focused, send a scroll-down event to the unfocused one. + call test_setmouse(7, 1) + call term_sendkeys(buf, "\") + call TermWait(buf) + call term_sendkeys(buf, ":echo g:scrolled\") + call WaitForAssert({-> assert_match('^1', term_getline(buf, 10))}, 1000) + + " Again, but this time while we're in insert mode. + call term_sendkeys(buf, "i\\") + call TermWait(buf) + call term_sendkeys(buf, ":echo g:scrolled\") + call WaitForAssert({-> assert_match('^2', term_getline(buf, 10))}, 1000) + + call StopVimInTerminal(buf) endfunc func Test_WinScrolled_close_curwin() @@ -359,7 +388,7 @@ func Test_WinScrolled_close_curwin() au WinScrolled * close au VimLeave * call writefile(['123456'], 'Xtestout') END - call writefile(lines, 'Xtest_winscrolled_close_curwin') + call writefile(lines, 'Xtest_winscrolled_close_curwin', 'D') let buf = RunVimInTerminal('-S Xtest_winscrolled_close_curwin', {'rows': 6}) " This was using freed memory @@ -367,12 +396,38 @@ func Test_WinScrolled_close_curwin() call TermWait(buf) call StopVimInTerminal(buf) + " check the startup script finished to the end call assert_equal(['123456'], readfile('Xtestout')) - - call delete('Xtest_winscrolled_close_curwin') call delete('Xtestout') endfunc +func Test_WinScrolled_once_only() + CheckRunVimInTerminal + + let lines =<< trim END + set cmdheight=2 + call setline(1, ['aaa', 'bbb']) + let trigger_count = 0 + func ShowInfo(id) + echo g:trigger_count g:winid winlayout() + endfunc + + vsplit + split + " use a timer to show the info after a redraw + au WinScrolled * let trigger_count += 1 | let winid = expand('') | call timer_start(100, 'ShowInfo') + wincmd j + wincmd l + END + call writefile(lines, 'Xtest_winscrolled_once', 'D') + let buf = RunVimInTerminal('-S Xtest_winscrolled_once', #{rows: 10, cols: 60, statusoff: 2}) + + call term_sendkeys(buf, "\") + call VerifyScreenDump(buf, 'Test_winscrolled_once_only_1', {}) + + call StopVimInTerminal(buf) +endfunc + func Test_WinScrolled_long_wrapped() CheckRunVimInTerminal @@ -385,7 +440,7 @@ func Test_WinScrolled_long_wrapped() call setline(1, repeat('foo', height * width)) call cursor(1, height * width) END - call writefile(lines, 'Xtest_winscrolled_long_wrapped') + call writefile(lines, 'Xtest_winscrolled_long_wrapped', 'D') let buf = RunVimInTerminal('-S Xtest_winscrolled_long_wrapped', {'rows': 6}) call term_sendkeys(buf, ":echo g:scrolled\") @@ -402,8 +457,6 @@ func Test_WinScrolled_long_wrapped() call term_sendkeys(buf, '$') call term_sendkeys(buf, ":echo g:scrolled\") call WaitForAssert({-> assert_match('^3 ', term_getline(buf, 6))}, 1000) - - call delete('Xtest_winscrolled_long_wrapped') endfunc func Test_WinClosed() @@ -2788,6 +2841,7 @@ func Test_SpellFileMissing_bwipe() call assert_fails('set spell spelllang=0', 'E937:') au! SpellFileMissing + set nospell spelllang=en bwipe endfunc -- cgit From 91c192922da0240be5a8eb4045dae6cd968957e9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 20 Nov 2022 21:11:57 +0800 Subject: vim-patch:9.0.0915: WinScrolled may trigger immediately when defined Problem: WinScrolled may trigger immediately when defined. Solution: Initialize the fields in all windows. (closes vim/vim#11582) https://github.com/vim/vim/commit/29967732761d1ffb5592db5f5aa7036f5b52abf1 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_autocmd.vim | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index bfb4a23f42..3030ecdfa9 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -428,6 +428,32 @@ func Test_WinScrolled_once_only() call StopVimInTerminal(buf) endfunc +" Check that WinScrolled is not triggered immediately when defined and there +" are split windows. +func Test_WinScrolled_not_when_defined() + CheckRunVimInTerminal + + let lines =<< trim END + call setline(1, ['aaa', 'bbb']) + echo 'nothing happened' + func ShowTriggered(id) + echo 'triggered' + endfunc + END + call writefile(lines, 'Xtest_winscrolled_not', 'D') + let buf = RunVimInTerminal('-S Xtest_winscrolled_not', #{rows: 10, cols: 60, statusoff: 2}) + call term_sendkeys(buf, ":split\") + call TermWait(buf) + " use a timer to show the message after redrawing + call term_sendkeys(buf, ":au WinScrolled * call timer_start(100, 'ShowTriggered')\") + call VerifyScreenDump(buf, 'Test_winscrolled_not_when_defined_1', {}) + + call term_sendkeys(buf, "\") + call VerifyScreenDump(buf, 'Test_winscrolled_not_when_defined_2', {}) + + call StopVimInTerminal(buf) +endfunc + func Test_WinScrolled_long_wrapped() CheckRunVimInTerminal -- cgit From ef5dfe6c652473a8982b93bceebb470c1cee813e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 22 Nov 2022 06:56:56 +0800 Subject: vim-patch:8.2.2435: setline() gives an error for some types Problem: setline() gives an error for some types. Solution: Allow any type, convert each item to a string. https://github.com/vim/vim/commit/3445320839a38b3b0c253513b125da8298ec27d6 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_bufline.vim | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_bufline.vim b/src/nvim/testdir/test_bufline.vim index fae6b1dab7..0553774819 100644 --- a/src/nvim/testdir/test_bufline.vim +++ b/src/nvim/testdir/test_bufline.vim @@ -5,6 +5,7 @@ source screendump.vim source check.vim func Test_setbufline_getbufline() + " similar to Test_set_get_bufline() new let b = bufnr('%') hide @@ -38,6 +39,12 @@ func Test_setbufline_getbufline() call assert_equal(['e'], getbufline(b, 5)) call assert_equal([], getbufline(b, 6)) call assert_equal([], getbufline(b, 2, 1)) + + call setbufline(b, 2, [function('eval'), #{key: 123}, test_null_job()]) + call assert_equal(["function('eval')", + \ "{'key': 123}", + \ "no process"], + \ getbufline(b, 2, 4)) exe "bwipe! " . b endfunc -- cgit From 5836c89ed0506748458e495b2751789e81057519 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 22 Nov 2022 07:11:24 +0800 Subject: vim-patch:8.2.2479: set/getbufline test fails without the job feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: set/getbufline test fails without the job feature. Solution: Check whether the job feature is supported. (Dominique Pellé, closes vim/vim#7790) https://github.com/vim/vim/commit/00385114dbd6a3d59516baa02e1ea86a1e7ee70e Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_bufline.vim | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_bufline.vim b/src/nvim/testdir/test_bufline.vim index 0553774819..9c4e48734a 100644 --- a/src/nvim/testdir/test_bufline.vim +++ b/src/nvim/testdir/test_bufline.vim @@ -40,11 +40,13 @@ func Test_setbufline_getbufline() call assert_equal([], getbufline(b, 6)) call assert_equal([], getbufline(b, 2, 1)) - call setbufline(b, 2, [function('eval'), #{key: 123}, test_null_job()]) - call assert_equal(["function('eval')", - \ "{'key': 123}", - \ "no process"], - \ getbufline(b, 2, 4)) + if has('job') + call setbufline(b, 2, [function('eval'), #{key: 123}, test_null_job()]) + call assert_equal(["function('eval')", + \ "{'key': 123}", + \ "no process"], + \ getbufline(b, 2, 4)) + endif exe "bwipe! " . b endfunc -- cgit From 9b768752353d3cf99c6cb02e6c1f9d70c029ecb6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 22 Nov 2022 06:52:21 +0800 Subject: vim-patch:9.0.0916: getbufline() is inefficient for getting a single line Problem: getbufline() is inefficient for getting a single line. Solution: Add getbufoneline(). https://github.com/vim/vim/commit/ce30ccc06af7f2c03762e5b18dde37b26ea6ec42 Cherry-pick part of usr_41.txt from patch 8.1.1628. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_bufline.vim | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_bufline.vim b/src/nvim/testdir/test_bufline.vim index 9c4e48734a..d4dee38620 100644 --- a/src/nvim/testdir/test_bufline.vim +++ b/src/nvim/testdir/test_bufline.vim @@ -11,7 +11,9 @@ func Test_setbufline_getbufline() hide call assert_equal(0, setbufline(b, 1, ['foo', 'bar'])) call assert_equal(['foo'], getbufline(b, 1)) + call assert_equal('foo', getbufoneline(b, 1)) call assert_equal(['bar'], getbufline(b, '$')) + call assert_equal('bar', getbufoneline(b, '$')) call assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) exe "bd!" b call assert_equal([], getbufline(b, 1, 2)) @@ -35,8 +37,11 @@ func Test_setbufline_getbufline() call assert_equal(0, setbufline(b, 4, ['d', 'e'])) call assert_equal(['c'], b->getbufline(3)) + call assert_equal('c', b->getbufoneline(3)) call assert_equal(['d'], getbufline(b, 4)) + call assert_equal('d', getbufoneline(b, 4)) call assert_equal(['e'], getbufline(b, 5)) + call assert_equal('e', getbufoneline(b, 5)) call assert_equal([], getbufline(b, 6)) call assert_equal([], getbufline(b, 2, 1)) -- cgit From d41e93d5a83642f90898cae211e017d99ff97fd9 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Tue, 22 Nov 2022 23:28:49 +0100 Subject: vim-patch:9.0.0922: Mermaid files are not recognized (#21160) Problem: Mermaid files are not recognized. Solution: Add patterns for Mermaid. (Crag MacEachern) https://github.com/vim/vim/commit/364438d1e817d1d76003695f9ab533df35f8948a Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_filetype.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index c8d8239757..1d9465dd94 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -350,6 +350,7 @@ let s:filename_checks = { \ 'maxima': ['file.demo', 'file.dmt', 'file.dm1', 'file.dm2', 'file.dm3', \ 'file.wxm', 'maxima-init.mac'], \ 'mel': ['file.mel'], + \ 'mermaid': ['file.mmd', 'file.mmdc', 'file.mermaid'], \ 'meson': ['meson.build', 'meson_options.txt'], \ 'messages': ['/log/auth', '/log/cron', '/log/daemon', '/log/debug', '/log/kern', '/log/lpr', '/log/mail', '/log/messages', '/log/news/news', '/log/syslog', '/log/user', \ '/log/auth.log', '/log/cron.log', '/log/daemon.log', '/log/debug.log', '/log/kern.log', '/log/lpr.log', '/log/mail.log', '/log/messages.log', '/log/news/news.log', '/log/syslog.log', '/log/user.log', -- cgit From 4571ba4d0a5234408e544c3a98f107688a792f0d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 23 Nov 2022 09:54:48 +0800 Subject: vim-patch:partial:9.0.0917: the WinScrolled autocommand event is not enough (#21161) Problem: The WinScrolled autocommand event is not enough. Solution: Add WinResized and provide information about what changed. (closes vim/vim#11576) https://github.com/vim/vim/commit/35fc61cb5b5eba8bbb9d8f0700332fbab38f40ca Omit "func_name" comment in tv_dict_extend(): Vim9 script only. Skip layout locking and E1312. Skip list_alloc_with_items() and list_set_item(). Since this overrides remaining changes in patch 9.0.0913, that patch can now be marked as fully ported: vim-patch:9.0.0913: only change in current window triggers the WinScrolled event N/A patches for version.c: vim-patch:9.0.0919: build failure with tiny features Problem: Build failure with tiny features. Solution: Adjust #ifdef's. https://github.com/vim/vim/commit/9c5b7cb4cf67c64648a324e9dfd1e17d793335a4 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_autocmd.vim | 84 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 3030ecdfa9..2945b4a03a 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -295,6 +295,61 @@ func Test_win_tab_autocmd() unlet g:record endfunc +func Test_WinResized() + CheckRunVimInTerminal + + let lines =<< trim END + set scrolloff=0 + call setline(1, ['111', '222']) + vnew + call setline(1, ['aaa', 'bbb']) + new + call setline(1, ['foo', 'bar']) + + let g:resized = 0 + au WinResized * let g:resized += 1 + + func WriteResizedEvent() + call writefile([json_encode(v:event)], 'XresizeEvent') + endfunc + au WinResized * call WriteResizedEvent() + END + call writefile(lines, 'Xtest_winresized', 'D') + let buf = RunVimInTerminal('-S Xtest_winresized', {'rows': 10}) + + " redraw now to avoid a redraw after the :echo command + call term_sendkeys(buf, ":redraw!\") + call TermWait(buf) + + call term_sendkeys(buf, ":echo g:resized\") + call WaitForAssert({-> assert_match('^0$', term_getline(buf, 10))}, 1000) + + " increase window height, two windows will be reported + call term_sendkeys(buf, "\+") + call TermWait(buf) + call term_sendkeys(buf, ":echo g:resized\") + call WaitForAssert({-> assert_match('^1$', term_getline(buf, 10))}, 1000) + + let event = readfile('XresizeEvent')[0]->json_decode() + call assert_equal({ + \ 'windows': [1002, 1001], + \ }, event) + + " increase window width, three windows will be reported + call term_sendkeys(buf, "\>") + call TermWait(buf) + call term_sendkeys(buf, ":echo g:resized\") + call WaitForAssert({-> assert_match('^2$', term_getline(buf, 10))}, 1000) + + let event = readfile('XresizeEvent')[0]->json_decode() + call assert_equal({ + \ 'windows': [1002, 1001, 1000], + \ }, event) + + call delete('XresizeEvent') + call StopVimInTerminal(buf) +endfunc + func Test_WinScrolled() CheckRunVimInTerminal @@ -305,11 +360,15 @@ func Test_WinScrolled() endfor let win_id = win_getid() let g:matched = v:false + func WriteScrollEvent() + call writefile([json_encode(v:event)], 'XscrollEvent') + endfunc execute 'au WinScrolled' win_id 'let g:matched = v:true' let g:scrolled = 0 au WinScrolled * let g:scrolled += 1 au WinScrolled * let g:amatch = str2nr(expand('')) au WinScrolled * let g:afile = str2nr(expand('')) + au WinScrolled * call WriteScrollEvent() END call writefile(lines, 'Xtest_winscrolled', 'D') let buf = RunVimInTerminal('-S Xtest_winscrolled', {'rows': 6}) @@ -321,15 +380,33 @@ func Test_WinScrolled() call term_sendkeys(buf, "zlzh:echo g:scrolled\") call WaitForAssert({-> assert_match('^2 ', term_getline(buf, 6))}, 1000) + let event = readfile('XscrollEvent')[0]->json_decode() + call assert_equal({ + \ 'all': {'leftcol': 1, 'topline': 0, 'width': 0, 'height': 0, 'skipcol': 0}, + \ '1000': {'leftcol': -1, 'topline': 0, 'width': 0, 'height': 0, 'skipcol': 0} + \ }, event) + " Scroll up/down in Normal mode. call term_sendkeys(buf, "\\:echo g:scrolled\") call WaitForAssert({-> assert_match('^4 ', term_getline(buf, 6))}, 1000) + let event = readfile('XscrollEvent')[0]->json_decode() + call assert_equal({ + \ 'all': {'leftcol': 0, 'topline': 1, 'width': 0, 'height': 0, 'skipcol': 0}, + \ '1000': {'leftcol': 0, 'topline': -1, 'width': 0, 'height': 0, 'skipcol': 0} + \ }, event) + " Scroll up/down in Insert mode. call term_sendkeys(buf, "Mi\\\i\\\") call term_sendkeys(buf, ":echo g:scrolled\") call WaitForAssert({-> assert_match('^6 ', term_getline(buf, 6))}, 1000) + let event = readfile('XscrollEvent')[0]->json_decode() + call assert_equal({ + \ 'all': {'leftcol': 0, 'topline': 1, 'width': 0, 'height': 0, 'skipcol': 0}, + \ '1000': {'leftcol': 0, 'topline': -1, 'width': 0, 'height': 0, 'skipcol': 0} + \ }, event) + " Scroll the window horizontally to focus the last letter of the third line " containing only six characters. Moving to the previous and shorter lines " should trigger another autocommand as Vim has to make them visible. @@ -337,6 +414,12 @@ func Test_WinScrolled() call term_sendkeys(buf, ":echo g:scrolled\") call WaitForAssert({-> assert_match('^8 ', term_getline(buf, 6))}, 1000) + let event = readfile('XscrollEvent')[0]->json_decode() + call assert_equal({ + \ 'all': {'leftcol': 5, 'topline': 0, 'width': 0, 'height': 0, 'skipcol': 0}, + \ '1000': {'leftcol': -5, 'topline': 0, 'width': 0, 'height': 0, 'skipcol': 0} + \ }, event) + " Ensure the command was triggered for the specified window ID. call term_sendkeys(buf, ":echo g:matched\") call WaitForAssert({-> assert_match('^v:true ', term_getline(buf, 6))}, 1000) @@ -345,6 +428,7 @@ func Test_WinScrolled() call term_sendkeys(buf, ":echo g:amatch == win_id && g:afile == win_id\") call WaitForAssert({-> assert_match('^v:true ', term_getline(buf, 6))}, 1000) + call delete('XscrollEvent') call StopVimInTerminal(buf) endfunc -- cgit From 81c87857f632d1afe147e9b77a97da38f8f3a887 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 24 Nov 2022 18:37:52 +0800 Subject: vim-patch:8.2.3698: match highlighting continues over breakindent Problem: Match highlighting continues over breakindent. Solution: Stop before the end column. (closes vim/vim#9242) https://github.com/vim/vim/commit/0c359af5c0fd106d3f57cc0bb7cef1c89b5e1e10 Cherry-pick Test_matchdelete_redraw() from patch 8.2.1077. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_match.vim | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_match.vim b/src/nvim/testdir/test_match.vim index 5d9be99444..e9dae8d67e 100644 --- a/src/nvim/testdir/test_match.vim +++ b/src/nvim/testdir/test_match.vim @@ -363,4 +363,41 @@ func Test_matchadd_other_window() call delete('XscriptMatchCommon') endfunc +func Test_match_in_linebreak() + CheckRunVimInTerminal + + let lines =<< trim END + set breakindent linebreak breakat+=] + call printf('%s]%s', repeat('x', 50), repeat('x', 70))->setline(1) + call matchaddpos('ErrorMsg', [[1, 51]]) + END + call writefile(lines, 'XscriptMatchLinebreak') + let buf = RunVimInTerminal('-S XscriptMatchLinebreak', #{rows: 10}) + call TermWait(buf) + call VerifyScreenDump(buf, 'Test_match_linebreak', {}) + + call StopVimInTerminal(buf) + call delete('XscriptMatchLinebreak') +endfunc + +" Test for deleting matches outside of the screen redraw top/bottom lines +" This should cause a redraw of those lines. +func Test_matchdelete_redraw() + new + call setline(1, range(1, 500)) + call cursor(250, 1) + let m1 = matchaddpos('Search', [[250]]) + let m2 = matchaddpos('Search', [[10], [450]]) + redraw! + let m3 = matchaddpos('Search', [[240], [260]]) + call matchdelete(m2) + let m = getmatches() + call assert_equal(2, len(m)) + call assert_equal([250], m[0].pos1) + redraw! + call matchdelete(m1) + call assert_equal(1, len(getmatches())) + bw! +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From e38ae3b74ff513d991f8212dfbba75fe8c66aad3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 24 Nov 2022 18:53:28 +0800 Subject: vim-patch:8.2.3940: match highlight disappears when doing incsearch for ":s/pat" Problem: Match highlight disappears when doing incsearch for ":s/pat". Solution: Only use line limit for incsearch highlighting. (closes vim/vim#9425) https://github.com/vim/vim/commit/94fb8274ca8c93a10102d41c8bcc848f75cb7334 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_match.vim | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_match.vim b/src/nvim/testdir/test_match.vim index e9dae8d67e..3c63314253 100644 --- a/src/nvim/testdir/test_match.vim +++ b/src/nvim/testdir/test_match.vim @@ -380,6 +380,27 @@ func Test_match_in_linebreak() call delete('XscriptMatchLinebreak') endfunc +func Test_match_with_incsearch() + CheckRunVimInTerminal + + let lines =<< trim END + set incsearch + call setline(1, range(20)) + call matchaddpos('ErrorMsg', [3]) + END + call writefile(lines, 'XmatchWithIncsearch') + let buf = RunVimInTerminal('-S XmatchWithIncsearch', #{rows: 6}) + call TermWait(buf) + call VerifyScreenDump(buf, 'Test_match_with_incsearch_1', {}) + + call term_sendkeys(buf, ":s/0") + call VerifyScreenDump(buf, 'Test_match_with_incsearch_2', {}) + + call term_sendkeys(buf, "\") + call StopVimInTerminal(buf) + call delete('XmatchWithIncsearch') +endfunc + " Test for deleting matches outside of the screen redraw top/bottom lines " This should cause a redraw of those lines. func Test_matchdelete_redraw() -- cgit From a98970219ddc90b6f599203f6bb24da79fc6bbeb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 24 Nov 2022 19:05:53 +0800 Subject: vim-patch:8.2.4062: match highlighting of tab too short Problem: Match highlighting of tab too short. Solution: Do not stop match highlighting if on a Tab. (Christian Brabandt, closes vim/vim#9507, closes vim/vim#9500) https://github.com/vim/vim/commit/0bbca540f7377889e2154aa5731f6eeffcb5c0cc Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_match.vim | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_match.vim b/src/nvim/testdir/test_match.vim index 3c63314253..600b6132a9 100644 --- a/src/nvim/testdir/test_match.vim +++ b/src/nvim/testdir/test_match.vim @@ -421,4 +421,22 @@ func Test_matchdelete_redraw() bw! endfunc +func Test_match_tab_with_linebreak() + CheckRunVimInTerminal + + let lines =<< trim END + set linebreak + call setline(1, "\tix") + call matchadd('ErrorMsg', '\t') + END + call writefile(lines, 'XscriptMatchTabLinebreak') + let buf = RunVimInTerminal('-S XscriptMatchTabLinebreak', #{rows: 10}) + call TermWait(buf) + call VerifyScreenDump(buf, 'Test_match_tab_linebreak', {}) + + call StopVimInTerminal(buf) + call delete('XscriptMatchTabLinebreak') +endfunc + + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 5bdd787a7a2274d802479498ccd1d1f0c4fc589b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 25 Nov 2022 10:35:20 +0800 Subject: vim-patch:8.2.2466: max() and min() can give many error messages Problem: Max() and min() can give many error messages. Solution: Bail out at the first error. (closes vim/vim#1039, closes vim/vim#7778) https://github.com/vim/vim/commit/ab65fc77c5389f7d3f788bbdc3d931561feab131 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_functions.vim | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 5ff544ab55..f0cd8ee878 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -110,6 +110,10 @@ func Test_max() call assert_fails('call max(1)', 'E712:') " call assert_fails('call max(v:none)', 'E712:') + + " check we only get one error + call assert_fails('call max([#{}, [1]])', ['E728:', 'E728:']) + call assert_fails('call max(#{a: {}, b: [1]})', ['E728:', 'E728:']) endfunc func Test_min() @@ -123,6 +127,10 @@ func Test_min() call assert_fails('call min(1)', 'E712:') " call assert_fails('call min(v:none)', 'E712:') + + " check we only get one error + call assert_fails('call min([[1], #{}])', ['E745:', 'E745:']) + call assert_fails('call min(#{a: [1], b: #{}})', ['E745:', 'E745:']) endfunc func Test_strwidth() -- cgit From 0d6e1273d6e39c1102d5ee77e778a1d2d42a4fa0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 25 Nov 2022 10:38:30 +0800 Subject: vim-patch:8.2.2886: various pieces of code not covered by tests Problem: Various pieces of code not covered by tests. Solution: Add a few more tests. (Yegappan Lakshmanan, closes vim/vim#8255) https://github.com/vim/vim/commit/34fcb697240c1bc9e69417ed75db3b1a83479724 Nvim does not have test_unknown(). Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_expr.vim | 3 ++- src/nvim/testdir/test_functions.vim | 2 ++ src/nvim/testdir/test_listdict.vim | 5 +++++ src/nvim/testdir/test_registers.vim | 9 +++++++++ src/nvim/testdir/test_user_func.vim | 10 ++++++++++ 5 files changed, 28 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 9dbc923b96..f33358c59a 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -92,10 +92,11 @@ func Test_getreg_empty_list() let y = x call add(x, 'foo') call assert_equal(['foo'], y) + call assert_fails('call getreg([])', 'E730:') endfunc func Test_loop_over_null_list() - let null_list = submatch(1, 1) + let null_list = v:_null_list for i in null_list call assert_report('should not get here') endfor diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index f0cd8ee878..1308beeae5 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -127,6 +127,7 @@ func Test_min() call assert_fails('call min(1)', 'E712:') " call assert_fails('call min(v:none)', 'E712:') + call assert_fails('call min([1, {}])', 'E728:') " check we only get one error call assert_fails('call min([[1], #{}])', ['E745:', 'E745:']) @@ -591,6 +592,7 @@ func Test_tr() call assert_fails("let s=tr('abcd', 'abcd', 'def')", 'E475:') call assert_equal('hEllO', tr('hello', 'eo', 'EO')) call assert_equal('hello', tr('hello', 'xy', 'ab')) + call assert_fails('call tr("abc", "123", "₁₂")', 'E475:') set encoding=utf8 endfunc diff --git a/src/nvim/testdir/test_listdict.vim b/src/nvim/testdir/test_listdict.vim index 7ea488f41d..8d7bede403 100644 --- a/src/nvim/testdir/test_listdict.vim +++ b/src/nvim/testdir/test_listdict.vim @@ -516,6 +516,11 @@ func Test_list_locked_var_unlet() call assert_equal(expected[depth][u][1], ps) endfor endfor + " Deleting a list range should fail if the range is locked + let l = [1, 2, 3, 4] + lockvar l[1:2] + call assert_fails('unlet l[1:2]', 'E741:') + unlet l endfunc " Locked variables and :unlet or list / dict functions diff --git a/src/nvim/testdir/test_registers.vim b/src/nvim/testdir/test_registers.vim index 5bdbbe7a22..a308a3e7eb 100644 --- a/src/nvim/testdir/test_registers.vim +++ b/src/nvim/testdir/test_registers.vim @@ -299,6 +299,7 @@ endfunc func Test_set_register() call assert_fails("call setreg('#', 200)", 'E86:') + " call assert_fails("call setreg('a', test_unknown())", 'E908:') edit Xfile_alt_1 let b1 = bufnr('') @@ -490,6 +491,14 @@ func Test_get_reginfo() let info = getreginfo('"') call assert_equal('z', info.points_to) + let @a="a1b2" + nnoremap let g:RegInfo = getreginfo() + exe "normal \"a\" + call assert_equal({'regcontents': ['a1b2'], 'isunnamed': v:false, + \ 'regtype': 'v'}, g:RegInfo) + nunmap + unlet g:RegInfo + bwipe! endfunc diff --git a/src/nvim/testdir/test_user_func.vim b/src/nvim/testdir/test_user_func.vim index f13c082814..4742293ed5 100644 --- a/src/nvim/testdir/test_user_func.vim +++ b/src/nvim/testdir/test_user_func.vim @@ -163,6 +163,16 @@ func Test_default_arg() \ .. "1 return deepcopy(a:)\n" \ .. " endfunction", \ execute('func Args2')) + + " Error in default argument expression + let l =<< trim END + func F1(x = y) + return a:x * 2 + endfunc + echo F1() + END + let @a = l->join("\n") + call assert_fails("exe @a", 'E121:') endfunc func s:addFoo(lead) -- cgit From 0482f53395e7b26016942bd8e5a173a7894a44a5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 25 Nov 2022 10:43:51 +0800 Subject: vim-patch:9.0.0936: wrong type for "isunnamed" returned by getreginfo() Problem: Wrong type for "isunnamed" returned by getreginfo(). Solution: Use VAR_BOOL instead of VAR_SPECIAL. (closes vim/vim#11598) https://github.com/vim/vim/commit/82946e1439d31e86dfeb6166415c73e70475cce2 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_registers.vim | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_registers.vim b/src/nvim/testdir/test_registers.vim index a308a3e7eb..bbf1aa53b5 100644 --- a/src/nvim/testdir/test_registers.vim +++ b/src/nvim/testdir/test_registers.vim @@ -499,6 +499,13 @@ func Test_get_reginfo() nunmap unlet g:RegInfo + " The type of "isunnamed" was VAR_SPECIAL but should be VAR_BOOL. Can only + " be noticed when using json_encod(). + call setreg('a', 'foo') + let reginfo = getreginfo('a') + let expected = #{regcontents: ['foo'], isunnamed: v:false, regtype: 'v'} + call assert_equal(json_encode(expected), json_encode(reginfo)) + bwipe! endfunc -- cgit From ba360a26a294e0ed83ff8e401caabaf4a17c7c30 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 25 Nov 2022 15:07:25 +0800 Subject: vim-patch:8.2.2684: not enough folding code is tested Problem: Not enough folding code is tested. Solution: Add more test cases. (Yegappan Lakshmanan, closes vim/vim#8046) https://github.com/vim/vim/commit/5c504f680e63120fea36becfabb8d939d4449e34 Reorder test_fold.vim to match upstream. Cherry-pick Test_fold_expr_error() from patch 8.2.0633. Cherry-pick syntax feature check from patch 8.2.1432. Cherry-pick a delete() call from patch 8.2.2112. --- src/nvim/testdir/test_fold.vim | 307 ++++++++++++++++++++++++++++++------ src/nvim/testdir/test_mksession.vim | 32 ++++ src/nvim/testdir/test_source.vim | 17 ++ 3 files changed, 306 insertions(+), 50 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_fold.vim b/src/nvim/testdir/test_fold.vim index 1b979dbc03..35fa81e296 100644 --- a/src/nvim/testdir/test_fold.vim +++ b/src/nvim/testdir/test_fold.vim @@ -142,6 +142,21 @@ func Test_indent_fold2() bw! endfunc +" Test for fold indent with indents greater than 'foldnestmax' +func Test_indent_fold_max() + new + setlocal foldmethod=indent + setlocal shiftwidth=2 + " 'foldnestmax' default value is 20 + call setline(1, "\t\t\t\t\t\ta") + call assert_equal(20, foldlevel(1)) + setlocal foldnestmax=10 + call assert_equal(10, foldlevel(1)) + setlocal foldnestmax=-1 + call assert_equal(0, foldlevel(1)) + bw! +endfunc + func Test_manual_fold_with_filter() CheckExecutable cat for type in ['manual', 'marker'] @@ -465,27 +480,6 @@ func Test_move_folds_around_indent() bw! endfunc -" test for patch 7.3.637 -" Cannot catch the error caused by a foldopen when there is no fold. -func Test_foldopen_exception() - enew! - let a = 'No error caught' - try - foldopen - catch - let a = matchstr(v:exception,'^[^ ]*') - endtry - call assert_equal('Vim(foldopen):E490:', a) - - let a = 'No error caught' - try - foobar - catch - let a = matchstr(v:exception,'^[^ ]*') - endtry - call assert_match('E492:', a) -endfunc - func Test_folddoopen_folddoclosed() new call setline(1, range(1, 9)) @@ -539,11 +533,24 @@ func Test_fold_error() bw! endfunc +func Test_foldtext_recursive() + new + call setline(1, ['{{{', 'some text', '}}}']) + setlocal foldenable foldmethod=marker foldtext=foldtextresult(v\:foldstart) + " This was crashing because of endless recursion. + 2foldclose + redraw + call assert_equal(1, foldlevel(2)) + call assert_equal(1, foldclosed(2)) + call assert_equal(3, foldclosedend(2)) + bwipe! +endfunc + " Various fold related tests " Basic test if a fold can be created, opened, moving to the end and closed func Test_fold_manual() - enew! + new set fdm=manual let content = ['1 aa', '2 bb', '3 cc'] @@ -559,12 +566,12 @@ func Test_fold_manual() call assert_equal('1 aa', getline(foldclosed('.'))) set fdm& - enew! + bw! endfunc " test folding with markers. func Test_fold_marker() - enew! + new set fdm=marker fdl=1 fdc=3 let content = ['4 dd {{{', '5 ee {{{ }}}', '6 ff }}}'] @@ -578,13 +585,22 @@ func Test_fold_marker() normal kYpj call assert_equal(0, foldlevel('.')) + " Use only closing fold marker (without and with a count) + set fdl& + %d _ + call setline(1, ['one }}}', 'two']) + call assert_equal([0, 0], [foldlevel(1), foldlevel(2)]) + %d _ + call setline(1, ['one }}}4', 'two']) + call assert_equal([4, 3], [foldlevel(1), foldlevel(2)]) + set fdm& fdl& fdc& - enew! + bw! endfunc " test create fold markers with C filetype func Test_fold_create_marker_in_C() - enew! + bw! set fdm=marker fdl=9 set filetype=c @@ -609,12 +625,12 @@ func Test_fold_create_marker_in_C() endfor set fdm& fdl& - enew! + bw! endfunc " test folding with indent func Test_fold_indent() - enew! + new set fdm=indent sw=2 let content = ['1 aa', '2 bb', '3 cc'] @@ -626,16 +642,14 @@ func Test_fold_indent() call assert_equal(1, foldlevel('.')) set fdm& sw& - enew! + bw! endfunc " test syntax folding func Test_fold_syntax() - if !has('syntax') - return - endif + CheckFeature syntax - enew! + new set fdm=syntax fdl=0 syn region Hup start="dd" end="ii" fold contains=Fd1,Fd2,Fd3 @@ -659,7 +673,7 @@ func Test_fold_syntax() syn clear Fd1 Fd2 Fd3 Hup set fdm& fdl& - enew! + bw! endfunc func Flvl() @@ -678,7 +692,7 @@ endfun " test expression folding func Test_fold_expr() - enew! + new set fdm=expr fde=Flvl() let content = ['1 aa', @@ -706,14 +720,14 @@ func Test_fold_expr() call assert_equal(0, foldlevel('.')) set fdm& fde& - enew! + bw! endfunc " Bug with fdm=indent and moving folds " Moving a fold a few times, messes up the folds below the moved fold. " Fixed by 7.4.700 func Test_fold_move() - enew! + new set fdm=indent sw=2 fdl=0 let content = ['', '', 'Line1', ' Line2', ' Line3', @@ -733,24 +747,33 @@ func Test_fold_move() call assert_equal('+-- 2 lines: Line8', 10->foldtextresult()) set fdm& sw& fdl& - enew! + bw! endfunc -func Test_foldtext_recursive() +" test for patch 7.3.637 +" Cannot catch the error caused by a foldopen when there is no fold. +func Test_foldopen_exception() new - call setline(1, ['{{{', 'some text', '}}}']) - setlocal foldenable foldmethod=marker foldtext=foldtextresult(v\:foldstart) - " This was crashing because of endless recursion. - 2foldclose - redraw - call assert_equal(1, foldlevel(2)) - call assert_equal(1, foldclosed(2)) - call assert_equal(3, foldclosedend(2)) - bwipe! + let a = 'No error caught' + try + foldopen + catch + let a = matchstr(v:exception,'^[^ ]*') + endtry + call assert_equal('Vim(foldopen):E490:', a) + + let a = 'No error caught' + try + foobar + catch + let a = matchstr(v:exception,'^[^ ]*') + endtry + call assert_match('E492:', a) + bw! endfunc func Test_fold_last_line_with_pagedown() - enew! + new set fdm=manual let expect = '+-- 11 lines: 9---' @@ -770,7 +793,7 @@ func Test_fold_last_line_with_pagedown() call assert_equal(expect, ScreenLines(1, len(expect))[0]) set fdm& - enew! + bw! endfunc func Test_folds_with_rnu() @@ -861,6 +884,31 @@ func Test_fold_delete_first_line() set foldmethod& endfunc +" Test for errors in 'foldexpr' +func Test_fold_expr_error() + new + call setline(1, ['one', 'two', 'three']) + " In a window with no folds, foldlevel() should return 0 + call assert_equal(0, foldlevel(1)) + + " Return a list from the expression + set foldexpr=[] + set foldmethod=expr + for i in range(3) + call assert_equal(0, foldlevel(i)) + endfor + + " expression error + set foldexpr=[{] + set foldmethod=expr + for i in range(3) + call assert_equal(0, foldlevel(i)) + endfor + + set foldmethod& foldexpr& + close! +endfunc + func Test_undo_fold_deletion() new set fdm=marker @@ -944,6 +992,165 @@ func Test_fold_relative_move() call assert_equal(2, winline()) set fdm& sw& wrap& tw& + bw! +endfunc + +" Test for calling foldlevel() from a fold expression +let g:FoldLevels = [] +func FoldExpr1(lnum) + let f = [a:lnum] + for i in range(1, line('$')) + call add(f, foldlevel(i)) + endfor + call add(g:FoldLevels, f) + return getline(a:lnum)[0] == "\t" +endfunc + +func Test_foldexpr_foldlevel() + new + call setline(1, ['one', "\ttwo", "\tthree"]) + setlocal foldmethod=expr + setlocal foldexpr=FoldExpr1(v:lnum) + setlocal foldenable + setlocal foldcolumn=3 + redraw! + call assert_equal([[1, -1, -1, -1], [2, -1, -1, -1], [3, 0, 1, -1]], + \ g:FoldLevels) + set foldmethod& foldexpr& foldenable& foldcolumn& + bw! +endfunc + +" Test for returning different values from a fold expression +func FoldExpr2(lnum) + if a:lnum == 1 || a:lnum == 4 + return -2 + elseif a:lnum == 2 + return 'a1' + elseif a:lnum == 3 + return 's4' + endif + return '=' +endfunc + +func Test_foldexpr_2() + new + call setline(1, ['one', 'two', 'three', 'four']) + setlocal foldexpr=FoldExpr2(v:lnum) + setlocal foldmethod=expr + call assert_equal([0, 1, 1, 0], [foldlevel(1), foldlevel(2), foldlevel(3), + \ foldlevel(4)]) + bw! +endfunc + +" Test for the 'foldclose' option +func Test_foldclose_opt() + CheckScreendump + + let lines =<< trim END + set foldmethod=manual foldclose=all foldopen=all + call setline(1, ['one', 'two', 'three', 'four']) + 2,3fold + func XsaveFoldLevels() + redraw! + call writefile([json_encode([foldclosed(1), foldclosed(2), foldclosed(3), + \ foldclosed(4)])], 'Xoutput', 'a') + endfunc + END + call writefile(lines, 'Xscript') + let rows = 10 + let buf = RunVimInTerminal('-S Xscript', {'rows': rows}) + call term_wait(buf) + call term_sendkeys(buf, ":set noruler\n") + call term_wait(buf) + call term_sendkeys(buf, ":call XsaveFoldLevels()\n") + call term_sendkeys(buf, "2G") + call WaitForAssert({-> assert_equal('two', term_getline(buf, 2))}) + call term_sendkeys(buf, ":call XsaveFoldLevels()\n") + call term_sendkeys(buf, "4G") + call WaitForAssert({-> assert_equal('four', term_getline(buf, 3))}) + call term_sendkeys(buf, ":call XsaveFoldLevels()\n") + call term_sendkeys(buf, "3G") + call WaitForAssert({-> assert_equal('three', term_getline(buf, 3))}) + call term_sendkeys(buf, ":call XsaveFoldLevels()\n") + call term_sendkeys(buf, "1G") + call WaitForAssert({-> assert_equal('four', term_getline(buf, 3))}) + call term_sendkeys(buf, ":call XsaveFoldLevels()\n") + + " clean up + call StopVimInTerminal(buf) + + call assert_equal(['[-1,2,2,-1]', '[-1,-1,-1,-1]', '[-1,2,2,-1]', + \ '[-1,-1,-1,-1]', '[-1,2,2,-1]'], readfile('Xoutput')) + call delete('Xscript') + call delete('Xoutput') +endfunc + +" Test for foldtextresult() +func Test_foldtextresult() + new + call assert_equal('', foldtextresult(-1)) + call assert_equal('', foldtextresult(0)) + call assert_equal('', foldtextresult(1)) + call setline(1, ['one', 'two', 'three', 'four']) + 2,3fold + call assert_equal('', foldtextresult(1)) + call assert_equal('+-- 2 lines: two', foldtextresult(2)) + setlocal foldtext= + call assert_equal('+-- 2 lines folded ', foldtextresult(2)) + + " Fold text for a C comment fold + %d _ + setlocal foldtext& + call setline(1, ['', '/*', ' * Comment', ' */', '']) + 2,4fold + call assert_equal('+-- 3 lines: Comment', foldtextresult(2)) + + bw! +endfunc + +" Test for merging two recursive folds when an intermediate line with no fold +" is removed +func Test_fold_merge_recrusive() + new + call setline(1, [' one', ' two', 'xxxx', ' three', + \ ' four', "\tfive"]) + setlocal foldmethod=indent shiftwidth=2 + 3d_ + %foldclose + call assert_equal([1, 5], [foldclosed(5), foldclosedend(1)]) + bw! +endfunc + +" Test for moving a line which is the start of a fold from a recursive fold to +" outside. The fold length should reduce. +func Test_fold_move_foldlevel() + new + call setline(1, ['a{{{', 'b{{{', 'c{{{', 'd}}}', 'e}}}', 'f}}}', 'g']) + setlocal foldmethod=marker + normal zR + call assert_equal([3, 2, 1], [foldlevel(4), foldlevel(5), foldlevel(6)]) + 3move 7 + call assert_equal([2, 1, 0], [foldlevel(3), foldlevel(4), foldlevel(5)]) + call assert_equal(1, foldlevel(7)) + + " Move a line from outside a fold to inside the fold. + %d _ + call setline(1, ['a', 'b{{{', 'c}}}']) + normal zR + 1move 2 + call assert_equal([1, 1, 1], [foldlevel(1), foldlevel(2), foldlevel(3)]) + + " Move the start of one fold to inside another fold + %d _ + call setline(1, ['a', 'b{{{', 'c}}}', 'd{{{', 'e}}}']) + normal zR + call assert_equal([0, 1, 1, 1, 1], [foldlevel(1), foldlevel(2), + \ foldlevel(3), foldlevel(4), foldlevel(5)]) + 1,2move 4 + call assert_equal([0, 1, 1, 2, 2], [foldlevel(1), foldlevel(2), + \ foldlevel(3), foldlevel(4), foldlevel(5)]) + + bw! endfunc " Make sure a fold containing a nested fold is split correctly when using diff --git a/src/nvim/testdir/test_mksession.vim b/src/nvim/testdir/test_mksession.vim index 9cf80f631c..972397cb91 100644 --- a/src/nvim/testdir/test_mksession.vim +++ b/src/nvim/testdir/test_mksession.vim @@ -990,6 +990,38 @@ func Test_altfile() call assert_equal('Xtwoalt', bufname('#')) only bwipe! + call delete('Xtest_altfile') +endfunc + +" Test for creating views with manual folds +func Test_mkview_manual_fold() + call writefile(range(1,10), 'Xfile') + new Xfile + " create recursive folds + 5,6fold + 4,7fold + mkview Xview + normal zE + source Xview + call assert_equal([-1, 4, 4, 4, 4, -1], [foldclosed(3), foldclosed(4), + \ foldclosed(5), foldclosed(6), foldclosed(7), foldclosed(8)]) + " open one level of fold + 4foldopen + mkview! Xview + normal zE + source Xview + call assert_equal([-1, -1, 5, 5, -1, -1], [foldclosed(3), foldclosed(4), + \ foldclosed(5), foldclosed(6), foldclosed(7), foldclosed(8)]) + " open all the folds + %foldopen! + mkview! Xview + normal zE + source Xview + call assert_equal([-1, -1, -1, -1, -1, -1], [foldclosed(3), foldclosed(4), + \ foldclosed(5), foldclosed(6), foldclosed(7), foldclosed(8)]) + call delete('Xfile') + call delete('Xview') + bw! endfunc " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_source.vim b/src/nvim/testdir/test_source.vim index 0fd923abf2..d4d96e36bf 100644 --- a/src/nvim/testdir/test_source.vim +++ b/src/nvim/testdir/test_source.vim @@ -1,5 +1,8 @@ " Tests for the :source command. +source check.vim +source view_util.vim + func Test_source_autocmd() call writefile([ \ 'let did_source = 1', @@ -93,4 +96,18 @@ func Test_source_error() " call assert_fails('scriptversion 2', 'E984:') endfunc +" Test for sourcing a script recursively +func Test_nested_script() + CheckRunVimInTerminal + call writefile([':source! Xscript.vim', ''], 'Xscript.vim') + let buf = RunVimInTerminal('', {'rows': 6}) + call term_wait(buf) + call term_sendkeys(buf, ":set noruler\n") + call term_sendkeys(buf, ":source! Xscript.vim\n") + call term_wait(buf) + call WaitForAssert({-> assert_match('E22: Scripts nested too deep\s*', term_getline(buf, 6))}) + call delete('Xscript.vim') + call StopVimInTerminal(buf) +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 84646b80f3adb14d8e7c052047e2cb30a16b1eca Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 25 Nov 2022 15:50:54 +0800 Subject: vim-patch:8.2.2713: folding code not sufficiently tested Problem: Folding code not sufficiently tested. Solution: Add a few more test cases. (Yegappan Lakshmanan, closes vim/vim#8064) https://github.com/vim/vim/commit/68ffe8cade5e0c52680c00cb9f3f87104fbe653a --- src/nvim/testdir/test_fold.vim | 120 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_fold.vim b/src/nvim/testdir/test_fold.vim index 35fa81e296..23ed3817dd 100644 --- a/src/nvim/testdir/test_fold.vim +++ b/src/nvim/testdir/test_fold.vim @@ -565,6 +565,60 @@ func Test_fold_manual() normal zc call assert_equal('1 aa', getline(foldclosed('.'))) + " Create a fold inside a closed fold after setting 'foldlevel' + %d _ + call setline(1, range(1, 5)) + 1,5fold + normal zR + 2,4fold + set foldlevel=1 + 3fold + call assert_equal([1, 3, 3, 3, 1], map(range(1, 5), {->foldlevel(v:val)})) + set foldlevel& + + " Create overlapping folds (at the start and at the end) + normal zE + 2,3fold + normal zR + 3,4fold + call assert_equal([0, 2, 2, 1, 0], map(range(1, 5), {->foldlevel(v:val)})) + normal zE + 3,4fold + normal zR + 2,3fold + call assert_equal([0, 1, 2, 2, 0], map(range(1, 5), {->foldlevel(v:val)})) + + " Create a nested fold across two non-adjoining folds + %d _ + call setline(1, range(1, 7)) + 1,2fold + normal zR + 4,5fold + normal zR + 6,7fold + normal zR + 1,5fold + call assert_equal([2, 2, 1, 2, 2, 1, 1], + \ map(range(1, 7), {->foldlevel(v:val)})) + + " A newly created nested fold should be closed + %d _ + call setline(1, range(1, 6)) + 1,6fold + normal zR + 3,4fold + normal zR + 2,5fold + call assert_equal([1, 2, 3, 3, 2, 1], map(range(1, 6), {->foldlevel(v:val)})) + call assert_equal(2, foldclosed(4)) + call assert_equal(5, foldclosedend(4)) + + " Test zO, zC and zA on a line with no folds. + normal zE + call assert_fails('normal zO', 'E490:') + call assert_fails('normal zC', 'E490:') + call assert_fails('normal zA', 'E490:') + set fdm& bw! endfunc @@ -884,6 +938,30 @@ func Test_fold_delete_first_line() set foldmethod& endfunc +" Add a test for deleting the outer fold of a nested fold and promoting the +" inner folds to one level up with already a fold at that level following the +" nested fold. +func Test_fold_delete_recursive_fold() + new + call setline(1, range(1, 7)) + 2,3fold + normal zR + 4,5fold + normal zR + 1,5fold + normal zR + 6,7fold + normal zR + normal 1Gzd + normal 1Gzj + call assert_equal(2, line('.')) + normal zj + call assert_equal(4, line('.')) + normal zj + call assert_equal(6, line('.')) + bw! +endfunc + " Test for errors in 'foldexpr' func Test_fold_expr_error() new @@ -1075,6 +1153,10 @@ func Test_foldclose_opt() call term_sendkeys(buf, "1G") call WaitForAssert({-> assert_equal('four', term_getline(buf, 3))}) call term_sendkeys(buf, ":call XsaveFoldLevels()\n") + call term_sendkeys(buf, "2G") + call WaitForAssert({-> assert_equal('two', term_getline(buf, 2))}) + call term_sendkeys(buf, "k") + call WaitForAssert({-> assert_equal('four', term_getline(buf, 3))}) " clean up call StopVimInTerminal(buf) @@ -1153,6 +1235,44 @@ func Test_fold_move_foldlevel() bw! endfunc +" Test for using zj and zk to move downwards and upwards to the start and end +" of the next fold. +" Test for using [z and ]z in a closed fold to jump to the beginning and end +" of the fold. +func Test_fold_jump() + new + call setline(1, ["\t1", "\t2", "\t\t3", "\t\t4", "\t\t\t5", "\t\t\t6", "\t\t7", "\t\t8", "\t9", "\t10"]) + setlocal foldmethod=indent + normal zR + normal zj + call assert_equal(3, line('.')) + normal zj + call assert_equal(5, line('.')) + call assert_beeps('normal zj') + call assert_equal(5, line('.')) + call assert_beeps('normal 9Gzj') + call assert_equal(9, line('.')) + normal Gzk + call assert_equal(8, line('.')) + normal zk + call assert_equal(6, line('.')) + call assert_beeps('normal zk') + call assert_equal(6, line('.')) + call assert_beeps('normal 2Gzk') + call assert_equal(2, line('.')) + + " Using [z or ]z in a closed fold should not move the cursor + %d _ + call setline(1, ["1", "\t2", "\t3", "\t4", "\t5", "\t6", "7"]) + normal zR4Gzc + call assert_equal(4, line('.')) + call assert_beeps('normal [z') + call assert_equal(4, line('.')) + call assert_beeps('normal ]z') + call assert_equal(4, line('.')) + bw! +endfunc + " Make sure a fold containing a nested fold is split correctly when using " foldmethod=indent func Test_fold_split() -- cgit From 5ca1f48b4021e25d97bc0a29644310be4db5f70d Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Fri, 25 Nov 2022 09:17:08 +0100 Subject: vim-patch:9.0.0942: Workflow Description Language files are not recognized (#21183) Problem: Workflow Description Language files are not recognized. Solution: Add a pattern for the "wdl" filetype. (Matt Dunford, closes vim/vim#11611) https://github.com/vim/vim/commit/f60bdc3417a56a1f69e001a7ec210b92d5b0f2e1 Co-authored-by: Matt Dunford --- src/nvim/testdir/test_filetype.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 1d9465dd94..93bfb05d89 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -623,6 +623,7 @@ let s:filename_checks = { \ 'vroom': ['file.vroom'], \ 'vue': ['file.vue'], \ 'wast': ['file.wast', 'file.wat'], + \ 'wdl': ['file.wdl'], \ 'webmacro': ['file.wm'], \ 'wget': ['.wgetrc', 'wgetrc'], \ 'wget2': ['.wget2rc', 'wget2rc'], -- cgit From 7875e1377c24699a3773609996c4e21320a09f31 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 25 Nov 2022 16:17:30 +0800 Subject: vim-patch:9.0.0932: Oblivion files are not recognized (#21179) Problem: Oblivion files are not recognized. Solution: Recognize Oblivion files and alike as "obse". (closes vim/vim#11540) https://github.com/vim/vim/commit/ecfd511e8d802068434735dda00db6b783df6922 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_filetype.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 93bfb05d89..1bdda57868 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -396,6 +396,7 @@ let s:filename_checks = { \ 'nroff': ['file.tr', 'file.nr', 'file.roff', 'file.tmac', 'file.mom', 'tmac.file'], \ 'nsis': ['file.nsi', 'file.nsh'], \ 'obj': ['file.obj'], + \ 'obse': ['file.obl', 'file.obse', 'file.oblivion', 'file.obscript'], \ 'ocaml': ['file.ml', 'file.mli', 'file.mll', 'file.mly', '.ocamlinit', 'file.mlt', 'file.mlp', 'file.mlip', 'file.mli.cppo', 'file.ml.cppo'], \ 'occam': ['file.occ'], \ 'octave': ['octaverc', '.octaverc', 'octave.conf'], -- cgit From 29b80f6f2e9391b5d78390f65d09f00f73829310 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Fri, 25 Nov 2022 10:08:15 +0100 Subject: vim-patch:9.0.0935: when using dash it may not be recognize as filetype "sh" (#21174) * vim-patch:9.0.0935: when using dash it may not be recognize as filetype "sh" Problem: When using dash it may not be recognize as filetype "sh". Solution: Add checks for "dash". (Eisuke Kawashima,closes vim/vim#11600) https://github.com/vim/vim/commit/24482fbfd599d2273c48951df7d00d62f3e66c85 Co-authored-by: Eisuke Kawashima Co-authored-by: zeertzjq --- src/nvim/testdir/test_filetype.vim | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 1bdda57868..1ebf72ce41 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -706,6 +706,13 @@ let s:script_checks = { \ ['__libc_start_main and something']], \ 'clojure': [['#!/path/clojure']], \ 'scala': [['#!/path/scala']], + \ 'sh': [['#!/path/sh'], + \ ['#!/path/bash'], + \ ['#!/path/bash2'], + \ ['#!/path/dash'], + \ ['#!/path/ksh'], + \ ['#!/path/ksh93']], + \ 'csh': [['#!/path/csh']], \ 'tcsh': [['#!/path/tcsh']], \ 'zsh': [['#!/path/zsh']], \ 'tcl': [['#!/path/tclsh'], -- cgit From d38da27f1e1e4d8f2ff0af94b32aa531a9183255 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 26 Nov 2022 07:32:45 +0800 Subject: vim-patch:9.0.0950: the pattern "\_s\zs" matches at EOL (#21192) Problem: The pattern "\_s\zs" matches at EOL. Solution: Make the pattern "\_s\zs" match at the start of the next line. (closes vim/vim#11617) https://github.com/vim/vim/commit/c96311b5be307f5a1d1b20a0ec930d63964e7335 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_search.vim | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index 96ed35718f..0702e89ebb 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -1816,7 +1816,7 @@ func Test_search_smartcase_utf8() set ignorecase& smartcase& let &encoding = save_enc - close! + bwipe! endfunc " Test searching past the end of a file @@ -1825,7 +1825,29 @@ func Test_search_past_eof() call setline(1, ['Line']) exe "normal /\\n\\zs\" call assert_equal([1, 4], [line('.'), col('.')]) - close! + bwipe! +endfunc + +" Test setting the start of the match and still finding a next match in the +" same line. +func Test_search_set_start_same_line() + new + set cpo-=c + + call setline(1, ['1', '2', '3 .', '4', '5']) + exe "normal /\\_s\\zs\\S\" + call assert_equal([2, 1], [line('.'), col('.')]) + exe 'normal n' + call assert_equal([3, 1], [line('.'), col('.')]) + exe 'normal n' + call assert_equal([3, 3], [line('.'), col('.')]) + exe 'normal n' + call assert_equal([4, 1], [line('.'), col('.')]) + exe 'normal n' + call assert_equal([5, 1], [line('.'), col('.')]) + + set cpo+=c + bwipe! endfunc " Test for various search offsets -- cgit From 9dfbbde240fc095b856d8e0e1c670b1912ec6640 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 26 Nov 2022 00:52:30 +0100 Subject: docs: fix typos (#21168) --- src/nvim/testdir/test_fold.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_fold.vim b/src/nvim/testdir/test_fold.vim index 23ed3817dd..2215166cd6 100644 --- a/src/nvim/testdir/test_fold.vim +++ b/src/nvim/testdir/test_fold.vim @@ -1192,7 +1192,7 @@ endfunc " Test for merging two recursive folds when an intermediate line with no fold " is removed -func Test_fold_merge_recrusive() +func Test_fold_merge_recursive() new call setline(1, [' one', ' two', 'xxxx', ' three', \ ' four', "\tfive"]) -- cgit From 84465a8c1583f444d4365b2a70e03cd38ebe7f81 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 26 Nov 2022 11:15:27 +0800 Subject: vim-patch:8.2.1707: small inconsitency in highlight test (#21193) Problem: Small inconsitency in highlight test. Solution: Use one argument for :execute. (Antony Scriven, vim/vim#6975) https://github.com/vim/vim/commit/2bbada811625ee53c7bcdf689dbf409e9975ea8f --- src/nvim/testdir/test_highlight.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_highlight.vim b/src/nvim/testdir/test_highlight.vim index d618637d63..8a102f2e65 100644 --- a/src/nvim/testdir/test_highlight.vim +++ b/src/nvim/testdir/test_highlight.vim @@ -819,11 +819,11 @@ func Test_highlight_clear_restores_context() let patContextDefault = fnamemodify(scriptContextDefault, ':t') .. ' line 1' let patContextRelink = fnamemodify(scriptContextRelink, ':t') .. ' line 2' - exec "source" scriptContextDefault + exec 'source ' .. scriptContextDefault let hlContextDefault = execute("verbose hi Context") call assert_match(patContextDefault, hlContextDefault) - exec "source" scriptContextRelink + exec 'source ' .. scriptContextRelink let hlContextRelink = execute("verbose hi Context") call assert_match(patContextRelink, hlContextRelink) -- cgit From 319fbffc94896dd9cf0a77891d69b7fcada1fad4 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 26 Nov 2022 14:35:40 +0100 Subject: vim-patch:9.0.0952: Eclipse preference files are not recognized (#21199) Problem: Eclipse preference files are not recognized. Solution: Add a pattern to use "jproperties" for Eclipse preference files. (closes vim/vim#11618) https://github.com/vim/vim/commit/f3f198b6349fe252b72975701e2f17d932b19c70 Co-authored-by: ObserverOfTime --- src/nvim/testdir/test_filetype.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 1ebf72ce41..5ffddb7925 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -288,7 +288,7 @@ let s:filename_checks = { \ 'jess': ['file.clp'], \ 'jgraph': ['file.jgr'], \ 'jovial': ['file.jov', 'file.j73', 'file.jovial'], - \ 'jproperties': ['file.properties', 'file.properties_xx', 'file.properties_xx_xx', 'some.properties_xx_xx_file'], + \ 'jproperties': ['file.properties', 'file.properties_xx', 'file.properties_xx_xx', 'some.properties_xx_xx_file', 'org.eclipse.xyz.prefs'], \ 'json': ['file.json', 'file.jsonp', 'file.json-patch', 'file.webmanifest', 'Pipfile.lock', 'file.ipynb', '.babelrc', '.eslintrc', '.prettierrc', '.firebaserc', 'file.slnf'], \ 'json5': ['file.json5'], \ 'jsonc': ['file.jsonc'], -- cgit From a6f0444ab9b5d8947ff7e48718a6b3a484a096fa Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 28 Nov 2022 06:59:19 +0800 Subject: vim-patch:9.0.0958: messages test is flaky (#21205) Problem: Messages test is flaky. Solution: Add a short delay. https://github.com/vim/vim/commit/19cf525c20f9915ffcddda35c27608528f6af047 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_messages.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_messages.vim b/src/nvim/testdir/test_messages.vim index 42a1fdcfe2..bfdebdac79 100644 --- a/src/nvim/testdir/test_messages.vim +++ b/src/nvim/testdir/test_messages.vim @@ -353,7 +353,7 @@ func Test_echo_verbose_system() " display a page and go back, results in exactly the same view call term_sendkeys(buf, ' ') - call TermWait(buf) + call TermWait(buf, 50) call term_sendkeys(buf, 'b') call VerifyScreenDump(buf, 'Test_verbose_system_1', {}) @@ -366,7 +366,7 @@ func Test_echo_verbose_system() call VerifyScreenDump(buf, 'Test_verbose_system_2', {}) call term_sendkeys(buf, ' ') - call TermWait(buf) + call TermWait(buf, 50) call term_sendkeys(buf, 'b') call VerifyScreenDump(buf, 'Test_verbose_system_2', {}) -- cgit From b2bb3973d9c7f25acfead2718d74fcf5b1e4551e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 28 Nov 2022 20:01:36 +0800 Subject: vim-patch:9.0.0963: function name does not match autocmd event name (#21215) Problem: Function name does not match autocmd event name. Solution: Rename "optionsset" to "optionset". (closes vim/vim#11630) https://github.com/vim/vim/commit/269aa2b29ac3e4c0083d929e2477c95e7bd1177a --- src/nvim/testdir/test_quickfix.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 5edcf9ce0e..bde6f5a4fc 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -3237,7 +3237,7 @@ func Test_cclose_from_copen() endfunc func Test_cclose_in_autocmd() - " Problem is only triggered if "starting" is zero, so that the OptionsSet + " Problem is only triggered if "starting" is zero, so that the OptionSet " event will be triggered. " call test_override('starting', 1) augroup QF_Test -- cgit From bf0665b3f320cd183bd1f960cc8501fca60ced9e Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Mon, 28 Nov 2022 18:41:20 +0100 Subject: vim-patch:9.0.0964: status line not redrawn when 'splitkeep' is "screen" Problem: Status line of other window not redrawn when dragging it when 'splitkeep' is set to "screen". Solution: Set w_redr_status earlier. (Luuk van Baal, closes vim/vim#11635, closes vim/vim#11632) https://github.com/vim/vim/commit/74a694dbe20bb7dea4e06f474cf62e20f9c92f1d Co-authored-by: Luuk van Baal --- src/nvim/testdir/test_window_cmd.vim | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim index 20564fed66..6e8368f71d 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -1793,4 +1793,22 @@ function Test_splitkeep_fold() call VerifyScreenDump(buf, 'Test_splitkeep_fold_4', {}) endfunction +function Test_splitkeep_status() + CheckScreendump + + let lines =<< trim END + call setline(1, ['a', 'b', 'c']) + set nomodified + set splitkeep=screen + let win = winnr() + wincmd s + wincmd j + END + call writefile(lines, 'XTestSplitkeepStatus', 'D') + let buf = RunVimInTerminal('-S XTestSplitkeepStatus', #{rows: 10}) + + call term_sendkeys(buf, ":call win_move_statusline(win, 1)\") + call VerifyScreenDump(buf, 'Test_splitkeep_status_1', {}) +endfunction + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 615f124003376c007442319b31a172360796974c Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 29 Nov 2022 02:45:48 +0100 Subject: docs: fix typos (#21196) Co-authored-by: zeertzjq Co-authored-by: Raphael Co-authored-by: Gregory Anders --- src/nvim/testdir/test_vimscript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index c93ba9dcfc..aedc63ef00 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -6642,7 +6642,7 @@ func Test_invalid_function_names() endtry call assert_equal(1, caught_e884) - " function name folowed by # + " function name followed by # let caught_e128 = 0 try func! test2() "# -- cgit From 65e8ed45de98bf93491c6740772f0a42834696ab Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 29 Nov 2022 10:17:57 +0800 Subject: vim-patch:9.0.0969: matchparen highlight is not updated when switching buffers (#21227) Problem: Matchparen highlight is not updated when switching buffers. Solution: Listen to the BufLeave and the BufWinEnter autocmd events. (closes vim/vim#11626) https://github.com/vim/vim/commit/28a896f54d4b2f2b4bef8ef4144dde1673c9d6e7 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_autocmd.vim | 3 +-- src/nvim/testdir/test_display.vim | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 6 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 2945b4a03a..6fa191d928 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -2334,9 +2334,8 @@ function Test_dirchanged_auto() endfunc " Test TextChangedI and TextChangedP -" See test/functional/viml/completion_spec.lua' func Test_ChangedP() - CheckFunction test_override + throw 'Skipped: use test/functional/editor/completion_spec.lua' new call setline(1, ['foo', 'bar', 'foobar']) call test_override("char_avail", 1) diff --git a/src/nvim/testdir/test_display.vim b/src/nvim/testdir/test_display.vim index 679fe89628..b642f39c9f 100644 --- a/src/nvim/testdir/test_display.vim +++ b/src/nvim/testdir/test_display.vim @@ -226,7 +226,6 @@ endfunc " Test for scrolling that modifies buffer during visual block func Test_visual_block_scroll() - " See test/functional/legacy/visual_mode_spec.lua CheckScreendump let lines =<< trim END @@ -237,7 +236,7 @@ func Test_visual_block_scroll() END let filename = 'Xvisualblockmodifiedscroll' - call writefile(lines, filename) + call writefile(lines, filename, 'D') let buf = RunVimInTerminal('-S '.filename, #{rows: 7}) call term_sendkeys(buf, "V\\") @@ -245,11 +244,40 @@ func Test_visual_block_scroll() call VerifyScreenDump(buf, 'Test_display_visual_block_scroll', {}) call StopVimInTerminal(buf) - call delete(filename) +endfunc + +" Test for clearing paren highlight when switching buffers +func Test_matchparen_clear_highlight() + CheckScreendump + + let lines =<< trim END + source $VIMRUNTIME/plugin/matchparen.vim + set hidden + call setline(1, ['()']) + normal 0 + + func OtherBuffer() + enew + exe "normal iaa\0" + endfunc + END + call writefile(lines, 'XMatchparenClear', 'D') + let buf = RunVimInTerminal('-S XMatchparenClear', #{rows: 5}) + call VerifyScreenDump(buf, 'Test_matchparen_clear_highlight_1', {}) + + call term_sendkeys(buf, ":call OtherBuffer()\:\") + call VerifyScreenDump(buf, 'Test_matchparen_clear_highlight_2', {}) + + call term_sendkeys(buf, "\:\") + call VerifyScreenDump(buf, 'Test_matchparen_clear_highlight_1', {}) + + call term_sendkeys(buf, "\:\") + call VerifyScreenDump(buf, 'Test_matchparen_clear_highlight_2', {}) + + call StopVimInTerminal(buf) endfunc func Test_display_scroll_at_topline() - " See test/functional/legacy/display_spec.lua CheckScreendump let buf = RunVimInTerminal('', #{cols: 20}) -- cgit From 05f7d2badead3ba399578c2392e1d9b790df475d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 29 Nov 2022 16:55:46 +0800 Subject: vim-patch:9.0.0914: deletebufline() may move marks in the wrong window Problem: deletebufline() may move marks in the wrong window. Solution: Find a window for the buffer being changed. (closes vim/vim#11583) https://github.com/vim/vim/commit/228e422855d43965f2c3319ff0cdc26ea422c10f Cherry-pick code change from patch 9.0.0961. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_bufline.vim | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_bufline.vim b/src/nvim/testdir/test_bufline.vim index d4dee38620..0468025f55 100644 --- a/src/nvim/testdir/test_bufline.vim +++ b/src/nvim/testdir/test_bufline.vim @@ -98,12 +98,25 @@ func Test_appendbufline() new let b = bufnr('%') hide + + new + call setline(1, ['line1', 'line2', 'line3']) + normal! 2gggg + call assert_equal(2, line("''")) + call assert_equal(0, appendbufline(b, 0, ['foo', 'bar'])) call assert_equal(['foo'], getbufline(b, 1)) call assert_equal(['bar'], getbufline(b, 2)) call assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) + call assert_equal(0, appendbufline(b, 0, 'baz')) + call assert_equal(['baz', 'foo', 'bar'], getbufline(b, 1, 3)) + + " appendbufline() in a hidden buffer shouldn't move marks in current window. + call assert_equal(2, line("''")) + bwipe! + exe "bd!" b - call assert_equal([], getbufline(b, 1, 2)) + call assert_equal([], getbufline(b, 1, 3)) split Xtest call setline(1, ['a', 'b', 'c']) @@ -145,10 +158,21 @@ func Test_deletebufline() let b = bufnr('%') call setline(1, ['aaa', 'bbb', 'ccc']) hide + + new + call setline(1, ['line1', 'line2', 'line3']) + normal! 2gggg + call assert_equal(2, line("''")) + call assert_equal(0, deletebufline(b, 2)) call assert_equal(['aaa', 'ccc'], getbufline(b, 1, 2)) call assert_equal(0, deletebufline(b, 2, 8)) call assert_equal(['aaa'], getbufline(b, 1, 2)) + + " deletebufline() in a hidden buffer shouldn't move marks in current window. + call assert_equal(2, line("''")) + bwipe! + exe "bd!" b call assert_equal(1, b->deletebufline(1)) -- cgit From 3173d07564e7cdf0834099a379f0faf480c76224 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 29 Nov 2022 18:20:11 +0800 Subject: vim-patch:9.0.0965: using one window for executing autocommands is insufficient Problem: Using one window for executing autocommands is insufficient. Solution: Use up to five windows for executing autocommands. https://github.com/vim/vim/commit/e76062c078debed0df818f70e4db14ad7a7cb53a N/A patches for version.c: vim-patch:9.0.0966: some compilers don't allow a declaration after a label Problem: Some compilers don't allow a declaration after a label. Solution: Move the declaration to the start of the block. (John Marriott) https://github.com/vim/vim/commit/f86490ed4fdab213a28f667abd055c023a73d645 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_autocmd.vim | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 6fa191d928..199721b15e 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -3483,4 +3483,27 @@ func Test_autocmd_split_dummy() call delete('Xerr') endfunc +" This was crashing because there was only one window to execute autocommands +" in. +func Test_autocmd_nested_setbufvar() + CheckFeature python3 + + set hidden + edit Xaaa + edit Xbbb + call setline(1, 'bar') + enew + au BufWriteCmd Xbbb ++nested call setbufvar('Xaaa', '&ft', 'foo') | bw! Xaaa + au FileType foo call py3eval('vim.current.buffer.options["cindent"]') + wall + + au! BufWriteCmd + au! FileType foo + set nohidden + call delete('Xaaa') + call delete('Xbbb') + %bwipe! +endfunc + + " vim: shiftwidth=2 sts=2 expandtab -- cgit From f706d24045b5243386460119bbf7c1caa2c5cc37 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 30 Nov 2022 09:47:30 +0800 Subject: vim-patch:8.2.5082: retab test fails Problem: Retab test fails. Solution: Disable the test for now. https://github.com/vim/vim/commit/93974239857318fe604e53abd41ffead04b7c657 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_retab.vim | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_retab.vim b/src/nvim/testdir/test_retab.vim index 1650a03876..c08c226937 100644 --- a/src/nvim/testdir/test_retab.vim +++ b/src/nvim/testdir/test_retab.vim @@ -81,7 +81,8 @@ func Test_retab_error() call assert_fails('ret 80000000000000000000', 'E475:') endfunc -func Test_retab_endless() +" FIXME: the try/catch does not catch the interrupt +func FIXME_Test_retab_endless() new call setline(1, "\t0\t") let caught = 'no' @@ -90,9 +91,10 @@ func Test_retab_endless() set ts=4000 retab 4 endwhile - catch /E1240/ - let caught = 'yes' + catch + let caught = v:exception endtry + call assert_notequal('no', caught) bwipe! set tabstop& endfunc -- cgit From a7dc48f19dcd6341cf5e9e199b3ad30e1b9f7327 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 30 Nov 2022 09:48:10 +0800 Subject: vim-patch:8.2.5102: interrupt not caught in test Problem: Interrupt not caught in test. Solution: Consider an exception thrown in the current try/catch when got_int is set. Also catch early exit when not using try/catch. https://github.com/vim/vim/commit/8bea171f154845046239c61bdef50a8e0f12f643 Cherry-pick test changes from patch 8.2.0557. https://github.com/vim/vim/commit/bfe13ccc58ccb96f243a58309800410db1ccb52c Co-authored-by: Bram Moolenaar --- src/nvim/testdir/runtest.vim | 23 +++++++++++------------ src/nvim/testdir/test_escaped_glob.vim | 2 +- src/nvim/testdir/test_getcwd.vim | 2 +- src/nvim/testdir/test_hide.vim | 2 +- src/nvim/testdir/test_retab.vim | 30 ++++++++++++++++++++++-------- 5 files changed, 36 insertions(+), 23 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim index a1b04a4601..15f66fc1ad 100644 --- a/src/nvim/testdir/runtest.vim +++ b/src/nvim/testdir/runtest.vim @@ -171,6 +171,7 @@ func RunTheTest(test) endtry endif + au VimLeavePre * call EarlyExit(g:testfunc) if a:test =~ 'Test_nocatch_' " Function handles errors itself. This avoids skipping commands after the " error. @@ -182,10 +183,7 @@ func RunTheTest(test) endif else try - let s:test = a:test - au VimLeavePre * call EarlyExit(s:test) exe 'call ' . a:test - au! VimLeavePre catch /^\cskipped/ call add(s:messages, ' Skipped') call add(s:skipped, 'SKIPPED ' . a:test . ': ' . substitute(v:exception, '^\S*\s\+', '', '')) @@ -193,6 +191,7 @@ func RunTheTest(test) call add(v:errors, 'Caught exception in ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint) endtry endif + au! VimLeavePre " In case 'insertmode' was set and something went wrong, make sure it is " reset to avoid trouble with anything else. @@ -255,11 +254,11 @@ func AfterTheTest(func_name) if len(v:errors) > 0 if match(s:may_fail_list, '^' .. a:func_name) >= 0 let s:fail_expected += 1 - call add(s:errors_expected, 'Found errors in ' . s:test . ':') + call add(s:errors_expected, 'Found errors in ' . g:testfunc . ':') call extend(s:errors_expected, v:errors) else let s:fail += 1 - call add(s:errors, 'Found errors in ' . s:test . ':') + call add(s:errors, 'Found errors in ' . g:testfunc . ':') call extend(s:errors, v:errors) endif let v:errors = [] @@ -420,12 +419,12 @@ endif let s:may_fail_list = [] if $TEST_MAY_FAIL != '' - " Split the list at commas and add () to make it match s:test. + " Split the list at commas and add () to make it match g:testfunc. let s:may_fail_list = split($TEST_MAY_FAIL, ',')->map({i, v -> v .. '()'}) endif " Execute the tests in alphabetical order. -for s:test in sort(s:tests) +for g:testfunc in sort(s:tests) " Silence, please! set belloff=all let prev_error = '' @@ -435,7 +434,7 @@ for s:test in sort(s:tests) " A test can set g:test_is_flaky to retry running the test. let g:test_is_flaky = 0 - call RunTheTest(s:test) + call RunTheTest(g:testfunc) " Repeat a flaky test. Give up when: " - $TEST_NO_RETRY is not empty @@ -443,10 +442,10 @@ for s:test in sort(s:tests) " - it fails five times (with a different message) if len(v:errors) > 0 \ && $TEST_NO_RETRY == '' - \ && (index(s:flaky_tests, s:test) >= 0 + \ && (index(s:flaky_tests, g:testfunc) >= 0 \ || g:test_is_flaky) while 1 - call add(s:messages, 'Found errors in ' . s:test . ':') + call add(s:messages, 'Found errors in ' . g:testfunc . ':') call extend(s:messages, v:errors) call add(total_errors, 'Run ' . g:run_nr . ':') @@ -469,7 +468,7 @@ for s:test in sort(s:tests) let v:errors = [] let g:run_nr += 1 - call RunTheTest(s:test) + call RunTheTest(g:testfunc) if len(v:errors) == 0 " Test passed on rerun. @@ -478,7 +477,7 @@ for s:test in sort(s:tests) endwhile endif - call AfterTheTest(s:test) + call AfterTheTest(g:testfunc) endfor call FinishTesting() diff --git a/src/nvim/testdir/test_escaped_glob.vim b/src/nvim/testdir/test_escaped_glob.vim index 1a4fd8bdab..9f53c76a2c 100644 --- a/src/nvim/testdir/test_escaped_glob.vim +++ b/src/nvim/testdir/test_escaped_glob.vim @@ -1,7 +1,7 @@ " Test whether glob()/globpath() return correct results with certain escaped " characters. -function SetUp() +func SetUp() " consistent sorting of file names set nofileignorecase endfunction diff --git a/src/nvim/testdir/test_getcwd.vim b/src/nvim/testdir/test_getcwd.vim index a75583cd2c..073f8303dc 100644 --- a/src/nvim/testdir/test_getcwd.vim +++ b/src/nvim/testdir/test_getcwd.vim @@ -24,7 +24,7 @@ endfunc " Do all test in a separate window to avoid E211 when we recursively " delete the Xtopdir directory during cleanup -function SetUp() +func SetUp() set visualbell set nocp viminfo+=nviminfo diff --git a/src/nvim/testdir/test_hide.vim b/src/nvim/testdir/test_hide.vim index 41b1a4ad7c..b3ce395523 100644 --- a/src/nvim/testdir/test_hide.vim +++ b/src/nvim/testdir/test_hide.vim @@ -1,6 +1,6 @@ " Tests for :hide command/modifier and 'hidden' option -function SetUp() +func SetUp() let s:save_hidden = &hidden let s:save_bufhidden = &bufhidden let s:save_autowrite = &autowrite diff --git a/src/nvim/testdir/test_retab.vim b/src/nvim/testdir/test_retab.vim index c08c226937..a50f35ed7e 100644 --- a/src/nvim/testdir/test_retab.vim +++ b/src/nvim/testdir/test_retab.vim @@ -81,20 +81,34 @@ func Test_retab_error() call assert_fails('ret 80000000000000000000', 'E475:') endfunc -" FIXME: the try/catch does not catch the interrupt -func FIXME_Test_retab_endless() +func RetabLoop() + while 1 + set ts=4000 + retab 4 + endwhile +endfunc + +func Test_retab_endless() + " inside try/catch we catch the error message new call setline(1, "\t0\t") let caught = 'no' try - while 1 - set ts=4000 - retab 4 - endwhile - catch + call RetabLoop() + catch /E1240:/ let caught = v:exception endtry - call assert_notequal('no', caught) + call assert_match('E1240:', caught) + bwipe! + set tabstop& +endfunc + +func Test_nocatch_retab_endless() + " not inside try/catch an interrupt is generated to get out of loops + new + call setline(1, "\t0\t") + call assert_fails('call RetabLoop()', ['E1240:', 'Interrupted']) + bwipe! set tabstop& endfunc -- cgit From c180e0d8d578b41739a8cce588ef1b4fa26de560 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 30 Nov 2022 10:04:07 +0800 Subject: vim-patch:8.2.5103: build fails with small features Problem: Build fails with small features. Solution: Add #ifdef. Skip test on MS-Windows. https://github.com/vim/vim/commit/34f99584c73f91bcc8ca5236557a2a09335e1e43 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_retab.vim | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_retab.vim b/src/nvim/testdir/test_retab.vim index a50f35ed7e..bbca89432a 100644 --- a/src/nvim/testdir/test_retab.vim +++ b/src/nvim/testdir/test_retab.vim @@ -104,6 +104,9 @@ func Test_retab_endless() endfunc func Test_nocatch_retab_endless() + " FIXME: why does this hang on MS-Windows? + CheckNotMSWindows + " not inside try/catch an interrupt is generated to get out of loops new call setline(1, "\t0\t") -- cgit From b57daafdd9ece4d5e8412f080c01b8fa82774985 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 30 Nov 2022 10:04:50 +0800 Subject: vim-patch:8.2.5104: test hangs on MS-Windows Problem: Test hangs on MS-Windows. Solution: Skip another test on MS-Windows. https://github.com/vim/vim/commit/b31cb04771234556374cda45ce19dabd4a2a7fc7 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_retab.vim | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_retab.vim b/src/nvim/testdir/test_retab.vim index bbca89432a..3bd8a9928c 100644 --- a/src/nvim/testdir/test_retab.vim +++ b/src/nvim/testdir/test_retab.vim @@ -1,4 +1,7 @@ " Test :retab + +source check.vim + func SetUp() new call setline(1, "\ta \t b c ") @@ -89,6 +92,9 @@ func RetabLoop() endfunc func Test_retab_endless() + " FIXME: why does this hang on MS-Windows? + CheckNotMSWindows + " inside try/catch we catch the error message new call setline(1, "\t0\t") @@ -104,7 +110,7 @@ func Test_retab_endless() endfunc func Test_nocatch_retab_endless() - " FIXME: why does this hang on MS-Windows? + " FIXME: does this hang on MS-Windows? CheckNotMSWindows " not inside try/catch an interrupt is generated to get out of loops -- cgit From 3f743c39d3be332eede7fe7a4f6641dd9348b922 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 30 Nov 2022 10:07:04 +0800 Subject: vim-patch:8.2.5105: test still hangs on MS-Windows Problem: Test still hangs on MS-Windows. Solution: Skip "nocatch" test the right way. https://github.com/vim/vim/commit/83497f875881973df772cc4cc593766345df6c4a Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_retab.vim | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_retab.vim b/src/nvim/testdir/test_retab.vim index 3bd8a9928c..4253e77487 100644 --- a/src/nvim/testdir/test_retab.vim +++ b/src/nvim/testdir/test_retab.vim @@ -92,11 +92,7 @@ func RetabLoop() endfunc func Test_retab_endless() - " FIXME: why does this hang on MS-Windows? - CheckNotMSWindows - " inside try/catch we catch the error message - new call setline(1, "\t0\t") let caught = 'no' try @@ -105,20 +101,21 @@ func Test_retab_endless() let caught = v:exception endtry call assert_match('E1240:', caught) - bwipe! + set tabstop& endfunc func Test_nocatch_retab_endless() - " FIXME: does this hang on MS-Windows? - CheckNotMSWindows + " FIXME: why does this hang on MS-Windows? Is got_int reset somewhere? + if has('win32') + let g:skipped_reason = "does not work on MS-Windows" + return + endif " not inside try/catch an interrupt is generated to get out of loops - new call setline(1, "\t0\t") call assert_fails('call RetabLoop()', ['E1240:', 'Interrupted']) - bwipe! set tabstop& endfunc -- cgit From 22622df950fe90abcaaf2e6710cd6cd9451cdc34 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 30 Nov 2022 10:07:24 +0800 Subject: vim-patch:8.2.5108: retab test disabled because it hangs on MS-Windows Problem: Retab test disabled because it hangs on MS-Windows. Solution: Also set got_int at the other place a overlong text is detected. https://github.com/vim/vim/commit/308660bd263367a4f1a75498cbd2e29cade47f4d Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_retab.vim | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_retab.vim b/src/nvim/testdir/test_retab.vim index 4253e77487..a4f95053c0 100644 --- a/src/nvim/testdir/test_retab.vim +++ b/src/nvim/testdir/test_retab.vim @@ -92,7 +92,7 @@ func RetabLoop() endfunc func Test_retab_endless() - " inside try/catch we catch the error message + " inside try/catch we can catch the error message call setline(1, "\t0\t") let caught = 'no' try @@ -106,13 +106,7 @@ func Test_retab_endless() endfunc func Test_nocatch_retab_endless() - " FIXME: why does this hang on MS-Windows? Is got_int reset somewhere? - if has('win32') - let g:skipped_reason = "does not work on MS-Windows" - return - endif - - " not inside try/catch an interrupt is generated to get out of loops + " when not inside try/catch an interrupt is generated to get out of loops call setline(1, "\t0\t") call assert_fails('call RetabLoop()', ['E1240:', 'Interrupted']) -- cgit From 47d3d0102fffbfd52b950c521e5d1e443ac7885f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 2 Dec 2022 10:28:35 +0800 Subject: vim-patch:8.2.1748: closing split window in other tab may cause a crash Problem: Closing split window in other tab may cause a crash. Solution: Set tp_curwin properly. (Rob Pilling, closes vim/vim#7018) https://github.com/vim/vim/commit/f3c51bbff1256a52bdd9ede7887f40062be2628c Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_winbuf_close.vim | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_winbuf_close.vim b/src/nvim/testdir/test_winbuf_close.vim index 643c1068bd..26b4ba8778 100644 --- a/src/nvim/testdir/test_winbuf_close.vim +++ b/src/nvim/testdir/test_winbuf_close.vim @@ -192,7 +192,23 @@ func Test_tabwin_close() call win_execute(l:wid, 'close') " Should not crash. call assert_true(v:true) - %bwipe! + + " This tests closing a window in another tab, while leaving the tab open + " i.e. two windows in another tab. + tabedit + let w:this_win = 42 + new + let othertab_wid = win_getid() + tabprevious + call win_execute(othertab_wid, 'q') + " drawing the tabline helps check that the other tab's windows and buffers + " are still valid + redrawtabline + " but to be certain, ensure we can focus the other tab too + tabnext + call assert_equal(42, w:this_win) + + bwipe! endfunc " Test when closing a split window (above/below) restores space to the window -- cgit From 1aad5af637b0fc042e1155cc0955931e9ca75295 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 2 Dec 2022 20:44:26 +0800 Subject: vim-patch:8.2.3829: no error when setting a func option to script-local function Problem: No error when setting a func option to a script-local function. Solution: Give an error if the name starts with "s:". (closes vim/vim#9358) https://github.com/vim/vim/commit/94c785d235dccacf6cdf38c5903115b61ca8a981 Omit test: reverted in patch 8.2.3838. Cherry-pick SCRIPT_ID_VALID from patch 8.2.1539. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_tagfunc.vim | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_tagfunc.vim b/src/nvim/testdir/test_tagfunc.vim index 7a88723bc0..9b4a550945 100644 --- a/src/nvim/testdir/test_tagfunc.vim +++ b/src/nvim/testdir/test_tagfunc.vim @@ -1,6 +1,8 @@ " Test 'tagfunc' source vim9.vim +source check.vim +source screendump.vim func TagFunc(pat, flag, info) let g:tagfunc_args = [a:pat, a:flag, a:info] -- cgit From 7d1019442642d51f1af49bafa3b0450841129c2d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 2 Dec 2022 20:47:52 +0800 Subject: vim-patch:8.2.3838: cannot use script-local function for setting *func options Problem: Cannot use script-local function for setting *func options. Solution: Use the script context. (Yegappan Lakshmanan, closes vim/vim#9362) https://github.com/vim/vim/commit/db1a410b610b2c1941311acc57dcc4afec20720e Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_ins_complete.vim | 162 ++++++++++++++++++++++++++++++--- src/nvim/testdir/test_normal.vim | 35 ++++++- src/nvim/testdir/test_quickfix.vim | 17 ++++ src/nvim/testdir/test_tagfunc.vim | 61 +++++++++++-- 4 files changed, 254 insertions(+), 21 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 d788841833..1811c82767 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -1300,13 +1300,13 @@ func Test_completefunc_callback() endfunc let lines =<< trim END - #" Test for using a function name + #" Test for using a global function name LET &completefunc = 'g:CompleteFunc2' new - call setline(1, 'zero') + call setline(1, 'global') LET g:CompleteFunc2Args = [] call feedkeys("A\\\", 'x') - call assert_equal([[1, ''], [0, 'zero']], g:CompleteFunc2Args) + call assert_equal([[1, ''], [0, 'global']], g:CompleteFunc2Args) bw! #" Test for using a function() @@ -1442,6 +1442,29 @@ func Test_completefunc_callback() END call CheckLegacyAndVim9Success(lines) + " Test for using a script-local function name + func s:CompleteFunc3(findstart, base) + call add(g:CompleteFunc3Args, [a:findstart, a:base]) + return a:findstart ? 0 : [] + endfunc + set completefunc=s:CompleteFunc3 + new + call setline(1, 'script1') + let g:CompleteFunc3Args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'script1']], g:CompleteFunc3Args) + bw! + + let &completefunc = 's:CompleteFunc3' + new + call setline(1, 'script2') + let g:CompleteFunc3Args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'script2']], g:CompleteFunc3Args) + bw! + delfunc s:CompleteFunc3 + + " invalid return value let &completefunc = {a -> 'abc'} call feedkeys("A\\\", 'x') @@ -1476,11 +1499,12 @@ func Test_completefunc_callback() let lines =<< trim END vim9script - # Test for using a def function with completefunc - def Vim9CompleteFunc(val: number, findstart: number, base: string): any - add(g:Vim9completeFuncArgs, [val, findstart, base]) + def Vim9CompleteFunc(callnr: number, findstart: number, base: string): any + add(g:Vim9completeFuncArgs, [callnr, findstart, base]) return findstart ? 0 : [] enddef + + # Test for using a def function with completefunc set completefunc=function('Vim9CompleteFunc',\ [60]) new | only setline(1, 'one') @@ -1488,6 +1512,28 @@ func Test_completefunc_callback() feedkeys("A\\\", 'x') assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9completeFuncArgs) bw! + + # Test for using a global function name + &completefunc = g:CompleteFunc2 + new | only + setline(1, 'two') + g:CompleteFunc2Args = [] + feedkeys("A\\\", 'x') + assert_equal([[1, ''], [0, 'two']], g:CompleteFunc2Args) + bw! + + # Test for using a script-local function name + def s:LocalCompleteFunc(findstart: number, base: string): any + add(g:LocalCompleteFuncArgs, [findstart, base]) + return findstart ? 0 : [] + enddef + &completefunc = s:LocalCompleteFunc + new | only + setline(1, 'three') + g:LocalCompleteFuncArgs = [] + feedkeys("A\\\", 'x') + assert_equal([[1, ''], [0, 'three']], g:LocalCompleteFuncArgs) + bw! END " call CheckScriptSuccess(lines) @@ -1653,6 +1699,29 @@ func Test_omnifunc_callback() END call CheckLegacyAndVim9Success(lines) + " Test for using a script-local function name + func s:OmniFunc3(findstart, base) + call add(g:OmniFunc3Args, [a:findstart, a:base]) + return a:findstart ? 0 : [] + endfunc + set omnifunc=s:OmniFunc3 + new + call setline(1, 'script1') + let g:OmniFunc3Args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'script1']], g:OmniFunc3Args) + bw! + + let &omnifunc = 's:OmniFunc3' + new + call setline(1, 'script2') + let g:OmniFunc3Args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'script2']], g:OmniFunc3Args) + bw! + delfunc s:OmniFunc3 + + " invalid return value let &omnifunc = {a -> 'abc'} call feedkeys("A\\\", 'x') @@ -1687,11 +1756,12 @@ func Test_omnifunc_callback() let lines =<< trim END vim9script - # Test for using a def function with omnifunc - def Vim9omniFunc(val: number, findstart: number, base: string): any - add(g:Vim9omniFunc_Args, [val, findstart, base]) + def Vim9omniFunc(callnr: number, findstart: number, base: string): any + add(g:Vim9omniFunc_Args, [callnr, findstart, base]) return findstart ? 0 : [] enddef + + # Test for using a def function with omnifunc set omnifunc=function('Vim9omniFunc',\ [60]) new | only setline(1, 'one') @@ -1699,6 +1769,28 @@ func Test_omnifunc_callback() feedkeys("A\\\", 'x') assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9omniFunc_Args) bw! + + # Test for using a global function name + &omnifunc = g:OmniFunc2 + new | only + setline(1, 'two') + g:OmniFunc2Args = [] + feedkeys("A\\\", 'x') + assert_equal([[1, ''], [0, 'two']], g:OmniFunc2Args) + bw! + + # Test for using a script-local function name + def s:LocalOmniFunc(findstart: number, base: string): any + add(g:LocalOmniFuncArgs, [findstart, base]) + return findstart ? 0 : [] + enddef + &omnifunc = s:LocalOmniFunc + new | only + setline(1, 'three') + g:LocalOmniFuncArgs = [] + feedkeys("A\\\", 'x') + assert_equal([[1, ''], [0, 'three']], g:LocalOmniFuncArgs) + bw! END " call CheckScriptSuccess(lines) @@ -1887,6 +1979,29 @@ func Test_thesaurusfunc_callback() END call CheckLegacyAndVim9Success(lines) + " Test for using a script-local function name + func s:TsrFunc3(findstart, base) + call add(g:TsrFunc3Args, [a:findstart, a:base]) + return a:findstart ? 0 : [] + endfunc + set tsrfu=s:TsrFunc3 + new + call setline(1, 'script1') + let g:TsrFunc3Args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'script1']], g:TsrFunc3Args) + bw! + + let &tsrfu = 's:TsrFunc3' + new + call setline(1, 'script2') + let g:TsrFunc3Args = [] + call feedkeys("A\\\", 'x') + call assert_equal([[1, ''], [0, 'script2']], g:TsrFunc3Args) + bw! + delfunc s:TsrFunc3 + + " invalid return value let &thesaurusfunc = {a -> 'abc'} call feedkeys("A\\\", 'x') @@ -1934,11 +2049,12 @@ func Test_thesaurusfunc_callback() let lines =<< trim END vim9script - # Test for using a def function with thesaurusfunc - def Vim9tsrFunc(val: number, findstart: number, base: string): any - add(g:Vim9tsrFunc_Args, [val, findstart, base]) + def Vim9tsrFunc(callnr: number, findstart: number, base: string): any + add(g:Vim9tsrFunc_Args, [callnr, findstart, base]) return findstart ? 0 : [] enddef + + # Test for using a def function with thesaurusfunc set thesaurusfunc=function('Vim9tsrFunc',\ [60]) new | only setline(1, 'one') @@ -1946,6 +2062,28 @@ func Test_thesaurusfunc_callback() feedkeys("A\\\", 'x') assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9tsrFunc_Args) bw! + + # Test for using a global function name + &thesaurusfunc = g:TsrFunc2 + new | only + setline(1, 'two') + g:TsrFunc2Args = [] + feedkeys("A\\\", 'x') + assert_equal([[1, ''], [0, 'two']], g:TsrFunc2Args) + bw! + + # Test for using a script-local function name + def s:LocalTsrFunc(findstart: number, base: string): any + add(g:LocalTsrFuncArgs, [findstart, base]) + return findstart ? 0 : [] + enddef + &thesaurusfunc = s:LocalTsrFunc + new | only + setline(1, 'three') + g:LocalTsrFuncArgs = [] + feedkeys("A\\\", 'x') + assert_equal([[1, ''], [0, 'three']], g:LocalTsrFuncArgs) + bw! END " call CheckScriptSuccess(lines) diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index 83709420bf..d9b392992f 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -591,6 +591,21 @@ func Test_opfunc_callback() END call CheckTransLegacySuccess(lines) + " Test for using a script-local function name + func s:OpFunc3(type) + let g:OpFunc3Args = [a:type] + endfunc + set opfunc=s:OpFunc3 + let g:OpFunc3Args = [] + normal! g@l + call assert_equal(['char'], g:OpFunc3Args) + + let &opfunc = 's:OpFunc3' + let g:OpFunc3Args = [] + normal! g@l + call assert_equal(['char'], g:OpFunc3Args) + delfunc s:OpFunc3 + " Using Vim9 lambda expression in legacy context should fail " set opfunc=(a)\ =>\ OpFunc1(24,\ a) let g:OpFunc1Args = [] @@ -614,14 +629,32 @@ func Test_opfunc_callback() let lines =<< trim END vim9script - # Test for using a def function with opfunc def g:Vim9opFunc(val: number, type: string): void g:OpFunc1Args = [val, type] enddef + + # Test for using a def function with opfunc set opfunc=function('g:Vim9opFunc',\ [60]) g:OpFunc1Args = [] normal! g@l assert_equal([60, 'char'], g:OpFunc1Args) + + # Test for using a global function name + &opfunc = g:OpFunc2 + g:OpFunc2Args = [] + normal! g@l + assert_equal(['char'], g:OpFunc2Args) + bw! + + # Test for using a script-local function name + def s:LocalOpFunc(type: string): void + g:LocalOpFuncArgs = [type] + enddef + &opfunc = s:LocalOpFunc + g:LocalOpFuncArgs = [] + normal! g@l + assert_equal(['char'], g:LocalOpFuncArgs) + bw! END " call CheckScriptSuccess(lines) diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index bde6f5a4fc..02cee8a8dd 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -5789,6 +5789,23 @@ func Test_qftextfunc_callback() END call CheckLegacyAndVim9Success(lines) + " Test for using a script-local function name + func s:TqfFunc2(info) + let g:TqfFunc2Args = [a:info.start_idx, a:info.end_idx] + return '' + endfunc + let g:TqfFunc2Args = [] + set quickfixtextfunc=s:TqfFunc2 + cexpr "F10:10:10:L10" + cclose + call assert_equal([1, 1], g:TqfFunc2Args) + + let &quickfixtextfunc = 's:TqfFunc2' + cexpr "F11:11:11:L11" + cclose + call assert_equal([1, 1], g:TqfFunc2Args) + delfunc s:TqfFunc2 + " set 'quickfixtextfunc' to a partial with dict. This used to cause a crash. func SetQftfFunc() let params = {'qftf': function('g:DictQftfFunc')} diff --git a/src/nvim/testdir/test_tagfunc.vim b/src/nvim/testdir/test_tagfunc.vim index 9b4a550945..93b9c67b25 100644 --- a/src/nvim/testdir/test_tagfunc.vim +++ b/src/nvim/testdir/test_tagfunc.vim @@ -267,38 +267,62 @@ func Test_tagfunc_callback() END call CheckLegacyAndVim9Success(lines) + " Test for using a script-local function name + func s:TagFunc3(pat, flags, info) + let g:TagFunc3Args = [a:pat, a:flags, a:info] + return v:null + endfunc + set tagfunc=s:TagFunc3 + new + let g:TagFunc3Args = [] + call assert_fails('tag a21', 'E433:') + call assert_equal(['a21', '', {}], g:TagFunc3Args) + bw! + let &tagfunc = 's:TagFunc3' + new + let g:TagFunc3Args = [] + call assert_fails('tag a22', 'E433:') + call assert_equal(['a22', '', {}], g:TagFunc3Args) + bw! + delfunc s:TagFunc3 + + " invalid return value let &tagfunc = "{a -> 'abc'}" call assert_fails("echo taglist('a')", "E987:") " Using Vim9 lambda expression in legacy context should fail " set tagfunc=(a,\ b,\ c)\ =>\ g:TagFunc1(21,\ a,\ b,\ c) - new | only + new let g:TagFunc1Args = [] " call assert_fails("tag a17", "E117:") call assert_equal([], g:TagFunc1Args) + bw! " Test for using a script local function set tagfunc=ScriptLocalTagFunc - new | only + new let g:ScriptLocalFuncArgs = [] call assert_fails('tag a15', 'E433:') call assert_equal(['a15', '', {}], g:ScriptLocalFuncArgs) + bw! " Test for using a script local funcref variable let Fn = function("s:ScriptLocalTagFunc") let &tagfunc= Fn - new | only + new let g:ScriptLocalFuncArgs = [] call assert_fails('tag a16', 'E433:') call assert_equal(['a16', '', {}], g:ScriptLocalFuncArgs) + bw! " Test for using a string(script local funcref variable) let Fn = function("s:ScriptLocalTagFunc") let &tagfunc= string(Fn) - new | only + new let g:ScriptLocalFuncArgs = [] call assert_fails('tag a16', 'E433:') call assert_equal(['a16', '', {}], g:ScriptLocalFuncArgs) + bw! " set 'tagfunc' to a partial with dict. This used to cause a crash. func SetTagFunc() @@ -324,16 +348,37 @@ func Test_tagfunc_callback() let lines =<< trim END vim9script - # Test for using function() - def Vim9tagFunc(val: number, pat: string, flags: string, info: dict): any - g:Vim9tagFuncArgs = [val, pat, flags, info] + def Vim9tagFunc(callnr: number, pat: string, flags: string, info: dict): any + g:Vim9tagFuncArgs = [callnr, pat, flags, info] return null enddef + + # Test for using a def function with completefunc set tagfunc=function('Vim9tagFunc',\ [60]) - new | only + new g:Vim9tagFuncArgs = [] assert_fails('tag a10', 'E433:') assert_equal([60, 'a10', '', {}], g:Vim9tagFuncArgs) + + # Test for using a global function name + &tagfunc = g:TagFunc2 + new + g:TagFunc2Args = [] + assert_fails('tag a11', 'E433:') + assert_equal(['a11', '', {}], g:TagFunc2Args) + bw! + + # Test for using a script-local function name + def s:LocalTagFunc(pat: string, flags: string, info: dict ): any + g:LocalTagFuncArgs = [pat, flags, info] + return null + enddef + &tagfunc = s:LocalTagFunc + new + g:LocalTagFuncArgs = [] + assert_fails('tag a12', 'E433:') + assert_equal(['a12', '', {}], g:LocalTagFuncArgs) + bw! END " call CheckScriptSuccess(lines) -- cgit From 70ac0c9358251bf54f29a30a369880d94680ace7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 2 Dec 2022 21:00:27 +0800 Subject: vim-patch:8.2.3889: duplicate code for translating script-local function name Problem: Duplicate code for translating script-local function name. Solution: Move the code to get_scriptlocal_funcname(). (Yegappan Lakshmanan, closes vim/vim#9393) https://github.com/vim/vim/commit/e7f4abd38b6e05100c699900c8f87281e363beb2 Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_expr.vim | 15 +++++++++++++++ src/nvim/testdir/test_normal.vim | 12 ++++++++++++ 2 files changed, 27 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index f33358c59a..47f7f5eb0e 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -525,6 +525,21 @@ func Test_funcref() call assert_fails('echo function("min") =~ function("min")', 'E694:') endfunc +" Test for calling function() and funcref() outside of a Vim script context. +func Test_function_outside_script() + let cleanup =<< trim END + call writefile([execute('messages')], 'Xtest.out') + qall + END + call writefile(cleanup, 'Xverify.vim') + call RunVim([], [], "-c \"echo function('s:abc')\" -S Xverify.vim") + call assert_match('E81: Using not in a', readfile('Xtest.out')[0]) + call RunVim([], [], "-c \"echo funcref('s:abc')\" -S Xverify.vim") + call assert_match('E81: Using not in a', readfile('Xtest.out')[0]) + call delete('Xtest.out') + call delete('Xverify.vim') +endfunc + func Test_setmatches() hi def link 1 Comment hi def link 2 PreProc diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index d9b392992f..9c5cc51f79 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -658,6 +658,18 @@ func Test_opfunc_callback() END " call CheckScriptSuccess(lines) + " setting 'opfunc' to a script local function outside of a script context + " should fail + let cleanup =<< trim END + call writefile([execute('messages')], 'Xtest.out') + qall + END + call writefile(cleanup, 'Xverify.vim') + call RunVim([], [], "-c \"set opfunc=s:abc\" -S Xverify.vim") + call assert_match('E81: Using not in a', readfile('Xtest.out')[0]) + call delete('Xtest.out') + call delete('Xverify.vim') + " cleanup set opfunc& delfunc OpFunc1 -- cgit From 1e6d5fdf3f15142dafef6c5bd32ebacf383460f1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 3 Dec 2022 03:40:31 +0800 Subject: vim-patch:9.0.0805: filetype autocmd may cause freed memory access Problem: Filetype autocmd may cause freed memory access. Solution: Set the quickfix-busy flag while filling the buffer. https://github.com/vim/vim/commit/d0fab10ed2a86698937e3c3fed2f10bd9bb5e731 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_quickfix.vim | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 02cee8a8dd..a6c0b2491a 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -3298,6 +3298,21 @@ func Test_resize_from_copen() endtry endfunc +func Test_filetype_autocmd() + " this changes the location list while it is in use to fill a buffer + lexpr '' + lopen + augroup FT_loclist + au FileType * call setloclist(0, [], 'f') + augroup END + silent! lolder + lexpr '' + + augroup FT_loclist + au! FileType + augroup END +endfunc + func Test_vimgrep_with_textlock() new @@ -6165,4 +6180,5 @@ func Test_loclist_replace_autocmd() call setloclist(0, [], 'f') endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From afb3ff52ecafe2d5bd1239869124794bb2ac68b9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 3 Dec 2022 03:44:37 +0800 Subject: vim-patch:9.0.0990: callback name argument is changed by setqflist() Problem: Callback name argument is changed by setqflist(). Solution: Use the expanded function name for the callback, do not store it in the argument. (closes vim/vim#11653) https://github.com/vim/vim/commit/c96b7f5d2af241c5eb1589e9da3dc09e45355e65 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_quickfix.vim | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index a6c0b2491a..7b94c4027c 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -6180,5 +6180,17 @@ func Test_loclist_replace_autocmd() call setloclist(0, [], 'f') endfunc +func s:QfTf(_) +endfunc + +func Test_setqflist_cb_arg() + " This was changing the callback name in the dictionary. + let d = #{quickfixtextfunc: 's:QfTf'} + call setqflist([], 'a', d) + call assert_equal('s:QfTf', d.quickfixtextfunc) + + call setqflist([], 'f') +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 9671908c682dc3fc4e939f44a636457db6f3e5a4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 3 Dec 2022 08:17:38 +0800 Subject: vim-patch:8.2.3900: it is not easy to use a script-local function for an option Problem: It is not easy to use a script-local function for an option. Solution: recognize s: and at the start of the expression. (Yegappan Lakshmanan, closes vim/vim#9401) https://github.com/vim/vim/commit/8bb65f230d3025037f34021a72616038da0601ee Omit duplicate docs in fold.txt: removed in a later runtime update. Cherry-pick test_diffmode.vim changes from patch 8.2.1432. Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_diffmode.vim | 26 ++++++++++++++++++++++--- src/nvim/testdir/test_edit.vim | 10 ++++++++++ src/nvim/testdir/test_fold.vim | 26 +++++++++++++++++++++++++ src/nvim/testdir/test_gf.vim | 26 +++++++++++++++++++++++++ src/nvim/testdir/test_hardcopy.vim | 8 ++++++++ src/nvim/testdir/test_normal.vim | 39 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 132 insertions(+), 3 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_diffmode.vim b/src/nvim/testdir/test_diffmode.vim index d83cd505a6..0049398776 100644 --- a/src/nvim/testdir/test_diffmode.vim +++ b/src/nvim/testdir/test_diffmode.vim @@ -1,4 +1,5 @@ " Tests for diff mode + source shared.vim source screendump.vim source check.vim @@ -681,15 +682,25 @@ func Test_diffexpr() set diffexpr=NewDiffFunc() call assert_fails('windo diffthis', ['E117:', 'E97:']) diffoff! + + " Using a script-local function + func s:NewDiffExpr() + endfunc + set diffexpr=s:NewDiffExpr() + call assert_equal(expand('') .. 'NewDiffExpr()', &diffexpr) + set diffexpr=NewDiffExpr() + call assert_equal(expand('') .. 'NewDiffExpr()', &diffexpr) + %bwipe! set diffexpr& diffopt& + delfunc DiffExpr + delfunc s:NewDiffExpr endfunc func Test_diffpatch() " The patch program on MS-Windows may fail or hang. - if !executable('patch') || !has('unix') - return - endif + CheckExecutable patch + CheckUnix new insert *************** @@ -1250,10 +1261,19 @@ func Test_patchexpr() call assert_equal(2, winnr('$')) call assert_true(&diff) + " Using a script-local function + func s:NewPatchExpr() + endfunc + set patchexpr=s:NewPatchExpr() + call assert_equal(expand('') .. 'NewPatchExpr()', &patchexpr) + set patchexpr=NewPatchExpr() + call assert_equal(expand('') .. 'NewPatchExpr()', &patchexpr) + call delete('Xinput') call delete('Xdiff') set patchexpr& delfunc TPatch + delfunc s:NewPatchExpr %bwipe! endfunc diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index 89e597f401..fd54f77ccb 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -330,6 +330,16 @@ func Test_edit_11_indentexpr() set cinkeys&vim indentkeys&vim set nocindent indentexpr= delfu Do_Indent + + " Using a script-local function + func s:NewIndentExpr() + endfunc + set indentexpr=s:NewIndentExpr() + call assert_equal(expand('') .. 'NewIndentExpr()', &indentexpr) + set indentexpr=NewIndentExpr() + call assert_equal(expand('') .. 'NewIndentExpr()', &indentexpr) + set indentexpr& + bw! endfunc diff --git a/src/nvim/testdir/test_fold.vim b/src/nvim/testdir/test_fold.vim index 2215166cd6..bc8364a80e 100644 --- a/src/nvim/testdir/test_fold.vim +++ b/src/nvim/testdir/test_fold.vim @@ -1273,6 +1273,32 @@ func Test_fold_jump() bw! endfunc +" Test for using a script-local function for 'foldexpr' +func Test_foldexpr_scriptlocal_func() + func! s:FoldFunc() + let g:FoldLnum = v:lnum + endfunc + new | only + call setline(1, 'abc') + let g:FoldLnum = 0 + set foldmethod=expr foldexpr=s:FoldFunc() + redraw! + call assert_equal(expand('') .. 'FoldFunc()', &foldexpr) + call assert_equal(1, g:FoldLnum) + set foldmethod& foldexpr= + bw! + new | only + call setline(1, 'abc') + let g:FoldLnum = 0 + set foldmethod=expr foldexpr=FoldFunc() + redraw! + call assert_equal(expand('') .. 'FoldFunc()', &foldexpr) + call assert_equal(1, g:FoldLnum) + set foldmethod& foldexpr= + delfunc s:FoldFunc + bw! +endfunc + " Make sure a fold containing a nested fold is split correctly when using " foldmethod=indent func Test_fold_split() diff --git a/src/nvim/testdir/test_gf.vim b/src/nvim/testdir/test_gf.vim index b2bb189688..e369645328 100644 --- a/src/nvim/testdir/test_gf.vim +++ b/src/nvim/testdir/test_gf.vim @@ -226,6 +226,32 @@ func Test_gf_includeexpr() delfunc IncFunc endfunc +" Test for using a script-local function for 'includeexpr' +func Test_includeexpr_scriptlocal_func() + func! s:IncludeFunc() + let g:IncludeFname = v:fname + return '' + endfunc + set includeexpr=s:IncludeFunc() + call assert_equal(expand('') .. 'IncludeFunc()', &includeexpr) + new | only + call setline(1, 'TestFile1') + let g:IncludeFname = '' + call assert_fails('normal! gf', 'E447:') + call assert_equal('TestFile1', g:IncludeFname) + bw! + set includeexpr=IncludeFunc() + call assert_equal(expand('') .. 'IncludeFunc()', &includeexpr) + new | only + call setline(1, 'TestFile2') + let g:IncludeFname = '' + call assert_fails('normal! gf', 'E447:') + call assert_equal('TestFile2', g:IncludeFname) + set includeexpr& + delfunc s:IncludeFunc + bw! +endfunc + " Check that expanding directories can handle more than 255 entries. func Test_gf_subdirs_wildcard() let cwd = getcwd() diff --git a/src/nvim/testdir/test_hardcopy.vim b/src/nvim/testdir/test_hardcopy.vim index e390bd5cc8..be83728b4f 100644 --- a/src/nvim/testdir/test_hardcopy.vim +++ b/src/nvim/testdir/test_hardcopy.vim @@ -125,6 +125,14 @@ func Test_printexpr() set printexpr=PrintFails(v:fname_in) call assert_fails('hardcopy', 'E365:') + " Using a script-local function + func s:NewPrintExpr() + endfunc + set printexpr=s:NewPrintExpr() + call assert_equal(expand('') .. 'NewPrintExpr()', &printexpr) + set printexpr=NewPrintExpr() + call assert_equal(expand('') .. 'NewPrintExpr()', &printexpr) + set printexpr& bwipe endfunc diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index 9c5cc51f79..7e8b8c5eef 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -255,6 +255,45 @@ func Test_normal_formatexpr_returns_nonzero() close! endfunc +" Test for using a script-local function for 'formatexpr' +func Test_formatexpr_scriptlocal_func() + func! s:Format() + let g:FormatArgs = [v:lnum, v:count] + endfunc + set formatexpr=s:Format() + call assert_equal(expand('') .. 'Format()', &formatexpr) + new | only + call setline(1, range(1, 40)) + let g:FormatArgs = [] + normal! 2GVjgq + call assert_equal([2, 2], g:FormatArgs) + bw! + set formatexpr=Format() + call assert_equal(expand('') .. 'Format()', &formatexpr) + new | only + call setline(1, range(1, 40)) + let g:FormatArgs = [] + normal! 4GVjgq + call assert_equal([4, 2], g:FormatArgs) + bw! + let &formatexpr = 's:Format()' + new | only + call setline(1, range(1, 40)) + let g:FormatArgs = [] + normal! 6GVjgq + call assert_equal([6, 2], g:FormatArgs) + bw! + let &formatexpr = 'Format()' + new | only + call setline(1, range(1, 40)) + let g:FormatArgs = [] + normal! 8GVjgq + call assert_equal([8, 2], g:FormatArgs) + setlocal formatexpr= + delfunc s:Format + bw! +endfunc + " basic test for formatprg func Test_normal06_formatprg() " only test on non windows platform -- cgit From 5e97984188e95de419ba5a710a060f0614c6c9e0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 3 Dec 2022 08:37:10 +0800 Subject: vim-patch:partial:8.2.3908: cannot use a script-local function for 'foldtext' Problem: Cannot use a script-local function for 'foldtext'. Solution: Expand "s:" and "". (Yegappan Lakshmanan, closes vim/vim#9411) https://github.com/vim/vim/commit/27708e6c7b6f444fd599f3dc5015336b002b874d Only port the changes actually related to 'foldtext'. Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_fold.vim | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_fold.vim b/src/nvim/testdir/test_fold.vim index bc8364a80e..d74187537c 100644 --- a/src/nvim/testdir/test_fold.vim +++ b/src/nvim/testdir/test_fold.vim @@ -1299,6 +1299,37 @@ func Test_foldexpr_scriptlocal_func() bw! endfunc +" Test for using a script-local function for 'foldtext' +func Test_foldtext_scriptlocal_func() + func! s:FoldText() + let g:FoldTextArgs = [v:foldstart, v:foldend] + return foldtext() + endfunc + new | only + call setline(1, range(50)) + let g:FoldTextArgs = [] + set foldmethod=manual + set foldtext=s:FoldText() + norm! 4Gzf4j + redraw! + call assert_equal(expand('') .. 'FoldText()', &foldtext) + call assert_equal([4, 8], g:FoldTextArgs) + set foldtext& + bw! + new | only + call setline(1, range(50)) + let g:FoldTextArgs = [] + set foldmethod=manual + set foldtext=FoldText() + norm! 8Gzf4j + redraw! + call assert_equal(expand('') .. 'FoldText()', &foldtext) + call assert_equal([8, 12], g:FoldTextArgs) + set foldtext& + bw! + delfunc s:FoldText +endfunc + " Make sure a fold containing a nested fold is split correctly when using " foldmethod=indent func Test_fold_split() -- cgit From aa492127311692a576d308db3afbd3bba0fead00 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 3 Dec 2022 13:34:25 +0800 Subject: vim-patch:9.0.0322: crash when no errors and 'quickfixtextfunc' is set (#21269) Problem: Crash when no errors and 'quickfixtextfunc' is set. Solution: Do not handle errors if there aren't any. https://github.com/vim/vim/commit/4f1b083be43f351bc107541e7b0c9655a5d2c0bb Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_quickfix.vim | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 7b94c4027c..e7a4799e0b 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -3932,6 +3932,22 @@ func Xgetlist_empty_tests(cchar) endif endfunc +func Test_empty_list_quickfixtextfunc() + " This was crashing. Can only reproduce by running it in a separate Vim + " instance. + let lines =<< trim END + func s:Func(o) + cgetexpr '0' + endfunc + cope + let &quickfixtextfunc = 's:Func' + cgetfile [ex + END + call writefile(lines, 'Xquickfixtextfunc') + call RunVim([], [], '-e -s -S Xquickfixtextfunc -c qa') + call delete('Xquickfixtextfunc') +endfunc + func Test_getqflist() call Xgetlist_empty_tests('c') call Xgetlist_empty_tests('l') -- cgit From 8a29d9660ea27ff3cd55555f9373b1528808b264 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 3 Dec 2022 13:48:51 +0800 Subject: vim-patch:8.2.1420: test 49 is old style Problem: Test 49 is old style. Solution: Convert remaining parts to new style. Remove obsolete items. (Yegappan Lakshmanan, closes vim/vim#6683) https://github.com/vim/vim/commit/f7c4d83609acdfe0e4d0fec9413697ac97c0c3f9 --- src/nvim/testdir/Make_all.mak | 1 + src/nvim/testdir/Makefile | 29 +- src/nvim/testdir/test49.in | 31 - src/nvim/testdir/test49.ok | 12 - src/nvim/testdir/test49.vim | 1454 ----------------------------------- src/nvim/testdir/test_quickfix.vim | 23 + src/nvim/testdir/test_vimscript.vim | 506 +++++++++++- 7 files changed, 529 insertions(+), 1527 deletions(-) create mode 100644 src/nvim/testdir/Make_all.mak delete mode 100644 src/nvim/testdir/test49.in delete mode 100644 src/nvim/testdir/test49.ok delete mode 100644 src/nvim/testdir/test49.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/Make_all.mak b/src/nvim/testdir/Make_all.mak new file mode 100644 index 0000000000..b917877422 --- /dev/null +++ b/src/nvim/testdir/Make_all.mak @@ -0,0 +1 @@ +# Tests may depend on the existence of this file. diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 2d2853ead7..0684b3798e 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -13,22 +13,12 @@ export SHELL := sh export NVIM_PRG := $(NVIM_PRG) export TMPDIR := $(abspath Xtest-tmpdir) -SCRIPTS_DEFAULT = - -ifneq ($(OS),Windows_NT) - SCRIPTS_DEFAULTS := $(SCRIPTS_DEFAULT) \ - test49.out \ - -endif - ifeq ($(OS),Windows_NT) FIXFF = fixff else FIXFF = endif -SCRIPTS ?= $(SCRIPTS_DEFAULT) - # Tests using runtest.vim. NEW_TESTS_ALOT := test_alot_utf8 test_alot test_alot_latin NEW_TESTS_IN_ALOT := $(shell sed -n '/^source/ s/^source //; s/\.vim$$//p' $(addsuffix .vim,$(NEW_TESTS_ALOT))) @@ -65,11 +55,7 @@ else endif endif -ifdef TESTNUM - SCRIPTS := test$(TESTNUM).out -endif - -nongui: nolog $(FIXFF) $(SCRIPTS) newtests report +nongui: nolog $(FIXFF) newtests report .gdbinit: @echo "[OLDTEST-PREP] Setting up .gdbinit" @@ -87,8 +73,6 @@ report: test1.out: $(NVIM_PRG) -$(SCRIPTS): $(NVIM_PRG) test1.out - NO_PLUGINS = --noplugin --headless # In vim, if the -u command line option is specified, compatible is turned on # and viminfo is not read. Unlike vim, neovim reads viminfo and requires the @@ -146,17 +130,6 @@ test1.out: .gdbinit test1.in @rm -f wrongtermsize @rm -rf X* viminfo -%.out: %.in .gdbinit - @echo "[OLDESTTEST] Running" $* - @rm -rf $*.failed test.ok $(RM_ON_RUN) - @mkdir -p $(TMPDIR) - @cp $*.ok test.ok - @/bin/sh runnvim.sh --oldesttest $(ROOT) $(NVIM_PRG) $* $(RUN_VIM) $*.in - @rm -rf X* test.ok viminfo - -# Explicit dependencies. -test49.out: test49.vim - nolog: @echo "[OLDTEST-PREP] Removing test.log and messages" @rm -f test.log messages diff --git a/src/nvim/testdir/test49.in b/src/nvim/testdir/test49.in deleted file mode 100644 index 435e62765b..0000000000 --- a/src/nvim/testdir/test49.in +++ /dev/null @@ -1,31 +0,0 @@ -This is a test of the script language. - -If after adding a new test, the test output doesn't appear properly in -test49.failed, try to add one or more "G"s at the line ending in "test.out" - -STARTTEST -:se nomore -:lang mess C -:so test49.vim -:" Go back to this file and append the results from register r. -:buf test49.in -G"rp:/^Results/,$w! test.out -:" -:" make valgrind happy -:redir => funclist -:silent func -:redir END -:for line in split(funclist, "\n") -: let name = matchstr(line, 'function \zs[A-Z]\w*\ze(') -: if name != '' -: exe "delfunc " . name -: endif -:endfor -:for v in keys(g:) -: silent! exe "unlet " . v -:endfor -:unlet v -:qa! -ENDTEST - -Results of test49.vim: diff --git a/src/nvim/testdir/test49.ok b/src/nvim/testdir/test49.ok deleted file mode 100644 index d687f5bc77..0000000000 --- a/src/nvim/testdir/test49.ok +++ /dev/null @@ -1,12 +0,0 @@ -Results of test49.vim: -*** Test 82: OK (8454401) -*** Test 83: OK (2835) -*** Test 84: OK (934782101) -*** Test 85: OK (198689) ---- Test 86: No Crash for vimgrep on BufUnload -*** Test 86: OK (0) ---- Test 88: All tests were run with throwing exceptions on error. - The $VIMNOERRTHROW control is not configured. ---- Test 88: All tests were run with throwing exceptions on interrupt. - The $VIMNOINTTHROW control is not configured. -*** Test 88: OK (50443995) diff --git a/src/nvim/testdir/test49.vim b/src/nvim/testdir/test49.vim deleted file mode 100644 index d5f8cd3b60..0000000000 --- a/src/nvim/testdir/test49.vim +++ /dev/null @@ -1,1454 +0,0 @@ -" Vim script language tests -" Author: Servatius Brandt -" Last Change: 2020 Jun 07 - -"------------------------------------------------------------------------------- -" Test environment {{{1 -"------------------------------------------------------------------------------- - - -" Adding new tests easily. {{{2 -" -" Writing new tests is eased considerably with the following functions and -" abbreviations (see "Commands for recording the execution path", "Automatic -" argument generation"). -" -" To get the abbreviations, execute the command -" -" :let test49_set_env = 1 | source test49.vim -" -" To get them always (from src/nvim/testdir), put a line -" -" au! BufRead test49.vim let test49_set_env = 1 | source test49.vim -" -" into the local .vimrc file in the src/nvim/testdir directory. -" -if exists("test49_set_env") && test49_set_env - - " Automatic argument generation for the test environment commands. - - function! Xsum() - let addend = substitute(getline("."), '^.*"\s*X:\s*\|^.*', '', "") - " Evaluate arithmetic expression. - if addend != "" - exec "let g:Xsum = g:Xsum + " . addend - endif - endfunction - - function! Xcheck() - let g:Xsum=0 - ?XpathINIT?,.call Xsum() - exec "norm A " - return g:Xsum - endfunction - - iab Xcheck Xcheck=Xcheck()x - - function! Xcomment(num) - let str = "" - let tabwidth = &sts ? &sts : &ts - let tabs = (48+tabwidth - a:num - virtcol(".")) / tabwidth - while tabs > 0 - let str = str . "\t" - let tabs = tabs - 1 - endwhile - let str = str . '" X:' - return str - endfunction - - function! Xloop() - let back = line(".") . "|norm" . virtcol(".") . "|" - norm 0 - let last = search('X\(loop\|path\)INIT\|Xloop\>', "bW") - exec back - let theline = getline(last) - if theline =~ 'X\(loop\|path\)INIT' - let num = 1 - else - let num = 2 * substitute(theline, '.*Xloop\s*\(\d\+\).*', '\1', "") - endif - ?X\(loop\|path\)INIT? - \s/\(XloopINIT!\=\s*\d\+\s\+\)\@<=\(\d\+\)/\=2*submatch(2)/ - exec back - exec "norm a " - return num . Xcomment(strlen(num)) - endfunction - - iab Xloop Xloop=Xloop()x - - function! Xpath(loopinit) - let back = line(".") . "|norm" . virtcol(".") . "|" - norm 0 - let last = search('XpathINIT\|Xpath\>\|XloopINIT', "bW") - exec back - let theline = getline(last) - if theline =~ 'XpathINIT' - let num = 1 - elseif theline =~ 'Xpath\>' - let num = 2 * substitute(theline, '.*Xpath\s*\(\d\+\).*', '\1', "") - else - let pattern = '.*XloopINIT!\=\s*\(\d\+\)\s*\(\d\+\).*' - let num = substitute(theline, pattern, '\1', "") - let factor = substitute(theline, pattern, '\2', "") - " The "x" from the "Xpath" iab and the character triggering its - " expansion are in the input buffer. Save and clear typeahead so - " that it is not read away by the call to "input()" below. Restore - " afterwards. - call inputsave() - let loops = input("Number of iterations in previous loop? ") - call inputrestore() - while (loops > 0) - let num = num * factor - let loops = loops - 1 - endwhile - endif - exec "norm a " - if a:loopinit - return num . " 1" - endif - return num . Xcomment(strlen(num)) - endfunction - - iab Xpath Xpath=Xpath(0)x - iab XloopINIT XloopINIT=Xpath(1)x - - " Also useful (see ExtraVim below): - aug ExtraVim - au! - au BufEnter syn region ExtraVim - \ start=+^if\s\+ExtraVim(.*)+ end=+^endif+ - \ transparent keepend - au BufEnter syn match ExtraComment /^"/ - \ contained containedin=ExtraVim - au BufEnter hi link ExtraComment vimComment - aug END - - aug Xpath - au BufEnter syn keyword Xpath - \ XpathINIT Xpath XloopINIT Xloop XloopNEXT Xcheck Xout - au BufEnter hi link Xpath Special - aug END - - do BufEnter - - " Do not execute the tests when sourcing this file for getting the functions - " and abbreviations above, which are intended for easily adding new test - " cases; they are not needed for test execution. Unlet the variable - " controlling this so that an explicit ":source" command for this file will - " execute the tests. - unlet test49_set_env - finish - -endif - - -" Commands for recording the execution path. {{{2 -" -" The Xpath/Xloop commands can be used for computing the eXecution path by -" adding (different) powers of 2 from those script lines, for which the -" execution should be checked. Xloop provides different addends for each -" execution of a loop. Permitted values are 2^0 to 2^30, so that 31 execution -" points (multiply counted inside loops) can be tested. -" -" Note that the arguments of the following commands can be generated -" automatically, see below. -" -" Usage: {{{3 -" -" - Use XpathINIT at the beginning of the test. -" -" - Use Xpath to check if a line is executed. -" Argument: power of 2 (decimal). -" -" - To check multiple execution of loops use Xloop for automatically -" computing Xpath values: -" -" - Use XloopINIT before the loop. -" Two arguments: -" - the first Xpath value (power of 2) to be used (Xnext), -" - factor for computing a new Xnext value when reexecuting a loop -" (by a ":continue" or ":endwhile"); this should be 2^n where -" n is the number of Xloop commands inside the loop. -" If XloopINIT! is used, the first execution of XloopNEXT is -" a no-operation. -" -" - Use Xloop inside the loop: -" One argument: -" The argument and the Xnext value are multiplied to build the -" next Xpath value. No new Xnext value is prepared. The argument -" should be 2^(n-1) for the nth Xloop command inside the loop. -" If the loop has only one Xloop command, the argument can be -" omitted (default: 1). -" -" - Use XloopNEXT before ":continue" and ":endwhile". This computes a new -" Xnext value for the next execution of the loop by multiplying the old -" one with the factor specified in the XloopINIT command. No Argument. -" Alternatively, when XloopINIT! is used, a single XloopNEXT at the -" beginning of the loop can be used. -" -" Nested loops are not supported. -" -" - Use Xcheck at end of each test. It prints the test number, the expected -" execution path value, the test result ("OK" or "FAIL"), and, if the tests -" fails, the actual execution path. -" One argument: -" Expected Xpath/Xloop sum for the correct execution path. -" In order that this value can be computed automatically, do the -" following: For each line in the test with an Xpath and Xloop -" command, add a comment starting with "X:" and specifying an -" expression that evaluates to the value contributed by this line to -" the correct execution path. (For copying an Xpath argument of at -" least two digits into the comment, press .) At the end of the -" test, just type "Xcheck" and press . -" -" - In order to add additional information to the test output file, use the -" Xout command. Argument(s) like ":echo". -" -" Automatic argument generation: {{{3 -" -" The arguments of the Xpath, XloopINIT, Xloop, and Xcheck commands can be -" generated automatically, so that new tests can easily be written without -" mental arithmetic. The Xcheck argument is computed from the "X:" comments -" of the preceding Xpath and Xloop commands. See the commands and -" abbreviations at the beginning of this file. -" -" Implementation: {{{3 -" XpathINIT, Xpath, XloopINIT, Xloop, XloopNEXT, Xcheck, Xout. -" -" The variants for existing g:ExtraVimResult are needed when executing a script -" in an extra Vim process, see ExtraVim below. - -" EXTRA_VIM_START - do not change or remove this line. - -com! XpathINIT let g:Xpath = 0 - -if exists("g:ExtraVimResult") - com! -count -bar Xpath exec "!echo >>" . g:ExtraVimResult -else - com! -count -bar Xpath let g:Xpath = g:Xpath + -endif - -com! -count -nargs=1 -bang - \ XloopINIT let g:Xnext = | - \ let g:Xfactor = | - \ let g:Xskip = strlen("") - -if exists("g:ExtraVimResult") - com! -count=1 -bar Xloop exec "!echo " . (g:Xnext * ) . " >>" . - \ g:ExtraVimResult -else - com! -count=1 -bar Xloop let g:Xpath = g:Xpath + g:Xnext * -endif - -com! XloopNEXT let g:Xnext = g:Xnext * - \ (g:Xskip ? 1 : g:Xfactor) | - \ let g:Xskip = 0 - -let @r = "" -let Xtest = 1 -com! -count Xcheck let Xresult = "*** Test " . - \ (Xtest<10?" ":Xtest<100?" ":"") . - \ Xtest . ": " . ( - \ (Xpath==) ? "OK (".Xpath.")" : - \ "FAIL (".Xpath." instead of )" - \ ) | - \ let @R = Xresult . "\n" | - \ echo Xresult | - \ let Xtest = Xtest + 1 - -if exists("g:ExtraVimResult") - com! -nargs=+ Xoutq exec "!echo @R:'" . - \ substitute(substitute(, - \ "'", '&\\&&', "g"), "\n", "@NL@", "g") - \ . "' >>" . g:ExtraVimResult -else - com! -nargs=+ Xoutq let @R = "--- Test " . - \ (g:Xtest<10?" ":g:Xtest<100?" ":"") . - \ g:Xtest . ": " . substitute(, - \ "\n", "&\t ", "g") . "\n" -endif -com! -nargs=+ Xout exec 'Xoutq' - -" Switch off storing of lines for undoing changes. Speeds things up a little. -set undolevels=-1 - -" EXTRA_VIM_STOP - do not change or remove this line. - - -" ExtraVim() - Run a script file in an extra Vim process. {{{2 -" -" This is useful for testing immediate abortion of the script processing due to -" an error in a command dynamically enclosed by a :try/:tryend region or when an -" exception is thrown but not caught or when an interrupt occurs. It can also -" be used for testing :finish. -" -" An interrupt location can be specified by an "INTERRUPT" comment. A number -" telling how often this location is reached (in a loop or in several function -" calls) should be specified as argument. When missing, once per script -" invocation or function call is assumed. INTERRUPT locations are tested by -" setting a breakpoint in that line and using the ">quit" debug command when -" the breakpoint is reached. A function for which an INTERRUPT location is -" specified must be defined before calling it (or executing it as a script by -" using ExecAsScript below). -" -" This function is only called in normal modus ("g:ExtraVimResult" undefined). -" -" Tests to be executed as an extra script should be written as follows: -" -" column 1 column 1 -" | | -" v v -" -" XpathINIT XpathINIT -" if ExtraVim() if ExtraVim() -" ... " ... -" ... " ... -" endif endif -" Xcheck Xcheck -" -" Double quotes in column 1 are removed before the script is executed. -" They should be used if the test has unbalanced conditionals (:if/:endif, -" :while:/endwhile, :try/:endtry) or for a line with a syntax error. The -" extra script may use Xpath, XloopINIT, Xloop, XloopNEXT, and Xout as usual. -" -" A file name may be specified as argument. All messages of the extra Vim -" process are then redirected to the file. An existing file is overwritten. -" -let ExtraVimCount = 0 -let ExtraVimBase = expand("") -let ExtraVimTestEnv = "" -" -function ExtraVim(...) - " Count how often this function is called. - let g:ExtraVimCount = g:ExtraVimCount + 1 - - " Disable folds to prevent that the ranges in the ":write" commands below - " are extended up to the end of a closed fold. This also speeds things up - " considerably. - set nofoldenable - - " Open a buffer for this test script and copy the test environment to - " a temporary file. Take account of parts relevant for the extra script - " execution only. - let current_buffnr = bufnr("%") - execute "view +1" g:ExtraVimBase - if g:ExtraVimCount == 1 - let g:ExtraVimTestEnv = tempname() - execute "/E" . "XTRA_VIM_START/+,/E" . "XTRA_VIM_STOP/-w" - \ g:ExtraVimTestEnv "|']+" - execute "/E" . "XTRA_VIM_START/+,/E" . "XTRA_VIM_STOP/-w >>" - \ g:ExtraVimTestEnv "|']+" - execute "/E" . "XTRA_VIM_START/+,/E" . "XTRA_VIM_STOP/-w >>" - \ g:ExtraVimTestEnv "|']+" - execute "/E" . "XTRA_VIM_START/+,/E" . "XTRA_VIM_STOP/-w >>" - \ g:ExtraVimTestEnv "|']+" - endif - - " Start the extra Vim script with a ":source" command for the test - " environment. The source line number where the extra script will be - " appended, needs to be passed as variable "ExtraVimBegin" to the script. - let extra_script = tempname() - exec "!echo 'source " . g:ExtraVimTestEnv . "' >" . extra_script - let extra_begin = 1 - - " Starting behind the test environment, skip over the first g:ExtraVimCount - " occurrences of "if ExtraVim()" and copy the following lines up to the - " matching "endif" to the extra Vim script. - execute "/E" . "ND_OF_TEST_ENVIRONMENT/" - exec 'norm ' . g:ExtraVimCount . '/^\s*if\s\+ExtraVim(.*)/+' . "\n" - execute ".,/^endif/-write >>" . extra_script - - " Open a buffer for the extra Vim script, delete all ^", and write the - " script if was actually modified. - execute "edit +" . (extra_begin + 1) extra_script - ,$s/^"//e - update - - " Count the INTERRUPTs and build the breakpoint and quit commands. - let breakpoints = "" - let debug_quits = "" - let in_func = 0 - exec extra_begin - while search( - \ '"\s*INTERRUPT\h\@!\|^\s*fu\%[nction]\>!\=\s*\%(\u\|s:\)\w*\s*(\|' - \ . '^\s*\\\|^\s*endf\%[unction]\>\|' - \ . '\%(^\s*fu\%[nction]!\=\s*\)\@ 0 - let theline = getline(".") - if theline =~ '^\s*fu' - " Function definition. - let in_func = 1 - let func_start = line(".") - let func_name = substitute(theline, - \ '^\s*fu\%[nction]!\=\s*\(\%(\u\|s:\)\w*\).*', '\1', "") - elseif theline =~ '^\s*endf' - " End of function definition. - let in_func = 0 - else - let finding = substitute(theline, '.*\(\%' . col(".") . 'c.*\)', - \ '\1', "") - if finding =~ '^"\s*INTERRUPT\h\@!' - " Interrupt comment. Compose as many quit commands as - " specified. - let cnt = substitute(finding, - \ '^"\s*INTERRUPT\s*\(\d*\).*$', '\1', "") - let quits = "" - while cnt > 0 - " Use "\r" rather than "\n" to separate the quit commands. - " "\r" is not interpreted as command separator by the ":!" - " command below but works to separate commands in the - " external vim. - let quits = quits . "q\r" - let cnt = cnt - 1 - endwhile - if in_func - " Add the function breakpoint and note the number of quits - " to be used, if specified, or one for every call else. - let breakpoints = breakpoints . " -c 'breakadd func " . - \ (line(".") - func_start) . " " . - \ func_name . "'" - if quits != "" - let debug_quits = debug_quits . quits - elseif !exists("quits{func_name}") - let quits{func_name} = "q\r" - else - let quits{func_name} = quits{func_name} . "q\r" - endif - else - " Add the file breakpoint and the quits to be used for it. - let breakpoints = breakpoints . " -c 'breakadd file " . - \ line(".") . " " . extra_script . "'" - if quits == "" - let quits = "q\r" - endif - let debug_quits = debug_quits . quits - endif - else - " Add the quits to be used for calling the function or executing - " it as script file. - if finding =~ '^ExecAsScript' - " Sourcing function as script. - let finding = substitute(finding, - \ '^ExecAsScript\s\+\(\%(\u\|s:\)\w*\).*', '\1', "") - else - " Function call. - let finding = substitute(finding, - \ '^\(\%(\u\|s:\)\w*\).*', '\1', "") - endif - if exists("quits{finding}") - let debug_quits = debug_quits . quits{finding} - endif - endif - endif - endwhile - - " Close the buffer for the script and create an (empty) resultfile. - bwipeout - let resultfile = tempname() - exec "!>" . resultfile - - " Run the script in an extra vim. Switch to extra modus by passing the - " resultfile in ExtraVimResult. Redirect messages to the file specified as - " argument if any. Use ":debuggreedy" so that the commands provided on the - " pipe are consumed at the debug prompt. Use "-N" to enable command-line - " continuation ("C" in 'cpo'). Add "nviminfo" to 'viminfo' to avoid - " messing up the user's viminfo file. - let redirect = a:0 ? - \ " -c 'au VimLeave * redir END' -c 'redir\\! >" . a:1 . "'" : "" - exec "!echo '" . debug_quits . "q' | " .. v:progpath .. " -u NONE -N -Xes" . redirect . - \ " -c 'debuggreedy|set viminfo+=nviminfo'" . - \ " -c 'let ExtraVimBegin = " . extra_begin . "'" . - \ " -c 'let ExtraVimResult = \"" . resultfile . "\"'" . breakpoints . - \ " -S " . extra_script - - " Build the resulting sum for resultfile and add it to g:Xpath. Add Xout - " information provided by the extra Vim process to the test output. - let sum = 0 - exec "edit" resultfile - let line = 1 - while line <= line("$") - let theline = getline(line) - if theline =~ '^@R:' - exec 'Xout "' . substitute(substitute( - \ escape(escape(theline, '"'), '\"'), - \ '^@R:', '', ""), '@NL@', "\n", "g") . '"' - else - let sum = sum + getline(line) - endif - let line = line + 1 - endwhile - bwipeout - let g:Xpath = g:Xpath + sum - - " Delete the extra script and the resultfile. - call delete(extra_script) - call delete(resultfile) - - " Switch back to the buffer that was active when this function was entered. - exec "buffer" current_buffnr - - " Return 0. This protects extra scripts from being run in the main Vim - " process. - return 0 -endfunction - - -" ExtraVimThrowpoint() - Relative throwpoint in ExtraVim script {{{2 -" -" Evaluates v:throwpoint and returns the throwpoint relative to the beginning of -" an ExtraVim script as passed by ExtraVim() in ExtraVimBegin. -" -" EXTRA_VIM_START - do not change or remove this line. -function ExtraVimThrowpoint() - if !exists("g:ExtraVimBegin") - Xout "ExtraVimThrowpoint() used outside ExtraVim() script." - return v:throwpoint - endif - - if v:throwpoint =~ '^function\>' - return v:throwpoint - endif - - return "line " . - \ (substitute(v:throwpoint, '.*, line ', '', "") - g:ExtraVimBegin) . - \ " of ExtraVim() script" -endfunction -" EXTRA_VIM_STOP - do not change or remove this line. - - -" MakeScript() - Make a script file from a function. {{{2 -" -" Create a script that consists of the body of the function a:funcname. -" Replace any ":return" by a ":finish", any argument variable by a global -" variable, and every ":call" by a ":source" for the next following argument -" in the variable argument list. This function is useful if similar tests are -" to be made for a ":return" from a function call or a ":finish" in a script -" file. -" -" In order to execute a function specifying an INTERRUPT location (see ExtraVim) -" as a script file, use ExecAsScript below. -" -" EXTRA_VIM_START - do not change or remove this line. -function MakeScript(funcname, ...) - let script = tempname() - execute "redir! >" . script - execute "function" a:funcname - redir END - execute "edit" script - " Delete the "function" and the "endfunction" lines. Do not include the - " word "function" in the pattern since it might be translated if LANG is - " set. When MakeScript() is being debugged, this deletes also the debugging - " output of its line 3 and 4. - exec '1,/.*' . a:funcname . '(.*)/d' - /^\d*\s*endfunction\>/,$d - %s/^\d*//e - %s/return/finish/e - %s/\ 0 - let cnt = cnt + 1 - s/\" . bplist - breaklist - redir END - execute "edit" bplist - " Get the line number from the function breakpoint. Works also when - " LANG is set. - execute 'v/^\s*\d\+\s\+func\s\+' . a:funcname . '\s.*/d' - %s/^\s*\d\+\s\+func\s\+\%(\u\|s:\)\w*\s\D*\(\d*\).*/\1/e - let cnt = 0 - while cnt < line("$") - let cnt = cnt + 1 - if getline(cnt) != "" - execute "breakadd file" getline(cnt) script - endif - endwhile - bwipeout! - call delete(bplist) - endif - - " Source and delete the script. - exec "source" script - call delete(script) -endfunction - -com! -nargs=1 -bar ExecAsScript call ExecAsScript() -" EXTRA_VIM_STOP - do not change or remove this line. - - -" END_OF_TEST_ENVIRONMENT - do not change or remove this line. - -function! MESSAGES(...) - try - exec "edit" g:msgfile - catch /^Vim(edit):/ - return 0 - endtry - - let english = v:lang == "C" || v:lang =~ '^[Ee]n' - let match = 1 - norm gg - - let num = a:0 / 2 - let cnt = 1 - while cnt <= num - let enr = a:{2*cnt - 1} - let emsg= a:{2*cnt} - let cnt = cnt + 1 - - if enr == "" - Xout "TODO: Add message number for:" emsg - elseif enr == "INT" - let enr = "" - endif - if enr == "" && !english - continue - endif - let pattern = (enr != "") ? enr . ':.*' : '' - if english - let pattern = pattern . emsg - endif - if !search(pattern, "W") - let match = 0 - Xout "No match for:" pattern - endif - norm $ - endwhile - - bwipeout! - return match -endfunction - -" Following tests were moved to test_vimscript.vim: -" 1-24, 27-31, 34-40, 49-50, 52-68, 76-81, 87 -" Following tests were moved to test_trycatch.vim: -" 25-26, 32-33, 41-48, 51, 69-75 -let Xtest = 82 - -"------------------------------------------------------------------------------- -" Test 82: Ignoring :catch clauses after an error or interrupt {{{1 -" -" When an exception is thrown and an error or interrupt occurs before -" the matching :catch clause is reached, the exception is discarded -" and the :catch clause is ignored (also for the error or interrupt -" exception being thrown then). -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - try - try - Xpath 1 " X: 1 - throw "arrgh" - Xpath 2 " X: 0 -" if 1 - Xpath 4 " X: 0 - " error after :throw: missing :endif - catch /.*/ - Xpath 8 " X: 0 - Xout v:exception "in" ExtraVimThrowpoint() - catch /.*/ - Xpath 16 " X: 0 - Xout v:exception "in" ExtraVimThrowpoint() - endtry - Xpath 32 " X: 0 - catch /arrgh/ - Xpath 64 " X: 0 - endtry - Xpath 128 " X: 0 -endif - -if ExtraVim() - function! E() - try - try - Xpath 256 " X: 256 - throw "arrgh" - Xpath 512 " X: 0 -" if 1 - Xpath 1024 " X: 0 - " error after :throw: missing :endif - catch /.*/ - Xpath 2048 " X: 0 - Xout v:exception "in" ExtraVimThrowpoint() - catch /.*/ - Xpath 4096 " X: 0 - Xout v:exception "in" ExtraVimThrowpoint() - endtry - Xpath 8192 " X: 0 - catch /arrgh/ - Xpath 16384 " X: 0 - endtry - endfunction - - call E() - Xpath 32768 " X: 0 -endif - -if ExtraVim() - try - try - Xpath 65536 " X: 65536 - throw "arrgh" - Xpath 131072 " X: 0 - catch /.*/ "INTERRUPT - Xpath 262144 " X: 0 - Xout v:exception "in" ExtraVimThrowpoint() - catch /.*/ - Xpath 524288 " X: 0 - Xout v:exception "in" ExtraVimThrowpoint() - endtry - Xpath 1048576 " X: 0 - catch /arrgh/ - Xpath 2097152 " X: 0 - endtry - Xpath 4194304 " X: 0 -endif - -if ExtraVim() - function I() - try - try - Xpath 8388608 " X: 8388608 - throw "arrgh" - Xpath 16777216 " X: 0 - catch /.*/ "INTERRUPT - Xpath 33554432 " X: 0 - Xout v:exception "in" ExtraVimThrowpoint() - catch /.*/ - Xpath 67108864 " X: 0 - Xout v:exception "in" ExtraVimThrowpoint() - endtry - Xpath 134217728 " X: 0 - catch /arrgh/ - Xpath 268435456 " X: 0 - endtry - endfunction - - call I() - Xpath 536870912 " X: 0 -endif - -Xcheck 8454401 - - -"------------------------------------------------------------------------------- -" Test 83: Executing :finally clauses after an error or interrupt {{{1 -" -" When an exception is thrown and an error or interrupt occurs before -" the :finally of the innermost :try is reached, the exception is -" discarded and the :finally clause is executed. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - try - Xpath 1 " X: 1 - try - Xpath 2 " X: 2 - throw "arrgh" - Xpath 4 " X: 0 -" if 1 - Xpath 8 " X: 0 - " error after :throw: missing :endif - finally - Xpath 16 " X: 16 - endtry - Xpath 32 " X: 0 - catch /arrgh/ - Xpath 64 " X: 0 - endtry - Xpath 128 " X: 0 -endif - -if ExtraVim() - try - Xpath 256 " X: 256 - try - Xpath 512 " X: 512 - throw "arrgh" - Xpath 1024 " X: 0 - finally "INTERRUPT - Xpath 2048 " X: 2048 - endtry - Xpath 4096 " X: 0 - catch /arrgh/ - Xpath 8192 " X: 0 - endtry - Xpath 16384 " X: 0 -endif - -Xcheck 2835 - - -"------------------------------------------------------------------------------- -" Test 84: Exceptions in autocommand sequences. {{{1 -" -" When an exception occurs in a sequence of autocommands for -" a specific event, the rest of the sequence is not executed. The -" command that triggered the autocommand execution aborts, and the -" exception is propagated to the caller. -" -" For the FuncUndefined event under a function call expression or -" :call command, the function is not executed, even when it has -" been defined by the autocommands before the exception occurred. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - - function! INT() - "INTERRUPT - let dummy = 0 - endfunction - - aug TMP - autocmd! - - autocmd User x1 Xpath 1 " X: 1 - autocmd User x1 throw "x1" - autocmd User x1 Xpath 2 " X: 0 - - autocmd User x2 Xpath 4 " X: 4 - autocmd User x2 asdf - autocmd User x2 Xpath 8 " X: 0 - - autocmd User x3 Xpath 16 " X: 16 - autocmd User x3 call INT() - autocmd User x3 Xpath 32 " X: 0 - - autocmd FuncUndefined U1 function! U1() - autocmd FuncUndefined U1 Xpath 64 " X: 0 - autocmd FuncUndefined U1 endfunction - autocmd FuncUndefined U1 Xpath 128 " X: 128 - autocmd FuncUndefined U1 throw "U1" - autocmd FuncUndefined U1 Xpath 256 " X: 0 - - autocmd FuncUndefined U2 function! U2() - autocmd FuncUndefined U2 Xpath 512 " X: 0 - autocmd FuncUndefined U2 endfunction - autocmd FuncUndefined U2 Xpath 1024 " X: 1024 - autocmd FuncUndefined U2 ASDF - autocmd FuncUndefined U2 Xpath 2048 " X: 0 - - autocmd FuncUndefined U3 function! U3() - autocmd FuncUndefined U3 Xpath 4096 " X: 0 - autocmd FuncUndefined U3 endfunction - autocmd FuncUndefined U3 Xpath 8192 " X: 8192 - autocmd FuncUndefined U3 call INT() - autocmd FuncUndefined U3 Xpath 16384 " X: 0 - aug END - - try - try - Xpath 32768 " X: 32768 - doautocmd User x1 - catch /x1/ - Xpath 65536 " X: 65536 - endtry - - while 1 - try - Xpath 131072 " X: 131072 - let caught = 0 - doautocmd User x2 - catch /asdf/ - let caught = 1 - finally - Xpath 262144 " X: 262144 - if !caught && !$VIMNOERRTHROW - Xpath 524288 " X: 0 - " Propagate uncaught error exception, - else - " ... but break loop for caught error exception, - " or discard error and break loop if $VIMNOERRTHROW - break - endif - endtry - endwhile - - while 1 - try - Xpath 1048576 " X: 1048576 - let caught = 0 - doautocmd User x3 - catch /Vim:Interrupt/ - let caught = 1 - finally - Xpath 2097152 " X: 2097152 - if !caught && !$VIMNOINTTHROW - Xpath 4194304 " X: 0 - " Propagate uncaught interrupt exception, - else - " ... but break loop for caught interrupt exception, - " or discard interrupt and break loop if $VIMNOINTTHROW - break - endif - endtry - endwhile - - if exists("*U1") | delfunction U1 | endif - if exists("*U2") | delfunction U2 | endif - if exists("*U3") | delfunction U3 | endif - - try - Xpath 8388608 " X: 8388608 - call U1() - catch /U1/ - Xpath 16777216 " X: 16777216 - endtry - - while 1 - try - Xpath 33554432 " X: 33554432 - let caught = 0 - call U2() - catch /ASDF/ - let caught = 1 - finally - Xpath 67108864 " X: 67108864 - if !caught && !$VIMNOERRTHROW - Xpath 134217728 " X: 0 - " Propagate uncaught error exception, - else - " ... but break loop for caught error exception, - " or discard error and break loop if $VIMNOERRTHROW - break - endif - endtry - endwhile - - while 1 - try - Xpath 268435456 " X: 268435456 - let caught = 0 - call U3() - catch /Vim:Interrupt/ - let caught = 1 - finally - Xpath 536870912 " X: 536870912 - if !caught && !$VIMNOINTTHROW - Xpath 1073741824 " X: 0 - " Propagate uncaught interrupt exception, - else - " ... but break loop for caught interrupt exception, - " or discard interrupt and break loop if $VIMNOINTTHROW - break - endif - endtry - endwhile - catch /.*/ - " The Xpath command does not accept 2^31 (negative); display explicitly: - exec "!echo 2147483648 >>" . g:ExtraVimResult - Xout "Caught" v:exception "in" v:throwpoint - endtry - - unlet caught - delfunction INT - delfunction U1 - delfunction U2 - delfunction U3 - au! TMP - aug! TMP -endif - -Xcheck 934782101 - - -"------------------------------------------------------------------------------- -" Test 85: Error exceptions in autocommands for I/O command events {{{1 -" -" When an I/O command is inside :try/:endtry, autocommands to be -" executed after it should be skipped on an error (exception) in the -" command itself or in autocommands to be executed before the command. -" In the latter case, the I/O command should not be executed either. -" Example 1: BufWritePre, :write, BufWritePost -" Example 2: FileReadPre, :read, FileReadPost. -"------------------------------------------------------------------------------- - -XpathINIT - -function! MSG(enr, emsg) - let english = v:lang == "C" || v:lang =~ '^[Ee]n' - if a:enr == "" - Xout "TODO: Add message number for:" a:emsg - let v:errmsg = ":" . v:errmsg - endif - let match = 1 - if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg) - let match = 0 - if v:errmsg == "" - Xout "Message missing." - else - let v:errmsg = escape(v:errmsg, '"') - Xout "Unexpected message:" v:errmsg - endif - endif - return match -endfunction - -" Remove the autocommands for the events specified as arguments in all used -" autogroups. -function Delete_autocommands(...) - let augfile = tempname() - while 1 - try - exec "redir >" . augfile - aug - redir END - exec "edit" augfile - g/^$/d - norm G$ - let wrap = "w" - while search('\%( \|^\)\@<=.\{-}\%( \)\@=', wrap) > 0 - let wrap = "W" - exec "norm y/ \n" - let argno = 1 - while argno <= a:0 - exec "au!" escape(@", " ") a:{argno} - let argno = argno + 1 - endwhile - endwhile - catch /.*/ - finally - bwipeout! - call delete(augfile) - break " discard errors for $VIMNOERRTHROW - endtry - endwhile -endfunction - -call Delete_autocommands("BufWritePre", "BufWritePost") - -while 1 - try - try - let post = 0 - aug TMP - au! BufWritePost * let post = 1 - aug END - let caught = 0 - write /n/o/n/e/x/i/s/t/e/n/t - catch /^Vim(write):/ - let caught = 1 - let v:errmsg = substitute(v:exception, '^Vim(write):', '', "") - finally - Xpath 1 " X: 1 - if !caught && !$VIMNOERRTHROW - Xpath 2 " X: 0 - endif - let v:errmsg = substitute(v:errmsg, '^"/n/o/n/e/x/i/s/t/e/n/t" ', - \ '', "") - if !MSG('E212', "Can't open file for writing") - Xpath 4 " X: 0 - endif - if post - Xpath 8 " X: 0 - Xout "BufWritePost commands executed after write error" - endif - au! TMP - aug! TMP - endtry - catch /.*/ - Xpath 16 " X: 0 - Xout v:exception "in" v:throwpoint - finally - break " discard error for $VIMNOERRTHROW - endtry -endwhile - -while 1 - try - try - let post = 0 - aug TMP - au! BufWritePre * asdf - au! BufWritePost * let post = 1 - aug END - let tmpfile = tempname() - let caught = 0 - exec "write" tmpfile - catch /^Vim\((write)\)\=:/ - let caught = 1 - let v:errmsg = substitute(v:exception, '^Vim\((write)\)\=:', '', "") - finally - Xpath 32 " X: 32 - if !caught && !$VIMNOERRTHROW - Xpath 64 " X: 0 - endif - let v:errmsg = substitute(v:errmsg, '^"'.tmpfile.'" ', '', "") - if !MSG('E492', "Not an editor command") - Xpath 128 " X: 0 - endif - if filereadable(tmpfile) - Xpath 256 " X: 0 - Xout ":write command not suppressed after BufWritePre error" - endif - if post - Xpath 512 " X: 0 - Xout "BufWritePost commands executed after BufWritePre error" - endif - au! TMP - aug! TMP - endtry - catch /.*/ - Xpath 1024 " X: 0 - Xout v:exception "in" v:throwpoint - finally - break " discard error for $VIMNOERRTHROW - endtry -endwhile - -call delete(tmpfile) - -call Delete_autocommands("BufWritePre", "BufWritePost", - \ "BufReadPre", "BufReadPost", "FileReadPre", "FileReadPost") - -while 1 - try - try - let post = 0 - aug TMP - au! FileReadPost * let post = 1 - aug END - let caught = 0 - read /n/o/n/e/x/i/s/t/e/n/t - catch /^Vim(read):/ - let caught = 1 - let v:errmsg = substitute(v:exception, '^Vim(read):', '', "") - finally - Xpath 2048 " X: 2048 - if !caught && !$VIMNOERRTHROW - Xpath 4096 " X: 0 - endif - let v:errmsg = substitute(v:errmsg, ' /n/o/n/e/x/i/s/t/e/n/t$', - \ '', "") - if !MSG('E484', "Can't open file") - Xpath 8192 " X: 0 - endif - if post - Xpath 16384 " X: 0 - Xout "FileReadPost commands executed after write error" - endif - au! TMP - aug! TMP - endtry - catch /.*/ - Xpath 32768 " X: 0 - Xout v:exception "in" v:throwpoint - finally - break " discard error for $VIMNOERRTHROW - endtry -endwhile - -while 1 - try - let infile = tempname() - let tmpfile = tempname() - exec "!echo XYZ >" . infile - exec "edit" tmpfile - try - Xpath 65536 " X: 65536 - try - let post = 0 - aug TMP - au! FileReadPre * asdf - au! FileReadPost * let post = 1 - aug END - let caught = 0 - exec "0read" infile - catch /^Vim\((read)\)\=:/ - let caught = 1 - let v:errmsg = substitute(v:exception, '^Vim\((read)\)\=:', '', - \ "") - finally - Xpath 131072 " X: 131072 - if !caught && !$VIMNOERRTHROW - Xpath 262144 " X: 0 - endif - let v:errmsg = substitute(v:errmsg, ' '.infile.'$', '', "") - if !MSG('E492', "Not an editor command") - Xpath 524288 " X: 0 - endif - if getline("1") == "XYZ" - Xpath 1048576 " X: 0 - Xout ":read command not suppressed after FileReadPre error" - endif - if post - Xpath 2097152 " X: 0 - Xout "FileReadPost commands executed after " . - \ "FileReadPre error" - endif - au! TMP - aug! TMP - endtry - finally - bwipeout! - endtry - catch /.*/ - Xpath 4194304 " X: 0 - Xout v:exception "in" v:throwpoint - finally - break " discard error for $VIMNOERRTHROW - endtry -endwhile - -call delete(infile) -call delete(tmpfile) -unlet! caught post infile tmpfile -delfunction MSG -delfunction Delete_autocommands - -Xcheck 198689 - -"------------------------------------------------------------------------------- -" Test 86: setloclist crash {{{1 -" -" Executing a setloclist() on BufUnload shouldn't crash Vim -"------------------------------------------------------------------------------- - -func F - au BufUnload * :call setloclist(0, [{'bufnr':1, 'lnum':1, 'col':1, 'text': 'tango down'}]) - - :lvimgrep /.*/ *.mak -endfunc - -XpathINIT - -ExecAsScript F - -delfunction F -Xout "No Crash for vimgrep on BufUnload" -Xcheck 0 - -" Test 87 was moved to test_vimscript.vim -let Xtest = 88 - - -"------------------------------------------------------------------------------- -" Test 88: $VIMNOERRTHROW and $VIMNOINTTHROW support {{{1 -" -" It is possible to configure Vim for throwing exceptions on error -" or interrupt, controlled by variables $VIMNOERRTHROW and -" $VIMNOINTTHROW. This is just for increasing the number of tests. -" All tests here should run for all four combinations of setting -" these variables to 0 or 1. The variables are intended for the -" development phase only. In the final release, Vim should be -" configured to always use error and interrupt exceptions. -" -" The test result is "OK", -" -" - if the $VIMNOERRTHROW and the $VIMNOINTTHROW control are not -" configured and exceptions are thrown on error and on -" interrupt. -" -" - if the $VIMNOERRTHROW or the $VIMNOINTTHROW control is -" configured and works as intended. -" -" What actually happens, is shown in the test output. -" -" Otherwise, the test result is "FAIL", and the test output describes -" the problem. -" -" IMPORTANT: This must be the last test because it sets $VIMNOERRTHROW and -" $VIMNOINTTHROW. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - - function! ThrowOnError() - XloopNEXT - let caught = 0 - try - Xloop 1 " X: 1 + 8 + 64 - asdf - catch /.*/ - let caught = 1 " error exception caught - finally - Xloop 2 " X: 2 + 16 + 128 - return caught " discard aborting error - endtry - Xloop 4 " X: 0 - endfunction - - let quits_skipped = 0 - - function! ThrowOnInterrupt() - XloopNEXT - let caught = 0 - try - Xloop 1 " X: (1 + 8 + 64) * 512 - "INTERRUPT3 - let dummy = 0 - let g:quits_skipped = g:quits_skipped + 1 - catch /.*/ - let caught = 1 " interrupt exception caught - finally - Xloop 2 " X: (2 + 16 + 128) * 512 - return caught " discard interrupt - endtry - Xloop 4 " X: 0 - endfunction - - function! CheckThrow(Type) - execute 'return ThrowOn' . a:Type . '()' - endfunction - - function! CheckConfiguration(type) " type is "error" or "interrupt" - - let type = a:type - let Type = substitute(type, '.*', '\u&', "") - let VAR = '$VIMNO' . substitute(type, '\(...\).*', '\U\1', "") . 'THROW' - - if type == "error" - XloopINIT! 1 8 - elseif type == "interrupt" - XloopINIT! 512 8 - endif - - exec 'let requested_for_tests = exists(VAR) && ' . VAR . ' == 0' - exec 'let suppressed_for_tests = ' . VAR . ' != 0' - let used_in_tests = CheckThrow(Type) - - exec 'let ' . VAR . ' = 0' - let request_works = CheckThrow(Type) - - exec 'let ' . VAR . ' = 1' - let suppress_works = !CheckThrow(Type) - - if type == "error" - XloopINIT! 262144 8 - elseif type == "interrupt" - XloopINIT! 2097152 8 - - if g:quits_skipped != 0 - Xloop 1 " X: 0*2097152 - Xout "Test environment error. Interrupt breakpoints skipped: " - \ . g:quits_skipped . ".\n" - \ . "Cannot check whether interrupt exceptions are thrown." - return - endif - endif - - let failure = - \ !suppressed_for_tests && !used_in_tests - \ || !request_works - - let contradiction = - \ used_in_tests - \ ? suppressed_for_tests && !request_works - \ : !suppressed_for_tests - - if failure - " Failure in configuration. - Xloop 2 " X: 0 * 2* (262144 + 2097152) - elseif contradiction - " Failure in test logic. Should not happen. - Xloop 4 " X: 0 * 4 * (262144 + 2097152) - endif - - let var_control_configured = - \ request_works != used_in_tests - \ || suppress_works == used_in_tests - - let var_control_not_configured = - \ requested_for_tests || suppressed_for_tests - \ ? request_works && !suppress_works - \ : request_works == used_in_tests - \ && suppress_works != used_in_tests - - let with = used_in_tests ? "with" : "without" - - let set = suppressed_for_tests ? "non-zero" : - \ requested_for_tests ? "0" : "unset" - - let although = contradiction && !var_control_not_configured - \ ? ",\nalthough " - \ : ".\n" - - let output = "All tests were run " . with . " throwing exceptions on " - \ . type . although - - if !var_control_not_configured - let output = output . VAR . " was " . set . "." - - if !request_works && !requested_for_tests - let output = output . - \ "\n" . Type . " exceptions are not thrown when " . VAR . - \ " is\nset to 0." - endif - - if !suppress_works && (!used_in_tests || - \ !request_works && - \ !requested_for_tests && !suppressed_for_tests) - let output = output . - \ "\n" . Type . " exceptions are thrown when " . VAR . - \ " is set to 1." - endif - - if !failure && var_control_configured - let output = output . - \ "\nRun tests also with " . substitute(VAR, '^\$', '', "") - \ . "=" . used_in_tests . "." - \ . "\nThis is for testing in the development phase only." - \ . " Remove the \n" - \ . VAR . " control in the final release." - endif - else - let output = output . - \ "The " . VAR . " control is not configured." - endif - - Xout output - endfunction - - call CheckConfiguration("error") - Xpath 16777216 " X: 16777216 - call CheckConfiguration("interrupt") - Xpath 33554432 " X: 33554432 -endif - -Xcheck 50443995 - -" IMPORTANT: No test should be added after this test because it changes -" $VIMNOERRTHROW and $VIMNOINTTHROW. - - -"------------------------------------------------------------------------------- -" Modelines {{{1 -" vim: ts=8 sw=4 tw=80 fdm=marker -"------------------------------------------------------------------------------- diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index e7a4799e0b..45b6e6b38c 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -5328,6 +5328,29 @@ func Test_lhelpgrep_from_help_window() new | only! endfunc +" Test for the crash fixed by 7.3.715 +func Test_setloclist_crash() + %bw! + let g:BufNum = bufnr() + augroup QF_Test + au! + au BufUnload * call setloclist(0, [{'bufnr':g:BufNum, 'lnum':1, 'col':1, 'text': 'tango down'}]) + augroup END + + try + lvimgrep /.*/ *.mak + catch /E926:/ + endtry + call assert_equal('tango down', getloclist(0, {'items' : 0}).items[0].text) + call assert_equal(1, getloclist(0, {'size' : 0}).size) + + augroup QF_Test + au! + augroup END + unlet g:BufNum + %bw! +endfunc + " Test for adding an invalid entry with the quickfix window open and making " sure that the window contents are not changed func Test_add_invalid_entry_with_qf_window() diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index aedc63ef00..f85864cdce 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -1,5 +1,6 @@ " Test various aspects of the Vim script language. -" Most of this was formerly in test49. +" Most of this was formerly in test49.vim (developed by Servatius Brandt +" ) source check.vim source shared.vim @@ -5878,7 +5879,7 @@ func Test_discard_exception_after_error_1() call RunInNewVim(test, verify) endfunc -" TODO: Not able inject an interrupt after throwing an exception +" TODO: Need to interrupt the code before the endtry is invoked func Disable_Test_discard_exception_after_error_2() let test =<< trim [CODE] try @@ -5901,6 +5902,507 @@ func Disable_Test_discard_exception_after_error_2() call RunInNewVim(test, verify) endfunc +"------------------------------------------------------------------------------- +" Test 82: Ignoring :catch clauses after an error or interrupt {{{1 +" +" When an exception is thrown and an error or interrupt occurs before +" the matching :catch clause is reached, the exception is discarded +" and the :catch clause is ignored (also for the error or interrupt +" exception being thrown then). +"------------------------------------------------------------------------------- + +func Test_ignore_catch_after_error_1() + let test =<< trim [CODE] + try + try + Xpath 'a' + throw "arrgh" + call assert_report('should not get here') + if 1 + call assert_report('should not get here') + " error after :throw: missing :endif + catch /.*/ + call assert_report('should not get here') + catch /.*/ + call assert_report('should not get here') + endtry + call assert_report('should not get here') + catch /arrgh/ + call assert_report('should not get here') + endtry + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('a', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +func Test_ignore_catch_after_error_2() + let test =<< trim [CODE] + func E() + try + try + Xpath 'a' + throw "arrgh" + call assert_report('should not get here') + if 1 + call assert_report('should not get here') + " error after :throw: missing :endif + catch /.*/ + call assert_report('should not get here') + catch /.*/ + call assert_report('should not get here') + endtry + call assert_report('should not get here') + catch /arrgh/ + call assert_report('should not get here') + endtry + endfunc + + call E() + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('a', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +" TODO: Need to interrupt the code right before the catch is invoked +func FIXME_Test_ignore_catch_after_intr_1() + let test =<< trim [CODE] + try + try + Xpath 'a' + throw "arrgh" + call assert_report('should not get here') + catch /.*/ " TODO: Need to interrupt before this catch is + call interrupt() " invoked + call assert_report('should not get here') + catch /.*/ + call assert_report('should not get here') + endtry + call assert_report('should not get here') + catch /arrgh/ + call assert_report('should not get here') + endtry + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('a', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +" TODO: Need to interrupt the code right before the catch is invoked +func FIXME_Test_ignore_catch_after_intr_2() + let test =<< trim [CODE] + func I() + try + try + Xpath 'a' + throw "arrgh" + call assert_report('should not get here') + catch /.*/ " TODO: Need to interrupt before this catch is + " invoked + call interrupt() + call assert_report('should not get here') + catch /.*/ + call assert_report('should not get here') + endtry + call assert_report('should not get here') + catch /arrgh/ + call assert_report('should not get here') + endtry + endfunc + + call I() + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('a', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 83: Executing :finally clauses after an error or interrupt {{{1 +" +" When an exception is thrown and an error or interrupt occurs before +" the :finally of the innermost :try is reached, the exception is +" discarded and the :finally clause is executed. +"------------------------------------------------------------------------------- + +func Test_finally_after_error() + let test =<< trim [CODE] + try + Xpath 'a' + try + Xpath 'b' + throw "arrgh" + call assert_report('should not get here') + if 1 + call assert_report('should not get here') + " error after :throw: missing :endif + finally + Xpath 'c' + endtry + call assert_report('should not get here') + catch /arrgh/ + call assert_report('should not get here') + endtry + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('abc', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +" TODO: Need to interrupt the code right before the finally is invoked +func FIXME_Test_finally_after_intr() + let test =<< trim [CODE] + try + Xpath 'a' + try + Xpath 'b' + throw "arrgh" + call assert_report('should not get here') + finally " TODO: Need to interrupt before the finally is invoked + Xpath 'c' + endtry + call assert_report('should not get here') + catch /arrgh/ + call assert_report('should not get here') + endtry + call assert_report('should not get here') + [CODE] + let verify =<< trim [CODE] + call assert_equal('abc', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 84: Exceptions in autocommand sequences. {{{1 +" +" When an exception occurs in a sequence of autocommands for +" a specific event, the rest of the sequence is not executed. The +" command that triggered the autocommand execution aborts, and the +" exception is propagated to the caller. +" +" For the FuncUndefined event under a function call expression or +" :call command, the function is not executed, even when it has +" been defined by the autocommands before the exception occurred. +"------------------------------------------------------------------------------- + +func Test_autocmd_exception() + let test =<< trim [CODE] + func INT() + call interrupt() + endfunc + + aug TMP + autocmd! + + autocmd User x1 Xpath 'a' + autocmd User x1 throw "x1" + autocmd User x1 call assert_report('should not get here') + + autocmd User x2 Xpath 'b' + autocmd User x2 asdf + autocmd User x2 call assert_report('should not get here') + + autocmd User x3 Xpath 'c' + autocmd User x3 call INT() + autocmd User x3 call assert_report('should not get here') + + autocmd FuncUndefined U1 func U1() + autocmd FuncUndefined U1 call assert_report('should not get here') + autocmd FuncUndefined U1 endfunc + autocmd FuncUndefined U1 Xpath 'd' + autocmd FuncUndefined U1 throw "U1" + autocmd FuncUndefined U1 call assert_report('should not get here') + + autocmd FuncUndefined U2 func U2() + autocmd FuncUndefined U2 call assert_report('should not get here') + autocmd FuncUndefined U2 endfunc + autocmd FuncUndefined U2 Xpath 'e' + autocmd FuncUndefined U2 ASDF + autocmd FuncUndefined U2 call assert_report('should not get here') + + autocmd FuncUndefined U3 func U3() + autocmd FuncUndefined U3 call assert_report('should not get here') + autocmd FuncUndefined U3 endfunc + autocmd FuncUndefined U3 Xpath 'f' + autocmd FuncUndefined U3 call INT() + autocmd FuncUndefined U3 call assert_report('should not get here') + aug END + + try + try + Xpath 'g' + doautocmd User x1 + catch /x1/ + Xpath 'h' + endtry + + while 1 + try + Xpath 'i' + doautocmd User x2 + catch /asdf/ + Xpath 'j' + finally + Xpath 'k' + break + endtry + endwhile + + while 1 + try + Xpath 'l' + doautocmd User x3 + catch /Vim:Interrupt/ + Xpath 'm' + finally + Xpath 'n' + " ... but break loop for caught interrupt exception, + " or discard interrupt and break loop if $VIMNOINTTHROW + break + endtry + endwhile + + if exists("*U1") | delfunction U1 | endif + if exists("*U2") | delfunction U2 | endif + if exists("*U3") | delfunction U3 | endif + + try + Xpath 'o' + call U1() + catch /U1/ + Xpath 'p' + endtry + + while 1 + try + Xpath 'q' + call U2() + catch /ASDF/ + Xpath 'r' + finally + Xpath 's' + " ... but break loop for caught error exception, + " or discard error and break loop if $VIMNOERRTHROW + break + endtry + endwhile + + while 1 + try + Xpath 't' + call U3() + catch /Vim:Interrupt/ + Xpath 'u' + finally + Xpath 'v' + " ... but break loop for caught interrupt exception, + " or discard interrupt and break loop if $VIMNOINTTHROW + break + endtry + endwhile + catch /.*/ + call assert_report('should not get here') + endtry + Xpath 'w' + [CODE] + let verify =<< trim [CODE] + call assert_equal('gahibjklcmnodpqerstfuvw', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + +"------------------------------------------------------------------------------- +" Test 85: Error exceptions in autocommands for I/O command events {{{1 +" +" When an I/O command is inside :try/:endtry, autocommands to be +" executed after it should be skipped on an error (exception) in the +" command itself or in autocommands to be executed before the command. +" In the latter case, the I/O command should not be executed either. +" Example 1: BufWritePre, :write, BufWritePost +" Example 2: FileReadPre, :read, FileReadPost. +"------------------------------------------------------------------------------- + +func Test_autocmd_error_io_exception() + let test =<< trim [CODE] + " Remove the autocommands for the events specified as arguments in all used + " autogroups. + func Delete_autocommands(...) + let augfile = tempname() + while 1 + try + exec "redir >" . augfile + aug + redir END + exec "edit" augfile + g/^$/d + norm G$ + let wrap = "w" + while search('\%( \|^\)\@<=.\{-}\%( \)\@=', wrap) > 0 + let wrap = "W" + exec "norm y/ \n" + let argno = 1 + while argno <= a:0 + exec "au!" escape(@", " ") a:{argno} + let argno = argno + 1 + endwhile + endwhile + catch /.*/ + finally + bwipeout! + call delete(augfile) + break + endtry + endwhile + endfunc + + call Delete_autocommands("BufWritePre", "BufWritePost") + + while 1 + try + try + let post = 0 + aug TMP + au! BufWritePost * let post = 1 + aug END + write /n/o/n/e/x/i/s/t/e/n/t + catch /^Vim(write):/ + Xpath 'a' + call assert_match("E212: Can't open file for writing", v:exception) + finally + Xpath 'b' + call assert_equal(0, post) + au! TMP + aug! TMP + endtry + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'c' + break + endtry + endwhile + + while 1 + try + try + let post = 0 + aug TMP + au! BufWritePre * asdf + au! BufWritePost * let post = 1 + aug END + let tmpfile = tempname() + exec "write" tmpfile + catch /^Vim\((write)\)\=:/ + Xpath 'd' + call assert_match('E492: Not an editor command', v:exception) + finally + Xpath 'e' + if filereadable(tmpfile) + call assert_report('should not get here') + endif + call assert_equal(0, post) + au! TMP + aug! TMP + endtry + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'f' + break + endtry + endwhile + + call delete(tmpfile) + + call Delete_autocommands("BufWritePre", "BufWritePost", + \ "BufReadPre", "BufReadPost", "FileReadPre", "FileReadPost") + + while 1 + try + try + let post = 0 + aug TMP + au! FileReadPost * let post = 1 + aug END + let caught = 0 + read /n/o/n/e/x/i/s/t/e/n/t + catch /^Vim(read):/ + Xpath 'g' + call assert_match("E484: Can't open file", v:exception) + finally + Xpath 'h' + call assert_equal(0, post) + au! TMP + aug! TMP + endtry + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'i' + break + endtry + endwhile + + while 1 + try + let infile = tempname() + let tmpfile = tempname() + call writefile(["XYZ"], infile) + exec "edit" tmpfile + try + Xpath 'j' + try + let post = 0 + aug TMP + au! FileReadPre * asdf + au! FileReadPost * let post = 1 + aug END + exec "0read" infile + catch /^Vim\((read)\)\=:/ + Xpath 'k' + call assert_match('E492: Not an editor command', v:exception) + finally + Xpath 'l' + if getline("1") == "XYZ" + call assert_report('should not get here') + endif + call assert_equal(0, post) + au! TMP + aug! TMP + endtry + finally + Xpath 'm' + bwipeout! + endtry + catch /.*/ + call assert_report('should not get here') + finally + Xpath 'n' + break + endtry + endwhile + + call delete(infile) + call delete(tmpfile) + [CODE] + let verify =<< trim [CODE] + call assert_equal('abcdefghijklmn', g:Xpath) + [CODE] + call RunInNewVim(test, verify) +endfunc + "------------------------------------------------------------------------------- " Test 87 using (expr) ? funcref : funcref {{{1 " -- cgit From 7d283d21390e061d35888b66a15a00898c8af2ff Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 3 Dec 2022 14:22:18 +0800 Subject: vim-patch:8.2.1440: debugger code insufficiently tested Problem: Debugger code insufficiently tested. Solution: Add a few more tests. (Yegappan Lakshmanan, closes vim/vim#6700) https://github.com/vim/vim/commit/16c6232cad40af37f37dc9c561392b7761b9e229 --- src/nvim/testdir/test_debugger.vim | 43 ++++------- src/nvim/testdir/test_vimscript.vim | 143 +++++++++++++++++++++++------------- 2 files changed, 106 insertions(+), 80 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_debugger.vim b/src/nvim/testdir/test_debugger.vim index 2be94409ca..4609b9d2f9 100644 --- a/src/nvim/testdir/test_debugger.vim +++ b/src/nvim/testdir/test_debugger.vim @@ -1145,7 +1145,6 @@ func Test_breakpt_endif_intr() let caught_intr = 0 debuggreedy call feedkeys(":call F()\quit\", "xt") - call F() catch /^Vim:Interrupt$/ call assert_match('\.F, line 4', v:throwpoint) let caught_intr = 1 @@ -1176,7 +1175,6 @@ func Test_breakpt_else_intr() let caught_intr = 0 debuggreedy call feedkeys(":call F()\quit\", "xt") - call F() catch /^Vim:Interrupt$/ call assert_match('\.F, line 4', v:throwpoint) let caught_intr = 1 @@ -1205,7 +1203,6 @@ func Test_breakpt_endwhile_intr() let caught_intr = 0 debuggreedy call feedkeys(":call F()\quit\", "xt") - call F() catch /^Vim:Interrupt$/ call assert_match('\.F, line 4', v:throwpoint) let caught_intr = 1 @@ -1217,38 +1214,24 @@ func Test_breakpt_endwhile_intr() delfunc F endfunc -" Test for setting a breakpoint on an :endtry where an exception is pending to -" be processed and then quit the script. This should generate an interrupt and -" the thrown exception should be ignored. -func Test_breakpt_endtry_intr() - func F() - try - let g:Xpath ..= 'a' - throw "abc" - endtry - invalid_command +" Test for setting a breakpoint on a script local function +func Test_breakpt_scriptlocal_func() + let g:Xpath = '' + func s:G() + let g:Xpath ..= 'a' endfunc - let g:Xpath = '' - breakadd func 4 F - try - let caught_intr = 0 - let caught_abc = 0 - debuggreedy - call feedkeys(":call F()\quit\", "xt") - call F() - catch /abc/ - let caught_abc = 1 - catch /^Vim:Interrupt$/ - call assert_match('\.F, line 4', v:throwpoint) - let caught_intr = 1 - endtry + let funcname = expand("") .. "G" + exe "breakadd func 1 " .. funcname + debuggreedy + redir => output + call feedkeys(":call " .. funcname .. "()\c\", "xt") + redir END 0debuggreedy - call assert_equal(1, caught_intr) - call assert_equal(0, caught_abc) + call assert_match('Breakpoint in "' .. funcname .. '" line 1', output) call assert_equal('a', g:Xpath) breakdel * - delfunc F + exe "delfunc " .. funcname endfunc " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index f85864cdce..b0c4baf7c2 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -5879,27 +5879,39 @@ func Test_discard_exception_after_error_1() call RunInNewVim(test, verify) endfunc -" TODO: Need to interrupt the code before the endtry is invoked -func Disable_Test_discard_exception_after_error_2() - let test =<< trim [CODE] +" interrupt the code before the endtry is invoked +func Test_discard_exception_after_error_2() + XpathINIT + let lines =<< trim [CODE] try Xpath 'a' try Xpath 'b' throw "arrgh" - call interrupt() " FIXME: throw is not interrupted here call assert_report('should not get here') - endtry + endtry " interrupt here call assert_report('should not get here') catch /arrgh/ call assert_report('should not get here') endtry call assert_report('should not get here') [CODE] - let verify =<< trim [CODE] - call assert_equal('ab', g:Xpath) - [CODE] - call RunInNewVim(test, verify) + call writefile(lines, 'Xscript') + + breakadd file 7 Xscript + try + let caught_intr = 0 + debuggreedy + call feedkeys(":source Xscript\quit\", "xt") + catch /^Vim:Interrupt$/ + call assert_match('Xscript, line 7', v:throwpoint) + let caught_intr = 1 + endtry + 0debuggreedy + call assert_equal(1, caught_intr) + call assert_equal('ab', g:Xpath) + breakdel * + call delete('Xscript') endfunc "------------------------------------------------------------------------------- @@ -5969,16 +5981,16 @@ func Test_ignore_catch_after_error_2() call RunInNewVim(test, verify) endfunc -" TODO: Need to interrupt the code right before the catch is invoked -func FIXME_Test_ignore_catch_after_intr_1() - let test =<< trim [CODE] +" interrupt right before a catch is invoked in a script +func Test_ignore_catch_after_intr_1() + XpathINIT + let lines =<< trim [CODE] try try Xpath 'a' throw "arrgh" call assert_report('should not get here') - catch /.*/ " TODO: Need to interrupt before this catch is - call interrupt() " invoked + catch /.*/ " interrupt here call assert_report('should not get here') catch /.*/ call assert_report('should not get here') @@ -5989,41 +6001,59 @@ func FIXME_Test_ignore_catch_after_intr_1() endtry call assert_report('should not get here') [CODE] - let verify =<< trim [CODE] - call assert_equal('a', g:Xpath) - [CODE] - call RunInNewVim(test, verify) + call writefile(lines, 'Xscript') + + breakadd file 6 Xscript + try + let caught_intr = 0 + debuggreedy + call feedkeys(":source Xscript\quit\", "xt") + catch /^Vim:Interrupt$/ + call assert_match('Xscript, line 6', v:throwpoint) + let caught_intr = 1 + endtry + 0debuggreedy + call assert_equal(1, caught_intr) + call assert_equal('a', g:Xpath) + breakdel * + call delete('Xscript') endfunc -" TODO: Need to interrupt the code right before the catch is invoked -func FIXME_Test_ignore_catch_after_intr_2() - let test =<< trim [CODE] - func I() +" interrupt right before a catch is invoked inside a function. +func Test_ignore_catch_after_intr_2() + XpathINIT + func F() + try try - try - Xpath 'a' - throw "arrgh" - call assert_report('should not get here') - catch /.*/ " TODO: Need to interrupt before this catch is - " invoked - call interrupt() - call assert_report('should not get here') - catch /.*/ - call assert_report('should not get here') - endtry + Xpath 'a' + throw "arrgh" call assert_report('should not get here') - catch /arrgh/ + catch /.*/ " interrupt here + call assert_report('should not get here') + catch /.*/ call assert_report('should not get here') endtry - endfunc - - call I() + call assert_report('should not get here') + catch /arrgh/ + call assert_report('should not get here') + endtry call assert_report('should not get here') - [CODE] - let verify =<< trim [CODE] - call assert_equal('a', g:Xpath) - [CODE] - call RunInNewVim(test, verify) + endfunc + + breakadd func 6 F + try + let caught_intr = 0 + debuggreedy + call feedkeys(":call F()\quit\", "xt") + catch /^Vim:Interrupt$/ + call assert_match('\.F, line 6', v:throwpoint) + let caught_intr = 1 + endtry + 0debuggreedy + call assert_equal(1, caught_intr) + call assert_equal('a', g:Xpath) + breakdel * + delfunc F endfunc "------------------------------------------------------------------------------- @@ -6060,16 +6090,17 @@ func Test_finally_after_error() call RunInNewVim(test, verify) endfunc -" TODO: Need to interrupt the code right before the finally is invoked -func FIXME_Test_finally_after_intr() - let test =<< trim [CODE] +" interrupt the code right before the finally is invoked +func Test_finally_after_intr() + XpathINIT + let lines =<< trim [CODE] try Xpath 'a' try Xpath 'b' throw "arrgh" call assert_report('should not get here') - finally " TODO: Need to interrupt before the finally is invoked + finally " interrupt here Xpath 'c' endtry call assert_report('should not get here') @@ -6078,10 +6109,22 @@ func FIXME_Test_finally_after_intr() endtry call assert_report('should not get here') [CODE] - let verify =<< trim [CODE] - call assert_equal('abc', g:Xpath) - [CODE] - call RunInNewVim(test, verify) + call writefile(lines, 'Xscript') + + breakadd file 7 Xscript + try + let caught_intr = 0 + debuggreedy + call feedkeys(":source Xscript\quit\", "xt") + catch /^Vim:Interrupt$/ + call assert_match('Xscript, line 7', v:throwpoint) + let caught_intr = 1 + endtry + 0debuggreedy + call assert_equal(1, caught_intr) + call assert_equal('abc', g:Xpath) + breakdel * + call delete('Xscript') endfunc "------------------------------------------------------------------------------- -- cgit From e7a2ae829ae92476b67ca86b039d6b79208080d8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 3 Dec 2022 20:10:36 +0800 Subject: test(old): make ":h local-additions" work properly in test_help.vim --- src/nvim/testdir/runtest.vim | 2 +- src/nvim/testdir/test_help.vim | 15 +++++++++++++++ src/nvim/testdir/test_help_tagjump.vim | 12 ------------ 3 files changed, 16 insertions(+), 13 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim index 15f66fc1ad..3c5699af73 100644 --- a/src/nvim/testdir/runtest.vim +++ b/src/nvim/testdir/runtest.vim @@ -105,7 +105,7 @@ set nomore lang mess C " Nvim: append runtime from build dir, which contains the generated doc/tags. -let &runtimepath .= ','.expand($BUILD_DIR).'/runtime/' +let &runtimepath ..= ',' .. expand($BUILD_DIR) .. '/runtime/' let s:t_bold = &t_md let s:t_normal = &t_me diff --git a/src/nvim/testdir/test_help.vim b/src/nvim/testdir/test_help.vim index e30d305703..2ba30ce57f 100644 --- a/src/nvim/testdir/test_help.vim +++ b/src/nvim/testdir/test_help.vim @@ -2,6 +2,21 @@ source check.vim +func SetUp() + let s:vimruntime = $VIMRUNTIME + let s:runtimepath = &runtimepath + " Set $VIMRUNTIME to $BUILD_DIR/runtime and remove the original $VIMRUNTIME + " path from &runtimepath so that ":h local-additions" won't pick up builtin + " help files. + let $VIMRUNTIME = expand($BUILD_DIR) .. '/runtime' + set runtimepath-=../../../runtime +endfunc + +func TearDown() + let $VIMRUNTIME = s:vimruntime + let &runtimepath = s:runtimepath +endfunc + func Test_help_restore_snapshot() help set buftype= diff --git a/src/nvim/testdir/test_help_tagjump.vim b/src/nvim/testdir/test_help_tagjump.vim index f81e4fb1ef..eae1a241e3 100644 --- a/src/nvim/testdir/test_help_tagjump.vim +++ b/src/nvim/testdir/test_help_tagjump.vim @@ -1,17 +1,5 @@ " Tests for :help! {subject} -func SetUp() - " v:progpath is …/build/bin/nvim and we need …/build/runtime - " to be added to &rtp - let builddir = fnamemodify(exepath(v:progpath), ':h:h') - let s:rtp = &rtp - let &rtp .= printf(',%s/runtime', builddir) -endfunc - -func TearDown() - let &rtp = s:rtp -endfunc - func Test_help_tagjump() help call assert_equal("help", &filetype) -- cgit From b69c5817619c8922039e75e9aaaed06ae35ee002 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 3 Dec 2022 19:09:19 +0800 Subject: vim-patch:8.2.3992: wrong local-additions in the help with language mix Problem: Wrong local-additions in the help with language mix. Solution: Adjust how the local additions list is generated. (Hirohito Higashi, closes vim/vim#9464) https://github.com/vim/vim/commit/0e2508d9e63e63414de2c06b3c8a446fdfe4470b Co-authored-by: h-east --- src/nvim/testdir/test_help.vim | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_help.vim b/src/nvim/testdir/test_help.vim index 2ba30ce57f..b370a1e13e 100644 --- a/src/nvim/testdir/test_help.vim +++ b/src/nvim/testdir/test_help.vim @@ -96,16 +96,42 @@ func Test_help_local_additions() call writefile(['*mydoc-ext.txt* my extended awesome doc'], 'Xruntime/doc/mydoc-ext.txt') let rtp_save = &rtp set rtp+=./Xruntime - help - 1 - call search('mydoc.txt') - call assert_equal('|mydoc.txt| my awesome doc', getline('.')) - 1 - call search('mydoc-ext.txt') - call assert_equal('|mydoc-ext.txt| my extended awesome doc', getline('.')) + help local-additions + let lines = getline(line(".") + 1, search("^$") - 1) + call assert_equal([ + \ '|mydoc-ext.txt| my extended awesome doc', + \ '|mydoc.txt| my awesome doc' + \ ], lines) + call delete('Xruntime/doc/mydoc-ext.txt') + close + + call mkdir('Xruntime-ja/doc', 'p') + call writefile(["local-additions\thelp.jax\t/*local-additions*"], 'Xruntime-ja/doc/tags-ja') + call writefile(['*help.txt* This is jax file', '', + \ 'LOCAL ADDITIONS: *local-additions*', ''], 'Xruntime-ja/doc/help.jax') + call writefile(['*work.txt* This is jax file'], 'Xruntime-ja/doc/work.jax') + call writefile(['*work2.txt* This is jax file'], 'Xruntime-ja/doc/work2.jax') + set rtp+=./Xruntime-ja + + help local-additions@en + let lines = getline(line(".") + 1, search("^$") - 1) + call assert_equal([ + \ '|mydoc.txt| my awesome doc' + \ ], lines) + close + + help local-additions@ja + let lines = getline(line(".") + 1, search("^$") - 1) + call assert_equal([ + \ '|mydoc.txt| my awesome doc', + \ '|help.txt| This is jax file', + \ '|work.txt| This is jax file', + \ '|work2.txt| This is jax file', + \ ], lines) close call delete('Xruntime', 'rf') + call delete('Xruntime-ja', 'rf') let &rtp = rtp_save endfunc -- cgit From f6caa35e6576dc97a70a31e1919a320d67f169ca Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 3 Dec 2022 20:15:52 +0800 Subject: vim-patch:8.2.4261: accessing invalid memory in a regular expression Problem: Accessing invalid memory when a regular expression checks the Visual area while matching in a string. Solution: Do not try matching the Visual area in a string. https://github.com/vim/vim/commit/679d66c2d21dfe03d0f89b9a818b0aaebb4c3b87 Use CheckScriptFailure() instead of v9.CheckScriptFailure(). Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_help.vim | 11 +++++++++++ src/nvim/testdir/vim9.vim | 26 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_help.vim b/src/nvim/testdir/test_help.vim index b370a1e13e..6cebc49b61 100644 --- a/src/nvim/testdir/test_help.vim +++ b/src/nvim/testdir/test_help.vim @@ -1,6 +1,7 @@ " Tests for :help source check.vim +source vim9.vim func SetUp() let s:vimruntime = $VIMRUNTIME @@ -207,5 +208,15 @@ func Test_help_long_argument() endtry endfunc +func Test_help_using_visual_match() + let lines =<< trim END + call setline(1, ' ') + /^ + exe "normal \\" + h5\%V€] + END + call CheckScriptFailure(lines, 'E149:') +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/vim9.vim b/src/nvim/testdir/vim9.vim index db74ce3b11..d598683d81 100644 --- a/src/nvim/testdir/vim9.vim +++ b/src/nvim/testdir/vim9.vim @@ -2,6 +2,32 @@ " Use a different file name for each run. let s:sequence = 1 +func CheckScriptFailure(lines, error, lnum = -3) + let cwd = getcwd() + let fname = 'XScriptFailure' .. s:sequence + let s:sequence += 1 + call writefile(a:lines, fname) + try + call assert_fails('so ' .. fname, a:error, a:lines, a:lnum) + finally + call chdir(cwd) + call delete(fname) + endtry +endfunc + +func CheckScriptSuccess(lines) + let cwd = getcwd() + let fname = 'XScriptSuccess' .. s:sequence + let s:sequence += 1 + call writefile(a:lines, fname) + try + exe 'so ' .. fname + finally + call chdir(cwd) + call delete(fname) + endtry +endfunc + " Check that "lines" inside a legacy function has no error. func CheckLegacySuccess(lines) let cwd = getcwd() -- cgit From 3838ee63d0af8021b506b8d1c3bb9a4ce961fb8c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 3 Dec 2022 20:27:09 +0800 Subject: test(old): skip Vim9 script with less divergence --- src/nvim/testdir/test_functions.vim | 5 ++++- src/nvim/testdir/test_ins_complete.vim | 6 +++--- src/nvim/testdir/test_normal.vim | 2 +- src/nvim/testdir/test_tagfunc.vim | 2 +- src/nvim/testdir/vim9.vim | 6 ++++++ 5 files changed, 15 insertions(+), 6 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 1308beeae5..f3594d3cdc 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -2,6 +2,9 @@ source shared.vim source check.vim +source term_util.vim +source screendump.vim +source vim9.vim " Must be done first, since the alternate buffer must be unset. func Test_00_bufexists() @@ -2518,7 +2521,7 @@ func Test_builtin_check() vim9script var s:trim = (x) => " " .. x END - " call CheckScriptFailure(lines, 'E704:') + call CheckScriptFailure(lines, 'E704:') call assert_fails('call extend(g:, #{foo: { -> "foo" }})', 'E704:') let g:bar = 123 diff --git a/src/nvim/testdir/test_ins_complete.vim b/src/nvim/testdir/test_ins_complete.vim index 1811c82767..c1c78e9a8f 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -1535,7 +1535,7 @@ func Test_completefunc_callback() assert_equal([[1, ''], [0, 'three']], g:LocalCompleteFuncArgs) bw! END - " call CheckScriptSuccess(lines) + call CheckScriptSuccess(lines) " cleanup set completefunc& @@ -1792,7 +1792,7 @@ func Test_omnifunc_callback() assert_equal([[1, ''], [0, 'three']], g:LocalOmniFuncArgs) bw! END - " call CheckScriptSuccess(lines) + call CheckScriptSuccess(lines) " cleanup set omnifunc& @@ -2085,7 +2085,7 @@ func Test_thesaurusfunc_callback() assert_equal([[1, ''], [0, 'three']], g:LocalTsrFuncArgs) bw! END - " call CheckScriptSuccess(lines) + call CheckScriptSuccess(lines) " cleanup set thesaurusfunc& diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index 7e8b8c5eef..c2ad49f0c9 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -695,7 +695,7 @@ func Test_opfunc_callback() assert_equal(['char'], g:LocalOpFuncArgs) bw! END - " call CheckScriptSuccess(lines) + call CheckScriptSuccess(lines) " setting 'opfunc' to a script local function outside of a script context " should fail diff --git a/src/nvim/testdir/test_tagfunc.vim b/src/nvim/testdir/test_tagfunc.vim index 93b9c67b25..cba96d3504 100644 --- a/src/nvim/testdir/test_tagfunc.vim +++ b/src/nvim/testdir/test_tagfunc.vim @@ -380,7 +380,7 @@ func Test_tagfunc_callback() assert_equal(['a12', '', {}], g:LocalTagFuncArgs) bw! END - " call CheckScriptSuccess(lines) + call CheckScriptSuccess(lines) " cleanup delfunc TagFunc1 diff --git a/src/nvim/testdir/vim9.vim b/src/nvim/testdir/vim9.vim index d598683d81..3c0ff2b2dd 100644 --- a/src/nvim/testdir/vim9.vim +++ b/src/nvim/testdir/vim9.vim @@ -3,6 +3,9 @@ let s:sequence = 1 func CheckScriptFailure(lines, error, lnum = -3) + if get(a:lines, 0, '') ==# 'vim9script' + return + endif let cwd = getcwd() let fname = 'XScriptFailure' .. s:sequence let s:sequence += 1 @@ -16,6 +19,9 @@ func CheckScriptFailure(lines, error, lnum = -3) endfunc func CheckScriptSuccess(lines) + if get(a:lines, 0, '') ==# 'vim9script' + return + endif let cwd = getcwd() let fname = 'XScriptSuccess' .. s:sequence let s:sequence += 1 -- cgit From bf4bf7f9e034ca2262e53e347ecb87054aa688d7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 3 Dec 2022 20:46:01 +0800 Subject: vim-patch:9.0.0110: help tag generation picks up words in code examples Problem: Help tag generation picks up words in code examples. Solution: Skip over examples. (Carlo Teubner, closes vim/vim#10813) https://github.com/vim/vim/commit/ddab3ce3457aadffb16ce0127f67a99966a065a8 Also fix mistakes in help files. Co-authored-by: Carlo Teubner --- src/nvim/testdir/test_help.vim | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_help.vim b/src/nvim/testdir/test_help.vim index 6cebc49b61..08dd3dcb9a 100644 --- a/src/nvim/testdir/test_help.vim +++ b/src/nvim/testdir/test_help.vim @@ -156,6 +156,13 @@ func Test_helptag_cmd() call assert_equal(["help-tags\ttags\t1"], readfile('Xdir/tags')) call delete('Xdir/tags') + " Test parsing tags + call writefile(['*tag1*', 'Example: >', ' *notag*', 'Example end: *tag2*'], + \ 'Xdir/a/doc/sample.txt') + helptags Xdir + call assert_equal(["tag1\ta/doc/sample.txt\t/*tag1*", + \ "tag2\ta/doc/sample.txt\t/*tag2*"], readfile('Xdir/tags')) + " Duplicate tags in the help file call writefile(['*tag1*', '*tag1*', '*tag2*'], 'Xdir/a/doc/sample.txt') call assert_fails('helptags Xdir', 'E154:') -- cgit From 0cb90114d4c4801457e286c9b72ad0f394877d05 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 3 Dec 2022 20:53:43 +0800 Subject: vim-patch:9.0.0577: buffer underflow with unexpected :finally Problem: Buffer underflow with unexpected :finally. Solution: Check CSF_TRY can be found. https://github.com/vim/vim/commit/96b9bf8f74af8abf1e30054f996708db7dc285be Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_trycatch.vim | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_trycatch.vim b/src/nvim/testdir/test_trycatch.vim index 8a1d2d3fa7..ef20e03126 100644 --- a/src/nvim/testdir/test_trycatch.vim +++ b/src/nvim/testdir/test_trycatch.vim @@ -3,6 +3,7 @@ source check.vim source shared.vim +source vim9.vim "------------------------------------------------------------------------------- " Test environment {{{1 @@ -2007,6 +2008,27 @@ func Test_try_catch_errors() call assert_fails('try | for i in range(5) | endif | endtry', 'E580:') call assert_fails('try | while v:true | endtry', 'E170:') call assert_fails('try | if v:true | endtry', 'E171:') + + " this was using a negative index in cstack[] + let lines =<< trim END + try + for + if + endwhile + if + finally + END + call CheckScriptFailure(lines, 'E690:') + + let lines =<< trim END + try + for + if + endwhile + if + endtry + END + call CheckScriptFailure(lines, 'E690:') endfunc " Test for verbose messages with :try :catch, and :finally {{{1 -- cgit From 46e4be0fd0002233bde613295607ce5eeb498567 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 4 Dec 2022 09:09:00 +0800 Subject: vim-patch:8.2.2295: incsearch does not detect empty pattern properly Problem: Incsearch does not detect empty pattern properly. Solution: Return magic state when skipping over a pattern. (Christian Brabandt, closes vim/vim#7612, closes vim/vim#6420) https://github.com/vim/vim/commit/d93a7fc1a98a58f8101ee780d4735079ad99ae35 --- src/nvim/testdir/test_search.vim | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index 0702e89ebb..8bb7d8687f 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -1969,6 +1969,35 @@ func Test_incsearch_highlighting_newline() bw endfunc +func Test_incsearch_substitute_dump2() + CheckOption incsearch + CheckScreendump + + call writefile([ + \ 'set incsearch hlsearch scrolloff=0', + \ 'for n in range(1, 4)', + \ ' call setline(n, "foo " . n)', + \ 'endfor', + \ 'call setline(5, "abc|def")', + \ '3', + \ ], 'Xis_subst_script2') + let buf = RunVimInTerminal('-S Xis_subst_script2', {'rows': 9, 'cols': 70}) + + call term_sendkeys(buf, ':%s/\vabc|') + sleep 100m + call VerifyScreenDump(buf, 'Test_incsearch_sub_01', {}) + call term_sendkeys(buf, "\") + + " The following should not be highlighted + call term_sendkeys(buf, ':1,5s/\v|') + sleep 100m + call VerifyScreenDump(buf, 'Test_incsearch_sub_02', {}) + + + call StopVimInTerminal(buf) + call delete('Xis_subst_script2') +endfunc + func Test_no_last_search_pattern() CheckOption incsearch -- cgit From 3f1ee12d311fffe30936217c74ef0352bb7d97d9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 4 Dec 2022 09:43:38 +0800 Subject: vim-patch:8.2.3265: smartcase does not work correctly in very magic pattern Problem: Smartcase does not work correctly in very magic pattern. Solution: Take the magicness into account when skipping over regexp items. (Christian Brabandt, closes vim/vim#8682, closes vim/vim#7845) https://github.com/vim/vim/commit/78ba933d18439ff1a02f6be4c571e73ddceb3cd4 Co-authored-by: Christian Brabandt --- src/nvim/testdir/test_search.vim | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index 8bb7d8687f..51e7064c94 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -1998,6 +1998,60 @@ func Test_incsearch_substitute_dump2() call delete('Xis_subst_script2') endfunc +func Test_pattern_is_uppercase_smartcase() + new + let input=['abc', 'ABC', 'Abc', 'abC'] + call setline(1, input) + call cursor(1,1) + " default, matches firstline + %s/abc//g + call assert_equal(['', 'ABC', 'Abc', 'abC'], + \ getline(1, '$')) + + set smartcase ignorecase + sil %d + call setline(1, input) + call cursor(1,1) + " with smartcase and incsearch set, matches everything + %s/abc//g + call assert_equal(['', '', '', ''], getline(1, '$')) + + sil %d + call setline(1, input) + call cursor(1,1) + " with smartcase and incsearch set and found an uppercase letter, + " match only that. + %s/abC//g + call assert_equal(['abc', 'ABC', 'Abc', ''], + \ getline(1, '$')) + + sil %d + call setline(1, input) + call cursor(1,1) + exe "norm! vG$\" + " \%V should not be detected as uppercase letter + %s/\%Vabc//g + call assert_equal(['', '', '', ''], getline(1, '$')) + + call setline(1, input) + call cursor(1,1) + exe "norm! vG$\" + " \v%V should not be detected as uppercase letter + %s/\v%Vabc//g + call assert_equal(['', '', '', ''], getline(1, '$')) + + call setline(1, input) + call cursor(1,1) + exe "norm! vG$\" + " \v%VabC should be detected as uppercase letter + %s/\v%VabC//g + call assert_equal(['abc', 'ABC', 'Abc', ''], + \ getline(1, '$')) + + set smartcase& ignorecase& + bw! +endfunc + func Test_no_last_search_pattern() CheckOption incsearch -- cgit From 9476dd2f923d9e5d86237836131f67024613308f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 4 Dec 2022 09:46:26 +0800 Subject: vim-patch:8.2.3292: underscore in very magic pattern causes a hang Problem: Underscore in very magic pattern causes a hang. Pattern with \V are case sensitive. (Yutao Yuan) Solution: Adjust condition for magicness and advance pointer. (Christian Brabandt, closes vim/vim#8707, closes vim/vim#8704, closes vim/vim#8705) https://github.com/vim/vim/commit/bc67e5a0a494f5fc48e872d747371e31a782d171 Co-authored-by: Christian Brabandt --- src/nvim/testdir/test_search.vim | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index 51e7064c94..a9cad3ed44 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -2048,6 +2048,17 @@ func Test_pattern_is_uppercase_smartcase() call assert_equal(['abc', 'ABC', 'Abc', ''], \ getline(1, '$')) + call setline(1, input) + call cursor(1,1) + " \Vabc should match everything + %s/\Vabc//g + call assert_equal(['', '', '', ''], getline(1, '$')) + + call setline(1, input + ['_abc']) + " _ matches normally + %s/\v_.*//g + call assert_equal(['abc', 'ABC', 'Abc', 'abC', ''], getline(1, '$')) + set smartcase& ignorecase& bw! endfunc -- cgit From d93b9062549662bfb9262967ac546291ccbc73be Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 4 Dec 2022 16:29:36 +0800 Subject: vim-patch:8.2.4168: disallowing empty function name breaks existing plugins Problem: Disallowing empty function name breaks existing plugins. Solution: Allow empty function name in legacy script. https://github.com/vim/vim/commit/e6a4200ff47708febcd7cb2b8c3dd3801a975d43 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/sautest/autoload/foo.vim | 4 ++++ src/nvim/testdir/test_autoload.vim | 6 ++++++ 2 files changed, 10 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/sautest/autoload/foo.vim b/src/nvim/testdir/sautest/autoload/foo.vim index 298e7275d8..21d33a0f4d 100644 --- a/src/nvim/testdir/sautest/autoload/foo.vim +++ b/src/nvim/testdir/sautest/autoload/foo.vim @@ -9,3 +9,7 @@ endfunc func foo#addFoo(head) return a:head .. 'foo' endfunc + +func foo#() + return 'empty' +endfunc diff --git a/src/nvim/testdir/test_autoload.vim b/src/nvim/testdir/test_autoload.vim index b8c4fa251f..e89fe3943b 100644 --- a/src/nvim/testdir/test_autoload.vim +++ b/src/nvim/testdir/test_autoload.vim @@ -10,6 +10,9 @@ func Test_autoload_dict_func() call assert_equal(1, g:called_foo_bar_echo) eval 'bar'->g:foo#addFoo()->assert_equal('barfoo') + + " empty name works in legacy script + call assert_equal('empty', foo#()) endfunc func Test_source_autoload() @@ -17,3 +20,6 @@ func Test_source_autoload() source sautest/autoload/sourced.vim call assert_equal(1, g:loaded_sourced_vim) endfunc + + +" vim: shiftwidth=2 sts=2 expandtab -- cgit From 9263f17d0d741f52e9fafae9779ddaa4e3441fcc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 4 Dec 2022 17:44:51 +0800 Subject: vim-patch:9.0.0259: crash with mouse click when not initialized (#21282) Problem: Crash with mouse click when not initialized. Solution: Check TabPageIdxs[] is not NULL. https://github.com/vim/vim/commit/80525751c5ce9ed82c41d83faf9ef38667bf61b1 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_tabline.vim | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_tabline.vim b/src/nvim/testdir/test_tabline.vim index e58a412c5a..556b85931c 100644 --- a/src/nvim/testdir/test_tabline.vim +++ b/src/nvim/testdir/test_tabline.vim @@ -147,4 +147,18 @@ func Test_tabline_20_format_items_no_overrun() set showtabline& tabline& endfunc +func Test_mouse_click_in_tab() + " This used to crash because TabPageIdxs[] was not initialized + let lines =<< trim END + tabnew + set mouse=a + exe "norm \" + END + call writefile(lines, 'Xclickscript') + call RunVim([], [], "-e -s -S Xclickscript -c qa") + + call delete('Xclickscript') +endfunc + + " vim: shiftwidth=2 sts=2 expandtab -- cgit From b866d8d2e7cf4c2f00b1adc997188f1d04c13fa1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 4 Dec 2022 18:33:04 +0800 Subject: vim-patch:9.0.0610: global interrupt test fails when run under valgrind (#21285) Problem: Global interrupt test fails when run under valgrind. Solution: Use TermWait(). https://github.com/vim/vim/commit/859ea4bc76699232e41aea0f308463bab887b0c1 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_global.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_global.vim b/src/nvim/testdir/test_global.vim index bbfe374f51..8fb4ee0cfa 100644 --- a/src/nvim/testdir/test_global.vim +++ b/src/nvim/testdir/test_global.vim @@ -91,6 +91,7 @@ endfunc " Test for interrupting :global using Ctrl-C func Test_interrupt_global() CheckRunVimInTerminal + let lines =<< trim END cnoremap ; sleep 10 call setline(1, repeat(['foo'], 5)) @@ -100,14 +101,14 @@ func Test_interrupt_global() call term_sendkeys(buf, ":g/foo/norm :\;\") " Wait for :sleep to start - call term_wait(buf) + call TermWait(buf, 100) call term_sendkeys(buf, "\") call WaitForAssert({-> assert_match('Interrupted', term_getline(buf, 6))}, 1000) " Also test in Ex mode call term_sendkeys(buf, "gQg/foo/norm :\;\") " Wait for :sleep to start - call term_wait(buf) + call TermWait(buf, 100) call term_sendkeys(buf, "\") call WaitForAssert({-> assert_match('Interrupted', term_getline(buf, 5))}, 1000) -- cgit From 5d691a4669dd90a0e29dae699ccd845aca3ef667 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 5 Dec 2022 09:49:23 +0800 Subject: vim-patch:8.2.1195: clientserver test fails on MS-Windows Problem: Clientserver test fails on MS-Windows. Solution: Expect a different error message. https://github.com/vim/vim/commit/4d57ba02029071e5947a54766e9f5d42e3bb3008 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_clientserver.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_clientserver.vim b/src/nvim/testdir/test_clientserver.vim index 19a92dce3c..fdecda1800 100644 --- a/src/nvim/testdir/test_clientserver.vim +++ b/src/nvim/testdir/test_clientserver.vim @@ -184,8 +184,10 @@ func Test_client_server() call assert_fails('call remote_startserver([])', 'E730:') call assert_fails("let x = remote_peek([])", 'E730:') - call assert_fails("let x = remote_read('vim10')", ['E573:.*vim10']) - call assert_fails("call server2client('abc', 'xyz')", ['E573:.*abc']) + call assert_fails("let x = remote_read('vim10')", + \ [has('unix') ? 'E573:.*vim10' : 'E277:.*vim10']) + call assert_fails("call server2client('abc', 'xyz')", + \ [has('unix') ? 'E573:.*abc' : 'E258:.*abc']) endfunc " Uncomment this line to get a debugging log -- cgit From ee944ef10387f70bdf0baae10dfdcbe7e19ab035 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 5 Dec 2022 09:49:38 +0800 Subject: vim-patch:8.2.1197: clientserver test still fails on MS-Windows Problem: Clientserver test still fails on MS-Windows. Solution: Expect a different error message. https://github.com/vim/vim/commit/c212dd0a346d57f62013094ea6861eb28e33023c Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_clientserver.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_clientserver.vim b/src/nvim/testdir/test_clientserver.vim index fdecda1800..5a88c7fed1 100644 --- a/src/nvim/testdir/test_clientserver.vim +++ b/src/nvim/testdir/test_clientserver.vim @@ -185,9 +185,9 @@ func Test_client_server() call assert_fails('call remote_startserver([])', 'E730:') call assert_fails("let x = remote_peek([])", 'E730:') call assert_fails("let x = remote_read('vim10')", - \ [has('unix') ? 'E573:.*vim10' : 'E277:.*vim10']) + \ has('unix') ? ['E573:.*vim10'] : 'E277:') call assert_fails("call server2client('abc', 'xyz')", - \ [has('unix') ? 'E573:.*abc' : 'E258:.*abc']) + \ has('unix') ? ['E573:.*abc'] : 'E258:') endfunc " Uncomment this line to get a debugging log -- cgit From 060789e3350a99a41c503d76766ddfaac0c5e93a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 5 Dec 2022 09:50:11 +0800 Subject: vim-patch:8.2.2240: clientserver test fails if full path is used Problem: Clientserver test fails if full path is used. Solution: Ignore the path preceding the file name. https://github.com/vim/vim/commit/41a834d1e3dbf9c8759737bcd6524159a9b93d2a Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_clientserver.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_clientserver.vim b/src/nvim/testdir/test_clientserver.vim index 5a88c7fed1..d135e3a194 100644 --- a/src/nvim/testdir/test_clientserver.vim +++ b/src/nvim/testdir/test_clientserver.vim @@ -142,19 +142,19 @@ func Test_client_server() " Edit multiple files using --remote call system(cmd .. ' --remote Xfile1 Xfile2 Xfile3') - call assert_equal("Xfile1\nXfile2\nXfile3\n", remote_expr(name, 'argv()')) + call assert_match(".*Xfile1\n.*Xfile2\n.*Xfile3\n", remote_expr(name, 'argv()')) eval name->remote_send(":%bw!\") " Edit files in separate tab pages call system(cmd .. ' --remote-tab Xfile1 Xfile2 Xfile3') call WaitForAssert({-> assert_equal('3', remote_expr(name, 'tabpagenr("$")'))}) - call assert_equal('Xfile2', remote_expr(name, 'bufname(tabpagebuflist(2)[0])')) + call assert_match('.*\remote_send(":%bw!\") " Edit a file using --remote-wait eval name->remote_send(":source $VIMRUNTIME/plugin/rrhelper.vim\") call system(cmd .. ' --remote-wait +enew Xfile1') - call assert_equal("Xfile1", remote_expr(name, 'bufname("#")')) + call assert_match('.*\remote_send(":%bw!\") " Edit files using --remote-tab-wait -- cgit From adcf7a221984d61fc472c12875930783bef4e97a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 5 Dec 2022 09:50:27 +0800 Subject: vim-patch:8.2.3108: test for remote_foreground() fails Problem: Test for remote_foreground() fails. (Elimar Riesebieter) Solution: Check that $DISPLAY is set. (Christian Brabandt) https://github.com/vim/vim/commit/d6fa7bd5b900dd363d3a824e0ebe3619a1634df6 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/check.vim | 8 ++++++++ src/nvim/testdir/test_clientserver.vim | 4 +--- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/check.vim b/src/nvim/testdir/check.vim index 61d3a99a67..0fba0e107b 100644 --- a/src/nvim/testdir/check.vim +++ b/src/nvim/testdir/check.vim @@ -123,6 +123,14 @@ func CheckCanRunGui() endif endfunc +" Command to Check for an environment variable +command -nargs=1 CheckEnv call CheckEnv() +func CheckEnv(name) + if empty('$' .. a:name) + throw 'Skipped: Environment variable ' .. a:name .. ' is not set' + endif +endfunc + " Command to check that we are using the GUI command CheckGui call CheckGui() func CheckGui() diff --git a/src/nvim/testdir/test_clientserver.vim b/src/nvim/testdir/test_clientserver.vim index d135e3a194..c54996a545 100644 --- a/src/nvim/testdir/test_clientserver.vim +++ b/src/nvim/testdir/test_clientserver.vim @@ -13,9 +13,7 @@ source shared.vim func Check_X11_Connection() if has('x11') - if empty($DISPLAY) - throw 'Skipped: $DISPLAY is not set' - endif + CheckEnv DISPLAY try call remote_send('xxx', '') catch -- cgit From e9ad613fdfd91c7d4b090e404976f9ea8667fae0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 5 Dec 2022 09:51:01 +0800 Subject: vim-patch:8.2.3109: check for $DISPLAY never fails Problem: Check for $DISPLAY never fails. Solution: Use eval(). https://github.com/vim/vim/commit/f6d877975ba93fc9b4bee2c5d2aff88dbf9bea59 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/check.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/check.vim b/src/nvim/testdir/check.vim index 0fba0e107b..a7ecf455bc 100644 --- a/src/nvim/testdir/check.vim +++ b/src/nvim/testdir/check.vim @@ -126,7 +126,7 @@ endfunc " Command to Check for an environment variable command -nargs=1 CheckEnv call CheckEnv() func CheckEnv(name) - if empty('$' .. a:name) + if empty(eval('$' .. a:name)) throw 'Skipped: Environment variable ' .. a:name .. ' is not set' endif endfunc -- cgit From 78fa1f069ddfdc65d2452056d051678d1242e034 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 5 Dec 2022 09:52:34 +0800 Subject: vim-patch:8.2.3495: GUI geometry startup test fails on some systems Problem: GUI geometry startup test fails on some systems. (Drew Vogel) Solution: Add tolerance to the size check. (closes vim/vim#8815) https://github.com/vim/vim/commit/b376aa2da4211fee7eaf16450bb8b37674e45bb0 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_startup.vim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim index 42467c5508..96a5c96da1 100644 --- a/src/nvim/testdir/test_startup.vim +++ b/src/nvim/testdir/test_startup.vim @@ -522,7 +522,14 @@ func Test_geometry() [CODE] if RunVim([], after, '-f -g -geometry 31x13+41+43') let lines = readfile('Xtest_geometry') - call assert_equal(['31', '13', '41', '43', '[41, 43]'], lines) + " Depending on the GUI library and the windowing system the final size + " might be a bit different, allow for some tolerance. Tuned based on + " actual failures. + call assert_inrange(31, 35, lines[0]) + call assert_equal(13, lines[1]) + call assert_equal(41, lines[2]) + call assert_equal(43, lines[3]) + call assert_equal([41, 43], lines[4]) endif endif -- cgit From e043dbf0aaaed75c00196fc6ccd094bb3b61da65 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 5 Dec 2022 09:52:46 +0800 Subject: vim-patch:8.2.3499: GUI geometry startup test fails Problem: GUI geometry startup test fails. Solution: Check string values instead of numbers https://github.com/vim/vim/commit/3d031a0ae791f901c0c2dedd5d8b9de137c23acc Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_startup.vim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim index 96a5c96da1..7db033cb65 100644 --- a/src/nvim/testdir/test_startup.vim +++ b/src/nvim/testdir/test_startup.vim @@ -525,11 +525,11 @@ func Test_geometry() " Depending on the GUI library and the windowing system the final size " might be a bit different, allow for some tolerance. Tuned based on " actual failures. - call assert_inrange(31, 35, lines[0]) - call assert_equal(13, lines[1]) - call assert_equal(41, lines[2]) - call assert_equal(43, lines[3]) - call assert_equal([41, 43], lines[4]) + call assert_inrange(31, 35, str2nr(lines[0])) + call assert_equal('13', lines[1]) + call assert_equal('41', lines[2]) + call assert_equal('43', lines[3]) + call assert_equal('[41, 43]', lines[4]) endif endif -- cgit From ba9fcc22ef02c70ffea367bc9fbf22c0dca7c103 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 5 Dec 2022 09:51:39 +0800 Subject: vim-patch:8.2.3526: tests have clumsy check for X11 based GUI Problem: Tests have clumsy check for X11 based GUI. Solution: Add CheckX11BasedGui. https://github.com/vim/vim/commit/40bd5a15405206b130d487af0ca61b5d9b5859f8 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/check.vim | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/check.vim b/src/nvim/testdir/check.vim index a7ecf455bc..d200633115 100644 --- a/src/nvim/testdir/check.vim +++ b/src/nvim/testdir/check.vim @@ -171,6 +171,14 @@ func CheckNotAsan() endif endfunc +" Command to check for X11 based GUI +command CheckX11BasedGui call CheckX11BasedGui() +func CheckX11BasedGui() + if !g:x11_based_gui + throw 'Skipped: requires X11 based GUI' + endif +endfunc + " Command to check for satisfying any of the conditions. " e.g. CheckAnyOf Feature:bsd Feature:sun Linux command -nargs=+ CheckAnyOf call CheckAnyOf() -- cgit From 9ae6b03e7aaf635da5d39c1bd7ff6829cc232acb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 5 Dec 2022 09:53:31 +0800 Subject: vim-patch:8.2.5145: exit test causes spurious valgrind reports Problem: Exit test causes spurious valgrind reports. Solution: Skip test. Add CheckNotValgrind. https://github.com/vim/vim/commit/cf801d4b95180ddaee1bf633ef482232625dd80b Cherry-pick RunningWithValgrind() from patch 8.2.5136. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/check.vim | 8 ++++++++ src/nvim/testdir/shared.vim | 6 ++++++ src/nvim/testdir/test_exit.vim | 1 + 3 files changed, 15 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/check.vim b/src/nvim/testdir/check.vim index d200633115..a188f7afa1 100644 --- a/src/nvim/testdir/check.vim +++ b/src/nvim/testdir/check.vim @@ -171,6 +171,14 @@ func CheckNotAsan() endif endfunc +" Command to check for not running under valgrind +command CheckNotValgrind call CheckNotValgrind() +func CheckNotValgrind() + if RunningWithValgrind() + throw 'Skipped: does not work well with valgrind' + endif +endfunc + " Command to check for X11 based GUI command CheckX11BasedGui call CheckX11BasedGui() func CheckX11BasedGui() diff --git a/src/nvim/testdir/shared.vim b/src/nvim/testdir/shared.vim index ef7cc4ac5f..953118f650 100644 --- a/src/nvim/testdir/shared.vim +++ b/src/nvim/testdir/shared.vim @@ -285,6 +285,12 @@ func GetVimCommand(...) return cmd endfunc +" Return one when it looks like the tests are run with valgrind, which means +" that everything is much slower. +func RunningWithValgrind() + return GetVimCommand() =~ '\' +endfunc + " Get the command to run Vim, with --clean instead of "-u NONE". func GetVimCommandClean() let cmd = GetVimCommand() diff --git a/src/nvim/testdir/test_exit.vim b/src/nvim/testdir/test_exit.vim index 37be293950..6dbfb7047c 100644 --- a/src/nvim/testdir/test_exit.vim +++ b/src/nvim/testdir/test_exit.vim @@ -117,6 +117,7 @@ func Test_exit_error_reading_input() CheckNotMSWindows " The early exit causes memory not to be freed somehow CheckNotAsan + CheckNotValgrind call writefile([":au VimLeave * call writefile(['l = ' .. v:exiting], 'Xtestout')", ":tabnew", "q:"], 'Xscript', 'b') -- cgit From 89374da798ff29e651c47ed4159aa89e3395af9f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 5 Dec 2022 10:47:05 +0800 Subject: vim-patch:8.2.2328: some test files may not be deleted (#21194) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Some test files may not be deleted. Solution: Add a delete() call, correct name. (Dominique Pellé, closes vim/vim#7654) https://github.com/vim/vim/commit/48e11c10548782f573411b6302f77adb69c40401 --- src/nvim/testdir/test_clientserver.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_clientserver.vim b/src/nvim/testdir/test_clientserver.vim index c54996a545..d8b29f6c42 100644 --- a/src/nvim/testdir/test_clientserver.vim +++ b/src/nvim/testdir/test_clientserver.vim @@ -87,6 +87,7 @@ func Test_client_server() call writefile(['one', 'two'], 'Xclientfile') call system(cmd) call WaitForAssert({-> assert_equal('two', remote_expr(name, "getline(2)", "", 2))}) + call delete('Xclientfile') " Expression evaluated locally. if v:servername == '' -- cgit From 0ff9131a925dfc94cf0ce787578ee6e3c5e673d7 Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Mon, 5 Dec 2022 15:54:32 -0700 Subject: vim-patch:9.0.1014: zir files are not recognized (#21301) Problem: Zir files are not recognized. Solution: Add a pattern for Zir files. (closes vim/vim#11664) https://github.com/vim/vim/commit/25201016d5043954689a4c9f7833935294149404 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_filetype.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 5ffddb7925..88f0c74d37 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -653,6 +653,7 @@ let s:filename_checks = { \ 'zig': ['file.zig'], \ 'zimbu': ['file.zu'], \ 'zimbutempl': ['file.zut'], + \ 'zir': ['file.zir'], \ 'zsh': ['.zprofile', '/etc/zprofile', '.zfbfmarks', 'file.zsh', '.zcompdump', '.zlogin', '.zlogout', '.zshenv', '.zshrc', '.zcompdump-file', '.zlog', '.zlog-file', '.zsh', '.zsh-file', 'any/etc/zprofile', 'zlog', 'zlog-file', 'zsh', 'zsh-file'], \ \ 'help': [$VIMRUNTIME . '/doc/help.txt'], -- cgit From 11d2704274ff817678e29f115ba1f074a52e519c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 6 Dec 2022 06:51:17 +0800 Subject: vim-patch:8.2.3193: screenpos() is wrong when 'display' is "lastline" Problem: screenpos() is wrong when the last line is partially visible and 'display' is "lastline". Solution: Also compute the position for a partially visible line. (closes vim/vim#8599) https://github.com/vim/vim/commit/189663bdac1156237c49925f77bd197c1bdea12c Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_cursor_func.vim | 40 ++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cursor_func.vim b/src/nvim/testdir/test_cursor_func.vim index 7f9e74e94b..0a88bf9db3 100644 --- a/src/nvim/testdir/test_cursor_func.vim +++ b/src/nvim/testdir/test_cursor_func.vim @@ -82,25 +82,41 @@ func Test_screenpos() let winid = win_getid() let [winrow, wincol] = win_screenpos(winid) call assert_equal({'row': winrow, - \ 'col': wincol + 0, - \ 'curscol': wincol + 7, - \ 'endcol': wincol + 7}, winid->screenpos(1, 1)) + \ 'col': wincol + 0, + \ 'curscol': wincol + 7, + \ 'endcol': wincol + 7}, winid->screenpos(1, 1)) call assert_equal({'row': winrow, - \ 'col': wincol + 13, - \ 'curscol': wincol + 13, - \ 'endcol': wincol + 13}, winid->screenpos(1, 7)) + \ 'col': wincol + 13, + \ 'curscol': wincol + 13, + \ 'endcol': wincol + 13}, winid->screenpos(1, 7)) call assert_equal({'row': winrow + 2, - \ 'col': wincol + 1, - \ 'curscol': wincol + 1, - \ 'endcol': wincol + 1}, screenpos(winid, 2, 22)) + \ 'col': wincol + 1, + \ 'curscol': wincol + 1, + \ 'endcol': wincol + 1}, screenpos(winid, 2, 22)) setlocal number call assert_equal({'row': winrow + 3, - \ 'col': wincol + 9, - \ 'curscol': wincol + 9, - \ 'endcol': wincol + 9}, screenpos(winid, 2, 22)) + \ 'col': wincol + 9, + \ 'curscol': wincol + 9, + \ 'endcol': wincol + 9}, screenpos(winid, 2, 22)) + + let wininfo = getwininfo(winid)[0] + call setline(3, ['x']->repeat(wininfo.height)) + call setline(line('$') + 1, 'x'->repeat(wininfo.width * 3)) + setlocal nonumber display=lastline so=0 + exe "normal G\\" + redraw + call assert_equal({'row': winrow + wininfo.height - 1, + \ 'col': wincol + 7, + \ 'curscol': wincol + 7, + \ 'endcol': wincol + 7}, winid->screenpos(line('$'), 8)) + call assert_equal({'row': winrow - 1, 'col': 0, 'curscol': 0, 'endcol': 0}, + \ winid->screenpos(line('$'), 22)) + close call assert_equal({}, screenpos(999, 1, 1)) + bwipe! + set display& call assert_equal({'col': 1, 'row': 1, 'endcol': 1, 'curscol': 1}, screenpos(win_getid(), 1, 1)) " nmenu WinBar.TEST : -- cgit From 6f9cda0f0a9d2e38654e4a0afc4701a356efb862 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 6 Dec 2022 07:26:41 +0800 Subject: vim-patch:8.2.4204: screenpos() has non-zero row for invisible text Problem: screenpos() has non-zero row for invisible text. Solution: Only add the window row when the text is visible. (closes vim/vim#9618) https://github.com/vim/vim/commit/7924a17791217d50be5a91989a9641bf68e7a735 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_cursor_func.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cursor_func.vim b/src/nvim/testdir/test_cursor_func.vim index 0a88bf9db3..b08eb328b7 100644 --- a/src/nvim/testdir/test_cursor_func.vim +++ b/src/nvim/testdir/test_cursor_func.vim @@ -109,7 +109,7 @@ func Test_screenpos() \ 'col': wincol + 7, \ 'curscol': wincol + 7, \ 'endcol': wincol + 7}, winid->screenpos(line('$'), 8)) - call assert_equal({'row': winrow - 1, 'col': 0, 'curscol': 0, 'endcol': 0}, + call assert_equal({'row': 0, 'col': 0, 'curscol': 0, 'endcol': 0}, \ winid->screenpos(line('$'), 22)) close -- cgit From 10af0549df7ac4ea9907b34624228755b9752318 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 6 Dec 2022 07:41:33 +0800 Subject: vim-patch:8.2.4389: screenpos() does not handle a position in a closed fold Problem: screenpos() does not handle a position in a closed fold. Solution: Check if the position is inside a closed fold. (closes vim/vim#9778) https://github.com/vim/vim/commit/4556a2e8681c5c98fb4c7ca0a016924a69b4452a Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_cursor_func.vim | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cursor_func.vim b/src/nvim/testdir/test_cursor_func.vim index b08eb328b7..ad78adfc09 100644 --- a/src/nvim/testdir/test_cursor_func.vim +++ b/src/nvim/testdir/test_cursor_func.vim @@ -1,7 +1,10 @@ " Tests for cursor() and other functions that get/set the cursor position +source check.vim + func Test_wrong_arguments() call assert_fails('call cursor(1. 3)', 'E474:') + call assert_fails('call cursor(v:_null_list)', 'E474:') endfunc func Test_move_cursor() @@ -118,14 +121,29 @@ func Test_screenpos() bwipe! set display& - call assert_equal({'col': 1, 'row': 1, 'endcol': 1, 'curscol': 1}, screenpos(win_getid(), 1, 1)) + call assert_equal(#{col: 1, row: 1, endcol: 1, curscol: 1}, screenpos(win_getid(), 1, 1)) " nmenu WinBar.TEST : setlocal winbar=TEST - call assert_equal({'col': 1, 'row': 2, 'endcol': 1, 'curscol': 1}, screenpos(win_getid(), 1, 1)) + call assert_equal(#{col: 1, row: 2, endcol: 1, curscol: 1}, screenpos(win_getid(), 1, 1)) " nunmenu WinBar.TEST setlocal winbar& endfunc +func Test_screenpos_fold() + CheckFeature folding + + enew! + call setline(1, range(10)) + 3,5fold + redraw + call assert_equal(2, screenpos(1, 2, 1).row) + call assert_equal(#{col: 1, row: 3, endcol: 1, curscol: 1}, screenpos(1, 3, 1)) + call assert_equal(3, screenpos(1, 4, 1).row) + call assert_equal(3, screenpos(1, 5, 1).row) + call assert_equal(4, screenpos(1, 6, 1).row) + bwipe! +endfunc + func Test_screenpos_number() rightbelow new rightbelow 73vsplit -- cgit From 0909d987fe925483dc513ae330179339899cd0a5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 6 Dec 2022 07:52:00 +0800 Subject: vim-patch:9.0.1011: ml_get error when using screenpos() Problem: ml_get error when using screenpos(). Solution: Give an error for the line number. (closes vim/vim#11661) https://github.com/vim/vim/commit/99d19438cabaf13074229d9a32e3a4af9ce98744 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_cursor_func.vim | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cursor_func.vim b/src/nvim/testdir/test_cursor_func.vim index ad78adfc09..634b27b0ed 100644 --- a/src/nvim/testdir/test_cursor_func.vim +++ b/src/nvim/testdir/test_cursor_func.vim @@ -155,6 +155,9 @@ func Test_screenpos_number() let pos = screenpos(winid, 1, 66) call assert_equal(winrow, pos.row) call assert_equal(wincol + 66 + 3, pos.col) + + call assert_fails('echo screenpos(0, 2, 1)', 'E966:') + close bwipe! endfunc -- cgit From 52b3e8bdef6896b53d3c4ee3fbc7d8ae5f480948 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 6 Dec 2022 08:00:30 +0800 Subject: vim-patch:9.0.1016: screenpos() does not count filler lines for diff mode Problem: screenpos() does not count filler lines for diff mode. Solution: Add filler lines. (closes 11658) https://github.com/vim/vim/commit/1cb16c3a20a9d17df1a8dc3813ef64dc98e42637 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_cursor_func.vim | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cursor_func.vim b/src/nvim/testdir/test_cursor_func.vim index 634b27b0ed..2151076cb9 100644 --- a/src/nvim/testdir/test_cursor_func.vim +++ b/src/nvim/testdir/test_cursor_func.vim @@ -144,6 +144,22 @@ func Test_screenpos_fold() bwipe! endfunc +func Test_screenpos_diff() + CheckFeature diff + + enew! + call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']) + vnew + call setline(1, ['a', 'b', 'c', 'g', 'h', 'i']) + windo diffthis + wincmd w + call assert_equal(#{col: 3, row: 7, endcol: 3, curscol: 3}, screenpos(0, 4, 1)) + + windo diffoff + bwipe! + bwipe! +endfunc + func Test_screenpos_number() rightbelow new rightbelow 73vsplit -- cgit From 5199c333a072933d6a2bb8b9e99076761da7396a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 6 Dec 2022 09:15:04 +0800 Subject: vim-patch:9.0.1015: without /dev/urandom srand() seed is too predictable (#21303) Problem: Without /dev/urandom srand() seed is too predictable. Solution: Use micro seconds and XOR with process ID. (Yasuhiro Matsumoto, closes vim/vim#11656) https://github.com/vim/vim/commit/f0a9c004825ab686270ee57260652cce25e61049 Co-authored-by: Yasuhiro Matsumoto --- src/nvim/testdir/test_random.vim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_random.vim b/src/nvim/testdir/test_random.vim index fb1c9ab6cd..d91815703c 100644 --- a/src/nvim/testdir/test_random.vim +++ b/src/nvim/testdir/test_random.vim @@ -1,5 +1,8 @@ " Tests for srand() and rand() +source check.vim +source shared.vim + func Test_Rand() let r = srand(123456789) call assert_equal([1573771921, 319883699, 2742014374, 1324369493], r) @@ -48,4 +51,20 @@ func Test_issue_5587() call rand() endfunc +func Test_srand() + CheckNotGui + + let cmd = GetVimCommand() .. ' -V -es -c "echo rand()" -c qa!' + let bad = 0 + for _ in range(10) + echo cmd + let result1 = system(cmd) + let result2 = system(cmd) + if result1 ==# result2 + let bad += 1 + endif + endfor + call assert_inrange(0, 4, bad) +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 9628348a6a547db17f3867f48ae43ff71bbf6324 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 6 Dec 2022 17:41:57 +0800 Subject: vim-patch:9.0.1017: test for srand() fails on MS-Windows (#21308) Problem: Test for srand() fails on MS-Windows. Solution: Do not expect the same result a second time. https://github.com/vim/vim/commit/9dacdb1d56ee0f9272f3fc956a12f15f84ffb205 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_random.vim | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_random.vim b/src/nvim/testdir/test_random.vim index d91815703c..5fdbfe9cd8 100644 --- a/src/nvim/testdir/test_random.vim +++ b/src/nvim/testdir/test_random.vim @@ -12,18 +12,9 @@ func Test_Rand() call assert_equal(2658065534, rand(r)) call assert_equal(3104308804, rand(r)) - " Nvim does not support test_settime - " call test_settime(12341234) let s = srand() - if !has('win32') && filereadable('/dev/urandom') - " using /dev/urandom - call assert_notequal(s, srand()) - " else - " " using time() - " call assert_equal(s, srand()) - " call test_settime(12341235) - " call assert_notequal(s, srand()) - endif + " using /dev/urandom or used time, result is different each time + call assert_notequal(s, srand()) " Nvim does not support test_srand_seed " call test_srand_seed(123456789) @@ -41,8 +32,6 @@ func Test_Rand() call assert_fails('echo rand([1, [2], 3, 4])', 'E730:') call assert_fails('echo rand([1, 2, [3], 4])', 'E730:') call assert_fails('echo rand([1, 2, 3, [4]])', 'E730:') - - " call test_settime(0) endfunc func Test_issue_5587() -- cgit From f92aab5f704f6e94e80f2fcbab42acc272a66a29 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 7 Dec 2022 18:34:39 +0800 Subject: vim-patch:9.0.1025: WinScrolled is not triggered when filler lines change (#21325) Problem: WinScrolled is not triggered when filler lines change. Solution: Add "topfill" to the values that WinScrolled triggers on. (closes vim/vim#11668) https://github.com/vim/vim/commit/3fc84dc2c7efecd7c14ce341cd777475058936fd Cherry-pick StopVimInTerminal() from patch 9.0.1010. --- src/nvim/testdir/test_autocmd.vim | 78 +++++++++++++++++++++++++++++++++++---- 1 file changed, 70 insertions(+), 8 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 199721b15e..704ff6ec55 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -382,8 +382,8 @@ func Test_WinScrolled() let event = readfile('XscrollEvent')[0]->json_decode() call assert_equal({ - \ 'all': {'leftcol': 1, 'topline': 0, 'width': 0, 'height': 0, 'skipcol': 0}, - \ '1000': {'leftcol': -1, 'topline': 0, 'width': 0, 'height': 0, 'skipcol': 0} + \ 'all': {'leftcol': 1, 'topline': 0, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}, + \ '1000': {'leftcol': -1, 'topline': 0, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0} \ }, event) " Scroll up/down in Normal mode. @@ -392,8 +392,8 @@ func Test_WinScrolled() let event = readfile('XscrollEvent')[0]->json_decode() call assert_equal({ - \ 'all': {'leftcol': 0, 'topline': 1, 'width': 0, 'height': 0, 'skipcol': 0}, - \ '1000': {'leftcol': 0, 'topline': -1, 'width': 0, 'height': 0, 'skipcol': 0} + \ 'all': {'leftcol': 0, 'topline': 1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}, + \ '1000': {'leftcol': 0, 'topline': -1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0} \ }, event) " Scroll up/down in Insert mode. @@ -403,8 +403,8 @@ func Test_WinScrolled() let event = readfile('XscrollEvent')[0]->json_decode() call assert_equal({ - \ 'all': {'leftcol': 0, 'topline': 1, 'width': 0, 'height': 0, 'skipcol': 0}, - \ '1000': {'leftcol': 0, 'topline': -1, 'width': 0, 'height': 0, 'skipcol': 0} + \ 'all': {'leftcol': 0, 'topline': 1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}, + \ '1000': {'leftcol': 0, 'topline': -1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0} \ }, event) " Scroll the window horizontally to focus the last letter of the third line @@ -416,8 +416,8 @@ func Test_WinScrolled() let event = readfile('XscrollEvent')[0]->json_decode() call assert_equal({ - \ 'all': {'leftcol': 5, 'topline': 0, 'width': 0, 'height': 0, 'skipcol': 0}, - \ '1000': {'leftcol': -5, 'topline': 0, 'width': 0, 'height': 0, 'skipcol': 0} + \ 'all': {'leftcol': 5, 'topline': 0, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}, + \ '1000': {'leftcol': -5, 'topline': 0, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0} \ }, event) " Ensure the command was triggered for the specified window ID. @@ -567,6 +567,68 @@ func Test_WinScrolled_long_wrapped() call term_sendkeys(buf, '$') call term_sendkeys(buf, ":echo g:scrolled\") call WaitForAssert({-> assert_match('^3 ', term_getline(buf, 6))}, 1000) + + call StopVimInTerminal(buf) +endfunc + +func Test_WinScrolled_diff() + CheckRunVimInTerminal + + let lines =<< trim END + set diffopt+=foldcolumn:0 + call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']) + vnew + call setline(1, ['d', 'e', 'f', 'g', 'h', 'i']) + windo diffthis + func WriteScrollEvent() + call writefile([json_encode(v:event)], 'XscrollEvent') + endfunc + au WinScrolled * call WriteScrollEvent() + END + call writefile(lines, 'Xtest_winscrolled_diff', 'D') + let buf = RunVimInTerminal('-S Xtest_winscrolled_diff', {'rows': 8}) + + call term_sendkeys(buf, "\") + call WaitForAssert({-> assert_match('^d', term_getline(buf, 3))}, 1000) + + let event = readfile('XscrollEvent')[0]->json_decode() + call assert_equal({ + \ 'all': {'leftcol': 0, 'topline': 1, 'topfill': 1, 'width': 0, 'height': 0, 'skipcol': 0}, + \ '1000': {'leftcol': 0, 'topline': 1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}, + \ '1001': {'leftcol': 0, 'topline': 0, 'topfill': -1, 'width': 0, 'height': 0, 'skipcol': 0} + \ }, event) + + call term_sendkeys(buf, "2\") + call WaitForAssert({-> assert_match('^f', term_getline(buf, 3))}, 1000) + + let event = readfile('XscrollEvent')[0]->json_decode() + call assert_equal({ + \ 'all': {'leftcol': 0, 'topline': 2, 'topfill': 2, 'width': 0, 'height': 0, 'skipcol': 0}, + \ '1000': {'leftcol': 0, 'topline': 2, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}, + \ '1001': {'leftcol': 0, 'topline': 0, 'topfill': -2, 'width': 0, 'height': 0, 'skipcol': 0} + \ }, event) + + call term_sendkeys(buf, "\") + call WaitForAssert({-> assert_match('^g', term_getline(buf, 3))}, 1000) + + let event = readfile('XscrollEvent')[0]->json_decode() + call assert_equal({ + \ 'all': {'leftcol': 0, 'topline': 2, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}, + \ '1000': {'leftcol': 0, 'topline': 1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}, + \ '1001': {'leftcol': 0, 'topline': 1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0} + \ }, event) + + call term_sendkeys(buf, "2\") + call WaitForAssert({-> assert_match('^e', term_getline(buf, 3))}, 1000) + + let event = readfile('XscrollEvent')[0]->json_decode() + call assert_equal({ + \ 'all': {'leftcol': 0, 'topline': 3, 'topfill': 1, 'width': 0, 'height': 0, 'skipcol': 0}, + \ '1000': {'leftcol': 0, 'topline': -2, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}, + \ '1001': {'leftcol': 0, 'topline': -1, 'topfill': 1, 'width': 0, 'height': 0, 'skipcol': 0} + \ }, event) + + call StopVimInTerminal(buf) endfunc func Test_WinClosed() -- cgit From 4f64aef29f24b5ac305b609d0abf78d93e2c5e0d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 8 Dec 2022 18:58:06 +0800 Subject: vim-patch:8.2.3564: invalid memory access when scrolling without valid screen (#21335) vim-patch:8.2.3564: invalid memory access when scrolling without valid screen Problem: Invalid memory access when scrolling without a valid screen. Solution: Do not set VALID_BOTLINE in w_valid. https://github.com/vim/vim/commit/777e7c21b7627be80961848ac560cb0a9978ff43 Remove -Z flag when using RunVim(). Co-authored-by: Bram Moolenaar --- src/nvim/testdir/shared.vim | 5 +++-- src/nvim/testdir/test_normal.vim | 22 +++++++++++++++++++--- src/nvim/testdir/test_quickfix.vim | 2 +- 3 files changed, 23 insertions(+), 6 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/shared.vim b/src/nvim/testdir/shared.vim index 953118f650..aba995e788 100644 --- a/src/nvim/testdir/shared.vim +++ b/src/nvim/testdir/shared.vim @@ -323,7 +323,6 @@ func RunVim(before, after, arguments) endfunc func RunVimPiped(before, after, arguments, pipecmd) - let $NVIM_LOG_FILE = exists($NVIM_LOG_FILE) ? $NVIM_LOG_FILE : 'Xnvim.log' let cmd = GetVimCommand() let args = '' if len(a:before) > 0 @@ -338,7 +337,9 @@ func RunVimPiped(before, after, arguments, pipecmd) " Optionally run Vim under valgrind " let cmd = 'valgrind --tool=memcheck --leak-check=yes --num-callers=25 --log-file=valgrind ' . cmd - exe "silent !" . a:pipecmd . cmd . args . ' ' . a:arguments + let $NVIM_LOG_FILE = exists($NVIM_LOG_FILE) ? $NVIM_LOG_FILE : 'Xnvim.log' + " Nvim does not support -Z flag, remove it. + exe "silent !" . a:pipecmd . cmd . args . ' ' . substitute(a:arguments, '-Z', '', 'g') if len(a:before) > 0 call delete('Xbefore.vim') diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index c2ad49f0c9..7c90b444e5 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -36,14 +36,14 @@ func CountSpaces(type, ...) else silent exe "normal! `[v`]y" endif - let g:a=strlen(substitute(@@, '[^ ]', '', 'g')) + let g:a = strlen(substitute(@@, '[^ ]', '', 'g')) let &selection = sel_save let @@ = reg_save endfunc func OpfuncDummy(type, ...) " for testing operatorfunc - let g:opt=&linebreak + let g:opt = &linebreak if a:0 " Invoked from Visual mode, use gv command. silent exe "normal! gvy" @@ -54,7 +54,7 @@ func OpfuncDummy(type, ...) endif " Create a new dummy window new - let g:bufnr=bufnr('%') + let g:bufnr = bufnr('%') endfunc func Test_normal00_optrans() @@ -1286,6 +1286,22 @@ func Test_vert_scroll_cmds() close! endfunc +func Test_scroll_in_ex_mode() + " This was using invalid memory because w_botline was invalid. + let lines =<< trim END + diffsplit + norm os00( + call writefile(['done'], 'Xdone') + qa! + END + call writefile(lines, 'Xscript') + call assert_equal(1, RunVim([], [], '--clean -X -Z -e -s -S Xscript')) + call assert_equal(['done'], readfile('Xdone')) + + call delete('Xscript') + call delete('Xdone') +endfunc + " Test for the 'sidescroll' option func Test_sidescroll_opt() new diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 45b6e6b38c..e13ff77705 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -6088,7 +6088,7 @@ func Test_lopen_bwipe_all() qall! END call writefile(lines, 'Xscript') - if RunVim([], [], '--clean -n -S Xscript') + if RunVim([], [], '-u NONE -n -X -Z -e -m -s -S Xscript') call assert_equal(['done'], readfile('Xresult')) endif -- cgit From 7b9ad45178fc2f53c4824ad42213c340bdd66ebf Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 8 Dec 2022 22:52:25 +0800 Subject: vim-patch:8.2.1634: loop to handle keys for the command line is too long (#21340) Problem: Loop to handle keys for the command line is too long. Solution: Move a few more parts to separate functions. (Yegappan Lakshmanan, closes vim/vim#6895) https://github.com/vim/vim/commit/9c929713b7588f2e44a1533809d2ba0bbd2631be --- src/nvim/testdir/test_cmdline.vim | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index b9da4ca7bb..218a2143e8 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -1100,6 +1100,15 @@ func Test_cmdline_complete_various() " completion after a range followed by a pipe (|) character call feedkeys(":1,10 | chist\t\\"\", 'xt') call assert_equal('"1,10 | chistory', @:) + + " use as the 'wildchar' for completion + set wildchar= + call feedkeys(":g/a\\xb/clearj\\\"\", 'xt') + call assert_equal('"g/a\xb/clearjumps', @:) + " pressing twice should cancel the command + call feedkeys(":chist\\", 'xt') + call assert_equal('"g/a\xb/clearjumps', @:) + set wildchar& endfunc func Test_cmdline_write_alternatefile() -- cgit From 4d22424d9ecdb7c2485a1d7272e1b75e69386891 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 8 Dec 2022 20:11:39 +0800 Subject: vim-patch:9.0.1030: using freed memory with the cmdline popup menu Problem: Using freed memory with the cmdline popup menu. Solution: Clear the popup menu when clearing the matches. (closes vim/vim#11677) https://github.com/vim/vim/commit/038e6d20e680ce8c850d07f6b035c4e1904c1201 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_cmdline.vim | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 218a2143e8..bd5cd5dc7d 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -2281,6 +2281,21 @@ func Test_wildmenu_pum() call delete('Xdir', 'rf') endfunc +func Test_wildmenu_pum_clear_entries() + " This was using freed memory. Run in a terminal to get the pum to update. + let lines =<< trim END + set wildoptions=pum + set wildchar= + END + call writefile(lines, 'XwildmenuTest', 'D') + let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10}) + + call term_sendkeys(buf, ":\\") + call VerifyScreenDump(buf, 'Test_wildmenu_pum_clear_entries_1', {}) + + set wildoptions& wildchar& +endfunc + " this was going over the end of IObuff func Test_report_error_with_composing() let caught = 'no' -- cgit From 95c655fedcb2c3a6fd6250b0174d1b62f9a9c099 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 9 Dec 2022 02:16:18 +0800 Subject: vim-patch:9.0.1032: test fails when terminal feature is missing Problem: Test fails when terminal feature is missing. Solution: Use CheckRunVimInTerminal. https://github.com/vim/vim/commit/b9603f6498e5637e111bd1dca0eab88c8dd0f99b Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_cmdline.vim | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index bd5cd5dc7d..d09c9e2171 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -2282,6 +2282,8 @@ func Test_wildmenu_pum() endfunc func Test_wildmenu_pum_clear_entries() + CheckRunVimInTerminal + " This was using freed memory. Run in a terminal to get the pum to update. let lines =<< trim END set wildoptions=pum -- cgit From 70d6c335b17cf166760457e3673aa61098ef0e66 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 9 Dec 2022 06:35:29 +0800 Subject: vim-patch:9.0.1036: undo misbehaves when writing from an insert mode mapping Problem: Undo misbehaves when writing from an insert mode mapping. Solution: Sync undo when writing. (closes vim/vim#11674) https://github.com/vim/vim/commit/3f8f82772313af9f2417b06651f30988b63e1c96 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_undo.vim | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_undo.vim b/src/nvim/testdir/test_undo.vim index eb47af08d7..ee8b52caaf 100644 --- a/src/nvim/testdir/test_undo.vim +++ b/src/nvim/testdir/test_undo.vim @@ -3,6 +3,9 @@ " undo-able pieces. Do that by setting 'undolevels'. " Also tests :earlier and :later. +source check.vim +source screendump.vim + func Test_undotree() new @@ -773,4 +776,30 @@ func Test_undo_mark() bwipe! endfunc +func Test_undo_after_write() + " use a terminal to make undo work like when text is typed + CheckRunVimInTerminal + + let lines =<< trim END + edit Xtestfile.txt + set undolevels=100 undofile + imap . write + write + END + call writefile(lines, 'Xtest_undo_after_write', 'D') + let buf = RunVimInTerminal('-S Xtest_undo_after_write', #{rows: 6}) + + call term_sendkeys(buf, "Otest.\boo!!!\") + sleep 100m + call term_sendkeys(buf, "u") + call VerifyScreenDump(buf, 'Test_undo_after_write_1', {}) + + call term_sendkeys(buf, "u") + call VerifyScreenDump(buf, 'Test_undo_after_write_2', {}) + + call StopVimInTerminal(buf) + call delete('Xtestfile.txt') +endfunc + + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 8b3412636a1027eaa14a95211efb449b58e9a01e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 9 Dec 2022 07:51:37 +0800 Subject: test(old): change $TMPDIR from Xtest-tmpdir to X-test-tmpdir (#21346) I've noticed a patch 8.2.4376 that uses more Xtest directories. Change $TMPDIR to X-test-tmpdir to avoid more future divergence. --- src/nvim/testdir/Makefile | 2 +- src/nvim/testdir/shared.vim | 2 +- src/nvim/testdir/test_cmdline.vim | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 0684b3798e..9511b311e6 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -11,7 +11,7 @@ ROOT := ../../.. export SHELL := sh export NVIM_PRG := $(NVIM_PRG) -export TMPDIR := $(abspath Xtest-tmpdir) +export TMPDIR := $(abspath X-test-tmpdir) ifeq ($(OS),Windows_NT) FIXFF = fixff diff --git a/src/nvim/testdir/shared.vim b/src/nvim/testdir/shared.vim index aba995e788..33f6d9a2d0 100644 --- a/src/nvim/testdir/shared.vim +++ b/src/nvim/testdir/shared.vim @@ -9,7 +9,7 @@ source view_util.vim " {Nvim} " Filepath captured from output may be truncated, like this: -" /home/va...estdir/Xtest-tmpdir/nvimxbXN4i/10 +" /home/va...estdir/X-test-tmpdir/nvimxbXN4i/10 " Get last 2 segments, then combine with $TMPDIR. func! Fix_truncated_tmpfile(fname) " sanity check diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index d09c9e2171..9889e46a06 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -7,7 +7,7 @@ source shared.vim func Test_complete_tab() call writefile(['testfile'], 'Xtestfile') - call feedkeys(":e Xtestf\t\r", "tx") + call feedkeys(":e Xtest\t\r", "tx") call assert_equal('testfile', getline(1)) " Pressing after '%' completes the current file, also on MS-Windows -- cgit 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/testdir/test_cmdline.vim | 47 +++++++++++++++++++++++++++++++++- src/nvim/testdir/test_usercommands.vim | 11 ++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') 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/nvim/testdir') 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 From 0483ee825414ee02d0fc446c9bad4949b28e622f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 9 Dec 2022 09:45:45 +0800 Subject: vim-patch:8.2.4387: command line completion doesn't always work properly (#21352) Problem: Command line completion doesn't always work properly. Solution: Adjust triggering after a "|". Add more tests. (Yegappan Lakshmanan, closes vim/vim#9779) https://github.com/vim/vim/commit/e3846cf1ebdc4af0b39885153b4703f71a9b919e Co-authored-by: Yegappan Lakshmanan --- src/nvim/testdir/test_cmdline.vim | 135 +++++++++++++++++++++++++++++++------- 1 file changed, 110 insertions(+), 25 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index ebb3d4f0b3..c79aba810e 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -293,9 +293,6 @@ func Test_cmdheight_tabline() endfunc func Test_map_completion() - if !has('cmdline_compl') - return - endif call feedkeys(":map \\"\", 'xt') call assert_equal('"map ', getreg(':')) call feedkeys(":map