blob: 46f336834614f6200844210dee25cde17edecee9 [file] [log] [blame]
Bram Moolenaar461a7fc2018-12-22 13:28:07 +01001" Tests for :messages, :echomsg, :echoerr
Bram Moolenaar451f8492016-04-14 17:16:22 +02002
Bram Moolenaar494e9062020-05-31 21:28:02 +02003source check.vim
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +02004source shared.vim
Bram Moolenaarc6d539b2019-12-28 17:10:46 +01005source term_util.vim
Bram Moolenaarb42c0d52020-05-29 22:41:41 +02006source view_util.vim
Bram Moolenaar3d30af82020-10-13 22:15:56 +02007source screendump.vim
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +02008
Bram Moolenaar49b2fb32020-04-25 17:13:56 +02009func Test_messages()
Bram Moolenaar451f8492016-04-14 17:16:22 +020010 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
Bram Moolenaar451f8492016-04-14 17:16:22 +020018
Bram Moolenaarbea1ede2016-04-14 19:44:36 +020019 " get last two messages
Bram Moolenaar451f8492016-04-14 17:16:22 +020020 redir => result
21 2messages | redraw
22 redir END
Bram Moolenaarbea1ede2016-04-14 19:44:36 +020023 let msg_list = split(result, "\n")
24 call assert_equal(["hello8", "hello9"], msg_list)
Bram Moolenaar451f8492016-04-14 17:16:22 +020025
26 " clear messages without last one
27 1messages clear
Bram Moolenaar49b2fb32020-04-25 17:13:56 +020028 let msg_list = GetMessages()
Bram Moolenaarbea1ede2016-04-14 19:44:36 +020029 call assert_equal(['hello9'], msg_list)
Bram Moolenaar451f8492016-04-14 17:16:22 +020030
31 " clear all messages
32 messages clear
Bram Moolenaar49b2fb32020-04-25 17:13:56 +020033 let msg_list = GetMessages()
34 call assert_equal([], msg_list)
Bram Moolenaar451f8492016-04-14 17:16:22 +020035 finally
36 let &more = oldmore
37 endtry
Bram Moolenaar067297e2020-04-13 19:55:50 +020038
39 call assert_fails('message 1', 'E474:')
Bram Moolenaar49b2fb32020-04-25 17:13:56 +020040endfunc
Bram Moolenaar2abad542018-05-19 14:43:45 +020041
Bram Moolenaarf52f9ea2018-06-27 20:49:44 +020042" Patch 7.4.1696 defined the "clearmode()" function for clearing the mode
Bram Moolenaar2abad542018-05-19 14:43:45 +020043" 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.
Bram Moolenaar1e115362019-01-09 23:01:02 +010046func Test_stopinsert_does_not_break_message_output()
Bram Moolenaar2abad542018-05-19 14:43:45 +020047 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&
Bram Moolenaar1e115362019-01-09 23:01:02 +010061endfunc
Bram Moolenaarb513d302018-12-02 14:55:08 +010062
63func Test_message_completion()
64 call feedkeys(":message \<C-A>\<C-B>\"\<CR>", 'tx')
65 call assert_equal('"message clear', @:)
66endfunc
Bram Moolenaar461a7fc2018-12-22 13:28:07 +010067
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]'))
Bram Moolenaardb950e42020-04-22 19:13:19 +020074 call assert_equal("\n[1, 2, []]", execute(':echomsg [1, 2, test_null_list()]'))
Bram Moolenaar461a7fc2018-12-22 13:28:07 +010075 call assert_equal("\n{}", execute(':echomsg {}'))
76 call assert_equal("\n{'a': 1, 'b': 2}", execute(':echomsg {"a": 1, "b": 2}'))
Bram Moolenaar73e28dc2022-09-17 21:08:33 +010077 call assert_equal("\n1.23", execute(':echomsg 1.23'))
Bram Moolenaar461a7fc2018-12-22 13:28:07 +010078 call assert_match("function('<lambda>\\d*')", execute(':echomsg {-> 1234}'))
79endfunc
80
81func Test_echoerr()
82 call test_ignore_error('IgNoRe')
83 call assert_equal("\nIgNoRe hello", execute(':echoerr "IgNoRe hello"'))
84 call assert_equal("\n12345 IgNoRe", execute(':echoerr 12345 "IgNoRe"'))
85 call assert_equal("\n[1, 2, 'IgNoRe']", execute(':echoerr [1, 2, "IgNoRe"]'))
86 call assert_equal("\n{'IgNoRe': 2, 'a': 1}", execute(':echoerr {"a": 1, "IgNoRe": 2}'))
Bram Moolenaar73e28dc2022-09-17 21:08:33 +010087 call assert_equal("\n1.23 IgNoRe", execute(':echoerr 1.23 "IgNoRe"'))
Bram Moolenaarce90e362019-09-08 18:58:44 +020088 eval '<lambda>'->test_ignore_error()
Bram Moolenaar461a7fc2018-12-22 13:28:07 +010089 call assert_match("function('<lambda>\\d*')", execute(':echoerr {-> 1234}'))
90 call test_ignore_error('RESET')
91endfunc
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +020092
93func Test_mode_message_at_leaving_insert_by_ctrl_c()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020094 CheckFeature terminal
95 CheckNotGui
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +020096
97 " Set custom statusline built by user-defined function.
98 let testfile = 'Xtest.vim'
Bram Moolenaare7eb9272019-06-24 00:58:07 +020099 let lines =<< trim END
100 func StatusLine() abort
101 return ""
102 endfunc
103 set statusline=%!StatusLine()
104 set laststatus=2
105 END
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100106 call writefile(lines, testfile, 'D')
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +0200107
108 let rows = 10
109 let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200110 call TermWait(buf, 100)
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +0200111 call assert_equal('run', job_status(term_getjob(buf)))
112
113 call term_sendkeys(buf, "i")
114 call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, rows))})
115 call term_sendkeys(buf, "\<C-C>")
116 call WaitForAssert({-> assert_match('^\s*$', term_getline(buf, rows))})
117
118 call term_sendkeys(buf, ":qall!\<CR>")
119 call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))})
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100120
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +0200121 exe buf . 'bwipe!'
Bram Moolenaarabc7c7f2019-04-20 15:10:13 +0200122endfunc
Bram Moolenaar4c25bd72019-04-20 23:38:07 +0200123
124func Test_mode_message_at_leaving_insert_with_esc_mapped()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200125 CheckFeature terminal
126 CheckNotGui
Bram Moolenaar4c25bd72019-04-20 23:38:07 +0200127
128 " Set custom statusline built by user-defined function.
129 let testfile = 'Xtest.vim'
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200130 let lines =<< trim END
131 set laststatus=2
132 inoremap <Esc> <Esc>00
133 END
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100134 call writefile(lines, testfile, 'D')
Bram Moolenaar4c25bd72019-04-20 23:38:07 +0200135
136 let rows = 10
137 let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200138 call WaitForAssert({-> assert_match('0,0-1\s*All$', term_getline(buf, rows - 1))})
Bram Moolenaar4c25bd72019-04-20 23:38:07 +0200139 call assert_equal('run', job_status(term_getjob(buf)))
140
141 call term_sendkeys(buf, "i")
142 call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, rows))})
143 call term_sendkeys(buf, "\<Esc>")
144 call WaitForAssert({-> assert_match('^\s*$', term_getline(buf, rows))})
145
146 call term_sendkeys(buf, ":qall!\<CR>")
147 call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))})
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100148
Bram Moolenaar4c25bd72019-04-20 23:38:07 +0200149 exe buf . 'bwipe!'
Bram Moolenaar4c25bd72019-04-20 23:38:07 +0200150endfunc
Bram Moolenaar37f4cbd2019-08-23 20:58:45 +0200151
152func Test_echospace()
153 set noruler noshowcmd laststatus=1
154 call assert_equal(&columns - 1, v:echospace)
155 split
156 call assert_equal(&columns - 1, v:echospace)
157 set ruler
158 call assert_equal(&columns - 1, v:echospace)
159 close
160 call assert_equal(&columns - 19, v:echospace)
161 set showcmd noruler
162 call assert_equal(&columns - 12, v:echospace)
163 set showcmd ruler
164 call assert_equal(&columns - 29, v:echospace)
Sam-programs062141b2024-02-29 17:40:29 +0100165 set showcmdloc=statusline
166 call assert_equal(&columns - 19, v:echospace)
167 set showcmdloc=tabline
168 call assert_equal(&columns - 19, v:echospace)
zeertzjqc27fcf42024-03-01 23:01:43 +0100169 call assert_fails('set showcmdloc=leap', 'E474:')
170 call assert_equal(&columns - 19, v:echospace)
171 set showcmdloc=last
172 call assert_equal(&columns - 29, v:echospace)
173 call assert_fails('set showcmdloc=jump', 'E474:')
174 call assert_equal(&columns - 29, v:echospace)
Bram Moolenaar37f4cbd2019-08-23 20:58:45 +0200175
Sam-programs062141b2024-02-29 17:40:29 +0100176 set ruler& showcmd& showcmdloc&
Bram Moolenaar37f4cbd2019-08-23 20:58:45 +0200177endfunc
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100178
zeertzjqbdedd2b2022-09-20 12:45:15 +0100179func Test_warning_scroll()
180 CheckRunVimInTerminal
181 let lines =<< trim END
182 call test_override('ui_delay', 50)
183 set noruler
184 set readonly
185 undo
186 END
187 call writefile(lines, 'XTestWarningScroll', 'D')
188 let buf = RunVimInTerminal('', #{rows: 8})
189
190 " When the warning comes from a script, messages are scrolled so that the
191 " stacktrace is visible.
192 call term_sendkeys(buf, ":source XTestWarningScroll\n")
193 " only match the final colon in the line that shows the source
194 call WaitForAssert({-> assert_match(':$', term_getline(buf, 5))})
195 call WaitForAssert({-> assert_equal('line 4:W10: Warning: Changing a readonly file', term_getline(buf, 6))})
196 call WaitForAssert({-> assert_equal('Already at oldest change', term_getline(buf, 7))})
197 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 8))})
198 call term_sendkeys(buf, "\n")
199
200 " When the warning does not come from a script, messages are not scrolled.
201 call term_sendkeys(buf, ":enew\n")
202 call term_sendkeys(buf, ":set readonly\n")
203 call term_sendkeys(buf, 'u')
204 call WaitForAssert({-> assert_equal('W10: Warning: Changing a readonly file', term_getline(buf, 8))})
205 call WaitForAssert({-> assert_equal('Already at oldest change', term_getline(buf, 8))})
206
207 " clean up
208 call StopVimInTerminal(buf)
209endfunc
210
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100211" Test more-prompt (see :help more-prompt).
212func Test_message_more()
Bram Moolenaar494e9062020-05-31 21:28:02 +0200213 CheckRunVimInTerminal
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100214 let buf = RunVimInTerminal('', {'rows': 6})
215 call term_sendkeys(buf, ":call setline(1, range(1, 100))\n")
216
zeertzjq46af7bc2022-07-28 12:34:09 +0100217 call term_sendkeys(buf, ":%pfoo\<C-H>\<C-H>\<C-H>#")
218 call WaitForAssert({-> assert_equal(':%p#', term_getline(buf, 6))})
219 call term_sendkeys(buf, "\n")
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100220 call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))})
221 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
222
223 call term_sendkeys(buf, '?')
224 call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))})
225 call WaitForAssert({-> assert_equal('-- More -- SPACE/d/j: screen/page/line down, b/u/k: up, q: quit ', term_getline(buf, 6))})
226
227 " Down a line with j, <CR>, <NL> or <Down>.
228 call term_sendkeys(buf, "j")
229 call WaitForAssert({-> assert_equal(' 6 6', term_getline(buf, 5))})
230 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
231 call term_sendkeys(buf, "\<NL>")
232 call WaitForAssert({-> assert_equal(' 7 7', term_getline(buf, 5))})
233 call term_sendkeys(buf, "\<CR>")
234 call WaitForAssert({-> assert_equal(' 8 8', term_getline(buf, 5))})
235 call term_sendkeys(buf, "\<Down>")
236 call WaitForAssert({-> assert_equal(' 9 9', term_getline(buf, 5))})
237
238 " Down a screen with <Space>, f, or <PageDown>.
239 call term_sendkeys(buf, 'f')
240 call WaitForAssert({-> assert_equal(' 14 14', term_getline(buf, 5))})
241 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
242 call term_sendkeys(buf, ' ')
243 call WaitForAssert({-> assert_equal(' 19 19', term_getline(buf, 5))})
244 call term_sendkeys(buf, "\<PageDown>")
245 call WaitForAssert({-> assert_equal(' 24 24', term_getline(buf, 5))})
246
247 " Down a page (half a screen) with d.
248 call term_sendkeys(buf, 'd')
249 call WaitForAssert({-> assert_equal(' 27 27', term_getline(buf, 5))})
250
251 " Down all the way with 'G'.
252 call term_sendkeys(buf, 'G')
253 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))})
254 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
255
256 " Up a line k, <BS> or <Up>.
257 call term_sendkeys(buf, 'k')
258 call WaitForAssert({-> assert_equal(' 99 99', term_getline(buf, 5))})
259 call term_sendkeys(buf, "\<BS>")
260 call WaitForAssert({-> assert_equal(' 98 98', term_getline(buf, 5))})
261 call term_sendkeys(buf, "\<Up>")
262 call WaitForAssert({-> assert_equal(' 97 97', term_getline(buf, 5))})
263
264 " Up a screen with b or <PageUp>.
265 call term_sendkeys(buf, 'b')
266 call WaitForAssert({-> assert_equal(' 92 92', term_getline(buf, 5))})
267 call term_sendkeys(buf, "\<PageUp>")
268 call WaitForAssert({-> assert_equal(' 87 87', term_getline(buf, 5))})
269
270 " Up a page (half a screen) with u.
271 call term_sendkeys(buf, 'u')
272 call WaitForAssert({-> assert_equal(' 84 84', term_getline(buf, 5))})
273
274 " Up all the way with 'g'.
275 call term_sendkeys(buf, 'g')
zeertzjqecdc82e2022-07-25 19:50:57 +0100276 call WaitForAssert({-> assert_equal(' 4 4', term_getline(buf, 5))})
277 call WaitForAssert({-> assert_equal(':%p#', term_getline(buf, 1))})
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100278 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
279
280 " All the way down. Pressing f should do nothing but pressing
281 " space should end the more prompt.
282 call term_sendkeys(buf, 'G')
283 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))})
284 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
285 call term_sendkeys(buf, 'f')
286 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))})
287 call term_sendkeys(buf, ' ')
288 call WaitForAssert({-> assert_equal('100', term_getline(buf, 5))})
289
290 " Pressing g< shows the previous command output.
291 call term_sendkeys(buf, 'g<')
292 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))})
293 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
294
zeertzjq46af7bc2022-07-28 12:34:09 +0100295 " A command line that doesn't print text is appended to scrollback,
296 " even if it invokes a nested command line.
297 call term_sendkeys(buf, ":\<C-R>=':'\<CR>:\<CR>g<")
298 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 4))})
299 call WaitForAssert({-> assert_equal(':::', term_getline(buf, 5))})
300 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
301
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100302 call term_sendkeys(buf, ":%p#\n")
303 call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))})
304 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
305
306 " Stop command output with q, <Esc> or CTRL-C.
307 call term_sendkeys(buf, 'q')
308 call WaitForAssert({-> assert_equal('100', term_getline(buf, 5))})
309
Bram Moolenaarf4fcedc2021-03-15 18:36:20 +0100310 " Execute a : command from the more prompt
311 call term_sendkeys(buf, ":%p#\n")
312 call term_wait(buf)
313 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
314 call term_sendkeys(buf, ":")
315 call term_wait(buf)
316 call WaitForAssert({-> assert_equal(':', term_getline(buf, 6))})
317 call term_sendkeys(buf, "echo 'Hello'\n")
318 call term_wait(buf)
319 call WaitForAssert({-> assert_equal('Hello ', term_getline(buf, 5))})
320
Bram Moolenaar43c60ed2020-02-02 15:55:19 +0100321 call StopVimInTerminal(buf)
322endfunc
323
Bram Moolenaar838b7462022-09-26 15:19:56 +0100324" Test more-prompt scrollback
325func Test_message_more_scrollback()
326 CheckRunVimInTerminal
327
328 let lines =<< trim END
329 set t_ut=
330 hi Normal ctermfg=15 ctermbg=0
331 for i in range(100)
332 echo i
333 endfor
334 END
335 call writefile(lines, 'XmoreScrollback', 'D')
336 let buf = RunVimInTerminal('-S XmoreScrollback', {'rows': 10})
337 call VerifyScreenDump(buf, 'Test_more_scrollback_1', {})
338
339 call term_sendkeys(buf, 'f')
340 call TermWait(buf)
341 call term_sendkeys(buf, 'b')
342 call VerifyScreenDump(buf, 'Test_more_scrollback_2', {})
343
344 call term_sendkeys(buf, 'q')
345 call TermWait(buf)
346 call StopVimInTerminal(buf)
347endfunc
348
Bram Moolenaar800cdbb2023-06-15 16:40:02 +0100349func Test_message_not_cleared_after_mode()
350 CheckRunVimInTerminal
351
352 let lines =<< trim END
353 nmap <silent> gx :call DebugSilent('normal')<CR>
354 vmap <silent> gx :call DebugSilent('visual')<CR>
355 function DebugSilent(arg)
356 echomsg "from DebugSilent" a:arg
357 endfunction
358 set showmode
359 set cmdheight=1
Bram Moolenaarda51ad52023-06-15 18:44:50 +0100360 call test_settime(1)
361 call setline(1, ['one', 'NoSuchFile', 'three'])
Bram Moolenaar800cdbb2023-06-15 16:40:02 +0100362 END
363 call writefile(lines, 'XmessageMode', 'D')
364 let buf = RunVimInTerminal('-S XmessageMode', {'rows': 10})
365
366 call term_sendkeys(buf, 'gx')
367 call TermWait(buf)
368 call VerifyScreenDump(buf, 'Test_message_not_cleared_after_mode_1', {})
369
370 " removing the mode message used to also clear the intended message
371 call term_sendkeys(buf, 'vEgx')
372 call TermWait(buf)
373 call VerifyScreenDump(buf, 'Test_message_not_cleared_after_mode_2', {})
374
Bram Moolenaarda51ad52023-06-15 18:44:50 +0100375 " removing the mode message used to also clear the error message
376 call term_sendkeys(buf, ":set cmdheight=2\<CR>")
377 call term_sendkeys(buf, '2GvEgf')
378 call TermWait(buf)
379 call VerifyScreenDump(buf, 'Test_message_not_cleared_after_mode_3', {})
380
Bram Moolenaar800cdbb2023-06-15 16:40:02 +0100381 call StopVimInTerminal(buf)
382endfunc
383
Bram Moolenaar11901392022-09-26 19:50:44 +0100384" Test verbose message before echo command
385func Test_echo_verbose_system()
386 CheckRunVimInTerminal
Bram Moolenaarf8027672022-09-27 15:55:43 +0100387 CheckUnix " needs the "seq" command
388 CheckNotMac " doesn't use /tmp
Bram Moolenaar11901392022-09-26 19:50:44 +0100389
390 let buf = RunVimInTerminal('', {'rows': 10})
391 call term_sendkeys(buf, ":4 verbose echo system('seq 20')\<CR>")
392 " Note that the screendump is filtered to remove the name of the temp file
393 call VerifyScreenDump(buf, 'Test_verbose_system_1', {})
394
395 " display a page and go back, results in exactly the same view
396 call term_sendkeys(buf, ' ')
Bram Moolenaar19cf5252022-11-27 14:39:31 +0000397 call TermWait(buf, 50)
Bram Moolenaar11901392022-09-26 19:50:44 +0100398 call term_sendkeys(buf, 'b')
399 call VerifyScreenDump(buf, 'Test_verbose_system_1', {})
400
401 " do the same with 'cmdheight' set to 2
402 call term_sendkeys(buf, 'q')
403 call TermWait(buf)
404 call term_sendkeys(buf, ":set ch=2\<CR>")
405 call TermWait(buf)
406 call term_sendkeys(buf, ":4 verbose echo system('seq 20')\<CR>")
407 call VerifyScreenDump(buf, 'Test_verbose_system_2', {})
408
409 call term_sendkeys(buf, ' ')
Bram Moolenaar19cf5252022-11-27 14:39:31 +0000410 call TermWait(buf, 50)
Bram Moolenaar11901392022-09-26 19:50:44 +0100411 call term_sendkeys(buf, 'b')
412 call VerifyScreenDump(buf, 'Test_verbose_system_2', {})
413
414 call term_sendkeys(buf, 'q')
415 call TermWait(buf)
416 call StopVimInTerminal(buf)
417endfunc
418
Bram Moolenaar838b7462022-09-26 15:19:56 +0100419
Bram Moolenaar43c60ed2020-02-02 15:55:19 +0100420func Test_ask_yesno()
Bram Moolenaar494e9062020-05-31 21:28:02 +0200421 CheckRunVimInTerminal
Bram Moolenaar43c60ed2020-02-02 15:55:19 +0100422 let buf = RunVimInTerminal('', {'rows': 6})
423 call term_sendkeys(buf, ":call setline(1, range(1, 2))\n")
424
425 call term_sendkeys(buf, ":2,1s/^/n/\n")
426 call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))})
427 call term_sendkeys(buf, "n")
428 call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?n *1,1 *All$', term_getline(buf, 6))})
429 call WaitForAssert({-> assert_equal('1', term_getline(buf, 1))})
430
431 call term_sendkeys(buf, ":2,1s/^/Esc/\n")
432 call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))})
433 call term_sendkeys(buf, "\<Esc>")
434 call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?n *1,1 *All$', term_getline(buf, 6))})
435 call WaitForAssert({-> assert_equal('1', term_getline(buf, 1))})
436
437 call term_sendkeys(buf, ":2,1s/^/y/\n")
438 call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))})
439 call term_sendkeys(buf, "y")
440 call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?y *2,1 *All$', term_getline(buf, 6))})
441 call WaitForAssert({-> assert_equal('y1', term_getline(buf, 1))})
442 call WaitForAssert({-> assert_equal('y2', term_getline(buf, 2))})
443
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100444 call StopVimInTerminal(buf)
445endfunc
Bram Moolenaar9db2afe2020-01-08 18:56:20 +0100446
447func Test_null()
448 echom test_null_list()
449 echom test_null_dict()
450 echom test_null_blob()
Bram Moolenaar9db2afe2020-01-08 18:56:20 +0100451 echom test_null_string()
Bram Moolenaar92b83cc2020-04-25 15:24:44 +0200452 echom test_null_function()
Bram Moolenaar9db2afe2020-01-08 18:56:20 +0100453 echom test_null_partial()
Bram Moolenaarda292b02020-01-08 19:27:40 +0100454 if has('job')
455 echom test_null_job()
456 echom test_null_channel()
457 endif
Bram Moolenaar9db2afe2020-01-08 18:56:20 +0100458endfunc
Bram Moolenaar92b83cc2020-04-25 15:24:44 +0200459
Bram Moolenaarb42c0d52020-05-29 22:41:41 +0200460func Test_mapping_at_hit_return_prompt()
461 nnoremap <C-B> :echo "hit ctrl-b"<CR>
462 call feedkeys(":ls\<CR>", "xt")
Bram Moolenaarfccd93f2020-05-31 22:06:51 +0200463 call feedkeys("\<*C-B>", "xt")
Bram Moolenaarb42c0d52020-05-29 22:41:41 +0200464 call assert_match('hit ctrl-b', Screenline(&lines - 1))
465 nunmap <C-B>
466endfunc
467
Bram Moolenaar3d30af82020-10-13 22:15:56 +0200468func Test_quit_long_message()
469 CheckScreendump
470
471 let content =<< trim END
472 echom range(9999)->join("\x01")
473 END
Bram Moolenaar124af712022-09-25 18:44:03 +0100474 call writefile(content, 'Xtest_quit_message', 'D')
475 let buf = RunVimInTerminal('-S Xtest_quit_message', #{rows: 10, wait_for_ruler: 0})
476 call WaitForAssert({-> assert_match('^-- More --', term_getline(buf, 10))})
Bram Moolenaar3d30af82020-10-13 22:15:56 +0200477 call term_sendkeys(buf, "q")
478 call VerifyScreenDump(buf, 'Test_quit_long_message', {})
479
480 " clean up
481 call StopVimInTerminal(buf)
Bram Moolenaar3d30af82020-10-13 22:15:56 +0200482endfunc
483
Bram Moolenaar2de53712021-12-19 11:06:35 +0000484" this was missing a terminating NUL
485func Test_echo_string_partial()
486 function CountSpaces()
487 endfunction
Yegappan Lakshmananbc404bf2021-12-19 19:19:31 +0000488 call assert_equal("function('CountSpaces', [{'ccccccccccc': ['ab', 'cd'], 'aaaaaaaaaaa': v:false, 'bbbbbbbbbbbb': ''}])", string(function('CountSpaces', [#{aaaaaaaaaaa: v:false, bbbbbbbbbbbb: '', ccccccccccc: ['ab', 'cd']}])))
Bram Moolenaar2de53712021-12-19 11:06:35 +0000489endfunc
490
zeertzjq40ed6712023-11-23 20:37:01 +0100491" Test that fileinfo is shown properly when 'cmdheight' has just decreased
492" due to switching tabpage and 'shortmess' doesn't contain 'o' or 'O'.
493func Test_fileinfo_tabpage_cmdheight()
494 CheckRunVimInTerminal
495
496 let content =<< trim END
497 set shortmess-=o
498 set shortmess-=O
499 set shortmess-=F
500 tabnew
501 set cmdheight=2
502 tabprev
503 edit Xfileinfo.txt
504 END
505
506 call writefile(content, 'Xtest_fileinfo_tabpage_cmdheight', 'D')
507 let buf = RunVimInTerminal('-S Xtest_fileinfo_tabpage_cmdheight', #{rows: 6})
508 call WaitForAssert({-> assert_match('^"Xfileinfo.txt" \[New\]', term_getline(buf, 6))})
509
510 " clean up
511 call StopVimInTerminal(buf)
512endfunc
513
Rob Pilling726f7f92022-01-20 14:44:38 +0000514" Message output was previously overwritten by the fileinfo display, shown
515" when switching buffers. If a buffer is switched to, then a message if
516" echoed, we should show the message, rather than overwriting it with
517" fileinfo.
518func Test_fileinfo_after_echo()
519 CheckScreendump
520
521 let content =<< trim END
522 file a.txt
523
524 hide edit b.txt
525 call setline(1, "hi")
526 setlocal modified
527
528 hide buffer a.txt
529
Bram Moolenaar9323ca52022-03-16 11:14:57 +0000530 autocmd CursorHold * buf b.txt | w | echo "'b' written"
Rob Pilling726f7f92022-01-20 14:44:38 +0000531 END
532
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100533 call writefile(content, 'Xtest_fileinfo_after_echo', 'D')
Rob Pilling726f7f92022-01-20 14:44:38 +0000534 let buf = RunVimInTerminal('-S Xtest_fileinfo_after_echo', #{rows: 6})
Bram Moolenaar9323ca52022-03-16 11:14:57 +0000535 call term_sendkeys(buf, ":set updatetime=50\<CR>")
536 call term_sendkeys(buf, "0$")
Rob Pilling726f7f92022-01-20 14:44:38 +0000537 call VerifyScreenDump(buf, 'Test_fileinfo_after_echo', {})
538
539 call term_sendkeys(buf, ":q\<CR>")
540
541 " clean up
542 call StopVimInTerminal(buf)
Yegappan Lakshmanan7e765a32022-01-24 11:40:37 +0000543 call delete('b.txt')
Rob Pilling726f7f92022-01-20 14:44:38 +0000544endfunc
545
Bram Moolenaar37fef162022-08-29 18:16:32 +0100546func Test_echowindow()
547 CheckScreendump
548
549 let lines =<< trim END
550 call setline(1, 'some text')
551 func ShowMessage(arg)
552 echowindow a:arg
553 endfunc
554 echowindow 'first line'
Bram Moolenaarb5b4f612022-09-01 16:43:17 +0100555 func ManyMessages()
556 for n in range(20)
557 echowindow 'line' n
558 endfor
559 endfunc
Bram Moolenaarcf0995d2022-09-11 21:36:17 +0100560
561 def TwoMessages()
562 popup_clear()
563 set cmdheight=2
564 redraw
565 timer_start(100, (_) => {
566 echowin 'message'
567 })
568 echo 'one'
569 echo 'two'
570 enddef
571
572 def ThreeMessages()
573 popup_clear()
574 redraw
575 timer_start(100, (_) => {
576 echowin 'later message'
577 })
578 echo 'one'
579 echo 'two'
580 echo 'three'
581 enddef
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100582
583 def HideWin()
584 popup_hide(popup_findecho())
585 enddef
Bram Moolenaar37fef162022-08-29 18:16:32 +0100586 END
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100587 call writefile(lines, 'XtestEchowindow', 'D')
Bram Moolenaar37fef162022-08-29 18:16:32 +0100588 let buf = RunVimInTerminal('-S XtestEchowindow', #{rows: 8})
589 call VerifyScreenDump(buf, 'Test_echowindow_1', {})
590
591 call term_sendkeys(buf, ":call ShowMessage('second line')\<CR>")
592 call VerifyScreenDump(buf, 'Test_echowindow_2', {})
593
594 call term_sendkeys(buf, ":call popup_clear()\<CR>")
595 call VerifyScreenDump(buf, 'Test_echowindow_3', {})
596
Bram Moolenaarb5b4f612022-09-01 16:43:17 +0100597 call term_sendkeys(buf, ":call ManyMessages()\<CR>")
598 call VerifyScreenDump(buf, 'Test_echowindow_4', {})
599
Bram Moolenaarcf0995d2022-09-11 21:36:17 +0100600 call term_sendkeys(buf, ":call TwoMessages()\<CR>")
601 call VerifyScreenDump(buf, 'Test_echowindow_5', {})
602
603 call term_sendkeys(buf, ":call ThreeMessages()\<CR>")
604 sleep 120m
605 call VerifyScreenDump(buf, 'Test_echowindow_6', {})
606
607 call term_sendkeys(buf, "\<CR>")
608 call VerifyScreenDump(buf, 'Test_echowindow_7', {})
609
Bram Moolenaar45690202022-09-26 12:57:11 +0100610 call term_sendkeys(buf, ":tabnew\<CR>")
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100611 call term_sendkeys(buf, ":7echowin 'more'\<CR>")
Bram Moolenaar45690202022-09-26 12:57:11 +0100612 call VerifyScreenDump(buf, 'Test_echowindow_8', {})
613
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100614 call term_sendkeys(buf, ":call HideWin()\<CR>")
615 call VerifyScreenDump(buf, 'Test_echowindow_9', {})
616
Bram Moolenaar37fef162022-08-29 18:16:32 +0100617 " clean up
618 call StopVimInTerminal(buf)
Bram Moolenaar37fef162022-08-29 18:16:32 +0100619endfunc
620
Yasuhiro Matsumotoa02a8a42022-09-02 12:16:21 +0100621" messages window should not be used while evaluating the :echowin argument
622func Test_echowin_eval()
623 CheckScreendump
624
625 let lines =<< trim END
626 func ShowMessage()
627 echo 123
628 return 'test'
629 endfunc
630 echowindow ShowMessage()
631 END
Bram Moolenaarb152b6a2022-09-29 21:37:33 +0100632 call writefile(lines, 'XtestEchowindow', 'D')
Yasuhiro Matsumotoa02a8a42022-09-02 12:16:21 +0100633 let buf = RunVimInTerminal('-S XtestEchowindow', #{rows: 8})
634 call VerifyScreenDump(buf, 'Test_echowin_eval', {})
635
636 " clean up
637 call StopVimInTerminal(buf)
Yasuhiro Matsumotoa02a8a42022-09-02 12:16:21 +0100638endfunc
639
Bram Moolenaar7cf58392022-09-09 20:19:40 +0100640" messages window should not be used for showing the mode
641func Test_echowin_showmode()
642 CheckScreendump
643
644 let lines =<< trim END
645 vim9script
646 setline(1, ['one', 'two'])
647 timer_start(100, (_) => {
648 echowin 'echo window'
649 })
650 normal V
651 END
652 call writefile(lines, 'XtestEchowinMode', 'D')
653 let buf = RunVimInTerminal('-S XtestEchowinMode', #{rows: 8})
654 call VerifyScreenDump(buf, 'Test_echowin_showmode', {})
655
656 " clean up
657 call StopVimInTerminal(buf)
658endfunc
659
Bram Moolenaar43568642022-08-28 13:02:45 +0100660
Bram Moolenaar92b83cc2020-04-25 15:24:44 +0200661" vim: shiftwidth=2 sts=2 expandtab