1" Test for completion menu 2 3source shared.vim 4 5let g:months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] 6let g:setting = '' 7 8func! ListMonths() 9 if g:setting != '' 10 exe ":set" g:setting 11 endif 12 let mth = copy(g:months) 13 let entered = strcharpart(getline('.'),0,col('.')) 14 if !empty(entered) 15 let mth = filter(mth, 'v:val=~"^".entered') 16 endif 17 call complete(1, mth) 18 return '' 19endfunc 20 21func! Test_popup_complete2() 22 " Although the popupmenu is not visible, this does not mean completion mode 23 " has ended. After pressing <f5> to complete the currently typed char, Vim 24 " still stays in the first state of the completion (:h ins-completion-menu), 25 " although the popupmenu wasn't shown <c-e> will remove the inserted 26 " completed text (:h complete_CTRL-E), while the following <c-e> will behave 27 " like expected (:h i_CTRL-E) 28 new 29 inoremap <f5> <c-r>=ListMonths()<cr> 30 call append(1, ["December2015"]) 31 :1 32 call feedkeys("aD\<f5>\<C-E>\<C-E>\<C-E>\<C-E>\<enter>\<esc>", 'tx') 33 call assert_equal(["Dece", "", "December2015"], getline(1,3)) 34 %d 35 bw! 36endfu 37 38func! Test_popup_complete() 39 new 40 inoremap <f5> <c-r>=ListMonths()<cr> 41 42 " <C-E> - select original typed text before the completion started 43 call feedkeys("aJu\<f5>\<down>\<c-e>\<esc>", 'tx') 44 call assert_equal(["Ju"], getline(1,2)) 45 %d 46 47 " <C-Y> - accept current match 48 call feedkeys("a\<f5>". repeat("\<down>",7). "\<c-y>\<esc>", 'tx') 49 call assert_equal(["August"], getline(1,2)) 50 %d 51 52 " <BS> - Delete one character from the inserted text (state: 1) 53 " TODO: This should not end the completion, but it does. 54 " This should according to the documentation: 55 " January 56 " but instead, this does 57 " Januar 58 " (idea is, C-L inserts the match from the popup menu 59 " but if the menu is closed, it will insert the character <c-l> 60 call feedkeys("aJ\<f5>\<bs>\<c-l>\<esc>", 'tx') 61 call assert_equal(["Januar"], getline(1,2)) 62 %d 63 64 " any-non special character: Stop completion without changing the match 65 " and insert the typed character 66 call feedkeys("a\<f5>20", 'tx') 67 call assert_equal(["January20"], getline(1,2)) 68 %d 69 70 " any-non printable, non-white character: Add this character and 71 " reduce number of matches 72 call feedkeys("aJu\<f5>\<c-p>l\<c-y>", 'tx') 73 call assert_equal(["Jul"], getline(1,2)) 74 %d 75 76 " any-non printable, non-white character: Add this character and 77 " reduce number of matches 78 call feedkeys("aJu\<f5>\<c-p>l\<c-n>\<c-y>", 'tx') 79 call assert_equal(["July"], getline(1,2)) 80 %d 81 82 " any-non printable, non-white character: Add this character and 83 " reduce number of matches 84 call feedkeys("aJu\<f5>\<c-p>l\<c-e>", 'tx') 85 call assert_equal(["Jul"], getline(1,2)) 86 %d 87 88 " <BS> - Delete one character from the inserted text (state: 2) 89 call feedkeys("a\<f5>\<c-n>\<bs>", 'tx') 90 call assert_equal(["Februar"], getline(1,2)) 91 %d 92 93 " <c-l> - Insert one character from the current match 94 call feedkeys("aJ\<f5>".repeat("\<c-n>",3)."\<c-l>\<esc>", 'tx') 95 call assert_equal(["J"], getline(1,2)) 96 %d 97 98 " <c-l> - Insert one character from the current match 99 call feedkeys("aJ\<f5>".repeat("\<c-n>",4)."\<c-l>\<esc>", 'tx') 100 call assert_equal(["January"], getline(1,2)) 101 %d 102 103 " <c-y> - Accept current selected match 104 call feedkeys("aJ\<f5>\<c-y>\<esc>", 'tx') 105 call assert_equal(["January"], getline(1,2)) 106 %d 107 108 " <c-e> - End completion, go back to what was there before selecting a match 109 call feedkeys("aJu\<f5>\<c-e>\<esc>", 'tx') 110 call assert_equal(["Ju"], getline(1,2)) 111 %d 112 113 " <PageUp> - Select a match several entries back 114 call feedkeys("a\<f5>\<PageUp>\<c-y>\<esc>", 'tx') 115 call assert_equal([""], getline(1,2)) 116 %d 117 118 " <PageUp><PageUp> - Select a match several entries back 119 call feedkeys("a\<f5>\<PageUp>\<PageUp>\<c-y>\<esc>", 'tx') 120 call assert_equal(["December"], getline(1,2)) 121 %d 122 123 " <PageUp><PageUp><PageUp> - Select a match several entries back 124 call feedkeys("a\<f5>\<PageUp>\<PageUp>\<PageUp>\<c-y>\<esc>", 'tx') 125 call assert_equal(["February"], getline(1,2)) 126 %d 127 128 " <PageDown> - Select a match several entries further 129 call feedkeys("a\<f5>\<PageDown>\<c-y>\<esc>", 'tx') 130 call assert_equal(["November"], getline(1,2)) 131 %d 132 133 " <PageDown><PageDown> - Select a match several entries further 134 call feedkeys("a\<f5>\<PageDown>\<PageDown>\<c-y>\<esc>", 'tx') 135 call assert_equal(["December"], getline(1,2)) 136 %d 137 138 " <PageDown><PageDown><PageDown> - Select a match several entries further 139 call feedkeys("a\<f5>\<PageDown>\<PageDown>\<PageDown>\<c-y>\<esc>", 'tx') 140 call assert_equal([""], getline(1,2)) 141 %d 142 143 " <PageDown><PageDown><PageDown><PageDown> - Select a match several entries further 144 call feedkeys("a\<f5>".repeat("\<PageDown>",4)."\<c-y>\<esc>", 'tx') 145 call assert_equal(["October"], getline(1,2)) 146 %d 147 148 " <Up> - Select a match don't insert yet 149 call feedkeys("a\<f5>\<Up>\<c-y>\<esc>", 'tx') 150 call assert_equal([""], getline(1,2)) 151 %d 152 153 " <Up><Up> - Select a match don't insert yet 154 call feedkeys("a\<f5>\<Up>\<Up>\<c-y>\<esc>", 'tx') 155 call assert_equal(["December"], getline(1,2)) 156 %d 157 158 " <Up><Up><Up> - Select a match don't insert yet 159 call feedkeys("a\<f5>\<Up>\<Up>\<Up>\<c-y>\<esc>", 'tx') 160 call assert_equal(["November"], getline(1,2)) 161 %d 162 163 " <Tab> - Stop completion and insert the match 164 call feedkeys("a\<f5>\<Tab>\<c-y>\<esc>", 'tx') 165 call assert_equal(["January "], getline(1,2)) 166 %d 167 168 " <Space> - Stop completion and insert the match 169 call feedkeys("a\<f5>".repeat("\<c-p>",5)." \<esc>", 'tx') 170 call assert_equal(["September "], getline(1,2)) 171 %d 172 173 " <Enter> - Use the text and insert line break (state: 1) 174 call feedkeys("a\<f5>\<enter>\<esc>", 'tx') 175 call assert_equal(["January", ''], getline(1,2)) 176 %d 177 178 " <Enter> - Insert the current selected text (state: 2) 179 call feedkeys("a\<f5>".repeat("\<Up>",5)."\<enter>\<esc>", 'tx') 180 call assert_equal(["September"], getline(1,2)) 181 %d 182 183 " Insert match immediately, if there is only one match 184 " <c-y> selects a character from the line above 185 call append(0, ["December2015"]) 186 call feedkeys("aD\<f5>\<C-Y>\<C-Y>\<C-Y>\<C-Y>\<enter>\<esc>", 'tx') 187 call assert_equal(["December2015", "December2015", ""], getline(1,3)) 188 %d 189 190 " use menuone for 'completeopt' 191 " Since for the first <c-y> the menu is still shown, will only select 192 " three letters from the line above 193 set completeopt&vim 194 set completeopt+=menuone 195 call append(0, ["December2015"]) 196 call feedkeys("aD\<f5>\<C-Y>\<C-Y>\<C-Y>\<C-Y>\<enter>\<esc>", 'tx') 197 call assert_equal(["December2015", "December201", ""], getline(1,3)) 198 %d 199 200 " use longest for 'completeopt' 201 set completeopt&vim 202 call feedkeys("aM\<f5>\<C-N>\<C-P>\<c-e>\<enter>\<esc>", 'tx') 203 set completeopt+=longest 204 call feedkeys("aM\<f5>\<C-N>\<C-P>\<c-e>\<enter>\<esc>", 'tx') 205 call assert_equal(["M", "Ma", ""], getline(1,3)) 206 %d 207 208 " use noselect/noinsert for 'completeopt' 209 set completeopt&vim 210 call feedkeys("aM\<f5>\<enter>\<esc>", 'tx') 211 set completeopt+=noselect 212 call feedkeys("aM\<f5>\<enter>\<esc>", 'tx') 213 set completeopt-=noselect completeopt+=noinsert 214 call feedkeys("aM\<f5>\<enter>\<esc>", 'tx') 215 call assert_equal(["March", "M", "March"], getline(1,4)) 216 %d 217endfu 218 219 220func! Test_popup_completion_insertmode() 221 new 222 inoremap <F5> <C-R>=ListMonths()<CR> 223 224 call feedkeys("a\<f5>\<down>\<enter>\<esc>", 'tx') 225 call assert_equal('February', getline(1)) 226 %d 227 " Set noinsertmode 228 let g:setting = 'noinsertmode' 229 call feedkeys("a\<f5>\<down>\<enter>\<esc>", 'tx') 230 call assert_equal('February', getline(1)) 231 call assert_false(pumvisible()) 232 %d 233 " Go through all matches, until none is selected 234 let g:setting = '' 235 call feedkeys("a\<f5>". repeat("\<c-n>",12)."\<enter>\<esc>", 'tx') 236 call assert_equal('', getline(1)) 237 %d 238 " select previous entry 239 call feedkeys("a\<f5>\<c-p>\<enter>\<esc>", 'tx') 240 call assert_equal('', getline(1)) 241 %d 242 " select last entry 243 call feedkeys("a\<f5>\<c-p>\<c-p>\<enter>\<esc>", 'tx') 244 call assert_equal('December', getline(1)) 245 246 iunmap <F5> 247endfunc 248 249func Test_noinsert_complete() 250 function! s:complTest1() abort 251 call complete(1, ['source', 'soundfold']) 252 return '' 253 endfunction 254 255 function! s:complTest2() abort 256 call complete(1, ['source', 'soundfold']) 257 return '' 258 endfunction 259 260 new 261 set completeopt+=noinsert 262 inoremap <F5> <C-R>=s:complTest1()<CR> 263 call feedkeys("i\<F5>soun\<CR>\<CR>\<ESC>.", 'tx') 264 call assert_equal('soundfold', getline(1)) 265 call assert_equal('soundfold', getline(2)) 266 bwipe! 267 268 new 269 inoremap <F5> <C-R>=s:complTest2()<CR> 270 call feedkeys("i\<F5>\<CR>\<ESC>", 'tx') 271 call assert_equal('source', getline(1)) 272 bwipe! 273 274 set completeopt-=noinsert 275 iunmap <F5> 276endfunc 277 278func Test_compl_vim_cmds_after_register_expr() 279 function! s:test_func() 280 return 'autocmd ' 281 endfunction 282 augroup AAAAA_Group 283 au! 284 augroup END 285 286 new 287 call feedkeys("i\<c-r>=s:test_func()\<CR>\<C-x>\<C-v>\<Esc>", 'tx') 288 call assert_equal('autocmd AAAAA_Group', getline(1)) 289 autocmd! AAAAA_Group 290 augroup! AAAAA_Group 291 bwipe! 292endfunc 293 294func DummyCompleteOne(findstart, base) 295 if a:findstart 296 return 0 297 else 298 wincmd n 299 return ['onedef', 'oneDEF'] 300 endif 301endfunc 302 303" Test that nothing happens if the 'completefunc' opens 304" a new window (no completion, no crash) 305func Test_completefunc_opens_new_window_one() 306 new 307 let winid = win_getid() 308 setlocal completefunc=DummyCompleteOne 309 call setline(1, 'one') 310 /^one 311 call assert_fails('call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")', 'E839:') 312 call assert_notequal(winid, win_getid()) 313 q! 314 call assert_equal(winid, win_getid()) 315 call assert_equal('', getline(1)) 316 q! 317endfunc 318 319" Test that nothing happens if the 'completefunc' opens 320" a new window (no completion, no crash) 321func DummyCompleteTwo(findstart, base) 322 if a:findstart 323 wincmd n 324 return 0 325 else 326 return ['twodef', 'twoDEF'] 327 endif 328endfunction 329 330" Test that nothing happens if the 'completefunc' opens 331" a new window (no completion, no crash) 332func Test_completefunc_opens_new_window_two() 333 new 334 let winid = win_getid() 335 setlocal completefunc=DummyCompleteTwo 336 call setline(1, 'two') 337 /^two 338 call assert_fails('call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")', 'E764:') 339 call assert_notequal(winid, win_getid()) 340 q! 341 call assert_equal(winid, win_getid()) 342 call assert_equal('two', getline(1)) 343 q! 344endfunc 345 346func DummyCompleteThree(findstart, base) 347 if a:findstart 348 return 0 349 else 350 return ['threedef', 'threeDEF'] 351 endif 352endfunc 353 354:"Test that 'completefunc' works when it's OK. 355func Test_completefunc_works() 356 new 357 let winid = win_getid() 358 setlocal completefunc=DummyCompleteThree 359 call setline(1, 'three') 360 /^three 361 call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x") 362 call assert_equal(winid, win_getid()) 363 call assert_equal('threeDEF', getline(1)) 364 q! 365endfunc 366 367func DummyCompleteFour(findstart, base) 368 if a:findstart 369 return 0 370 else 371 call complete_add('four1') 372 call complete_add('four2') 373 call complete_check() 374 call complete_add('four3') 375 call complete_add('four4') 376 call complete_check() 377 call complete_add('four5') 378 call complete_add('four6') 379 return [] 380 endif 381endfunc 382 383" Test that 'omnifunc' works when it's OK. 384func Test_omnifunc_with_check() 385 new 386 setlocal omnifunc=DummyCompleteFour 387 call setline(1, 'four') 388 /^four 389 call feedkeys("A\<C-X>\<C-O>\<C-N>\<Esc>", "x") 390 call assert_equal('four2', getline(1)) 391 392 call setline(1, 'four') 393 /^four 394 call feedkeys("A\<C-X>\<C-O>\<C-N>\<C-N>\<Esc>", "x") 395 call assert_equal('four3', getline(1)) 396 397 call setline(1, 'four') 398 /^four 399 call feedkeys("A\<C-X>\<C-O>\<C-N>\<C-N>\<C-N>\<C-N>\<Esc>", "x") 400 call assert_equal('four5', getline(1)) 401 402 q! 403endfunc 404 405function UndoComplete() 406 call complete(1, ['January', 'February', 'March', 407 \ 'April', 'May', 'June', 'July', 'August', 'September', 408 \ 'October', 'November', 'December']) 409 return '' 410endfunc 411 412" Test that no undo item is created when no completion is inserted 413func Test_complete_no_undo() 414 set completeopt=menu,preview,noinsert,noselect 415 inoremap <Right> <C-R>=UndoComplete()<CR> 416 new 417 call feedkeys("ixxx\<CR>\<CR>yyy\<Esc>k", 'xt') 418 call feedkeys("iaaa\<Esc>0", 'xt') 419 call assert_equal('aaa', getline(2)) 420 call feedkeys("i\<Right>\<Esc>", 'xt') 421 call assert_equal('aaa', getline(2)) 422 call feedkeys("u", 'xt') 423 call assert_equal('', getline(2)) 424 425 call feedkeys("ibbb\<Esc>0", 'xt') 426 call assert_equal('bbb', getline(2)) 427 call feedkeys("A\<Right>\<Down>\<CR>\<Esc>", 'xt') 428 call assert_equal('January', getline(2)) 429 call feedkeys("u", 'xt') 430 call assert_equal('bbb', getline(2)) 431 432 call feedkeys("A\<Right>\<C-N>\<Esc>", 'xt') 433 call assert_equal('January', getline(2)) 434 call feedkeys("u", 'xt') 435 call assert_equal('bbb', getline(2)) 436 437 iunmap <Right> 438 set completeopt& 439 q! 440endfunc 441 442function! DummyCompleteFive(findstart, base) 443 if a:findstart 444 return 0 445 else 446 return [ 447 \ { 'word': 'January', 'info': "info1-1\n1-2\n1-3" }, 448 \ { 'word': 'February', 'info': "info2-1\n2-2\n2-3" }, 449 \ { 'word': 'March', 'info': "info3-1\n3-2\n3-3" }, 450 \ { 'word': 'April', 'info': "info4-1\n4-2\n4-3" }, 451 \ { 'word': 'May', 'info': "info5-1\n5-2\n5-3" }, 452 \ ] 453 endif 454endfunc 455 456" Test that 'completefunc' on Scratch buffer with preview window works when 457" it's OK. 458func Test_completefunc_with_scratch_buffer() 459 new +setlocal\ buftype=nofile\ bufhidden=wipe\ noswapfile 460 set completeopt+=preview 461 setlocal completefunc=DummyCompleteFive 462 call feedkeys("A\<C-X>\<C-U>\<C-N>\<C-N>\<C-N>\<Esc>", "x") 463 call assert_equal(['April'], getline(1, '$')) 464 pclose 465 q! 466 set completeopt& 467endfunc 468 469" <C-E> - select original typed text before the completion started without 470" auto-wrap text. 471func Test_completion_ctrl_e_without_autowrap() 472 new 473 let tw_save = &tw 474 set tw=78 475 let li = [ 476 \ '" zzz', 477 \ '" zzzyyyyyyyyyyyyyyyyyyy'] 478 call setline(1, li) 479 0 480 call feedkeys("A\<C-X>\<C-N>\<C-E>\<Esc>", "tx") 481 call assert_equal(li, getline(1, '$')) 482 483 let &tw = tw_save 484 q! 485endfunc 486 487function! DummyCompleteSix() 488 call complete(1, ['Hello', 'World']) 489 return '' 490endfunction 491 492" complete() correctly clears the list of autocomplete candidates 493" See #1411 494func Test_completion_clear_candidate_list() 495 new 496 %d 497 " select first entry from the completion popup 498 call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>", "tx") 499 call assert_equal('Hello', getline(1)) 500 %d 501 " select second entry from the completion popup 502 call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>", "tx") 503 call assert_equal('World', getline(1)) 504 %d 505 " select original text 506 call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>\<C-N>", "tx") 507 call assert_equal(' xxx', getline(1)) 508 %d 509 " back at first entry from completion list 510 call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>\<C-N>\<C-N>", "tx") 511 call assert_equal('Hello', getline(1)) 512 513 bw! 514endfunc 515 516func Test_completion_respect_bs_option() 517 new 518 let li = ["aaa", "aaa12345", "aaaabcdef", "aaaABC"] 519 520 set bs=indent,eol 521 call setline(1, li) 522 1 523 call feedkeys("A\<C-X>\<C-N>\<C-P>\<BS>\<BS>\<BS>\<Esc>", "tx") 524 call assert_equal('aaa', getline(1)) 525 526 %d 527 set bs=indent,eol,start 528 call setline(1, li) 529 1 530 call feedkeys("A\<C-X>\<C-N>\<C-P>\<BS>\<BS>\<BS>\<Esc>", "tx") 531 call assert_equal('', getline(1)) 532 533 bw! 534endfunc 535 536func CompleteUndo() abort 537 call complete(1, g:months) 538 return '' 539endfunc 540 541func Test_completion_can_undo() 542 inoremap <Right> <c-r>=CompleteUndo()<cr> 543 set completeopt+=noinsert,noselect 544 545 new 546 call feedkeys("a\<Right>a\<Esc>", 'xt') 547 call assert_equal('a', getline(1)) 548 undo 549 call assert_equal('', getline(1)) 550 551 bwipe! 552 set completeopt& 553 iunmap <Right> 554endfunc 555 556func Test_completion_comment_formatting() 557 new 558 setl formatoptions=tcqro 559 call feedkeys("o/*\<cr>\<cr>/\<esc>", 'tx') 560 call assert_equal(['', '/*', ' *', ' */'], getline(1,4)) 561 %d 562 call feedkeys("o/*\<cr>foobar\<cr>/\<esc>", 'tx') 563 call assert_equal(['', '/*', ' * foobar', ' */'], getline(1,4)) 564 %d 565 try 566 call feedkeys("o/*\<cr>\<cr>\<c-x>\<c-u>/\<esc>", 'tx') 567 call assert_report('completefunc not set, should have failed') 568 catch 569 call assert_exception('E764:') 570 endtry 571 call assert_equal(['', '/*', ' *', ' */'], getline(1,4)) 572 bwipe! 573endfunc 574 575fun MessCompleteMonths() 576 for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep") 577 call complete_add(m) 578 if complete_check() 579 break 580 endif 581 endfor 582 return [] 583endfun 584 585fun MessCompleteMore() 586 call complete(1, split("Oct Nov Dec")) 587 return [] 588endfun 589 590fun MessComplete(findstart, base) 591 if a:findstart 592 let line = getline('.') 593 let start = col('.') - 1 594 while start > 0 && line[start - 1] =~ '\a' 595 let start -= 1 596 endwhile 597 return start 598 else 599 call MessCompleteMonths() 600 call MessCompleteMore() 601 return [] 602 endif 603endf 604 605func Test_complete_func_mess() 606 " Calling complete() after complete_add() in 'completefunc' is wrong, but it 607 " should not crash. 608 set completefunc=MessComplete 609 new 610 call setline(1, 'Ju') 611 call feedkeys("A\<c-x>\<c-u>/\<esc>", 'tx') 612 call assert_equal('Oct/Oct', getline(1)) 613 bwipe! 614 set completefunc= 615endfunc 616 617func Test_complete_CTRLN_startofbuffer() 618 new 619 call setline(1, [ 'organize(cupboard, 3, 2);', 620 \ 'prioritize(bureau, 8, 7);', 621 \ 'realize(bannister, 4, 4);', 622 \ 'moralize(railing, 3,9);']) 623 let expected=['cupboard.organize(3, 2);', 624 \ 'bureau.prioritize(8, 7);', 625 \ 'bannister.realize(4, 4);', 626 \ 'railing.moralize(3,9);'] 627 call feedkeys("qai\<c-n>\<c-n>.\<esc>3wdW\<cr>q3@a", 'tx') 628 call assert_equal(expected, getline(1,'$')) 629 bwipe! 630endfunc 631 632func Test_popup_and_window_resize() 633 if !has('terminal') || has('gui_running') 634 return 635 endif 636 let h = winheight(0) 637 if h < 15 638 return 639 endif 640 let rows = h / 3 641 let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile'], {'term_rows': rows}) 642 call term_sendkeys(buf, (h / 3 - 1) . "o\<esc>") 643 " Wait for the nested Vim to exit insert mode, where it will show the ruler. 644 " Need to trigger a redraw. 645 call WaitFor({-> execute("redraw") == "" && term_getline(buf, rows) =~ '\<' . rows . ',.*Bot'}) 646 647 call term_sendkeys(buf, "Gi\<c-x>") 648 call term_sendkeys(buf, "\<c-v>") 649 call term_wait(buf, 100) 650 " popup first entry "!" must be at the top 651 call WaitFor({-> term_getline(buf, 1) =~ "^!"}) 652 call assert_match('^!\s*$', term_getline(buf, 1)) 653 exe 'resize +' . (h - 1) 654 call term_wait(buf, 100) 655 redraw! 656 " popup shifted down, first line is now empty 657 call WaitFor({-> term_getline(buf, 1) == ""}) 658 call assert_equal('', term_getline(buf, 1)) 659 sleep 100m 660 " popup is below cursor line and shows first match "!" 661 call WaitFor({-> term_getline(buf, term_getcursor(buf)[0] + 1) =~ "^!"}) 662 call assert_match('^!\s*$', term_getline(buf, term_getcursor(buf)[0] + 1)) 663 " cursor line also shows ! 664 call assert_match('^!\s*$', term_getline(buf, term_getcursor(buf)[0])) 665 bwipe! 666endfunc 667 668func Test_popup_and_preview_autocommand() 669 " This used to crash Vim 670 if !has('python') 671 return 672 endif 673 let h = winheight(0) 674 if h < 15 675 return 676 endif 677 new 678 augroup MyBufAdd 679 au! 680 au BufAdd * nested tab sball 681 augroup END 682 set omnifunc=pythoncomplete#Complete 683 call setline(1, 'import os') 684 " make the line long 685 call setline(2, ' os.') 686 $ 687 call feedkeys("A\<C-X>\<C-O>\<C-N>\<C-N>\<C-N>\<enter>\<esc>", 'tx') 688 call assert_equal("import os", getline(1)) 689 call assert_match(' os.\(EX_IOERR\|O_CREAT\)$', getline(2)) 690 call assert_equal(1, winnr('$')) 691 " previewwindow option is not set 692 call assert_equal(0, &previewwindow) 693 norm! gt 694 call assert_equal(0, &previewwindow) 695 norm! gT 696 call assert_equal(12, tabpagenr('$')) 697 tabonly 698 pclose 699 augroup MyBufAdd 700 au! 701 augroup END 702 augroup! MyBufAdd 703 bw! 704endfunc 705 706" vim: shiftwidth=2 sts=2 expandtab 707