blob: 7ec43e9d58c298ceb04b7341b1e0ae86f9faddef [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 Moolenaar917c46a2021-08-10 19:53:01 +0200810
811 var lines =<< trim END
812 vim9script
813 set history=11
814 silent! while 0
815 set history=22
816 silent! endwhile
817 assert_equal(11, &history)
818 set history&
819 END
820 CheckScriptSuccess(lines)
Bram Moolenaare88c8e82020-11-01 17:03:37 +0100821enddef
822
Bram Moolenaar36113e42020-11-02 21:08:47 +0100823def Test_range_after_command_modifier()
Bram Moolenaar6e2c2c52020-12-25 19:25:45 +0100824 CheckScriptFailure(['vim9script', 'silent keepjump 1d _'], 'E1050: Colon required before a range: 1d _', 2)
Bram Moolenaar36113e42020-11-02 21:08:47 +0100825 new
826 setline(1, 'xxx')
827 CheckScriptSuccess(['vim9script', 'silent keepjump :1d _'])
828 assert_equal('', getline(1))
829 bwipe!
830enddef
831
Bram Moolenaarece0b872021-01-08 20:40:45 +0100832def Test_silent_pattern()
833 new
834 silent! :/pat/put _
835 bwipe!
836enddef
837
Bram Moolenaarfa984412021-03-25 22:15:28 +0100838def Test_useless_command_modifier()
839 g:maybe = true
840 var lines =<< trim END
841 if g:maybe
842 silent endif
843 END
844 CheckDefAndScriptFailure(lines, 'E1176:', 2)
845
846 lines =<< trim END
847 for i in [0]
848 silent endfor
849 END
Bram Moolenaar917c46a2021-08-10 19:53:01 +0200850 CheckDefFailure(lines, 'E1176:', 2)
851 CheckScriptSuccess(['vim9script'] + lines)
Bram Moolenaarfa984412021-03-25 22:15:28 +0100852
853 lines =<< trim END
854 while g:maybe
855 silent endwhile
856 END
Bram Moolenaar917c46a2021-08-10 19:53:01 +0200857 CheckDefFailure(lines, 'E1176:', 2)
858 g:maybe = false
859 CheckScriptSuccess(['vim9script'] + lines)
Bram Moolenaarfa984412021-03-25 22:15:28 +0100860
861 lines =<< trim END
862 silent try
863 finally
864 endtry
865 END
866 CheckDefAndScriptFailure(lines, 'E1176:', 1)
867
868 lines =<< trim END
869 try
870 silent catch
871 endtry
872 END
873 CheckDefAndScriptFailure(lines, 'E1176:', 2)
874
875 lines =<< trim END
876 try
877 silent finally
878 endtry
879 END
880 CheckDefAndScriptFailure(lines, 'E1176:', 2)
881
882 lines =<< trim END
883 try
884 finally
885 silent endtry
886 END
887 CheckDefAndScriptFailure(lines, 'E1176:', 3)
888enddef
889
Bram Moolenaar007f9d62020-07-06 23:04:49 +0200890def Test_eval_command()
Bram Moolenaarac564082020-09-27 19:05:33 +0200891 var from = 3
892 var to = 5
Bram Moolenaar007f9d62020-07-06 23:04:49 +0200893 g:val = 111
894 def Increment(nrs: list<number>)
895 for nr in nrs
896 g:val += nr
897 endfor
898 enddef
899 eval range(from, to)
900 ->Increment()
901 assert_equal(111 + 3 + 4 + 5, g:val)
902 unlet g:val
Bram Moolenaard0fe6202020-12-05 17:11:12 +0100903
904 var lines =<< trim END
905 vim9script
906 g:caught = 'no'
907 try
908 eval 123 || 0
909 catch
910 g:caught = 'yes'
911 endtry
912 assert_equal('yes', g:caught)
913 unlet g:caught
914 END
915 CheckScriptSuccess(lines)
Bram Moolenaar007f9d62020-07-06 23:04:49 +0200916enddef
917
Bram Moolenaarb8a92962020-08-20 18:02:47 +0200918def Test_map_command()
Bram Moolenaarac564082020-09-27 19:05:33 +0200919 var lines =<< trim END
Bram Moolenaarb8a92962020-08-20 18:02:47 +0200920 nnoremap <F3> :echo 'hit F3 #'<CR>
921 assert_equal(":echo 'hit F3 #'<CR>", maparg("<F3>", "n"))
922 END
923 CheckDefSuccess(lines)
924 CheckScriptSuccess(['vim9script'] + lines)
925enddef
926
Bram Moolenaarb3ea36c2020-08-23 21:46:32 +0200927def Test_normal_command()
928 new
929 setline(1, 'doesnotexist')
Bram Moolenaarac564082020-09-27 19:05:33 +0200930 var caught = 0
Bram Moolenaarb3ea36c2020-08-23 21:46:32 +0200931 try
932 exe "norm! \<C-]>"
933 catch /E433/
934 caught = 2
935 endtry
936 assert_equal(2, caught)
937
938 try
939 exe "norm! 3\<C-]>"
940 catch /E433/
941 caught = 3
942 endtry
943 assert_equal(3, caught)
944 bwipe!
945enddef
946
Bram Moolenaarc3516f72020-09-08 22:45:35 +0200947def Test_put_command()
948 new
949 @p = 'ppp'
950 put p
951 assert_equal('ppp', getline(2))
952
953 put ='below'
954 assert_equal('below', getline(3))
955 put! ='above'
956 assert_equal('above', getline(3))
957 assert_equal('below', getline(4))
958
Bram Moolenaar883cf972021-01-15 18:04:43 +0100959 :2put =['a', 'b', 'c']
960 assert_equal(['ppp', 'a', 'b', 'c', 'above'], getline(2, 6))
961
Bram Moolenaar08597872020-12-10 19:43:40 +0100962 # compute range at runtime
963 setline(1, range(1, 8))
964 @a = 'aaa'
965 :$-2put a
966 assert_equal('aaa', getline(7))
967
968 setline(1, range(1, 8))
969 :2
970 :+2put! a
971 assert_equal('aaa', getline(4))
972
Bram Moolenaara28639e2021-01-19 22:48:09 +0100973 []->mapnew(() => 0)
974 :$put ='end'
975 assert_equal('end', getline('$'))
976
Bram Moolenaarc3516f72020-09-08 22:45:35 +0200977 bwipe!
Bram Moolenaar025cb1c2020-12-14 18:31:27 +0100978
979 CheckDefFailure(['put =xxx'], 'E1001:')
980enddef
981
982def Test_put_with_linebreak()
983 new
984 var lines =<< trim END
985 vim9script
986 pu =split('abc', '\zs')
987 ->join()
988 END
989 CheckScriptSuccess(lines)
990 getline(2)->assert_equal('a b c')
991 bwipe!
Bram Moolenaarc3516f72020-09-08 22:45:35 +0200992enddef
993
Bram Moolenaar3bd8de42020-09-14 16:37:34 +0200994def Test_command_star_range()
995 new
996 setline(1, ['xxx foo xxx', 'xxx bar xxx', 'xxx foo xx bar'])
997 setpos("'<", [0, 1, 0, 0])
998 setpos("'>", [0, 3, 0, 0])
999 :*s/\(foo\|bar\)/baz/g
1000 getline(1, 3)->assert_equal(['xxx baz xxx', 'xxx baz xxx', 'xxx baz xx baz'])
1001
1002 bwipe!
1003enddef
1004
Bram Moolenaar20d89e02020-10-20 23:11:33 +02001005def Test_f_args()
1006 var lines =<< trim END
1007 vim9script
1008
1009 func SaveCmdArgs(...)
1010 let g:args = a:000
1011 endfunc
1012
1013 command -nargs=* TestFArgs call SaveCmdArgs(<f-args>)
1014
1015 TestFArgs
1016 assert_equal([], g:args)
1017
1018 TestFArgs one two three
1019 assert_equal(['one', 'two', 'three'], g:args)
1020 END
1021 CheckScriptSuccess(lines)
1022enddef
Bram Moolenaarc3516f72020-09-08 22:45:35 +02001023
Bram Moolenaard1510ee2021-01-04 16:15:58 +01001024def Test_user_command_comment()
1025 command -nargs=1 Comd echom <q-args>
1026
1027 var lines =<< trim END
Bram Moolenaarb98cec22021-04-25 16:35:55 +02001028 vim9script
1029 Comd # comment
Bram Moolenaard1510ee2021-01-04 16:15:58 +01001030 END
1031 CheckScriptSuccess(lines)
1032
1033 lines =<< trim END
Bram Moolenaarb98cec22021-04-25 16:35:55 +02001034 vim9script
1035 Comd# comment
Bram Moolenaard1510ee2021-01-04 16:15:58 +01001036 END
1037 CheckScriptFailure(lines, 'E1144:')
Bram Moolenaard1510ee2021-01-04 16:15:58 +01001038 delcommand Comd
Bram Moolenaarb98cec22021-04-25 16:35:55 +02001039
1040 lines =<< trim END
1041 vim9script
1042 command Foo echo 'Foo'
1043 Foo3Bar
1044 END
1045 CheckScriptFailure(lines, 'E1144: Command "Foo" is not followed by white space: Foo3Bar')
1046
1047 delcommand Foo
Bram Moolenaard1510ee2021-01-04 16:15:58 +01001048enddef
1049
Bram Moolenaar95388e32020-11-20 21:07:00 +01001050def Test_star_command()
1051 var lines =<< trim END
1052 vim9script
1053 @s = 'g:success = 8'
1054 set cpo+=*
1055 exe '*s'
1056 assert_equal(8, g:success)
1057 unlet g:success
1058 set cpo-=*
1059 assert_fails("exe '*s'", 'E1050:')
1060 END
1061 CheckScriptSuccess(lines)
1062enddef
1063
Bram Moolenaar47a2abf2020-11-25 20:12:11 +01001064def Test_cmd_argument_without_colon()
1065 new Xfile
1066 setline(1, ['a', 'b', 'c', 'd'])
1067 write
1068 edit +3 %
1069 assert_equal(3, getcurpos()[1])
1070 edit +/a %
1071 assert_equal(1, getcurpos()[1])
1072 bwipe
1073 delete('Xfile')
1074enddef
1075
Bram Moolenaar1c0aa972020-12-16 21:43:54 +01001076def Test_ambiguous_user_cmd()
Bram Moolenaard1510ee2021-01-04 16:15:58 +01001077 command Cmd1 eval 0
1078 command Cmd2 eval 0
Bram Moolenaar1c0aa972020-12-16 21:43:54 +01001079 var lines =<< trim END
Bram Moolenaar1c0aa972020-12-16 21:43:54 +01001080 Cmd
1081 END
Bram Moolenaard1510ee2021-01-04 16:15:58 +01001082 CheckDefAndScriptFailure(lines, 'E464:', 1)
1083 delcommand Cmd1
1084 delcommand Cmd2
Bram Moolenaar1c0aa972020-12-16 21:43:54 +01001085enddef
1086
Bram Moolenaar52c124d2020-12-20 21:43:35 +01001087def Test_command_not_recognized()
1088 var lines =<< trim END
1089 d.key = 'asdf'
1090 END
1091 CheckDefFailure(lines, 'E1146:', 1)
1092
1093 lines =<< trim END
1094 d['key'] = 'asdf'
1095 END
1096 CheckDefFailure(lines, 'E1146:', 1)
1097enddef
Bram Moolenaarb7a78f72020-06-28 18:43:40 +02001098
Bram Moolenaarf4e20992020-12-21 19:59:08 +01001099def Test_magic_not_used()
1100 new
1101 for cmd in ['set magic', 'set nomagic']
1102 exe cmd
1103 setline(1, 'aaa')
1104 s/.../bbb/
1105 assert_equal('bbb', getline(1))
1106 endfor
1107
1108 set magic
1109 setline(1, 'aaa')
1110 assert_fails('s/.\M../bbb/', 'E486:')
1111 assert_fails('snomagic/.../bbb/', 'E486:')
1112 assert_equal('aaa', getline(1))
1113
1114 bwipe!
1115enddef
1116
Bram Moolenaar60f63102020-12-21 20:32:43 +01001117def Test_gdefault_not_used()
1118 new
1119 for cmd in ['set gdefault', 'set nogdefault']
1120 exe cmd
1121 setline(1, 'aaa')
1122 s/./b/
1123 assert_equal('baa', getline(1))
1124 endfor
1125
1126 set nogdefault
1127 bwipe!
1128enddef
1129
Bram Moolenaar179eb562020-12-27 18:03:22 +01001130def g:SomeComplFunc(findstart: number, base: string): any
1131 if findstart
1132 return 0
1133 else
1134 return ['aaa', 'bbb']
1135 endif
1136enddef
1137
1138def Test_insert_complete()
1139 # this was running into an error with the matchparen hack
1140 new
1141 set completefunc=SomeComplFunc
1142 feedkeys("i\<c-x>\<c-u>\<Esc>", 'ntx')
1143 assert_equal('aaa', getline(1))
1144
1145 set completefunc=
1146 bwipe!
1147enddef
1148
Bram Moolenaara11919f2021-01-02 19:44:56 +01001149def Test_wincmd()
1150 split
1151 var id1 = win_getid()
1152 if true
1153 try | wincmd w | catch | endtry
1154 endif
1155 assert_notequal(id1, win_getid())
1156 close
Bram Moolenaar1ff89de2021-03-24 20:08:12 +01001157
1158 split
1159 var id = win_getid()
1160 split
1161 :2wincmd o
1162 assert_equal(id, win_getid())
1163 only
1164
1165 split
1166 split
1167 assert_equal(3, winnr('$'))
1168 :2wincmd c
1169 assert_equal(2, winnr('$'))
1170 only
1171
1172 split
1173 split
1174 assert_equal(3, winnr('$'))
1175 :2wincmd q
1176 assert_equal(2, winnr('$'))
1177 only
Bram Moolenaara11919f2021-01-02 19:44:56 +01001178enddef
1179
Bram Moolenaar9567efa2021-01-11 22:16:30 +01001180def Test_windo_missing_endif()
1181 var lines =<< trim END
1182 windo if 1
1183 END
1184 CheckDefExecFailure(lines, 'E171:', 1)
1185enddef
1186
Bram Moolenaarb2cb6c82021-03-28 20:38:34 +02001187let s:theList = [1, 2, 3]
1188
1189def Test_lockvar()
1190 s:theList[1] = 22
1191 assert_equal([1, 22, 3], s:theList)
1192 lockvar s:theList
1193 assert_fails('theList[1] = 77', 'E741:')
1194 unlockvar s:theList
1195 s:theList[1] = 44
1196 assert_equal([1, 44, 3], s:theList)
1197
Bram Moolenaaraacc9662021-08-13 19:40:51 +02001198 var d = {a: 1, b: 2}
1199 d.a = 3
1200 d.b = 4
1201 assert_equal({a: 3, b: 4}, d)
1202 lockvar d.a
1203 d.b = 5
1204 var ex = ''
1205 try
1206 d.a = 6
1207 catch
1208 ex = v:exception
1209 endtry
1210 assert_match('E1121:', ex)
1211 unlockvar d.a
1212 d.a = 7
1213 assert_equal({a: 7, b: 5}, d)
1214
Bram Moolenaarb2cb6c82021-03-28 20:38:34 +02001215 var lines =<< trim END
1216 vim9script
1217 var theList = [1, 2, 3]
1218 def SetList()
1219 theList[1] = 22
1220 assert_equal([1, 22, 3], theList)
1221 lockvar theList
1222 theList[1] = 77
1223 enddef
1224 SetList()
1225 END
1226 CheckScriptFailure(lines, 'E1119', 4)
1227
1228 lines =<< trim END
1229 var theList = [1, 2, 3]
1230 lockvar theList
1231 END
1232 CheckDefFailure(lines, 'E1178', 2)
1233
1234 lines =<< trim END
1235 var theList = [1, 2, 3]
1236 unlockvar theList
1237 END
1238 CheckDefFailure(lines, 'E1178', 2)
1239enddef
1240
Bram Moolenaar4c137212021-04-19 16:48:48 +02001241def Test_substitute_expr()
1242 var to = 'repl'
1243 new
1244 setline(1, 'one from two')
1245 s/from/\=to
1246 assert_equal('one repl two', getline(1))
1247
1248 setline(1, 'one from two')
1249 s/from/\=to .. '_x'
1250 assert_equal('one repl_x two', getline(1))
1251
1252 setline(1, 'one from two from three')
1253 var also = 'also'
1254 s/from/\=to .. '_' .. also/g#e
1255 assert_equal('one repl_also two repl_also three', getline(1))
1256
Bram Moolenaar8238f082021-04-20 21:10:48 +02001257 setline(1, 'abc abc abc')
1258 for choice in [true, false]
1259 :1s/abc/\=choice ? 'yes' : 'no'/
1260 endfor
1261 assert_equal('yes no abc', getline(1))
1262
Bram Moolenaard386e922021-04-25 14:48:49 +02001263 bwipe!
1264
Bram Moolenaar4c137212021-04-19 16:48:48 +02001265 CheckDefFailure(['s/from/\="x")/'], 'E488:')
1266 CheckDefFailure(['s/from/\="x"/9'], 'E488:')
1267
Bram Moolenaard386e922021-04-25 14:48:49 +02001268 # When calling a function the right instruction list needs to be restored.
Bram Moolenaar5930ddc2021-04-26 20:32:59 +02001269 g:cond = true
Bram Moolenaard386e922021-04-25 14:48:49 +02001270 var lines =<< trim END
1271 vim9script
1272 def Foo()
1273 Bar([])
1274 enddef
1275 def Bar(l: list<number>)
Bram Moolenaar5930ddc2021-04-26 20:32:59 +02001276 if g:cond
Bram Moolenaard386e922021-04-25 14:48:49 +02001277 s/^/\=Rep()/
1278 for n in l[:]
1279 endfor
Bram Moolenaar5930ddc2021-04-26 20:32:59 +02001280 endif
Bram Moolenaard386e922021-04-25 14:48:49 +02001281 enddef
1282 def Rep(): string
1283 return 'rep'
1284 enddef
1285 new
1286 Foo()
1287 assert_equal('rep', getline(1))
1288 bwipe!
1289 END
1290 CheckScriptSuccess(lines)
Bram Moolenaar5930ddc2021-04-26 20:32:59 +02001291 unlet g:cond
Bram Moolenaar27523602021-06-05 21:36:19 +02001292
1293 # List results in multiple lines
1294 new
1295 setline(1, 'some text here')
Bram Moolenaar2c707112021-08-02 22:26:56 +02001296 s/text/\=['aaa', 'bbb', 'ccc']/
Bram Moolenaar27523602021-06-05 21:36:19 +02001297 assert_equal(['some aaa', 'bbb', 'ccc', ' here'], getline(1, '$'))
1298 bwipe!
Bram Moolenaar4c137212021-04-19 16:48:48 +02001299enddef
1300
Bram Moolenaar2d1c57e2021-04-19 20:50:03 +02001301def Test_redir_to_var()
1302 var result: string
1303 redir => result
1304 echo 'something'
1305 redir END
1306 assert_equal("\nsomething", result)
1307
1308 redir =>> result
1309 echo 'more'
1310 redir END
1311 assert_equal("\nsomething\nmore", result)
1312
Bram Moolenaar753bcf82021-04-21 14:24:24 +02001313 var d: dict<string>
1314 redir => d.redir
1315 echo 'dict'
1316 redir END
1317 assert_equal({redir: "\ndict"}, d)
1318
1319 var l = ['a', 'b', 'c']
1320 redir => l[1]
1321 echo 'list'
1322 redir END
1323 assert_equal(['a', "\nlist", 'c'], l)
1324
1325 var dl = {l: ['x']}
1326 redir => dl.l[0]
1327 echo 'dict-list'
1328 redir END
1329 assert_equal({l: ["\ndict-list"]}, dl)
1330
Bram Moolenaara369c3d2021-04-21 16:00:10 +02001331 redir =>> d.redir
1332 echo 'more'
1333 redir END
1334 assert_equal({redir: "\ndict\nmore"}, d)
1335
Bram Moolenaar2d1c57e2021-04-19 20:50:03 +02001336 var lines =<< trim END
1337 redir => notexist
1338 END
1339 CheckDefFailure(lines, 'E1089:')
Bram Moolenaar753bcf82021-04-21 14:24:24 +02001340
1341 lines =<< trim END
1342 var ls = 'asdf'
1343 redir => ls[1]
1344 redir END
1345 END
1346 CheckDefFailure(lines, 'E1141:')
Bram Moolenaar2d1c57e2021-04-19 20:50:03 +02001347enddef
1348
Bram Moolenaar68db9962021-05-09 23:19:22 +02001349def Test_echo_void()
1350 var lines =<< trim END
1351 vim9script
1352 def NoReturn()
1353 echo 'nothing'
1354 enddef
1355 echo NoReturn()
1356 END
1357 CheckScriptFailure(lines, 'E1186:', 5)
1358
1359 lines =<< trim END
1360 vim9script
1361 def NoReturn()
1362 echo 'nothing'
1363 enddef
1364 def Try()
1365 echo NoReturn()
1366 enddef
1367 defcompile
1368 END
1369 CheckScriptFailure(lines, 'E1186:', 1)
1370enddef
1371
Bram Moolenaar2c707112021-08-02 22:26:56 +02001372def Test_cmdwin_block()
1373 augroup justTesting
1374 autocmd BufEnter * {
1375 echomsg 'in block'
1376 }
1377 augroup END
1378 feedkeys('q:', 'xt')
1379 redraw
1380 feedkeys("aclose\<CR>", 'xt')
1381
1382 au! justTesting
1383enddef
1384
Bram Moolenaarb2cb6c82021-03-28 20:38:34 +02001385
Bram Moolenaarcfe435d2020-04-25 20:02:55 +02001386" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker