neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

test_popup.vim (70507B)


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