annotate src/testdir/test_terminal.vim @ 32669:448aef880252

normalize line endings
author Christian Brabandt <cb@256bit.org>
date Mon, 26 Jun 2023 09:54:34 +0200
parents b1dcb60b1e6c
children 695b50472e85
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32669
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1 " Tests for the terminal window.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2 " This is split in two, because it can take a lot of time.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
3 " See test_terminal2.vim and test_terminal3.vim for further tests.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
4
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
5 source check.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
6 CheckFeature terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
7
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
8 source shared.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
9 source screendump.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
10 source mouse.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
11 source term_util.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
12
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
13 let s:python = PythonProg()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
14 let $PROMPT_COMMAND=''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
15
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
16 func Test_terminal_basic()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
17 call test_override('vterm_title', 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
18 au TerminalOpen * let b:done = 'yes'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
19 let buf = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
20
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
21 call assert_equal('t', mode())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
22 call assert_equal('yes', b:done)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
23 call assert_match('%aR[^\n]*running]', execute('ls'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
24 call assert_match('%aR[^\n]*running]', execute('ls R'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
25 call assert_notmatch('%[^\n]*running]', execute('ls F'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
26 call assert_notmatch('%[^\n]*running]', execute('ls ?'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
27 call assert_fails('set modifiable', 'E946:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
28
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
29 call StopShellInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
30 call assert_equal('n', mode())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
31 call assert_match('%aF[^\n]*finished]', execute('ls'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
32 call assert_match('%aF[^\n]*finished]', execute('ls F'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
33 call assert_notmatch('%[^\n]*finished]', execute('ls R'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
34 call assert_notmatch('%[^\n]*finished]', execute('ls ?'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
35
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
36 " closing window wipes out the terminal buffer a with finished job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
37 close
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
38 call assert_equal("", bufname(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
39
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
40 au! TerminalOpen
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
41 call test_override('ALL', 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
42 unlet g:job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
43 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
44
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
45 func Test_terminal_no_name()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
46 let buf = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
47 call assert_match('^!', bufname(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
48 0file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
49 call assert_equal("", bufname(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
50 call assert_match('\[No Name\]', execute('file'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
51 call StopShellInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
52 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
53
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
54 func Test_terminal_TerminalWinOpen()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
55 au TerminalWinOpen * let b:done = 'yes'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
56 let buf = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
57 call assert_equal('yes', b:done)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
58 call StopShellInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
59 " closing window wipes out the terminal buffer with the finished job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
60 close
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
61
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
62 if has("unix")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
63 terminal ++hidden ++open sleep 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
64 sleep 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
65 call assert_fails("echo b:done", 'E121:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
66 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
67
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
68 au! TerminalWinOpen
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
69 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
70
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
71 func Test_terminal_make_change()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
72 let buf = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
73 call StopShellInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
74
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
75 setlocal modifiable
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
76 exe "normal Axxx\<Esc>"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
77 call assert_fails(buf . 'bwipe', 'E89:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
78 undo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
79
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
80 exe buf . 'bwipe'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
81 unlet g:job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
82 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
83
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
84 func Test_terminal_paste_register()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
85 let @" = "text to paste"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
86
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
87 let buf = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
88 " Wait for the shell to display a prompt
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
89 call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
90
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
91 call feedkeys("echo \<C-W>\"\" \<C-W>\"=37 + 5\<CR>\<CR>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
92 call WaitForAssert({-> assert_match("echo text to paste 42$", getline(1))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
93 call WaitForAssert({-> assert_equal('text to paste 42', 2->getline())})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
94
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
95 exe buf . 'bwipe!'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
96 unlet g:job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
97 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
98
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
99 func Test_terminal_unload_buffer()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
100 let buf = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
101 call assert_fails(buf . 'bunload', 'E948:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
102 exe buf . 'bunload!'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
103 call WaitForAssert({-> assert_equal('dead', job_status(g:job))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
104 call assert_equal("", bufname(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
105
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
106 unlet g:job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
107 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
108
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
109 func Test_terminal_wipe_buffer()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
110 let buf = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
111 call assert_fails(buf . 'bwipe', 'E948:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
112 exe buf . 'bwipe!'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
113 call WaitForAssert({-> assert_equal('dead', job_status(g:job))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
114 call assert_equal("", bufname(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
115
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
116 unlet g:job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
117 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
118
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
119 " Test that using ':confirm bwipe' on terminal works
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
120 func Test_terminal_confirm_wipe_buffer()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
121 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
122 CheckNotGui
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
123 CheckFeature dialog_con
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
124 let buf = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
125 call assert_fails(buf . 'bwipe', 'E948:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
126 call feedkeys('n', 'L')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
127 call assert_fails('confirm ' .. buf .. 'bwipe', 'E517:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
128 call assert_equal(buf, bufnr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
129 call assert_equal(1, &modified)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
130 call feedkeys('y', 'L')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
131 exe 'confirm ' .. buf .. 'bwipe'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
132 call assert_notequal(buf, bufnr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
133 call WaitForAssert({-> assert_equal('dead', job_status(g:job))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
134 call assert_equal("", bufname(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
135
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
136 unlet g:job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
137 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
138
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
139 " Test that using :b! will hide the terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
140 func Test_terminal_goto_buffer()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
141 let buf_mod = bufnr()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
142 let buf_term = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
143 call assert_equal(buf_term, bufnr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
144 call assert_fails(buf_mod . 'b', 'E948:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
145 exe buf_mod . 'b!'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
146 call assert_equal(buf_mod, bufnr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
147 call assert_equal('run', job_status(g:job))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
148 call assert_notequal('', bufname(buf_term))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
149 exec buf_mod .. 'bwipe!'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
150 exec buf_term .. 'bwipe!'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
151
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
152 unlet g:job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
153 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
154
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
155 " Test that using ':confirm :b' will kill terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
156 func Test_terminal_confirm_goto_buffer()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
157 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
158 CheckNotGui
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
159 CheckFeature dialog_con
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
160 let buf_mod = bufnr()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
161 let buf_term = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
162 call feedkeys('n', 'L')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
163 exe 'confirm ' .. buf_mod .. 'b'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
164 call assert_equal(buf_term, bufnr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
165 call feedkeys('y', 'L')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
166 exec 'confirm ' .. buf_mod .. 'b'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
167 call assert_equal(buf_mod, bufnr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
168 call WaitForAssert({-> assert_equal('dead', job_status(g:job))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
169 call assert_equal("", bufname(buf_term))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
170 exec buf_mod .. 'bwipe!'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
171
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
172 unlet g:job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
173 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
174
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
175 " Test that using :close! will hide the terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
176 func Test_terminal_close_win()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
177 let buf = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
178 call assert_equal(buf, bufnr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
179 call assert_fails('close', 'E948:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
180 close!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
181 call assert_notequal(buf, bufnr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
182 call assert_equal('run', job_status(g:job))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
183 call assert_notequal('', bufname(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
184 exec buf .. 'bwipe!'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
185
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
186 unlet g:job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
187 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
188
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
189 " Test that using ':confirm close' will kill terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
190 func Test_terminal_confirm_close_win()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
191 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
192 CheckNotGui
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
193 CheckFeature dialog_con
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
194 let buf = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
195 call feedkeys('n', 'L')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
196 confirm close
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
197 call assert_equal(buf, bufnr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
198 call feedkeys('y', 'L')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
199 confirm close
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
200 call assert_notequal(buf, bufnr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
201 call WaitForAssert({-> assert_equal('dead', job_status(g:job))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
202 call assert_equal("", bufname(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
203
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
204 unlet g:job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
205 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
206
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
207 " Test that using :quit! will kill the terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
208 func Test_terminal_quit()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
209 let buf = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
210 call assert_equal(buf, bufnr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
211 call assert_fails('quit', 'E948:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
212 quit!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
213 call assert_notequal(buf, bufnr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
214 call WaitForAssert({-> assert_equal('dead', job_status(g:job))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
215 call assert_equal("", bufname(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
216
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
217 unlet g:job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
218 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
219
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
220 " Test that using ':confirm quit' will kill terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
221 func Test_terminal_confirm_quit()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
222 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
223 CheckNotGui
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
224 CheckFeature dialog_con
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
225 let buf = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
226 call feedkeys('n', 'L')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
227 confirm quit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
228 call assert_equal(buf, bufnr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
229 call feedkeys('y', 'L')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
230 confirm quit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
231 call assert_notequal(buf, bufnr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
232 call WaitForAssert({-> assert_equal('dead', job_status(g:job))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
233
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
234 unlet g:job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
235 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
236
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
237 " Test :q or :next
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
238
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
239 func Test_terminal_split_quit()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
240 let buf = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
241 split
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
242 quit!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
243 call TermWait(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
244 sleep 50m
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
245 call assert_equal('run', job_status(g:job))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
246
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
247 quit!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
248 call WaitForAssert({-> assert_equal('dead', job_status(g:job))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
249
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
250 call assert_equal("", bufname(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
251 unlet g:job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
252 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
253
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
254 func Test_terminal_hide_buffer_job_running()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
255 let buf = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
256 setlocal bufhidden=hide
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
257 quit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
258 for nr in range(1, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
259 call assert_notequal(winbufnr(nr), buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
260 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
261 call assert_true(bufloaded(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
262 call assert_true(buflisted(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
263
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
264 exe 'split ' . buf . 'buf'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
265 call StopShellInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
266 exe buf . 'bwipe'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
267
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
268 unlet g:job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
269 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
270
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
271 func Test_terminal_hide_buffer_job_finished()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
272 term echo hello
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
273 let buf = bufnr()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
274 call WaitForAssert({-> assert_equal('finished', term_getstatus(buf))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
275
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
276 call assert_true(bufloaded(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
277 call assert_true(buflisted(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
278
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
279 " Test :hide
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
280 hide
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
281 call assert_true(bufloaded(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
282 call assert_true(buflisted(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
283 split
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
284 exe buf .. 'buf'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
285 call assert_equal(buf, bufnr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
286
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
287 " Test bufhidden, which exercises a different code path
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
288 setlocal bufhidden=hide
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
289 edit Xasdfasdf
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
290 call assert_true(bufloaded(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
291 call assert_true(buflisted(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
292 exe buf .. 'buf'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
293 call assert_equal(buf, bufnr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
294 setlocal bufhidden=
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
295
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
296 edit Xasdfasdf
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
297 call assert_false(bufloaded(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
298 call assert_false(buflisted(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
299 bwipe Xasdfasdf
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
300 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
301
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
302 func Test_terminal_rename_buffer()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
303 let cmd = Get_cat_123_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
304 let buf = term_start(cmd, {'term_name': 'foo'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
305 call WaitForAssert({-> assert_equal('finished', term_getstatus(buf))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
306 call assert_equal('foo', bufname())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
307 call assert_match('foo.*finished', execute('ls'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
308 file bar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
309 call assert_equal('bar', bufname())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
310 call assert_match('bar.*finished', execute('ls'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
311 exe 'bwipe! ' .. buf
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
312 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
313
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
314 func s:Nasty_exit_cb(job, st)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
315 exe g:buf . 'bwipe!'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
316 let g:buf = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
317 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
318
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
319 func Get_cat_123_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
320 if has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
321 if !has('conpty')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
322 return 'cmd /c "cls && color 2 && echo 123"'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
323 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
324 " When clearing twice, extra sequence is not output.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
325 return 'cmd /c "cls && cls && color 2 && echo 123"'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
326 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
327 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
328 call writefile(["\<Esc>[32m123"], 'Xtext')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
329 return "cat Xtext"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
330 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
331 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
332
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
333 func Test_terminal_nasty_cb()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
334 let cmd = Get_cat_123_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
335 let g:buf = term_start(cmd, {'exit_cb': function('s:Nasty_exit_cb')})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
336 let g:job = term_getjob(g:buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
337
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
338 call WaitForAssert({-> assert_equal("dead", job_status(g:job))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
339 call WaitForAssert({-> assert_equal(0, g:buf)})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
340 unlet g:job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
341 unlet g:buf
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
342 call delete('Xtext')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
343 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
344
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
345 func Check_123(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
346 let l = term_scrape(a:buf, 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
347 call assert_true(len(l) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
348 let l = term_scrape(a:buf, 999)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
349 call assert_true(len(l) == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
350 let l = a:buf->term_scrape(1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
351 call assert_true(len(l) > 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
352 call assert_equal('1', l[0].chars)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
353 call assert_equal('2', l[1].chars)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
354 call assert_equal('3', l[2].chars)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
355 call assert_equal('#00e000', l[0].fg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
356 call assert_equal(0, term_getattr(l[0].attr, 'bold'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
357 call assert_equal(0, l[0].attr->term_getattr('italic'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
358 if has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
359 " On Windows 'background' always defaults to dark, even though the terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
360 " may use a light background. Therefore accept both white and black.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
361 call assert_match('#ffffff\|#000000', l[0].bg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
362 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
363 if &background == 'light'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
364 call assert_equal('#ffffff', l[0].bg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
365 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
366 call assert_equal('#000000', l[0].bg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
367 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
368 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
369
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
370 let l = term_getline(a:buf, -1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
371 call assert_equal('', l)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
372 let l = term_getline(a:buf, 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
373 call assert_equal('', l)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
374 let l = term_getline(a:buf, 999)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
375 call assert_equal('', l)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
376 let l = term_getline(a:buf, 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
377 call assert_equal('123', l)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
378 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
379
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
380 func Test_terminal_scrape_123()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
381 let cmd = Get_cat_123_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
382 let buf = term_start(cmd)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
383
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
384 let termlist = term_list()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
385 call assert_equal(1, len(termlist))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
386 call assert_equal(buf, termlist[0])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
387
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
388 " Nothing happens with invalid buffer number
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
389 call term_wait(1234)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
390
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
391 call TermWait(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
392 " On MS-Windows we first get a startup message of two lines, wait for the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
393 " "cls" to happen, after that we have one line with three characters.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
394 call WaitForAssert({-> assert_equal(3, len(term_scrape(buf, 1)))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
395 call Check_123(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
396
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
397 " Must still work after the job ended.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
398 let job = term_getjob(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
399 call WaitForAssert({-> assert_equal("dead", job_status(job))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
400 call TermWait(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
401 call Check_123(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
402
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
403 exe buf . 'bwipe'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
404 call delete('Xtext')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
405 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
406
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
407 func Test_terminal_scrape_multibyte()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
408 call writefile(["léttまrs"], 'Xtext', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
409 if has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
410 " Run cmd with UTF-8 codepage to make the type command print the expected
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
411 " multibyte characters.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
412 let buf = term_start("cmd /K chcp 65001")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
413 call term_sendkeys(buf, "type Xtext\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
414 eval buf->term_sendkeys("exit\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
415 let line = 4
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
416 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
417 let buf = term_start("cat Xtext")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
418 let line = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
419 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
420
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
421 call WaitFor({-> len(term_scrape(buf, line)) >= 7 && term_scrape(buf, line)[0].chars == "l"})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
422 let l = term_scrape(buf, line)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
423 call assert_true(len(l) >= 7)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
424 call assert_equal('l', l[0].chars)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
425 call assert_equal('é', l[1].chars)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
426 call assert_equal(1, l[1].width)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
427 call assert_equal('t', l[2].chars)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
428 call assert_equal('t', l[3].chars)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
429 call assert_equal('ま', l[4].chars)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
430 call assert_equal(2, l[4].width)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
431 call assert_equal('r', l[5].chars)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
432 call assert_equal('s', l[6].chars)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
433
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
434 let job = term_getjob(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
435 call WaitForAssert({-> assert_equal("dead", job_status(job))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
436 call TermWait(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
437
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
438 exe buf . 'bwipe'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
439 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
440
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
441 func Test_terminal_one_column()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
442 " This creates a terminal, displays a double-wide character and makes the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
443 " window one column wide. This used to cause a crash.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
444 let width = &columns
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
445 botright vert term
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
446 let buf = bufnr('$')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
447 call TermWait(buf, 100)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
448 exe "set columns=" .. (width / 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
449 redraw
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
450 call term_sendkeys(buf, "キ")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
451 call TermWait(buf, 10)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
452 exe "set columns=" .. width
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
453 exe buf . 'bwipe!'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
454 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
455
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
456 func Test_terminal_scroll()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
457 call writefile(range(1, 200), 'Xtext', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
458 if has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
459 let cmd = 'cmd /c "type Xtext"'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
460 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
461 let cmd = "cat Xtext"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
462 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
463 let buf = term_start(cmd)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
464
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
465 let job = term_getjob(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
466 call WaitForAssert({-> assert_equal("dead", job_status(job))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
467 call TermWait(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
468
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
469 " wait until the scrolling stops
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
470 while 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
471 let scrolled = buf->term_getscrolled()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
472 sleep 20m
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
473 if scrolled == buf->term_getscrolled()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
474 break
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
475 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
476 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
477
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
478 call assert_equal('1', getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
479 call assert_equal('1', term_getline(buf, 1 - scrolled))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
480 call assert_equal('49', getline(49))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
481 call assert_equal('49', term_getline(buf, 49 - scrolled))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
482 call assert_equal('200', getline(200))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
483 call assert_equal('200', term_getline(buf, 200 - scrolled))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
484
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
485 exe buf . 'bwipe'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
486 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
487
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
488 func Test_terminal_scrollback()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
489 let buf = Run_shell_in_terminal({'term_rows': 15})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
490 set termwinscroll=100
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
491 call writefile(range(150), 'Xtext', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
492 if has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
493 call term_sendkeys(buf, "type Xtext\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
494 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
495 call term_sendkeys(buf, "cat Xtext\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
496 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
497 let rows = term_getsize(buf)[0]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
498 " On MS-Windows there is an empty line, check both last line and above it.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
499 call WaitForAssert({-> assert_match( '149', term_getline(buf, rows - 1) . term_getline(buf, rows - 2))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
500 let lines = line('$')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
501 call assert_inrange(91, 100, lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
502
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
503 call StopShellInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
504 exe buf . 'bwipe'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
505 set termwinscroll&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
506 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
507
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
508 func Test_terminal_postponed_scrollback()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
509 " tail -f only works on Unix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
510 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
511
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
512 call writefile(range(50), 'Xtext', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
513 call writefile([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
514 \ 'set shell=/bin/sh noruler',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
515 \ 'terminal',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
516 \ 'sleep 200m',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
517 \ 'call feedkeys("tail -n 100 -f Xtext\<CR>", "xt")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
518 \ 'sleep 100m',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
519 \ 'call feedkeys("\<C-W>N", "xt")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
520 \ ], 'XTest_postponed', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
521 let buf = RunVimInTerminal('-S XTest_postponed', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
522 " Check that the Xtext lines are displayed and in Terminal-Normal mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
523 call VerifyScreenDump(buf, 'Test_terminal_scrollback_1', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
524
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
525 silent !echo 'one more line' >>Xtext
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
526 " Screen will not change, move cursor to get a different dump
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
527 call term_sendkeys(buf, "k")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
528 call VerifyScreenDump(buf, 'Test_terminal_scrollback_2', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
529
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
530 " Back to Terminal-Job mode, text will scroll and show the extra line.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
531 call term_sendkeys(buf, "a")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
532 call VerifyScreenDump(buf, 'Test_terminal_scrollback_3', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
533
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
534 " stop "tail -f"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
535 call term_sendkeys(buf, "\<C-C>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
536 call TermWait(buf, 25)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
537 " stop shell
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
538 call term_sendkeys(buf, "exit\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
539 call TermWait(buf, 50)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
540 " close terminal window
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
541 let tsk_ret = term_sendkeys(buf, ":q\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
542
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
543 " check type of term_sendkeys() return value
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
544 echo type(tsk_ret)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
545
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
546 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
547 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
548
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
549 " Run diff on two dumps with different size.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
550 func Test_terminal_dumpdiff_size()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
551 call assert_equal(1, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
552 call term_dumpdiff('dumps/Test_incsearch_search_01.dump', 'dumps/Test_popup_command_01.dump')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
553 call assert_equal(2, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
554 call assert_match('Test_incsearch_search_01.dump', getline(10))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
555 call assert_match(' +++++$', getline(11))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
556 call assert_match('Test_popup_command_01.dump', getline(31))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
557 call assert_equal(repeat('+', 75), getline(30))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
558 quit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
559 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
560
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
561 func Test_terminal_size()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
562 let cmd = Get_cat_123_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
563
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
564 exe 'terminal ++rows=5 ' . cmd
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
565 let size = term_getsize('')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
566 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
567 call assert_equal(5, size[0])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
568
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
569 call term_start(cmd, {'term_rows': 6})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
570 let size = term_getsize('')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
571 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
572 call assert_equal(6, size[0])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
573
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
574 vsplit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
575 exe 'terminal ++rows=5 ++cols=33 ' . cmd
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
576 call assert_equal([5, 33], ''->term_getsize())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
577
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
578 call term_setsize('', 6, 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
579 call assert_equal([6, 33], term_getsize(''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
580
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
581 eval ''->term_setsize(0, 35)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
582 call assert_equal([6, 35], term_getsize(''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
583
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
584 call term_setsize('', 7, 30)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
585 call assert_equal([7, 30], term_getsize(''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
586
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
587 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
588 call assert_fails("call term_setsize('', 7, 30)", "E955:")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
589
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
590 call term_start(cmd, {'term_rows': 6, 'term_cols': 36})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
591 let size = term_getsize('')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
592 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
593 call assert_equal([6, 36], size)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
594
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
595 exe 'vertical terminal ++cols=20 ' . cmd
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
596 let size = term_getsize('')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
597 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
598 call assert_equal(20, size[1])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
599
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
600 eval cmd->term_start({'vertical': 1, 'term_cols': 26})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
601 let size = term_getsize('')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
602 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
603 call assert_equal(26, size[1])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
604
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
605 split
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
606 exe 'vertical terminal ++rows=6 ++cols=20 ' . cmd
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
607 let size = term_getsize('')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
608 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
609 call assert_equal([6, 20], size)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
610
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
611 call term_start(cmd, {'vertical': 1, 'term_rows': 7, 'term_cols': 27})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
612 let size = term_getsize('')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
613 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
614 call assert_equal([7, 27], size)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
615
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
616 call assert_fails("call term_start(cmd, {'term_rows': -1})", 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
617 call assert_fails("call term_start(cmd, {'term_rows': 1001})", 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
618 call assert_fails("call term_start(cmd, {'term_rows': 10.0})", 'E805:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
619
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
620 call assert_fails("call term_start(cmd, {'term_cols': -1})", 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
621 call assert_fails("call term_start(cmd, {'term_cols': 1001})", 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
622 call assert_fails("call term_start(cmd, {'term_cols': 10.0})", 'E805:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
623
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
624 call delete('Xtext')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
625 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
626
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
627 func Test_terminal_zero_height()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
628 split
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
629 wincmd j
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
630 anoremenu 1.1 WinBar.test :
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
631 terminal ++curwin
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
632 wincmd k
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
633 wincmd _
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
634 redraw
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
635
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
636 call term_sendkeys(bufnr(), "exit\r")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
637 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
638 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
639
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
640 func Test_terminal_curwin()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
641 let cmd = Get_cat_123_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
642 call assert_equal(1, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
643
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
644 split Xdummy
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
645 call setline(1, 'dummy')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
646 write
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
647 call assert_equal(1, getbufinfo('Xdummy')[0].loaded)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
648 exe 'terminal ++curwin ' . cmd
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
649 call assert_equal(2, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
650 call assert_equal(0, getbufinfo('Xdummy')[0].loaded)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
651 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
652
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
653 split Xdummy
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
654 call term_start(cmd, {'curwin': 1})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
655 call assert_equal(2, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
656 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
657
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
658 split Xdummy
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
659 call setline(1, 'change')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
660 call assert_fails('terminal ++curwin ' . cmd, 'E37:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
661 call assert_equal(2, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
662 exe 'terminal! ++curwin ' . cmd
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
663 call assert_equal(2, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
664 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
665
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
666 split Xdummy
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
667 call setline(1, 'change')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
668 call assert_fails("call term_start(cmd, {'curwin': 1})", 'E37:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
669 call assert_equal(2, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
670 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
671
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
672 split Xdummy
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
673 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
674 call delete('Xtext')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
675 call delete('Xdummy')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
676 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
677
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
678 func s:get_sleep_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
679 if s:python != ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
680 let cmd = s:python . " test_short_sleep.py"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
681 " 500 was not enough for Travis
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
682 let waittime = 900
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
683 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
684 echo 'This will take five seconds...'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
685 let waittime = 2000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
686 if has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
687 let cmd = $windir . '\system32\timeout.exe 1'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
688 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
689 let cmd = 'sleep 1'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
690 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
691 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
692 return [cmd, waittime]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
693 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
694
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
695 func Test_terminal_finish_open_close()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
696 call assert_equal(1, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
697
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
698 let [cmd, waittime] = s:get_sleep_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
699
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
700 " shell terminal closes automatically
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
701 terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
702 let buf = bufnr('%')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
703 call assert_equal(2, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
704 " Wait for the shell to display a prompt
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
705 call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
706 call StopShellInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
707 call WaitForAssert({-> assert_equal(1, winnr('$'))}, waittime)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
708
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
709 " shell terminal that does not close automatically
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
710 terminal ++noclose
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
711 let buf = bufnr('%')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
712 call assert_equal(2, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
713 " Wait for the shell to display a prompt
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
714 call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
715 call StopShellInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
716 call assert_equal(2, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
717 quit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
718 call assert_equal(1, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
719
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
720 exe 'terminal ++close ' . cmd
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
721 call assert_equal(2, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
722 wincmd p
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
723 call WaitForAssert({-> assert_equal(1, winnr('$'))}, waittime)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
724
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
725 call term_start(cmd, {'term_finish': 'close'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
726 call assert_equal(2, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
727 wincmd p
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
728 call WaitForAssert({-> assert_equal(1, winnr('$'))}, waittime)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
729 call assert_equal(1, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
730
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
731 exe 'terminal ++open ' . cmd
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
732 close!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
733 call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
734 bwipe
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
735
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
736 call term_start(cmd, {'term_finish': 'open'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
737 close!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
738 call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
739 bwipe
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
740
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
741 exe 'terminal ++hidden ++open ' . cmd
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
742 call assert_equal(1, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
743 call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
744 bwipe
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
745
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
746 call term_start(cmd, {'term_finish': 'open', 'hidden': 1})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
747 call assert_equal(1, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
748 call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
749 bwipe
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
750
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
751 call assert_fails("call term_start(cmd, {'term_opencmd': 'open'})", 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
752 call assert_fails("call term_start(cmd, {'term_opencmd': 'split %x'})", 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
753 call assert_fails("call term_start(cmd, {'term_opencmd': 'split %d and %s'})", 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
754 call assert_fails("call term_start(cmd, {'term_opencmd': 'split % and %d'})", 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
755
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
756 call term_start(cmd, {'term_finish': 'open', 'term_opencmd': '4split | buffer %d | let g:result = "opened the buffer in a window"'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
757 close!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
758 call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
759 call assert_equal(4, winheight(0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
760 call assert_equal('opened the buffer in a window', g:result)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
761 unlet g:result
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
762 bwipe
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
763 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
764
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
765 func Test_terminal_cwd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
766 if has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
767 let cmd = 'cmd /c cd'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
768 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
769 CheckExecutable pwd
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
770 let cmd = 'pwd'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
771 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
772 call mkdir('Xtermdir')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
773 let buf = term_start(cmd, {'cwd': 'Xtermdir'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
774 " if the path is very long it may be split over two lines, join them
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
775 " together
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
776 call WaitForAssert({-> assert_equal('Xtermdir', fnamemodify(getline(1) .. getline(2), ":t"))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
777
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
778 exe buf . 'bwipe'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
779 call delete('Xtermdir', 'rf')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
780 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
781
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
782 func Test_terminal_cwd_failure()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
783 " Case 1: Provided directory is not actually a directory. Attempt to make
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
784 " the file executable as well.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
785 call writefile([], 'Xtcfile', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
786 call setfperm('Xtcfile', 'rwx------')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
787 call assert_fails("call term_start(&shell, {'cwd': 'Xtcfile'})", 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
788
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
789 " Case 2: Directory does not exist.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
790 call assert_fails("call term_start(&shell, {'cwd': 'Xdir'})", 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
791
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
792 " Case 3: Directory exists but is not accessible.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
793 " Skip this for root, it will be accessible anyway.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
794 if !IsRoot()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
795 call mkdir('XdirNoAccess', '', '0600')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
796 " return early if the directory permissions could not be set properly
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
797 if getfperm('XdirNoAccess')[2] == 'x'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
798 call delete('XdirNoAccess', 'rf')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
799 return
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
800 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
801 call assert_fails("call term_start(&shell, {'cwd': 'XdirNoAccess'})", 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
802 call delete('XdirNoAccess', 'rf')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
803 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
804 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
805
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
806 func Test_terminal_servername()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
807 CheckFeature clientserver
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
808 call s:test_environment("VIM_SERVERNAME", v:servername)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
809 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
810
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
811 func Test_terminal_version()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
812 call s:test_environment("VIM_TERMINAL", string(v:version))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
813 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
814
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
815 func s:test_environment(name, value)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
816 let buf = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
817 " Wait for the shell to display a prompt
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
818 call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
819 if has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
820 call term_sendkeys(buf, "echo %" . a:name . "%\r")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
821 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
822 call term_sendkeys(buf, "echo $" . a:name . "\r")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
823 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
824 call TermWait(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
825 call StopShellInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
826 call WaitForAssert({-> assert_equal(a:value, getline(2))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
827
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
828 exe buf . 'bwipe'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
829 unlet buf
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
830 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
831
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
832 func Test_terminal_env()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
833 let buf = Run_shell_in_terminal({'env': {'TESTENV': 'correct'}})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
834 " Wait for the shell to display a prompt
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
835 call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
836 if has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
837 call term_sendkeys(buf, "echo %TESTENV%\r")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
838 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
839 call term_sendkeys(buf, "echo $TESTENV\r")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
840 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
841 eval buf->TermWait()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
842 call StopShellInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
843 call WaitForAssert({-> assert_equal('correct', getline(2))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
844
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
845 exe buf . 'bwipe'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
846 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
847
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
848 func Test_terminal_list_args()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
849 let buf = term_start([&shell, &shellcmdflag, 'echo "123"'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
850 call assert_fails(buf . 'bwipe', 'E948:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
851 exe buf . 'bwipe!'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
852 call assert_equal("", bufname(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
853 endfunction
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
854
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
855 func Test_terminal_noblock()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
856 let g:test_is_flaky = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
857 let buf = term_start(&shell)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
858 " Starting a terminal can be slow, esp. on busy CI machines.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
859 let wait_time = 7500
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
860 let letters = 'abcdefghijklmnopqrstuvwxyz'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
861 if has('bsd') || has('mac') || has('sun')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
862 " The shell or something else has a problem dealing with more than 1000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
863 " characters at the same time. It's very slow too.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
864 let len = 1000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
865 let wait_time = 15000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
866 let letters = 'abcdefghijklm'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
867 " NPFS is used in Windows, nonblocking mode does not work properly.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
868 elseif has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
869 let len = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
870 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
871 let len = 5000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
872 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
873
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
874 " Send a lot of text lines, should be buffered properly.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
875 for c in split(letters, '\zs')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
876 call term_sendkeys(buf, 'echo ' . repeat(c, len) . "\<cr>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
877 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
878 call term_sendkeys(buf, "echo done\<cr>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
879
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
880 " On MS-Windows there is an extra empty line below "done". Find "done" in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
881 " the last-but-one or the last-but-two line.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
882 let lnum = term_getsize(buf)[0] - 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
883 call WaitForAssert({-> assert_match('done', term_getline(buf, lnum - 1) .. '//' .. term_getline(buf, lnum))}, wait_time)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
884 let line = term_getline(buf, lnum)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
885 if line !~ 'done'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
886 let line = term_getline(buf, lnum - 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
887 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
888 call assert_match('done', line)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
889
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
890 let g:job = term_getjob(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
891 call StopShellInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
892 unlet g:job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
893 bwipe
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
894 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
895
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
896 func Test_terminal_write_stdin()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
897 " TODO: enable once writing to stdin works on MS-Windows
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
898 CheckNotMSWindows
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
899 CheckExecutable wc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
900 let g:test_is_flaky = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
901
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
902 call setline(1, ['one', 'two', 'three'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
903 %term wc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
904 call WaitForAssert({-> assert_match('3', getline("$"))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
905 let nrs = split(getline('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
906 call assert_equal(['3', '3', '14'], nrs)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
907 %bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
908
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
909 call setline(1, ['one', 'two', 'three', 'four'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
910 2,3term wc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
911 call WaitForAssert({-> assert_match('2', getline("$"))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
912 let nrs = split(getline('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
913 call assert_equal(['2', '2', '10'], nrs)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
914 %bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
915 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
916
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
917 func Test_terminal_eof_arg()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
918 call CheckPython(s:python)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
919 let g:test_is_flaky = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
920
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
921 call setline(1, ['print("hello")'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
922 exe '1term ++eof=exit(123) ' .. s:python
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
923 " MS-Windows echoes the input, Unix doesn't.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
924 if has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
925 call WaitFor({-> getline('$') =~ 'exit(123)'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
926 call assert_equal('hello', getline(line('$') - 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
927 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
928 call WaitFor({-> getline('$') =~ 'hello'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
929 call assert_equal('hello', getline('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
930 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
931 call assert_equal(123, bufnr()->term_getjob()->job_info().exitval)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
932 %bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
933 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
934
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
935 func Test_terminal_eof_arg_win32_ctrl_z()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
936 CheckMSWindows
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
937 call CheckPython(s:python)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
938 let g:test_is_flaky = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
939
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
940 call setline(1, ['print("hello")'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
941 exe '1term ++eof=<C-Z> ' .. s:python
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
942 call WaitForAssert({-> assert_match('\^Z', getline(line('$') - 1))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
943 call assert_match('\^Z', getline(line('$') - 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
944 %bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
945 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
946
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
947 func Test_terminal_duplicate_eof_arg()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
948 call CheckPython(s:python)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
949 let g:test_is_flaky = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
950
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
951 " Check the last specified ++eof arg is used and does not leak memory.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
952 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
953 call setline(1, ['print("hello")'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
954 exe '1term ++eof=<C-Z> ++eof=exit(123) ' .. s:python
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
955 " MS-Windows echoes the input, Unix doesn't.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
956 if has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
957 call WaitFor({-> getline('$') =~ 'exit(123)'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
958 call assert_equal('hello', getline(line('$') - 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
959 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
960 call WaitFor({-> getline('$') =~ 'hello'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
961 call assert_equal('hello', getline('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
962 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
963 call assert_equal(123, bufnr()->term_getjob()->job_info().exitval)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
964 %bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
965 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
966
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
967 func Test_terminal_no_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
968 let g:test_is_flaky = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
969 let buf = term_start('NONE', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
970 call assert_notequal(0, buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
971
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
972 let pty = job_info(term_getjob(buf))['tty_out']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
973 call assert_notequal('', pty)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
974 if has('gui_running') && !has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
975 " In the GUI job_start() doesn't work, it does not read from the pty.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
976 call system('echo "look here" > ' . pty)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
977 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
978 " Otherwise using a job works on all systems.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
979 call job_start([&shell, &shellcmdflag, 'echo "look here" > ' . pty])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
980 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
981 call WaitForAssert({-> assert_match('look here', term_getline(buf, 1))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
982
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
983 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
984 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
985
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
986 func Test_terminal_special_chars()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
987 " this file name only works on Unix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
988 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
989
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
990 call mkdir('Xdir with spaces', 'R')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
991 call writefile(['x'], 'Xdir with spaces/quoted"file')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
992 term ls Xdir\ with\ spaces/quoted\"file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
993 call WaitForAssert({-> assert_match('quoted"file', term_getline('', 1))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
994 " make sure the job has finished
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
995 call WaitForAssert({-> assert_match('finish', term_getstatus(bufnr()))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
996
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
997 bwipe
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
998 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
999
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1000 func Test_terminal_wrong_options()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1001 call assert_fails('call term_start(&shell, {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1002 \ "in_io": "file",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1003 \ "in_name": "xxx",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1004 \ "out_io": "file",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1005 \ "out_name": "xxx",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1006 \ "err_io": "file",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1007 \ "err_name": "xxx"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1008 \ })', 'E474:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1009 call assert_fails('call term_start(&shell, {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1010 \ "out_buf": bufnr("%")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1011 \ })', 'E474:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1012 call assert_fails('call term_start(&shell, {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1013 \ "err_buf": bufnr("%")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1014 \ })', 'E474:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1015 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1016
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1017 func Test_terminal_redir_file()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1018 let g:test_is_flaky = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1019 let cmd = Get_cat_123_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1020 let buf = term_start(cmd, {'out_io': 'file', 'out_name': 'Xtrfile'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1021 call TermWait(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1022 " ConPTY may precede escape sequence. There are things that are not so.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1023 if !has('conpty')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1024 call WaitForAssert({-> assert_notequal(0, len(readfile("Xtrfile")))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1025 call assert_match('123', readfile('Xtrfile')[0])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1026 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1027 let g:job = term_getjob(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1028 call WaitForAssert({-> assert_equal("dead", job_status(g:job))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1029
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1030 if has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1031 " On Windows we cannot delete a file being used by a process. When
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1032 " job_status() returns "dead", the process remains for a short time.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1033 " Just wait for a moment.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1034 sleep 50m
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1035 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1036 call delete('Xtrfile')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1037 bwipe
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1038
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1039 if has('unix')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1040 call writefile(['one line'], 'Xtrfile', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1041 let buf = term_start('cat', {'in_io': 'file', 'in_name': 'Xtrfile'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1042 call TermWait(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1043 call WaitForAssert({-> assert_equal('one line', term_getline(buf, 1))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1044 let g:job = term_getjob(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1045 call WaitForAssert({-> assert_equal('dead', job_status(g:job))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1046 bwipe
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1047 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1048 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1049
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1050 func TerminalTmap(remap)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1051 let buf = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1052 " Wait for the shell to display a prompt
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1053 call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1054 call assert_equal('t', mode())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1055
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1056 if a:remap
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1057 tmap 123 456
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1058 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1059 tnoremap 123 456
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1060 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1061 " don't use abcde, it's an existing command
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1062 tmap 456 abxde
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1063 call assert_equal('456', maparg('123', 't'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1064 call assert_equal('abxde', maparg('456', 't'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1065 call feedkeys("123", 'tx')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1066 call WaitForAssert({-> assert_match('abxde\|456', term_getline(buf, term_getcursor(buf)[0]))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1067 let lnum = term_getcursor(buf)[0]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1068 if a:remap
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1069 call assert_match('abxde', term_getline(buf, lnum))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1070 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1071 call assert_match('456', term_getline(buf, lnum))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1072 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1073
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1074 call term_sendkeys(buf, "\r")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1075 call StopShellInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1076
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1077 tunmap 123
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1078 tunmap 456
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1079 call assert_equal('', maparg('123', 't'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1080 exe buf . 'bwipe'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1081 unlet g:job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1082 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1083
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1084 func Test_terminal_tmap()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1085 call TerminalTmap(1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1086 call TerminalTmap(0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1087 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1088
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1089 func Test_terminal_wall()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1090 let buf = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1091 wall
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1092 call StopShellInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1093 exe buf . 'bwipe'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1094 unlet g:job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1095 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1096
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1097 func Test_terminal_wqall()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1098 let buf = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1099 call assert_fails('wqall', 'E948:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1100 call StopShellInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1101 exe buf . 'bwipe'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1102 unlet g:job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1103 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1104
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1105 func Test_terminal_composing_unicode()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1106 let g:test_is_flaky = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1107 let save_enc = &encoding
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1108 set encoding=utf-8
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1109
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1110 if has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1111 let cmd = "cmd /K chcp 65001"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1112 let lnum = [3, 6, 9]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1113 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1114 let cmd = &shell
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1115 let lnum = [1, 3, 5]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1116 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1117
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1118 enew
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1119 let buf = term_start(cmd, {'curwin': 1})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1120 let g:job = term_getjob(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1121 call WaitFor({-> term_getline(buf, 1) !=# ''}, 1000)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1122
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1123 if has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1124 call assert_equal('cmd', job_info(g:job).cmd[0])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1125 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1126 call assert_equal(&shell, job_info(g:job).cmd[0])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1127 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1128
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1129 " ascii + composing
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1130 let txt = "a\u0308bc"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1131 call term_sendkeys(buf, "echo " . txt)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1132 call TermWait(buf, 25)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1133 call assert_match("echo " . txt, term_getline(buf, lnum[0]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1134 call term_sendkeys(buf, "\<cr>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1135 call WaitForAssert({-> assert_equal(txt, term_getline(buf, lnum[0] + 1))}, 1000)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1136 let l = term_scrape(buf, lnum[0] + 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1137 call assert_equal("a\u0308", l[0].chars)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1138 call assert_equal("b", l[1].chars)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1139 call assert_equal("c", l[2].chars)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1140
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1141 " multibyte + composing: がぎぐげご
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1142 let txt = "\u304b\u3099\u304e\u304f\u3099\u3052\u3053\u3099"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1143 call term_sendkeys(buf, "echo " . txt)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1144 call TermWait(buf, 25)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1145 call assert_match("echo " . txt, term_getline(buf, lnum[1]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1146 call term_sendkeys(buf, "\<cr>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1147 call WaitForAssert({-> assert_equal(txt, term_getline(buf, lnum[1] + 1))}, 1000)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1148 let l = term_scrape(buf, lnum[1] + 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1149 call assert_equal("\u304b\u3099", l[0].chars)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1150 call assert_equal(2, l[0].width)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1151 call assert_equal("\u304e", l[1].chars)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1152 call assert_equal(2, l[1].width)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1153 call assert_equal("\u304f\u3099", l[2].chars)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1154 call assert_equal(2, l[2].width)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1155 call assert_equal("\u3052", l[3].chars)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1156 call assert_equal(2, l[3].width)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1157 call assert_equal("\u3053\u3099", l[4].chars)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1158 call assert_equal(2, l[4].width)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1159
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1160 " \u00a0 + composing
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1161 let txt = "abc\u00a0\u0308"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1162 call term_sendkeys(buf, "echo " . txt)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1163 call TermWait(buf, 25)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1164 call assert_match("echo " . txt, term_getline(buf, lnum[2]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1165 call term_sendkeys(buf, "\<cr>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1166 call WaitForAssert({-> assert_equal(txt, term_getline(buf, lnum[2] + 1))}, 1000)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1167 let l = term_scrape(buf, lnum[2] + 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1168 call assert_equal("\u00a0\u0308", l[3].chars)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1169
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1170 call term_sendkeys(buf, "exit\r")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1171 call WaitForAssert({-> assert_equal('dead', job_status(g:job))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1172 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1173 unlet g:job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1174 let &encoding = save_enc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1175 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1176
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1177 func Test_terminal_aucmd_on_close()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1178 fun Nop()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1179 let s:called = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1180 endfun
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1181
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1182 aug repro
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1183 au!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1184 au BufWinLeave * call Nop()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1185 aug END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1186
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1187 let [cmd, waittime] = s:get_sleep_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1188
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1189 call assert_equal(1, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1190 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1191 call setline(1, ['one', 'two'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1192 exe 'term ++close ' . cmd
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1193 wincmd p
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1194 call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1195 call assert_equal(1, s:called)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1196 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1197
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1198 unlet s:called
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1199 au! repro
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1200 delfunc Nop
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1201 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1202
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1203 func Test_terminal_term_start_empty_command()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1204 let cmd = "call term_start('', {'curwin' : 1, 'term_finish' : 'close'})"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1205 call assert_fails(cmd, 'E474:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1206 let cmd = "call term_start('', {'curwin' : 1, 'term_finish' : 'close'})"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1207 call assert_fails(cmd, 'E474:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1208 let cmd = "call term_start({}, {'curwin' : 1, 'term_finish' : 'close'})"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1209 call assert_fails(cmd, 'E474:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1210 let cmd = "call term_start(0, {'curwin' : 1, 'term_finish' : 'close'})"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1211 call assert_fails(cmd, 'E474:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1212 let cmd = "call term_start('', {'term_name' : []})"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1213 call assert_fails(cmd, 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1214 let cmd = "call term_start('', {'term_finish' : 'axby'})"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1215 call assert_fails(cmd, 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1216 let cmd = "call term_start('', {'eof_chars' : []})"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1217 call assert_fails(cmd, 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1218 let cmd = "call term_start('', {'term_kill' : []})"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1219 call assert_fails(cmd, 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1220 let cmd = "call term_start('', {'tty_type' : []})"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1221 call assert_fails(cmd, 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1222 let cmd = "call term_start('', {'tty_type' : 'abc'})"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1223 call assert_fails(cmd, 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1224 let cmd = "call term_start('', {'term_highlight' : []})"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1225 call assert_fails(cmd, 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1226 if has('gui') || has('termguicolors')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1227 let cmd = "call term_start('', {'ansi_colors' : 'abc'})"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1228 call assert_fails(cmd, 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1229 let cmd = "call term_start('', {'ansi_colors' : [[]]})"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1230 call assert_fails(cmd, 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1231 let cmd = "call term_start('', {'ansi_colors' : repeat(['blue'], 18)})"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1232 if has('gui_running') || has('termguicolors')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1233 call assert_fails(cmd, 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1234 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1235 call assert_fails(cmd, 'E254:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1236 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1237 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1238 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1239
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1240 func Test_terminal_response_to_control_sequence()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1241 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1242
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1243 let buf = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1244 call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1245
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1246 call term_sendkeys(buf, "cat\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1247 call WaitForAssert({-> assert_match('cat', term_getline(buf, 1))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1248
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1249 " Request the cursor position.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1250 call term_sendkeys(buf, "\x1b[6n\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1251
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1252 " Wait for output from tty to display, below an empty line.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1253 call WaitForAssert({-> assert_match('3;1R', term_getline(buf, 4))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1254
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1255 " End "cat" gently.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1256 call term_sendkeys(buf, "\<CR>\<C-D>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1257
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1258 call StopShellInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1259 exe buf . 'bwipe'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1260 unlet g:job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1261 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1262
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1263 " Run this first, it fails when run after other tests.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1264 func Test_aa_terminal_focus_events()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1265 CheckNotGui
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1266 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1267 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1268
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1269 let save_term = &term
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1270 let save_ttymouse = &ttymouse
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1271 set term=xterm ttymouse=xterm2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1272
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1273 let lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1274 set term=xterm ttymouse=xterm2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1275 au FocusLost * call setline(1, 'I am lost') | set nomod
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1276 au FocusGained * call setline(1, 'I am back') | set nomod
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1277 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1278 call writefile(lines, 'XtermFocus', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1279 let buf = RunVimInTerminal('-S XtermFocus', #{rows: 6})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1280
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1281 " Send a focus event to ourselves, it should be forwarded to the terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1282 call feedkeys("\<Esc>[O", "Lx!")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1283 call VerifyScreenDump(buf, 'Test_terminal_focus_1', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1284
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1285 call feedkeys("\<Esc>[I", "Lx!")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1286 call VerifyScreenDump(buf, 'Test_terminal_focus_2', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1287
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1288 " check that a command line being edited is redrawn in place
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1289 call term_sendkeys(buf, ":" .. repeat('x', 80))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1290 call TermWait(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1291 call feedkeys("\<Esc>[O", "Lx!")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1292 call VerifyScreenDump(buf, 'Test_terminal_focus_3', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1293 call term_sendkeys(buf, "\<Esc>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1294
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1295 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1296 let &term = save_term
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1297 let &ttymouse = save_ttymouse
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1298 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1299
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1300 " Run Vim, start a terminal in that Vim with the kill argument,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1301 " :qall works.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1302 func Run_terminal_qall_kill(line1, line2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1303 " 1. Open a terminal window and wait for the prompt to appear
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1304 " 2. set kill using term_setkill()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1305 " 3. make Vim exit, it will kill the shell
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1306 let after = [
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1307 \ a:line1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1308 \ 'let buf = bufnr("%")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1309 \ 'while term_getline(buf, 1) =~ "^\\s*$"',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1310 \ ' sleep 10m',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1311 \ 'endwhile',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1312 \ a:line2,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1313 \ 'au VimLeavePre * call writefile(["done"], "Xdone")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1314 \ 'qall',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1315 \ ]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1316 if !RunVim([], after, '')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1317 return
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1318 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1319 call assert_equal("done", readfile("Xdone")[0])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1320 call delete("Xdone")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1321 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1322
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1323 " Run Vim in a terminal, then start a terminal in that Vim with a kill
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1324 " argument, check that :qall works.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1325 func Test_terminal_qall_kill_arg()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1326 call Run_terminal_qall_kill('term ++kill=kill', '')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1327 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1328
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1329 " Run Vim, start a terminal in that Vim, set the kill argument with
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1330 " term_setkill(), check that :qall works.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1331 func Test_terminal_qall_kill_func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1332 call Run_terminal_qall_kill('term', 'eval buf->term_setkill("kill")')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1333 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1334
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1335 " Run Vim, start a terminal in that Vim without the kill argument,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1336 " check that :qall does not exit, :qall! does.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1337 func Test_terminal_qall_exit()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1338 let after =<< trim [CODE]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1339 term
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1340 let buf = bufnr("%")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1341 while term_getline(buf, 1) =~ "^\\s*$"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1342 sleep 10m
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1343 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1344 set nomore
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1345 au VimLeavePre * call writefile(["too early"], "Xdone")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1346 qall
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1347 au! VimLeavePre * exe buf . "bwipe!" | call writefile(["done"], "Xdone")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1348 cquit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1349 [CODE]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1350
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1351 if !RunVim([], after, '')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1352 return
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1353 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1354 call assert_equal("done", readfile("Xdone")[0])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1355 call delete("Xdone")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1356 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1357
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1358 " Run Vim in a terminal, then start a terminal in that Vim without a kill
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1359 " argument, check that :confirm qall works.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1360 func Test_terminal_qall_prompt()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1361 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1362
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1363 let buf = RunVimInTerminal('', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1364
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1365 " the shell may set the window title, we don't want that here
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1366 call term_sendkeys(buf, ":call test_override('vterm_title', 1)\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1367
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1368 " Open a terminal window and wait for the prompt to appear
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1369 call term_sendkeys(buf, ":term\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1370 call WaitForAssert({-> assert_match('\[running]', term_getline(buf, 10))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1371 call WaitForAssert({-> assert_notmatch('^\s*$', term_getline(buf, 1))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1372
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1373 " make Vim exit, it will prompt to kill the shell
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1374 call term_sendkeys(buf, "\<C-W>:confirm qall\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1375 call WaitForAssert({-> assert_match('\[Y\]es, (N)o:', term_getline(buf, 20))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1376 call term_sendkeys(buf, "y")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1377 call WaitForAssert({-> assert_equal('finished', term_getstatus(buf))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1378
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1379 " close the terminal window where Vim was running
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1380 quit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1381 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1382
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1383 " Run Vim in a terminal, then start a terminal window with a shell and check
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1384 " that Vim exits if it is closed.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1385 func Test_terminal_exit()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1386 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1387
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1388 let lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1389 let winid = win_getid()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1390 help
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1391 term
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1392 let termid = win_getid()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1393 call win_gotoid(winid)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1394 close
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1395 call win_gotoid(termid)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1396 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1397 call writefile(lines, 'XtermExit', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1398 let buf = RunVimInTerminal('-S XtermExit', #{rows: 10})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1399 let job = term_getjob(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1400 call WaitForAssert({-> assert_equal("run", job_status(job))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1401
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1402 " quit the shell, it will make Vim exit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1403 call term_sendkeys(buf, "exit\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1404 call WaitForAssert({-> assert_equal("dead", job_status(job))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1405 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1406
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1407 func Test_terminal_open_autocmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1408 augroup repro
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1409 au!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1410 au TerminalOpen * let s:called += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1411 augroup END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1412
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1413 let s:called = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1414
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1415 " Open a terminal window with :terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1416 terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1417 call assert_equal(1, s:called)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1418 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1419
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1420 " Open a terminal window with term_start()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1421 call term_start(&shell)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1422 call assert_equal(2, s:called)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1423 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1424
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1425 " Open a hidden terminal buffer with :terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1426 terminal ++hidden
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1427 call assert_equal(3, s:called)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1428 for buf in term_list()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1429 exe buf . "bwipe!"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1430 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1431
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1432 " Open a hidden terminal buffer with term_start()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1433 let buf = term_start(&shell, {'hidden': 1})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1434 call assert_equal(4, s:called)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1435 exe buf . "bwipe!"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1436
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1437 unlet s:called
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1438 au! repro
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1439 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1440
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1441 func Test_open_term_from_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1442 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1443 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1444
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1445 let lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1446 call setline(1, ['a', 'b', 'c'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1447 3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1448 set incsearch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1449 cnoremap <F3> <Cmd>call term_start(['/bin/sh', '-c', ':'])<CR>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1450 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1451 call writefile(lines, 'Xopenterm', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1452 let buf = RunVimInTerminal('-S Xopenterm', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1453
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1454 " this opens a window, incsearch should not use the old cursor position
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1455 call term_sendkeys(buf, "/\<F3>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1456 call VerifyScreenDump(buf, 'Test_terminal_from_cmd', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1457 call term_sendkeys(buf, "\<Esc>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1458 call term_sendkeys(buf, ":q\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1459
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1460 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1461 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1462
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1463 func Test_combining_double_width()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1464 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1465 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1466
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1467 call writefile(["\xe3\x83\x9b\xe3\x82\x9a"], 'Xonedouble', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1468 let lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1469 call term_start(['/bin/sh', '-c', 'cat Xonedouble'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1470 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1471 call writefile(lines, 'Xcombining', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1472 let buf = RunVimInTerminal('-S Xcombining', #{rows: 9})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1473
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1474 " this opens a window, incsearch should not use the old cursor position
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1475 call VerifyScreenDump(buf, 'Test_terminal_combining', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1476 call term_sendkeys(buf, ":q\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1477
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1478 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1479 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1480
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1481 func Test_terminal_popup_with_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1482 " this was crashing
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1483 let buf = term_start(&shell, #{hidden: v:true})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1484 let s:winid = popup_create(buf, {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1485 tnoremap <F3> <Cmd>call popup_close(s:winid)<CR>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1486 call feedkeys("\<F3>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1487
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1488 tunmap <F3>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1489 exe 'bwipe! ' .. buf
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1490 unlet s:winid
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1491 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1492
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1493 func Test_terminal_popup_bufload()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1494 let termbuf = term_start(&shell, #{hidden: v:true, term_finish: 'close'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1495 let winid = popup_create(termbuf, {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1496 sleep 50m
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1497
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1498 let newbuf = bufadd('')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1499 call bufload(newbuf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1500 call setbufline(newbuf, 1, 'foobar')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1501
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1502 " must not have switched to another window
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1503 call assert_equal(winid, win_getid())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1504
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1505 call StopShellInTerminal(termbuf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1506 call WaitFor({-> win_getid() != winid})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1507 exe 'bwipe! ' .. newbuf
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1508 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1509
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1510 func Test_terminal_popup_two_windows()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1511 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1512 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1513
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1514 " use "sh" instead of "&shell" in the hope it will use a short prompt
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1515 let lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1516 let termbuf = term_start('sh', #{hidden: v:true, term_finish: 'close'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1517 exe 'buffer ' .. termbuf
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1518
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1519 let winid = popup_create(termbuf, #{line: 2, minwidth: 30, border: []})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1520 sleep 50m
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1521
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1522 call term_sendkeys(termbuf, "echo 'test'")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1523 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1524 call writefile(lines, 'XpopupScript', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1525 let buf = RunVimInTerminal('-S XpopupScript', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1526
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1527 " typed text appears both in normal window and in popup
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1528 call WaitForAssert({-> assert_match("echo 'test'", term_getline(buf, 1))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1529 call WaitForAssert({-> assert_match("echo 'test'", term_getline(buf, 3))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1530
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1531 call term_sendkeys(buf, "\<CR>\<CR>exit\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1532 call TermWait(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1533 call term_sendkeys(buf, ":q\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1534 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1535 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1536
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1537 func Test_terminal_popup_insert_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1538 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1539
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1540 inoremap <F3> <Cmd>call StartTermInPopup()<CR>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1541 func StartTermInPopup()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1542 call term_start(['/bin/sh', '-c', 'cat'], #{hidden: v:true, term_finish: 'close'})->popup_create(#{highlight: 'Pmenu'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1543 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1544 call feedkeys("i\<F3>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1545 sleep 10m
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1546 call assert_equal('n', mode())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1547
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1548 call feedkeys("\<C-D>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1549 call WaitFor({-> popup_list() == []})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1550 delfunc StartTermInPopup
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1551 iunmap <F3>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1552 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1553
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1554 func Check_dump01(off)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1555 call assert_equal('one two three four five', trim(getline(a:off + 1)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1556 call assert_equal('~ Select Word', trim(getline(a:off + 7)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1557 call assert_equal(':popup PopUp', trim(getline(a:off + 20)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1558 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1559
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1560 func Test_terminal_dumpwrite_composing()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1561 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1562
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1563 let save_enc = &encoding
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1564 set encoding=utf-8
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1565 call assert_equal(1, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1566
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1567 let text = " a\u0300 e\u0302 o\u0308"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1568 call writefile([text], 'Xcomposing', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1569 let buf = RunVimInTerminal('--cmd "set encoding=utf-8" Xcomposing', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1570 call WaitForAssert({-> assert_match(text, term_getline(buf, 1))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1571 eval 'Xdump'->term_dumpwrite(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1572 let dumpline = readfile('Xdump')[0]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1573 call assert_match('|à| |ê| |ö', dumpline)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1574
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1575 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1576 call delete('Xdump')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1577 let &encoding = save_enc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1578 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1579
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1580 " Tests for failures in the term_dumpwrite() function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1581 func Test_terminal_dumpwrite_errors()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1582 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1583 call assert_fails("call term_dumpwrite({}, 'Xtest.dump')", 'E728:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1584 let buf = RunVimInTerminal('', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1585 call TermWait(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1586 call assert_fails("call term_dumpwrite(buf, 'Xtest.dump', '')", 'E1206:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1587 call assert_fails("call term_dumpwrite(buf, [])", 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1588 call writefile([], 'Xtest.dump')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1589 call assert_fails("call term_dumpwrite(buf, 'Xtest.dump')", 'E953:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1590 call delete('Xtest.dump')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1591 call assert_fails("call term_dumpwrite(buf, '')", 'E482:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1592 call assert_fails("call term_dumpwrite(buf, test_null_string())", 'E482:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1593 call test_garbagecollect_now()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1594 call StopVimInTerminal(buf, 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1595 call TermWait(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1596 call assert_fails("call term_dumpwrite(buf, 'Xtest.dump')", 'E958:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1597 call assert_fails('call term_sendkeys([], ":q\<CR>")', 'E745:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1598 call assert_equal(0, term_sendkeys(buf, ":q\<CR>"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1599 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1600
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1601 " just testing basic functionality.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1602 func Test_terminal_dumpload()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1603 let curbuf = winbufnr('')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1604 call assert_equal(1, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1605 let buf = term_dumpload('dumps/Test_popup_command_01.dump')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1606 call assert_equal(2, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1607 call assert_equal(20, line('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1608 call Check_dump01(0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1609
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1610 " Load another dump in the same window
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1611 let buf2 = 'dumps/Test_diff_01.dump'->term_dumpload({'bufnr': buf})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1612 call assert_equal(buf, buf2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1613 call assert_notequal('one two three four five', trim(getline(1)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1614
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1615 " Load the first dump again in the same window
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1616 let buf2 = term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': buf})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1617 call assert_equal(buf, buf2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1618 call Check_dump01(0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1619
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1620 call assert_fails("call term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': curbuf})", 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1621 call assert_fails("call term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': 9999})", 'E86:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1622 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1623 let closedbuf = winbufnr('')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1624 quit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1625 call assert_fails("call term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': closedbuf})", 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1626 call assert_fails('call term_dumpload([])', 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1627 call assert_fails('call term_dumpload("xabcy.dump")', 'E485:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1628
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1629 quit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1630 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1631
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1632 func Test_terminal_dumpload_dump()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1633 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1634
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1635 let lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1636 call term_dumpload('dumps/Test_popupwin_22.dump', #{term_rows: 12})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1637 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1638 call writefile(lines, 'XtermDumpload', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1639 let buf = RunVimInTerminal('-S XtermDumpload', #{rows: 15})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1640 call VerifyScreenDump(buf, 'Test_terminal_dumpload', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1641
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1642 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1643 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1644
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1645 func Test_terminal_dumpdiff()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1646 call assert_equal(1, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1647 eval 'dumps/Test_popup_command_01.dump'->term_dumpdiff('dumps/Test_popup_command_02.dump')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1648 call assert_equal(2, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1649 call assert_equal(62, line('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1650 call Check_dump01(0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1651 call Check_dump01(42)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1652 call assert_equal(' bbbbbbbbbbbbbbbbbb ', getline(26)[0:29])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1653 quit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1654
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1655 call assert_fails('call term_dumpdiff("X1.dump", [])', 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1656 call assert_fails('call term_dumpdiff("X1.dump", "X2.dump")', 'E485:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1657 call writefile([], 'X1.dump', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1658 call assert_fails('call term_dumpdiff("X1.dump", "X2.dump")', 'E485:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1659 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1660
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1661 func Test_terminal_dumpdiff_swap()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1662 call assert_equal(1, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1663 call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_03.dump')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1664 call assert_equal(2, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1665 call assert_equal(62, line('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1666 call assert_match('Test_popup_command_01.dump', getline(21))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1667 call assert_match('Test_popup_command_03.dump', getline(42))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1668 call assert_match('Undo', getline(3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1669 call assert_match('three four five', getline(45))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1670
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1671 normal s
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1672 call assert_match('Test_popup_command_03.dump', getline(21))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1673 call assert_match('Test_popup_command_01.dump', getline(42))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1674 call assert_match('three four five', getline(3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1675 call assert_match('Undo', getline(45))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1676 quit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1677
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1678 " Diff two terminal dump files with different number of rows
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1679 " Swap the diffs
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1680 call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_winline_rnu.dump')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1681 call assert_match('Test_popup_command_01.dump', getline(21))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1682 call assert_match('Test_winline_rnu.dump', getline(42))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1683 normal s
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1684 call assert_match('Test_winline_rnu.dump', getline(6))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1685 call assert_match('Test_popup_command_01.dump', getline(27))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1686 quit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1687 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1688
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1689 func Test_terminal_dumpdiff_options()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1690 set laststatus=0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1691 call assert_equal(1, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1692 let height = winheight(0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1693 call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump', {'vertical': 1, 'term_cols': 33})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1694 call assert_equal(2, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1695 call assert_equal(height, winheight(winnr()))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1696 call assert_equal(33, winwidth(winnr()))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1697 call assert_equal('dump diff dumps/Test_popup_command_01.dump', bufname('%'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1698 quit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1699
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1700 call assert_equal(1, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1701 call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump', {'vertical': 0, 'term_rows': 13, 'term_name': 'something else'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1702 call assert_equal(2, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1703 call assert_equal(&columns, winwidth(0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1704 call assert_equal(13, winheight(0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1705 call assert_equal('something else', bufname('%'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1706 quit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1707
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1708 call assert_equal(1, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1709 call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump', {'curwin': 1})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1710 call assert_equal(1, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1711 call assert_fails("call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump', {'bufnr': -1})", 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1712 bwipe
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1713
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1714 set laststatus&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1715 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1716
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1717 " When drawing the statusline the cursor position may not have been updated
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1718 " yet.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1719 " 1. create a terminal, make it show 2 lines
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1720 " 2. 0.5 sec later: leave terminal window, execute "i"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1721 " 3. 0.5 sec later: clear terminal window, now it's 1 line
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1722 " 4. 0.5 sec later: redraw, including statusline (used to trigger bug)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1723 " 4. 0.5 sec later: should be done, clean up
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1724 func Test_terminal_statusline()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1725 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1726 CheckFeature timers
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1727
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1728 set statusline=x
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1729 terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1730 let tbuf = bufnr('')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1731 call term_sendkeys(tbuf, "clear; echo a; echo b; sleep 1; clear\n")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1732 call timer_start(500, { tid -> feedkeys("\<C-w>j", 'tx') })
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1733 call timer_start(1500, { tid -> feedkeys("\<C-l>", 'tx') })
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1734 au BufLeave * if &buftype == 'terminal' | silent! normal i | endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1735
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1736 sleep 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1737 exe tbuf . 'bwipe!'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1738 au! BufLeave
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1739 set statusline=
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1740 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1741
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1742 func CheckTerminalWindowWorks(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1743 call WaitForAssert({-> assert_match('!sh \[running\]', term_getline(a:buf, 10))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1744 call term_sendkeys(a:buf, "exit\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1745 call WaitForAssert({-> assert_match('!sh \[finished\]', term_getline(a:buf, 10))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1746 call term_sendkeys(a:buf, ":q\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1747 call WaitForAssert({-> assert_match('^\~', term_getline(a:buf, 10))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1748 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1749
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1750 func Test_start_terminal_from_timer()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1751 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1752 CheckFeature timers
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1753
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1754 " Open a terminal window from a timer, typed text goes to the terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1755 call writefile(["call timer_start(100, { -> term_start('sh') })"], 'XtimerTerm', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1756 let buf = RunVimInTerminal('-S XtimerTerm', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1757 call CheckTerminalWindowWorks(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1758
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1759 " do the same in Insert mode
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1760 call term_sendkeys(buf, ":call timer_start(200, { -> term_start('sh') })\<CR>a")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1761 call CheckTerminalWindowWorks(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1762
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1763 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1764 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1765
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1766 func Test_terminal_window_focus()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1767 let winid1 = win_getid()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1768 terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1769 let winid2 = win_getid()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1770 call feedkeys("\<C-W>j", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1771 call assert_equal(winid1, win_getid())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1772 call feedkeys("\<C-W>k", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1773 call assert_equal(winid2, win_getid())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1774 " can use a cursor key here
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1775 call feedkeys("\<C-W>\<Down>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1776 call assert_equal(winid1, win_getid())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1777 call feedkeys("\<C-W>\<Up>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1778 call assert_equal(winid2, win_getid())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1779
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1780 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1781 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1782
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1783 func Api_drop_common(options)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1784 call assert_equal(1, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1785
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1786 " Use the title termcap entries to output the escape sequence.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1787 call writefile([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1788 \ 'set title',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1789 \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1790 \ 'let &titlestring = ''["drop","Xtextfile"' . a:options . ']''',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1791 \ 'redraw',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1792 \ "set t_ts=",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1793 \ ], 'Xscript')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1794 let buf = RunVimInTerminal('-S Xscript', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1795 call WaitFor({-> bufnr('Xtextfile') > 0})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1796 call assert_equal('Xtextfile', expand('%:t'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1797 call assert_true(winnr('$') >= 3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1798 return buf
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1799 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1800
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1801 func Test_terminal_api_drop_newwin()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1802 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1803 let buf = Api_drop_common('')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1804 call assert_equal(0, &bin)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1805 call assert_equal('', &fenc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1806
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1807 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1808 call delete('Xscript')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1809 bwipe Xtextfile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1810 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1811
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1812 func Test_terminal_api_drop_newwin_bin()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1813 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1814 let buf = Api_drop_common(',{"bin":1}')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1815 call assert_equal(1, &bin)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1816
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1817 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1818 call delete('Xscript')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1819 bwipe Xtextfile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1820 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1821
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1822 func Test_terminal_api_drop_newwin_binary()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1823 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1824 let buf = Api_drop_common(',{"binary":1}')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1825 call assert_equal(1, &bin)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1826
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1827 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1828 call delete('Xscript')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1829 bwipe Xtextfile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1830 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1831
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1832 func Test_terminal_api_drop_newwin_nobin()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1833 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1834 set binary
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1835 let buf = Api_drop_common(',{"nobin":1}')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1836 call assert_equal(0, &bin)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1837
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1838 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1839 call delete('Xscript')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1840 bwipe Xtextfile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1841 set nobinary
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1842 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1843
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1844 func Test_terminal_api_drop_newwin_nobinary()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1845 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1846 set binary
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1847 let buf = Api_drop_common(',{"nobinary":1}')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1848 call assert_equal(0, &bin)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1849
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1850 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1851 call delete('Xscript')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1852 bwipe Xtextfile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1853 set nobinary
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1854 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1855
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1856 func Test_terminal_api_drop_newwin_ff()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1857 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1858 let buf = Api_drop_common(',{"ff":"dos"}')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1859 call assert_equal("dos", &ff)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1860
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1861 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1862 call delete('Xscript')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1863 bwipe Xtextfile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1864 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1865
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1866 func Test_terminal_api_drop_newwin_fileformat()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1867 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1868 let buf = Api_drop_common(',{"fileformat":"dos"}')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1869 call assert_equal("dos", &ff)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1870
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1871 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1872 call delete('Xscript')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1873 bwipe Xtextfile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1874 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1875
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1876 func Test_terminal_api_drop_newwin_enc()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1877 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1878 let buf = Api_drop_common(',{"enc":"utf-16"}')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1879 call assert_equal("utf-16", &fenc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1880
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1881 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1882 call delete('Xscript')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1883 bwipe Xtextfile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1884 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1885
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1886 func Test_terminal_api_drop_newwin_encoding()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1887 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1888 let buf = Api_drop_common(',{"encoding":"utf-16"}')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1889 call assert_equal("utf-16", &fenc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1890
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1891 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1892 call delete('Xscript')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1893 bwipe Xtextfile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1894 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1895
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1896 func Test_terminal_api_drop_oldwin()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1897 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1898 let firstwinid = win_getid()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1899 split Xtextfile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1900 let textfile_winid = win_getid()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1901 call assert_equal(2, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1902 call win_gotoid(firstwinid)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1903
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1904 " Use the title termcap entries to output the escape sequence.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1905 call writefile([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1906 \ 'set title',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1907 \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1908 \ 'let &titlestring = ''["drop","Xtextfile"]''',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1909 \ 'redraw',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1910 \ "set t_ts=",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1911 \ ], 'Xscript', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1912 let buf = RunVimInTerminal('-S Xscript', {'rows': 10})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1913 call WaitForAssert({-> assert_equal('Xtextfile', expand('%:t'))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1914 call assert_equal(textfile_winid, win_getid())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1915
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1916 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1917 bwipe Xtextfile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1918 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1919
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1920 func Tapi_TryThis(bufnum, arg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1921 let g:called_bufnum = a:bufnum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1922 let g:called_arg = a:arg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1923 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1924
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1925 func WriteApiCall(funcname)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1926 " Use the title termcap entries to output the escape sequence.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1927 call writefile([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1928 \ 'set title',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1929 \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1930 \ 'let &titlestring = ''["call","' . a:funcname . '",["hello",123]]''',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1931 \ 'redraw',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1932 \ "set t_ts=",
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1933 \ ], 'Xscript')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1934 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1935
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1936 func Test_terminal_api_call()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1937 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1938
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1939 unlet! g:called_bufnum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1940 unlet! g:called_arg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1941
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1942 call WriteApiCall('Tapi_TryThis')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1943
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1944 " Default
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1945 let buf = RunVimInTerminal('-S Xscript', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1946 call WaitFor({-> exists('g:called_bufnum')})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1947 call assert_equal(buf, g:called_bufnum)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1948 call assert_equal(['hello', 123], g:called_arg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1949 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1950
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1951 unlet! g:called_bufnum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1952 unlet! g:called_arg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1953
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1954 " Enable explicitly
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1955 let buf = RunVimInTerminal('-S Xscript', {'term_api': 'Tapi_Try'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1956 call WaitFor({-> exists('g:called_bufnum')})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1957 call assert_equal(buf, g:called_bufnum)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1958 call assert_equal(['hello', 123], g:called_arg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1959 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1960
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1961 unlet! g:called_bufnum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1962 unlet! g:called_arg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1963
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1964 func! ApiCall_TryThis(bufnum, arg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1965 let g:called_bufnum2 = a:bufnum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1966 let g:called_arg2 = a:arg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1967 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1968
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1969 call WriteApiCall('ApiCall_TryThis')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1970
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1971 " Use prefix match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1972 let buf = RunVimInTerminal('-S Xscript', {'term_api': 'ApiCall_'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1973 call WaitFor({-> exists('g:called_bufnum2')})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1974 call assert_equal(buf, g:called_bufnum2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1975 call assert_equal(['hello', 123], g:called_arg2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1976 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1977
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1978 call assert_fails("call term_start('ls', {'term_api' : []})", 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1979
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1980 unlet! g:called_bufnum2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1981 unlet! g:called_arg2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1982
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1983 call delete('Xscript')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1984 delfunction! ApiCall_TryThis
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1985 unlet! g:called_bufnum2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1986 unlet! g:called_arg2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1987 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1988
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1989 func Test_terminal_api_call_fails()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1990 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1991
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1992 func! TryThis(bufnum, arg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1993 let g:called_bufnum3 = a:bufnum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1994 let g:called_arg3 = a:arg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1995 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1996
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1997 call WriteApiCall('TryThis')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1998
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
1999 unlet! g:called_bufnum3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2000 unlet! g:called_arg3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2001
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2002 " Not permitted
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2003 call ch_logfile('Xlog', 'w')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2004 let buf = RunVimInTerminal('-S Xscript', {'term_api': ''})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2005 call WaitForAssert({-> assert_match('Unpermitted function: TryThis', string(readfile('Xlog')))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2006 call assert_false(exists('g:called_bufnum3'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2007 call assert_false(exists('g:called_arg3'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2008 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2009
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2010 " No match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2011 call ch_logfile('Xlog', 'w')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2012 let buf = RunVimInTerminal('-S Xscript', {'term_api': 'TryThat'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2013 call WaitFor({-> string(readfile('Xlog')) =~ 'Unpermitted function: TryThis'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2014 call assert_false(exists('g:called_bufnum3'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2015 call assert_false(exists('g:called_arg3'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2016 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2017
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2018 call delete('Xscript')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2019 call ch_logfile('')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2020 call delete('Xlog')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2021 delfunction! TryThis
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2022 unlet! g:called_bufnum3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2023 unlet! g:called_arg3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2024 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2025
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2026 let s:caught_e937 = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2027
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2028 func Tapi_Delete(bufnum, arg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2029 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2030 execute 'bdelete!' a:bufnum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2031 catch /E937:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2032 let s:caught_e937 = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2033 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2034 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2035
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2036 func Test_terminal_api_call_fail_delete()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2037 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2038
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2039 call WriteApiCall('Tapi_Delete')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2040 let buf = RunVimInTerminal('-S Xscript', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2041 call WaitForAssert({-> assert_equal(1, s:caught_e937)})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2042
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2043 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2044 call delete('Xscript')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2045 call ch_logfile('', '')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2046 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2047
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2048 func Test_terminal_setapi_and_call()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2049 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2050
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2051 call WriteApiCall('Tapi_TryThis')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2052 call ch_logfile('Xlog', 'w')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2053
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2054 unlet! g:called_bufnum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2055 unlet! g:called_arg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2056
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2057 let buf = RunVimInTerminal('-S Xscript', {'term_api': ''})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2058 call WaitForAssert({-> assert_match('Unpermitted function: Tapi_TryThis', string(readfile('Xlog')))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2059 call assert_false(exists('g:called_bufnum'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2060 call assert_false(exists('g:called_arg'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2061
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2062 eval buf->term_setapi('Tapi_')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2063 call term_sendkeys(buf, ":set notitle\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2064 call term_sendkeys(buf, ":source Xscript\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2065 call WaitFor({-> exists('g:called_bufnum')})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2066 call assert_equal(buf, g:called_bufnum)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2067 call assert_equal(['hello', 123], g:called_arg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2068
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2069 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2070
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2071 call delete('Xscript')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2072 call ch_logfile('')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2073 call delete('Xlog')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2074 unlet! g:called_bufnum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2075 unlet! g:called_arg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2076 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2077
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2078 func Test_terminal_api_arg()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2079 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2080
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2081 call WriteApiCall('Tapi_TryThis')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2082 call ch_logfile('Xlog', 'w')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2083
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2084 unlet! g:called_bufnum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2085 unlet! g:called_arg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2086
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2087 execute 'term ++api= ' .. GetVimCommandCleanTerm() .. '-S Xscript'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2088 let buf = bufnr('%')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2089 call WaitForAssert({-> assert_match('Unpermitted function: Tapi_TryThis', string(readfile('Xlog')))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2090 call assert_false(exists('g:called_bufnum'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2091 call assert_false(exists('g:called_arg'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2092
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2093 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2094
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2095 call ch_logfile('Xlog', 'w')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2096
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2097 execute 'term ++api=Tapi_ ' .. GetVimCommandCleanTerm() .. '-S Xscript'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2098 let buf = bufnr('%')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2099 call WaitFor({-> exists('g:called_bufnum')})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2100 call assert_equal(buf, g:called_bufnum)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2101 call assert_equal(['hello', 123], g:called_arg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2102
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2103 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2104
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2105 call delete('Xscript')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2106 call ch_logfile('')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2107 call delete('Xlog')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2108 unlet! g:called_bufnum
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2109 unlet! g:called_arg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2110 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2111
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2112 func Test_terminal_ansicolors_default()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2113 CheckFunction term_getansicolors
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2114
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2115 let colors = [
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2116 \ '#000000', '#e00000',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2117 \ '#00e000', '#e0e000',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2118 \ '#0000e0', '#e000e0',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2119 \ '#00e0e0', '#e0e0e0',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2120 \ '#808080', '#ff4040',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2121 \ '#40ff40', '#ffff40',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2122 \ '#4040ff', '#ff40ff',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2123 \ '#40ffff', '#ffffff',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2124 \]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2125
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2126 let buf = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2127 call assert_equal(colors, term_getansicolors(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2128 call StopShellInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2129 call assert_equal([], term_getansicolors(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2130
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2131 exe buf . 'bwipe'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2132 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2133
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2134 let s:test_colors = [
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2135 \ '#616e64', '#0d0a79',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2136 \ '#6d610d', '#0a7373',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2137 \ '#690d0a', '#6d696e',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2138 \ '#0d0a6f', '#616e0d',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2139 \ '#0a6479', '#6d0d0a',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2140 \ '#617373', '#0d0a69',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2141 \ '#6d690d', '#0a6e6f',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2142 \ '#610d0a', '#6e6479',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2143 \]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2144
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2145 func Test_terminal_ansicolors_global()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2146 CheckFeature termguicolors
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2147 CheckFunction term_getansicolors
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2148
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2149 if has('vtp') && !has('vcon') && !has('gui_running')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2150 throw 'Skipped: does not support termguicolors'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2151 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2152
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2153 set tgc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2154 let g:terminal_ansi_colors = reverse(copy(s:test_colors))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2155 let buf = Run_shell_in_terminal({})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2156 call assert_equal(g:terminal_ansi_colors, term_getansicolors(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2157 call StopShellInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2158 set tgc&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2159
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2160 exe buf . 'bwipe'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2161 unlet g:terminal_ansi_colors
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2162 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2163
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2164 func Test_terminal_ansicolors_func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2165 CheckFeature termguicolors
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2166 CheckFunction term_getansicolors
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2167
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2168 if has('vtp') && !has('vcon') && !has('gui_running')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2169 throw 'Skipped: does not support termguicolors'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2170 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2171
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2172 set tgc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2173 let g:terminal_ansi_colors = reverse(copy(s:test_colors))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2174 let buf = Run_shell_in_terminal({'ansi_colors': s:test_colors})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2175 call assert_equal(s:test_colors, term_getansicolors(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2176
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2177 call term_setansicolors(buf, g:terminal_ansi_colors)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2178 call assert_equal(g:terminal_ansi_colors, buf->term_getansicolors())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2179
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2180 let colors = [
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2181 \ 'ivory', 'AliceBlue',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2182 \ 'grey67', 'dark goldenrod',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2183 \ 'SteelBlue3', 'PaleVioletRed4',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2184 \ 'MediumPurple2', 'yellow2',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2185 \ 'RosyBrown3', 'OrangeRed2',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2186 \ 'white smoke', 'navy blue',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2187 \ 'grey47', 'gray97',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2188 \ 'MistyRose2', 'DodgerBlue4',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2189 \]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2190 eval buf->term_setansicolors(colors)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2191
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2192 let colors[4] = 'Invalid'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2193 call assert_fails('call term_setansicolors(buf, colors)', 'E254:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2194 call assert_fails('call term_setansicolors(buf, {})', 'E1211:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2195 call assert_fails('call term_setansicolors(buf, [])', 'E475: Invalid value for argument "colors"')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2196 set tgc&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2197
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2198 call StopShellInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2199 call assert_equal(0, term_setansicolors(buf, []))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2200 exe buf . 'bwipe'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2201 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2202
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2203 func Test_terminal_all_ansi_colors()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2204 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2205
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2206 " Use all the ANSI colors.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2207 call writefile([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2208 \ 'call setline(1, "AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPP XXYYZZ")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2209 \ 'hi Tblack ctermfg=0 ctermbg=8',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2210 \ 'hi Tdarkred ctermfg=1 ctermbg=9',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2211 \ 'hi Tdarkgreen ctermfg=2 ctermbg=10',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2212 \ 'hi Tbrown ctermfg=3 ctermbg=11',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2213 \ 'hi Tdarkblue ctermfg=4 ctermbg=12',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2214 \ 'hi Tdarkmagenta ctermfg=5 ctermbg=13',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2215 \ 'hi Tdarkcyan ctermfg=6 ctermbg=14',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2216 \ 'hi Tlightgrey ctermfg=7 ctermbg=15',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2217 \ 'hi Tdarkgrey ctermfg=8 ctermbg=0',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2218 \ 'hi Tred ctermfg=9 ctermbg=1',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2219 \ 'hi Tgreen ctermfg=10 ctermbg=2',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2220 \ 'hi Tyellow ctermfg=11 ctermbg=3',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2221 \ 'hi Tblue ctermfg=12 ctermbg=4',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2222 \ 'hi Tmagenta ctermfg=13 ctermbg=5',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2223 \ 'hi Tcyan ctermfg=14 ctermbg=6',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2224 \ 'hi Twhite ctermfg=15 ctermbg=7',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2225 \ 'hi TdarkredBold ctermfg=1 cterm=bold',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2226 \ 'hi TgreenBold ctermfg=10 cterm=bold',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2227 \ 'hi TmagentaBold ctermfg=13 cterm=bold ctermbg=5',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2228 \ '',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2229 \ 'call matchadd("Tblack", "A")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2230 \ 'call matchadd("Tdarkred", "B")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2231 \ 'call matchadd("Tdarkgreen", "C")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2232 \ 'call matchadd("Tbrown", "D")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2233 \ 'call matchadd("Tdarkblue", "E")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2234 \ 'call matchadd("Tdarkmagenta", "F")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2235 \ 'call matchadd("Tdarkcyan", "G")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2236 \ 'call matchadd("Tlightgrey", "H")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2237 \ 'call matchadd("Tdarkgrey", "I")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2238 \ 'call matchadd("Tred", "J")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2239 \ 'call matchadd("Tgreen", "K")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2240 \ 'call matchadd("Tyellow", "L")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2241 \ 'call matchadd("Tblue", "M")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2242 \ 'call matchadd("Tmagenta", "N")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2243 \ 'call matchadd("Tcyan", "O")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2244 \ 'call matchadd("Twhite", "P")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2245 \ 'call matchadd("TdarkredBold", "X")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2246 \ 'call matchadd("TgreenBold", "Y")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2247 \ 'call matchadd("TmagentaBold", "Z")',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2248 \ 'redraw',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2249 \ ], 'Xcolorscript', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2250 let buf = RunVimInTerminal('-S Xcolorscript', {'rows': 10})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2251 call VerifyScreenDump(buf, 'Test_terminal_all_ansi_colors', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2252
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2253 call term_sendkeys(buf, ":q\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2254 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2255 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2256
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2257 function On_BufFilePost()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2258 doautocmd <nomodeline> User UserEvent
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2259 endfunction
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2260
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2261 func Test_terminal_nested_autocmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2262 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2263 call setline(1, range(500))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2264 $
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2265 let lastline = line('.')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2266
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2267 augroup TermTest
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2268 autocmd BufFilePost * call On_BufFilePost()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2269 autocmd User UserEvent silent
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2270 augroup END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2271
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2272 let cmd = Get_cat_123_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2273 let buf = term_start(cmd, #{term_finish: 'close', hidden: 1})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2274 call assert_equal(lastline, line('.'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2275
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2276 let job = term_getjob(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2277 call WaitForAssert({-> assert_equal("dead", job_status(job))})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2278 call delete('Xtext')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2279 augroup TermTest
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2280 au!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2281 augroup END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2282 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2283
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2284 func Test_terminal_adds_jump()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2285 clearjumps
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2286 call term_start("ls", #{curwin: 1})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2287 call assert_equal(1, getjumplist()[0]->len())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2288 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2289 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2290
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2291 func Close_cb(ch, ctx)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2292 call term_wait(a:ctx.bufnr)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2293 let g:close_done = 'done'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2294 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2295
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2296 func Test_term_wait_in_close_cb()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2297 let g:close_done = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2298 let ctx = {}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2299 let ctx.bufnr = term_start('echo "HELLO WORLD"',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2300 \ {'close_cb': {ch -> Close_cb(ch, ctx)}})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2301
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2302 call WaitForAssert({-> assert_equal("done", g:close_done)})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2303
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2304 unlet g:close_done
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2305 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2306 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2307
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2308 func Test_term_TextChangedT()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2309 augroup TermTest
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2310 autocmd TextChangedT * ++once
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2311 \ execute expand('<abuf>') . 'buffer' |
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2312 \ let b:called = 1 |
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2313 \ split |
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2314 \ enew
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2315 augroup END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2316
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2317 terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2318
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2319 let term_buf = bufnr()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2320
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2321 let b:called = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2322
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2323 call term_sendkeys(term_buf, "aaabbc\r")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2324 call TermWait(term_buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2325
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2326 call assert_equal(1, getbufvar(term_buf, 'called'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2327
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2328 " Current buffer will be restored
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2329 call assert_equal(bufnr(), term_buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2330
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2331 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2332 augroup TermTest
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2333 au!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2334 augroup END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2335 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2336
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2337 func Test_term_TextChangedT_close()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2338 augroup TermTest
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2339 autocmd TextChangedT * ++once split | enew | 1close!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2340 augroup END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2341
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2342 terminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2343
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2344 let term_buf = bufnr()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2345
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2346 call term_sendkeys(term_buf, "aaabbc\r")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2347 call TermWait(term_buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2348
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2349 " Current buffer will be restored
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2350 call assert_equal(bufnr(), term_buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2351
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2352 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2353 augroup TermTest
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2354 au!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2355 augroup END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2356 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2357
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32391
diff changeset
2358 " vim: shiftwidth=2 sts=2 expandtab