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_normal.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir/test_normal.vim') 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! -- 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/test_normal.vim | 111 +++++++++++++++++++++++++++------------ 1 file changed, 76 insertions(+), 35 deletions(-) (limited to 'src/nvim/testdir/test_normal.vim') 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() -- 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_normal.vim | 79 ---------------------------------------- 1 file changed, 79 deletions(-) (limited to 'src/nvim/testdir/test_normal.vim') 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_normal.vim | 9 --------- 1 file changed, 9 deletions(-) (limited to 'src/nvim/testdir/test_normal.vim') 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 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_normal.vim | 68 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'src/nvim/testdir/test_normal.vim') 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_normal.vim | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/nvim/testdir/test_normal.vim') 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() -- 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_normal.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir/test_normal.vim') 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 -- 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_normal.vim | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/testdir/test_normal.vim') 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 -- 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_normal.vim | 240 ++++++++++++++++++++++++++++----------- 1 file changed, 176 insertions(+), 64 deletions(-) (limited to 'src/nvim/testdir/test_normal.vim') 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 -- 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_normal.vim | 249 +++++++++++++++++++-------------------- 1 file changed, 120 insertions(+), 129 deletions(-) (limited to 'src/nvim/testdir/test_normal.vim') 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) -- 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_normal.vim | 132 +++++++++++++++++++++------------------ 1 file changed, 71 insertions(+), 61 deletions(-) (limited to 'src/nvim/testdir/test_normal.vim') 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 -- 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/test_normal.vim') 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 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_normal.vim | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'src/nvim/testdir/test_normal.vim') 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 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_normal.vim | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir/test_normal.vim') 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) -- 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_normal.vim | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/nvim/testdir/test_normal.vim') 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 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_normal.vim | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/nvim/testdir/test_normal.vim') 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 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_normal.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/testdir/test_normal.vim') 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 -- 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/test_normal.vim | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/nvim/testdir/test_normal.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 -- cgit