1source check.vim 2 3" Test for insert expansion 4func Test_ins_complete() 5 edit test_ins_complete.vim 6 " The files in the current directory interferes with the files 7 " used by this test. So use a separate directory for the test. 8 call mkdir('Xdir') 9 cd Xdir 10 11 set ff=unix 12 call writefile(["test11\t36Gepeto\t/Tag/", 13 \ "asd\ttest11file\t36G", 14 \ "Makefile\tto\trun"], 'Xtestfile') 15 call writefile(['', 'start of testfile', 16 \ 'ru', 17 \ 'run1', 18 \ 'run2', 19 \ 'STARTTEST', 20 \ 'ENDTEST', 21 \ 'end of testfile'], 'Xtestdata') 22 set ff& 23 24 enew! 25 edit Xtestdata 26 new 27 call append(0, ['#include "Xtestfile"', '']) 28 call cursor(2, 1) 29 30 set cot= 31 set cpt=.,w 32 " add-expands (word from next line) from other window 33 exe "normal iru\<C-N>\<C-N>\<C-X>\<C-N>\<Esc>\<C-A>" 34 call assert_equal('run1 run3', getline('.')) 35 " add-expands (current buffer first) 36 exe "normal o\<C-P>\<C-X>\<C-N>" 37 call assert_equal('run3 run3', getline('.')) 38 " Local expansion, ends in an empty line (unless it becomes a global 39 " expansion) 40 exe "normal o\<C-X>\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>" 41 call assert_equal('', getline('.')) 42 " starts Local and switches to global add-expansion 43 exe "normal o\<C-X>\<C-P>\<C-P>\<C-X>\<C-X>\<C-N>\<C-X>\<C-N>\<C-N>" 44 call assert_equal('run1 run2', getline('.')) 45 46 set cpt=.,w,i 47 " i-add-expands and switches to local 48 exe "normal OM\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>\<C-X>\<C-X>\<C-X>\<C-P>" 49 call assert_equal("Makefile\tto\trun3", getline('.')) 50 " add-expands lines (it would end in an empty line if it didn't ignored 51 " itself) 52 exe "normal o\<C-X>\<C-L>\<C-X>\<C-L>\<C-P>\<C-P>" 53 call assert_equal("Makefile\tto\trun3", getline('.')) 54 call assert_equal("Makefile\tto\trun3", getline(line('.') - 1)) 55 56 set cpt=kXtestfile 57 " checks k-expansion, and file expansion (use Xtest11 instead of test11, 58 " because TEST11.OUT may match first on DOS) 59 write Xtest11.one 60 write Xtest11.two 61 exe "normal o\<C-N>\<Esc>IX\<Esc>A\<C-X>\<C-F>\<C-N>" 62 call assert_equal('Xtest11.two', getline('.')) 63 64 " use CTRL-X CTRL-F to complete Xtest11.one, remove it and then use CTRL-X 65 " CTRL-F again to verify this doesn't cause trouble. 66 exe "normal oXt\<C-X>\<C-F>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<C-X>\<C-F>" 67 call assert_equal('Xtest11.one', getline('.')) 68 normal ddk 69 70 set cpt=w 71 " checks make_cyclic in other window 72 exe "normal oST\<C-N>\<C-P>\<C-P>\<C-P>\<C-P>" 73 call assert_equal('STARTTEST', getline('.')) 74 75 set cpt=u nohid 76 " checks unloaded buffer expansion 77 only 78 exe "normal oEN\<C-N>" 79 call assert_equal('ENDTEST', getline('.')) 80 " checks adding mode abortion 81 exe "normal ounl\<C-N>\<C-X>\<C-X>\<C-P>" 82 call assert_equal('unless', getline('.')) 83 84 set cpt=t,d def=^\\k* tags=Xtestfile notagbsearch 85 " tag expansion, define add-expansion interrupted 86 exe "normal o\<C-X>\<C-]>\<C-X>\<C-D>\<C-X>\<C-D>\<C-X>\<C-X>\<C-D>\<C-X>\<C-D>\<C-X>\<C-D>\<C-X>\<C-D>" 87 call assert_equal('test11file 36Gepeto /Tag/ asd', getline('.')) 88 " t-expansion 89 exe "normal oa\<C-N>\<Esc>" 90 call assert_equal('asd', getline('.')) 91 92 %bw! 93 call delete('Xtestfile') 94 call delete('Xtest11.one') 95 call delete('Xtest11.two') 96 call delete('Xtestdata') 97 set cpt& cot& def& tags& tagbsearch& hidden& 98 cd .. 99 call delete('Xdir', 'rf') 100endfunc 101 102func Test_omni_dash() 103 func Omni(findstart, base) 104 if a:findstart 105 return 5 106 else 107 echom a:base 108 return ['-help', '-v'] 109 endif 110 endfunc 111 set omnifunc=Omni 112 new 113 exe "normal Gofind -\<C-x>\<C-o>" 114 call assert_equal("\n-\nmatch 1 of 2", execute(':2mess')) 115 116 bwipe! 117 delfunc Omni 118 set omnifunc= 119endfunc 120 121func Test_completefunc_args() 122 let s:args = [] 123 func! CompleteFunc(findstart, base) 124 let s:args += [[a:findstart, empty(a:base)]] 125 endfunc 126 new 127 128 set completefunc=CompleteFunc 129 call feedkeys("i\<C-X>\<C-U>\<Esc>", 'x') 130 call assert_equal([1, 1], s:args[0]) 131 call assert_equal(0, s:args[1][0]) 132 set completefunc= 133 134 let s:args = [] 135 set omnifunc=CompleteFunc 136 call feedkeys("i\<C-X>\<C-O>\<Esc>", 'x') 137 call assert_equal([1, 1], s:args[0]) 138 call assert_equal(0, s:args[1][0]) 139 set omnifunc= 140 141 bwipe! 142 unlet s:args 143 delfunc CompleteFunc 144endfunc 145 146func s:CompleteDone_CompleteFuncNone( findstart, base ) 147 if a:findstart 148 return 0 149 endif 150 151 return v:none 152endfunc 153 154func s:CompleteDone_CompleteFuncDict( findstart, base ) 155 if a:findstart 156 return 0 157 endif 158 159 return { 160 \ 'words': [ 161 \ { 162 \ 'word': 'aword', 163 \ 'abbr': 'wrd', 164 \ 'menu': 'extra text', 165 \ 'info': 'words are cool', 166 \ 'kind': 'W', 167 \ 'user_data': 'test' 168 \ } 169 \ ] 170 \ } 171endfunc 172 173func s:CompleteDone_CheckCompletedItemNone() 174 let s:called_completedone = 1 175endfunc 176 177func s:CompleteDone_CheckCompletedItemDict() 178 call assert_equal( 'aword', v:completed_item[ 'word' ] ) 179 call assert_equal( 'wrd', v:completed_item[ 'abbr' ] ) 180 call assert_equal( 'extra text', v:completed_item[ 'menu' ] ) 181 call assert_equal( 'words are cool', v:completed_item[ 'info' ] ) 182 call assert_equal( 'W', v:completed_item[ 'kind' ] ) 183 call assert_equal( 'test', v:completed_item[ 'user_data' ] ) 184 185 let s:called_completedone = 1 186endfunc 187 188func Test_CompleteDoneNone() 189 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemNone() 190 let oldline = join(map(range(&columns), 'nr2char(screenchar(&lines-1, v:val+1))'), '') 191 192 set completefunc=<SID>CompleteDone_CompleteFuncNone 193 execute "normal a\<C-X>\<C-U>\<C-Y>" 194 set completefunc& 195 let newline = join(map(range(&columns), 'nr2char(screenchar(&lines-1, v:val+1))'), '') 196 197 call assert_true(s:called_completedone) 198 call assert_equal(oldline, newline) 199 200 let s:called_completedone = 0 201 au! CompleteDone 202endfunc 203 204func Test_CompleteDoneDict() 205 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDict() 206 207 set completefunc=<SID>CompleteDone_CompleteFuncDict 208 execute "normal a\<C-X>\<C-U>\<C-Y>" 209 set completefunc& 210 211 call assert_equal('test', v:completed_item[ 'user_data' ]) 212 call assert_true(s:called_completedone) 213 214 let s:called_completedone = 0 215 au! CompleteDone 216endfunc 217 218func s:CompleteDone_CompleteFuncDictNoUserData(findstart, base) 219 if a:findstart 220 return 0 221 endif 222 223 return { 224 \ 'words': [ 225 \ { 226 \ 'word': 'aword', 227 \ 'abbr': 'wrd', 228 \ 'menu': 'extra text', 229 \ 'info': 'words are cool', 230 \ 'kind': 'W' 231 \ } 232 \ ] 233 \ } 234endfunc 235 236func s:CompleteDone_CheckCompletedItemDictNoUserData() 237 call assert_equal( 'aword', v:completed_item[ 'word' ] ) 238 call assert_equal( 'wrd', v:completed_item[ 'abbr' ] ) 239 call assert_equal( 'extra text', v:completed_item[ 'menu' ] ) 240 call assert_equal( 'words are cool', v:completed_item[ 'info' ] ) 241 call assert_equal( 'W', v:completed_item[ 'kind' ] ) 242 call assert_equal( '', v:completed_item[ 'user_data' ] ) 243 244 let s:called_completedone = 1 245endfunc 246 247func Test_CompleteDoneDictNoUserData() 248 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDictNoUserData() 249 250 set completefunc=<SID>CompleteDone_CompleteFuncDictNoUserData 251 execute "normal a\<C-X>\<C-U>\<C-Y>" 252 set completefunc& 253 254 call assert_equal('', v:completed_item[ 'user_data' ]) 255 call assert_true(s:called_completedone) 256 257 let s:called_completedone = 0 258 au! CompleteDone 259endfunc 260 261func s:CompleteDone_CompleteFuncList(findstart, base) 262 if a:findstart 263 return 0 264 endif 265 266 return [ 'aword' ] 267endfunc 268 269func s:CompleteDone_CheckCompletedItemList() 270 call assert_equal( 'aword', v:completed_item[ 'word' ] ) 271 call assert_equal( '', v:completed_item[ 'abbr' ] ) 272 call assert_equal( '', v:completed_item[ 'menu' ] ) 273 call assert_equal( '', v:completed_item[ 'info' ] ) 274 call assert_equal( '', v:completed_item[ 'kind' ] ) 275 call assert_equal( '', v:completed_item[ 'user_data' ] ) 276 277 let s:called_completedone = 1 278endfunc 279 280func Test_CompleteDoneList() 281 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemList() 282 283 set completefunc=<SID>CompleteDone_CompleteFuncList 284 execute "normal a\<C-X>\<C-U>\<C-Y>" 285 set completefunc& 286 287 call assert_equal('', v:completed_item[ 'user_data' ]) 288 call assert_true(s:called_completedone) 289 290 let s:called_completedone = 0 291 au! CompleteDone 292endfunc 293 294func Test_CompleteDone_undo() 295 au CompleteDone * call append(0, "prepend1") 296 new 297 call setline(1, ["line1", "line2"]) 298 call feedkeys("Go\<C-X>\<C-N>\<CR>\<ESC>", "tx") 299 call assert_equal(["prepend1", "line1", "line2", "line1", ""], 300 \ getline(1, '$')) 301 undo 302 call assert_equal(["line1", "line2"], getline(1, '$')) 303 bwipe! 304 au! CompleteDone 305endfunc 306 307" Check that when using feedkeys() typeahead does not interrupt searching for 308" completions. 309func Test_compl_feedkeys() 310 new 311 set completeopt=menuone,noselect 312 call feedkeys("ajump ju\<C-X>\<C-N>\<C-P>\<ESC>", "tx") 313 call assert_equal("jump jump", getline(1)) 314 bwipe! 315 set completeopt& 316endfunc 317 318func Test_compl_in_cmdwin() 319 set wildmenu wildchar=<Tab> 320 com! -nargs=1 -complete=command GetInput let input = <q-args> 321 com! -buffer TestCommand echo 'TestCommand' 322 323 let input = '' 324 call feedkeys("q:iGetInput T\<C-x>\<C-v>\<CR>", 'tx!') 325 call assert_equal('TestCommand', input) 326 327 let input = '' 328 call feedkeys("q::GetInput T\<Tab>\<CR>:q\<CR>", 'tx!') 329 call assert_equal('T', input) 330 331 delcom TestCommand 332 delcom GetInput 333 set wildmenu& wildchar& 334endfunc 335 336" Test for insert path completion with completeslash option 337func Test_ins_completeslash() 338 CheckMSWindows 339 340 call mkdir('Xdir') 341 let orig_shellslash = &shellslash 342 set cpt& 343 new 344 345 set noshellslash 346 347 set completeslash= 348 exe "normal oXd\<C-X>\<C-F>" 349 call assert_equal('Xdir\', getline('.')) 350 351 set completeslash=backslash 352 exe "normal oXd\<C-X>\<C-F>" 353 call assert_equal('Xdir\', getline('.')) 354 355 set completeslash=slash 356 exe "normal oXd\<C-X>\<C-F>" 357 call assert_equal('Xdir/', getline('.')) 358 359 set shellslash 360 361 set completeslash= 362 exe "normal oXd\<C-X>\<C-F>" 363 call assert_equal('Xdir/', getline('.')) 364 365 set completeslash=backslash 366 exe "normal oXd\<C-X>\<C-F>" 367 call assert_equal('Xdir\', getline('.')) 368 369 set completeslash=slash 370 exe "normal oXd\<C-X>\<C-F>" 371 call assert_equal('Xdir/', getline('.')) 372 %bw! 373 call delete('Xdir', 'rf') 374 375 set noshellslash 376 set completeslash=slash 377 call assert_true(stridx(globpath(&rtp, 'syntax/*.vim', 1, 1)[0], '\') != -1) 378 379 let &shellslash = orig_shellslash 380 set completeslash= 381endfunc 382 383