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