blob: 96a9e63c131d3f2aa12d27a1c9fdd2e69ce0c3de [file] [log] [blame]
Bram Moolenaar18aa13d2020-07-11 13:09:36 +02001" Tests for the terminal window.
2" This is split in two, because it can take a lot of time.
3" See test_terminal.vim and test_terminal2.vim for further tests.
4
5source check.vim
6CheckFeature terminal
7
8source shared.vim
9source screendump.vim
10source mouse.vim
11source term_util.vim
12
13let $PROMPT_COMMAND=''
14
15func Test_terminal_altscreen()
16 " somehow doesn't work on MS-Windows
17 CheckUnix
18 let cmd = "cat Xtext\<CR>"
19
20 let buf = term_start(&shell, {})
Yegappan Lakshmanane446a012023-01-19 17:49:58 +000021 call TermWait(buf)
Bram Moolenaarc4860bd2022-10-15 20:52:26 +010022 call writefile(["\<Esc>[?1047h"], 'Xtext', 'D')
Bram Moolenaar18aa13d2020-07-11 13:09:36 +020023 call term_sendkeys(buf, cmd)
24 call WaitForAssert({-> assert_equal(1, term_getaltscreen(buf))})
25
26 call writefile(["\<Esc>[?1047l"], 'Xtext')
27 call term_sendkeys(buf, cmd)
28 call WaitForAssert({-> assert_equal(0, term_getaltscreen(buf))})
29
30 call term_sendkeys(buf, "exit\r")
31 exe buf . "bwipe!"
Bram Moolenaar18aa13d2020-07-11 13:09:36 +020032endfunc
33
34func Test_terminal_shell_option()
35 if has('unix')
36 " exec is a shell builtin command, should fail without a shell.
37 term exec ls runtest.vim
38 call WaitForAssert({-> assert_match('job failed', term_getline(bufnr(), 1))})
39 bwipe!
40
41 term ++shell exec ls runtest.vim
42 call WaitForAssert({-> assert_match('runtest.vim', term_getline(bufnr(), 1))})
43 bwipe!
44 elseif has('win32')
45 " dir is a shell builtin command, should fail without a shell.
Bram Moolenaar066b12e2020-07-28 21:40:27 +020046 " However, if dir.exe (which might be provided by Cygwin/MSYS2) exists in
47 " the %PATH%, "term dir" succeeds unintentionally. Use dir.com instead.
Bram Moolenaar18aa13d2020-07-11 13:09:36 +020048 try
Bram Moolenaar066b12e2020-07-28 21:40:27 +020049 term dir.com /b runtest.vim
50 call WaitForAssert({-> assert_match('job failed', term_getline(bufnr(), 1))})
Bram Moolenaar18aa13d2020-07-11 13:09:36 +020051 catch /CreateProcess/
52 " ignore
53 endtry
54 bwipe!
55
Bram Moolenaar066b12e2020-07-28 21:40:27 +020056 " This should execute the dir builtin command even with ".com".
57 term ++shell dir.com /b runtest.vim
Bram Moolenaar18aa13d2020-07-11 13:09:36 +020058 call WaitForAssert({-> assert_match('runtest.vim', term_getline(bufnr(), 1))})
59 bwipe!
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020060 else
61 throw 'Skipped: does not work on this platform'
Bram Moolenaar18aa13d2020-07-11 13:09:36 +020062 endif
63endfunc
64
65func Test_terminal_invalid_arg()
66 call assert_fails('terminal ++xyz', 'E181:')
67endfunc
68
Bram Moolenaar87fd0922021-11-20 13:47:45 +000069" Check a terminal with different colors
70func Terminal_color(group_name, highlight_cmds, highlight_opt, open_cmds)
71 CheckRunVimInTerminal
72 CheckUnix
73
74 let lines = [
75 \ 'call setline(1, range(20))',
76 \ 'func OpenTerm()',
77 \ ' set noruler',
78 \ " call term_start('cat', #{vertical: 1, " .. a:highlight_opt .. "})",
79 \ ] + a:open_cmds + [
80 \ 'endfunc',
81 \ ] + a:highlight_cmds
Bram Moolenaarc4860bd2022-10-15 20:52:26 +010082 call writefile(lines, 'XtermStart', 'D')
Bram Moolenaar87fd0922021-11-20 13:47:45 +000083 let buf = RunVimInTerminal('-S XtermStart', #{rows: 15})
84 call TermWait(buf, 100)
85 call term_sendkeys(buf, ":call OpenTerm()\<CR>")
86 call TermWait(buf, 50)
87 call term_sendkeys(buf, "hello\<CR>")
88 call VerifyScreenDump(buf, 'Test_terminal_color_' .. a:group_name, {})
89
90 call term_sendkeys(buf, "\<C-D>")
91 call TermWait(buf, 50)
92 call StopVimInTerminal(buf)
Bram Moolenaar87fd0922021-11-20 13:47:45 +000093endfunc
94
95func Test_terminal_color_Terminal()
96 call Terminal_color("Terminal", [
97 \ "highlight Terminal ctermfg=blue ctermbg=yellow",
98 \ ], "", [])
99endfunc
100
101func Test_terminal_color_group()
102 call Terminal_color("MyTermCol", [
103 \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue",
104 \ ], "term_highlight: 'MyTermCol',", [])
105endfunc
106
107func Test_terminal_color_wincolor()
108 call Terminal_color("MyWinCol", [
109 \ "highlight MyWinCol ctermfg=red ctermbg=darkyellow",
110 \ ], "", [
111 \ 'set wincolor=MyWinCol',
112 \ ])
113endfunc
114
115func Test_terminal_color_group_over_Terminal()
116 call Terminal_color("MyTermCol_over_Terminal", [
117 \ "highlight Terminal ctermfg=blue ctermbg=yellow",
118 \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue",
119 \ ], "term_highlight: 'MyTermCol',", [])
120endfunc
121
122func Test_terminal_color_wincolor_over_group()
123 call Terminal_color("MyWinCol_over_group", [
124 \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue",
125 \ "highlight MyWinCol ctermfg=red ctermbg=darkyellow",
126 \ ], "term_highlight: 'MyTermCol',", [
127 \ 'set wincolor=MyWinCol',
128 \ ])
129endfunc
130
131func Test_terminal_color_wincolor_split()
132 CheckRunVimInTerminal
133 CheckUnix
134
135 let lines = [
136 \ 'call setline(1, range(20))',
137 \ 'func OpenTerm()',
138 \ ' set noruler',
139 \ " call term_start('cat', #{vertical: 1, term_highlight: 'MyTermCol'})",
140 \ 'endfunc',
141 \ 'highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue',
142 \ 'highlight MyWinCol ctermfg=red ctermbg=darkyellow',
143 \ 'highlight MyWinCol2 ctermfg=black ctermbg=blue',
144 \ ]
Bram Moolenaarc4860bd2022-10-15 20:52:26 +0100145 call writefile(lines, 'XtermStart', 'D')
Bram Moolenaar87fd0922021-11-20 13:47:45 +0000146 let buf = RunVimInTerminal('-S XtermStart', #{rows: 15})
147 call TermWait(buf, 100)
148 call term_sendkeys(buf, ":call OpenTerm()\<CR>")
149 call TermWait(buf, 50)
150 call term_sendkeys(buf, "hello\<CR>")
151 call TermWait(buf, 50)
152
153 call term_sendkeys(buf, "\<C-W>:split\<CR>")
154 call term_sendkeys(buf, "\<C-W>:set wincolor=MyWinCol\<CR>")
155 call VerifyScreenDump(buf, 'Test_terminal_wincolor_split_MyWinCol', {})
156
157 call term_sendkeys(buf, "\<C-W>b:2sb\<CR>")
158 call term_sendkeys(buf, "\<C-W>:set wincolor=MyWinCol2\<CR>")
159 call VerifyScreenDump(buf, 'Test_terminal_wincolor_split_MyWinCol2', {})
160
161 call term_sendkeys(buf, "\<C-D>")
162 call TermWait(buf, 50)
163 call StopVimInTerminal(buf)
Bram Moolenaar87fd0922021-11-20 13:47:45 +0000164endfunc
165
166func Test_terminal_color_transp_Terminal()
167 call Terminal_color("transp_Terminal", [
168 \ "highlight Terminal ctermfg=blue",
169 \ ], "", [])
170endfunc
171
172func Test_terminal_color_transp_group()
173 call Terminal_color("transp_MyTermCol", [
174 \ "highlight MyTermCol ctermfg=darkgreen",
175 \ ], "term_highlight: 'MyTermCol',", [])
176endfunc
177
178func Test_terminal_color_transp_wincolor()
179 call Terminal_color("transp_MyWinCol", [
180 \ "highlight MyWinCol ctermfg=red",
181 \ ], "", [
182 \ 'set wincolor=MyWinCol',
183 \ ])
184endfunc
185
186func Test_terminal_color_gui_Terminal()
187 CheckFeature termguicolors
188 call Terminal_color("gui_Terminal", [
189 \ "set termguicolors",
190 \ "highlight Terminal guifg=#3344ff guibg=#b0a700",
191 \ ], "", [])
192endfunc
193
194func Test_terminal_color_gui_group()
195 CheckFeature termguicolors
196 call Terminal_color("gui_MyTermCol", [
197 \ "set termguicolors",
198 \ "highlight MyTermCol guifg=#007800 guibg=#6789ff",
199 \ ], "term_highlight: 'MyTermCol',", [])
200endfunc
201
202func Test_terminal_color_gui_wincolor()
203 CheckFeature termguicolors
204 call Terminal_color("gui_MyWinCol", [
205 \ "set termguicolors",
206 \ "highlight MyWinCol guifg=#fe1122 guibg=#818100",
207 \ ], "", [
208 \ 'set wincolor=MyWinCol',
209 \ ])
210endfunc
211
212func Test_terminal_color_gui_transp_Terminal()
213 CheckFeature termguicolors
214 call Terminal_color("gui_transp_Terminal", [
215 \ "set termguicolors",
216 \ "highlight Terminal guifg=#3344ff",
217 \ ], "", [])
218endfunc
219
220func Test_terminal_color_gui_transp_group()
221 CheckFeature termguicolors
222 call Terminal_color("gui_transp_MyTermCol", [
223 \ "set termguicolors",
224 \ "highlight MyTermCol guifg=#007800",
225 \ ], "term_highlight: 'MyTermCol',", [])
226endfunc
227
228func Test_terminal_color_gui_transp_wincolor()
229 CheckFeature termguicolors
230 call Terminal_color("gui_transp_MyWinCol", [
231 \ "set termguicolors",
232 \ "highlight MyWinCol guifg=#fe1122",
233 \ ], "", [
234 \ 'set wincolor=MyWinCol',
235 \ ])
236endfunc
237
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200238func Test_terminal_in_popup()
239 CheckRunVimInTerminal
240
241 let text =<< trim END
242 some text
243 to edit
244 in a popup window
245 END
Bram Moolenaarc4860bd2022-10-15 20:52:26 +0100246 call writefile(text, 'Xtext', 'D')
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200247 let cmd = GetVimCommandCleanTerm()
248 let lines = [
249 \ 'call setline(1, range(20))',
250 \ 'hi PopTerm ctermbg=grey',
251 \ 'func OpenTerm(setColor)',
252 \ " set noruler",
253 \ " let s:buf = term_start('" .. cmd .. " Xtext', #{hidden: 1, term_finish: 'close'})",
254 \ ' let g:winid = popup_create(s:buf, #{minwidth: 45, minheight: 7, border: [], drag: 1, resize: 1})',
255 \ ' if a:setColor',
256 \ ' call win_execute(g:winid, "set wincolor=PopTerm")',
257 \ ' endif',
258 \ 'endfunc',
259 \ 'func HidePopup()',
260 \ ' call popup_hide(g:winid)',
261 \ 'endfunc',
262 \ 'func ClosePopup()',
263 \ ' call popup_close(g:winid)',
264 \ 'endfunc',
265 \ 'func ReopenPopup()',
266 \ ' call popup_create(s:buf, #{minwidth: 40, minheight: 6, border: []})',
267 \ 'endfunc',
268 \ ]
Bram Moolenaarc4860bd2022-10-15 20:52:26 +0100269 call writefile(lines, 'XtermPopup', 'D')
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200270 let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15})
James McCoy157241e2022-11-09 23:29:14 +0000271 call TermWait(buf, 200)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200272 call term_sendkeys(buf, ":call OpenTerm(0)\<CR>")
James McCoy157241e2022-11-09 23:29:14 +0000273 call TermWait(buf, 800)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200274 call term_sendkeys(buf, ":\<CR>")
James McCoy157241e2022-11-09 23:29:14 +0000275 call TermWait(buf, 500)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200276 call term_sendkeys(buf, "\<C-W>:echo getwinvar(g:winid, \"&buftype\") win_gettype(g:winid)\<CR>")
277 call VerifyScreenDump(buf, 'Test_terminal_popup_1', {})
278
279 call term_sendkeys(buf, ":q\<CR>")
280 call VerifyScreenDump(buf, 'Test_terminal_popup_2', {})
281
282 call term_sendkeys(buf, ":call OpenTerm(1)\<CR>")
James McCoy157241e2022-11-09 23:29:14 +0000283 call TermWait(buf, 800)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200284 call term_sendkeys(buf, ":set hlsearch\<CR>")
James McCoy157241e2022-11-09 23:29:14 +0000285 call TermWait(buf, 500)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200286 call term_sendkeys(buf, "/edit\<CR>")
287 call VerifyScreenDump(buf, 'Test_terminal_popup_3', {})
288
289 call term_sendkeys(buf, "\<C-W>:call HidePopup()\<CR>")
290 call VerifyScreenDump(buf, 'Test_terminal_popup_4', {})
291 call term_sendkeys(buf, "\<CR>")
292 call TermWait(buf, 50)
293
294 call term_sendkeys(buf, "\<C-W>:call ClosePopup()\<CR>")
295 call VerifyScreenDump(buf, 'Test_terminal_popup_5', {})
296
297 call term_sendkeys(buf, "\<C-W>:call ReopenPopup()\<CR>")
298 call VerifyScreenDump(buf, 'Test_terminal_popup_6', {})
299
300 " Go to terminal-Normal mode and visually select text.
301 call term_sendkeys(buf, "\<C-W>Ngg/in\<CR>vww")
302 call VerifyScreenDump(buf, 'Test_terminal_popup_7', {})
303
304 " Back to job mode, redraws
305 call term_sendkeys(buf, "A")
306 call VerifyScreenDump(buf, 'Test_terminal_popup_8', {})
307
308 call TermWait(buf, 50)
309 call term_sendkeys(buf, ":q\<CR>")
Bram Moolenaar4d8c96d2020-12-29 20:53:33 +0100310 call TermWait(buf, 250) " wait for terminal to vanish
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200311
312 call StopVimInTerminal(buf)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200313endfunc
314
Bram Moolenaar8e7d6222020-12-18 19:49:56 +0100315" Check a terminal in popup window uses the default minimum size.
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200316func Test_terminal_in_popup_min_size()
317 CheckRunVimInTerminal
318
319 let text =<< trim END
320 another text
321 to show
322 in a popup window
323 END
Bram Moolenaarc4860bd2022-10-15 20:52:26 +0100324 call writefile(text, 'Xtext', 'D')
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200325 let lines = [
326 \ 'call setline(1, range(20))',
327 \ 'func OpenTerm()',
328 \ " let s:buf = term_start('cat Xtext', #{hidden: 1})",
329 \ ' let g:winid = popup_create(s:buf, #{ border: []})',
330 \ 'endfunc',
331 \ ]
Bram Moolenaarc4860bd2022-10-15 20:52:26 +0100332 call writefile(lines, 'XtermPopup', 'D')
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200333 let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15})
334 call TermWait(buf, 100)
335 call term_sendkeys(buf, ":set noruler\<CR>")
336 call term_sendkeys(buf, ":call OpenTerm()\<CR>")
337 call TermWait(buf, 50)
338 call term_sendkeys(buf, ":\<CR>")
339 call VerifyScreenDump(buf, 'Test_terminal_popup_m1', {})
340
341 call TermWait(buf, 50)
342 call term_sendkeys(buf, ":q\<CR>")
343 call TermWait(buf, 50) " wait for terminal to vanish
344 call StopVimInTerminal(buf)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200345endfunc
346
347" Check a terminal in popup window with different colors
Bram Moolenaar87fd0922021-11-20 13:47:45 +0000348func Terminal_in_popup_color(group_name, highlight_cmds, highlight_opt, popup_cmds, popup_opt)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200349 CheckRunVimInTerminal
350 CheckUnix
351
352 let lines = [
353 \ 'call setline(1, range(20))',
354 \ 'func OpenTerm()',
355 \ " let s:buf = term_start('cat', #{hidden: 1, "
356 \ .. a:highlight_opt .. "})",
Bram Moolenaar87fd0922021-11-20 13:47:45 +0000357 \ ' let g:winid = popup_create(s:buf, #{border: [], '
358 \ .. a:popup_opt .. '})',
359 \ ] + a:popup_cmds + [
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200360 \ 'endfunc',
Bram Moolenaar87fd0922021-11-20 13:47:45 +0000361 \ ] + a:highlight_cmds
Bram Moolenaarc4860bd2022-10-15 20:52:26 +0100362 call writefile(lines, 'XtermPopup', 'D')
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200363 let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15})
364 call TermWait(buf, 100)
365 call term_sendkeys(buf, ":set noruler\<CR>")
366 call term_sendkeys(buf, ":call OpenTerm()\<CR>")
367 call TermWait(buf, 50)
368 call term_sendkeys(buf, "hello\<CR>")
369 call VerifyScreenDump(buf, 'Test_terminal_popup_' .. a:group_name, {})
370
371 call term_sendkeys(buf, "\<C-D>")
372 call TermWait(buf, 50)
373 call term_sendkeys(buf, ":q\<CR>")
374 call TermWait(buf, 50) " wait for terminal to vanish
375 call StopVimInTerminal(buf)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200376endfunc
377
Bram Moolenaar87fd0922021-11-20 13:47:45 +0000378func Test_terminal_in_popup_color_Terminal()
379 call Terminal_in_popup_color("Terminal", [
380 \ "highlight Terminal ctermfg=blue ctermbg=yellow",
381 \ ], "", [], "")
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200382endfunc
383
Bram Moolenaar87fd0922021-11-20 13:47:45 +0000384func Test_terminal_in_popup_color_group()
385 call Terminal_in_popup_color("MyTermCol", [
386 \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue",
387 \ ], "term_highlight: 'MyTermCol',", [], "")
388endfunc
389
390func Test_terminal_in_popup_color_wincolor()
391 call Terminal_in_popup_color("MyWinCol", [
392 \ "highlight MyWinCol ctermfg=red ctermbg=darkyellow",
393 \ ], "", [
394 \ 'call setwinvar(g:winid, "&wincolor", "MyWinCol")',
395 \ ], "")
396endfunc
397
398func Test_terminal_in_popup_color_popup_highlight()
399 call Terminal_in_popup_color("MyPopupHlCol", [
400 \ "highlight MyPopupHlCol ctermfg=cyan ctermbg=green",
401 \ ], "", [], "highlight: 'MyPopupHlCol'")
402endfunc
403
404func Test_terminal_in_popup_color_group_over_Terminal()
405 call Terminal_in_popup_color("MyTermCol_over_Terminal", [
406 \ "highlight Terminal ctermfg=blue ctermbg=yellow",
407 \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue",
408 \ ], "term_highlight: 'MyTermCol',", [], "")
409endfunc
410
411func Test_terminal_in_popup_color_wincolor_over_group()
412 call Terminal_in_popup_color("MyWinCol_over_group", [
413 \ "highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue",
414 \ "highlight MyWinCol ctermfg=red ctermbg=darkyellow",
415 \ ], "term_highlight: 'MyTermCol',", [
416 \ 'call setwinvar(g:winid, "&wincolor", "MyWinCol")',
417 \ ], "")
418endfunc
419
420func Test_terminal_in_popup_color_transp_Terminal()
421 call Terminal_in_popup_color("transp_Terminal", [
422 \ "highlight Terminal ctermfg=blue",
423 \ ], "", [], "")
424endfunc
425
426func Test_terminal_in_popup_color_transp_group()
427 call Terminal_in_popup_color("transp_MyTermCol", [
428 \ "highlight MyTermCol ctermfg=darkgreen",
429 \ ], "term_highlight: 'MyTermCol',", [], "")
430endfunc
431
432func Test_terminal_in_popup_color_transp_wincolor()
433 call Terminal_in_popup_color("transp_MyWinCol", [
434 \ "highlight MyWinCol ctermfg=red",
435 \ ], "", [
436 \ 'call setwinvar(g:winid, "&wincolor", "MyWinCol")',
437 \ ], "")
438endfunc
439
440func Test_terminal_in_popup_color_transp_popup_highlight()
441 call Terminal_in_popup_color("transp_MyPopupHlCol", [
442 \ "highlight MyPopupHlCol ctermfg=cyan",
443 \ ], "", [], "highlight: 'MyPopupHlCol'")
444endfunc
445
446func Test_terminal_in_popup_color_gui_Terminal()
447 CheckFeature termguicolors
448 call Terminal_in_popup_color("gui_Terminal", [
449 \ "set termguicolors",
450 \ "highlight Terminal guifg=#3344ff guibg=#b0a700",
451 \ ], "", [], "")
452endfunc
453
454func Test_terminal_in_popup_color_gui_group()
455 CheckFeature termguicolors
456 call Terminal_in_popup_color("gui_MyTermCol", [
457 \ "set termguicolors",
458 \ "highlight MyTermCol guifg=#007800 guibg=#6789ff",
459 \ ], "term_highlight: 'MyTermCol',", [], "")
460endfunc
461
462func Test_terminal_in_popup_color_gui_wincolor()
463 CheckFeature termguicolors
464 call Terminal_in_popup_color("gui_MyWinCol", [
465 \ "set termguicolors",
466 \ "highlight MyWinCol guifg=#fe1122 guibg=#818100",
467 \ ], "", [
468 \ 'call setwinvar(g:winid, "&wincolor", "MyWinCol")',
469 \ ], "")
470endfunc
471
472func Test_terminal_in_popup_color_gui_popup_highlight()
473 CheckFeature termguicolors
474 call Terminal_in_popup_color("gui_MyPopupHlCol", [
475 \ "set termguicolors",
476 \ "highlight MyPopupHlCol guifg=#00e8f0 guibg=#126521",
477 \ ], "", [], "highlight: 'MyPopupHlCol'")
478endfunc
479
480func Test_terminal_in_popup_color_gui_transp_Terminal()
481 CheckFeature termguicolors
482 call Terminal_in_popup_color("gui_transp_Terminal", [
483 \ "set termguicolors",
484 \ "highlight Terminal guifg=#3344ff",
485 \ ], "", [], "")
486endfunc
487
488func Test_terminal_in_popup_color_gui_transp_group()
489 CheckFeature termguicolors
490 call Terminal_in_popup_color("gui_transp_MyTermCol", [
491 \ "set termguicolors",
492 \ "highlight MyTermCol guifg=#007800",
493 \ ], "term_highlight: 'MyTermCol',", [], "")
494endfunc
495
496func Test_terminal_in_popup_color_gui_transp_wincolor()
497 CheckFeature termguicolors
498 call Terminal_in_popup_color("gui_transp_MyWinCol", [
499 \ "set termguicolors",
500 \ "highlight MyWinCol guifg=#fe1122",
501 \ ], "", [
502 \ 'call setwinvar(g:winid, "&wincolor", "MyWinCol")',
503 \ ], "")
504endfunc
505
506func Test_terminal_in_popup_color_gui_transp_popup_highlight()
507 CheckFeature termguicolors
508 call Terminal_in_popup_color("gui_transp_MyPopupHlCol", [
509 \ "set termguicolors",
510 \ "highlight MyPopupHlCol guifg=#00e8f0",
511 \ ], "", [], "highlight: 'MyPopupHlCol'")
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200512endfunc
513
514func Test_double_popup_terminal()
515 let buf1 = term_start(&shell, #{hidden: 1})
516 let win1 = popup_create(buf1, {})
517 let buf2 = term_start(&shell, #{hidden: 1})
518 call assert_fails('call popup_create(buf2, {})', 'E861:')
519 call popup_close(win1)
520 exe buf1 .. 'bwipe!'
521 exe buf2 .. 'bwipe!'
522endfunc
523
LemonBoy4a392d22022-04-23 14:07:56 +0100524func Test_escape_popup_terminal()
525 set hidden
526
527 " Cannot escape a terminal popup window using win_gotoid
528 let prev_win = win_getid()
529 eval term_start('sh', #{hidden: 1, term_finish: 'close'})->popup_create({})
530 call assert_fails("call win_gotoid(" .. prev_win .. ")", 'E863:')
531
532 call popup_clear(1)
533 set hidden&
534endfunc
535
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200536func Test_issue_5607()
537 let wincount = winnr('$')
538 exe 'terminal' &shell &shellcmdflag 'exit'
539 let job = term_getjob(bufnr())
540 call WaitForAssert({-> assert_equal("dead", job_status(job))})
541
542 let old_wincolor = &wincolor
543 try
544 set wincolor=
545 finally
546 let &wincolor = old_wincolor
547 bw!
548 endtry
549endfunc
550
551func Test_hidden_terminal()
552 let buf = term_start(&shell, #{hidden: 1})
553 call assert_equal('', bufname('^$'))
554 call StopShellInTerminal(buf)
555endfunc
556
557func Test_term_nasty_callback()
558 CheckExecutable sh
559
560 set hidden
561 let g:buf0 = term_start('sh', #{hidden: 1, term_finish: 'close'})
562 call popup_create(g:buf0, {})
563 call assert_fails("call term_start(['sh', '-c'], #{curwin: 1})", 'E863:')
564
565 call popup_clear(1)
566 set hidden&
567endfunc
568
569func Test_term_and_startinsert()
570 CheckRunVimInTerminal
571 CheckUnix
572
573 let lines =<< trim EOL
574 put='some text'
575 term
576 startinsert
577 EOL
Bram Moolenaarc4860bd2022-10-15 20:52:26 +0100578 call writefile(lines, 'XTest_startinsert', 'D')
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200579 let buf = RunVimInTerminal('-S XTest_startinsert', {})
580
581 call term_sendkeys(buf, "exit\r")
582 call WaitForAssert({-> assert_equal("some text", term_getline(buf, 1))})
583 call term_sendkeys(buf, "0l")
584 call term_sendkeys(buf, "A<\<Esc>")
585 call WaitForAssert({-> assert_equal("some text<", term_getline(buf, 1))})
586
587 call StopVimInTerminal(buf)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200588endfunc
589
590" Test for passing invalid arguments to terminal functions
591func Test_term_func_invalid_arg()
592 call assert_fails('let b = term_getaltscreen([])', 'E745:')
593 call assert_fails('let a = term_getattr(1, [])', 'E730:')
594 call assert_fails('let c = term_getcursor([])', 'E745:')
595 call assert_fails('let l = term_getline([], 1)', 'E745:')
596 call assert_fails('let l = term_getscrolled([])', 'E745:')
597 call assert_fails('let s = term_getsize([])', 'E745:')
598 call assert_fails('let s = term_getstatus([])', 'E745:')
599 call assert_fails('let s = term_scrape([], 1)', 'E745:')
600 call assert_fails('call term_sendkeys([], "a")', 'E745:')
601 call assert_fails('call term_setapi([], "")', 'E745:')
602 call assert_fails('call term_setrestore([], "")', 'E745:')
603 call assert_fails('call term_setkill([], "")', 'E745:')
604 if has('gui') || has('termguicolors')
605 call assert_fails('let p = term_getansicolors([])', 'E745:')
606 call assert_fails('call term_setansicolors([], [])', 'E745:')
607 endif
Bram Moolenaara1070ea2021-02-20 19:21:36 +0100608 let buf = term_start('echo')
609 call assert_fails('call term_setapi(' .. buf .. ', {})', 'E731:')
610 call assert_fails('call term_setkill(' .. buf .. ', {})', 'E731:')
611 call assert_fails('call term_setrestore(' .. buf .. ', {})', 'E731:')
612 exe buf . "bwipe!"
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200613endfunc
614
615" Test for sending various special keycodes to a terminal
616func Test_term_keycode_translation()
617 CheckRunVimInTerminal
618
619 let buf = RunVimInTerminal('', {})
620 call term_sendkeys(buf, ":set nocompatible\<CR>")
Bram Moolenaar4d8c96d2020-12-29 20:53:33 +0100621 call term_sendkeys(buf, ":set timeoutlen=20\<CR>")
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200622
623 let keys = ["\<F1>", "\<F2>", "\<F3>", "\<F4>", "\<F5>", "\<F6>", "\<F7>",
624 \ "\<F8>", "\<F9>", "\<F10>", "\<F11>", "\<F12>", "\<Home>",
625 \ "\<S-Home>", "\<C-Home>", "\<End>", "\<S-End>", "\<C-End>",
626 \ "\<Ins>", "\<Del>", "\<Left>", "\<S-Left>", "\<C-Left>", "\<Right>",
627 \ "\<S-Right>", "\<C-Right>", "\<Up>", "\<S-Up>", "\<Down>",
628 \ "\<S-Down>"]
629 let output = ['<F1>', '<F2>', '<F3>', '<F4>', '<F5>', '<F6>', '<F7>',
630 \ '<F8>', '<F9>', '<F10>', '<F11>', '<F12>', '<Home>', '<S-Home>',
631 \ '<C-Home>', '<End>', '<S-End>', '<C-End>', '<Insert>', '<Del>',
632 \ '<Left>', '<S-Left>', '<C-Left>', '<Right>', '<S-Right>',
633 \ '<C-Right>', '<Up>', '<S-Up>', '<Down>', '<S-Down>']
634
635 call term_sendkeys(buf, "i")
636 for i in range(len(keys))
637 call term_sendkeys(buf, "\<C-U>\<C-K>" .. keys[i])
Bram Moolenaar4d8c96d2020-12-29 20:53:33 +0100638 call WaitForAssert({-> assert_equal(output[i], term_getline(buf, 1))}, 200)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200639 endfor
640
641 let keypad_keys = ["\<k0>", "\<k1>", "\<k2>", "\<k3>", "\<k4>", "\<k5>",
642 \ "\<k6>", "\<k7>", "\<k8>", "\<k9>", "\<kPoint>", "\<kPlus>",
643 \ "\<kMinus>", "\<kMultiply>", "\<kDivide>"]
644 let keypad_output = ['0', '1', '2', '3', '4', '5',
645 \ '6', '7', '8', '9', '.', '+',
646 \ '-', '*', '/']
647 for i in range(len(keypad_keys))
648 " TODO: Mysteriously keypad 3 and 9 do not work on some systems.
649 if keypad_output[i] == '3' || keypad_output[i] == '9'
650 continue
651 endif
652 call term_sendkeys(buf, "\<C-U>" .. keypad_keys[i])
Bram Moolenaar4d8c96d2020-12-29 20:53:33 +0100653 call WaitForAssert({-> assert_equal(keypad_output[i], term_getline(buf, 1))}, 100)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200654 endfor
655
656 call feedkeys("\<C-U>\<kEnter>\<BS>one\<C-W>.two", 'xt')
657 call WaitForAssert({-> assert_equal('two', term_getline(buf, 1))})
658
659 call StopVimInTerminal(buf)
660endfunc
661
662" Test for using the mouse in a terminal
663func Test_term_mouse()
664 CheckNotGui
665 CheckRunVimInTerminal
666
667 let save_mouse = &mouse
668 let save_term = &term
669 let save_ttymouse = &ttymouse
670 let save_clipboard = &clipboard
671 set mouse=a term=xterm ttymouse=sgr mousetime=200 clipboard=
672
673 let lines =<< trim END
674 one two three four five
675 red green yellow red blue
676 vim emacs sublime nano
677 END
Bram Moolenaarc4860bd2022-10-15 20:52:26 +0100678 call writefile(lines, 'Xtest_mouse', 'D')
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200679
680 " Create a terminal window running Vim for the test with mouse enabled
681 let prev_win = win_getid()
682 let buf = RunVimInTerminal('Xtest_mouse -n', {})
683 call term_sendkeys(buf, ":set nocompatible\<CR>")
684 call term_sendkeys(buf, ":set mouse=a term=xterm ttymouse=sgr\<CR>")
685 call term_sendkeys(buf, ":set clipboard=\<CR>")
686 call term_sendkeys(buf, ":set mousemodel=extend\<CR>")
Bram Moolenaar733d2592020-08-20 18:59:06 +0200687 call TermWait(buf)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200688 redraw!
689
Bram Moolenaar98aebcc2022-11-10 12:38:16 +0000690 " Funcref used in WaitFor() to check that the "Xbuf" file is readable and
691 " has some contents. This avoids a "List index out of range" error when the
692 " file hasn't been written yet.
693 let XbufNotEmpty = {-> filereadable('Xbuf') && len(readfile('Xbuf')) > 0}
James McCoy157241e2022-11-09 23:29:14 +0000694
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200695 " Use the mouse to enter the terminal window
696 call win_gotoid(prev_win)
697 call feedkeys(MouseLeftClickCode(1, 1), 'x')
698 call feedkeys(MouseLeftReleaseCode(1, 1), 'x')
699 call assert_equal(1, getwininfo(win_getid())[0].terminal)
700
701 " Test for <LeftMouse> click/release
702 call test_setmouse(2, 5)
703 call feedkeys("\<LeftMouse>\<LeftRelease>", 'xt')
704 call test_setmouse(3, 8)
705 call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>")
Bram Moolenaar733d2592020-08-20 18:59:06 +0200706 call TermWait(buf, 50)
James McCoy157241e2022-11-09 23:29:14 +0000707 call delete('Xbuf')
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200708 call term_sendkeys(buf, ":call writefile([json_encode(getpos('.'))], 'Xbuf')\<CR>")
Bram Moolenaar733d2592020-08-20 18:59:06 +0200709 call TermWait(buf, 50)
Bram Moolenaar98aebcc2022-11-10 12:38:16 +0000710 call WaitFor(XbufNotEmpty)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200711 let pos = json_decode(readfile('Xbuf')[0])
712 call assert_equal([3, 8], pos[1:2])
James McCoy157241e2022-11-09 23:29:14 +0000713 call delete('Xbuf')
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200714
715 " Test for selecting text using mouse
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200716 call test_setmouse(2, 11)
717 call term_sendkeys(buf, "\<LeftMouse>")
718 call test_setmouse(2, 16)
719 call term_sendkeys(buf, "\<LeftRelease>y")
Bram Moolenaar733d2592020-08-20 18:59:06 +0200720 call TermWait(buf, 50)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200721 call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>")
Bram Moolenaar98aebcc2022-11-10 12:38:16 +0000722 call WaitFor(XbufNotEmpty)
Bram Moolenaar1d139a02022-11-10 00:09:22 +0000723 call WaitForAssert({-> assert_equal('yellow', readfile('Xbuf')[0])})
James McCoy157241e2022-11-09 23:29:14 +0000724 call delete('Xbuf')
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200725
Bram Moolenaar87fd0922021-11-20 13:47:45 +0000726 " Test for selecting text using double click
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200727 call test_setmouse(1, 11)
728 call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>\<LeftMouse>")
729 call test_setmouse(1, 17)
730 call term_sendkeys(buf, "\<LeftRelease>y")
Bram Moolenaar733d2592020-08-20 18:59:06 +0200731 call TermWait(buf, 50)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200732 call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>")
Bram Moolenaar98aebcc2022-11-10 12:38:16 +0000733 call WaitFor(XbufNotEmpty)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200734 call assert_equal('three four', readfile('Xbuf')[0])
James McCoy157241e2022-11-09 23:29:14 +0000735 call delete('Xbuf')
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200736
737 " Test for selecting a line using triple click
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200738 call test_setmouse(3, 2)
739 call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>y")
Bram Moolenaar733d2592020-08-20 18:59:06 +0200740 call TermWait(buf, 50)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200741 call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>")
Bram Moolenaar98aebcc2022-11-10 12:38:16 +0000742 call WaitFor(XbufNotEmpty)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200743 call assert_equal("vim emacs sublime nano\n", readfile('Xbuf')[0])
James McCoy157241e2022-11-09 23:29:14 +0000744 call delete('Xbuf')
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200745
Bram Moolenaar87fd0922021-11-20 13:47:45 +0000746 " Test for selecting a block using quadruple click
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200747 call test_setmouse(1, 11)
748 call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>\<LeftMouse>\<LeftRelease>\<LeftMouse>")
749 call test_setmouse(3, 13)
750 call term_sendkeys(buf, "\<LeftRelease>y")
Bram Moolenaar733d2592020-08-20 18:59:06 +0200751 call TermWait(buf, 50)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200752 call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>")
Bram Moolenaar98aebcc2022-11-10 12:38:16 +0000753 call WaitFor(XbufNotEmpty)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200754 call assert_equal("ree\nyel\nsub", readfile('Xbuf')[0])
James McCoy157241e2022-11-09 23:29:14 +0000755 call delete('Xbuf')
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200756
757 " Test for extending a selection using right click
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200758 call test_setmouse(2, 9)
759 call term_sendkeys(buf, "\<LeftMouse>\<LeftRelease>")
760 call test_setmouse(2, 16)
761 call term_sendkeys(buf, "\<RightMouse>\<RightRelease>y")
Bram Moolenaar733d2592020-08-20 18:59:06 +0200762 call TermWait(buf, 50)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200763 call term_sendkeys(buf, ":call writefile([@\"], 'Xbuf')\<CR>")
Bram Moolenaar98aebcc2022-11-10 12:38:16 +0000764 call WaitFor(XbufNotEmpty)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200765 call assert_equal("n yellow", readfile('Xbuf')[0])
James McCoy157241e2022-11-09 23:29:14 +0000766 call delete('Xbuf')
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200767
768 " Test for pasting text using middle click
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200769 call term_sendkeys(buf, ":let @r='bright '\<CR>")
770 call test_setmouse(2, 22)
771 call term_sendkeys(buf, "\"r\<MiddleMouse>\<MiddleRelease>")
Bram Moolenaar733d2592020-08-20 18:59:06 +0200772 call TermWait(buf, 50)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200773 call term_sendkeys(buf, ":call writefile([getline(2)], 'Xbuf')\<CR>")
Bram Moolenaar98aebcc2022-11-10 12:38:16 +0000774 call WaitFor(XbufNotEmpty)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200775 call assert_equal("red bright blue", readfile('Xbuf')[0][-15:])
James McCoy157241e2022-11-09 23:29:14 +0000776 call delete('Xbuf')
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200777
778 " cleanup
Bram Moolenaar733d2592020-08-20 18:59:06 +0200779 call TermWait(buf)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200780 call StopVimInTerminal(buf)
781 let &mouse = save_mouse
782 let &term = save_term
783 let &ttymouse = save_ttymouse
784 let &clipboard = save_clipboard
785 set mousetime&
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200786 call delete('Xbuf')
787endfunc
788
Bram Moolenaar8b9abfd2021-03-29 20:49:05 +0200789" Test for sync buffer cwd with shell's pwd
790func Test_terminal_sync_shell_dir()
791 CheckUnix
792 " The test always use sh (see src/testdir/unix.vim).
Bram Moolenaar7bfa6d62022-01-14 12:06:47 +0000793 " BSD's sh doesn't seem to play well with the OSC 7 escape sequence.
794 CheckNotBSD
Bram Moolenaar8b9abfd2021-03-29 20:49:05 +0200795
796 set asd
797 " , is
798 " 1. a valid character for directory names
799 " 2. a reserved character in url-encoding
800 let chars = ",a"
801 " "," is url-encoded as '%2C'
802 let chars_url = "%2Ca"
Bram Moolenaarced2b382022-01-13 15:25:32 +0000803 let tmpfolder = fnamemodify(tempname(),':h') .. '/' .. chars
804 let tmpfolder_url = fnamemodify(tempname(),':h') .. '/' .. chars_url
Bram Moolenaar8b9abfd2021-03-29 20:49:05 +0200805 call mkdir(tmpfolder, "p")
806 let buf = Run_shell_in_terminal({})
Bram Moolenaarced2b382022-01-13 15:25:32 +0000807 call term_sendkeys(buf, "echo $'\\e\]7;file://" .. tmpfolder_url .. "\\a'\<CR>")
808 "call term_sendkeys(buf, "cd " .. tmpfolder .. "\<CR>")
Bram Moolenaar8b9abfd2021-03-29 20:49:05 +0200809 call TermWait(buf)
810 if has("mac")
Bram Moolenaarced2b382022-01-13 15:25:32 +0000811 let expected = "/private" .. tmpfolder
Bram Moolenaar8b9abfd2021-03-29 20:49:05 +0200812 else
813 let expected = tmpfolder
814 endif
815 call assert_equal(expected, getcwd(winnr()))
Bram Moolenaar82820d92021-03-30 20:54:28 +0200816
817 set noasd
Bram Moolenaar8b9abfd2021-03-29 20:49:05 +0200818endfunc
819
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200820" Test for modeless selection in a terminal
821func Test_term_modeless_selection()
822 CheckUnix
823 CheckNotGui
824 CheckRunVimInTerminal
825 CheckFeature clipboard_working
826
827 let save_mouse = &mouse
828 let save_term = &term
829 let save_ttymouse = &ttymouse
830 set mouse=a term=xterm ttymouse=sgr mousetime=200
831 set clipboard=autoselectml
832
833 let lines =<< trim END
834 one two three four five
835 red green yellow red blue
836 vim emacs sublime nano
837 END
Bram Moolenaarc4860bd2022-10-15 20:52:26 +0100838 call writefile(lines, 'Xtest_modeless', 'D')
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200839
840 " Create a terminal window running Vim for the test with mouse disabled
841 let prev_win = win_getid()
842 let buf = RunVimInTerminal('Xtest_modeless -n', {})
843 call term_sendkeys(buf, ":set nocompatible\<CR>")
844 call term_sendkeys(buf, ":set mouse=\<CR>")
Bram Moolenaar733d2592020-08-20 18:59:06 +0200845 call TermWait(buf)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200846 redraw!
847
848 " Use the mouse to enter the terminal window
849 call win_gotoid(prev_win)
850 call feedkeys(MouseLeftClickCode(1, 1), 'x')
851 call feedkeys(MouseLeftReleaseCode(1, 1), 'x')
Bram Moolenaar733d2592020-08-20 18:59:06 +0200852 call TermWait(buf)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200853 call assert_equal(1, getwininfo(win_getid())[0].terminal)
854
855 " Test for copying a modeless selection to clipboard
856 let @* = 'clean'
857 " communicating with X server may take a little time
858 sleep 100m
859 call feedkeys(MouseLeftClickCode(2, 3), 'x')
860 call feedkeys(MouseLeftDragCode(2, 11), 'x')
861 call feedkeys(MouseLeftReleaseCode(2, 11), 'x')
862 call assert_equal("d green y", @*)
863
864 " cleanup
Bram Moolenaar733d2592020-08-20 18:59:06 +0200865 call TermWait(buf)
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200866 call StopVimInTerminal(buf)
867 let &mouse = save_mouse
868 let &term = save_term
869 let &ttymouse = save_ttymouse
870 set mousetime& clipboard&
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200871 new | only!
872endfunc
873
Bram Moolenaara4b44262020-07-12 21:38:29 +0200874func Test_terminal_getwinpos()
875 CheckRunVimInTerminal
876
877 " split, go to the bottom-right window
878 split
879 wincmd j
880 set splitright
881
Bram Moolenaar42095212020-07-21 21:48:58 +0200882 let buf = RunVimInTerminal('', {'cols': 60})
883 call TermWait(buf, 100)
884 call term_sendkeys(buf, ":echo getwinpos(500)\<CR>")
Bram Moolenaara4b44262020-07-12 21:38:29 +0200885
886 " Find the output of getwinpos() in the bottom line.
887 let rows = term_getsize(buf)[0]
888 call WaitForAssert({-> assert_match('\[\d\+, \d\+\]', term_getline(buf, rows))})
889 let line = term_getline(buf, rows)
890 let xpos = str2nr(substitute(line, '\[\(\d\+\), \d\+\]', '\1', ''))
891 let ypos = str2nr(substitute(line, '\[\d\+, \(\d\+\)\]', '\1', ''))
892
893 " Position must be bigger than the getwinpos() result of Vim itself.
894 " The calculation in the console assumes a 10 x 7 character cell.
895 " In the GUI it can be more, let's assume a 20 x 14 cell.
896 " And then add 100 / 200 tolerance.
897 let [xroot, yroot] = getwinpos()
898 let winpos = 50->getwinpos()
899 call assert_equal(xroot, winpos[0])
900 call assert_equal(yroot, winpos[1])
Bram Moolenaar7dfc5ce2020-09-05 15:05:30 +0200901 let [winrow, wincol] = win_screenpos(0)
Bram Moolenaara4b44262020-07-12 21:38:29 +0200902 let xoff = wincol * (has('gui_running') ? 14 : 7) + 100
903 let yoff = winrow * (has('gui_running') ? 20 : 10) + 200
904 call assert_inrange(xroot + 2, xroot + xoff, xpos)
905 call assert_inrange(yroot + 2, yroot + yoff, ypos)
906
907 call TermWait(buf)
908 call term_sendkeys(buf, ":q\<CR>")
909 call StopVimInTerminal(buf)
Bram Moolenaara4b44262020-07-12 21:38:29 +0200910 set splitright&
911 only!
912endfunc
913
ichizokc3f91c02021-12-17 09:44:33 +0000914func Test_terminal_term_start_error()
915 func s:term_start_error() abort
916 try
917 return term_start([[]])
918 catch
919 return v:exception
920 finally
921 "
922 endtry
923 endfunc
924 autocmd WinEnter * call type(0)
925
926 " Must not crash in s:term_start_error, nor the exception thrown.
927 let result = s:term_start_error()
928 call assert_match('^Vim(return):E730:', result)
929
930 autocmd! WinEnter
931 delfunc s:term_start_error
932endfunc
933
Bram Moolenaar18aa13d2020-07-11 13:09:36 +0200934
935" vim: shiftwidth=2 sts=2 expandtab