robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 9a29622b3b00ddb601

master
69.7 KiB2329 linesraw
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()
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 ''
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)
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!
38endfunc
39
40func 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&
221endfunc
222
223func 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>
250endfunc
251
252func 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>
279endfunc
280
281func 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>
311endfunc
312
313func 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!
327endfunc
328
329func 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!
342endfunc
343
344func DummyCompleteOne(findstart, base)
345  if a:findstart
346    return 0
347  else
348    wincmd n
349    return ['onedef', 'oneDEF']
350  endif
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()
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!
365endfunc
366
367" Test that nothing happens if the 'completefunc' opens
368" a new window (no completion, no crash)
369func DummyCompleteTwo(findstart, base)
370  if a:findstart
371    wincmd n
372    return 0
373  else
374    return ['twodef', 'twoDEF']
375  endif
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()
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!
390endfunc
391
392func DummyCompleteThree(findstart, base)
393  if a:findstart
394    return 0
395  else
396    return ['threedef', 'threeDEF']
397  endif
398endfunc
399
400:"Test that 'completefunc' works when it's OK.
401func 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!
411endfunc
412
413func 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
427endfunc
428
429" Test that 'omnifunc' works when it's OK.
430func 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!
449endfunc
450
451func UndoComplete()
452  call complete(1, ['January', 'February', 'March',
453        \ 'April', 'May', 'June', 'July', 'August', 'September',
454        \ 'October', 'November', 'December'])
455  return ''
456endfunc
457
458" Test that no undo item is created when no completion is inserted
459func 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!
486endfunc
487
488func 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
500endfunc
501
502" Test that 'completefunc' on Scratch buffer with preview window works when
503" it's OK.
504func 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&
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()
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!
533endfunc
534
535func DummyCompleteSix()
536  call complete(1, ['Hello', 'World'])
537  return ''
538endfunction
539
540" complete() correctly clears the list of autocomplete candidates
541" See #1411
542func 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!
562endfunc
563
564func 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!
582endfunc
583
584func CompleteUndo() abort
585  call complete(1, g:months)
586  return ''
587endfunc
588
589func 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>
602endfunc
603
604func 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!
621endfunc
622
623func 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 []
631endfunc
632
633func MessCompleteMore()
634  call complete(1, split("Oct Nov Dec"))
635  return []
636endfunc
637
638func 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
651endfunc
652
653func 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=
663endfunc
664
665func 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!
678endfunc
679
680func 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!
713endfunc
714
715func 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  " Let pythoncomplete follow the buffer's 'import os' (off by default
729  " since v9.2.0561) so 'os.' can be completed.
730  let g:pythoncomplete_allow_import = 1
731  set omnifunc=pythoncomplete#Complete
732  call setline(1, 'import os')
733  " make the line long
734  call setline(2, '                                 os.')
735  $
736  call feedkeys("A\<C-X>\<C-O>\<C-N>\<C-N>\<C-N>\<enter>\<esc>", 'tx')
737  call assert_equal("import os", getline(1))
738  call assert_match('                                 os.\(EX_IOERR\|O_CREAT\)$', getline(2))
739  call assert_equal(1, winnr('$'))
740  " previewwindow option is not set
741  call assert_equal(0, &previewwindow)
742  norm! gt
743  call assert_equal(0, &previewwindow)
744  norm! gT
745  call assert_equal(10, tabpagenr('$'))
746  tabonly
747  pclose
748  augroup MyBufAdd
749    au!
750  augroup END
751  augroup! MyBufAdd
752  bw!
753  unlet g:pythoncomplete_allow_import
754endfunc
755
756func s:run_popup_and_previewwindow_dump(lines, dumpfile)
757  CheckScreendump
758  CheckFeature quickfix
759
760  call writefile(a:lines, 'Xscript', 'D')
761  let buf = RunVimInTerminal('-S Xscript', {})
762
763  " wait for the script to finish
764  call TermWait(buf)
765
766  " Test that popup and previewwindow do not overlap.
767  call term_sendkeys(buf, "o")
768  call TermWait(buf, 50)
769  call term_sendkeys(buf, "\<C-X>\<C-N>")
770  call VerifyScreenDump(buf, a:dumpfile, {})
771
772  call term_sendkeys(buf, "\<Esc>u")
773  call StopVimInTerminal(buf)
774endfunc
775
776func Test_popup_and_previewwindow_dump_pedit()
777  let lines =<< trim END
778    set previewheight=9
779    silent! pedit
780    call setline(1, map(repeat(["ab"], 10), "v:val .. v:key"))
781    exec "norm! G\<C-E>\<C-E>"
782  END
783  call s:run_popup_and_previewwindow_dump(lines, 'Test_popup_and_previewwindow_pedit')
784endfunc
785
786func Test_popup_and_previewwindow_dump_pbuffer()
787  let lines =<< trim END
788    set previewheight=9
789    silent! pbuffer
790    call setline(1, map(repeat(["ab"], 10), "v:val .. v:key"))
791    exec "norm! G\<C-E>\<C-E>\<C-E>"
792  END
793  call s:run_popup_and_previewwindow_dump(lines, 'Test_popup_and_previewwindow_pbuffer')
794endfunc
795
796func Test_balloon_split()
797  CheckFunction balloon_split
798
799  call assert_equal([
800        \ 'tempname: 0x555555e380a0 "/home/mool/.viminfz.tmp"',
801        \ ], balloon_split(
802        \ 'tempname: 0x555555e380a0 "/home/mool/.viminfz.tmp"'))
803  call 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
809  eval '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
818  call 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}'))
827  call 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}'))
834  call 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()
843  CheckScreendump
844
845  let lines =<< trim END
846    123456789_123456789_123456789_a
847    123456789_123456789_123456789_b
848                123
849  END
850  call writefile(lines, 'Xtest')
851  let buf = RunVimInTerminal('Xtest', {})
852  call term_sendkeys(buf, ":vsplit\<CR>")
853
854  " default pumwidth in left window: overlap in right window
855  call term_sendkeys(buf, "GA\<C-N>")
856  call VerifyScreenDump(buf, 'Test_popup_position_01', {'rows': 8})
857  call term_sendkeys(buf, "\<Esc>u")
858
859  " default pumwidth: fill until right of window
860  call term_sendkeys(buf, "\<C-W>l")
861  call term_sendkeys(buf, "GA\<C-N>")
862  call VerifyScreenDump(buf, 'Test_popup_position_02', {'rows': 8})
863
864  " larger pumwidth: used as minimum width
865  call term_sendkeys(buf, "\<Esc>u")
866  call term_sendkeys(buf, ":set pumwidth=30\<CR>")
867  call term_sendkeys(buf, "GA\<C-N>")
868  call VerifyScreenDump(buf, 'Test_popup_position_03', {'rows': 8})
869
870  " completed text wider than the window and 'pumwidth' smaller than available
871  " space
872  call term_sendkeys(buf, "\<Esc>u")
873  call term_sendkeys(buf, ":set pumwidth=20\<CR>")
874  call term_sendkeys(buf, "ggI123456789_\<Esc>")
875  call term_sendkeys(buf, "jI123456789_\<Esc>")
876  call term_sendkeys(buf, "GA\<C-N>")
877  call VerifyScreenDump(buf, 'Test_popup_position_04', {'rows': 10})
878
879  call term_sendkeys(buf, "\<Esc>u")
880  call StopVimInTerminal(buf)
881  call delete('Xtest')
882endfunc
883
884func Test_popup_command()
885  CheckFeature menu
886
887  menu Test.Foo Foo
888  call assert_fails('popup Test.Foo', 'E336:')
889  call assert_fails('popup Test.Foo.X', 'E327:')
890  call assert_fails('popup Foo', 'E337:')
891  unmenu Test.Foo
892endfunc
893
894func Test_popup_command_dump()
895  CheckFeature menu
896  CheckScreendump
897
898  let script =<< trim END
899    func StartTimer()
900      call timer_start(100, {-> ChangeMenu()})
901    endfunc
902    func ChangeMenu()
903      aunmenu PopUp.&Paste
904      nnoremenu 1.40 PopUp.&Paste :echomsg "pasted"<CR>
905      echomsg 'changed'
906    endfunc
907  END
908  call writefile(script, 'XtimerScript', 'D')
909
910  let lines =<< trim END
911	one two three four five
912	and one two Xthree four five
913	one more two three four five
914  END
915  call writefile(lines, 'Xtest', 'D')
916  let buf = RunVimInTerminal('-S XtimerScript Xtest', {})
917  call term_sendkeys(buf, ":source $VIMRUNTIME/menu.vim\<CR>")
918  call term_sendkeys(buf, "/X\<CR>:popup PopUp\<CR>")
919  call VerifyScreenDump(buf, 'Test_popup_command_01', {})
920
921  " go to the Paste entry in the menu
922  call term_sendkeys(buf, "jj")
923  call VerifyScreenDump(buf, 'Test_popup_command_02', {})
924
925  " Select a word
926  call term_sendkeys(buf, "j\<CR>")
927  call VerifyScreenDump(buf, 'Test_popup_command_03', {})
928
929  call term_sendkeys(buf, "\<Esc>")
930
931  if has('rightleft')
932    call term_sendkeys(buf, ":set rightleft\<CR>")
933    call term_sendkeys(buf, "/X\<CR>:popup PopUp\<CR>")
934    call VerifyScreenDump(buf, 'Test_popup_command_rl', {})
935    call term_sendkeys(buf, "\<Esc>:set norightleft\<CR>")
936  endif
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.
941  call term_sendkeys(buf, "/X\<CR>:call StartTimer() | popup PopUp\<CR>")
942  call VerifyScreenDump(buf, 'Test_popup_command_04', {})
943
944  " Select the Paste entry, executes the changed menu item.
945  call term_sendkeys(buf, "jj\<CR>")
946  call VerifyScreenDump(buf, 'Test_popup_command_05', {})
947
948  call term_sendkeys(buf, "\<Esc>")
949
950  " Add a window toolbar to the window and check the :popup menu position.
951  call term_sendkeys(buf, ":nnoremenu WinBar.TEST :\<CR>")
952  call term_sendkeys(buf, "/X\<CR>:popup PopUp\<CR>")
953  call VerifyScreenDump(buf, 'Test_popup_command_06', {})
954
955  call term_sendkeys(buf, "\<Esc>")
956
957  call StopVimInTerminal(buf)
958endfunc
959
960" Test position of right-click menu when clicking near window edge.
961func Test_mouse_popup_position()
962  CheckFeature menu
963  CheckScreendump
964
965  let script =<< trim END
966    set mousemodel=popup_setpos
967    source $VIMRUNTIME/menu.vim
968    call setline(1, join(range(20)))
969    func Trigger(col)
970      call test_setmouse(1, a:col)
971      call feedkeys("\<RightMouse>", 't')
972    endfunc
973  END
974  call writefile(script, 'XmousePopupPosition', 'D')
975  let buf = RunVimInTerminal('-S XmousePopupPosition', #{rows: 20, cols: 50})
976
977  call term_sendkeys(buf, ":call Trigger(45)\<CR>")
978  call VerifyScreenDump(buf, 'Test_mouse_popup_position_01', {})
979  call term_sendkeys(buf, "\<Esc>")
980
981  if has('rightleft')
982    call term_sendkeys(buf, ":set rightleft\<CR>")
983    call term_sendkeys(buf, ":call Trigger(50 + 1 - 45)\<CR>")
984    call VerifyScreenDump(buf, 'Test_mouse_popup_position_02', {})
985    call term_sendkeys(buf, "\<Esc>:set norightleft\<CR>")
986  endif
987
988  call StopVimInTerminal(buf)
989endfunc
990
991func Test_popup_complete_backwards()
992  new
993  call setline(1, ['Post', 'Port', 'Po'])
994  let expected=['Post', 'Port', 'Port']
995  call cursor(3,2)
996  call feedkeys("A\<C-X>". repeat("\<C-P>", 3). "rt\<C-Y>", 'tx')
997  call assert_equal(expected, getline(1,'$'))
998  bwipe!
999endfunc
1000
1001func Test_popup_complete_backwards_ctrl_p()
1002  new
1003  call setline(1, ['Post', 'Port', 'Po'])
1004  let expected=['Post', 'Port', 'Port']
1005  call cursor(3,2)
1006  call feedkeys("A\<C-P>\<C-N>rt\<C-Y>", 'tx')
1007  call assert_equal(expected, getline(1,'$'))
1008  bwipe!
1009endfunc
1010
1011func Test_complete_o_tab()
1012  let s:o_char_pressed = 0
1013
1014  fun! s:act_on_text_changed()
1015    if s:o_char_pressed
1016      let s:o_char_pressed = 0
1017      call feedkeys("\<c-x>\<c-n>", 'i')
1018    endif
1019  endfunc
1020
1021  set completeopt=menu,noselect
1022  new
1023  imap <expr> <buffer> <tab> pumvisible() ? "\<c-p>" : "X"
1024  autocmd! InsertCharPre <buffer> let s:o_char_pressed = (v:char ==# 'o')
1025  autocmd! TextChangedI <buffer> call <sid>act_on_text_changed()
1026  call setline(1,  ['hoard', 'hoax', 'hoarse', ''])
1027  let l:expected = ['hoard', 'hoax', 'hoarse', 'hoax', 'hoax']
1028  call cursor(4,1)
1029  call Ntest_override("char_avail", 1)
1030  call feedkeys("Ahoa\<tab>\<tab>\<c-y>\<esc>", 'tx')
1031  call feedkeys("oho\<tab>\<tab>\<c-y>\<esc>", 'tx')
1032  call assert_equal(l:expected, getline(1,'$'))
1033
1034  call Ntest_override("char_avail", 0)
1035  bwipe!
1036  set completeopt&
1037  delfunc s:act_on_text_changed
1038endfunc
1039
1040func Test_menu_only_exists_in_terminal()
1041  CheckCommand tlmenu
1042  CheckNotGui
1043
1044  tlnoremenu  &Edit.&Paste<Tab>"+gP  <C-W>"+
1045  aunmenu *
1046  try
1047    popup Edit
1048    call assert_false(1, 'command should have failed')
1049  catch
1050    call assert_exception('E328:')
1051  endtry
1052endfunc
1053
1054" This used to crash before patch 8.1.1424
1055func Test_popup_delete_when_shown()
1056  CheckFeature menu
1057  CheckNotGui
1058
1059  func Func()
1060    popup Foo
1061    return "\<Ignore>"
1062  endfunc
1063
1064  nmenu Foo.Bar :
1065  nnoremap <expr> <F2> Func()
1066  call feedkeys("\<F2>\<F2>\<Esc>", 'xt')
1067
1068  delfunc Func
1069  nunmenu Foo.Bar
1070  nunmap <F2>
1071endfunc
1072
1073func Test_popup_complete_info_01()
1074  new
1075  inoremap <buffer><F5> <C-R>=complete_info().mode<CR>
1076  func s:complTestEval() abort
1077    call complete(1, ['aa', 'ab'])
1078    return ''
1079  endfunc
1080  inoremap <buffer><F6> <C-R>=s:complTestEval()<CR>
1081  call writefile([
1082        \ 'dummy	dummy.txt	1',
1083        \], 'Xdummy.txt')
1084  setlocal tags=Xdummy.txt
1085  setlocal dictionary=Xdummy.txt
1086  setlocal thesaurus=Xdummy.txt
1087  setlocal omnifunc=syntaxcomplete#Complete
1088  setlocal completefunc=syntaxcomplete#Complete
1089  setlocal completeopt+=noinsert
1090  setlocal spell
1091  for [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        \]
1113    call feedkeys("i" . keys . "\<F5>\<Esc>", 'tx')
1114    call assert_equal(mode_name, getline('.'))
1115    %d
1116  endfor
1117  call delete('Xdummy.txt')
1118  bwipe!
1119endfunc
1120
1121func UserDefinedComplete(findstart, base)
1122  if a:findstart
1123    return 0
1124  else
1125    return [
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          \ ]
1132  endif
1133endfunc
1134
1135func GetCompleteInfo()
1136  if empty(g:compl_what)
1137    let g:compl_info = complete_info()
1138  else
1139    let g:compl_info = g:compl_what->complete_info()
1140  endif
1141  return ''
1142endfunc
1143
1144func Test_popup_complete_info_02()
1145  new
1146  inoremap <buffer><F5> <C-R>=GetCompleteInfo()<CR>
1147  setlocal completefunc=UserDefinedComplete
1148
1149  let 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
1163  let g:compl_what = []
1164  call feedkeys("i\<C-X>\<C-U>\<F5>", 'tx')
1165  call assert_equal(d, g:compl_info)
1166
1167  let g:compl_what = ['mode', 'pum_visible', 'preinserted_text', 'selected']
1168  call remove(d, 'items')
1169  call feedkeys("i\<C-X>\<C-U>\<F5>", 'tx')
1170  call assert_equal(d, g:compl_info)
1171
1172  let g:compl_what = ['mode']
1173  call remove(d, 'selected')
1174  call remove(d, 'pum_visible')
1175  call remove(d, 'preinserted_text')
1176  call feedkeys("i\<C-X>\<C-U>\<F5>", 'tx')
1177  call assert_equal(d, g:compl_info)
1178  bwipe!
1179endfunc
1180
1181func Test_popup_complete_info_no_pum()
1182  new
1183  call assert_false( pumvisible() )
1184  let no_pum_info = complete_info()
1185  let d = {
1186        \   'mode': '',
1187        \   'pum_visible': 0,
1188        \   'items': [],
1189        \   'preinserted_text': '',
1190        \   'selected': -1,
1191        \  }
1192  call assert_equal( d, complete_info() )
1193  bwipe!
1194endfunc
1195
1196func Test_CompleteChanged()
1197  new
1198  call setline(1, ['foo', 'bar', 'foobar', ''])
1199  set complete=. completeopt=noinsert,noselect,menuone
1200  function! OnPumChange()
1201    let g:event = copy(v:event)
1202    let g:item = get(v:event, 'completed_item', {})
1203    let g:word = get(g:item, 'word', v:null)
1204    let l:line = getline('.')
1205    if g:word == v:null && l:line == "bc"
1206      let g:word = l:line
1207    endif
1208  endfunction
1209  augroup AAAAA_Group
1210    au!
1211    autocmd CompleteChanged * :call OnPumChange()
1212  augroup END
1213  call cursor(4, 1)
1214
1215  call feedkeys("Sf\<C-N>", 'tx')
1216  call 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)
1219  call feedkeys("a\<C-N>\<C-N>\<C-E>", 'tx')
1220  call assert_equal('foo', g:word)
1221  call feedkeys("a\<C-N>\<C-N>\<C-N>\<C-E>", 'tx')
1222  call assert_equal('foobar', g:word)
1223  call feedkeys("a\<C-N>\<C-N>\<C-N>\<C-N>\<C-E>", 'tx')
1224  call assert_equal(v:null, g:word)
1225  call feedkeys("a\<C-N>\<C-N>\<C-N>\<C-N>\<C-P>", 'tx')
1226  call assert_equal('foobar', g:word)
1227  call feedkeys("S\<C-N>bc", 'tx')
1228  call assert_equal("bc", g:word)
1229
1230  func Omni_test(findstart, base)
1231    if a:findstart
1232      return col(".")
1233    endif
1234    return [#{word: "one"}, #{word: "two"}, #{word: "five"}]
1235  endfunc
1236  set omnifunc=Omni_test
1237  set completeopt=menu,menuone
1238  call feedkeys("i\<C-X>\<C-O>\<BS>\<BS>\<BS>f", 'tx')
1239  call assert_equal('five', g:word)
1240  call feedkeys("i\<C-X>\<C-O>\<BS>\<BS>\<BS>f\<BS>", 'tx')
1241  call assert_equal('one', g:word)
1242
1243  autocmd! AAAAA_Group
1244  set complete& completeopt&
1245  delfunc! OnPumChange
1246  delfunc! Omni_test
1247  bw!
1248endfunc
1249
1250func GetPumPosition()
1251  call assert_true( pumvisible() )
1252  let g:pum_pos = pum_getpos()
1253  return ''
1254endfunc
1255
1256func Test_pum_getpos()
1257  new
1258  inoremap <buffer><F5> <C-R>=GetPumPosition()<CR>
1259  setlocal completefunc=UserDefinedComplete
1260
1261   let 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    \ }
1269  call feedkeys("i\<C-X>\<C-U>\<F5>", 'tx')
1270  call assert_equal(d, g:pum_pos)
1271
1272  call assert_false( pumvisible() )
1273  call assert_equal( {}, pum_getpos() )
1274  bw!
1275  unlet g:pum_pos
1276endfunc
1277
1278" The popup menu is also used on a terminal without colors (issue #20800)
1279func Test_pum_without_colors()
1280  CheckNotGui
1281
1282  new
1283  let save_t_Co = &t_Co
1284  set t_Co=0
1285  inoremap <buffer><F5> <C-R>=GetPumPosition()<CR>
1286  call setline(1, ['hello', 'help', ''])
1287  call cursor(3, 1)
1288  call feedkeys("ih\<C-N>\<F5>\<Esc>", 'tx')
1289  call assert_equal(2, g:pum_pos.size)
1290
1291  let &t_Co = save_t_Co
1292  bw!
1293  unlet g:pum_pos
1294endfunc
1295
1296" Test for the popup menu with the 'rightleft' option set
1297func Test_pum_rightleft()
1298  CheckFeature rightleft
1299  CheckScreendump
1300
1301  let lines =<< trim END
1302    abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
1303    vim
1304    victory
1305  END
1306  call writefile(lines, 'Xtest1')
1307  let buf = RunVimInTerminal('--cmd "set rightleft" Xtest1', {})
1308  call term_wait(buf)
1309  call term_sendkeys(buf, "Go\<C-P>")
1310  call VerifyScreenDump(buf, 'Test_pum_rightleft_01', {'rows': 8})
1311  call term_sendkeys(buf, "\<C-P>\<C-Y>")
1312  call term_wait(buf)
1313  redraw!
1314  call assert_match('\s*miv', Screenline(5))
1315
1316  " Test for expanding tabs to spaces in the popup menu
1317  let lines =<< trim END
1318    one	two
1319    one	three
1320    four
1321  END
1322  call writefile(lines, 'Xtest2')
1323  call term_sendkeys(buf, "\<Esc>:e! Xtest2\<CR>")
1324  call term_wait(buf)
1325  call term_sendkeys(buf, "Goone\<C-X>\<C-L>")
1326  call term_wait(buf)
1327  redraw!
1328  call VerifyScreenDump(buf, 'Test_pum_rightleft_02', {'rows': 7})
1329  call term_sendkeys(buf, "\<C-Y>")
1330  call term_wait(buf)
1331  redraw!
1332  call assert_match('\s*eerht     eno', Screenline(4))
1333
1334  call StopVimInTerminal(buf)
1335  call delete('Xtest1')
1336  call delete('Xtest2')
1337endfunc
1338
1339" Test for a popup menu with a scrollbar
1340func Test_pum_scrollbar()
1341  CheckScreendump
1342  let lines =<< trim END
1343    one
1344    two
1345    three
1346  END
1347  call writefile(lines, 'Xtest1')
1348  let buf = RunVimInTerminal('--cmd "set pumheight=2" Xtest1', {})
1349  call term_wait(buf)
1350  call term_sendkeys(buf, "Go\<C-P>\<C-P>\<C-P>")
1351  call VerifyScreenDump(buf, 'Test_pum_scrollbar_01', {'rows': 7})
1352  call term_sendkeys(buf, "\<C-E>\<Esc>dd")
1353  call term_wait(buf)
1354
1355  if has('rightleft')
1356    call term_sendkeys(buf, ":set rightleft\<CR>")
1357    call term_wait(buf)
1358    call term_sendkeys(buf, "Go\<C-P>\<C-P>\<C-P>")
1359    call VerifyScreenDump(buf, 'Test_pum_scrollbar_02', {'rows': 7})
1360  endif
1361
1362  call StopVimInTerminal(buf)
1363  call delete('Xtest1')
1364endfunc
1365
1366" Test default highlight groups for popup menu
1367func Test_pum_highlights_default()
1368  CheckScreendump
1369  let lines =<< trim END
1370    func CompleteFunc( findstart, base )
1371      if a:findstart
1372        return 0
1373      endif
1374      return {
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            \]}
1380    endfunc
1381    set completeopt=menu
1382    set completefunc=CompleteFunc
1383  END
1384  call writefile(lines, 'Xscript', 'D')
1385  let buf = RunVimInTerminal('-S Xscript', {})
1386  call TermWait(buf)
1387  call term_sendkeys(buf, "iaw\<C-X>\<C-u>")
1388  call TermWait(buf, 50)
1389  call VerifyScreenDump(buf, 'Test_pum_highlights_01', {})
1390  call term_sendkeys(buf, "\<C-E>\<Esc>u")
1391  call TermWait(buf)
1392  call StopVimInTerminal(buf)
1393endfunc
1394
1395" Test custom highlight groups for popup menu
1396func Test_pum_highlights_custom()
1397  CheckScreendump
1398  let lines =<< trim END
1399    func CompleteFunc( findstart, base )
1400      if a:findstart
1401        return 0
1402      endif
1403      return {
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            \]}
1409    endfunc
1410    set completeopt=menu
1411    set completefunc=CompleteFunc
1412    hi PmenuKind      ctermfg=1 ctermbg=225
1413    hi PmenuKindSel   ctermfg=1 ctermbg=7
1414    hi PmenuExtra     ctermfg=243 ctermbg=225
1415    hi PmenuExtraSel  ctermfg=0 ctermbg=7
1416  END
1417  call writefile(lines, 'Xscript', 'D')
1418  let buf = RunVimInTerminal('-S Xscript', {})
1419  call TermWait(buf)
1420  call term_sendkeys(buf, "iaw\<C-X>\<C-u>")
1421  call TermWait(buf, 50)
1422  call VerifyScreenDump(buf, 'Test_pum_highlights_02', {})
1423  call term_sendkeys(buf, "\<C-E>\<Esc>u")
1424  call TermWait(buf)
1425  call StopVimInTerminal(buf)
1426endfunc
1427
1428" Test match relate highlight group in pmenu
1429func Test_pum_highlights_match()
1430  CheckScreendump
1431  let lines =<< trim END
1432    func Omni_test(findstart, base)
1433      if a:findstart
1434        return col(".")
1435      endif
1436      return {
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            \]}
1448    endfunc
1449
1450    func Comp()
1451      let col = col('.')
1452      if getline('.') == 'f'
1453        let col -= 1
1454      endif
1455      call complete(col, [
1456            \ #{word: "foo", icase: 1},
1457            \ #{word: "Foobar", icase: 1},
1458            \ #{word: "fooBaz", icase: 1},
1459            \])
1460      return ''
1461    endfunc
1462
1463    set omnifunc=Omni_test
1464    set completeopt=menu,noinsert,fuzzy
1465    hi PmenuMatchSel  ctermfg=6 ctermbg=7
1466    hi PmenuMatch     ctermfg=4 ctermbg=225
1467  END
1468  call writefile(lines, 'Xscript', 'D')
1469  let  buf = RunVimInTerminal('-S Xscript', {})
1470  call TermWait(buf)
1471  call term_sendkeys(buf, "i\<C-X>\<C-O>")
1472  call TermWait(buf, 50)
1473  call term_sendkeys(buf, "fo")
1474  call TermWait(buf, 50)
1475  call VerifyScreenDump(buf, 'Test_pum_highlights_03', {})
1476  call term_sendkeys(buf, "\<Esc>S\<C-X>\<C-O>")
1477  call TermWait(buf, 50)
1478  call term_sendkeys(buf, "你")
1479  call TermWait(buf, 50)
1480  call VerifyScreenDump(buf, 'Test_pum_highlights_04', {})
1481  call term_sendkeys(buf, "吗")
1482  call TermWait(buf, 50)
1483  call VerifyScreenDump(buf, 'Test_pum_highlights_05', {})
1484  call term_sendkeys(buf, "\<C-E>\<Esc>")
1485
1486  if has('rightleft')
1487    call term_sendkeys(buf, ":set rightleft\<CR>")
1488    call TermWait(buf, 50)
1489    call term_sendkeys(buf, "S\<C-X>\<C-O>")
1490    call TermWait(buf, 50)
1491    call term_sendkeys(buf, "fo")
1492    call TermWait(buf, 50)
1493    call VerifyScreenDump(buf, 'Test_pum_highlights_06', {})
1494    call term_sendkeys(buf, "\<Esc>S\<C-X>\<C-O>")
1495    call TermWait(buf, 50)
1496    call term_sendkeys(buf, "你")
1497    call VerifyScreenDump(buf, 'Test_pum_highlights_06a', {})
1498    call term_sendkeys(buf, "吗")
1499    call VerifyScreenDump(buf, 'Test_pum_highlights_06b', {})
1500    call term_sendkeys(buf, "\<C-E>\<Esc>")
1501    call term_sendkeys(buf, ":set norightleft\<CR>")
1502    call TermWait(buf)
1503  endif
1504
1505  call term_sendkeys(buf, ":set completeopt-=fuzzy\<CR>")
1506  call TermWait(buf)
1507  call term_sendkeys(buf, "S\<C-X>\<C-O>")
1508  call TermWait(buf, 50)
1509  call term_sendkeys(buf, "fo")
1510  call TermWait(buf, 50)
1511  call VerifyScreenDump(buf, 'Test_pum_highlights_07', {})
1512  call term_sendkeys(buf, "\<C-E>\<Esc>")
1513
1514  if has('rightleft')
1515    call term_sendkeys(buf, ":set rightleft\<CR>")
1516    call TermWait(buf, 50)
1517    call term_sendkeys(buf, "S\<C-X>\<C-O>")
1518    call TermWait(buf, 50)
1519    call term_sendkeys(buf, "fo")
1520    call TermWait(buf, 50)
1521    call VerifyScreenDump(buf, 'Test_pum_highlights_08', {})
1522    call term_sendkeys(buf, "\<C-E>\<Esc>")
1523    call term_sendkeys(buf, ":set norightleft\<CR>")
1524  endif
1525
1526  call term_sendkeys(buf, "S\<C-R>=Comp()\<CR>f")
1527  call VerifyScreenDump(buf, 'Test_pum_highlights_09', {})
1528  call term_sendkeys(buf, "o\<BS>\<C-R>=Comp()\<CR>")
1529  call VerifyScreenDump(buf, 'Test_pum_highlights_09', {})
1530  call term_sendkeys(buf, "\<C-E>\<Esc>")
1531
1532  call term_sendkeys(buf, ":hi PmenuMatchSel ctermfg=14 ctermbg=NONE\<CR>")
1533  call TermWait(buf, 50)
1534  call term_sendkeys(buf, ":hi PmenuMatch ctermfg=12 ctermbg=NONE\<CR>")
1535  call term_sendkeys(buf, ":set cot=menu,noinsert,fuzzy\<CR>")
1536  call term_sendkeys(buf, "S\<C-X>\<C-O>")
1537  call TermWait(buf, 50)
1538  call term_sendkeys(buf, "fb")
1539  call VerifyScreenDump(buf, 'Test_pum_highlights_18', {})
1540
1541  call term_sendkeys(buf, "\<C-E>\<Esc>")
1542  call TermWait(buf)
1543  call StopVimInTerminal(buf)
1544endfunc
1545
1546func Test_pum_completefuzzycollect()
1547  CheckScreendump
1548  let lines =<< trim END
1549    set completeopt=menu,menuone,fuzzy
1550  END
1551  call writefile(lines, 'Xscript', 'D')
1552  let  buf = RunVimInTerminal('-S Xscript', {})
1553
1554  " issue #15095 wrong select
1555  call term_sendkeys(buf, "S hello helio hero h\<C-X>\<C-P>")
1556  call TermWait(buf, 50)
1557  call VerifyScreenDump(buf, 'Test_pum_completefuzzycollect_01', {})
1558
1559  call term_sendkeys(buf, "\<ESC>S hello helio hero h\<C-X>\<C-P>\<C-P>")
1560  call TermWait(buf, 50)
1561  call VerifyScreenDump(buf, 'Test_pum_completefuzzycollect_02', {})
1562
1563  " issue #15357
1564  call term_sendkeys(buf, "\<ESC>S/non_existing_folder\<C-X>\<C-F>")
1565  call TermWait(buf, 50)
1566  call VerifyScreenDump(buf, 'Test_pum_completefuzzycollect_03', {})
1567  call term_sendkeys(buf, "\<C-E>\<Esc>")
1568
1569  call TermWait(buf)
1570  call StopVimInTerminal(buf)
1571endfunc
1572
1573func Test_pum_highlights_match_with_abbr()
1574  CheckScreendump
1575  let lines =<< trim END
1576    func Omni_test(findstart, base)
1577      if a:findstart
1578        return col(".")
1579      endif
1580      return {
1581            \ 'words': [
1582            \ { 'word': 'foobar', 'abbr': "foobar\t\t!" },
1583            \ { 'word': 'foobaz', 'abbr': "foobaz\t\t!" },
1584            \]}
1585    endfunc
1586
1587    set omnifunc=Omni_test
1588    set completeopt=menuone,noinsert
1589    hi PmenuMatchSel  ctermfg=6 ctermbg=7
1590    hi PmenuMatch     ctermfg=4 ctermbg=225
1591  END
1592  call writefile(lines, 'Xscript', 'D')
1593  let  buf = RunVimInTerminal('-S Xscript', {})
1594  call TermWait(buf)
1595  call term_sendkeys(buf, "i\<C-X>\<C-O>")
1596  call TermWait(buf, 50)
1597  call term_sendkeys(buf, "foo")
1598  call VerifyScreenDump(buf, 'Test_pum_highlights_19', {})
1599
1600  call term_sendkeys(buf, "\<C-E>\<Esc>")
1601  call TermWait(buf)
1602
1603  call StopVimInTerminal(buf)
1604endfunc
1605
1606func Test_pum_user_abbr_hlgroup()
1607  CheckScreendump
1608  let lines =<< trim END
1609    let s:var = 0
1610    func CompleteFunc(findstart, base)
1611      if a:findstart
1612        return 0
1613      endif
1614      if s:var == 1
1615        return {
1616              \ 'words': [
1617              \ { 'word': 'aword1', 'abbr_hlgroup': 'StrikeFake' },
1618              \ { 'word': '你好', 'abbr_hlgroup': 'StrikeFake' },
1619              \]}
1620      endif
1621      return {
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            \]}
1627    endfunc
1628    func ChangeVar()
1629      let s:var = 1
1630    endfunc
1631    set completeopt=menu
1632    set completefunc=CompleteFunc
1633
1634    hi StrikeFake ctermfg=9
1635    func HlMatch()
1636      hi PmenuMatchSel  ctermfg=6 ctermbg=7 cterm=underline
1637      hi PmenuMatch     ctermfg=4 ctermbg=225 cterm=underline
1638    endfunc
1639  END
1640  call writefile(lines, 'Xscript', 'D')
1641  let buf = RunVimInTerminal('-S Xscript', {})
1642
1643  call TermWait(buf)
1644  call term_sendkeys(buf, "Saw\<C-X>\<C-U>")
1645  call VerifyScreenDump(buf, 'Test_pum_highlights_12', {})
1646  call term_sendkeys(buf, "\<C-E>\<Esc>")
1647
1648  call TermWait(buf)
1649  call term_sendkeys(buf, ":call HlMatch()\<CR>")
1650
1651  call TermWait(buf)
1652  call term_sendkeys(buf, "Saw\<C-X>\<C-U>")
1653  call VerifyScreenDump(buf, 'Test_pum_highlights_13', {})
1654  call term_sendkeys(buf, "\<C-N>")
1655  call VerifyScreenDump(buf, 'Test_pum_highlights_14', {})
1656  call term_sendkeys(buf, "\<C-E>\<Esc>")
1657
1658  call TermWait(buf)
1659  call term_sendkeys(buf, ":call ChangeVar()\<CR>")
1660  call TermWait(buf)
1661  call term_sendkeys(buf, "S\<C-X>\<C-U>")
1662  call VerifyScreenDump(buf, 'Test_pum_highlights_17', {})
1663  call term_sendkeys(buf, "\<C-E>\<Esc>")
1664
1665  call StopVimInTerminal(buf)
1666endfunc
1667
1668func Test_pum_user_kind_hlgroup()
1669  CheckScreendump
1670  let lines =<< trim END
1671    func CompleteFunc(findstart, base)
1672      if a:findstart
1673        return 0
1674      endif
1675      return {
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            \]}
1681    endfunc
1682    set completeopt=menu
1683    set completefunc=CompleteFunc
1684
1685    hi StrikeFake ctermfg=9
1686    hi KindVar ctermfg=yellow
1687    hi KindFunc ctermfg=blue
1688    hi KindClass ctermfg=green
1689  END
1690  call writefile(lines, 'Xscript', 'D')
1691  let buf = RunVimInTerminal('-S Xscript', {})
1692
1693  call TermWait(buf)
1694  call term_sendkeys(buf, "S\<C-X>\<C-U>")
1695  call VerifyScreenDump(buf, 'Test_pum_highlights_16', {})
1696  call term_sendkeys(buf, "\<C-E>\<Esc>")
1697
1698  call StopVimInTerminal(buf)
1699endfunc
1700
1701func Test_pum_completeitemalign()
1702  CheckScreendump
1703  let lines =<< trim END
1704    func Omni_test(findstart, base)
1705      if a:findstart
1706        return col(".")
1707      endif
1708      return {
1709            \ 'words': [
1710            \ { 'word': 'foo', 'kind': 'S', 'menu': 'menu' },
1711            \ { 'word': 'bar', 'kind': 'T', 'menu': 'menu' },
1712            \ { 'word': '你好', 'kind': 'C', 'menu': '中文' },
1713            \]}
1714    endfunc
1715
1716    func Omni_long(findstart, base)
1717      if a:findstart
1718        return col(".")
1719      endif
1720      return {
1721            \ 'words': [
1722            \ { 'word': 'loooong_foo', 'kind': 'S', 'menu': 'menu' },
1723            \ { 'word': 'loooong_bar', 'kind': 'T', 'menu': 'menu' },
1724            \]}
1725    endfunc
1726    set omnifunc=Omni_test
1727    command! -nargs=0 T1 set cia=abbr,kind,menu
1728    command! -nargs=0 T2 set cia=abbr,menu,kind
1729    command! -nargs=0 T3 set cia=kind,abbr,menu
1730    command! -nargs=0 T4 set cia=kind,menu,abbr
1731    command! -nargs=0 T5 set cia=menu,abbr,kind
1732    command! -nargs=0 T6 set cia=menu,kind,abbr
1733    command! -nargs=0 T7 set cia&
1734  END
1735  call writefile(lines, 'Xscript', 'D')
1736  let  buf = RunVimInTerminal('-S Xscript', {})
1737  call TermWait(buf)
1738
1739  " T1 is default
1740  call term_sendkeys(buf, ":T1\<CR>S\<C-X>\<C-O>")
1741  call VerifyScreenDump(buf, 'Test_pum_completeitemalign_01', {})
1742  call term_sendkeys(buf, "\<C-E>\<Esc>")
1743
1744  " T2
1745  call term_sendkeys(buf, ":T2\<CR>S\<C-X>\<C-O>")
1746  call VerifyScreenDump(buf, 'Test_pum_completeitemalign_02', {})
1747  call term_sendkeys(buf, "\<C-E>\<Esc>")
1748
1749  " T3
1750  call term_sendkeys(buf, ":T3\<CR>S\<C-X>\<C-O>")
1751  call VerifyScreenDump(buf, 'Test_pum_completeitemalign_03', {})
1752  call term_sendkeys(buf, "\<C-E>\<Esc>")
1753
1754  " T4
1755  call term_sendkeys(buf, ":T4\<CR>S\<C-X>\<C-O>")
1756  call VerifyScreenDump(buf, 'Test_pum_completeitemalign_04', {})
1757  call term_sendkeys(buf, "\<C-E>\<Esc>")
1758
1759  " T5
1760  call term_sendkeys(buf, ":T5\<CR>S\<C-X>\<C-O>")
1761  call VerifyScreenDump(buf, 'Test_pum_completeitemalign_05', {})
1762  call term_sendkeys(buf, "\<C-E>\<Esc>")
1763
1764  " T6
1765  call term_sendkeys(buf, ":T6\<CR>S\<C-X>\<C-O>")
1766  call VerifyScreenDump(buf, 'Test_pum_completeitemalign_06', {})
1767  call term_sendkeys(buf, "\<C-E>\<Esc>")
1768
1769  call term_sendkeys(buf, ":set columns=12 cmdheight=2 omnifunc=Omni_long\<CR>S\<C-X>\<C-O>")
1770  call VerifyScreenDump(buf, 'Test_pum_completeitemalign_07', {})
1771  call term_sendkeys(buf, "\<C-E>\<Esc>:T7\<CR>")
1772  call StopVimInTerminal(buf)
1773endfunc
1774
1775func Test_pum_keep_select()
1776  CheckScreendump
1777  let lines =<< trim END
1778    set completeopt=menu,menuone,noinsert
1779  END
1780  call writefile(lines, 'Xscript', 'D')
1781  let buf = RunVimInTerminal('-S Xscript', {})
1782  call TermWait(buf)
1783
1784  call term_sendkeys(buf, "ggSFab\<CR>Five\<CR>find\<CR>film\<CR>\<C-X>\<C-P>")
1785  call TermWait(buf, 50)
1786  call VerifyScreenDump(buf, 'Test_pum_keep_select_01', {})
1787  call term_sendkeys(buf, "\<C-E>\<Esc>")
1788  call TermWait(buf, 50)
1789
1790  call term_sendkeys(buf, "S\<C-X>\<C-P>")
1791  call TermWait(buf, 50)
1792  call term_sendkeys(buf, "F")
1793  call VerifyScreenDump(buf, 'Test_pum_keep_select_02', {})
1794  call term_sendkeys(buf, "\<C-E>\<Esc>")
1795
1796  call TermWait(buf, 50)
1797  call StopVimInTerminal(buf)
1798endfunc
1799
1800func Test_pum_matchins_highlight()
1801  CheckScreendump
1802  let lines =<< trim END
1803    let g:change = 0
1804    func Omni_test(findstart, base)
1805      if a:findstart
1806        return col(".")
1807      endif
1808      if g:change == 0
1809        return [#{word: "foo"}, #{word: "bar"}, #{word: "你好"}]
1810      endif
1811      return [#{word: "foo", info: "info"}, #{word: "bar"}, #{word: "你好"}]
1812    endfunc
1813    set omnifunc=Omni_test
1814    hi ComplMatchIns ctermfg=red
1815  END
1816  call writefile(lines, 'Xscript', 'D')
1817  let buf = RunVimInTerminal('-S Xscript', {})
1818
1819  call TermWait(buf)
1820  call term_sendkeys(buf, "Sαβγ \<C-X>\<C-O>")
1821  call VerifyScreenDump(buf, 'Test_pum_matchins_01', {})
1822  call term_sendkeys(buf, "\<C-E>\<Esc>")
1823
1824  call TermWait(buf)
1825  call term_sendkeys(buf, "Sαβγ \<C-X>\<C-O>\<C-N>")
1826  call VerifyScreenDump(buf, 'Test_pum_matchins_02', {})
1827  call term_sendkeys(buf, "\<C-E>\<Esc>")
1828
1829  call TermWait(buf)
1830  call term_sendkeys(buf, "Sαβγ \<C-X>\<C-O>\<C-N>\<C-N>")
1831  call VerifyScreenDump(buf, 'Test_pum_matchins_03', {})
1832  call term_sendkeys(buf, "\<C-E>\<Esc>")
1833
1834  " restore after accept
1835  call TermWait(buf)
1836  call term_sendkeys(buf, "Sαβγ \<C-X>\<C-O>\<C-Y>")
1837  call VerifyScreenDump(buf, 'Test_pum_matchins_04', {})
1838  call term_sendkeys(buf, "\<Esc>")
1839
1840  " restore after cancel completion
1841  call TermWait(buf)
1842  call term_sendkeys(buf, "Sαβγ \<C-X>\<C-O>\<Space>")
1843  call VerifyScreenDump(buf, 'Test_pum_matchins_05', {})
1844  call term_sendkeys(buf, "\<Esc>")
1845
1846  " text after the inserted text shouldn't be highlighted
1847  call TermWait(buf)
1848  call term_sendkeys(buf, "0ea \<C-X>\<C-O>")
1849  call VerifyScreenDump(buf, 'Test_pum_matchins_07', {})
1850  call term_sendkeys(buf, "\<C-P>")
1851  call VerifyScreenDump(buf, 'Test_pum_matchins_08', {})
1852  call term_sendkeys(buf, "\<C-P>")
1853  call VerifyScreenDump(buf, 'Test_pum_matchins_09', {})
1854  call term_sendkeys(buf, "\<C-Y>")
1855  call VerifyScreenDump(buf, 'Test_pum_matchins_10', {})
1856  call term_sendkeys(buf, "\<Esc>")
1857
1858  call term_sendkeys(buf, ":let g:change=1\<CR>S\<C-X>\<C-O>")
1859  call VerifyScreenDump(buf, 'Test_pum_matchins_11', {})
1860  call term_sendkeys(buf, "\<Esc>")
1861
1862  call StopVimInTerminal(buf)
1863endfunc
1864
1865func Test_pum_matchins_highlight_combine()
1866  CheckScreendump
1867  let lines =<< trim END
1868    func Omni_test(findstart, base)
1869      if a:findstart
1870        return col(".")
1871      endif
1872      return [#{word: "foo"}, #{word: "bar"}, #{word: "你好"}]
1873    endfunc
1874    set omnifunc=Omni_test
1875    hi Normal ctermbg=blue
1876    hi CursorLine cterm=underline ctermbg=green
1877    set cursorline
1878    call setline(1, 'aaa bbb')
1879  END
1880  call writefile(lines, 'Xscript', 'D')
1881  let buf = RunVimInTerminal('-S Xscript', {})
1882
1883  " when ComplMatchIns is not set, CursorLine applies normally
1884  call term_sendkeys(buf, "0ea \<C-X>\<C-O>")
1885  call VerifyScreenDump(buf, 'Test_pum_matchins_combine_01', {})
1886  call term_sendkeys(buf, "\<C-E>")
1887  call VerifyScreenDump(buf, 'Test_pum_matchins_combine_02', {})
1888  call term_sendkeys(buf, "\<BS>\<Esc>")
1889
1890  " when ComplMatchIns is set, it is applied over CursorLine
1891  call TermWait(buf)
1892  call term_sendkeys(buf, ":hi ComplMatchIns ctermbg=red ctermfg=yellow\<CR>")
1893  call TermWait(buf)
1894  call term_sendkeys(buf, "0ea \<C-X>\<C-O>")
1895  call VerifyScreenDump(buf, 'Test_pum_matchins_combine_03', {})
1896  call term_sendkeys(buf, "\<C-P>")
1897  call VerifyScreenDump(buf, 'Test_pum_matchins_combine_04', {})
1898  call term_sendkeys(buf, "\<C-P>")
1899  call VerifyScreenDump(buf, 'Test_pum_matchins_combine_05', {})
1900  call term_sendkeys(buf, "\<C-E>")
1901  call VerifyScreenDump(buf, 'Test_pum_matchins_combine_06', {})
1902  call term_sendkeys(buf, "\<Esc>")
1903
1904  " Does not highlight the compl leader
1905  call TermWait(buf)
1906  call term_sendkeys(buf, ":set cot+=menuone,noselect\<CR>")
1907  call TermWait(buf)
1908  call term_sendkeys(buf, "S\<C-X>\<C-O>f\<C-N>")
1909  call VerifyScreenDump(buf, 'Test_pum_matchins_combine_07', {})
1910  call term_sendkeys(buf, "\<C-E>\<Esc>")
1911
1912  call term_sendkeys(buf, ":set cot+=fuzzy\<CR>")
1913  call TermWait(buf)
1914  call term_sendkeys(buf, "S\<C-X>\<C-O>f\<C-N>")
1915  call VerifyScreenDump(buf, 'Test_pum_matchins_combine_08', {})
1916  call term_sendkeys(buf, "\<C-E>\<Esc>")
1917  call TermWait(buf)
1918
1919  call term_sendkeys(buf, ":set cot-=fuzzy\<CR>")
1920  call TermWait(buf)
1921  call term_sendkeys(buf, "Sf\<C-N>")
1922  call VerifyScreenDump(buf, 'Test_pum_matchins_combine_09', {})
1923  call term_sendkeys(buf, "\<C-E>\<Esc>")
1924
1925  call StopVimInTerminal(buf)
1926endfunc
1927
1928" this used to crash
1929func Test_popup_completion_many_ctrlp()
1930  new
1931  let candidates=repeat(['a0'], 99)
1932  call setline(1, candidates)
1933  exe ":norm! VGg\<C-A>"
1934  norm! G
1935  call feedkeys("o" .. repeat("\<c-p>", 100), 'tx')
1936  bw!
1937endfunc
1938
1939func Test_pum_complete_with_special_characters()
1940  CheckScreendump
1941
1942  let lines =<< trim END
1943    func Omni_test(findstart, base)
1944      if a:findstart
1945        return col(".")
1946      endif
1947      return [#{word: "func ()\n\t\nend", abbr: "function ()",}, #{word: "foobar"}, #{word: "你好\n\t\n我好"}]
1948    endfunc
1949    set omnifunc=Omni_test
1950    inoremap <F5> <Cmd>call complete(col('.'), [ "my\n\tmulti\nline", "my\n\t\tmulti\nline" ])<CR>
1951  END
1952
1953  call writefile(lines, 'Xpreviewscript', 'D')
1954  let buf = RunVimInTerminal('-S Xpreviewscript', #{rows: 12})
1955  call term_sendkeys(buf, "S\<C-X>\<C-O>")
1956  call TermWait(buf, 50)
1957  call VerifyScreenDump(buf, 'Test_pum_with_special_characters_01', {})
1958
1959  call term_sendkeys(buf, "\<C-N>")
1960  call TermWait(buf, 50)
1961  call VerifyScreenDump(buf, 'Test_pum_with_special_characters_02', {})
1962  call term_sendkeys(buf, "\<C-E>\<Esc>")
1963
1964  call term_sendkeys(buf, "Shello  hero\<ESC>hhhhha\<C-X>\<C-O>")
1965  call TermWait(buf, 50)
1966  call VerifyScreenDump(buf, 'Test_pum_with_special_characters_03', {})
1967
1968  call term_sendkeys(buf, "\<C-N>")
1969  call TermWait(buf, 50)
1970  call VerifyScreenDump(buf, 'Test_pum_with_special_characters_04', {})
1971
1972  call term_sendkeys(buf, "\<C-N>")
1973  call TermWait(buf, 50)
1974  call VerifyScreenDump(buf, 'Test_pum_with_special_characters_05', {})
1975
1976  call term_sendkeys(buf, "\<C-N>")
1977  call TermWait(buf, 50)
1978  call VerifyScreenDump(buf, 'Test_pum_with_special_characters_06', {})
1979  call term_sendkeys(buf, "\<C-E>\<Esc>")
1980
1981  call term_sendkeys(buf, ":hi ComplMatchIns ctermfg=red\<CR>")
1982  call TermWait(buf, 50)
1983  call term_sendkeys(buf, "S\<C-X>\<C-O>")
1984  call VerifyScreenDump(buf, 'Test_pum_with_special_characters_07', {})
1985  call term_sendkeys(buf, "\<C-E>\<Esc>")
1986
1987  call term_sendkeys(buf, "Shello  hero\<ESC>hhhhha\<C-X>\<C-O>")
1988  call TermWait(buf, 50)
1989  call VerifyScreenDump(buf, 'Test_pum_with_special_characters_08', {})
1990  call term_sendkeys(buf, "\<C-E>\<Esc>")
1991
1992  call term_sendkeys(buf, ":setlocal autoindent tabstop=2 shiftwidth=2\<CR>")
1993  call term_sendkeys(buf, "Slocal a = \<C-X>\<C-O>")
1994  call TermWait(buf, 50)
1995  call VerifyScreenDump(buf, 'Test_pum_with_special_characters_09', {})
1996
1997  call term_sendkeys(buf, "\<C-Y>")
1998  call TermWait(buf, 50)
1999  call VerifyScreenDump(buf, 'Test_pum_with_special_characters_10', {})
2000
2001  call term_sendkeys(buf, "\<ESC>kAlocal b = \<C-X>\<C-O>")
2002  call TermWait(buf, 50)
2003  call VerifyScreenDump(buf, 'Test_pum_with_special_characters_11', {})
2004
2005  call term_sendkeys(buf, "\<C-Y>")
2006  call TermWait(buf, 50)
2007  call VerifyScreenDump(buf, 'Test_pum_with_special_characters_12', {})
2008
2009  call term_sendkeys(buf, "\<ESC>ggVGd")
2010  call term_sendkeys(buf, ":filetype indent on\<CR>")
2011  call term_sendkeys(buf, ":set nocompatible autoindent& shiftwidth& tabstop&\<CR>")
2012  call term_sendkeys(buf, ":setlocal ft=lua\<CR>")
2013  call term_sendkeys(buf, "S\<F5>")
2014  call TermWait(buf, 50)
2015  call VerifyScreenDump(buf, 'Test_pum_with_special_characters_13', {})
2016
2017  call StopVimInTerminal(buf)
2018endfunc
2019
2020func Test_pum_maxwidth()
2021  CheckScreendump
2022
2023  let lines =<< trim END
2024    123456789_123456789_123456789_a
2025    123456789_123456789_123456789_b
2026                123
2027  END
2028  call writefile(lines, 'Xtest', 'D')
2029  let buf = RunVimInTerminal('Xtest', {})
2030
2031  call term_sendkeys(buf, "G\"zyy")
2032  call term_sendkeys(buf, "A\<C-N>")
2033  call VerifyScreenDump(buf, 'Test_pum_maxwidth_01', {'rows': 8})
2034  call term_sendkeys(buf, "\<Esc>3Gdd\"zp")
2035
2036  call term_sendkeys(buf, ":set pummaxwidth=10\<CR>")
2037  call term_sendkeys(buf, "GA\<C-N>")
2038  call VerifyScreenDump(buf, 'Test_pum_maxwidth_02', {'rows': 8})
2039  call term_sendkeys(buf, "\<Esc>3Gdd\"zp")
2040
2041  call term_sendkeys(buf, ":set pummaxwidth=20\<CR>")
2042  call term_sendkeys(buf, "GA\<C-N>")
2043  call VerifyScreenDump(buf, 'Test_pum_maxwidth_03', {'rows': 8})
2044  call term_sendkeys(buf, "\<Esc>3Gdd\"zp")
2045
2046  call term_sendkeys(buf, ":set pumwidth=20 pummaxwidth=8\<CR>")
2047  call term_sendkeys(buf, "GA\<C-N>")
2048  call VerifyScreenDump(buf, 'Test_pum_maxwidth_04', {'rows': 8})
2049  call term_sendkeys(buf, "\<Esc>3Gdd\"zp")
2050
2051  call term_sendkeys(buf, ":set lines=10 columns=32\<CR>")
2052  call TermWait(buf, 50)
2053  call term_sendkeys(buf, "GA\<C-N>")
2054  call VerifyScreenDump(buf, 'Test_pum_maxwidth_05', {'rows': 10, 'cols': 32})
2055  call term_sendkeys(buf, "\<Esc>3Gdd\"zp")
2056
2057  call StopVimInTerminal(buf)
2058endfunc
2059
2060func Test_pum_maxwidth_multibyte()
2061  CheckScreendump
2062
2063  let lines =<< trim END
2064    hi StrikeFake ctermfg=9
2065    let g:change = 0
2066    func Omni_test(findstart, base)
2067      if a:findstart
2068        return col(".")
2069      endif
2070      if g:change == 0
2071        return [
2072          \ #{word: "123456789_123456789_123456789_"},
2073          \ #{word: "一二三四五六七八九十"},
2074          \ #{word: "abcdefghij"},
2075          \ #{word: "上下左右"},
2076          \ ]
2077      elseif g:change == 1
2078        return [
2079          \ #{word: "foo", menu: "fooMenu", kind: "fooKind"},
2080          \ #{word: "bar", menu: "barMenu", kind: "barKind"},
2081          \ #{word: "baz", menu: "bazMenu", kind: "bazKind"},
2082          \ ]
2083      elseif g:change == 2
2084        return [
2085          \ #{word: "foo", menu: "fooMenu", kind: "fooKind"},
2086          \ #{word: "bar", menu: "fooMenu", kind: "一二三四"},
2087          \ #{word: "一二三四五", kind: "multi"},
2088          \ ]
2089        return [#{word: "bar", menu: "fooMenu", kind: "一二三"}]
2090      elseif g:change == 3
2091        return [#{word: "bar", menu: "fooMenu", kind: "一二三"}]
2092      else
2093        return [
2094          \ #{word: "一二三四五六七八九十", abbr_hlgroup: "StrikeFake"},
2095          \ #{word: "123456789_123456789_123456789_", abbr_hlgroup: "StrikeFake"},
2096          \ ]
2097      endif
2098    endfunc
2099    set omnifunc=Omni_test
2100    set cot+=menuone
2101  END
2102  call writefile(lines, 'Xtest', 'D')
2103  let  buf = RunVimInTerminal('-S Xtest', {})
2104  call TermWait(buf)
2105
2106  call term_sendkeys(buf, "S\<C-X>\<C-O>")
2107  call VerifyScreenDump(buf, 'Test_pum_maxwidth_06', {'rows': 8})
2108  call term_sendkeys(buf, "\<ESC>")
2109
2110  call term_sendkeys(buf, ":set pummaxwidth=10\<CR>")
2111  call term_sendkeys(buf, "S\<C-X>\<C-O>")
2112  call VerifyScreenDump(buf, 'Test_pum_maxwidth_07', {'rows': 8})
2113  call term_sendkeys(buf, "\<ESC>")
2114
2115  if has('rightleft')
2116    call term_sendkeys(buf, ":set rightleft\<CR>")
2117    call term_sendkeys(buf, "S\<C-X>\<C-O>")
2118    call VerifyScreenDump(buf, 'Test_pum_maxwidth_08', {'rows': 8})
2119    call term_sendkeys(buf, "\<Esc>:set norightleft\<CR>")
2120  endif
2121
2122  call term_sendkeys(buf, ":set pummaxwidth=2\<CR>")
2123  call term_sendkeys(buf, "S\<C-X>\<C-O>")
2124  call VerifyScreenDump(buf, 'Test_pum_maxwidth_09', {'rows': 8})
2125  call term_sendkeys(buf, "\<ESC>")
2126
2127  call term_sendkeys(buf, ":set pummaxwidth=14\<CR>")
2128  call term_sendkeys(buf, ":let g:change=1\<CR>S\<C-X>\<C-O>")
2129  call VerifyScreenDump(buf, 'Test_pum_maxwidth_10', {'rows': 8})
2130  call term_sendkeys(buf, "\<ESC>")
2131
2132  " Unicode Character U+2026 but one cell
2133  call term_sendkeys(buf, ":set fcs+=trunc:…\<CR>")
2134  call term_sendkeys(buf, "S\<C-X>\<C-O>")
2135  call VerifyScreenDump(buf, 'Test_pum_maxwidth_11', {'rows': 8})
2136  call term_sendkeys(buf, "\<ESC>")
2137
2138  call term_sendkeys(buf, ":let g:change=2\<CR>S\<C-X>\<C-O>")
2139  call VerifyScreenDump(buf, 'Test_pum_maxwidth_12', {'rows': 8})
2140  call term_sendkeys(buf, "\<ESC>")
2141
2142  call term_sendkeys(buf, ":set fcs&\<CR>")
2143  call term_sendkeys(buf, "S\<C-X>\<C-O>")
2144  call VerifyScreenDump(buf, 'Test_pum_maxwidth_13', {'rows': 8})
2145  call term_sendkeys(buf, "\<ESC>")
2146
2147  call term_sendkeys(buf, ":set fcs=trunc:_\<CR>")
2148  call term_sendkeys(buf, ":let g:change=1\<CR>")
2149  call TermWait(buf, 50)
2150  call term_sendkeys(buf, "S\<C-X>\<C-O>")
2151  call VerifyScreenDump(buf, 'Test_pum_maxwidth_14', {'rows': 8})
2152  call term_sendkeys(buf, "\<ESC>")
2153  call term_sendkeys(buf, ":set fcs&\<CR>")
2154
2155  if has('rightleft')
2156    call term_sendkeys(buf, ":set rightleft\<CR>")
2157    call term_sendkeys(buf, "S\<C-X>\<C-O>")
2158    call VerifyScreenDump(buf, 'Test_pum_maxwidth_15', {'rows': 8})
2159    call term_sendkeys(buf, "\<ESC>")
2160
2161    call term_sendkeys(buf, ":let g:change=2\<CR>")
2162    call TermWait(buf, 50)
2163    call term_sendkeys(buf, "S\<C-X>\<C-O>")
2164    call VerifyScreenDump(buf, 'Test_pum_maxwidth_16', {'rows': 8})
2165    call term_sendkeys(buf, "\<ESC>")
2166
2167    call term_sendkeys(buf, ":set fcs+=truncrl:…\<CR>")
2168    call term_sendkeys(buf, "S\<C-X>\<C-O>")
2169    call VerifyScreenDump(buf, 'Test_pum_maxwidth_17', {'rows': 8})
2170    call term_sendkeys(buf, "\<ESC>")
2171
2172    call term_sendkeys(buf, ":set fcs&\<CR>")
2173    call term_sendkeys(buf, ":let g:change=3\<CR>")
2174    call TermWait(buf, 50)
2175    call term_sendkeys(buf, "S\<C-X>\<C-O>")
2176    call VerifyScreenDump(buf, 'Test_pum_maxwidth_18', {'rows': 8})
2177    call term_sendkeys(buf, "\<Esc>:set norightleft\<CR>")
2178  endif
2179
2180  call term_sendkeys(buf, ":set pummaxwidth=4\<CR>")
2181  call term_sendkeys(buf, ":let g:change=2\<CR>")
2182  call TermWait(buf, 50)
2183  call term_sendkeys(buf, "S\<C-X>\<C-O>")
2184  call VerifyScreenDump(buf, 'Test_pum_maxwidth_19', {'rows': 8})
2185  call term_sendkeys(buf, "\<ESC>")
2186
2187  if has('rightleft')
2188    call term_sendkeys(buf, ":set rightleft\<CR>")
2189    call TermWait(buf, 50)
2190    call term_sendkeys(buf, "S\<C-X>\<C-O>")
2191    call VerifyScreenDump(buf, 'Test_pum_maxwidth_20', {'rows': 8})
2192    call term_sendkeys(buf, "\<Esc>:set norightleft\<CR>")
2193  endif
2194
2195  call term_sendkeys(buf, ":set pummaxwidth=16\<CR>")
2196  call TermWait(buf, 50)
2197  call term_sendkeys(buf, "S\<C-X>\<C-O>")
2198  call VerifyScreenDump(buf, 'Test_pum_maxwidth_21', {'rows': 8})
2199  call term_sendkeys(buf, "\<ESC>")
2200
2201  if has('rightleft')
2202    call term_sendkeys(buf, ":set rightleft\<CR>")
2203    call TermWait(buf, 50)
2204    call term_sendkeys(buf, "S\<C-X>\<C-O>")
2205    call VerifyScreenDump(buf, 'Test_pum_maxwidth_22', {'rows': 8})
2206    call term_sendkeys(buf, "\<Esc>:set norightleft\<CR>")
2207  endif
2208
2209  call term_sendkeys(buf, ":let g:change=4\<CR>")
2210  call TermWait(buf, 50)
2211  call term_sendkeys(buf, "S\<C-X>\<C-O>")
2212  call VerifyScreenDump(buf, 'Test_pum_maxwidth_23', {'rows': 8})
2213  call term_sendkeys(buf, "\<ESC>")
2214
2215  call StopVimInTerminal(buf)
2216endfunc
2217
2218func Test_pum_clear_when_switch_tab_or_win()
2219  CheckScreendump
2220
2221  let lines =<< trim END
2222    inoremap <F4> <Cmd>wincmd w<CR>
2223    inoremap <F5> <Cmd>tabnext<CR>
2224  END
2225
2226  call writefile(lines, 'Xtest', 'D')
2227  let buf = RunVimInTerminal('-S Xtest', {})
2228
2229  call term_sendkeys(buf, ":tabe\<CR>")
2230  call TermWait(buf, 50)
2231  call term_sendkeys(buf, "Aaa aaa \<C-N>")
2232  call VerifyScreenDump(buf, 'Test_tabnext_clear_pum_01', {})
2233  call term_sendkeys(buf, "\<F5>")
2234  call TermWait(buf, 50)
2235  call VerifyScreenDump(buf, 'Test_tabnext_clear_pum_02', {})
2236  call term_sendkeys(buf, "\<ESC>:tabclose!\<CR>")
2237
2238  call term_sendkeys(buf, ":vnew win_b\<CR>")
2239  call TermWait(buf, 50)
2240  call term_sendkeys(buf, "Abb bbb \<C-N>")
2241  call VerifyScreenDump(buf, 'Test_switchwin_clear_pum_01', {})
2242  call term_sendkeys(buf, "\<F4>")
2243  call TermWait(buf, 50)
2244  call VerifyScreenDump(buf, 'Test_switchwin_clear_pum_02', {})
2245
2246  call StopVimInTerminal(buf)
2247endfunc
2248
2249func Test_pum_position_when_wrap()
2250  CheckScreendump
2251  let lines =<< trim END
2252    func Omni_test(findstart, base)
2253      if a:findstart
2254        return col(".")
2255      endif
2256      return ['foo', 'bar', 'foobar']
2257    endfunc
2258    set omnifunc=Omni_test
2259    set wrap
2260    set cot+=noinsert
2261  END
2262  call writefile(lines, 'Xtest', 'D')
2263  let buf = RunVimInTerminal('-S Xtest', #{rows: 15, cols: 25})
2264
2265  let long_text = repeat('abcde ', 20)
2266  call term_sendkeys(buf, "i" .. long_text)
2267  call TermWait(buf, 50)
2268  call term_sendkeys(buf, "\<ESC>")
2269  call TermWait(buf, 50)
2270
2271  call term_sendkeys(buf, "5|")
2272  call TermWait(buf, 50)
2273  call term_sendkeys(buf, "a\<C-X>\<C-O>")
2274  call TermWait(buf, 100)
2275  call VerifyScreenDump(buf, 'Test_pum_wrap_line1', {})
2276  call term_sendkeys(buf, "\<ESC>")
2277  call TermWait(buf, 50)
2278
2279  call term_sendkeys(buf, "30|")
2280  call TermWait(buf, 50)
2281  call term_sendkeys(buf, "a\<C-X>\<C-O>")
2282  call TermWait(buf, 100)
2283  call VerifyScreenDump(buf, 'Test_pum_wrap_line2', {})
2284  call term_sendkeys(buf, "\<ESC>")
2285  call TermWait(buf, 50)
2286
2287  call term_sendkeys(buf, "55|")
2288  call TermWait(buf, 50)
2289  call term_sendkeys(buf, "a\<C-X>\<C-O>")
2290  call TermWait(buf, 100)
2291  call VerifyScreenDump(buf, 'Test_pum_wrap_line3', {})
2292  call term_sendkeys(buf, "\<C-E>\<ESC>")
2293  call TermWait(buf, 50)
2294
2295  call term_sendkeys(buf, "85|")
2296  call TermWait(buf, 50)
2297  call term_sendkeys(buf, "a\<C-X>\<C-O>")
2298  call TermWait(buf, 100)
2299  call VerifyScreenDump(buf, 'Test_pum_wrap_line4', {})
2300  call term_sendkeys(buf, "\<C-E>\<ESC>")
2301  call TermWait(buf, 100)
2302
2303  call term_sendkeys(buf, "108|")
2304  call TermWait(buf, 50)
2305  call term_sendkeys(buf, "a\<C-X>\<C-O>")
2306  call TermWait(buf, 100)
2307  call VerifyScreenDump(buf, 'Test_pum_wrap_line5', {})
2308  call term_sendkeys(buf, "\<C-E>\<ESC>")
2309  call TermWait(buf, 100)
2310
2311  call 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()
2317  throw "Skipped: Nvim supports cmdwin freedom #40312"
2318  func! CompleteWithPreview(findstart, base)
2319    if a:findstart
2320      return getline('.')->strpart(0, col('.') - 1)
2321    endif
2322    return [#{word: 'echo', info: 'bar'}, #{word: 'echomsg', info: 'baz'}]
2323  endfunc
2324  set omnifunc=CompleteWithPreview
2325  call feedkeys("q:if\<C-X>\<C-O>\<C-N>\<ESC>\<CR>", 'tx!')
2326  set omnifunc&
2327endfunc
2328
2329" vim: shiftwidth=2 sts=2 expandtab