annotate src/testdir/test_tagfunc.vim @ 30867:0913cd44fdfa v9.0.0768

patch 9.0.0768: too many delete() calls in tests Commit: https://github.com/vim/vim/commit/5b148ef2628251b2d79f78c65a614f8aca404329 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Oct 15 21:35:56 2022 +0100 patch 9.0.0768: too many delete() calls in tests Problem: Too many delete() calls in tests. Solution: Use deferred delete where possible.
author Bram Moolenaar <Bram@vim.org>
date Sat, 15 Oct 2022 22:45:02 +0200
parents c8ebe35b2475
children dbec60b8c253
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16447
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Test 'tagfunc'
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26618
diff changeset
3 import './vim9.vim' as v9
26600
6fed1f1bc282 patch 8.2.3829: no error when setting a func option to script-local function
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
4 source check.vim
6fed1f1bc282 patch 8.2.3829: no error when setting a func option to script-local function
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
5 source screendump.vim
26362
dbe615b75f15 patch 8.2.3712: cannot use Vim9 lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26268
diff changeset
6
16447
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 func TagFunc(pat, flag, info)
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 let g:tagfunc_args = [a:pat, a:flag, a:info]
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 let tags = []
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 for num in range(1,10)
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 let tags += [{
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 \ 'cmd': '2', 'name': 'nothing'.num, 'kind': 'm',
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 \ 'filename': 'Xfile1', 'user_data': 'somedata'.num,
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 \}]
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 endfor
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 return tags
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 endfunc
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 func Test_tagfunc()
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 set tagfunc=TagFunc
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 new Xfile1
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 call setline(1, ['empty', 'one()', 'empty'])
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 write
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 call assert_equal({'cmd': '2', 'static': 0,
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 \ 'name': 'nothing2', 'user_data': 'somedata2',
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 \ 'kind': 'm', 'filename': 'Xfile1'}, taglist('.')[1])
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 call settagstack(win_getid(), {'items': []})
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 tag arbitrary
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 call assert_equal('arbitrary', g:tagfunc_args[0])
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 call assert_equal('', g:tagfunc_args[1])
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 call assert_equal('somedata1', gettagstack().items[0].user_data)
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 5tag arbitrary
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 call assert_equal('arbitrary', g:tagfunc_args[0])
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 call assert_equal('', g:tagfunc_args[1])
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 call assert_equal('somedata5', gettagstack().items[1].user_data)
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 pop
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 tag
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 call assert_equal('arbitrary', g:tagfunc_args[0])
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 call assert_equal('', g:tagfunc_args[1])
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 call assert_equal('somedata5', gettagstack().items[1].user_data)
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 let g:tagfunc_args=[]
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 execute "normal! \<c-]>"
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 call assert_equal('one', g:tagfunc_args[0])
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 call assert_equal('c', g:tagfunc_args[1])
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49
24186
4902263c302e patch 8.2.2634: 'tagfunc' does not indicate using a pattern
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
50 let g:tagfunc_args=[]
4902263c302e patch 8.2.2634: 'tagfunc' does not indicate using a pattern
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
51 execute "tag /foo$"
4902263c302e patch 8.2.2634: 'tagfunc' does not indicate using a pattern
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
52 call assert_equal('foo$', g:tagfunc_args[0])
4902263c302e patch 8.2.2634: 'tagfunc' does not indicate using a pattern
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
53 call assert_equal('r', g:tagfunc_args[1])
4902263c302e patch 8.2.2634: 'tagfunc' does not indicate using a pattern
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
54
16447
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 set cpt=t
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 let g:tagfunc_args=[]
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 execute "normal! i\<c-n>\<c-y>"
24186
4902263c302e patch 8.2.2634: 'tagfunc' does not indicate using a pattern
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
58 call assert_equal('\<\k\k', g:tagfunc_args[0])
4902263c302e patch 8.2.2634: 'tagfunc' does not indicate using a pattern
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
59 call assert_equal('cir', g:tagfunc_args[1])
16447
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 call assert_equal('nothing1', getline('.')[0:7])
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61
24186
4902263c302e patch 8.2.2634: 'tagfunc' does not indicate using a pattern
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
62 let g:tagfunc_args=[]
4902263c302e patch 8.2.2634: 'tagfunc' does not indicate using a pattern
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
63 execute "normal! ono\<c-n>\<c-n>\<c-y>"
4902263c302e patch 8.2.2634: 'tagfunc' does not indicate using a pattern
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
64 call assert_equal('\<no', g:tagfunc_args[0])
4902263c302e patch 8.2.2634: 'tagfunc' does not indicate using a pattern
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
65 call assert_equal('cir', g:tagfunc_args[1])
4902263c302e patch 8.2.2634: 'tagfunc' does not indicate using a pattern
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
66 call assert_equal('nothing2', getline('.')[0:7])
4902263c302e patch 8.2.2634: 'tagfunc' does not indicate using a pattern
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
67
16447
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 func BadTagFunc1(...)
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 return 0
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 endfunc
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 func BadTagFunc2(...)
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 return [1]
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 endfunc
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 func BadTagFunc3(...)
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 return [{'name': 'foo'}]
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 endfunc
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 for &tagfunc in ['BadTagFunc1', 'BadTagFunc2', 'BadTagFunc3']
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 try
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 tag nothing
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 call assert_false(1, 'tag command should have failed')
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 catch
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 call assert_exception('E987:')
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 endtry
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 exe 'delf' &tagfunc
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 endfor
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 func NullTagFunc(...)
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 return v:null
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 endfunc
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 set tags= tfu=NullTagFunc
22087
ff21e2962490 patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
92 call assert_fails('tag nothing', 'E433:')
16447
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 delf NullTagFunc
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 bwipe!
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 set tags& tfu& cpt&
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 call delete('Xfile1')
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 endfunc
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99
19055
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 16447
diff changeset
100 " Test for modifying the tag stack from a tag function and jumping to a tag
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 16447
diff changeset
101 " from a tag function
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 16447
diff changeset
102 func Test_tagfunc_settagstack()
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 16447
diff changeset
103 func Mytagfunc1(pat, flags, info)
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 16447
diff changeset
104 call settagstack(1, {'tagname' : 'mytag', 'from' : [0, 10, 1, 0]})
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 16447
diff changeset
105 return [{'name' : 'mytag', 'filename' : 'Xtest', 'cmd' : '1'}]
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 16447
diff changeset
106 endfunc
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 16447
diff changeset
107 set tagfunc=Mytagfunc1
30865
c8ebe35b2475 patch 9.0.0767: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents: 30106
diff changeset
108 call writefile([''], 'Xtest', 'D')
19055
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 16447
diff changeset
109 call assert_fails('tag xyz', 'E986:')
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 16447
diff changeset
110
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 16447
diff changeset
111 func Mytagfunc2(pat, flags, info)
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 16447
diff changeset
112 tag test_tag
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 16447
diff changeset
113 return [{'name' : 'mytag', 'filename' : 'Xtest', 'cmd' : '1'}]
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 16447
diff changeset
114 endfunc
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 16447
diff changeset
115 set tagfunc=Mytagfunc2
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 16447
diff changeset
116 call assert_fails('tag xyz', 'E986:')
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 16447
diff changeset
117
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 16447
diff changeset
118 set tagfunc&
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 16447
diff changeset
119 delfunc Mytagfunc1
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 16447
diff changeset
120 delfunc Mytagfunc2
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 16447
diff changeset
121 endfunc
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 16447
diff changeset
122
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26362
diff changeset
123 " Script local tagfunc callback function
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26362
diff changeset
124 func s:ScriptLocalTagFunc(pat, flags, info)
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26362
diff changeset
125 let g:ScriptLocalFuncArgs = [a:pat, a:flags, a:info]
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26362
diff changeset
126 return v:null
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26362
diff changeset
127 endfunc
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26362
diff changeset
128
26268
3aa48d4e3dc8 patch 8.2.3665: cannot use a lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents: 24186
diff changeset
129 " Test for different ways of setting the 'tagfunc' option
3aa48d4e3dc8 patch 8.2.3665: cannot use a lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents: 24186
diff changeset
130 func Test_tagfunc_callback()
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
131 func TagFunc1(callnr, pat, flags, info)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
132 let g:TagFunc1Args = [a:callnr, a:pat, a:flags, a:info]
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
133 return v:null
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
134 endfunc
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
135 func TagFunc2(pat, flags, info)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
136 let g:TagFunc2Args = [a:pat, a:flags, a:info]
26268
3aa48d4e3dc8 patch 8.2.3665: cannot use a lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents: 24186
diff changeset
137 return v:null
3aa48d4e3dc8 patch 8.2.3665: cannot use a lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents: 24186
diff changeset
138 endfunc
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
139
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
140 let lines =<< trim END
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
141 #" Test for using a function name
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
142 LET &tagfunc = 'g:TagFunc2'
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
143 new
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
144 LET g:TagFunc2Args = []
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
145 call assert_fails('tag a10', 'E433:')
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
146 call assert_equal(['a10', '', {}], g:TagFunc2Args)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
147 bw!
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
148
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
149 #" Test for using a function()
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
150 set tagfunc=function('g:TagFunc1',\ [10])
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
151 new
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
152 LET g:TagFunc1Args = []
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
153 call assert_fails('tag a11', 'E433:')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
154 call assert_equal([10, 'a11', '', {}], g:TagFunc1Args)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
155 bw!
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
156
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
157 #" Using a funcref variable to set 'tagfunc'
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
158 VAR Fn = function('g:TagFunc1', [11])
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
159 LET &tagfunc = Fn
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
160 new
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
161 LET g:TagFunc1Args = []
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
162 call assert_fails('tag a12', 'E433:')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
163 call assert_equal([11, 'a12', '', {}], g:TagFunc1Args)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
164 bw!
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
165
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
166 #" Using a string(funcref_variable) to set 'tagfunc'
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
167 LET Fn = function('g:TagFunc1', [12])
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
168 LET &tagfunc = string(Fn)
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
169 new
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
170 LET g:TagFunc1Args = []
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
171 call assert_fails('tag a12', 'E433:')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
172 call assert_equal([12, 'a12', '', {}], g:TagFunc1Args)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
173 bw!
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
174
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
175 #" Test for using a funcref()
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
176 set tagfunc=funcref('g:TagFunc1',\ [13])
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
177 new
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
178 LET g:TagFunc1Args = []
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
179 call assert_fails('tag a13', 'E433:')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
180 call assert_equal([13, 'a13', '', {}], g:TagFunc1Args)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
181 bw!
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
182
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
183 #" Using a funcref variable to set 'tagfunc'
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
184 LET Fn = funcref('g:TagFunc1', [14])
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
185 LET &tagfunc = Fn
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
186 new
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
187 LET g:TagFunc1Args = []
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
188 call assert_fails('tag a14', 'E433:')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
189 call assert_equal([14, 'a14', '', {}], g:TagFunc1Args)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
190 bw!
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
191
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
192 #" Using a string(funcref_variable) to set 'tagfunc'
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
193 LET Fn = funcref('g:TagFunc1', [15])
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
194 LET &tagfunc = string(Fn)
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
195 new
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
196 LET g:TagFunc1Args = []
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
197 call assert_fails('tag a14', 'E433:')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
198 call assert_equal([15, 'a14', '', {}], g:TagFunc1Args)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
199 bw!
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
200
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
201 #" Test for using a lambda function
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26618
diff changeset
202 VAR optval = "LSTART a, b, c LMIDDLE g:TagFunc1(16, a, b, c) LEND"
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
203 LET optval = substitute(optval, ' ', '\\ ', 'g')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
204 exe "set tagfunc=" .. optval
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
205 new
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
206 LET g:TagFunc1Args = []
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
207 call assert_fails('tag a17', 'E433:')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
208 call assert_equal([16, 'a17', '', {}], g:TagFunc1Args)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
209 bw!
26362
dbe615b75f15 patch 8.2.3712: cannot use Vim9 lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26268
diff changeset
210
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
211 #" Set 'tagfunc' to a lambda expression
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26618
diff changeset
212 LET &tagfunc = LSTART a, b, c LMIDDLE g:TagFunc1(17, a, b, c) LEND
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
213 new
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
214 LET g:TagFunc1Args = []
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
215 call assert_fails('tag a18', 'E433:')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
216 call assert_equal([17, 'a18', '', {}], g:TagFunc1Args)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
217 bw!
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
218
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
219 #" Set 'tagfunc' to a string(lambda expression)
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26618
diff changeset
220 LET &tagfunc = 'LSTART a, b, c LMIDDLE g:TagFunc1(18, a, b, c) LEND'
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
221 new
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
222 LET g:TagFunc1Args = []
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
223 call assert_fails('tag a18', 'E433:')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
224 call assert_equal([18, 'a18', '', {}], g:TagFunc1Args)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
225 bw!
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
226
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
227 #" Set 'tagfunc' to a variable with a lambda expression
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26618
diff changeset
228 VAR Lambda = LSTART a, b, c LMIDDLE g:TagFunc1(19, a, b, c) LEND
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
229 LET &tagfunc = Lambda
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
230 new
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
231 LET g:TagFunc1Args = []
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
232 call assert_fails("tag a19", "E433:")
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
233 call assert_equal([19, 'a19', '', {}], g:TagFunc1Args)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
234 bw!
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26388
diff changeset
235
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
236 #" Set 'tagfunc' to a string(variable with a lambda expression)
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26618
diff changeset
237 LET Lambda = LSTART a, b, c LMIDDLE g:TagFunc1(20, a, b, c) LEND
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
238 LET &tagfunc = string(Lambda)
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
239 new
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
240 LET g:TagFunc1Args = []
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
241 call assert_fails("tag a19", "E433:")
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
242 call assert_equal([20, 'a19', '', {}], g:TagFunc1Args)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
243 bw!
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
244
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
245 #" Test for using a lambda function with incorrect return value
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
246 LET Lambda = LSTART a, b, c LMIDDLE strlen(a) LEND
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
247 LET &tagfunc = string(Lambda)
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
248 new
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
249 call assert_fails("tag a20", "E987:")
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
250 bw!
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
251
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
252 #" Test for clearing the 'tagfunc' option
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
253 set tagfunc=''
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
254 set tagfunc&
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
255 call assert_fails("set tagfunc=function('abc')", "E700:")
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
256 call assert_fails("set tagfunc=funcref('abc')", "E700:")
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
257
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
258 #" set 'tagfunc' to a non-existing function
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
259 LET &tagfunc = function('g:TagFunc2', [21])
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
260 LET g:TagFunc2Args = []
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
261 call assert_fails("set tagfunc=function('NonExistingFunc')", 'E700:')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
262 call assert_fails("LET &tagfunc = function('NonExistingFunc')", 'E700:')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
263 call assert_fails("tag axb123", 'E426:')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
264 call assert_equal([], g:TagFunc2Args)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
265 bw!
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
266 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26618
diff changeset
267 call v9.CheckLegacyAndVim9Success(lines)
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
268
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
269 " Test for using a script-local function name
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
270 func s:TagFunc3(pat, flags, info)
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
271 let g:TagFunc3Args = [a:pat, a:flags, a:info]
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
272 return v:null
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
273 endfunc
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
274 set tagfunc=s:TagFunc3
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
275 new
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
276 let g:TagFunc3Args = []
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
277 call assert_fails('tag a21', 'E433:')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
278 call assert_equal(['a21', '', {}], g:TagFunc3Args)
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
279 bw!
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
280 let &tagfunc = 's:TagFunc3'
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
281 new
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
282 let g:TagFunc3Args = []
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
283 call assert_fails('tag a22', 'E433:')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
284 call assert_equal(['a22', '', {}], g:TagFunc3Args)
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
285 bw!
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
286 delfunc s:TagFunc3
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
287
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
288 " invalid return value
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
289 let &tagfunc = "{a -> 'abc'}"
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
290 call assert_fails("echo taglist('a')", "E987:")
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
291
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
292 " Using Vim9 lambda expression in legacy context should fail
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
293 set tagfunc=(a,\ b,\ c)\ =>\ g:TagFunc1(21,\ a,\ b,\ c)
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
294 new
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
295 let g:TagFunc1Args = []
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
296 call assert_fails("tag a17", "E117:")
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
297 call assert_equal([], g:TagFunc1Args)
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
298 bw!
26268
3aa48d4e3dc8 patch 8.2.3665: cannot use a lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents: 24186
diff changeset
299
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26362
diff changeset
300 " Test for using a script local function
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26362
diff changeset
301 set tagfunc=<SID>ScriptLocalTagFunc
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
302 new
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26362
diff changeset
303 let g:ScriptLocalFuncArgs = []
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26362
diff changeset
304 call assert_fails('tag a15', 'E433:')
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26362
diff changeset
305 call assert_equal(['a15', '', {}], g:ScriptLocalFuncArgs)
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
306 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26362
diff changeset
307
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26362
diff changeset
308 " Test for using a script local funcref variable
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26362
diff changeset
309 let Fn = function("s:ScriptLocalTagFunc")
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26388
diff changeset
310 let &tagfunc= Fn
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
311 new
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26388
diff changeset
312 let g:ScriptLocalFuncArgs = []
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26388
diff changeset
313 call assert_fails('tag a16', 'E433:')
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26388
diff changeset
314 call assert_equal(['a16', '', {}], g:ScriptLocalFuncArgs)
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
315 bw!
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26388
diff changeset
316
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26388
diff changeset
317 " Test for using a string(script local funcref variable)
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26388
diff changeset
318 let Fn = function("s:ScriptLocalTagFunc")
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26362
diff changeset
319 let &tagfunc= string(Fn)
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
320 new
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26362
diff changeset
321 let g:ScriptLocalFuncArgs = []
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26362
diff changeset
322 call assert_fails('tag a16', 'E433:')
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26362
diff changeset
323 call assert_equal(['a16', '', {}], g:ScriptLocalFuncArgs)
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
324 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26362
diff changeset
325
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
326 " set 'tagfunc' to a partial with dict. This used to cause a crash.
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
327 func SetTagFunc()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
328 let params = {'tagfn': function('g:DictTagFunc')}
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
329 let &tagfunc = params.tagfn
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
330 endfunc
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
331 func g:DictTagFunc(_) dict
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
332 endfunc
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
333 call SetTagFunc()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
334 new
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
335 call SetTagFunc()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
336 bw
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
337 call test_garbagecollect_now()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
338 new
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
339 set tagfunc=
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
340 wincmd w
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
341 set tagfunc=
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
342 :%bw!
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
343 delfunc g:DictTagFunc
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
344 delfunc SetTagFunc
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
345
26362
dbe615b75f15 patch 8.2.3712: cannot use Vim9 lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26268
diff changeset
346 " Vim9 tests
dbe615b75f15 patch 8.2.3712: cannot use Vim9 lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26268
diff changeset
347 let lines =<< trim END
dbe615b75f15 patch 8.2.3712: cannot use Vim9 lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26268
diff changeset
348 vim9script
dbe615b75f15 patch 8.2.3712: cannot use Vim9 lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26268
diff changeset
349
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
350 def Vim9tagFunc(callnr: number, pat: string, flags: string, info: dict<any>): any
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
351 g:Vim9tagFuncArgs = [callnr, pat, flags, info]
26362
dbe615b75f15 patch 8.2.3712: cannot use Vim9 lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26268
diff changeset
352 return null
dbe615b75f15 patch 8.2.3712: cannot use Vim9 lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26268
diff changeset
353 enddef
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
354
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
355 # Test for using a def function with completefunc
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
356 set tagfunc=function('Vim9tagFunc',\ [60])
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
357 new
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
358 g:Vim9tagFuncArgs = []
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
359 assert_fails('tag a10', 'E433:')
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
360 assert_equal([60, 'a10', '', {}], g:Vim9tagFuncArgs)
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
361
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
362 # Test for using a global function name
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
363 &tagfunc = g:TagFunc2
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
364 new
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
365 g:TagFunc2Args = []
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
366 assert_fails('tag a11', 'E433:')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
367 assert_equal(['a11', '', {}], g:TagFunc2Args)
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
368 bw!
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
369
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
370 # Test for using a script-local function name
27671
19367412787c patch 8.2.4361: Vim9: some tests fail
Bram Moolenaar <Bram@vim.org>
parents: 27457
diff changeset
371 def LocalTagFunc(pat: string, flags: string, info: dict<any> ): any
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
372 g:LocalTagFuncArgs = [pat, flags, info]
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
373 return null
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
374 enddef
27671
19367412787c patch 8.2.4361: Vim9: some tests fail
Bram Moolenaar <Bram@vim.org>
parents: 27457
diff changeset
375 &tagfunc = LocalTagFunc
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
376 new
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
377 g:LocalTagFuncArgs = []
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
378 assert_fails('tag a12', 'E433:')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
379 assert_equal(['a12', '', {}], g:LocalTagFuncArgs)
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26600
diff changeset
380 bw!
26362
dbe615b75f15 patch 8.2.3712: cannot use Vim9 lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26268
diff changeset
381 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26618
diff changeset
382 call v9.CheckScriptSuccess(lines)
26362
dbe615b75f15 patch 8.2.3712: cannot use Vim9 lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26268
diff changeset
383
26268
3aa48d4e3dc8 patch 8.2.3665: cannot use a lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents: 24186
diff changeset
384 " cleanup
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
385 delfunc TagFunc1
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
386 delfunc TagFunc2
26362
dbe615b75f15 patch 8.2.3712: cannot use Vim9 lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26268
diff changeset
387 set tagfunc&
26268
3aa48d4e3dc8 patch 8.2.3665: cannot use a lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents: 24186
diff changeset
388 %bw!
3aa48d4e3dc8 patch 8.2.3665: cannot use a lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents: 24186
diff changeset
389 endfunc
3aa48d4e3dc8 patch 8.2.3665: cannot use a lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents: 24186
diff changeset
390
29814
1aec47ab35f0 patch 9.0.0246: using freed memory when 'tagfunc' deletes the buffer
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
391 func Test_tagfunc_wipes_buffer()
1aec47ab35f0 patch 9.0.0246: using freed memory when 'tagfunc' deletes the buffer
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
392 func g:Tag0unc0(t,f,o)
1aec47ab35f0 patch 9.0.0246: using freed memory when 'tagfunc' deletes the buffer
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
393 bwipe
1aec47ab35f0 patch 9.0.0246: using freed memory when 'tagfunc' deletes the buffer
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
394 endfunc
1aec47ab35f0 patch 9.0.0246: using freed memory when 'tagfunc' deletes the buffer
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
395 set tagfunc=g:Tag0unc0
1aec47ab35f0 patch 9.0.0246: using freed memory when 'tagfunc' deletes the buffer
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
396 new
1aec47ab35f0 patch 9.0.0246: using freed memory when 'tagfunc' deletes the buffer
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
397 cal assert_fails('tag 0', 'E987:')
1aec47ab35f0 patch 9.0.0246: using freed memory when 'tagfunc' deletes the buffer
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
398
1aec47ab35f0 patch 9.0.0246: using freed memory when 'tagfunc' deletes the buffer
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
399 delfunc g:Tag0unc0
1aec47ab35f0 patch 9.0.0246: using freed memory when 'tagfunc' deletes the buffer
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
400 set tagfunc=
1aec47ab35f0 patch 9.0.0246: using freed memory when 'tagfunc' deletes the buffer
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
401 endfunc
1aec47ab35f0 patch 9.0.0246: using freed memory when 'tagfunc' deletes the buffer
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
402
30106
0e9b58353412 patch 9.0.0389: crash when 'tagfunc' closes the window
Bram Moolenaar <Bram@vim.org>
parents: 29814
diff changeset
403 func Test_tagfunc_closes_window()
0e9b58353412 patch 9.0.0389: crash when 'tagfunc' closes the window
Bram Moolenaar <Bram@vim.org>
parents: 29814
diff changeset
404 split any
0e9b58353412 patch 9.0.0389: crash when 'tagfunc' closes the window
Bram Moolenaar <Bram@vim.org>
parents: 29814
diff changeset
405 func MytagfuncClose(pat, flags, info)
0e9b58353412 patch 9.0.0389: crash when 'tagfunc' closes the window
Bram Moolenaar <Bram@vim.org>
parents: 29814
diff changeset
406 close
0e9b58353412 patch 9.0.0389: crash when 'tagfunc' closes the window
Bram Moolenaar <Bram@vim.org>
parents: 29814
diff changeset
407 return [{'name' : 'mytag', 'filename' : 'Xtest', 'cmd' : '1'}]
0e9b58353412 patch 9.0.0389: crash when 'tagfunc' closes the window
Bram Moolenaar <Bram@vim.org>
parents: 29814
diff changeset
408 endfunc
0e9b58353412 patch 9.0.0389: crash when 'tagfunc' closes the window
Bram Moolenaar <Bram@vim.org>
parents: 29814
diff changeset
409 set tagfunc=MytagfuncClose
0e9b58353412 patch 9.0.0389: crash when 'tagfunc' closes the window
Bram Moolenaar <Bram@vim.org>
parents: 29814
diff changeset
410 call assert_fails('tag xyz', 'E1299:')
0e9b58353412 patch 9.0.0389: crash when 'tagfunc' closes the window
Bram Moolenaar <Bram@vim.org>
parents: 29814
diff changeset
411
0e9b58353412 patch 9.0.0389: crash when 'tagfunc' closes the window
Bram Moolenaar <Bram@vim.org>
parents: 29814
diff changeset
412 set tagfunc=
0e9b58353412 patch 9.0.0389: crash when 'tagfunc' closes the window
Bram Moolenaar <Bram@vim.org>
parents: 29814
diff changeset
413 endfunc
0e9b58353412 patch 9.0.0389: crash when 'tagfunc' closes the window
Bram Moolenaar <Bram@vim.org>
parents: 29814
diff changeset
414
0e9b58353412 patch 9.0.0389: crash when 'tagfunc' closes the window
Bram Moolenaar <Bram@vim.org>
parents: 29814
diff changeset
415
16447
54ffc82f38a8 patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 " vim: shiftwidth=2 sts=2 expandtab