To: vim_dev@googlegroups.com Subject: Patch 8.2.3792 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3792 Problem: Setting *func options insufficiently tested. Solution: Impove tests. (Yegappan Lakshmanan, closes #9337) Files: src/testdir/test_iminsert.vim, src/testdir/test_ins_complete.vim, src/testdir/test_normal.vim, src/testdir/test_quickfix.vim, src/testdir/test_tagfunc.vim *** ../vim-8.2.3791/src/testdir/test_iminsert.vim 2021-12-12 16:26:35.868627601 +0000 --- src/testdir/test_iminsert.vim 2021-12-12 20:06:43.188489742 +0000 *************** *** 125,130 **** --- 125,135 ---- LET g:IMactivatefunc_called = 0 LET g:IMstatusfunc_called = 0 + #" Test for using a function name + LET &imactivatefunc = 'g:IMactivatefunc1' + LET &imstatusfunc = 'g:IMstatusfunc1' + normal! i + #" Test for using a function() set imactivatefunc=function('g:IMactivatefunc1') set imstatusfunc=function('g:IMstatusfunc1') *************** *** 215,222 **** call assert_fails("LET &imstatusfunc = function('NonExistingFunc')", 'E700:') normal! i ! call assert_equal(13, g:IMactivatefunc_called) ! call assert_equal(26, g:IMstatusfunc_called) END call CheckLegacyAndVim9Success(lines) --- 220,227 ---- call assert_fails("LET &imstatusfunc = function('NonExistingFunc')", 'E700:') normal! i ! call assert_equal(14, g:IMactivatefunc_called) ! call assert_equal(28, g:IMstatusfunc_called) END call CheckLegacyAndVim9Success(lines) *************** *** 283,294 **** call CheckScriptSuccess(lines) " cleanup delfunc IMactivatefunc1 delfunc IMstatusfunc1 ! set iminsert=0 ! set imactivatefunc= ! set imstatusfunc= ! %bw! endfunc --- 288,299 ---- call CheckScriptSuccess(lines) " cleanup + set iminsert=0 + set imactivatefunc& + set imstatusfunc& delfunc IMactivatefunc1 delfunc IMstatusfunc1 ! unlet g:IMactivatefunc_called g:IMstatusfunc_called %bw! endfunc *** ../vim-8.2.3791/src/testdir/test_ins_complete.vim 2021-12-12 16:26:35.872627594 +0000 --- src/testdir/test_ins_complete.vim 2021-12-12 20:06:43.192489733 +0000 *************** *** 870,992 **** " 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]) return a:findstart ? 0 : [] endfunc 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' ! 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('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('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('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('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 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 = 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 = '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 ! 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 = 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 = LSTART a, b LMIDDLE strlen(a) LEND LET &completefunc = Lambda ! new | only call setline(1, 'eight') call feedkeys("A\\\", 'x') bw! --- 870,1005 ---- " Test for different ways of setting the 'completefunc' option func Test_completefunc_callback() ! 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:CompleteFunc1',\ [10]) ! new call setline(1, 'one') ! LET g:CompleteFunc1Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[10, 1, ''], [10, 0, 'one']], g:CompleteFunc1Args) bw! #" Using a funcref variable to set 'completefunc' ! VAR Fn = function('g:CompleteFunc1', [11]) LET &completefunc = Fn ! new call setline(1, 'two') ! LET g:CompleteFunc1Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[11, 1, ''], [11, 0, 'two']], g:CompleteFunc1Args) bw! #" Using string(funcref_variable) to set 'completefunc' ! LET Fn = function('g:CompleteFunc1', [12]) LET &completefunc = string(Fn) ! new call setline(1, 'two') ! LET g:CompleteFunc1Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[12, 1, ''], [12, 0, 'two']], g:CompleteFunc1Args) bw! #" Test for using a funcref() ! set completefunc=funcref('g:CompleteFunc1',\ [13]) ! new call setline(1, 'three') ! LET g:CompleteFunc1Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[13, 1, ''], [13, 0, 'three']], g:CompleteFunc1Args) bw! #" Using a funcref variable to set 'completefunc' ! LET Fn = funcref('g:CompleteFunc1', [14]) LET &completefunc = Fn ! new call setline(1, 'four') ! LET g:CompleteFunc1Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[14, 1, ''], [14, 0, 'four']], g:CompleteFunc1Args) bw! #" Using a string(funcref_variable) to set 'completefunc' ! LET Fn = funcref('g:CompleteFunc1', [15]) LET &completefunc = string(Fn) ! new call setline(1, 'four') ! LET g:CompleteFunc1Args = [] call feedkeys("A\\\", 'x') ! 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 CompleteFunc1(16, a, b) LEND" LET optval = substitute(optval, ' ', '\\ ', 'g') exe "set completefunc=" .. optval ! new call setline(1, 'five') ! LET g:CompleteFunc1Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[16, 1, ''], [16, 0, 'five']], g:CompleteFunc1Args) bw! #" Set 'completefunc' to a lambda expression ! LET &completefunc = LSTART a, b LMIDDLE CompleteFunc1(17, a, b) LEND ! new call setline(1, 'six') ! LET g:CompleteFunc1Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[17, 1, ''], [17, 0, 'six']], g:CompleteFunc1Args) bw! #" Set 'completefunc' to string(lambda_expression) ! LET &completefunc = 'LSTART a, b LMIDDLE CompleteFunc1(18, a, b) LEND' ! new call setline(1, 'six') ! LET g:CompleteFunc1Args = [] call feedkeys("A\\\", 'x') ! 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 CompleteFunc1(19, a, b) LEND LET &completefunc = Lambda ! new call setline(1, 'seven') ! LET g:CompleteFunc1Args = [] call feedkeys("A\\\", 'x') ! 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 CompleteFunc1(20, a, b) LEND LET &completefunc = string(Lambda) ! new call setline(1, 'seven') ! LET g:CompleteFunc1Args = [] call feedkeys("A\\\", 'x') ! 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 call setline(1, 'eight') call feedkeys("A\\\", 'x') bw! *************** *** 998,1014 **** 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) --- 1011,1023 ---- call assert_fails("set completefunc=funcref('abc')", "E700:") #" set 'completefunc' to a non-existing function ! 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:CompleteFunc2Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[1, ''], [0, 'five']], g:CompleteFunc2Args) bw! END call CheckLegacyAndVim9Success(lines) *************** *** 1017,1027 **** call feedkeys("A\\\", 'x') " Using Vim9 lambda expression in legacy context should fail ! 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 partial with dict. This used to cause a crash. func SetCompleteFunc() --- 1026,1036 ---- call feedkeys("A\\\", 'x') " Using Vim9 lambda expression in legacy context should fail ! set completefunc=(a,\ b)\ =>\ CompleteFunc1(21,\ a,\ b) new | only ! let g:CompleteFunc1Args = [] call assert_fails('call feedkeys("A\\\", "x")', 'E117:') ! call assert_equal([], g:CompleteFunc1Args) " set 'completefunc' to a partial with dict. This used to cause a crash. func SetCompleteFunc() *************** *** 1063,1193 **** call CheckScriptSuccess(lines) " cleanup - delfunc MycompleteFunc1 - delfunc MycompleteFunc2 set completefunc& %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]) return a:findstart ? 0 : [] endfunc 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' ! 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('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('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! #" 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) 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 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 = 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 = '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 ! 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 = 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 = LSTART a, b LMIDDLE strlen(a) LEND LET &omnifunc = Lambda ! new | only call setline(1, 'eight') call feedkeys("A\\\", 'x') bw! --- 1072,1216 ---- call CheckScriptSuccess(lines) " cleanup 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 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:OmniFunc1',\ [10]) ! new call setline(1, 'one') ! LET g:OmniFunc1Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[10, 1, ''], [10, 0, 'one']], g:OmniFunc1Args) bw! #" Using a funcref variable to set 'omnifunc' ! VAR Fn = function('g:OmniFunc1', [11]) LET &omnifunc = Fn ! new call setline(1, 'two') ! LET g:OmniFunc1Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[11, 1, ''], [11, 0, 'two']], g:OmniFunc1Args) bw! #" Using a string(funcref_variable) to set 'omnifunc' ! LET Fn = function('g:OmniFunc1', [12]) LET &omnifunc = string(Fn) ! new call setline(1, 'two') ! LET g:OmniFunc1Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[12, 1, ''], [12, 0, 'two']], g:OmniFunc1Args) bw! #" Test for using a funcref() ! set omnifunc=funcref('g:OmniFunc1',\ [13]) ! new call setline(1, 'three') ! LET g:OmniFunc1Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[13, 1, ''], [13, 0, 'three']], g:OmniFunc1Args) bw! #" Use let to set 'omnifunc' to a funcref ! LET Fn = funcref('g:OmniFunc1', [14]) LET &omnifunc = Fn ! new call setline(1, 'four') ! LET g:OmniFunc1Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[14, 1, ''], [14, 0, 'four']], g:OmniFunc1Args) bw! #" Using a string(funcref) to set 'omnifunc' ! LET Fn = funcref("g:OmniFunc1", [15]) LET &omnifunc = string(Fn) ! new call setline(1, 'four') ! LET g:OmniFunc1Args = [] call feedkeys("A\\\", 'x') ! 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 OmniFunc1(16, a, b) LEND" LET optval = substitute(optval, ' ', '\\ ', 'g') exe "set omnifunc=" .. optval ! new call setline(1, 'five') ! LET g:OmniFunc1Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[16, 1, ''], [16, 0, 'five']], g:OmniFunc1Args) bw! #" Set 'omnifunc' to a lambda expression ! LET &omnifunc = LSTART a, b LMIDDLE OmniFunc1(17, a, b) LEND ! new call setline(1, 'six') ! LET g:OmniFunc1Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[17, 1, ''], [17, 0, 'six']], g:OmniFunc1Args) bw! #" Set 'omnifunc' to a string(lambda_expression) ! LET &omnifunc = 'LSTART a, b LMIDDLE OmniFunc1(18, a, b) LEND' ! new call setline(1, 'six') ! LET g:OmniFunc1Args = [] call feedkeys("A\\\", 'x') ! 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 OmniFunc1(19, a, b) LEND LET &omnifunc = Lambda ! new call setline(1, 'seven') ! LET g:OmniFunc1Args = [] call feedkeys("A\\\", 'x') ! 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 OmniFunc1(20, a, b) LEND LET &omnifunc = string(Lambda) ! new call setline(1, 'seven') ! LET g:OmniFunc1Args = [] call feedkeys("A\\\", 'x') ! 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 call setline(1, 'eight') call feedkeys("A\\\", 'x') bw! *************** *** 1199,1215 **** 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) --- 1222,1234 ---- call assert_fails("set omnifunc=funcref('abc')", "E700:") #" set 'omnifunc' to a non-existing function ! 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:OmniFunc2Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[1, ''], [0, 'nine']], g:OmniFunc2Args) bw! END call CheckLegacyAndVim9Success(lines) *************** *** 1218,1228 **** call feedkeys("A\\\", 'x') " Using Vim9 lambda expression in legacy context should fail ! 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 partial with dict. This used to cause a crash. func SetOmniFunc() --- 1237,1247 ---- call feedkeys("A\\\", 'x') " Using Vim9 lambda expression in legacy context should fail ! set omnifunc=(a,\ b)\ =>\ OmniFunc1(21,\ a,\ b) new | only ! let g:OmniFunc1Args = [] call assert_fails('call feedkeys("A\\\", "x")', 'E117:') ! call assert_equal([], g:OmniFunc1Args) " set 'omnifunc' to a partial with dict. This used to cause a crash. func SetOmniFunc() *************** *** 1264,1394 **** call CheckScriptSuccess(lines) " cleanup - delfunc MyomniFunc1 - delfunc MyomniFunc2 set omnifunc& %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]) return a:findstart ? 0 : [] endfunc 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' ! 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('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('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('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('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 ! 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! #" 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 = '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 ! 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 = 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 = LSTART a, b LMIDDLE strlen(a) LEND LET &thesaurusfunc = Lambda ! new | only call setline(1, 'eight') call feedkeys("A\\\", 'x') bw! --- 1283,1427 ---- call CheckScriptSuccess(lines) " cleanup 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 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:TsrFunc1',\ [10]) ! new call setline(1, 'one') ! LET g:TsrFunc1Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[10, 1, ''], [10, 0, 'one']], g:TsrFunc1Args) bw! #" Using a funcref variable to set 'thesaurusfunc' ! VAR Fn = function('g:TsrFunc1', [11]) LET &thesaurusfunc = Fn ! new call setline(1, 'two') ! LET g:TsrFunc1Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[11, 1, ''], [11, 0, 'two']], g:TsrFunc1Args) bw! #" Using a string(funcref_variable) to set 'thesaurusfunc' ! LET Fn = function('g:TsrFunc1', [12]) LET &thesaurusfunc = string(Fn) ! new call setline(1, 'two') ! LET g:TsrFunc1Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[12, 1, ''], [12, 0, 'two']], g:TsrFunc1Args) bw! #" Test for using a funcref() ! set thesaurusfunc=funcref('g:TsrFunc1',\ [13]) ! new call setline(1, 'three') ! LET g:TsrFunc1Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[13, 1, ''], [13, 0, 'three']], g:TsrFunc1Args) bw! #" Using a funcref variable to set 'thesaurusfunc' ! LET Fn = funcref('g:TsrFunc1', [14]) LET &thesaurusfunc = Fn ! new call setline(1, 'four') ! LET g:TsrFunc1Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[14, 1, ''], [14, 0, 'four']], g:TsrFunc1Args) bw! #" Using a string(funcref_variable) to set 'thesaurusfunc' ! LET Fn = funcref('g:TsrFunc1', [15]) LET &thesaurusfunc = string(Fn) ! new call setline(1, 'four') ! LET g:TsrFunc1Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[15, 1, ''], [15, 0, 'four']], g:TsrFunc1Args) bw! #" Test for using a lambda function ! VAR optval = "LSTART a, b LMIDDLE TsrFunc1(16, a, b) LEND" LET optval = substitute(optval, ' ', '\\ ', 'g') exe "set thesaurusfunc=" .. optval ! new call setline(1, 'five') ! LET g:TsrFunc1Args = [] call feedkeys("A\\\", 'x') ! 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 TsrFunc1(17, a, b) LEND ! new call setline(1, 'six') ! LET g:TsrFunc1Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[17, 1, ''], [17, 0, 'six']], g:TsrFunc1Args) bw! #" Set 'thesaurusfunc' to a string(lambda expression) ! LET &thesaurusfunc = 'LSTART a, b LMIDDLE TsrFunc1(18, a, b) LEND' ! new call setline(1, 'six') ! LET g:TsrFunc1Args = [] call feedkeys("A\\\", 'x') ! 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 TsrFunc1(19, a, b) LEND LET &thesaurusfunc = Lambda ! new call setline(1, 'seven') ! LET g:TsrFunc1Args = [] call feedkeys("A\\\", 'x') ! 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 TsrFunc1(20, a, b) LEND LET &thesaurusfunc = string(Lambda) ! new call setline(1, 'seven') ! LET g:TsrFunc1Args = [] call feedkeys("A\\\", 'x') ! 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 call setline(1, 'eight') call feedkeys("A\\\", 'x') bw! *************** *** 1400,1439 **** 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) --- 1433,1468 ---- call assert_fails("set thesaurusfunc=funcref('abc')", "E700:") #" set 'thesaurusfunc' to a non-existing function ! 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:TsrFunc2Args = [] call feedkeys("A\\\", 'x') ! call assert_equal([[1, ''], [0, 'ten']], g:TsrFunc2Args) bw! #" Use a buffer-local value and a global value set thesaurusfunc& ! setlocal thesaurusfunc=function('g:TsrFunc1',\ [22]) call setline(1, 'sun') ! LET g:TsrFunc1Args = [] call feedkeys("A\\\", "x") call assert_equal('sun', getline(1)) ! call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:TsrFunc1Args) new call setline(1, 'sun') ! LET g:TsrFunc1Args = [] call feedkeys("A\\\", "x") call assert_equal('sun', getline(1)) ! call assert_equal([], g:TsrFunc1Args) ! set thesaurusfunc=function('g:TsrFunc1',\ [23]) wincmd w call setline(1, 'sun') ! LET g:TsrFunc1Args = [] call feedkeys("A\\\", "x") call assert_equal('sun', getline(1)) ! call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:TsrFunc1Args) :%bw! END call CheckLegacyAndVim9Success(lines) *************** *** 1442,1452 **** call feedkeys("A\\\", 'x') " Using Vim9 lambda expression in legacy context should fail ! 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! " set 'thesaurusfunc' to a partial with dict. This used to cause a crash. --- 1471,1481 ---- call feedkeys("A\\\", 'x') " Using Vim9 lambda expression in legacy context should fail ! set thesaurusfunc=(a,\ b)\ =>\ TsrFunc1(21,\ a,\ b) new | only ! let g:TsrFunc1Args = [] call assert_fails('call feedkeys("A\\\", "x")', 'E117:') ! call assert_equal([], g:TsrFunc1Args) bw! " set 'thesaurusfunc' to a partial with dict. This used to cause a crash. *************** *** 1502,1509 **** " cleanup set thesaurusfunc& ! delfunc MytsrFunc1 ! delfunc MytsrFunc2 %bw! endfunc --- 1531,1539 ---- " cleanup set thesaurusfunc& ! delfunc TsrFunc1 ! delfunc TsrFunc2 ! unlet g:TsrFunc1Args g:TsrFunc2Args %bw! endfunc *** ../vim-8.2.3791/src/testdir/test_normal.vim 2021-12-12 16:26:35.872627594 +0000 --- src/testdir/test_normal.vim 2021-12-12 20:06:43.192489733 +0000 *************** *** 444,553 **** " 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 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) #" 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) #" 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) #" Test for using a funcref() ! set operatorfunc=funcref('g:MyopFunc',\ [13]) ! LET g:OpFuncArgs = [] normal! g@l ! call assert_equal([13, '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) #" 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) #" 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) #" 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) #" 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) #" 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) #" 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='' --- 444,563 ---- " Test for different ways of setting the 'operatorfunc' option func Test_opfunc_callback() new ! 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:OpFunc1',\ [10]) ! LET g:OpFunc1Args = [] normal! g@l ! call assert_equal([10, 'char'], g:OpFunc1Args) #" Using a funcref variable to set 'operatorfunc' ! VAR Fn = function('g:OpFunc1', [11]) LET &opfunc = Fn ! LET g:OpFunc1Args = [] normal! g@l ! call assert_equal([11, 'char'], g:OpFunc1Args) #" Using a string(funcref_variable) to set 'operatorfunc' ! LET Fn = function('g:OpFunc1', [12]) LET &operatorfunc = string(Fn) ! LET g:OpFunc1Args = [] normal! g@l ! call assert_equal([12, 'char'], g:OpFunc1Args) #" Test for using a funcref() ! set operatorfunc=funcref('g:OpFunc1',\ [13]) ! LET g:OpFunc1Args = [] normal! g@l ! call assert_equal([13, 'char'], g:OpFunc1Args) #" Using a funcref variable to set 'operatorfunc' ! LET Fn = funcref('g:OpFunc1', [14]) LET &opfunc = Fn ! LET g:OpFunc1Args = [] normal! g@l ! call assert_equal([14, 'char'], g:OpFunc1Args) #" Using a string(funcref_variable) to set 'operatorfunc' ! LET Fn = funcref('g:OpFunc1', [15]) LET &opfunc = string(Fn) ! LET g:OpFunc1Args = [] normal! g@l ! call assert_equal([15, 'char'], g:OpFunc1Args) #" Test for using a lambda function using set ! VAR optval = "LSTART a LMIDDLE OpFunc1(16, a) LEND" LET optval = substitute(optval, ' ', '\\ ', 'g') exe "set opfunc=" .. optval ! LET g:OpFunc1Args = [] normal! g@l ! call assert_equal([16, 'char'], g:OpFunc1Args) #" Test for using a lambda function using LET ! LET &opfunc = LSTART a LMIDDLE OpFunc1(17, a) LEND ! LET g:OpFunc1Args = [] normal! g@l ! call assert_equal([17, 'char'], g:OpFunc1Args) #" Set 'operatorfunc' to a string(lambda expression) ! LET &opfunc = 'LSTART a LMIDDLE OpFunc1(18, a) LEND' ! LET g:OpFunc1Args = [] normal! g@l ! call assert_equal([18, 'char'], g:OpFunc1Args) #" Set 'operatorfunc' to a variable with a lambda expression ! VAR Lambda = LSTART a LMIDDLE OpFunc1(19, a) LEND LET &opfunc = Lambda ! LET g:OpFunc1Args = [] normal! g@l ! call assert_equal([19, 'char'], g:OpFunc1Args) #" Set 'operatorfunc' to a string(variable with a lambda expression) ! LET Lambda = LSTART a LMIDDLE OpFunc1(20, a) LEND LET &opfunc = string(Lambda) ! LET g:OpFunc1Args = [] normal! g@l ! call assert_equal([20, 'char'], g:OpFunc1Args) #" Try to use 'operatorfunc' after the function is deleted ! func g:TmpOpFunc1(type) ! let g:TmpOpFunc1Args = [21, a:type] endfunc ! LET &opfunc = function('g:TmpOpFunc1') ! delfunc g:TmpOpFunc1 call test_garbagecollect_now() ! LET g:TmpOpFunc1Args = [] call assert_fails('normal! g@l', 'E117:') ! call assert_equal([], g:TmpOpFunc1Args) #" Try to use a function with two arguments for 'operatorfunc' ! func g:TmpOpFunc2(x, y) ! let g:TmpOpFunc2Args = [a:x, a:y] endfunc ! set opfunc=TmpOpFunc2 ! LET g:TmpOpFunc2Args = [] call assert_fails('normal! g@l', 'E119:') ! call assert_equal([], g:TmpOpFunc2Args) ! delfunc TmpOpFunc2 #" Try to use a lambda function with two arguments for 'operatorfunc' ! LET &opfunc = LSTART a, b LMIDDLE OpFunc1(22, b) LEND ! LET g:OpFunc1Args = [] call assert_fails('normal! g@l', 'E119:') ! call assert_equal([], g:OpFunc1Args) #" Test for clearing the 'operatorfunc' option set opfunc='' *************** *** 556,575 **** 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) ! let g:OpFuncArgs = [] call assert_fails('normal! g@l', 'E117:') ! call assert_equal([], g:OpFuncArgs) " set 'operatorfunc' to a partial with dict. This used to cause a crash. func SetOpFunc() --- 566,585 ---- call assert_fails("set opfunc=funcref('abc')", "E700:") #" set 'operatorfunc' to a non-existing function ! LET &opfunc = function('g:OpFunc1', [23]) call assert_fails("set opfunc=function('NonExistingFunc')", 'E700:') call assert_fails("LET &opfunc = function('NonExistingFunc')", 'E700:') ! LET g:OpFunc1Args = [] normal! g@l ! call assert_equal([23, 'char'], g:OpFunc1Args) END call CheckTransLegacySuccess(lines) " Using Vim9 lambda expression in legacy context should fail ! set opfunc=(a)\ =>\ OpFunc1(24,\ a) ! let g:OpFunc1Args = [] call assert_fails('normal! g@l', 'E117:') ! call assert_equal([], g:OpFunc1Args) " set 'operatorfunc' to a partial with dict. This used to cause a crash. func SetOpFunc() *************** *** 590,609 **** # Test for using a def function with opfunc 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) END call CheckScriptSuccess(lines) " cleanup set opfunc& ! delfunc MyopFunc ! delfunc MyopFunc2 ! unlet g:OpFuncArgs %bw! endfunc --- 600,619 ---- # Test for using a def function with opfunc def g:Vim9opFunc(val: number, type: string): void ! g:OpFunc1Args = [val, type] enddef set opfunc=function('g:Vim9opFunc',\ [60]) ! g:OpFunc1Args = [] normal! g@l ! assert_equal([60, 'char'], g:OpFunc1Args) END call CheckScriptSuccess(lines) " cleanup set opfunc& ! delfunc OpFunc1 ! delfunc OpFunc2 ! unlet g:OpFunc1Args g:OpFunc2Args %bw! endfunc *** ../vim-8.2.3791/src/testdir/test_quickfix.vim 2021-12-12 16:26:35.872627594 +0000 --- src/testdir/test_quickfix.vim 2021-12-12 20:06:43.192489733 +0000 *************** *** 5287,5292 **** --- 5287,5299 ---- 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" *** ../vim-8.2.3791/src/testdir/test_tagfunc.vim 2021-12-12 16:26:35.872627594 +0000 --- src/testdir/test_tagfunc.vim 2021-12-12 20:06:43.192489733 +0000 *************** *** 127,228 **** " 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] return v:null endfunc 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' ! 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('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() ! 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('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) #" 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='' --- 127,252 ---- " Test for different ways of setting the 'tagfunc' option func Test_tagfunc_callback() ! 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:TagFunc1',\ [10]) ! new ! LET g:TagFunc1Args = [] call assert_fails('tag a11', 'E433:') ! call assert_equal([10, 'a11', '', {}], g:TagFunc1Args) ! bw! #" Using a funcref variable to set 'tagfunc' ! VAR Fn = function('g:TagFunc1', [11]) LET &tagfunc = Fn ! new ! LET g:TagFunc1Args = [] call assert_fails('tag a12', 'E433:') ! call assert_equal([11, 'a12', '', {}], g:TagFunc1Args) ! bw! #" Using a string(funcref_variable) to set 'tagfunc' ! LET Fn = function('g:TagFunc1', [12]) LET &tagfunc = string(Fn) ! new ! LET g:TagFunc1Args = [] call assert_fails('tag a12', 'E433:') ! call assert_equal([12, 'a12', '', {}], g:TagFunc1Args) ! bw! #" Test for using a funcref() ! set tagfunc=funcref('g:TagFunc1',\ [13]) ! new ! LET g:TagFunc1Args = [] call assert_fails('tag a13', 'E433:') ! call assert_equal([13, 'a13', '', {}], g:TagFunc1Args) ! bw! #" Using a funcref variable to set 'tagfunc' ! LET Fn = funcref('g:TagFunc1', [14]) LET &tagfunc = Fn ! new ! LET g:TagFunc1Args = [] call assert_fails('tag a14', 'E433:') ! call assert_equal([14, 'a14', '', {}], g:TagFunc1Args) ! bw! #" Using a string(funcref_variable) to set 'tagfunc' ! LET Fn = funcref('g:TagFunc1', [15]) LET &tagfunc = string(Fn) ! new ! LET g:TagFunc1Args = [] call assert_fails('tag a14', 'E433:') ! call assert_equal([15, 'a14', '', {}], g:TagFunc1Args) ! bw! #" Test for using a lambda function ! VAR optval = "LSTART a, b, c LMIDDLE TagFunc1(16, a, b, c) LEND" LET optval = substitute(optval, ' ', '\\ ', 'g') exe "set tagfunc=" .. optval ! new ! LET g:TagFunc1Args = [] call assert_fails('tag a17', 'E433:') ! call assert_equal([16, 'a17', '', {}], g:TagFunc1Args) ! bw! #" Set 'tagfunc' to a lambda expression ! 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:TagFunc1Args) ! bw! #" Set 'tagfunc' to a string(lambda expression) ! 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:TagFunc1Args) ! bw! #" Set 'tagfunc' to a variable with a lambda expression ! VAR Lambda = LSTART a, b, c LMIDDLE TagFunc1(19, a, b, c) LEND LET &tagfunc = Lambda ! new ! LET g:TagFunc1Args = [] call assert_fails("tag a19", "E433:") ! 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 TagFunc1(20, a, b, c) LEND LET &tagfunc = string(Lambda) ! new ! LET g:TagFunc1Args = [] call assert_fails("tag a19", "E433:") ! 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 call assert_fails("tag a20", "E987:") + bw! #" Test for clearing the 'tagfunc' option set tagfunc='' *************** *** 231,240 **** 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) --- 255,267 ---- call assert_fails("set tagfunc=funcref('abc')", "E700:") #" set 'tagfunc' to a non-existing function ! 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,252 **** 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) " Test for using a script local function set tagfunc=ScriptLocalTagFunc --- 269,279 ---- 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 ! let g:TagFunc1Args = [] call assert_fails("tag a17", "E117:") ! call assert_equal([], g:TagFunc1Args) " Test for using a script local function set tagfunc=ScriptLocalTagFunc *************** *** 309,315 **** call CheckScriptSuccess(lines) " cleanup ! delfunc MytagFunc1 set tagfunc& %bw! endfunc --- 336,343 ---- call CheckScriptSuccess(lines) " cleanup ! delfunc TagFunc1 ! delfunc TagFunc2 set tagfunc& %bw! endfunc *** ../vim-8.2.3791/src/version.c 2021-12-12 19:10:39.629912018 +0000 --- src/version.c 2021-12-12 20:07:21.044413342 +0000 *************** *** 755,756 **** --- 755,758 ---- { /* Add new patch number below this line */ + /**/ + 3792, /**/ -- "So this is it," said Arthur, "we are going to die." "Yes," said Ford, "except...no! Wait a minute!" He suddenly lunged across the chamber at something behind Arthur's line of vision. "What's this switch?" he cried. "What? Where?" cried Arthur, twisting around. "No, I was only fooling," said Ford, "we are going to die after all." -- Douglas Adams, "The Hitchhiker's Guide to the Galaxy" /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///