blob: 49bb8739f89550cbdf32b1dfcd4c511ed21d8f0b [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 Moolenaar2596a4e2021-08-14 21:35:40 +020017 assert_fails('vim9cmd echo "con" . "cat"', 'E15:')
Bram Moolenaar678b2072021-07-26 21:10:11 +020018
19 lines =<< trim END
20 vim9script
21 def Foo()
22 g:found_bar = "bar"
23 enddef
24 nmap ,; :vim9cmd <SID>Foo()<CR>
25 END
26 CheckScriptSuccess(lines)
27 feedkeys(',;', 'xt')
28 assert_equal("bar", g:found_bar)
29
30 nunmap ,;
31 unlet g:found_bar
Bram Moolenaar39f3b142021-02-14 12:57:36 +010032enddef
33
Bram Moolenaarcfe435d2020-04-25 20:02:55 +020034def Test_edit_wildcards()
Bram Moolenaarac564082020-09-27 19:05:33 +020035 var filename = 'Xtest'
Bram Moolenaarcfe435d2020-04-25 20:02:55 +020036 edit `=filename`
37 assert_equal('Xtest', bufname())
38
Bram Moolenaarac564082020-09-27 19:05:33 +020039 var filenr = 123
Bram Moolenaarcfe435d2020-04-25 20:02:55 +020040 edit Xtest`=filenr`
41 assert_equal('Xtest123', bufname())
42
43 filenr = 77
44 edit `=filename``=filenr`
45 assert_equal('Xtest77', bufname())
46
47 edit X`=filename`xx`=filenr`yy
48 assert_equal('XXtestxx77yy', bufname())
Bram Moolenaar025cb1c2020-12-14 18:31:27 +010049
50 CheckDefFailure(['edit `=xxx`'], 'E1001:')
51 CheckDefFailure(['edit `="foo"'], 'E1083:')
Bram Moolenaarb288ba92021-06-05 17:10:55 +020052
53 var files = ['file 1', 'file%2', 'file# 3']
54 args `=files`
55 assert_equal(files, argv())
Bram Moolenaarcfe435d2020-04-25 20:02:55 +020056enddef
57
Bram Moolenaar4389f9c2020-12-27 16:55:11 +010058def Test_expand_alternate_file()
59 var lines =<< trim END
60 edit Xfileone
61 var bone = bufnr()
62 edit Xfiletwo
63 var btwo = bufnr()
64 edit Xfilethree
65 var bthree = bufnr()
66
67 edit #
68 assert_equal(bthree, bufnr())
69 edit %%
70 assert_equal(btwo, bufnr())
71 edit %% # comment
72 assert_equal(bthree, bufnr())
73 edit %%yy
74 assert_equal('Xfiletwoyy', bufname())
75
76 exe "edit %%" .. bone
77 assert_equal(bone, bufnr())
78 exe "edit %%" .. btwo .. "xx"
79 assert_equal('Xfiletwoxx', bufname())
80
81 next Xfileone Xfiletwo Xfilethree
82 assert_equal('Xfileone', argv(0))
83 assert_equal('Xfiletwo', argv(1))
84 assert_equal('Xfilethree', argv(2))
85 next %%%zz
86 assert_equal('Xfileone', argv(0))
87 assert_equal('Xfiletwo', argv(1))
88 assert_equal('Xfilethreezz', argv(2))
89
90 v:oldfiles = ['Xonefile', 'Xtwofile']
91 edit %%<1
92 assert_equal('Xonefile', bufname())
93 edit %%<2
94 assert_equal('Xtwofile', bufname())
95 assert_fails('edit %%<3', 'E684:')
96
97 edit Xfileone.vim
98 edit Xfiletwo
99 edit %%:r
100 assert_equal('Xfileone', bufname())
Bram Moolenaardfbc5fd2021-01-23 15:15:01 +0100101
102 assert_false(bufexists('altfoo'))
103 edit altfoo
104 edit bar
105 assert_true(bufexists('altfoo'))
106 assert_true(buflisted('altfoo'))
107 bdel %%
108 assert_true(bufexists('altfoo'))
109 assert_false(buflisted('altfoo'))
110 bwipe! altfoo
111 bwipe! bar
Bram Moolenaar4389f9c2020-12-27 16:55:11 +0100112 END
113 CheckDefAndScriptSuccess(lines)
114enddef
115
Bram Moolenaar56ce9ea2020-12-25 18:35:29 +0100116def Test_global_backtick_expansion()
117 new
118 setline(1, 'xx')
119 var name = 'foobar'
120 g/^xx/s/.*/`=name`
121 assert_equal('foobar', getline(1))
122 bwipe!
123enddef
124
Bram Moolenaarecac5912021-01-05 19:23:28 +0100125def Test_folddo_backtick_expansion()
126 new
127 var name = 'xxx'
128 folddoopen edit `=name`
129 assert_equal('xxx', bufname())
130 bwipe!
131
132 new
133 setline(1, ['one', 'two'])
134 set nomodified
135 :1,2fold
136 foldclose
137 folddoclose edit `=name`
138 assert_equal('xxx', bufname())
139 bwipe!
140enddef
141
Bram Moolenaar6378c4f2020-04-26 13:50:41 +0200142def Test_hardcopy_wildcards()
143 CheckUnix
144 CheckFeature postscript
145
Bram Moolenaarac564082020-09-27 19:05:33 +0200146 var outfile = 'print'
Bram Moolenaar6378c4f2020-04-26 13:50:41 +0200147 hardcopy > X`=outfile`.ps
148 assert_true(filereadable('Xprint.ps'))
149
150 delete('Xprint.ps')
151enddef
152
153def Test_syn_include_wildcards()
154 writefile(['syn keyword Found found'], 'Xthemine.vim')
Bram Moolenaarac564082020-09-27 19:05:33 +0200155 var save_rtp = &rtp
Bram Moolenaar6378c4f2020-04-26 13:50:41 +0200156 &rtp = '.'
157
Bram Moolenaarac564082020-09-27 19:05:33 +0200158 var fname = 'mine'
Bram Moolenaar6378c4f2020-04-26 13:50:41 +0200159 syn include @Group Xthe`=fname`.vim
160 assert_match('Found.* contained found', execute('syn list Found'))
161
162 &rtp = save_rtp
163 delete('Xthemine.vim')
164enddef
165
Bram Moolenaar7e8967f2020-06-27 21:56:17 +0200166def Test_echo_linebreak()
Bram Moolenaarac564082020-09-27 19:05:33 +0200167 var lines =<< trim END
Bram Moolenaar7e8967f2020-06-27 21:56:17 +0200168 vim9script
169 redir @a
170 echo 'one'
171 .. 'two'
172 redir END
173 assert_equal("\nonetwo", @a)
174 END
175 CheckScriptSuccess(lines)
176
177 lines =<< trim END
178 vim9script
179 redir @a
180 echo 11 +
181 77
182 - 22
183 redir END
184 assert_equal("\n66", @a)
185 END
186 CheckScriptSuccess(lines)
187enddef
188
Bram Moolenaar13106602020-10-04 16:06:05 +0200189def Test_condition_types()
190 var lines =<< trim END
191 if 'text'
192 endif
193 END
Bram Moolenaarea2d4072020-11-12 12:08:51 +0100194 CheckDefAndScriptFailure(lines, 'E1135:', 1)
Bram Moolenaar13106602020-10-04 16:06:05 +0200195
196 lines =<< trim END
197 if [1]
198 endif
199 END
200 CheckDefFailure(lines, 'E1012:', 1)
201 CheckScriptFailure(['vim9script'] + lines, 'E745:', 2)
202
203 lines =<< trim END
204 g:cond = 'text'
205 if g:cond
206 endif
207 END
Bram Moolenaarea2d4072020-11-12 12:08:51 +0100208 CheckDefExecAndScriptFailure(lines, 'E1135:', 2)
Bram Moolenaar13106602020-10-04 16:06:05 +0200209
210 lines =<< trim END
211 g:cond = 0
212 if g:cond
213 elseif 'text'
214 endif
215 END
216 CheckDefFailure(lines, 'E1012:', 3)
Bram Moolenaarea2d4072020-11-12 12:08:51 +0100217 CheckScriptFailure(['vim9script'] + lines, 'E1135:', 4)
Bram Moolenaar13106602020-10-04 16:06:05 +0200218
219 lines =<< trim END
220 if g:cond
221 elseif [1]
222 endif
223 END
224 CheckDefFailure(lines, 'E1012:', 2)
225 CheckScriptFailure(['vim9script'] + lines, 'E745:', 3)
226
227 lines =<< trim END
228 g:cond = 'text'
229 if 0
230 elseif g:cond
231 endif
232 END
Bram Moolenaarea2d4072020-11-12 12:08:51 +0100233 CheckDefExecAndScriptFailure(lines, 'E1135:', 3)
Bram Moolenaar13106602020-10-04 16:06:05 +0200234
235 lines =<< trim END
236 while 'text'
237 endwhile
238 END
239 CheckDefFailure(lines, 'E1012:', 1)
Bram Moolenaarea2d4072020-11-12 12:08:51 +0100240 CheckScriptFailure(['vim9script'] + lines, 'E1135:', 2)
Bram Moolenaar13106602020-10-04 16:06:05 +0200241
242 lines =<< trim END
243 while [1]
244 endwhile
245 END
246 CheckDefFailure(lines, 'E1012:', 1)
247 CheckScriptFailure(['vim9script'] + lines, 'E745:', 2)
248
249 lines =<< trim END
250 g:cond = 'text'
251 while g:cond
252 endwhile
253 END
Bram Moolenaarea2d4072020-11-12 12:08:51 +0100254 CheckDefExecAndScriptFailure(lines, 'E1135:', 2)
Bram Moolenaar13106602020-10-04 16:06:05 +0200255enddef
256
Bram Moolenaarfaf86262020-06-27 23:07:36 +0200257def Test_if_linebreak()
Bram Moolenaarac564082020-09-27 19:05:33 +0200258 var lines =<< trim END
Bram Moolenaarfaf86262020-06-27 23:07:36 +0200259 vim9script
260 if 1 &&
Bram Moolenaar2bb26582020-10-03 22:52:39 +0200261 true
262 || 1
Bram Moolenaarfaf86262020-06-27 23:07:36 +0200263 g:res = 42
264 endif
265 assert_equal(42, g:res)
266 END
267 CheckScriptSuccess(lines)
268 unlet g:res
269
270 lines =<< trim END
271 vim9script
272 if 1 &&
273 0
274 g:res = 0
275 elseif 0 ||
276 0
277 || 1
278 g:res = 12
279 endif
280 assert_equal(12, g:res)
281 END
282 CheckScriptSuccess(lines)
283 unlet g:res
284enddef
285
286def Test_while_linebreak()
Bram Moolenaarac564082020-09-27 19:05:33 +0200287 var lines =<< trim END
Bram Moolenaarfaf86262020-06-27 23:07:36 +0200288 vim9script
Bram Moolenaarac564082020-09-27 19:05:33 +0200289 var nr = 0
Bram Moolenaard5053d02020-06-28 15:51:16 +0200290 while nr <
291 10 + 3
292 nr = nr
293 + 4
294 endwhile
295 assert_equal(16, nr)
296 END
297 CheckScriptSuccess(lines)
298
299 lines =<< trim END
300 vim9script
Bram Moolenaarac564082020-09-27 19:05:33 +0200301 var nr = 0
Bram Moolenaard5053d02020-06-28 15:51:16 +0200302 while nr
303 <
304 10
305 +
306 3
307 nr = nr
308 +
309 4
Bram Moolenaarfaf86262020-06-27 23:07:36 +0200310 endwhile
311 assert_equal(16, nr)
312 END
313 CheckScriptSuccess(lines)
314enddef
Bram Moolenaarcfe435d2020-04-25 20:02:55 +0200315
Bram Moolenaarb7a78f72020-06-28 18:43:40 +0200316def Test_for_linebreak()
Bram Moolenaarac564082020-09-27 19:05:33 +0200317 var lines =<< trim END
Bram Moolenaarb7a78f72020-06-28 18:43:40 +0200318 vim9script
Bram Moolenaarac564082020-09-27 19:05:33 +0200319 var nr = 0
Bram Moolenaarb7a78f72020-06-28 18:43:40 +0200320 for x
321 in
322 [1, 2, 3, 4]
323 nr = nr + x
324 endfor
325 assert_equal(10, nr)
326 END
327 CheckScriptSuccess(lines)
328
329 lines =<< trim END
330 vim9script
Bram Moolenaarac564082020-09-27 19:05:33 +0200331 var nr = 0
Bram Moolenaarb7a78f72020-06-28 18:43:40 +0200332 for x
333 in
334 [1, 2,
335 3, 4
336 ]
337 nr = nr
338 +
339 x
340 endfor
341 assert_equal(10, nr)
342 END
343 CheckScriptSuccess(lines)
344enddef
345
Bram Moolenaare0890d62021-02-17 14:52:14 +0100346def MethodAfterLinebreak(arg: string)
347 arg
348 ->setline(1)
349enddef
350
Bram Moolenaard2ef6b32020-07-02 21:11:34 +0200351def Test_method_call_linebreak()
Bram Moolenaarac564082020-09-27 19:05:33 +0200352 var lines =<< trim END
Bram Moolenaar5f195932020-07-01 20:07:14 +0200353 vim9script
Bram Moolenaarac564082020-09-27 19:05:33 +0200354 var res = []
Bram Moolenaar5f195932020-07-01 20:07:14 +0200355 func RetArg(
356 arg
357 )
358 let s:res = a:arg
359 endfunc
360 [1,
361 2,
362 3]->RetArg()
363 assert_equal([1, 2, 3], res)
364 END
365 CheckScriptSuccess(lines)
Bram Moolenaar148be9b2021-02-02 21:33:52 +0100366
367 lines =<< trim END
368 new
369 var name = [1, 2]
370 name
371 ->copy()
372 ->setline(1)
373 assert_equal(['1', '2'], getline(1, 2))
374 bwipe!
375 END
376 CheckDefAndScriptSuccess(lines)
377
378 lines =<< trim END
379 new
Bram Moolenaar6914e872021-03-06 21:01:09 +0100380 def Foo(): string
381 return 'the text'
382 enddef
383 def Bar(F: func): string
384 return F()
385 enddef
386 def Test()
Bram Moolenaar77b10ff2021-03-14 13:21:35 +0100387 Foo ->Bar()
388 ->setline(1)
Bram Moolenaar6914e872021-03-06 21:01:09 +0100389 enddef
390 Test()
391 assert_equal('the text', getline(1))
392 bwipe!
393 END
394 CheckDefAndScriptSuccess(lines)
395
396 lines =<< trim END
397 new
Bram Moolenaar148be9b2021-02-02 21:33:52 +0100398 g:shortlist
399 ->copy()
400 ->setline(1)
401 assert_equal(['1', '2'], getline(1, 2))
402 bwipe!
403 END
404 g:shortlist = [1, 2]
405 CheckDefAndScriptSuccess(lines)
406 unlet g:shortlist
Bram Moolenaare0890d62021-02-17 14:52:14 +0100407
408 new
409 MethodAfterLinebreak('foobar')
410 assert_equal('foobar', getline(1))
411 bwipe!
Bram Moolenaar2e2d7582021-03-03 21:22:41 +0100412
413 lines =<< trim END
414 vim9script
415 def Foo(): string
416 return '# some text'
417 enddef
418
419 def Bar(F: func): string
420 return F()
421 enddef
422
Bram Moolenaar77b10ff2021-03-14 13:21:35 +0100423 Foo->Bar()
Bram Moolenaar2e2d7582021-03-03 21:22:41 +0100424 ->setline(1)
425 END
426 CheckScriptSuccess(lines)
427 assert_equal('# some text', getline(1))
428 bwipe!
Bram Moolenaar5f195932020-07-01 20:07:14 +0200429enddef
430
Bram Moolenaar7cebe8b2021-01-23 14:22:16 +0100431def Test_method_call_whitespace()
432 var lines =<< trim END
433 new
434 var yank = 'text'
435 yank->setline(1)
436 yank ->setline(2)
437 yank-> setline(3)
438 yank -> setline(4)
439 assert_equal(['text', 'text', 'text', 'text'], getline(1, 4))
440 bwipe!
441 END
442 CheckDefAndScriptSuccess(lines)
443enddef
444
Bram Moolenaar77b10ff2021-03-14 13:21:35 +0100445def Test_method_and_user_command()
446 var lines =<< trim END
447 vim9script
448 def Cmd()
449 g:didFunc = 1
450 enddef
451 command Cmd g:didCmd = 1
452 Cmd
453 assert_equal(1, g:didCmd)
454 Cmd()
455 assert_equal(1, g:didFunc)
456 unlet g:didFunc
457 unlet g:didCmd
458
459 def InDefFunc()
460 Cmd
461 assert_equal(1, g:didCmd)
462 Cmd()
463 assert_equal(1, g:didFunc)
464 unlet g:didFunc
465 unlet g:didCmd
466 enddef
467 InDefFunc()
468 END
469 CheckScriptSuccess(lines)
470enddef
471
Bram Moolenaar683581e2020-10-22 21:22:58 +0200472def Test_skipped_expr_linebreak()
473 if 0
474 var x = []
Bram Moolenaar2949cfd2020-12-31 21:28:47 +0100475 ->map(() => 0)
Bram Moolenaar683581e2020-10-22 21:22:58 +0200476 endif
477enddef
478
Bram Moolenaar0a47e092020-07-08 18:30:06 +0200479def Test_dict_member()
Bram Moolenaare0de1712020-12-02 17:36:54 +0100480 var test: dict<list<number>> = {data: [3, 1, 2]}
Bram Moolenaar0a47e092020-07-08 18:30:06 +0200481 test.data->sort()
Bram Moolenaare0de1712020-12-02 17:36:54 +0100482 assert_equal({data: [1, 2, 3]}, test)
Bram Moolenaar0a47e092020-07-08 18:30:06 +0200483 test.data
484 ->reverse()
Bram Moolenaare0de1712020-12-02 17:36:54 +0100485 assert_equal({data: [3, 2, 1]}, test)
Bram Moolenaar0a47e092020-07-08 18:30:06 +0200486
Bram Moolenaarac564082020-09-27 19:05:33 +0200487 var lines =<< trim END
Bram Moolenaar0a47e092020-07-08 18:30:06 +0200488 vim9script
Bram Moolenaare0de1712020-12-02 17:36:54 +0100489 var test: dict<list<number>> = {data: [3, 1, 2]}
Bram Moolenaar0a47e092020-07-08 18:30:06 +0200490 test.data->sort()
Bram Moolenaare0de1712020-12-02 17:36:54 +0100491 assert_equal({data: [1, 2, 3]}, test)
Bram Moolenaar0a47e092020-07-08 18:30:06 +0200492 END
493 CheckScriptSuccess(lines)
494enddef
495
Bram Moolenaare9f262b2020-07-05 14:57:51 +0200496def Test_bar_after_command()
497 def RedrawAndEcho()
Bram Moolenaarac564082020-09-27 19:05:33 +0200498 var x = 'did redraw'
Bram Moolenaare9f262b2020-07-05 14:57:51 +0200499 redraw | echo x
500 enddef
501 RedrawAndEcho()
502 assert_match('did redraw', Screenline(&lines))
503
Bram Moolenaar788123c2020-07-05 15:32:17 +0200504 def CallAndEcho()
Bram Moolenaarac564082020-09-27 19:05:33 +0200505 var x = 'did redraw'
Bram Moolenaar788123c2020-07-05 15:32:17 +0200506 reg_executing() | echo x
507 enddef
508 CallAndEcho()
509 assert_match('did redraw', Screenline(&lines))
510
Bram Moolenaare9f262b2020-07-05 14:57:51 +0200511 if has('unix')
512 # bar in filter write command does not start new command
513 def WriteToShell()
514 new
515 setline(1, 'some text')
516 w !cat | cat > Xoutfile
517 bwipe!
518 enddef
519 WriteToShell()
520 assert_equal(['some text'], readfile('Xoutfile'))
521 delete('Xoutfile')
522
523 # bar in filter read command does not start new command
524 def ReadFromShell()
525 new
526 r! echo hello there | cat > Xoutfile
527 r !echo again | cat >> Xoutfile
528 bwipe!
529 enddef
530 ReadFromShell()
531 assert_equal(['hello there', 'again'], readfile('Xoutfile'))
532 delete('Xoutfile')
533 endif
534enddef
535
Bram Moolenaarb074e8b2020-07-11 13:40:45 +0200536def Test_filter_is_not_modifier()
Bram Moolenaare0de1712020-12-02 17:36:54 +0100537 var tags = [{a: 1, b: 2}, {x: 3, y: 4}]
Bram Moolenaar2949cfd2020-12-31 21:28:47 +0100538 filter(tags, ( _, v) => has_key(v, 'x') ? 1 : 0 )
Bram Moolenaare0de1712020-12-02 17:36:54 +0100539 assert_equal([{x: 3, y: 4}], tags)
Bram Moolenaarb074e8b2020-07-11 13:40:45 +0200540enddef
541
Bram Moolenaare88c8e82020-11-01 17:03:37 +0100542def Test_command_modifier_filter()
Bram Moolenaar4f6b6ed2020-10-29 20:24:34 +0100543 var lines =<< trim END
544 final expected = "\nType Name Content\n c \"c piyo"
545 @a = 'hoge'
546 @b = 'fuga'
547 @c = 'piyo'
548
549 assert_equal(execute('filter /piyo/ registers abc'), expected)
550 END
551 CheckDefAndScriptSuccess(lines)
Bram Moolenaare729ce22021-06-06 21:38:09 +0200552
553 # also do this compiled
554 lines =<< trim END
555 @a = 'very specific z3d37dh234 string'
556 filter z3d37dh234 registers
557 assert_match('very specific z3d37dh234 string', Screenline(&lines))
558 END
559 CheckDefAndScriptSuccess(lines)
Bram Moolenaar4f6b6ed2020-10-29 20:24:34 +0100560enddef
561
Bram Moolenaare88c8e82020-11-01 17:03:37 +0100562def Test_win_command_modifiers()
563 assert_equal(1, winnr('$'))
564
565 set splitright
566 vsplit
567 assert_equal(2, winnr())
568 close
569 aboveleft vsplit
570 assert_equal(1, winnr())
571 close
572 set splitright&
573
574 vsplit
575 assert_equal(1, winnr())
576 close
577 belowright vsplit
578 assert_equal(2, winnr())
579 close
580 rightbelow vsplit
581 assert_equal(2, winnr())
582 close
583
Bram Moolenaar97a19002020-11-01 22:15:44 +0100584 if has('browse')
585 browse set
586 assert_equal('option-window', expand('%'))
587 close
588 endif
Bram Moolenaare88c8e82020-11-01 17:03:37 +0100589
590 vsplit
591 botright split
592 assert_equal(3, winnr())
593 assert_equal(&columns, winwidth(0))
594 close
595 close
596
597 vsplit
598 topleft split
599 assert_equal(1, winnr())
600 assert_equal(&columns, winwidth(0))
601 close
602 close
603
604 gettabinfo()->len()->assert_equal(1)
605 tab split
606 gettabinfo()->len()->assert_equal(2)
607 tabclose
608
609 vertical new
610 assert_inrange(&columns / 2 - 2, &columns / 2 + 1, winwidth(0))
611 close
612enddef
613
614func Test_command_modifier_confirm()
615 CheckNotGui
616 CheckRunVimInTerminal
617
618 " Test for saving all the modified buffers
619 let lines =<< trim END
620 call setline(1, 'changed')
621 def Getout()
622 confirm write Xfile
623 enddef
624 END
625 call writefile(lines, 'Xconfirmscript')
626 call writefile(['empty'], 'Xfile')
627 let buf = RunVimInTerminal('-S Xconfirmscript', {'rows': 8})
628 call term_sendkeys(buf, ":call Getout()\n")
629 call WaitForAssert({-> assert_match('(Y)es, \[N\]o: ', term_getline(buf, 8))}, 1000)
630 call term_sendkeys(buf, "y")
Bram Moolenaar645cd3e2020-11-01 20:04:57 +0100631 call WaitForAssert({-> assert_match('(Y)es, \[N\]o: ', term_getline(buf, 8))}, 1000)
632 call term_sendkeys(buf, "\<CR>")
633 call TermWait(buf)
Bram Moolenaare88c8e82020-11-01 17:03:37 +0100634 call StopVimInTerminal(buf)
635
636 call assert_equal(['changed'], readfile('Xfile'))
637 call delete('Xfile')
Bram Moolenaar645cd3e2020-11-01 20:04:57 +0100638 call delete('.Xfile.swp') " in case Vim was killed
Bram Moolenaare88c8e82020-11-01 17:03:37 +0100639 call delete('Xconfirmscript')
640endfunc
641
642def Test_command_modifiers_keep()
643 if has('unix')
644 def DoTest(addRflag: bool, keepMarks: bool, hasMarks: bool)
645 new
646 setline(1, ['one', 'two', 'three'])
647 normal 1Gma
648 normal 2Gmb
649 normal 3Gmc
650 if addRflag
651 set cpo+=R
652 else
653 set cpo-=R
654 endif
655 if keepMarks
656 keepmarks :%!cat
657 else
658 :%!cat
659 endif
660 if hasMarks
661 assert_equal(1, line("'a"))
662 assert_equal(2, line("'b"))
663 assert_equal(3, line("'c"))
664 else
665 assert_equal(0, line("'a"))
666 assert_equal(0, line("'b"))
667 assert_equal(0, line("'c"))
668 endif
669 quit!
670 enddef
671 DoTest(false, false, true)
672 DoTest(true, false, false)
673 DoTest(false, true, true)
674 DoTest(true, true, true)
675 set cpo&vim
Bram Moolenaarf65b35b2020-11-04 18:02:44 +0100676
677 new
678 setline(1, ['one', 'two', 'three', 'four'])
679 assert_equal(4, line("$"))
680 normal 1Gma
681 normal 2Gmb
682 normal 3Gmc
683 lockmarks :1,2!wc
684 # line is deleted, marks don't move
685 assert_equal(3, line("$"))
686 assert_equal('four', getline(3))
687 assert_equal(1, line("'a"))
688 assert_equal(2, line("'b"))
689 assert_equal(3, line("'c"))
690 quit!
Bram Moolenaare88c8e82020-11-01 17:03:37 +0100691 endif
692
Bram Moolenaarf65b35b2020-11-04 18:02:44 +0100693 edit Xone
694 edit Xtwo
695 assert_equal('Xone', expand('#'))
696 keepalt edit Xthree
697 assert_equal('Xone', expand('#'))
698
699 normal /a*b*
700 assert_equal('a*b*', histget("search"))
701 keeppatterns normal /c*d*
702 assert_equal('a*b*', histget("search"))
703
704 new
705 setline(1, range(10))
706 :10
707 normal gg
708 assert_equal(10, getpos("''")[1])
709 keepjumps normal 5G
710 assert_equal(10, getpos("''")[1])
711 quit!
Bram Moolenaare88c8e82020-11-01 17:03:37 +0100712enddef
713
Bram Moolenaar8242ebb2020-12-29 11:15:01 +0100714def Test_bar_line_continuation()
715 var lines =<< trim END
716 au BufNewFile Xfile g:readFile = 1
717 | g:readExtra = 2
718 g:readFile = 0
719 g:readExtra = 0
720 edit Xfile
721 assert_equal(1, g:readFile)
722 assert_equal(2, g:readExtra)
723 bwipe!
724 au! BufNewFile
725
726 au BufNewFile Xfile g:readFile = 1
727 | g:readExtra = 2
728 | g:readMore = 3
729 g:readFile = 0
730 g:readExtra = 0
731 g:readMore = 0
732 edit Xfile
733 assert_equal(1, g:readFile)
734 assert_equal(2, g:readExtra)
735 assert_equal(3, g:readMore)
736 bwipe!
737 au! BufNewFile
738 unlet g:readFile
739 unlet g:readExtra
740 unlet g:readMore
741 END
742 CheckDefAndScriptSuccess(lines)
743enddef
744
Bram Moolenaare88c8e82020-11-01 17:03:37 +0100745def Test_command_modifier_other()
Bram Moolenaar66669fc2020-11-04 18:53:35 +0100746 new Xsomefile
747 setline(1, 'changed')
748 var buf = bufnr()
749 hide edit Xotherfile
750 var info = getbufinfo(buf)
751 assert_equal(1, info[0].hidden)
752 assert_equal(1, info[0].changed)
753 edit Xsomefile
754 bwipe!
755
756 au BufNewFile Xfile g:readFile = 1
757 g:readFile = 0
758 edit Xfile
759 assert_equal(1, g:readFile)
760 bwipe!
761 g:readFile = 0
762 noautocmd edit Xfile
763 assert_equal(0, g:readFile)
Bram Moolenaardcc58e02020-12-28 20:53:21 +0100764 au! BufNewFile
Bram Moolenaardcc58e02020-12-28 20:53:21 +0100765 unlet g:readFile
Bram Moolenaar66669fc2020-11-04 18:53:35 +0100766
767 noswapfile edit XnoSwap
Bram Moolenaardd1f4262020-12-31 17:41:01 +0100768 assert_equal(false, &l:swapfile)
Bram Moolenaar66669fc2020-11-04 18:53:35 +0100769 bwipe!
770
771 var caught = false
772 try
773 sandbox !ls
774 catch /E48:/
775 caught = true
776 endtry
777 assert_true(caught)
778
779 :8verbose g:verbose_now = &verbose
780 assert_equal(8, g:verbose_now)
781 unlet g:verbose_now
782enddef
783
784def EchoHere()
785 echomsg 'here'
786enddef
787def EchoThere()
788 unsilent echomsg 'there'
789enddef
790
791def Test_modifier_silent_unsilent()
792 echomsg 'last one'
793 silent echomsg "text"
794 assert_equal("\nlast one", execute(':1messages'))
795
796 silent! echoerr "error"
797
798 echomsg 'last one'
799 silent EchoHere()
800 assert_equal("\nlast one", execute(':1messages'))
801
802 silent EchoThere()
803 assert_equal("\nthere", execute(':1messages'))
Bram Moolenaar20a76292020-12-25 19:47:24 +0100804
805 try
806 silent eval [][0]
807 catch
808 echomsg "caught"
809 endtry
810 assert_equal("\ncaught", execute(':1messages'))
Bram Moolenaar917c46a2021-08-10 19:53:01 +0200811
812 var lines =<< trim END
813 vim9script
814 set history=11
815 silent! while 0
816 set history=22
817 silent! endwhile
818 assert_equal(11, &history)
819 set history&
820 END
821 CheckScriptSuccess(lines)
Bram Moolenaare88c8e82020-11-01 17:03:37 +0100822enddef
823
Bram Moolenaar36113e42020-11-02 21:08:47 +0100824def Test_range_after_command_modifier()
Bram Moolenaar6e2c2c52020-12-25 19:25:45 +0100825 CheckScriptFailure(['vim9script', 'silent keepjump 1d _'], 'E1050: Colon required before a range: 1d _', 2)
Bram Moolenaar36113e42020-11-02 21:08:47 +0100826 new
827 setline(1, 'xxx')
828 CheckScriptSuccess(['vim9script', 'silent keepjump :1d _'])
829 assert_equal('', getline(1))
830 bwipe!
831enddef
832
Bram Moolenaarece0b872021-01-08 20:40:45 +0100833def Test_silent_pattern()
834 new
835 silent! :/pat/put _
836 bwipe!
837enddef
838
Bram Moolenaarfa984412021-03-25 22:15:28 +0100839def Test_useless_command_modifier()
840 g:maybe = true
841 var lines =<< trim END
842 if g:maybe
843 silent endif
844 END
845 CheckDefAndScriptFailure(lines, 'E1176:', 2)
846
847 lines =<< trim END
848 for i in [0]
849 silent endfor
850 END
Bram Moolenaar917c46a2021-08-10 19:53:01 +0200851 CheckDefFailure(lines, 'E1176:', 2)
852 CheckScriptSuccess(['vim9script'] + lines)
Bram Moolenaarfa984412021-03-25 22:15:28 +0100853
854 lines =<< trim END
855 while g:maybe
856 silent endwhile
857 END
Bram Moolenaar917c46a2021-08-10 19:53:01 +0200858 CheckDefFailure(lines, 'E1176:', 2)
859 g:maybe = false
860 CheckScriptSuccess(['vim9script'] + lines)
Bram Moolenaarfa984412021-03-25 22:15:28 +0100861
862 lines =<< trim END
863 silent try
864 finally
865 endtry
866 END
867 CheckDefAndScriptFailure(lines, 'E1176:', 1)
868
869 lines =<< trim END
870 try
871 silent catch
872 endtry
873 END
874 CheckDefAndScriptFailure(lines, 'E1176:', 2)
875
876 lines =<< trim END
877 try
878 silent finally
879 endtry
880 END
881 CheckDefAndScriptFailure(lines, 'E1176:', 2)
882
883 lines =<< trim END
884 try
885 finally
886 silent endtry
887 END
888 CheckDefAndScriptFailure(lines, 'E1176:', 3)
889enddef
890
Bram Moolenaar007f9d62020-07-06 23:04:49 +0200891def Test_eval_command()
Bram Moolenaarac564082020-09-27 19:05:33 +0200892 var from = 3
893 var to = 5
Bram Moolenaar007f9d62020-07-06 23:04:49 +0200894 g:val = 111
895 def Increment(nrs: list<number>)
896 for nr in nrs
897 g:val += nr
898 endfor
899 enddef
900 eval range(from, to)
901 ->Increment()
902 assert_equal(111 + 3 + 4 + 5, g:val)
903 unlet g:val
Bram Moolenaard0fe6202020-12-05 17:11:12 +0100904
905 var lines =<< trim END
906 vim9script
907 g:caught = 'no'
908 try
909 eval 123 || 0
910 catch
911 g:caught = 'yes'
912 endtry
913 assert_equal('yes', g:caught)
914 unlet g:caught
915 END
916 CheckScriptSuccess(lines)
Bram Moolenaar007f9d62020-07-06 23:04:49 +0200917enddef
918
Bram Moolenaarb8a92962020-08-20 18:02:47 +0200919def Test_map_command()
Bram Moolenaarac564082020-09-27 19:05:33 +0200920 var lines =<< trim END
Bram Moolenaarb8a92962020-08-20 18:02:47 +0200921 nnoremap <F3> :echo 'hit F3 #'<CR>
922 assert_equal(":echo 'hit F3 #'<CR>", maparg("<F3>", "n"))
923 END
924 CheckDefSuccess(lines)
925 CheckScriptSuccess(['vim9script'] + lines)
926enddef
927
Bram Moolenaarb3ea36c2020-08-23 21:46:32 +0200928def Test_normal_command()
929 new
930 setline(1, 'doesnotexist')
Bram Moolenaarac564082020-09-27 19:05:33 +0200931 var caught = 0
Bram Moolenaarb3ea36c2020-08-23 21:46:32 +0200932 try
933 exe "norm! \<C-]>"
934 catch /E433/
935 caught = 2
936 endtry
937 assert_equal(2, caught)
938
939 try
940 exe "norm! 3\<C-]>"
941 catch /E433/
942 caught = 3
943 endtry
944 assert_equal(3, caught)
945 bwipe!
946enddef
947
Bram Moolenaarc3516f72020-09-08 22:45:35 +0200948def Test_put_command()
949 new
950 @p = 'ppp'
951 put p
952 assert_equal('ppp', getline(2))
953
954 put ='below'
955 assert_equal('below', getline(3))
956 put! ='above'
957 assert_equal('above', getline(3))
958 assert_equal('below', getline(4))
959
Bram Moolenaar883cf972021-01-15 18:04:43 +0100960 :2put =['a', 'b', 'c']
961 assert_equal(['ppp', 'a', 'b', 'c', 'above'], getline(2, 6))
962
Bram Moolenaar08597872020-12-10 19:43:40 +0100963 # compute range at runtime
964 setline(1, range(1, 8))
965 @a = 'aaa'
966 :$-2put a
967 assert_equal('aaa', getline(7))
968
969 setline(1, range(1, 8))
970 :2
971 :+2put! a
972 assert_equal('aaa', getline(4))
973
Bram Moolenaara28639e2021-01-19 22:48:09 +0100974 []->mapnew(() => 0)
975 :$put ='end'
976 assert_equal('end', getline('$'))
977
Bram Moolenaarc3516f72020-09-08 22:45:35 +0200978 bwipe!
Bram Moolenaar025cb1c2020-12-14 18:31:27 +0100979
980 CheckDefFailure(['put =xxx'], 'E1001:')
981enddef
982
983def Test_put_with_linebreak()
984 new
985 var lines =<< trim END
986 vim9script
987 pu =split('abc', '\zs')
988 ->join()
989 END
990 CheckScriptSuccess(lines)
991 getline(2)->assert_equal('a b c')
992 bwipe!
Bram Moolenaarc3516f72020-09-08 22:45:35 +0200993enddef
994
Bram Moolenaar3bd8de42020-09-14 16:37:34 +0200995def Test_command_star_range()
996 new
997 setline(1, ['xxx foo xxx', 'xxx bar xxx', 'xxx foo xx bar'])
998 setpos("'<", [0, 1, 0, 0])
999 setpos("'>", [0, 3, 0, 0])
1000 :*s/\(foo\|bar\)/baz/g
1001 getline(1, 3)->assert_equal(['xxx baz xxx', 'xxx baz xxx', 'xxx baz xx baz'])
1002
1003 bwipe!
1004enddef
1005
Bram Moolenaar20d89e02020-10-20 23:11:33 +02001006def Test_f_args()
1007 var lines =<< trim END
1008 vim9script
1009
1010 func SaveCmdArgs(...)
1011 let g:args = a:000
1012 endfunc
1013
1014 command -nargs=* TestFArgs call SaveCmdArgs(<f-args>)
1015
1016 TestFArgs
1017 assert_equal([], g:args)
1018
1019 TestFArgs one two three
1020 assert_equal(['one', 'two', 'three'], g:args)
1021 END
1022 CheckScriptSuccess(lines)
1023enddef
Bram Moolenaarc3516f72020-09-08 22:45:35 +02001024
Bram Moolenaard1510ee2021-01-04 16:15:58 +01001025def Test_user_command_comment()
1026 command -nargs=1 Comd echom <q-args>
1027
1028 var lines =<< trim END
Bram Moolenaarb98cec22021-04-25 16:35:55 +02001029 vim9script
1030 Comd # comment
Bram Moolenaard1510ee2021-01-04 16:15:58 +01001031 END
1032 CheckScriptSuccess(lines)
1033
1034 lines =<< trim END
Bram Moolenaarb98cec22021-04-25 16:35:55 +02001035 vim9script
1036 Comd# comment
Bram Moolenaard1510ee2021-01-04 16:15:58 +01001037 END
1038 CheckScriptFailure(lines, 'E1144:')
Bram Moolenaard1510ee2021-01-04 16:15:58 +01001039 delcommand Comd
Bram Moolenaarb98cec22021-04-25 16:35:55 +02001040
1041 lines =<< trim END
1042 vim9script
1043 command Foo echo 'Foo'
1044 Foo3Bar
1045 END
1046 CheckScriptFailure(lines, 'E1144: Command "Foo" is not followed by white space: Foo3Bar')
1047
1048 delcommand Foo
Bram Moolenaard1510ee2021-01-04 16:15:58 +01001049enddef
1050
Bram Moolenaar95388e32020-11-20 21:07:00 +01001051def Test_star_command()
1052 var lines =<< trim END
1053 vim9script
1054 @s = 'g:success = 8'
1055 set cpo+=*
1056 exe '*s'
1057 assert_equal(8, g:success)
1058 unlet g:success
1059 set cpo-=*
1060 assert_fails("exe '*s'", 'E1050:')
1061 END
1062 CheckScriptSuccess(lines)
1063enddef
1064
Bram Moolenaar47a2abf2020-11-25 20:12:11 +01001065def Test_cmd_argument_without_colon()
1066 new Xfile
1067 setline(1, ['a', 'b', 'c', 'd'])
1068 write
1069 edit +3 %
1070 assert_equal(3, getcurpos()[1])
1071 edit +/a %
1072 assert_equal(1, getcurpos()[1])
1073 bwipe
1074 delete('Xfile')
1075enddef
1076
Bram Moolenaar1c0aa972020-12-16 21:43:54 +01001077def Test_ambiguous_user_cmd()
Bram Moolenaard1510ee2021-01-04 16:15:58 +01001078 command Cmd1 eval 0
1079 command Cmd2 eval 0
Bram Moolenaar1c0aa972020-12-16 21:43:54 +01001080 var lines =<< trim END
Bram Moolenaar1c0aa972020-12-16 21:43:54 +01001081 Cmd
1082 END
Bram Moolenaard1510ee2021-01-04 16:15:58 +01001083 CheckDefAndScriptFailure(lines, 'E464:', 1)
1084 delcommand Cmd1
1085 delcommand Cmd2
Bram Moolenaar1c0aa972020-12-16 21:43:54 +01001086enddef
1087
Bram Moolenaar52c124d2020-12-20 21:43:35 +01001088def Test_command_not_recognized()
1089 var lines =<< trim END
1090 d.key = 'asdf'
1091 END
1092 CheckDefFailure(lines, 'E1146:', 1)
1093
1094 lines =<< trim END
1095 d['key'] = 'asdf'
1096 END
1097 CheckDefFailure(lines, 'E1146:', 1)
1098enddef
Bram Moolenaarb7a78f72020-06-28 18:43:40 +02001099
Bram Moolenaarf4e20992020-12-21 19:59:08 +01001100def Test_magic_not_used()
1101 new
1102 for cmd in ['set magic', 'set nomagic']
1103 exe cmd
1104 setline(1, 'aaa')
1105 s/.../bbb/
1106 assert_equal('bbb', getline(1))
1107 endfor
1108
1109 set magic
1110 setline(1, 'aaa')
1111 assert_fails('s/.\M../bbb/', 'E486:')
1112 assert_fails('snomagic/.../bbb/', 'E486:')
1113 assert_equal('aaa', getline(1))
1114
1115 bwipe!
1116enddef
1117
Bram Moolenaar60f63102020-12-21 20:32:43 +01001118def Test_gdefault_not_used()
1119 new
1120 for cmd in ['set gdefault', 'set nogdefault']
1121 exe cmd
1122 setline(1, 'aaa')
1123 s/./b/
1124 assert_equal('baa', getline(1))
1125 endfor
1126
1127 set nogdefault
1128 bwipe!
1129enddef
1130
Bram Moolenaar179eb562020-12-27 18:03:22 +01001131def g:SomeComplFunc(findstart: number, base: string): any
1132 if findstart
1133 return 0
1134 else
1135 return ['aaa', 'bbb']
1136 endif
1137enddef
1138
1139def Test_insert_complete()
1140 # this was running into an error with the matchparen hack
1141 new
1142 set completefunc=SomeComplFunc
1143 feedkeys("i\<c-x>\<c-u>\<Esc>", 'ntx')
1144 assert_equal('aaa', getline(1))
1145
1146 set completefunc=
1147 bwipe!
1148enddef
1149
Bram Moolenaara11919f2021-01-02 19:44:56 +01001150def Test_wincmd()
1151 split
1152 var id1 = win_getid()
1153 if true
1154 try | wincmd w | catch | endtry
1155 endif
1156 assert_notequal(id1, win_getid())
1157 close
Bram Moolenaar1ff89de2021-03-24 20:08:12 +01001158
1159 split
1160 var id = win_getid()
1161 split
1162 :2wincmd o
1163 assert_equal(id, win_getid())
1164 only
1165
1166 split
1167 split
1168 assert_equal(3, winnr('$'))
1169 :2wincmd c
1170 assert_equal(2, winnr('$'))
1171 only
1172
1173 split
1174 split
1175 assert_equal(3, winnr('$'))
1176 :2wincmd q
1177 assert_equal(2, winnr('$'))
1178 only
Bram Moolenaara11919f2021-01-02 19:44:56 +01001179enddef
1180
Bram Moolenaar9567efa2021-01-11 22:16:30 +01001181def Test_windo_missing_endif()
1182 var lines =<< trim END
1183 windo if 1
1184 END
1185 CheckDefExecFailure(lines, 'E171:', 1)
1186enddef
1187
Bram Moolenaarb2cb6c82021-03-28 20:38:34 +02001188let s:theList = [1, 2, 3]
1189
1190def Test_lockvar()
1191 s:theList[1] = 22
1192 assert_equal([1, 22, 3], s:theList)
1193 lockvar s:theList
1194 assert_fails('theList[1] = 77', 'E741:')
1195 unlockvar s:theList
1196 s:theList[1] = 44
1197 assert_equal([1, 44, 3], s:theList)
1198
Bram Moolenaaraacc9662021-08-13 19:40:51 +02001199 var d = {a: 1, b: 2}
1200 d.a = 3
1201 d.b = 4
1202 assert_equal({a: 3, b: 4}, d)
1203 lockvar d.a
1204 d.b = 5
1205 var ex = ''
1206 try
1207 d.a = 6
1208 catch
1209 ex = v:exception
1210 endtry
1211 assert_match('E1121:', ex)
1212 unlockvar d.a
1213 d.a = 7
1214 assert_equal({a: 7, b: 5}, d)
1215
Bram Moolenaarb2cb6c82021-03-28 20:38:34 +02001216 var lines =<< trim END
1217 vim9script
1218 var theList = [1, 2, 3]
1219 def SetList()
1220 theList[1] = 22
1221 assert_equal([1, 22, 3], theList)
1222 lockvar theList
1223 theList[1] = 77
1224 enddef
1225 SetList()
1226 END
1227 CheckScriptFailure(lines, 'E1119', 4)
1228
1229 lines =<< trim END
1230 var theList = [1, 2, 3]
1231 lockvar theList
1232 END
1233 CheckDefFailure(lines, 'E1178', 2)
1234
1235 lines =<< trim END
1236 var theList = [1, 2, 3]
1237 unlockvar theList
1238 END
1239 CheckDefFailure(lines, 'E1178', 2)
1240enddef
1241
Bram Moolenaar4c137212021-04-19 16:48:48 +02001242def Test_substitute_expr()
1243 var to = 'repl'
1244 new
1245 setline(1, 'one from two')
1246 s/from/\=to
1247 assert_equal('one repl two', getline(1))
1248
1249 setline(1, 'one from two')
1250 s/from/\=to .. '_x'
1251 assert_equal('one repl_x two', getline(1))
1252
1253 setline(1, 'one from two from three')
1254 var also = 'also'
1255 s/from/\=to .. '_' .. also/g#e
1256 assert_equal('one repl_also two repl_also three', getline(1))
1257
Bram Moolenaar8238f082021-04-20 21:10:48 +02001258 setline(1, 'abc abc abc')
1259 for choice in [true, false]
1260 :1s/abc/\=choice ? 'yes' : 'no'/
1261 endfor
1262 assert_equal('yes no abc', getline(1))
1263
Bram Moolenaard386e922021-04-25 14:48:49 +02001264 bwipe!
1265
Bram Moolenaar4c137212021-04-19 16:48:48 +02001266 CheckDefFailure(['s/from/\="x")/'], 'E488:')
1267 CheckDefFailure(['s/from/\="x"/9'], 'E488:')
1268
Bram Moolenaard386e922021-04-25 14:48:49 +02001269 # When calling a function the right instruction list needs to be restored.
Bram Moolenaar5930ddc2021-04-26 20:32:59 +02001270 g:cond = true
Bram Moolenaard386e922021-04-25 14:48:49 +02001271 var lines =<< trim END
1272 vim9script
1273 def Foo()
1274 Bar([])
1275 enddef
1276 def Bar(l: list<number>)
Bram Moolenaar5930ddc2021-04-26 20:32:59 +02001277 if g:cond
Bram Moolenaard386e922021-04-25 14:48:49 +02001278 s/^/\=Rep()/
1279 for n in l[:]
1280 endfor
Bram Moolenaar5930ddc2021-04-26 20:32:59 +02001281 endif
Bram Moolenaard386e922021-04-25 14:48:49 +02001282 enddef
1283 def Rep(): string
1284 return 'rep'
1285 enddef
1286 new
1287 Foo()
1288 assert_equal('rep', getline(1))
1289 bwipe!
1290 END
1291 CheckScriptSuccess(lines)
Bram Moolenaar5930ddc2021-04-26 20:32:59 +02001292 unlet g:cond
Bram Moolenaar27523602021-06-05 21:36:19 +02001293
1294 # List results in multiple lines
1295 new
1296 setline(1, 'some text here')
Bram Moolenaar2c707112021-08-02 22:26:56 +02001297 s/text/\=['aaa', 'bbb', 'ccc']/
Bram Moolenaar27523602021-06-05 21:36:19 +02001298 assert_equal(['some aaa', 'bbb', 'ccc', ' here'], getline(1, '$'))
1299 bwipe!
Bram Moolenaar4c137212021-04-19 16:48:48 +02001300enddef
1301
Bram Moolenaar2d1c57e2021-04-19 20:50:03 +02001302def Test_redir_to_var()
1303 var result: string
1304 redir => result
1305 echo 'something'
1306 redir END
1307 assert_equal("\nsomething", result)
1308
1309 redir =>> result
1310 echo 'more'
1311 redir END
1312 assert_equal("\nsomething\nmore", result)
1313
Bram Moolenaar753bcf82021-04-21 14:24:24 +02001314 var d: dict<string>
1315 redir => d.redir
1316 echo 'dict'
1317 redir END
1318 assert_equal({redir: "\ndict"}, d)
1319
1320 var l = ['a', 'b', 'c']
1321 redir => l[1]
1322 echo 'list'
1323 redir END
1324 assert_equal(['a', "\nlist", 'c'], l)
1325
1326 var dl = {l: ['x']}
1327 redir => dl.l[0]
1328 echo 'dict-list'
1329 redir END
1330 assert_equal({l: ["\ndict-list"]}, dl)
1331
Bram Moolenaara369c3d2021-04-21 16:00:10 +02001332 redir =>> d.redir
1333 echo 'more'
1334 redir END
1335 assert_equal({redir: "\ndict\nmore"}, d)
1336
Bram Moolenaar2d1c57e2021-04-19 20:50:03 +02001337 var lines =<< trim END
1338 redir => notexist
1339 END
1340 CheckDefFailure(lines, 'E1089:')
Bram Moolenaar753bcf82021-04-21 14:24:24 +02001341
1342 lines =<< trim END
1343 var ls = 'asdf'
1344 redir => ls[1]
1345 redir END
1346 END
1347 CheckDefFailure(lines, 'E1141:')
Bram Moolenaar2d1c57e2021-04-19 20:50:03 +02001348enddef
1349
Bram Moolenaar68db9962021-05-09 23:19:22 +02001350def Test_echo_void()
1351 var lines =<< trim END
1352 vim9script
1353 def NoReturn()
1354 echo 'nothing'
1355 enddef
1356 echo NoReturn()
1357 END
1358 CheckScriptFailure(lines, 'E1186:', 5)
1359
1360 lines =<< trim END
1361 vim9script
1362 def NoReturn()
1363 echo 'nothing'
1364 enddef
1365 def Try()
1366 echo NoReturn()
1367 enddef
1368 defcompile
1369 END
1370 CheckScriptFailure(lines, 'E1186:', 1)
1371enddef
1372
Bram Moolenaar2c707112021-08-02 22:26:56 +02001373def Test_cmdwin_block()
1374 augroup justTesting
1375 autocmd BufEnter * {
1376 echomsg 'in block'
1377 }
1378 augroup END
1379 feedkeys('q:', 'xt')
1380 redraw
1381 feedkeys("aclose\<CR>", 'xt')
1382
1383 au! justTesting
1384enddef
1385
Bram Moolenaarb2cb6c82021-03-28 20:38:34 +02001386
Bram Moolenaarcfe435d2020-04-25 20:02:55 +02001387" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker