blob: a6241134a492fdd95fe8cacbba6b80911f26eab5 [file] [log] [blame]
Bram Moolenaarcfe435d2020-04-25 20:02:55 +02001" Test commands that are not compiled in a :def function
2
Bram Moolenaar6378c4f2020-04-26 13:50:41 +02003source check.vim
Bram Moolenaarcfe435d2020-04-25 20:02:55 +02004source vim9.vim
Bram Moolenaare88c8e82020-11-01 17:03:37 +01005source term_util.vim
Bram Moolenaare9f262b2020-07-05 14:57:51 +02006source view_util.vim
Bram Moolenaarcfe435d2020-04-25 20:02:55 +02007
Bram Moolenaar39f3b142021-02-14 12:57:36 +01008def Test_vim9cmd()
9 var lines =<< trim END
10 vim9cmd var x = 123
11 let s:y = 'yes'
12 vim9c assert_equal(123, x)
13 vim9cm assert_equal('yes', y)
14 END
15 CheckScriptSuccess(lines)
Dominique Pelle6d37e8e2021-05-06 17:36:55 +020016 assert_fails('vim9cmd', 'E1164:')
Bram Moolenaar678b2072021-07-26 21:10:11 +020017
18 lines =<< trim END
19 vim9script
20 def Foo()
21 g:found_bar = "bar"
22 enddef
23 nmap ,; :vim9cmd <SID>Foo()<CR>
24 END
25 CheckScriptSuccess(lines)
26 feedkeys(',;', 'xt')
27 assert_equal("bar", g:found_bar)
28
29 nunmap ,;
30 unlet g:found_bar
Bram Moolenaar39f3b142021-02-14 12:57:36 +010031enddef
32
Bram Moolenaarcfe435d2020-04-25 20:02:55 +020033def Test_edit_wildcards()
Bram Moolenaarac564082020-09-27 19:05:33 +020034 var filename = 'Xtest'
Bram Moolenaarcfe435d2020-04-25 20:02:55 +020035 edit `=filename`
36 assert_equal('Xtest', bufname())
37
Bram Moolenaarac564082020-09-27 19:05:33 +020038 var filenr = 123
Bram Moolenaarcfe435d2020-04-25 20:02:55 +020039 edit Xtest`=filenr`
40 assert_equal('Xtest123', bufname())
41
42 filenr = 77
43 edit `=filename``=filenr`
44 assert_equal('Xtest77', bufname())
45
46 edit X`=filename`xx`=filenr`yy
47 assert_equal('XXtestxx77yy', bufname())
Bram Moolenaar025cb1c2020-12-14 18:31:27 +010048
49 CheckDefFailure(['edit `=xxx`'], 'E1001:')
50 CheckDefFailure(['edit `="foo"'], 'E1083:')
Bram Moolenaarb288ba92021-06-05 17:10:55 +020051
52 var files = ['file 1', 'file%2', 'file# 3']
53 args `=files`
54 assert_equal(files, argv())
Bram Moolenaarcfe435d2020-04-25 20:02:55 +020055enddef
56
Bram Moolenaar4389f9c2020-12-27 16:55:11 +010057def Test_expand_alternate_file()
58 var lines =<< trim END
59 edit Xfileone
60 var bone = bufnr()
61 edit Xfiletwo
62 var btwo = bufnr()
63 edit Xfilethree
64 var bthree = bufnr()
65
66 edit #
67 assert_equal(bthree, bufnr())
68 edit %%
69 assert_equal(btwo, bufnr())
70 edit %% # comment
71 assert_equal(bthree, bufnr())
72 edit %%yy
73 assert_equal('Xfiletwoyy', bufname())
74
75 exe "edit %%" .. bone
76 assert_equal(bone, bufnr())
77 exe "edit %%" .. btwo .. "xx"
78 assert_equal('Xfiletwoxx', bufname())
79
80 next Xfileone Xfiletwo Xfilethree
81 assert_equal('Xfileone', argv(0))
82 assert_equal('Xfiletwo', argv(1))
83 assert_equal('Xfilethree', argv(2))
84 next %%%zz
85 assert_equal('Xfileone', argv(0))
86 assert_equal('Xfiletwo', argv(1))
87 assert_equal('Xfilethreezz', argv(2))
88
89 v:oldfiles = ['Xonefile', 'Xtwofile']
90 edit %%<1
91 assert_equal('Xonefile', bufname())
92 edit %%<2
93 assert_equal('Xtwofile', bufname())
94 assert_fails('edit %%<3', 'E684:')
95
96 edit Xfileone.vim
97 edit Xfiletwo
98 edit %%:r
99 assert_equal('Xfileone', bufname())
Bram Moolenaardfbc5fd2021-01-23 15:15:01 +0100100
101 assert_false(bufexists('altfoo'))
102 edit altfoo
103 edit bar
104 assert_true(bufexists('altfoo'))
105 assert_true(buflisted('altfoo'))
106 bdel %%
107 assert_true(bufexists('altfoo'))
108 assert_false(buflisted('altfoo'))
109 bwipe! altfoo
110 bwipe! bar
Bram Moolenaar4389f9c2020-12-27 16:55:11 +0100111 END
112 CheckDefAndScriptSuccess(lines)
113enddef
114
Bram Moolenaar56ce9ea2020-12-25 18:35:29 +0100115def Test_global_backtick_expansion()
116 new
117 setline(1, 'xx')
118 var name = 'foobar'
119 g/^xx/s/.*/`=name`
120 assert_equal('foobar', getline(1))
121 bwipe!
122enddef
123
Bram Moolenaarecac5912021-01-05 19:23:28 +0100124def Test_folddo_backtick_expansion()
125 new
126 var name = 'xxx'
127 folddoopen edit `=name`
128 assert_equal('xxx', bufname())
129 bwipe!
130
131 new
132 setline(1, ['one', 'two'])
133 set nomodified
134 :1,2fold
135 foldclose
136 folddoclose edit `=name`
137 assert_equal('xxx', bufname())
138 bwipe!
139enddef
140
Bram Moolenaar6378c4f2020-04-26 13:50:41 +0200141def Test_hardcopy_wildcards()
142 CheckUnix
143 CheckFeature postscript
144
Bram Moolenaarac564082020-09-27 19:05:33 +0200145 var outfile = 'print'
Bram Moolenaar6378c4f2020-04-26 13:50:41 +0200146 hardcopy > X`=outfile`.ps
147 assert_true(filereadable('Xprint.ps'))
148
149 delete('Xprint.ps')
150enddef
151
152def Test_syn_include_wildcards()
153 writefile(['syn keyword Found found'], 'Xthemine.vim')
Bram Moolenaarac564082020-09-27 19:05:33 +0200154 var save_rtp = &rtp
Bram Moolenaar6378c4f2020-04-26 13:50:41 +0200155 &rtp = '.'
156
Bram Moolenaarac564082020-09-27 19:05:33 +0200157 var fname = 'mine'
Bram Moolenaar6378c4f2020-04-26 13:50:41 +0200158 syn include @Group Xthe`=fname`.vim
159 assert_match('Found.* contained found', execute('syn list Found'))
160
161 &rtp = save_rtp
162 delete('Xthemine.vim')
163enddef
164
Bram Moolenaar7e8967f2020-06-27 21:56:17 +0200165def Test_echo_linebreak()
Bram Moolenaarac564082020-09-27 19:05:33 +0200166 var lines =<< trim END
Bram Moolenaar7e8967f2020-06-27 21:56:17 +0200167 vim9script
168 redir @a
169 echo 'one'
170 .. 'two'
171 redir END
172 assert_equal("\nonetwo", @a)
173 END
174 CheckScriptSuccess(lines)
175
176 lines =<< trim END
177 vim9script
178 redir @a
179 echo 11 +
180 77
181 - 22
182 redir END
183 assert_equal("\n66", @a)
184 END
185 CheckScriptSuccess(lines)
186enddef
187
Bram Moolenaar13106602020-10-04 16:06:05 +0200188def Test_condition_types()
189 var lines =<< trim END
190 if 'text'
191 endif
192 END
Bram Moolenaarea2d4072020-11-12 12:08:51 +0100193 CheckDefAndScriptFailure(lines, 'E1135:', 1)
Bram Moolenaar13106602020-10-04 16:06:05 +0200194
195 lines =<< trim END
196 if [1]
197 endif
198 END
199 CheckDefFailure(lines, 'E1012:', 1)
200 CheckScriptFailure(['vim9script'] + lines, 'E745:', 2)
201
202 lines =<< trim END
203 g:cond = 'text'
204 if g:cond
205 endif
206 END
Bram Moolenaarea2d4072020-11-12 12:08:51 +0100207 CheckDefExecAndScriptFailure(lines, 'E1135:', 2)
Bram Moolenaar13106602020-10-04 16:06:05 +0200208
209 lines =<< trim END
210 g:cond = 0
211 if g:cond
212 elseif 'text'
213 endif
214 END
215 CheckDefFailure(lines, 'E1012:', 3)
Bram Moolenaarea2d4072020-11-12 12:08:51 +0100216 CheckScriptFailure(['vim9script'] + lines, 'E1135:', 4)
Bram Moolenaar13106602020-10-04 16:06:05 +0200217
218 lines =<< trim END
219 if g:cond
220 elseif [1]
221 endif
222 END
223 CheckDefFailure(lines, 'E1012:', 2)
224 CheckScriptFailure(['vim9script'] + lines, 'E745:', 3)
225
226 lines =<< trim END
227 g:cond = 'text'
228 if 0
229 elseif g:cond
230 endif
231 END
Bram Moolenaarea2d4072020-11-12 12:08:51 +0100232 CheckDefExecAndScriptFailure(lines, 'E1135:', 3)
Bram Moolenaar13106602020-10-04 16:06:05 +0200233
234 lines =<< trim END
235 while 'text'
236 endwhile
237 END
238 CheckDefFailure(lines, 'E1012:', 1)
Bram Moolenaarea2d4072020-11-12 12:08:51 +0100239 CheckScriptFailure(['vim9script'] + lines, 'E1135:', 2)
Bram Moolenaar13106602020-10-04 16:06:05 +0200240
241 lines =<< trim END
242 while [1]
243 endwhile
244 END
245 CheckDefFailure(lines, 'E1012:', 1)
246 CheckScriptFailure(['vim9script'] + lines, 'E745:', 2)
247
248 lines =<< trim END
249 g:cond = 'text'
250 while g:cond
251 endwhile
252 END
Bram Moolenaarea2d4072020-11-12 12:08:51 +0100253 CheckDefExecAndScriptFailure(lines, 'E1135:', 2)
Bram Moolenaar13106602020-10-04 16:06:05 +0200254enddef
255
Bram Moolenaarfaf86262020-06-27 23:07:36 +0200256def Test_if_linebreak()
Bram Moolenaarac564082020-09-27 19:05:33 +0200257 var lines =<< trim END
Bram Moolenaarfaf86262020-06-27 23:07:36 +0200258 vim9script
259 if 1 &&
Bram Moolenaar2bb26582020-10-03 22:52:39 +0200260 true
261 || 1
Bram Moolenaarfaf86262020-06-27 23:07:36 +0200262 g:res = 42
263 endif
264 assert_equal(42, g:res)
265 END
266 CheckScriptSuccess(lines)
267 unlet g:res
268
269 lines =<< trim END
270 vim9script
271 if 1 &&
272 0
273 g:res = 0
274 elseif 0 ||
275 0
276 || 1
277 g:res = 12
278 endif
279 assert_equal(12, g:res)
280 END
281 CheckScriptSuccess(lines)
282 unlet g:res
283enddef
284
285def Test_while_linebreak()
Bram Moolenaarac564082020-09-27 19:05:33 +0200286 var lines =<< trim END
Bram Moolenaarfaf86262020-06-27 23:07:36 +0200287 vim9script
Bram Moolenaarac564082020-09-27 19:05:33 +0200288 var nr = 0
Bram Moolenaard5053d02020-06-28 15:51:16 +0200289 while nr <
290 10 + 3
291 nr = nr
292 + 4
293 endwhile
294 assert_equal(16, nr)
295 END
296 CheckScriptSuccess(lines)
297
298 lines =<< trim END
299 vim9script
Bram Moolenaarac564082020-09-27 19:05:33 +0200300 var nr = 0
Bram Moolenaard5053d02020-06-28 15:51:16 +0200301 while nr
302 <
303 10
304 +
305 3
306 nr = nr
307 +
308 4
Bram Moolenaarfaf86262020-06-27 23:07:36 +0200309 endwhile
310 assert_equal(16, nr)
311 END
312 CheckScriptSuccess(lines)
313enddef
Bram Moolenaarcfe435d2020-04-25 20:02:55 +0200314
Bram Moolenaarb7a78f72020-06-28 18:43:40 +0200315def Test_for_linebreak()
Bram Moolenaarac564082020-09-27 19:05:33 +0200316 var lines =<< trim END
Bram Moolenaarb7a78f72020-06-28 18:43:40 +0200317 vim9script
Bram Moolenaarac564082020-09-27 19:05:33 +0200318 var nr = 0
Bram Moolenaarb7a78f72020-06-28 18:43:40 +0200319 for x
320 in
321 [1, 2, 3, 4]
322 nr = nr + x
323 endfor
324 assert_equal(10, nr)
325 END
326 CheckScriptSuccess(lines)
327
328 lines =<< trim END
329 vim9script
Bram Moolenaarac564082020-09-27 19:05:33 +0200330 var nr = 0
Bram Moolenaarb7a78f72020-06-28 18:43:40 +0200331 for x
332 in
333 [1, 2,
334 3, 4
335 ]
336 nr = nr
337 +
338 x
339 endfor
340 assert_equal(10, nr)
341 END
342 CheckScriptSuccess(lines)
343enddef
344
Bram Moolenaare0890d62021-02-17 14:52:14 +0100345def MethodAfterLinebreak(arg: string)
346 arg
347 ->setline(1)
348enddef
349
Bram Moolenaard2ef6b32020-07-02 21:11:34 +0200350def Test_method_call_linebreak()
Bram Moolenaarac564082020-09-27 19:05:33 +0200351 var lines =<< trim END
Bram Moolenaar5f195932020-07-01 20:07:14 +0200352 vim9script
Bram Moolenaarac564082020-09-27 19:05:33 +0200353 var res = []
Bram Moolenaar5f195932020-07-01 20:07:14 +0200354 func RetArg(
355 arg
356 )
357 let s:res = a:arg
358 endfunc
359 [1,
360 2,
361 3]->RetArg()
362 assert_equal([1, 2, 3], res)
363 END
364 CheckScriptSuccess(lines)
Bram Moolenaar148be9b2021-02-02 21:33:52 +0100365
366 lines =<< trim END
367 new
368 var name = [1, 2]
369 name
370 ->copy()
371 ->setline(1)
372 assert_equal(['1', '2'], getline(1, 2))
373 bwipe!
374 END
375 CheckDefAndScriptSuccess(lines)
376
377 lines =<< trim END
378 new
Bram Moolenaar6914e872021-03-06 21:01:09 +0100379 def Foo(): string
380 return 'the text'
381 enddef
382 def Bar(F: func): string
383 return F()
384 enddef
385 def Test()
Bram Moolenaar77b10ff2021-03-14 13:21:35 +0100386 Foo ->Bar()
387 ->setline(1)
Bram Moolenaar6914e872021-03-06 21:01:09 +0100388 enddef
389 Test()
390 assert_equal('the text', getline(1))
391 bwipe!
392 END
393 CheckDefAndScriptSuccess(lines)
394
395 lines =<< trim END
396 new
Bram Moolenaar148be9b2021-02-02 21:33:52 +0100397 g:shortlist
398 ->copy()
399 ->setline(1)
400 assert_equal(['1', '2'], getline(1, 2))
401 bwipe!
402 END
403 g:shortlist = [1, 2]
404 CheckDefAndScriptSuccess(lines)
405 unlet g:shortlist
Bram Moolenaare0890d62021-02-17 14:52:14 +0100406
407 new
408 MethodAfterLinebreak('foobar')
409 assert_equal('foobar', getline(1))
410 bwipe!
Bram Moolenaar2e2d7582021-03-03 21:22:41 +0100411
412 lines =<< trim END
413 vim9script
414 def Foo(): string
415 return '# some text'
416 enddef
417
418 def Bar(F: func): string
419 return F()
420 enddef
421
Bram Moolenaar77b10ff2021-03-14 13:21:35 +0100422 Foo->Bar()
Bram Moolenaar2e2d7582021-03-03 21:22:41 +0100423 ->setline(1)
424 END
425 CheckScriptSuccess(lines)
426 assert_equal('# some text', getline(1))
427 bwipe!
Bram Moolenaar5f195932020-07-01 20:07:14 +0200428enddef
429
Bram Moolenaar7cebe8b2021-01-23 14:22:16 +0100430def Test_method_call_whitespace()
431 var lines =<< trim END
432 new
433 var yank = 'text'
434 yank->setline(1)
435 yank ->setline(2)
436 yank-> setline(3)
437 yank -> setline(4)
438 assert_equal(['text', 'text', 'text', 'text'], getline(1, 4))
439 bwipe!
440 END
441 CheckDefAndScriptSuccess(lines)
442enddef
443
Bram Moolenaar77b10ff2021-03-14 13:21:35 +0100444def Test_method_and_user_command()
445 var lines =<< trim END
446 vim9script
447 def Cmd()
448 g:didFunc = 1
449 enddef
450 command Cmd g:didCmd = 1
451 Cmd
452 assert_equal(1, g:didCmd)
453 Cmd()
454 assert_equal(1, g:didFunc)
455 unlet g:didFunc
456 unlet g:didCmd
457
458 def InDefFunc()
459 Cmd
460 assert_equal(1, g:didCmd)
461 Cmd()
462 assert_equal(1, g:didFunc)
463 unlet g:didFunc
464 unlet g:didCmd
465 enddef
466 InDefFunc()
467 END
468 CheckScriptSuccess(lines)
469enddef
470
Bram Moolenaar683581e2020-10-22 21:22:58 +0200471def Test_skipped_expr_linebreak()
472 if 0
473 var x = []
Bram Moolenaar2949cfd2020-12-31 21:28:47 +0100474 ->map(() => 0)
Bram Moolenaar683581e2020-10-22 21:22:58 +0200475 endif
476enddef
477
Bram Moolenaar0a47e092020-07-08 18:30:06 +0200478def Test_dict_member()
Bram Moolenaare0de1712020-12-02 17:36:54 +0100479 var test: dict<list<number>> = {data: [3, 1, 2]}
Bram Moolenaar0a47e092020-07-08 18:30:06 +0200480 test.data->sort()
Bram Moolenaare0de1712020-12-02 17:36:54 +0100481 assert_equal({data: [1, 2, 3]}, test)
Bram Moolenaar0a47e092020-07-08 18:30:06 +0200482 test.data
483 ->reverse()
Bram Moolenaare0de1712020-12-02 17:36:54 +0100484 assert_equal({data: [3, 2, 1]}, test)
Bram Moolenaar0a47e092020-07-08 18:30:06 +0200485
Bram Moolenaarac564082020-09-27 19:05:33 +0200486 var lines =<< trim END
Bram Moolenaar0a47e092020-07-08 18:30:06 +0200487 vim9script
Bram Moolenaare0de1712020-12-02 17:36:54 +0100488 var test: dict<list<number>> = {data: [3, 1, 2]}
Bram Moolenaar0a47e092020-07-08 18:30:06 +0200489 test.data->sort()
Bram Moolenaare0de1712020-12-02 17:36:54 +0100490 assert_equal({data: [1, 2, 3]}, test)
Bram Moolenaar0a47e092020-07-08 18:30:06 +0200491 END
492 CheckScriptSuccess(lines)
493enddef
494
Bram Moolenaare9f262b2020-07-05 14:57:51 +0200495def Test_bar_after_command()
496 def RedrawAndEcho()
Bram Moolenaarac564082020-09-27 19:05:33 +0200497 var x = 'did redraw'
Bram Moolenaare9f262b2020-07-05 14:57:51 +0200498 redraw | echo x
499 enddef
500 RedrawAndEcho()
501 assert_match('did redraw', Screenline(&lines))
502
Bram Moolenaar788123c2020-07-05 15:32:17 +0200503 def CallAndEcho()
Bram Moolenaarac564082020-09-27 19:05:33 +0200504 var x = 'did redraw'
Bram Moolenaar788123c2020-07-05 15:32:17 +0200505 reg_executing() | echo x
506 enddef
507 CallAndEcho()
508 assert_match('did redraw', Screenline(&lines))
509
Bram Moolenaare9f262b2020-07-05 14:57:51 +0200510 if has('unix')
511 # bar in filter write command does not start new command
512 def WriteToShell()
513 new
514 setline(1, 'some text')
515 w !cat | cat > Xoutfile
516 bwipe!
517 enddef
518 WriteToShell()
519 assert_equal(['some text'], readfile('Xoutfile'))
520 delete('Xoutfile')
521
522 # bar in filter read command does not start new command
523 def ReadFromShell()
524 new
525 r! echo hello there | cat > Xoutfile
526 r !echo again | cat >> Xoutfile
527 bwipe!
528 enddef
529 ReadFromShell()
530 assert_equal(['hello there', 'again'], readfile('Xoutfile'))
531 delete('Xoutfile')
532 endif
533enddef
534
Bram Moolenaarb074e8b2020-07-11 13:40:45 +0200535def Test_filter_is_not_modifier()
Bram Moolenaare0de1712020-12-02 17:36:54 +0100536 var tags = [{a: 1, b: 2}, {x: 3, y: 4}]
Bram Moolenaar2949cfd2020-12-31 21:28:47 +0100537 filter(tags, ( _, v) => has_key(v, 'x') ? 1 : 0 )
Bram Moolenaare0de1712020-12-02 17:36:54 +0100538 assert_equal([{x: 3, y: 4}], tags)
Bram Moolenaarb074e8b2020-07-11 13:40:45 +0200539enddef
540
Bram Moolenaare88c8e82020-11-01 17:03:37 +0100541def Test_command_modifier_filter()
Bram Moolenaar4f6b6ed2020-10-29 20:24:34 +0100542 var lines =<< trim END
543 final expected = "\nType Name Content\n c \"c piyo"
544 @a = 'hoge'
545 @b = 'fuga'
546 @c = 'piyo'
547
548 assert_equal(execute('filter /piyo/ registers abc'), expected)
549 END
550 CheckDefAndScriptSuccess(lines)
Bram Moolenaare729ce22021-06-06 21:38:09 +0200551
552 # also do this compiled
553 lines =<< trim END
554 @a = 'very specific z3d37dh234 string'
555 filter z3d37dh234 registers
556 assert_match('very specific z3d37dh234 string', Screenline(&lines))
557 END
558 CheckDefAndScriptSuccess(lines)
Bram Moolenaar4f6b6ed2020-10-29 20:24:34 +0100559enddef
560
Bram Moolenaare88c8e82020-11-01 17:03:37 +0100561def Test_win_command_modifiers()
562 assert_equal(1, winnr('$'))
563
564 set splitright
565 vsplit
566 assert_equal(2, winnr())
567 close
568 aboveleft vsplit
569 assert_equal(1, winnr())
570 close
571 set splitright&
572
573 vsplit
574 assert_equal(1, winnr())
575 close
576 belowright vsplit
577 assert_equal(2, winnr())
578 close
579 rightbelow vsplit
580 assert_equal(2, winnr())
581 close
582
Bram Moolenaar97a19002020-11-01 22:15:44 +0100583 if has('browse')
584 browse set
585 assert_equal('option-window', expand('%'))
586 close
587 endif
Bram Moolenaare88c8e82020-11-01 17:03:37 +0100588
589 vsplit
590 botright split
591 assert_equal(3, winnr())
592 assert_equal(&columns, winwidth(0))
593 close
594 close
595
596 vsplit
597 topleft split
598 assert_equal(1, winnr())
599 assert_equal(&columns, winwidth(0))
600 close
601 close
602
603 gettabinfo()->len()->assert_equal(1)
604 tab split
605 gettabinfo()->len()->assert_equal(2)
606 tabclose
607
608 vertical new
609 assert_inrange(&columns / 2 - 2, &columns / 2 + 1, winwidth(0))
610 close
611enddef
612
613func Test_command_modifier_confirm()
614 CheckNotGui
615 CheckRunVimInTerminal
616
617 " Test for saving all the modified buffers
618 let lines =<< trim END
619 call setline(1, 'changed')
620 def Getout()
621 confirm write Xfile
622 enddef
623 END
624 call writefile(lines, 'Xconfirmscript')
625 call writefile(['empty'], 'Xfile')
626 let buf = RunVimInTerminal('-S Xconfirmscript', {'rows': 8})
627 call term_sendkeys(buf, ":call Getout()\n")
628 call WaitForAssert({-> assert_match('(Y)es, \[N\]o: ', term_getline(buf, 8))}, 1000)
629 call term_sendkeys(buf, "y")
Bram Moolenaar645cd3e2020-11-01 20:04:57 +0100630 call WaitForAssert({-> assert_match('(Y)es, \[N\]o: ', term_getline(buf, 8))}, 1000)
631 call term_sendkeys(buf, "\<CR>")
632 call TermWait(buf)
Bram Moolenaare88c8e82020-11-01 17:03:37 +0100633 call StopVimInTerminal(buf)
634
635 call assert_equal(['changed'], readfile('Xfile'))
636 call delete('Xfile')
Bram Moolenaar645cd3e2020-11-01 20:04:57 +0100637 call delete('.Xfile.swp') " in case Vim was killed
Bram Moolenaare88c8e82020-11-01 17:03:37 +0100638 call delete('Xconfirmscript')
639endfunc
640
641def Test_command_modifiers_keep()
642 if has('unix')
643 def DoTest(addRflag: bool, keepMarks: bool, hasMarks: bool)
644 new
645 setline(1, ['one', 'two', 'three'])
646 normal 1Gma
647 normal 2Gmb
648 normal 3Gmc
649 if addRflag
650 set cpo+=R
651 else
652 set cpo-=R
653 endif
654 if keepMarks
655 keepmarks :%!cat
656 else
657 :%!cat
658 endif
659 if hasMarks
660 assert_equal(1, line("'a"))
661 assert_equal(2, line("'b"))
662 assert_equal(3, line("'c"))
663 else
664 assert_equal(0, line("'a"))
665 assert_equal(0, line("'b"))
666 assert_equal(0, line("'c"))
667 endif
668 quit!
669 enddef
670 DoTest(false, false, true)
671 DoTest(true, false, false)
672 DoTest(false, true, true)
673 DoTest(true, true, true)
674 set cpo&vim
Bram Moolenaarf65b35b2020-11-04 18:02:44 +0100675
676 new
677 setline(1, ['one', 'two', 'three', 'four'])
678 assert_equal(4, line("$"))
679 normal 1Gma
680 normal 2Gmb
681 normal 3Gmc
682 lockmarks :1,2!wc
683 # line is deleted, marks don't move
684 assert_equal(3, line("$"))
685 assert_equal('four', getline(3))
686 assert_equal(1, line("'a"))
687 assert_equal(2, line("'b"))
688 assert_equal(3, line("'c"))
689 quit!
Bram Moolenaare88c8e82020-11-01 17:03:37 +0100690 endif
691
Bram Moolenaarf65b35b2020-11-04 18:02:44 +0100692 edit Xone
693 edit Xtwo
694 assert_equal('Xone', expand('#'))
695 keepalt edit Xthree
696 assert_equal('Xone', expand('#'))
697
698 normal /a*b*
699 assert_equal('a*b*', histget("search"))
700 keeppatterns normal /c*d*
701 assert_equal('a*b*', histget("search"))
702
703 new
704 setline(1, range(10))
705 :10
706 normal gg
707 assert_equal(10, getpos("''")[1])
708 keepjumps normal 5G
709 assert_equal(10, getpos("''")[1])
710 quit!
Bram Moolenaare88c8e82020-11-01 17:03:37 +0100711enddef
712
Bram Moolenaar8242ebb2020-12-29 11:15:01 +0100713def Test_bar_line_continuation()
714 var lines =<< trim END
715 au BufNewFile Xfile g:readFile = 1
716 | g:readExtra = 2
717 g:readFile = 0
718 g:readExtra = 0
719 edit Xfile
720 assert_equal(1, g:readFile)
721 assert_equal(2, g:readExtra)
722 bwipe!
723 au! BufNewFile
724
725 au BufNewFile Xfile g:readFile = 1
726 | g:readExtra = 2
727 | g:readMore = 3
728 g:readFile = 0
729 g:readExtra = 0
730 g:readMore = 0
731 edit Xfile
732 assert_equal(1, g:readFile)
733 assert_equal(2, g:readExtra)
734 assert_equal(3, g:readMore)
735 bwipe!
736 au! BufNewFile
737 unlet g:readFile
738 unlet g:readExtra
739 unlet g:readMore
740 END
741 CheckDefAndScriptSuccess(lines)
742enddef
743
Bram Moolenaare88c8e82020-11-01 17:03:37 +0100744def Test_command_modifier_other()
Bram Moolenaar66669fc2020-11-04 18:53:35 +0100745 new Xsomefile
746 setline(1, 'changed')
747 var buf = bufnr()
748 hide edit Xotherfile
749 var info = getbufinfo(buf)
750 assert_equal(1, info[0].hidden)
751 assert_equal(1, info[0].changed)
752 edit Xsomefile
753 bwipe!
754
755 au BufNewFile Xfile g:readFile = 1
756 g:readFile = 0
757 edit Xfile
758 assert_equal(1, g:readFile)
759 bwipe!
760 g:readFile = 0
761 noautocmd edit Xfile
762 assert_equal(0, g:readFile)
Bram Moolenaardcc58e02020-12-28 20:53:21 +0100763 au! BufNewFile
Bram Moolenaardcc58e02020-12-28 20:53:21 +0100764 unlet g:readFile
Bram Moolenaar66669fc2020-11-04 18:53:35 +0100765
766 noswapfile edit XnoSwap
Bram Moolenaardd1f4262020-12-31 17:41:01 +0100767 assert_equal(false, &l:swapfile)
Bram Moolenaar66669fc2020-11-04 18:53:35 +0100768 bwipe!
769
770 var caught = false
771 try
772 sandbox !ls
773 catch /E48:/
774 caught = true
775 endtry
776 assert_true(caught)
777
778 :8verbose g:verbose_now = &verbose
779 assert_equal(8, g:verbose_now)
780 unlet g:verbose_now
781enddef
782
783def EchoHere()
784 echomsg 'here'
785enddef
786def EchoThere()
787 unsilent echomsg 'there'
788enddef
789
790def Test_modifier_silent_unsilent()
791 echomsg 'last one'
792 silent echomsg "text"
793 assert_equal("\nlast one", execute(':1messages'))
794
795 silent! echoerr "error"
796
797 echomsg 'last one'
798 silent EchoHere()
799 assert_equal("\nlast one", execute(':1messages'))
800
801 silent EchoThere()
802 assert_equal("\nthere", execute(':1messages'))
Bram Moolenaar20a76292020-12-25 19:47:24 +0100803
804 try
805 silent eval [][0]
806 catch
807 echomsg "caught"
808 endtry
809 assert_equal("\ncaught", execute(':1messages'))
Bram Moolenaare88c8e82020-11-01 17:03:37 +0100810enddef
811
Bram Moolenaar36113e42020-11-02 21:08:47 +0100812def Test_range_after_command_modifier()
Bram Moolenaar6e2c2c52020-12-25 19:25:45 +0100813 CheckScriptFailure(['vim9script', 'silent keepjump 1d _'], 'E1050: Colon required before a range: 1d _', 2)
Bram Moolenaar36113e42020-11-02 21:08:47 +0100814 new
815 setline(1, 'xxx')
816 CheckScriptSuccess(['vim9script', 'silent keepjump :1d _'])
817 assert_equal('', getline(1))
818 bwipe!
819enddef
820
Bram Moolenaarece0b872021-01-08 20:40:45 +0100821def Test_silent_pattern()
822 new
823 silent! :/pat/put _
824 bwipe!
825enddef
826
Bram Moolenaarfa984412021-03-25 22:15:28 +0100827def Test_useless_command_modifier()
828 g:maybe = true
829 var lines =<< trim END
830 if g:maybe
831 silent endif
832 END
833 CheckDefAndScriptFailure(lines, 'E1176:', 2)
834
835 lines =<< trim END
836 for i in [0]
837 silent endfor
838 END
839 CheckDefAndScriptFailure(lines, 'E1176:', 2)
840
841 lines =<< trim END
842 while g:maybe
843 silent endwhile
844 END
845 CheckDefAndScriptFailure(lines, 'E1176:', 2)
846
847 lines =<< trim END
848 silent try
849 finally
850 endtry
851 END
852 CheckDefAndScriptFailure(lines, 'E1176:', 1)
853
854 lines =<< trim END
855 try
856 silent catch
857 endtry
858 END
859 CheckDefAndScriptFailure(lines, 'E1176:', 2)
860
861 lines =<< trim END
862 try
863 silent finally
864 endtry
865 END
866 CheckDefAndScriptFailure(lines, 'E1176:', 2)
867
868 lines =<< trim END
869 try
870 finally
871 silent endtry
872 END
873 CheckDefAndScriptFailure(lines, 'E1176:', 3)
874enddef
875
Bram Moolenaar007f9d62020-07-06 23:04:49 +0200876def Test_eval_command()
Bram Moolenaarac564082020-09-27 19:05:33 +0200877 var from = 3
878 var to = 5
Bram Moolenaar007f9d62020-07-06 23:04:49 +0200879 g:val = 111
880 def Increment(nrs: list<number>)
881 for nr in nrs
882 g:val += nr
883 endfor
884 enddef
885 eval range(from, to)
886 ->Increment()
887 assert_equal(111 + 3 + 4 + 5, g:val)
888 unlet g:val
Bram Moolenaard0fe6202020-12-05 17:11:12 +0100889
890 var lines =<< trim END
891 vim9script
892 g:caught = 'no'
893 try
894 eval 123 || 0
895 catch
896 g:caught = 'yes'
897 endtry
898 assert_equal('yes', g:caught)
899 unlet g:caught
900 END
901 CheckScriptSuccess(lines)
Bram Moolenaar007f9d62020-07-06 23:04:49 +0200902enddef
903
Bram Moolenaarb8a92962020-08-20 18:02:47 +0200904def Test_map_command()
Bram Moolenaarac564082020-09-27 19:05:33 +0200905 var lines =<< trim END
Bram Moolenaarb8a92962020-08-20 18:02:47 +0200906 nnoremap <F3> :echo 'hit F3 #'<CR>
907 assert_equal(":echo 'hit F3 #'<CR>", maparg("<F3>", "n"))
908 END
909 CheckDefSuccess(lines)
910 CheckScriptSuccess(['vim9script'] + lines)
911enddef
912
Bram Moolenaarb3ea36c2020-08-23 21:46:32 +0200913def Test_normal_command()
914 new
915 setline(1, 'doesnotexist')
Bram Moolenaarac564082020-09-27 19:05:33 +0200916 var caught = 0
Bram Moolenaarb3ea36c2020-08-23 21:46:32 +0200917 try
918 exe "norm! \<C-]>"
919 catch /E433/
920 caught = 2
921 endtry
922 assert_equal(2, caught)
923
924 try
925 exe "norm! 3\<C-]>"
926 catch /E433/
927 caught = 3
928 endtry
929 assert_equal(3, caught)
930 bwipe!
931enddef
932
Bram Moolenaarc3516f72020-09-08 22:45:35 +0200933def Test_put_command()
934 new
935 @p = 'ppp'
936 put p
937 assert_equal('ppp', getline(2))
938
939 put ='below'
940 assert_equal('below', getline(3))
941 put! ='above'
942 assert_equal('above', getline(3))
943 assert_equal('below', getline(4))
944
Bram Moolenaar883cf972021-01-15 18:04:43 +0100945 :2put =['a', 'b', 'c']
946 assert_equal(['ppp', 'a', 'b', 'c', 'above'], getline(2, 6))
947
Bram Moolenaar08597872020-12-10 19:43:40 +0100948 # compute range at runtime
949 setline(1, range(1, 8))
950 @a = 'aaa'
951 :$-2put a
952 assert_equal('aaa', getline(7))
953
954 setline(1, range(1, 8))
955 :2
956 :+2put! a
957 assert_equal('aaa', getline(4))
958
Bram Moolenaara28639e2021-01-19 22:48:09 +0100959 []->mapnew(() => 0)
960 :$put ='end'
961 assert_equal('end', getline('$'))
962
Bram Moolenaarc3516f72020-09-08 22:45:35 +0200963 bwipe!
Bram Moolenaar025cb1c2020-12-14 18:31:27 +0100964
965 CheckDefFailure(['put =xxx'], 'E1001:')
966enddef
967
968def Test_put_with_linebreak()
969 new
970 var lines =<< trim END
971 vim9script
972 pu =split('abc', '\zs')
973 ->join()
974 END
975 CheckScriptSuccess(lines)
976 getline(2)->assert_equal('a b c')
977 bwipe!
Bram Moolenaarc3516f72020-09-08 22:45:35 +0200978enddef
979
Bram Moolenaar3bd8de42020-09-14 16:37:34 +0200980def Test_command_star_range()
981 new
982 setline(1, ['xxx foo xxx', 'xxx bar xxx', 'xxx foo xx bar'])
983 setpos("'<", [0, 1, 0, 0])
984 setpos("'>", [0, 3, 0, 0])
985 :*s/\(foo\|bar\)/baz/g
986 getline(1, 3)->assert_equal(['xxx baz xxx', 'xxx baz xxx', 'xxx baz xx baz'])
987
988 bwipe!
989enddef
990
Bram Moolenaar20d89e02020-10-20 23:11:33 +0200991def Test_f_args()
992 var lines =<< trim END
993 vim9script
994
995 func SaveCmdArgs(...)
996 let g:args = a:000
997 endfunc
998
999 command -nargs=* TestFArgs call SaveCmdArgs(<f-args>)
1000
1001 TestFArgs
1002 assert_equal([], g:args)
1003
1004 TestFArgs one two three
1005 assert_equal(['one', 'two', 'three'], g:args)
1006 END
1007 CheckScriptSuccess(lines)
1008enddef
Bram Moolenaarc3516f72020-09-08 22:45:35 +02001009
Bram Moolenaard1510ee2021-01-04 16:15:58 +01001010def Test_user_command_comment()
1011 command -nargs=1 Comd echom <q-args>
1012
1013 var lines =<< trim END
Bram Moolenaarb98cec22021-04-25 16:35:55 +02001014 vim9script
1015 Comd # comment
Bram Moolenaard1510ee2021-01-04 16:15:58 +01001016 END
1017 CheckScriptSuccess(lines)
1018
1019 lines =<< trim END
Bram Moolenaarb98cec22021-04-25 16:35:55 +02001020 vim9script
1021 Comd# comment
Bram Moolenaard1510ee2021-01-04 16:15:58 +01001022 END
1023 CheckScriptFailure(lines, 'E1144:')
Bram Moolenaard1510ee2021-01-04 16:15:58 +01001024 delcommand Comd
Bram Moolenaarb98cec22021-04-25 16:35:55 +02001025
1026 lines =<< trim END
1027 vim9script
1028 command Foo echo 'Foo'
1029 Foo3Bar
1030 END
1031 CheckScriptFailure(lines, 'E1144: Command "Foo" is not followed by white space: Foo3Bar')
1032
1033 delcommand Foo
Bram Moolenaard1510ee2021-01-04 16:15:58 +01001034enddef
1035
Bram Moolenaar95388e32020-11-20 21:07:00 +01001036def Test_star_command()
1037 var lines =<< trim END
1038 vim9script
1039 @s = 'g:success = 8'
1040 set cpo+=*
1041 exe '*s'
1042 assert_equal(8, g:success)
1043 unlet g:success
1044 set cpo-=*
1045 assert_fails("exe '*s'", 'E1050:')
1046 END
1047 CheckScriptSuccess(lines)
1048enddef
1049
Bram Moolenaar47a2abf2020-11-25 20:12:11 +01001050def Test_cmd_argument_without_colon()
1051 new Xfile
1052 setline(1, ['a', 'b', 'c', 'd'])
1053 write
1054 edit +3 %
1055 assert_equal(3, getcurpos()[1])
1056 edit +/a %
1057 assert_equal(1, getcurpos()[1])
1058 bwipe
1059 delete('Xfile')
1060enddef
1061
Bram Moolenaar1c0aa972020-12-16 21:43:54 +01001062def Test_ambiguous_user_cmd()
Bram Moolenaard1510ee2021-01-04 16:15:58 +01001063 command Cmd1 eval 0
1064 command Cmd2 eval 0
Bram Moolenaar1c0aa972020-12-16 21:43:54 +01001065 var lines =<< trim END
Bram Moolenaar1c0aa972020-12-16 21:43:54 +01001066 Cmd
1067 END
Bram Moolenaard1510ee2021-01-04 16:15:58 +01001068 CheckDefAndScriptFailure(lines, 'E464:', 1)
1069 delcommand Cmd1
1070 delcommand Cmd2
Bram Moolenaar1c0aa972020-12-16 21:43:54 +01001071enddef
1072
Bram Moolenaar52c124d2020-12-20 21:43:35 +01001073def Test_command_not_recognized()
1074 var lines =<< trim END
1075 d.key = 'asdf'
1076 END
1077 CheckDefFailure(lines, 'E1146:', 1)
1078
1079 lines =<< trim END
1080 d['key'] = 'asdf'
1081 END
1082 CheckDefFailure(lines, 'E1146:', 1)
1083enddef
Bram Moolenaarb7a78f72020-06-28 18:43:40 +02001084
Bram Moolenaarf4e20992020-12-21 19:59:08 +01001085def Test_magic_not_used()
1086 new
1087 for cmd in ['set magic', 'set nomagic']
1088 exe cmd
1089 setline(1, 'aaa')
1090 s/.../bbb/
1091 assert_equal('bbb', getline(1))
1092 endfor
1093
1094 set magic
1095 setline(1, 'aaa')
1096 assert_fails('s/.\M../bbb/', 'E486:')
1097 assert_fails('snomagic/.../bbb/', 'E486:')
1098 assert_equal('aaa', getline(1))
1099
1100 bwipe!
1101enddef
1102
Bram Moolenaar60f63102020-12-21 20:32:43 +01001103def Test_gdefault_not_used()
1104 new
1105 for cmd in ['set gdefault', 'set nogdefault']
1106 exe cmd
1107 setline(1, 'aaa')
1108 s/./b/
1109 assert_equal('baa', getline(1))
1110 endfor
1111
1112 set nogdefault
1113 bwipe!
1114enddef
1115
Bram Moolenaar179eb562020-12-27 18:03:22 +01001116def g:SomeComplFunc(findstart: number, base: string): any
1117 if findstart
1118 return 0
1119 else
1120 return ['aaa', 'bbb']
1121 endif
1122enddef
1123
1124def Test_insert_complete()
1125 # this was running into an error with the matchparen hack
1126 new
1127 set completefunc=SomeComplFunc
1128 feedkeys("i\<c-x>\<c-u>\<Esc>", 'ntx')
1129 assert_equal('aaa', getline(1))
1130
1131 set completefunc=
1132 bwipe!
1133enddef
1134
Bram Moolenaara11919f2021-01-02 19:44:56 +01001135def Test_wincmd()
1136 split
1137 var id1 = win_getid()
1138 if true
1139 try | wincmd w | catch | endtry
1140 endif
1141 assert_notequal(id1, win_getid())
1142 close
Bram Moolenaar1ff89de2021-03-24 20:08:12 +01001143
1144 split
1145 var id = win_getid()
1146 split
1147 :2wincmd o
1148 assert_equal(id, win_getid())
1149 only
1150
1151 split
1152 split
1153 assert_equal(3, winnr('$'))
1154 :2wincmd c
1155 assert_equal(2, winnr('$'))
1156 only
1157
1158 split
1159 split
1160 assert_equal(3, winnr('$'))
1161 :2wincmd q
1162 assert_equal(2, winnr('$'))
1163 only
Bram Moolenaara11919f2021-01-02 19:44:56 +01001164enddef
1165
Bram Moolenaar9567efa2021-01-11 22:16:30 +01001166def Test_windo_missing_endif()
1167 var lines =<< trim END
1168 windo if 1
1169 END
1170 CheckDefExecFailure(lines, 'E171:', 1)
1171enddef
1172
Bram Moolenaarb2cb6c82021-03-28 20:38:34 +02001173let s:theList = [1, 2, 3]
1174
1175def Test_lockvar()
1176 s:theList[1] = 22
1177 assert_equal([1, 22, 3], s:theList)
1178 lockvar s:theList
1179 assert_fails('theList[1] = 77', 'E741:')
1180 unlockvar s:theList
1181 s:theList[1] = 44
1182 assert_equal([1, 44, 3], s:theList)
1183
1184 var lines =<< trim END
1185 vim9script
1186 var theList = [1, 2, 3]
1187 def SetList()
1188 theList[1] = 22
1189 assert_equal([1, 22, 3], theList)
1190 lockvar theList
1191 theList[1] = 77
1192 enddef
1193 SetList()
1194 END
1195 CheckScriptFailure(lines, 'E1119', 4)
1196
1197 lines =<< trim END
1198 var theList = [1, 2, 3]
1199 lockvar theList
1200 END
1201 CheckDefFailure(lines, 'E1178', 2)
1202
1203 lines =<< trim END
1204 var theList = [1, 2, 3]
1205 unlockvar theList
1206 END
1207 CheckDefFailure(lines, 'E1178', 2)
1208enddef
1209
Bram Moolenaar4c137212021-04-19 16:48:48 +02001210def Test_substitute_expr()
1211 var to = 'repl'
1212 new
1213 setline(1, 'one from two')
1214 s/from/\=to
1215 assert_equal('one repl two', getline(1))
1216
1217 setline(1, 'one from two')
1218 s/from/\=to .. '_x'
1219 assert_equal('one repl_x two', getline(1))
1220
1221 setline(1, 'one from two from three')
1222 var also = 'also'
1223 s/from/\=to .. '_' .. also/g#e
1224 assert_equal('one repl_also two repl_also three', getline(1))
1225
Bram Moolenaar8238f082021-04-20 21:10:48 +02001226 setline(1, 'abc abc abc')
1227 for choice in [true, false]
1228 :1s/abc/\=choice ? 'yes' : 'no'/
1229 endfor
1230 assert_equal('yes no abc', getline(1))
1231
Bram Moolenaard386e922021-04-25 14:48:49 +02001232 bwipe!
1233
Bram Moolenaar4c137212021-04-19 16:48:48 +02001234 CheckDefFailure(['s/from/\="x")/'], 'E488:')
1235 CheckDefFailure(['s/from/\="x"/9'], 'E488:')
1236
Bram Moolenaard386e922021-04-25 14:48:49 +02001237 # When calling a function the right instruction list needs to be restored.
Bram Moolenaar5930ddc2021-04-26 20:32:59 +02001238 g:cond = true
Bram Moolenaard386e922021-04-25 14:48:49 +02001239 var lines =<< trim END
1240 vim9script
1241 def Foo()
1242 Bar([])
1243 enddef
1244 def Bar(l: list<number>)
Bram Moolenaar5930ddc2021-04-26 20:32:59 +02001245 if g:cond
Bram Moolenaard386e922021-04-25 14:48:49 +02001246 s/^/\=Rep()/
1247 for n in l[:]
1248 endfor
Bram Moolenaar5930ddc2021-04-26 20:32:59 +02001249 endif
Bram Moolenaard386e922021-04-25 14:48:49 +02001250 enddef
1251 def Rep(): string
1252 return 'rep'
1253 enddef
1254 new
1255 Foo()
1256 assert_equal('rep', getline(1))
1257 bwipe!
1258 END
1259 CheckScriptSuccess(lines)
Bram Moolenaar5930ddc2021-04-26 20:32:59 +02001260 unlet g:cond
Bram Moolenaar27523602021-06-05 21:36:19 +02001261
1262 # List results in multiple lines
1263 new
1264 setline(1, 'some text here')
Bram Moolenaar2c707112021-08-02 22:26:56 +02001265 s/text/\=['aaa', 'bbb', 'ccc']/
Bram Moolenaar27523602021-06-05 21:36:19 +02001266 assert_equal(['some aaa', 'bbb', 'ccc', ' here'], getline(1, '$'))
1267 bwipe!
Bram Moolenaar4c137212021-04-19 16:48:48 +02001268enddef
1269
Bram Moolenaar2d1c57e2021-04-19 20:50:03 +02001270def Test_redir_to_var()
1271 var result: string
1272 redir => result
1273 echo 'something'
1274 redir END
1275 assert_equal("\nsomething", result)
1276
1277 redir =>> result
1278 echo 'more'
1279 redir END
1280 assert_equal("\nsomething\nmore", result)
1281
Bram Moolenaar753bcf82021-04-21 14:24:24 +02001282 var d: dict<string>
1283 redir => d.redir
1284 echo 'dict'
1285 redir END
1286 assert_equal({redir: "\ndict"}, d)
1287
1288 var l = ['a', 'b', 'c']
1289 redir => l[1]
1290 echo 'list'
1291 redir END
1292 assert_equal(['a', "\nlist", 'c'], l)
1293
1294 var dl = {l: ['x']}
1295 redir => dl.l[0]
1296 echo 'dict-list'
1297 redir END
1298 assert_equal({l: ["\ndict-list"]}, dl)
1299
Bram Moolenaara369c3d2021-04-21 16:00:10 +02001300 redir =>> d.redir
1301 echo 'more'
1302 redir END
1303 assert_equal({redir: "\ndict\nmore"}, d)
1304
Bram Moolenaar2d1c57e2021-04-19 20:50:03 +02001305 var lines =<< trim END
1306 redir => notexist
1307 END
1308 CheckDefFailure(lines, 'E1089:')
Bram Moolenaar753bcf82021-04-21 14:24:24 +02001309
1310 lines =<< trim END
1311 var ls = 'asdf'
1312 redir => ls[1]
1313 redir END
1314 END
1315 CheckDefFailure(lines, 'E1141:')
Bram Moolenaar2d1c57e2021-04-19 20:50:03 +02001316enddef
1317
Bram Moolenaar68db9962021-05-09 23:19:22 +02001318def Test_echo_void()
1319 var lines =<< trim END
1320 vim9script
1321 def NoReturn()
1322 echo 'nothing'
1323 enddef
1324 echo NoReturn()
1325 END
1326 CheckScriptFailure(lines, 'E1186:', 5)
1327
1328 lines =<< trim END
1329 vim9script
1330 def NoReturn()
1331 echo 'nothing'
1332 enddef
1333 def Try()
1334 echo NoReturn()
1335 enddef
1336 defcompile
1337 END
1338 CheckScriptFailure(lines, 'E1186:', 1)
1339enddef
1340
Bram Moolenaar2c707112021-08-02 22:26:56 +02001341def Test_cmdwin_block()
1342 augroup justTesting
1343 autocmd BufEnter * {
1344 echomsg 'in block'
1345 }
1346 augroup END
1347 feedkeys('q:', 'xt')
1348 redraw
1349 feedkeys("aclose\<CR>", 'xt')
1350
1351 au! justTesting
1352enddef
1353
Bram Moolenaarb2cb6c82021-03-28 20:38:34 +02001354
Bram Moolenaarcfe435d2020-04-25 20:02:55 +02001355" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker