Mercurial > vim
comparison src/testdir/test_tagfunc.vim @ 16447:54ffc82f38a8 v8.1.1228
patch 8.1.1228: not possible to process tags with a function
commit https://github.com/vim/vim/commit/45e18cbdc40afd8144d20dcc07ad2d981636f4c9
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Apr 28 18:05:35 2019 +0200
patch 8.1.1228: not possible to process tags with a function
Problem: Not possible to process tags with a function.
Solution: Add tagfunc() (Christian Brabandt, Andy Massimino, closes https://github.com/vim/vim/issues/4010)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 28 Apr 2019 18:15:07 +0200 |
parents | |
children | 8645b73b3645 |
comparison
equal
deleted
inserted
replaced
16446:cee0719a1b4b | 16447:54ffc82f38a8 |
---|---|
1 " Test 'tagfunc' | |
2 | |
3 func TagFunc(pat, flag, info) | |
4 let g:tagfunc_args = [a:pat, a:flag, a:info] | |
5 let tags = [] | |
6 for num in range(1,10) | |
7 let tags += [{ | |
8 \ 'cmd': '2', 'name': 'nothing'.num, 'kind': 'm', | |
9 \ 'filename': 'Xfile1', 'user_data': 'somedata'.num, | |
10 \}] | |
11 endfor | |
12 return tags | |
13 endfunc | |
14 | |
15 func Test_tagfunc() | |
16 set tagfunc=TagFunc | |
17 new Xfile1 | |
18 call setline(1, ['empty', 'one()', 'empty']) | |
19 write | |
20 | |
21 call assert_equal({'cmd': '2', 'static': 0, | |
22 \ 'name': 'nothing2', 'user_data': 'somedata2', | |
23 \ 'kind': 'm', 'filename': 'Xfile1'}, taglist('.')[1]) | |
24 | |
25 call settagstack(win_getid(), {'items': []}) | |
26 | |
27 tag arbitrary | |
28 call assert_equal('arbitrary', g:tagfunc_args[0]) | |
29 call assert_equal('', g:tagfunc_args[1]) | |
30 call assert_equal('somedata1', gettagstack().items[0].user_data) | |
31 5tag arbitrary | |
32 call assert_equal('arbitrary', g:tagfunc_args[0]) | |
33 call assert_equal('', g:tagfunc_args[1]) | |
34 call assert_equal('somedata5', gettagstack().items[1].user_data) | |
35 pop | |
36 tag | |
37 call assert_equal('arbitrary', g:tagfunc_args[0]) | |
38 call assert_equal('', g:tagfunc_args[1]) | |
39 call assert_equal('somedata5', gettagstack().items[1].user_data) | |
40 | |
41 let g:tagfunc_args=[] | |
42 execute "normal! \<c-]>" | |
43 call assert_equal('one', g:tagfunc_args[0]) | |
44 call assert_equal('c', g:tagfunc_args[1]) | |
45 | |
46 set cpt=t | |
47 let g:tagfunc_args=[] | |
48 execute "normal! i\<c-n>\<c-y>" | |
49 call assert_equal('ci', g:tagfunc_args[1]) | |
50 call assert_equal('nothing1', getline('.')[0:7]) | |
51 | |
52 func BadTagFunc1(...) | |
53 return 0 | |
54 endfunc | |
55 func BadTagFunc2(...) | |
56 return [1] | |
57 endfunc | |
58 func BadTagFunc3(...) | |
59 return [{'name': 'foo'}] | |
60 endfunc | |
61 | |
62 for &tagfunc in ['BadTagFunc1', 'BadTagFunc2', 'BadTagFunc3'] | |
63 try | |
64 tag nothing | |
65 call assert_false(1, 'tag command should have failed') | |
66 catch | |
67 call assert_exception('E987:') | |
68 endtry | |
69 exe 'delf' &tagfunc | |
70 endfor | |
71 | |
72 func NullTagFunc(...) | |
73 return v:null | |
74 endfunc | |
75 set tags= tfu=NullTagFunc | |
76 call assert_fails('tag nothing', 'E426') | |
77 delf NullTagFunc | |
78 | |
79 bwipe! | |
80 set tags& tfu& cpt& | |
81 call delete('Xfile1') | |
82 endfunc | |
83 | |
84 " vim: shiftwidth=2 sts=2 expandtab |