1" Tests for tagjump (tags and special searches) 2 3" SEGV occurs in older versions. (At least 7.4.1748 or older) 4func Test_ptag_with_notagstack() 5 set notagstack 6 call assert_fails('ptag does_not_exist_tag_name', 'E426') 7 set tagstack&vim 8endfunc 9 10func Test_cancel_ptjump() 11 set tags=Xtags 12 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", 13 \ "word\tfile1\tcmd1", 14 \ "word\tfile2\tcmd2"], 15 \ 'Xtags') 16 17 only! 18 call feedkeys(":ptjump word\<CR>\<CR>", "xt") 19 help 20 call assert_equal(2, winnr('$')) 21 22 call delete('Xtags') 23 quit 24endfunc 25 26func Test_static_tagjump() 27 set tags=Xtags 28 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", 29 \ "one\tXfile1\t/^one/;\"\tf\tfile:\tsignature:(void)", 30 \ "word\tXfile2\tcmd2"], 31 \ 'Xtags') 32 new Xfile1 33 call setline(1, ['empty', 'one()', 'empty']) 34 write 35 tag one 36 call assert_equal(2, line('.')) 37 38 bwipe! 39 set tags& 40 call delete('Xtags') 41 call delete('Xfile1') 42endfunc 43 44func Test_duplicate_tagjump() 45 set tags=Xtags 46 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", 47 \ "thesame\tXfile1\t1;\"\td\tfile:", 48 \ "thesame\tXfile1\t2;\"\td\tfile:", 49 \ "thesame\tXfile1\t3;\"\td\tfile:", 50 \ ], 51 \ 'Xtags') 52 new Xfile1 53 call setline(1, ['thesame one', 'thesame two', 'thesame three']) 54 write 55 tag thesame 56 call assert_equal(1, line('.')) 57 tnext 58 call assert_equal(2, line('.')) 59 tnext 60 call assert_equal(3, line('.')) 61 62 bwipe! 63 set tags& 64 call delete('Xtags') 65 call delete('Xfile1') 66endfunc 67 68func Test_tagjump_switchbuf() 69 set tags=Xtags 70 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", 71 \ "second\tXfile1\t2", 72 \ "third\tXfile1\t3",], 73 \ 'Xtags') 74 call writefile(['first', 'second', 'third'], 'Xfile1') 75 76 enew | only 77 set switchbuf= 78 stag second 79 call assert_equal(2, winnr('$')) 80 call assert_equal(2, line('.')) 81 stag third 82 call assert_equal(3, winnr('$')) 83 call assert_equal(3, line('.')) 84 85 enew | only 86 set switchbuf=useopen 87 stag second 88 call assert_equal(2, winnr('$')) 89 call assert_equal(2, line('.')) 90 stag third 91 call assert_equal(2, winnr('$')) 92 call assert_equal(3, line('.')) 93 94 enew | only 95 set switchbuf=usetab 96 tab stag second 97 call assert_equal(2, tabpagenr('$')) 98 call assert_equal(2, line('.')) 99 1tabnext | stag third 100 call assert_equal(2, tabpagenr('$')) 101 call assert_equal(3, line('.')) 102 103 tabclose! 104 enew | only 105 call delete('Xfile1') 106 call delete('Xtags') 107 set switchbuf&vim 108endfunc 109 110" Tests for [ CTRL-I and CTRL-W CTRL-I commands 111function Test_keyword_jump() 112 call writefile(["#include Xinclude", "", 113 \ "", 114 \ "/* test text test tex start here", 115 \ " some text", 116 \ " test text", 117 \ " start OK if found this line", 118 \ " start found wrong line", 119 \ "test text"], 'Xtestfile') 120 call writefile(["/* test text test tex start here", 121 \ " some text", 122 \ " test text", 123 \ " start OK if found this line", 124 \ " start found wrong line", 125 \ "test text"], 'Xinclude') 126 new Xtestfile 127 call cursor(1,1) 128 call search("start") 129 exe "normal! 5[\<C-I>" 130 call assert_equal(" start OK if found this line", getline('.')) 131 call cursor(1,1) 132 call search("start") 133 exe "normal! 5\<C-W>\<C-I>" 134 call assert_equal(" start OK if found this line", getline('.')) 135 enew! | only 136 call delete('Xtestfile') 137 call delete('Xinclude') 138endfunction 139 140" Test for jumping to a tag with 'hidden' set, with symbolic link in path of 141" tag. This only works for Unix, because of the symbolic link. 142func Test_tag_symbolic() 143 if !has('unix') 144 return 145 endif 146 set hidden 147 call delete("Xtest.dir", "rf") 148 call system("ln -s . Xtest.dir") 149 " Create a tags file with the current directory name inserted. 150 call writefile([ 151 \ "SECTION_OFF " . getcwd() . "/Xtest.dir/Xtest.c /^#define SECTION_OFF 3$/", 152 \ '', 153 \ ], 'Xtags') 154 call writefile(['#define SECTION_OFF 3', 155 \ '#define NUM_SECTIONS 3'], 'Xtest.c') 156 157 " Try jumping to a tag, but with a path that contains a symbolic link. When 158 " wrong, this will give the ATTENTION message. The next space will then be 159 " eaten by hit-return, instead of moving the cursor to 'd'. 160 set tags=Xtags 161 enew! 162 call append(0, 'SECTION_OFF') 163 call cursor(1,1) 164 exe "normal \<C-]> " 165 call assert_equal('Xtest.c', expand('%:t')) 166 call assert_equal(2, col('.')) 167 168 set hidden& 169 set tags& 170 enew! 171 call delete('Xtags') 172 call delete('Xtest.c') 173 call delete("Xtest.dir", "rf") 174 %bwipe! 175endfunc 176 177" Tests for tag search with !_TAG_FILE_ENCODING. 178" Depends on the test83-tags2 and test83-tags3 files. 179func Test_tag_file_encoding() 180 if has('vms') 181 return 182 endif 183 184 if !has('iconv') || iconv("\x82\x60", "cp932", "utf-8") != "\uff21" 185 return 186 endif 187 188 let save_enc = &encoding 189 set encoding=utf8 190 191 let content = ['text for tags1', 'abcdefghijklmnopqrs'] 192 call writefile(content, 'Xtags1.txt') 193 let content = ['text for tags2', 'ABC'] 194 call writefile(content, 'Xtags2.txt') 195 let content = ['text for tags3', 'ABC'] 196 call writefile(content, 'Xtags3.txt') 197 let content = ['!_TAG_FILE_ENCODING utf-8 //', 'abcdefghijklmnopqrs Xtags1.txt /abcdefghijklmnopqrs'] 198 call writefile(content, 'Xtags1') 199 200 " case1: 201 new 202 set tags=Xtags1 203 tag abcdefghijklmnopqrs 204 call assert_equal('Xtags1.txt', expand('%:t')) 205 call assert_equal('abcdefghijklmnopqrs', getline('.')) 206 close 207 208 " case2: 209 new 210 set tags=test83-tags2 211 tag /.BC 212 call assert_equal('Xtags2.txt', expand('%:t')) 213 call assert_equal('ABC', getline('.')) 214 close 215 216 " case3: 217 new 218 set tags=test83-tags3 219 tag abc50 220 call assert_equal('Xtags3.txt', expand('%:t')) 221 call assert_equal('ABC', getline('.')) 222 close 223 224 set tags& 225 let &encoding = save_enc 226 call delete('Xtags1.txt') 227 call delete('Xtags2.txt') 228 call delete('Xtags3.txt') 229 call delete('Xtags1') 230endfunc 231 232" vim: shiftwidth=2 sts=2 expandtab 233