blob: 2e137f0e61679f1113b29a6d3c3bec869a3922c2 [file] [log] [blame]
Bram Moolenaar94f82cb2019-07-24 22:30:27 +02001" Tests for various Ex commands.
2
Bram Moolenaare20b9ec2020-02-03 21:40:04 +01003source check.vim
4
Bram Moolenaar94f82cb2019-07-24 22:30:27 +02005func Test_ex_delete()
6 new
7 call setline(1, ['a', 'b', 'c'])
8 2
9 " :dl is :delete with the "l" flag, not :dlist
10 .dl
11 call assert_equal(['a', 'c'], getline(1, 2))
12endfunc
Bram Moolenaar0acae7a2019-08-06 21:29:29 +020013
14func Test_range_error()
15 call assert_fails(':.echo 1', 'E481:')
16 call assert_fails(':$echo 1', 'E481:')
17 call assert_fails(':1,2echo 1', 'E481:')
18 call assert_fails(':+1echo 1', 'E481:')
19 call assert_fails(':/1/echo 1', 'E481:')
20 call assert_fails(':\/echo 1', 'E481:')
21 normal vv
22 call assert_fails(":'<,'>echo 1", 'E481:')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +010023 call assert_fails(":\\xcenter", 'E10:')
Bram Moolenaar0acae7a2019-08-06 21:29:29 +020024endfunc
Bram Moolenaar52410572019-10-27 05:12:45 +010025
26func Test_buffers_lastused()
27 call test_settime(localtime() - 2000) " middle
28 edit bufa
29 enew
30 call test_settime(localtime() - 10) " newest
31 edit bufb
32 enew
33 call test_settime(1550010000) " oldest
34 edit bufc
35 enew
36 call test_settime(0)
37 enew
38
39 let ls = split(execute('buffers t', 'silent!'), '\n')
40 let bufs = ls->map({i,v->split(v, '"\s*')[1:2]})
41 call assert_equal(['bufb', 'bufa', 'bufc'], bufs[1:]->map({i,v->v[0]}))
42 call assert_match('1[0-3] seconds ago', bufs[1][1])
43 call assert_match('\d\d:\d\d:\d\d', bufs[2][1])
44 call assert_match('2019/02/1\d \d\d:\d\d:00', bufs[3][1])
45
46 bwipeout bufa
47 bwipeout bufb
48 bwipeout bufc
49endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +010050
51" Test for the :copy command
52func Test_copy()
53 new
54
55 call setline(1, ['L1', 'L2', 'L3', 'L4'])
56 " copy lines in a range to inside the range
57 1,3copy 2
58 call assert_equal(['L1', 'L2', 'L1', 'L2', 'L3', 'L3', 'L4'], getline(1, 7))
59
Bram Moolenaar1671f442020-03-10 07:48:13 +010060 " Specifying a count before using : to run an ex-command
61 exe "normal! gg4:yank\<CR>"
62 call assert_equal("L1\nL2\nL1\nL2\n", @")
63
Bram Moolenaar5d98dc22020-01-29 21:57:34 +010064 close!
65endfunc
66
67" Test for the :file command
68func Test_file_cmd()
69 call assert_fails('3file', 'E474:')
70 call assert_fails('0,0file', 'E474:')
71 call assert_fails('0file abc', 'E474:')
72endfunc
73
74" Test for the :drop command
75func Test_drop_cmd()
76 call writefile(['L1', 'L2'], 'Xfile')
77 enew | only
78 drop Xfile
79 call assert_equal('L2', getline(2))
80 " Test for switching to an existing window
81 below new
82 drop Xfile
83 call assert_equal(1, winnr())
84 " Test for splitting the current window
85 enew | only
86 set modified
87 drop Xfile
88 call assert_equal(2, winnr('$'))
89 " Check for setting the argument list
90 call assert_equal(['Xfile'], argv())
91 enew | only!
92 call delete('Xfile')
93endfunc
94
95" Test for the :append command
96func Test_append_cmd()
97 new
98 call setline(1, [' L1'])
99 call feedkeys(":append\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt')
100 call assert_equal([' L1', ' L2', ' L3'], getline(1, '$'))
101 %delete _
102 " append after a specific line
103 call setline(1, [' L1', ' L2', ' L3'])
104 call feedkeys(":2append\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt')
105 call assert_equal([' L1', ' L2', ' L4', ' L5', ' L3'], getline(1, '$'))
106 %delete _
107 " append with toggling 'autoindent'
108 call setline(1, [' L1'])
109 call feedkeys(":append!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt')
110 call assert_equal([' L1', ' L2', ' L3'], getline(1, '$'))
111 call assert_false(&autoindent)
112 %delete _
113 " append with 'autoindent' set and toggling 'autoindent'
114 set autoindent
115 call setline(1, [' L1'])
116 call feedkeys(":append!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt')
117 call assert_equal([' L1', ' L2', ' L3'], getline(1, '$'))
118 call assert_true(&autoindent)
119 set autoindent&
120 close!
121endfunc
122
123" Test for the :insert command
124func Test_insert_cmd()
125 new
126 call setline(1, [' L1'])
127 call feedkeys(":insert\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt')
128 call assert_equal([' L2', ' L3', ' L1'], getline(1, '$'))
129 %delete _
130 " insert before a specific line
131 call setline(1, [' L1', ' L2', ' L3'])
132 call feedkeys(":2insert\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt')
133 call assert_equal([' L1', ' L4', ' L5', ' L2', ' L3'], getline(1, '$'))
134 %delete _
135 " insert with toggling 'autoindent'
136 call setline(1, [' L1'])
137 call feedkeys(":insert!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt')
138 call assert_equal([' L2', ' L3', ' L1'], getline(1, '$'))
139 call assert_false(&autoindent)
140 %delete _
141 " insert with 'autoindent' set and toggling 'autoindent'
142 set autoindent
143 call setline(1, [' L1'])
144 call feedkeys(":insert!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt')
145 call assert_equal([' L2', ' L3', ' L1'], getline(1, '$'))
146 call assert_true(&autoindent)
147 set autoindent&
148 close!
149endfunc
150
151" Test for the :change command
152func Test_change_cmd()
153 new
154 call setline(1, [' L1', 'L2', 'L3'])
155 call feedkeys(":change\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt')
156 call assert_equal([' L4', ' L5', 'L2', 'L3'], getline(1, '$'))
157 %delete _
158 " change a specific line
159 call setline(1, [' L1', ' L2', ' L3'])
160 call feedkeys(":2change\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt')
161 call assert_equal([' L1', ' L4', ' L5', ' L3'], getline(1, '$'))
162 %delete _
163 " change with toggling 'autoindent'
164 call setline(1, [' L1', 'L2', 'L3'])
165 call feedkeys(":change!\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt')
166 call assert_equal([' L4', ' L5', 'L2', 'L3'], getline(1, '$'))
167 call assert_false(&autoindent)
168 %delete _
169 " change with 'autoindent' set and toggling 'autoindent'
170 set autoindent
171 call setline(1, [' L1', 'L2', 'L3'])
172 call feedkeys(":change!\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt')
173 call assert_equal([' L4', ' L5', 'L2', 'L3'], getline(1, '$'))
174 call assert_true(&autoindent)
175 set autoindent&
176 close!
177endfunc
178
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100179" Test for the :language command
180func Test_language_cmd()
181 CheckFeature multi_lang
182
183 call assert_fails('language ctype non_existing_lang', 'E197:')
184 call assert_fails('language time non_existing_lang', 'E197:')
185endfunc
186
187" Test for the :confirm command dialog
188func Test_confirm_cmd()
189 CheckNotGui
190 CheckRunVimInTerminal
191
Bram Moolenaar27321db2020-07-06 21:24:57 +0200192 call writefile(['foo1'], 'Xfoo')
193 call writefile(['bar1'], 'Xbar')
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100194
195 " Test for saving all the modified buffers
Bram Moolenaar27321db2020-07-06 21:24:57 +0200196 let lines =<< trim END
197 set nomore
198 new Xfoo
199 call setline(1, 'foo2')
200 new Xbar
201 call setline(1, 'bar2')
202 wincmd b
203 END
204 call writefile(lines, 'Xscript')
205 let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100206 call term_sendkeys(buf, ":confirm qall\n")
207 call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000)
208 call term_sendkeys(buf, "A")
209 call StopVimInTerminal(buf)
210
Bram Moolenaar27321db2020-07-06 21:24:57 +0200211 call assert_equal(['foo2'], readfile('Xfoo'))
212 call assert_equal(['bar2'], readfile('Xbar'))
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100213
214 " Test for discarding all the changes to modified buffers
Bram Moolenaar27321db2020-07-06 21:24:57 +0200215 let lines =<< trim END
216 set nomore
217 new Xfoo
218 call setline(1, 'foo3')
219 new Xbar
220 call setline(1, 'bar3')
221 wincmd b
222 END
223 call writefile(lines, 'Xscript')
224 let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100225 call term_sendkeys(buf, ":confirm qall\n")
226 call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000)
227 call term_sendkeys(buf, "D")
228 call StopVimInTerminal(buf)
229
Bram Moolenaar27321db2020-07-06 21:24:57 +0200230 call assert_equal(['foo2'], readfile('Xfoo'))
231 call assert_equal(['bar2'], readfile('Xbar'))
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100232
233 " Test for saving and discarding changes to some buffers
Bram Moolenaar27321db2020-07-06 21:24:57 +0200234 let lines =<< trim END
235 set nomore
236 new Xfoo
237 call setline(1, 'foo4')
238 new Xbar
239 call setline(1, 'bar4')
240 wincmd b
241 END
242 call writefile(lines, 'Xscript')
243 let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100244 call term_sendkeys(buf, ":confirm qall\n")
245 call WaitForAssert({-> assert_match('\[Y\]es, (N)o, Save (A)ll, (D)iscard All, (C)ancel: ', term_getline(buf, 20))}, 1000)
246 call term_sendkeys(buf, "N")
247 call WaitForAssert({-> assert_match('\[Y\]es, (N)o, (C)ancel: ', term_getline(buf, 20))}, 1000)
248 call term_sendkeys(buf, "Y")
249 call StopVimInTerminal(buf)
250
Bram Moolenaar27321db2020-07-06 21:24:57 +0200251 call assert_equal(['foo4'], readfile('Xfoo'))
252 call assert_equal(['bar2'], readfile('Xbar'))
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100253
Bram Moolenaar27321db2020-07-06 21:24:57 +0200254 call delete('Xscript')
255 call delete('Xfoo')
256 call delete('Xbar')
Bram Moolenaar72749f02020-03-26 20:51:43 +0100257endfunc
258
259func Test_confirm_cmd_cancel()
Bram Moolenaarbea90232020-03-26 22:09:52 +0100260 CheckNotGui
261 CheckRunVimInTerminal
262
Bram Moolenaar406cd902020-02-18 21:54:41 +0100263 " Test for closing a window with a modified buffer
Bram Moolenaar27321db2020-07-06 21:24:57 +0200264 let lines =<< trim END
265 set nomore
266 new
267 call setline(1, 'abc')
268 END
269 call writefile(lines, 'Xscript')
270 let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
Bram Moolenaar406cd902020-02-18 21:54:41 +0100271 call term_sendkeys(buf, ":confirm close\n")
272 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$',
273 \ term_getline(buf, 20))}, 1000)
274 call term_sendkeys(buf, "C")
Bram Moolenaar7b1b36b2020-03-28 21:48:55 +0100275 call WaitForAssert({-> assert_equal('', term_getline(buf, 20))}, 1000)
Bram Moolenaar406cd902020-02-18 21:54:41 +0100276 call term_sendkeys(buf, ":confirm close\n")
277 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$',
278 \ term_getline(buf, 20))}, 1000)
279 call term_sendkeys(buf, "N")
Bram Moolenaar9207d1f2020-03-27 19:41:02 +0100280 call WaitForAssert({-> assert_match('^ *0,0-1 All$',
281 \ term_getline(buf, 20))}, 1000)
Bram Moolenaar406cd902020-02-18 21:54:41 +0100282 call StopVimInTerminal(buf)
Bram Moolenaar27321db2020-07-06 21:24:57 +0200283 call delete('Xscript')
284endfunc
285
286" The ":confirm" prompt was sometimes used with the terminal in cooked mode.
287" This test verifies that a "\<CR>" character is NOT required to respond to a
288" prompt from the ":conf q" and ":conf wq" commands.
289func Test_confirm_q_wq()
290 CheckNotGui
291 CheckRunVimInTerminal
292
293 call writefile(['foo'], 'Xfoo')
294
295 let lines =<< trim END
296 set hidden nomore
297 call setline(1, 'abc')
298 edit Xfoo
299 END
300 call writefile(lines, 'Xscript')
301 let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
302 call term_sendkeys(buf, ":confirm q\n")
303 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$',
304 \ term_getline(buf, 20))}, 1000)
305 call term_sendkeys(buf, 'C')
306 call WaitForAssert({-> assert_notmatch('^\[Y\]es, (N)o, (C)ancel: C*$',
307 \ term_getline(buf, 20))}, 1000)
308
309 call term_sendkeys(buf, ":edit Xfoo\n")
310 call term_sendkeys(buf, ":confirm wq\n")
311 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o, (C)ancel: *$',
312 \ term_getline(buf, 20))}, 1000)
313 call term_sendkeys(buf, 'C')
314 call WaitForAssert({-> assert_notmatch('^\[Y\]es, (N)o, (C)ancel: C*$',
315 \ term_getline(buf, 20))}, 1000)
316 call StopVimInTerminal(buf)
317
318 call delete('Xscript')
319 call delete('Xfoo')
Bram Moolenaare20b9ec2020-02-03 21:40:04 +0100320endfunc
321
Dominique Pelle2bf60342021-05-02 20:16:24 +0200322func Test_confirm_write_ro()
323 CheckNotGui
324 CheckRunVimInTerminal
325
326 call writefile(['foo'], 'Xconfirm_write_ro')
327 let lines =<< trim END
328 set nobackup ff=unix cmdheight=2
329 edit Xconfirm_write_ro
330 norm Abar
331 END
332 call writefile(lines, 'Xscript')
333 let buf = RunVimInTerminal('-S Xscript', {'rows': 20})
334
335 " Try to write with 'ro' option.
336 call term_sendkeys(buf, ":set ro | confirm w\n")
337 call WaitForAssert({-> assert_match("^'readonly' option is set for \"Xconfirm_write_ro\"\. *$",
338 \ term_getline(buf, 18))}, 1000)
339 call WaitForAssert({-> assert_match('^Do you wish to write anyway? *$',
340 \ term_getline(buf, 19))}, 1000)
341 call WaitForAssert({-> assert_match('^(Y)es, \[N\]o: *$', term_getline(buf, 20))}, 1000)
342 call term_sendkeys(buf, 'N')
343 call WaitForAssert({-> assert_match('^ *$', term_getline(buf, 19))}, 1000)
344 call WaitForAssert({-> assert_match('.* All$', term_getline(buf, 20))}, 1000)
345 call assert_equal(['foo'], readfile('Xconfirm_write_ro'))
346
347 call term_sendkeys(buf, ":confirm w\n")
348 call WaitForAssert({-> assert_match("^'readonly' option is set for \"Xconfirm_write_ro\"\. *$",
349 \ term_getline(buf, 18))}, 1000)
350 call WaitForAssert({-> assert_match('^Do you wish to write anyway? *$',
351 \ term_getline(buf, 19))}, 1000)
352 call WaitForAssert({-> assert_match('^(Y)es, \[N\]o: *$', term_getline(buf, 20))}, 1000)
353 call term_sendkeys(buf, 'Y')
354 call WaitForAssert({-> assert_match('^"Xconfirm_write_ro" 1L, 7B written$',
355 \ term_getline(buf, 19))}, 1000)
356 call assert_equal(['foobar'], readfile('Xconfirm_write_ro'))
357
358 " Try to write with read-only file permissions.
359 call setfperm('Xconfirm_write_ro', 'r--r--r--')
360 call term_sendkeys(buf, ":set noro | undo | confirm w\n")
361 call WaitForAssert({-> assert_match("^File permissions of \"Xconfirm_write_ro\" are read-only\. *$",
362 \ term_getline(buf, 17))}, 1000)
363 call WaitForAssert({-> assert_match('^It may still be possible to write it\. *$',
364 \ term_getline(buf, 18))}, 1000)
365 call WaitForAssert({-> assert_match('^Do you wish to try? *$', term_getline(buf, 19))}, 1000)
366 call WaitForAssert({-> assert_match('^(Y)es, \[N\]o: *$', term_getline(buf, 20))}, 1000)
367 call term_sendkeys(buf, 'Y')
368 call WaitForAssert({-> assert_match('^"Xconfirm_write_ro" 1L, 4B written$',
369 \ term_getline(buf, 19))}, 1000)
370 call assert_equal(['foo'], readfile('Xconfirm_write_ro'))
371
372 call StopVimInTerminal(buf)
373 call delete('Xscript')
374 call delete('Xconfirm_write_ro')
375endfunc
376
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100377" Test for the :print command
378func Test_print_cmd()
379 call assert_fails('print', 'E749:')
380endfunc
381
382" Test for the :winsize command
383func Test_winsize_cmd()
384 call assert_fails('winsize 1', 'E465:')
Bram Moolenaarf5a51162021-02-06 12:58:18 +0100385 call assert_fails('winsize 1 x', 'E465:')
386 call assert_fails('win_getid(1)', 'E475: Invalid argument: _getid(1)')
387 " Actually changing the window size would be flaky.
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100388endfunc
389
390" Test for the :redir command
Bram Moolenaarf9a65502021-03-05 20:47:44 +0100391" NOTE: if you run tests as root this will fail. Don't run tests as root!
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100392func Test_redir_cmd()
393 call assert_fails('redir @@', 'E475:')
394 call assert_fails('redir abc', 'E475:')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +0100395 call assert_fails('redir => 1abc', 'E474:')
396 call assert_fails('redir => a b', 'E488:')
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +0200397 call assert_fails('redir => abc[1]', 'E121:')
398 let b = 0zFF
Bram Moolenaar8dfcce32020-03-18 19:32:26 +0100399 call assert_fails('redir =>> b', 'E734:')
400 unlet b
401
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100402 if has('unix')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +0100403 " Redirecting to a directory name
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100404 call mkdir('Xdir')
405 call assert_fails('redir > Xdir', 'E17:')
406 call delete('Xdir', 'd')
407 endif
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +0100408
409 " Test for redirecting to a register
410 redir @q> | echon 'clean ' | redir END
411 redir @q>> | echon 'water' | redir END
412 call assert_equal('clean water', @q)
413
414 " Test for redirecting to a variable
415 redir => color | echon 'blue ' | redir END
416 redir =>> color | echon 'sky' | redir END
417 call assert_equal('blue sky', color)
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100418endfunc
419
Bram Moolenaar17709e22021-03-19 14:38:12 +0100420func Test_redir_cmd_readonly()
421 CheckNotRoot
Bram Moolenaar17709e22021-03-19 14:38:12 +0100422
423 " Redirecting to a read-only file
424 call writefile([], 'Xfile')
425 call setfperm('Xfile', 'r--r--r--')
426 call assert_fails('redir! > Xfile', 'E190:')
427 call delete('Xfile')
428endfunc
429
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100430" Test for the :filetype command
431func Test_filetype_cmd()
432 call assert_fails('filetype abc', 'E475:')
433endfunc
434
435" Test for the :mode command
436func Test_mode_cmd()
437 call assert_fails('mode abc', 'E359:')
438endfunc
439
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +0100440" Test for the :sleep command
441func Test_sleep_cmd()
442 call assert_fails('sleep x', 'E475:')
443endfunc
444
445" Test for the :read command
446func Test_read_cmd()
447 call writefile(['one'], 'Xfile')
448 new
449 call assert_fails('read', 'E32:')
450 edit Xfile
451 read
452 call assert_equal(['one', 'one'], getline(1, '$'))
453 close!
454 new
455 read Xfile
456 call assert_equal(['', 'one'], getline(1, '$'))
457 call deletebufline('', 1, '$')
458 call feedkeys("Qr Xfile\<CR>visual\<CR>", 'xt')
459 call assert_equal(['one'], getline(1, '$'))
460 close!
461 call delete('Xfile')
462endfunc
463
464" Test for running Ex commands when text is locked.
465" <C-\>e in the command line is used to lock the text
466func Test_run_excmd_with_text_locked()
467 " :quit
468 let cmd = ":\<C-\>eexecute('quit')\<CR>\<C-C>"
Bram Moolenaarff06f282020-04-21 22:01:14 +0200469 call assert_fails("call feedkeys(cmd, 'xt')", 'E565:')
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +0100470
471 " :qall
472 let cmd = ":\<C-\>eexecute('qall')\<CR>\<C-C>"
Bram Moolenaarff06f282020-04-21 22:01:14 +0200473 call assert_fails("call feedkeys(cmd, 'xt')", 'E565:')
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +0100474
475 " :exit
476 let cmd = ":\<C-\>eexecute('exit')\<CR>\<C-C>"
Bram Moolenaarff06f282020-04-21 22:01:14 +0200477 call assert_fails("call feedkeys(cmd, 'xt')", 'E565:')
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +0100478
479 " :close - should be ignored
480 new
481 let cmd = ":\<C-\>eexecute('close')\<CR>\<C-C>"
482 call assert_equal(2, winnr('$'))
483 close
Bram Moolenaar818fc9a2020-02-21 17:54:45 +0100484
Bram Moolenaarff06f282020-04-21 22:01:14 +0200485 call assert_fails("call feedkeys(\":\<C-R>=execute('bnext')\<CR>\", 'xt')", 'E565:')
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +0200486
487 " :tabfirst
488 tabnew
489 call assert_fails("call feedkeys(\":\<C-R>=execute('tabfirst')\<CR>\", 'xt')", 'E565:')
490 tabclose
Bram Moolenaar818fc9a2020-02-21 17:54:45 +0100491endfunc
492
493" Test for the :verbose command
494func Test_verbose_cmd()
495 call assert_equal([' verbose=1'], split(execute('verbose set vbs'), "\n"))
496 call assert_equal([' verbose=0'], split(execute('0verbose set vbs'), "\n"))
497 let l = execute("4verbose set verbose | set verbose")
498 call assert_equal([' verbose=4', ' verbose=0'], split(l, "\n"))
499endfunc
500
501" Test for the :delete command and the related abbreviated commands
502func Test_excmd_delete()
503 new
504 call setline(1, ['foo', "\tbar"])
505 call assert_equal(['^Ibar$'], split(execute('dl'), "\n"))
506 call setline(1, ['foo', "\tbar"])
507 call assert_equal(['^Ibar$'], split(execute('dell'), "\n"))
508 call setline(1, ['foo', "\tbar"])
509 call assert_equal(['^Ibar$'], split(execute('delel'), "\n"))
510 call setline(1, ['foo', "\tbar"])
511 call assert_equal(['^Ibar$'], split(execute('deletl'), "\n"))
512 call setline(1, ['foo', "\tbar"])
513 call assert_equal(['^Ibar$'], split(execute('deletel'), "\n"))
514 call setline(1, ['foo', "\tbar"])
515 call assert_equal([' bar'], split(execute('dp'), "\n"))
516 call setline(1, ['foo', "\tbar"])
517 call assert_equal([' bar'], split(execute('dep'), "\n"))
518 call setline(1, ['foo', "\tbar"])
519 call assert_equal([' bar'], split(execute('delp'), "\n"))
520 call setline(1, ['foo', "\tbar"])
521 call assert_equal([' bar'], split(execute('delep'), "\n"))
522 call setline(1, ['foo', "\tbar"])
523 call assert_equal([' bar'], split(execute('deletp'), "\n"))
524 call setline(1, ['foo', "\tbar"])
525 call assert_equal([' bar'], split(execute('deletep'), "\n"))
526 close!
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +0100527endfunc
528
Bram Moolenaarca68ae12020-03-30 19:32:53 +0200529" Test for commands that are blocked in a sandbox
530func Sandbox_tests()
531 call assert_fails("call histadd(':', 'ls')", 'E48:')
532 call assert_fails("call mkdir('Xdir')", 'E48:')
533 call assert_fails("call rename('a', 'b')", 'E48:')
534 call assert_fails("call setbufvar(1, 'myvar', 1)", 'E48:')
535 call assert_fails("call settabvar(1, 'myvar', 1)", 'E48:')
536 call assert_fails("call settabwinvar(1, 1, 'myvar', 1)", 'E48:')
537 call assert_fails("call setwinvar(1, 'myvar', 1)", 'E48:')
538 call assert_fails("call timer_start(100, '')", 'E48:')
539 if has('channel')
540 call assert_fails("call prompt_setcallback(1, '')", 'E48:')
541 call assert_fails("call prompt_setinterrupt(1, '')", 'E48:')
542 call assert_fails("call prompt_setprompt(1, '')", 'E48:')
543 endif
544 call assert_fails("let $TESTVAR=1", 'E48:')
545 call assert_fails("call feedkeys('ivim')", 'E48:')
546 call assert_fails("source! Xfile", 'E48:')
547 call assert_fails("call delete('Xfile')", 'E48:')
548 call assert_fails("call writefile([], 'Xfile')", 'E48:')
549 call assert_fails('!ls', 'E48:')
550 call assert_fails('shell', 'E48:')
551 call assert_fails('stop', 'E48:')
552 call assert_fails('exe "normal \<C-Z>"', 'E48:')
553 set insertmode
554 call assert_fails('call feedkeys("\<C-Z>", "xt")', 'E48:')
555 set insertmode&
556 call assert_fails('suspend', 'E48:')
557 call assert_fails('call system("ls")', 'E48:')
558 call assert_fails('call systemlist("ls")', 'E48:')
559 if has('clientserver')
560 call assert_fails('let s=remote_expr("gvim", "2+2")', 'E48:')
561 if !has('win32')
562 " remote_foreground() doesn't thrown an error message on MS-Windows
563 call assert_fails('call remote_foreground("gvim")', 'E48:')
564 endif
565 call assert_fails('let s=remote_peek("gvim")', 'E48:')
566 call assert_fails('let s=remote_read("gvim")', 'E48:')
567 call assert_fails('let s=remote_send("gvim", "abc")', 'E48:')
568 call assert_fails('let s=server2client("gvim", "abc")', 'E48:')
569 endif
570 if has('terminal')
571 call assert_fails('terminal', 'E48:')
572 call assert_fails('call term_start("vim")', 'E48:')
573 call assert_fails('call term_dumpwrite(1, "Xfile")', 'E48:')
574 endif
575 if has('channel')
576 call assert_fails("call ch_logfile('chlog')", 'E48:')
577 call assert_fails("call ch_open('localhost:8765')", 'E48:')
578 endif
579 if has('job')
580 call assert_fails("call job_start('vim')", 'E48:')
581 endif
582 if has('unix') && has('libcall')
583 call assert_fails("echo libcall('libc.so', 'getenv', 'HOME')", 'E48:')
584 endif
585 if has('unix')
586 call assert_fails('cd `pwd`', 'E48:')
587 endif
588endfunc
589
590func Test_sandbox()
591 sandbox call Sandbox_tests()
592endfunc
593
Dominique Pelle6d37e8e2021-05-06 17:36:55 +0200594func Test_command_not_implemented_E319()
595 if !has('mzscheme')
596 call assert_fails('mzscheme', 'E319:')
597 endif
598endfunc
599
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100600" vim: shiftwidth=2 sts=2 expandtab