1" Test 'tagfunc' 2 3func 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 13endfunc 14 15func 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 let g:tagfunc_args=[] 47 execute "tag /foo$" 48 call assert_equal('foo$', g:tagfunc_args[0]) 49 call assert_equal('r', g:tagfunc_args[1]) 50 51 set cpt=t 52 let g:tagfunc_args=[] 53 execute "normal! i\<c-n>\<c-y>" 54 call assert_equal('\<\k\k', g:tagfunc_args[0]) 55 call assert_equal('cir', g:tagfunc_args[1]) 56 call assert_equal('nothing1', getline('.')[0:7]) 57 58 let g:tagfunc_args=[] 59 execute "normal! ono\<c-n>\<c-n>\<c-y>" 60 call assert_equal('\<no', g:tagfunc_args[0]) 61 call assert_equal('cir', g:tagfunc_args[1]) 62 call assert_equal('nothing2', getline('.')[0:7]) 63 64 func BadTagFunc1(...) 65 return 0 66 endfunc 67 func BadTagFunc2(...) 68 return [1] 69 endfunc 70 func BadTagFunc3(...) 71 return [{'name': 'foo'}] 72 endfunc 73 74 for &tagfunc in ['BadTagFunc1', 'BadTagFunc2', 'BadTagFunc3'] 75 try 76 tag nothing 77 call assert_false(1, 'tag command should have failed') 78 catch 79 call assert_exception('E987:') 80 endtry 81 exe 'delf' &tagfunc 82 endfor 83 84 func NullTagFunc(...) 85 return v:null 86 endfunc 87 set tags= tfu=NullTagFunc 88 call assert_fails('tag nothing', 'E433:') 89 delf NullTagFunc 90 91 bwipe! 92 set tags& tfu& cpt& 93 call delete('Xfile1') 94endfunc 95 96" Test for modifying the tag stack from a tag function and jumping to a tag 97" from a tag function 98func Test_tagfunc_settagstack() 99 func Mytagfunc1(pat, flags, info) 100 call settagstack(1, {'tagname' : 'mytag', 'from' : [0, 10, 1, 0]}) 101 return [{'name' : 'mytag', 'filename' : 'Xtest', 'cmd' : '1'}] 102 endfunc 103 set tagfunc=Mytagfunc1 104 call writefile([''], 'Xtest') 105 call assert_fails('tag xyz', 'E986:') 106 107 func Mytagfunc2(pat, flags, info) 108 tag test_tag 109 return [{'name' : 'mytag', 'filename' : 'Xtest', 'cmd' : '1'}] 110 endfunc 111 set tagfunc=Mytagfunc2 112 call assert_fails('tag xyz', 'E986:') 113 114 call delete('Xtest') 115 set tagfunc& 116 delfunc Mytagfunc1 117 delfunc Mytagfunc2 118endfunc 119 120" vim: shiftwidth=2 sts=2 expandtab 121