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