robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
3b00ddb601
master
1" Test for completion menu 2 3source shared.vim 4source screendump.vim 5source check.vim 6 7let g: months = [ 'January' , 'February' , 'March' , 'April' , 'May' , 'June' , 'July' , 'August' , 'September' , 'October' , 'November' , 'December' ] 8let g: setting = '' 9 10func ListMonths () 11if g: setting != '' 12exe ":set" g: setting 13endif 14let mth = copy ( g: months ) 15let entered = strcharpart ( getline ( '.' ), 0 , col ( '.' )) 16if ! empty ( entered ) 17let mth = filter ( mth , 'v:val=~"^".entered' ) 18endif 19call complete ( 1 , mth ) 20return '' 21endfunc 22 23func Test_popup_complete2 () 24" Although the popupmenu is not visible, this does not mean completion mode 25" has ended. After pressing <f5> to complete the currently typed char, Vim 26" still stays in the first state of the completion (:h ins-completion-menu), 27" although the popupmenu wasn't shown <c-e> will remove the inserted 28" completed text (:h complete_CTRL-E), while the following <c-e> will behave 29" like expected (:h i_CTRL-E) 30new 31inoremap < f5 > < c-r > =ListMonths()< cr > 32call append ( 1 , [ "December2015" ]) 33: 1 34call feedkeys ( "aD\<f5>\<C-E>\<C-E>\<C-E>\<C-E>\<enter>\<esc>" , 'tx' ) 35call assert_equal ([ "Dece" , "" , "December2015" ], getline ( 1 , 3 )) 36 %d 37bw ! 38endfunc 39 40func Test_popup_complete () 41new 42inoremap < f5 > < c-r > =ListMonths()< cr > 43 44" <C-E> - select original typed text before the completion started 45call feedkeys ( "aJu\<f5>\<down>\<c-e>\<esc>" , 'tx' ) 46call assert_equal ([ "Ju" ], getline ( 1 , 2 )) 47 %d 48 49" <C-Y> - accept current match 50call feedkeys ( "a\<f5>" . repeat ( "\<down>" , 7 ) . "\<c-y>\<esc>" , 'tx' ) 51call assert_equal ([ "August" ], getline ( 1 , 2 )) 52 %d 53 54" <BS> - Delete one character from the inserted text (state: 1) 55" TODO: This should not end the completion, but it does. 56" This should according to the documentation: 57" January 58" but instead, this does 59" Januar 60" (idea is, C-L inserts the match from the popup menu 61" but if the menu is closed, it will insert the character <c-l> 62call feedkeys ( "aJ\<f5>\<bs>\<c-l>\<esc>" , 'tx' ) 63call assert_equal ([ "Januar" ], getline ( 1 , 2 )) 64 %d 65 66" any-non special character: Stop completion without changing the match 67" and insert the typed character 68call feedkeys ( "a\<f5>20" , 'tx' ) 69call assert_equal ([ "January20" ], getline ( 1 , 2 )) 70 %d 71 72" any-non printable, non-white character: Add this character and 73" reduce number of matches 74call feedkeys ( "aJu\<f5>\<c-p>l\<c-y>" , 'tx' ) 75call assert_equal ([ "Jul" ], getline ( 1 , 2 )) 76 %d 77 78" any-non printable, non-white character: Add this character and 79" reduce number of matches 80call feedkeys ( "aJu\<f5>\<c-p>l\<c-n>\<c-y>" , 'tx' ) 81call assert_equal ([ "July" ], getline ( 1 , 2 )) 82 %d 83 84" any-non printable, non-white character: Add this character and 85" reduce number of matches 86call feedkeys ( "aJu\<f5>\<c-p>l\<c-e>" , 'tx' ) 87call assert_equal ([ "Jul" ], getline ( 1 , 2 )) 88 %d 89 90" <BS> - Delete one character from the inserted text (state: 2) 91call feedkeys ( "a\<f5>\<c-n>\<bs>" , 'tx' ) 92call assert_equal ([ "Februar" ], getline ( 1 , 2 )) 93 %d 94 95" <c-l> - Insert one character from the current match 96call feedkeys ( "aJ\<f5>" . repeat ( "\<c-n>" , 3 ) . "\<c-l>\<esc>" , 'tx' ) 97call assert_equal ([ "J" ], getline ( 1 , 2 )) 98 %d 99 100" <c-l> - Insert one character from the current match 101call feedkeys ( "aJ\<f5>" . repeat ( "\<c-n>" , 4 ) . "\<c-l>\<esc>" , 'tx' ) 102call assert_equal ([ "January" ], getline ( 1 , 2 )) 103 %d 104 105" <c-y> - Accept current selected match 106call feedkeys ( "aJ\<f5>\<c-y>\<esc>" , 'tx' ) 107call assert_equal ([ "January" ], getline ( 1 , 2 )) 108 %d 109 110" <c-e> - End completion, go back to what was there before selecting a match 111call feedkeys ( "aJu\<f5>\<c-e>\<esc>" , 'tx' ) 112call assert_equal ([ "Ju" ], getline ( 1 , 2 )) 113 %d 114 115" <PageUp> - Select a match several entries back 116call feedkeys ( "a\<f5>\<PageUp>\<c-y>\<esc>" , 'tx' ) 117call assert_equal ([ "" ], getline ( 1 , 2 )) 118 %d 119 120" <PageUp><PageUp> - Select a match several entries back 121call feedkeys ( "a\<f5>\<PageUp>\<PageUp>\<c-y>\<esc>" , 'tx' ) 122call assert_equal ([ "December" ], getline ( 1 , 2 )) 123 %d 124 125" <PageUp><PageUp><PageUp> - Select a match several entries back 126call feedkeys ( "a\<f5>\<PageUp>\<PageUp>\<PageUp>\<c-y>\<esc>" , 'tx' ) 127call assert_equal ([ "February" ], getline ( 1 , 2 )) 128 %d 129 130" <PageDown> - Select a match several entries further 131call feedkeys ( "a\<f5>\<PageDown>\<c-y>\<esc>" , 'tx' ) 132call assert_equal ([ "November" ], getline ( 1 , 2 )) 133 %d 134 135" <PageDown><PageDown> - Select a match several entries further 136call feedkeys ( "a\<f5>\<PageDown>\<PageDown>\<c-y>\<esc>" , 'tx' ) 137call assert_equal ([ "December" ], getline ( 1 , 2 )) 138 %d 139 140" <PageDown><PageDown><PageDown> - Select a match several entries further 141call feedkeys ( "a\<f5>\<PageDown>\<PageDown>\<PageDown>\<c-y>\<esc>" , 'tx' ) 142call assert_equal ([ "" ], getline ( 1 , 2 )) 143 %d 144 145" <PageDown><PageDown><PageDown><PageDown> - Select a match several entries further 146call feedkeys ( "a\<f5>" . repeat ( "\<PageDown>" , 4 ) . "\<c-y>\<esc>" , 'tx' ) 147call assert_equal ([ "October" ], getline ( 1 , 2 )) 148 %d 149 150" <Up> - Select a match don't insert yet 151call feedkeys ( "a\<f5>\<Up>\<c-y>\<esc>" , 'tx' ) 152call assert_equal ([ "" ], getline ( 1 , 2 )) 153 %d 154 155" <Up><Up> - Select a match don't insert yet 156call feedkeys ( "a\<f5>\<Up>\<Up>\<c-y>\<esc>" , 'tx' ) 157call assert_equal ([ "December" ], getline ( 1 , 2 )) 158 %d 159 160" <Up><Up><Up> - Select a match don't insert yet 161call feedkeys ( "a\<f5>\<Up>\<Up>\<Up>\<c-y>\<esc>" , 'tx' ) 162call assert_equal ([ "November" ], getline ( 1 , 2 )) 163 %d 164 165" <Tab> - Stop completion and insert the match 166call feedkeys ( "a\<f5>\<Tab>\<c-y>\<esc>" , 'tx' ) 167call assert_equal ([ "January " ], getline ( 1 , 2 )) 168 %d 169 170" <Space> - Stop completion and insert the match 171call feedkeys ( "a\<f5>" . repeat ( "\<c-p>" , 5 ) . " \<esc>" , 'tx' ) 172call assert_equal ([ "September " ], getline ( 1 , 2 )) 173 %d 174 175" <Enter> - Use the text and insert line break (state: 1) 176call feedkeys ( "a\<f5>\<enter>\<esc>" , 'tx' ) 177call assert_equal ([ "January" , '' ], getline ( 1 , 2 )) 178 %d 179 180" <Enter> - Insert the current selected text (state: 2) 181call feedkeys ( "a\<f5>" . repeat ( "\<Up>" , 5 ) . "\<enter>\<esc>" , 'tx' ) 182call assert_equal ([ "September" ], getline ( 1 , 2 )) 183 %d 184 185" Insert match immediately, if there is only one match 186" <c-y> selects a character from the line above 187call append ( 0 , [ "December2015" ]) 188call feedkeys ( "aD\<f5>\<C-Y>\<C-Y>\<C-Y>\<C-Y>\<enter>\<esc>" , 'tx' ) 189call assert_equal ([ "December2015" , "December2015" , "" ], getline ( 1 , 3 )) 190 %d 191 192" use menuone for 'completeopt' 193" Since for the first <c-y> the menu is still shown, will only select 194" three letters from the line above 195set completeopt & vim 196set completeopt += menuone 197call append ( 0 , [ "December2015" ]) 198call feedkeys ( "aD\<f5>\<C-Y>\<C-Y>\<C-Y>\<C-Y>\<enter>\<esc>" , 'tx' ) 199call assert_equal ([ "December2015" , "December201" , "" ], getline ( 1 , 3 )) 200 %d 201 202" use longest for 'completeopt' 203set completeopt & vim 204call feedkeys ( "aM\<f5>\<C-N>\<C-P>\<c-e>\<enter>\<esc>" , 'tx' ) 205set completeopt += longest 206call feedkeys ( "aM\<f5>\<C-N>\<C-P>\<c-e>\<enter>\<esc>" , 'tx' ) 207call assert_equal ([ "M" , "Ma" , "" ], getline ( 1 , 3 )) 208 %d 209 210" use noselect/noinsert for 'completeopt' 211set completeopt & vim 212call feedkeys ( "aM\<f5>\<enter>\<esc>" , 'tx' ) 213set completeopt += noselect 214call feedkeys ( "aM\<f5>\<enter>\<esc>" , 'tx' ) 215set completeopt -= noselectcompleteopt += noinsert 216call feedkeys ( "aM\<f5>\<enter>\<esc>" , 'tx' ) 217call assert_equal ([ "March" , "M" , "March" ], getline ( 1 , 4 )) 218 %d 219 220set completeopt & 221endfunc 222 223func Test_popup_completion_insertmode () 224new 225inoremap < F5 > < C-R > =ListMonths()< CR > 226 227call feedkeys ( "a\<f5>\<down>\<enter>\<esc>" , 'tx' ) 228call assert_equal ( 'February' , getline ( 1 )) 229 %d 230" Set noinsertmode 231let g: setting = 'noinsertmode' 232call feedkeys ( "a\<f5>\<down>\<enter>\<esc>" , 'tx' ) 233call assert_equal ( 'February' , getline ( 1 )) 234call assert_false ( pumvisible ()) 235 %d 236" Go through all matches, until none is selected 237let g: setting = '' 238call feedkeys ( "a\<f5>" . repeat ( "\<c-n>" , 12 ) . "\<enter>\<esc>" , 'tx' ) 239call assert_equal ( '' , getline ( 1 )) 240 %d 241" select previous entry 242call feedkeys ( "a\<f5>\<c-p>\<enter>\<esc>" , 'tx' ) 243call assert_equal ( '' , getline ( 1 )) 244 %d 245" select last entry 246call feedkeys ( "a\<f5>\<c-p>\<c-p>\<enter>\<esc>" , 'tx' ) 247call assert_equal ( 'December' , getline ( 1 )) 248 249iunmap <F5> 250endfunc 251 252func Test_noinsert_complete () 253func ! s: complTest1 () abort 254eval [ 'source' , 'soundfold' ] ->complete ( 1 ) 255return '' 256endfunc 257 258func ! s: complTest2 () abort 259call complete ( 1 , [ 'source' , 'soundfold' ]) 260return '' 261endfunc 262 263new 264set completeopt += noinsert 265inoremap < F5 > < C-R > =s:complTest1()< CR > 266call feedkeys ( "i\<F5>soun\<CR>\<CR>\<ESC>." , 'tx' ) 267call assert_equal ( 'soundfold' , getline ( 1 )) 268call assert_equal ( 'soundfold' , getline ( 2 )) 269bwipe ! 270 271new 272inoremap < F5 > < C-R > =s:complTest2()< CR > 273call feedkeys ( "i\<F5>\<CR>\<ESC>" , 'tx' ) 274call assert_equal ( 'source' , getline ( 1 )) 275bwipe ! 276 277set completeopt -= noinsert 278iunmap <F5> 279endfunc 280 281func Test_complete_no_filter () 282func ! s: complTest1 () abort 283call complete ( 1 , [{ 'word' : 'foobar' }]) 284return '' 285endfunc 286func ! s: complTest2 () abort 287call complete ( 1 , [{ 'word' : 'foobar' , 'equal' : 1 }]) 288return '' 289endfunc 290 291let completeopt = & completeopt 292 293" without equal=1 294new 295set completeopt = menuone,noinsert,menu 296inoremap < F5 > < C-R > =s:complTest1()< CR > 297call feedkeys ( "i\<F5>z\<CR>\<CR>\<ESC>." , 'tx' ) 298call assert_equal ( 'z' , getline ( 1 )) 299bwipe ! 300 301" with equal=1 302new 303set completeopt = menuone,noinsert,menu 304inoremap < F5 > < C-R > =s:complTest2()< CR > 305call feedkeys ( "i\<F5>z\<CR>\<CR>\<ESC>." , 'tx' ) 306call assert_equal ( 'foobar' , getline ( 1 )) 307bwipe ! 308 309let & completeopt = completeopt 310iunmap <F5> 311endfunc 312 313func Test_compl_vim_cmds_after_register_expr () 314func ! s: test_func () 315return 'autocmd ' 316endfunc 317augroup AAAAA_Group 318au ! 319augroup END 320 321new 322call feedkeys ( "i\<c-r>=s:test_func()\<CR>\<C-x>\<C-v>\<Esc>" , 'tx' ) 323call assert_equal ( 'autocmd AAAAA_Group' , getline ( 1 )) 324autocmd ! AAAAA_Group 325augroup ! AAAAA_Group 326bwipe ! 327endfunc 328 329func Test_compl_ignore_mappings () 330call setline ( 1 , [ 'foo' , 'bar' , 'baz' , 'foobar' ]) 331inoremap < C-P > (C-P) 332inoremap < C-N > (C-N) 333normal ! G 334call feedkeys ( "o\<C-X>\<C-N>\<C-N>\<C-N>\<C-P>\<C-N>\<C-Y>" , 'tx' ) 335call assert_equal ( 'baz' , getline ( '.' )) 336" Also test with unsimplified keys 337call feedkeys ( "o\<C-X>\<*C-N>\<*C-N>\<*C-N>\<*C-P>\<*C-N>\<C-Y>" , 'tx' ) 338call assert_equal ( 'baz' , getline ( '.' )) 339iunmap <C-P> 340iunmap <C-N> 341bwipe ! 342endfunc 343 344func DummyCompleteOne ( findstart , base ) 345if a: findstart 346return 0 347else 348wincmd n 349return [ 'onedef' , 'oneDEF' ] 350endif 351endfunc 352 353" Test that nothing happens if the 'completefunc' tries to open 354" a new window (fails to open window, continues) 355func Test_completefunc_opens_new_window_one () 356new 357let winid = win_getid () 358setlocal completefunc = DummyCompleteOne 359call setline ( 1 , 'one' ) 360/ ^one 361call assert_fails ( 'call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")' , 'E565:' ) 362call assert_equal ( winid , win_getid ()) 363call assert_equal ( 'onedef' , getline ( 1 )) 364q ! 365endfunc 366 367" Test that nothing happens if the 'completefunc' opens 368" a new window (no completion, no crash) 369func DummyCompleteTwo ( findstart , base ) 370if a: findstart 371wincmd n 372return 0 373else 374return [ 'twodef' , 'twoDEF' ] 375endif 376endfunc 377 378" Test that nothing happens if the 'completefunc' opens 379" a new window (no completion, no crash) 380func Test_completefunc_opens_new_window_two () 381new 382let winid = win_getid () 383setlocal completefunc = DummyCompleteTwo 384call setline ( 1 , 'two' ) 385/ ^two 386call assert_fails ( 'call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")' , 'E565:' ) 387call assert_equal ( winid , win_getid ()) 388call assert_equal ( 'twodef' , getline ( 1 )) 389q ! 390endfunc 391 392func DummyCompleteThree ( findstart , base ) 393if a: findstart 394return 0 395else 396return [ 'threedef' , 'threeDEF' ] 397endif 398endfunc 399 400: "Test that 'completefunc' works when it'sOK. 401func Test_completefunc_works () 402new 403let winid = win_getid () 404setlocal completefunc = DummyCompleteThree 405call setline ( 1 , 'three' ) 406/ ^three 407call feedkeys ( "A\<C-X>\<C-U>\<C-N>\<Esc>" , "x" ) 408call assert_equal ( winid , win_getid ()) 409call assert_equal ( 'threeDEF' , getline ( 1 )) 410q ! 411endfunc 412 413func DummyCompleteFour ( findstart , base ) 414if a: findstart 415return 0 416else 417call complete_add ( 'four1' ) 418eval 'four2' ->complete_add () 419call complete_check () 420call complete_add ( 'four3' ) 421call complete_add ( 'four4' ) 422call complete_check () 423call complete_add ( 'four5' ) 424call complete_add ( 'four6' ) 425return [] 426endif 427endfunc 428 429" Test that 'omnifunc' works when it's OK. 430func Test_omnifunc_with_check () 431new 432setlocal omnifunc = DummyCompleteFour 433call setline ( 1 , 'four' ) 434/ ^four 435call feedkeys ( "A\<C-X>\<C-O>\<C-N>\<Esc>" , "x" ) 436call assert_equal ( 'four2' , getline ( 1 )) 437 438call setline ( 1 , 'four' ) 439/ ^four 440call feedkeys ( "A\<C-X>\<C-O>\<C-N>\<C-N>\<Esc>" , "x" ) 441call assert_equal ( 'four3' , getline ( 1 )) 442 443call setline ( 1 , 'four' ) 444/ ^four 445call feedkeys ( "A\<C-X>\<C-O>\<C-N>\<C-N>\<C-N>\<C-N>\<Esc>" , "x" ) 446call assert_equal ( 'four5' , getline ( 1 )) 447 448q ! 449endfunc 450 451func UndoComplete () 452call complete ( 1 , [ 'January' , 'February' , 'March' , 453 \'April' , 'May' , 'June' , 'July' , 'August' , 'September' , 454 \'October' , 'November' , 'December' ]) 455return '' 456endfunc 457 458" Test that no undo item is created when no completion is inserted 459func Test_complete_no_undo () 460set completeopt = menu,preview,noinsert,noselect 461inoremap < Right > < C-R > =UndoComplete()< CR > 462new 463call feedkeys ( "ixxx\<CR>\<CR>yyy\<Esc>k" , 'xt' ) 464call feedkeys ( "iaaa\<Esc>0" , 'xt' ) 465call assert_equal ( 'aaa' , getline ( 2 )) 466call feedkeys ( "i\<Right>\<Esc>" , 'xt' ) 467call assert_equal ( 'aaa' , getline ( 2 )) 468call feedkeys ( "u" , 'xt' ) 469call assert_equal ( '' , getline ( 2 )) 470 471call feedkeys ( "ibbb\<Esc>0" , 'xt' ) 472call assert_equal ( 'bbb' , getline ( 2 )) 473call feedkeys ( "A\<Right>\<Down>\<CR>\<Esc>" , 'xt' ) 474call assert_equal ( 'January' , getline ( 2 )) 475call feedkeys ( "u" , 'xt' ) 476call assert_equal ( 'bbb' , getline ( 2 )) 477 478call feedkeys ( "A\<Right>\<C-N>\<Esc>" , 'xt' ) 479call assert_equal ( 'January' , getline ( 2 )) 480call feedkeys ( "u" , 'xt' ) 481call assert_equal ( 'bbb' , getline ( 2 )) 482 483iunmap <Right> 484set completeopt & 485q ! 486endfunc 487 488func DummyCompleteFive ( findstart , base ) 489if a: findstart 490return 0 491else 492return [ 493 \{ 'word' : 'January' , 'info' : "info1-1\n1-2\n1-3" }, 494 \{ 'word' : 'February' , 'info' : "info2-1\n2-2\n2-3" }, 495 \{ 'word' : 'March' , 'info' : "info3-1\n3-2\n3-3" }, 496 \{ 'word' : 'April' , 'info' : "info4-1\n4-2\n4-3" }, 497 \{ 'word' : 'May' , 'info' : "info5-1\n5-2\n5-3" }, 498 \] 499endif 500endfunc 501 502" Test that 'completefunc' on Scratch buffer with preview window works when 503" it's OK. 504func Test_completefunc_with_scratch_buffer () 505CheckFeature quickfix 506 507new +setlocal\ buftype=nofile\ bufhidden=wipe\ noswapfile 508set completeopt += preview 509setlocal completefunc = DummyCompleteFive 510call feedkeys ( "A\<C-X>\<C-U>\<C-N>\<C-N>\<C-N>\<Esc>" , "x" ) 511call assert_equal ([ 'April' ], getline ( 1 , '$' )) 512pclose 513q ! 514set completeopt & 515endfunc 516 517" <C-E> - select original typed text before the completion started without 518" auto-wrap text. 519func Test_completion_ctrl_e_without_autowrap () 520new 521let tw_save = & tw 522set tw = 78 523let li = [ 524 \'" zzz' , 525 \'" zzzyyyyyyyyyyyyyyyyyyy' ] 526call setline ( 1 , li ) 5270 528call feedkeys ( "A\<C-X>\<C-N>\<C-E>\<Esc>" , "tx" ) 529call assert_equal ( li , getline ( 1 , '$' )) 530 531let & tw = tw_save 532q ! 533endfunc 534 535func DummyCompleteSix () 536call complete ( 1 , [ 'Hello' , 'World' ]) 537return '' 538endfunction 539 540" complete() correctly clears the list of autocomplete candidates 541" See #1411 542func Test_completion_clear_candidate_list () 543new 544 %d 545" select first entry from the completion popup 546call feedkeys ( "a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>" , "tx" ) 547call assert_equal ( 'Hello' , getline ( 1 )) 548 %d 549" select second entry from the completion popup 550call feedkeys ( "a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>" , "tx" ) 551call assert_equal ( 'World' , getline ( 1 )) 552 %d 553" select original text 554call feedkeys ( "a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>\<C-N>" , "tx" ) 555call assert_equal ( ' xxx' , getline ( 1 )) 556 %d 557" back at first entry from completion list 558call feedkeys ( "a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>\<C-N>\<C-N>" , "tx" ) 559call assert_equal ( 'Hello' , getline ( 1 )) 560 561bw ! 562endfunc 563 564func Test_completion_respect_bs_option () 565new 566let li = [ "aaa" , "aaa12345" , "aaaabcdef" , "aaaABC" ] 567 568set bs = indent,eol 569call setline ( 1 , li ) 5701 571call feedkeys ( "A\<C-X>\<C-N>\<C-P>\<BS>\<BS>\<BS>\<Esc>" , "tx" ) 572call assert_equal ( 'aaa' , getline ( 1 )) 573 574 %d 575set bs = indent,eol,start 576call setline ( 1 , li ) 5771 578call feedkeys ( "A\<C-X>\<C-N>\<C-P>\<BS>\<BS>\<BS>\<Esc>" , "tx" ) 579call assert_equal ( '' , getline ( 1 )) 580 581bw ! 582endfunc 583 584func CompleteUndo () abort 585call complete ( 1 , g: months ) 586return '' 587endfunc 588 589func Test_completion_can_undo () 590inoremap < Right > < c-r > =CompleteUndo()< cr > 591set completeopt += noinsert,noselect 592 593new 594call feedkeys ( "a\<Right>a\<Esc>" , 'xt' ) 595call assert_equal ( 'a' , getline ( 1 )) 596undo 597call assert_equal ( '' , getline ( 1 )) 598 599bwipe ! 600set completeopt & 601iunmap <Right> 602endfunc 603 604func Test_completion_comment_formatting () 605new 606setl formatoptions = tcqro 607call feedkeys ( "o/*\<cr>\<cr>/\<esc>" , 'tx' ) 608call assert_equal ([ '' , '/*' , ' *' , ' */' ], getline ( 1 , 4 )) 609 %d 610call feedkeys ( "o/*\<cr>foobar\<cr>/\<esc>" , 'tx' ) 611call assert_equal ([ '' , '/*' , ' * foobar' , ' */' ], getline ( 1 , 4 )) 612 %d 613try 614call feedkeys ( "o/*\<cr>\<cr>\<c-x>\<c-u>/\<esc>" , 'tx' ) 615call assert_report ( 'completefunc not set, should have failed' ) 616catch 617call assert_exception ( 'E764:' ) 618endtry 619call assert_equal ([ '' , '/*' , ' *' , ' */' ], getline ( 1 , 4 )) 620bwipe ! 621endfunc 622 623func MessCompleteMonths () 624for m in split ( "Jan Feb Mar Apr May Jun Jul Aug Sep" ) 625call complete_add ( m ) 626if complete_check () 627break 628endif 629endfor 630return [] 631endfunc 632 633func MessCompleteMore () 634call complete ( 1 , split ( "Oct Nov Dec" )) 635return [] 636endfunc 637 638func MessComplete ( findstart , base ) 639if a: findstart 640let line = getline ( '.' ) 641let start = col ( '.' ) - 1 642while start > 0 && line [ start - 1 ] =~ '\a' 643let start -= 1 644endwhile 645return start 646else 647call MessCompleteMonths () 648call MessCompleteMore () 649return [] 650endif 651endfunc 652 653func Test_complete_func_mess () 654" Calling complete() after complete_add() in 'completefunc' is wrong, but it 655" should not crash. 656set completefunc = MessComplete 657new 658call setline ( 1 , 'Ju' ) 659call assert_fails ( 'call feedkeys("A\<c-x>\<c-u>/\<esc>", "tx")' , 'E565:' ) 660call assert_equal ( 'Jan/' , getline ( 1 )) 661bwipe ! 662set completefunc = 663endfunc 664 665func Test_complete_CTRLN_startofbuffer () 666new 667call setline ( 1 , [ 'organize(cupboard, 3, 2);' , 668 \'prioritize(bureau, 8, 7);' , 669 \'realize(bannister, 4, 4);' , 670 \'moralize(railing, 3,9);' ]) 671let expected = [ 'cupboard.organize(3, 2);' , 672 \'bureau.prioritize(8, 7);' , 673 \'bannister.realize(4, 4);' , 674 \'railing.moralize(3,9);' ] 675call feedkeys ( "qai\<c-n>\<c-n>.\<esc>3wdW\<cr>q3@a" , 'tx' ) 676call assert_equal ( expected , getline ( 1 , '$' )) 677bwipe ! 678endfunc 679 680func Test_popup_and_window_resize () 681CheckFeature terminal 682CheckFeature quickfix 683CheckNotGui 684let g: test_is_flaky = 1 685 686let h = winheight ( 0 ) 687if h < 15 688return 689endif 690let rows = h / 3 691let buf = term_start ([ GetVimProg (), '--clean' , '-c' , 'set noswapfile' ], { 'term_rows' : rows }) 692call term_sendkeys ( buf , ( h / 3 - 1 ) . "o\<esc>" ) 693" Wait for the nested Vim to exit insert mode, where it will show the ruler. 694" Need to trigger a redraw. 695call WaitFor ({ ->execute ( "redraw" ) == "" && term_getline ( buf , rows ) =~ '\<' . rows . ',.*Bot' }) 696 697call term_sendkeys ( buf , "Gi\<c-x>" ) 698call term_sendkeys ( buf , "\<c-v>" ) 699call TermWait ( buf , 50 ) 700" popup first entry "!" must be at the top 701call WaitForAssert ({ ->assert_match ( '^!\s*$' , term_getline ( buf , 1 ))}) 702exe 'resize +' . ( h - 1 ) 703call TermWait ( buf , 50 ) 704redraw ! 705" popup shifted down, first line is now empty 706call WaitForAssert ({ ->assert_equal ( '' , term_getline ( buf , 1 ))}) 707sleep 100m 708" popup is below cursor line and shows first match "!" 709call WaitForAssert ({ ->assert_match ( '^!\s*$' , term_getline ( buf , term_getcursor ( buf )[ 0 ] + 1 ))}) 710" cursor line also shows ! 711call assert_match ( '^!\s*$' , term_getline ( buf , term_getcursor ( buf )[ 0 ])) 712bwipe ! 713endfunc 714 715func Test_popup_and_preview_autocommand () 716CheckFeature python 717CheckFeature quickfix 718if winheight ( 0 ) < 15 719throw 'Skipped: window height insufficient' 720endif 721 722" This used to crash Vim 723new 724augroup MyBufAdd 725au ! 726au BufAdd * nested tab sball 727augroup END 728" Let pythoncomplete follow the buffer's 'import os' (off by default 729" since v9.2.0561) so 'os.' can be completed. 730let g: pythoncomplete_allow_import = 1 731set omnifunc = pythoncomplete#Complete 732call setline ( 1 , 'import os' ) 733" make the line long 734call setline ( 2 , ' os.' ) 735$ 736call feedkeys ( "A\<C-X>\<C-O>\<C-N>\<C-N>\<C-N>\<enter>\<esc>" , 'tx' ) 737call assert_equal ( "import os" , getline ( 1 )) 738call assert_match ( ' os.\(EX_IOERR\|O_CREAT\)$' , getline ( 2 )) 739call assert_equal ( 1 , winnr ( '$' )) 740" previewwindow option is not set 741call assert_equal ( 0 , & previewwindow ) 742norm ! gt 743call assert_equal ( 0 , & previewwindow ) 744norm ! gT 745call assert_equal ( 10 , tabpagenr ( '$' )) 746tabonly 747pclose 748augroup MyBufAdd 749au ! 750augroup END 751augroup ! MyBufAdd 752bw ! 753unlet g: pythoncomplete_allow_import 754endfunc 755 756func s: run_popup_and_previewwindow_dump ( lines , dumpfile ) 757CheckScreendump 758CheckFeature quickfix 759 760call writefile ( a: lines , 'Xscript' , 'D' ) 761let buf = RunVimInTerminal ( '-S Xscript' , {}) 762 763" wait for the script to finish 764call TermWait ( buf ) 765 766" Test that popup and previewwindow do not overlap. 767call term_sendkeys ( buf , "o" ) 768call TermWait ( buf , 50 ) 769call term_sendkeys ( buf , "\<C-X>\<C-N>" ) 770call VerifyScreenDump ( buf , a: dumpfile , {}) 771 772call term_sendkeys ( buf , "\<Esc>u" ) 773call StopVimInTerminal ( buf ) 774endfunc 775 776func Test_popup_and_previewwindow_dump_pedit () 777let lines =<< trim END 778set previewheight=9 779silent! pedit 780call setline(1, map(repeat(["ab"], 10), "v:val .. v:key")) 781exec "norm! G\<C-E>\<C-E>" 782END 783call s: run_popup_and_previewwindow_dump ( lines , 'Test_popup_and_previewwindow_pedit' ) 784endfunc 785 786func Test_popup_and_previewwindow_dump_pbuffer () 787let lines =<< trim END 788set previewheight=9 789silent! pbuffer 790call setline(1, map(repeat(["ab"], 10), "v:val .. v:key")) 791exec "norm! G\<C-E>\<C-E>\<C-E>" 792END 793call s: run_popup_and_previewwindow_dump ( lines , 'Test_popup_and_previewwindow_pbuffer' ) 794endfunc 795 796func Test_balloon_split () 797CheckFunction balloon_split 798 799call assert_equal ([ 800 \'tempname: 0x555555e380a0 "/home/mool/.viminfz.tmp"' , 801 \], balloon_split ( 802 \'tempname: 0x555555e380a0 "/home/mool/.viminfz.tmp"' )) 803call assert_equal ([ 804 \'one two three four one two three four one two thre' , 805 \'e four' , 806 \], balloon_split ( 807 \'one two three four one two three four one two three four' )) 808 809eval 'struct = {one = 1, two = 2, three = 3}' 810 \ ->balloon_split () 811 \ ->assert_equal ([ 812 \'struct = {' , 813 \' one = 1,' , 814 \' two = 2,' , 815 \' three = 3}' , 816 \]) 817 818call assert_equal ([ 819 \'struct = {' , 820 \' one = 1,' , 821 \' nested = {' , 822 \' n1 = "yes",' , 823 \' n2 = "no"}' , 824 \' two = 2}' , 825 \], balloon_split ( 826 \'struct = {one = 1, nested = {n1 = "yes", n2 = "no"} two = 2}' )) 827call assert_equal ([ 828 \'struct = 0x234 {' , 829 \' long = 2343 "\\"some long string that will be wr' , 830 \'apped in two\\"",' , 831 \' next = 123}' , 832 \], balloon_split ( 833 \'struct = 0x234 {long = 2343 "\\"some long string that will be wrapped in two\\"", next = 123}' )) 834call assert_equal ([ 835 \'Some comment' , 836 \'' , 837 \'typedef this that;' , 838 \], balloon_split ( 839 \"Some comment\n\ntypedef this that;" )) 840endfunc 841 842func Test_popup_position () 843CheckScreendump 844 845let lines =<< trim END 846123456789_123456789_123456789_a 847123456789_123456789_123456789_b 848123 849END 850call writefile ( lines , 'Xtest' ) 851let buf = RunVimInTerminal ( 'Xtest' , {}) 852call term_sendkeys ( buf , ":vsplit\<CR>" ) 853 854" default pumwidth in left window: overlap in right window 855call term_sendkeys ( buf , "GA\<C-N>" ) 856call VerifyScreenDump ( buf , 'Test_popup_position_01' , { 'rows' : 8 }) 857call term_sendkeys ( buf , "\<Esc>u" ) 858 859" default pumwidth: fill until right of window 860call term_sendkeys ( buf , "\<C-W>l" ) 861call term_sendkeys ( buf , "GA\<C-N>" ) 862call VerifyScreenDump ( buf , 'Test_popup_position_02' , { 'rows' : 8 }) 863 864" larger pumwidth: used as minimum width 865call term_sendkeys ( buf , "\<Esc>u" ) 866call term_sendkeys ( buf , ":set pumwidth=30\<CR>" ) 867call term_sendkeys ( buf , "GA\<C-N>" ) 868call VerifyScreenDump ( buf , 'Test_popup_position_03' , { 'rows' : 8 }) 869 870" completed text wider than the window and 'pumwidth' smaller than available 871" space 872call term_sendkeys ( buf , "\<Esc>u" ) 873call term_sendkeys ( buf , ":set pumwidth=20\<CR>" ) 874call term_sendkeys ( buf , "ggI123456789_\<Esc>" ) 875call term_sendkeys ( buf , "jI123456789_\<Esc>" ) 876call term_sendkeys ( buf , "GA\<C-N>" ) 877call VerifyScreenDump ( buf , 'Test_popup_position_04' , { 'rows' : 10 }) 878 879call term_sendkeys ( buf , "\<Esc>u" ) 880call StopVimInTerminal ( buf ) 881call delete ( 'Xtest' ) 882endfunc 883 884func Test_popup_command () 885CheckFeature menu 886 887menu Test.Foo Foo 888call assert_fails ( 'popup Test.Foo' , 'E336:' ) 889call assert_fails ( 'popup Test.Foo.X' , 'E327:' ) 890call assert_fails ( 'popup Foo' , 'E337:' ) 891unmenu Test.Foo 892endfunc 893 894func Test_popup_command_dump () 895CheckFeature menu 896CheckScreendump 897 898let script =<< trim END 899func StartTimer() 900call timer_start(100, {-> ChangeMenu()}) 901endfunc 902func ChangeMenu() 903aunmenu PopUp.&Paste 904nnoremenu 1.40 PopUp.&Paste :echomsg "pasted"<CR> 905echomsg 'changed' 906endfunc 907END 908call writefile ( script , 'XtimerScript' , 'D' ) 909 910let lines =<< trim END 911one two three four five 912and one two Xthree four five 913one more two three four five 914END 915call writefile ( lines , 'Xtest' , 'D' ) 916let buf = RunVimInTerminal ( '-S XtimerScript Xtest' , {}) 917call term_sendkeys ( buf , ":source $VIMRUNTIME/menu.vim\<CR>" ) 918call term_sendkeys ( buf , "/X\<CR>:popup PopUp\<CR>" ) 919call VerifyScreenDump ( buf , 'Test_popup_command_01' , {}) 920 921" go to the Paste entry in the menu 922call term_sendkeys ( buf , "jj" ) 923call VerifyScreenDump ( buf , 'Test_popup_command_02' , {}) 924 925" Select a word 926call term_sendkeys ( buf , "j\<CR>" ) 927call VerifyScreenDump ( buf , 'Test_popup_command_03' , {}) 928 929call term_sendkeys ( buf , "\<Esc>" ) 930 931if has ( 'rightleft' ) 932call term_sendkeys ( buf , ":set rightleft\<CR>" ) 933call term_sendkeys ( buf , "/X\<CR>:popup PopUp\<CR>" ) 934call VerifyScreenDump ( buf , 'Test_popup_command_rl' , {}) 935call term_sendkeys ( buf , "\<Esc>:set norightleft\<CR>" ) 936endif 937 938" Set a timer to change a menu entry while it's displayed. The text should 939" not change but the command does. Making the screendump also verifies that 940" "changed" shows up, which means the timer triggered. 941call term_sendkeys ( buf , "/X\<CR>:call StartTimer() | popup PopUp\<CR>" ) 942call VerifyScreenDump ( buf , 'Test_popup_command_04' , {}) 943 944" Select the Paste entry, executes the changed menu item. 945call term_sendkeys ( buf , "jj\<CR>" ) 946call VerifyScreenDump ( buf , 'Test_popup_command_05' , {}) 947 948call term_sendkeys ( buf , "\<Esc>" ) 949 950" Add a window toolbar to the window and check the :popup menu position. 951call term_sendkeys ( buf , ":nnoremenu WinBar.TEST :\<CR>" ) 952call term_sendkeys ( buf , "/X\<CR>:popup PopUp\<CR>" ) 953call VerifyScreenDump ( buf , 'Test_popup_command_06' , {}) 954 955call term_sendkeys ( buf , "\<Esc>" ) 956 957call StopVimInTerminal ( buf ) 958endfunc 959 960" Test position of right-click menu when clicking near window edge. 961func Test_mouse_popup_position () 962CheckFeature menu 963CheckScreendump 964 965let script =<< trim END 966set mousemodel=popup_setpos 967source $VIMRUNTIME/menu.vim 968call setline(1, join(range(20))) 969func Trigger(col) 970call test_setmouse(1, a:col) 971call feedkeys("\<RightMouse>", 't') 972endfunc 973END 974call writefile ( script , 'XmousePopupPosition' , 'D' ) 975let buf = RunVimInTerminal ( '-S XmousePopupPosition' , #{ rows : 20 , cols : 50 }) 976 977call term_sendkeys ( buf , ":call Trigger(45)\<CR>" ) 978call VerifyScreenDump ( buf , 'Test_mouse_popup_position_01' , {}) 979call term_sendkeys ( buf , "\<Esc>" ) 980 981if has ( 'rightleft' ) 982call term_sendkeys ( buf , ":set rightleft\<CR>" ) 983call term_sendkeys ( buf , ":call Trigger(50 + 1 - 45)\<CR>" ) 984call VerifyScreenDump ( buf , 'Test_mouse_popup_position_02' , {}) 985call term_sendkeys ( buf , "\<Esc>:set norightleft\<CR>" ) 986endif 987 988call StopVimInTerminal ( buf ) 989endfunc 990 991func Test_popup_complete_backwards () 992new 993call setline ( 1 , [ 'Post' , 'Port' , 'Po' ]) 994let expected = [ 'Post' , 'Port' , 'Port' ] 995call cursor ( 3 , 2 ) 996call feedkeys ( "A\<C-X>" . repeat ( "\<C-P>" , 3 ) . "rt\<C-Y>" , 'tx' ) 997call assert_equal ( expected , getline ( 1 , '$' )) 998bwipe ! 999endfunc 1000 1001func Test_popup_complete_backwards_ctrl_p () 1002new 1003call setline ( 1 , [ 'Post' , 'Port' , 'Po' ]) 1004let expected = [ 'Post' , 'Port' , 'Port' ] 1005call cursor ( 3 , 2 ) 1006call feedkeys ( "A\<C-P>\<C-N>rt\<C-Y>" , 'tx' ) 1007call assert_equal ( expected , getline ( 1 , '$' )) 1008bwipe ! 1009endfunc 1010 1011func Test_complete_o_tab () 1012let s: o_char_pressed = 0 1013 1014fun ! s: act_on_text_changed () 1015if s: o_char_pressed 1016let s: o_char_pressed = 0 1017call feedkeys ( "\<c-x>\<c-n>" , 'i' ) 1018endif 1019endfunc 1020 1021set completeopt = menu,noselect 1022new 1023imap <expr> <buffer> < tab > pumvisible () ? "\<c-p>" : "X" 1024autocmd ! InsertCharPre <buffer> let s: o_char_pressed = ( v: char ==# 'o' ) 1025autocmd ! TextChangedI <buffer> call <sid>act_on_text_changed() 1026call setline ( 1 , [ 'hoard' , 'hoax' , 'hoarse' , '' ]) 1027let l: expected = [ 'hoard' , 'hoax' , 'hoarse' , 'hoax' , 'hoax' ] 1028call cursor ( 4 , 1 ) 1029call Ntest_override ( "char_avail" , 1 ) 1030call feedkeys ( "Ahoa\<tab>\<tab>\<c-y>\<esc>" , 'tx' ) 1031call feedkeys ( "oho\<tab>\<tab>\<c-y>\<esc>" , 'tx' ) 1032call assert_equal ( l: expected , getline ( 1 , '$' )) 1033 1034call Ntest_override ( "char_avail" , 0 ) 1035bwipe ! 1036set completeopt & 1037delfunc s:act_on_text_changed 1038endfunc 1039 1040func Test_menu_only_exists_in_terminal () 1041CheckCommand tlmenu 1042CheckNotGui 1043 1044tlnoremenu &Edit.&Paste<Tab>"+gP <C-W>"+ 1045aunmenu * 1046try 1047popup Edit 1048call assert_false ( 1 , 'command should have failed' ) 1049catch 1050call assert_exception ( 'E328:' ) 1051endtry 1052endfunc 1053 1054" This used to crash before patch 8.1.1424 1055func Test_popup_delete_when_shown () 1056CheckFeature menu 1057CheckNotGui 1058 1059func Func () 1060popup Foo 1061return "\<Ignore>" 1062endfunc 1063 1064nmenu Foo.Bar : 1065nnoremap <expr> < F2 > Func () 1066call feedkeys ( "\<F2>\<F2>\<Esc>" , 'xt' ) 1067 1068delfunc Func 1069nunmenu Foo.Bar 1070nunmap <F2> 1071endfunc 1072 1073func Test_popup_complete_info_01 () 1074new 1075inoremap <buffer> < F5 > < C-R > =complete_info().mode< CR > 1076func s: complTestEval () abort 1077call complete ( 1 , [ 'aa' , 'ab' ]) 1078return '' 1079endfunc 1080inoremap <buffer> < F6 > < C-R > =s:complTestEval()< CR > 1081call writefile ([ 1082 \'dummy dummy.txt 1' , 1083 \], 'Xdummy.txt' ) 1084setlocal tags = Xdummy.txt 1085setlocal dictionary = Xdummy.txt 1086setlocal thesaurus = Xdummy.txt 1087setlocal omnifunc = syntaxcomplete#Complete 1088setlocal completefunc = syntaxcomplete#Complete 1089setlocal completeopt += noinsert 1090setlocal spell 1091for [ keys , mode_name ] in [ 1092 \[ "" , '' ], 1093 \[ "\<C-X>" , 'ctrl_x' ], 1094 \[ "\<C-X>\<C-N>" , 'keyword' ], 1095 \[ "\<C-X>\<C-P>" , 'keyword' ], 1096 \[ "\<C-X>\<C-E>" , 'scroll' ], 1097 \[ "\<C-X>\<C-Y>" , 'scroll' ], 1098 \[ "\<C-X>\<C-E>\<C-E>\<C-Y>" , 'scroll' ], 1099 \[ "\<C-X>\<C-Y>\<C-E>\<C-Y>" , 'scroll' ], 1100 \[ "\<C-X>\<C-L>" , 'whole_line' ], 1101 \[ "\<C-X>\<C-F>" , 'files' ], 1102 \[ "\<C-X>\<C-]>" , 'tags' ], 1103 \[ "\<C-X>\<C-D>" , 'path_defines' ], 1104 \[ "\<C-X>\<C-I>" , 'path_patterns' ], 1105 \[ "\<C-X>\<C-K>" , 'dictionary' ], 1106 \[ "\<C-X>\<C-T>" , 'thesaurus' ], 1107 \[ "\<C-X>\<C-V>" , 'cmdline' ], 1108 \[ "\<C-X>\<C-U>" , 'function' ], 1109 \[ "\<C-X>\<C-O>" , 'omni' ], 1110 \[ "\<C-X>s" , 'spell' ], 1111 \[ "\<F6>" , 'eval' ], 1112 \] 1113call feedkeys ( "i" . keys . "\<F5>\<Esc>" , 'tx' ) 1114call assert_equal ( mode_name , getline ( '.' )) 1115 %d 1116endfor 1117call delete ( 'Xdummy.txt' ) 1118bwipe ! 1119endfunc 1120 1121func UserDefinedComplete ( findstart , base ) 1122if a: findstart 1123return 0 1124else 1125return [ 1126 \{ 'word' : 'Jan' , 'menu' : 'January' }, 1127 \{ 'word' : 'Feb' , 'menu' : 'February' }, 1128 \{ 'word' : 'Mar' , 'menu' : 'March' }, 1129 \{ 'word' : 'Apr' , 'menu' : 'April' }, 1130 \{ 'word' : 'May' , 'menu' : 'May' }, 1131 \] 1132endif 1133endfunc 1134 1135func GetCompleteInfo () 1136if empty ( g: compl_what ) 1137let g: compl_info = complete_info () 1138else 1139let g: compl_info = g: compl_what ->complete_info () 1140endif 1141return '' 1142endfunc 1143 1144func Test_popup_complete_info_02 () 1145new 1146inoremap <buffer> < F5 > < C-R > =GetCompleteInfo()< CR > 1147setlocal completefunc = UserDefinedComplete 1148 1149let d = { 1150 \'mode' : 'function' , 1151 \'pum_visible' : 1 , 1152 \'items' : [ 1153 \{ 'word' : 'Jan' , 'menu' : 'January' , 'kind_hlgroup' : '' , 'abbr_hlgroup' : '' , 'user_data' : '' , 'info' : '' , 'kind' : '' , 'abbr' : '' }, 1154 \{ 'word' : 'Feb' , 'menu' : 'February' , 'kind_hlgroup' : '' , 'abbr_hlgroup' : '' , 'user_data' : '' , 'info' : '' , 'kind' : '' , 'abbr' : '' }, 1155 \{ 'word' : 'Mar' , 'menu' : 'March' , 'kind_hlgroup' : '' , 'abbr_hlgroup' : '' , 'user_data' : '' , 'info' : '' , 'kind' : '' , 'abbr' : '' }, 1156 \{ 'word' : 'Apr' , 'menu' : 'April' , 'kind_hlgroup' : '' , 'abbr_hlgroup' : '' , 'user_data' : '' , 'info' : '' , 'kind' : '' , 'abbr' : '' }, 1157 \{ 'word' : 'May' , 'menu' : 'May' , 'kind_hlgroup' : '' , 'abbr_hlgroup' : '' , 'user_data' : '' , 'info' : '' , 'kind' : '' , 'abbr' : '' } 1158 \], 1159 \'preinserted_text' : '' , 1160 \'selected' : 0 , 1161 \} 1162 1163let g: compl_what = [] 1164call feedkeys ( "i\<C-X>\<C-U>\<F5>" , 'tx' ) 1165call assert_equal ( d , g: compl_info ) 1166 1167let g: compl_what = [ 'mode' , 'pum_visible' , 'preinserted_text' , 'selected' ] 1168call remove ( d , 'items' ) 1169call feedkeys ( "i\<C-X>\<C-U>\<F5>" , 'tx' ) 1170call assert_equal ( d , g: compl_info ) 1171 1172let g: compl_what = [ 'mode' ] 1173call remove ( d , 'selected' ) 1174call remove ( d , 'pum_visible' ) 1175call remove ( d , 'preinserted_text' ) 1176call feedkeys ( "i\<C-X>\<C-U>\<F5>" , 'tx' ) 1177call assert_equal ( d , g: compl_info ) 1178bwipe ! 1179endfunc 1180 1181func Test_popup_complete_info_no_pum () 1182new 1183call assert_false ( pumvisible () ) 1184let no_pum_info = complete_info () 1185let d = { 1186 \'mode' : '' , 1187 \'pum_visible' : 0 , 1188 \'items' : [], 1189 \'preinserted_text' : '' , 1190 \'selected' : -1 , 1191 \} 1192call assert_equal ( d , complete_info () ) 1193bwipe ! 1194endfunc 1195 1196func Test_CompleteChanged () 1197new 1198call setline ( 1 , [ 'foo' , 'bar' , 'foobar' , '' ]) 1199set complete = .completeopt = noinsert,noselect,menuone 1200function ! OnPumChange () 1201let g: event = copy ( v: event ) 1202let g: item = get ( v: event , 'completed_item' , {}) 1203let g: word = get ( g: item , 'word' , v: null ) 1204let l: line = getline ( '.' ) 1205if g: word == v: null && l: line == "bc" 1206let g: word = l: line 1207endif 1208endfunction 1209augroup AAAAA_Group 1210au ! 1211autocmd CompleteChanged * : call OnPumChange () 1212augroup END 1213call cursor ( 4 , 1 ) 1214 1215call feedkeys ( "Sf\<C-N>" , 'tx' ) 1216call assert_equal ({ 'completed_item' : {}, 'width' : 15.0 , 1217 \'height' : 2.0 , 'size' : 2 , 1218 \'col' : 0.0 , 'row' : 4.0 , 'scrollbar' : v: false }, g: event ) 1219call feedkeys ( "a\<C-N>\<C-N>\<C-E>" , 'tx' ) 1220call assert_equal ( 'foo' , g: word ) 1221call feedkeys ( "a\<C-N>\<C-N>\<C-N>\<C-E>" , 'tx' ) 1222call assert_equal ( 'foobar' , g: word ) 1223call feedkeys ( "a\<C-N>\<C-N>\<C-N>\<C-N>\<C-E>" , 'tx' ) 1224call assert_equal ( v: null , g: word ) 1225call feedkeys ( "a\<C-N>\<C-N>\<C-N>\<C-N>\<C-P>" , 'tx' ) 1226call assert_equal ( 'foobar' , g: word ) 1227call feedkeys ( "S\<C-N>bc" , 'tx' ) 1228call assert_equal ( "bc" , g: word ) 1229 1230func Omni_test ( findstart , base ) 1231if a: findstart 1232return col ( "." ) 1233endif 1234return [#{ word : "one" }, #{ word : "two" }, #{ word : "five" }] 1235endfunc 1236set omnifunc = Omni_test 1237set completeopt = menu,menuone 1238call feedkeys ( "i\<C-X>\<C-O>\<BS>\<BS>\<BS>f" , 'tx' ) 1239call assert_equal ( 'five' , g: word ) 1240call feedkeys ( "i\<C-X>\<C-O>\<BS>\<BS>\<BS>f\<BS>" , 'tx' ) 1241call assert_equal ( 'one' , g: word ) 1242 1243autocmd ! AAAAA_Group 1244set complete & completeopt & 1245delfunc ! OnPumChange 1246delfunc ! Omni_test 1247bw ! 1248endfunc 1249 1250func GetPumPosition () 1251call assert_true ( pumvisible () ) 1252let g: pum_pos = pum_getpos () 1253return '' 1254endfunc 1255 1256func Test_pum_getpos () 1257new 1258inoremap <buffer> < F5 > < C-R > =GetPumPosition()< CR > 1259setlocal completefunc = UserDefinedComplete 1260 1261let d = { 1262 \'height' : 5.0 , 1263 \'width' : 15.0 , 1264 \'row' : 1.0 , 1265 \'col' : 0.0 , 1266 \'size' : 5 , 1267 \'scrollbar' : v: false , 1268 \} 1269call feedkeys ( "i\<C-X>\<C-U>\<F5>" , 'tx' ) 1270call assert_equal ( d , g: pum_pos ) 1271 1272call assert_false ( pumvisible () ) 1273call assert_equal ( {}, pum_getpos () ) 1274bw ! 1275unlet g: pum_pos 1276endfunc 1277 1278" The popup menu is also used on a terminal without colors (issue #20800) 1279func Test_pum_without_colors () 1280CheckNotGui 1281 1282new 1283let save_t_Co = & t_Co 1284set t_Co = 0 1285inoremap <buffer> < F5 > < C-R > =GetPumPosition()< CR > 1286call setline ( 1 , [ 'hello' , 'help' , '' ]) 1287call cursor ( 3 , 1 ) 1288call feedkeys ( "ih\<C-N>\<F5>\<Esc>" , 'tx' ) 1289call assert_equal ( 2 , g: pum_pos . size ) 1290 1291let & t_Co = save_t_Co 1292bw ! 1293unlet g: pum_pos 1294endfunc 1295 1296" Test for the popup menu with the 'rightleft' option set 1297func Test_pum_rightleft () 1298CheckFeature rightleft 1299CheckScreendump 1300 1301let lines =<< trim END 1302abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz 1303vim 1304victory 1305END 1306call writefile ( lines , 'Xtest1' ) 1307let buf = RunVimInTerminal ( '--cmd "set rightleft" Xtest1' , {}) 1308call term_wait ( buf ) 1309call term_sendkeys ( buf , "Go\<C-P>" ) 1310call VerifyScreenDump ( buf , 'Test_pum_rightleft_01' , { 'rows' : 8 }) 1311call term_sendkeys ( buf , "\<C-P>\<C-Y>" ) 1312call term_wait ( buf ) 1313redraw ! 1314call assert_match ( '\s*miv' , Screenline ( 5 )) 1315 1316" Test for expanding tabs to spaces in the popup menu 1317let lines =<< trim END 1318one two 1319one three 1320four 1321END 1322call writefile ( lines , 'Xtest2' ) 1323call term_sendkeys ( buf , "\<Esc>:e! Xtest2\<CR>" ) 1324call term_wait ( buf ) 1325call term_sendkeys ( buf , "Goone\<C-X>\<C-L>" ) 1326call term_wait ( buf ) 1327redraw ! 1328call VerifyScreenDump ( buf , 'Test_pum_rightleft_02' , { 'rows' : 7 }) 1329call term_sendkeys ( buf , "\<C-Y>" ) 1330call term_wait ( buf ) 1331redraw ! 1332call assert_match ( '\s*eerht eno' , Screenline ( 4 )) 1333 1334call StopVimInTerminal ( buf ) 1335call delete ( 'Xtest1' ) 1336call delete ( 'Xtest2' ) 1337endfunc 1338 1339" Test for a popup menu with a scrollbar 1340func Test_pum_scrollbar () 1341CheckScreendump 1342let lines =<< trim END 1343one 1344two 1345three 1346END 1347call writefile ( lines , 'Xtest1' ) 1348let buf = RunVimInTerminal ( '--cmd "set pumheight=2" Xtest1' , {}) 1349call term_wait ( buf ) 1350call term_sendkeys ( buf , "Go\<C-P>\<C-P>\<C-P>" ) 1351call VerifyScreenDump ( buf , 'Test_pum_scrollbar_01' , { 'rows' : 7 }) 1352call term_sendkeys ( buf , "\<C-E>\<Esc>dd" ) 1353call term_wait ( buf ) 1354 1355if has ( 'rightleft' ) 1356call term_sendkeys ( buf , ":set rightleft\<CR>" ) 1357call term_wait ( buf ) 1358call term_sendkeys ( buf , "Go\<C-P>\<C-P>\<C-P>" ) 1359call VerifyScreenDump ( buf , 'Test_pum_scrollbar_02' , { 'rows' : 7 }) 1360endif 1361 1362call StopVimInTerminal ( buf ) 1363call delete ( 'Xtest1' ) 1364endfunc 1365 1366" Test default highlight groups for popup menu 1367func Test_pum_highlights_default () 1368CheckScreendump 1369let lines =<< trim END 1370func CompleteFunc( findstart, base ) 1371if a:findstart 1372return 0 1373endif 1374return { 1375\ 'words': [ 1376\ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', }, 1377\ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', }, 1378\ { 'word': 'aword3', 'menu': 'extra text 3', 'kind': 'W', }, 1379\]} 1380endfunc 1381set completeopt=menu 1382set completefunc=CompleteFunc 1383END 1384call writefile ( lines , 'Xscript' , 'D' ) 1385let buf = RunVimInTerminal ( '-S Xscript' , {}) 1386call TermWait ( buf ) 1387call term_sendkeys ( buf , "iaw\<C-X>\<C-u>" ) 1388call TermWait ( buf , 50 ) 1389call VerifyScreenDump ( buf , 'Test_pum_highlights_01' , {}) 1390call term_sendkeys ( buf , "\<C-E>\<Esc>u" ) 1391call TermWait ( buf ) 1392call StopVimInTerminal ( buf ) 1393endfunc 1394 1395" Test custom highlight groups for popup menu 1396func Test_pum_highlights_custom () 1397CheckScreendump 1398let lines =<< trim END 1399func CompleteFunc( findstart, base ) 1400if a:findstart 1401return 0 1402endif 1403return { 1404\ 'words': [ 1405\ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', }, 1406\ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', }, 1407\ { 'word': 'aword3', 'menu': 'extra text 3', 'kind': 'W', }, 1408\]} 1409endfunc 1410set completeopt=menu 1411set completefunc=CompleteFunc 1412hi PmenuKind ctermfg=1 ctermbg=225 1413hi PmenuKindSel ctermfg=1 ctermbg=7 1414hi PmenuExtra ctermfg=243 ctermbg=225 1415hi PmenuExtraSel ctermfg=0 ctermbg=7 1416END 1417call writefile ( lines , 'Xscript' , 'D' ) 1418let buf = RunVimInTerminal ( '-S Xscript' , {}) 1419call TermWait ( buf ) 1420call term_sendkeys ( buf , "iaw\<C-X>\<C-u>" ) 1421call TermWait ( buf , 50 ) 1422call VerifyScreenDump ( buf , 'Test_pum_highlights_02' , {}) 1423call term_sendkeys ( buf , "\<C-E>\<Esc>u" ) 1424call TermWait ( buf ) 1425call StopVimInTerminal ( buf ) 1426endfunc 1427 1428" Test match relate highlight group in pmenu 1429func Test_pum_highlights_match () 1430CheckScreendump 1431let lines =<< trim END 1432func Omni_test(findstart, base) 1433if a:findstart 1434return col(".") 1435endif 1436return { 1437\ 'words': [ 1438\ { 'word': 'foo', 'kind': 'fookind' }, 1439\ { 'word': 'foofoo', 'kind': 'fookind' }, 1440\ { 'word': 'foobar', 'kind': 'fookind' }, 1441\ { 'word': 'fooBaz', 'kind': 'fookind' }, 1442\ { 'word': 'foobala', 'kind': 'fookind' }, 1443\ { 'word': '你好' }, 1444\ { 'word': '你好吗' }, 1445\ { 'word': '你不好吗' }, 1446\ { 'word': '你可好吗' }, 1447\]} 1448endfunc 1449 1450func Comp() 1451let col = col('.') 1452if getline('.') == 'f' 1453let col -= 1 1454endif 1455call complete(col, [ 1456\ #{word: "foo", icase: 1}, 1457\ #{word: "Foobar", icase: 1}, 1458\ #{word: "fooBaz", icase: 1}, 1459\]) 1460return '' 1461endfunc 1462 1463set omnifunc=Omni_test 1464set completeopt=menu,noinsert,fuzzy 1465hi PmenuMatchSel ctermfg=6 ctermbg=7 1466hi PmenuMatch ctermfg=4 ctermbg=225 1467END 1468call writefile ( lines , 'Xscript' , 'D' ) 1469let buf = RunVimInTerminal ( '-S Xscript' , {}) 1470call TermWait ( buf ) 1471call term_sendkeys ( buf , "i\<C-X>\<C-O>" ) 1472call TermWait ( buf , 50 ) 1473call term_sendkeys ( buf , "fo" ) 1474call TermWait ( buf , 50 ) 1475call VerifyScreenDump ( buf , 'Test_pum_highlights_03' , {}) 1476call term_sendkeys ( buf , "\<Esc>S\<C-X>\<C-O>" ) 1477call TermWait ( buf , 50 ) 1478call term_sendkeys ( buf , "你" ) 1479call TermWait ( buf , 50 ) 1480call VerifyScreenDump ( buf , 'Test_pum_highlights_04' , {}) 1481call term_sendkeys ( buf , "吗" ) 1482call TermWait ( buf , 50 ) 1483call VerifyScreenDump ( buf , 'Test_pum_highlights_05' , {}) 1484call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1485 1486if has ( 'rightleft' ) 1487call term_sendkeys ( buf , ":set rightleft\<CR>" ) 1488call TermWait ( buf , 50 ) 1489call term_sendkeys ( buf , "S\<C-X>\<C-O>" ) 1490call TermWait ( buf , 50 ) 1491call term_sendkeys ( buf , "fo" ) 1492call TermWait ( buf , 50 ) 1493call VerifyScreenDump ( buf , 'Test_pum_highlights_06' , {}) 1494call term_sendkeys ( buf , "\<Esc>S\<C-X>\<C-O>" ) 1495call TermWait ( buf , 50 ) 1496call term_sendkeys ( buf , "你" ) 1497call VerifyScreenDump ( buf , 'Test_pum_highlights_06a' , {}) 1498call term_sendkeys ( buf , "吗" ) 1499call VerifyScreenDump ( buf , 'Test_pum_highlights_06b' , {}) 1500call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1501call term_sendkeys ( buf , ":set norightleft\<CR>" ) 1502call TermWait ( buf ) 1503endif 1504 1505call term_sendkeys ( buf , ":set completeopt-=fuzzy\<CR>" ) 1506call TermWait ( buf ) 1507call term_sendkeys ( buf , "S\<C-X>\<C-O>" ) 1508call TermWait ( buf , 50 ) 1509call term_sendkeys ( buf , "fo" ) 1510call TermWait ( buf , 50 ) 1511call VerifyScreenDump ( buf , 'Test_pum_highlights_07' , {}) 1512call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1513 1514if has ( 'rightleft' ) 1515call term_sendkeys ( buf , ":set rightleft\<CR>" ) 1516call TermWait ( buf , 50 ) 1517call term_sendkeys ( buf , "S\<C-X>\<C-O>" ) 1518call TermWait ( buf , 50 ) 1519call term_sendkeys ( buf , "fo" ) 1520call TermWait ( buf , 50 ) 1521call VerifyScreenDump ( buf , 'Test_pum_highlights_08' , {}) 1522call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1523call term_sendkeys ( buf , ":set norightleft\<CR>" ) 1524endif 1525 1526call term_sendkeys ( buf , "S\<C-R>=Comp()\<CR>f" ) 1527call VerifyScreenDump ( buf , 'Test_pum_highlights_09' , {}) 1528call term_sendkeys ( buf , "o\<BS>\<C-R>=Comp()\<CR>" ) 1529call VerifyScreenDump ( buf , 'Test_pum_highlights_09' , {}) 1530call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1531 1532call term_sendkeys ( buf , ":hi PmenuMatchSel ctermfg=14 ctermbg=NONE\<CR>" ) 1533call TermWait ( buf , 50 ) 1534call term_sendkeys ( buf , ":hi PmenuMatch ctermfg=12 ctermbg=NONE\<CR>" ) 1535call term_sendkeys ( buf , ":set cot=menu,noinsert,fuzzy\<CR>" ) 1536call term_sendkeys ( buf , "S\<C-X>\<C-O>" ) 1537call TermWait ( buf , 50 ) 1538call term_sendkeys ( buf , "fb" ) 1539call VerifyScreenDump ( buf , 'Test_pum_highlights_18' , {}) 1540 1541call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1542call TermWait ( buf ) 1543call StopVimInTerminal ( buf ) 1544endfunc 1545 1546func Test_pum_completefuzzycollect () 1547CheckScreendump 1548let lines =<< trim END 1549set completeopt=menu,menuone,fuzzy 1550END 1551call writefile ( lines , 'Xscript' , 'D' ) 1552let buf = RunVimInTerminal ( '-S Xscript' , {}) 1553 1554" issue #15095 wrong select 1555call term_sendkeys ( buf , "S hello helio hero h\<C-X>\<C-P>" ) 1556call TermWait ( buf , 50 ) 1557call VerifyScreenDump ( buf , 'Test_pum_completefuzzycollect_01' , {}) 1558 1559call term_sendkeys ( buf , "\<ESC>S hello helio hero h\<C-X>\<C-P>\<C-P>" ) 1560call TermWait ( buf , 50 ) 1561call VerifyScreenDump ( buf , 'Test_pum_completefuzzycollect_02' , {}) 1562 1563" issue #15357 1564call term_sendkeys ( buf , "\<ESC>S/non_existing_folder\<C-X>\<C-F>" ) 1565call TermWait ( buf , 50 ) 1566call VerifyScreenDump ( buf , 'Test_pum_completefuzzycollect_03' , {}) 1567call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1568 1569call TermWait ( buf ) 1570call StopVimInTerminal ( buf ) 1571endfunc 1572 1573func Test_pum_highlights_match_with_abbr () 1574CheckScreendump 1575let lines =<< trim END 1576func Omni_test(findstart, base) 1577if a:findstart 1578return col(".") 1579endif 1580return { 1581\ 'words': [ 1582\ { 'word': 'foobar', 'abbr': "foobar\t\t!" }, 1583\ { 'word': 'foobaz', 'abbr': "foobaz\t\t!" }, 1584\]} 1585endfunc 1586 1587set omnifunc=Omni_test 1588set completeopt=menuone,noinsert 1589hi PmenuMatchSel ctermfg=6 ctermbg=7 1590hi PmenuMatch ctermfg=4 ctermbg=225 1591END 1592call writefile ( lines , 'Xscript' , 'D' ) 1593let buf = RunVimInTerminal ( '-S Xscript' , {}) 1594call TermWait ( buf ) 1595call term_sendkeys ( buf , "i\<C-X>\<C-O>" ) 1596call TermWait ( buf , 50 ) 1597call term_sendkeys ( buf , "foo" ) 1598call VerifyScreenDump ( buf , 'Test_pum_highlights_19' , {}) 1599 1600call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1601call TermWait ( buf ) 1602 1603call StopVimInTerminal ( buf ) 1604endfunc 1605 1606func Test_pum_user_abbr_hlgroup () 1607CheckScreendump 1608let lines =<< trim END 1609let s:var = 0 1610func CompleteFunc(findstart, base) 1611if a:findstart 1612return 0 1613endif 1614if s:var == 1 1615return { 1616\ 'words': [ 1617\ { 'word': 'aword1', 'abbr_hlgroup': 'StrikeFake' }, 1618\ { 'word': '你好', 'abbr_hlgroup': 'StrikeFake' }, 1619\]} 1620endif 1621return { 1622\ 'words': [ 1623\ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', 'abbr_hlgroup': 'StrikeFake' }, 1624\ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', }, 1625\ { 'word': '你好', 'menu': 'extra text 3', 'kind': 'W', 'abbr_hlgroup': 'StrikeFake' }, 1626\]} 1627endfunc 1628func ChangeVar() 1629let s:var = 1 1630endfunc 1631set completeopt=menu 1632set completefunc=CompleteFunc 1633 1634hi StrikeFake ctermfg=9 1635func HlMatch() 1636hi PmenuMatchSel ctermfg=6 ctermbg=7 cterm=underline 1637hi PmenuMatch ctermfg=4 ctermbg=225 cterm=underline 1638endfunc 1639END 1640call writefile ( lines , 'Xscript' , 'D' ) 1641let buf = RunVimInTerminal ( '-S Xscript' , {}) 1642 1643call TermWait ( buf ) 1644call term_sendkeys ( buf , "Saw\<C-X>\<C-U>" ) 1645call VerifyScreenDump ( buf , 'Test_pum_highlights_12' , {}) 1646call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1647 1648call TermWait ( buf ) 1649call term_sendkeys ( buf , ":call HlMatch()\<CR>" ) 1650 1651call TermWait ( buf ) 1652call term_sendkeys ( buf , "Saw\<C-X>\<C-U>" ) 1653call VerifyScreenDump ( buf , 'Test_pum_highlights_13' , {}) 1654call term_sendkeys ( buf , "\<C-N>" ) 1655call VerifyScreenDump ( buf , 'Test_pum_highlights_14' , {}) 1656call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1657 1658call TermWait ( buf ) 1659call term_sendkeys ( buf , ":call ChangeVar()\<CR>" ) 1660call TermWait ( buf ) 1661call term_sendkeys ( buf , "S\<C-X>\<C-U>" ) 1662call VerifyScreenDump ( buf , 'Test_pum_highlights_17' , {}) 1663call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1664 1665call StopVimInTerminal ( buf ) 1666endfunc 1667 1668func Test_pum_user_kind_hlgroup () 1669CheckScreendump 1670let lines =<< trim END 1671func CompleteFunc(findstart, base) 1672if a:findstart 1673return 0 1674endif 1675return { 1676\ 'words': [ 1677\ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'variable', 'kind_hlgroup': 'KindVar', 'abbr_hlgroup': 'StrikeFake' }, 1678\ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'function', 'kind_hlgroup': 'KindFunc' }, 1679\ { 'word': '你好', 'menu': 'extra text 3', 'kind': 'class', 'kind_hlgroup': 'KindClass' }, 1680\]} 1681endfunc 1682set completeopt=menu 1683set completefunc=CompleteFunc 1684 1685hi StrikeFake ctermfg=9 1686hi KindVar ctermfg=yellow 1687hi KindFunc ctermfg=blue 1688hi KindClass ctermfg=green 1689END 1690call writefile ( lines , 'Xscript' , 'D' ) 1691let buf = RunVimInTerminal ( '-S Xscript' , {}) 1692 1693call TermWait ( buf ) 1694call term_sendkeys ( buf , "S\<C-X>\<C-U>" ) 1695call VerifyScreenDump ( buf , 'Test_pum_highlights_16' , {}) 1696call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1697 1698call StopVimInTerminal ( buf ) 1699endfunc 1700 1701func Test_pum_completeitemalign () 1702CheckScreendump 1703let lines =<< trim END 1704func Omni_test(findstart, base) 1705if a:findstart 1706return col(".") 1707endif 1708return { 1709\ 'words': [ 1710\ { 'word': 'foo', 'kind': 'S', 'menu': 'menu' }, 1711\ { 'word': 'bar', 'kind': 'T', 'menu': 'menu' }, 1712\ { 'word': '你好', 'kind': 'C', 'menu': '中文' }, 1713\]} 1714endfunc 1715 1716func Omni_long(findstart, base) 1717if a:findstart 1718return col(".") 1719endif 1720return { 1721\ 'words': [ 1722\ { 'word': 'loooong_foo', 'kind': 'S', 'menu': 'menu' }, 1723\ { 'word': 'loooong_bar', 'kind': 'T', 'menu': 'menu' }, 1724\]} 1725endfunc 1726set omnifunc=Omni_test 1727command! -nargs=0 T1 set cia=abbr,kind,menu 1728command! -nargs=0 T2 set cia=abbr,menu,kind 1729command! -nargs=0 T3 set cia=kind,abbr,menu 1730command! -nargs=0 T4 set cia=kind,menu,abbr 1731command! -nargs=0 T5 set cia=menu,abbr,kind 1732command! -nargs=0 T6 set cia=menu,kind,abbr 1733command! -nargs=0 T7 set cia& 1734END 1735call writefile ( lines , 'Xscript' , 'D' ) 1736let buf = RunVimInTerminal ( '-S Xscript' , {}) 1737call TermWait ( buf ) 1738 1739" T1 is default 1740call term_sendkeys ( buf , ":T1\<CR>S\<C-X>\<C-O>" ) 1741call VerifyScreenDump ( buf , 'Test_pum_completeitemalign_01' , {}) 1742call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1743 1744" T2 1745call term_sendkeys ( buf , ":T2\<CR>S\<C-X>\<C-O>" ) 1746call VerifyScreenDump ( buf , 'Test_pum_completeitemalign_02' , {}) 1747call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1748 1749" T3 1750call term_sendkeys ( buf , ":T3\<CR>S\<C-X>\<C-O>" ) 1751call VerifyScreenDump ( buf , 'Test_pum_completeitemalign_03' , {}) 1752call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1753 1754" T4 1755call term_sendkeys ( buf , ":T4\<CR>S\<C-X>\<C-O>" ) 1756call VerifyScreenDump ( buf , 'Test_pum_completeitemalign_04' , {}) 1757call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1758 1759" T5 1760call term_sendkeys ( buf , ":T5\<CR>S\<C-X>\<C-O>" ) 1761call VerifyScreenDump ( buf , 'Test_pum_completeitemalign_05' , {}) 1762call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1763 1764" T6 1765call term_sendkeys ( buf , ":T6\<CR>S\<C-X>\<C-O>" ) 1766call VerifyScreenDump ( buf , 'Test_pum_completeitemalign_06' , {}) 1767call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1768 1769call term_sendkeys ( buf , ":set columns=12 cmdheight=2 omnifunc=Omni_long\<CR>S\<C-X>\<C-O>" ) 1770call VerifyScreenDump ( buf , 'Test_pum_completeitemalign_07' , {}) 1771call term_sendkeys ( buf , "\<C-E>\<Esc>:T7\<CR>" ) 1772call StopVimInTerminal ( buf ) 1773endfunc 1774 1775func Test_pum_keep_select () 1776CheckScreendump 1777let lines =<< trim END 1778set completeopt=menu,menuone,noinsert 1779END 1780call writefile ( lines , 'Xscript' , 'D' ) 1781let buf = RunVimInTerminal ( '-S Xscript' , {}) 1782call TermWait ( buf ) 1783 1784call term_sendkeys ( buf , "ggSFab\<CR>Five\<CR>find\<CR>film\<CR>\<C-X>\<C-P>" ) 1785call TermWait ( buf , 50 ) 1786call VerifyScreenDump ( buf , 'Test_pum_keep_select_01' , {}) 1787call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1788call TermWait ( buf , 50 ) 1789 1790call term_sendkeys ( buf , "S\<C-X>\<C-P>" ) 1791call TermWait ( buf , 50 ) 1792call term_sendkeys ( buf , "F" ) 1793call VerifyScreenDump ( buf , 'Test_pum_keep_select_02' , {}) 1794call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1795 1796call TermWait ( buf , 50 ) 1797call StopVimInTerminal ( buf ) 1798endfunc 1799 1800func Test_pum_matchins_highlight () 1801CheckScreendump 1802let lines =<< trim END 1803let g:change = 0 1804func Omni_test(findstart, base) 1805if a:findstart 1806return col(".") 1807endif 1808if g:change == 0 1809return [#{word: "foo"}, #{word: "bar"}, #{word: "你好"}] 1810endif 1811return [#{word: "foo", info: "info"}, #{word: "bar"}, #{word: "你好"}] 1812endfunc 1813set omnifunc=Omni_test 1814hi ComplMatchIns ctermfg=red 1815END 1816call writefile ( lines , 'Xscript' , 'D' ) 1817let buf = RunVimInTerminal ( '-S Xscript' , {}) 1818 1819call TermWait ( buf ) 1820call term_sendkeys ( buf , "Sαβγ \<C-X>\<C-O>" ) 1821call VerifyScreenDump ( buf , 'Test_pum_matchins_01' , {}) 1822call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1823 1824call TermWait ( buf ) 1825call term_sendkeys ( buf , "Sαβγ \<C-X>\<C-O>\<C-N>" ) 1826call VerifyScreenDump ( buf , 'Test_pum_matchins_02' , {}) 1827call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1828 1829call TermWait ( buf ) 1830call term_sendkeys ( buf , "Sαβγ \<C-X>\<C-O>\<C-N>\<C-N>" ) 1831call VerifyScreenDump ( buf , 'Test_pum_matchins_03' , {}) 1832call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1833 1834" restore after accept 1835call TermWait ( buf ) 1836call term_sendkeys ( buf , "Sαβγ \<C-X>\<C-O>\<C-Y>" ) 1837call VerifyScreenDump ( buf , 'Test_pum_matchins_04' , {}) 1838call term_sendkeys ( buf , "\<Esc>" ) 1839 1840" restore after cancel completion 1841call TermWait ( buf ) 1842call term_sendkeys ( buf , "Sαβγ \<C-X>\<C-O>\<Space>" ) 1843call VerifyScreenDump ( buf , 'Test_pum_matchins_05' , {}) 1844call term_sendkeys ( buf , "\<Esc>" ) 1845 1846" text after the inserted text shouldn't be highlighted 1847call TermWait ( buf ) 1848call term_sendkeys ( buf , "0ea \<C-X>\<C-O>" ) 1849call VerifyScreenDump ( buf , 'Test_pum_matchins_07' , {}) 1850call term_sendkeys ( buf , "\<C-P>" ) 1851call VerifyScreenDump ( buf , 'Test_pum_matchins_08' , {}) 1852call term_sendkeys ( buf , "\<C-P>" ) 1853call VerifyScreenDump ( buf , 'Test_pum_matchins_09' , {}) 1854call term_sendkeys ( buf , "\<C-Y>" ) 1855call VerifyScreenDump ( buf , 'Test_pum_matchins_10' , {}) 1856call term_sendkeys ( buf , "\<Esc>" ) 1857 1858call term_sendkeys ( buf , ":let g:change=1\<CR>S\<C-X>\<C-O>" ) 1859call VerifyScreenDump ( buf , 'Test_pum_matchins_11' , {}) 1860call term_sendkeys ( buf , "\<Esc>" ) 1861 1862call StopVimInTerminal ( buf ) 1863endfunc 1864 1865func Test_pum_matchins_highlight_combine () 1866CheckScreendump 1867let lines =<< trim END 1868func Omni_test(findstart, base) 1869if a:findstart 1870return col(".") 1871endif 1872return [#{word: "foo"}, #{word: "bar"}, #{word: "你好"}] 1873endfunc 1874set omnifunc=Omni_test 1875hi Normal ctermbg=blue 1876hi CursorLine cterm=underline ctermbg=green 1877set cursorline 1878call setline(1, 'aaa bbb') 1879END 1880call writefile ( lines , 'Xscript' , 'D' ) 1881let buf = RunVimInTerminal ( '-S Xscript' , {}) 1882 1883" when ComplMatchIns is not set, CursorLine applies normally 1884call term_sendkeys ( buf , "0ea \<C-X>\<C-O>" ) 1885call VerifyScreenDump ( buf , 'Test_pum_matchins_combine_01' , {}) 1886call term_sendkeys ( buf , "\<C-E>" ) 1887call VerifyScreenDump ( buf , 'Test_pum_matchins_combine_02' , {}) 1888call term_sendkeys ( buf , "\<BS>\<Esc>" ) 1889 1890" when ComplMatchIns is set, it is applied over CursorLine 1891call TermWait ( buf ) 1892call term_sendkeys ( buf , ":hi ComplMatchIns ctermbg=red ctermfg=yellow\<CR>" ) 1893call TermWait ( buf ) 1894call term_sendkeys ( buf , "0ea \<C-X>\<C-O>" ) 1895call VerifyScreenDump ( buf , 'Test_pum_matchins_combine_03' , {}) 1896call term_sendkeys ( buf , "\<C-P>" ) 1897call VerifyScreenDump ( buf , 'Test_pum_matchins_combine_04' , {}) 1898call term_sendkeys ( buf , "\<C-P>" ) 1899call VerifyScreenDump ( buf , 'Test_pum_matchins_combine_05' , {}) 1900call term_sendkeys ( buf , "\<C-E>" ) 1901call VerifyScreenDump ( buf , 'Test_pum_matchins_combine_06' , {}) 1902call term_sendkeys ( buf , "\<Esc>" ) 1903 1904" Does not highlight the compl leader 1905call TermWait ( buf ) 1906call term_sendkeys ( buf , ":set cot+=menuone,noselect\<CR>" ) 1907call TermWait ( buf ) 1908call term_sendkeys ( buf , "S\<C-X>\<C-O>f\<C-N>" ) 1909call VerifyScreenDump ( buf , 'Test_pum_matchins_combine_07' , {}) 1910call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1911 1912call term_sendkeys ( buf , ":set cot+=fuzzy\<CR>" ) 1913call TermWait ( buf ) 1914call term_sendkeys ( buf , "S\<C-X>\<C-O>f\<C-N>" ) 1915call VerifyScreenDump ( buf , 'Test_pum_matchins_combine_08' , {}) 1916call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1917call TermWait ( buf ) 1918 1919call term_sendkeys ( buf , ":set cot-=fuzzy\<CR>" ) 1920call TermWait ( buf ) 1921call term_sendkeys ( buf , "Sf\<C-N>" ) 1922call VerifyScreenDump ( buf , 'Test_pum_matchins_combine_09' , {}) 1923call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1924 1925call StopVimInTerminal ( buf ) 1926endfunc 1927 1928" this used to crash 1929func Test_popup_completion_many_ctrlp () 1930new 1931let candidates = repeat ([ 'a0' ], 99 ) 1932call setline ( 1 , candidates ) 1933exe ":norm! VGg\<C-A>" 1934norm ! G 1935call feedkeys ( "o" .. repeat ( "\<c-p>" , 100 ), 'tx' ) 1936bw ! 1937endfunc 1938 1939func Test_pum_complete_with_special_characters () 1940CheckScreendump 1941 1942let lines =<< trim END 1943func Omni_test(findstart, base) 1944if a:findstart 1945return col(".") 1946endif 1947return [#{word: "func ()\n\t\nend", abbr: "function ()",}, #{word: "foobar"}, #{word: "你好\n\t\n我好"}] 1948endfunc 1949set omnifunc=Omni_test 1950inoremap <F5> <Cmd>call complete(col('.'), [ "my\n\tmulti\nline", "my\n\t\tmulti\nline" ])<CR> 1951END 1952 1953call writefile ( lines , 'Xpreviewscript' , 'D' ) 1954let buf = RunVimInTerminal ( '-S Xpreviewscript' , #{ rows : 12 }) 1955call term_sendkeys ( buf , "S\<C-X>\<C-O>" ) 1956call TermWait ( buf , 50 ) 1957call VerifyScreenDump ( buf , 'Test_pum_with_special_characters_01' , {}) 1958 1959call term_sendkeys ( buf , "\<C-N>" ) 1960call TermWait ( buf , 50 ) 1961call VerifyScreenDump ( buf , 'Test_pum_with_special_characters_02' , {}) 1962call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1963 1964call term_sendkeys ( buf , "Shello hero\<ESC>hhhhha\<C-X>\<C-O>" ) 1965call TermWait ( buf , 50 ) 1966call VerifyScreenDump ( buf , 'Test_pum_with_special_characters_03' , {}) 1967 1968call term_sendkeys ( buf , "\<C-N>" ) 1969call TermWait ( buf , 50 ) 1970call VerifyScreenDump ( buf , 'Test_pum_with_special_characters_04' , {}) 1971 1972call term_sendkeys ( buf , "\<C-N>" ) 1973call TermWait ( buf , 50 ) 1974call VerifyScreenDump ( buf , 'Test_pum_with_special_characters_05' , {}) 1975 1976call term_sendkeys ( buf , "\<C-N>" ) 1977call TermWait ( buf , 50 ) 1978call VerifyScreenDump ( buf , 'Test_pum_with_special_characters_06' , {}) 1979call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1980 1981call term_sendkeys ( buf , ":hi ComplMatchIns ctermfg=red\<CR>" ) 1982call TermWait ( buf , 50 ) 1983call term_sendkeys ( buf , "S\<C-X>\<C-O>" ) 1984call VerifyScreenDump ( buf , 'Test_pum_with_special_characters_07' , {}) 1985call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1986 1987call term_sendkeys ( buf , "Shello hero\<ESC>hhhhha\<C-X>\<C-O>" ) 1988call TermWait ( buf , 50 ) 1989call VerifyScreenDump ( buf , 'Test_pum_with_special_characters_08' , {}) 1990call term_sendkeys ( buf , "\<C-E>\<Esc>" ) 1991 1992call term_sendkeys ( buf , ":setlocal autoindent tabstop=2 shiftwidth=2\<CR>" ) 1993call term_sendkeys ( buf , "Slocal a = \<C-X>\<C-O>" ) 1994call TermWait ( buf , 50 ) 1995call VerifyScreenDump ( buf , 'Test_pum_with_special_characters_09' , {}) 1996 1997call term_sendkeys ( buf , "\<C-Y>" ) 1998call TermWait ( buf , 50 ) 1999call VerifyScreenDump ( buf , 'Test_pum_with_special_characters_10' , {}) 2000 2001call term_sendkeys ( buf , "\<ESC>kAlocal b = \<C-X>\<C-O>" ) 2002call TermWait ( buf , 50 ) 2003call VerifyScreenDump ( buf , 'Test_pum_with_special_characters_11' , {}) 2004 2005call term_sendkeys ( buf , "\<C-Y>" ) 2006call TermWait ( buf , 50 ) 2007call VerifyScreenDump ( buf , 'Test_pum_with_special_characters_12' , {}) 2008 2009call term_sendkeys ( buf , "\<ESC>ggVGd" ) 2010call term_sendkeys ( buf , ":filetype indent on\<CR>" ) 2011call term_sendkeys ( buf , ":set nocompatible autoindent& shiftwidth& tabstop&\<CR>" ) 2012call term_sendkeys ( buf , ":setlocal ft=lua\<CR>" ) 2013call term_sendkeys ( buf , "S\<F5>" ) 2014call TermWait ( buf , 50 ) 2015call VerifyScreenDump ( buf , 'Test_pum_with_special_characters_13' , {}) 2016 2017call StopVimInTerminal ( buf ) 2018endfunc 2019 2020func Test_pum_maxwidth () 2021CheckScreendump 2022 2023let lines =<< trim END 2024123456789_123456789_123456789_a 2025123456789_123456789_123456789_b 2026123 2027END 2028call writefile ( lines , 'Xtest' , 'D' ) 2029let buf = RunVimInTerminal ( 'Xtest' , {}) 2030 2031call term_sendkeys ( buf , "G\"zyy" ) 2032call term_sendkeys ( buf , "A\<C-N>" ) 2033call VerifyScreenDump ( buf , 'Test_pum_maxwidth_01' , { 'rows' : 8 }) 2034call term_sendkeys ( buf , "\<Esc>3Gdd\"zp" ) 2035 2036call term_sendkeys ( buf , ":set pummaxwidth=10\<CR>" ) 2037call term_sendkeys ( buf , "GA\<C-N>" ) 2038call VerifyScreenDump ( buf , 'Test_pum_maxwidth_02' , { 'rows' : 8 }) 2039call term_sendkeys ( buf , "\<Esc>3Gdd\"zp" ) 2040 2041call term_sendkeys ( buf , ":set pummaxwidth=20\<CR>" ) 2042call term_sendkeys ( buf , "GA\<C-N>" ) 2043call VerifyScreenDump ( buf , 'Test_pum_maxwidth_03' , { 'rows' : 8 }) 2044call term_sendkeys ( buf , "\<Esc>3Gdd\"zp" ) 2045 2046call term_sendkeys ( buf , ":set pumwidth=20 pummaxwidth=8\<CR>" ) 2047call term_sendkeys ( buf , "GA\<C-N>" ) 2048call VerifyScreenDump ( buf , 'Test_pum_maxwidth_04' , { 'rows' : 8 }) 2049call term_sendkeys ( buf , "\<Esc>3Gdd\"zp" ) 2050 2051call term_sendkeys ( buf , ":set lines=10 columns=32\<CR>" ) 2052call TermWait ( buf , 50 ) 2053call term_sendkeys ( buf , "GA\<C-N>" ) 2054call VerifyScreenDump ( buf , 'Test_pum_maxwidth_05' , { 'rows' : 10 , 'cols' : 32 }) 2055call term_sendkeys ( buf , "\<Esc>3Gdd\"zp" ) 2056 2057call StopVimInTerminal ( buf ) 2058endfunc 2059 2060func Test_pum_maxwidth_multibyte () 2061CheckScreendump 2062 2063let lines =<< trim END 2064hi StrikeFake ctermfg=9 2065let g:change = 0 2066func Omni_test(findstart, base) 2067if a:findstart 2068return col(".") 2069endif 2070if g:change == 0 2071return [ 2072\ #{word: "123456789_123456789_123456789_"}, 2073\ #{word: "一二三四五六七八九十"}, 2074\ #{word: "abcdefghij"}, 2075\ #{word: "上下左右"}, 2076\ ] 2077elseif g:change == 1 2078return [ 2079\ #{word: "foo", menu: "fooMenu", kind: "fooKind"}, 2080\ #{word: "bar", menu: "barMenu", kind: "barKind"}, 2081\ #{word: "baz", menu: "bazMenu", kind: "bazKind"}, 2082\ ] 2083elseif g:change == 2 2084return [ 2085\ #{word: "foo", menu: "fooMenu", kind: "fooKind"}, 2086\ #{word: "bar", menu: "fooMenu", kind: "一二三四"}, 2087\ #{word: "一二三四五", kind: "multi"}, 2088\ ] 2089return [#{word: "bar", menu: "fooMenu", kind: "一二三"}] 2090elseif g:change == 3 2091return [#{word: "bar", menu: "fooMenu", kind: "一二三"}] 2092else 2093return [ 2094\ #{word: "一二三四五六七八九十", abbr_hlgroup: "StrikeFake"}, 2095\ #{word: "123456789_123456789_123456789_", abbr_hlgroup: "StrikeFake"}, 2096\ ] 2097endif 2098endfunc 2099set omnifunc=Omni_test 2100set cot+=menuone 2101END 2102call writefile ( lines , 'Xtest' , 'D' ) 2103let buf = RunVimInTerminal ( '-S Xtest' , {}) 2104call TermWait ( buf ) 2105 2106call term_sendkeys ( buf , "S\<C-X>\<C-O>" ) 2107call VerifyScreenDump ( buf , 'Test_pum_maxwidth_06' , { 'rows' : 8 }) 2108call term_sendkeys ( buf , "\<ESC>" ) 2109 2110call term_sendkeys ( buf , ":set pummaxwidth=10\<CR>" ) 2111call term_sendkeys ( buf , "S\<C-X>\<C-O>" ) 2112call VerifyScreenDump ( buf , 'Test_pum_maxwidth_07' , { 'rows' : 8 }) 2113call term_sendkeys ( buf , "\<ESC>" ) 2114 2115if has ( 'rightleft' ) 2116call term_sendkeys ( buf , ":set rightleft\<CR>" ) 2117call term_sendkeys ( buf , "S\<C-X>\<C-O>" ) 2118call VerifyScreenDump ( buf , 'Test_pum_maxwidth_08' , { 'rows' : 8 }) 2119call term_sendkeys ( buf , "\<Esc>:set norightleft\<CR>" ) 2120endif 2121 2122call term_sendkeys ( buf , ":set pummaxwidth=2\<CR>" ) 2123call term_sendkeys ( buf , "S\<C-X>\<C-O>" ) 2124call VerifyScreenDump ( buf , 'Test_pum_maxwidth_09' , { 'rows' : 8 }) 2125call term_sendkeys ( buf , "\<ESC>" ) 2126 2127call term_sendkeys ( buf , ":set pummaxwidth=14\<CR>" ) 2128call term_sendkeys ( buf , ":let g:change=1\<CR>S\<C-X>\<C-O>" ) 2129call VerifyScreenDump ( buf , 'Test_pum_maxwidth_10' , { 'rows' : 8 }) 2130call term_sendkeys ( buf , "\<ESC>" ) 2131 2132" Unicode Character U+2026 but one cell 2133call term_sendkeys ( buf , ":set fcs+=trunc:…\<CR>" ) 2134call term_sendkeys ( buf , "S\<C-X>\<C-O>" ) 2135call VerifyScreenDump ( buf , 'Test_pum_maxwidth_11' , { 'rows' : 8 }) 2136call term_sendkeys ( buf , "\<ESC>" ) 2137 2138call term_sendkeys ( buf , ":let g:change=2\<CR>S\<C-X>\<C-O>" ) 2139call VerifyScreenDump ( buf , 'Test_pum_maxwidth_12' , { 'rows' : 8 }) 2140call term_sendkeys ( buf , "\<ESC>" ) 2141 2142call term_sendkeys ( buf , ":set fcs&\<CR>" ) 2143call term_sendkeys ( buf , "S\<C-X>\<C-O>" ) 2144call VerifyScreenDump ( buf , 'Test_pum_maxwidth_13' , { 'rows' : 8 }) 2145call term_sendkeys ( buf , "\<ESC>" ) 2146 2147call term_sendkeys ( buf , ":set fcs=trunc:_\<CR>" ) 2148call term_sendkeys ( buf , ":let g:change=1\<CR>" ) 2149call TermWait ( buf , 50 ) 2150call term_sendkeys ( buf , "S\<C-X>\<C-O>" ) 2151call VerifyScreenDump ( buf , 'Test_pum_maxwidth_14' , { 'rows' : 8 }) 2152call term_sendkeys ( buf , "\<ESC>" ) 2153call term_sendkeys ( buf , ":set fcs&\<CR>" ) 2154 2155if has ( 'rightleft' ) 2156call term_sendkeys ( buf , ":set rightleft\<CR>" ) 2157call term_sendkeys ( buf , "S\<C-X>\<C-O>" ) 2158call VerifyScreenDump ( buf , 'Test_pum_maxwidth_15' , { 'rows' : 8 }) 2159call term_sendkeys ( buf , "\<ESC>" ) 2160 2161call term_sendkeys ( buf , ":let g:change=2\<CR>" ) 2162call TermWait ( buf , 50 ) 2163call term_sendkeys ( buf , "S\<C-X>\<C-O>" ) 2164call VerifyScreenDump ( buf , 'Test_pum_maxwidth_16' , { 'rows' : 8 }) 2165call term_sendkeys ( buf , "\<ESC>" ) 2166 2167call term_sendkeys ( buf , ":set fcs+=truncrl:…\<CR>" ) 2168call term_sendkeys ( buf , "S\<C-X>\<C-O>" ) 2169call VerifyScreenDump ( buf , 'Test_pum_maxwidth_17' , { 'rows' : 8 }) 2170call term_sendkeys ( buf , "\<ESC>" ) 2171 2172call term_sendkeys ( buf , ":set fcs&\<CR>" ) 2173call term_sendkeys ( buf , ":let g:change=3\<CR>" ) 2174call TermWait ( buf , 50 ) 2175call term_sendkeys ( buf , "S\<C-X>\<C-O>" ) 2176call VerifyScreenDump ( buf , 'Test_pum_maxwidth_18' , { 'rows' : 8 }) 2177call term_sendkeys ( buf , "\<Esc>:set norightleft\<CR>" ) 2178endif 2179 2180call term_sendkeys ( buf , ":set pummaxwidth=4\<CR>" ) 2181call term_sendkeys ( buf , ":let g:change=2\<CR>" ) 2182call TermWait ( buf , 50 ) 2183call term_sendkeys ( buf , "S\<C-X>\<C-O>" ) 2184call VerifyScreenDump ( buf , 'Test_pum_maxwidth_19' , { 'rows' : 8 }) 2185call term_sendkeys ( buf , "\<ESC>" ) 2186 2187if has ( 'rightleft' ) 2188call term_sendkeys ( buf , ":set rightleft\<CR>" ) 2189call TermWait ( buf , 50 ) 2190call term_sendkeys ( buf , "S\<C-X>\<C-O>" ) 2191call VerifyScreenDump ( buf , 'Test_pum_maxwidth_20' , { 'rows' : 8 }) 2192call term_sendkeys ( buf , "\<Esc>:set norightleft\<CR>" ) 2193endif 2194 2195call term_sendkeys ( buf , ":set pummaxwidth=16\<CR>" ) 2196call TermWait ( buf , 50 ) 2197call term_sendkeys ( buf , "S\<C-X>\<C-O>" ) 2198call VerifyScreenDump ( buf , 'Test_pum_maxwidth_21' , { 'rows' : 8 }) 2199call term_sendkeys ( buf , "\<ESC>" ) 2200 2201if has ( 'rightleft' ) 2202call term_sendkeys ( buf , ":set rightleft\<CR>" ) 2203call TermWait ( buf , 50 ) 2204call term_sendkeys ( buf , "S\<C-X>\<C-O>" ) 2205call VerifyScreenDump ( buf , 'Test_pum_maxwidth_22' , { 'rows' : 8 }) 2206call term_sendkeys ( buf , "\<Esc>:set norightleft\<CR>" ) 2207endif 2208 2209call term_sendkeys ( buf , ":let g:change=4\<CR>" ) 2210call TermWait ( buf , 50 ) 2211call term_sendkeys ( buf , "S\<C-X>\<C-O>" ) 2212call VerifyScreenDump ( buf , 'Test_pum_maxwidth_23' , { 'rows' : 8 }) 2213call term_sendkeys ( buf , "\<ESC>" ) 2214 2215call StopVimInTerminal ( buf ) 2216endfunc 2217 2218func Test_pum_clear_when_switch_tab_or_win () 2219CheckScreendump 2220 2221let lines =<< trim END 2222inoremap <F4> <Cmd>wincmd w<CR> 2223inoremap <F5> <Cmd>tabnext<CR> 2224END 2225 2226call writefile ( lines , 'Xtest' , 'D' ) 2227let buf = RunVimInTerminal ( '-S Xtest' , {}) 2228 2229call term_sendkeys ( buf , ":tabe\<CR>" ) 2230call TermWait ( buf , 50 ) 2231call term_sendkeys ( buf , "Aaa aaa \<C-N>" ) 2232call VerifyScreenDump ( buf , 'Test_tabnext_clear_pum_01' , {}) 2233call term_sendkeys ( buf , "\<F5>" ) 2234call TermWait ( buf , 50 ) 2235call VerifyScreenDump ( buf , 'Test_tabnext_clear_pum_02' , {}) 2236call term_sendkeys ( buf , "\<ESC>:tabclose!\<CR>" ) 2237 2238call term_sendkeys ( buf , ":vnew win_b\<CR>" ) 2239call TermWait ( buf , 50 ) 2240call term_sendkeys ( buf , "Abb bbb \<C-N>" ) 2241call VerifyScreenDump ( buf , 'Test_switchwin_clear_pum_01' , {}) 2242call term_sendkeys ( buf , "\<F4>" ) 2243call TermWait ( buf , 50 ) 2244call VerifyScreenDump ( buf , 'Test_switchwin_clear_pum_02' , {}) 2245 2246call StopVimInTerminal ( buf ) 2247endfunc 2248 2249func Test_pum_position_when_wrap () 2250CheckScreendump 2251let lines =<< trim END 2252func Omni_test(findstart, base) 2253if a:findstart 2254return col(".") 2255endif 2256return ['foo', 'bar', 'foobar'] 2257endfunc 2258set omnifunc=Omni_test 2259set wrap 2260set cot+=noinsert 2261END 2262call writefile ( lines , 'Xtest' , 'D' ) 2263let buf = RunVimInTerminal ( '-S Xtest' , #{ rows : 15 , cols : 25 }) 2264 2265let long_text = repeat ( 'abcde ' , 20 ) 2266call term_sendkeys ( buf , "i" .. long_text ) 2267call TermWait ( buf , 50 ) 2268call term_sendkeys ( buf , "\<ESC>" ) 2269call TermWait ( buf , 50 ) 2270 2271call term_sendkeys ( buf , "5|" ) 2272call TermWait ( buf , 50 ) 2273call term_sendkeys ( buf , "a\<C-X>\<C-O>" ) 2274call TermWait ( buf , 100 ) 2275call VerifyScreenDump ( buf , 'Test_pum_wrap_line1' , {}) 2276call term_sendkeys ( buf , "\<ESC>" ) 2277call TermWait ( buf , 50 ) 2278 2279call term_sendkeys ( buf , "30|" ) 2280call TermWait ( buf , 50 ) 2281call term_sendkeys ( buf , "a\<C-X>\<C-O>" ) 2282call TermWait ( buf , 100 ) 2283call VerifyScreenDump ( buf , 'Test_pum_wrap_line2' , {}) 2284call term_sendkeys ( buf , "\<ESC>" ) 2285call TermWait ( buf , 50 ) 2286 2287call term_sendkeys ( buf , "55|" ) 2288call TermWait ( buf , 50 ) 2289call term_sendkeys ( buf , "a\<C-X>\<C-O>" ) 2290call TermWait ( buf , 100 ) 2291call VerifyScreenDump ( buf , 'Test_pum_wrap_line3' , {}) 2292call term_sendkeys ( buf , "\<C-E>\<ESC>" ) 2293call TermWait ( buf , 50 ) 2294 2295call term_sendkeys ( buf , "85|" ) 2296call TermWait ( buf , 50 ) 2297call term_sendkeys ( buf , "a\<C-X>\<C-O>" ) 2298call TermWait ( buf , 100 ) 2299call VerifyScreenDump ( buf , 'Test_pum_wrap_line4' , {}) 2300call term_sendkeys ( buf , "\<C-E>\<ESC>" ) 2301call TermWait ( buf , 100 ) 2302 2303call term_sendkeys ( buf , "108|" ) 2304call TermWait ( buf , 50 ) 2305call term_sendkeys ( buf , "a\<C-X>\<C-O>" ) 2306call TermWait ( buf , 100 ) 2307call VerifyScreenDump ( buf , 'Test_pum_wrap_line5' , {}) 2308call term_sendkeys ( buf , "\<C-E>\<ESC>" ) 2309call TermWait ( buf , 100 ) 2310 2311call StopVimInTerminal ( buf ) 2312endfunc 2313 2314" Test that Vim does not crash when completion inside cmdwin opens a 'info' 2315" preview window. 2316func Test_popup_complete_cmdwin_preview () 2317throw "Skipped: Nvim supports cmdwin freedom #40312" 2318func ! CompleteWithPreview ( findstart , base ) 2319if a: findstart 2320return getline ( '.' ) ->strpart ( 0 , col ( '.' ) - 1 ) 2321endif 2322return [#{ word : 'echo' , info : 'bar' }, #{ word : 'echomsg' , info : 'baz' }] 2323endfunc 2324set omnifunc = CompleteWithPreview 2325call feedkeys ( "q:if\<C-X>\<C-O>\<C-N>\<ESC>\<CR>" , 'tx!' ) 2326set omnifunc & 2327endfunc 2328 2329" vim: shiftwidth=2 sts=2 expandtab