blob: e35fb0c383f58f3abf9eeff62e55329f64e0a5fc [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
106 call writefile(lines, testfile)
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)))})
120 exe buf . 'bwipe!'
121 call delete(testfile)
122endfunc
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
134 call writefile(lines, testfile)
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)))})
148 exe buf . 'bwipe!'
149 call delete(testfile)
150endfunc
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)
165
166 set ruler& showcmd&
167endfunc
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100168
169" Test more-prompt (see :help more-prompt).
170func Test_message_more()
Bram Moolenaar494e9062020-05-31 21:28:02 +0200171 CheckRunVimInTerminal
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100172 let buf = RunVimInTerminal('', {'rows': 6})
173 call term_sendkeys(buf, ":call setline(1, range(1, 100))\n")
174
zeertzjq46af7bc2022-07-28 12:34:09 +0100175 call term_sendkeys(buf, ":%pfoo\<C-H>\<C-H>\<C-H>#")
176 call WaitForAssert({-> assert_equal(':%p#', term_getline(buf, 6))})
177 call term_sendkeys(buf, "\n")
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100178 call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))})
179 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
180
181 call term_sendkeys(buf, '?')
182 call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))})
183 call WaitForAssert({-> assert_equal('-- More -- SPACE/d/j: screen/page/line down, b/u/k: up, q: quit ', term_getline(buf, 6))})
184
185 " Down a line with j, <CR>, <NL> or <Down>.
186 call term_sendkeys(buf, "j")
187 call WaitForAssert({-> assert_equal(' 6 6', term_getline(buf, 5))})
188 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
189 call term_sendkeys(buf, "\<NL>")
190 call WaitForAssert({-> assert_equal(' 7 7', term_getline(buf, 5))})
191 call term_sendkeys(buf, "\<CR>")
192 call WaitForAssert({-> assert_equal(' 8 8', term_getline(buf, 5))})
193 call term_sendkeys(buf, "\<Down>")
194 call WaitForAssert({-> assert_equal(' 9 9', term_getline(buf, 5))})
195
196 " Down a screen with <Space>, f, or <PageDown>.
197 call term_sendkeys(buf, 'f')
198 call WaitForAssert({-> assert_equal(' 14 14', term_getline(buf, 5))})
199 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
200 call term_sendkeys(buf, ' ')
201 call WaitForAssert({-> assert_equal(' 19 19', term_getline(buf, 5))})
202 call term_sendkeys(buf, "\<PageDown>")
203 call WaitForAssert({-> assert_equal(' 24 24', term_getline(buf, 5))})
204
205 " Down a page (half a screen) with d.
206 call term_sendkeys(buf, 'd')
207 call WaitForAssert({-> assert_equal(' 27 27', term_getline(buf, 5))})
208
209 " Down all the way with 'G'.
210 call term_sendkeys(buf, 'G')
211 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))})
212 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
213
214 " Up a line k, <BS> or <Up>.
215 call term_sendkeys(buf, 'k')
216 call WaitForAssert({-> assert_equal(' 99 99', term_getline(buf, 5))})
217 call term_sendkeys(buf, "\<BS>")
218 call WaitForAssert({-> assert_equal(' 98 98', term_getline(buf, 5))})
219 call term_sendkeys(buf, "\<Up>")
220 call WaitForAssert({-> assert_equal(' 97 97', term_getline(buf, 5))})
221
222 " Up a screen with b or <PageUp>.
223 call term_sendkeys(buf, 'b')
224 call WaitForAssert({-> assert_equal(' 92 92', term_getline(buf, 5))})
225 call term_sendkeys(buf, "\<PageUp>")
226 call WaitForAssert({-> assert_equal(' 87 87', term_getline(buf, 5))})
227
228 " Up a page (half a screen) with u.
229 call term_sendkeys(buf, 'u')
230 call WaitForAssert({-> assert_equal(' 84 84', term_getline(buf, 5))})
231
232 " Up all the way with 'g'.
233 call term_sendkeys(buf, 'g')
zeertzjqecdc82e2022-07-25 19:50:57 +0100234 call WaitForAssert({-> assert_equal(' 4 4', term_getline(buf, 5))})
235 call WaitForAssert({-> assert_equal(':%p#', term_getline(buf, 1))})
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100236 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
237
238 " All the way down. Pressing f should do nothing but pressing
239 " space should end the more prompt.
240 call term_sendkeys(buf, 'G')
241 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))})
242 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
243 call term_sendkeys(buf, 'f')
244 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))})
245 call term_sendkeys(buf, ' ')
246 call WaitForAssert({-> assert_equal('100', term_getline(buf, 5))})
247
248 " Pressing g< shows the previous command output.
249 call term_sendkeys(buf, 'g<')
250 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))})
251 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
252
zeertzjq46af7bc2022-07-28 12:34:09 +0100253 " A command line that doesn't print text is appended to scrollback,
254 " even if it invokes a nested command line.
255 call term_sendkeys(buf, ":\<C-R>=':'\<CR>:\<CR>g<")
256 call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 4))})
257 call WaitForAssert({-> assert_equal(':::', term_getline(buf, 5))})
258 call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 6))})
259
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100260 call term_sendkeys(buf, ":%p#\n")
261 call WaitForAssert({-> assert_equal(' 5 5', term_getline(buf, 5))})
262 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
263
264 " Stop command output with q, <Esc> or CTRL-C.
265 call term_sendkeys(buf, 'q')
266 call WaitForAssert({-> assert_equal('100', term_getline(buf, 5))})
267
Bram Moolenaarf4fcedc2021-03-15 18:36:20 +0100268 " Execute a : command from the more prompt
269 call term_sendkeys(buf, ":%p#\n")
270 call term_wait(buf)
271 call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
272 call term_sendkeys(buf, ":")
273 call term_wait(buf)
274 call WaitForAssert({-> assert_equal(':', term_getline(buf, 6))})
275 call term_sendkeys(buf, "echo 'Hello'\n")
276 call term_wait(buf)
277 call WaitForAssert({-> assert_equal('Hello ', term_getline(buf, 5))})
278
Bram Moolenaar43c60ed2020-02-02 15:55:19 +0100279 call StopVimInTerminal(buf)
280endfunc
281
282func Test_ask_yesno()
Bram Moolenaar494e9062020-05-31 21:28:02 +0200283 CheckRunVimInTerminal
Bram Moolenaar43c60ed2020-02-02 15:55:19 +0100284 let buf = RunVimInTerminal('', {'rows': 6})
285 call term_sendkeys(buf, ":call setline(1, range(1, 2))\n")
286
287 call term_sendkeys(buf, ":2,1s/^/n/\n")
288 call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))})
289 call term_sendkeys(buf, "n")
290 call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?n *1,1 *All$', term_getline(buf, 6))})
291 call WaitForAssert({-> assert_equal('1', term_getline(buf, 1))})
292
293 call term_sendkeys(buf, ":2,1s/^/Esc/\n")
294 call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))})
295 call term_sendkeys(buf, "\<Esc>")
296 call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?n *1,1 *All$', term_getline(buf, 6))})
297 call WaitForAssert({-> assert_equal('1', term_getline(buf, 1))})
298
299 call term_sendkeys(buf, ":2,1s/^/y/\n")
300 call WaitForAssert({-> assert_equal('Backwards range given, OK to swap (y/n)?', term_getline(buf, 6))})
301 call term_sendkeys(buf, "y")
302 call WaitForAssert({-> assert_match('^Backwards range given, OK to swap (y/n)?y *2,1 *All$', term_getline(buf, 6))})
303 call WaitForAssert({-> assert_equal('y1', term_getline(buf, 1))})
304 call WaitForAssert({-> assert_equal('y2', term_getline(buf, 2))})
305
Bram Moolenaarc6d539b2019-12-28 17:10:46 +0100306 call StopVimInTerminal(buf)
307endfunc
Bram Moolenaar9db2afe2020-01-08 18:56:20 +0100308
309func Test_null()
310 echom test_null_list()
311 echom test_null_dict()
312 echom test_null_blob()
Bram Moolenaar9db2afe2020-01-08 18:56:20 +0100313 echom test_null_string()
Bram Moolenaar92b83cc2020-04-25 15:24:44 +0200314 echom test_null_function()
Bram Moolenaar9db2afe2020-01-08 18:56:20 +0100315 echom test_null_partial()
Bram Moolenaarda292b02020-01-08 19:27:40 +0100316 if has('job')
317 echom test_null_job()
318 echom test_null_channel()
319 endif
Bram Moolenaar9db2afe2020-01-08 18:56:20 +0100320endfunc
Bram Moolenaar92b83cc2020-04-25 15:24:44 +0200321
Bram Moolenaarb42c0d52020-05-29 22:41:41 +0200322func Test_mapping_at_hit_return_prompt()
323 nnoremap <C-B> :echo "hit ctrl-b"<CR>
324 call feedkeys(":ls\<CR>", "xt")
Bram Moolenaarfccd93f2020-05-31 22:06:51 +0200325 call feedkeys("\<*C-B>", "xt")
Bram Moolenaarb42c0d52020-05-29 22:41:41 +0200326 call assert_match('hit ctrl-b', Screenline(&lines - 1))
327 nunmap <C-B>
328endfunc
329
Bram Moolenaar3d30af82020-10-13 22:15:56 +0200330func Test_quit_long_message()
331 CheckScreendump
332
333 let content =<< trim END
334 echom range(9999)->join("\x01")
335 END
336 call writefile(content, 'Xtest_quit_message')
337 let buf = RunVimInTerminal('-S Xtest_quit_message', #{rows: 6})
338 call term_sendkeys(buf, "q")
339 call VerifyScreenDump(buf, 'Test_quit_long_message', {})
340
341 " clean up
342 call StopVimInTerminal(buf)
Bram Moolenaarac665c22020-12-08 20:39:15 +0100343 call delete('Xtest_quit_message')
Bram Moolenaar3d30af82020-10-13 22:15:56 +0200344endfunc
345
Bram Moolenaar2de53712021-12-19 11:06:35 +0000346" this was missing a terminating NUL
347func Test_echo_string_partial()
348 function CountSpaces()
349 endfunction
Yegappan Lakshmananbc404bf2021-12-19 19:19:31 +0000350 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 +0000351endfunc
352
Rob Pilling726f7f92022-01-20 14:44:38 +0000353" Message output was previously overwritten by the fileinfo display, shown
354" when switching buffers. If a buffer is switched to, then a message if
355" echoed, we should show the message, rather than overwriting it with
356" fileinfo.
357func Test_fileinfo_after_echo()
358 CheckScreendump
359
360 let content =<< trim END
361 file a.txt
362
363 hide edit b.txt
364 call setline(1, "hi")
365 setlocal modified
366
367 hide buffer a.txt
368
Bram Moolenaar9323ca52022-03-16 11:14:57 +0000369 autocmd CursorHold * buf b.txt | w | echo "'b' written"
Rob Pilling726f7f92022-01-20 14:44:38 +0000370 END
371
372 call writefile(content, 'Xtest_fileinfo_after_echo')
373 let buf = RunVimInTerminal('-S Xtest_fileinfo_after_echo', #{rows: 6})
Bram Moolenaar9323ca52022-03-16 11:14:57 +0000374 call term_sendkeys(buf, ":set updatetime=50\<CR>")
375 call term_sendkeys(buf, "0$")
Rob Pilling726f7f92022-01-20 14:44:38 +0000376 call VerifyScreenDump(buf, 'Test_fileinfo_after_echo', {})
377
378 call term_sendkeys(buf, ":q\<CR>")
379
380 " clean up
381 call StopVimInTerminal(buf)
382 call delete('Xtest_fileinfo_after_echo')
Yegappan Lakshmanan7e765a32022-01-24 11:40:37 +0000383 call delete('b.txt')
Rob Pilling726f7f92022-01-20 14:44:38 +0000384endfunc
385
Bram Moolenaar37fef162022-08-29 18:16:32 +0100386func Test_echowindow()
387 CheckScreendump
388
389 let lines =<< trim END
390 call setline(1, 'some text')
391 func ShowMessage(arg)
392 echowindow a:arg
393 endfunc
394 echowindow 'first line'
Bram Moolenaarb5b4f612022-09-01 16:43:17 +0100395 func ManyMessages()
396 for n in range(20)
397 echowindow 'line' n
398 endfor
399 endfunc
Bram Moolenaarcf0995d2022-09-11 21:36:17 +0100400
401 def TwoMessages()
402 popup_clear()
403 set cmdheight=2
404 redraw
405 timer_start(100, (_) => {
406 echowin 'message'
407 })
408 echo 'one'
409 echo 'two'
410 enddef
411
412 def ThreeMessages()
413 popup_clear()
414 redraw
415 timer_start(100, (_) => {
416 echowin 'later message'
417 })
418 echo 'one'
419 echo 'two'
420 echo 'three'
421 enddef
Bram Moolenaar37fef162022-08-29 18:16:32 +0100422 END
423 call writefile(lines, 'XtestEchowindow')
424 let buf = RunVimInTerminal('-S XtestEchowindow', #{rows: 8})
425 call VerifyScreenDump(buf, 'Test_echowindow_1', {})
426
427 call term_sendkeys(buf, ":call ShowMessage('second line')\<CR>")
428 call VerifyScreenDump(buf, 'Test_echowindow_2', {})
429
430 call term_sendkeys(buf, ":call popup_clear()\<CR>")
431 call VerifyScreenDump(buf, 'Test_echowindow_3', {})
432
Bram Moolenaarb5b4f612022-09-01 16:43:17 +0100433 call term_sendkeys(buf, ":call ManyMessages()\<CR>")
434 call VerifyScreenDump(buf, 'Test_echowindow_4', {})
435
Bram Moolenaarcf0995d2022-09-11 21:36:17 +0100436 call term_sendkeys(buf, ":call TwoMessages()\<CR>")
437 call VerifyScreenDump(buf, 'Test_echowindow_5', {})
438
439 call term_sendkeys(buf, ":call ThreeMessages()\<CR>")
440 sleep 120m
441 call VerifyScreenDump(buf, 'Test_echowindow_6', {})
442
443 call term_sendkeys(buf, "\<CR>")
444 call VerifyScreenDump(buf, 'Test_echowindow_7', {})
445
Bram Moolenaar37fef162022-08-29 18:16:32 +0100446 " clean up
447 call StopVimInTerminal(buf)
448 call delete('XtestEchowindow')
449endfunc
450
Yasuhiro Matsumotoa02a8a42022-09-02 12:16:21 +0100451" messages window should not be used while evaluating the :echowin argument
452func Test_echowin_eval()
453 CheckScreendump
454
455 let lines =<< trim END
456 func ShowMessage()
457 echo 123
458 return 'test'
459 endfunc
460 echowindow ShowMessage()
461 END
462 call writefile(lines, 'XtestEchowindow')
463 let buf = RunVimInTerminal('-S XtestEchowindow', #{rows: 8})
464 call VerifyScreenDump(buf, 'Test_echowin_eval', {})
465
466 " clean up
467 call StopVimInTerminal(buf)
468 call delete('XtestEchowindow')
469endfunc
470
Bram Moolenaar7cf58392022-09-09 20:19:40 +0100471" messages window should not be used for showing the mode
472func Test_echowin_showmode()
473 CheckScreendump
474
475 let lines =<< trim END
476 vim9script
477 setline(1, ['one', 'two'])
478 timer_start(100, (_) => {
479 echowin 'echo window'
480 })
481 normal V
482 END
483 call writefile(lines, 'XtestEchowinMode', 'D')
484 let buf = RunVimInTerminal('-S XtestEchowinMode', #{rows: 8})
485 call VerifyScreenDump(buf, 'Test_echowin_showmode', {})
486
487 " clean up
488 call StopVimInTerminal(buf)
489endfunc
490
Bram Moolenaar43568642022-08-28 13:02:45 +0100491
Bram Moolenaar92b83cc2020-04-25 15:24:44 +0200492" vim: shiftwidth=2 sts=2 expandtab