mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.3792: setting *func options insufficiently tested
Problem: Setting *func options insufficiently tested. Solution: Impove tests. (Yegappan Lakshmanan, closes #9337)
This commit is contained in:
parent
d2439e0443
commit
04ef1fb13d
@ -125,6 +125,11 @@ func Test_imactivatefunc_imstatusfunc_callback()
|
|||||||
LET g:IMactivatefunc_called = 0
|
LET g:IMactivatefunc_called = 0
|
||||||
LET g:IMstatusfunc_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()
|
#" Test for using a function()
|
||||||
set imactivatefunc=function('g:IMactivatefunc1')
|
set imactivatefunc=function('g:IMactivatefunc1')
|
||||||
set imstatusfunc=function('g:IMstatusfunc1')
|
set imstatusfunc=function('g:IMstatusfunc1')
|
||||||
@ -215,8 +220,8 @@ func Test_imactivatefunc_imstatusfunc_callback()
|
|||||||
call assert_fails("LET &imstatusfunc = function('NonExistingFunc')", 'E700:')
|
call assert_fails("LET &imstatusfunc = function('NonExistingFunc')", 'E700:')
|
||||||
normal! i
|
normal! i
|
||||||
|
|
||||||
call assert_equal(13, g:IMactivatefunc_called)
|
call assert_equal(14, g:IMactivatefunc_called)
|
||||||
call assert_equal(26, g:IMstatusfunc_called)
|
call assert_equal(28, g:IMstatusfunc_called)
|
||||||
END
|
END
|
||||||
call CheckLegacyAndVim9Success(lines)
|
call CheckLegacyAndVim9Success(lines)
|
||||||
|
|
||||||
@ -283,12 +288,12 @@ func Test_imactivatefunc_imstatusfunc_callback()
|
|||||||
call CheckScriptSuccess(lines)
|
call CheckScriptSuccess(lines)
|
||||||
|
|
||||||
" cleanup
|
" cleanup
|
||||||
|
set iminsert=0
|
||||||
|
set imactivatefunc&
|
||||||
|
set imstatusfunc&
|
||||||
delfunc IMactivatefunc1
|
delfunc IMactivatefunc1
|
||||||
delfunc IMstatusfunc1
|
delfunc IMstatusfunc1
|
||||||
set iminsert=0
|
unlet g:IMactivatefunc_called g:IMstatusfunc_called
|
||||||
set imactivatefunc=
|
|
||||||
set imstatusfunc=
|
|
||||||
|
|
||||||
%bw!
|
%bw!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@ -870,123 +870,136 @@ endfunc
|
|||||||
|
|
||||||
" Test for different ways of setting the 'completefunc' option
|
" Test for different ways of setting the 'completefunc' option
|
||||||
func Test_completefunc_callback()
|
func Test_completefunc_callback()
|
||||||
func MycompleteFunc1(val, findstart, base)
|
func CompleteFunc1(callnr, findstart, base)
|
||||||
call add(g:MycompleteFunc1_args, [a:val, a:findstart, a: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 : []
|
return a:findstart ? 0 : []
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
let lines =<< trim END
|
let lines =<< trim END
|
||||||
#" Test for using a function()
|
#" Test for using a function name
|
||||||
set completefunc=function('g:MycompleteFunc1',\ [10])
|
LET &completefunc = 'g:CompleteFunc2'
|
||||||
new | only
|
new
|
||||||
call setline(1, 'one')
|
call setline(1, 'zero')
|
||||||
LET g:MycompleteFunc1_args = []
|
LET g:CompleteFunc2Args = []
|
||||||
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Using a funcref variable to set 'completefunc'
|
#" Using a funcref variable to set 'completefunc'
|
||||||
VAR Fn = function('g:MycompleteFunc1', [11])
|
VAR Fn = function('g:CompleteFunc1', [11])
|
||||||
LET &completefunc = Fn
|
LET &completefunc = Fn
|
||||||
new | only
|
new
|
||||||
call setline(1, 'two')
|
call setline(1, 'two')
|
||||||
LET g:MycompleteFunc1_args = []
|
LET g:CompleteFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Using string(funcref_variable) to set 'completefunc'
|
#" Using string(funcref_variable) to set 'completefunc'
|
||||||
LET Fn = function('g:MycompleteFunc1', [12])
|
LET Fn = function('g:CompleteFunc1', [12])
|
||||||
LET &completefunc = string(Fn)
|
LET &completefunc = string(Fn)
|
||||||
new | only
|
new
|
||||||
call setline(1, 'two')
|
call setline(1, 'two')
|
||||||
LET g:MycompleteFunc1_args = []
|
LET g:CompleteFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Test for using a funcref()
|
#" Test for using a funcref()
|
||||||
set completefunc=funcref('g:MycompleteFunc1',\ [13])
|
set completefunc=funcref('g:CompleteFunc1',\ [13])
|
||||||
new | only
|
new
|
||||||
call setline(1, 'three')
|
call setline(1, 'three')
|
||||||
LET g:MycompleteFunc1_args = []
|
LET g:CompleteFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Using a funcref variable to set 'completefunc'
|
#" Using a funcref variable to set 'completefunc'
|
||||||
LET Fn = funcref('g:MycompleteFunc1', [14])
|
LET Fn = funcref('g:CompleteFunc1', [14])
|
||||||
LET &completefunc = Fn
|
LET &completefunc = Fn
|
||||||
new | only
|
new
|
||||||
call setline(1, 'four')
|
call setline(1, 'four')
|
||||||
LET g:MycompleteFunc1_args = []
|
LET g:CompleteFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Using a string(funcref_variable) to set 'completefunc'
|
#" Using a string(funcref_variable) to set 'completefunc'
|
||||||
LET Fn = funcref('g:MycompleteFunc1', [15])
|
LET Fn = funcref('g:CompleteFunc1', [15])
|
||||||
LET &completefunc = string(Fn)
|
LET &completefunc = string(Fn)
|
||||||
new | only
|
new
|
||||||
call setline(1, 'four')
|
call setline(1, 'four')
|
||||||
LET g:MycompleteFunc1_args = []
|
LET g:CompleteFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Test for using a lambda function with set
|
#" 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')
|
LET optval = substitute(optval, ' ', '\\ ', 'g')
|
||||||
exe "set completefunc=" .. optval
|
exe "set completefunc=" .. optval
|
||||||
new | only
|
new
|
||||||
call setline(1, 'five')
|
call setline(1, 'five')
|
||||||
LET g:MycompleteFunc1_args = []
|
LET g:CompleteFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Set 'completefunc' to a lambda expression
|
#" Set 'completefunc' to a lambda expression
|
||||||
LET &completefunc = LSTART a, b LMIDDLE MycompleteFunc1(17, a, b) LEND
|
LET &completefunc = LSTART a, b LMIDDLE CompleteFunc1(17, a, b) LEND
|
||||||
new | only
|
new
|
||||||
call setline(1, 'six')
|
call setline(1, 'six')
|
||||||
LET g:MycompleteFunc1_args = []
|
LET g:CompleteFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Set 'completefunc' to string(lambda_expression)
|
#" Set 'completefunc' to string(lambda_expression)
|
||||||
LET &completefunc = 'LSTART a, b LMIDDLE MycompleteFunc1(18, a, b) LEND'
|
LET &completefunc = 'LSTART a, b LMIDDLE CompleteFunc1(18, a, b) LEND'
|
||||||
new | only
|
new
|
||||||
call setline(1, 'six')
|
call setline(1, 'six')
|
||||||
LET g:MycompleteFunc1_args = []
|
LET g:CompleteFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Set 'completefunc' to a variable with a lambda expression
|
#" 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
|
LET &completefunc = Lambda
|
||||||
new | only
|
new
|
||||||
call setline(1, 'seven')
|
call setline(1, 'seven')
|
||||||
LET g:MycompleteFunc1_args = []
|
LET g:CompleteFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Set 'completefunc' to a string(variable with a lambda expression)
|
#" 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)
|
LET &completefunc = string(Lambda)
|
||||||
new | only
|
new
|
||||||
call setline(1, 'seven')
|
call setline(1, 'seven')
|
||||||
LET g:MycompleteFunc1_args = []
|
LET g:CompleteFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Test for using a lambda function with incorrect return value
|
#" Test for using a lambda function with incorrect return value
|
||||||
LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND
|
LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND
|
||||||
LET &completefunc = Lambda
|
LET &completefunc = Lambda
|
||||||
new | only
|
new
|
||||||
call setline(1, 'eight')
|
call setline(1, 'eight')
|
||||||
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
||||||
bw!
|
bw!
|
||||||
@ -998,17 +1011,13 @@ func Test_completefunc_callback()
|
|||||||
call assert_fails("set completefunc=funcref('abc')", "E700:")
|
call assert_fails("set completefunc=funcref('abc')", "E700:")
|
||||||
|
|
||||||
#" set 'completefunc' to a non-existing function
|
#" set 'completefunc' to a non-existing function
|
||||||
func MycompleteFunc2(findstart, base)
|
set completefunc=CompleteFunc2
|
||||||
call add(g:MycompleteFunc2_args, [a:findstart, a:base])
|
|
||||||
return a:findstart ? 0 : []
|
|
||||||
endfunc
|
|
||||||
set completefunc=MycompleteFunc2
|
|
||||||
call setline(1, 'five')
|
call setline(1, 'five')
|
||||||
call assert_fails("set completefunc=function('NonExistingFunc')", 'E700:')
|
call assert_fails("set completefunc=function('NonExistingFunc')", 'E700:')
|
||||||
call assert_fails("LET &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 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!
|
bw!
|
||||||
END
|
END
|
||||||
call CheckLegacyAndVim9Success(lines)
|
call CheckLegacyAndVim9Success(lines)
|
||||||
@ -1017,11 +1026,11 @@ func Test_completefunc_callback()
|
|||||||
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
||||||
|
|
||||||
" Using Vim9 lambda expression in legacy context should fail
|
" 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
|
new | only
|
||||||
let g:MycompleteFunc1_args = []
|
let g:CompleteFunc1Args = []
|
||||||
call assert_fails('call feedkeys("A\<C-X>\<C-U>\<Esc>", "x")', 'E117:')
|
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.
|
" set 'completefunc' to a partial with dict. This used to cause a crash.
|
||||||
func SetCompleteFunc()
|
func SetCompleteFunc()
|
||||||
@ -1063,131 +1072,145 @@ func Test_completefunc_callback()
|
|||||||
call CheckScriptSuccess(lines)
|
call CheckScriptSuccess(lines)
|
||||||
|
|
||||||
" cleanup
|
" cleanup
|
||||||
delfunc MycompleteFunc1
|
|
||||||
delfunc MycompleteFunc2
|
|
||||||
set completefunc&
|
set completefunc&
|
||||||
|
delfunc CompleteFunc1
|
||||||
|
delfunc CompleteFunc2
|
||||||
|
unlet g:CompleteFunc1Args g:CompleteFunc2Args
|
||||||
%bw!
|
%bw!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test for different ways of setting the 'omnifunc' option
|
" Test for different ways of setting the 'omnifunc' option
|
||||||
func Test_omnifunc_callback()
|
func Test_omnifunc_callback()
|
||||||
func MyomniFunc1(val, findstart, base)
|
func OmniFunc1(callnr, findstart, base)
|
||||||
call add(g:MyomniFunc1_args, [a:val, a:findstart, a: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 : []
|
return a:findstart ? 0 : []
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
let lines =<< trim END
|
let lines =<< trim END
|
||||||
#" Test for using a function()
|
#" Test for using a function name
|
||||||
set omnifunc=function('g:MyomniFunc1',\ [10])
|
LET &omnifunc = 'g:OmniFunc2'
|
||||||
new | only
|
new
|
||||||
call setline(1, 'one')
|
call setline(1, 'zero')
|
||||||
LET g:MyomniFunc1_args = []
|
LET g:OmniFunc2Args = []
|
||||||
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Using a funcref variable to set 'omnifunc'
|
#" Using a funcref variable to set 'omnifunc'
|
||||||
VAR Fn = function('g:MyomniFunc1', [11])
|
VAR Fn = function('g:OmniFunc1', [11])
|
||||||
LET &omnifunc = Fn
|
LET &omnifunc = Fn
|
||||||
new | only
|
new
|
||||||
call setline(1, 'two')
|
call setline(1, 'two')
|
||||||
LET g:MyomniFunc1_args = []
|
LET g:OmniFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Using a string(funcref_variable) to set 'omnifunc'
|
#" Using a string(funcref_variable) to set 'omnifunc'
|
||||||
LET Fn = function('g:MyomniFunc1', [12])
|
LET Fn = function('g:OmniFunc1', [12])
|
||||||
LET &omnifunc = string(Fn)
|
LET &omnifunc = string(Fn)
|
||||||
new | only
|
new
|
||||||
call setline(1, 'two')
|
call setline(1, 'two')
|
||||||
LET g:MyomniFunc1_args = []
|
LET g:OmniFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Test for using a funcref()
|
#" Test for using a funcref()
|
||||||
set omnifunc=funcref('g:MyomniFunc1',\ [13])
|
set omnifunc=funcref('g:OmniFunc1',\ [13])
|
||||||
new | only
|
new
|
||||||
call setline(1, 'three')
|
call setline(1, 'three')
|
||||||
LET g:MyomniFunc1_args = []
|
LET g:OmniFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Use let to set 'omnifunc' to a funcref
|
#" Use let to set 'omnifunc' to a funcref
|
||||||
LET Fn = funcref('g:MyomniFunc1', [14])
|
LET Fn = funcref('g:OmniFunc1', [14])
|
||||||
LET &omnifunc = Fn
|
LET &omnifunc = Fn
|
||||||
new | only
|
new
|
||||||
call setline(1, 'four')
|
call setline(1, 'four')
|
||||||
LET g:MyomniFunc1_args = []
|
LET g:OmniFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Using a string(funcref) to set 'omnifunc'
|
#" Using a string(funcref) to set 'omnifunc'
|
||||||
LET Fn = funcref("g:MyomniFunc1", [15])
|
LET Fn = funcref("g:OmniFunc1", [15])
|
||||||
LET &omnifunc = string(Fn)
|
LET &omnifunc = string(Fn)
|
||||||
new | only
|
new
|
||||||
call setline(1, 'four')
|
call setline(1, 'four')
|
||||||
LET g:MyomniFunc1_args = []
|
LET g:OmniFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Test for using a lambda function with set
|
#" 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')
|
LET optval = substitute(optval, ' ', '\\ ', 'g')
|
||||||
exe "set omnifunc=" .. optval
|
exe "set omnifunc=" .. optval
|
||||||
new | only
|
new
|
||||||
call setline(1, 'five')
|
call setline(1, 'five')
|
||||||
LET g:MyomniFunc1_args = []
|
LET g:OmniFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Set 'omnifunc' to a lambda expression
|
#" Set 'omnifunc' to a lambda expression
|
||||||
LET &omnifunc = LSTART a, b LMIDDLE MyomniFunc1(17, a, b) LEND
|
LET &omnifunc = LSTART a, b LMIDDLE OmniFunc1(17, a, b) LEND
|
||||||
new | only
|
new
|
||||||
call setline(1, 'six')
|
call setline(1, 'six')
|
||||||
LET g:MyomniFunc1_args = []
|
LET g:OmniFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Set 'omnifunc' to a string(lambda_expression)
|
#" Set 'omnifunc' to a string(lambda_expression)
|
||||||
LET &omnifunc = 'LSTART a, b LMIDDLE MyomniFunc1(18, a, b) LEND'
|
LET &omnifunc = 'LSTART a, b LMIDDLE OmniFunc1(18, a, b) LEND'
|
||||||
new | only
|
new
|
||||||
call setline(1, 'six')
|
call setline(1, 'six')
|
||||||
LET g:MyomniFunc1_args = []
|
LET g:OmniFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Set 'omnifunc' to a variable with a lambda expression
|
#" 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
|
LET &omnifunc = Lambda
|
||||||
new | only
|
new
|
||||||
call setline(1, 'seven')
|
call setline(1, 'seven')
|
||||||
LET g:MyomniFunc1_args = []
|
LET g:OmniFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Set 'omnifunc' to a string(variable with a lambda expression)
|
#" 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)
|
LET &omnifunc = string(Lambda)
|
||||||
new | only
|
new
|
||||||
call setline(1, 'seven')
|
call setline(1, 'seven')
|
||||||
LET g:MyomniFunc1_args = []
|
LET g:OmniFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Test for using a lambda function with incorrect return value
|
#" Test for using a lambda function with incorrect return value
|
||||||
LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND
|
LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND
|
||||||
LET &omnifunc = Lambda
|
LET &omnifunc = Lambda
|
||||||
new | only
|
new
|
||||||
call setline(1, 'eight')
|
call setline(1, 'eight')
|
||||||
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
||||||
bw!
|
bw!
|
||||||
@ -1199,17 +1222,13 @@ func Test_omnifunc_callback()
|
|||||||
call assert_fails("set omnifunc=funcref('abc')", "E700:")
|
call assert_fails("set omnifunc=funcref('abc')", "E700:")
|
||||||
|
|
||||||
#" set 'omnifunc' to a non-existing function
|
#" set 'omnifunc' to a non-existing function
|
||||||
func MyomniFunc2(findstart, base)
|
set omnifunc=OmniFunc2
|
||||||
call add(g:MyomniFunc2_args, [a:findstart, a:base])
|
|
||||||
return a:findstart ? 0 : []
|
|
||||||
endfunc
|
|
||||||
set omnifunc=MyomniFunc2
|
|
||||||
call setline(1, 'nine')
|
call setline(1, 'nine')
|
||||||
call assert_fails("set omnifunc=function('NonExistingFunc')", 'E700:')
|
call assert_fails("set omnifunc=function('NonExistingFunc')", 'E700:')
|
||||||
call assert_fails("LET &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 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!
|
bw!
|
||||||
END
|
END
|
||||||
call CheckLegacyAndVim9Success(lines)
|
call CheckLegacyAndVim9Success(lines)
|
||||||
@ -1218,11 +1237,11 @@ func Test_omnifunc_callback()
|
|||||||
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
||||||
|
|
||||||
" Using Vim9 lambda expression in legacy context should fail
|
" 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
|
new | only
|
||||||
let g:MyomniFunc1_args = []
|
let g:OmniFunc1Args = []
|
||||||
call assert_fails('call feedkeys("A\<C-X>\<C-O>\<Esc>", "x")', 'E117:')
|
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.
|
" set 'omnifunc' to a partial with dict. This used to cause a crash.
|
||||||
func SetOmniFunc()
|
func SetOmniFunc()
|
||||||
@ -1264,131 +1283,145 @@ func Test_omnifunc_callback()
|
|||||||
call CheckScriptSuccess(lines)
|
call CheckScriptSuccess(lines)
|
||||||
|
|
||||||
" cleanup
|
" cleanup
|
||||||
delfunc MyomniFunc1
|
|
||||||
delfunc MyomniFunc2
|
|
||||||
set omnifunc&
|
set omnifunc&
|
||||||
|
delfunc OmniFunc1
|
||||||
|
delfunc OmniFunc2
|
||||||
|
unlet g:OmniFunc1Args g:OmniFunc2Args
|
||||||
%bw!
|
%bw!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test for different ways of setting the 'thesaurusfunc' option
|
" Test for different ways of setting the 'thesaurusfunc' option
|
||||||
func Test_thesaurusfunc_callback()
|
func Test_thesaurusfunc_callback()
|
||||||
func MytsrFunc1(val, findstart, base)
|
func TsrFunc1(callnr, findstart, base)
|
||||||
call add(g:MytsrFunc1_args, [a:val, a:findstart, a:base])
|
call add(g:TsrFunc1Args, [a:callnr, a:findstart, a:base])
|
||||||
return a:findstart ? 0 : []
|
return a:findstart ? 0 : []
|
||||||
endfunc
|
endfunc
|
||||||
|
func TsrFunc2(findstart, base)
|
||||||
|
call add(g:TsrFunc2Args, [a:findstart, a:base])
|
||||||
|
return a:findstart ? 0 : ['sunday']
|
||||||
|
endfunc
|
||||||
|
|
||||||
let lines =<< trim END
|
let lines =<< trim END
|
||||||
#" Test for using a function()
|
#" Test for using a function name
|
||||||
set thesaurusfunc=function('g:MytsrFunc1',\ [10])
|
LET &thesaurusfunc = 'g:TsrFunc2'
|
||||||
new | only
|
new
|
||||||
call setline(1, 'one')
|
call setline(1, 'zero')
|
||||||
LET g:MytsrFunc1_args = []
|
LET g:TsrFunc2Args = []
|
||||||
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Using a funcref variable to set 'thesaurusfunc'
|
#" Using a funcref variable to set 'thesaurusfunc'
|
||||||
VAR Fn = function('g:MytsrFunc1', [11])
|
VAR Fn = function('g:TsrFunc1', [11])
|
||||||
LET &thesaurusfunc = Fn
|
LET &thesaurusfunc = Fn
|
||||||
new | only
|
new
|
||||||
call setline(1, 'two')
|
call setline(1, 'two')
|
||||||
LET g:MytsrFunc1_args = []
|
LET g:TsrFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Using a string(funcref_variable) to set 'thesaurusfunc'
|
#" Using a string(funcref_variable) to set 'thesaurusfunc'
|
||||||
LET Fn = function('g:MytsrFunc1', [12])
|
LET Fn = function('g:TsrFunc1', [12])
|
||||||
LET &thesaurusfunc = string(Fn)
|
LET &thesaurusfunc = string(Fn)
|
||||||
new | only
|
new
|
||||||
call setline(1, 'two')
|
call setline(1, 'two')
|
||||||
LET g:MytsrFunc1_args = []
|
LET g:TsrFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Test for using a funcref()
|
#" Test for using a funcref()
|
||||||
set thesaurusfunc=funcref('g:MytsrFunc1',\ [13])
|
set thesaurusfunc=funcref('g:TsrFunc1',\ [13])
|
||||||
new | only
|
new
|
||||||
call setline(1, 'three')
|
call setline(1, 'three')
|
||||||
LET g:MytsrFunc1_args = []
|
LET g:TsrFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Using a funcref variable to set 'thesaurusfunc'
|
#" Using a funcref variable to set 'thesaurusfunc'
|
||||||
LET Fn = funcref('g:MytsrFunc1', [14])
|
LET Fn = funcref('g:TsrFunc1', [14])
|
||||||
LET &thesaurusfunc = Fn
|
LET &thesaurusfunc = Fn
|
||||||
new | only
|
new
|
||||||
call setline(1, 'four')
|
call setline(1, 'four')
|
||||||
LET g:MytsrFunc1_args = []
|
LET g:TsrFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Using a string(funcref_variable) to set 'thesaurusfunc'
|
#" Using a string(funcref_variable) to set 'thesaurusfunc'
|
||||||
LET Fn = funcref('g:MytsrFunc1', [15])
|
LET Fn = funcref('g:TsrFunc1', [15])
|
||||||
LET &thesaurusfunc = string(Fn)
|
LET &thesaurusfunc = string(Fn)
|
||||||
new | only
|
new
|
||||||
call setline(1, 'four')
|
call setline(1, 'four')
|
||||||
LET g:MytsrFunc1_args = []
|
LET g:TsrFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Test for using a lambda function
|
#" 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')
|
LET optval = substitute(optval, ' ', '\\ ', 'g')
|
||||||
exe "set thesaurusfunc=" .. optval
|
exe "set thesaurusfunc=" .. optval
|
||||||
new | only
|
new
|
||||||
call setline(1, 'five')
|
call setline(1, 'five')
|
||||||
LET g:MytsrFunc1_args = []
|
LET g:TsrFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Test for using a lambda function with set
|
#" Test for using a lambda function with set
|
||||||
LET &thesaurusfunc = LSTART a, b LMIDDLE MytsrFunc1(17, a, b) LEND
|
LET &thesaurusfunc = LSTART a, b LMIDDLE TsrFunc1(17, a, b) LEND
|
||||||
new | only
|
new
|
||||||
call setline(1, 'six')
|
call setline(1, 'six')
|
||||||
LET g:MytsrFunc1_args = []
|
LET g:TsrFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Set 'thesaurusfunc' to a string(lambda expression)
|
#" Set 'thesaurusfunc' to a string(lambda expression)
|
||||||
LET &thesaurusfunc = 'LSTART a, b LMIDDLE MytsrFunc1(18, a, b) LEND'
|
LET &thesaurusfunc = 'LSTART a, b LMIDDLE TsrFunc1(18, a, b) LEND'
|
||||||
new | only
|
new
|
||||||
call setline(1, 'six')
|
call setline(1, 'six')
|
||||||
LET g:MytsrFunc1_args = []
|
LET g:TsrFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Set 'thesaurusfunc' to a variable with a lambda expression
|
#" 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
|
LET &thesaurusfunc = Lambda
|
||||||
new | only
|
new
|
||||||
call setline(1, 'seven')
|
call setline(1, 'seven')
|
||||||
LET g:MytsrFunc1_args = []
|
LET g:TsrFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Set 'thesaurusfunc' to a string(variable with a lambda expression)
|
#" 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)
|
LET &thesaurusfunc = string(Lambda)
|
||||||
new | only
|
new
|
||||||
call setline(1, 'seven')
|
call setline(1, 'seven')
|
||||||
LET g:MytsrFunc1_args = []
|
LET g:TsrFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
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!
|
bw!
|
||||||
|
|
||||||
#" Test for using a lambda function with incorrect return value
|
#" Test for using a lambda function with incorrect return value
|
||||||
LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND
|
LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND
|
||||||
LET &thesaurusfunc = Lambda
|
LET &thesaurusfunc = Lambda
|
||||||
new | only
|
new
|
||||||
call setline(1, 'eight')
|
call setline(1, 'eight')
|
||||||
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
||||||
bw!
|
bw!
|
||||||
@ -1400,40 +1433,36 @@ func Test_thesaurusfunc_callback()
|
|||||||
call assert_fails("set thesaurusfunc=funcref('abc')", "E700:")
|
call assert_fails("set thesaurusfunc=funcref('abc')", "E700:")
|
||||||
|
|
||||||
#" set 'thesaurusfunc' to a non-existing function
|
#" set 'thesaurusfunc' to a non-existing function
|
||||||
func MytsrFunc2(findstart, base)
|
set thesaurusfunc=TsrFunc2
|
||||||
call add(g:MytsrFunc2_args, [a:findstart, a:base])
|
|
||||||
return a:findstart ? 0 : ['sunday']
|
|
||||||
endfunc
|
|
||||||
set thesaurusfunc=MytsrFunc2
|
|
||||||
call setline(1, 'ten')
|
call setline(1, 'ten')
|
||||||
call assert_fails("set thesaurusfunc=function('NonExistingFunc')", 'E700:')
|
call assert_fails("set thesaurusfunc=function('NonExistingFunc')", 'E700:')
|
||||||
call assert_fails("LET &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 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!
|
bw!
|
||||||
|
|
||||||
#" Use a buffer-local value and a global value
|
#" Use a buffer-local value and a global value
|
||||||
set thesaurusfunc&
|
set thesaurusfunc&
|
||||||
setlocal thesaurusfunc=function('g:MytsrFunc1',\ [22])
|
setlocal thesaurusfunc=function('g:TsrFunc1',\ [22])
|
||||||
call setline(1, 'sun')
|
call setline(1, 'sun')
|
||||||
LET g:MytsrFunc1_args = []
|
LET g:TsrFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")
|
||||||
call assert_equal('sun', getline(1))
|
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
|
new
|
||||||
call setline(1, 'sun')
|
call setline(1, 'sun')
|
||||||
LET g:MytsrFunc1_args = []
|
LET g:TsrFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")
|
||||||
call assert_equal('sun', getline(1))
|
call assert_equal('sun', getline(1))
|
||||||
call assert_equal([], g:MytsrFunc1_args)
|
call assert_equal([], g:TsrFunc1Args)
|
||||||
set thesaurusfunc=function('g:MytsrFunc1',\ [23])
|
set thesaurusfunc=function('g:TsrFunc1',\ [23])
|
||||||
wincmd w
|
wincmd w
|
||||||
call setline(1, 'sun')
|
call setline(1, 'sun')
|
||||||
LET g:MytsrFunc1_args = []
|
LET g:TsrFunc1Args = []
|
||||||
call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")
|
||||||
call assert_equal('sun', getline(1))
|
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!
|
:%bw!
|
||||||
END
|
END
|
||||||
call CheckLegacyAndVim9Success(lines)
|
call CheckLegacyAndVim9Success(lines)
|
||||||
@ -1442,11 +1471,11 @@ func Test_thesaurusfunc_callback()
|
|||||||
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
||||||
|
|
||||||
" Using Vim9 lambda expression in legacy context should fail
|
" 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
|
new | only
|
||||||
let g:MytsrFunc1_args = []
|
let g:TsrFunc1Args = []
|
||||||
call assert_fails('call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")', 'E117:')
|
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!
|
bw!
|
||||||
|
|
||||||
" set 'thesaurusfunc' to a partial with dict. This used to cause a crash.
|
" set 'thesaurusfunc' to a partial with dict. This used to cause a crash.
|
||||||
@ -1502,8 +1531,9 @@ func Test_thesaurusfunc_callback()
|
|||||||
|
|
||||||
" cleanup
|
" cleanup
|
||||||
set thesaurusfunc&
|
set thesaurusfunc&
|
||||||
delfunc MytsrFunc1
|
delfunc TsrFunc1
|
||||||
delfunc MytsrFunc2
|
delfunc TsrFunc2
|
||||||
|
unlet g:TsrFunc1Args g:TsrFunc2Args
|
||||||
%bw!
|
%bw!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@ -444,110 +444,120 @@ endfunc
|
|||||||
" Test for different ways of setting the 'operatorfunc' option
|
" Test for different ways of setting the 'operatorfunc' option
|
||||||
func Test_opfunc_callback()
|
func Test_opfunc_callback()
|
||||||
new
|
new
|
||||||
func MyopFunc(val, type)
|
func OpFunc1(callnr, type)
|
||||||
let g:OpFuncArgs = [a:val, a:type]
|
let g:OpFunc1Args = [a:callnr, a:type]
|
||||||
|
endfunc
|
||||||
|
func OpFunc2(type)
|
||||||
|
let g:OpFunc2Args = [a:type]
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
let lines =<< trim END
|
let lines =<< trim END
|
||||||
#" Test for using a function()
|
#" Test for using a function name
|
||||||
set opfunc=function('g:MyopFunc',\ [10])
|
LET &opfunc = 'g:OpFunc2'
|
||||||
LET g:OpFuncArgs = []
|
LET g:OpFunc2Args = []
|
||||||
normal! g@l
|
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'
|
#" Using a funcref variable to set 'operatorfunc'
|
||||||
VAR Fn = function('g:MyopFunc', [11])
|
VAR Fn = function('g:OpFunc1', [11])
|
||||||
LET &opfunc = Fn
|
LET &opfunc = Fn
|
||||||
LET g:OpFuncArgs = []
|
LET g:OpFunc1Args = []
|
||||||
normal! g@l
|
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'
|
#" 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 &operatorfunc = string(Fn)
|
||||||
LET g:OpFuncArgs = []
|
LET g:OpFunc1Args = []
|
||||||
normal! g@l
|
normal! g@l
|
||||||
call assert_equal([12, 'char'], g:OpFuncArgs)
|
call assert_equal([12, 'char'], g:OpFunc1Args)
|
||||||
|
|
||||||
#" Test for using a funcref()
|
#" Test for using a funcref()
|
||||||
set operatorfunc=funcref('g:MyopFunc',\ [13])
|
set operatorfunc=funcref('g:OpFunc1',\ [13])
|
||||||
LET g:OpFuncArgs = []
|
LET g:OpFunc1Args = []
|
||||||
normal! g@l
|
normal! g@l
|
||||||
call assert_equal([13, 'char'], g:OpFuncArgs)
|
call assert_equal([13, 'char'], g:OpFunc1Args)
|
||||||
|
|
||||||
#" Using a funcref variable to set 'operatorfunc'
|
#" Using a funcref variable to set 'operatorfunc'
|
||||||
LET Fn = funcref('g:MyopFunc', [14])
|
LET Fn = funcref('g:OpFunc1', [14])
|
||||||
LET &opfunc = Fn
|
LET &opfunc = Fn
|
||||||
LET g:OpFuncArgs = []
|
LET g:OpFunc1Args = []
|
||||||
normal! g@l
|
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'
|
#" 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 &opfunc = string(Fn)
|
||||||
LET g:OpFuncArgs = []
|
LET g:OpFunc1Args = []
|
||||||
normal! g@l
|
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
|
#" 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')
|
LET optval = substitute(optval, ' ', '\\ ', 'g')
|
||||||
exe "set opfunc=" .. optval
|
exe "set opfunc=" .. optval
|
||||||
LET g:OpFuncArgs = []
|
LET g:OpFunc1Args = []
|
||||||
normal! g@l
|
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
|
#" Test for using a lambda function using LET
|
||||||
LET &opfunc = LSTART a LMIDDLE MyopFunc(17, a) LEND
|
LET &opfunc = LSTART a LMIDDLE OpFunc1(17, a) LEND
|
||||||
LET g:OpFuncArgs = []
|
LET g:OpFunc1Args = []
|
||||||
normal! g@l
|
normal! g@l
|
||||||
call assert_equal([17, 'char'], g:OpFuncArgs)
|
call assert_equal([17, 'char'], g:OpFunc1Args)
|
||||||
|
|
||||||
#" Set 'operatorfunc' to a string(lambda expression)
|
#" Set 'operatorfunc' to a string(lambda expression)
|
||||||
LET &opfunc = 'LSTART a LMIDDLE MyopFunc(18, a) LEND'
|
LET &opfunc = 'LSTART a LMIDDLE OpFunc1(18, a) LEND'
|
||||||
LET g:OpFuncArgs = []
|
LET g:OpFunc1Args = []
|
||||||
normal! g@l
|
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
|
#" 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 &opfunc = Lambda
|
||||||
LET g:OpFuncArgs = []
|
LET g:OpFunc1Args = []
|
||||||
normal! g@l
|
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)
|
#" 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 &opfunc = string(Lambda)
|
||||||
LET g:OpFuncArgs = []
|
LET g:OpFunc1Args = []
|
||||||
normal! g@l
|
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
|
#" Try to use 'operatorfunc' after the function is deleted
|
||||||
func g:TmpOpFunc(type)
|
func g:TmpOpFunc1(type)
|
||||||
LET g:OpFuncArgs = [21, a:type]
|
let g:TmpOpFunc1Args = [21, a:type]
|
||||||
endfunc
|
endfunc
|
||||||
LET &opfunc = function('g:TmpOpFunc')
|
LET &opfunc = function('g:TmpOpFunc1')
|
||||||
delfunc g:TmpOpFunc
|
delfunc g:TmpOpFunc1
|
||||||
call test_garbagecollect_now()
|
call test_garbagecollect_now()
|
||||||
LET g:OpFuncArgs = []
|
LET g:TmpOpFunc1Args = []
|
||||||
call assert_fails('normal! g@l', 'E117:')
|
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'
|
#" Try to use a function with two arguments for 'operatorfunc'
|
||||||
func MyopFunc2(x, y)
|
func g:TmpOpFunc2(x, y)
|
||||||
LET g:OpFuncArgs = [a:x, a:y]
|
let g:TmpOpFunc2Args = [a:x, a:y]
|
||||||
endfunc
|
endfunc
|
||||||
set opfunc=MyopFunc2
|
set opfunc=TmpOpFunc2
|
||||||
LET g:OpFuncArgs = []
|
LET g:TmpOpFunc2Args = []
|
||||||
call assert_fails('normal! g@l', 'E119:')
|
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'
|
#" Try to use a lambda function with two arguments for 'operatorfunc'
|
||||||
LET &opfunc = LSTART a, b LMIDDLE MyopFunc(22, b) LEND
|
LET &opfunc = LSTART a, b LMIDDLE OpFunc1(22, b) LEND
|
||||||
LET g:OpFuncArgs = []
|
LET g:OpFunc1Args = []
|
||||||
call assert_fails('normal! g@l', 'E119:')
|
call assert_fails('normal! g@l', 'E119:')
|
||||||
call assert_equal([], g:OpFuncArgs)
|
call assert_equal([], g:OpFunc1Args)
|
||||||
|
|
||||||
#" Test for clearing the 'operatorfunc' option
|
#" Test for clearing the 'operatorfunc' option
|
||||||
set opfunc=''
|
set opfunc=''
|
||||||
@ -556,20 +566,20 @@ func Test_opfunc_callback()
|
|||||||
call assert_fails("set opfunc=funcref('abc')", "E700:")
|
call assert_fails("set opfunc=funcref('abc')", "E700:")
|
||||||
|
|
||||||
#" set 'operatorfunc' to a non-existing function
|
#" 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("set opfunc=function('NonExistingFunc')", 'E700:')
|
||||||
call assert_fails("LET &opfunc = function('NonExistingFunc')", 'E700:')
|
call assert_fails("LET &opfunc = function('NonExistingFunc')", 'E700:')
|
||||||
LET g:OpFuncArgs = []
|
LET g:OpFunc1Args = []
|
||||||
normal! g@l
|
normal! g@l
|
||||||
call assert_equal([23, 'char'], g:OpFuncArgs)
|
call assert_equal([23, 'char'], g:OpFunc1Args)
|
||||||
END
|
END
|
||||||
call CheckTransLegacySuccess(lines)
|
call CheckTransLegacySuccess(lines)
|
||||||
|
|
||||||
" Using Vim9 lambda expression in legacy context should fail
|
" Using Vim9 lambda expression in legacy context should fail
|
||||||
set opfunc=(a)\ =>\ MyopFunc(24,\ a)
|
set opfunc=(a)\ =>\ OpFunc1(24,\ a)
|
||||||
let g:OpFuncArgs = []
|
let g:OpFunc1Args = []
|
||||||
call assert_fails('normal! g@l', 'E117:')
|
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.
|
" set 'operatorfunc' to a partial with dict. This used to cause a crash.
|
||||||
func SetOpFunc()
|
func SetOpFunc()
|
||||||
@ -590,20 +600,20 @@ func Test_opfunc_callback()
|
|||||||
|
|
||||||
# Test for using a def function with opfunc
|
# Test for using a def function with opfunc
|
||||||
def g:Vim9opFunc(val: number, type: string): void
|
def g:Vim9opFunc(val: number, type: string): void
|
||||||
g:OpFuncArgs = [val, type]
|
g:OpFunc1Args = [val, type]
|
||||||
enddef
|
enddef
|
||||||
set opfunc=function('g:Vim9opFunc',\ [60])
|
set opfunc=function('g:Vim9opFunc',\ [60])
|
||||||
g:OpFuncArgs = []
|
g:OpFunc1Args = []
|
||||||
normal! g@l
|
normal! g@l
|
||||||
assert_equal([60, 'char'], g:OpFuncArgs)
|
assert_equal([60, 'char'], g:OpFunc1Args)
|
||||||
END
|
END
|
||||||
call CheckScriptSuccess(lines)
|
call CheckScriptSuccess(lines)
|
||||||
|
|
||||||
" cleanup
|
" cleanup
|
||||||
set opfunc&
|
set opfunc&
|
||||||
delfunc MyopFunc
|
delfunc OpFunc1
|
||||||
delfunc MyopFunc2
|
delfunc OpFunc2
|
||||||
unlet g:OpFuncArgs
|
unlet g:OpFunc1Args g:OpFunc2Args
|
||||||
%bw!
|
%bw!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@ -5287,6 +5287,13 @@ func Test_qftextfunc_callback()
|
|||||||
let lines =<< trim END
|
let lines =<< trim END
|
||||||
set efm=%f:%l:%c:%m
|
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()
|
#" Test for using a function()
|
||||||
set qftf=function('g:Tqfexpr')
|
set qftf=function('g:Tqfexpr')
|
||||||
cexpr "F1:1:1:L1"
|
cexpr "F1:1:1:L1"
|
||||||
|
@ -127,102 +127,126 @@ endfunc
|
|||||||
|
|
||||||
" Test for different ways of setting the 'tagfunc' option
|
" Test for different ways of setting the 'tagfunc' option
|
||||||
func Test_tagfunc_callback()
|
func Test_tagfunc_callback()
|
||||||
func MytagFunc1(val, pat, flags, info)
|
func TagFunc1(callnr, pat, flags, info)
|
||||||
let g:MytagFunc1_args = [a:val, a:pat, a:flags, a: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
|
return v:null
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
let lines =<< trim END
|
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()
|
#" Test for using a function()
|
||||||
set tagfunc=function('g:MytagFunc1',\ [10])
|
set tagfunc=function('g:TagFunc1',\ [10])
|
||||||
new | only
|
new
|
||||||
LET g:MytagFunc1_args = []
|
LET g:TagFunc1Args = []
|
||||||
call assert_fails('tag a11', 'E433:')
|
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'
|
#" Using a funcref variable to set 'tagfunc'
|
||||||
VAR Fn = function('g:MytagFunc1', [11])
|
VAR Fn = function('g:TagFunc1', [11])
|
||||||
LET &tagfunc = Fn
|
LET &tagfunc = Fn
|
||||||
new | only
|
new
|
||||||
LET g:MytagFunc1_args = []
|
LET g:TagFunc1Args = []
|
||||||
call assert_fails('tag a12', 'E433:')
|
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'
|
#" Using a string(funcref_variable) to set 'tagfunc'
|
||||||
LET Fn = function('g:MytagFunc1', [12])
|
LET Fn = function('g:TagFunc1', [12])
|
||||||
LET &tagfunc = string(Fn)
|
LET &tagfunc = string(Fn)
|
||||||
new | only
|
new
|
||||||
LET g:MytagFunc1_args = []
|
LET g:TagFunc1Args = []
|
||||||
call assert_fails('tag a12', 'E433:')
|
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()
|
#" Test for using a funcref()
|
||||||
set tagfunc=funcref('g:MytagFunc1',\ [13])
|
set tagfunc=funcref('g:TagFunc1',\ [13])
|
||||||
new | only
|
new
|
||||||
LET g:MytagFunc1_args = []
|
LET g:TagFunc1Args = []
|
||||||
call assert_fails('tag a13', 'E433:')
|
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'
|
#" Using a funcref variable to set 'tagfunc'
|
||||||
LET Fn = funcref('g:MytagFunc1', [14])
|
LET Fn = funcref('g:TagFunc1', [14])
|
||||||
LET &tagfunc = Fn
|
LET &tagfunc = Fn
|
||||||
new | only
|
new
|
||||||
LET g:MytagFunc1_args = []
|
LET g:TagFunc1Args = []
|
||||||
call assert_fails('tag a14', 'E433:')
|
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'
|
#" Using a string(funcref_variable) to set 'tagfunc'
|
||||||
LET Fn = funcref('g:MytagFunc1', [15])
|
LET Fn = funcref('g:TagFunc1', [15])
|
||||||
LET &tagfunc = string(Fn)
|
LET &tagfunc = string(Fn)
|
||||||
new | only
|
new
|
||||||
LET g:MytagFunc1_args = []
|
LET g:TagFunc1Args = []
|
||||||
call assert_fails('tag a14', 'E433:')
|
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
|
#" 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')
|
LET optval = substitute(optval, ' ', '\\ ', 'g')
|
||||||
exe "set tagfunc=" .. optval
|
exe "set tagfunc=" .. optval
|
||||||
new | only
|
new
|
||||||
LET g:MytagFunc1_args = []
|
LET g:TagFunc1Args = []
|
||||||
call assert_fails('tag a17', 'E433:')
|
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
|
#" Set 'tagfunc' to a lambda expression
|
||||||
LET &tagfunc = LSTART a, b, c LMIDDLE MytagFunc1(17, a, b, c) LEND
|
LET &tagfunc = LSTART a, b, c LMIDDLE TagFunc1(17, a, b, c) LEND
|
||||||
new | only
|
new
|
||||||
LET g:MytagFunc1_args = []
|
LET g:TagFunc1Args = []
|
||||||
call assert_fails('tag a18', 'E433:')
|
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)
|
#" Set 'tagfunc' to a string(lambda expression)
|
||||||
LET &tagfunc = 'LSTART a, b, c LMIDDLE MytagFunc1(18, a, b, c) LEND'
|
LET &tagfunc = 'LSTART a, b, c LMIDDLE TagFunc1(18, a, b, c) LEND'
|
||||||
new | only
|
new
|
||||||
LET g:MytagFunc1_args = []
|
LET g:TagFunc1Args = []
|
||||||
call assert_fails('tag a18', 'E433:')
|
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
|
#" 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
|
LET &tagfunc = Lambda
|
||||||
new | only
|
new
|
||||||
LET g:MytagFunc1_args = []
|
LET g:TagFunc1Args = []
|
||||||
call assert_fails("tag a19", "E433:")
|
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)
|
#" 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)
|
LET &tagfunc = string(Lambda)
|
||||||
new | only
|
new
|
||||||
LET g:MytagFunc1_args = []
|
LET g:TagFunc1Args = []
|
||||||
call assert_fails("tag a19", "E433:")
|
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
|
#" Test for using a lambda function with incorrect return value
|
||||||
LET Lambda = LSTART a, b, c LMIDDLE strlen(a) LEND
|
LET Lambda = LSTART a, b, c LMIDDLE strlen(a) LEND
|
||||||
LET &tagfunc = string(Lambda)
|
LET &tagfunc = string(Lambda)
|
||||||
new | only
|
new
|
||||||
call assert_fails("tag a20", "E987:")
|
call assert_fails("tag a20", "E987:")
|
||||||
|
bw!
|
||||||
|
|
||||||
#" Test for clearing the 'tagfunc' option
|
#" Test for clearing the 'tagfunc' option
|
||||||
set tagfunc=''
|
set tagfunc=''
|
||||||
@ -231,10 +255,13 @@ func Test_tagfunc_callback()
|
|||||||
call assert_fails("set tagfunc=funcref('abc')", "E700:")
|
call assert_fails("set tagfunc=funcref('abc')", "E700:")
|
||||||
|
|
||||||
#" set 'tagfunc' to a non-existing function
|
#" 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("set tagfunc=function('NonExistingFunc')", 'E700:')
|
||||||
call assert_fails("LET &tagfunc = function('NonExistingFunc')", 'E700:')
|
call assert_fails("LET &tagfunc = function('NonExistingFunc')", 'E700:')
|
||||||
call assert_fails("tag axb123", 'E426:')
|
call assert_fails("tag axb123", 'E426:')
|
||||||
|
call assert_equal([], g:TagFunc2Args)
|
||||||
|
bw!
|
||||||
END
|
END
|
||||||
call CheckLegacyAndVim9Success(lines)
|
call CheckLegacyAndVim9Success(lines)
|
||||||
|
|
||||||
@ -242,11 +269,11 @@ func Test_tagfunc_callback()
|
|||||||
call assert_fails("echo taglist('a')", "E987:")
|
call assert_fails("echo taglist('a')", "E987:")
|
||||||
|
|
||||||
" Using Vim9 lambda expression in legacy context should fail
|
" 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
|
new | only
|
||||||
let g:MytagFunc1_args = []
|
let g:TagFunc1Args = []
|
||||||
call assert_fails("tag a17", "E117:")
|
call assert_fails("tag a17", "E117:")
|
||||||
call assert_equal([], g:MytagFunc1_args)
|
call assert_equal([], g:TagFunc1Args)
|
||||||
|
|
||||||
" Test for using a script local function
|
" Test for using a script local function
|
||||||
set tagfunc=<SID>ScriptLocalTagFunc
|
set tagfunc=<SID>ScriptLocalTagFunc
|
||||||
@ -309,7 +336,8 @@ func Test_tagfunc_callback()
|
|||||||
call CheckScriptSuccess(lines)
|
call CheckScriptSuccess(lines)
|
||||||
|
|
||||||
" cleanup
|
" cleanup
|
||||||
delfunc MytagFunc1
|
delfunc TagFunc1
|
||||||
|
delfunc TagFunc2
|
||||||
set tagfunc&
|
set tagfunc&
|
||||||
%bw!
|
%bw!
|
||||||
endfunc
|
endfunc
|
||||||
|
@ -753,6 +753,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
3792,
|
||||||
/**/
|
/**/
|
||||||
3791,
|
3791,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user