1" Test commands that are not compiled in a :def function
2
3source check.vim
4source vim9.vim
5source term_util.vim
6source view_util.vim
7
8def Test_edit_wildcards()
9  var filename = 'Xtest'
10  edit `=filename`
11  assert_equal('Xtest', bufname())
12
13  var filenr = 123
14  edit Xtest`=filenr`
15  assert_equal('Xtest123', bufname())
16
17  filenr = 77
18  edit `=filename``=filenr`
19  assert_equal('Xtest77', bufname())
20
21  edit X`=filename`xx`=filenr`yy
22  assert_equal('XXtestxx77yy', bufname())
23
24  CheckDefFailure(['edit `=xxx`'], 'E1001:')
25  CheckDefFailure(['edit `="foo"'], 'E1083:')
26enddef
27
28def Test_expand_alternate_file()
29  var lines =<< trim END
30    edit Xfileone
31    var bone = bufnr()
32    edit Xfiletwo
33    var btwo = bufnr()
34    edit Xfilethree
35    var bthree = bufnr()
36
37    edit #
38    assert_equal(bthree, bufnr())
39    edit %%
40    assert_equal(btwo, bufnr())
41    edit %% # comment
42    assert_equal(bthree, bufnr())
43    edit %%yy
44    assert_equal('Xfiletwoyy', bufname())
45
46    exe "edit %%" .. bone
47    assert_equal(bone, bufnr())
48    exe "edit %%" .. btwo .. "xx"
49    assert_equal('Xfiletwoxx', bufname())
50
51    next Xfileone Xfiletwo Xfilethree
52    assert_equal('Xfileone', argv(0))
53    assert_equal('Xfiletwo', argv(1))
54    assert_equal('Xfilethree', argv(2))
55    next %%%zz
56    assert_equal('Xfileone', argv(0))
57    assert_equal('Xfiletwo', argv(1))
58    assert_equal('Xfilethreezz', argv(2))
59
60    v:oldfiles = ['Xonefile', 'Xtwofile']
61    edit %%<1
62    assert_equal('Xonefile', bufname())
63    edit %%<2
64    assert_equal('Xtwofile', bufname())
65    assert_fails('edit %%<3', 'E684:')
66
67    edit Xfileone.vim
68    edit Xfiletwo
69    edit %%:r
70    assert_equal('Xfileone', bufname())
71
72    assert_false(bufexists('altfoo'))
73    edit altfoo
74    edit bar
75    assert_true(bufexists('altfoo'))
76    assert_true(buflisted('altfoo'))
77    bdel %%
78    assert_true(bufexists('altfoo'))
79    assert_false(buflisted('altfoo'))
80    bwipe! altfoo
81    bwipe! bar
82  END
83  CheckDefAndScriptSuccess(lines)
84enddef
85
86def Test_global_backtick_expansion()
87  new
88  setline(1, 'xx')
89  var name = 'foobar'
90  g/^xx/s/.*/`=name`
91  assert_equal('foobar', getline(1))
92  bwipe!
93enddef
94
95def Test_folddo_backtick_expansion()
96  new
97  var name = 'xxx'
98  folddoopen edit `=name`
99  assert_equal('xxx', bufname())
100  bwipe!
101
102  new
103  setline(1, ['one', 'two'])
104  set nomodified
105  :1,2fold
106  foldclose
107  folddoclose edit `=name`
108  assert_equal('xxx', bufname())
109  bwipe!
110enddef
111
112def Test_hardcopy_wildcards()
113  CheckUnix
114  CheckFeature postscript
115
116  var outfile = 'print'
117  hardcopy > X`=outfile`.ps
118  assert_true(filereadable('Xprint.ps'))
119
120  delete('Xprint.ps')
121enddef
122
123def Test_syn_include_wildcards()
124  writefile(['syn keyword Found found'], 'Xthemine.vim')
125  var save_rtp = &rtp
126  &rtp = '.'
127
128  var fname = 'mine'
129  syn include @Group Xthe`=fname`.vim
130  assert_match('Found.* contained found', execute('syn list Found'))
131
132  &rtp = save_rtp
133  delete('Xthemine.vim')
134enddef
135
136def Test_echo_linebreak()
137  var lines =<< trim END
138      vim9script
139      redir @a
140      echo 'one'
141            .. 'two'
142      redir END
143      assert_equal("\nonetwo", @a)
144  END
145  CheckScriptSuccess(lines)
146
147  lines =<< trim END
148      vim9script
149      redir @a
150      echo 11 +
151            77
152            - 22
153      redir END
154      assert_equal("\n66", @a)
155  END
156  CheckScriptSuccess(lines)
157enddef
158
159def Test_condition_types()
160  var lines =<< trim END
161      if 'text'
162      endif
163  END
164  CheckDefAndScriptFailure(lines, 'E1135:', 1)
165
166  lines =<< trim END
167      if [1]
168      endif
169  END
170  CheckDefFailure(lines, 'E1012:', 1)
171  CheckScriptFailure(['vim9script'] + lines, 'E745:', 2)
172
173  lines =<< trim END
174      g:cond = 'text'
175      if g:cond
176      endif
177  END
178  CheckDefExecAndScriptFailure(lines, 'E1135:', 2)
179
180  lines =<< trim END
181      g:cond = 0
182      if g:cond
183      elseif 'text'
184      endif
185  END
186  CheckDefFailure(lines, 'E1012:', 3)
187  CheckScriptFailure(['vim9script'] + lines, 'E1135:', 4)
188
189  lines =<< trim END
190      if g:cond
191      elseif [1]
192      endif
193  END
194  CheckDefFailure(lines, 'E1012:', 2)
195  CheckScriptFailure(['vim9script'] + lines, 'E745:', 3)
196
197  lines =<< trim END
198      g:cond = 'text'
199      if 0
200      elseif g:cond
201      endif
202  END
203  CheckDefExecAndScriptFailure(lines, 'E1135:', 3)
204
205  lines =<< trim END
206      while 'text'
207      endwhile
208  END
209  CheckDefFailure(lines, 'E1012:', 1)
210  CheckScriptFailure(['vim9script'] + lines, 'E1135:', 2)
211
212  lines =<< trim END
213      while [1]
214      endwhile
215  END
216  CheckDefFailure(lines, 'E1012:', 1)
217  CheckScriptFailure(['vim9script'] + lines, 'E745:', 2)
218
219  lines =<< trim END
220      g:cond = 'text'
221      while g:cond
222      endwhile
223  END
224  CheckDefExecAndScriptFailure(lines, 'E1135:', 2)
225enddef
226
227def Test_if_linebreak()
228  var lines =<< trim END
229      vim9script
230      if 1 &&
231            true
232            || 1
233        g:res = 42
234      endif
235      assert_equal(42, g:res)
236  END
237  CheckScriptSuccess(lines)
238  unlet g:res
239
240  lines =<< trim END
241      vim9script
242      if 1 &&
243            0
244        g:res = 0
245      elseif 0 ||
246              0
247              || 1
248        g:res = 12
249      endif
250      assert_equal(12, g:res)
251  END
252  CheckScriptSuccess(lines)
253  unlet g:res
254enddef
255
256def Test_while_linebreak()
257  var lines =<< trim END
258      vim9script
259      var nr = 0
260      while nr <
261              10 + 3
262            nr = nr
263                  + 4
264      endwhile
265      assert_equal(16, nr)
266  END
267  CheckScriptSuccess(lines)
268
269  lines =<< trim END
270      vim9script
271      var nr = 0
272      while nr
273            <
274              10
275              +
276              3
277            nr = nr
278                  +
279                  4
280      endwhile
281      assert_equal(16, nr)
282  END
283  CheckScriptSuccess(lines)
284enddef
285
286def Test_for_linebreak()
287  var lines =<< trim END
288      vim9script
289      var nr = 0
290      for x
291            in
292              [1, 2, 3, 4]
293          nr = nr + x
294      endfor
295      assert_equal(10, nr)
296  END
297  CheckScriptSuccess(lines)
298
299  lines =<< trim END
300      vim9script
301      var nr = 0
302      for x
303            in
304              [1, 2,
305                  3, 4
306                  ]
307          nr = nr
308                 +
309                  x
310      endfor
311      assert_equal(10, nr)
312  END
313  CheckScriptSuccess(lines)
314enddef
315
316def Test_method_call_linebreak()
317  var lines =<< trim END
318      vim9script
319      var res = []
320      func RetArg(
321            arg
322            )
323            let s:res = a:arg
324      endfunc
325      [1,
326          2,
327          3]->RetArg()
328      assert_equal([1, 2, 3], res)
329  END
330  CheckScriptSuccess(lines)
331
332  lines =<< trim END
333      new
334      var name = [1, 2]
335      name
336          ->copy()
337          ->setline(1)
338      assert_equal(['1', '2'], getline(1, 2))
339      bwipe!
340  END
341  CheckDefAndScriptSuccess(lines)
342
343  lines =<< trim END
344      new
345      g:shortlist
346          ->copy()
347          ->setline(1)
348      assert_equal(['1', '2'], getline(1, 2))
349      bwipe!
350  END
351  g:shortlist = [1, 2]
352  CheckDefAndScriptSuccess(lines)
353  unlet g:shortlist
354enddef
355
356def Test_method_call_whitespace()
357  var lines =<< trim END
358    new
359    var yank = 'text'
360    yank->setline(1)
361    yank  ->setline(2)
362    yank->  setline(3)
363    yank  ->  setline(4)
364    assert_equal(['text', 'text', 'text', 'text'], getline(1, 4))
365    bwipe!
366  END
367  CheckDefAndScriptSuccess(lines)
368enddef
369
370def Test_skipped_expr_linebreak()
371  if 0
372    var x = []
373               ->map(() => 0)
374  endif
375enddef
376
377def Test_dict_member()
378   var test: dict<list<number>> = {data: [3, 1, 2]}
379   test.data->sort()
380   assert_equal({data: [1, 2, 3]}, test)
381   test.data
382      ->reverse()
383   assert_equal({data: [3, 2, 1]}, test)
384
385  var lines =<< trim END
386      vim9script
387      var test: dict<list<number>> = {data: [3, 1, 2]}
388      test.data->sort()
389      assert_equal({data: [1, 2, 3]}, test)
390  END
391  CheckScriptSuccess(lines)
392enddef
393
394def Test_bar_after_command()
395  def RedrawAndEcho()
396    var x = 'did redraw'
397    redraw | echo x
398  enddef
399  RedrawAndEcho()
400  assert_match('did redraw', Screenline(&lines))
401
402  def CallAndEcho()
403    var x = 'did redraw'
404    reg_executing() | echo x
405  enddef
406  CallAndEcho()
407  assert_match('did redraw', Screenline(&lines))
408
409  if has('unix')
410    # bar in filter write command does not start new command
411    def WriteToShell()
412      new
413      setline(1, 'some text')
414      w !cat | cat > Xoutfile
415      bwipe!
416    enddef
417    WriteToShell()
418    assert_equal(['some text'], readfile('Xoutfile'))
419    delete('Xoutfile')
420
421    # bar in filter read command does not start new command
422    def ReadFromShell()
423      new
424      r! echo hello there | cat > Xoutfile
425      r !echo again | cat >> Xoutfile
426      bwipe!
427    enddef
428    ReadFromShell()
429    assert_equal(['hello there', 'again'], readfile('Xoutfile'))
430    delete('Xoutfile')
431  endif
432enddef
433
434def Test_filter_is_not_modifier()
435  var tags = [{a: 1, b: 2}, {x: 3, y: 4}]
436  filter(tags, ( _, v) => has_key(v, 'x') ? 1 : 0 )
437  assert_equal([{x: 3, y: 4}], tags)
438enddef
439
440def Test_command_modifier_filter()
441  var lines =<< trim END
442    final expected = "\nType Name Content\n  c  \"c   piyo"
443    @a = 'hoge'
444    @b = 'fuga'
445    @c = 'piyo'
446
447    assert_equal(execute('filter /piyo/ registers abc'), expected)
448  END
449  CheckDefAndScriptSuccess(lines)
450enddef
451
452def Test_win_command_modifiers()
453  assert_equal(1, winnr('$'))
454
455  set splitright
456  vsplit
457  assert_equal(2, winnr())
458  close
459  aboveleft vsplit
460  assert_equal(1, winnr())
461  close
462  set splitright&
463
464  vsplit
465  assert_equal(1, winnr())
466  close
467  belowright vsplit
468  assert_equal(2, winnr())
469  close
470  rightbelow vsplit
471  assert_equal(2, winnr())
472  close
473
474  if has('browse')
475    browse set
476    assert_equal('option-window', expand('%'))
477    close
478  endif
479
480  vsplit
481  botright split
482  assert_equal(3, winnr())
483  assert_equal(&columns, winwidth(0))
484  close
485  close
486
487  vsplit
488  topleft split
489  assert_equal(1, winnr())
490  assert_equal(&columns, winwidth(0))
491  close
492  close
493
494  gettabinfo()->len()->assert_equal(1)
495  tab split
496  gettabinfo()->len()->assert_equal(2)
497  tabclose
498
499  vertical new
500  assert_inrange(&columns / 2 - 2, &columns / 2 + 1, winwidth(0))
501  close
502enddef
503
504func Test_command_modifier_confirm()
505  CheckNotGui
506  CheckRunVimInTerminal
507
508  " Test for saving all the modified buffers
509  let lines =<< trim END
510    call setline(1, 'changed')
511    def Getout()
512      confirm write Xfile
513    enddef
514  END
515  call writefile(lines, 'Xconfirmscript')
516  call writefile(['empty'], 'Xfile')
517  let buf = RunVimInTerminal('-S Xconfirmscript', {'rows': 8})
518  call term_sendkeys(buf, ":call Getout()\n")
519  call WaitForAssert({-> assert_match('(Y)es, \[N\]o: ', term_getline(buf, 8))}, 1000)
520  call term_sendkeys(buf, "y")
521  call WaitForAssert({-> assert_match('(Y)es, \[N\]o: ', term_getline(buf, 8))}, 1000)
522  call term_sendkeys(buf, "\<CR>")
523  call TermWait(buf)
524  call StopVimInTerminal(buf)
525
526  call assert_equal(['changed'], readfile('Xfile'))
527  call delete('Xfile')
528  call delete('.Xfile.swp')  " in case Vim was killed
529  call delete('Xconfirmscript')
530endfunc
531
532def Test_command_modifiers_keep()
533  if has('unix')
534    def DoTest(addRflag: bool, keepMarks: bool, hasMarks: bool)
535      new
536      setline(1, ['one', 'two', 'three'])
537      normal 1Gma
538      normal 2Gmb
539      normal 3Gmc
540      if addRflag
541        set cpo+=R
542      else
543        set cpo-=R
544      endif
545      if keepMarks
546        keepmarks :%!cat
547      else
548        :%!cat
549      endif
550      if hasMarks
551        assert_equal(1, line("'a"))
552        assert_equal(2, line("'b"))
553        assert_equal(3, line("'c"))
554      else
555        assert_equal(0, line("'a"))
556        assert_equal(0, line("'b"))
557        assert_equal(0, line("'c"))
558      endif
559      quit!
560    enddef
561    DoTest(false, false, true)
562    DoTest(true, false, false)
563    DoTest(false, true, true)
564    DoTest(true, true, true)
565    set cpo&vim
566
567    new
568    setline(1, ['one', 'two', 'three', 'four'])
569    assert_equal(4, line("$"))
570    normal 1Gma
571    normal 2Gmb
572    normal 3Gmc
573    lockmarks :1,2!wc
574    # line is deleted, marks don't move
575    assert_equal(3, line("$"))
576    assert_equal('four', getline(3))
577    assert_equal(1, line("'a"))
578    assert_equal(2, line("'b"))
579    assert_equal(3, line("'c"))
580    quit!
581  endif
582
583  edit Xone
584  edit Xtwo
585  assert_equal('Xone', expand('#'))
586  keepalt edit Xthree
587  assert_equal('Xone', expand('#'))
588
589  normal /a*b*
590  assert_equal('a*b*', histget("search"))
591  keeppatterns normal /c*d*
592  assert_equal('a*b*', histget("search"))
593
594  new
595  setline(1, range(10))
596  :10
597  normal gg
598  assert_equal(10, getpos("''")[1])
599  keepjumps normal 5G
600  assert_equal(10, getpos("''")[1])
601  quit!
602enddef
603
604def Test_bar_line_continuation()
605  var lines =<< trim END
606      au BufNewFile Xfile g:readFile = 1
607          | g:readExtra = 2
608      g:readFile = 0
609      g:readExtra = 0
610      edit Xfile
611      assert_equal(1, g:readFile)
612      assert_equal(2, g:readExtra)
613      bwipe!
614      au! BufNewFile
615
616      au BufNewFile Xfile g:readFile = 1
617          | g:readExtra = 2
618          | g:readMore = 3
619      g:readFile = 0
620      g:readExtra = 0
621      g:readMore = 0
622      edit Xfile
623      assert_equal(1, g:readFile)
624      assert_equal(2, g:readExtra)
625      assert_equal(3, g:readMore)
626      bwipe!
627      au! BufNewFile
628      unlet g:readFile
629      unlet g:readExtra
630      unlet g:readMore
631  END
632  CheckDefAndScriptSuccess(lines)
633enddef
634
635def Test_command_modifier_other()
636  new Xsomefile
637  setline(1, 'changed')
638  var buf = bufnr()
639  hide edit Xotherfile
640  var info = getbufinfo(buf)
641  assert_equal(1, info[0].hidden)
642  assert_equal(1, info[0].changed)
643  edit Xsomefile
644  bwipe!
645
646  au BufNewFile Xfile g:readFile = 1
647  g:readFile = 0
648  edit Xfile
649  assert_equal(1, g:readFile)
650  bwipe!
651  g:readFile = 0
652  noautocmd edit Xfile
653  assert_equal(0, g:readFile)
654  au! BufNewFile
655  unlet g:readFile
656
657  noswapfile edit XnoSwap
658  assert_equal(false, &l:swapfile)
659  bwipe!
660
661  var caught = false
662  try
663    sandbox !ls
664  catch /E48:/
665    caught = true
666  endtry
667  assert_true(caught)
668
669  :8verbose g:verbose_now = &verbose
670  assert_equal(8, g:verbose_now)
671  unlet g:verbose_now
672enddef
673
674def EchoHere()
675  echomsg 'here'
676enddef
677def EchoThere()
678  unsilent echomsg 'there'
679enddef
680
681def Test_modifier_silent_unsilent()
682  echomsg 'last one'
683  silent echomsg "text"
684  assert_equal("\nlast one", execute(':1messages'))
685
686  silent! echoerr "error"
687
688  echomsg 'last one'
689  silent EchoHere()
690  assert_equal("\nlast one", execute(':1messages'))
691
692  silent EchoThere()
693  assert_equal("\nthere", execute(':1messages'))
694
695  try
696    silent eval [][0]
697  catch
698    echomsg "caught"
699  endtry
700  assert_equal("\ncaught", execute(':1messages'))
701enddef
702
703def Test_range_after_command_modifier()
704  CheckScriptFailure(['vim9script', 'silent keepjump 1d _'], 'E1050: Colon required before a range: 1d _', 2)
705  new
706  setline(1, 'xxx')
707  CheckScriptSuccess(['vim9script', 'silent keepjump :1d _'])
708  assert_equal('', getline(1))
709  bwipe!
710enddef
711
712def Test_silent_pattern()
713  new
714  silent! :/pat/put _
715  bwipe!
716enddef
717
718def Test_eval_command()
719  var from = 3
720  var to = 5
721  g:val = 111
722  def Increment(nrs: list<number>)
723    for nr in nrs
724      g:val += nr
725    endfor
726  enddef
727  eval range(from, to)
728        ->Increment()
729  assert_equal(111 + 3 + 4 + 5, g:val)
730  unlet g:val
731
732  var lines =<< trim END
733    vim9script
734    g:caught = 'no'
735    try
736      eval 123 || 0
737    catch
738      g:caught = 'yes'
739    endtry
740    assert_equal('yes', g:caught)
741    unlet g:caught
742  END
743  CheckScriptSuccess(lines)
744enddef
745
746def Test_map_command()
747  var lines =<< trim END
748      nnoremap <F3> :echo 'hit F3 #'<CR>
749      assert_equal(":echo 'hit F3 #'<CR>", maparg("<F3>", "n"))
750  END
751  CheckDefSuccess(lines)
752  CheckScriptSuccess(['vim9script'] + lines)
753enddef
754
755def Test_normal_command()
756  new
757  setline(1, 'doesnotexist')
758  var caught = 0
759  try
760    exe "norm! \<C-]>"
761  catch /E433/
762    caught = 2
763  endtry
764  assert_equal(2, caught)
765
766  try
767    exe "norm! 3\<C-]>"
768  catch /E433/
769    caught = 3
770  endtry
771  assert_equal(3, caught)
772  bwipe!
773enddef
774
775def Test_put_command()
776  new
777  @p = 'ppp'
778  put p
779  assert_equal('ppp', getline(2))
780
781  put ='below'
782  assert_equal('below', getline(3))
783  put! ='above'
784  assert_equal('above', getline(3))
785  assert_equal('below', getline(4))
786
787  :2put =['a', 'b', 'c']
788  assert_equal(['ppp', 'a', 'b', 'c', 'above'], getline(2, 6))
789
790  # compute range at runtime
791  setline(1, range(1, 8))
792  @a = 'aaa'
793  :$-2put a
794  assert_equal('aaa', getline(7))
795
796  setline(1, range(1, 8))
797  :2
798  :+2put! a
799  assert_equal('aaa', getline(4))
800
801  []->mapnew(() => 0)
802  :$put ='end'
803  assert_equal('end', getline('$'))
804
805  bwipe!
806
807  CheckDefFailure(['put =xxx'], 'E1001:')
808enddef
809
810def Test_put_with_linebreak()
811  new
812  var lines =<< trim END
813    vim9script
814    pu =split('abc', '\zs')
815            ->join()
816  END
817  CheckScriptSuccess(lines)
818  getline(2)->assert_equal('a b c')
819  bwipe!
820enddef
821
822def Test_command_star_range()
823  new
824  setline(1, ['xxx foo xxx', 'xxx bar xxx', 'xxx foo xx bar'])
825  setpos("'<", [0, 1, 0, 0])
826  setpos("'>", [0, 3, 0, 0])
827  :*s/\(foo\|bar\)/baz/g
828  getline(1, 3)->assert_equal(['xxx baz xxx', 'xxx baz xxx', 'xxx baz xx baz'])
829
830  bwipe!
831enddef
832
833def Test_f_args()
834  var lines =<< trim END
835    vim9script
836
837    func SaveCmdArgs(...)
838      let g:args = a:000
839    endfunc
840
841    command -nargs=* TestFArgs call SaveCmdArgs(<f-args>)
842
843    TestFArgs
844    assert_equal([], g:args)
845
846    TestFArgs one two three
847    assert_equal(['one', 'two', 'three'], g:args)
848  END
849  CheckScriptSuccess(lines)
850enddef
851
852def Test_user_command_comment()
853  command -nargs=1 Comd echom <q-args>
854
855  var lines =<< trim END
856    vim9script
857    Comd # comment
858  END
859  CheckScriptSuccess(lines)
860
861  lines =<< trim END
862    vim9script
863    Comd# comment
864  END
865  CheckScriptFailure(lines, 'E1144:')
866
867  delcommand Comd
868enddef
869
870def Test_star_command()
871  var lines =<< trim END
872    vim9script
873    @s = 'g:success = 8'
874    set cpo+=*
875    exe '*s'
876    assert_equal(8, g:success)
877    unlet g:success
878    set cpo-=*
879    assert_fails("exe '*s'", 'E1050:')
880  END
881  CheckScriptSuccess(lines)
882enddef
883
884def Test_cmd_argument_without_colon()
885  new Xfile
886  setline(1, ['a', 'b', 'c', 'd'])
887  write
888  edit +3 %
889  assert_equal(3, getcurpos()[1])
890  edit +/a %
891  assert_equal(1, getcurpos()[1])
892  bwipe
893  delete('Xfile')
894enddef
895
896def Test_ambiguous_user_cmd()
897  command Cmd1 eval 0
898  command Cmd2 eval 0
899  var lines =<< trim END
900      Cmd
901  END
902  CheckDefAndScriptFailure(lines, 'E464:', 1)
903  delcommand Cmd1
904  delcommand Cmd2
905enddef
906
907def Test_command_not_recognized()
908  var lines =<< trim END
909    d.key = 'asdf'
910  END
911  CheckDefFailure(lines, 'E1146:', 1)
912
913  lines =<< trim END
914    d['key'] = 'asdf'
915  END
916  CheckDefFailure(lines, 'E1146:', 1)
917enddef
918
919def Test_magic_not_used()
920  new
921  for cmd in ['set magic', 'set nomagic']
922    exe cmd
923    setline(1, 'aaa')
924    s/.../bbb/
925    assert_equal('bbb', getline(1))
926  endfor
927
928  set magic
929  setline(1, 'aaa')
930  assert_fails('s/.\M../bbb/', 'E486:')
931  assert_fails('snomagic/.../bbb/', 'E486:')
932  assert_equal('aaa', getline(1))
933
934  bwipe!
935enddef
936
937def Test_gdefault_not_used()
938  new
939  for cmd in ['set gdefault', 'set nogdefault']
940    exe cmd
941    setline(1, 'aaa')
942    s/./b/
943    assert_equal('baa', getline(1))
944  endfor
945
946  set nogdefault
947  bwipe!
948enddef
949
950def g:SomeComplFunc(findstart: number, base: string): any
951  if findstart
952    return 0
953  else
954    return ['aaa', 'bbb']
955  endif
956enddef
957
958def Test_insert_complete()
959  # this was running into an error with the matchparen hack
960  new
961  set completefunc=SomeComplFunc
962  feedkeys("i\<c-x>\<c-u>\<Esc>", 'ntx')
963  assert_equal('aaa', getline(1))
964
965  set completefunc=
966  bwipe!
967enddef
968
969def Test_wincmd()
970  split
971  var id1 = win_getid()
972  if true
973    try | wincmd w | catch | endtry
974  endif
975  assert_notequal(id1, win_getid())
976  close
977enddef
978
979def Test_windo_missing_endif()
980  var lines =<< trim END
981      windo if 1
982  END
983  CheckDefExecFailure(lines, 'E171:', 1)
984enddef
985
986" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
987