robin/laufey

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

robinmerge: 1dc9728daa1d8a2702

master
45.5 KiB957 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, finally = t.describe, t.it, t.before_each, t.finally
6local clear = n.clear
7local command = n.command
8local exec = n.exec
9local feed = n.feed
10local api = n.api
11local fn = n.fn
12local nvim_dir = n.nvim_dir
13local assert_alive = n.assert_alive
14
15before_each(clear)
16
17describe('messages', function()
18  local screen
19
20  -- oldtest: Test_warning_scroll()
21  it('a warning causes scrolling if and only if it has a stacktrace', function()
22    t.skip(t.is_arch('s390x'), 'timing-sensitive test unreliable on s390x')
23    screen = Screen.new(75, 6)
24
25    -- When the warning comes from a script, messages are scrolled so that the
26    -- stacktrace is visible.
27    -- It is a bit hard to assert the screen when sourcing a script, so skip this part.
28
29    -- When the warning does not come from a script, messages are not scrolled.
30    command('enew')
31    command('set readonly')
32    feed('u')
33    screen:expect({
34      grid = [[
35                                                                                 |
36      {1:~                                                                          }|*4
37      {19:W10: Warning: Changing a readonly file}^                                     |
38    ]],
39      timeout = 500,
40    })
41    screen:expect([[
42      ^                                                                           |
43      {1:~                                                                          }|*4
44      Already at oldest change                                                   |
45    ]])
46  end)
47
48  -- oldtest: Test_message_not_cleared_after_mode()
49  it('clearing mode does not remove message', function()
50    screen = Screen.new(60, 10)
51    exec([[
52      nmap <silent> gx :call DebugSilent('normal')<CR>
53      vmap <silent> gx :call DebugSilent('visual')<CR>
54      function DebugSilent(arg)
55          echomsg "from DebugSilent" a:arg
56      endfunction
57      set showmode
58      set cmdheight=1
59      call setline(1, ['one', 'NoSuchFile', 'three'])
60    ]])
61
62    feed('gx')
63    screen:expect([[
64      ^one                                                         |
65      NoSuchFile                                                  |
66      three                                                       |
67      {1:~                                                           }|*6
68      from DebugSilent normal                                     |
69    ]])
70
71    -- removing the mode message used to also clear the intended message
72    feed('vEgx')
73    screen:expect([[
74      ^one                                                         |
75      NoSuchFile                                                  |
76      three                                                       |
77      {1:~                                                           }|*6
78      from DebugSilent visual                                     |
79    ]])
80
81    -- removing the mode message used to also clear the error message
82    command('set cmdheight=2')
83    feed('2GvEgf')
84    screen:expect([[
85      one                                                         |
86      NoSuchFil^e                                                  |
87      three                                                       |
88      {1:~                                                           }|*5
89                                                                  |
90      {9:E447: Can't find file "NoSuchFile" in path}                  |
91    ]])
92  end)
93
94  -- oldtest: Test_mode_cleared_after_silent_message()
95  it('mode is cleared properly after silent message', function()
96    screen = Screen.new(60, 10)
97    exec([[
98      edit XsilentMessageMode.txt
99      call setline(1, 'foobar')
100      autocmd TextChanged * silent update
101    ]])
102    finally(function()
103      os.remove('XsilentMessageMode.txt')
104    end)
105
106    feed('v')
107    screen:expect([[
108      {17:^f}oobar                                                      |
109      {1:~                                                           }|*8
110      {5:-- VISUAL --}                                                |
111    ]])
112
113    feed('d')
114    screen:expect([[
115      ^oobar                                                       |
116      {1:~                                                           }|*8
117                                                                  |
118    ]])
119  end)
120
121  describe('more prompt', function()
122    before_each(function()
123      command('set more')
124    end)
125
126    -- oldtest: Test_message_more()
127    it('works', function()
128      screen = Screen.new(75, 6)
129
130      command('call setline(1, range(1, 100))')
131
132      feed(':%pfoo<C-H><C-H><C-H>#')
133      screen:expect([[
134        1                                                                          |
135        2                                                                          |
136        3                                                                          |
137        4                                                                          |
138        5                                                                          |
139        :%p#^                                                                       |
140      ]])
141      feed('\n')
142      screen:expect([[
143        {8:  1 }1                                                                      |
144        {8:  2 }2                                                                      |
145        {8:  3 }3                                                                      |
146        {8:  4 }4                                                                      |
147        {8:  5 }5                                                                      |
148        {6:-- More --}^                                                                 |
149      ]])
150
151      feed('?')
152      screen:expect([[
153        {8:  1 }1                                                                      |
154        {8:  2 }2                                                                      |
155        {8:  3 }3                                                                      |
156        {8:  4 }4                                                                      |
157        {8:  5 }5                                                                      |
158        {6:-- More -- SPACE/d/j: screen/page/line down, b/u/k: up, q: quit }^           |
159      ]])
160
161      -- Down a line with j, <CR>, <NL> or <Down>.
162      feed('j')
163      screen:expect([[
164        {8:  2 }2                                                                      |
165        {8:  3 }3                                                                      |
166        {8:  4 }4                                                                      |
167        {8:  5 }5                                                                      |
168        {8:  6 }6                                                                      |
169        {6:-- More --}^                                                                 |
170      ]])
171      feed('<NL>')
172      screen:expect([[
173        {8:  3 }3                                                                      |
174        {8:  4 }4                                                                      |
175        {8:  5 }5                                                                      |
176        {8:  6 }6                                                                      |
177        {8:  7 }7                                                                      |
178        {6:-- More --}^                                                                 |
179      ]])
180      feed('<CR>')
181      screen:expect([[
182        {8:  4 }4                                                                      |
183        {8:  5 }5                                                                      |
184        {8:  6 }6                                                                      |
185        {8:  7 }7                                                                      |
186        {8:  8 }8                                                                      |
187        {6:-- More --}^                                                                 |
188      ]])
189      feed('<Down>')
190      screen:expect([[
191        {8:  5 }5                                                                      |
192        {8:  6 }6                                                                      |
193        {8:  7 }7                                                                      |
194        {8:  8 }8                                                                      |
195        {8:  9 }9                                                                      |
196        {6:-- More --}^                                                                 |
197      ]])
198
199      -- Down a screen with <Space>, f, <C-F>, or <PageDown>.
200      feed('f')
201      screen:expect([[
202        {8: 10 }10                                                                     |
203        {8: 11 }11                                                                     |
204        {8: 12 }12                                                                     |
205        {8: 13 }13                                                                     |
206        {8: 14 }14                                                                     |
207        {6:-- More --}^                                                                 |
208      ]])
209      feed('\6')
210      screen:expect([[
211        {8: 15 }15                                                                     |
212        {8: 16 }16                                                                     |
213        {8: 17 }17                                                                     |
214        {8: 18 }18                                                                     |
215        {8: 19 }19                                                                     |
216        {6:-- More --}^                                                                 |
217      ]])
218      feed(' ')
219      screen:expect([[
220        {8: 20 }20                                                                     |
221        {8: 21 }21                                                                     |
222        {8: 22 }22                                                                     |
223        {8: 23 }23                                                                     |
224        {8: 24 }24                                                                     |
225        {6:-- More --}^                                                                 |
226      ]])
227      feed('<PageDown>')
228      screen:expect([[
229        {8: 25 }25                                                                     |
230        {8: 26 }26                                                                     |
231        {8: 27 }27                                                                     |
232        {8: 28 }28                                                                     |
233        {8: 29 }29                                                                     |
234        {6:-- More --}^                                                                 |
235      ]])
236
237      -- Down a page (half a screen) with d.
238      feed('d')
239      screen:expect([[
240        {8: 28 }28                                                                     |
241        {8: 29 }29                                                                     |
242        {8: 30 }30                                                                     |
243        {8: 31 }31                                                                     |
244        {8: 32 }32                                                                     |
245        {6:-- More --}^                                                                 |
246      ]])
247
248      -- Down all the way with 'G'.
249      feed('G')
250      screen:expect([[
251        {8: 96 }96                                                                     |
252        {8: 97 }97                                                                     |
253        {8: 98 }98                                                                     |
254        {8: 99 }99                                                                     |
255        {8:100 }100                                                                    |
256        {6:Press ENTER or type command to continue}^                                    |
257      ]])
258
259      -- Up a line k, <BS> or <Up>.
260      feed('k')
261      screen:expect([[
262        {8: 95 }95                                                                     |
263        {8: 96 }96                                                                     |
264        {8: 97 }97                                                                     |
265        {8: 98 }98                                                                     |
266        {8: 99 }99                                                                     |
267        {6:-- More --}^                                                                 |
268      ]])
269      feed('<BS>')
270      screen:expect([[
271        {8: 94 }94                                                                     |
272        {8: 95 }95                                                                     |
273        {8: 96 }96                                                                     |
274        {8: 97 }97                                                                     |
275        {8: 98 }98                                                                     |
276        {6:-- More --}^                                                                 |
277      ]])
278      feed('<Up>')
279      screen:expect([[
280        {8: 93 }93                                                                     |
281        {8: 94 }94                                                                     |
282        {8: 95 }95                                                                     |
283        {8: 96 }96                                                                     |
284        {8: 97 }97                                                                     |
285        {6:-- More --}^                                                                 |
286      ]])
287
288      -- Up a screen with b, <C-B> or <PageUp>.
289      feed('b')
290      screen:expect([[
291        {8: 88 }88                                                                     |
292        {8: 89 }89                                                                     |
293        {8: 90 }90                                                                     |
294        {8: 91 }91                                                                     |
295        {8: 92 }92                                                                     |
296        {6:-- More --}^                                                                 |
297      ]])
298      feed('\2')
299      screen:expect([[
300        {8: 83 }83                                                                     |
301        {8: 84 }84                                                                     |
302        {8: 85 }85                                                                     |
303        {8: 86 }86                                                                     |
304        {8: 87 }87                                                                     |
305        {6:-- More --}^                                                                 |
306      ]])
307      feed('<PageUp>')
308      screen:expect([[
309        {8: 78 }78                                                                     |
310        {8: 79 }79                                                                     |
311        {8: 80 }80                                                                     |
312        {8: 81 }81                                                                     |
313        {8: 82 }82                                                                     |
314        {6:-- More --}^                                                                 |
315      ]])
316
317      -- Up a page (half a screen) with u.
318      feed('u')
319      screen:expect([[
320        {8: 75 }75                                                                     |
321        {8: 76 }76                                                                     |
322        {8: 77 }77                                                                     |
323        {8: 78 }78                                                                     |
324        {8: 79 }79                                                                     |
325        {6:-- More --}^                                                                 |
326      ]])
327
328      -- Test <C-F> and <C-B> as keycodes instead of raw control chars.
329      feed('<C-F>')
330      screen:expect([[
331        {8: 80 }80                                                                     |
332        {8: 81 }81                                                                     |
333        {8: 82 }82                                                                     |
334        {8: 83 }83                                                                     |
335        {8: 84 }84                                                                     |
336        {6:-- More --}^                                                                 |
337      ]])
338      feed('<C-B>')
339      screen:expect([[
340        {8: 75 }75                                                                     |
341        {8: 76 }76                                                                     |
342        {8: 77 }77                                                                     |
343        {8: 78 }78                                                                     |
344        {8: 79 }79                                                                     |
345        {6:-- More --}^                                                                 |
346      ]])
347
348      -- Up all the way with 'g'.
349      feed('g')
350      screen:expect([[
351        :%p#                                                                       |
352        {8:  1 }1                                                                      |
353        {8:  2 }2                                                                      |
354        {8:  3 }3                                                                      |
355        {8:  4 }4                                                                      |
356        {6:-- More --}^                                                                 |
357      ]])
358
359      -- All the way down. Pressing f or CTRL-F should do nothing but pressing
360      -- space should end the more prompt.
361      feed('G')
362      screen:expect([[
363        {8: 96 }96                                                                     |
364        {8: 97 }97                                                                     |
365        {8: 98 }98                                                                     |
366        {8: 99 }99                                                                     |
367        {8:100 }100                                                                    |
368        {6:Press ENTER or type command to continue}^                                    |
369      ]])
370      feed('f')
371      screen:expect_unchanged()
372      feed('<C-F>')
373      screen:expect_unchanged()
374      feed('<Space>')
375      screen:expect([[
376        96                                                                         |
377        97                                                                         |
378        98                                                                         |
379        99                                                                         |
380        ^100                                                                        |
381                                                                                   |
382      ]])
383
384      -- Pressing g< shows the previous command output.
385      feed('g<lt>')
386      screen:expect([[
387        {8: 96 }96                                                                     |
388        {8: 97 }97                                                                     |
389        {8: 98 }98                                                                     |
390        {8: 99 }99                                                                     |
391        {8:100 }100                                                                    |
392        {6:Press ENTER or type command to continue}^                                    |
393      ]])
394
395      -- A command line that doesn't print text is appended to scrollback,
396      -- even if it invokes a nested command line.
397      feed([[:<C-R>=':'<CR>:<CR>g<lt>]])
398      screen:expect([[
399        {8: 97 }97                                                                     |
400        {8: 98 }98                                                                     |
401        {8: 99 }99                                                                     |
402        {8:100 }100                                                                    |
403        :::                                                                        |
404        {6:Press ENTER or type command to continue}^                                    |
405      ]])
406
407      feed(':%p#\n')
408      screen:expect([[
409        {8:  1 }1                                                                      |
410        {8:  2 }2                                                                      |
411        {8:  3 }3                                                                      |
412        {8:  4 }4                                                                      |
413        {8:  5 }5                                                                      |
414        {6:-- More --}^                                                                 |
415      ]])
416
417      -- Stop command output with q, <Esc> or CTRL-C.
418      feed('q')
419      screen:expect([[
420        96                                                                         |
421        97                                                                         |
422        98                                                                         |
423        99                                                                         |
424        ^100                                                                        |
425                                                                                   |
426      ]])
427
428      -- Execute a : command from the more prompt
429      feed(':%p#\n')
430      screen:expect([[
431        {8:  1 }1                                                                      |
432        {8:  2 }2                                                                      |
433        {8:  3 }3                                                                      |
434        {8:  4 }4                                                                      |
435        {8:  5 }5                                                                      |
436        {6:-- More --}^                                                                 |
437      ]])
438      feed(':')
439      screen:expect([[
440        {8:  1 }1                                                                      |
441        {8:  2 }2                                                                      |
442        {8:  3 }3                                                                      |
443        {8:  4 }4                                                                      |
444        {8:  5 }5                                                                      |
445        :^                                                                          |
446      ]])
447      feed("echo 'Hello'\n")
448      screen:expect([[
449        {8:  2 }2                                                                      |
450        {8:  3 }3                                                                      |
451        {8:  4 }4                                                                      |
452        {8:  5 }5                                                                      |
453        Hello                                                                      |
454        {6:Press ENTER or type command to continue}^                                    |
455      ]])
456    end)
457
458    -- oldtest: Test_message_more_recording()
459    it("hitting 'q' at hit-enter prompt does not start recording", function()
460      screen = Screen.new(60, 6)
461      command('call setline(1, range(1, 100))')
462      feed(':%p\n')
463      screen:expect([[
464        1                                                           |
465        2                                                           |
466        3                                                           |
467        4                                                           |
468        5                                                           |
469        {6:-- More --}^                                                  |
470      ]])
471      feed('G')
472      screen:expect([[
473        96                                                          |
474        97                                                          |
475        98                                                          |
476        99                                                          |
477        100                                                         |
478        {6:Press ENTER or type command to continue}^                     |
479      ]])
480
481      -- Hitting 'q' at the end of the more prompt should not start recording
482      feed('q')
483      screen:expect([[
484        96                                                          |
485        97                                                          |
486        98                                                          |
487        99                                                          |
488        ^100                                                         |
489                                                                    |
490      ]])
491      -- Hitting 'k' now should move the cursor up instead of recording keys
492      feed('k')
493      screen:expect([[
494        96                                                          |
495        97                                                          |
496        98                                                          |
497        ^99                                                          |
498        100                                                         |
499                                                                    |
500      ]])
501    end)
502
503    -- oldtest: Test_echo_verbose_system()
504    it('verbose message before echo command', function()
505      screen = Screen.new(60, 10)
506
507      command('cd ' .. nvim_dir)
508      api.nvim_set_option_value('shell', './shell-test', {})
509      api.nvim_set_option_value('shellcmdflag', 'REP 20', {})
510      api.nvim_set_option_value('shellxquote', '', {}) -- win: avoid extra quotes
511
512      -- display a page and go back, results in exactly the same view
513      feed([[:4 verbose echo system('foo')<CR>]])
514      screen:expect([[
515        Executing command: "'./shell-test' 'REP' '20' 'foo'"        |
516                                                                    |
517        0: foo                                                      |
518        1: foo                                                      |
519        2: foo                                                      |
520        3: foo                                                      |
521        4: foo                                                      |
522        5: foo                                                      |
523        6: foo                                                      |
524        {6:-- More --}^                                                  |
525      ]])
526      feed('<Space>')
527      screen:expect([[
528        7: foo                                                      |
529        8: foo                                                      |
530        9: foo                                                      |
531        10: foo                                                     |
532        11: foo                                                     |
533        12: foo                                                     |
534        13: foo                                                     |
535        14: foo                                                     |
536        15: foo                                                     |
537        {6:-- More --}^                                                  |
538      ]])
539      feed('b')
540      screen:expect([[
541        Executing command: "'./shell-test' 'REP' '20' 'foo'"        |
542                                                                    |
543        0: foo                                                      |
544        1: foo                                                      |
545        2: foo                                                      |
546        3: foo                                                      |
547        4: foo                                                      |
548        5: foo                                                      |
549        6: foo                                                      |
550        {6:-- More --}^                                                  |
551      ]])
552
553      -- do the same with 'cmdheight' set to 2
554      feed('q')
555      command('set ch=2')
556      screen:expect([[
557        ^                                                            |
558        {1:~                                                           }|*7
559                                                                    |*2
560      ]])
561      feed([[:4 verbose echo system('foo')<CR>]])
562      screen:expect([[
563        Executing command: "'./shell-test' 'REP' '20' 'foo'"        |
564                                                                    |
565        0: foo                                                      |
566        1: foo                                                      |
567        2: foo                                                      |
568        3: foo                                                      |
569        4: foo                                                      |
570        5: foo                                                      |
571        6: foo                                                      |
572        {6:-- More --}^                                                  |
573      ]])
574      feed('<Space>')
575      screen:expect([[
576        7: foo                                                      |
577        8: foo                                                      |
578        9: foo                                                      |
579        10: foo                                                     |
580        11: foo                                                     |
581        12: foo                                                     |
582        13: foo                                                     |
583        14: foo                                                     |
584        15: foo                                                     |
585        {6:-- More --}^                                                  |
586      ]])
587      feed('b')
588      screen:expect([[
589        Executing command: "'./shell-test' 'REP' '20' 'foo'"        |
590                                                                    |
591        0: foo                                                      |
592        1: foo                                                      |
593        2: foo                                                      |
594        3: foo                                                      |
595        4: foo                                                      |
596        5: foo                                                      |
597        6: foo                                                      |
598        {6:-- More --}^                                                  |
599      ]])
600    end)
601
602    -- oldtest: Test_quit_long_message()
603    it('with control characters can be quit vim-patch:8.2.1844', function()
604      screen = Screen.new(40, 10)
605
606      feed([[:echom range(9999)->join("\x01")<CR>]])
607      screen:expect([[
608        0{18:^A}1{18:^A}2{18:^A}3{18:^A}4{18:^A}5{18:^A}6{18:^A}7{18:^A}8{18:^A}9{18:^A}10{18:^A}11{18:^A}12|
609        {18:^A}13{18:^A}14{18:^A}15{18:^A}16{18:^A}17{18:^A}18{18:^A}19{18:^A}20{18:^A}21{18:^A}22|
610        {18:^A}23{18:^A}24{18:^A}25{18:^A}26{18:^A}27{18:^A}28{18:^A}29{18:^A}30{18:^A}31{18:^A}32|
611        {18:^A}33{18:^A}34{18:^A}35{18:^A}36{18:^A}37{18:^A}38{18:^A}39{18:^A}40{18:^A}41{18:^A}42|
612        {18:^A}43{18:^A}44{18:^A}45{18:^A}46{18:^A}47{18:^A}48{18:^A}49{18:^A}50{18:^A}51{18:^A}52|
613        {18:^A}53{18:^A}54{18:^A}55{18:^A}56{18:^A}57{18:^A}58{18:^A}59{18:^A}60{18:^A}61{18:^A}62|
614        {18:^A}63{18:^A}64{18:^A}65{18:^A}66{18:^A}67{18:^A}68{18:^A}69{18:^A}70{18:^A}71{18:^A}72|
615        {18:^A}73{18:^A}74{18:^A}75{18:^A}76{18:^A}77{18:^A}78{18:^A}79{18:^A}80{18:^A}81{18:^A}82|
616        {18:^A}83{18:^A}84{18:^A}85{18:^A}86{18:^A}87{18:^A}88{18:^A}89{18:^A}90{18:^A}91{18:^A}92|
617        {6:-- More --}^                              |
618      ]])
619      feed('q')
620      screen:expect([[
621        ^                                        |
622        {1:~                                       }|*8
623                                                |
624      ]])
625    end)
626  end)
627
628  describe('mode is cleared when', function()
629    before_each(function()
630      screen = Screen.new(40, 6)
631    end)
632
633    -- oldtest: Test_mode_message_at_leaving_insert_by_ctrl_c()
634    it('leaving Insert mode with Ctrl-C vim-patch:8.1.1189', function()
635      exec([[
636        func StatusLine() abort
637          return ""
638        endfunc
639        set statusline=%!StatusLine()
640        set laststatus=2
641      ]])
642      feed('i')
643      screen:expect([[
644        ^                                        |
645        {1:~                                       }|*3
646        {3:                                        }|
647        {5:-- INSERT --}                            |
648      ]])
649      feed('<C-C>')
650      screen:expect([[
651        ^                                        |
652        {1:~                                       }|*3
653        {3:                                        }|
654                                                |
655      ]])
656    end)
657
658    -- oldtest: Test_mode_message_at_leaving_insert_with_esc_mapped()
659    it('leaving Insert mode with ESC in the middle of a mapping vim-patch:8.1.1192', function()
660      exec([[
661        set laststatus=2
662        inoremap <Esc> <Esc>00
663      ]])
664      feed('i')
665      screen:expect([[
666        ^                                        |
667        {1:~                                       }|*3
668        {3:[No Name]                               }|
669        {5:-- INSERT --}                            |
670      ]])
671      feed('<Esc>')
672      screen:expect([[
673        ^                                        |
674        {1:~                                       }|*3
675        {3:[No Name]                               }|
676                                                |
677      ]])
678    end)
679
680    -- oldtest: Test_mode_updated_after_ctrl_c()
681    it('pressing Ctrl-C in i_CTRL-O', function()
682      feed('i<C-O>')
683      screen:expect([[
684        ^                                        |
685        {1:~                                       }|*4
686        {5:-- (insert) --}                          |
687      ]])
688      feed('<C-C>')
689      screen:expect([[
690        ^                                        |
691        {1:~                                       }|*4
692                                                |
693      ]])
694    end)
695  end)
696
697  -- oldtest: Test_ask_yesno()
698  it('y/n prompt works', function()
699    screen = Screen.new(75, 6)
700    command('set noincsearch nohlsearch inccommand=')
701    command('call setline(1, range(1, 2))')
702
703    feed(':2,1s/^/n/\n')
704    screen:expect([[
705      1                                                                          |
706      2                                                                          |
707      {1:~                                                                          }|*3
708      {6:Backwards range given, OK to swap (y/n)?}^                                   |
709    ]])
710    feed('n')
711    screen:expect([[
712      ^1                                                                          |
713      2                                                                          |
714      {1:~                                                                          }|*3
715      {6:Backwards range given, OK to swap (y/n)?}n                                  |
716    ]])
717
718    feed(':2,1s/^/Esc/\n')
719    screen:expect([[
720      1                                                                          |
721      2                                                                          |
722      {1:~                                                                          }|*3
723      {6:Backwards range given, OK to swap (y/n)?}^                                   |
724    ]])
725    feed('<Esc>')
726    screen:expect([[
727      ^1                                                                          |
728      2                                                                          |
729      {1:~                                                                          }|*3
730      {6:Backwards range given, OK to swap (y/n)?}n                                  |
731    ]])
732
733    feed(':2,1s/^/y/\n')
734    screen:expect([[
735      1                                                                          |
736      2                                                                          |
737      {1:~                                                                          }|*3
738      {6:Backwards range given, OK to swap (y/n)?}^                                   |
739    ]])
740    feed('y')
741    screen:expect([[
742      y1                                                                         |
743      ^y2                                                                         |
744      {1:~                                                                          }|*3
745      {6:Backwards range given, OK to swap (y/n)?}y                                  |
746    ]])
747  end)
748
749  -- oldtest: Test_fileinfo_tabpage_cmdheight()
750  it("fileinfo works when 'cmdheight' has just decreased", function()
751    screen = Screen.new(40, 6)
752
753    exec([[
754      set shortmess-=o
755      set shortmess-=O
756      set shortmess-=F
757      tabnew
758      set cmdheight=2
759    ]])
760    screen:expect([[
761      {24: [No Name] }{5: [No Name] }{2:                 }{24:X}|
762      ^                                        |
763      {1:~                                       }|*2
764                                              |*2
765    ]])
766
767    feed(':tabprev | edit Xfileinfo.txt<CR>')
768    screen:expect([[
769      {5: Xfileinfo.txt }{24: [No Name] }{2:             }{24:X}|
770      ^                                        |
771      {1:~                                       }|*3
772      "Xfileinfo.txt" [New]                   |
773    ]])
774    assert_alive()
775  end)
776
777  -- oldtest: Test_fileinfo_after_echo()
778  it('fileinfo does not overwrite echo message vim-patch:8.2.4156', function()
779    screen = Screen.new(40, 6)
780
781    exec([[
782      set shortmess-=F
783
784      file a.txt
785
786      hide edit b.txt
787      call setline(1, "hi")
788      setlocal modified
789
790      hide buffer a.txt
791
792      autocmd CursorHold * buf b.txt | w | echo "'b' written"
793    ]])
794
795    command('set updatetime=50')
796    feed('0$')
797    screen:expect([[
798      ^hi                                      |
799      {1:~                                       }|*4
800      'b' written                             |
801    ]])
802    os.remove('b.txt')
803  end)
804
805  -- oldtest: Test_messagesopt_wait()
806  it('&messagesopt "wait"', function()
807    screen = Screen.new(45, 6)
808    command('set cmdheight=1')
809
810    -- Check hit-enter prompt
811    command('set messagesopt=hit-enter,history:500')
812    feed(":echo 'foo' | echo 'bar' | echo 'baz'\n")
813    screen:expect([[
814                                                   |
815      {3:                                             }|
816      foo                                          |
817      bar                                          |
818      baz                                          |
819      {6:Press ENTER or type command to continue}^      |
820    ]])
821    feed('<CR>')
822
823    -- Check no hit-enter prompt when "wait:" is set
824    command('set messagesopt=wait:500,history:500')
825    feed(":echo 'foo' | echo 'bar' | echo 'baz'\n")
826    screen:expect({
827      grid = [[
828                                                   |
829      {1:~                                            }|
830      {3:                                             }|
831      foo                                          |
832      bar                                          |
833      baz                                          |
834    ]],
835      timeout = 500,
836    })
837    screen:expect([[
838      ^                                             |
839      {1:~                                            }|*4
840                                                   |
841    ]])
842  end)
843
844  -- oldtest: Test_long_formatprg_no_hit_enter()
845  it("long 'formatprg' doesn't cause hit-enter prompt or wrong cursor pos", function()
846    t.skip(fn.executable('sed') == 0, 'missing "sed" command')
847
848    screen = Screen.new(75, 10)
849    exec([[
850      setlocal scrolloff=0
851      call setline(1, range(1, 40))
852      let &l:formatprg = $'sed{repeat(' ', &columns)}p'
853      normal 20Gmz
854      normal 10Gzt
855    ]])
856    screen:expect([[
857      ^10                                                                         |
858      11                                                                         |
859      12                                                                         |
860      13                                                                         |
861      14                                                                         |
862      15                                                                         |
863      16                                                                         |
864      17                                                                         |
865      18                                                                         |
866                                                                                 |
867    ]])
868    feed('gq2j')
869    screen:expect([[
870      10                                                                         |*2
871      11                                                                         |*2
872      12                                                                         |
873      ^12                                                                         |
874      13                                                                         |
875      14                                                                         |
876      15                                                                         |
877                                                                                 |
878    ]])
879    feed(':messages<CR>')
880    screen:expect([[
881      10                                                                         |*2
882      11                                                                         |*2
883      12                                                                         |
884      ^12                                                                         |
885      13                                                                         |
886      14                                                                         |
887      15                                                                         |
888      3 lines filtered                                                           |
889    ]])
890  end)
891
892  -- oldtest: Test_hit_enter_during_mapping()
893  it('hit-enter prompt during a mapping', function()
894    screen = Screen.new(75, 10)
895    exec([[
896      set ruler
897      call setline(1, range(1, 20))
898      " The 8-line :echo leads to a hit-enter prompt.
899      nnoremap X :echo "a\nb\nc\nd\ne\nf\ng\nh"<CR>gg
900      nnoremap \b :echo "a\nb\nc\nd\ne\nf\ng\nh"<CR>:b<Space>
901      normal! 10G
902    ]])
903    t.eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
904    t.eq({ 10, 0 }, api.nvim_win_get_cursor(0))
905
906    feed('X')
907    -- Without the fix the hit-enter prompt eats the mapping's "g" keys and the
908    -- cursor stays put.  With the fix "gg" runs and moves the cursor to line 1.
909    t.eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
910    t.eq({ 1, 0 }, api.nvim_win_get_cursor(0))
911
912    -- If a mapping starts cmdline after multiline messages exceeding 'cmdheight',
913    -- the messages should still be visible.
914    feed('\\b')
915    screen:expect([[
916      {3:                                                                           }|
917      a                                                                          |
918      b                                                                          |
919      c                                                                          |
920      d                                                                          |
921      e                                                                          |
922      f                                                                          |
923      g                                                                          |
924      h                                                                          |
925      :b ^                                                                        |
926    ]])
927  end)
928
929  -- oldtest: Test_fileinfo_after_last_bd()
930  it('fileinfo is shown after :bd on last listed buffer', function()
931    screen = Screen.new(50, 10)
932    exec([[
933      set shortmess-=F
934      edit xxx
935      edit yyy
936    ]])
937    screen:expect([[
938      ^                                                  |
939      {1:~                                                 }|*8
940      "yyy" [New]                                       |
941    ]])
942
943    command('bd')
944    screen:expect([[
945      ^                                                  |
946      {1:~                                                 }|*8
947      "xxx" [New] --No lines in buffer--                |
948    ]])
949
950    command('bd')
951    screen:expect([[
952      ^                                                  |
953      {1:~                                                 }|*8
954      "[No Name]" --No lines in buffer--                |
955    ]])
956  end)
957end)