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)

04ef1fb13d

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
zeertzjq 2022-11-07 14:08:29 +08:00
parent c00d241981
commit be19990f30
4 changed files with 380 additions and 305 deletions

View File

@ -1290,123 +1290,136 @@ endfunc
" Test for different ways of setting the 'completefunc' option
func Test_completefunc_callback()
func MycompleteFunc1(val, findstart, base)
call add(g:MycompleteFunc1_args, [a:val, a:findstart, a:base])
func CompleteFunc1(callnr, findstart, base)
call add(g:CompleteFunc1Args, [a:callnr, a:findstart, a:base])
return a:findstart ? 0 : []
endfunc
func CompleteFunc2(findstart, base)
call add(g:CompleteFunc2Args, [a:findstart, a:base])
return a:findstart ? 0 : []
endfunc
let lines =<< trim END
#" Test for using a function()
set completefunc=function('g:MycompleteFunc1',\ [10])
new | only
call setline(1, 'one')
LET g:MycompleteFunc1_args = []
#" Test for using a function name
LET &completefunc = 'g:CompleteFunc2'
new
call setline(1, 'zero')
LET g:CompleteFunc2Args = []
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MycompleteFunc1_args)
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\<C-X>\<C-U>\<Esc>", 'x')
call assert_equal([[10, 1, ''], [10, 0, 'one']], g:CompleteFunc1Args)
bw!
#" Using a funcref variable to set 'completefunc'
VAR Fn = function('g:MycompleteFunc1', [11])
VAR Fn = function('g:CompleteFunc1', [11])
LET &completefunc = Fn
new | only
new
call setline(1, 'two')
LET g:MycompleteFunc1_args = []
LET g:CompleteFunc1Args = []
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MycompleteFunc1_args)
call assert_equal([[11, 1, ''], [11, 0, 'two']], g:CompleteFunc1Args)
bw!
#" Using string(funcref_variable) to set 'completefunc'
LET Fn = function('g:MycompleteFunc1', [12])
LET Fn = function('g:CompleteFunc1', [12])
LET &completefunc = string(Fn)
new | only
new
call setline(1, 'two')
LET g:MycompleteFunc1_args = []
LET g:CompleteFunc1Args = []
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MycompleteFunc1_args)
call assert_equal([[12, 1, ''], [12, 0, 'two']], g:CompleteFunc1Args)
bw!
#" Test for using a funcref()
set completefunc=funcref('g:MycompleteFunc1',\ [13])
new | only
set completefunc=funcref('g:CompleteFunc1',\ [13])
new
call setline(1, 'three')
LET g:MycompleteFunc1_args = []
LET g:CompleteFunc1Args = []
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MycompleteFunc1_args)
call assert_equal([[13, 1, ''], [13, 0, 'three']], g:CompleteFunc1Args)
bw!
#" Using a funcref variable to set 'completefunc'
LET Fn = funcref('g:MycompleteFunc1', [14])
LET Fn = funcref('g:CompleteFunc1', [14])
LET &completefunc = Fn
new | only
new
call setline(1, 'four')
LET g:MycompleteFunc1_args = []
LET g:CompleteFunc1Args = []
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MycompleteFunc1_args)
call assert_equal([[14, 1, ''], [14, 0, 'four']], g:CompleteFunc1Args)
bw!
#" Using a string(funcref_variable) to set 'completefunc'
LET Fn = funcref('g:MycompleteFunc1', [15])
LET Fn = funcref('g:CompleteFunc1', [15])
LET &completefunc = string(Fn)
new | only
new
call setline(1, 'four')
LET g:MycompleteFunc1_args = []
LET g:CompleteFunc1Args = []
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MycompleteFunc1_args)
call assert_equal([[15, 1, ''], [15, 0, 'four']], g:CompleteFunc1Args)
bw!
#" Test for using a lambda function with set
VAR optval = "LSTART a, b LMIDDLE MycompleteFunc1(16, a, b) LEND"
VAR optval = "LSTART a, b LMIDDLE CompleteFunc1(16, a, b) LEND"
LET optval = substitute(optval, ' ', '\\ ', 'g')
exe "set completefunc=" .. optval
new | only
new
call setline(1, 'five')
LET g:MycompleteFunc1_args = []
LET g:CompleteFunc1Args = []
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MycompleteFunc1_args)
call assert_equal([[16, 1, ''], [16, 0, 'five']], g:CompleteFunc1Args)
bw!
#" Set 'completefunc' to a lambda expression
LET &completefunc = LSTART a, b LMIDDLE MycompleteFunc1(17, a, b) LEND
new | only
LET &completefunc = LSTART a, b LMIDDLE CompleteFunc1(17, a, b) LEND
new
call setline(1, 'six')
LET g:MycompleteFunc1_args = []
LET g:CompleteFunc1Args = []
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MycompleteFunc1_args)
call assert_equal([[17, 1, ''], [17, 0, 'six']], g:CompleteFunc1Args)
bw!
#" Set 'completefunc' to string(lambda_expression)
LET &completefunc = 'LSTART a, b LMIDDLE MycompleteFunc1(18, a, b) LEND'
new | only
LET &completefunc = 'LSTART a, b LMIDDLE CompleteFunc1(18, a, b) LEND'
new
call setline(1, 'six')
LET g:MycompleteFunc1_args = []
LET g:CompleteFunc1Args = []
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MycompleteFunc1_args)
call assert_equal([[18, 1, ''], [18, 0, 'six']], g:CompleteFunc1Args)
bw!
#" Set 'completefunc' to a variable with a lambda expression
VAR Lambda = LSTART a, b LMIDDLE MycompleteFunc1(19, a, b) LEND
VAR Lambda = LSTART a, b LMIDDLE CompleteFunc1(19, a, b) LEND
LET &completefunc = Lambda
new | only
new
call setline(1, 'seven')
LET g:MycompleteFunc1_args = []
LET g:CompleteFunc1Args = []
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MycompleteFunc1_args)
call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:CompleteFunc1Args)
bw!
#" Set 'completefunc' to a string(variable with a lambda expression)
LET Lambda = LSTART a, b LMIDDLE MycompleteFunc1(20, a, b) LEND
LET Lambda = LSTART a, b LMIDDLE CompleteFunc1(20, a, b) LEND
LET &completefunc = string(Lambda)
new | only
new
call setline(1, 'seven')
LET g:MycompleteFunc1_args = []
LET g:CompleteFunc1Args = []
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MycompleteFunc1_args)
call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:CompleteFunc1Args)
bw!
#" Test for using a lambda function with incorrect return value
LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND
LET &completefunc = Lambda
new | only
new
call setline(1, 'eight')
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
bw!
@ -1418,17 +1431,13 @@ func Test_completefunc_callback()
call assert_fails("set completefunc=funcref('abc')", "E700:")
#" set 'completefunc' to a non-existing function
func MycompleteFunc2(findstart, base)
call add(g:MycompleteFunc2_args, [a:findstart, a:base])
return a:findstart ? 0 : []
endfunc
set completefunc=MycompleteFunc2
set completefunc=CompleteFunc2
call setline(1, 'five')
call assert_fails("set completefunc=function('NonExistingFunc')", 'E700:')
call assert_fails("LET &completefunc = function('NonExistingFunc')", 'E700:')
LET g:MycompleteFunc2_args = []
LET g:CompleteFunc2Args = []
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
call assert_equal([[1, ''], [0, 'five']], g:MycompleteFunc2_args)
call assert_equal([[1, ''], [0, 'five']], g:CompleteFunc2Args)
bw!
END
call CheckLegacyAndVim9Success(lines)
@ -1437,11 +1446,11 @@ func Test_completefunc_callback()
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
" Using Vim9 lambda expression in legacy context should fail
" set completefunc=(a,\ b)\ =>\ MycompleteFunc1(21,\ a,\ b)
" set completefunc=(a,\ b)\ =>\ CompleteFunc1(21,\ a,\ b)
new | only
let g:MycompleteFunc1_args = []
let g:CompleteFunc1Args = []
" call assert_fails('call feedkeys("A\<C-X>\<C-U>\<Esc>", "x")', 'E117:')
call assert_equal([], g:MycompleteFunc1_args)
call assert_equal([], g:CompleteFunc1Args)
" set 'completefunc' to a partial with dict. This used to cause a crash.
func SetCompleteFunc()
@ -1483,131 +1492,145 @@ func Test_completefunc_callback()
" call CheckScriptSuccess(lines)
" cleanup
delfunc MycompleteFunc1
delfunc MycompleteFunc2
set completefunc&
delfunc CompleteFunc1
delfunc CompleteFunc2
unlet g:CompleteFunc1Args g:CompleteFunc2Args
%bw!
endfunc
" Test for different ways of setting the 'omnifunc' option
func Test_omnifunc_callback()
func MyomniFunc1(val, findstart, base)
call add(g:MyomniFunc1_args, [a:val, a:findstart, a:base])
func OmniFunc1(callnr, findstart, base)
call add(g:OmniFunc1Args, [a:callnr, a:findstart, a:base])
return a:findstart ? 0 : []
endfunc
func OmniFunc2(findstart, base)
call add(g:OmniFunc2Args, [a:findstart, a:base])
return a:findstart ? 0 : []
endfunc
let lines =<< trim END
#" Test for using a function()
set omnifunc=function('g:MyomniFunc1',\ [10])
new | only
call setline(1, 'one')
LET g:MyomniFunc1_args = []
#" Test for using a function name
LET &omnifunc = 'g:OmniFunc2'
new
call setline(1, 'zero')
LET g:OmniFunc2Args = []
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MyomniFunc1_args)
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\<C-X>\<C-O>\<Esc>", 'x')
call assert_equal([[10, 1, ''], [10, 0, 'one']], g:OmniFunc1Args)
bw!
#" Using a funcref variable to set 'omnifunc'
VAR Fn = function('g:MyomniFunc1', [11])
VAR Fn = function('g:OmniFunc1', [11])
LET &omnifunc = Fn
new | only
new
call setline(1, 'two')
LET g:MyomniFunc1_args = []
LET g:OmniFunc1Args = []
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MyomniFunc1_args)
call assert_equal([[11, 1, ''], [11, 0, 'two']], g:OmniFunc1Args)
bw!
#" Using a string(funcref_variable) to set 'omnifunc'
LET Fn = function('g:MyomniFunc1', [12])
LET Fn = function('g:OmniFunc1', [12])
LET &omnifunc = string(Fn)
new | only
new
call setline(1, 'two')
LET g:MyomniFunc1_args = []
LET g:OmniFunc1Args = []
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MyomniFunc1_args)
call assert_equal([[12, 1, ''], [12, 0, 'two']], g:OmniFunc1Args)
bw!
#" Test for using a funcref()
set omnifunc=funcref('g:MyomniFunc1',\ [13])
new | only
set omnifunc=funcref('g:OmniFunc1',\ [13])
new
call setline(1, 'three')
LET g:MyomniFunc1_args = []
LET g:OmniFunc1Args = []
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MyomniFunc1_args)
call assert_equal([[13, 1, ''], [13, 0, 'three']], g:OmniFunc1Args)
bw!
#" Use let to set 'omnifunc' to a funcref
LET Fn = funcref('g:MyomniFunc1', [14])
LET Fn = funcref('g:OmniFunc1', [14])
LET &omnifunc = Fn
new | only
new
call setline(1, 'four')
LET g:MyomniFunc1_args = []
LET g:OmniFunc1Args = []
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MyomniFunc1_args)
call assert_equal([[14, 1, ''], [14, 0, 'four']], g:OmniFunc1Args)
bw!
#" Using a string(funcref) to set 'omnifunc'
LET Fn = funcref("g:MyomniFunc1", [15])
LET Fn = funcref("g:OmniFunc1", [15])
LET &omnifunc = string(Fn)
new | only
new
call setline(1, 'four')
LET g:MyomniFunc1_args = []
LET g:OmniFunc1Args = []
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MyomniFunc1_args)
call assert_equal([[15, 1, ''], [15, 0, 'four']], g:OmniFunc1Args)
bw!
#" Test for using a lambda function with set
VAR optval = "LSTART a, b LMIDDLE MyomniFunc1(16, a, b) LEND"
VAR optval = "LSTART a, b LMIDDLE OmniFunc1(16, a, b) LEND"
LET optval = substitute(optval, ' ', '\\ ', 'g')
exe "set omnifunc=" .. optval
new | only
new
call setline(1, 'five')
LET g:MyomniFunc1_args = []
LET g:OmniFunc1Args = []
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MyomniFunc1_args)
call assert_equal([[16, 1, ''], [16, 0, 'five']], g:OmniFunc1Args)
bw!
#" Set 'omnifunc' to a lambda expression
LET &omnifunc = LSTART a, b LMIDDLE MyomniFunc1(17, a, b) LEND
new | only
LET &omnifunc = LSTART a, b LMIDDLE OmniFunc1(17, a, b) LEND
new
call setline(1, 'six')
LET g:MyomniFunc1_args = []
LET g:OmniFunc1Args = []
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MyomniFunc1_args)
call assert_equal([[17, 1, ''], [17, 0, 'six']], g:OmniFunc1Args)
bw!
#" Set 'omnifunc' to a string(lambda_expression)
LET &omnifunc = 'LSTART a, b LMIDDLE MyomniFunc1(18, a, b) LEND'
new | only
LET &omnifunc = 'LSTART a, b LMIDDLE OmniFunc1(18, a, b) LEND'
new
call setline(1, 'six')
LET g:MyomniFunc1_args = []
LET g:OmniFunc1Args = []
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MyomniFunc1_args)
call assert_equal([[18, 1, ''], [18, 0, 'six']], g:OmniFunc1Args)
bw!
#" Set 'omnifunc' to a variable with a lambda expression
VAR Lambda = LSTART a, b LMIDDLE MyomniFunc1(19, a, b) LEND
VAR Lambda = LSTART a, b LMIDDLE OmniFunc1(19, a, b) LEND
LET &omnifunc = Lambda
new | only
new
call setline(1, 'seven')
LET g:MyomniFunc1_args = []
LET g:OmniFunc1Args = []
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MyomniFunc1_args)
call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:OmniFunc1Args)
bw!
#" Set 'omnifunc' to a string(variable with a lambda expression)
LET Lambda = LSTART a, b LMIDDLE MyomniFunc1(20, a, b) LEND
LET Lambda = LSTART a, b LMIDDLE OmniFunc1(20, a, b) LEND
LET &omnifunc = string(Lambda)
new | only
new
call setline(1, 'seven')
LET g:MyomniFunc1_args = []
LET g:OmniFunc1Args = []
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MyomniFunc1_args)
call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:OmniFunc1Args)
bw!
#" Test for using a lambda function with incorrect return value
LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND
LET &omnifunc = Lambda
new | only
new
call setline(1, 'eight')
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
bw!
@ -1619,17 +1642,13 @@ func Test_omnifunc_callback()
call assert_fails("set omnifunc=funcref('abc')", "E700:")
#" set 'omnifunc' to a non-existing function
func MyomniFunc2(findstart, base)
call add(g:MyomniFunc2_args, [a:findstart, a:base])
return a:findstart ? 0 : []
endfunc
set omnifunc=MyomniFunc2
set omnifunc=OmniFunc2
call setline(1, 'nine')
call assert_fails("set omnifunc=function('NonExistingFunc')", 'E700:')
call assert_fails("LET &omnifunc = function('NonExistingFunc')", 'E700:')
LET g:MyomniFunc2_args = []
LET g:OmniFunc2Args = []
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
call assert_equal([[1, ''], [0, 'nine']], g:MyomniFunc2_args)
call assert_equal([[1, ''], [0, 'nine']], g:OmniFunc2Args)
bw!
END
call CheckLegacyAndVim9Success(lines)
@ -1638,11 +1657,11 @@ func Test_omnifunc_callback()
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
" Using Vim9 lambda expression in legacy context should fail
" set omnifunc=(a,\ b)\ =>\ MyomniFunc1(21,\ a,\ b)
" set omnifunc=(a,\ b)\ =>\ OmniFunc1(21,\ a,\ b)
new | only
let g:MyomniFunc1_args = []
let g:OmniFunc1Args = []
" call assert_fails('call feedkeys("A\<C-X>\<C-O>\<Esc>", "x")', 'E117:')
call assert_equal([], g:MyomniFunc1_args)
call assert_equal([], g:OmniFunc1Args)
" set 'omnifunc' to a partial with dict. This used to cause a crash.
func SetOmniFunc()
@ -1684,131 +1703,145 @@ func Test_omnifunc_callback()
" call CheckScriptSuccess(lines)
" cleanup
delfunc MyomniFunc1
delfunc MyomniFunc2
set omnifunc&
delfunc OmniFunc1
delfunc OmniFunc2
unlet g:OmniFunc1Args g:OmniFunc2Args
%bw!
endfunc
" Test for different ways of setting the 'thesaurusfunc' option
func Test_thesaurusfunc_callback()
func MytsrFunc1(val, findstart, base)
call add(g:MytsrFunc1_args, [a:val, a:findstart, a:base])
func TsrFunc1(callnr, findstart, base)
call add(g:TsrFunc1Args, [a:callnr, a:findstart, a:base])
return a:findstart ? 0 : []
endfunc
func TsrFunc2(findstart, base)
call add(g:TsrFunc2Args, [a:findstart, a:base])
return a:findstart ? 0 : ['sunday']
endfunc
let lines =<< trim END
#" Test for using a function()
set thesaurusfunc=function('g:MytsrFunc1',\ [10])
new | only
call setline(1, 'one')
LET g:MytsrFunc1_args = []
#" Test for using a function name
LET &thesaurusfunc = 'g:TsrFunc2'
new
call setline(1, 'zero')
LET g:TsrFunc2Args = []
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MytsrFunc1_args)
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\<C-X>\<C-T>\<Esc>", 'x')
call assert_equal([[10, 1, ''], [10, 0, 'one']], g:TsrFunc1Args)
bw!
#" Using a funcref variable to set 'thesaurusfunc'
VAR Fn = function('g:MytsrFunc1', [11])
VAR Fn = function('g:TsrFunc1', [11])
LET &thesaurusfunc = Fn
new | only
new
call setline(1, 'two')
LET g:MytsrFunc1_args = []
LET g:TsrFunc1Args = []
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MytsrFunc1_args)
call assert_equal([[11, 1, ''], [11, 0, 'two']], g:TsrFunc1Args)
bw!
#" Using a string(funcref_variable) to set 'thesaurusfunc'
LET Fn = function('g:MytsrFunc1', [12])
LET Fn = function('g:TsrFunc1', [12])
LET &thesaurusfunc = string(Fn)
new | only
new
call setline(1, 'two')
LET g:MytsrFunc1_args = []
LET g:TsrFunc1Args = []
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MytsrFunc1_args)
call assert_equal([[12, 1, ''], [12, 0, 'two']], g:TsrFunc1Args)
bw!
#" Test for using a funcref()
set thesaurusfunc=funcref('g:MytsrFunc1',\ [13])
new | only
set thesaurusfunc=funcref('g:TsrFunc1',\ [13])
new
call setline(1, 'three')
LET g:MytsrFunc1_args = []
LET g:TsrFunc1Args = []
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MytsrFunc1_args)
call assert_equal([[13, 1, ''], [13, 0, 'three']], g:TsrFunc1Args)
bw!
#" Using a funcref variable to set 'thesaurusfunc'
LET Fn = funcref('g:MytsrFunc1', [14])
LET Fn = funcref('g:TsrFunc1', [14])
LET &thesaurusfunc = Fn
new | only
new
call setline(1, 'four')
LET g:MytsrFunc1_args = []
LET g:TsrFunc1Args = []
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MytsrFunc1_args)
call assert_equal([[14, 1, ''], [14, 0, 'four']], g:TsrFunc1Args)
bw!
#" Using a string(funcref_variable) to set 'thesaurusfunc'
LET Fn = funcref('g:MytsrFunc1', [15])
LET Fn = funcref('g:TsrFunc1', [15])
LET &thesaurusfunc = string(Fn)
new | only
new
call setline(1, 'four')
LET g:MytsrFunc1_args = []
LET g:TsrFunc1Args = []
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MytsrFunc1_args)
call assert_equal([[15, 1, ''], [15, 0, 'four']], g:TsrFunc1Args)
bw!
#" Test for using a lambda function
VAR optval = "LSTART a, b LMIDDLE MytsrFunc1(16, a, b) LEND"
VAR optval = "LSTART a, b LMIDDLE TsrFunc1(16, a, b) LEND"
LET optval = substitute(optval, ' ', '\\ ', 'g')
exe "set thesaurusfunc=" .. optval
new | only
new
call setline(1, 'five')
LET g:MytsrFunc1_args = []
LET g:TsrFunc1Args = []
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MytsrFunc1_args)
call assert_equal([[16, 1, ''], [16, 0, 'five']], g:TsrFunc1Args)
bw!
#" Test for using a lambda function with set
LET &thesaurusfunc = LSTART a, b LMIDDLE MytsrFunc1(17, a, b) LEND
new | only
LET &thesaurusfunc = LSTART a, b LMIDDLE TsrFunc1(17, a, b) LEND
new
call setline(1, 'six')
LET g:MytsrFunc1_args = []
LET g:TsrFunc1Args = []
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MytsrFunc1_args)
call assert_equal([[17, 1, ''], [17, 0, 'six']], g:TsrFunc1Args)
bw!
#" Set 'thesaurusfunc' to a string(lambda expression)
LET &thesaurusfunc = 'LSTART a, b LMIDDLE MytsrFunc1(18, a, b) LEND'
new | only
LET &thesaurusfunc = 'LSTART a, b LMIDDLE TsrFunc1(18, a, b) LEND'
new
call setline(1, 'six')
LET g:MytsrFunc1_args = []
LET g:TsrFunc1Args = []
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MytsrFunc1_args)
call assert_equal([[18, 1, ''], [18, 0, 'six']], g:TsrFunc1Args)
bw!
#" Set 'thesaurusfunc' to a variable with a lambda expression
VAR Lambda = LSTART a, b LMIDDLE MytsrFunc1(19, a, b) LEND
VAR Lambda = LSTART a, b LMIDDLE TsrFunc1(19, a, b) LEND
LET &thesaurusfunc = Lambda
new | only
new
call setline(1, 'seven')
LET g:MytsrFunc1_args = []
LET g:TsrFunc1Args = []
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MytsrFunc1_args)
call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:TsrFunc1Args)
bw!
#" Set 'thesaurusfunc' to a string(variable with a lambda expression)
LET Lambda = LSTART a, b LMIDDLE MytsrFunc1(20, a, b) LEND
LET Lambda = LSTART a, b LMIDDLE TsrFunc1(20, a, b) LEND
LET &thesaurusfunc = string(Lambda)
new | only
new
call setline(1, 'seven')
LET g:MytsrFunc1_args = []
LET g:TsrFunc1Args = []
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MytsrFunc1_args)
call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:TsrFunc1Args)
bw!
#" Test for using a lambda function with incorrect return value
LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND
LET &thesaurusfunc = Lambda
new | only
new
call setline(1, 'eight')
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
bw!
@ -1820,40 +1853,36 @@ func Test_thesaurusfunc_callback()
call assert_fails("set thesaurusfunc=funcref('abc')", "E700:")
#" set 'thesaurusfunc' to a non-existing function
func MytsrFunc2(findstart, base)
call add(g:MytsrFunc2_args, [a:findstart, a:base])
return a:findstart ? 0 : ['sunday']
endfunc
set thesaurusfunc=MytsrFunc2
set thesaurusfunc=TsrFunc2
call setline(1, 'ten')
call assert_fails("set thesaurusfunc=function('NonExistingFunc')", 'E700:')
call assert_fails("LET &thesaurusfunc = function('NonExistingFunc')", 'E700:')
LET g:MytsrFunc2_args = []
LET g:TsrFunc2Args = []
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
call assert_equal([[1, ''], [0, 'ten']], g:MytsrFunc2_args)
call assert_equal([[1, ''], [0, 'ten']], g:TsrFunc2Args)
bw!
#" Use a buffer-local value and a global value
set thesaurusfunc&
setlocal thesaurusfunc=function('g:MytsrFunc1',\ [22])
setlocal thesaurusfunc=function('g:TsrFunc1',\ [22])
call setline(1, 'sun')
LET g:MytsrFunc1_args = []
LET g:TsrFunc1Args = []
call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")
call assert_equal('sun', getline(1))
call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:MytsrFunc1_args)
call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:TsrFunc1Args)
new
call setline(1, 'sun')
LET g:MytsrFunc1_args = []
LET g:TsrFunc1Args = []
call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")
call assert_equal('sun', getline(1))
call assert_equal([], g:MytsrFunc1_args)
set thesaurusfunc=function('g:MytsrFunc1',\ [23])
call assert_equal([], g:TsrFunc1Args)
set thesaurusfunc=function('g:TsrFunc1',\ [23])
wincmd w
call setline(1, 'sun')
LET g:MytsrFunc1_args = []
LET g:TsrFunc1Args = []
call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")
call assert_equal('sun', getline(1))
call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:MytsrFunc1_args)
call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:TsrFunc1Args)
:%bw!
END
call CheckLegacyAndVim9Success(lines)
@ -1862,11 +1891,11 @@ func Test_thesaurusfunc_callback()
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
" Using Vim9 lambda expression in legacy context should fail
" set thesaurusfunc=(a,\ b)\ =>\ MytsrFunc1(21,\ a,\ b)
" set thesaurusfunc=(a,\ b)\ =>\ TsrFunc1(21,\ a,\ b)
new | only
let g:MytsrFunc1_args = []
let g:TsrFunc1Args = []
" call assert_fails('call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")', 'E117:')
call assert_equal([], g:MytsrFunc1_args)
call assert_equal([], g:TsrFunc1Args)
bw!
" set 'thesaurusfunc' to a partial with dict. This used to cause a crash.
@ -1922,8 +1951,9 @@ func Test_thesaurusfunc_callback()
" cleanup
set thesaurusfunc&
delfunc MytsrFunc1
delfunc MytsrFunc2
delfunc TsrFunc1
delfunc TsrFunc2
unlet g:TsrFunc1Args g:TsrFunc2Args
%bw!
endfunc

View File

@ -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()
set opfunc=function('g:MyopFunc',\ [10])
LET g:OpFuncArgs = []
#" Test for using a function name
LET &opfunc = 'g:OpFunc2'
LET g:OpFunc2Args = []
normal! g@l
call assert_equal([10, 'char'], g:OpFuncArgs)
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: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

View File

@ -5695,6 +5695,13 @@ func Test_qftextfunc_callback()
let lines =<< trim END
set efm=%f:%l:%c:%m
#" Test for using a function name
LET &qftf = 'g:Tqfexpr'
cexpr "F0:0:0:L0"
copen
call assert_equal('F0-L0C0-L0', getline(1))
cclose
#" Test for using a function()
set qftf=function('g:Tqfexpr')
cexpr "F1:1:1:L1"

View File

@ -127,102 +127,126 @@ endfunc
" Test for different ways of setting the 'tagfunc' option
func Test_tagfunc_callback()
func MytagFunc1(val, pat, flags, info)
let g:MytagFunc1_args = [a:val, a:pat, a:flags, a:info]
func TagFunc1(callnr, pat, flags, info)
let g:TagFunc1Args = [a:callnr, a:pat, a:flags, a:info]
return v:null
endfunc
func TagFunc2(pat, flags, info)
let g:TagFunc2Args = [a:pat, a:flags, a:info]
return v:null
endfunc
let lines =<< trim END
#" Test for using a function name
LET &tagfunc = 'g:TagFunc2'
new
LET g:TagFunc2Args = []
call assert_fails('tag a10', 'E433:')
call assert_equal(['a10', '', {}], g:TagFunc2Args)
bw!
#" Test for using a function()
set tagfunc=function('g:MytagFunc1',\ [10])
new | only
LET g:MytagFunc1_args = []
set tagfunc=function('g:TagFunc1',\ [10])
new
LET g:TagFunc1Args = []
call assert_fails('tag a11', 'E433:')
call assert_equal([10, 'a11', '', {}], g:MytagFunc1_args)
call assert_equal([10, 'a11', '', {}], g:TagFunc1Args)
bw!
#" Using a funcref variable to set 'tagfunc'
VAR Fn = function('g:MytagFunc1', [11])
VAR Fn = function('g:TagFunc1', [11])
LET &tagfunc = Fn
new | only
LET g:MytagFunc1_args = []
new
LET g:TagFunc1Args = []
call assert_fails('tag a12', 'E433:')
call assert_equal([11, 'a12', '', {}], g:MytagFunc1_args)
call assert_equal([11, 'a12', '', {}], g:TagFunc1Args)
bw!
#" Using a string(funcref_variable) to set 'tagfunc'
LET Fn = function('g:MytagFunc1', [12])
LET Fn = function('g:TagFunc1', [12])
LET &tagfunc = string(Fn)
new | only
LET g:MytagFunc1_args = []
new
LET g:TagFunc1Args = []
call assert_fails('tag a12', 'E433:')
call assert_equal([12, 'a12', '', {}], g:MytagFunc1_args)
call assert_equal([12, 'a12', '', {}], g:TagFunc1Args)
bw!
#" Test for using a funcref()
set tagfunc=funcref('g:MytagFunc1',\ [13])
new | only
LET g:MytagFunc1_args = []
set tagfunc=funcref('g:TagFunc1',\ [13])
new
LET g:TagFunc1Args = []
call assert_fails('tag a13', 'E433:')
call assert_equal([13, 'a13', '', {}], g:MytagFunc1_args)
call assert_equal([13, 'a13', '', {}], g:TagFunc1Args)
bw!
#" Using a funcref variable to set 'tagfunc'
LET Fn = funcref('g:MytagFunc1', [14])
LET Fn = funcref('g:TagFunc1', [14])
LET &tagfunc = Fn
new | only
LET g:MytagFunc1_args = []
new
LET g:TagFunc1Args = []
call assert_fails('tag a14', 'E433:')
call assert_equal([14, 'a14', '', {}], g:MytagFunc1_args)
call assert_equal([14, 'a14', '', {}], g:TagFunc1Args)
bw!
#" Using a string(funcref_variable) to set 'tagfunc'
LET Fn = funcref('g:MytagFunc1', [15])
LET Fn = funcref('g:TagFunc1', [15])
LET &tagfunc = string(Fn)
new | only
LET g:MytagFunc1_args = []
new
LET g:TagFunc1Args = []
call assert_fails('tag a14', 'E433:')
call assert_equal([15, 'a14', '', {}], g:MytagFunc1_args)
call assert_equal([15, 'a14', '', {}], g:TagFunc1Args)
bw!
#" Test for using a lambda function
VAR optval = "LSTART a, b, c LMIDDLE MytagFunc1(16, a, b, c) LEND"
VAR optval = "LSTART a, b, c LMIDDLE TagFunc1(16, a, b, c) LEND"
LET optval = substitute(optval, ' ', '\\ ', 'g')
exe "set tagfunc=" .. optval
new | only
LET g:MytagFunc1_args = []
new
LET g:TagFunc1Args = []
call assert_fails('tag a17', 'E433:')
call assert_equal([16, 'a17', '', {}], g:MytagFunc1_args)
call assert_equal([16, 'a17', '', {}], g:TagFunc1Args)
bw!
#" Set 'tagfunc' to a lambda expression
LET &tagfunc = LSTART a, b, c LMIDDLE MytagFunc1(17, a, b, c) LEND
new | only
LET g:MytagFunc1_args = []
LET &tagfunc = LSTART a, b, c LMIDDLE TagFunc1(17, a, b, c) LEND
new
LET g:TagFunc1Args = []
call assert_fails('tag a18', 'E433:')
call assert_equal([17, 'a18', '', {}], g:MytagFunc1_args)
call assert_equal([17, 'a18', '', {}], g:TagFunc1Args)
bw!
#" Set 'tagfunc' to a string(lambda expression)
LET &tagfunc = 'LSTART a, b, c LMIDDLE MytagFunc1(18, a, b, c) LEND'
new | only
LET g:MytagFunc1_args = []
LET &tagfunc = 'LSTART a, b, c LMIDDLE TagFunc1(18, a, b, c) LEND'
new
LET g:TagFunc1Args = []
call assert_fails('tag a18', 'E433:')
call assert_equal([18, 'a18', '', {}], g:MytagFunc1_args)
call assert_equal([18, 'a18', '', {}], g:TagFunc1Args)
bw!
#" Set 'tagfunc' to a variable with a lambda expression
VAR Lambda = LSTART a, b, c LMIDDLE MytagFunc1(19, a, b, c) LEND
VAR Lambda = LSTART a, b, c LMIDDLE TagFunc1(19, a, b, c) LEND
LET &tagfunc = Lambda
new | only
LET g:MytagFunc1_args = []
new
LET g:TagFunc1Args = []
call assert_fails("tag a19", "E433:")
call assert_equal([19, 'a19', '', {}], g:MytagFunc1_args)
call assert_equal([19, 'a19', '', {}], g:TagFunc1Args)
bw!
#" Set 'tagfunc' to a string(variable with a lambda expression)
LET Lambda = LSTART a, b, c LMIDDLE MytagFunc1(20, a, b, c) LEND
LET Lambda = LSTART a, b, c LMIDDLE TagFunc1(20, a, b, c) LEND
LET &tagfunc = string(Lambda)
new | only
LET g:MytagFunc1_args = []
new
LET g:TagFunc1Args = []
call assert_fails("tag a19", "E433:")
call assert_equal([20, 'a19', '', {}], g:MytagFunc1_args)
call assert_equal([20, 'a19', '', {}], g:TagFunc1Args)
bw!
#" Test for using a lambda function with incorrect return value
LET Lambda = LSTART a, b, c LMIDDLE strlen(a) LEND
LET &tagfunc = string(Lambda)
new | only
new
call assert_fails("tag a20", "E987:")
bw!
#" Test for clearing the 'tagfunc' option
set tagfunc=''
@ -231,10 +255,13 @@ func Test_tagfunc_callback()
call assert_fails("set tagfunc=funcref('abc')", "E700:")
#" set 'tagfunc' to a non-existing function
LET &tagfunc = function('g:MytagFunc1', [21])
LET &tagfunc = function('g:TagFunc2', [21])
LET g:TagFunc2Args = []
call assert_fails("set tagfunc=function('NonExistingFunc')", 'E700:')
call assert_fails("LET &tagfunc = function('NonExistingFunc')", 'E700:')
call assert_fails("tag axb123", 'E426:')
call assert_equal([], g:TagFunc2Args)
bw!
END
call CheckLegacyAndVim9Success(lines)
@ -242,11 +269,11 @@ func Test_tagfunc_callback()
call assert_fails("echo taglist('a')", "E987:")
" Using Vim9 lambda expression in legacy context should fail
" set tagfunc=(a,\ b,\ c)\ =>\ g:MytagFunc1(21,\ a,\ b,\ c)
" set tagfunc=(a,\ b,\ c)\ =>\ g:TagFunc1(21,\ a,\ b,\ c)
new | only
let g:MytagFunc1_args = []
let g:TagFunc1Args = []
" call assert_fails("tag a17", "E117:")
call assert_equal([], g:MytagFunc1_args)
call assert_equal([], g:TagFunc1Args)
" Test for using a script local function
set tagfunc=<SID>ScriptLocalTagFunc
@ -309,7 +336,8 @@ func Test_tagfunc_callback()
" call CheckScriptSuccess(lines)
" cleanup
delfunc MytagFunc1
delfunc TagFunc1
delfunc TagFunc2
set tagfunc&
%bw!
endfunc