1" Tests for Vim9 script expressions
2
3source check.vim
4source vim9.vim
5
6let g:cond = v:false
7def FuncOne(arg: number): string
8  return 'yes'
9enddef
10def FuncTwo(arg: number): number
11  return 123
12enddef
13
14" test cond ? expr : expr
15def Test_expr1_trinary()
16  var lines =<< trim END
17      assert_equal('one', true ? 'one' : 'two')
18      assert_equal('one', 1 ?
19                            'one' :
20                            'two')
21      if has('float')
22        assert_equal('one', !!0.1 ? 'one' : 'two')
23      endif
24      assert_equal('one', !!'x' ? 'one' : 'two')
25      assert_equal('one', !!'x'
26                            ? 'one'
27                            : 'two')
28      assert_equal('one', !!0z1234 ? 'one' : 'two')
29      assert_equal('one', !![0] ? 'one' : 'two')
30      assert_equal('one', !!{x: 0} ? 'one' : 'two')
31      var name = 1
32      assert_equal('one', name ? 'one' : 'two')
33
34      assert_equal('two', false ? 'one' : 'two')
35      assert_equal('two', 0 ? 'one' : 'two')
36      if has('float')
37        assert_equal('two', !!0.0 ? 'one' : 'two')
38      endif
39      assert_equal('two', !!'' ? 'one' : 'two')
40      assert_equal('two', !!0z ? 'one' : 'two')
41      assert_equal('two', !![] ? 'one' : 'two')
42      assert_equal('two', !!{} ? 'one' : 'two')
43      name = 0
44      assert_equal('two', name ? 'one' : 'two')
45
46      echo ['a'] + (1 ? ['b'] : ['c']
47                )
48      echo ['a'] + (1 ? ['b'] : ['c'] # comment
49                )
50
51      # with constant condition expression is not evaluated
52      assert_equal('one', 1 ? 'one' : xxx)
53
54      var Some: func = function('len')
55      var Other: func = function('winnr')
56      var Res: func = g:atrue ? Some : Other
57      assert_equal(function('len'), Res)
58
59      var RetOne: func(string): number = function('len')
60      var RetTwo: func(string): number = function('winnr')
61      var RetThat: func = g:atrue ? RetOne : RetTwo
62      assert_equal(function('len'), RetThat)
63
64      var X = FuncOne
65      var Y = FuncTwo
66      var Z = g:cond ? FuncOne : FuncTwo
67      assert_equal(123, Z(3))
68  END
69  CheckDefAndScriptSuccess(lines)
70enddef
71
72def Test_expr1_trinary_vimscript()
73  # check line continuation
74  var lines =<< trim END
75      var name = 1
76      		? 'yes'
77		: 'no'
78      assert_equal('yes', name)
79  END
80  CheckDefAndScriptSuccess(lines)
81
82  lines =<< trim END
83      var name = v:false
84      		? 'yes'
85		: 'no'
86      assert_equal('no', name)
87  END
88  CheckDefAndScriptSuccess(lines)
89
90  lines =<< trim END
91      var name = v:false ?
92      		'yes' :
93		'no'
94      assert_equal('no', name)
95  END
96  CheckDefAndScriptSuccess(lines)
97
98  lines =<< trim END
99      var name = v:false ?  # comment
100      		'yes' :
101                # comment
102		'no' # comment
103      assert_equal('no', name)
104  END
105  CheckDefAndScriptSuccess(lines)
106
107  # check white space
108  lines =<< trim END
109      var name = v:true?1:2
110  END
111  CheckDefAndScriptFailure(lines, 'E1004: White space required before and after ''?'' at "?1:2"', 1)
112
113  lines =<< trim END
114      var name = v:true? 1 : 2
115  END
116  CheckDefAndScriptFailure(lines, 'E1004:', 1)
117
118  lines =<< trim END
119      var name = v:true ?1 : 2
120  END
121  CheckDefAndScriptFailure(lines, 'E1004:', 1)
122
123  lines =<< trim END
124      var name = v:true ? 1: 2
125  END
126  CheckDefAndScriptFailure(lines, 'E1004: White space required before and after '':'' at ": 2"', 1)
127
128  lines =<< trim END
129      var name = v:true ? 1 :2
130  END
131  CheckDefAndScriptFailure(lines, 'E1004:', 1)
132
133  lines =<< trim END
134      var name = 'x' ? 1 : 2
135  END
136  CheckDefAndScriptFailure(lines, 'E1135:', 1)
137
138  lines =<< trim END
139      var name = [] ? 1 : 2
140  END
141  CheckDefExecAndScriptFailure(lines, 'E745:', 1)
142
143  lines =<< trim END
144      var name = {} ? 1 : 2
145  END
146  CheckDefExecAndScriptFailure(lines, 'E728:', 1)
147
148  # check after failure eval_flags is reset
149  lines =<< trim END
150      try
151        eval('0 ? 1: 2')
152      catch
153      endtry
154      assert_equal(v:true, eval(string(v:true)))
155  END
156  CheckDefAndScriptSuccess(lines)
157
158  lines =<< trim END
159      try
160        eval('0 ? 1 :2')
161      catch
162      endtry
163      assert_equal(v:true, eval(string(v:true)))
164  END
165  CheckDefAndScriptSuccess(lines)
166enddef
167
168func Test_expr1_trinary_fails()
169  call CheckDefAndScriptFailure(["var x = 1 ? 'one'"], "Missing ':' after '?'", 1)
170
171  let msg = "White space required before and after '?'"
172  call CheckDefAndScriptFailure(["var x = 1? 'one' : 'two'"], msg, 1)
173  call CheckDefAndScriptFailure(["var x = 1 ?'one' : 'two'"], msg, 1)
174  call CheckDefAndScriptFailure(["var x = 1?'one' : 'two'"], msg, 1)
175
176  let msg = "White space required before and after ':'"
177  call CheckDefAndScriptFailure(["var x = 1 ? 'one': 'two'"], msg, 1)
178  call CheckDefAndScriptFailure(["var x = 1 ? 'one' :'two'"], msg, 1)
179  call CheckDefAndScriptFailure(["var x = 1 ? 'one':'two'"], msg, 1)
180
181  call CheckDefAndScriptFailure(["var x = 'x' ? 'one' : 'two'"], 'E1135:', 1)
182  call CheckDefAndScriptFailure(["var x = 0z1234 ? 'one' : 'two'"], 'E974:', 1)
183  call CheckDefExecAndScriptFailure(["var x = [] ? 'one' : 'two'"], 'E745:', 1)
184  call CheckDefExecAndScriptFailure(["var x = {} ? 'one' : 'two'"], 'E728:', 1)
185
186  call CheckDefExecFailure(["var x = false ? "], 'E1097:', 3)
187  call CheckScriptFailure(['vim9script', "var x = false ? "], 'E15:', 2)
188  call CheckDefExecFailure(["var x = false ? 'one' : "], 'E1097:', 3)
189  call CheckScriptFailure(['vim9script', "var x = false ? 'one' : "], 'E15:', 2)
190
191  call CheckDefExecAndScriptFailure2(["var x = true ? xxx : 'foo'"], 'E1001:', 'E121:', 1)
192  call CheckDefExecAndScriptFailure2(["var x = false ? 'foo' : xxx"], 'E1001:', 'E121:', 1)
193
194  if has('float')
195    call CheckDefAndScriptFailure(["var x = 0.1 ? 'one' : 'two'"], 'E805:', 1)
196  endif
197
198  " missing argument detected even when common type is used
199  call CheckDefAndScriptFailure([
200	\ 'var X = FuncOne',
201	\ 'var Y = FuncTwo',
202	\ 'var Z = g:cond ? FuncOne : FuncTwo',
203	\ 'Z()'], 'E119:', 4)
204endfunc
205
206def Test_expr1_falsy()
207  var lines =<< trim END
208      assert_equal(v:true, v:true ?? 456)
209      assert_equal(123, 123 ?? 456)
210      assert_equal('yes', 'yes' ?? 456)
211      assert_equal([1], [1] ?? 456)
212      assert_equal({one: 1}, {one: 1} ?? 456)
213      if has('float')
214        assert_equal(0.1, 0.1 ?? 456)
215      endif
216
217      assert_equal(456, v:false ?? 456)
218      assert_equal(456, 0 ?? 456)
219      assert_equal(456, '' ?? 456)
220      assert_equal(456, [] ?? 456)
221      assert_equal(456, {} ?? 456)
222      if has('float')
223        assert_equal(456, 0.0 ?? 456)
224      endif
225  END
226  CheckDefAndScriptSuccess(lines)
227
228  var msg = "White space required before and after '??'"
229  call CheckDefAndScriptFailure(["var x = 1?? 'one' : 'two'"], msg, 1)
230  call CheckDefAndScriptFailure(["var x = 1 ??'one' : 'two'"], msg, 1)
231  call CheckDefAndScriptFailure(["var x = 1??'one' : 'two'"], msg, 1)
232enddef
233
234def Record(val: any): any
235  g:vals->add(val)
236  return val
237enddef
238
239" test ||
240def Test_expr2()
241  var lines =<< trim END
242      assert_equal(true, 1 || 0)
243      assert_equal(true, 0 ||
244                        0 ||
245                        1)
246      assert_equal(true, 0 ||
247			0 ||
248			!!7)
249      assert_equal(false, 0 || 0)
250      assert_equal(false, 0
251                        || 0)
252      assert_equal(false, 0 || false)
253
254      g:vals = []
255      assert_equal(true, Record(1) || Record(3))
256      assert_equal([1], g:vals)
257
258      g:vals = []
259      assert_equal(true, Record(0) || Record(1))
260      assert_equal([0, 1], g:vals)
261
262      g:vals = []
263      assert_equal(true, Record(0) || Record(true))
264      assert_equal([0, true], g:vals)
265
266      g:vals = []
267      assert_equal(true, Record(0)
268                          || Record(1)
269                          || Record(0))
270      assert_equal([0, 1], g:vals)
271
272      g:vals = []
273      assert_equal(true, Record(0)
274			  || Record(true)
275			  || Record(0))
276      assert_equal([0, true], g:vals)
277
278      g:vals = []
279      assert_equal(true, Record(true) || Record(false))
280      assert_equal([true], g:vals)
281
282      g:vals = []
283      assert_equal(false, Record(0) || Record(false) || Record(0))
284      assert_equal([0, false, 0], g:vals)
285  END
286  CheckDefAndScriptSuccess(lines)
287enddef
288
289def Test_expr2_vimscript()
290  # check line continuation
291  var lines =<< trim END
292      var name = 0
293      		|| 1
294      assert_equal(true, name)
295  END
296  CheckDefAndScriptSuccess(lines)
297
298  lines =<< trim END
299      var name = v:false
300      		|| v:true
301      		|| v:false
302      assert_equal(v:true, name)
303  END
304  CheckDefAndScriptSuccess(lines)
305
306  lines =<< trim END
307      var name = v:false ||
308      		v:true ||
309		v:false
310      assert_equal(v:true, name)
311  END
312  CheckDefAndScriptSuccess(lines)
313
314  lines =<< trim END
315      var name = v:false || # comment
316                # comment
317      		v:true ||
318                # comment
319		v:false # comment
320      assert_equal(v:true, name)
321  END
322  CheckDefAndScriptSuccess(lines)
323
324  # check white space
325  lines =<< trim END
326      var name = v:true||v:true
327  END
328  CheckDefExecAndScriptFailure(lines, 'E1004: White space required before and after ''||'' at "||v:true"', 1)
329
330  lines =<< trim END
331      var name = v:true ||v:true
332  END
333  CheckDefAndScriptFailure(lines, 'E1004:', 1)
334
335  lines =<< trim END
336      var name = v:true|| v:true
337  END
338  CheckDefAndScriptFailure(lines, 'E1004:', 1)
339enddef
340
341def Test_expr2_fails()
342  var msg = "White space required before and after '||'"
343  call CheckDefAndScriptFailure(["var x = 1||2"], msg, 1)
344  call CheckDefAndScriptFailure(["var x = 1 ||2"], msg, 1)
345  call CheckDefAndScriptFailure(["var x = 1|| 2"], msg, 1)
346
347  call CheckDefFailure(["var x = false || "], 'E1097:', 3)
348  call CheckScriptFailure(['vim9script', "var x = false || "], 'E15:', 2)
349
350  # script does not fail, the second expression is skipped
351  call CheckDefFailure(["var x = 1 || xxx"], 'E1001:', 1)
352
353  call CheckDefAndScriptFailure2(["var x = [] || false"], 'E1012:', 'E745:', 1)
354
355  call CheckDefAndScriptFailure2(["if 'yes' || 0", 'echo 0', 'endif'], 'E1012: Type mismatch; expected bool but got string', 'E1135: Using a String as a Bool', 1)
356
357  # TODO: should fail at compile time
358  call CheckDefExecAndScriptFailure(["var x = 3 || 7"], 'E1023:', 1)
359
360  call CheckDefAndScriptFailure2(["var x = [] || false"], 'E1012: Type mismatch; expected bool but got list<unknown>', 'E745:', 1)
361
362enddef
363
364" test &&
365def Test_expr3()
366  var lines =<< trim END
367      assert_equal(false, 1 && 0)
368      assert_equal(false, 0 &&
369                    0 &&
370                    1)
371      assert_equal(true, 1
372                        && true
373                        && 1)
374      assert_equal(false, 0 && 0)
375      assert_equal(false, 0 && false)
376      assert_equal(true, 1 && true)
377
378      g:vals = []
379      assert_equal(true, Record(true) && Record(1))
380      assert_equal([true, 1], g:vals)
381
382      g:vals = []
383      assert_equal(true, Record(1) && Record(true))
384      assert_equal([1, true], g:vals)
385
386      g:vals = []
387      assert_equal(false, Record(0) && Record(1))
388      assert_equal([0], g:vals)
389
390      g:vals = []
391      assert_equal(false, Record(0) && Record(1) && Record(0))
392      assert_equal([0], g:vals)
393
394      g:vals = []
395      assert_equal(false, Record(0) && Record(4) && Record(0))
396      assert_equal([0], g:vals)
397
398      g:vals = []
399      assert_equal(false, Record(1) && Record(true) && Record(0))
400      assert_equal([1, true, 0], g:vals)
401  END
402  CheckDefAndScriptSuccess(lines)
403enddef
404
405def Test_expr3_vimscript()
406  # check line continuation
407  var lines =<< trim END
408      var name = 0
409      		&& 1
410      assert_equal(false, name)
411  END
412  CheckDefAndScriptSuccess(lines)
413
414  lines =<< trim END
415      var name = v:true
416      		&& v:true
417      		&& v:true
418      assert_equal(v:true, name)
419  END
420  CheckDefAndScriptSuccess(lines)
421
422  lines =<< trim END
423      var name = v:true &&
424      		v:true &&
425      		v:true
426      assert_equal(v:true, name)
427  END
428  CheckDefAndScriptSuccess(lines)
429
430  lines =<< trim END
431      var name = v:true &&  # comment
432                # comment
433      		v:true &&
434                # comment
435      		v:true
436      assert_equal(v:true, name)
437  END
438  CheckDefAndScriptSuccess(lines)
439
440  # check white space
441  lines =<< trim END
442      var name = v:true&&v:true
443  END
444  CheckDefAndScriptFailure(lines, 'E1004:', 1)
445
446  lines =<< trim END
447      var name = v:true &&v:true
448  END
449  CheckDefAndScriptFailure(lines, 'E1004: White space required before and after ''&&'' at "&&v:true"', 1)
450
451  lines =<< trim END
452      var name = v:true&& v:true
453  END
454  CheckDefAndScriptFailure(lines, 'E1004:', 1)
455enddef
456
457def Test_expr3_fails()
458  var msg = "White space required before and after '&&'"
459  CheckDefAndScriptFailure(["var x = 1&&2"], msg, 1)
460  CheckDefAndScriptFailure(["var x = 1 &&2"], msg, 1)
461  CheckDefAndScriptFailure(["var x = 1&& 2"], msg, 1)
462
463  g:vals = []
464  CheckDefAndScriptFailure2(["if 'yes' && 0", 'echo 0', 'endif'], 'E1012: Type mismatch; expected bool but got string', 'E1135: Using a String as a Bool', 1)
465
466  CheckDefExecAndScriptFailure(['assert_equal(false, Record(1) && Record(4) && Record(0))'], 'E1023: Using a Number as a Bool: 4', 1)
467
468  var lines =<< trim END
469      if 3
470          && true
471      endif
472  END
473  CheckDefExecAndScriptFailure(lines, 'E1023:', 1)
474
475  lines =<< trim END
476      if 'yes'
477          && true
478      endif
479  END
480  CheckDefAndScriptFailure2(lines, 'E1012:', 'E1135: Using a String as a Bool', 1)
481enddef
482
483" global variables to use for tests with the "any" type
484let atrue = v:true
485let afalse = v:false
486let anone = v:none
487let anull = v:null
488let anint = 10
489let theone = 1
490let thefour = 4
491if has('float')
492  let afloat = 0.1
493endif
494let astring = 'asdf'
495let ablob = 0z01ab
496let alist = [2, 3, 4]
497let adict = #{aaa: 2, bbb: 8}
498
499" test == comperator
500def Test_expr4_equal()
501  var lines =<< trim END
502      var trueVar = true
503      var falseVar = false
504      assert_equal(true, true == true)
505      assert_equal(false, true ==
506                            false)
507      assert_equal(true, true
508                            == trueVar)
509      assert_equal(false, true == falseVar)
510      assert_equal(true, true == g:atrue)
511      assert_equal(false, g:atrue == false)
512
513      assert_equal(true, v:none == v:none)
514      assert_equal(false, v:none == v:null)
515      assert_equal(true, g:anone == v:none)
516      assert_equal(true, null == v:null)
517      assert_equal(true, null == g:anull)
518      assert_equal(false, v:none == g:anull)
519
520      var nr0 = 0
521      var nr61 = 61
522      assert_equal(false, 2 == 0)
523      assert_equal(false, 2 == nr0)
524      assert_equal(true, 61 == 61)
525      assert_equal(true, 61 == nr61)
526      assert_equal(true, g:anint == 10)
527      assert_equal(false, 61 == g:anint)
528
529      if has('float')
530        var ff = 0.3
531        assert_equal(true, ff == 0.3)
532        assert_equal(false, 0.4 == ff)
533        assert_equal(true, 0.1 == g:afloat)
534        assert_equal(false, g:afloat == 0.3)
535
536        ff = 3.0
537        assert_equal(true, ff == 3)
538        assert_equal(true, 3 == ff)
539        ff = 3.1
540        assert_equal(false, ff == 3)
541        assert_equal(false, 3 == ff)
542      endif
543
544      assert_equal(true, 'abc' == 'abc')
545      assert_equal(false, 'xyz' == 'abc')
546      assert_equal(true, g:astring == 'asdf')
547      assert_equal(false, 'xyz' == g:astring)
548
549      assert_equal(false, 'abc' == 'aBc')
550      assert_equal(false, 'abc' ==# 'aBc')
551      assert_equal(true, 'abc' ==? 'aBc')
552
553      assert_equal(false, 'abc' == 'ABC')
554      set ignorecase
555      assert_equal(false, 'abc' == 'ABC')
556      assert_equal(false, 'abc' ==# 'ABC')
557      assert_equal(true, 'abc' ==? 'ABC')
558      set noignorecase
559
560      var bb = 0z3f
561      assert_equal(true, 0z3f == bb)
562      assert_equal(false, bb == 0z4f)
563      assert_equal(true, g:ablob == 0z01ab)
564      assert_equal(false, 0z3f == g:ablob)
565
566      assert_equal(true, [1, 2, 3] == [1, 2, 3])
567      assert_equal(false, [1, 2, 3] == [2, 3, 1])
568      assert_equal(true, [2, 3, 4] == g:alist)
569      assert_equal(false, g:alist == [2, 3, 1])
570      assert_equal(false, [1, 2, 3] == [])
571      assert_equal(false, [1, 2, 3] == ['1', '2', '3'])
572
573      assert_equal(true, {one: 1, two: 2} == {one: 1, two: 2})
574      assert_equal(false, {one: 1, two: 2} == {one: 2, two: 2})
575      assert_equal(false, {one: 1, two: 2} == {two: 2})
576      assert_equal(false, {one: 1, two: 2} == {})
577      assert_equal(true, g:adict == {bbb: 8, aaa: 2})
578      assert_equal(false, {ccc: 9, aaa: 2} == g:adict)
579
580      assert_equal(true, function('g:Test_expr4_equal') == function('g:Test_expr4_equal'))
581      assert_equal(false, function('g:Test_expr4_equal') == function('g:Test_expr4_is'))
582
583      assert_equal(true, function('g:Test_expr4_equal', [123]) == function('g:Test_expr4_equal', [123]))
584      assert_equal(false, function('g:Test_expr4_equal', [123]) == function('g:Test_expr4_is', [123]))
585      assert_equal(false, function('g:Test_expr4_equal', [123]) == function('g:Test_expr4_equal', [999]))
586
587      # TODO: this unexpectedly sometimes fails on Appveyor
588      if !has('win32')
589        var OneFunc: func
590        var TwoFunc: func
591        OneFunc = function('len')
592        TwoFunc = function('len')
593        assert_equal(true, OneFunc('abc') == TwoFunc('123'))
594      endif
595  END
596  CheckDefAndScriptSuccess(lines)
597
598  CheckDefAndScriptFailure2(["var x = 'a' == xxx"], 'E1001:', 'E121:', 1)
599  CheckDefFailure(["var x = 'a' == "], 'E1097:', 3)
600  CheckScriptFailure(['vim9script', "var x = 'a' == "], 'E15:', 2)
601
602  CheckDefExecAndScriptFailure2(['var items: any', 'eval 1', 'eval 2', 'if items == []', 'endif'], 'E691:', 'E1072:', 4)
603
604  CheckDefExecAndScriptFailure(['var x: any = "a"', 'echo x == true'], 'E1072: Cannot compare string with bool', 2)
605  CheckDefExecAndScriptFailure(["var x: any = true", 'echo x == ""'], 'E1072: Cannot compare bool with string', 2)
606  CheckDefExecAndScriptFailure2(["var x: any = 99", 'echo x == true'], 'E1138', 'E1072:', 2)
607  CheckDefExecAndScriptFailure2(["var x: any = 'a'", 'echo x == 99'], 'E1030:', 'E1072:', 2)
608
609  for op in ['>', '>=', '<', '<=', '=~', '!~']
610    CheckDefExecAndScriptFailure([
611        "var a: any = 'a'",
612        'var b: any = true',
613        'echo a ' .. op .. ' b'], 'E1072:', 3)
614  endfor
615enddef
616
617" test != comperator
618def Test_expr4_notequal()
619  var lines =<< trim END
620      var trueVar = true
621      var falseVar = false
622      assert_equal(false, true != true)
623      assert_equal(true, true !=
624                            false)
625      assert_equal(false, true
626                            != trueVar)
627      assert_equal(true, true != falseVar)
628      assert_equal(false, true != g:atrue)
629      assert_equal(true, g:atrue != false)
630
631      assert_equal(false, v:none != v:none)
632      assert_equal(true, v:none != v:null)
633      assert_equal(false, g:anone != v:none)
634      assert_equal(true, v:none != g:anull)
635
636      var nr55 = 55
637      var nr0 = 55
638      assert_equal(true, 2 != 0)
639      assert_equal(true, 2 != nr0)
640      assert_equal(false, 55 != 55)
641      assert_equal(false, 55 != nr55)
642      assert_equal(false, g:anint != 10)
643      assert_equal(true, 61 != g:anint)
644
645      if has('float')
646        var ff = 0.3
647        assert_equal(false, 0.3 != ff)
648        assert_equal(true, 0.4 != ff)
649        assert_equal(false, 0.1 != g:afloat)
650        assert_equal(true, g:afloat != 0.3)
651
652        ff = 3.0
653        assert_equal(false, ff != 3)
654        assert_equal(false, 3 != ff)
655        ff = 3.1
656        assert_equal(true, ff != 3)
657        assert_equal(true, 3 != ff)
658      endif
659
660      assert_equal(false, 'abc' != 'abc')
661      assert_equal(true, 'xyz' != 'abc')
662      assert_equal(false, g:astring != 'asdf')
663      assert_equal(true, 'xyz' != g:astring)
664
665      assert_equal(true, 'abc' != 'ABC')
666      set ignorecase
667      assert_equal(true, 'abc' != 'ABC')
668      assert_equal(true, 'abc' !=# 'ABC')
669      assert_equal(false, 'abc' !=? 'ABC')
670      set noignorecase
671
672      var bb = 0z3f
673      assert_equal(false, 0z3f != bb)
674      assert_equal(true, bb != 0z4f)
675      assert_equal(false, g:ablob != 0z01ab)
676      assert_equal(true, 0z3f != g:ablob)
677
678      assert_equal(false, [1, 2, 3] != [1, 2, 3])
679      assert_equal(true, [1, 2, 3] != [2, 3, 1])
680      assert_equal(false, [2, 3, 4] != g:alist)
681      assert_equal(true, g:alist != [2, 3, 1])
682      assert_equal(true, [1, 2, 3] != [])
683      assert_equal(true, [1, 2, 3] != ['1', '2', '3'])
684
685      assert_equal(false, {one: 1, two: 2} != {one: 1, two: 2})
686      assert_equal(true, {one: 1, two: 2} != {one: 2, two: 2})
687      assert_equal(true, {one: 1, two: 2} != {two: 2})
688      assert_equal(true, {one: 1, two: 2} != {})
689      assert_equal(false, g:adict != {bbb: 8, aaa: 2})
690      assert_equal(true, {ccc: 9, aaa: 2} != g:adict)
691
692      assert_equal(false, function('g:Test_expr4_equal') != function('g:Test_expr4_equal'))
693      assert_equal(true, function('g:Test_expr4_equal') != function('g:Test_expr4_is'))
694
695      assert_equal(false, function('g:Test_expr4_equal', [123]) != function('g:Test_expr4_equal', [123]))
696      assert_equal(true, function('g:Test_expr4_equal', [123]) != function('g:Test_expr4_is', [123]))
697      assert_equal(true, function('g:Test_expr4_equal', [123]) != function('g:Test_expr4_equal', [999]))
698  END
699  CheckDefAndScriptSuccess(lines)
700enddef
701
702" test > comperator
703def Test_expr4_greater()
704  var lines =<< trim END
705      assert_true(2 > 0)
706      assert_true(2 >
707                    1)
708      assert_false(2 > 2)
709      assert_false(2 > 3)
710      var nr2 = 2
711      assert_true(nr2 > 0)
712      assert_true(nr2 >
713                    1)
714      assert_false(nr2 > 2)
715      assert_false(nr2
716                        > 3)
717      if has('float')
718        var ff = 2.0
719        assert_true(ff > 0.0)
720        assert_true(ff > 1.0)
721        assert_false(ff > 2.0)
722        assert_false(ff > 3.0)
723      endif
724  END
725  CheckDefAndScriptSuccess(lines)
726enddef
727
728" test >= comperator
729def Test_expr4_greaterequal()
730  var lines =<< trim END
731      assert_true(2 >= 0)
732      assert_true(2 >=
733                            2)
734      assert_false(2 >= 3)
735      var nr2 = 2
736      assert_true(nr2 >= 0)
737      assert_true(nr2 >= 2)
738      assert_false(nr2 >= 3)
739      if has('float')
740        var ff = 2.0
741        assert_true(ff >= 0.0)
742        assert_true(ff >= 2.0)
743        assert_false(ff >= 3.0)
744      endif
745  END
746  CheckDefAndScriptSuccess(lines)
747enddef
748
749" test < comperator
750def Test_expr4_smaller()
751  var lines =<< trim END
752      assert_false(2 < 0)
753      assert_false(2 <
754                            2)
755      assert_true(2
756                    < 3)
757      var nr2 = 2
758      assert_false(nr2 < 0)
759      assert_false(nr2 < 2)
760      assert_true(nr2 < 3)
761      if has('float')
762        var ff = 2.0
763        assert_false(ff < 0.0)
764        assert_false(ff < 2.0)
765        assert_true(ff < 3.0)
766      endif
767  END
768  CheckDefAndScriptSuccess(lines)
769enddef
770
771" test <= comperator
772def Test_expr4_smallerequal()
773  var lines =<< trim END
774      assert_false(2 <= 0)
775      assert_false(2 <=
776                            1)
777      assert_true(2
778                    <= 2)
779      assert_true(2 <= 3)
780      var nr2 = 2
781      assert_false(nr2 <= 0)
782      assert_false(nr2 <= 1)
783      assert_true(nr2 <= 2)
784      assert_true(nr2 <= 3)
785      if has('float')
786        var ff = 2.0
787        assert_false(ff <= 0.0)
788        assert_false(ff <= 1.0)
789        assert_true(ff <= 2.0)
790        assert_true(ff <= 3.0)
791      endif
792  END
793  CheckDefAndScriptSuccess(lines)
794enddef
795
796" test =~ comperator
797def Test_expr4_match()
798  var lines =<< trim END
799      assert_equal(false, '2' =~ '0')
800      assert_equal(false, ''
801                             =~ '0')
802      assert_equal(true, '2' =~
803                            '[0-9]')
804      set ignorecase
805      assert_equal(false, 'abc' =~ 'ABC')
806      assert_equal(false, 'abc' =~# 'ABC')
807      assert_equal(true, 'abc' =~? 'ABC')
808      set noignorecase
809  END
810  CheckDefAndScriptSuccess(lines)
811enddef
812
813" test !~ comperator
814def Test_expr4_nomatch()
815  var lines =<< trim END
816      assert_equal(true, '2' !~ '0')
817      assert_equal(true, ''
818                            !~ '0')
819      assert_equal(false, '2' !~
820                            '[0-9]')
821  END
822  CheckDefAndScriptSuccess(lines)
823enddef
824
825" test is comperator
826def Test_expr4_is()
827  var lines =<< trim END
828      var mylist = [2]
829      assert_false(mylist is [2])
830      var other = mylist
831      assert_true(mylist is
832                    other)
833
834      var myblob = 0z1234
835      assert_false(myblob
836                            is 0z1234)
837      var otherblob = myblob
838      assert_true(myblob is otherblob)
839  END
840  CheckDefAndScriptSuccess(lines)
841enddef
842
843" test isnot comperator
844def Test_expr4_isnot()
845  var lines =<< trim END
846      var mylist = [2]
847      assert_true('2' isnot '0')
848      assert_true(mylist isnot [2])
849      var other = mylist
850      assert_false(mylist isnot
851                            other)
852
853      var myblob = 0z1234
854      assert_true(myblob
855                    isnot 0z1234)
856      var otherblob = myblob
857      assert_false(myblob isnot otherblob)
858  END
859  CheckDefAndScriptSuccess(lines)
860enddef
861
862def RetVoid()
863  var x = 1
864enddef
865
866def Test_expr4_vim9script()
867  # check line continuation
868  var lines =<< trim END
869      var name = 0
870      		< 1
871      assert_equal(true, name)
872  END
873  CheckDefAndScriptSuccess(lines)
874
875  lines =<< trim END
876      var name = 123
877                # comment
878      		!= 123
879      assert_equal(false, name)
880  END
881  CheckDefAndScriptSuccess(lines)
882
883  lines =<< trim END
884      var name = 123 ==
885      			123
886      assert_equal(true, name)
887  END
888  CheckDefAndScriptSuccess(lines)
889
890  lines =<< trim END
891      var list = [1, 2, 3]
892      var name = list
893      		is list
894      assert_equal(true, name)
895  END
896  CheckDefAndScriptSuccess(lines)
897
898  lines =<< trim END
899      var list = [1, 2, 3]
900      var name = list # comment
901                 # comment
902      		is list
903      assert_equal(true, name)
904  END
905  CheckDefAndScriptSuccess(lines)
906
907  lines =<< trim END
908      var myblob = 0z1234
909      var name = myblob
910      		isnot 0z11
911      assert_equal(true, name)
912  END
913  CheckDefAndScriptSuccess(lines)
914
915  # spot check mismatching types
916  lines =<< trim END
917      echo '' == 0
918  END
919  CheckDefAndScriptFailure(lines, 'E1072:', 1)
920
921  lines =<< trim END
922      echo v:true > v:false
923  END
924  CheckDefAndScriptFailure(lines, 'Cannot compare bool with bool', 1)
925
926  lines =<< trim END
927      echo 123 is 123
928  END
929  CheckDefAndScriptFailure(lines, 'Cannot use "is" with number', 1)
930
931  # check missing white space
932  lines =<< trim END
933    echo 2>3
934  END
935  CheckDefAndScriptFailure(lines, 'E1004: White space required before and after ''>'' at ">3"', 1)
936
937  lines =<< trim END
938    echo 2 >3
939  END
940  CheckDefAndScriptFailure(lines, 'E1004:', 1)
941
942  lines =<< trim END
943    echo 2> 3
944  END
945  CheckDefAndScriptFailure(lines, 'E1004:', 1)
946
947  lines =<< trim END
948    echo 2!=3
949  END
950  CheckDefAndScriptFailure(lines, 'E1004:', 1)
951
952  lines =<< trim END
953    echo 2 !=3
954  END
955  CheckDefAndScriptFailure(lines, 'E1004: White space required before and after ''!='' at "!=3"', 1)
956
957  lines =<< trim END
958    echo 2!= 3
959  END
960  CheckDefAndScriptFailure(lines, 'E1004:', 1)
961
962  lines =<< trim END
963    echo len('xxx') == 3
964  END
965  CheckDefAndScriptSuccess(lines)
966
967  lines =<< trim END
968    var line = 'abc'
969    echo line[1] =~ '\w'
970  END
971  CheckDefAndScriptSuccess(lines)
972enddef
973
974func Test_expr4_fails()
975  let msg = "White space required before and after '>'"
976  call CheckDefAndScriptFailure(["var x = 1>2"], msg, 1)
977  call CheckDefAndScriptFailure(["var x = 1 >2"], msg, 1)
978  call CheckDefAndScriptFailure(["var x = 1> 2"], msg, 1)
979
980  let msg = "White space required before and after '=='"
981  call CheckDefAndScriptFailure(["var x = 1==2"], msg, 1)
982  call CheckDefAndScriptFailure(["var x = 1 ==2"], msg, 1)
983  call CheckDefAndScriptFailure(["var x = 1== 2"], msg, 1)
984
985  let msg = "White space required before and after 'is'"
986  call CheckDefAndScriptFailure(["var x = '1'is'2'"], msg, 1)
987  call CheckDefAndScriptFailure(["var x = '1' is'2'"], msg, 1)
988  call CheckDefAndScriptFailure(["var x = '1'is '2'"], msg, 1)
989
990  let msg = "White space required before and after 'isnot'"
991  call CheckDefAndScriptFailure(["var x = '1'isnot'2'"], msg, 1)
992  call CheckDefAndScriptFailure(["var x = '1' isnot'2'"], msg, 1)
993  call CheckDefAndScriptFailure(["var x = '1'isnot '2'"], msg, 1)
994
995  call CheckDefAndScriptFailure(["var x = 1 is# 2"], 'E15:', 1)
996  call CheckDefAndScriptFailure(["var x = 1 is? 2"], 'E15:', 1)
997  call CheckDefAndScriptFailure(["var x = 1 isnot# 2"], 'E15:', 1)
998  call CheckDefAndScriptFailure(["var x = 1 isnot? 2"], 'E15:', 1)
999
1000  call CheckDefAndScriptFailure(["var x = 1 == '2'"], 'Cannot compare number with string', 1)
1001  call CheckDefAndScriptFailure(["var x = '1' == 2"], 'Cannot compare string with number', 1)
1002  call CheckDefAndScriptFailure(["var x = 1 == RetVoid()"], 'Cannot compare number with void', 1)
1003  call CheckDefAndScriptFailure(["var x = RetVoid() == 1"], 'Cannot compare void with number', 1)
1004
1005  call CheckDefAndScriptFailure(["var x = true > false"], 'Cannot compare bool with bool', 1)
1006  call CheckDefAndScriptFailure(["var x = true >= false"], 'Cannot compare bool with bool', 1)
1007  call CheckDefAndScriptFailure(["var x = true < false"], 'Cannot compare bool with bool', 1)
1008  call CheckDefAndScriptFailure(["var x = true <= false"], 'Cannot compare bool with bool', 1)
1009  call CheckDefAndScriptFailure(["var x = true =~ false"], 'Cannot compare bool with bool', 1)
1010  call CheckDefAndScriptFailure(["var x = true !~ false"], 'Cannot compare bool with bool', 1)
1011  call CheckDefAndScriptFailure(["var x = true is false"], 'Cannot use "is" with bool', 1)
1012  call CheckDefAndScriptFailure(["var x = true isnot false"], 'Cannot use "isnot" with bool', 1)
1013
1014  call CheckDefAndScriptFailure(["var x = v:none is v:null"], 'Cannot use "is" with special', 1)
1015  call CheckDefAndScriptFailure(["var x = v:none isnot v:null"], 'Cannot use "isnot" with special', 1)
1016  call CheckDefAndScriptFailure(["var x = 123 is 123"], 'Cannot use "is" with number', 1)
1017  call CheckDefAndScriptFailure(["var x = 123 isnot 123"], 'Cannot use "isnot" with number', 1)
1018  if has('float')
1019    call CheckDefAndScriptFailure(["var x = 1.3 is 1.3"], 'Cannot use "is" with float', 1)
1020    call CheckDefAndScriptFailure(["var x = 1.3 isnot 1.3"], 'Cannot use "isnot" with float', 1)
1021  endif
1022
1023  call CheckDefAndScriptFailure(["var x = 0za1 > 0z34"], 'Cannot compare blob with blob', 1)
1024  call CheckDefAndScriptFailure(["var x = 0za1 >= 0z34"], 'Cannot compare blob with blob', 1)
1025  call CheckDefAndScriptFailure(["var x = 0za1 < 0z34"], 'Cannot compare blob with blob', 1)
1026  call CheckDefAndScriptFailure(["var x = 0za1 <= 0z34"], 'Cannot compare blob with blob', 1)
1027  call CheckDefAndScriptFailure(["var x = 0za1 =~ 0z34"], 'Cannot compare blob with blob', 1)
1028  call CheckDefAndScriptFailure(["var x = 0za1 !~ 0z34"], 'Cannot compare blob with blob', 1)
1029
1030  call CheckDefAndScriptFailure(["var x = [13] > [88]"], 'Cannot compare list with list', 1)
1031  call CheckDefAndScriptFailure(["var x = [13] >= [88]"], 'Cannot compare list with list', 1)
1032  call CheckDefAndScriptFailure(["var x = [13] < [88]"], 'Cannot compare list with list', 1)
1033  call CheckDefAndScriptFailure(["var x = [13] <= [88]"], 'Cannot compare list with list', 1)
1034  call CheckDefAndScriptFailure(["var x = [13] =~ [88]"], 'Cannot compare list with list', 1)
1035  call CheckDefAndScriptFailure(["var x = [13] !~ [88]"], 'Cannot compare list with list', 1)
1036
1037  call CheckDefAndScriptFailure(['var j: job', 'var chan: channel', 'var r = j == chan'], 'Cannot compare job with channel', 3)
1038  call CheckDefAndScriptFailure(['var j: job', 'var x: list<any>', 'var r = j == x'], 'Cannot compare job with list', 3)
1039  call CheckDefAndScriptFailure(['var j: job', 'var Xx: func', 'var r = j == Xx'], 'Cannot compare job with func', 3)
1040  call CheckDefAndScriptFailure(['var j: job', 'var Xx: func', 'var r = j == Xx'], 'Cannot compare job with func', 3)
1041endfunc
1042
1043" test addition, subtraction, concatenation
1044def Test_expr5()
1045  var lines =<< trim END
1046      assert_equal(66, 60 + 6)
1047      assert_equal(70, 60 +
1048                            g:anint)
1049      assert_equal(9, g:thefour
1050                            + 5)
1051      assert_equal(14, g:thefour + g:anint)
1052      assert_equal([1, 2, 3, 4], [1] + g:alist)
1053
1054      assert_equal(54, 60 - 6)
1055      assert_equal(50, 60 -
1056                        g:anint)
1057      assert_equal(-1, g:thefour
1058                            - 5)
1059      assert_equal(-6, g:thefour - g:anint)
1060
1061      assert_equal('hello', 'hel' .. 'lo')
1062      assert_equal('hello 123', 'hello ' ..
1063                                            123)
1064      assert_equal('hello 123', 'hello '
1065                                    ..  123)
1066      assert_equal('123 hello', 123 .. ' hello')
1067      assert_equal('123456', 123 .. 456)
1068
1069      assert_equal('atrue', 'a' .. true)
1070      assert_equal('afalse', 'a' .. false)
1071      assert_equal('anull', 'a' .. v:null)
1072      assert_equal('av:none', 'a' .. v:none)
1073      if has('float')
1074        assert_equal('a0.123', 'a' .. 0.123)
1075      endif
1076
1077      assert_equal(3, 1 + [2, 3, 4][0])
1078      assert_equal(5, 2 + {key: 3}['key'])
1079
1080      set digraph
1081      assert_equal('val: true', 'val: ' .. &digraph)
1082      set nodigraph
1083      assert_equal('val: false', 'val: ' .. &digraph)
1084
1085      assert_equal([1, 2, 3, 4], [1, 2] + [3, 4])
1086      assert_equal(0z11223344, 0z1122 + 0z3344)
1087      assert_equal(0z112201ab, 0z1122
1088                                    + g:ablob)
1089      assert_equal(0z01ab3344, g:ablob + 0z3344)
1090      assert_equal(0z01ab01ab, g:ablob + g:ablob)
1091
1092      # concatenate non-constant to constant
1093      var save_path = &path
1094      &path = 'b'
1095      assert_equal('ab', 'a' .. &path)
1096      &path = save_path
1097
1098      @b = 'b'
1099      assert_equal('ab', 'a' .. @b)
1100
1101      $ENVVAR = 'env'
1102      assert_equal('aenv', 'a' .. $ENVVAR)
1103
1104      assert_equal('val', '' .. {key: 'val'}['key'])
1105  END
1106  CheckDefAndScriptSuccess(lines)
1107enddef
1108
1109def Test_expr5_vim9script()
1110  # check line continuation
1111  var lines =<< trim END
1112      var name = 11
1113      		+ 77
1114		- 22
1115      assert_equal(66, name)
1116  END
1117  CheckDefAndScriptSuccess(lines)
1118
1119  lines =<< trim END
1120      var name = 11 +
1121		  77 -
1122		  22
1123      assert_equal(66, name)
1124  END
1125  CheckDefAndScriptSuccess(lines)
1126
1127  lines =<< trim END
1128      var name = 11 +  # comment
1129		  77 -
1130                  # comment
1131		  22
1132      assert_equal(66, name)
1133  END
1134  CheckDefAndScriptSuccess(lines)
1135
1136  lines =<< trim END
1137      var name = 'one'
1138      		.. 'two'
1139      assert_equal('onetwo', name)
1140  END
1141  CheckDefAndScriptSuccess(lines)
1142
1143  lines =<< trim END
1144      echo 'abc' is# 'abc'
1145  END
1146  CheckDefAndScriptFailure(lines, 'E15:', 1)
1147
1148  lines =<< trim END
1149      echo {} - 22
1150  END
1151  CheckDefAndScriptFailure2(lines, 'E1036:', 'E728:', 1)
1152
1153  lines =<< trim END
1154      echo [] - 33
1155  END
1156  CheckDefAndScriptFailure2(lines, 'E1036:', 'E745:', 1)
1157
1158  lines =<< trim END
1159      echo 0z1234 - 44
1160  END
1161  CheckDefAndScriptFailure2(lines, 'E1036', 'E974:', 1)
1162
1163  lines =<< trim END
1164      echo 'abc' is? 'abc'
1165  END
1166  CheckDefAndScriptFailure(lines, 'E15:', 1)
1167
1168  lines =<< trim END
1169      echo 'abc' isnot# 'abc'
1170  END
1171  CheckDefAndScriptFailure(lines, 'E15:', 1)
1172
1173  lines =<< trim END
1174      echo 'abc' isnot? 'abc'
1175  END
1176  CheckDefAndScriptFailure(lines, 'E15:', 1)
1177
1178  # check white space
1179  lines =<< trim END
1180      echo 5+6
1181  END
1182  CheckDefAndScriptFailure(lines, 'E1004:', 1)
1183  lines =<< trim END
1184      echo 5 +6
1185  END
1186  CheckDefAndScriptFailure(lines, 'E1004:', 1)
1187
1188  lines =<< trim END
1189      echo 5+ 6
1190  END
1191  CheckDefAndScriptFailure(lines, 'E1004:', 1)
1192
1193  lines =<< trim END
1194      echo 'a'..'b'
1195  END
1196  CheckDefAndScriptFailure(lines, 'E1004: White space required before and after ''..'' at "..''b''"', 1)
1197
1198  lines =<< trim END
1199      echo 'a' ..'b'
1200  END
1201  CheckDefAndScriptFailure(lines, 'E1004:', 1)
1202
1203  lines =<< trim END
1204      echo 'a'.. 'b'
1205  END
1206  CheckDefAndScriptFailure(lines, 'E1004:', 1)
1207
1208  # check invalid string concatenation
1209  lines =<< trim END
1210      echo 'a' .. [1]
1211  END
1212  CheckDefAndScriptFailure2(lines, 'E1105:', 'E730:', 1)
1213
1214  lines =<< trim END
1215      echo 'a' .. {a: 1}
1216  END
1217  CheckDefAndScriptFailure2(lines, 'E1105:', 'E731:', 1)
1218
1219  lines =<< trim END
1220      echo 'a' .. test_void()
1221  END
1222  CheckDefAndScriptFailure2(lines, 'E1105:', 'E908:', 1)
1223
1224  lines =<< trim END
1225      echo 'a' .. 0z33
1226  END
1227  CheckDefAndScriptFailure2(lines, 'E1105:', 'E976:', 1)
1228
1229  lines =<< trim END
1230      echo 'a' .. function('len')
1231  END
1232  CheckDefAndScriptFailure2(lines, 'E1105:', 'E729:', 1)
1233
1234  lines =<< trim END
1235      new
1236      ['']->setline(1)
1237      /pattern
1238
1239      eval 0
1240      bwipe!
1241  END
1242  CheckDefAndScriptFailure(lines, "E1004: White space required before and after '/' at \"/pattern", 3)
1243enddef
1244
1245def Test_expr5_vim9script_channel()
1246  if !has('channel')
1247    MissingFeature 'float'
1248  else
1249    var lines =<< trim END
1250        echo 'a' .. test_null_job()
1251    END
1252    CheckDefAndScriptFailure2(lines, 'E1105:', 'E908:', 1)
1253    lines =<< trim END
1254        echo 'a' .. test_null_channel()
1255    END
1256    CheckDefAndScriptFailure2(lines, 'E1105:', 'E908:', 1)
1257  endif
1258enddef
1259
1260def Test_expr5_float()
1261  if !has('float')
1262    MissingFeature 'float'
1263  else
1264    var lines =<< trim END
1265        assert_equal(66.0, 60.0 + 6.0)
1266        assert_equal(66.0, 60.0 + 6)
1267        assert_equal(66.0, 60 +
1268                             6.0)
1269        assert_equal(5.1, g:afloat
1270                            + 5)
1271        assert_equal(8.1, 8 + g:afloat)
1272        assert_equal(10.1, g:anint + g:afloat)
1273        assert_equal(10.1, g:afloat + g:anint)
1274
1275        assert_equal(54.0, 60.0 - 6.0)
1276        assert_equal(54.0, 60.0
1277                                - 6)
1278        assert_equal(54.0, 60 - 6.0)
1279        assert_equal(-4.9, g:afloat - 5)
1280        assert_equal(7.9, 8 - g:afloat)
1281        assert_equal(9.9, g:anint - g:afloat)
1282        assert_equal(-9.9, g:afloat - g:anint)
1283    END
1284    CheckDefAndScriptSuccess(lines)
1285  endif
1286enddef
1287
1288func Test_expr5_fails()
1289  let msg = "White space required before and after '+'"
1290  call CheckDefAndScriptFailure(["var x = 1+2"], msg, 1)
1291  call CheckDefAndScriptFailure(["var x = 1 +2"], msg, 1)
1292  call CheckDefAndScriptFailure(["var x = 1+ 2"], msg, 1)
1293
1294  let msg = "White space required before and after '-'"
1295  call CheckDefAndScriptFailure(["var x = 1-2"], msg, 1)
1296  call CheckDefAndScriptFailure(["var x = 1 -2"], msg, 1)
1297  call CheckDefAndScriptFailure(["var x = 1- 2"], msg, 1)
1298
1299  let msg = "White space required before and after '..'"
1300  call CheckDefAndScriptFailure(["var x = '1'..'2'"], msg, 1)
1301  call CheckDefAndScriptFailure(["var x = '1' ..'2'"], msg, 1)
1302  call CheckDefAndScriptFailure(["var x = '1'.. '2'"], msg, 1)
1303
1304  call CheckDefAndScriptFailure2(["var x = 0z1122 + 33"], 'E1051:', 'E974:', 1)
1305  call CheckDefAndScriptFailure2(["var x = 0z1122 + [3]"], 'E1051:', 'E974:', 1)
1306  call CheckDefAndScriptFailure2(["var x = 0z1122 + 'asd'"], 'E1051:', 'E974:', 1)
1307  call CheckDefAndScriptFailure2(["var x = 33 + 0z1122"], 'E1051:', 'E974:', 1)
1308  call CheckDefAndScriptFailure2(["var x = [3] + 0z1122"], 'E1051:', 'E745:', 1)
1309  call CheckDefAndScriptFailure2(["var x = 'asdf' + 0z1122"], 'E1051:', 'E1030:', 1)
1310  call CheckDefAndScriptFailure2(["var x = 6 + xxx"], 'E1001:', 'E121:', 1)
1311
1312  call CheckDefAndScriptFailure2(["var x = 'a' .. [1]"], 'E1105:', 'E730:', 1)
1313  call CheckDefAndScriptFailure2(["var x = 'a' .. {a: 1}"], 'E1105:', 'E731:', 1)
1314  call CheckDefAndScriptFailure2(["var x = 'a' .. test_void()"], 'E1105:', 'E908:', 1)
1315  call CheckDefAndScriptFailure2(["var x = 'a' .. 0z32"], 'E1105:', 'E976:', 1)
1316  call CheckDefAndScriptFailure2(["var x = 'a' .. function('len')"], 'E1105:', 'E729:', 1)
1317  call CheckDefAndScriptFailure2(["var x = 'a' .. function('len', ['a'])"], 'E1105:', 'E729:', 1)
1318
1319  call CheckDefAndScriptFailure2(['var x = 1 + v:none'], 'E1051:', 'E611:', 1)
1320  call CheckDefAndScriptFailure2(['var x = 1 + v:null'], 'E1051:', 'E611:', 1)
1321  call CheckDefAndScriptFailure2(['var x = 1 + v:true'], 'E1051:', 'E1138:', 1)
1322  call CheckDefAndScriptFailure2(['var x = 1 + v:false'], 'E1051:', 'E1138:', 1)
1323  call CheckDefAndScriptFailure2(['var x = 1 + true'], 'E1051:', 'E1138:', 1)
1324  call CheckDefAndScriptFailure2(['var x = 1 + false'], 'E1051:', 'E1138:', 1)
1325endfunc
1326
1327func Test_expr5_fails_channel()
1328  CheckFeature channel
1329  call CheckDefAndScriptFailure2(["var x = 'a' .. test_null_job()"], 'E1105:', 'E908:', 1)
1330  call CheckDefAndScriptFailure2(["var x = 'a' .. test_null_channel()"], 'E1105:', 'E908:', 1)
1331endfunc
1332
1333def Test_expr5_list_add()
1334  var lines =<< trim END
1335      # concatenating two lists with same member types is OK
1336      var d = {}
1337      for i in ['a'] + ['b']
1338        d = {[i]: 0}
1339      endfor
1340
1341      # concatenating two lists with different member types results in "any"
1342      var dany = {}
1343      for i in ['a'] + [12]
1344        dany[i] = i
1345      endfor
1346      assert_equal({a: 'a', 12: 12}, dany)
1347
1348      # result of glob() is "any", runtime type check
1349      var sl: list<string> = glob('*.txt', false, true) + ['']
1350  END
1351  CheckDefAndScriptSuccess(lines)
1352enddef
1353
1354" test multiply, divide, modulo
1355def Test_expr6()
1356  var lines =<< trim END
1357      assert_equal(36, 6 * 6)
1358      assert_equal(24, 6 *
1359                            g:thefour)
1360      assert_equal(24, g:thefour
1361                            * 6)
1362      assert_equal(40, g:anint * g:thefour)
1363
1364      assert_equal(10, 60 / 6)
1365      assert_equal(6, 60 /
1366                            g:anint)
1367      assert_equal(1, g:anint / 6)
1368      assert_equal(2, g:anint
1369                            / g:thefour)
1370
1371      assert_equal(5, 11 % 6)
1372      assert_equal(4, g:anint % 6)
1373      assert_equal(3, 13 %
1374                            g:anint)
1375      assert_equal(2, g:anint
1376                            % g:thefour)
1377
1378      assert_equal(4, 6 * 4 / 6)
1379
1380      var x = [2]
1381      var y = [3]
1382      assert_equal(5, x[0] + y[0])
1383      assert_equal(6, x[0] * y[0])
1384      if has('float')
1385        var xf = [2.0]
1386        var yf = [3.0]
1387        assert_equal(5.0, xf[0]
1388                            + yf[0])
1389        assert_equal(6.0, xf[0]
1390                            * yf[0])
1391      endif
1392  END
1393  CheckDefAndScriptSuccess(lines)
1394
1395  CheckDefAndScriptFailure2(["var x = 6 * xxx"], 'E1001:', 'E121:', 1)
1396  CheckDefFailure(["var d = 6 * "], 'E1097:', 3)
1397  CheckScriptFailure(['vim9script', "var d = 6 * "], 'E15:', 2)
1398
1399  CheckDefExecAndScriptFailure(['echo 1 / 0'], 'E1154', 1)
1400  CheckDefExecAndScriptFailure(['echo 1 % 0'], 'E1154', 1)
1401enddef
1402
1403def Test_expr6_vim9script()
1404  # check line continuation
1405  var lines =<< trim END
1406      var name = 11
1407      		* 22
1408		/ 3
1409      assert_equal(80, name)
1410  END
1411  CheckDefAndScriptSuccess(lines)
1412
1413  lines =<< trim END
1414      var name = 25
1415      		% 10
1416      assert_equal(5, name)
1417  END
1418  CheckDefAndScriptSuccess(lines)
1419
1420  lines =<< trim END
1421      var name = 25
1422                # comment
1423
1424                # comment
1425      		% 10
1426      assert_equal(5, name)
1427  END
1428  CheckDefAndScriptSuccess(lines)
1429
1430  lines =<< trim END
1431      var name = 11 *
1432      		22 /
1433		3
1434      assert_equal(80, name)
1435  END
1436  CheckDefAndScriptSuccess(lines)
1437
1438  # check white space
1439  lines =<< trim END
1440      echo 5*6
1441  END
1442  CheckDefAndScriptFailure(lines, 'E1004:', 1)
1443
1444  lines =<< trim END
1445      echo 5 *6
1446  END
1447  CheckDefAndScriptFailure(lines, 'E1004:', 1)
1448
1449  lines =<< trim END
1450      echo 5* 6
1451  END
1452  CheckDefAndScriptFailure(lines, 'E1004:', 1)
1453enddef
1454
1455def Test_expr6_float()
1456  if !has('float')
1457    MissingFeature 'float'
1458  else
1459    var lines =<< trim END
1460        assert_equal(36.0, 6.0 * 6)
1461        assert_equal(36.0, 6 *
1462                               6.0)
1463        assert_equal(36.0, 6.0 * 6.0)
1464        assert_equal(1.0, g:afloat * g:anint)
1465
1466        assert_equal(10.0, 60 / 6.0)
1467        assert_equal(10.0, 60.0 /
1468                            6)
1469        assert_equal(10.0, 60.0 / 6.0)
1470        assert_equal(0.01, g:afloat / g:anint)
1471
1472        assert_equal(4.0, 6.0 * 4 / 6)
1473        assert_equal(4.0, 6 *
1474                            4.0 /
1475                            6)
1476        assert_equal(4.0, 6 * 4 / 6.0)
1477        assert_equal(4.0, 6.0 * 4.0 / 6)
1478        assert_equal(4.0, 6 * 4.0 / 6.0)
1479        assert_equal(4.0, 6.0 * 4 / 6.0)
1480        assert_equal(4.0, 6.0 * 4.0 / 6.0)
1481
1482        assert_equal(4.0, 6.0 * 4.0 / 6.0)
1483    END
1484    CheckDefAndScriptSuccess(lines)
1485  endif
1486enddef
1487
1488func Test_expr6_fails()
1489  let msg = "White space required before and after '*'"
1490  call CheckDefAndScriptFailure(["var x = 1*2"], msg, 1)
1491  call CheckDefAndScriptFailure(["var x = 1 *2"], msg, 1)
1492  call CheckDefAndScriptFailure(["var x = 1* 2"], msg, 1)
1493
1494  let msg = "White space required before and after '/'"
1495  call CheckDefAndScriptFailure(["var x = 1/2"], msg, 1)
1496  call CheckDefAndScriptFailure(["var x = 1 /2"], msg, 1)
1497  call CheckDefAndScriptFailure(["var x = 1/ 2"], msg, 1)
1498
1499  let msg = "White space required before and after '%'"
1500  call CheckDefAndScriptFailure(["var x = 1%2"], msg, 1)
1501  call CheckDefAndScriptFailure(["var x = 1 %2"], msg, 1)
1502  call CheckDefAndScriptFailure(["var x = 1% 2"], msg, 1)
1503
1504  call CheckDefAndScriptFailure2(["var x = '1' * '2'"], 'E1036:', 'E1030:', 1)
1505  call CheckDefAndScriptFailure2(["var x = '1' / '2'"], 'E1036:', 'E1030:', 1)
1506  call CheckDefAndScriptFailure2(["var x = '1' % '2'"], 'E1035:', 'E1030:', 1)
1507
1508  call CheckDefAndScriptFailure2(["var x = 0z01 * 0z12"], 'E1036:', 'E974:', 1)
1509  call CheckDefAndScriptFailure2(["var x = 0z01 / 0z12"], 'E1036:', 'E974:', 1)
1510  call CheckDefAndScriptFailure2(["var x = 0z01 % 0z12"], 'E1035:', 'E974:', 1)
1511
1512  call CheckDefAndScriptFailure2(["var x = [1] * [2]"], 'E1036:', 'E745:', 1)
1513  call CheckDefAndScriptFailure2(["var x = [1] / [2]"], 'E1036:', 'E745:', 1)
1514  call CheckDefAndScriptFailure2(["var x = [1] % [2]"], 'E1035:', 'E745:', 1)
1515
1516  call CheckDefAndScriptFailure2(["var x = {one: 1} * {two: 2}"], 'E1036:', 'E728:', 1)
1517  call CheckDefAndScriptFailure2(["var x = {one: 1} / {two: 2}"], 'E1036:', 'E728:', 1)
1518  call CheckDefAndScriptFailure2(["var x = {one: 1} % {two: 2}"], 'E1035:', 'E728:', 1)
1519
1520  call CheckDefAndScriptFailure2(["var x = 0xff[1]"], 'E1107:', 'E1062:', 1)
1521  if has('float')
1522    call CheckDefAndScriptFailure2(["var x = 0.7[1]"], 'E1107:', 'E806:', 1)
1523  endif
1524endfunc
1525
1526func Test_expr6_float_fails()
1527  CheckFeature float
1528  call CheckDefAndScriptFailure2(["var x = 1.0 % 2"], 'E1035:', 'E804:', 1)
1529endfunc
1530
1531" define here to use old style parsing
1532if has('float')
1533  let g:float_zero = 0.0
1534  let g:float_neg = -9.8
1535  let g:float_big = 9.9e99
1536endif
1537let g:blob_empty = 0z
1538let g:blob_one = 0z01
1539let g:blob_long = 0z0102.0304
1540
1541let g:string_empty = ''
1542let g:string_short = 'x'
1543let g:string_long = 'abcdefghijklm'
1544let g:string_special = "ab\ncd\ref\ekk"
1545
1546let g:special_true = v:true
1547let g:special_false = v:false
1548let g:special_null = v:null
1549let g:special_none = v:none
1550
1551let g:list_empty = []
1552let g:list_mixed = [1, 'b', v:false]
1553
1554let g:dict_empty = {}
1555let g:dict_one = #{one: 1}
1556
1557let $TESTVAR = 'testvar'
1558
1559" type casts
1560def Test_expr7t()
1561  var ls: list<string> = ['a', <string>g:string_empty]
1562  var ln: list<number> = [<number>g:anint, <number>g:thefour]
1563  var nr = <number>234
1564  assert_equal(234, nr)
1565
1566  CheckDefAndScriptFailure2(["var x = <nr>123"], 'E1010:', 'E15:', 1)
1567  CheckDefFailure(["var x = <number>"], 'E1097:', 3)
1568  CheckScriptFailure(['vim9script', "var x = <number>"], 'E15:', 2)
1569  CheckDefAndScriptFailure2(["var x = <number >123"], 'E1068:', 'E15:', 1)
1570  CheckDefAndScriptFailure2(["var x = <number 123"], 'E1104:', 'E15:', 1)
1571enddef
1572
1573" test low level expression
1574def Test_expr7_number()
1575  # number constant
1576  var lines =<< trim END
1577      assert_equal(0, 0)
1578      assert_equal(654, 0654)
1579
1580      assert_equal(6, 0x6)
1581      assert_equal(15, 0xf)
1582      assert_equal(255, 0xff)
1583  END
1584  CheckDefAndScriptSuccess(lines)
1585enddef
1586
1587def Test_expr7_float()
1588  # float constant
1589  if !has('float')
1590    MissingFeature 'float'
1591  else
1592    var lines =<< trim END
1593        assert_equal(g:float_zero, .0)
1594        assert_equal(g:float_zero, 0.0)
1595        assert_equal(g:float_neg, -9.8)
1596        assert_equal(g:float_big, 9.9e99)
1597    END
1598    CheckDefAndScriptSuccess(lines)
1599  endif
1600enddef
1601
1602def Test_expr7_blob()
1603  # blob constant
1604  var lines =<< trim END
1605      assert_equal(g:blob_empty, 0z)
1606      assert_equal(g:blob_one, 0z01)
1607      assert_equal(g:blob_long, 0z0102.0304)
1608  END
1609  CheckDefAndScriptSuccess(lines)
1610
1611  CheckDefAndScriptFailure(["var x = 0z123"], 'E973:', 1)
1612enddef
1613
1614def Test_expr7_string()
1615  # string constant
1616  var lines =<< trim END
1617      assert_equal(g:string_empty, '')
1618      assert_equal(g:string_empty, "")
1619      assert_equal(g:string_short, 'x')
1620      assert_equal(g:string_short, "x")
1621      assert_equal(g:string_long, 'abcdefghijklm')
1622      assert_equal(g:string_long, "abcdefghijklm")
1623      assert_equal(g:string_special, "ab\ncd\ref\ekk")
1624  END
1625  CheckDefAndScriptSuccess(lines)
1626
1627  CheckDefAndScriptFailure(['var x = "abc'], 'E114:', 1)
1628  CheckDefAndScriptFailure(["var x = 'abc"], 'E115:', 1)
1629enddef
1630
1631def Test_expr7_vimvar()
1632  var old: list<string> = v:oldfiles
1633  var compl: dict<any> = v:completed_item
1634
1635  CheckDefFailure(["var old: list<number> = v:oldfiles"], 'E1012: Type mismatch; expected list<number> but got list<string>', 1)
1636  CheckScriptFailure(['vim9script', 'v:oldfiles = ["foo"]', "var old: list<number> = v:oldfiles"], 'E1012: Type mismatch; expected list<number> but got list<string>', 3)
1637  new
1638  exec "normal! afoo fo\<C-N>\<Esc>"
1639  CheckDefExecAndScriptFailure(["var old: dict<number> = v:completed_item"], 'E1012: Type mismatch; expected dict<number> but got dict<string>', 1)
1640  bwipe!
1641enddef
1642
1643def Test_expr7_special()
1644  # special constant
1645  var lines =<< trim END
1646      assert_equal(g:special_true, true)
1647      assert_equal(g:special_false, false)
1648      assert_equal(g:special_true, v:true)
1649      assert_equal(g:special_false, v:false)
1650      assert_equal(v:true, true)
1651      assert_equal(v:false, false)
1652
1653      assert_equal(true, !false)
1654      assert_equal(false, !true)
1655      assert_equal(true, !0)
1656      assert_equal(false, !1)
1657      assert_equal(false, !!false)
1658      assert_equal(true, !!true)
1659      assert_equal(false, !!0)
1660      assert_equal(true, !!1)
1661
1662      var t = true
1663      var f = false
1664      assert_equal(true, t)
1665      assert_equal(false, f)
1666
1667      assert_equal(g:special_null, v:null)
1668      assert_equal(g:special_null, null)
1669      assert_equal(g:special_none, v:none)
1670  END
1671  CheckDefAndScriptSuccess(lines)
1672
1673  CheckDefAndScriptFailure(['v:true = true'], 'E46:', 1)
1674  CheckDefAndScriptFailure(['v:true = false'], 'E46:', 1)
1675  CheckDefAndScriptFailure(['v:false = true'], 'E46:', 1)
1676  CheckDefAndScriptFailure(['v:null = 11'], 'E46:', 1)
1677  CheckDefAndScriptFailure(['v:none = 22'], 'E46:', 1)
1678enddef
1679
1680def Test_expr7_list()
1681  # list
1682  var lines =<< trim END
1683      assert_equal(g:list_empty, [])
1684      assert_equal(g:list_empty, [  ])
1685
1686      var numbers: list<number> = [1, 2, 3]
1687      numbers = [1]
1688      numbers = []
1689
1690      var strings: list<string> = ['a', 'b', 'c']
1691      strings = ['x']
1692      strings = []
1693
1694      var mixed: list<any> = [1, 'b', false,]
1695      assert_equal(g:list_mixed, mixed)
1696      assert_equal('b', mixed[1])
1697
1698      echo [1,
1699            2] [3,
1700                    4]
1701
1702      var llstring: list<list<string>> = [['text'], []]
1703      llstring = [[], ['text']]
1704      llstring = [[], []]
1705  END
1706  CheckDefAndScriptSuccess(lines)
1707
1708  var rangelist: list<number> = range(3)
1709  g:rangelist = range(3)
1710  CheckDefExecAndScriptFailure(["var x: list<string> = g:rangelist"], 'E1012: Type mismatch; expected list<string> but got list<number>', 1)
1711
1712  CheckDefAndScriptFailure2(["var x = 1234[3]"], 'E1107:', 'E1062:', 1)
1713  CheckDefExecAndScriptFailure(["var x = g:anint[3]"], 'E1062:', 1)
1714
1715  CheckDefAndScriptFailure2(["var x = g:list_mixed[xxx]"], 'E1001:', 'E121:', 1)
1716
1717  CheckDefAndScriptFailure(["var x = [1,2,3]"], 'E1069:', 1)
1718  CheckDefAndScriptFailure(["var x = [1 ,2, 3]"], 'E1068:', 1)
1719
1720  CheckDefExecAndScriptFailure(["echo 1", "var x = [][0]", "echo 3"], 'E684:', 2)
1721
1722  CheckDefExecAndScriptFailure2(["var x = g:list_mixed['xx']"], 'E1012:', 'E1030:', 1)
1723  CheckDefFailure(["var x = g:list_mixed["], 'E1097:', 3)
1724  CheckScriptFailure(['vim9script', "var x = g:list_mixed["], 'E15:', 2)
1725  CheckDefFailure(["var x = g:list_mixed[0"], 'E1097:', 3)
1726  CheckScriptFailure(['vim9script', "var x = g:list_mixed[0"], 'E111:', 2)
1727  CheckDefExecAndScriptFailure(["var x = g:list_empty[3]"], 'E684:', 1)
1728  CheckDefExecAndScriptFailure(["var l: list<number> = [234, 'x']"], 'E1012:', 1)
1729  CheckDefExecAndScriptFailure(["var l: list<number> = ['x', 234]"], 'E1012:', 1)
1730  CheckDefExecAndScriptFailure(["var l: list<string> = [234, 'x']"], 'E1012:', 1)
1731  CheckDefExecAndScriptFailure(["var l: list<string> = ['x', 123]"], 'E1012:', 1)
1732
1733  lines =<< trim END
1734      var datalist: list<string>
1735      def Main()
1736        datalist += ['x'.
1737      enddef
1738      Main()
1739  END
1740  CheckDefAndScriptFailure(lines, 'E1127:')
1741
1742  lines =<< trim END
1743      var numbers = [1, 2, 3, 4]
1744      var a = 1
1745      var b = 2
1746  END
1747  CheckDefAndScriptFailure(lines + ['echo numbers[1:b]'],
1748      'E1004: White space required before and after '':'' at ":b]"', 4)
1749  CheckDefAndScriptFailure(lines + ['echo numbers[1: b]'], 'E1004:', 4)
1750  CheckDefAndScriptFailure(lines + ['echo numbers[a :b]'], 'E1004:', 4)
1751enddef
1752
1753def Test_expr7_list_vim9script()
1754  var lines =<< trim END
1755      var l = [
1756		11,
1757		22,
1758		]
1759      assert_equal([11, 22], l)
1760
1761      echo [1,
1762	    2] [3,
1763		    4]
1764
1765      echo [1, # comment
1766            # comment
1767	    2] [3,
1768            # comment
1769		    4]
1770  END
1771  CheckDefAndScriptSuccess(lines)
1772
1773  lines =<< trim END
1774      var l = [11,
1775		22]
1776      assert_equal([11, 22], l)
1777  END
1778  CheckDefAndScriptSuccess(lines)
1779
1780  lines =<< trim END
1781      var l = [11,22]
1782  END
1783  CheckDefAndScriptFailure(lines, 'E1069:', 1)
1784
1785  lines =<< trim END
1786      var l = [11 , 22]
1787  END
1788  CheckDefAndScriptFailure(lines, 'E1068:', 1)
1789
1790  lines =<< trim END
1791    var l: list<number> = [234, 'x']
1792  END
1793  CheckDefAndScriptFailure(lines, 'E1012:', 1)
1794
1795  lines =<< trim END
1796    var l: list<number> = ['x', 234]
1797  END
1798  CheckDefAndScriptFailure(lines, 'E1012:', 1)
1799
1800  lines =<< trim END
1801    var l: list<string> = ['x', 234]
1802  END
1803  CheckDefAndScriptFailure(lines, 'E1012:', 1)
1804
1805  lines =<< trim END
1806    var l: list<string> = [234, 'x']
1807  END
1808  CheckDefAndScriptFailure(lines, 'E1012:', 1)
1809
1810  lines =<< trim END
1811      def Failing()
1812        job_stop()
1813      enddef
1814      var list = [Failing]
1815  END
1816  if has('channel')
1817    CheckDefAndScriptFailure(lines, 'E119:', 0)
1818  else
1819    CheckDefAndScriptFailure(lines, 'E117:', 0)
1820  endif
1821enddef
1822
1823def LambdaWithComments(): func
1824  return (x) =>
1825            # some comment
1826            x == 1
1827            # some comment
1828            ||
1829            x == 2
1830enddef
1831
1832def LambdaUsingArg(x: number): func
1833  return () =>
1834            # some comment
1835            x == 1
1836            # some comment
1837            ||
1838            x == 2
1839enddef
1840
1841def Test_expr7_lambda()
1842  var lines =<< trim END
1843      var La = () => 'result'
1844      assert_equal('result', La())
1845      assert_equal([1, 3, 5], [1, 2, 3]->map((key, val) => key + val))
1846
1847      # line continuation inside lambda with "cond ? expr : expr" works
1848      var ll = range(3)
1849      var dll = mapnew(ll, (k, v) => v % 2 ? {
1850                ['111']: 111 } : {}
1851            )
1852      assert_equal([{}, {111: 111}, {}], dll)
1853
1854      ll = range(3)
1855      map(ll, (k, v) => v == 8 || v
1856                    == 9
1857                    || v % 2 ? 111 : 222
1858            )
1859      assert_equal([222, 111, 222], ll)
1860
1861      ll = range(3)
1862      map(ll, (k, v) => v != 8 && v
1863                    != 9
1864                    && v % 2 == 0 ? 111 : 222
1865            )
1866      assert_equal([111, 222, 111], ll)
1867
1868      var dl = [{key: 0}, {key: 22}]->filter(( _, v) => v['key'] )
1869      assert_equal([{key: 22}], dl)
1870
1871      dl = [{key: 12}, {['foo']: 34}]
1872      assert_equal([{key: 12}], filter(dl,
1873            (_, v) => has_key(v, 'key') ? v['key'] == 12 : 0))
1874
1875      assert_equal(false, LambdaWithComments()(0))
1876      assert_equal(true, LambdaWithComments()(1))
1877      assert_equal(true, LambdaWithComments()(2))
1878      assert_equal(false, LambdaWithComments()(3))
1879
1880      assert_equal(false, LambdaUsingArg(0)())
1881      assert_equal(true, LambdaUsingArg(1)())
1882
1883      var res = map([1, 2, 3], (i: number, v: number) => i + v)
1884      assert_equal([1, 3, 5], res)
1885  END
1886  CheckDefAndScriptSuccess(lines)
1887
1888  CheckDefAndScriptFailure(["var Ref = (a)=>a + 1"], 'E1004:')
1889  CheckDefAndScriptFailure(["var Ref = (a)=> a + 1"], 'E1004: White space required before and after ''=>'' at "=> a + 1"')
1890  CheckDefAndScriptFailure(["var Ref = (a) =>a + 1"], 'E1004:')
1891
1892  CheckDefAndScriptFailure(["filter([1, 2], (k,v) => 1)"], 'E1069:', 1)
1893  # error is in first line of the lambda
1894  CheckDefAndScriptFailure(["var L = (a) => a + b"], 'E1001:', 0)
1895
1896  assert_equal('xxxyyy', 'xxx'->((a, b) => a .. b)('yyy'))
1897
1898  CheckDefExecFailure(["var s = 'asdf'->((a) => a)('x')"], 'E118:')
1899  CheckDefExecFailure(["var s = 'asdf'->((a) => a)('x', 'y')"], 'E118:')
1900  CheckDefAndScriptFailure2(["echo 'asdf'->((a) => a)(x)"], 'E1001:', 'E121:', 1)
1901
1902  CheckDefAndScriptSuccess(['var Fx = (a) => ({k1: 0,', ' k2: 1})'])
1903  CheckDefAndScriptFailure(['var Fx = (a) => ({k1: 0', ' k2: 1})'], 'E722:', 2)
1904  CheckDefAndScriptFailure(['var Fx = (a) => ({k1: 0,', ' k2 1})'], 'E720:', 2)
1905
1906  CheckDefAndScriptSuccess(['var Fx = (a) => [0,', ' 1]'])
1907  CheckDefAndScriptFailure(['var Fx = (a) => [0', ' 1]'], 'E696:', 2)
1908
1909  # no error for existing script variable when checking for lambda
1910  lines =<< trim END
1911    var name = 0
1912    eval (name + 2) / 3
1913  END
1914  CheckDefAndScriptSuccess(lines)
1915enddef
1916
1917def Test_expr7_lambda_block()
1918  var lines =<< trim END
1919      var Func = (s: string): string => {
1920                      return 'hello ' .. s
1921                    }
1922      assert_equal('hello there', Func('there'))
1923
1924      var ll = range(3)
1925      var dll = mapnew(ll, (k, v): string => {
1926          if v % 2
1927            return 'yes'
1928          endif
1929          return 'no'
1930        })
1931      assert_equal(['no', 'yes', 'no'], dll)
1932
1933      sandbox var Safe = (nr: number): number => {
1934          return nr + 7
1935        }
1936      assert_equal(10, Safe(3))
1937  END
1938  CheckDefAndScriptSuccess(lines)
1939
1940  lines =<< trim END
1941      map([1, 2], (k, v) => { redrawt })
1942  END
1943  CheckDefAndScriptFailure(lines, 'E488')
1944
1945  lines =<< trim END
1946      var Func = (nr: int) => {
1947              echo nr
1948            }
1949  END
1950  CheckDefAndScriptFailure(lines, 'E1010', 1)
1951
1952  lines =<< trim END
1953      var Func = (nr: number): int => {
1954              return nr
1955            }
1956  END
1957  CheckDefAndScriptFailure(lines, 'E1010', 1)
1958
1959  lines =<< trim END
1960      var Func = (nr: number): int => {
1961              return nr
1962  END
1963  CheckDefAndScriptFailure(lines, 'E1171', 1)  # line nr is function start
1964
1965  lines =<< trim END
1966      var Func = (nr: number): int => {
1967          var ll =<< ENDIT
1968             nothing
1969  END
1970  CheckDefFailure(lines, 'E1145: Missing heredoc end marker: ENDIT', 0)
1971  CheckScriptFailure(['vim9script'] + lines, 'E1145: Missing heredoc end marker: ENDIT', 2)
1972enddef
1973
1974def NewLambdaWithComments(): func
1975  return (x) =>
1976            # some comment
1977            x == 1
1978            # some comment
1979            ||
1980            x == 2
1981enddef
1982
1983def NewLambdaUsingArg(x: number): func
1984  return () =>
1985            # some comment
1986            x == 1
1987            # some comment
1988            ||
1989            x == 2
1990enddef
1991
1992def Test_expr7_new_lambda()
1993  var lines =<< trim END
1994      var La = () => 'result'
1995      assert_equal('result', La())
1996      assert_equal([1, 3, 5], [1, 2, 3]->map((key, val) => key + val))
1997
1998      # line continuation inside lambda with "cond ? expr : expr" works
1999      var ll = range(3)
2000      var dll = mapnew(ll, (k, v) => v % 2 ? {
2001                ['111']: 111 } : {}
2002            )
2003      assert_equal([{}, {111: 111}, {}], dll)
2004
2005      ll = range(3)
2006      map(ll, (k, v) => v == 8 || v
2007                    == 9
2008                    || v % 2 ? 111 : 222
2009            )
2010      assert_equal([222, 111, 222], ll)
2011
2012      ll = range(3)
2013      map(ll, (k, v) => v != 8 && v
2014                    != 9
2015                    && v % 2 == 0 ? 111 : 222
2016            )
2017      assert_equal([111, 222, 111], ll)
2018
2019      var dl = [{key: 0}, {key: 22}]->filter(( _, v) => v['key'] )
2020      assert_equal([{key: 22}], dl)
2021
2022      dl = [{key: 12}, {['foo']: 34}]
2023      assert_equal([{key: 12}], filter(dl,
2024            (_, v) => has_key(v, 'key') ? v['key'] == 12 : 0))
2025
2026      assert_equal(false, NewLambdaWithComments()(0))
2027      assert_equal(true, NewLambdaWithComments()(1))
2028      assert_equal(true, NewLambdaWithComments()(2))
2029      assert_equal(false, NewLambdaWithComments()(3))
2030
2031      assert_equal(false, NewLambdaUsingArg(0)())
2032      assert_equal(true, NewLambdaUsingArg(1)())
2033
2034      var res = map([1, 2, 3], (i: number, v: number) => i + v)
2035      assert_equal([1, 3, 5], res)
2036
2037      # Lambda returning a dict
2038      var Lmb = () => ({key: 42})
2039      assert_equal({key: 42}, Lmb())
2040
2041      var RefOne: func(number): string = (a: number): string => 'x'
2042      var RefTwo: func(number): any = (a: number): any => 'x'
2043
2044      var Fx = (a) => ({k1: 0,
2045                         k2: 1})
2046      var Fy = (a) => [0,
2047                       1]
2048  END
2049  CheckDefAndScriptSuccess(lines)
2050
2051  CheckDefAndScriptFailure(["var Ref = (a)=>a + 1"], 'E1004:')
2052  CheckDefAndScriptFailure(["var Ref = (a)=> a + 1"], 'E1004:')
2053  CheckDefAndScriptFailure(["var Ref = (a) =>a + 1"],
2054      'E1004: White space required before and after ''=>'' at " =>a + 1"')
2055
2056  CheckDefAndScriptFailure(["var Ref: func(number): number = (a: number): string => 'x'"], 'E1012:')
2057  CheckDefAndScriptFailure(["var Ref: func(number): string = (a: number): string => 99"], 'E1012:')
2058
2059  CheckDefAndScriptFailure(["filter([1, 2], (k,v) => 1)"], 'E1069:', 1)
2060  # error is in first line of the lambda
2061  CheckDefAndScriptFailure2(["var L = (a) -> a + b"], 'E1001:', 'E121:', 1)
2062
2063  assert_equal('xxxyyy', 'xxx'->((a, b) => a .. b)('yyy'))
2064
2065  CheckDefExecFailure(["var s = 'asdf'->((a) => a)('x')"],
2066        'E118: Too many arguments for function:')
2067  CheckDefExecFailure(["var s = 'asdf'->((a) => a)('x', 'y')"],
2068        'E118: Too many arguments for function:')
2069  CheckDefFailure(["echo 'asdf'->((a) => a)(x)"], 'E1001:', 1)
2070
2071  CheckDefAndScriptFailure(['var Fx = (a) => ({k1: 0', ' k2: 1})'], 'E722:', 2)
2072  CheckDefAndScriptFailure(['var Fx = (a) => ({k1: 0,', ' k2 1})'], 'E720:', 2)
2073
2074  CheckDefAndScriptFailure(['var Fx = (a) => [0', ' 1]'], 'E696:', 2)
2075enddef
2076
2077def Test_expr7_lambda_vim9script()
2078  var lines =<< trim END
2079      var v = 10->((a) =>
2080	    a
2081	      + 2
2082            )()
2083      assert_equal(12, v)
2084  END
2085  CheckDefAndScriptSuccess(lines)
2086
2087  # nested lambda with line breaks
2088  lines =<< trim END
2089      search('"', 'cW', 0, 0, () =>
2090	synstack('.', col('.'))
2091          ->map((_, v) => synIDattr(v, 'name'))->len())
2092  END
2093  CheckDefAndScriptSuccess(lines)
2094enddef
2095
2096def Test_expr7_funcref()
2097  var lines =<< trim END
2098      def RetNumber(): number
2099        return 123
2100      enddef
2101      var FuncRef = RetNumber
2102      assert_equal(123, FuncRef())
2103  END
2104  CheckDefAndScriptSuccess(lines)
2105enddef
2106
2107let g:test_space_dict = {'': 'empty', ' ': 'space'}
2108let g:test_hash_dict = #{one: 1, two: 2}
2109
2110def Test_expr7_dict()
2111  # dictionary
2112  var lines =<< trim END
2113      assert_equal(g:dict_empty, {})
2114      assert_equal(g:dict_empty, {  })
2115      assert_equal(g:dict_one, {['one']: 1})
2116      var key = 'one'
2117      var val = 1
2118      assert_equal(g:dict_one, {[key]: val})
2119
2120      var numbers: dict<number> = {a: 1, b: 2, c: 3}
2121      numbers = {a: 1}
2122      numbers = {}
2123
2124      var strings: dict<string> = {a: 'a', b: 'b', c: 'c'}
2125      strings = {a: 'x'}
2126      strings = {}
2127
2128      var dash = {xx-x: 8}
2129      assert_equal({['xx-x']: 8}, dash)
2130
2131      var dnr = {8: 8}
2132      assert_equal({['8']: 8}, dnr)
2133
2134      var mixed: dict<any> = {a: 'a', b: 42}
2135      mixed = {a: 'x'}
2136      mixed = {a: 234}
2137      mixed = {}
2138
2139      var dictlist: dict<list<string>> = {absent: [], present: ['hi']}
2140      dictlist = {absent: ['hi'], present: []}
2141      dictlist = {absent: [], present: []}
2142
2143      var dictdict: dict<dict<string>> = {one: {a: 'text'}, two: {}}
2144      dictdict = {one: {}, two: {a: 'text'}}
2145      dictdict = {one: {}, two: {}}
2146
2147      assert_equal({['']: 0}, {[matchstr('string', 'wont match')]: 0})
2148
2149      assert_equal(g:test_space_dict, {['']: 'empty', [' ']: 'space'})
2150      assert_equal(g:test_hash_dict, {one: 1, two: 2})
2151
2152      assert_equal({['a a']: 1, ['b/c']: 2}, {'a a': 1, "b/c": 2})
2153
2154      var d = {a: () => 3, b: () => 7}
2155      assert_equal(3, d.a())
2156      assert_equal(7, d.b())
2157
2158      var cd = { # comment
2159                key: 'val' # comment
2160               }
2161
2162      # different types used for the key
2163      var dkeys = {['key']: 'string',
2164                   [12]: 'numberexpr',
2165                   34: 'number',
2166                   [true]: 'bool'}
2167      assert_equal('string', dkeys['key'])
2168      assert_equal('numberexpr', dkeys[12])
2169      assert_equal('number', dkeys[34])
2170      assert_equal('bool', dkeys[true])
2171      if has('float')
2172        dkeys = {[1.2]: 'floatexpr', [3.4]: 'float'}
2173        assert_equal('floatexpr', dkeys[1.2])
2174        assert_equal('float', dkeys[3.4])
2175      endif
2176
2177      # automatic conversion from number to string
2178      var n = 123
2179      var dictnr = {[n]: 1}
2180
2181      # comment to start fold is OK
2182      var x1: number #{{ fold
2183      var x2 = 9 #{{ fold
2184  END
2185  CheckDefAndScriptSuccess(lines)
2186
2187  # legacy syntax doesn't work
2188  CheckDefAndScriptFailure(["var x = #{key: 8}"], 'E1170:', 1)
2189  CheckDefAndScriptFailure(["var x = 'a' #{a: 1}"], 'E1170:', 1)
2190  CheckDefAndScriptFailure(["var x = 'a' .. #{a: 1}"], 'E1170:', 1)
2191  CheckDefAndScriptFailure(["var x = true ? #{a: 1}"], 'E1170:', 1)
2192
2193  CheckDefAndScriptFailure(["var x = {a:8}"], 'E1069:', 1)
2194  CheckDefAndScriptFailure(["var x = {a : 8}"], 'E1068:', 1)
2195  CheckDefAndScriptFailure(["var x = {a :8}"], 'E1068:', 1)
2196  CheckDefAndScriptFailure(["var x = {a: 8 , b: 9}"], 'E1068:', 1)
2197  CheckDefAndScriptFailure(["var x = {a: 1,b: 2}"], 'E1069:', 1)
2198
2199  CheckDefAndScriptFailure(["var x = {xxx}"], 'E720:', 1)
2200  CheckDefAndScriptFailure(["var x = {xxx: 1", "var y = 2"], 'E722:', 2)
2201  CheckDefFailure(["var x = {xxx: 1,"], 'E723:', 2)
2202  CheckScriptFailure(['vim9script', "var x = {xxx: 1,"], 'E723:', 2)
2203  CheckDefAndScriptFailure2(["var x = {['a']: xxx}"], 'E1001:', 'E121:', 1)
2204  CheckDefAndScriptFailure(["var x = {a: 1, a: 2}"], 'E721:', 1)
2205  CheckDefExecAndScriptFailure2(["var x = g:anint.member"], 'E715:', 'E15:', 1)
2206  CheckDefExecAndScriptFailure(["var x = g:dict_empty.member"], 'E716:', 1)
2207
2208  CheckDefExecAndScriptFailure(['var x: dict<number> = {a: 234, b: "1"}'], 'E1012:', 1)
2209  CheckDefExecAndScriptFailure(['var x: dict<number> = {a: "x", b: 134}'], 'E1012:', 1)
2210  CheckDefExecAndScriptFailure(['var x: dict<string> = {a: 234, b: "1"}'], 'E1012:', 1)
2211  CheckDefExecAndScriptFailure(['var x: dict<string> = {a: "x", b: 134}'], 'E1012:', 1)
2212
2213  # invalid types for the key
2214  CheckDefAndScriptFailure2(["var x = {[[1, 2]]: 0}"], 'E1105:', 'E730:', 1)
2215
2216  CheckDefFailure(['var x = ({'], 'E723:', 2)
2217  CheckScriptFailure(['vim9script', 'var x = ({'], 'E723:', 2)
2218  CheckDefExecAndScriptFailure(['{}[getftype("file")]'], 'E716: Key not present in Dictionary: ""', 1)
2219enddef
2220
2221def Test_expr7_dict_vim9script()
2222  var lines =<< trim END
2223      var d = {
2224		['one']:
2225		   1,
2226		['two']: 2,
2227		   }
2228      assert_equal({one: 1, two: 2}, d)
2229
2230      d = {  # comment
2231		['one']:
2232                # comment
2233
2234		   1,
2235                # comment
2236                # comment
2237		['two']: 2,
2238		   }
2239      assert_equal({one: 1, two: 2}, d)
2240
2241      var dd = {k: 123->len()}
2242      assert_equal(3, dd.k)
2243  END
2244  CheckDefAndScriptSuccess(lines)
2245
2246  lines =<< trim END
2247      var d = { ["one"]: "one", ["two"]: "two", }
2248      assert_equal({one: 'one', two: 'two'}, d)
2249  END
2250  CheckDefAndScriptSuccess(lines)
2251
2252  lines =<< trim END
2253      var d = {one: 1,
2254		two: 2,
2255	       }
2256      assert_equal({one: 1, two: 2}, d)
2257  END
2258  CheckDefAndScriptSuccess(lines)
2259
2260  lines =<< trim END
2261      var d = {one:1, two: 2}
2262  END
2263  CheckDefAndScriptFailure(lines, 'E1069:', 1)
2264
2265  lines =<< trim END
2266      var d = {one: 1,two: 2}
2267  END
2268  CheckDefAndScriptFailure(lines, 'E1069:', 1)
2269
2270  lines =<< trim END
2271      var d = {one : 1}
2272  END
2273  CheckDefAndScriptFailure(lines, 'E1068:', 1)
2274
2275  lines =<< trim END
2276      var d = {one:1}
2277  END
2278  CheckDefAndScriptFailure(lines, 'E1069:', 1)
2279
2280  lines =<< trim END
2281      var d = {one: 1 , two: 2}
2282  END
2283  CheckDefAndScriptFailure(lines, 'E1068:', 1)
2284
2285  lines =<< trim END
2286    var l: dict<number> = {a: 234, b: 'x'}
2287  END
2288  CheckDefAndScriptFailure(lines, 'E1012:', 1)
2289
2290  lines =<< trim END
2291    var l: dict<number> = {a: 'x', b: 234}
2292  END
2293  CheckDefAndScriptFailure(lines, 'E1012:', 1)
2294
2295  lines =<< trim END
2296    var l: dict<string> = {a: 'x', b: 234}
2297  END
2298  CheckDefAndScriptFailure(lines, 'E1012:', 1)
2299
2300  lines =<< trim END
2301    var l: dict<string> = {a: 234, b: 'x'}
2302  END
2303  CheckDefAndScriptFailure(lines, 'E1012:', 1)
2304
2305  lines =<< trim END
2306    var d = {['a']: 234, ['b': 'x'}
2307  END
2308  CheckDefAndScriptFailure(lines, 'E1139:', 1)
2309
2310  lines =<< trim END
2311    def Func()
2312      var d = {['a']: 234, ['b': 'x'}
2313    enddef
2314    defcompile
2315  END
2316  CheckDefAndScriptFailure(lines, 'E1139:', 0)
2317
2318  lines =<< trim END
2319    var d = {'a':
2320  END
2321  CheckDefFailure(lines, 'E723:', 2)
2322  CheckScriptFailure(['vim9script'] + lines, 'E15:', 2)
2323
2324  lines =<< trim END
2325    def Func()
2326      var d = {'a':
2327    enddef
2328    defcompile
2329  END
2330  CheckDefAndScriptFailure(lines, 'E723:', 0)
2331
2332  lines =<< trim END
2333      def Failing()
2334        job_stop()
2335      enddef
2336      var dict = {name: Failing}
2337  END
2338  if has('channel')
2339    CheckDefAndScriptFailure(lines, 'E119:', 0)
2340  else
2341    CheckDefAndScriptFailure(lines, 'E117:', 0)
2342  endif
2343enddef
2344
2345let g:oneString = 'one'
2346
2347def Test_expr_member()
2348  var lines =<< trim END
2349      assert_equal(1, g:dict_one.one)
2350      var d: dict<number> = g:dict_one
2351      assert_equal(1, d['one'])
2352      assert_equal(1, d[
2353                      'one'
2354                      ])
2355      assert_equal(1, d
2356            .one)
2357      d = {1: 1, _: 2}
2358      assert_equal(1, d
2359            .1)
2360      assert_equal(2, d
2361            ._)
2362
2363      # getting the one member should clear the dict after getting the item
2364      assert_equal('one', {one: 'one'}.one)
2365      assert_equal('one', {one: 'one'}[g:oneString])
2366  END
2367  CheckDefAndScriptSuccess(lines)
2368
2369  CheckDefAndScriptFailure2(["var x = g:dict_one.#$!"], 'E1002:', 'E15:', 1)
2370  CheckDefExecAndScriptFailure(["var d: dict<any>", "echo d['a']"], 'E716:', 2)
2371  CheckDefExecAndScriptFailure(["var d: dict<number>", "d = g:list_empty"], 'E1012: Type mismatch; expected dict<number> but got list<unknown>', 2)
2372enddef
2373
2374def Test_expr7_any_index_slice()
2375  var lines =<< trim END
2376    # getting the one member should clear the list only after getting the item
2377    assert_equal('bbb', ['aaa', 'bbb', 'ccc'][1])
2378
2379    # string is permissive, index out of range accepted
2380    g:teststring = 'abcdef'
2381    assert_equal('b', g:teststring[1])
2382    assert_equal('f', g:teststring[-1])
2383    assert_equal('', g:teststring[99])
2384
2385    assert_equal('b', g:teststring[1 : 1])
2386    assert_equal('bcdef', g:teststring[1 :])
2387    assert_equal('abcd', g:teststring[: 3])
2388    assert_equal('cdef', g:teststring[-4 :])
2389    assert_equal('abcdef', g:teststring[-9 :])
2390    assert_equal('abcd', g:teststring[: -3])
2391    assert_equal('', g:teststring[: -9])
2392
2393    # composing characters are included
2394    g:teststring = 'àéû'
2395    assert_equal('à', g:teststring[0])
2396    assert_equal('é', g:teststring[1])
2397    assert_equal('û', g:teststring[2])
2398    assert_equal('', g:teststring[3])
2399    assert_equal('', g:teststring[4])
2400
2401    assert_equal('û', g:teststring[-1])
2402    assert_equal('é', g:teststring[-2])
2403    assert_equal('à', g:teststring[-3])
2404    assert_equal('', g:teststring[-4])
2405    assert_equal('', g:teststring[-5])
2406
2407    assert_equal('à', g:teststring[0 : 0])
2408    assert_equal('é', g:teststring[1 : 1])
2409    assert_equal('àé', g:teststring[0 : 1])
2410    assert_equal('àéû', g:teststring[0 : -1])
2411    assert_equal('àé', g:teststring[0 : -2])
2412    assert_equal('à', g:teststring[0 : -3])
2413    assert_equal('', g:teststring[0 : -4])
2414    assert_equal('', g:teststring[0 : -5])
2415    assert_equal('àéû', g:teststring[ : ])
2416    assert_equal('àéû', g:teststring[0 : ])
2417    assert_equal('éû', g:teststring[1 : ])
2418    assert_equal('û', g:teststring[2 : ])
2419    assert_equal('', g:teststring[3 : ])
2420    assert_equal('', g:teststring[4 : ])
2421
2422    # blob index cannot be out of range
2423    g:testblob = 0z01ab
2424    assert_equal(0x01, g:testblob[0])
2425    assert_equal(0xab, g:testblob[1])
2426    assert_equal(0xab, g:testblob[-1])
2427    assert_equal(0x01, g:testblob[-2])
2428
2429    # blob slice accepts out of range
2430    assert_equal(0z01ab, g:testblob[0 : 1])
2431    assert_equal(0z01, g:testblob[0 : 0])
2432    assert_equal(0z01, g:testblob[-2 : -2])
2433    assert_equal(0zab, g:testblob[1 : 1])
2434    assert_equal(0zab, g:testblob[-1 : -1])
2435    assert_equal(0z, g:testblob[2 : 2])
2436    assert_equal(0z, g:testblob[0 : -3])
2437
2438    # list index cannot be out of range
2439    g:testlist = [0, 1, 2, 3]
2440    assert_equal(0, g:testlist[0])
2441    assert_equal(1, g:testlist[1])
2442    assert_equal(3, g:testlist[3])
2443    assert_equal(3, g:testlist[-1])
2444    assert_equal(0, g:testlist[-4])
2445    assert_equal(1, g:testlist[g:theone])
2446
2447    # list slice accepts out of range
2448    assert_equal([0], g:testlist[0 : 0])
2449    assert_equal([3], g:testlist[3 : 3])
2450    assert_equal([0, 1], g:testlist[0 : 1])
2451    assert_equal([0, 1, 2, 3], g:testlist[0 : 3])
2452    assert_equal([0, 1, 2, 3], g:testlist[0 : 9])
2453    assert_equal([], g:testlist[-1 : 1])
2454    assert_equal([1], g:testlist[-3 : 1])
2455    assert_equal([0, 1], g:testlist[-4 : 1])
2456    assert_equal([0, 1], g:testlist[-9 : 1])
2457    assert_equal([1, 2, 3], g:testlist[1 : -1])
2458    assert_equal([1], g:testlist[1 : -3])
2459    assert_equal([], g:testlist[1 : -4])
2460    assert_equal([], g:testlist[1 : -9])
2461
2462    g:testdict = {a: 1, b: 2}
2463    assert_equal(1, g:testdict['a'])
2464    assert_equal(2, g:testdict['b'])
2465  END
2466
2467  CheckDefAndScriptSuccess(lines)
2468
2469  CheckDefExecAndScriptFailure(['echo g:testblob[2]'], 'E979:', 1)
2470  CheckDefExecAndScriptFailure(['echo g:testblob[-3]'], 'E979:', 1)
2471
2472  CheckDefExecAndScriptFailure(['echo g:testlist[4]'], 'E684: list index out of range: 4', 1)
2473  CheckDefExecAndScriptFailure(['echo g:testlist[-5]'], 'E684:', 1)
2474
2475  CheckDefExecAndScriptFailure(['echo g:testdict["a" : "b"]'], 'E719:', 1)
2476  CheckDefExecAndScriptFailure(['echo g:testdict[1]'], 'E716:', 1)
2477
2478  unlet g:teststring
2479  unlet g:testblob
2480  unlet g:testlist
2481enddef
2482
2483def Test_expr_member_vim9script()
2484  var lines =<< trim END
2485      var d = {one:
2486      		'one',
2487		two: 'two',
2488		1: 1,
2489		_: 2}
2490      assert_equal('one', d.one)
2491      assert_equal('one', d
2492                            .one)
2493      assert_equal(1, d
2494                            .1)
2495      assert_equal(2, d
2496                            ._)
2497      assert_equal('one', d[
2498			    'one'
2499			    ])
2500  END
2501  CheckDefAndScriptSuccess(lines)
2502
2503  lines =<< trim END
2504      var l = [1,
2505		  2,
2506		  3, 4
2507		  ]
2508      assert_equal(2, l[
2509			    1
2510			    ])
2511      assert_equal([2, 3], l[1 : 2])
2512      assert_equal([1, 2, 3], l[
2513				:
2514				2
2515				])
2516      assert_equal([3, 4], l[
2517				2
2518				:
2519				])
2520  END
2521  CheckDefAndScriptSuccess(lines)
2522enddef
2523
2524def SetSomeVar()
2525  b:someVar = &fdm
2526enddef
2527
2528def Test_expr7_option()
2529  var lines =<< trim END
2530      # option
2531      set ts=11
2532      assert_equal(11, &ts)
2533      &ts = 9
2534      assert_equal(9, &ts)
2535      set ts=8
2536      set grepprg=some\ text
2537      assert_equal('some text', &grepprg)
2538      &grepprg = test_null_string()
2539      assert_equal('', &grepprg)
2540      set grepprg&
2541
2542      # check matching type
2543      var bval: bool = &tgc
2544      var nval: number = &ts
2545      var sval: string = &path
2546
2547      # check v_lock is cleared (requires using valgrind, doesn't always show)
2548      SetSomeVar()
2549      b:someVar = 0
2550      unlet b:someVar
2551  END
2552  CheckDefAndScriptSuccess(lines)
2553enddef
2554
2555def Test_expr7_environment()
2556  var lines =<< trim END
2557      # environment variable
2558      assert_equal('testvar', $TESTVAR)
2559      assert_equal('', $ASDF_ASD_XXX)
2560  END
2561  CheckDefAndScriptSuccess(lines)
2562
2563  CheckDefAndScriptFailure2(["var x = $$$"], 'E1002:', 'E15:', 1)
2564enddef
2565
2566def Test_expr7_register()
2567  var lines =<< trim END
2568      @a = 'register a'
2569      assert_equal('register a', @a)
2570
2571      var fname = expand('%')
2572      assert_equal(fname, @%)
2573
2574      feedkeys(":echo 'some'\<CR>", "xt")
2575      assert_equal("echo 'some'", @:)
2576
2577      normal axyz
2578      assert_equal("xyz", @.)
2579
2580      @/ = 'slash'
2581      assert_equal('slash', @/)
2582
2583      @= = 'equal'
2584      assert_equal('equal', @=)
2585  END
2586  CheckDefAndScriptSuccess(lines)
2587
2588  CheckDefAndScriptFailure2(["@. = 'yes'"], 'E354:', 'E488:', 1)
2589enddef
2590
2591" This is slow when run under valgrind.
2592def Test_expr7_namespace()
2593  var lines =<< trim END
2594      g:some_var = 'some'
2595      assert_equal('some', get(g:, 'some_var'))
2596      assert_equal('some', get(g:, 'some_var', 'xxx'))
2597      assert_equal('xxx', get(g:, 'no_var', 'xxx'))
2598      unlet g:some_var
2599
2600      b:some_var = 'some'
2601      assert_equal('some', get(b:, 'some_var'))
2602      assert_equal('some', get(b:, 'some_var', 'xxx'))
2603      assert_equal('xxx', get(b:, 'no_var', 'xxx'))
2604      unlet b:some_var
2605
2606      w:some_var = 'some'
2607      assert_equal('some', get(w:, 'some_var'))
2608      assert_equal('some', get(w:, 'some_var', 'xxx'))
2609      assert_equal('xxx', get(w:, 'no_var', 'xxx'))
2610      unlet w:some_var
2611
2612      t:some_var = 'some'
2613      assert_equal('some', get(t:, 'some_var'))
2614      assert_equal('some', get(t:, 'some_var', 'xxx'))
2615      assert_equal('xxx', get(t:, 'no_var', 'xxx'))
2616      unlet t:some_var
2617
2618      # check using g: in a for loop more than DO_NOT_FREE_CNT times
2619      for i in range(100000)
2620        if has_key(g:, 'does-not-exist')
2621        endif
2622      endfor
2623  END
2624  CheckDefAndScriptSuccess(lines)
2625enddef
2626
2627def Test_expr7_parens()
2628  # (expr)
2629  var lines =<< trim END
2630      assert_equal(4, (6 * 4) / 6)
2631      assert_equal(0, 6 * ( 4 / 6 ))
2632
2633      assert_equal(6, +6)
2634      assert_equal(-6, -6)
2635      assert_equal(false, !-3)
2636      assert_equal(true, !+0)
2637
2638      assert_equal(7, 5 + (
2639                    2))
2640      assert_equal(7, 5 + (
2641                    2
2642                    ))
2643      assert_equal(7, 5 + ( # comment
2644                    2))
2645      assert_equal(7, 5 + ( # comment
2646                    # comment
2647                    2))
2648
2649      var s = (
2650		'one'
2651		..
2652		'two'
2653		)
2654      assert_equal('onetwo', s)
2655  END
2656  CheckDefAndScriptSuccess(lines)
2657enddef
2658
2659def Test_expr7_negate_add()
2660  var lines =<< trim END
2661      assert_equal(-99, -99)
2662      assert_equal(-99, - 99)
2663      assert_equal(99, +99)
2664
2665      var nr = 88
2666      assert_equal(-88, -nr)
2667      assert_equal(-88, - nr)
2668      assert_equal(88, + nr)
2669  END
2670  CheckDefAndScriptSuccess(lines)
2671
2672  lines =<< trim END
2673    var n = 12
2674    echo ++n
2675  END
2676  CheckDefAndScriptFailure(lines, 'E15:')
2677  lines =<< trim END
2678    var n = 12
2679    echo --n
2680  END
2681  CheckDefAndScriptFailure(lines, 'E15:')
2682  lines =<< trim END
2683    var n = 12
2684    echo +-n
2685  END
2686  CheckDefAndScriptFailure(lines, 'E15:')
2687  lines =<< trim END
2688    var n = 12
2689    echo -+n
2690  END
2691  CheckDefAndScriptFailure(lines, 'E15:')
2692  lines =<< trim END
2693    var n = 12
2694    echo - -n
2695  END
2696  CheckDefAndScriptFailure(lines, 'E15:')
2697  lines =<< trim END
2698    var n = 12
2699    echo + +n
2700  END
2701  CheckDefAndScriptFailure(lines, 'E15:')
2702
2703  lines =<< trim END
2704    var n = 12
2705    :1
2706    ++n
2707  END
2708  CheckDefAndScriptFailure(lines, 'E1050:')
2709  lines =<< trim END
2710    var n = 12
2711    :1
2712    --n
2713  END
2714  CheckDefAndScriptFailure(lines, 'E1050:')
2715enddef
2716
2717def Echo(arg: any): string
2718  return arg
2719enddef
2720
2721def s:Echo4Arg(arg: any): string
2722  return arg
2723enddef
2724
2725def Test_expr7_call()
2726  var lines =<< trim END
2727      assert_equal('yes', 'yes'->Echo())
2728      assert_equal(true, !range(5)->empty())
2729      assert_equal([0, 1, 2], 3->range())
2730  END
2731  CheckDefAndScriptSuccess(lines)
2732
2733  assert_equal('yes', 'yes'
2734                        ->s:Echo4Arg())
2735
2736  CheckDefAndScriptFailure(["var x = 'yes'->Echo"], 'E107:', 1)
2737  CheckDefAndScriptFailure2([
2738       "var x = substitute ('x', 'x', 'x', 'x')"
2739       ], 'E1001:', 'E121:', 1)
2740  CheckDefAndScriptFailure2(["var Ref = function('len' [1, 2])"], 'E1123:', 'E116:', 1)
2741
2742  var auto_lines =<< trim END
2743      def g:some#func(): string
2744	return 'found'
2745      enddef
2746  END
2747  mkdir('Xruntime/autoload', 'p')
2748  writefile(auto_lines, 'Xruntime/autoload/some.vim')
2749  var save_rtp = &rtp
2750  &rtp = getcwd() .. '/Xruntime,' .. &rtp
2751  assert_equal('found', g:some#func())
2752  assert_equal('found', some#func())
2753
2754  &rtp = save_rtp
2755  delete('Xruntime', 'rf')
2756enddef
2757
2758def Test_expr7_method_call()
2759  var lines =<< trim END
2760      new
2761      setline(1, ['first', 'last'])
2762      'second'->append(1)
2763      "third"->append(2)
2764      assert_equal(['first', 'second', 'third', 'last'], getline(1, '$'))
2765      bwipe!
2766
2767      var bufnr = bufnr()
2768      var loclist = [{bufnr: bufnr, lnum: 42, col: 17, text: 'wrong'}]
2769      loclist->setloclist(0)
2770      assert_equal([{bufnr: bufnr,
2771                    lnum: 42,
2772                    col: 17,
2773                    text: 'wrong',
2774                    pattern: '',
2775                    valid: 1,
2776                    vcol: 0,
2777                    nr: 0,
2778                    type: '',
2779                    module: ''}
2780                    ], getloclist(0))
2781
2782      var result: bool = get({n: 0}, 'n', 0)
2783      assert_equal(false, result)
2784
2785      assert_equal('+string+', 'string'->((s) => '+' .. s .. '+')())
2786      assert_equal('-text-', 'text'->((s, c) => c .. s .. c)('-'))
2787
2788      var Join = (l) => join(l, 'x')
2789      assert_equal('axb', ['a', 'b']->(Join)())
2790  END
2791  CheckDefAndScriptSuccess(lines)
2792enddef
2793
2794
2795def Test_expr7_not()
2796  var lines =<< trim END
2797      assert_equal(true, !'')
2798      assert_equal(true, ![])
2799      assert_equal(false, !'asdf')
2800      assert_equal(false, ![2])
2801      assert_equal(true, !!'asdf')
2802      assert_equal(true, !![2])
2803
2804      assert_equal(true, ! false)
2805      assert_equal(true, !! true)
2806      assert_equal(true, ! ! true)
2807      assert_equal(true, !!! false)
2808      assert_equal(true, ! ! ! false)
2809
2810      g:true = true
2811      g:false = false
2812      assert_equal(true, ! g:false)
2813      assert_equal(true, !! g:true)
2814      assert_equal(true, ! ! g:true)
2815      assert_equal(true, !!! g:false)
2816      assert_equal(true, ! ! ! g:false)
2817      unlet g:true
2818      unlet g:false
2819
2820      assert_equal(true, !test_null_partial())
2821      assert_equal(false, !() => 'yes')
2822
2823      assert_equal(true, !test_null_dict())
2824      assert_equal(true, !{})
2825      assert_equal(false, !{yes: 'no'})
2826
2827      if has('channel')
2828	assert_equal(true, !test_null_job())
2829	assert_equal(true, !test_null_channel())
2830      endif
2831
2832      assert_equal(true, !test_null_blob())
2833      assert_equal(true, !0z)
2834      assert_equal(false, !0z01)
2835
2836      assert_equal(true, !test_void())
2837      assert_equal(true, !test_unknown())
2838
2839      assert_equal(false, ![1, 2, 3]->reverse())
2840      assert_equal(true, ![]->reverse())
2841  END
2842  CheckDefAndScriptSuccess(lines)
2843enddef
2844
2845func Test_expr7_fails()
2846  call CheckDefFailure(["var x = (12"], "E1097:", 3)
2847  call CheckScriptFailure(['vim9script', "var x = (12"], 'E110:', 2)
2848
2849  call CheckDefAndScriptFailure(["var x = -'xx'"], "E1030:", 1)
2850  call CheckDefAndScriptFailure(["var x = +'xx'"], "E1030:", 1)
2851  call CheckDefAndScriptFailure(["var x = -0z12"], "E974:", 1)
2852  call CheckDefExecAndScriptFailure2(["var x = -[8]"], "E39:", 'E745:', 1)
2853  call CheckDefExecAndScriptFailure2(["var x = -{a: 1}"], "E39:", 'E728:', 1)
2854
2855  call CheckDefAndScriptFailure(["var x = @"], "E1002:", 1)
2856  call CheckDefAndScriptFailure(["var x = @<"], "E354:", 1)
2857
2858  call CheckDefFailure(["var x = [1, 2"], "E697:", 2)
2859  call CheckScriptFailure(['vim9script', "var x = [1, 2"], 'E696:', 2)
2860
2861  call CheckDefAndScriptFailure2(["var x = [notfound]"], "E1001:", 'E121:', 1)
2862
2863  call CheckDefAndScriptFailure2(["var X = () => 123)"], "E488:", 'E15:', 1)
2864  call CheckDefAndScriptFailure(["var x = 123->((x) => x + 5)"], "E107:", 1)
2865
2866  call CheckDefAndScriptFailure(["var x = &notexist"], 'E113:', 1)
2867  call CheckDefAndScriptFailure2(["&grepprg = [343]"], 'E1012:', 'E730:', 1)
2868
2869  call CheckDefExecAndScriptFailure(["echo s:doesnt_exist"], 'E121:', 1)
2870  call CheckDefExecAndScriptFailure(["echo g:doesnt_exist"], 'E121:', 1)
2871
2872  call CheckDefAndScriptFailure2(["echo a:somevar"], 'E1075:', 'E121:', 1)
2873  call CheckDefAndScriptFailure2(["echo l:somevar"], 'E1075:', 'E121:', 1)
2874  call CheckDefAndScriptFailure2(["echo x:somevar"], 'E1075:', 'E121:', 1)
2875
2876  call CheckDefExecAndScriptFailure(["var x = +g:astring"], 'E1030:', 1)
2877  call CheckDefExecAndScriptFailure(["var x = +g:ablob"], 'E974:', 1)
2878  call CheckDefExecAndScriptFailure(["var x = +g:alist"], 'E745:', 1)
2879  call CheckDefExecAndScriptFailure(["var x = +g:adict"], 'E728:', 1)
2880
2881  call CheckDefAndScriptFailure2(["var x = ''", "var y = x.memb"], 'E715:', 'E15:', 2)
2882
2883  call CheckDefAndScriptFailure2(["'yes'->", "Echo()"], 'E488: Trailing characters: ->', 'E260: Missing name after ->', 1)
2884
2885  call CheckDefExecFailure(["[1, 2->len()"], 'E697:', 2)
2886  call CheckScriptFailure(['vim9script', "[1, 2->len()"], 'E696:', 2)
2887
2888  call CheckDefFailure(["{a: 1->len()"], 'E723:', 2)
2889  call CheckScriptFailure(['vim9script', "{a: 1->len()"], 'E722:', 2)
2890
2891  call CheckDefExecFailure(["{['a']: 1->len()"], 'E723:', 2)
2892  call CheckScriptFailure(['vim9script', "{['a']: 1->len()"], 'E722:', 2)
2893endfunc
2894
2895let g:Funcrefs = [function('add')]
2896
2897func CallMe(arg)
2898  return a:arg
2899endfunc
2900
2901func CallMe2(one, two)
2902  return a:one .. a:two
2903endfunc
2904
2905def Test_expr7_trailing()
2906  var lines =<< trim END
2907      # user function call
2908      assert_equal(123, g:CallMe(123))
2909      assert_equal(123, g:CallMe(  123))
2910      assert_equal(123, g:CallMe(123  ))
2911      assert_equal('yesno', g:CallMe2('yes', 'no'))
2912      assert_equal('yesno', g:CallMe2( 'yes', 'no' ))
2913      assert_equal('nothing', g:CallMe('nothing'))
2914
2915      # partial call
2916      var Part = function('g:CallMe')
2917      assert_equal('yes', Part('yes'))
2918
2919      # funcref call, using list index
2920      var l = []
2921      g:Funcrefs[0](l, 2)
2922      assert_equal([2], l)
2923
2924      # method call
2925      l = [2, 5, 6]
2926      l->map((k, v) => k + v)
2927      assert_equal([2, 6, 8], l)
2928
2929      # lambda method call
2930      l = [2, 5]
2931      l->((ll) => add(ll, 8))()
2932      assert_equal([2, 5, 8], l)
2933
2934      # dict member
2935      var d = {key: 123}
2936      assert_equal(123, d.key)
2937  END
2938  CheckDefAndScriptSuccess(lines)
2939enddef
2940
2941def Test_expr7_string_subscript()
2942  var lines =<< trim END
2943    var text = 'abcdef'
2944    assert_equal('f', text[-1])
2945    assert_equal('a', text[0])
2946    assert_equal('e', text[4])
2947    assert_equal('f', text[5])
2948    assert_equal('', text[6])
2949
2950    text = 'ábçdë'
2951    assert_equal('ë', text[-1])
2952    assert_equal('d', text[-2])
2953    assert_equal('ç', text[-3])
2954    assert_equal('b', text[-4])
2955    assert_equal('á', text[-5])
2956    assert_equal('', text[-6])
2957
2958    text = 'ábçdëf'
2959    assert_equal('', text[-999])
2960    assert_equal('f', text[-1])
2961    assert_equal('á', text[0])
2962    assert_equal('b', text[1])
2963    assert_equal('ç', text[2])
2964    assert_equal('d', text[3])
2965    assert_equal('ë', text[4])
2966    assert_equal('f', text[5])
2967    assert_equal('', text[6])
2968    assert_equal('', text[999])
2969
2970    assert_equal('ábçdëf', text[0 : -1])
2971    assert_equal('ábçdëf', text[0 : -1])
2972    assert_equal('ábçdëf', text[0 : -1])
2973    assert_equal('ábçdëf', text[0 : -1])
2974    assert_equal('ábçdëf', text[0
2975                  : -1])
2976    assert_equal('ábçdëf', text[0 :
2977                  -1])
2978    assert_equal('ábçdëf', text[0 : -1
2979                  ])
2980    assert_equal('bçdëf', text[1 : -1])
2981    assert_equal('çdëf', text[2 : -1])
2982    assert_equal('dëf', text[3 : -1])
2983    assert_equal('ëf', text[4 : -1])
2984    assert_equal('f', text[5 : -1])
2985    assert_equal('', text[6 : -1])
2986    assert_equal('', text[999 : -1])
2987
2988    assert_equal('ábçd', text[: 3])
2989    assert_equal('bçdëf', text[1 :])
2990    assert_equal('ábçdëf', text[:])
2991  END
2992  CheckDefAndScriptSuccess(lines)
2993
2994  lines =<< trim END
2995      var d = 'asdf'[1 :
2996  END
2997  CheckDefFailure(lines, 'E1097:', 3)
2998  CheckScriptFailure(['vim9script'] + lines, 'E15:', 2)
2999
3000  lines =<< trim END
3001      var d = 'asdf'[1 : xxx]
3002  END
3003  CheckDefAndScriptFailure2(lines, 'E1001:', 'E121:', 1)
3004
3005  lines =<< trim END
3006      var d = 'asdf'[1 : 2
3007  END
3008  CheckDefFailure(lines, 'E1097:', 3)
3009  CheckScriptFailure(['vim9script'] + lines, 'E111:', 2)
3010
3011  lines =<< trim END
3012      var d = 'asdf'[1 : 2
3013      echo d
3014  END
3015  CheckDefAndScriptFailure(lines, 'E111:', 2)
3016
3017  lines =<< trim END
3018      var d = 'asdf'['1']
3019      echo d
3020  END
3021  CheckDefAndScriptFailure2(lines, 'E1012: Type mismatch; expected number but got string', 'E1030: Using a String as a Number: "1"', 1)
3022
3023  lines =<< trim END
3024      var d = 'asdf'['1' : 2]
3025      echo d
3026  END
3027  CheckDefAndScriptFailure2(lines, 'E1012: Type mismatch; expected number but got string', 'E1030: Using a String as a Number: "1"', 1)
3028
3029  lines =<< trim END
3030      var d = 'asdf'[1 : '2']
3031      echo d
3032  END
3033  CheckDefAndScriptFailure2(lines, 'E1012: Type mismatch; expected number but got string', 'E1030: Using a String as a Number: "2"', 1)
3034enddef
3035
3036def Test_expr7_list_subscript()
3037  var lines =<< trim END
3038      var list = [0, 1, 2, 3, 4]
3039      assert_equal(0, list[0])
3040      assert_equal(4, list[4])
3041      assert_equal(4, list[-1])
3042      assert_equal(0, list[-5])
3043
3044      assert_equal([0, 1, 2, 3, 4], list[0 : 4])
3045      assert_equal([0, 1, 2, 3, 4], list[:])
3046      assert_equal([1, 2, 3, 4], list[1 :])
3047      assert_equal([2, 3, 4], list[2 : -1])
3048      assert_equal([4], list[4 : -1])
3049      assert_equal([], list[5 : -1])
3050      assert_equal([], list[999 : -1])
3051      assert_equal([1, 2, 3, 4], list[g:theone : g:thefour])
3052
3053      assert_equal([0, 1, 2, 3], list[0 : 3])
3054      assert_equal([0], list[0 : 0])
3055      assert_equal([0, 1, 2, 3, 4], list[0 : -1])
3056      assert_equal([0, 1, 2], list[0 : -3])
3057      assert_equal([0], list[0 : -5])
3058      assert_equal([], list[0 : -6])
3059      assert_equal([], list[0 : -99])
3060  END
3061  CheckDefAndScriptSuccess(lines)
3062
3063  lines = ['var l = [0, 1, 2]', 'echo l[g:astring : g:theone]']
3064  CheckDefExecAndScriptFailure2(lines, 'E1012:', 'E1030:', 2)
3065
3066  lines =<< trim END
3067      var ld = []
3068      def Func()
3069        eval ld[0].key
3070      enddef
3071      defcompile
3072  END
3073  CheckDefAndScriptSuccess(lines)
3074enddef
3075
3076def Test_expr7_dict_subscript()
3077  var lines =<< trim END
3078      var l = [{lnum: 2}, {lnum: 1}]
3079      var res = l[0].lnum > l[1].lnum
3080      assert_true(res)
3081
3082      var dd = {}
3083      def Func1()
3084        eval dd.key1.key2
3085      enddef
3086      def Func2()
3087        eval dd['key1'].key2
3088      enddef
3089      defcompile
3090  END
3091  CheckDefAndScriptSuccess(lines)
3092enddef
3093
3094def Test_expr7_subscript_linebreak()
3095  var lines =<< trim END
3096      var range = range(
3097                    3)
3098      var l = range
3099            ->mapnew('string(v:key)')
3100      assert_equal(['0', '1', '2'], l)
3101
3102      l = range
3103            ->mapnew('string(v:key)')
3104      assert_equal(['0', '1', '2'], l)
3105
3106      l = range # comment
3107            ->mapnew('string(v:key)')
3108      assert_equal(['0', '1', '2'], l)
3109
3110      l = range
3111
3112            ->mapnew('string(v:key)')
3113      assert_equal(['0', '1', '2'], l)
3114
3115      l = range
3116            # comment
3117            ->mapnew('string(v:key)')
3118      assert_equal(['0', '1', '2'], l)
3119
3120      assert_equal('1', l[
3121            1])
3122
3123      var d = {one: 33}
3124      assert_equal(33, d
3125            .one)
3126  END
3127  CheckDefAndScriptSuccess(lines)
3128
3129  lines =<< trim END
3130      var d = {one: 33}
3131      assert_equal(33, d.
3132            one)
3133  END
3134  CheckDefAndScriptFailure2(lines, 'E1127:', 'E116:', 2)
3135enddef
3136
3137func Test_expr7_trailing_fails()
3138  call CheckDefAndScriptFailure(['var l = [2]', 'l->((ll) => add(ll, 8))'], 'E107:', 2)
3139  call CheckDefAndScriptFailure(['var l = [2]', 'l->((ll) => add(ll, 8)) ()'], 'E274:', 2)
3140endfunc
3141
3142func Test_expr_fails()
3143  call CheckDefAndScriptFailure2(["var x = '1'is2"], 'E488:', 'E15:', 1)
3144  call CheckDefAndScriptFailure2(["var x = '1'isnot2"], 'E488:', 'E15:', 1)
3145
3146  call CheckDefAndScriptFailure2(["CallMe ('yes')"], 'E476:', 'E492:', 1)
3147
3148  call CheckDefAndScriptFailure(["CallMe2('yes','no')"], 'E1069:', 1)
3149
3150  call CheckDefAndScriptFailure2(["v:nosuch += 3"], 'E1001:', 'E121:', 1)
3151  call CheckDefAndScriptFailure(["var v:statusmsg = ''"], 'E1016: Cannot declare a v: variable:', 1)
3152  call CheckDefAndScriptFailure2(["var asdf = v:nosuch"], 'E1001:', 'E121:', 1)
3153
3154  call CheckDefFailure(["echo len('asdf'"], 'E110:', 2)
3155  call CheckScriptFailure(['vim9script', "echo len('asdf'"], 'E116:', 2)
3156
3157  call CheckDefAndScriptFailure2(["echo Func0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789()"], 'E1011:', 'E117:', 1)
3158  call CheckDefAndScriptFailure(["echo doesnotexist()"], 'E117:', 1)
3159endfunc
3160
3161" vim: shiftwidth=2 sts=2 expandtab
3162