robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
20.7 KiB733 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3local Screen = require('test.functional.ui.screen')
4
5local describe, it, before_each, after_each = t.describe, t.it, t.before_each, t.after_each
6local clear, feed, command = n.clear, n.feed, n.command
7local fn = n.fn
8local api = n.api
9local eq = t.eq
10local eval = n.eval
11local retry = t.retry
12local testprg = n.testprg
13local is_os = t.is_os
14
15describe("'wildmenu'", function()
16  local screen
17  before_each(function()
18    clear()
19    screen = Screen.new(25, 5)
20    screen:add_extra_attr_ids {
21      [100] = { background = Screen.colors.Yellow1, foreground = Screen.colors.Black },
22    }
23  end)
24
25  -- oldtest: Test_wildmenu_screendump()
26  it('works', function()
27    screen:add_extra_attr_ids {
28      [100] = { background = Screen.colors.Yellow1, foreground = Screen.colors.Black },
29    }
30    -- Test simple wildmenu
31    feed(':sign <Tab>')
32    screen:expect {
33      grid = [[
34                               |
35      {1:~                        }|*2
36      {100:define}{3:  jump  list  >    }|
37      :sign define^             |
38    ]],
39    }
40
41    feed('<Tab>')
42    screen:expect {
43      grid = [[
44                               |
45      {1:~                        }|*2
46      {3:define  }{100:jump}{3:  list  >    }|
47      :sign jump^               |
48    ]],
49    }
50
51    feed('<Tab>')
52    screen:expect {
53      grid = [[
54                               |
55      {1:~                        }|*2
56      {3:define  jump  }{100:list}{3:  >    }|
57      :sign list^               |
58    ]],
59    }
60
61    -- Looped back to the original value
62    feed('<Tab><Tab><Tab><Tab>')
63    screen:expect {
64      grid = [[
65                               |
66      {1:~                        }|*2
67      {3:define  jump  list  >    }|
68      :sign ^                   |
69    ]],
70    }
71
72    -- Test that the wild menu is cleared properly
73    feed('<Space>')
74    screen:expect {
75      grid = [[
76                               |
77      {1:~                        }|*3
78      :sign  ^                  |
79    ]],
80    }
81
82    -- Test that a different wildchar still works
83    feed('<Esc>')
84    command('set wildchar=<Esc>')
85    feed(':sign <Esc>')
86    screen:expect {
87      grid = [[
88                               |
89      {1:~                        }|*2
90      {100:define}{3:  jump  list  >    }|
91      :sign define^             |
92    ]],
93    }
94
95    -- Double-<Esc> is a hard-coded method to escape while wildchar=<Esc>. Make
96    -- sure clean up is properly done in edge case like this.
97    feed('<Esc>')
98    screen:expect {
99      grid = [[
100      ^                         |
101      {1:~                        }|*3
102                               |
103    ]],
104    }
105  end)
106
107  it('C-E to cancel wildmenu completion restore original input', function()
108    feed(':sign <tab>')
109    screen:expect([[
110                               |
111      {1:~                        }|*2
112      {100:define}{3:  jump  list  >    }|
113      :sign define^             |
114    ]])
115    feed('<C-E>')
116    screen:expect([[
117                               |
118      {1:~                        }|*3
119      :sign ^                   |
120    ]])
121  end)
122
123  it('C-Y to apply selection and end wildmenu completion', function()
124    feed(':sign <tab>')
125    screen:expect([[
126                               |
127      {1:~                        }|*2
128      {100:define}{3:  jump  list  >    }|
129      :sign define^             |
130    ]])
131    feed('<tab><C-Y>')
132    screen:expect([[
133                               |
134      {1:~                        }|*3
135      :sign jump^               |
136    ]])
137  end)
138
139  it(':sign <tab> shows wildmenu completions', function()
140    command('set wildmenu wildmode=full')
141    feed(':sign <tab>')
142    screen:expect([[
143                               |
144      {1:~                        }|*2
145      {100:define}{3:  jump  list  >    }|
146      :sign define^             |
147    ]])
148  end)
149
150  it(':sign <tab> <space> hides wildmenu #8453', function()
151    command('set wildmode=full')
152    -- only a regression if status-line open
153    command('set laststatus=2')
154    command('set wildmenu')
155    feed(':sign <tab>')
156    screen:expect([[
157                               |
158      {1:~                        }|*2
159      {100:define}{3:  jump  list  >    }|
160      :sign define^             |
161    ]])
162    feed('<space>')
163    screen:expect([[
164                               |
165      {1:~                        }|*2
166      {3:[No Name]                }|
167      :sign define ^            |
168    ]])
169  end)
170
171  it('does not crash after cycling back to original text', function()
172    command('set wildmode=full')
173    feed(':j<Tab><Tab><Tab>')
174    screen:expect([[
175                               |
176      {1:~                        }|*2
177      {3:join  jumps              }|
178      :j^                       |
179    ]])
180    -- This would cause nvim to crash before #6650
181    feed('<BS><Tab>')
182    screen:expect([[
183                               |
184      {1:~                        }|*2
185      {100:!}{3:  #  &  <  =  >  @  >   }|
186      :!^                       |
187    ]])
188  end)
189
190  it('is preserved during :terminal activity', function()
191    command('set wildmenu wildmode=full')
192    command('set scrollback=4')
193    feed((':terminal "%s" REP 5000 !terminal_output!<cr>'):format(testprg('shell-test')))
194    feed('G') -- Follow :terminal output.
195    feed([[:sign <Tab>]]) -- Invoke wildmenu.
196    screen:add_extra_attr_ids {
197      [100] = { foreground = Screen.colors.Black, background = Screen.colors.Yellow },
198      [101] = {
199        bold = true,
200        foreground = Screen.colors.White,
201        background = Screen.colors.DarkGreen,
202      },
203    }
204    -- NB: in earlier versions terminal output was redrawn during cmdline mode.
205    -- For now just assert that the screen remains unchanged.
206    screen:expect { any = '{100:define}{101:  jump  list  >    }|\n:sign define^             |' }
207    screen:expect_unchanged()
208
209    -- cmdline CTRL-D display should also be preserved.
210    feed([[<C-U>]])
211    feed([[sign <C-D>]]) -- Invoke cmdline CTRL-D.
212    screen:expect {
213      grid = [[
214      :sign                    |
215      define    place          |
216      jump      undefine       |
217      list      unplace        |
218      :sign ^                   |
219    ]],
220    }
221    screen:expect_unchanged()
222
223    -- Exiting cmdline should show the buffer.
224    feed([[<C-\><C-N>]])
225    screen:expect { any = [[!terminal_output!]] }
226  end)
227
228  it('ignores :redrawstatus called from a timer #7108', function()
229    command('set wildmenu wildmode=full')
230    command([[call timer_start(10, {->execute('redrawstatus')}, {'repeat':-1})]])
231    feed([[<C-\><C-N>]])
232    feed([[:sign <Tab>]]) -- Invoke wildmenu.
233    screen:expect {
234      grid = [[
235                               |
236      {1:~                        }|*2
237      {100:define}{3:  jump  list  >    }|
238      :sign define^             |
239    ]],
240    }
241    screen:expect_unchanged()
242  end)
243
244  it('with laststatus=0, :vsplit, :term #2255', function()
245    if not is_os('win') then
246      command('set shell=sh') -- Need a predictable "$" prompt.
247      command('let $PS1 = "$"')
248    end
249    command('set laststatus=0')
250    command('vsplit')
251    command('term')
252
253    -- Check for a shell prompt to verify that the terminal loaded.
254    retry(nil, nil, function()
255      if is_os('win') then
256        eq('Microsoft', eval("matchstr(join(getline(1, '$')), 'Microsoft')"))
257      else
258        eq('$', eval([[matchstr(getline(1), '\$')]]))
259      end
260    end)
261
262    feed([[<C-\><C-N>]])
263    feed([[:<Tab>]]) -- Invoke wildmenu.
264    screen:add_extra_attr_ids {
265      [100] = { foreground = Screen.colors.Black, background = Screen.colors.Yellow },
266      [101] = {
267        bold = true,
268        foreground = Screen.colors.White,
269        background = Screen.colors.DarkGreen,
270      },
271    }
272    -- Check only the last 2 lines, because the shell output is
273    -- system-dependent.
274    screen:expect { any = '{100:!}{101:  #  &  <  =  >  @  >   }|\n:!^' }
275    -- Because this test verifies a _lack_ of activity, we must wait the full timeout.
276    -- So make it reasonable.
277    screen:expect_unchanged(false, 1000)
278  end)
279
280  it('wildmode=list,full and messages interaction #10092', function()
281    -- Need more than 5 rows, else tabline is covered and will be redrawn.
282    screen:try_resize(25, 7)
283
284    command('set wildmenu wildmode=list,full')
285    command('set showtabline=2')
286    feed(':set wildm<tab>')
287    screen:expect([[
288      {5: [No Name] }{2:              }|
289                               |
290      {1:~                        }|
291      {3:                         }|
292      :set wildm               |
293      wildmenu  wildmode       |
294      :set wildm^               |
295    ]])
296    feed('<tab>') -- trigger wildmode full
297    screen:expect([[
298      {5: [No Name] }{2:              }|
299                               |
300      {3:                         }|
301      :set wildm               |
302      wildmenu  wildmode       |
303      {100:wildmenu}{3:  wildmode       }|
304      :set wildmenu^            |
305    ]])
306    feed('<Esc>')
307    screen:expect([[
308      {5: [No Name] }{2:              }|
309      ^                         |
310      {1:~                        }|*4
311                               |
312    ]])
313  end)
314
315  it('wildmode=longest,list', function()
316    -- Need more than 5 rows, else tabline is covered and will be redrawn.
317    screen:try_resize(25, 7)
318
319    command('set wildmenu wildmode=longest,list')
320
321    -- give wildmode-longest something to expand to
322    feed(':sign u<tab>')
323    screen:expect([[
324                               |
325      {1:~                        }|*5
326      :sign un^                 |
327    ]])
328    feed('<tab>') -- trigger wildmode list
329    screen:expect([[
330                               |
331      {1:~                        }|*2
332      {3:                         }|
333      :sign un                 |
334      undefine  unplace        |
335      :sign un^                 |
336    ]])
337    feed('<Esc>')
338    screen:expect([[
339      ^                         |
340      {1:~                        }|*5
341                               |
342    ]])
343
344    -- give wildmode-longest something it cannot expand, use list
345    feed(':sign un<tab>')
346    screen:expect([[
347                               |
348      {1:~                        }|*2
349      {3:                         }|
350      :sign un                 |
351      undefine  unplace        |
352      :sign un^                 |
353    ]])
354    feed('<tab>')
355    screen:expect_unchanged()
356    feed('<Esc>')
357    screen:expect([[
358      ^                         |
359      {1:~                        }|*5
360                               |
361    ]])
362  end)
363
364  it('wildmode=list,longest', function()
365    -- Need more than 5 rows, else tabline is covered and will be redrawn.
366    screen:try_resize(25, 7)
367
368    command('set wildmenu wildmode=list,longest')
369    feed(':sign u<tab>')
370    screen:expect([[
371                               |
372      {1:~                        }|*2
373      {3:                         }|
374      :sign u                  |
375      undefine  unplace        |
376      :sign u^                  |
377    ]])
378    feed('<tab>') -- trigger wildmode longest
379    screen:expect([[
380                               |
381      {1:~                        }|*2
382      {3:                         }|
383      :sign u                  |
384      undefine  unplace        |
385      :sign un^                 |
386    ]])
387    feed('<Esc>')
388    screen:expect([[
389      ^                         |
390      {1:~                        }|*5
391                               |
392    ]])
393  end)
394
395  it('multiple <C-D> renders correctly', function()
396    screen:try_resize(25, 7)
397
398    command('set laststatus=2')
399    feed(':set wildm')
400    feed('<c-d>')
401    screen:expect([[
402                               |
403      {1:~                        }|*2
404      {3:                         }|
405      :set wildm               |
406      wildmenu  wildmode       |
407      :set wildm^               |
408    ]])
409    feed('<c-d>')
410    screen:expect([[
411                               |
412      {3:                         }|
413      :set wildm               |
414      wildmenu  wildmode       |
415      :set wildm               |
416      wildmenu  wildmode       |
417      :set wildm^               |
418    ]])
419    feed('<Esc>')
420    screen:expect([[
421      ^                         |
422      {1:~                        }|*4
423      {3:[No Name]                }|
424                               |
425    ]])
426  end)
427
428  it("<C-D> doesn't make statuslines disappear with 'nowildmenu' #36053", function()
429    screen:try_resize(60, 10)
430    command('set laststatus=2 nowildmenu')
431    feed(':sign <C-D>')
432    screen:expect([[
433                                                                  |
434      {1:~                                                           }|*5
435      {3:                                                            }|
436      :sign                                                       |
437      define    jump      list      place     undefine  unplace   |
438      :sign ^                                                      |
439    ]])
440    feed('<Esc>')
441    screen:expect([[
442      ^                                                            |
443      {1:~                                                           }|*7
444      {3:[No Name]                                                   }|
445                                                                  |
446    ]])
447    command('mode')
448    screen:expect_unchanged()
449    feed('ifoobar<Esc>')
450    screen:expect([[
451      fooba^r                                                      |
452      {1:~                                                           }|*7
453      {3:[No Name] [+]                                               }|
454                                                                  |
455    ]])
456  end)
457
458  it('works with c_CTRL_Z standard mapping', function()
459    screen:add_extra_attr_ids {
460      [100] = { background = Screen.colors.Yellow1, foreground = Screen.colors.Black },
461    }
462
463    -- Wildcharm? where we are going we aint't no need no wildcharm.
464    eq(0, api.nvim_get_option_value('wildcharm', {}))
465    -- Don't mess the defaults yet (neovim is about backwards compatibility)
466    eq(9, api.nvim_get_option_value('wildchar', {}))
467    -- Lol what is cnoremap? Some say it can define mappings.
468    command 'set wildchar=0'
469    eq(0, api.nvim_get_option_value('wildchar', {}))
470
471    command 'cnoremap <f2> <c-z>'
472    feed(':syntax <f2>')
473    screen:expect {
474      grid = [[
475                               |
476      {1:~                        }|*2
477      {100:case}{3:  clear  cluster  >  }|
478      :syntax case^             |
479    ]],
480    }
481    feed '<esc>'
482
483    command 'set wildmode=longest:full,full'
484    -- this will get cleaner once we have native lua expr mappings:
485    command [[cnoremap <expr> <tab> luaeval("not rawset(_G, 'coin', not coin).coin") ? "<c-z>" : "c"]]
486
487    feed ':syntax <tab>'
488    screen:expect {
489      grid = [[
490                               |
491      {1:~                        }|*3
492      :syntax c^                |
493    ]],
494    }
495
496    feed '<tab>'
497    screen:expect {
498      grid = [[
499                               |
500      {1:~                        }|*2
501      {3:case  clear  cluster  >  }|
502      :syntax c^                |
503    ]],
504    }
505
506    feed '<tab>'
507    screen:expect {
508      grid = [[
509                               |
510      {1:~                        }|*3
511      :syntax cc^               |
512    ]],
513    }
514  end)
515end)
516
517describe('command line completion', function()
518  local screen
519  before_each(function()
520    clear()
521    screen = Screen.new(40, 5)
522    screen:add_extra_attr_ids {
523      [100] = { background = Screen.colors.Yellow1, foreground = Screen.colors.Black },
524    }
525  end)
526  after_each(function()
527    os.remove('Xtest-functional-viml-compl-dir')
528  end)
529
530  it('lists directories with empty PATH', function()
531    local tmp = fn.tempname()
532    command('e ' .. tmp)
533    command('cd %:h')
534    command("call mkdir('Xtest-functional-viml-compl-dir')")
535    command('let $PATH=""')
536    feed(':!<tab><bs>')
537    screen:expect([[
538                                              |
539      {1:~                                       }|*3
540      :!Xtest-functional-viml-compl-dir^       |
541    ]])
542  end)
543
544  it('completes env var names #9681', function()
545    command('let $XTEST_1 = "foo" | let $XTEST_2 = "bar"')
546    command('set wildmenu wildmode=full')
547    feed(':!echo $XTEST_<tab>')
548    screen:expect([[
549                                              |
550      {1:~                                       }|*2
551      {100:XTEST_1}{3:  XTEST_2                        }|
552      :!echo $XTEST_1^                         |
553    ]])
554  end)
555
556  it('completes (multibyte) env var names #9655', function()
557    clear({ env = {
558      ['XTEST_1AaあB'] = 'foo',
559      ['XTEST_2'] = 'bar',
560    } })
561    screen:attach()
562    command('set wildmenu wildmode=full')
563    feed(':!echo $XTEST_<tab>')
564    screen:expect([[
565                                              |
566      {1:~                                       }|*2
567      {100:XTEST_1AaあB}{3:  XTEST_2                   }|
568      :!echo $XTEST_1AaあB^                    |
569    ]])
570  end)
571
572  it('does not leak memory with <S-Tab> with wildmenu and only one match #19874', function()
573    api.nvim_set_option_value('wildmenu', true, {})
574    api.nvim_set_option_value('wildmode', 'full', {})
575    api.nvim_set_option_value('wildoptions', 'pum', {})
576
577    feed(':sign unpla<S-Tab>')
578    screen:expect([[
579                                              |
580      {1:~                                       }|*3
581      :sign unplace^                           |
582    ]])
583
584    feed('<Space>buff<Tab>')
585    screen:expect([[
586                                              |
587      {1:~                                       }|*3
588      :sign unplace buffer=^                   |
589    ]])
590  end)
591
592  it('does not show matches with <S-Tab> without wildmenu with wildmode=full', function()
593    api.nvim_set_option_value('wildmenu', false, {})
594    api.nvim_set_option_value('wildmode', 'full', {})
595
596    feed(':sign <S-Tab>')
597    screen:expect([[
598                                              |
599      {1:~                                       }|*3
600      :sign unplace^                           |
601    ]])
602  end)
603
604  it('shows matches with <S-Tab> without wildmenu with wildmode=list', function()
605    api.nvim_set_option_value('wildmenu', false, {})
606    api.nvim_set_option_value('wildmode', 'list', {})
607
608    feed(':sign <S-Tab>')
609    screen:expect([[
610      {3:                                        }|
611      :sign define                            |
612      define    list      undefine            |
613      jump      place     unplace             |
614      :sign unplace^                           |
615    ]])
616  end)
617end)
618
619describe('ui/ext_wildmenu', function()
620  local screen
621
622  before_each(function()
623    clear()
624    screen = Screen.new(25, 5, { rgb = true, ext_wildmenu = true })
625  end)
626
627  local function test_ext_wildmenu_sign_cmd()
628    local expected = {
629      'define',
630      'jump',
631      'list',
632      'place',
633      'undefine',
634      'unplace',
635    }
636
637    command('set wildmode=full')
638    command('set wildmenu')
639    feed(':sign <tab>')
640    screen:expect {
641      grid = [[
642                               |
643      {1:~                        }|*3
644      :sign define^             |
645    ]],
646      wildmenu_items = expected,
647      wildmenu_pos = 0,
648    }
649
650    feed('<tab>')
651    screen:expect {
652      grid = [[
653                               |
654      {1:~                        }|*3
655      :sign jump^               |
656    ]],
657      wildmenu_items = expected,
658      wildmenu_pos = 1,
659    }
660
661    feed('<left><left>')
662    screen:expect {
663      grid = [[
664                               |
665      {1:~                        }|*3
666      :sign ^                   |
667    ]],
668      wildmenu_items = expected,
669      wildmenu_pos = -1,
670    }
671
672    feed('<right>')
673    screen:expect {
674      grid = [[
675                               |
676      {1:~                        }|*3
677      :sign define^             |
678    ]],
679      wildmenu_items = expected,
680      wildmenu_pos = 0,
681    }
682
683    feed('a')
684    screen:expect([[
685                               |
686      {1:~                        }|*3
687      :sign definea^            |
688    ]])
689
690    feed('<Esc>')
691    command('set wildmode=longest,full')
692    feed(':sign u<tab>')
693    screen:expect([[
694                               |
695      {1:~                        }|*3
696      :sign un^                 |
697    ]])
698
699    feed('<tab>')
700    local s_undefine_unplace_0 = {
701      grid = [[
702                               |
703      {1:~                        }|*3
704      :sign undefine^           |
705    ]],
706      wildmenu_items = { 'undefine', 'unplace' },
707      wildmenu_pos = 0,
708    }
709    screen:expect(s_undefine_unplace_0)
710
711    feed('<Esc>')
712    screen:expect([[
713      ^                         |
714      {1:~                        }|*3
715                               |
716    ]])
717
718    feed(':sign un<tab>')
719    screen:expect(s_undefine_unplace_0)
720  end
721
722  describe('works with :sign <tab>', function()
723    it('with wildoptions=pum', function()
724      command('set wildoptions=pum')
725      test_ext_wildmenu_sign_cmd()
726    end)
727
728    it('with wildoptions=', function()
729      command('set wildoptions=')
730      test_ext_wildmenu_sign_cmd()
731    end)
732  end)
733end)