robin/laufey

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

robinmerge: 1dc9728daa1d8a2702

master
48.7 KiB1716 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, pending = t.describe, t.it, t.before_each, t.pending
6local clear, feed = n.clear, n.feed
7local source = n.source
8local command = n.command
9local assert_alive = n.assert_alive
10local poke_eventloop = n.poke_eventloop
11local exec = n.exec
12local eval = n.eval
13local eq = t.eq
14local is_os = t.is_os
15local api = n.api
16
17local function test_cmdline(linegrid)
18  local screen
19
20  before_each(function()
21    clear()
22    screen = Screen.new(25, 5, { rgb = true, ext_cmdline = true, ext_linegrid = linegrid })
23  end)
24
25  it('works', function()
26    feed(':')
27    screen:expect {
28      grid = [[
29        ^                         |
30        {1:~                        }|*3
31                                 |
32      ]],
33      cmdline = { { firstc = ':', content = { { '' } }, pos = 0 } },
34    }
35
36    feed('sign')
37    screen:expect {
38      grid = [[
39        ^                         |
40        {1:~                        }|*3
41                                 |
42      ]],
43      cmdline = { { firstc = ':', content = { { 'sign' } }, pos = 4 } },
44    }
45
46    feed('<Left>')
47    screen:expect {
48      grid = [[
49        ^                         |
50        {1:~                        }|*3
51                                 |
52      ]],
53      cmdline = { { firstc = ':', content = { { 'sign' } }, pos = 3 } },
54    }
55
56    feed('<bs>')
57    screen:expect {
58      grid = [[
59        ^                         |
60        {1:~                        }|*3
61                                 |
62      ]],
63      cmdline = { { firstc = ':', content = { { 'sin' } }, pos = 2 } },
64    }
65
66    feed('<Esc>')
67    screen:expect {
68      grid = [[
69        ^                         |
70        {1:~                        }|*3
71                                 |
72      ]],
73      cmdline = { { abort = true } },
74    }
75  end)
76
77  it('works with input()', function()
78    feed(':call input("input", "default")<cr>')
79    screen:expect({
80      grid = [[
81        ^                         |
82        {1:~                        }|*3
83                                 |
84      ]],
85      cmdline = { { content = { { 'default' } }, pos = 7, prompt = 'input' } },
86    })
87
88    feed('<cr>')
89    screen:expect_unchanged()
90  end)
91
92  it('works with special chars and nested cmdline', function()
93    feed(':xx<c-r>')
94    screen:expect {
95      grid = [[
96        ^                         |
97        {1:~                        }|*3
98                                 |
99      ]],
100      cmdline = { { firstc = ':', content = { { 'xx' } }, pos = 2, special = { '"', true } } },
101    }
102
103    feed('=')
104    screen:expect {
105      grid = [[
106        ^                         |
107        {1:~                        }|*3
108                                 |
109      ]],
110      cmdline = {
111        { firstc = ':', content = { { 'xx' } }, pos = 2, special = { '"', true } },
112        { firstc = '=', content = { { '' } }, pos = 0 },
113      },
114    }
115
116    feed('1+2')
117
118    screen:expect {
119      grid = [[
120        ^                         |
121        {1:~                        }|*3
122                                 |
123      ]],
124      cmdline = {
125        { firstc = ':', content = { { 'xx' } }, pos = 2, special = { '"', true } },
126        {
127          firstc = '=',
128          content = {
129            { '1', 26, linegrid and 'NvimNumber' or nil },
130            { '+', 15, linegrid and 'NvimBinaryPlus' or nil },
131            { '2', 26, linegrid and 'NvimNumber' or nil },
132          },
133          pos = 3,
134        },
135      },
136    }
137
138    -- erase information, so we check if it is retransmitted
139    command('mode')
140    screen:expect {
141      grid = [[
142        ^                         |
143        {1:~                        }|*3
144                                 |
145      ]],
146      cmdline = {
147        { firstc = ':', content = { { 'xx' } }, pos = 2, special = { '"', true } },
148        {
149          firstc = '=',
150          content = {
151            { '1', 26, linegrid and 'NvimNumber' or nil },
152            { '+', 15, linegrid and 'NvimBinaryPlus' or nil },
153            { '2', 26, linegrid and 'NvimNumber' or nil },
154          },
155          pos = 3,
156        },
157      },
158      reset = true,
159    }
160
161    feed('<cr>')
162    screen:expect {
163      grid = [[
164        ^                         |
165        {1:~                        }|*3
166                                 |
167      ]],
168      cmdline = { { firstc = ':', content = { { 'xx3' } }, pos = 3 } },
169    }
170
171    feed('<esc>')
172    screen:expect {
173      grid = [[
174        ^                         |
175        {1:~                        }|*3
176                                 |
177      ]],
178      cmdline = { { abort = true } },
179    }
180  end)
181
182  it('works with function definitions', function()
183    feed(':function Foo()<cr>')
184    screen:expect {
185      grid = [[
186        ^                         |
187        {1:~                        }|*3
188                                 |
189      ]],
190      cmdline = { { indent = 2, firstc = ':', content = { { '' } }, pos = 0 } },
191      cmdline_block = { { { 'function Foo()' } } },
192    }
193
194    feed('line1<cr>')
195    screen:expect {
196      grid = [[
197        ^                         |
198        {1:~                        }|*3
199                                 |
200      ]],
201      cmdline = { { indent = 2, firstc = ':', content = { { '' } }, pos = 0 } },
202      cmdline_block = { { { 'function Foo()' } }, { { '  line1' } } },
203    }
204
205    command('mode')
206    screen:expect {
207      grid = [[
208        ^                         |
209        {1:~                        }|*3
210                                 |
211      ]],
212      cmdline = { { indent = 2, firstc = ':', content = { { '' } }, pos = 0 } },
213      cmdline_block = { { { 'function Foo()' } }, { { '  line1' } } },
214      reset = true,
215    }
216
217    feed('endfunction<cr>')
218    screen:expect([[
219      ^                         |
220      {1:~                        }|*3
221                               |
222    ]])
223
224    -- Try once more, to check buffer is reinitialized. #8007
225    feed(':function Bar()<cr>')
226    screen:expect {
227      grid = [[
228        ^                         |
229        {1:~                        }|*3
230                                 |
231      ]],
232      cmdline = { { indent = 2, firstc = ':', content = { { '' } }, pos = 0 } },
233      cmdline_block = { { { 'function Bar()' } } },
234    }
235
236    feed('endfunction<cr>')
237    screen:expect([[
238      ^                         |
239      {1:~                        }|*3
240                               |
241    ]])
242  end)
243
244  it('with cmdwin', function()
245    feed(':make')
246    screen:expect {
247      grid = [[
248        ^                         |
249        {1:~                        }|*3
250                                 |
251      ]],
252      cmdline = { { firstc = ':', content = { { 'make' } }, pos = 4 } },
253    }
254
255    feed('<c-f>')
256    screen:expect([[
257                               |
258      {2:[No Name]                }|
259      {1::}mak^e                    |
260      {3:[Command Line]           }|
261                               |
262    ]])
263
264    -- cmdwin is a plain window so `:yank` opens a top-level cmdline. No nesting allowed. #40312
265    feed(':yank')
266    screen:expect {
267      grid = [[
268                                 |
269        {2:[No Name]                }|
270        {1::}mak^e                    |
271        {3:[Command Line]           }|
272                                 |
273      ]],
274      cmdline = { { firstc = ':', content = { { 'yank' } }, pos = 4 } },
275    }
276
277    command('mode')
278    screen:expect {
279      grid = [[
280                                 |
281        {2:[No Name]                }|
282        {1::}mak^e                    |
283        {3:[Command Line]           }|
284                                 |
285      ]],
286      cmdline = { { firstc = ':', content = { { 'yank' } }, pos = 4 } },
287      reset = true,
288    }
289
290    feed('<c-c>')
291    screen:expect {
292      grid = [[
293                                 |
294        {2:[No Name]                }|
295        {1::}mak^e                    |
296        {3:[Command Line]           }|
297                                 |
298      ]],
299      cmdline = { { abort = true } },
300    }
301
302    feed('<c-c>')
303    screen:expect {
304      grid = [[
305        ^                         |
306        {1:~                        }|*3
307                                 |
308      ]],
309      cmdline = { { firstc = ':', content = { { 'make' } }, pos = 4 } },
310    }
311  end)
312
313  it('works with inputsecret()', function()
314    feed(":call inputsecret('secret:')<cr>abc123")
315    screen:expect {
316      grid = [[
317        ^                         |
318        {1:~                        }|*3
319                                 |
320      ]],
321      cmdline = { { prompt = 'secret:', content = { { '******' } }, pos = 6 } },
322    }
323  end)
324
325  it('works with highlighted cmdline', function()
326    source([[
327      highlight RBP1 guibg=Red
328      highlight RBP2 guibg=Yellow
329      highlight RBP3 guibg=Green
330      highlight RBP4 guibg=Blue
331      let g:NUM_LVLS = 4
332      function RainBowParens(cmdline)
333        let ret = []
334        let i = 0
335        let lvl = 0
336        while i < len(a:cmdline)
337          if a:cmdline[i] is# '('
338            call add(ret, [i, i + 1, 'RBP' . ((lvl % g:NUM_LVLS) + 1)])
339            let lvl += 1
340          elseif a:cmdline[i] is# ')'
341            let lvl -= 1
342            call add(ret, [i, i + 1, 'RBP' . ((lvl % g:NUM_LVLS) + 1)])
343          endif
344          let i += 1
345        endwhile
346        return ret
347      endfunction
348      map <f5>  :let x = input({'prompt':'>','highlight':'RainBowParens'})<cr>
349      "map <f5>  :let x = input({'prompt':'>'})<cr>
350    ]])
351    feed('<f5>(a(b)a)')
352    screen:expect {
353      grid = [[
354        ^                         |
355        {1:~                        }|*3
356                                 |
357      ]],
358      cmdline = {
359        {
360          prompt = '>',
361          content = {
362            { '(', 30, linegrid and 'RBP1' or nil },
363            { 'a' },
364            { '(', 10, linegrid and 'RBP2' or nil },
365            { 'b' },
366            { ')', 10, linegrid and 'RBP2' or nil },
367            { 'a' },
368            { ')', 30, linegrid and 'RBP1' or nil },
369          },
370          pos = 7,
371        },
372      },
373    }
374  end)
375
376  it('works together with ext_wildmenu', function()
377    command('set wildmode=full')
378    command('set wildmenu')
379    screen:set_option('ext_wildmenu', true)
380    feed(':sign <tab>')
381
382    screen:expect {
383      grid = [[
384        ^                         |
385        {1:~                        }|*3
386                                 |
387      ]],
388      cmdline = { { firstc = ':', content = { { 'sign define' } }, pos = 11 } },
389      wildmenu_items = { 'define', 'jump', 'list', 'place', 'undefine', 'unplace' },
390      wildmenu_pos = 0,
391    }
392
393    feed('<tab>')
394    screen:expect {
395      grid = [[
396        ^                         |
397        {1:~                        }|*3
398                                 |
399      ]],
400      cmdline = { { firstc = ':', content = { { 'sign jump' } }, pos = 9 } },
401      wildmenu_items = { 'define', 'jump', 'list', 'place', 'undefine', 'unplace' },
402      wildmenu_pos = 1,
403    }
404
405    feed('<left><left>')
406    screen:expect {
407      grid = [[
408        ^                         |
409        {1:~                        }|*3
410                                 |
411      ]],
412      cmdline = { { firstc = ':', content = { { 'sign ' } }, pos = 5 } },
413      wildmenu_items = { 'define', 'jump', 'list', 'place', 'undefine', 'unplace' },
414      wildmenu_pos = -1,
415    }
416
417    feed('<right>')
418    screen:expect {
419      grid = [[
420        ^                         |
421        {1:~                        }|*3
422                                 |
423      ]],
424      cmdline = { { firstc = ':', content = { { 'sign define' } }, pos = 11 } },
425      wildmenu_items = { 'define', 'jump', 'list', 'place', 'undefine', 'unplace' },
426      wildmenu_pos = 0,
427    }
428
429    feed('a')
430    screen:expect {
431      grid = [[
432        ^                         |
433        {1:~                        }|*3
434                                 |
435      ]],
436      cmdline = { { firstc = ':', content = { { 'sign definea' } }, pos = 12 } },
437    }
438  end)
439
440  local function test_ext_cmdline_popupmenu()
441    local expected = {
442      { 'define', '', '', '' },
443      { 'jump', '', '', '' },
444      { 'list', '', '', '' },
445      { 'place', '', '', '' },
446      { 'undefine', '', '', '' },
447      { 'unplace', '', '', '' },
448    }
449
450    command('set wildmode=full')
451    command('set wildmenu')
452    screen:set_option('ext_popupmenu', true)
453    feed(':sign <tab>')
454
455    screen:expect {
456      grid = [[
457        ^                         |
458        {1:~                        }|*3
459                                 |
460      ]],
461      cmdline = { { firstc = ':', content = { { 'sign define' } }, pos = 11 } },
462      popupmenu = { items = expected, pos = 0, anchor = { -1, 0, 5 } },
463    }
464
465    feed('<tab>')
466    screen:expect {
467      grid = [[
468        ^                         |
469        {1:~                        }|*3
470                                 |
471      ]],
472      cmdline = { { firstc = ':', content = { { 'sign jump' } }, pos = 9 } },
473      popupmenu = { items = expected, pos = 1, anchor = { -1, 0, 5 } },
474    }
475
476    feed('<left><left>')
477    screen:expect {
478      grid = [[
479        ^                         |
480        {1:~                        }|*3
481                                 |
482      ]],
483      cmdline = { { firstc = ':', content = { { 'sign ' } }, pos = 5 } },
484      popupmenu = { items = expected, pos = -1, anchor = { -1, 0, 5 } },
485    }
486
487    feed('<right>')
488    screen:expect {
489      grid = [[
490        ^                         |
491        {1:~                        }|*3
492                                 |
493      ]],
494      cmdline = { { firstc = ':', content = { { 'sign define' } }, pos = 11 } },
495      popupmenu = { items = expected, pos = 0, anchor = { -1, 0, 5 } },
496    }
497
498    feed('a')
499    screen:expect {
500      grid = [[
501        ^                         |
502        {1:~                        }|*3
503                                 |
504      ]],
505      cmdline = { { firstc = ':', content = { { 'sign definea' } }, pos = 12 } },
506    }
507    feed('<esc>')
508
509    -- check positioning with multibyte char in pattern
510    command('e långfile1')
511    command('sp långfile2')
512    feed(':b lå<tab>')
513    screen:expect {
514      grid = [[
515        ^                         |
516        {3:långfile2                }|
517                                 |
518        {2:långfile1                }|
519                                 |
520      ]],
521      cmdline = { { content = { { 'b långfile1' } }, firstc = ':', pos = 12 } },
522      popupmenu = {
523        anchor = { -1, 0, 2 },
524        items = { { 'långfile1', '', '', '' }, { 'långfile2', '', '', '' } },
525        pos = 0,
526      },
527    }
528
529    feed('<Esc>')
530    command('silent %bwipe')
531
532    command('set shellslash')
533    -- position is correct when expanding environment variable #20348
534    command('silent cd test/functional/fixtures')
535    n.fn.setenv('XNDIR', 'wildpum/Xnamedir')
536    feed(':e $XNDIR/<Tab>')
537    screen:expect {
538      grid = [[
539        ^                         |
540        {1:~                        }|*3
541                                 |
542      ]],
543      cmdline = { { content = { { 'e wildpum/Xnamedir/XdirA/' } }, firstc = ':', pos = 25 } },
544      popupmenu = {
545        anchor = { -1, 0, 19 },
546        items = { { 'XdirA/', '', '', '' }, { 'XfileA', '', '', '' } },
547        pos = 0,
548      },
549    }
550
551    feed('<Esc>')
552    command('set wildmode=longest,full')
553    feed(':sign u<tab>')
554    screen:expect {
555      grid = [[
556        ^                         |
557        {1:~                        }|*3
558                                 |
559      ]],
560      cmdline = { { content = { { 'sign un' } }, firstc = ':', pos = 7 } },
561    }
562
563    feed('<tab>')
564    local s_undefine_unplace_0 = {
565      grid = [[
566        ^                         |
567        {1:~                        }|*3
568                                 |
569      ]],
570      cmdline = { { content = { { 'sign undefine' } }, firstc = ':', pos = 13 } },
571      popupmenu = {
572        anchor = { -1, 0, 5 },
573        items = { { 'undefine', '', '', '' }, { 'unplace', '', '', '' } },
574        pos = 0,
575      },
576    }
577    screen:expect(s_undefine_unplace_0)
578
579    feed('<Esc>')
580    screen:expect([[
581      ^                         |
582      {1:~                        }|*3
583                               |
584    ]])
585
586    feed(':sign un<tab>')
587    screen:expect(s_undefine_unplace_0)
588  end
589
590  describe('works together with ext_popupmenu', function()
591    it('with wildoptions=pum', function()
592      command('set wildoptions=pum')
593      test_ext_cmdline_popupmenu()
594    end)
595
596    it('with wildoptions=', function()
597      command('set wildoptions=')
598      test_ext_cmdline_popupmenu()
599    end)
600  end)
601
602  it('ext_wildmenu takes precedence over ext_popupmenu', function()
603    local expected = {
604      'define',
605      'jump',
606      'list',
607      'place',
608      'undefine',
609      'unplace',
610    }
611
612    command('set wildmode=full')
613    command('set wildmenu')
614    screen:set_option('ext_wildmenu', true)
615    screen:set_option('ext_popupmenu', true)
616    feed(':sign <tab>')
617
618    screen:expect {
619      grid = [[
620        ^                         |
621        {1:~                        }|*3
622                                 |
623      ]],
624      cmdline = { { firstc = ':', content = { { 'sign define' } }, pos = 11 } },
625      wildmenu_items = expected,
626      wildmenu_pos = 0,
627    }
628  end)
629
630  it("doesn't send invalid events when aborting mapping #10000", function()
631    command('set notimeout')
632    command('cnoremap ab c')
633
634    feed(':xa')
635    screen:expect {
636      grid = [[
637        ^                         |
638        {1:~                        }|*3
639                                 |
640      ]],
641      cmdline = { { content = { { 'x' } }, firstc = ':', pos = 1, special = { 'a', false } } },
642    }
643
644    -- This used to send an invalid event where pos where larger than the total
645    -- length of content. Checked in _handle_cmdline_show.
646    feed('<esc>')
647    screen:expect({
648      grid = [[
649        ^                         |
650        {1:~                        }|*3
651                                 |
652      ]],
653      cmdline = { { abort = true } },
654    })
655  end)
656
657  it('does not move cursor to curwin #20309', function()
658    local win = api.nvim_get_current_win()
659    command('norm icmdlinewin')
660    command('new')
661    command('norm icurwin')
662    feed(':')
663    api.nvim_win_set_cursor(win, { 1, 7 })
664    api.nvim__redraw({ win = win, cursor = true })
665    screen:expect {
666      grid = [[
667        curwin                   |
668        {3:[No Name] [+]            }|
669        cmdline^win               |
670        {2:[No Name] [+]            }|
671                                 |
672      ]],
673      cmdline = { { content = { { '' } }, firstc = ':', pos = 0 } },
674    }
675  end)
676
677  it('show prompt hl_id', function()
678    screen:expect([[
679      ^                         |
680      {1:~                        }|*3
681                               |
682    ]])
683    feed(':echohl Error | call input("Prompt:")<CR>')
684    screen:expect({
685      grid = [[
686        ^                         |
687        {1:~                        }|*3
688                                 |
689      ]],
690      cmdline = { { content = { { '' } }, hl = 'Error', pos = 0, prompt = 'Prompt:' } },
691    })
692  end)
693
694  it('works with conditionals', function()
695    screen:expect([[
696      ^                         |
697      {1:~                        }|*3
698                               |
699    ]])
700    feed(':if 1<CR>')
701    screen:expect({
702      grid = [[
703        ^                         |
704        {1:~                        }|*3
705                                 |
706      ]],
707      cmdline = { { content = { { '' } }, firstc = ':', indent = 2, pos = 0 } },
708      cmdline_block = { { { 'if 1' } } },
709    })
710    feed('let x = 1<CR>')
711    screen:expect({
712      grid = [[
713        ^                         |
714        {1:~                        }|*3
715                                 |
716      ]],
717      cmdline = { { content = { { '' } }, firstc = ':', indent = 2, pos = 0 } },
718      cmdline_block = { { { 'if 1' } }, { { '  let x = 1' } } },
719    })
720    feed('<CR>')
721    eq('let x = 1', eval('@:'))
722    screen:expect({
723      grid = [[
724        ^                         |
725        {1:~                        }|*3
726                                 |
727      ]],
728      cmdline = { { content = { { '' } }, firstc = ':', indent = 2, pos = 0 } },
729      cmdline_block = { { { 'if 1' } }, { { '  let x = 1' } }, { { '  ' } } },
730    })
731    feed('call input("foo:")<CR>')
732    screen:expect({
733      grid = [[
734        ^                         |
735        {1:~                        }|*3
736                                 |
737      ]],
738      cmdline = { { content = { { '' } }, pos = 0, prompt = 'foo:' } },
739      cmdline_block = {
740        { { 'if 1' } },
741        { { '  let x = 1' } },
742        { { '  ' } },
743        { { '  call input("foo:")' } },
744      },
745    })
746    feed('bar<CR>')
747    screen:expect({
748      grid = [[
749        ^                         |
750        {1:~                        }|*3
751                                 |
752      ]],
753      cmdline = { { content = { { '' } }, firstc = ':', indent = 2, pos = 0 } },
754      cmdline_block = {
755        { { 'if 1' } },
756        { { '  let x = 1' } },
757        { { '  ' } },
758        { { '  call input("foo:")' } },
759      },
760    })
761    feed('endif')
762    screen:expect({
763      grid = [[
764        ^                         |
765        {1:~                        }|*3
766                                 |
767      ]],
768      cmdline = { { content = { { 'endif' } }, firstc = ':', indent = 2, pos = 5 } },
769      cmdline_block = {
770        { { 'if 1' } },
771        { { '  let x = 1' } },
772        { { '  ' } },
773        { { '  call input("foo:")' } },
774      },
775    })
776    feed('<CR>')
777    screen:expect([[
778      ^                         |
779      {1:~                        }|*3
780                               |
781    ]])
782  end)
783
784  it('works with exmode', function()
785    screen:try_resize(60, 12)
786    feed('1q:')
787    screen:expect([[
788                                                                  |
789      {1:~                                                           }|
790      {2:[No Name]                                                   }|
791      {1::}^                                                           |
792      {1:~                                                           }|*6
793      {3:[Ex mode]                                                   }|
794      {5:-- INSERT --}                                                |
795    ]])
796    feed('echo "foo"<CR>')
797    screen:expect([[
798                                                                  |
799      {1:~                                                           }|
800      {2:[No Name]                                                   }|
801      {1::}echo "foo"                                                 |
802      {1::}" foo                                                      |
803      {1::}^                                                           |
804      {1:~                                                           }|*4
805      {3:[Ex mode]                                                   }|
806      {5:-- INSERT --}                                                |
807    ]])
808    feed('<C-\\><C-N>vis<CR>')
809    screen:expect([[
810      ^                                                            |
811      {1:~                                                           }|*10
812                                                                  |
813    ]])
814    assert_alive()
815  end)
816
817  it('works with :lua debug.debug()', function()
818    feed(':lua debug.debug()<CR>')
819    screen:expect({
820      grid = [[
821        ^                         |
822        {1:~                        }|*3
823                                 |
824      ]],
825      cmdline = { { content = { { '' } }, pos = 0, prompt = 'lua_debug> ' } },
826    })
827    feed('print("foo")<CR>')
828    screen:expect({
829      grid = [[
830                                 |
831        {1:~                        }|*3
832        foo^                      |
833      ]],
834      cmdline = { { content = { { '' } }, pos = 0, prompt = 'lua_debug> ' } },
835      cmdline_block = { { { 'lua_debug> print("foo")' } } },
836    })
837    feed('<Esc>')
838    screen:expect({
839      grid = [[
840        ^                         |
841        {1:~                        }|*3
842                                 |
843      ]],
844      cmdline = { { abort = true } },
845    })
846  end)
847end
848
849-- the representation of cmdline and cmdline_block contents changed with ext_linegrid
850-- (which uses indexed highlights) so make sure to test both
851describe('ui/ext_cmdline', function()
852  test_cmdline(true)
853end)
854describe('ui/ext_cmdline (legacy highlights)', function()
855  test_cmdline(false)
856end)
857
858describe('cmdline redraw', function()
859  local screen
860  before_each(function()
861    clear()
862    screen = Screen.new(25, 5, { rgb = true })
863  end)
864
865  it('with timer', function()
866    feed(':012345678901234567890123456789')
867    screen:expect([[
868                               |
869      {1:~                        }|
870      {3:                         }|
871      :012345678901234567890123|
872      456789^                   |
873    ]])
874    command('call timer_start(0, {-> 1})')
875    screen:expect_unchanged()
876  end)
877
878  it('with <Cmd>', function()
879    if is_os('bsd') then
880      pending('FIXME #10804')
881    end
882    command('cmap a <Cmd>call sin(0)<CR>') -- no-op
883    feed(':012345678901234567890123456789')
884    screen:expect([[
885                               |
886      {1:~                        }|
887      {3:                         }|
888      :012345678901234567890123|
889      456789^                   |
890    ]])
891    feed('a')
892    screen:expect_unchanged()
893  end)
894
895  it('after pressing Ctrl-C in cmdwin in Visual mode #18967', function()
896    screen:try_resize(40, 10)
897    command('set cmdwinheight=3')
898    feed('q:iabc<Esc>vhh')
899    screen:expect([[
900                                              |
901      {1:~                                       }|*3
902      {2:[No Name]                               }|
903      {1::}{17:^abc}                                    |
904      {1:~                                       }|*2
905      {3:[Command Line]                          }|
906      {5:-- VISUAL --}                            |
907    ]])
908    -- Ctrl-C closes cmdwin and drops back into pre-filled cmdline. #40312
909    feed('<C-C>')
910    screen:expect([[
911                                              |
912      {1:~                                       }|*8
913      :abc^                                    |
914    ]])
915  end)
916
917  it('with rightleftcmd', function()
918    command('set rightleft rightleftcmd=search shortmess+=s')
919    api.nvim_buf_set_lines(0, 0, -1, true, { "let's rock!" })
920    screen:expect([[
921                    !kcor s'te^l|
922      {1:                        ~}|*3
923                               |
924    ]])
925
926    feed '/'
927    screen:expect([[
928                    !kcor s'tel|
929      {1:                        ~}|*3
930                             ^ /|
931    ]])
932
933    feed "let's"
934    -- note: cursor looks off but looks alright in real use
935    -- when rendered as a block so it touches the end of the text
936    screen:expect([[
937                    !kcor {2:s'tel}|
938      {1:                        ~}|*3
939                        ^ s'tel/|
940    ]])
941
942    -- cursor movement
943    feed '<space>'
944    screen:expect([[
945                    !kcor{2: s'tel}|
946      {1:                        ~}|*3
947                       ^  s'tel/|
948    ]])
949
950    feed 'rock'
951    screen:expect([[
952                    !{2:kcor s'tel}|
953      {1:                        ~}|*3
954                   ^ kcor s'tel/|
955    ]])
956
957    feed '<right>'
958    screen:expect([[
959                    !{2:kcor s'tel}|
960      {1:                        ~}|*3
961                    ^kcor s'tel/|
962    ]])
963
964    feed '<left>'
965    screen:expect([[
966                    !{2:kcor s'tel}|
967      {1:                        ~}|*3
968                   ^ kcor s'tel/|
969    ]])
970
971    feed '<cr>'
972    screen:expect([[
973                    !{10:kcor s'te^l}|
974      {1:                        ~}|*3
975      kcor s'tel/              |
976    ]])
977  end)
978
979  it('prompt with silent mapping and screen update', function()
980    command([[nmap <silent> T :call confirm("Save changes?", "&Yes\n&No\n&Cancel")<CR>]])
981    feed('T')
982    screen:expect([[
983                               |
984      {3:                         }|
985                               |
986      {6:Save changes?}            |
987      {6:[Y]es, (N)o, (C)ancel: }^  |
988    ]])
989    command('call setline(1, "foo") | redraw')
990    screen:expect([[
991      foo                      |
992      {3:                         }|
993                               |
994      {6:Save changes?}            |
995      {6:[Y]es, (N)o, (C)ancel: }^  |
996    ]])
997    feed('Y')
998    screen:expect([[
999      ^foo                      |
1000      {1:~                        }|*3
1001                               |
1002    ]])
1003    screen:try_resize(75, screen._height)
1004    feed(':call inputlist(["foo", "bar"])<CR>')
1005    screen:expect([[
1006      foo                                                                        |
1007      {3:                                                                           }|
1008      foo                                                                        |
1009      bar                                                                        |
1010      Type number and <Enter> (q or empty cancels): ^                             |
1011    ]])
1012    command('redraw')
1013    screen:expect_unchanged()
1014
1015    command('set keymap=dvorak')
1016    feed('<C-^>')
1017    command('redraw')
1018    screen:expect_unchanged()
1019
1020    feed('<C-^>')
1021    command('set keymap&')
1022    command('redraw')
1023    screen:expect_unchanged()
1024  end)
1025
1026  it('substitute confirm prompt does not scroll', function()
1027    screen:try_resize(75, screen._height)
1028    command('call setline(1, "foo")')
1029    command('set report=0')
1030    feed(':%s/foo/bar/c<CR>')
1031    screen:expect([[
1032      {2:foo}                                                                        |
1033      {1:~                                                                          }|*3
1034      {6:replace with bar? (y)es/(n)o/(a)ll/(q)uit/(l)ast/scroll up(^E)/down(^Y)}^    |
1035    ]])
1036    feed('y')
1037    screen:expect([[
1038      ^bar                                                                        |
1039      {1:~                                                                          }|*3
1040      1 substitution on 1 line                                                   |
1041    ]])
1042  end)
1043
1044  it('no empty cmdline after empty echo #18274', function()
1045    feed(':foo')
1046    api.nvim_echo({ { '' } }, false, {})
1047    screen:expect([[
1048                               |
1049      {1:~                        }|*3
1050      :foo^                     |
1051    ]])
1052    feed(('o'):rep(screen._width - 4))
1053    -- No repeated cmdline redraws at screen width
1054    screen:expect([[
1055                               |
1056      {1:~                        }|
1057      {3:                         }|
1058      :fooooooooooooooooooooooo|
1059      ^                         |
1060    ]])
1061    command('call timer_start(0, {-> 1})')
1062    screen:expect_unchanged()
1063  end)
1064end)
1065
1066describe('statusline is redrawn on entering cmdline', function()
1067  local screen
1068
1069  before_each(function()
1070    clear()
1071    screen = Screen.new(25, 5)
1072    command('set laststatus=2')
1073  end)
1074
1075  it('from normal mode', function()
1076    command('set statusline=%{mode()}')
1077    screen:expect([[
1078      ^                         |
1079      {1:~                        }|*2
1080      {3:n                        }|
1081                               |
1082    ]])
1083
1084    feed(':')
1085    screen:expect([[
1086                               |
1087      {1:~                        }|*2
1088      {3:c                        }|
1089      :^                        |
1090    ]])
1091  end)
1092
1093  it('from normal mode when : is mapped', function()
1094    command('set statusline=%{mode()}')
1095    command('nnoremap ; :')
1096
1097    screen:expect([[
1098      ^                         |
1099      {1:~                        }|*2
1100      {3:n                        }|
1101                               |
1102    ]])
1103
1104    feed(';')
1105    screen:expect([[
1106                               |
1107      {1:~                        }|*2
1108      {3:c                        }|
1109      :^                        |
1110    ]])
1111  end)
1112
1113  it('with scrolled messages', function()
1114    screen:try_resize(35, 14)
1115    exec([[
1116      let g:count = 0
1117      autocmd CmdlineEnter * let g:count += 1
1118      split
1119      resize 1
1120      setlocal statusline=%{mode()}%{g:count}
1121      setlocal winbar=%{mode()}%{g:count}
1122    ]])
1123    feed(':echoerr doesnotexist<cr>')
1124    screen:expect([[
1125      {5:c1                                 }|
1126                                         |
1127      {3:c1                                 }|
1128                                         |
1129      {1:~                                  }|*5
1130      {3:                                   }|
1131      {9:E121: Undefined variable: doesnotex}|
1132      {9:ist}                                |
1133      {6:Press ENTER or type command to cont}|
1134      {6:inue}^                               |
1135    ]])
1136    feed(':echoerr doesnotexist<cr>')
1137    screen:expect([[
1138      {5:c2                                 }|
1139                                         |
1140      {3:c2                                 }|
1141                                         |
1142      {1:~                                  }|*2
1143      {3:                                   }|
1144      {9:E121: Undefined variable: doesnotex}|
1145      {9:ist}                                |
1146      {6:Press ENTER or type command to cont}|
1147      {9:E121: Undefined variable: doesnotex}|
1148      {9:ist}                                |
1149      {6:Press ENTER or type command to cont}|
1150      {6:inue}^                               |
1151    ]])
1152
1153    feed(':echoerr doesnotexist<cr>')
1154    screen:expect([[
1155      {5:c3                                 }|
1156                                         |
1157      {3:c3                                 }|
1158      {3:                                   }|
1159      {9:E121: Undefined variable: doesnotex}|
1160      {9:ist}                                |
1161      {6:Press ENTER or type command to cont}|
1162      {9:E121: Undefined variable: doesnotex}|
1163      {9:ist}                                |
1164      {6:Press ENTER or type command to cont}|
1165      {9:E121: Undefined variable: doesnotex}|
1166      {9:ist}                                |
1167      {6:Press ENTER or type command to cont}|
1168      {6:inue}^                               |
1169    ]])
1170
1171    feed('<cr>')
1172    screen:expect([[
1173      {5:n3                                 }|
1174      ^                                   |
1175      {3:n3                                 }|
1176                                         |
1177      {1:~                                  }|*8
1178      {2:[No Name]                          }|
1179                                         |
1180    ]])
1181  end)
1182
1183  describe('if custom statusline is set by', function()
1184    before_each(function()
1185      command('set statusline=')
1186      screen:expect([[
1187        ^                         |
1188        {1:~                        }|*2
1189        {3:[No Name]                }|
1190                                 |
1191      ]])
1192    end)
1193
1194    it('CmdlineEnter autocommand', function()
1195      command('autocmd CmdlineEnter * set statusline=command')
1196      feed(':')
1197      screen:expect([[
1198                                 |
1199        {1:~                        }|*2
1200        {3:command                  }|
1201        :^                        |
1202      ]])
1203    end)
1204
1205    it('ModeChanged autocommand', function()
1206      command('autocmd ModeChanged *:c set statusline=command')
1207      feed(':')
1208      screen:expect([[
1209                                 |
1210        {1:~                        }|*2
1211        {3:command                  }|
1212        :^                        |
1213      ]])
1214    end)
1215  end)
1216end)
1217
1218it('tabline is not redrawn in Ex mode #24122', function()
1219  clear()
1220  local screen = Screen.new(60, 8)
1221
1222  exec([[
1223    set showtabline=2
1224    set tabline=%!MyTabLine()
1225
1226    function! MyTabLine()
1227
1228      return "foo"
1229    endfunction
1230  ]])
1231
1232  feed('1q:')
1233  screen:expect([[
1234    {2:foo                                                         }|
1235                                                                |
1236    {2:[No Name]                                                   }|
1237    {1::}^                                                           |
1238    {1:~                                                           }|*2
1239    {3:[Ex mode]                                                   }|
1240    {5:-- INSERT --}                                                |
1241  ]])
1242  feed('echo 1<CR>')
1243  screen:expect([[
1244    {2:foo                                                         }|
1245                                                                |
1246    {2:[No Name]                                                   }|
1247    {1::}echo 1                                                     |
1248    {1::}" 1                                                        |
1249    {1::}^                                                           |
1250    {3:[Ex mode]                                                   }|
1251    {5:-- INSERT --}                                                |
1252  ]])
1253end)
1254
1255describe('cmdline height', function()
1256  before_each(clear)
1257
1258  it('does not crash resized screen #14263', function()
1259    local screen = Screen.new(25, 10)
1260    command('set cmdheight=9999')
1261    screen:try_resize(25, 5)
1262    assert_alive()
1263  end)
1264
1265  it('unchanged when restoring window sizes with global statusline', function()
1266    command('set cmdheight=2 laststatus=2')
1267    feed('q:')
1268    command('set cmdheight=1 laststatus=3 | quit')
1269    -- Available lines changed, so closing cmdwin should skip restoring window sizes, leaving the
1270    -- cmdheight unchanged.
1271    eq(1, eval('&cmdheight'))
1272  end)
1273
1274  it('not increased to 0 from 1 with wincmd _', function()
1275    command('set cmdheight=0 laststatus=0')
1276    command('wincmd _')
1277    eq(0, eval('&cmdheight'))
1278  end)
1279end)
1280
1281describe('cmdheight=0', function()
1282  local screen
1283  before_each(function()
1284    clear()
1285    screen = Screen.new(25, 5)
1286  end)
1287
1288  it('with redrawdebug=invalid resize -1', function()
1289    command('set redrawdebug=invalid cmdheight=0 noruler laststatus=0')
1290    screen:expect([[
1291      ^                         |
1292      {1:~                        }|*4
1293    ]])
1294    feed(':resize -1<CR>')
1295    screen:expect([[
1296      ^                         |
1297      {1:~                        }|*3
1298                               |
1299    ]])
1300    assert_alive()
1301  end)
1302
1303  it('with cmdheight=1 noruler laststatus=2', function()
1304    command('set cmdheight=1 noruler laststatus=2')
1305    screen:expect([[
1306      ^                         |
1307      {1:~                        }|*2
1308      {3:[No Name]                }|
1309                               |
1310    ]])
1311  end)
1312
1313  it('with cmdheight=0 noruler laststatus=2', function()
1314    command('set cmdheight=0 noruler laststatus=2')
1315    screen:expect([[
1316      ^                         |
1317      {1:~                        }|*3
1318      {3:[No Name]                }|
1319    ]])
1320  end)
1321
1322  it('with cmdheight=0 ruler laststatus=0', function()
1323    command('set cmdheight=0 ruler laststatus=0')
1324    screen:expect([[
1325      ^                         |
1326      {1:~                        }|*4
1327    ]])
1328  end)
1329
1330  it('with cmdheight=0 ruler laststatus=0', function()
1331    command('set cmdheight=0 noruler laststatus=0 showmode')
1332    feed('i')
1333    screen:expect {
1334      grid = [[
1335        ^                         |
1336        {1:~                        }|*4
1337      ]],
1338      showmode = {},
1339    }
1340    feed('<Esc>')
1341    eq(0, eval('&cmdheight'))
1342  end)
1343
1344  it('with cmdheight=0 ruler rulerformat laststatus=0', function()
1345    command('set cmdheight=0 noruler laststatus=0 rulerformat=%l,%c%= showmode')
1346    feed('i')
1347    screen:expect {
1348      grid = [[
1349        ^                         |
1350        {1:~                        }|*4
1351      ]],
1352      showmode = {},
1353    }
1354    feed('<Esc>')
1355    eq(0, eval('&cmdheight'))
1356  end)
1357
1358  it('with showmode', function()
1359    command('set cmdheight=1 noruler laststatus=0 showmode')
1360    feed('i')
1361    screen:expect([[
1362      ^                         |
1363      {1:~                        }|*3
1364      {5:-- INSERT --}             |
1365    ]])
1366    feed('<Esc>')
1367    eq(1, eval('&cmdheight'))
1368  end)
1369
1370  it('when using command line', function()
1371    command('set cmdheight=0 noruler laststatus=0')
1372    feed(':')
1373    screen:expect([[
1374                               |
1375      {1:~                        }|*3
1376      :^                        |
1377    ]])
1378    eq(0, eval('&cmdheight'))
1379    feed('<cr>')
1380    screen:expect {
1381      grid = [[
1382        ^                         |
1383        {1:~                        }|*4
1384      ]],
1385      showmode = {},
1386    }
1387    eq(0, eval('&cmdheight'))
1388  end)
1389
1390  it('when using input()', function()
1391    command('set cmdheight=0 noruler laststatus=0')
1392    feed(':call input("foo >")<cr>')
1393    screen:expect([[
1394                               |
1395      {1:~                        }|
1396      {3:                         }|
1397      :call input("foo >")     |
1398      foo >^                    |
1399    ]])
1400    eq(0, eval('&cmdheight'))
1401    feed('<cr>')
1402    screen:expect {
1403      grid = [[
1404        ^                         |
1405        {1:~                        }|*4
1406      ]],
1407      showmode = {},
1408    }
1409    eq(0, eval('&cmdheight'))
1410  end)
1411
1412  it('with winbar and splits', function()
1413    command('set cmdheight=0 noruler laststatus=3 winbar=foo')
1414    feed(':split<CR>')
1415    screen:expect([[
1416      {3:                         }|
1417      :split                   |
1418      {9:E36: Not enough room}     |
1419      {6:Press ENTER or type comma}|
1420      {6:nd to continue}^           |
1421    ]])
1422    feed('<CR>')
1423    screen:expect([[
1424      {5:foo                      }|
1425      ^                         |
1426      {1:~                        }|*2
1427      {3:[No Name]                }|
1428    ]])
1429    feed(':')
1430    screen:expect([[
1431      {5:foo                      }|
1432                               |
1433      {1:~                        }|*2
1434      :^                        |
1435    ]])
1436    feed('<Esc>')
1437    screen:expect {
1438      grid = [[
1439        {5:foo                      }|
1440        ^                         |
1441        {1:~                        }|*2
1442        {3:[No Name]                }|
1443      ]],
1444      showmode = {},
1445    }
1446    eq(0, eval('&cmdheight'))
1447
1448    assert_alive()
1449  end)
1450
1451  it('when macro with lastline', function()
1452    command('set cmdheight=0 display=lastline')
1453    feed('qq')
1454    screen:expect([[
1455      ^                         |
1456      {1:~                        }|*4
1457    ]])
1458    feed('q')
1459    screen:expect {
1460      grid = [[
1461        ^                         |
1462        {1:~                        }|*4
1463      ]],
1464      unchanged = true,
1465    }
1466  end)
1467
1468  it('when substitute text', function()
1469    command('set cmdheight=0 noruler laststatus=3')
1470    feed('ifoo<ESC>')
1471    screen:try_resize(screen._width, 7)
1472    screen:expect([[
1473      fo^o                      |
1474      {1:~                        }|*5
1475      {3:[No Name] [+]            }|
1476    ]])
1477
1478    feed(':%s/foo/bar/gc<CR>')
1479    screen:expect([[
1480      {2:foo}                      |
1481      {3:                         }|
1482                               |*2
1483      {6:replace with bar? (y)es/(}|
1484      {6:n)o/(a)ll/(q)uit/(l)ast/s}|
1485      {6:croll up(^E)/down(^Y)}^    |
1486    ]])
1487
1488    feed('y')
1489    screen:expect([[
1490      ^bar                      |
1491      {1:~                        }|*5
1492      {3:[No Name] [+]            }|
1493    ]])
1494
1495    assert_alive()
1496  end)
1497
1498  it('when window resize', function()
1499    command('set cmdheight=0')
1500    feed('<C-w>+')
1501    eq(0, eval('&cmdheight'))
1502  end)
1503
1504  it('with non-silent mappings with cmdline', function()
1505    command('set cmdheight=0')
1506    command('map <f3> :nohlsearch<cr>')
1507    feed('iaabbaa<esc>/aa<cr>')
1508    screen:expect([[
1509      {10:^aa}bb{10:aa}                   |
1510      {1:~                        }|*4
1511    ]])
1512
1513    feed('<f3>')
1514    screen:expect([[
1515      ^aabbaa                   |
1516      {1:~                        }|*4
1517    ]])
1518  end)
1519
1520  it('with silent! at startup', function()
1521    clear { args = { '-c', 'set cmdheight=0', '-c', 'autocmd VimEnter * silent! call Foo()' } }
1522    screen = Screen.new(25, 5)
1523    -- doesn't crash while not displaying silent! error message
1524    screen:expect([[
1525      ^                         |
1526      {1:~                        }|*4
1527    ]])
1528  end)
1529
1530  it('with multigrid', function()
1531    clear { args = { '--cmd', 'set cmdheight=0' } }
1532    screen = Screen.new(25, 5, { ext_multigrid = true })
1533    api.nvim_buf_set_lines(0, 0, -1, true, { 'p' })
1534    screen:expect {
1535      grid = [[
1536      ## grid 1
1537        [2:-------------------------]|*5
1538      ## grid 2
1539        ^p                        |
1540        {1:~                        }|*4
1541      ## grid 3
1542      ]],
1543      win_viewport = {
1544        [2] = {
1545          win = 1000,
1546          topline = 0,
1547          botline = 2,
1548          curline = 0,
1549          curcol = 0,
1550          linecount = 1,
1551          sum_scroll_delta = 0,
1552        },
1553      },
1554    }
1555
1556    feed '/p'
1557    screen:expect {
1558      grid = [[
1559      ## grid 1
1560        [2:-------------------------]|*4
1561        [3:-------------------------]|
1562      ## grid 2
1563        {2:p}                        |
1564        {1:~                        }|*4
1565      ## grid 3
1566        /p^                       |
1567      ]],
1568      win_viewport = {
1569        [2] = {
1570          win = 1000,
1571          topline = 0,
1572          botline = 2,
1573          curline = 0,
1574          curcol = 1,
1575          linecount = 1,
1576          sum_scroll_delta = 0,
1577        },
1578      },
1579    }
1580  end)
1581
1582  it('winbar is redrawn on entering cmdline and :redrawstatus #20336', function()
1583    exec([[
1584      set cmdheight=0
1585      set winbar=%{mode()}%=:%{getcmdline()}
1586    ]])
1587    feed(':')
1588    screen:expect([[
1589      {5:c                       :}|
1590                               |
1591      {1:~                        }|*2
1592      :^                        |
1593    ]])
1594    feed('echo')
1595    -- not redrawn yet
1596    screen:expect([[
1597      {5:c                       :}|
1598                               |
1599      {1:~                        }|*2
1600      :echo^                    |
1601    ]])
1602    command('redrawstatus')
1603    screen:expect([[
1604      {5:c                   :echo}|
1605                               |
1606      {1:~                        }|*2
1607      :echo^                    |
1608    ]])
1609  end)
1610
1611  it('window equalization with laststatus=0 #20367', function()
1612    screen:try_resize(60, 9)
1613    command('set cmdheight=0 laststatus=0')
1614    command('vsplit')
1615    screen:expect([[
1616      ^                              │                             |
1617      {1:~                             }│{1:~                            }|*8
1618    ]])
1619    feed(':')
1620    command('split')
1621    feed('<Esc>')
1622    screen:expect([[
1623      ^                              │                             |
1624      {1:~                             }│{1:~                            }|*3
1625      {3:[No Name]                     }│{1:~                            }|
1626                                    │{1:~                            }|
1627      {1:~                             }│{1:~                            }|*3
1628    ]])
1629    command('resize 2')
1630    screen:expect([[
1631      ^                              │                             |
1632      {1:~                             }│{1:~                            }|
1633      {3:[No Name]                     }│{1:~                            }|
1634                                    │{1:~                            }|
1635      {1:~                             }│{1:~                            }|*5
1636    ]])
1637    feed(':')
1638    command('wincmd =')
1639    feed('<Esc>')
1640    screen:expect([[
1641      ^                              │                             |
1642      {1:~                             }│{1:~                            }|*3
1643      {3:[No Name]                     }│{1:~                            }|
1644                                    │{1:~                            }|
1645      {1:~                             }│{1:~                            }|*3
1646    ]])
1647  end)
1648
1649  it('no assert failure with showcmd', function()
1650    command('set showcmd cmdheight=0')
1651    feed('d')
1652    screen:expect([[
1653      ^                         |
1654      {1:~                        }|*4
1655    ]])
1656    assert_alive()
1657  end)
1658
1659  it('can only be resized to 0 if set explicitly', function()
1660    command('set laststatus=2')
1661    command('resize +1')
1662    screen:expect([[
1663      ^                         |
1664      {1:~                        }|*2
1665      {3:[No Name]                }|
1666                               |
1667    ]])
1668    command('set cmdheight=0')
1669    screen:expect([[
1670      ^                         |
1671      {1:~                        }|*3
1672      {3:[No Name]                }|
1673    ]])
1674    command('resize -1')
1675    screen:expect([[
1676      ^                         |
1677      {1:~                        }|*2
1678      {3:[No Name]                }|
1679                               |
1680    ]])
1681    command('resize +1')
1682    screen:expect([[
1683      ^                         |
1684      {1:~                        }|*3
1685      {3:[No Name]                }|
1686    ]])
1687  end)
1688
1689  it('can be resized with external messages', function()
1690    clear()
1691    screen = Screen.new(25, 5, { rgb = true, ext_messages = true })
1692    command('set laststatus=2 mouse=a')
1693    command('resize -1')
1694    screen:expect([[
1695      ^                         |
1696      {1:~                        }|*2
1697      {3:[No Name]                }|
1698                               |
1699    ]])
1700    api.nvim_input_mouse('left', 'press', '', 0, 3, 10)
1701    poke_eventloop()
1702    api.nvim_input_mouse('left', 'drag', '', 0, 4, 10)
1703    screen:expect([[
1704      ^                         |
1705      {1:~                        }|*3
1706      {3:[No Name]                }|
1707    ]])
1708  end)
1709
1710  it('no spurious newline before first message with --headless mode', function()
1711    local p = n.spawn_wait({
1712      args = { '--cmd', 'set cmdheight=0', '-c', 'echo 1', '+q' },
1713    })
1714    eq('1', p.stderr)
1715  end)
1716end)