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