robin/laufey

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

Justin M. KeyesMerge #41114 from epithet/default-ruler-as-expressiondab5fab948

master
28.1 KiB716 linesraw
1local n = require('test.functional.testnvim')()
2local t = require('test.testutil')
3local Screen = require('test.functional.ui.screen')
4
5local describe, it, before_each = t.describe, t.it, t.before_each
6local clear = n.clear
7local command = n.command
8local feed = n.feed
9local feed_command = n.feed_command
10local exec = n.exec
11local api = n.api
12
13describe('cmdline', function()
14  before_each(clear)
15
16  -- oldtest: Test_cmdlineclear_tabenter()
17  it('is cleared when switching tabs', function()
18    local screen = Screen.new(30, 10)
19
20    feed_command([[call setline(1, range(30))]])
21    screen:expect([[
22      ^0                             |
23      1                             |
24      2                             |
25      3                             |
26      4                             |
27      5                             |
28      6                             |
29      7                             |
30      8                             |
31      :call setline(1, range(30))   |
32    ]])
33
34    feed [[:tabnew<cr>]]
35    screen:expect {
36      grid = [[
37      {24: + [No Name] }{5: [No Name] }{2:     }{24:X}|
38      ^                              |
39      {1:~                             }|*7
40      :tabnew                       |
41    ]],
42    }
43
44    feed [[<C-w>-<C-w>-]]
45    screen:expect {
46      grid = [[
47      {24: + [No Name] }{5: [No Name] }{2:     }{24:X}|
48      ^                              |
49      {1:~                             }|*5
50                                    |*3
51    ]],
52    }
53
54    feed [[gt]]
55    screen:expect {
56      grid = [[
57      {5: + [No Name] }{24: [No Name] }{2:     }{24:X}|
58      ^0                             |
59      1                             |
60      2                             |
61      3                             |
62      4                             |
63      5                             |
64      6                             |
65      7                             |
66                                    |
67    ]],
68    }
69
70    feed [[gt]]
71    screen:expect([[
72      {24: + [No Name] }{5: [No Name] }{2:     }{24:X}|
73      ^                              |
74      {1:~                             }|*5
75                                    |*3
76    ]])
77  end)
78
79  -- oldtest: Test_verbose_option()
80  it('prints every executed Ex command if verbose >= 16', function()
81    local screen = Screen.new(60, 12)
82    exec([[
83      command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
84      call feedkeys("\r", 't') " for the hit-enter prompt
85      set verbose=20
86    ]])
87    feed_command('DoSomething')
88    screen:expect([[
89                                                                  |
90      {1:~                                                           }|*2
91      {3:                                                            }|
92      Executing: DoSomething                                      |
93      Executing: echo 'hello' |set ts=4 |let v = '123' |echo v    |
94      hello                                                       |
95      Executing: set ts=4 |let v = '123' |echo v                  |
96      Executing: let v = '123' |echo v                            |
97      Executing: echo v                                           |
98      123                                                         |
99      {6:Press ENTER or type command to continue}^                     |
100    ]])
101  end)
102
103  -- oldtest: Test_cmdline_redraw_tabline()
104  it('tabline is redrawn on entering cmdline', function()
105    local screen = Screen.new(30, 6)
106    exec([[
107      set showtabline=2
108      autocmd CmdlineEnter * set tabline=foo
109    ]])
110    feed(':')
111    screen:expect([[
112      {2:foo                           }|
113                                    |
114      {1:~                             }|*3
115      :^                             |
116    ]])
117  end)
118
119  -- oldtest: Test_wildmenu_with_input_func()
120  it('wildmenu works with input() function', function()
121    local screen = Screen.new(60, 8)
122    screen:add_extra_attr_ids({
123      [100] = { background = Screen.colors.Yellow, foreground = Screen.colors.Black },
124    })
125
126    feed(":call input('Command? ', '', 'command')<CR>")
127    screen:expect([[
128                                                                  |
129      {1:~                                                           }|*6
130      Command? ^                                                   |
131    ]])
132    feed('ech<Tab>')
133    screen:expect([[
134                                                                  |
135      {1:~                                                           }|*5
136      {100:echo}{3:  echoerr  echohl  echomsg  echon                       }|
137      Command? echo^                                               |
138    ]])
139    feed('<Space>')
140    screen:expect([[
141                                                                  |
142      {1:~                                                           }|*6
143      Command? echo ^                                              |
144    ]])
145    feed('bufn<Tab>')
146    screen:expect([[
147                                                                  |
148      {1:~                                                           }|*5
149      {100:bufname(}{3:  bufnr(                                            }|
150      Command? echo bufname(^                                      |
151    ]])
152    feed('<CR>')
153
154    command('set wildoptions+=pum')
155
156    feed(":call input('Command? ', '', 'command')<CR>")
157    screen:expect([[
158                                                                  |
159      {1:~                                                           }|*6
160      Command? ^                                                   |
161    ]])
162    feed('ech<Tab>')
163    screen:expect([[
164                                                                  |
165      {1:~                                                           }|
166      {1:~       }{12: echo           }{1:                                    }|
167      {1:~       }{4: echoerr        }{1:                                    }|
168      {1:~       }{4: echohl         }{1:                                    }|
169      {1:~       }{4: echomsg        }{1:                                    }|
170      {1:~       }{4: echon          }{1:                                    }|
171      Command? echo^                                               |
172    ]])
173    feed('<Space>')
174    screen:expect([[
175                                                                  |
176      {1:~                                                           }|*6
177      Command? echo ^                                              |
178    ]])
179    feed('bufn<Tab>')
180    screen:expect([[
181                                                                  |
182      {1:~                                                           }|*4
183      {1:~            }{12: bufname(       }{1:                               }|
184      {1:~            }{4: bufnr(         }{1:                               }|
185      Command? echo bufname(^                                      |
186    ]])
187    feed('<CR>')
188  end)
189
190  -- oldtest: Test_redraw_in_autocmd()
191  it('cmdline cursor position is correct after :redraw with cmdheight=2', function()
192    local screen = Screen.new(30, 6)
193    exec([[
194      set cmdheight=2
195      autocmd CmdlineChanged * redraw
196    ]])
197    feed(':for i in range(3)<CR>')
198    screen:expect([[
199                                    |
200      {1:~                             }|*3
201      :for i in range(3)            |
202      :  ^                           |
203    ]])
204    feed(':let i =')
205    -- Note: this may still be considered broken, ref #18140
206    screen:expect([[
207                                    |
208      {1:~                             }|*3
209      :  :let i =^                   |
210                                    |
211    ]])
212  end)
213
214  -- oldtest: Test_changing_cmdheight()
215  it("changing 'cmdheight'", function()
216    local screen = Screen.new(60, 8)
217    exec([[
218      set cmdheight=1 laststatus=2
219      func EchoOne()
220        set laststatus=2 cmdheight=1
221        echo 'foo'
222        echo 'bar'
223        set cmdheight=2
224      endfunc
225      func EchoTwo()
226        set laststatus=2
227        set cmdheight=5
228        echo 'foo'
229        echo 'bar'
230        set cmdheight=1
231      endfunc
232    ]])
233
234    feed(':resize -3<CR>')
235    screen:expect([[
236      ^                                                            |
237      {1:~                                                           }|*2
238      {3:[No Name]                                                   }|
239                                                                  |*4
240    ]])
241
242    -- :resize now also changes 'cmdheight' accordingly
243    feed(':set cmdheight+=1<CR>')
244    screen:expect([[
245      ^                                                            |
246      {1:~                                                           }|
247      {3:[No Name]                                                   }|
248                                                                  |*5
249    ]])
250
251    -- using more space moves the status line up
252    feed(':set cmdheight+=1<CR>')
253    screen:expect([[
254      ^                                                            |
255      {3:[No Name]                                                   }|
256                                                                  |*6
257    ]])
258
259    -- reducing cmdheight moves status line down
260    feed(':set cmdheight-=3<CR>')
261    screen:expect([[
262      ^                                                            |
263      {1:~                                                           }|*3
264      {3:[No Name]                                                   }|
265                                                                  |*3
266    ]])
267
268    -- reducing window size and then setting cmdheight
269    feed(':resize -1<CR>')
270    feed(':set cmdheight=1<CR>')
271    screen:expect([[
272      ^                                                            |
273      {1:~                                                           }|*5
274      {3:[No Name]                                                   }|
275                                                                  |
276    ]])
277
278    -- setting 'cmdheight' works after outputting two messages
279    feed(':call EchoTwo()')
280    screen:expect([[
281                                                                  |
282      {1:~                                                           }|*5
283      {3:[No Name]                                                   }|
284      :call EchoTwo()^                                             |
285    ]])
286    feed('<CR>')
287    screen:expect([[
288      ^                                                            |
289      {1:~                                                           }|*5
290      {3:[No Name]                                                   }|
291                                                                  |
292    ]])
293
294    -- increasing 'cmdheight' doesn't clear the messages that need hit-enter
295    feed(':call EchoOne()<CR>')
296    screen:expect([[
297                                                                  |
298      {1:~                                                           }|*3
299      {3:                                                            }|
300      foo                                                         |
301      bar                                                         |
302      {6:Press ENTER or type command to continue}^                     |
303    ]])
304
305    -- window commands do not reduce 'cmdheight' to value lower than :set by user
306    feed('<CR>:wincmd _<CR>')
307    screen:expect([[
308      ^                                                            |
309      {1:~                                                           }|*4
310      {3:[No Name]                                                   }|
311      :wincmd _                                                   |
312                                                                  |
313    ]])
314  end)
315
316  -- oldtest: Test_cmdheight_tabline()
317  it("changing 'cmdheight' when there is a tabline", function()
318    local screen = Screen.new(60, 8)
319    api.nvim_set_option_value('laststatus', 2, {})
320    api.nvim_set_option_value('showtabline', 2, {})
321    api.nvim_set_option_value('cmdheight', 1, {})
322    screen:expect([[
323      {5: [No Name] }{2:                                                 }|
324      ^                                                            |
325      {1:~                                                           }|*4
326      {3:[No Name]                                                   }|
327                                                                  |
328    ]])
329  end)
330
331  -- oldtest: Test_wildmenu_with_pum_foldexpr()
332  it('pum when using &foldtext', function()
333    local screen = Screen.new(60, 10)
334    exec([[
335      call setline(1, ['folded one', 'folded two', 'some more text'])
336      func MyFoldText()
337        return 'foo'
338      endfunc
339      set foldtext=MyFoldText() wildoptions=pum
340      normal ggzfj
341    ]])
342    feed(':set<Tab>')
343    screen:expect([[
344      {13:foo·························································}|
345      some more text                                              |
346      {1:~                                                           }|*3
347      {12: set            }{1:                                            }|
348      {4: setfiletype    }{1:                                            }|
349      {4: setglobal      }{1:                                            }|
350      {4: setlocal       }{1:                                            }|
351      :set^                                                        |
352    ]])
353    feed('<Esc>')
354    screen:expect([[
355      {13:^foo·························································}|
356      some more text                                              |
357      {1:~                                                           }|*7
358                                                                  |
359    ]])
360  end)
361
362  -- oldtest: Test_rulerformat_position()
363  it("ruler has correct position with 'rulerformat' set", function()
364    local screen = Screen.new(20, 3)
365    api.nvim_set_option_value('ruler', true, {})
366    api.nvim_set_option_value('rulerformat', 'longish', {})
367    api.nvim_set_option_value('laststatus', 0, {})
368    api.nvim_set_option_value('winwidth', 1, {})
369    feed [[<C-W>v<C-W>|<C-W>p]]
370    screen:expect [[
371                        │^ |
372      {1:~                 }│{1:~}|
373                longish   |
374    ]]
375  end)
376
377  -- oldtest: Test_rulerformat_function()
378  it("'rulerformat' can use %!", function()
379    local screen = Screen.new(40, 2)
380    exec([[
381      func TestRulerFn()
382        return '10,20%=30%%'
383      endfunc
384    ]])
385    api.nvim_set_option_value('ruler', true, {})
386    api.nvim_set_option_value('rulerformat', '%!TestRulerFn()', {})
387    screen:expect([[
388      ^                                        |
389                            10,20          30%|
390    ]])
391  end)
392
393  -- oldtest: Test_search_wildmenu_screendump()
394  it('wildmenu for search completion', function()
395    local screen = Screen.new(60, 10)
396    screen:add_extra_attr_ids({
397      [100] = { background = Screen.colors.Yellow, foreground = Screen.colors.Black },
398    })
399    exec([[
400      set wildmenu wildcharm=<f5> wildoptions-=pum
401      call setline(1, ['the', 'these', 'the', 'foobar', 'thethe', 'thethere'])
402    ]])
403
404    -- Pattern has newline at EOF
405    feed('gg2j/e\\n<f5>')
406    screen:expect([[
407      the                                                         |
408      these                                                       |
409      the                                                         |
410      foobar                                                      |
411      thethe                                                      |
412      thethere                                                    |
413      {1:~                                                           }|*2
414      {100:e\nfoobar}{3:  e\nthethere  e\nthese  e\nthe                    }|
415      /e\nfoobar^                                                  |
416    ]])
417
418    -- longest:full
419    feed('<esc>')
420    command('set wim=longest,full')
421    feed('gg/t<f5>')
422    screen:expect([[
423      the                                                         |
424      these                                                       |
425      the                                                         |
426      foobar                                                      |
427      thethe                                                      |
428      thethere                                                    |
429      {1:~                                                           }|*3
430      /the^                                                        |
431    ]])
432
433    -- list:full
434    feed('<esc>')
435    command('set wim=list,full')
436    feed('gg/t<f5>')
437    screen:expect([[
438      {10:t}he                                                         |
439      {10:t}hese                                                       |
440      {10:t}he                                                         |
441      foobar                                                      |
442      {10:t}he{10:t}he                                                      |
443      {10:t}he{10:t}here                                                    |
444      {3:                                                            }|
445      /t                                                          |
446      these     the       thethe    thethere  there               |
447      /t^                                                          |
448    ]])
449
450    -- noselect:full
451    feed('<esc>')
452    command('set wim=noselect,full')
453    feed('gg/t<f5>')
454    screen:expect([[
455      the                                                         |
456      these                                                       |
457      the                                                         |
458      foobar                                                      |
459      thethe                                                      |
460      thethere                                                    |
461      {1:~                                                           }|*2
462      {3:these  the  thethe  thethere  there                         }|
463      /t^                                                          |
464    ]])
465
466    -- Multiline
467    feed('<esc>gg/t.*\\n.*\\n.<tab>')
468    screen:expect([[
469      the                                                         |
470      these                                                       |
471      the                                                         |
472      foobar                                                      |
473      thethe                                                      |
474      thethere                                                    |
475      {1:~                                                           }|*2
476      {3:t.*\n.*\n.oobar  t.*\n.*\n.hethe  t.*\n.*\n.he              }|
477      /t.*\n.*\n.^                                                 |
478    ]])
479
480    -- 'incsearch' is redrawn after accepting completion
481    feed('<esc>')
482    command('set wim=full')
483    command('set incsearch hlsearch')
484    feed('/th')
485    screen:expect([[
486      {10:th}e                                                         |
487      {2:th}ese                                                       |
488      {10:th}e                                                         |
489      foobar                                                      |
490      {10:th}e{10:th}e                                                      |
491      {10:th}e{10:th}ere                                                    |
492      {1:~                                                           }|*3
493      /th^                                                         |
494    ]])
495    feed('<f5>')
496    screen:expect([[
497      {10:th}e                                                         |
498      {2:th}ese                                                       |
499      {10:th}e                                                         |
500      foobar                                                      |
501      {10:th}e{10:th}e                                                      |
502      {10:th}e{10:th}ere                                                    |
503      {1:~                                                           }|*2
504      {100:these}{3:  the  thethe  thethere  there                         }|
505      /these^                                                      |
506    ]])
507    feed('<c-n><c-y>')
508    screen:expect([[
509      {10:the}                                                         |
510      {2:the}se                                                       |
511      {10:the}                                                         |
512      foobar                                                      |
513      {10:thethe}                                                      |
514      {10:thethe}re                                                    |
515      {1:~                                                           }|*3
516      /the^                                                        |
517    ]])
518
519    -- 'incsearch' highlight is restored after dismissing popup (Ctrl_E)
520    feed('<esc>')
521    command('set wop=pum is nohls')
522    feed('gg/th<tab><c-e>')
523    screen:expect([[
524      the                                                         |
525      {2:th}ese                                                       |
526      the                                                         |
527      foobar                                                      |
528      thethe                                                      |
529      thethere                                                    |
530      {1:~                                                           }|*3
531      /th^                                                         |
532    ]])
533
534    feed('<esc>')
535  end)
536
537  -- oldtest: Test_search_wildmenu_iminsert()
538  it('search wildmenu pum with iminsert=1', function()
539    local screen = Screen.new(65, 12)
540    exec([[
541      set wop=pum imi=1
542      setlocal iskeyword=!-~,192-255
543      call setline(1, [
544            \ "global toggle global-local global/local glyphs toggles English",
545            \ "accordingly. toggled accordingly single-byte",
546            \ ])
547      call cursor(2, 42)
548    ]])
549    feed('/gl<Tab>')
550    screen:expect([[
551      {12: global         }obal-local global/local glyphs toggles English   |
552      {4: gle            }gled accordingly single-byte                     |
553      {4: global-local   }{1:                                                 }|
554      {4: global/local   }{1:                                                 }|
555      {4: glyphs         }{1:                                                 }|
556      {4: gles           }{1:                                                 }|
557      {4: glish          }{1:                                                 }|
558      {4: gly.           }{1:                                                 }|
559      {4: gled           }{1:                                                 }|
560      {4: gly            }{1:                                                 }|
561      {4: gle-byte       }{1:                                                 }|
562      /global^                                                          |
563    ]])
564  end)
565
566  -- oldtest: Test_wildtrigger_update_screen()
567  it('pum by wildtrigger() avoids flicker', function()
568    local screen = Screen.new(40, 10)
569    exec([[
570      command! -nargs=* -complete=customlist,TestFn TestCmd echo
571      func TestFn(cmdarg, b, c)
572        if a:cmdarg == 'ax'
573          return []
574        else
575          return map(range(1, 5), 'printf("abc%d", v:val)')
576        endif
577      endfunc
578      set wildmode=noselect,full
579      set wildoptions=pum
580      set wildmenu
581      cnoremap <F8> <C-R>=wildtrigger()[-1]<CR>
582    ]])
583
584    feed(':TestCmd a<F8>')
585    local s1 = [[
586                                              |
587      {1:~                                       }|*3
588      {1:~       }{4: abc1           }{1:                }|
589      {1:~       }{4: abc2           }{1:                }|
590      {1:~       }{4: abc3           }{1:                }|
591      {1:~       }{4: abc4           }{1:                }|
592      {1:~       }{4: abc5           }{1:                }|
593      :TestCmd a^                              |
594    ]]
595    screen:expect(s1)
596
597    -- Typing a character when pum is open does not close the pum window
598    -- This is needed to prevent pum window from flickering during
599    -- ':h cmdline-autocompletion'.
600    feed('x')
601    local s2 = [[
602                                              |
603      {1:~                                       }|*3
604      {1:~       }{4: abc1           }{1:                }|
605      {1:~       }{4: abc2           }{1:                }|
606      {1:~       }{4: abc3           }{1:                }|
607      {1:~       }{4: abc4           }{1:                }|
608      {1:~       }{4: abc5           }{1:                }|
609      :TestCmd ax^                             |
610    ]]
611    screen:expect(s2)
612
613    -- pum is closed when no completion candidates are available
614    feed('<F8>')
615    local s3 = [[
616                                              |
617      {1:~                                       }|*8
618      :TestCmd ax^                             |
619    ]]
620    screen:expect(s3)
621
622    feed('<BS><F8>')
623    screen:expect(s1)
624
625    feed('x')
626    screen:expect(s2)
627
628    -- pum is closed when leaving cmdline mode
629    feed('<Esc>')
630    screen:expect([[
631      ^                                        |
632      {1:~                                       }|*8
633                                              |
634    ]])
635
636    feed(':TestCmd a<F8>')
637    screen:expect(s1)
638    command('redraw')
639    screen:expect_unchanged()
640    feed('x')
641    screen:expect(s2)
642    -- outdated pum is closed by :redraw #36808
643    command('redraw')
644    screen:expect(s3)
645  end)
646
647  -- oldtest: Test_long_line_noselect()
648  it("long line is shown properly with noselect in 'wildmode'", function()
649    local screen = Screen.new(60, 8)
650    exec([[
651      set wildmenu wildoptions=pum wildmode=noselect,full
652      command -nargs=1 -complete=custom,Entries DoubleEntry echo
653      func Entries(a, b, c)
654        return 'loooooooooooooooong quite loooooooooooong, really loooooooooooong, probably too looooooooooooooooooooooooooong entry'
655      endfunc
656    ]])
657
658    feed(':DoubleEntry <Tab>')
659    screen:expect([[
660                                                                  |
661      {1:~                                                           }|*5
662      {1:~           }{4: loooooooooooooooong quite loooooooooooong, rea>}|
663      :DoubleEntry ^                                               |
664    ]])
665
666    feed('<C-N>')
667    screen:expect([[
668                                                                  |
669      {1:~                                                           }|*3
670      {3:                                                            }|
671      :DoubleEntry loooooooooooooooong quite loooooooooooong, real|
672      ly loooooooo{12: loooooooooooooooong quite loooooooooooong, rea>}|
673      ong entry^                                                   |
674    ]])
675
676    feed('<C-N>')
677    screen:expect([[
678                                                                  |
679      {1:~                                                           }|*3
680      {3:            }{4: loooooooooooooooong quite loooooooooooong, rea>}|
681      :DoubleEntry ^                                               |
682                                                                  |*2
683    ]])
684
685    feed('<Esc>')
686  end)
687
688  -- oldtest: Test_update_screen_after_wildtrigger()
689  it('pum is dismissed after wildtrigger() and whitespace', function()
690    local screen = Screen.new(40, 10)
691    exec([[
692      set wildmode=noselect:lastused,full wildmenu wildoptions=pum
693      autocmd CmdlineChanged : if getcmdcompltype() != 'shellcmd' | call wildtrigger() | endif
694    ]])
695
696    feed(':term')
697    screen:expect([[
698                                              |
699      {1:~                                       }|*7
700      {4: terminal       }{1:                        }|
701      :term^                                   |
702    ]])
703    feed(' ')
704    screen:expect([[
705                                              |
706      {1:~                                       }|*8
707      :term ^                                  |
708    ]])
709    feed('foo')
710    screen:expect([[
711                                              |
712      {1:~                                       }|*8
713      :term foo^                               |
714    ]])
715  end)
716end)