diff src/testdir/test_tagfunc.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 6fed1f1bc282
children 4c16acb2525f
line wrap: on
line diff
--- a/src/testdir/test_tagfunc.vim
+++ b/src/testdir/test_tagfunc.vim
@@ -267,38 +267,62 @@ func Test_tagfunc_callback()
   END
   call CheckLegacyAndVim9Success(lines)
 
+  " Test for using a script-local function name
+  func s:TagFunc3(pat, flags, info)
+    let g:TagFunc3Args = [a:pat, a:flags, a:info]
+    return v:null
+  endfunc
+  set tagfunc=s:TagFunc3
+  new
+  let g:TagFunc3Args = []
+  call assert_fails('tag a21', 'E433:')
+  call assert_equal(['a21', '', {}], g:TagFunc3Args)
+  bw!
+  let &tagfunc = 's:TagFunc3'
+  new
+  let g:TagFunc3Args = []
+  call assert_fails('tag a22', 'E433:')
+  call assert_equal(['a22', '', {}], g:TagFunc3Args)
+  bw!
+  delfunc s:TagFunc3
+
+  " invalid return value
   let &tagfunc = "{a -> 'abc'}"
   call assert_fails("echo taglist('a')", "E987:")
 
   " Using Vim9 lambda expression in legacy context should fail
   set tagfunc=(a,\ b,\ c)\ =>\ g:TagFunc1(21,\ a,\ b,\ c)
-  new | only
+  new
   let g:TagFunc1Args = []
   call assert_fails("tag a17", "E117:")
   call assert_equal([], g:TagFunc1Args)
+  bw!
 
   " Test for using a script local function
   set tagfunc=<SID>ScriptLocalTagFunc
-  new | only
+  new
   let g:ScriptLocalFuncArgs = []
   call assert_fails('tag a15', 'E433:')
   call assert_equal(['a15', '', {}], g:ScriptLocalFuncArgs)
+  bw!
 
   " Test for using a script local funcref variable
   let Fn = function("s:ScriptLocalTagFunc")
   let &tagfunc= Fn
-  new | only
+  new
   let g:ScriptLocalFuncArgs = []
   call assert_fails('tag a16', 'E433:')
   call assert_equal(['a16', '', {}], g:ScriptLocalFuncArgs)
+  bw!
 
   " Test for using a string(script local funcref variable)
   let Fn = function("s:ScriptLocalTagFunc")
   let &tagfunc= string(Fn)
-  new | only
+  new
   let g:ScriptLocalFuncArgs = []
   call assert_fails('tag a16', 'E433:')
   call assert_equal(['a16', '', {}], g:ScriptLocalFuncArgs)
+  bw!
 
   " set 'tagfunc' to a partial with dict. This used to cause a crash.
   func SetTagFunc()
@@ -324,16 +348,37 @@ func Test_tagfunc_callback()
   let lines =<< trim END
     vim9script
 
-    # Test for using function()
-    def Vim9tagFunc(val: number, pat: string, flags: string, info: dict<any>): any
-      g:Vim9tagFuncArgs = [val, pat, flags, info]
+    def Vim9tagFunc(callnr: number, pat: string, flags: string, info: dict<any>): any
+      g:Vim9tagFuncArgs = [callnr, pat, flags, info]
       return null
     enddef
+
+    # Test for using a def function with completefunc
     set tagfunc=function('Vim9tagFunc',\ [60])
-    new | only
+    new
     g:Vim9tagFuncArgs = []
     assert_fails('tag a10', 'E433:')
     assert_equal([60, 'a10', '', {}], g:Vim9tagFuncArgs)
+
+    # Test for using a global function name
+    &tagfunc = g:TagFunc2
+    new
+    g:TagFunc2Args = []
+    assert_fails('tag a11', 'E433:')
+    assert_equal(['a11', '', {}], g:TagFunc2Args)
+    bw!
+
+    # Test for using a script-local function name
+    def s:LocalTagFunc(pat: string, flags: string, info: dict<any> ): any
+      g:LocalTagFuncArgs = [pat, flags, info]
+      return null
+    enddef
+    &tagfunc = s:LocalTagFunc
+    new
+    g:LocalTagFuncArgs = []
+    assert_fails('tag a12', 'E433:')
+    assert_equal(['a12', '', {}], g:LocalTagFuncArgs)
+    bw!
   END
   call CheckScriptSuccess(lines)
 
@@ -344,13 +389,4 @@ func Test_tagfunc_callback()
   %bw!
 endfunc
 
-func Test_set_tagfunc_on_cmdline()
-  CheckScreendump
-
-  let buf = RunVimInTerminal(' +"set tagfunc=s:Func"', #{rows: 6, wait_for_ruler: 0})
-  call VerifyScreenDump(buf, 'Test_set_tagfunc_on_cmdline', {})
-  call StopVimInTerminal(buf)
-endfunc
-
-
 " vim: shiftwidth=2 sts=2 expandtab