robin/laufey

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

zeertzjqvim-patch:9.2.0985: Multiline messages not visible when mapping starts cmdline (#41405)af37d459a6

master
29.4 KiB890 linesraw
1" Tests for :messages, :echomsg, :echoerr
2
3source check.vim
4source shared.vim
5source term_util.vim
6source view_util.vim
7source screendump.vim
8
9func Test_messages()
10  let oldmore = &more
11  try
12    set nomore
13
14    let arr = map(range(10), '"hello" . v:val')
15    for s in arr
16      echomsg s | redraw
17    endfor
18
19    " get last two messages
20    redir => result
21    2messages | redraw
22    redir END
23    let msg_list = split(result, "\n")
24    call assert_equal(["hello8", "hello9"], msg_list)
25
26    " clear messages without last one
27    1messages clear
28    let msg_list = GetMessages()
29    call assert_equal(['hello9'], msg_list)
30
31    " clear all messages
32    messages clear
33    let msg_list = GetMessages()
34    call assert_equal([], msg_list)
35  finally
36    let &more = oldmore
37  endtry
38
39  call assert_fails('message 1', 'E474:')
40endfunc
41
42 " Patch 7.4.1696 defined the "clearmode()" command for clearing the mode
43" indicator (e.g., "-- INSERT --") when ":stopinsert" is invoked.  Message
44" output could then be disturbed when 'cmdheight' was greater than one.
45" This test ensures that the bugfix for this issue remains in place.
46func Test_stopinsert_does_not_break_message_output()
47  set cmdheight=2
48  redraw!
49
50   stopinsert | echo 'test echo'
51  call assert_equal(116, screenchar(&lines - 1, 1))
52  call assert_equal(32, screenchar(&lines, 1))
53  redraw!
54
55   stopinsert | echomsg 'test echomsg'
56  call assert_equal(116, screenchar(&lines - 1, 1))
57  call assert_equal(32, screenchar(&lines, 1))
58  redraw!
59
60   set cmdheight&
61endfunc
62
63func Test_message_completion()
64  call feedkeys(":message \<C-A>\<C-B>\"\<CR>", 'tx')
65  call assert_equal('"message clear', @:)
66endfunc
67
68func Test_echomsg()
69  call assert_equal("\nhello", execute(':echomsg "hello"'))
70  call assert_equal("\n", execute(':echomsg ""'))
71  call assert_equal("\n12345", execute(':echomsg 12345'))
72  call assert_equal("\n[]", execute(':echomsg []'))
73  call assert_equal("\n[1, 2, 3]", execute(':echomsg [1, 2, 3]'))
74  call assert_equal("\n[1, 2, []]", execute(':echomsg [1, 2, v:_null_list]'))
75  call assert_equal("\n{}", execute(':echomsg {}'))
76  call assert_equal("\n{'a': 1, 'b': 2}", execute(':echomsg {"a": 1, "b": 2}'))
77  if has('float')
78    call assert_equal("\n1.23", execute(':echomsg 1.23'))
79  endif
80  call assert_match("function('<lambda>\\d*')", execute(':echomsg {-> 1234}'))
81endfunc
82
83func Test_echoerr()
84  CheckFunction test_ignore_error
85  call test_ignore_error('IgNoRe')
86  call assert_equal("\nIgNoRe hello", execute(':echoerr "IgNoRe hello"'))
87  call assert_equal("\n12345 IgNoRe", execute(':echoerr 12345 "IgNoRe"'))
88  call assert_equal("\n[1, 2, 'IgNoRe']", execute(':echoerr [1, 2, "IgNoRe"]'))
89  call assert_equal("\n{'IgNoRe': 2, 'a': 1}", execute(':echoerr {"a": 1, "IgNoRe": 2}'))
90  if has('float')
91    call assert_equal("\n1.23 IgNoRe", execute(':echoerr 1.23 "IgNoRe"'))
92  endif
93  eval '<lambda>'->test_ignore_error()
94  call assert_match("function('<lambda>\\d*')", execute(':echoerr {-> 1234}'))
95  call test_ignore_error('RESET')
96endfunc
97
98func Test_mode_message_at_leaving_insert_by_ctrl_c()
99  if !has('terminal') || has('gui_running')
100    return
101  endif
102
103  " Set custom statusline built by user-defined function.
104  let testfile = 'Xtest.vim'
105  call writefile([
106        \ 'func StatusLine() abort',
107        \ '  return ""',
108        \ 'endfunc',
109        \ 'set statusline=%!StatusLine()',
110        \ 'set laststatus=2',
111        \ ], testfile)
112
113  let rows = 10
114  let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows})
115  call TermWait(buf, 100)
116  call assert_equal('run', job_status(term_getjob(buf)))
117
118  call term_sendkeys(buf, "i")
119  call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, rows))})
120  call term_sendkeys(buf, "\<C-C>")
121  call WaitForAssert({-> assert_match('^\s*$', term_getline(buf, rows))})
122
123  call term_sendkeys(buf, ":qall!\<CR>")
124  call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))})
125  exe buf . 'bwipe!'
126  call delete(testfile)
127endfunc
128
129func Test_mode_message_at_leaving_insert_with_esc_mapped()
130  if !has('terminal') || has('gui_running')
131    return
132  endif
133
134  " Set custom statusline built by user-defined function.
135  let testfile = 'Xtest.vim'
136  call writefile([
137        \ 'set laststatus=2',
138        \ 'inoremap <Esc> <Esc>00',
139        \ ], testfile)
140
141  let rows = 10
142  let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows})
143  call WaitForAssert({-> assert_match('0,0-1\s*All$', term_getline(buf, rows - 1))})
144  call assert_equal('run', job_status(term_getjob(buf)))
145
146  call term_sendkeys(buf, "i")
147  call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, rows))})
148  call term_sendkeys(buf, "\<Esc>")
149  call WaitForAssert({-> assert_match('^\s*$', term_getline(buf, rows))})
150
151  call term_sendkeys(buf, ":qall!\<CR>")
152  call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))})
153  exe buf . 'bwipe!'
154  call delete(testfile)
155endfunc
156
157func Test_echospace()
158  set noruler noshowcmd laststatus=1
159  call assert_equal(&columns - 1, v:echospace)
160  split
161  call assert_equal(&columns - 1, v:echospace)
162  set ruler
163  call assert_equal(&columns - 1, v:echospace)
164  close
165  call assert_equal(&columns - 19, v:echospace)
166  set showcmd noruler
167  call assert_equal(&columns - 12, v:echospace)
168  set showcmd ruler
169  call assert_equal(&columns - 29, v:echospace)
170  set showcmdloc=statusline
171  call assert_equal(&columns - 19, v:echospace)
172  set showcmdloc=tabline
173  call assert_equal(&columns - 19, v:echospace)
174  call assert_fails('set showcmdloc=leap', 'E474:')
175  call assert_equal(&columns - 19, v:echospace)
176  set showcmdloc=last
177  call assert_equal(&columns - 29, v:echospace)
178  call assert_fails('set showcmdloc=jump', 'E474:')
179  call assert_equal(&columns - 29, v:echospace)
180
181  set ruler& showcmd& showcmdloc&
182endfunc
183
184func Test_warning_scroll()
185  CheckRunVimInTerminal
186  let lines =<< trim END
187      call test_override('ui_delay', 50)
188      set noruler
189      set readonly
190      undo
191  END
192  call writefile(lines, 'XTestWarningScroll', 'D')
193  let buf = RunVimInTerminal('', #{rows: 8})
194
195  " When the warning comes from a script, messages are scrolled so that the
196  " stacktrace is visible.
197  call term_sendkeys(buf, ":source XTestWarningScroll\n")
198  " only match the final colon in the line that shows the source
199  call WaitForAssert({-> assert_match(':$', term_getline(buf, 5))})
200  call WaitForAssert({-> assert_equal('line    4:W10: Warning: Changing a readonly file', term_getline(buf, 6))})
201  call WaitForAssert({-> assert_equal('Already at oldest change', term_getline(buf, 7))})
202  call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 8))})
203  call term_sendkeys(buf, "\n")
204
205  " When the warning does not come from a script, messages are not scrolled.
206  call term_sendkeys(buf, ":enew\n")
207  call term_sendkeys(buf, ":set readonly\n")
208  call term_sendkeys(buf, 'u')
209  call WaitForAssert({-> assert_equal('W10: Warning: Changing a readonly file', term_getline(buf, 8))})
210  call WaitForAssert({-> assert_equal('Already at oldest change', term_getline(buf, 8))})
211
212  " clean up
213  call StopVimInTerminal(buf)
214endfunc
215
216" Test more-prompt (see :help more-prompt).
217func Test_message_more()
218  CheckRunVimInTerminal
219
220  let buf = RunVimInTerminal('', {'rows': 6})
221  let chan = buf->term_getjob()->job_getchannel()
222  call term_sendkeys(buf, ":call setline(1, range(1, 100))\n")
223
224  call term_sendkeys(buf, ":%pfoo\<C-H>\<C-H>\<C-H>#")
225  call WaitForAssert({-> assert_equal(':%p#', term_getline(buf, 6))})
226  call term_sendkeys(buf, "\n")
227  call WaitForAssert({-> assert_equal('  5 5', term_getline(buf, 5))})
228  call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
229
230  call term_sendkeys(buf, '?')
231  call WaitForAssert({-> assert_equal('  5 5', term_getline(buf, 5))})
232  call WaitForAssert({-> assert_equal('-- More -- SPACE/d/j: screen/page/line down, b/u/k: up, q: quit ', term_getline(buf, 6))})
233
234  " Down a line with j, <CR>, <NL> or <Down>.
235  call term_sendkeys(buf, "j")
236  call WaitForAssert({-> assert_equal('  6 6', term_getline(buf, 5))})
237  call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
238  call term_sendkeys(buf, "\<NL>")
239  call WaitForAssert({-> assert_equal('  7 7', term_getline(buf, 5))})
240  call term_sendkeys(buf, "\<CR>")
241  call WaitForAssert({-> assert_equal('  8 8', term_getline(buf, 5))})
242  call term_sendkeys(buf, "\<Down>")
243  call WaitForAssert({-> assert_equal('  9 9', term_getline(buf, 5))})
244
245  " Down a screen with <Space>, f, <C-F> or <PageDown>.
246  call term_sendkeys(buf, 'f')
247  call WaitForAssert({-> assert_equal(' 14 14', term_getline(buf, 5))})
248  call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
249  call term_sendkeys(buf, "\<C-F>")
250  call WaitForAssert({-> assert_equal(' 19 19', term_getline(buf, 5))})
251  call term_sendkeys(buf, ' ')
252  call WaitForAssert({-> assert_equal(' 24 24', term_getline(buf, 5))})
253  call term_sendkeys(buf, "\<PageDown>")
254  call WaitForAssert({-> assert_equal(' 29 29', term_getline(buf, 5))})
255
256  " Down a page (half a screen) with d.
257  call term_sendkeys(buf, 'd')
258  call WaitForAssert({-> assert_equal(' 32 32', term_getline(buf, 5))})
259
260  " Down all the way with 'G'.
261  call term_sendkeys(buf, 'G')
262  call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))})
263  call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
264
265  " Up a line k, <BS> or <Up>.
266  call term_sendkeys(buf, 'k')
267  call WaitForAssert({-> assert_equal(' 99 99', term_getline(buf, 5))})
268  call term_sendkeys(buf, "\<BS>")
269  call WaitForAssert({-> assert_equal(' 98 98', term_getline(buf, 5))})
270  call term_sendkeys(buf, "\<Up>")
271  call WaitForAssert({-> assert_equal(' 97 97', term_getline(buf, 5))})
272
273  " Up a screen with b, <C-B> or <PageUp>.
274  call term_sendkeys(buf, 'b')
275  call WaitForAssert({-> assert_equal(' 92 92', term_getline(buf, 5))})
276  call term_sendkeys(buf, "\<C-B>")
277  call WaitForAssert({-> assert_equal(' 87 87', term_getline(buf, 5))})
278  call term_sendkeys(buf, "\<PageUp>")
279  call WaitForAssert({-> assert_equal(' 82 82', term_getline(buf, 5))})
280
281  " Up a page (half a screen) with u.
282  call term_sendkeys(buf, 'u')
283  call WaitForAssert({-> assert_equal(' 79 79', term_getline(buf, 5))})
284
285  " Test <C-F> and <C-B> with different keyboard protocols.
286  for [ctrl_f, ctrl_b] in [
287        \ [GetEscCodeCSI27('f', 5), GetEscCodeCSI27('b', 5)],
288        \ [GetEscCodeCSI27('F', 5), GetEscCodeCSI27('B', 5)],
289        \ [GetEscCodeCSIu('f', 5), GetEscCodeCSIu('b', 5)],
290        \ [GetEscCodeCSIu('F', 5), GetEscCodeCSIu('B', 5)],
291        \ ]
292    call ch_sendraw(chan, ctrl_f)
293    call WaitForAssert({-> assert_equal(' 84 84', term_getline(buf, 5))})
294    call ch_sendraw(chan, ctrl_b)
295    call WaitForAssert({-> assert_equal(' 79 79', term_getline(buf, 5))})
296  endfor
297
298  " Up all the way with 'g'.
299  call term_sendkeys(buf, 'g')
300  call WaitForAssert({-> assert_equal('  4 4', term_getline(buf, 5))})
301  call WaitForAssert({-> assert_equal(':%p#', term_getline(buf, 1))})
302  call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
303
304  " All the way down. Pressing f or Ctrl-F should do nothing but pressing
305  " space should end the more prompt.
306  call term_sendkeys(buf, 'G')
307  call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))})
308  call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
309  call term_sendkeys(buf, 'f')
310  call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))})
311  call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
312  call term_sendkeys(buf, "\<C-F>")
313  call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))})
314  call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
315  call term_sendkeys(buf, ' ')
316  call WaitForAssert({-> assert_equal('100', term_getline(buf, 5))})
317
318  " Pressing g< shows the previous command output.
319  call term_sendkeys(buf, 'g<')
320  call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))})
321  call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
322
323  " A command line that doesn't print text is appended to scrollback,
324  " even if it invokes a nested command line.
325  call term_sendkeys(buf, ":\<C-R>=':'\<CR>:\<CR>g<")
326  call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 4))})
327  call WaitForAssert({-> assert_equal(':::', term_getline(buf, 5))})
328  call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
329
330  call term_sendkeys(buf, ":%p#\n")
331  call WaitForAssert({-> assert_equal('  5 5', term_getline(buf, 5))})
332  call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
333
334  " Stop command output with q, <Esc> or CTRL-C.
335  call term_sendkeys(buf, 'q')
336  call WaitForAssert({-> assert_equal('100', term_getline(buf, 5))})
337
338  " Execute a : command from the more prompt
339  call term_sendkeys(buf, ":%p#\n")
340  call term_wait(buf)
341  call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
342  call term_sendkeys(buf, ":")
343  call term_wait(buf)
344  call WaitForAssert({-> assert_equal(':', term_getline(buf, 6))})
345  call term_sendkeys(buf, "echo 'Hello'\n")
346  call term_wait(buf)
347  call WaitForAssert({-> assert_equal('Hello ', term_getline(buf, 5))})
348
349  call StopVimInTerminal(buf)
350endfunc
351
352func Test_message_more_recording()
353  CheckRunVimInTerminal
354  let buf = RunVimInTerminal('', {'rows': 6})
355  call term_sendkeys(buf, ":call setline(1, range(1, 100))\n")
356  call term_sendkeys(buf, ":%p\n")
357  call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
358  call term_sendkeys(buf, 'G')
359  call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
360
361  " Hitting 'q' at the end of the more prompt should not start recording
362  call term_sendkeys(buf, 'q')
363  call WaitForAssert({-> assert_equal(5, term_getcursor(buf)[0])})
364  " Hitting 'k' now should move the cursor up instead of recording keys
365  call term_sendkeys(buf, 'k')
366  call WaitForAssert({-> assert_equal(4, term_getcursor(buf)[0])})
367
368  call StopVimInTerminal(buf)
369endfunc
370
371" Test more-prompt scrollback
372func Test_message_more_scrollback()
373  CheckScreendump
374  CheckRunVimInTerminal
375
376  let lines =<< trim END
377      set t_ut=
378      hi Normal ctermfg=15 ctermbg=0
379      for i in range(100)
380          echo i
381      endfor
382  END
383  call writefile(lines, 'XmoreScrollback', 'D')
384  let buf = RunVimInTerminal('-S XmoreScrollback', {'rows': 10})
385  call VerifyScreenDump(buf, 'Test_more_scrollback_1', {})
386
387  call term_sendkeys(buf, 'f')
388  call TermWait(buf)
389  call term_sendkeys(buf, 'b')
390  call VerifyScreenDump(buf, 'Test_more_scrollback_2', {})
391
392  call term_sendkeys(buf, "\<C-F>")
393  call TermWait(buf)
394  call term_sendkeys(buf, "\<C-B>")
395  call VerifyScreenDump(buf, 'Test_more_scrollback_2', {})
396
397  call term_sendkeys(buf, 'q')
398  call TermWait(buf)
399  call StopVimInTerminal(buf)
400endfunc
401
402func Test_message_not_cleared_after_mode()
403  CheckScreendump
404  CheckRunVimInTerminal
405
406  let lines =<< trim END
407      nmap <silent> gx :call DebugSilent('normal')<CR>
408      vmap <silent> gx :call DebugSilent('visual')<CR>
409      function DebugSilent(arg)
410          echomsg "from DebugSilent" a:arg
411      endfunction
412      set showmode
413      set cmdheight=1
414      call test_settime(1)
415      call setline(1, ['one', 'NoSuchFile', 'three'])
416  END
417  call writefile(lines, 'XmessageMode', 'D')
418  let buf = RunVimInTerminal('-S XmessageMode', {'rows': 10})
419
420  call term_sendkeys(buf, 'gx')
421  call TermWait(buf)
422  call VerifyScreenDump(buf, 'Test_message_not_cleared_after_mode_1', {})
423
424  " removing the mode message used to also clear the intended message
425  call term_sendkeys(buf, 'vEgx')
426  call TermWait(buf)
427  call VerifyScreenDump(buf, 'Test_message_not_cleared_after_mode_2', {})
428
429  " removing the mode message used to also clear the error message
430  call term_sendkeys(buf, ":set cmdheight=2\<CR>")
431  call term_sendkeys(buf, '2GvEgf')
432  call TermWait(buf)
433  call VerifyScreenDump(buf, 'Test_message_not_cleared_after_mode_3', {})
434
435  call StopVimInTerminal(buf)
436endfunc
437
438func Test_mode_cleared_after_silent_message()
439  CheckScreendump
440  CheckRunVimInTerminal
441
442  let lines =<< trim END
443    edit XsilentMessageMode.txt
444    call setline(1, 'foobar')
445    autocmd TextChanged * silent update
446  END
447  call writefile(lines, 'XsilentMessageMode', 'D')
448  let buf = RunVimInTerminal('-S XsilentMessageMode', {'rows': 10})
449
450  call term_sendkeys(buf, 'v')
451  call WaitForAssert({-> assert_match('VISUAL.*\d\+\s\+\d', term_getline(buf, 10))}, 1000)
452  call VerifyScreenDump(buf, 'Test_mode_cleared_after_silent_message_1', {})
453
454  call term_sendkeys(buf, 'd')
455  call TermWait(buf)
456  call VerifyScreenDump(buf, 'Test_mode_cleared_after_silent_message_2', {})
457
458  call StopVimInTerminal(buf)
459  call delete('XsilentMessageMode.txt')
460endfunc
461
462" Test verbose message before echo command
463func Test_echo_verbose_system()
464  CheckScreendump
465  CheckRunVimInTerminal
466  CheckUnix    " needs the "seq" command
467  CheckNotMac  " the macos TMPDIR is too long for snapshot testing
468
469  let buf = RunVimInTerminal('', {'rows': 10})
470  " give it some time to handle DECRQM response
471  call TermWait(buf, 50)
472  call term_sendkeys(buf, ":4 verbose echo system('seq 20')\<CR>")
473  " Note that the screendump is filtered to remove the name of the temp file
474  call VerifyScreenDump(buf, 'Test_verbose_system_1', {})
475
476  " display a page and go back, results in exactly the same view
477  call term_sendkeys(buf, ' ')
478  call TermWait(buf, 50)
479  call term_sendkeys(buf, 'b')
480  call VerifyScreenDump(buf, 'Test_verbose_system_1', {})
481
482  " do the same with 'cmdheight' set to 2
483  call term_sendkeys(buf, 'q')
484  call TermWait(buf)
485  call term_sendkeys(buf, ":set ch=2\<CR>")
486  call TermWait(buf)
487  call term_sendkeys(buf, ":4 verbose echo system('seq 20')\<CR>")
488  call VerifyScreenDump(buf, 'Test_verbose_system_2', {})
489
490  call term_sendkeys(buf, ' ')
491  call TermWait(buf, 50)
492  call term_sendkeys(buf, 'b')
493  call VerifyScreenDump(buf, 'Test_verbose_system_2', {})
494
495  call term_sendkeys(buf, 'q')
496  call TermWait(buf)
497  call StopVimInTerminal(buf)
498endfunc
499
500
501func Test_ask_yesno()
502  CheckRunVimInTerminal
503  let buf = RunVimInTerminal('', {'rows': 6})
504  call term_sendkeys(buf, ":call setline(1, range(1, 2))\n")
505
506  call term_sendkeys(buf, ":2,1s/^/n/\n")
507  call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))})
508  call term_sendkeys(buf, "n")
509  call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?n *1,1 *All$', term_getline(buf, 6))})
510  call WaitForAssert({-> assert_equal('1', term_getline(buf, 1))})
511
512  call term_sendkeys(buf, ":2,1s/^/Esc/\n")
513  call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))})
514  call term_sendkeys(buf, "\<Esc>")
515  call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?n *1,1 *All$', term_getline(buf, 6))})
516  call WaitForAssert({-> assert_equal('1', term_getline(buf, 1))})
517
518  call term_sendkeys(buf, ":2,1s/^/y/\n")
519  call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))})
520  call term_sendkeys(buf, "y")
521  call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?y *2,1 *All$', term_getline(buf, 6))})
522  call WaitForAssert({-> assert_equal('y1', term_getline(buf, 1))})
523  call WaitForAssert({-> assert_equal('y2', term_getline(buf, 2))})
524
525  call StopVimInTerminal(buf)
526endfunc
527
528func Test_null()
529  echom v:_null_list
530  echom v:_null_dict
531  echom v:_null_blob
532  echom v:_null_string
533  " Nvim doesn't have NULL functions
534  " echom test_null_function()
535  " Nvim doesn't have NULL partials
536  " echom test_null_partial()
537  if has('job')
538    echom test_null_job()
539    echom test_null_channel()
540  endif
541endfunc
542
543func Test_mapping_at_hit_return_prompt()
544  nnoremap <C-B> :echo "hit ctrl-b"<CR>
545  call feedkeys(":ls\<CR>", "xt")
546  call feedkeys("\<*C-B>", "xt")
547  call assert_match('hit ctrl-b', Screenline(&lines - 1))
548  nunmap <C-B>
549endfunc
550
551func Test_quit_long_message()
552  CheckScreendump
553
554  let content =<< trim END
555    echom range(9999)->join("\x01")
556  END
557  call writefile(content, 'Xtest_quit_message', 'D')
558  let buf = RunVimInTerminal('-S Xtest_quit_message', #{rows: 10, wait_for_ruler: 0})
559  call WaitForAssert({-> assert_match('^-- More --', term_getline(buf, 10))})
560  call term_sendkeys(buf, "q")
561  call VerifyScreenDump(buf, 'Test_quit_long_message', {})
562
563  " clean up
564  call StopVimInTerminal(buf)
565endfunc
566
567" this was missing a terminating NUL
568func Test_echo_string_partial()
569  function CountSpaces()
570  endfunction
571  call assert_equal("function('CountSpaces', [{'ccccccccccc': ['ab', 'cd'], 'aaaaaaaaaaa': v:false, 'bbbbbbbbbbbb': ''}])", string(function('CountSpaces', [#{aaaaaaaaaaa: v:false, bbbbbbbbbbbb: '', ccccccccccc: ['ab', 'cd']}])))
572endfunc
573
574" Test that fileinfo is shown properly when 'cmdheight' has just decreased
575" due to switching tabpage and 'shortmess' doesn't contain 'o' or 'O'.
576func Test_fileinfo_tabpage_cmdheight()
577  CheckRunVimInTerminal
578
579  let content =<< trim END
580    set shortmess-=o
581    set shortmess-=O
582    set shortmess-=F
583    tabnew
584    set cmdheight=2
585    tabprev
586    edit Xfileinfo.txt
587  END
588
589  call writefile(content, 'Xtest_fileinfo_tabpage_cmdheight', 'D')
590  let buf = RunVimInTerminal('-S Xtest_fileinfo_tabpage_cmdheight', #{rows: 6})
591  call WaitForAssert({-> assert_match('^"Xfileinfo.txt" \[New\]', term_getline(buf, 6))})
592
593  " clean up
594  call StopVimInTerminal(buf)
595endfunc
596
597" Message output was previously overwritten by the fileinfo display, shown
598" when switching buffers. If a buffer is switched to, then a message if
599" echoed, we should show the message, rather than overwriting it with
600" fileinfo.
601func Test_fileinfo_after_echo()
602  CheckScreendump
603
604  let content =<< trim END
605    file a.txt
606
607    hide edit b.txt
608    call setline(1, "hi")
609    setlocal modified
610
611    hide buffer a.txt
612
613    autocmd CursorHold * buf b.txt | w | echo "'b' written"
614  END
615
616  call writefile(content, 'Xtest_fileinfo_after_echo')
617  let buf = RunVimInTerminal('-S Xtest_fileinfo_after_echo', #{rows: 6})
618  call term_sendkeys(buf, ":set updatetime=50\<CR>")
619  call term_sendkeys(buf, "0$")
620  call VerifyScreenDump(buf, 'Test_fileinfo_after_echo', {})
621
622  call term_sendkeys(buf, ":q\<CR>")
623
624  " clean up
625  call StopVimInTerminal(buf)
626  call delete('Xtest_fileinfo_after_echo')
627  call delete('b.txt')
628endfunc
629
630func Test_cmdheight_zero()
631  enew
632  set cmdheight=0
633  set showcmd
634  redraw!
635
636  echo 'test echo'
637  call assert_equal(116, screenchar(&lines, 1))
638  redraw!
639
640  echomsg 'test echomsg'
641  call assert_equal(116, screenchar(&lines, 1))
642  redraw!
643
644  call feedkeys(":ls\<CR>", "xt")
645  call assert_equal(':ls', Screenline(&lines - 1))
646  redraw!
647
648  let char = getchar(0)
649  call assert_match(char, 0)
650
651  " Check change/restore cmdheight when macro
652  call feedkeys("qa", "xt")
653  call assert_equal(0, &cmdheight)
654  call feedkeys("q", "xt")
655  call assert_equal(0, &cmdheight)
656
657  call setline(1, 'somestring')
658  call feedkeys("y", "n")
659  %s/somestring/otherstring/gc
660  call assert_equal('otherstring', getline(1))
661
662  call feedkeys("g\<C-g>", "xt")
663  call assert_match(
664        \ 'Col 1 of 11; Line 1 of 1; Word 1 of 1',
665        \ Screenline(&lines))
666
667  " Check split behavior
668  for i in range(1, 10)
669    split
670  endfor
671  only
672  call assert_equal(0, &cmdheight)
673
674  " Check that pressing ":" should not scroll a window
675  " Check for what patch 9.0.0115 fixes
676  botright 10new
677  call setline(1, range(12))
678  7
679  call feedkeys(":\"\<C-R>=line('w0')\<CR>\<CR>", "xt")
680  call assert_equal('"1', @:)
681
682  bwipe!
683  bwipe!
684  set cmdheight&
685  set showcmd&
686  tabnew
687  tabonly
688endfunc
689
690func Test_messagesopt_history()
691  " After setting 'messagesopt' "history" to 2 and outputting a message 4 times
692  " with :echomsg, is the number of output lines of :messages 2?
693  set messagesopt=hit-enter,history:2
694  echomsg 'foo'
695  echomsg 'bar'
696  echomsg 'baz'
697  echomsg 'foobar'
698  call assert_equal(['baz', 'foobar'], GetMessages())
699
700  " When the number of messages is 10 and 'messagesopt' "history" is changed to
701  " 5, is the number of output lines of :messages 5?
702  set messagesopt=hit-enter,history:10
703  for num in range(1, 10)
704    echomsg num
705  endfor
706  set messagesopt=hit-enter,history:5
707  call assert_equal(5, len(GetMessages()))
708
709  " Check empty list
710  set messagesopt=hit-enter,history:0
711  call assert_true(empty(GetMessages()))
712
713  set messagesopt&
714endfunc
715
716func Test_messagesopt_wait()
717  CheckRunVimInTerminal
718
719  let buf = RunVimInTerminal('', {'rows': 6, 'cols': 45})
720  call term_sendkeys(buf, ":set cmdheight=1\n")
721
722  " Check hit-enter prompt
723  call term_sendkeys(buf, ":set messagesopt=hit-enter,history:500\n")
724  call term_sendkeys(buf, ":echo 'foo' | echo 'bar' | echo 'baz'\n")
725  call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
726
727  " Check no hit-enter prompt when "wait:" is set
728  call term_sendkeys(buf, ":set messagesopt=wait:100,history:500\n")
729  call term_sendkeys(buf, ":echo 'foo' | echo 'bar' | echo 'baz'\n")
730  call WaitForAssert({-> assert_equal('                           0,0-1         All', term_getline(buf, 6))})
731
732  " clean up
733  call StopVimInTerminal(buf)
734endfunc
735
736" Check that using a long 'formatprg' doesn't cause a hit-enter prompt or
737" wrong cursor position.
738func Test_long_formatprg_no_hit_enter()
739  CheckScreendump
740  CheckExecutable sed
741
742  let lines =<< trim END
743    setlocal scrolloff=0
744    call setline(1, range(1, 40))
745    let &l:formatprg = $'sed{repeat(' ', &columns)}p'
746    normal 20Gmz
747    normal 10Gzt
748  END
749  call writefile(lines, 'XtestLongFormatprg', 'D')
750  let buf = RunVimInTerminal('-S XtestLongFormatprg', #{rows: 10})
751  call VerifyScreenDump(buf, 'Test_long_formatprg_no_hit_enter_1', {})
752  call term_sendkeys(buf, 'gq2j')
753  call VerifyScreenDump(buf, 'Test_long_formatprg_no_hit_enter_2', {})
754  call term_sendkeys(buf, ":messages\<CR>")
755  call VerifyScreenDump(buf, 'Test_long_formatprg_no_hit_enter_3', {})
756
757  " clean up
758  call StopVimInTerminal(buf)
759endfunc
760
761" A message shown while a mapping is still being processed must not eat the
762" mapping's remaining keys.
763" If a mapping starts cmdline after multiline messages exceeding 'cmdheight',
764" the messages should still be visible.
765func Test_hit_enter_during_mapping()
766  CheckRunVimInTerminal
767
768  let lines =<< trim END
769    set ruler
770    call setline(1, range(1, 20))
771    " The 8-line :echo leads to a hit-enter prompt.
772    nnoremap X :echo "a\nb\nc\nd\ne\nf\ng\nh"<CR>gg
773    nnoremap \b :echo "a\nb\nc\nd\ne\nf\ng\nh"<CR>:b<Space>
774    normal! 10G
775  END
776  call writefile(lines, 'XtestHitEnterMap', 'D')
777  let buf = RunVimInTerminal('-S XtestHitEnterMap', #{rows: 10})
778  call WaitForAssert({-> assert_match(' 10,1 ', term_getline(buf, 10))})
779
780  call term_sendkeys(buf, "X")
781  " Without the fix the hit-enter prompt eats the mapping's "g" keys and the
782  " cursor stays put.  With the fix "gg" runs and moves the cursor to line 1.
783  call WaitForAssert({-> assert_match(' 1,1 ', term_getline(buf, 10))})
784  call assert_notmatch('Press ENTER', term_getline(buf, 10))
785
786  call term_sendkeys(buf, '\b')
787  call WaitForAssert({-> assert_match('^:b ', term_getline(buf, 10))})
788  call assert_match('^a *$', term_getline(buf, 2))
789  call assert_match('^b *$', term_getline(buf, 3))
790  call assert_match('^c *$', term_getline(buf, 4))
791  call assert_match('^d *$', term_getline(buf, 5))
792  call assert_match('^e *$', term_getline(buf, 6))
793  call assert_match('^f *$', term_getline(buf, 7))
794  call assert_match('^g *$', term_getline(buf, 8))
795  call assert_match('^h *$', term_getline(buf, 9))
796
797  " clean up
798  call StopVimInTerminal(buf)
799endfunc
800
801" Test that fileinfo is shown after deleting the last listed buffer with :bd
802func Test_fileinfo_after_last_bd()
803  CheckRunVimInTerminal
804
805  let content =<< trim END
806    set shortmess-=F
807    edit xxx
808    edit yyy
809  END
810
811  call writefile(content, 'Xtest_fileinfo_last_bd', 'D')
812  let buf = RunVimInTerminal('-S Xtest_fileinfo_last_bd', #{rows: 10})
813  call WaitForAssert({-> assert_match('^"yyy" \[New\]', term_getline(buf, 10))})
814
815  call term_sendkeys(buf, ":bd\<CR>")
816  call WaitForAssert({-> assert_match('^"xxx" \[New\]', term_getline(buf, 10))})
817
818  call term_sendkeys(buf, ":bd\<CR>")
819  call WaitForAssert({-> assert_match('^\"\[No Name\]\" --No lines in buffer--', term_getline(buf, 10))})
820
821  " clean up
822  call StopVimInTerminal(buf)
823endfunc
824
825func Test_undo_messages()
826  new
827
828  " Normal undo/redo messages
829  redir => result
830  call setline(1, 'foo')
831  undo
832  undo
833  redo
834  redo
835  redir END
836  let msg_list = split(result, "\n")
837  call assert_match("^1 line less; before #1", msg_list[0])
838  call assert_equal("Already at oldest change", msg_list[1])
839  call assert_match("^1 more line; after #1", msg_list[2])
840  call assert_equal("Already at newest change", msg_list[3])
841
842  " Ignore undo/redo messages
843  redir => result
844  set shortmess+=u
845  call setline(1, 'foo')
846  undo
847  undo
848  redo
849  redo
850  redir END
851  let msg_list = split(result, "\n")
852  call assert_equal([], msg_list)
853  set shortmess&
854
855  " undo_time() path: :earlier and :later go through a separate
856  " message site than u_doit(); make sure SHM_UNDO suppresses it too.
857  enew!
858  call setline(1, 'a')
859  call setline(1, 'b')
860  call setline(1, 'c')
861
862  redir => result
863  earlier 1
864  earlier 999
865  earlier 999
866  later 1
867  later 999
868  redir END
869  let msg_list = split(result, "\n")
870  call assert_match('^1 line less; before #', msg_list[0])
871  call assert_match('^1 changes; before #', msg_list[1])
872  call assert_match('^1 changes; before #', msg_list[2])
873  call assert_match('^1 more line; after #', msg_list[3])
874  call assert_equal('Already at newest change', msg_list[4])
875
876  set shortmess+=u
877  redir => result
878  earlier 1
879  earlier 999
880  later 1
881  later 999
882  later 999
883  redir END
884  call assert_equal([], split(result, "\n"))
885
886  set shortmess&
887  bwipe!
888endfunc
889
890" vim: shiftwidth=2 sts=2 expandtab