66
77source shared.vim
88
9+ " Open a terminal with a shell, assign the job to g:job and return the buffer
10+ " number.
911func Run_shell_in_terminal ()
1012 let buf = term_start (&shell )
1113
@@ -16,22 +18,31 @@ func Run_shell_in_terminal()
1618 let g: job = term_getjob (buf )
1719 call assert_equal (v: t_job , type (g: job ))
1820
19- call term_sendkeys (buf , " exit\r " )
21+ return buf
22+ endfunc
23+
24+ " Stops the shell started by Run_shell_in_terminal().
25+ func Stop_shell_in_terminal (buf )
26+ call term_sendkeys (a: buf , " exit\r " )
2027 call WaitFor (' job_status(g:job) == "dead"' )
2128 call assert_equal (' dead' , job_status (g: job ))
22-
23- return buf
2429endfunc
2530
2631func Test_terminal_basic ()
2732 let buf = Run_shell_in_terminal ()
33+ call Stop_shell_in_terminal (buf )
34+ call term_wait (buf )
35+
36+ " closing window wipes out the terminal buffer a with finished job
37+ close
38+ call assert_equal (" " , bufname (buf ))
2839
29- exe buf . ' bwipe'
3040 unlet g: job
3141endfunc
3242
3343func Test_terminal_make_change ()
3444 let buf = Run_shell_in_terminal ()
45+ call Stop_shell_in_terminal (buf )
3546 call term_wait (buf )
3647
3748 setlocal modifiable
@@ -43,6 +54,32 @@ func Test_terminal_make_change()
4354 unlet g: job
4455endfunc
4556
57+ func Test_terminal_wipe_buffer ()
58+ let buf = Run_shell_in_terminal ()
59+ exe buf . ' bwipe'
60+ call WaitFor (' job_status(g:job) == "dead"' )
61+ call assert_equal (' dead' , job_status (g: job ))
62+ call assert_equal (" " , bufname (buf ))
63+
64+ unlet g: job
65+ endfunc
66+
67+ func Test_terminal_hide_buffer ()
68+ let buf = Run_shell_in_terminal ()
69+ quit
70+ for nr in range (1 , winnr (' $' ))
71+ call assert_notequal (winbufnr (nr), buf )
72+ endfor
73+ call assert_true (bufloaded (buf ))
74+ call assert_true (buflisted (buf ))
75+
76+ exe ' split ' . buf . ' buf'
77+ call Stop_shell_in_terminal (buf )
78+ exe buf . ' bwipe'
79+
80+ unlet g: job
81+ endfunc
82+
4683func Check_123 (buf )
4784 let l = term_scrape (a: buf , 1 )
4885 call assert_true (len (l ) > 0 )
0 commit comments