blob: 7474d335afb2d0ecd776c6be12662741712d1e2f [file] [log] [blame]
Bram Moolenaar72defda2016-01-17 18:04:33 +01001" Test argument list commands
2
Bram Moolenaar494e9062020-05-31 21:28:02 +02003source check.vim
Bram Moolenaar9f6277b2020-02-11 22:04:02 +01004source shared.vim
5source term_util.vim
6
Bram Moolenaar72defda2016-01-17 18:04:33 +01007func Test_argidx()
8 args a b c
9 last
10 call assert_equal(2, argidx())
11 %argdelete
12 call assert_equal(0, argidx())
Bram Moolenaar69a92fb2017-03-09 15:58:30 +010013 " doing it again doesn't result in an error
14 %argdelete
15 call assert_equal(0, argidx())
16 call assert_fails('2argdelete', 'E16:')
Bram Moolenaar72defda2016-01-17 18:04:33 +010017
18 args a b c
19 call assert_equal(0, argidx())
20 next
21 call assert_equal(1, argidx())
22 next
23 call assert_equal(2, argidx())
24 1argdelete
25 call assert_equal(1, argidx())
26 1argdelete
27 call assert_equal(0, argidx())
28 1argdelete
29 call assert_equal(0, argidx())
30endfunc
Bram Moolenaara24f0a52016-01-17 19:39:00 +010031
32func Test_argadd()
33 %argdelete
34 argadd a b c
35 call assert_equal(0, argidx())
36
37 %argdelete
38 argadd a
39 call assert_equal(0, argidx())
40 argadd b c d
41 call assert_equal(0, argidx())
42
43 call Init_abc()
44 argadd x
45 call Assert_argc(['a', 'b', 'x', 'c'])
46 call assert_equal(1, argidx())
47
48 call Init_abc()
49 0argadd x
50 call Assert_argc(['x', 'a', 'b', 'c'])
51 call assert_equal(2, argidx())
52
53 call Init_abc()
54 1argadd x
55 call Assert_argc(['a', 'x', 'b', 'c'])
56 call assert_equal(2, argidx())
57
58 call Init_abc()
59 $argadd x
60 call Assert_argc(['a', 'b', 'c', 'x'])
61 call assert_equal(1, argidx())
62
63 call Init_abc()
64 $argadd x
65 +2argadd y
66 call Assert_argc(['a', 'b', 'c', 'x', 'y'])
67 call assert_equal(1, argidx())
Bram Moolenaar2faa29f2016-01-23 23:02:34 +010068
69 %argd
70 edit d
71 arga
Bram Moolenaar398ee732017-08-03 14:29:14 +020072 call assert_equal(1, len(argv()))
73 call assert_equal('d', get(argv(), 0, ''))
74
75 %argd
76 edit some\ file
77 arga
78 call assert_equal(1, len(argv()))
79 call assert_equal('some file', get(argv(), 0, ''))
Bram Moolenaar2faa29f2016-01-23 23:02:34 +010080
81 %argd
82 new
83 arga
Bram Moolenaar398ee732017-08-03 14:29:14 +020084 call assert_equal(0, len(argv()))
Dominique Pellebfb2bb12021-08-14 21:11:51 +020085
86 if has('unix')
87 call assert_fails('argadd `Xdoes_not_exist`', 'E479:')
88 endif
Bram Moolenaara24f0a52016-01-17 19:39:00 +010089endfunc
90
Bram Moolenaar32bbd002018-08-31 23:06:22 +020091func Test_argadd_empty_curbuf()
92 new
93 let curbuf = bufnr('%')
94 call writefile(['test', 'Xargadd'], 'Xargadd')
95 " must not re-use the current buffer.
96 argadd Xargadd
97 call assert_equal(curbuf, bufnr('%'))
98 call assert_equal('', bufname('%'))
Bram Moolenaar02b31112019-08-31 22:16:38 +020099 call assert_equal(1, '$'->line())
Bram Moolenaar32bbd002018-08-31 23:06:22 +0200100 rew
Bram Moolenaar073e4b92019-08-18 23:01:56 +0200101 call assert_notequal(curbuf, '%'->bufnr())
102 call assert_equal('Xargadd', '%'->bufname())
Bram Moolenaar32bbd002018-08-31 23:06:22 +0200103 call assert_equal(2, line('$'))
104
Bram Moolenaard3398282018-09-24 21:32:11 +0200105 call delete('Xargadd')
Bram Moolenaar32bbd002018-08-31 23:06:22 +0200106 %argd
107 bwipe!
108endfunc
109
Bram Moolenaara24f0a52016-01-17 19:39:00 +0100110func Init_abc()
111 args a b c
112 next
113endfunc
114
115func Assert_argc(l)
116 call assert_equal(len(a:l), argc())
117 let i = 0
118 while i < len(a:l) && i < argc()
119 call assert_equal(a:l[i], argv(i))
120 let i += 1
121 endwhile
122endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100123
124" Test for [count]argument and [count]argdelete commands
125" Ported from the test_argument_count.in test script
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100126func Test_argument()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100127 " Clean the argument list
128 arga a | %argd
129
130 let save_hidden = &hidden
131 set hidden
132
133 let g:buffers = []
134 augroup TEST
135 au BufEnter * call add(buffers, expand('%:t'))
136 augroup END
137
138 argadd a b c d
139 $argu
140 $-argu
141 -argu
142 1argu
143 +2argu
144
145 augroup TEST
146 au!
147 augroup END
148
149 call assert_equal(['d', 'c', 'b', 'a', 'c'], g:buffers)
150
Bram Moolenaar949f1982019-07-23 23:00:08 +0200151 call assert_equal("\na b [c] d ", execute(':args'))
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100152
153 .argd
154 call assert_equal(['a', 'b', 'd'], argv())
155
156 -argd
157 call assert_equal(['a', 'd'], argv())
158
159 $argd
160 call assert_equal(['a'], argv())
161
162 1arga c
163 1arga b
164 $argu
165 $arga x
166 call assert_equal(['a', 'b', 'c', 'x'], argv())
167
Bram Moolenaar30141702016-01-19 14:14:08 +0100168 0arga y
169 call assert_equal(['y', 'a', 'b', 'c', 'x'], argv())
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100170
171 %argd
172 call assert_equal([], argv())
173
174 arga a b c d e f
175 2,$-argd
176 call assert_equal(['a', 'f'], argv())
177
178 let &hidden = save_hidden
179
Bram Moolenaar9800bfe2019-07-27 21:23:45 +0200180 let save_columns = &columns
181 let &columns = 79
Bram Moolenaar71478202020-06-26 22:46:27 +0200182 try
183 exe 'args ' .. join(range(1, 81))
184 call assert_equal(join([
185 \ '',
186 \ '[1] 6 11 16 21 26 31 36 41 46 51 56 61 66 71 76 81 ',
187 \ '2 7 12 17 22 27 32 37 42 47 52 57 62 67 72 77 ',
188 \ '3 8 13 18 23 28 33 38 43 48 53 58 63 68 73 78 ',
189 \ '4 9 14 19 24 29 34 39 44 49 54 59 64 69 74 79 ',
190 \ '5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 ',
191 \ ], "\n"),
192 \ execute('args'))
Bram Moolenaar9800bfe2019-07-27 21:23:45 +0200193
Bram Moolenaar71478202020-06-26 22:46:27 +0200194 " No trailing newline with one item per row.
195 let long_arg = repeat('X', 81)
196 exe 'args ' .. long_arg
197 call assert_equal("\n[".long_arg.']', execute('args'))
198 finally
199 let &columns = save_columns
200 endtry
Bram Moolenaar9800bfe2019-07-27 21:23:45 +0200201
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100202 " Setting argument list should fail when the current buffer has unsaved
203 " changes
204 %argd
205 enew!
206 set modified
207 call assert_fails('args x y z', 'E37:')
208 args! x y z
209 call assert_equal(['x', 'y', 'z'], argv())
210 call assert_equal('x', expand('%:t'))
211
212 last | enew | argu
213 call assert_equal('z', expand('%:t'))
214
215 %argdelete
216 call assert_fails('argument', 'E163:')
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100217endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100218
Bram Moolenaar5d69da42018-04-20 22:01:41 +0200219func Test_list_arguments()
220 " Clean the argument list
221 arga a | %argd
222
223 " four args half the screen width makes two lines with two columns
224 let aarg = repeat('a', &columns / 2 - 4)
225 let barg = repeat('b', &columns / 2 - 4)
226 let carg = repeat('c', &columns / 2 - 4)
227 let darg = repeat('d', &columns / 2 - 4)
228 exe 'argadd ' aarg barg carg darg
229
230 redir => result
231 args
232 redir END
233 call assert_match('\[' . aarg . '] \+' . carg . '\n' . barg . ' \+' . darg, trim(result))
234
235 " if one arg is longer than half the screen make one column
236 exe 'argdel' aarg
237 let aarg = repeat('a', &columns / 2 + 2)
238 exe '0argadd' aarg
239 redir => result
240 args
241 redir END
242 call assert_match(aarg . '\n\[' . barg . ']\n' . carg . '\n' . darg, trim(result))
243
244 %argdelete
245endfunc
246
Bram Moolenaar2ac372c2018-12-28 19:06:47 +0100247func Test_args_with_quote()
Bram Moolenaar3de8c2d2018-12-28 19:29:35 +0100248 " Only on Unix can a file name include a double quote.
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200249 CheckUnix
250
251 args \"foobar
252 call assert_equal('"foobar', argv(0))
253 %argdelete
Bram Moolenaar2ac372c2018-12-28 19:06:47 +0100254endfunc
255
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100256" Test for 0argadd and 0argedit
257" Ported from the test_argument_0count.in test script
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100258func Test_zero_argadd()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100259 " Clean the argument list
260 arga a | %argd
261
262 arga a b c d
263 2argu
264 0arga added
265 call assert_equal(['added', 'a', 'b', 'c', 'd'], argv())
266
267 2argu
268 arga third
269 call assert_equal(['added', 'a', 'third', 'b', 'c', 'd'], argv())
270
271 %argd
272 arga a b c d
273 2argu
274 0arge edited
275 call assert_equal(['edited', 'a', 'b', 'c', 'd'], argv())
276
277 2argu
278 arga third
279 call assert_equal(['edited', 'a', 'third', 'b', 'c', 'd'], argv())
Bram Moolenaar90305c62017-07-16 15:31:17 +0200280
281 2argu
282 argedit file\ with\ spaces another file
283 call assert_equal(['edited', 'a', 'file with spaces', 'another', 'file', 'third', 'b', 'c', 'd'], argv())
284 call assert_equal('file with spaces', expand('%'))
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100285endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100286
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100287func Reset_arglist()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100288 args a | %argd
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100289endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100290
291" Test for argc()
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100292func Test_argc()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100293 call Reset_arglist()
294 call assert_equal(0, argc())
295 argadd a b
296 call assert_equal(2, argc())
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100297endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100298
299" Test for arglistid()
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100300func Test_arglistid()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100301 call Reset_arglist()
302 arga a b
303 call assert_equal(0, arglistid())
304 split
305 arglocal
306 call assert_equal(1, arglistid())
307 tabnew | tabfirst
308 call assert_equal(0, arglistid(2))
309 call assert_equal(1, arglistid(1, 1))
310 call assert_equal(0, arglistid(2, 1))
311 call assert_equal(1, arglistid(1, 2))
312 tabonly | only | enew!
313 argglobal
314 call assert_equal(0, arglistid())
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100315endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100316
Bram Moolenaare6e39892018-10-25 12:32:11 +0200317" Tests for argv() and argc()
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100318func Test_argv()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100319 call Reset_arglist()
320 call assert_equal([], argv())
321 call assert_equal("", argv(2))
Bram Moolenaare6e39892018-10-25 12:32:11 +0200322 call assert_equal(0, argc())
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100323 argadd a b c d
Bram Moolenaare6e39892018-10-25 12:32:11 +0200324 call assert_equal(4, argc())
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100325 call assert_equal('c', argv(2))
Bram Moolenaare6e39892018-10-25 12:32:11 +0200326
327 let w1_id = win_getid()
328 split
329 let w2_id = win_getid()
330 arglocal
331 args e f g
332 tabnew
333 let w3_id = win_getid()
334 split
335 let w4_id = win_getid()
336 argglobal
337 tabfirst
338 call assert_equal(4, argc(w1_id))
339 call assert_equal('b', argv(1, w1_id))
340 call assert_equal(['a', 'b', 'c', 'd'], argv(-1, w1_id))
341
342 call assert_equal(3, argc(w2_id))
343 call assert_equal('f', argv(1, w2_id))
344 call assert_equal(['e', 'f', 'g'], argv(-1, w2_id))
345
346 call assert_equal(3, argc(w3_id))
347 call assert_equal('e', argv(0, w3_id))
348 call assert_equal(['e', 'f', 'g'], argv(-1, w3_id))
349
350 call assert_equal(4, argc(w4_id))
351 call assert_equal('c', argv(2, w4_id))
352 call assert_equal(['a', 'b', 'c', 'd'], argv(-1, w4_id))
353
354 call assert_equal(4, argc(-1))
355 call assert_equal(3, argc())
356 call assert_equal('d', argv(3, -1))
357 call assert_equal(['a', 'b', 'c', 'd'], argv(-1, -1))
358 tabonly | only | enew!
359 " Negative test cases
360 call assert_equal(-1, argc(100))
361 call assert_equal('', argv(1, 100))
362 call assert_equal([], argv(-1, 100))
363 call assert_equal('', argv(10, -1))
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100364endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100365
366" Test for the :argedit command
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100367func Test_argedit()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100368 call Reset_arglist()
369 argedit a
370 call assert_equal(['a'], argv())
371 call assert_equal('a', expand('%:t'))
372 argedit b
373 call assert_equal(['a', 'b'], argv())
374 call assert_equal('b', expand('%:t'))
375 argedit a
Bram Moolenaar90305c62017-07-16 15:31:17 +0200376 call assert_equal(['a', 'b', 'a'], argv())
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100377 call assert_equal('a', expand('%:t'))
Bram Moolenaar9b50bba2017-07-16 16:42:13 +0200378 " When file name case is ignored, an existing buffer with only case
Bram Moolenaarcf1ba352017-10-27 00:55:04 +0200379 " difference is re-used.
Bram Moolenaar90305c62017-07-16 15:31:17 +0200380 argedit C D
381 call assert_equal('C', expand('%:t'))
382 call assert_equal(['a', 'b', 'a', 'C', 'D'], argv())
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100383 argedit c
Bram Moolenaar9b50bba2017-07-16 16:42:13 +0200384 if has('fname_case')
385 call assert_equal(['a', 'b', 'a', 'C', 'c', 'D'], argv())
386 else
387 call assert_equal(['a', 'b', 'a', 'C', 'C', 'D'], argv())
388 endif
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100389 0argedit x
Bram Moolenaar9b50bba2017-07-16 16:42:13 +0200390 if has('fname_case')
391 call assert_equal(['x', 'a', 'b', 'a', 'C', 'c', 'D'], argv())
392 else
393 call assert_equal(['x', 'a', 'b', 'a', 'C', 'C', 'D'], argv())
394 endif
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100395 enew! | set modified
396 call assert_fails('argedit y', 'E37:')
397 argedit! y
Bram Moolenaar9b50bba2017-07-16 16:42:13 +0200398 if has('fname_case')
399 call assert_equal(['x', 'y', 'y', 'a', 'b', 'a', 'C', 'c', 'D'], argv())
400 else
401 call assert_equal(['x', 'y', 'y', 'a', 'b', 'a', 'C', 'C', 'D'], argv())
402 endif
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100403 %argd
Bram Moolenaar9b50bba2017-07-16 16:42:13 +0200404 bwipe! C
405 bwipe! D
Bram Moolenaar46a53df2018-04-24 21:58:51 +0200406
407 " :argedit reuses the current buffer if it is empty
408 %argd
409 " make sure to use a new buffer number for x when it is loaded
410 bw! x
411 new
Bram Moolenaara8eee212019-08-24 22:14:58 +0200412 let a = bufnr()
Bram Moolenaar46a53df2018-04-24 21:58:51 +0200413 argedit x
Bram Moolenaara8eee212019-08-24 22:14:58 +0200414 call assert_equal(a, bufnr())
415 call assert_equal('x', bufname())
Bram Moolenaar46a53df2018-04-24 21:58:51 +0200416 %argd
417 bw! x
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100418endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100419
420" Test for the :argdelete command
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100421func Test_argdelete()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100422 call Reset_arglist()
423 args aa a aaa b bb
424 argdelete a*
425 call assert_equal(['b', 'bb'], argv())
426 call assert_equal('aa', expand('%:t'))
427 last
428 argdelete %
429 call assert_equal(['b'], argv())
Bram Moolenaar7b221172020-08-17 19:34:10 +0200430 call assert_fails('argdelete', 'E610:')
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100431 call assert_fails('1,100argdelete', 'E16:')
Bram Moolenaar531be472020-09-23 22:38:05 +0200432 call assert_fails('argdel /\)/', 'E55:')
Bram Moolenaarafe8cf62020-10-05 20:07:18 +0200433 call assert_fails('1argdel 1', 'E474:')
Bram Moolenaar7b221172020-08-17 19:34:10 +0200434
435 call Reset_arglist()
436 args a b c d
437 next
438 argdel
439 call Assert_argc(['a', 'c', 'd'])
440 %argdel
Dominique Pellebfb2bb12021-08-14 21:11:51 +0200441
442 call assert_fails('argdel does_not_exist', 'E480:')
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100443endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100444
Bram Moolenaarb513d302018-12-02 14:55:08 +0100445func Test_argdelete_completion()
446 args foo bar
447
448 call feedkeys(":argdelete \<C-A>\<C-B>\"\<CR>", 'tx')
449 call assert_equal('"argdelete bar foo', @:)
450
451 call feedkeys(":argdelete x \<C-A>\<C-B>\"\<CR>", 'tx')
452 call assert_equal('"argdelete x bar foo', @:)
453
454 %argd
455endfunc
456
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100457" Tests for the :next, :prev, :first, :last, :rewind commands
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100458func Test_argpos()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100459 call Reset_arglist()
460 args a b c d
461 last
462 call assert_equal(3, argidx())
463 call assert_fails('next', 'E165:')
464 prev
465 call assert_equal(2, argidx())
466 Next
467 call assert_equal(1, argidx())
468 first
469 call assert_equal(0, argidx())
470 call assert_fails('prev', 'E164:')
471 3next
472 call assert_equal(3, argidx())
473 rewind
474 call assert_equal(0, argidx())
475 %argd
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100476endfunc
Bram Moolenaar53f16732016-09-07 20:46:39 +0200477
478" Test for autocommand that redefines the argument list, when doing ":all".
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100479func Test_arglist_autocmd()
Bram Moolenaar53f16732016-09-07 20:46:39 +0200480 autocmd BufReadPost Xxx2 next Xxx2 Xxx1
481 call writefile(['test file Xxx1'], 'Xxx1')
482 call writefile(['test file Xxx2'], 'Xxx2')
483 call writefile(['test file Xxx3'], 'Xxx3')
484
485 new
486 " redefine arglist; go to Xxx1
487 next! Xxx1 Xxx2 Xxx3
Bram Moolenaarafe8cf62020-10-05 20:07:18 +0200488 " open window for all args; Reading Xxx2 will change the arglist and the
489 " third window will get Xxx1:
490 " win 1: Xxx1
491 " win 2: Xxx2
492 " win 3: Xxx1
Bram Moolenaar53f16732016-09-07 20:46:39 +0200493 all
494 call assert_equal('test file Xxx1', getline(1))
495 wincmd w
496 wincmd w
497 call assert_equal('test file Xxx1', getline(1))
Bram Moolenaar53f16732016-09-07 20:46:39 +0200498 rewind
499 call assert_equal('test file Xxx2', getline(1))
500
501 autocmd! BufReadPost Xxx2
502 enew! | only
503 call delete('Xxx1')
504 call delete('Xxx2')
505 call delete('Xxx3')
506 argdelete Xxx*
507 bwipe! Xxx1 Xxx2 Xxx3
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100508endfunc
509
510func Test_arg_all_expand()
511 call writefile(['test file Xxx1'], 'Xx x')
512 next notexist Xx\ x runtest.vim
513 call assert_equal('notexist Xx\ x runtest.vim', expand('##'))
514 call delete('Xx x')
515endfunc
Bram Moolenaare961cba2018-09-18 21:51:47 +0200516
517func Test_large_arg()
518 " Argument longer or equal to the number of columns used to cause
519 " access to invalid memory.
520 exe 'argadd ' .repeat('x', &columns)
521 args
522endfunc
Bram Moolenaar72e1b392019-08-03 13:50:08 +0200523
524func Test_argdo()
525 next! Xa.c Xb.c Xc.c
526 new
527 let l = []
528 argdo call add(l, expand('%'))
529 call assert_equal(['Xa.c', 'Xb.c', 'Xc.c'], l)
530 bwipe Xa.c Xb.c Xc.c
531endfunc
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100532
Bram Moolenaar8e7d6222020-12-18 19:49:56 +0100533" Test for quitting Vim with unedited files in the argument list
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100534func Test_quit_with_arglist()
Bram Moolenaar494e9062020-05-31 21:28:02 +0200535 CheckRunVimInTerminal
Bram Moolenaar21829c52021-01-26 22:42:21 +0100536
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100537 let buf = RunVimInTerminal('', {'rows': 6})
Bram Moolenaar818fc9a2020-02-21 17:54:45 +0100538 call term_sendkeys(buf, ":set nomore\n")
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100539 call term_sendkeys(buf, ":args a b c\n")
540 call term_sendkeys(buf, ":quit\n")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200541 call TermWait(buf)
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100542 call WaitForAssert({-> assert_match('^E173:', term_getline(buf, 6))})
543 call StopVimInTerminal(buf)
Bram Moolenaar406cd902020-02-18 21:54:41 +0100544
545 " Try :confirm quit with unedited files in arglist
546 let buf = RunVimInTerminal('', {'rows': 6})
547 call term_sendkeys(buf, ":set nomore\n")
548 call term_sendkeys(buf, ":args a b c\n")
549 call term_sendkeys(buf, ":confirm quit\n")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200550 call TermWait(buf)
Bram Moolenaar406cd902020-02-18 21:54:41 +0100551 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$',
552 \ term_getline(buf, 6))})
553 call term_sendkeys(buf, "N")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200554 call TermWait(buf)
Bram Moolenaar406cd902020-02-18 21:54:41 +0100555 call term_sendkeys(buf, ":confirm quit\n")
556 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$',
557 \ term_getline(buf, 6))})
558 call term_sendkeys(buf, "Y")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200559 call TermWait(buf)
Bram Moolenaar818fc9a2020-02-21 17:54:45 +0100560 call WaitForAssert({-> assert_equal("finished", term_getstatus(buf))})
561 only!
Bram Moolenaar1671f442020-03-10 07:48:13 +0100562 " When this test fails, swap files are left behind which breaks subsequent
563 " tests
564 call delete('.a.swp')
565 call delete('.b.swp')
566 call delete('.c.swp')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100567endfunc
568
Bram Moolenaarbb4b93e2021-01-26 21:35:08 +0100569" Test for ":all" not working when in the cmdline window
570func Test_all_not_allowed_from_cmdwin()
Bram Moolenaar21829c52021-01-26 22:42:21 +0100571 CheckFeature cmdwin
Bram Moolenaar21829c52021-01-26 22:42:21 +0100572
Bram Moolenaarbb4b93e2021-01-26 21:35:08 +0100573 au BufEnter * all
574 next x
Bram Moolenaarbed72df2021-01-27 20:34:29 +0100575 " Use try/catch here, somehow assert_fails() doesn't work on MS-Windows
576 " console.
577 let caught = 'no'
578 try
579 exe ":norm! 7q?apat\<CR>"
580 catch /E11:/
581 let caught = 'yes'
582 endtry
583 call assert_equal('yes', caught)
Bram Moolenaarbb4b93e2021-01-26 21:35:08 +0100584 au! BufEnter
585endfunc
586
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100587" vim: shiftwidth=2 sts=2 expandtab