Mercurial > vim
diff src/testdir/test_normal.vim @ 26618:b531c26f728b v8.2.3838
patch 8.2.3838: cannot use script-local function for setting *func options
Commit: https://github.com/vim/vim/commit/db1a410b610b2c1941311acc57dcc4afec20720e
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Fri Dec 17 16:21:20 2021 +0000
patch 8.2.3838: cannot use script-local function for setting *func options
Problem: Cannot use script-local function for setting *func options.
Solution: Use the script context. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/9362)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 17 Dec 2021 17:30:04 +0100 |
parents | 255bc9a08e58 |
children | 9c9b8d95b05f |
line wrap: on
line diff
--- a/src/testdir/test_normal.vim +++ b/src/testdir/test_normal.vim @@ -575,6 +575,21 @@ func Test_opfunc_callback() END call CheckTransLegacySuccess(lines) + " Test for using a script-local function name + func s:OpFunc3(type) + let g:OpFunc3Args = [a:type] + endfunc + set opfunc=s:OpFunc3 + let g:OpFunc3Args = [] + normal! g@l + call assert_equal(['char'], g:OpFunc3Args) + + let &opfunc = 's:OpFunc3' + let g:OpFunc3Args = [] + normal! g@l + call assert_equal(['char'], g:OpFunc3Args) + delfunc s:OpFunc3 + " Using Vim9 lambda expression in legacy context should fail set opfunc=(a)\ =>\ OpFunc1(24,\ a) let g:OpFunc1Args = [] @@ -598,14 +613,32 @@ func Test_opfunc_callback() let lines =<< trim END vim9script - # Test for using a def function with opfunc def g:Vim9opFunc(val: number, type: string): void g:OpFunc1Args = [val, type] enddef + + # Test for using a def function with opfunc set opfunc=function('g:Vim9opFunc',\ [60]) g:OpFunc1Args = [] normal! g@l assert_equal([60, 'char'], g:OpFunc1Args) + + # Test for using a global function name + &opfunc = g:OpFunc2 + g:OpFunc2Args = [] + normal! g@l + assert_equal(['char'], g:OpFunc2Args) + bw! + + # Test for using a script-local function name + def s:LocalOpFunc(type: string): void + g:LocalOpFuncArgs = [type] + enddef + &opfunc = s:LocalOpFunc + g:LocalOpFuncArgs = [] + normal! g@l + assert_equal(['char'], g:LocalOpFuncArgs) + bw! END call CheckScriptSuccess(lines)