blob: b1f292975a9cd2877a9be616a370a8325fcde2c7 [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
Shougo Matsushita3cad4702021-11-18 15:37:29 +00007func Reset_arglist()
8 args a | %argd
9endfunc
10
Bram Moolenaar72defda2016-01-17 18:04:33 +010011func Test_argidx()
12 args a b c
13 last
14 call assert_equal(2, argidx())
15 %argdelete
16 call assert_equal(0, argidx())
Bram Moolenaar69a92fb2017-03-09 15:58:30 +010017 " doing it again doesn't result in an error
18 %argdelete
19 call assert_equal(0, argidx())
20 call assert_fails('2argdelete', 'E16:')
Bram Moolenaar72defda2016-01-17 18:04:33 +010021
22 args a b c
23 call assert_equal(0, argidx())
24 next
25 call assert_equal(1, argidx())
26 next
27 call assert_equal(2, argidx())
28 1argdelete
29 call assert_equal(1, argidx())
30 1argdelete
31 call assert_equal(0, argidx())
32 1argdelete
33 call assert_equal(0, argidx())
34endfunc
Bram Moolenaara24f0a52016-01-17 19:39:00 +010035
36func Test_argadd()
Shougo Matsushita3cad4702021-11-18 15:37:29 +000037 call Reset_arglist()
38
Bram Moolenaara24f0a52016-01-17 19:39:00 +010039 %argdelete
40 argadd a b c
41 call assert_equal(0, argidx())
42
43 %argdelete
44 argadd a
45 call assert_equal(0, argidx())
46 argadd b c d
47 call assert_equal(0, argidx())
48
49 call Init_abc()
50 argadd x
51 call Assert_argc(['a', 'b', 'x', 'c'])
52 call assert_equal(1, argidx())
53
54 call Init_abc()
55 0argadd x
56 call Assert_argc(['x', 'a', 'b', 'c'])
57 call assert_equal(2, argidx())
58
59 call Init_abc()
60 1argadd x
61 call Assert_argc(['a', 'x', 'b', 'c'])
62 call assert_equal(2, argidx())
63
64 call Init_abc()
65 $argadd x
66 call Assert_argc(['a', 'b', 'c', 'x'])
67 call assert_equal(1, argidx())
68
69 call Init_abc()
70 $argadd x
71 +2argadd y
72 call Assert_argc(['a', 'b', 'c', 'x', 'y'])
73 call assert_equal(1, argidx())
Bram Moolenaar2faa29f2016-01-23 23:02:34 +010074
75 %argd
76 edit d
77 arga
Bram Moolenaar398ee732017-08-03 14:29:14 +020078 call assert_equal(1, len(argv()))
79 call assert_equal('d', get(argv(), 0, ''))
80
81 %argd
82 edit some\ file
83 arga
84 call assert_equal(1, len(argv()))
85 call assert_equal('some file', get(argv(), 0, ''))
Bram Moolenaar2faa29f2016-01-23 23:02:34 +010086
87 %argd
88 new
89 arga
Bram Moolenaar398ee732017-08-03 14:29:14 +020090 call assert_equal(0, len(argv()))
Dominique Pellebfb2bb12021-08-14 21:11:51 +020091
92 if has('unix')
93 call assert_fails('argadd `Xdoes_not_exist`', 'E479:')
94 endif
Bram Moolenaara24f0a52016-01-17 19:39:00 +010095endfunc
96
Bram Moolenaar32bbd002018-08-31 23:06:22 +020097func Test_argadd_empty_curbuf()
98 new
99 let curbuf = bufnr('%')
100 call writefile(['test', 'Xargadd'], 'Xargadd')
101 " must not re-use the current buffer.
102 argadd Xargadd
103 call assert_equal(curbuf, bufnr('%'))
104 call assert_equal('', bufname('%'))
Bram Moolenaar02b31112019-08-31 22:16:38 +0200105 call assert_equal(1, '$'->line())
Bram Moolenaar32bbd002018-08-31 23:06:22 +0200106 rew
Bram Moolenaar073e4b92019-08-18 23:01:56 +0200107 call assert_notequal(curbuf, '%'->bufnr())
108 call assert_equal('Xargadd', '%'->bufname())
Bram Moolenaar32bbd002018-08-31 23:06:22 +0200109 call assert_equal(2, line('$'))
110
Bram Moolenaard3398282018-09-24 21:32:11 +0200111 call delete('Xargadd')
Bram Moolenaar32bbd002018-08-31 23:06:22 +0200112 %argd
113 bwipe!
114endfunc
115
Bram Moolenaara24f0a52016-01-17 19:39:00 +0100116func Init_abc()
117 args a b c
118 next
119endfunc
120
121func Assert_argc(l)
122 call assert_equal(len(a:l), argc())
123 let i = 0
124 while i < len(a:l) && i < argc()
125 call assert_equal(a:l[i], argv(i))
126 let i += 1
127 endwhile
128endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100129
130" Test for [count]argument and [count]argdelete commands
131" Ported from the test_argument_count.in test script
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100132func Test_argument()
Shougo Matsushita3cad4702021-11-18 15:37:29 +0000133 call Reset_arglist()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100134
135 let save_hidden = &hidden
136 set hidden
137
138 let g:buffers = []
139 augroup TEST
140 au BufEnter * call add(buffers, expand('%:t'))
141 augroup END
142
143 argadd a b c d
144 $argu
145 $-argu
146 -argu
147 1argu
148 +2argu
149
150 augroup TEST
151 au!
152 augroup END
153
154 call assert_equal(['d', 'c', 'b', 'a', 'c'], g:buffers)
155
Bram Moolenaar949f1982019-07-23 23:00:08 +0200156 call assert_equal("\na b [c] d ", execute(':args'))
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100157
158 .argd
159 call assert_equal(['a', 'b', 'd'], argv())
160
161 -argd
162 call assert_equal(['a', 'd'], argv())
163
164 $argd
165 call assert_equal(['a'], argv())
166
167 1arga c
168 1arga b
169 $argu
170 $arga x
171 call assert_equal(['a', 'b', 'c', 'x'], argv())
172
Bram Moolenaar30141702016-01-19 14:14:08 +0100173 0arga y
174 call assert_equal(['y', 'a', 'b', 'c', 'x'], argv())
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100175
176 %argd
177 call assert_equal([], argv())
178
179 arga a b c d e f
180 2,$-argd
181 call assert_equal(['a', 'f'], argv())
182
183 let &hidden = save_hidden
184
Bram Moolenaar9800bfe2019-07-27 21:23:45 +0200185 let save_columns = &columns
186 let &columns = 79
Bram Moolenaar71478202020-06-26 22:46:27 +0200187 try
188 exe 'args ' .. join(range(1, 81))
189 call assert_equal(join([
190 \ '',
191 \ '[1] 6 11 16 21 26 31 36 41 46 51 56 61 66 71 76 81 ',
192 \ '2 7 12 17 22 27 32 37 42 47 52 57 62 67 72 77 ',
193 \ '3 8 13 18 23 28 33 38 43 48 53 58 63 68 73 78 ',
194 \ '4 9 14 19 24 29 34 39 44 49 54 59 64 69 74 79 ',
195 \ '5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 ',
196 \ ], "\n"),
197 \ execute('args'))
Bram Moolenaar9800bfe2019-07-27 21:23:45 +0200198
Bram Moolenaar71478202020-06-26 22:46:27 +0200199 " No trailing newline with one item per row.
200 let long_arg = repeat('X', 81)
201 exe 'args ' .. long_arg
202 call assert_equal("\n[".long_arg.']', execute('args'))
203 finally
204 let &columns = save_columns
205 endtry
Bram Moolenaar9800bfe2019-07-27 21:23:45 +0200206
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100207 " Setting argument list should fail when the current buffer has unsaved
208 " changes
209 %argd
210 enew!
211 set modified
212 call assert_fails('args x y z', 'E37:')
213 args! x y z
214 call assert_equal(['x', 'y', 'z'], argv())
215 call assert_equal('x', expand('%:t'))
216
217 last | enew | argu
218 call assert_equal('z', expand('%:t'))
219
220 %argdelete
221 call assert_fails('argument', 'E163:')
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100222endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100223
Bram Moolenaar5d69da42018-04-20 22:01:41 +0200224func Test_list_arguments()
Shougo Matsushita3cad4702021-11-18 15:37:29 +0000225 call Reset_arglist()
Bram Moolenaar5d69da42018-04-20 22:01:41 +0200226
227 " four args half the screen width makes two lines with two columns
228 let aarg = repeat('a', &columns / 2 - 4)
229 let barg = repeat('b', &columns / 2 - 4)
230 let carg = repeat('c', &columns / 2 - 4)
231 let darg = repeat('d', &columns / 2 - 4)
232 exe 'argadd ' aarg barg carg darg
233
234 redir => result
235 args
236 redir END
237 call assert_match('\[' . aarg . '] \+' . carg . '\n' . barg . ' \+' . darg, trim(result))
238
239 " if one arg is longer than half the screen make one column
240 exe 'argdel' aarg
241 let aarg = repeat('a', &columns / 2 + 2)
242 exe '0argadd' aarg
243 redir => result
244 args
245 redir END
246 call assert_match(aarg . '\n\[' . barg . ']\n' . carg . '\n' . darg, trim(result))
247
248 %argdelete
249endfunc
250
Bram Moolenaar2ac372c2018-12-28 19:06:47 +0100251func Test_args_with_quote()
Bram Moolenaar3de8c2d2018-12-28 19:29:35 +0100252 " Only on Unix can a file name include a double quote.
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200253 CheckUnix
254
255 args \"foobar
256 call assert_equal('"foobar', argv(0))
257 %argdelete
Bram Moolenaar2ac372c2018-12-28 19:06:47 +0100258endfunc
259
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100260" Test for 0argadd and 0argedit
261" Ported from the test_argument_0count.in test script
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100262func Test_zero_argadd()
Shougo Matsushita3cad4702021-11-18 15:37:29 +0000263 call Reset_arglist()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100264
265 arga a b c d
266 2argu
267 0arga added
268 call assert_equal(['added', 'a', 'b', 'c', 'd'], argv())
269
270 2argu
271 arga third
272 call assert_equal(['added', 'a', 'third', 'b', 'c', 'd'], argv())
273
274 %argd
275 arga a b c d
276 2argu
277 0arge edited
278 call assert_equal(['edited', 'a', 'b', 'c', 'd'], argv())
279
280 2argu
281 arga third
282 call assert_equal(['edited', 'a', 'third', 'b', 'c', 'd'], argv())
Bram Moolenaar90305c62017-07-16 15:31:17 +0200283
284 2argu
285 argedit file\ with\ spaces another file
286 call assert_equal(['edited', 'a', 'file with spaces', 'another', 'file', 'third', 'b', 'c', 'd'], argv())
287 call assert_equal('file with spaces', expand('%'))
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100288endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100289
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100290" Test for argc()
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100291func Test_argc()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100292 call Reset_arglist()
293 call assert_equal(0, argc())
294 argadd a b
295 call assert_equal(2, argc())
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100296endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100297
298" Test for arglistid()
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100299func Test_arglistid()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100300 call Reset_arglist()
301 arga a b
302 call assert_equal(0, arglistid())
303 split
304 arglocal
305 call assert_equal(1, arglistid())
306 tabnew | tabfirst
307 call assert_equal(0, arglistid(2))
308 call assert_equal(1, arglistid(1, 1))
309 call assert_equal(0, arglistid(2, 1))
310 call assert_equal(1, arglistid(1, 2))
311 tabonly | only | enew!
312 argglobal
313 call assert_equal(0, arglistid())
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100314endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100315
Bram Moolenaare6e39892018-10-25 12:32:11 +0200316" Tests for argv() and argc()
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100317func Test_argv()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100318 call Reset_arglist()
319 call assert_equal([], argv())
320 call assert_equal("", argv(2))
Bram Moolenaare6e39892018-10-25 12:32:11 +0200321 call assert_equal(0, argc())
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100322 argadd a b c d
Bram Moolenaare6e39892018-10-25 12:32:11 +0200323 call assert_equal(4, argc())
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100324 call assert_equal('c', argv(2))
Bram Moolenaare6e39892018-10-25 12:32:11 +0200325
326 let w1_id = win_getid()
327 split
328 let w2_id = win_getid()
329 arglocal
330 args e f g
331 tabnew
332 let w3_id = win_getid()
333 split
334 let w4_id = win_getid()
335 argglobal
336 tabfirst
337 call assert_equal(4, argc(w1_id))
338 call assert_equal('b', argv(1, w1_id))
339 call assert_equal(['a', 'b', 'c', 'd'], argv(-1, w1_id))
340
341 call assert_equal(3, argc(w2_id))
342 call assert_equal('f', argv(1, w2_id))
343 call assert_equal(['e', 'f', 'g'], argv(-1, w2_id))
344
345 call assert_equal(3, argc(w3_id))
346 call assert_equal('e', argv(0, w3_id))
347 call assert_equal(['e', 'f', 'g'], argv(-1, w3_id))
348
349 call assert_equal(4, argc(w4_id))
350 call assert_equal('c', argv(2, w4_id))
351 call assert_equal(['a', 'b', 'c', 'd'], argv(-1, w4_id))
352
353 call assert_equal(4, argc(-1))
354 call assert_equal(3, argc())
355 call assert_equal('d', argv(3, -1))
356 call assert_equal(['a', 'b', 'c', 'd'], argv(-1, -1))
357 tabonly | only | enew!
358 " Negative test cases
359 call assert_equal(-1, argc(100))
360 call assert_equal('', argv(1, 100))
361 call assert_equal([], argv(-1, 100))
362 call assert_equal('', argv(10, -1))
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100363endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100364
365" Test for the :argedit command
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100366func Test_argedit()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100367 call Reset_arglist()
368 argedit a
369 call assert_equal(['a'], argv())
370 call assert_equal('a', expand('%:t'))
371 argedit b
372 call assert_equal(['a', 'b'], argv())
373 call assert_equal('b', expand('%:t'))
374 argedit a
Bram Moolenaar90305c62017-07-16 15:31:17 +0200375 call assert_equal(['a', 'b', 'a'], argv())
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100376 call assert_equal('a', expand('%:t'))
Bram Moolenaar9b50bba2017-07-16 16:42:13 +0200377 " When file name case is ignored, an existing buffer with only case
Bram Moolenaarcf1ba352017-10-27 00:55:04 +0200378 " difference is re-used.
Bram Moolenaar90305c62017-07-16 15:31:17 +0200379 argedit C D
380 call assert_equal('C', expand('%:t'))
381 call assert_equal(['a', 'b', 'a', 'C', 'D'], argv())
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100382 argedit c
Bram Moolenaar9b50bba2017-07-16 16:42:13 +0200383 if has('fname_case')
384 call assert_equal(['a', 'b', 'a', 'C', 'c', 'D'], argv())
385 else
386 call assert_equal(['a', 'b', 'a', 'C', 'C', 'D'], argv())
387 endif
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100388 0argedit x
Bram Moolenaar9b50bba2017-07-16 16:42:13 +0200389 if has('fname_case')
390 call assert_equal(['x', 'a', 'b', 'a', 'C', 'c', 'D'], argv())
391 else
392 call assert_equal(['x', 'a', 'b', 'a', 'C', 'C', 'D'], argv())
393 endif
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100394 enew! | set modified
395 call assert_fails('argedit y', 'E37:')
396 argedit! y
Bram Moolenaar9b50bba2017-07-16 16:42:13 +0200397 if has('fname_case')
398 call assert_equal(['x', 'y', 'y', 'a', 'b', 'a', 'C', 'c', 'D'], argv())
399 else
400 call assert_equal(['x', 'y', 'y', 'a', 'b', 'a', 'C', 'C', 'D'], argv())
401 endif
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100402 %argd
Bram Moolenaar9b50bba2017-07-16 16:42:13 +0200403 bwipe! C
404 bwipe! D
Bram Moolenaar46a53df2018-04-24 21:58:51 +0200405
406 " :argedit reuses the current buffer if it is empty
407 %argd
408 " make sure to use a new buffer number for x when it is loaded
409 bw! x
410 new
Bram Moolenaara8eee212019-08-24 22:14:58 +0200411 let a = bufnr()
Bram Moolenaar46a53df2018-04-24 21:58:51 +0200412 argedit x
Bram Moolenaara8eee212019-08-24 22:14:58 +0200413 call assert_equal(a, bufnr())
414 call assert_equal('x', bufname())
Bram Moolenaar46a53df2018-04-24 21:58:51 +0200415 %argd
416 bw! x
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100417endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100418
419" Test for the :argdelete command
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100420func Test_argdelete()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100421 call Reset_arglist()
422 args aa a aaa b bb
423 argdelete a*
424 call assert_equal(['b', 'bb'], argv())
425 call assert_equal('aa', expand('%:t'))
426 last
427 argdelete %
428 call assert_equal(['b'], argv())
Bram Moolenaar7b221172020-08-17 19:34:10 +0200429 call assert_fails('argdelete', 'E610:')
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100430 call assert_fails('1,100argdelete', 'E16:')
Bram Moolenaar531be472020-09-23 22:38:05 +0200431 call assert_fails('argdel /\)/', 'E55:')
Bram Moolenaarafe8cf62020-10-05 20:07:18 +0200432 call assert_fails('1argdel 1', 'E474:')
Bram Moolenaar7b221172020-08-17 19:34:10 +0200433
434 call Reset_arglist()
435 args a b c d
436 next
437 argdel
438 call Assert_argc(['a', 'c', 'd'])
439 %argdel
Dominique Pellebfb2bb12021-08-14 21:11:51 +0200440
441 call assert_fails('argdel does_not_exist', 'E480:')
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100442endfunc
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100443
Bram Moolenaarb513d302018-12-02 14:55:08 +0100444func Test_argdelete_completion()
445 args foo bar
446
447 call feedkeys(":argdelete \<C-A>\<C-B>\"\<CR>", 'tx')
448 call assert_equal('"argdelete bar foo', @:)
449
450 call feedkeys(":argdelete x \<C-A>\<C-B>\"\<CR>", 'tx')
451 call assert_equal('"argdelete x bar foo', @:)
452
453 %argd
454endfunc
455
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100456" Tests for the :next, :prev, :first, :last, :rewind commands
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100457func Test_argpos()
Bram Moolenaar99dbe292016-01-19 13:07:23 +0100458 call Reset_arglist()
459 args a b c d
460 last
461 call assert_equal(3, argidx())
462 call assert_fails('next', 'E165:')
463 prev
464 call assert_equal(2, argidx())
465 Next
466 call assert_equal(1, argidx())
467 first
468 call assert_equal(0, argidx())
469 call assert_fails('prev', 'E164:')
470 3next
471 call assert_equal(3, argidx())
472 rewind
473 call assert_equal(0, argidx())
474 %argd
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100475endfunc
Bram Moolenaar53f16732016-09-07 20:46:39 +0200476
477" Test for autocommand that redefines the argument list, when doing ":all".
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100478func Test_arglist_autocmd()
Bram Moolenaar53f16732016-09-07 20:46:39 +0200479 autocmd BufReadPost Xxx2 next Xxx2 Xxx1
480 call writefile(['test file Xxx1'], 'Xxx1')
481 call writefile(['test file Xxx2'], 'Xxx2')
482 call writefile(['test file Xxx3'], 'Xxx3')
483
484 new
485 " redefine arglist; go to Xxx1
486 next! Xxx1 Xxx2 Xxx3
Bram Moolenaarafe8cf62020-10-05 20:07:18 +0200487 " open window for all args; Reading Xxx2 will change the arglist and the
488 " third window will get Xxx1:
489 " win 1: Xxx1
490 " win 2: Xxx2
491 " win 3: Xxx1
Bram Moolenaar53f16732016-09-07 20:46:39 +0200492 all
493 call assert_equal('test file Xxx1', getline(1))
494 wincmd w
495 wincmd w
496 call assert_equal('test file Xxx1', getline(1))
Bram Moolenaar53f16732016-09-07 20:46:39 +0200497 rewind
498 call assert_equal('test file Xxx2', getline(1))
499
500 autocmd! BufReadPost Xxx2
501 enew! | only
502 call delete('Xxx1')
503 call delete('Xxx2')
504 call delete('Xxx3')
505 argdelete Xxx*
506 bwipe! Xxx1 Xxx2 Xxx3
Bram Moolenaar8c34aa02017-03-16 22:52:32 +0100507endfunc
508
509func Test_arg_all_expand()
510 call writefile(['test file Xxx1'], 'Xx x')
511 next notexist Xx\ x runtest.vim
512 call assert_equal('notexist Xx\ x runtest.vim', expand('##'))
513 call delete('Xx x')
514endfunc
Bram Moolenaare961cba2018-09-18 21:51:47 +0200515
516func Test_large_arg()
517 " Argument longer or equal to the number of columns used to cause
518 " access to invalid memory.
519 exe 'argadd ' .repeat('x', &columns)
520 args
521endfunc
Bram Moolenaar72e1b392019-08-03 13:50:08 +0200522
523func Test_argdo()
524 next! Xa.c Xb.c Xc.c
525 new
526 let l = []
527 argdo call add(l, expand('%'))
528 call assert_equal(['Xa.c', 'Xb.c', 'Xc.c'], l)
529 bwipe Xa.c Xb.c Xc.c
530endfunc
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100531
Bram Moolenaar8e7d6222020-12-18 19:49:56 +0100532" Test for quitting Vim with unedited files in the argument list
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100533func Test_quit_with_arglist()
Bram Moolenaar494e9062020-05-31 21:28:02 +0200534 CheckRunVimInTerminal
Bram Moolenaar21829c52021-01-26 22:42:21 +0100535
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100536 let buf = RunVimInTerminal('', {'rows': 6})
Bram Moolenaar818fc9a2020-02-21 17:54:45 +0100537 call term_sendkeys(buf, ":set nomore\n")
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100538 call term_sendkeys(buf, ":args a b c\n")
539 call term_sendkeys(buf, ":quit\n")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200540 call TermWait(buf)
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100541 call WaitForAssert({-> assert_match('^E173:', term_getline(buf, 6))})
542 call StopVimInTerminal(buf)
Bram Moolenaar406cd902020-02-18 21:54:41 +0100543
544 " Try :confirm quit with unedited files in arglist
545 let buf = RunVimInTerminal('', {'rows': 6})
546 call term_sendkeys(buf, ":set nomore\n")
547 call term_sendkeys(buf, ":args a b c\n")
548 call term_sendkeys(buf, ":confirm quit\n")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200549 call TermWait(buf)
Bram Moolenaar406cd902020-02-18 21:54:41 +0100550 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$',
551 \ term_getline(buf, 6))})
552 call term_sendkeys(buf, "N")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200553 call TermWait(buf)
Bram Moolenaar406cd902020-02-18 21:54:41 +0100554 call term_sendkeys(buf, ":confirm quit\n")
555 call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$',
556 \ term_getline(buf, 6))})
557 call term_sendkeys(buf, "Y")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200558 call TermWait(buf)
Bram Moolenaar818fc9a2020-02-21 17:54:45 +0100559 call WaitForAssert({-> assert_equal("finished", term_getstatus(buf))})
560 only!
Bram Moolenaar1671f442020-03-10 07:48:13 +0100561 " When this test fails, swap files are left behind which breaks subsequent
562 " tests
563 call delete('.a.swp')
564 call delete('.b.swp')
565 call delete('.c.swp')
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100566endfunc
567
Bram Moolenaarbb4b93e2021-01-26 21:35:08 +0100568" Test for ":all" not working when in the cmdline window
569func Test_all_not_allowed_from_cmdwin()
Bram Moolenaar21829c52021-01-26 22:42:21 +0100570 CheckFeature cmdwin
Bram Moolenaar21829c52021-01-26 22:42:21 +0100571
Bram Moolenaarbb4b93e2021-01-26 21:35:08 +0100572 au BufEnter * all
573 next x
Bram Moolenaarbed72df2021-01-27 20:34:29 +0100574 " Use try/catch here, somehow assert_fails() doesn't work on MS-Windows
575 " console.
576 let caught = 'no'
577 try
578 exe ":norm! 7q?apat\<CR>"
579 catch /E11:/
580 let caught = 'yes'
581 endtry
582 call assert_equal('yes', caught)
Bram Moolenaarbb4b93e2021-01-26 21:35:08 +0100583 au! BufEnter
584endfunc
585
Bram Moolenaar9f6277b2020-02-11 22:04:02 +0100586" vim: shiftwidth=2 sts=2 expandtab