1" Test for insert completion 2 3source screendump.vim 4source check.vim 5 6" Test for insert expansion 7func Test_ins_complete() 8 edit test_ins_complete.vim 9 " The files in the current directory interferes with the files 10 " used by this test. So use a separate directory for the test. 11 call mkdir('Xdir') 12 cd Xdir 13 14 set ff=unix 15 call writefile(["test11\t36Gepeto\t/Tag/", 16 \ "asd\ttest11file\t36G", 17 \ "Makefile\tto\trun"], 'Xtestfile') 18 call writefile(['', 'start of testfile', 19 \ 'ru', 20 \ 'run1', 21 \ 'run2', 22 \ 'STARTTEST', 23 \ 'ENDTEST', 24 \ 'end of testfile'], 'Xtestdata') 25 set ff& 26 27 enew! 28 edit Xtestdata 29 new 30 call append(0, ['#include "Xtestfile"', '']) 31 call cursor(2, 1) 32 33 set cot= 34 set cpt=.,w 35 " add-expands (word from next line) from other window 36 exe "normal iru\<C-N>\<C-N>\<C-X>\<C-N>\<Esc>\<C-A>" 37 call assert_equal('run1 run3', getline('.')) 38 " add-expands (current buffer first) 39 exe "normal o\<C-P>\<C-X>\<C-N>" 40 call assert_equal('run3 run3', getline('.')) 41 " Local expansion, ends in an empty line (unless it becomes a global 42 " expansion) 43 exe "normal o\<C-X>\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>" 44 call assert_equal('', getline('.')) 45 " starts Local and switches to global add-expansion 46 exe "normal o\<C-X>\<C-P>\<C-P>\<C-X>\<C-X>\<C-N>\<C-X>\<C-N>\<C-N>" 47 call assert_equal('run1 run2', getline('.')) 48 49 set cpt=.,w,i 50 " i-add-expands and switches to local 51 exe "normal OM\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>\<C-X>\<C-X>\<C-X>\<C-P>" 52 call assert_equal("Makefile\tto\trun3", getline('.')) 53 " add-expands lines (it would end in an empty line if it didn't ignored 54 " itself) 55 exe "normal o\<C-X>\<C-L>\<C-X>\<C-L>\<C-P>\<C-P>" 56 call assert_equal("Makefile\tto\trun3", getline('.')) 57 call assert_equal("Makefile\tto\trun3", getline(line('.') - 1)) 58 59 set cpt=kXtestfile 60 " checks k-expansion, and file expansion (use Xtest11 instead of test11, 61 " because TEST11.OUT may match first on DOS) 62 write Xtest11.one 63 write Xtest11.two 64 exe "normal o\<C-N>\<Esc>IX\<Esc>A\<C-X>\<C-F>\<C-N>" 65 call assert_equal('Xtest11.two', getline('.')) 66 67 " use CTRL-X CTRL-F to complete Xtest11.one, remove it and then use CTRL-X 68 " CTRL-F again to verify this doesn't cause trouble. 69 exe "normal oXt\<C-X>\<C-F>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<C-X>\<C-F>" 70 call assert_equal('Xtest11.one', getline('.')) 71 normal ddk 72 73 set cpt=w 74 " checks make_cyclic in other window 75 exe "normal oST\<C-N>\<C-P>\<C-P>\<C-P>\<C-P>" 76 call assert_equal('STARTTEST', getline('.')) 77 78 set cpt=u nohid 79 " checks unloaded buffer expansion 80 only 81 exe "normal oEN\<C-N>" 82 call assert_equal('ENDTEST', getline('.')) 83 " checks adding mode abortion 84 exe "normal ounl\<C-N>\<C-X>\<C-X>\<C-P>" 85 call assert_equal('unless', getline('.')) 86 87 set cpt=t,d def=^\\k* tags=Xtestfile notagbsearch 88 " tag expansion, define add-expansion interrupted 89 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>" 90 call assert_equal('test11file 36Gepeto /Tag/ asd', getline('.')) 91 " t-expansion 92 exe "normal oa\<C-N>\<Esc>" 93 call assert_equal('asd', getline('.')) 94 95 %bw! 96 call delete('Xtestfile') 97 call delete('Xtest11.one') 98 call delete('Xtest11.two') 99 call delete('Xtestdata') 100 set cpt& cot& def& tags& tagbsearch& hidden& 101 cd .. 102 call delete('Xdir', 'rf') 103endfunc 104 105func Test_omni_dash() 106 func Omni(findstart, base) 107 if a:findstart 108 return 5 109 else 110 echom a:base 111 return ['-help', '-v'] 112 endif 113 endfunc 114 set omnifunc=Omni 115 new 116 exe "normal Gofind -\<C-x>\<C-o>" 117 call assert_equal("find -help", getline('$')) 118 119 bwipe! 120 delfunc Omni 121 set omnifunc= 122endfunc 123 124func Test_omni_autoload() 125 let save_rtp = &rtp 126 set rtp=Xruntime/some 127 let dir = 'Xruntime/some/autoload' 128 call mkdir(dir, 'p') 129 130 let lines =<< trim END 131 vim9script 132 def omni#func(findstart: bool, base: string): any 133 if findstart 134 return 1 135 else 136 return ['match'] 137 endif 138 enddef 139 { 140 eval 1 + 2 141 } 142 END 143 call writefile(lines, dir .. '/omni.vim') 144 145 new 146 setlocal omnifunc=omni#func 147 call feedkeys("i\<C-X>\<C-O>\<Esc>", 'xt') 148 149 bwipe! 150 call delete('Xruntime', 'rf') 151 set omnifunc= 152 let &rtp = save_rtp 153endfunc 154 155func Test_completefunc_args() 156 let s:args = [] 157 func! CompleteFunc(findstart, base) 158 let s:args += [[a:findstart, empty(a:base)]] 159 endfunc 160 new 161 162 set completefunc=CompleteFunc 163 call feedkeys("i\<C-X>\<C-U>\<Esc>", 'x') 164 call assert_equal([1, 1], s:args[0]) 165 call assert_equal(0, s:args[1][0]) 166 set completefunc= 167 168 let s:args = [] 169 set omnifunc=CompleteFunc 170 call feedkeys("i\<C-X>\<C-O>\<Esc>", 'x') 171 call assert_equal([1, 1], s:args[0]) 172 call assert_equal(0, s:args[1][0]) 173 set omnifunc= 174 175 bwipe! 176 unlet s:args 177 delfunc CompleteFunc 178endfunc 179 180func s:CompleteDone_CompleteFuncNone( findstart, base ) 181 if a:findstart 182 return 0 183 endif 184 185 return v:none 186endfunc 187 188func s:CompleteDone_CompleteFuncDict( findstart, base ) 189 if a:findstart 190 return 0 191 endif 192 193 return { 194 \ 'words': [ 195 \ { 196 \ 'word': 'aword', 197 \ 'abbr': 'wrd', 198 \ 'menu': 'extra text', 199 \ 'info': 'words are cool', 200 \ 'kind': 'W', 201 \ 'user_data': 'test' 202 \ } 203 \ ] 204 \ } 205endfunc 206 207func s:CompleteDone_CheckCompletedItemNone() 208 let s:called_completedone = 1 209endfunc 210 211func s:CompleteDone_CheckCompletedItemDict(pre) 212 call assert_equal( 'aword', v:completed_item[ 'word' ] ) 213 call assert_equal( 'wrd', v:completed_item[ 'abbr' ] ) 214 call assert_equal( 'extra text', v:completed_item[ 'menu' ] ) 215 call assert_equal( 'words are cool', v:completed_item[ 'info' ] ) 216 call assert_equal( 'W', v:completed_item[ 'kind' ] ) 217 call assert_equal( 'test', v:completed_item[ 'user_data' ] ) 218 219 if a:pre 220 call assert_equal('function', complete_info().mode) 221 endif 222 223 let s:called_completedone = 1 224endfunc 225 226func Test_CompleteDoneNone() 227 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemNone() 228 let oldline = join(map(range(&columns), 'nr2char(screenchar(&lines-1, v:val+1))'), '') 229 230 set completefunc=<SID>CompleteDone_CompleteFuncNone 231 execute "normal a\<C-X>\<C-U>\<C-Y>" 232 set completefunc& 233 let newline = join(map(range(&columns), 'nr2char(screenchar(&lines-1, v:val+1))'), '') 234 235 call assert_true(s:called_completedone) 236 call assert_equal(oldline, newline) 237 238 let s:called_completedone = 0 239 au! CompleteDone 240endfunc 241 242func Test_CompleteDoneDict() 243 au CompleteDonePre * :call <SID>CompleteDone_CheckCompletedItemDict(1) 244 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDict(0) 245 246 set completefunc=<SID>CompleteDone_CompleteFuncDict 247 execute "normal a\<C-X>\<C-U>\<C-Y>" 248 set completefunc& 249 250 call assert_equal('test', v:completed_item[ 'user_data' ]) 251 call assert_true(s:called_completedone) 252 253 let s:called_completedone = 0 254 au! CompleteDone 255endfunc 256 257func s:CompleteDone_CompleteFuncDictNoUserData(findstart, base) 258 if a:findstart 259 return 0 260 endif 261 262 return { 263 \ 'words': [ 264 \ { 265 \ 'word': 'aword', 266 \ 'abbr': 'wrd', 267 \ 'menu': 'extra text', 268 \ 'info': 'words are cool', 269 \ 'kind': 'W', 270 \ 'user_data': ['one', 'two'], 271 \ } 272 \ ] 273 \ } 274endfunc 275 276func s:CompleteDone_CheckCompletedItemDictNoUserData() 277 call assert_equal( 'aword', v:completed_item[ 'word' ] ) 278 call assert_equal( 'wrd', v:completed_item[ 'abbr' ] ) 279 call assert_equal( 'extra text', v:completed_item[ 'menu' ] ) 280 call assert_equal( 'words are cool', v:completed_item[ 'info' ] ) 281 call assert_equal( 'W', v:completed_item[ 'kind' ] ) 282 call assert_equal( ['one', 'two'], v:completed_item[ 'user_data' ] ) 283 284 let s:called_completedone = 1 285endfunc 286 287func Test_CompleteDoneDictNoUserData() 288 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDictNoUserData() 289 290 set completefunc=<SID>CompleteDone_CompleteFuncDictNoUserData 291 execute "normal a\<C-X>\<C-U>\<C-Y>" 292 set completefunc& 293 294 call assert_equal(['one', 'two'], v:completed_item[ 'user_data' ]) 295 call assert_true(s:called_completedone) 296 297 let s:called_completedone = 0 298 au! CompleteDone 299endfunc 300 301func s:CompleteDone_CompleteFuncList(findstart, base) 302 if a:findstart 303 return 0 304 endif 305 306 return [ 'aword' ] 307endfunc 308 309func s:CompleteDone_CheckCompletedItemList() 310 call assert_equal( 'aword', v:completed_item[ 'word' ] ) 311 call assert_equal( '', v:completed_item[ 'abbr' ] ) 312 call assert_equal( '', v:completed_item[ 'menu' ] ) 313 call assert_equal( '', v:completed_item[ 'info' ] ) 314 call assert_equal( '', v:completed_item[ 'kind' ] ) 315 call assert_equal( '', v:completed_item[ 'user_data' ] ) 316 317 let s:called_completedone = 1 318endfunc 319 320func Test_CompleteDoneList() 321 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemList() 322 323 set completefunc=<SID>CompleteDone_CompleteFuncList 324 execute "normal a\<C-X>\<C-U>\<C-Y>" 325 set completefunc& 326 327 call assert_equal('', v:completed_item[ 'user_data' ]) 328 call assert_true(s:called_completedone) 329 330 let s:called_completedone = 0 331 au! CompleteDone 332endfunc 333 334func Test_CompleteDone_undo() 335 au CompleteDone * call append(0, "prepend1") 336 new 337 call setline(1, ["line1", "line2"]) 338 call feedkeys("Go\<C-X>\<C-N>\<CR>\<ESC>", "tx") 339 call assert_equal(["prepend1", "line1", "line2", "line1", ""], 340 \ getline(1, '$')) 341 undo 342 call assert_equal(["line1", "line2"], getline(1, '$')) 343 bwipe! 344 au! CompleteDone 345endfunc 346 347func CompleteTest(findstart, query) 348 if a:findstart 349 return col('.') 350 endif 351 return ['matched'] 352endfunc 353 354func Test_completefunc_info() 355 new 356 set completeopt=menuone 357 set completefunc=CompleteTest 358 call feedkeys("i\<C-X>\<C-U>\<C-R>\<C-R>=string(complete_info())\<CR>\<ESC>", "tx") 359 call assert_equal("matched{'pum_visible': 1, 'mode': 'function', 'selected': 0, 'items': [{'word': 'matched', 'menu': '', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}]}", getline(1)) 360 bwipe! 361 set completeopt& 362 set completefunc& 363endfunc 364 365" Check that when using feedkeys() typeahead does not interrupt searching for 366" completions. 367func Test_compl_feedkeys() 368 new 369 set completeopt=menuone,noselect 370 call feedkeys("ajump ju\<C-X>\<C-N>\<C-P>\<ESC>", "tx") 371 call assert_equal("jump jump", getline(1)) 372 bwipe! 373 set completeopt& 374endfunc 375 376func Test_compl_in_cmdwin() 377 CheckFeature cmdwin 378 379 set wildmenu wildchar=<Tab> 380 com! -nargs=1 -complete=command GetInput let input = <q-args> 381 com! -buffer TestCommand echo 'TestCommand' 382 let w:test_winvar = 'winvar' 383 let b:test_bufvar = 'bufvar' 384 385 " User-defined commands 386 let input = '' 387 call feedkeys("q:iGetInput T\<C-x>\<C-v>\<CR>", 'tx!') 388 call assert_equal('TestCommand', input) 389 390 let input = '' 391 call feedkeys("q::GetInput T\<Tab>\<CR>:q\<CR>", 'tx!') 392 call assert_equal('T', input) 393 394 395 com! -nargs=1 -complete=var GetInput let input = <q-args> 396 " Window-local variables 397 let input = '' 398 call feedkeys("q:iGetInput w:test_\<C-x>\<C-v>\<CR>", 'tx!') 399 call assert_equal('w:test_winvar', input) 400 401 let input = '' 402 call feedkeys("q::GetInput w:test_\<Tab>\<CR>:q\<CR>", 'tx!') 403 call assert_equal('w:test_', input) 404 405 " Buffer-local variables 406 let input = '' 407 call feedkeys("q:iGetInput b:test_\<C-x>\<C-v>\<CR>", 'tx!') 408 call assert_equal('b:test_bufvar', input) 409 410 let input = '' 411 call feedkeys("q::GetInput b:test_\<Tab>\<CR>:q\<CR>", 'tx!') 412 call assert_equal('b:test_', input) 413 414 delcom TestCommand 415 delcom GetInput 416 unlet w:test_winvar 417 unlet b:test_bufvar 418 set wildmenu& wildchar& 419endfunc 420 421" Test for insert path completion with completeslash option 422func Test_ins_completeslash() 423 CheckMSWindows 424 425 call mkdir('Xdir') 426 let orig_shellslash = &shellslash 427 set cpt& 428 new 429 430 set noshellslash 431 432 set completeslash= 433 exe "normal oXd\<C-X>\<C-F>" 434 call assert_equal('Xdir\', getline('.')) 435 436 set completeslash=backslash 437 exe "normal oXd\<C-X>\<C-F>" 438 call assert_equal('Xdir\', getline('.')) 439 440 set completeslash=slash 441 exe "normal oXd\<C-X>\<C-F>" 442 call assert_equal('Xdir/', getline('.')) 443 444 set shellslash 445 446 set completeslash= 447 exe "normal oXd\<C-X>\<C-F>" 448 call assert_equal('Xdir/', getline('.')) 449 450 set completeslash=backslash 451 exe "normal oXd\<C-X>\<C-F>" 452 call assert_equal('Xdir\', getline('.')) 453 454 set completeslash=slash 455 exe "normal oXd\<C-X>\<C-F>" 456 call assert_equal('Xdir/', getline('.')) 457 %bw! 458 call delete('Xdir', 'rf') 459 460 set noshellslash 461 set completeslash=slash 462 call assert_true(stridx(globpath(&rtp, 'syntax/*.vim', 1, 1)[0], '\') != -1) 463 464 let &shellslash = orig_shellslash 465 set completeslash= 466endfunc 467 468func Test_pum_stopped_by_timer() 469 CheckScreendump 470 471 let lines =<< trim END 472 call setline(1, ['hello', 'hullo', 'heeee', '']) 473 func StartCompl() 474 call timer_start(100, { -> execute('stopinsert') }) 475 call feedkeys("Gah\<C-N>") 476 endfunc 477 END 478 479 call writefile(lines, 'Xpumscript') 480 let buf = RunVimInTerminal('-S Xpumscript', #{rows: 12}) 481 call term_sendkeys(buf, ":call StartCompl()\<CR>") 482 call TermWait(buf, 200) 483 call term_sendkeys(buf, "k") 484 call VerifyScreenDump(buf, 'Test_pum_stopped_by_timer', {}) 485 486 call StopVimInTerminal(buf) 487 call delete('Xpumscript') 488endfunc 489 490func Test_pum_with_folds_two_tabs() 491 CheckScreendump 492 493 let lines =<< trim END 494 set fdm=marker 495 call setline(1, ['" x {{{1', '" a some text']) 496 call setline(3, range(&lines)->map({_, val -> '" a' .. val})) 497 norm! zm 498 tab sp 499 call feedkeys('2Gzv', 'xt') 500 call feedkeys("0fa", 'xt') 501 END 502 503 call writefile(lines, 'Xpumscript') 504 let buf = RunVimInTerminal('-S Xpumscript', #{rows: 10}) 505 call TermWait(buf, 50) 506 call term_sendkeys(buf, "a\<C-N>") 507 call VerifyScreenDump(buf, 'Test_pum_with_folds_two_tabs', {}) 508 509 call term_sendkeys(buf, "\<Esc>") 510 call StopVimInTerminal(buf) 511 call delete('Xpumscript') 512endfunc 513 514func Test_pum_with_preview_win() 515 CheckScreendump 516 517 let lines =<< trim END 518 funct Omni_test(findstart, base) 519 if a:findstart 520 return col(".") - 1 521 endif 522 return [#{word: "one", info: "1info"}, #{word: "two", info: "2info"}, #{word: "three", info: "3info"}] 523 endfunc 524 set omnifunc=Omni_test 525 set completeopt+=longest 526 END 527 528 call writefile(lines, 'Xpreviewscript') 529 let buf = RunVimInTerminal('-S Xpreviewscript', #{rows: 12}) 530 call TermWait(buf, 50) 531 call term_sendkeys(buf, "Gi\<C-X>\<C-O>") 532 call TermWait(buf, 100) 533 call term_sendkeys(buf, "\<C-N>") 534 call VerifyScreenDump(buf, 'Test_pum_with_preview_win', {}) 535 536 call term_sendkeys(buf, "\<Esc>") 537 call StopVimInTerminal(buf) 538 call delete('Xpreviewscript') 539endfunc 540 541" Test for inserting the tag search pattern in insert mode 542func Test_ins_compl_tag_sft() 543 call writefile([ 544 \ "!_TAG_FILE_ENCODING\tutf-8\t//", 545 \ "first\tXfoo\t/^int first() {}$/", 546 \ "second\tXfoo\t/^int second() {}$/", 547 \ "third\tXfoo\t/^int third() {}$/"], 548 \ 'Xtags') 549 set tags=Xtags 550 let code =<< trim [CODE] 551 int first() {} 552 int second() {} 553 int third() {} 554 [CODE] 555 call writefile(code, 'Xfoo') 556 557 enew 558 set showfulltag 559 exe "normal isec\<C-X>\<C-]>\<C-N>\<CR>" 560 call assert_equal('int second() {}', getline(1)) 561 set noshowfulltag 562 563 call delete('Xtags') 564 call delete('Xfoo') 565 set tags& 566 %bwipe! 567endfunc 568 569" Test for 'completefunc' deleting text 570func Test_completefunc_error() 571 new 572 " delete text when called for the first time 573 func CompleteFunc(findstart, base) 574 if a:findstart == 1 575 normal dd 576 return col('.') - 1 577 endif 578 return ['a', 'b'] 579 endfunc 580 set completefunc=CompleteFunc 581 call setline(1, ['', 'abcd', '']) 582 call assert_fails('exe "normal 2G$a\<C-X>\<C-U>"', 'E578:') 583 584 " delete text when called for the second time 585 func CompleteFunc2(findstart, base) 586 if a:findstart == 1 587 return col('.') - 1 588 endif 589 normal dd 590 return ['a', 'b'] 591 endfunc 592 set completefunc=CompleteFunc2 593 call setline(1, ['', 'abcd', '']) 594 call assert_fails('exe "normal 2G$a\<C-X>\<C-U>"', 'E578:') 595 596 " Jump to a different window from the complete function 597 func CompleteFunc3(findstart, base) 598 if a:findstart == 1 599 return col('.') - 1 600 endif 601 wincmd p 602 return ['a', 'b'] 603 endfunc 604 set completefunc=CompleteFunc3 605 new 606 call assert_fails('exe "normal a\<C-X>\<C-U>"', 'E565:') 607 close! 608 609 set completefunc& 610 delfunc CompleteFunc 611 delfunc CompleteFunc2 612 delfunc CompleteFunc3 613 close! 614endfunc 615 616" Test for returning non-string values from 'completefunc' 617func Test_completefunc_invalid_data() 618 new 619 func! CompleteFunc(findstart, base) 620 if a:findstart == 1 621 return col('.') - 1 622 endif 623 return [{}, '', 'moon'] 624 endfunc 625 set completefunc=CompleteFunc 626 exe "normal i\<C-X>\<C-U>" 627 call assert_equal('moon', getline(1)) 628 set completefunc& 629 close! 630endfunc 631 632" Test for errors in using complete() function 633func Test_complete_func_error() 634 call assert_fails('call complete(1, ["a"])', 'E785:') 635 func ListColors() 636 call complete(col('.'), "blue") 637 endfunc 638 call assert_fails('exe "normal i\<C-R>=ListColors()\<CR>"', 'E474:') 639 func ListMonths() 640 call complete(col('.'), test_null_list()) 641 endfunc 642 call assert_fails('exe "normal i\<C-R>=ListMonths()\<CR>"', 'E474:') 643 delfunc ListColors 644 delfunc ListMonths 645 call assert_fails('call complete_info({})', 'E714:') 646 call assert_equal([], complete_info(['items']).items) 647endfunc 648 649" Test for completing words following a completed word in a line 650func Test_complete_wrapscan() 651 " complete words from another buffer 652 new 653 call setline(1, ['one two', 'three four']) 654 new 655 setlocal complete=w 656 call feedkeys("itw\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>", 'xt') 657 call assert_equal('two three four', getline(1)) 658 close! 659 " complete words from the current buffer 660 setlocal complete=. 661 %d 662 call setline(1, ['one two', '']) 663 call cursor(2, 1) 664 call feedkeys("ion\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>", 'xt') 665 call assert_equal('one two one two', getline(2)) 666 close! 667endfunc 668 669" Test for completing special characters 670func Test_complete_special_chars() 671 new 672 call setline(1, 'int .*[-\^$ func float') 673 call feedkeys("oin\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>", 'xt') 674 call assert_equal('int .*[-\^$ func float', getline(2)) 675 close! 676endfunc 677 678" Test for completion when text is wrapped across lines. 679func Test_complete_across_line() 680 new 681 call setline(1, ['red green blue', 'one two three']) 682 setlocal textwidth=20 683 exe "normal 2G$a re\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>" 684 call assert_equal(['one two three red', 'green blue one'], getline(2, '$')) 685 close! 686endfunc 687 688" Test for using CTRL-L to add one character when completing matching 689func Test_complete_add_onechar() 690 new 691 call setline(1, ['wool', 'woodwork']) 692 call feedkeys("Gowoo\<C-P>\<C-P>\<C-P>\<C-L>f", 'xt') 693 call assert_equal('woof', getline(3)) 694 695 " use 'ignorecase' and backspace to erase characters from the prefix string 696 " and then add letters using CTRL-L 697 %d 698 set ignorecase backspace=2 699 setlocal complete=. 700 call setline(1, ['workhorse', 'workload']) 701 normal Go 702 exe "normal aWOR\<C-P>\<bs>\<bs>\<bs>\<bs>\<bs>\<bs>\<C-L>r\<C-L>\<C-L>" 703 call assert_equal('workh', getline(3)) 704 set ignorecase& backspace& 705 close! 706endfunc 707 708" Test insert completion with 'cindent' (adjust the indent) 709func Test_complete_with_cindent() 710 new 711 setlocal cindent 712 call setline(1, ['if (i == 1)', " j = 2;"]) 713 exe "normal Go{\<CR>i\<C-X>\<C-L>\<C-X>\<C-L>\<CR>}" 714 call assert_equal(['{', "\tif (i == 1)", "\t\tj = 2;", '}'], getline(3, '$')) 715 716 %d 717 call setline(1, ['when while', '{', '']) 718 setlocal cinkeys+==while 719 exe "normal Giwh\<C-P> " 720 call assert_equal("\twhile ", getline('$')) 721 close! 722endfunc 723 724" Test for <CTRL-X> <CTRL-V> completion. Complete commands and functions 725func Test_complete_cmdline() 726 new 727 exe "normal icaddb\<C-X>\<C-V>" 728 call assert_equal('caddbuffer', getline(1)) 729 exe "normal ocall getqf\<C-X>\<C-V>" 730 call assert_equal('call getqflist(', getline(2)) 731 exe "normal oabcxyz(\<C-X>\<C-V>" 732 call assert_equal('abcxyz(', getline(3)) 733 close! 734endfunc 735 736func Test_issue_7021() 737 CheckMSWindows 738 739 let orig_shellslash = &shellslash 740 set noshellslash 741 742 set completeslash=slash 743 call assert_false(expand('~') =~ '/') 744 745 let &shellslash = orig_shellslash 746 set completeslash= 747endfunc 748 749" Test to ensure 'Scanning...' messages are not recorded in messages history 750func Test_z1_complete_no_history() 751 new 752 messages clear 753 let currmess = execute('messages') 754 setlocal dictionary=README.txt 755 exe "normal owh\<C-X>\<C-K>" 756 exe "normal owh\<C-N>" 757 call assert_equal(currmess, execute('messages')) 758 close! 759endfunc 760 761" vim: shiftwidth=2 sts=2 expandtab 762