Mercurial > vim
comparison src/testdir/test_terminal3.vim @ 30865:c8ebe35b2475 v9.0.0767
patch 9.0.0767: too many delete() calls in tests
Commit: https://github.com/vim/vim/commit/c4860bdd2832feb7ab054c6dc14f68abe24c2373
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Oct 15 20:52:26 2022 +0100
patch 9.0.0767: too many delete() calls in tests
Problem: Too many delete() calls in tests.
Solution: Use deferred delete where possible.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 15 Oct 2022 22:00:04 +0200 |
parents | 39df510f97c3 |
children | bf8e9ef40006 |
comparison
equal
deleted
inserted
replaced
30864:51906709cb7a | 30865:c8ebe35b2475 |
---|---|
16 " somehow doesn't work on MS-Windows | 16 " somehow doesn't work on MS-Windows |
17 CheckUnix | 17 CheckUnix |
18 let cmd = "cat Xtext\<CR>" | 18 let cmd = "cat Xtext\<CR>" |
19 | 19 |
20 let buf = term_start(&shell, {}) | 20 let buf = term_start(&shell, {}) |
21 call writefile(["\<Esc>[?1047h"], 'Xtext') | 21 call writefile(["\<Esc>[?1047h"], 'Xtext', 'D') |
22 call term_sendkeys(buf, cmd) | 22 call term_sendkeys(buf, cmd) |
23 call WaitForAssert({-> assert_equal(1, term_getaltscreen(buf))}) | 23 call WaitForAssert({-> assert_equal(1, term_getaltscreen(buf))}) |
24 | 24 |
25 call writefile(["\<Esc>[?1047l"], 'Xtext') | 25 call writefile(["\<Esc>[?1047l"], 'Xtext') |
26 call term_sendkeys(buf, cmd) | 26 call term_sendkeys(buf, cmd) |
27 call WaitForAssert({-> assert_equal(0, term_getaltscreen(buf))}) | 27 call WaitForAssert({-> assert_equal(0, term_getaltscreen(buf))}) |
28 | 28 |
29 call term_sendkeys(buf, "exit\r") | 29 call term_sendkeys(buf, "exit\r") |
30 exe buf . "bwipe!" | 30 exe buf . "bwipe!" |
31 call delete('Xtext') | |
32 endfunc | 31 endfunc |
33 | 32 |
34 func Test_terminal_shell_option() | 33 func Test_terminal_shell_option() |
35 if has('unix') | 34 if has('unix') |
36 " exec is a shell builtin command, should fail without a shell. | 35 " exec is a shell builtin command, should fail without a shell. |
77 \ ' set noruler', | 76 \ ' set noruler', |
78 \ " call term_start('cat', #{vertical: 1, " .. a:highlight_opt .. "})", | 77 \ " call term_start('cat', #{vertical: 1, " .. a:highlight_opt .. "})", |
79 \ ] + a:open_cmds + [ | 78 \ ] + a:open_cmds + [ |
80 \ 'endfunc', | 79 \ 'endfunc', |
81 \ ] + a:highlight_cmds | 80 \ ] + a:highlight_cmds |
82 call writefile(lines, 'XtermStart') | 81 call writefile(lines, 'XtermStart', 'D') |
83 let buf = RunVimInTerminal('-S XtermStart', #{rows: 15}) | 82 let buf = RunVimInTerminal('-S XtermStart', #{rows: 15}) |
84 call TermWait(buf, 100) | 83 call TermWait(buf, 100) |
85 call term_sendkeys(buf, ":call OpenTerm()\<CR>") | 84 call term_sendkeys(buf, ":call OpenTerm()\<CR>") |
86 call TermWait(buf, 50) | 85 call TermWait(buf, 50) |
87 call term_sendkeys(buf, "hello\<CR>") | 86 call term_sendkeys(buf, "hello\<CR>") |
88 call VerifyScreenDump(buf, 'Test_terminal_color_' .. a:group_name, {}) | 87 call VerifyScreenDump(buf, 'Test_terminal_color_' .. a:group_name, {}) |
89 | 88 |
90 call term_sendkeys(buf, "\<C-D>") | 89 call term_sendkeys(buf, "\<C-D>") |
91 call TermWait(buf, 50) | 90 call TermWait(buf, 50) |
92 call StopVimInTerminal(buf) | 91 call StopVimInTerminal(buf) |
93 call delete('XtermStart') | |
94 endfunc | 92 endfunc |
95 | 93 |
96 func Test_terminal_color_Terminal() | 94 func Test_terminal_color_Terminal() |
97 call Terminal_color("Terminal", [ | 95 call Terminal_color("Terminal", [ |
98 \ "highlight Terminal ctermfg=blue ctermbg=yellow", | 96 \ "highlight Terminal ctermfg=blue ctermbg=yellow", |
141 \ 'endfunc', | 139 \ 'endfunc', |
142 \ 'highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue', | 140 \ 'highlight MyTermCol ctermfg=darkgreen ctermbg=lightblue', |
143 \ 'highlight MyWinCol ctermfg=red ctermbg=darkyellow', | 141 \ 'highlight MyWinCol ctermfg=red ctermbg=darkyellow', |
144 \ 'highlight MyWinCol2 ctermfg=black ctermbg=blue', | 142 \ 'highlight MyWinCol2 ctermfg=black ctermbg=blue', |
145 \ ] | 143 \ ] |
146 call writefile(lines, 'XtermStart') | 144 call writefile(lines, 'XtermStart', 'D') |
147 let buf = RunVimInTerminal('-S XtermStart', #{rows: 15}) | 145 let buf = RunVimInTerminal('-S XtermStart', #{rows: 15}) |
148 call TermWait(buf, 100) | 146 call TermWait(buf, 100) |
149 call term_sendkeys(buf, ":call OpenTerm()\<CR>") | 147 call term_sendkeys(buf, ":call OpenTerm()\<CR>") |
150 call TermWait(buf, 50) | 148 call TermWait(buf, 50) |
151 call term_sendkeys(buf, "hello\<CR>") | 149 call term_sendkeys(buf, "hello\<CR>") |
160 call VerifyScreenDump(buf, 'Test_terminal_wincolor_split_MyWinCol2', {}) | 158 call VerifyScreenDump(buf, 'Test_terminal_wincolor_split_MyWinCol2', {}) |
161 | 159 |
162 call term_sendkeys(buf, "\<C-D>") | 160 call term_sendkeys(buf, "\<C-D>") |
163 call TermWait(buf, 50) | 161 call TermWait(buf, 50) |
164 call StopVimInTerminal(buf) | 162 call StopVimInTerminal(buf) |
165 call delete('XtermStart') | |
166 endfunc | 163 endfunc |
167 | 164 |
168 func Test_terminal_color_transp_Terminal() | 165 func Test_terminal_color_transp_Terminal() |
169 call Terminal_color("transp_Terminal", [ | 166 call Terminal_color("transp_Terminal", [ |
170 \ "highlight Terminal ctermfg=blue", | 167 \ "highlight Terminal ctermfg=blue", |
243 let text =<< trim END | 240 let text =<< trim END |
244 some text | 241 some text |
245 to edit | 242 to edit |
246 in a popup window | 243 in a popup window |
247 END | 244 END |
248 call writefile(text, 'Xtext') | 245 call writefile(text, 'Xtext', 'D') |
249 let cmd = GetVimCommandCleanTerm() | 246 let cmd = GetVimCommandCleanTerm() |
250 let lines = [ | 247 let lines = [ |
251 \ 'call setline(1, range(20))', | 248 \ 'call setline(1, range(20))', |
252 \ 'hi PopTerm ctermbg=grey', | 249 \ 'hi PopTerm ctermbg=grey', |
253 \ 'func OpenTerm(setColor)', | 250 \ 'func OpenTerm(setColor)', |
266 \ 'endfunc', | 263 \ 'endfunc', |
267 \ 'func ReopenPopup()', | 264 \ 'func ReopenPopup()', |
268 \ ' call popup_create(s:buf, #{minwidth: 40, minheight: 6, border: []})', | 265 \ ' call popup_create(s:buf, #{minwidth: 40, minheight: 6, border: []})', |
269 \ 'endfunc', | 266 \ 'endfunc', |
270 \ ] | 267 \ ] |
271 call writefile(lines, 'XtermPopup') | 268 call writefile(lines, 'XtermPopup', 'D') |
272 let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15}) | 269 let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15}) |
273 call TermWait(buf, 100) | 270 call TermWait(buf, 100) |
274 call term_sendkeys(buf, ":call OpenTerm(0)\<CR>") | 271 call term_sendkeys(buf, ":call OpenTerm(0)\<CR>") |
275 call TermWait(buf, 500) | 272 call TermWait(buf, 500) |
276 call term_sendkeys(buf, ":\<CR>") | 273 call term_sendkeys(buf, ":\<CR>") |
310 call TermWait(buf, 50) | 307 call TermWait(buf, 50) |
311 call term_sendkeys(buf, ":q\<CR>") | 308 call term_sendkeys(buf, ":q\<CR>") |
312 call TermWait(buf, 250) " wait for terminal to vanish | 309 call TermWait(buf, 250) " wait for terminal to vanish |
313 | 310 |
314 call StopVimInTerminal(buf) | 311 call StopVimInTerminal(buf) |
315 call delete('Xtext') | |
316 call delete('XtermPopup') | |
317 endfunc | 312 endfunc |
318 | 313 |
319 " Check a terminal in popup window uses the default minimum size. | 314 " Check a terminal in popup window uses the default minimum size. |
320 func Test_terminal_in_popup_min_size() | 315 func Test_terminal_in_popup_min_size() |
321 CheckRunVimInTerminal | 316 CheckRunVimInTerminal |
323 let text =<< trim END | 318 let text =<< trim END |
324 another text | 319 another text |
325 to show | 320 to show |
326 in a popup window | 321 in a popup window |
327 END | 322 END |
328 call writefile(text, 'Xtext') | 323 call writefile(text, 'Xtext', 'D') |
329 let lines = [ | 324 let lines = [ |
330 \ 'call setline(1, range(20))', | 325 \ 'call setline(1, range(20))', |
331 \ 'func OpenTerm()', | 326 \ 'func OpenTerm()', |
332 \ " let s:buf = term_start('cat Xtext', #{hidden: 1})", | 327 \ " let s:buf = term_start('cat Xtext', #{hidden: 1})", |
333 \ ' let g:winid = popup_create(s:buf, #{ border: []})', | 328 \ ' let g:winid = popup_create(s:buf, #{ border: []})', |
334 \ 'endfunc', | 329 \ 'endfunc', |
335 \ ] | 330 \ ] |
336 call writefile(lines, 'XtermPopup') | 331 call writefile(lines, 'XtermPopup', 'D') |
337 let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15}) | 332 let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15}) |
338 call TermWait(buf, 100) | 333 call TermWait(buf, 100) |
339 call term_sendkeys(buf, ":set noruler\<CR>") | 334 call term_sendkeys(buf, ":set noruler\<CR>") |
340 call term_sendkeys(buf, ":call OpenTerm()\<CR>") | 335 call term_sendkeys(buf, ":call OpenTerm()\<CR>") |
341 call TermWait(buf, 50) | 336 call TermWait(buf, 50) |
344 | 339 |
345 call TermWait(buf, 50) | 340 call TermWait(buf, 50) |
346 call term_sendkeys(buf, ":q\<CR>") | 341 call term_sendkeys(buf, ":q\<CR>") |
347 call TermWait(buf, 50) " wait for terminal to vanish | 342 call TermWait(buf, 50) " wait for terminal to vanish |
348 call StopVimInTerminal(buf) | 343 call StopVimInTerminal(buf) |
349 call delete('Xtext') | |
350 call delete('XtermPopup') | |
351 endfunc | 344 endfunc |
352 | 345 |
353 " Check a terminal in popup window with different colors | 346 " Check a terminal in popup window with different colors |
354 func Terminal_in_popup_color(group_name, highlight_cmds, highlight_opt, popup_cmds, popup_opt) | 347 func Terminal_in_popup_color(group_name, highlight_cmds, highlight_opt, popup_cmds, popup_opt) |
355 CheckRunVimInTerminal | 348 CheckRunVimInTerminal |
363 \ ' let g:winid = popup_create(s:buf, #{border: [], ' | 356 \ ' let g:winid = popup_create(s:buf, #{border: [], ' |
364 \ .. a:popup_opt .. '})', | 357 \ .. a:popup_opt .. '})', |
365 \ ] + a:popup_cmds + [ | 358 \ ] + a:popup_cmds + [ |
366 \ 'endfunc', | 359 \ 'endfunc', |
367 \ ] + a:highlight_cmds | 360 \ ] + a:highlight_cmds |
368 call writefile(lines, 'XtermPopup') | 361 call writefile(lines, 'XtermPopup', 'D') |
369 let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15}) | 362 let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15}) |
370 call TermWait(buf, 100) | 363 call TermWait(buf, 100) |
371 call term_sendkeys(buf, ":set noruler\<CR>") | 364 call term_sendkeys(buf, ":set noruler\<CR>") |
372 call term_sendkeys(buf, ":call OpenTerm()\<CR>") | 365 call term_sendkeys(buf, ":call OpenTerm()\<CR>") |
373 call TermWait(buf, 50) | 366 call TermWait(buf, 50) |
377 call term_sendkeys(buf, "\<C-D>") | 370 call term_sendkeys(buf, "\<C-D>") |
378 call TermWait(buf, 50) | 371 call TermWait(buf, 50) |
379 call term_sendkeys(buf, ":q\<CR>") | 372 call term_sendkeys(buf, ":q\<CR>") |
380 call TermWait(buf, 50) " wait for terminal to vanish | 373 call TermWait(buf, 50) " wait for terminal to vanish |
381 call StopVimInTerminal(buf) | 374 call StopVimInTerminal(buf) |
382 call delete('XtermPopup') | |
383 endfunc | 375 endfunc |
384 | 376 |
385 func Test_terminal_in_popup_color_Terminal() | 377 func Test_terminal_in_popup_color_Terminal() |
386 call Terminal_in_popup_color("Terminal", [ | 378 call Terminal_in_popup_color("Terminal", [ |
387 \ "highlight Terminal ctermfg=blue ctermbg=yellow", | 379 \ "highlight Terminal ctermfg=blue ctermbg=yellow", |
580 let lines =<< trim EOL | 572 let lines =<< trim EOL |
581 put='some text' | 573 put='some text' |
582 term | 574 term |
583 startinsert | 575 startinsert |
584 EOL | 576 EOL |
585 call writefile(lines, 'XTest_startinsert') | 577 call writefile(lines, 'XTest_startinsert', 'D') |
586 let buf = RunVimInTerminal('-S XTest_startinsert', {}) | 578 let buf = RunVimInTerminal('-S XTest_startinsert', {}) |
587 | 579 |
588 call term_sendkeys(buf, "exit\r") | 580 call term_sendkeys(buf, "exit\r") |
589 call WaitForAssert({-> assert_equal("some text", term_getline(buf, 1))}) | 581 call WaitForAssert({-> assert_equal("some text", term_getline(buf, 1))}) |
590 call term_sendkeys(buf, "0l") | 582 call term_sendkeys(buf, "0l") |
591 call term_sendkeys(buf, "A<\<Esc>") | 583 call term_sendkeys(buf, "A<\<Esc>") |
592 call WaitForAssert({-> assert_equal("some text<", term_getline(buf, 1))}) | 584 call WaitForAssert({-> assert_equal("some text<", term_getline(buf, 1))}) |
593 | 585 |
594 call StopVimInTerminal(buf) | 586 call StopVimInTerminal(buf) |
595 call delete('XTest_startinsert') | |
596 endfunc | 587 endfunc |
597 | 588 |
598 " Test for passing invalid arguments to terminal functions | 589 " Test for passing invalid arguments to terminal functions |
599 func Test_term_func_invalid_arg() | 590 func Test_term_func_invalid_arg() |
600 call assert_fails('let b = term_getaltscreen([])', 'E745:') | 591 call assert_fails('let b = term_getaltscreen([])', 'E745:') |
681 let lines =<< trim END | 672 let lines =<< trim END |
682 one two three four five | 673 one two three four five |
683 red green yellow red blue | 674 red green yellow red blue |
684 vim emacs sublime nano | 675 vim emacs sublime nano |
685 END | 676 END |
686 call writefile(lines, 'Xtest_mouse') | 677 call writefile(lines, 'Xtest_mouse', 'D') |
687 | 678 |
688 " Create a terminal window running Vim for the test with mouse enabled | 679 " Create a terminal window running Vim for the test with mouse enabled |
689 let prev_win = win_getid() | 680 let prev_win = win_getid() |
690 let buf = RunVimInTerminal('Xtest_mouse -n', {}) | 681 let buf = RunVimInTerminal('Xtest_mouse -n', {}) |
691 call term_sendkeys(buf, ":set nocompatible\<CR>") | 682 call term_sendkeys(buf, ":set nocompatible\<CR>") |
781 let &mouse = save_mouse | 772 let &mouse = save_mouse |
782 let &term = save_term | 773 let &term = save_term |
783 let &ttymouse = save_ttymouse | 774 let &ttymouse = save_ttymouse |
784 let &clipboard = save_clipboard | 775 let &clipboard = save_clipboard |
785 set mousetime& | 776 set mousetime& |
786 call delete('Xtest_mouse') | |
787 call delete('Xbuf') | 777 call delete('Xbuf') |
788 endfunc | 778 endfunc |
789 | 779 |
790 " Test for sync buffer cwd with shell's pwd | 780 " Test for sync buffer cwd with shell's pwd |
791 func Test_terminal_sync_shell_dir() | 781 func Test_terminal_sync_shell_dir() |
834 let lines =<< trim END | 824 let lines =<< trim END |
835 one two three four five | 825 one two three four five |
836 red green yellow red blue | 826 red green yellow red blue |
837 vim emacs sublime nano | 827 vim emacs sublime nano |
838 END | 828 END |
839 call writefile(lines, 'Xtest_modeless') | 829 call writefile(lines, 'Xtest_modeless', 'D') |
840 | 830 |
841 " Create a terminal window running Vim for the test with mouse disabled | 831 " Create a terminal window running Vim for the test with mouse disabled |
842 let prev_win = win_getid() | 832 let prev_win = win_getid() |
843 let buf = RunVimInTerminal('Xtest_modeless -n', {}) | 833 let buf = RunVimInTerminal('Xtest_modeless -n', {}) |
844 call term_sendkeys(buf, ":set nocompatible\<CR>") | 834 call term_sendkeys(buf, ":set nocompatible\<CR>") |
867 call StopVimInTerminal(buf) | 857 call StopVimInTerminal(buf) |
868 let &mouse = save_mouse | 858 let &mouse = save_mouse |
869 let &term = save_term | 859 let &term = save_term |
870 let &ttymouse = save_ttymouse | 860 let &ttymouse = save_ttymouse |
871 set mousetime& clipboard& | 861 set mousetime& clipboard& |
872 call delete('Xtest_modeless') | |
873 new | only! | 862 new | only! |
874 endfunc | 863 endfunc |
875 | 864 |
876 func Test_terminal_getwinpos() | 865 func Test_terminal_getwinpos() |
877 CheckRunVimInTerminal | 866 CheckRunVimInTerminal |