1" Tests for Vim9 script expressions
2
3source check.vim
4source vim9.vim
5
6" test cond ? expr : expr
7def Test_expr1()
8  assert_equal('one', true ? 'one' : 'two')
9  assert_equal('one', 1 ?
10			'one' :
11			'two')
12  if has('float')
13    assert_equal('one', 0.1 ? 'one' : 'two')
14  endif
15  assert_equal('one', 'x' ? 'one' : 'two')
16  assert_equal('one', 'x'
17  			? 'one'
18			: 'two')
19  assert_equal('one', 0z1234 ? 'one' : 'two')
20  assert_equal('one', [0] ? 'one' : 'two')
21  assert_equal('one', #{x: 0} ? 'one' : 'two')
22  let var = 1
23  assert_equal('one', var ? 'one' : 'two')
24
25  assert_equal('two', false ? 'one' : 'two')
26  assert_equal('two', 0 ? 'one' : 'two')
27  if has('float')
28    assert_equal('two', 0.0 ? 'one' : 'two')
29  endif
30  assert_equal('two', '' ? 'one' : 'two')
31  assert_equal('two', 0z ? 'one' : 'two')
32  assert_equal('two', [] ? 'one' : 'two')
33  assert_equal('two', {} ? 'one' : 'two')
34  var = 0
35  assert_equal('two', var ? 'one' : 'two')
36
37  let Some: func = function('len')
38  let Other: func = function('winnr')
39  let Res: func = g:atrue ? Some : Other
40  assert_equal(function('len'), Res)
41
42  let RetOne: func(string): number = function('len')
43  let RetTwo: func(string): number = function('winnr')
44  let RetThat: func = g:atrue ? RetOne : RetTwo
45  assert_equal(function('len'), RetThat)
46enddef
47
48def Test_expr1_vimscript()
49  " only checks line continuation
50  let lines =<< trim END
51      vim9script
52      let var = 1
53      		? 'yes'
54		: 'no'
55      assert_equal('yes', var)
56  END
57  CheckScriptSuccess(lines)
58
59  lines =<< trim END
60      vim9script
61      let var = v:false
62      		? 'yes'
63		: 'no'
64      assert_equal('no', var)
65  END
66  CheckScriptSuccess(lines)
67
68  lines =<< trim END
69      vim9script
70      let var = v:false ?
71      		'yes' :
72		'no'
73      assert_equal('no', var)
74  END
75  CheckScriptSuccess(lines)
76enddef
77
78func Test_expr1_fails()
79  call CheckDefFailure(["let x = 1 ? 'one'"], "Missing ':' after '?'")
80  call CheckDefFailure(["let x = 1 ? 'one' : xxx"], "E1001:")
81
82  let msg = "white space required before and after '?'"
83  call CheckDefFailure(["let x = 1? 'one' : 'two'"], msg)
84  call CheckDefFailure(["let x = 1 ?'one' : 'two'"], msg)
85  call CheckDefFailure(["let x = 1?'one' : 'two'"], msg)
86
87  let msg = "white space required before and after ':'"
88  call CheckDefFailure(["let x = 1 ? 'one': 'two'"], msg)
89  call CheckDefFailure(["let x = 1 ? 'one' :'two'"], msg)
90  call CheckDefFailure(["let x = 1 ? 'one':'two'"], msg)
91endfunc
92
93" TODO: define inside test function
94def Record(val: any): any
95  g:vals->add(val)
96  return val
97enddef
98
99" test ||
100def Test_expr2()
101  assert_equal(2, 2 || 0)
102  assert_equal(7, 0 ||
103		    0 ||
104		    7)
105  assert_equal(0, 0 || 0)
106  assert_equal(0, 0
107  		    || 0)
108  assert_equal('', 0 || '')
109
110  g:vals = []
111  assert_equal(3, Record(3) || Record(1))
112  assert_equal([3], g:vals)
113
114  g:vals = []
115  assert_equal(5, Record(0) || Record(5))
116  assert_equal([0, 5], g:vals)
117
118  g:vals = []
119  assert_equal(4, Record(0)
120		      || Record(4)
121		      || Record(0))
122  assert_equal([0, 4], g:vals)
123
124  g:vals = []
125  assert_equal(0, Record([]) || Record('') || Record(0))
126  assert_equal([[], '', 0], g:vals)
127enddef
128
129def Test_expr2_vimscript()
130  " only checks line continuation
131  let lines =<< trim END
132      vim9script
133      let var = 0
134      		|| 1
135      assert_equal(1, var)
136  END
137  CheckScriptSuccess(lines)
138
139  lines =<< trim END
140      vim9script
141      let var = v:false
142      		|| v:true
143      		|| v:false
144      assert_equal(1, var)
145  END
146  CheckScriptSuccess(lines)
147
148  lines =<< trim END
149      vim9script
150      let var = v:false ||
151      		v:true ||
152		v:false
153      assert_equal(1, var)
154  END
155  CheckScriptSuccess(lines)
156enddef
157
158func Test_expr2_fails()
159  let msg = "white space required before and after '||'"
160  call CheckDefFailure(["let x = 1||2"], msg)
161  call CheckDefFailure(["let x = 1 ||2"], msg)
162  call CheckDefFailure(["let x = 1|| 2"], msg)
163
164  call CheckDefFailure(["let x = 1 || xxx"], 'E1001:')
165endfunc
166
167" test &&
168def Test_expr3()
169  assert_equal(0, 2 && 0)
170  assert_equal(0, 0 &&
171		0 &&
172		7)
173  assert_equal(7, 2
174  		    && 3
175		    && 7)
176  assert_equal(0, 0 && 0)
177  assert_equal(0, 0 && '')
178  assert_equal('', 8 && '')
179
180  g:vals = []
181  assert_equal(1, Record(3) && Record(1))
182  assert_equal([3, 1], g:vals)
183
184  g:vals = []
185  assert_equal(0, Record(0) && Record(5))
186  assert_equal([0], g:vals)
187
188  g:vals = []
189  assert_equal(0, Record(0) && Record(4) && Record(0))
190  assert_equal([0], g:vals)
191
192  g:vals = []
193  assert_equal(0, Record(8) && Record(4) && Record(0))
194  assert_equal([8, 4, 0], g:vals)
195
196  g:vals = []
197  assert_equal(0, Record([1]) && Record('z') && Record(0))
198  assert_equal([[1], 'z', 0], g:vals)
199enddef
200
201def Test_expr3_vimscript()
202  " only checks line continuation
203  let lines =<< trim END
204      vim9script
205      let var = 0
206      		&& 1
207      assert_equal(0, var)
208  END
209  CheckScriptSuccess(lines)
210
211  lines =<< trim END
212      vim9script
213      let var = v:true
214      		&& v:true
215      		&& v:true
216      assert_equal(1, var)
217  END
218  CheckScriptSuccess(lines)
219
220  lines =<< trim END
221      vim9script
222      let var = v:true &&
223      		v:true &&
224      		v:true
225      assert_equal(1, var)
226  END
227  CheckScriptSuccess(lines)
228enddef
229
230func Test_expr3_fails()
231  let msg = "white space required before and after '&&'"
232  call CheckDefFailure(["let x = 1&&2"], msg)
233  call CheckDefFailure(["let x = 1 &&2"], msg)
234  call CheckDefFailure(["let x = 1&& 2"], msg)
235endfunc
236
237let atrue = v:true
238let afalse = v:false
239let anone = v:none
240let anull = v:null
241let anint = 10
242let alsoint = 4
243if has('float')
244  let afloat = 0.1
245endif
246let astring = 'asdf'
247let ablob = 0z01ab
248let alist = [2, 3, 4]
249let adict = #{aaa: 2, bbb: 8}
250
251" test == comperator
252def Test_expr4_equal()
253  let trueVar = true
254  let falseVar = false
255  assert_equal(true, true == true)
256  assert_equal(false, true ==
257			false)
258  assert_equal(true, true
259			== trueVar)
260  assert_equal(false, true == falseVar)
261  assert_equal(true, true == g:atrue)
262  assert_equal(false, g:atrue == false)
263
264  assert_equal(true, v:none == v:none)
265  assert_equal(false, v:none == v:null)
266  assert_equal(true, g:anone == v:none)
267  assert_equal(false, v:none == g:anull)
268
269  let nr0 = 0
270  let nr61 = 61
271  assert_equal(false, 2 == 0)
272  assert_equal(false, 2 == nr0)
273  assert_equal(true, 61 == 61)
274  assert_equal(true, 61 == nr61)
275  assert_equal(true, g:anint == 10)
276  assert_equal(false, 61 == g:anint)
277
278  if has('float')
279    let ff = 0.3
280    assert_equal(true, ff == 0.3)
281    assert_equal(false, 0.4 == ff)
282    assert_equal(true, 0.1 == g:afloat)
283    assert_equal(false, g:afloat == 0.3)
284
285    ff = 3.0
286    assert_equal(true, ff == 3)
287    assert_equal(true, 3 == ff)
288    ff = 3.1
289    assert_equal(false, ff == 3)
290    assert_equal(false, 3 == ff)
291  endif
292
293  assert_equal(true, 'abc' == 'abc')
294  assert_equal(false, 'xyz' == 'abc')
295  assert_equal(true, g:astring == 'asdf')
296  assert_equal(false, 'xyz' == g:astring)
297
298  assert_equal(false, 'abc' == 'aBc')
299  assert_equal(false, 'abc' ==# 'aBc')
300  assert_equal(true, 'abc' ==? 'aBc')
301
302  assert_equal(false, 'abc' == 'ABC')
303  set ignorecase
304  assert_equal(false, 'abc' == 'ABC')
305  assert_equal(false, 'abc' ==# 'ABC')
306  set noignorecase
307
308  call CheckDefFailure(["let x = 'a' == xxx"], 'E1001:')
309
310  let bb = 0z3f
311  assert_equal(true, 0z3f == bb)
312  assert_equal(false, bb == 0z4f)
313  assert_equal(true, g:ablob == 0z01ab)
314  assert_equal(false, 0z3f == g:ablob)
315
316  assert_equal(true, [1, 2, 3] == [1, 2, 3])
317  assert_equal(false, [1, 2, 3] == [2, 3, 1])
318  assert_equal(true, [2, 3, 4] == g:alist)
319  assert_equal(false, g:alist == [2, 3, 1])
320  assert_equal(false, [1, 2, 3] == [])
321  assert_equal(false, [1, 2, 3] == ['1', '2', '3'])
322
323  assert_equal(true, #{one: 1, two: 2} == #{one: 1, two: 2})
324  assert_equal(false, #{one: 1, two: 2} == #{one: 2, two: 2})
325  assert_equal(false, #{one: 1, two: 2} == #{two: 2})
326  assert_equal(false, #{one: 1, two: 2} == #{})
327  assert_equal(true, g:adict == #{bbb: 8, aaa: 2})
328  assert_equal(false, #{ccc: 9, aaa: 2} == g:adict)
329
330  assert_equal(true, function('g:Test_expr4_equal') == function('g:Test_expr4_equal'))
331  assert_equal(false, function('g:Test_expr4_equal') == function('g:Test_expr4_is'))
332
333  assert_equal(true, function('g:Test_expr4_equal', [123]) == function('g:Test_expr4_equal', [123]))
334  assert_equal(false, function('g:Test_expr4_equal', [123]) == function('g:Test_expr4_is', [123]))
335  assert_equal(false, function('g:Test_expr4_equal', [123]) == function('g:Test_expr4_equal', [999]))
336
337  let OneFunc: func
338  let TwoFunc: func
339  OneFunc = function('len')
340  TwoFunc = function('len')
341  assert_equal(true, OneFunc('abc') == TwoFunc('123'))
342enddef
343
344" test != comperator
345def Test_expr4_notequal()
346  let trueVar = true
347  let falseVar = false
348  assert_equal(false, true != true)
349  assert_equal(true, true !=
350			false)
351  assert_equal(false, true
352  			!= trueVar)
353  assert_equal(true, true != falseVar)
354  assert_equal(false, true != g:atrue)
355  assert_equal(true, g:atrue != false)
356
357  assert_equal(false, v:none != v:none)
358  assert_equal(true, v:none != v:null)
359  assert_equal(false, g:anone != v:none)
360  assert_equal(true, v:none != g:anull)
361
362  let nr55 = 55
363  let nr0 = 55
364  assert_equal(true, 2 != 0)
365  assert_equal(true, 2 != nr0)
366  assert_equal(false, 55 != 55)
367  assert_equal(false, 55 != nr55)
368  assert_equal(false, g:anint != 10)
369  assert_equal(true, 61 != g:anint)
370
371  if has('float')
372    let ff = 0.3
373    assert_equal(false, 0.3 != ff)
374    assert_equal(true, 0.4 != ff)
375    assert_equal(false, 0.1 != g:afloat)
376    assert_equal(true, g:afloat != 0.3)
377
378    ff = 3.0
379    assert_equal(false, ff != 3)
380    assert_equal(false, 3 != ff)
381    ff = 3.1
382    assert_equal(true, ff != 3)
383    assert_equal(true, 3 != ff)
384  endif
385
386  assert_equal(false, 'abc' != 'abc')
387  assert_equal(true, 'xyz' != 'abc')
388  assert_equal(false, g:astring != 'asdf')
389  assert_equal(true, 'xyz' != g:astring)
390
391  assert_equal(true, 'abc' != 'ABC')
392  set ignorecase
393  assert_equal(true, 'abc' != 'ABC')
394  set noignorecase
395
396  let bb = 0z3f
397  assert_equal(false, 0z3f != bb)
398  assert_equal(true, bb != 0z4f)
399  assert_equal(false, g:ablob != 0z01ab)
400  assert_equal(true, 0z3f != g:ablob)
401
402  assert_equal(false, [1, 2, 3] != [1, 2, 3])
403  assert_equal(true, [1, 2, 3] != [2, 3, 1])
404  assert_equal(false, [2, 3, 4] != g:alist)
405  assert_equal(true, g:alist != [2, 3, 1])
406  assert_equal(true, [1, 2, 3] != [])
407  assert_equal(true, [1, 2, 3] != ['1', '2', '3'])
408
409  assert_equal(false, #{one: 1, two: 2} != #{one: 1, two: 2})
410  assert_equal(true, #{one: 1, two: 2} != #{one: 2, two: 2})
411  assert_equal(true, #{one: 1, two: 2} != #{two: 2})
412  assert_equal(true, #{one: 1, two: 2} != #{})
413  assert_equal(false, g:adict != #{bbb: 8, aaa: 2})
414  assert_equal(true, #{ccc: 9, aaa: 2} != g:adict)
415
416  assert_equal(false, function('g:Test_expr4_equal') != function('g:Test_expr4_equal'))
417  assert_equal(true, function('g:Test_expr4_equal') != function('g:Test_expr4_is'))
418
419  assert_equal(false, function('g:Test_expr4_equal', [123]) != function('g:Test_expr4_equal', [123]))
420  assert_equal(true, function('g:Test_expr4_equal', [123]) != function('g:Test_expr4_is', [123]))
421  assert_equal(true, function('g:Test_expr4_equal', [123]) != function('g:Test_expr4_equal', [999]))
422enddef
423
424" test > comperator
425def Test_expr4_greater()
426  assert_true(2 > 0)
427  assert_true(2 >
428		1)
429  assert_false(2 > 2)
430  assert_false(2 > 3)
431  let nr2 = 2
432  assert_true(nr2 > 0)
433  assert_true(nr2 >
434		1)
435  assert_false(nr2 > 2)
436  assert_false(nr2
437  		    > 3)
438  if has('float')
439    let ff = 2.0
440    assert_true(ff > 0.0)
441    assert_true(ff > 1.0)
442    assert_false(ff > 2.0)
443    assert_false(ff > 3.0)
444  endif
445enddef
446
447" test >= comperator
448def Test_expr4_greaterequal()
449  assert_true(2 >= 0)
450  assert_true(2 >=
451			2)
452  assert_false(2 >= 3)
453  let nr2 = 2
454  assert_true(nr2 >= 0)
455  assert_true(nr2 >= 2)
456  assert_false(nr2 >= 3)
457  if has('float')
458    let ff = 2.0
459    assert_true(ff >= 0.0)
460    assert_true(ff >= 2.0)
461    assert_false(ff >= 3.0)
462  endif
463enddef
464
465" test < comperator
466def Test_expr4_smaller()
467  assert_false(2 < 0)
468  assert_false(2 <
469			2)
470  assert_true(2
471  		< 3)
472  let nr2 = 2
473  assert_false(nr2 < 0)
474  assert_false(nr2 < 2)
475  assert_true(nr2 < 3)
476  if has('float')
477    let ff = 2.0
478    assert_false(ff < 0.0)
479    assert_false(ff < 2.0)
480    assert_true(ff < 3.0)
481  endif
482enddef
483
484" test <= comperator
485def Test_expr4_smallerequal()
486  assert_false(2 <= 0)
487  assert_false(2 <=
488			1)
489  assert_true(2
490  		<= 2)
491  assert_true(2 <= 3)
492  let nr2 = 2
493  assert_false(nr2 <= 0)
494  assert_false(nr2 <= 1)
495  assert_true(nr2 <= 2)
496  assert_true(nr2 <= 3)
497  if has('float')
498    let ff = 2.0
499    assert_false(ff <= 0.0)
500    assert_false(ff <= 1.0)
501    assert_true(ff <= 2.0)
502    assert_true(ff <= 3.0)
503  endif
504enddef
505
506" test =~ comperator
507def Test_expr4_match()
508  assert_equal(false, '2' =~ '0')
509  assert_equal(false, ''
510  			 =~ '0')
511  assert_equal(true, '2' =~
512			'[0-9]')
513enddef
514
515" test !~ comperator
516def Test_expr4_nomatch()
517  assert_equal(true, '2' !~ '0')
518  assert_equal(true, ''
519  			!~ '0')
520  assert_equal(false, '2' !~
521			'[0-9]')
522enddef
523
524" test is comperator
525def Test_expr4_is()
526  let mylist = [2]
527  assert_false(mylist is [2])
528  let other = mylist
529  assert_true(mylist is
530		other)
531
532  let myblob = 0z1234
533  assert_false(myblob
534  			is 0z1234)
535  let otherblob = myblob
536  assert_true(myblob is otherblob)
537enddef
538
539" test isnot comperator
540def Test_expr4_isnot()
541  let mylist = [2]
542  assert_true('2' isnot '0')
543  assert_true(mylist isnot [2])
544  let other = mylist
545  assert_false(mylist isnot
546			other)
547
548  let myblob = 0z1234
549  assert_true(myblob
550  		isnot 0z1234)
551  let otherblob = myblob
552  assert_false(myblob isnot otherblob)
553enddef
554
555def RetVoid()
556  let x = 1
557enddef
558
559def Test_expr4_vimscript()
560  " only checks line continuation
561  let lines =<< trim END
562      vim9script
563      let var = 0
564      		< 1
565      assert_equal(1, var)
566  END
567  CheckScriptSuccess(lines)
568
569  lines =<< trim END
570      vim9script
571      let var = 123
572      		!= 123
573      assert_equal(0, var)
574  END
575  CheckScriptSuccess(lines)
576
577  lines =<< trim END
578      vim9script
579      let var = 123 ==
580      			123
581      assert_equal(1, var)
582  END
583  CheckScriptSuccess(lines)
584
585  lines =<< trim END
586      vim9script
587      let list = [1, 2, 3]
588      let var = list
589      		is list
590      assert_equal(1, var)
591  END
592  CheckScriptSuccess(lines)
593
594  lines =<< trim END
595      vim9script
596      let myblob = 0z1234
597      let var = myblob
598      		isnot 0z11
599      assert_equal(1, var)
600  END
601  CheckScriptSuccess(lines)
602enddef
603
604func Test_expr4_fails()
605  let msg = "white space required before and after '>'"
606  call CheckDefFailure(["let x = 1>2"], msg)
607  call CheckDefFailure(["let x = 1 >2"], msg)
608  call CheckDefFailure(["let x = 1> 2"], msg)
609
610  let msg = "white space required before and after '=='"
611  call CheckDefFailure(["let x = 1==2"], msg)
612  call CheckDefFailure(["let x = 1 ==2"], msg)
613  call CheckDefFailure(["let x = 1== 2"], msg)
614
615  let msg = "white space required before and after 'is'"
616  call CheckDefFailure(["let x = '1'is'2'"], msg)
617  call CheckDefFailure(["let x = '1' is'2'"], msg)
618  call CheckDefFailure(["let x = '1'is '2'"], msg)
619
620  let msg = "white space required before and after 'isnot'"
621  call CheckDefFailure(["let x = '1'isnot'2'"], msg)
622  call CheckDefFailure(["let x = '1' isnot'2'"], msg)
623  call CheckDefFailure(["let x = '1'isnot '2'"], msg)
624
625  call CheckDefFailure(["let x = 1 is# 2"], 'E15:')
626  call CheckDefFailure(["let x = 1 is? 2"], 'E15:')
627  call CheckDefFailure(["let x = 1 isnot# 2"], 'E15:')
628  call CheckDefFailure(["let x = 1 isnot? 2"], 'E15:')
629
630  call CheckDefFailure(["let x = 1 == '2'"], 'Cannot compare number with string')
631  call CheckDefFailure(["let x = '1' == 2"], 'Cannot compare string with number')
632  call CheckDefFailure(["let x = 1 == RetVoid()"], 'Cannot compare number with void')
633  call CheckDefFailure(["let x = RetVoid() == 1"], 'Cannot compare void with number')
634
635  call CheckDefFailure(["let x = true > false"], 'Cannot compare bool with bool')
636  call CheckDefFailure(["let x = true >= false"], 'Cannot compare bool with bool')
637  call CheckDefFailure(["let x = true < false"], 'Cannot compare bool with bool')
638  call CheckDefFailure(["let x = true <= false"], 'Cannot compare bool with bool')
639  call CheckDefFailure(["let x = true =~ false"], 'Cannot compare bool with bool')
640  call CheckDefFailure(["let x = true !~ false"], 'Cannot compare bool with bool')
641  call CheckDefFailure(["let x = true is false"], 'Cannot use "is" with bool')
642  call CheckDefFailure(["let x = true isnot false"], 'Cannot use "isnot" with bool')
643
644  call CheckDefFailure(["let x = v:none is v:null"], 'Cannot use "is" with special')
645  call CheckDefFailure(["let x = v:none isnot v:null"], 'Cannot use "isnot" with special')
646  call CheckDefFailure(["let x = 123 is 123"], 'Cannot use "is" with number')
647  call CheckDefFailure(["let x = 123 isnot 123"], 'Cannot use "isnot" with number')
648  if has('float')
649    call CheckDefFailure(["let x = 1.3 is 1.3"], 'Cannot use "is" with float')
650    call CheckDefFailure(["let x = 1.3 isnot 1.3"], 'Cannot use "isnot" with float')
651  endif
652
653  call CheckDefFailure(["let x = 0za1 > 0z34"], 'Cannot compare blob with blob')
654  call CheckDefFailure(["let x = 0za1 >= 0z34"], 'Cannot compare blob with blob')
655  call CheckDefFailure(["let x = 0za1 < 0z34"], 'Cannot compare blob with blob')
656  call CheckDefFailure(["let x = 0za1 <= 0z34"], 'Cannot compare blob with blob')
657  call CheckDefFailure(["let x = 0za1 =~ 0z34"], 'Cannot compare blob with blob')
658  call CheckDefFailure(["let x = 0za1 !~ 0z34"], 'Cannot compare blob with blob')
659
660  call CheckDefFailure(["let x = [13] > [88]"], 'Cannot compare list with list')
661  call CheckDefFailure(["let x = [13] >= [88]"], 'Cannot compare list with list')
662  call CheckDefFailure(["let x = [13] < [88]"], 'Cannot compare list with list')
663  call CheckDefFailure(["let x = [13] <= [88]"], 'Cannot compare list with list')
664  call CheckDefFailure(["let x = [13] =~ [88]"], 'Cannot compare list with list')
665  call CheckDefFailure(["let x = [13] !~ [88]"], 'Cannot compare list with list')
666
667  call CheckDefFailure(['let j: job', 'let chan: channel', 'let r = j == chan'], 'Cannot compare job with channel')
668  call CheckDefFailure(['let j: job', 'let x: list<any>', 'let r = j == x'], 'Cannot compare job with list')
669  call CheckDefFailure(['let j: job', 'let Xx: func', 'let r = j == Xx'], 'Cannot compare job with func')
670  call CheckDefFailure(['let j: job', 'let Xx: func', 'let r = j == Xx'], 'Cannot compare job with func')
671endfunc
672
673" test addition, subtraction, concatenation
674def Test_expr5()
675  assert_equal(66, 60 + 6)
676  assert_equal(70, 60 +
677			g:anint)
678  assert_equal(9, g:alsoint
679  			+ 5)
680  assert_equal(14, g:alsoint + g:anint)
681  assert_equal([1, 2, 3, 4], [1] + g:alist)
682
683  assert_equal(54, 60 - 6)
684  assert_equal(50, 60 -
685		    g:anint)
686  assert_equal(-1, g:alsoint
687  			- 5)
688  assert_equal(-6, g:alsoint - g:anint)
689
690  assert_equal('hello', 'hel' .. 'lo')
691  assert_equal('hello 123', 'hello ' ..
692					123)
693  assert_equal('hello 123', 'hello '
694  				..  123)
695  assert_equal('123 hello', 123 .. ' hello')
696  assert_equal('123456', 123 .. 456)
697
698  assert_equal([1, 2, 3, 4], [1, 2] + [3, 4])
699  assert_equal(0z11223344, 0z1122 + 0z3344)
700  assert_equal(0z112201ab, 0z1122
701  				+ g:ablob)
702  assert_equal(0z01ab3344, g:ablob + 0z3344)
703  assert_equal(0z01ab01ab, g:ablob + g:ablob)
704enddef
705
706def Test_expr5_vim9script()
707  " only checks line continuation
708  let lines =<< trim END
709      vim9script
710      let var = 11
711      		+ 77
712		- 22
713      assert_equal(66, var)
714  END
715  CheckScriptSuccess(lines)
716
717  lines =<< trim END
718      vim9script
719      let var = 'one'
720      		.. 'two'
721      assert_equal('onetwo', var)
722  END
723  CheckScriptSuccess(lines)
724enddef
725
726def Test_expr5_float()
727  if !has('float')
728    MissingFeature 'float'
729  else
730    assert_equal(66.0, 60.0 + 6.0)
731    assert_equal(66.0, 60.0 + 6)
732    assert_equal(66.0, 60 +
733			 6.0)
734    assert_equal(5.1, g:afloat
735    			+ 5)
736    assert_equal(8.1, 8 + g:afloat)
737    assert_equal(10.1, g:anint + g:afloat)
738    assert_equal(10.1, g:afloat + g:anint)
739
740    assert_equal(54.0, 60.0 - 6.0)
741    assert_equal(54.0, 60.0
742    			    - 6)
743    assert_equal(54.0, 60 - 6.0)
744    assert_equal(-4.9, g:afloat - 5)
745    assert_equal(7.9, 8 - g:afloat)
746    assert_equal(9.9, g:anint - g:afloat)
747    assert_equal(-9.9, g:afloat - g:anint)
748  endif
749enddef
750
751func Test_expr5_fails()
752  let msg = "white space required before and after '+'"
753  call CheckDefFailure(["let x = 1+2"], msg)
754  call CheckDefFailure(["let x = 1 +2"], msg)
755  call CheckDefFailure(["let x = 1+ 2"], msg)
756
757  let msg = "white space required before and after '-'"
758  call CheckDefFailure(["let x = 1-2"], msg)
759  call CheckDefFailure(["let x = 1 -2"], msg)
760  call CheckDefFailure(["let x = 1- 2"], msg)
761
762  let msg = "white space required before and after '..'"
763  call CheckDefFailure(["let x = '1'..'2'"], msg)
764  call CheckDefFailure(["let x = '1' ..'2'"], msg)
765  call CheckDefFailure(["let x = '1'.. '2'"], msg)
766
767  call CheckDefFailure(["let x = 0z1122 + 33"], 'E1051')
768  call CheckDefFailure(["let x = 0z1122 + [3]"], 'E1051')
769  call CheckDefFailure(["let x = 0z1122 + 'asd'"], 'E1051')
770  call CheckDefFailure(["let x = 33 + 0z1122"], 'E1051')
771  call CheckDefFailure(["let x = [3] + 0z1122"], 'E1051')
772  call CheckDefFailure(["let x = 'asdf' + 0z1122"], 'E1051')
773  call CheckDefFailure(["let x = 6 + xxx"], 'E1001')
774endfunc
775
776" test multiply, divide, modulo
777def Test_expr6()
778  assert_equal(36, 6 * 6)
779  assert_equal(24, 6 *
780			g:alsoint)
781  assert_equal(24, g:alsoint
782  			* 6)
783  assert_equal(40, g:anint * g:alsoint)
784
785  assert_equal(10, 60 / 6)
786  assert_equal(6, 60 /
787			g:anint)
788  assert_equal(1, g:anint / 6)
789  assert_equal(2, g:anint
790  			/ g:alsoint)
791
792  assert_equal(5, 11 % 6)
793  assert_equal(4, g:anint % 6)
794  assert_equal(3, 13 %
795			g:anint)
796  assert_equal(2, g:anint
797  			% g:alsoint)
798
799  assert_equal(4, 6 * 4 / 6)
800
801  let x = [2]
802  let y = [3]
803  assert_equal(5, x[0] + y[0])
804  assert_equal(6, x[0] * y[0])
805  if has('float')
806    let xf = [2.0]
807    let yf = [3.0]
808    assert_equal(5.0, xf[0]
809    			+ yf[0])
810    assert_equal(6.0, xf[0]
811    			* yf[0])
812  endif
813
814  call CheckDefFailure(["let x = 6 * xxx"], 'E1001')
815enddef
816
817def Test_expr6_vim9script()
818  " only checks line continuation
819  let lines =<< trim END
820      vim9script
821      let var = 11
822      		* 22
823		/ 3
824      assert_equal(80, var)
825  END
826  CheckScriptSuccess(lines)
827
828  lines =<< trim END
829      vim9script
830      let var = 25
831      		% 10
832      assert_equal(5, var)
833  END
834  CheckScriptSuccess(lines)
835enddef
836
837def Test_expr6_float()
838  if !has('float')
839    MissingFeature 'float'
840  else
841    assert_equal(36.0, 6.0 * 6)
842    assert_equal(36.0, 6 *
843			   6.0)
844    assert_equal(36.0, 6.0 * 6.0)
845    assert_equal(1.0, g:afloat * g:anint)
846
847    assert_equal(10.0, 60 / 6.0)
848    assert_equal(10.0, 60.0 /
849			6)
850    assert_equal(10.0, 60.0 / 6.0)
851    assert_equal(0.01, g:afloat / g:anint)
852
853    assert_equal(4.0, 6.0 * 4 / 6)
854    assert_equal(4.0, 6 *
855			4.0 /
856			6)
857    assert_equal(4.0, 6 * 4 / 6.0)
858    assert_equal(4.0, 6.0 * 4.0 / 6)
859    assert_equal(4.0, 6 * 4.0 / 6.0)
860    assert_equal(4.0, 6.0 * 4 / 6.0)
861    assert_equal(4.0, 6.0 * 4.0 / 6.0)
862
863    assert_equal(4.0, 6.0 * 4.0 / 6.0)
864  endif
865enddef
866
867func Test_expr6_fails()
868  let msg = "white space required before and after '*'"
869  call CheckDefFailure(["let x = 1*2"], msg)
870  call CheckDefFailure(["let x = 1 *2"], msg)
871  call CheckDefFailure(["let x = 1* 2"], msg)
872
873  let msg = "white space required before and after '/'"
874  call CheckDefFailure(["let x = 1/2"], msg)
875  call CheckDefFailure(["let x = 1 /2"], msg)
876  call CheckDefFailure(["let x = 1/ 2"], msg)
877
878  let msg = "white space required before and after '%'"
879  call CheckDefFailure(["let x = 1%2"], msg)
880  call CheckDefFailure(["let x = 1 %2"], msg)
881  call CheckDefFailure(["let x = 1% 2"], msg)
882
883  call CheckDefFailure(["let x = '1' * '2'"], 'E1036:')
884  call CheckDefFailure(["let x = '1' / '2'"], 'E1036:')
885  call CheckDefFailure(["let x = '1' % '2'"], 'E1035:')
886
887  call CheckDefFailure(["let x = 0z01 * 0z12"], 'E1036:')
888  call CheckDefFailure(["let x = 0z01 / 0z12"], 'E1036:')
889  call CheckDefFailure(["let x = 0z01 % 0z12"], 'E1035:')
890
891  call CheckDefFailure(["let x = [1] * [2]"], 'E1036:')
892  call CheckDefFailure(["let x = [1] / [2]"], 'E1036:')
893  call CheckDefFailure(["let x = [1] % [2]"], 'E1035:')
894
895  call CheckDefFailure(["let x = #{one: 1} * #{two: 2}"], 'E1036:')
896  call CheckDefFailure(["let x = #{one: 1} / #{two: 2}"], 'E1036:')
897  call CheckDefFailure(["let x = #{one: 1} % #{two: 2}"], 'E1035:')
898
899  call CheckDefFailure(["let x = 0xff[1]"], 'E1090:')
900  if has('float')
901    call CheckDefFailure(["let x = 0.7[1]"], 'E1090:')
902  endif
903endfunc
904
905func Test_expr6_float_fails()
906  CheckFeature float
907  call CheckDefFailure(["let x = 1.0 % 2"], 'E1035:')
908endfunc
909
910" define here to use old style parsing
911if has('float')
912  let g:float_zero = 0.0
913  let g:float_neg = -9.8
914  let g:float_big = 9.9e99
915endif
916let g:blob_empty = 0z
917let g:blob_one = 0z01
918let g:blob_long = 0z0102.0304
919
920let g:string_empty = ''
921let g:string_short = 'x'
922let g:string_long = 'abcdefghijklm'
923let g:string_special = "ab\ncd\ref\ekk"
924
925let g:special_true = v:true
926let g:special_false = v:false
927let g:special_null = v:null
928let g:special_none = v:none
929
930let g:list_empty = []
931let g:list_mixed = [1, 'b', v:false]
932
933let g:dict_empty = {}
934let g:dict_one = #{one: 1}
935
936let $TESTVAR = 'testvar'
937
938" test low level expression
939def Test_expr7_number()
940  " number constant
941  assert_equal(0, 0)
942  assert_equal(654, 0654)
943
944  assert_equal(6, 0x6)
945  assert_equal(15, 0xf)
946  assert_equal(255, 0xff)
947enddef
948
949def Test_expr7_float()
950  " float constant
951  if !has('float')
952    MissingFeature 'float'
953  else
954    assert_equal(g:float_zero, .0)
955    assert_equal(g:float_zero, 0.0)
956    assert_equal(g:float_neg, -9.8)
957    assert_equal(g:float_big, 9.9e99)
958  endif
959enddef
960
961def Test_expr7_blob()
962  " blob constant
963  assert_equal(g:blob_empty, 0z)
964  assert_equal(g:blob_one, 0z01)
965  assert_equal(g:blob_long, 0z0102.0304)
966
967  call CheckDefFailure(["let x = 0z123"], 'E973:')
968enddef
969
970def Test_expr7_string()
971  " string constant
972  assert_equal(g:string_empty, '')
973  assert_equal(g:string_empty, "")
974  assert_equal(g:string_short, 'x')
975  assert_equal(g:string_short, "x")
976  assert_equal(g:string_long, 'abcdefghijklm')
977  assert_equal(g:string_long, "abcdefghijklm")
978  assert_equal(g:string_special, "ab\ncd\ref\ekk")
979
980  call CheckDefFailure(['let x = "abc'], 'E114:')
981  call CheckDefFailure(["let x = 'abc"], 'E115:')
982enddef
983
984def Test_expr7_vimvar()
985  let old: list<string> = v:oldfiles
986  let compl: dict<any> = v:completed_item
987
988  call CheckDefFailure(["let old: list<number> = v:oldfiles"], 'E1013: type mismatch, expected list<number> but got list<string>')
989  call CheckDefFailure(["let old: dict<number> = v:completed_item"], 'E1013: type mismatch, expected dict<number> but got dict<any>')
990enddef
991
992def Test_expr7_special()
993  " special constant
994  assert_equal(g:special_true, true)
995  assert_equal(g:special_false, false)
996  assert_equal(g:special_true, v:true)
997  assert_equal(g:special_false, v:false)
998  assert_equal(g:special_null, v:null)
999  assert_equal(g:special_none, v:none)
1000
1001  call CheckDefFailure(['v:true = true'], 'E46:')
1002  call CheckDefFailure(['v:true = false'], 'E46:')
1003  call CheckDefFailure(['v:false = true'], 'E46:')
1004  call CheckDefFailure(['v:null = 11'], 'E46:')
1005  call CheckDefFailure(['v:none = 22'], 'E46:')
1006enddef
1007
1008def Test_expr7_list()
1009  " list
1010  assert_equal(g:list_empty, [])
1011  assert_equal(g:list_empty, [  ])
1012  assert_equal(g:list_mixed, [1, 'b', false,])
1013  assert_equal('b', g:list_mixed[1])
1014
1015  call CheckDefExecFailure(["let x = g:anint[3]"], 'E714:')
1016  call CheckDefFailure(["let x = g:list_mixed[xxx]"], 'E1001:')
1017  call CheckDefFailure(["let x = [1,2,3]"], 'E1069:')
1018  call CheckDefExecFailure(["let x = g:list_mixed['xx']"], 'E39:')
1019  call CheckDefFailure(["let x = g:list_mixed[0"], 'E111:')
1020  call CheckDefExecFailure(["let x = g:list_empty[3]"], 'E684:')
1021enddef
1022
1023def Test_expr7_list_vim9script()
1024  let lines =<< trim END
1025      vim9script
1026      let l = [
1027		11,
1028		22,
1029		]
1030      assert_equal([11, 22], l)
1031  END
1032  CheckScriptSuccess(lines)
1033
1034  lines =<< trim END
1035      vim9script
1036      let l = [11,
1037		22]
1038      assert_equal([11, 22], l)
1039  END
1040  CheckScriptSuccess(lines)
1041
1042  lines =<< trim END
1043      vim9script
1044      let l = [11,22]
1045  END
1046  CheckScriptFailure(lines, 'E1069:')
1047enddef
1048
1049def Test_expr7_lambda()
1050  " lambda
1051  let La = { -> 'result'}
1052  assert_equal('result', La())
1053  assert_equal([1, 3, 5], [1, 2, 3]->map({key, val -> key + val}))
1054enddef
1055
1056def Test_expr7_lambda_vim9script()
1057  let lines =<< trim END
1058      vim9script
1059      let v = 10->{a ->
1060	    a
1061	      + 2
1062	  }()
1063      assert_equal(12, v)
1064  END
1065  CheckScriptSuccess(lines)
1066enddef
1067
1068def Test_expr7_dict()
1069  " dictionary
1070  assert_equal(g:dict_empty, {})
1071  assert_equal(g:dict_empty, {  })
1072  assert_equal(g:dict_one, {'one': 1})
1073  let key = 'one'
1074  let val = 1
1075  assert_equal(g:dict_one, {key: val})
1076
1077  call CheckDefFailure(["let x = #{8: 8}"], 'E1014:')
1078  call CheckDefFailure(["let x = #{xxx}"], 'E720:')
1079  call CheckDefFailure(["let x = #{xxx: 1", "let y = 2"], 'E722:')
1080  call CheckDefFailure(["let x = #{xxx: 1,"], 'E723:')
1081  call CheckDefFailure(["let x = {'a': xxx}"], 'E1001:')
1082  call CheckDefFailure(["let x = {xxx: 8}"], 'E1001:')
1083  call CheckDefFailure(["let x = #{a: 1, a: 2}"], 'E721:')
1084  call CheckDefFailure(["let x = #"], 'E1015:')
1085  call CheckDefFailure(["let x += 1"], 'E1020:')
1086  call CheckDefFailure(["let x = x + 1"], 'E1001:')
1087  call CheckDefExecFailure(["let x = g:anint.member"], 'E715:')
1088  call CheckDefExecFailure(["let x = g:dict_empty.member"], 'E716:')
1089enddef
1090
1091def Test_expr7_dict_vim9script()
1092  let lines =<< trim END
1093      vim9script
1094      let d = {
1095		'one':
1096		   1,
1097		'two': 2,
1098		   }
1099      assert_equal({'one': 1, 'two': 2}, d)
1100  END
1101  CheckScriptSuccess(lines)
1102
1103  lines =<< trim END
1104      vim9script
1105      let d = { "one": "one", "two": "two", }
1106      assert_equal({'one': 'one', 'two': 'two'}, d)
1107  END
1108  CheckScriptSuccess(lines)
1109
1110  lines =<< trim END
1111      vim9script
1112      let d = #{one: 1,
1113		two: 2,
1114	       }
1115      assert_equal({'one': 1, 'two': 2}, d)
1116  END
1117  CheckScriptSuccess(lines)
1118
1119  lines =<< trim END
1120      vim9script
1121      let d = #{one:1, two: 2}
1122  END
1123  CheckScriptFailure(lines, 'E1069:')
1124
1125  lines =<< trim END
1126      vim9script
1127      let d = #{one: 1,two: 2}
1128  END
1129  CheckScriptFailure(lines, 'E1069:')
1130enddef
1131
1132let g:oneString = 'one'
1133
1134def Test_expr_member()
1135  assert_equal(1, g:dict_one.one)
1136  let d: dict<number> = g:dict_one
1137  assert_equal(1, d['one'])
1138
1139  # getting the one member should clear the dict after getting the item
1140  assert_equal('one', #{one: 'one'}.one)
1141  assert_equal('one', #{one: 'one'}[g:oneString])
1142
1143  call CheckDefFailure(["let x = g:dict_one.#$!"], 'E1002:')
1144  call CheckDefExecFailure(["let d: dict<any>", "echo d['a']"], 'E716:')
1145  call CheckDefExecFailure(["let d: dict<number>", "d = g:list_empty"], 'E1029: Expected dict but got list')
1146enddef
1147
1148def Test_expr_index()
1149  # getting the one member should clear the list only after getting the item
1150  assert_equal('bbb', ['aaa', 'bbb', 'ccc'][1])
1151enddef
1152
1153def Test_expr_member_vim9script()
1154  let lines =<< trim END
1155      vim9script
1156      let d = #{one:
1157      		'one',
1158		two: 'two'}
1159      assert_equal('one', d.one)
1160      assert_equal('one', d
1161                            .one)
1162      assert_equal('one', d[
1163			    'one'
1164			    ])
1165  END
1166  CheckScriptSuccess(lines)
1167
1168  lines =<< trim END
1169      vim9script
1170      let l = [1,
1171		  2,
1172		  3, 4
1173		  ]
1174      assert_equal(2, l[
1175			    1
1176			    ])
1177      assert_equal([2, 3], l[1 : 2])
1178      assert_equal([1, 2, 3], l[
1179				:
1180				2
1181				])
1182      assert_equal([3, 4], l[
1183				2
1184				:
1185				])
1186  END
1187  CheckScriptSuccess(lines)
1188enddef
1189
1190def Test_expr7_option()
1191  " option
1192  set ts=11
1193  assert_equal(11, &ts)
1194  &ts = 9
1195  assert_equal(9, &ts)
1196  set ts=8
1197  set grepprg=some\ text
1198  assert_equal('some text', &grepprg)
1199  &grepprg = test_null_string()
1200  assert_equal('', &grepprg)
1201  set grepprg&
1202enddef
1203
1204def Test_expr7_environment()
1205  " environment variable
1206  assert_equal('testvar', $TESTVAR)
1207  assert_equal('', $ASDF_ASD_XXX)
1208
1209  call CheckDefFailure(["let x = $$$"], 'E1002:')
1210enddef
1211
1212def Test_expr7_register()
1213  @a = 'register a'
1214  assert_equal('register a', @a)
1215enddef
1216
1217def Test_expr7_parens()
1218  " (expr)
1219  assert_equal(4, (6 * 4) / 6)
1220  assert_equal(0, 6 * ( 4 / 6 ))
1221
1222  assert_equal(6, +6)
1223  assert_equal(-6, -6)
1224  assert_equal(6, --6)
1225  assert_equal(6, -+-6)
1226  assert_equal(-6, ---6)
1227  assert_equal(false, !-3)
1228  assert_equal(true, !+-+0)
1229enddef
1230
1231def Test_expr7_parens_vim9script()
1232  let lines =<< trim END
1233      vim9script
1234      let s = (
1235		'one'
1236		..
1237		'two'
1238		)
1239      assert_equal('onetwo', s)
1240  END
1241  CheckScriptSuccess(lines)
1242enddef
1243
1244def Test_expr7_negate()
1245  assert_equal(-99, -99)
1246  assert_equal(99, --99)
1247  let nr = 88
1248  assert_equal(-88, -nr)
1249  assert_equal(88, --nr)
1250enddef
1251
1252def Echo(arg: any): string
1253  return arg
1254enddef
1255
1256def s:EchoArg(arg: any): string
1257  return arg
1258enddef
1259
1260def Test_expr7_call()
1261  assert_equal('yes', 'yes'->Echo())
1262  assert_equal('yes', 'yes'->s:EchoArg())
1263  assert_equal(1, !range(5)->empty())
1264  assert_equal([0, 1, 2], --3->range())
1265
1266  call CheckDefFailure(["let x = 'yes'->Echo"], 'E107:')
1267enddef
1268
1269
1270def Test_expr7_not()
1271  assert_equal(true, !'')
1272  assert_equal(true, ![])
1273  assert_equal(false, !'asdf')
1274  assert_equal(false, ![2])
1275  assert_equal(true, !!'asdf')
1276  assert_equal(true, !![2])
1277
1278  assert_equal(true, !test_null_partial())
1279  assert_equal(false, !{-> 'yes'})
1280
1281  assert_equal(true, !test_null_dict())
1282  assert_equal(true, !{})
1283  assert_equal(false, !{'yes': 'no'})
1284
1285  if has('channel')
1286    assert_equal(true, !test_null_job())
1287    assert_equal(true, !test_null_channel())
1288  endif
1289
1290  assert_equal(true, !test_null_blob())
1291  assert_equal(true, !0z)
1292  assert_equal(false, !0z01)
1293
1294  assert_equal(true, !test_void())
1295  assert_equal(true, !test_unknown())
1296enddef
1297
1298func Test_expr7_fails()
1299  call CheckDefFailure(["let x = (12"], "E110:")
1300
1301  call CheckDefFailure(["let x = -'xx'"], "E1030:")
1302  call CheckDefFailure(["let x = +'xx'"], "E1030:")
1303  call CheckDefFailure(["let x = -0z12"], "E974:")
1304  call CheckDefExecFailure(["let x = -[8]"], "E39:")
1305  call CheckDefExecFailure(["let x = -{'a': 1}"], "E39:")
1306
1307  call CheckDefFailure(["let x = @"], "E1002:")
1308  call CheckDefFailure(["let x = @<"], "E354:")
1309
1310  call CheckDefFailure(["let x = [1, 2"], "E697:")
1311  call CheckDefFailure(["let x = [notfound]"], "E1001:")
1312
1313  call CheckDefFailure(["let x = { -> 123) }"], "E451:")
1314  call CheckDefFailure(["let x = 123->{x -> x + 5) }"], "E451:")
1315
1316  call CheckDefFailure(["let x = &notexist"], 'E113:')
1317  call CheckDefFailure(["&grepprg = [343]"], 'E1013:')
1318
1319  call CheckDefExecFailure(["echo s:doesnt_exist"], 'E121:')
1320  call CheckDefExecFailure(["echo g:doesnt_exist"], 'E121:')
1321
1322  call CheckDefFailure(["echo a:somevar"], 'E1075:')
1323  call CheckDefFailure(["echo l:somevar"], 'E1075:')
1324  call CheckDefFailure(["echo x:somevar"], 'E1075:')
1325
1326  call CheckDefExecFailure(["let x = +g:astring"], 'E1030:')
1327  call CheckDefExecFailure(["let x = +g:ablob"], 'E974:')
1328  call CheckDefExecFailure(["let x = +g:alist"], 'E745:')
1329  call CheckDefExecFailure(["let x = +g:adict"], 'E728:')
1330
1331  call CheckDefFailure(["let x = ''", "let y = x.memb"], 'E715:')
1332
1333  call CheckDefExecFailure(["[1, 2->len()"], 'E697:')
1334  call CheckDefExecFailure(["#{a: 1->len()"], 'E488:')
1335  call CheckDefExecFailure(["{'a': 1->len()"], 'E723:')
1336endfunc
1337
1338let g:Funcrefs = [function('add')]
1339
1340func CallMe(arg)
1341  return a:arg
1342endfunc
1343
1344func CallMe2(one, two)
1345  return a:one .. a:two
1346endfunc
1347
1348def Test_expr7_trailing()
1349  " user function call
1350  assert_equal(123, g:CallMe(123))
1351  assert_equal(123, g:CallMe(  123))
1352  assert_equal(123, g:CallMe(123  ))
1353  assert_equal('yesno', g:CallMe2('yes', 'no'))
1354  assert_equal('yesno', g:CallMe2( 'yes', 'no' ))
1355  assert_equal('nothing', g:CallMe('nothing'))
1356
1357  " partial call
1358  let Part = function('g:CallMe')
1359  assert_equal('yes', Part('yes'))
1360
1361  " funcref call, using list index
1362  let l = []
1363  g:Funcrefs[0](l, 2)
1364  assert_equal([2], l)
1365
1366  " method call
1367  l = [2, 5, 6]
1368  l->map({k, v -> k + v})
1369  assert_equal([2, 6, 8], l)
1370
1371  " lambda method call
1372  l = [2, 5]
1373  l->{l -> add(l, 8)}()
1374  assert_equal([2, 5, 8], l)
1375
1376  " dict member
1377  let d = #{key: 123}
1378  assert_equal(123, d.key)
1379enddef
1380
1381def Test_expr7_subscript_linebreak()
1382  let range = range(
1383  		3)
1384  let l = range->
1385  	map('string(v:key)')
1386  assert_equal(['0', '1', '2'], l)
1387
1388  l = range
1389  	->map('string(v:key)')
1390  assert_equal(['0', '1', '2'], l)
1391
1392  l = range # comment
1393  	->map('string(v:key)')
1394  assert_equal(['0', '1', '2'], l)
1395
1396  l = range
1397
1398  	->map('string(v:key)')
1399  assert_equal(['0', '1', '2'], l)
1400
1401  l = range
1402	# comment
1403  	->map('string(v:key)')
1404  assert_equal(['0', '1', '2'], l)
1405
1406  assert_equal('1', l[
1407	1])
1408
1409  let d = #{one: 33}
1410  assert_equal(33, d.
1411	one)
1412enddef
1413
1414def Test_expr7_method_call()
1415  new
1416  setline(1, ['first', 'last'])
1417  eval 'second'->append(1)
1418  assert_equal(['first', 'second', 'last'], getline(1, '$'))
1419  bwipe!
1420
1421  let bufnr = bufnr()
1422  let loclist = [#{bufnr: bufnr, lnum: 42, col: 17, text: 'wrong'}]
1423  loclist->setloclist(0)
1424  assert_equal([#{bufnr: bufnr,
1425  		lnum: 42,
1426		col: 17,
1427		text: 'wrong',
1428		pattern: '',
1429		valid: 1,
1430		vcol: 0,
1431		nr: 0,
1432		type: '',
1433		module: ''}
1434		], getloclist(0))
1435enddef
1436
1437func Test_expr7_trailing_fails()
1438  call CheckDefFailure(['let l = [2]', 'l->{l -> add(l, 8)}'], 'E107')
1439  call CheckDefFailure(['let l = [2]', 'l->{l -> add(l, 8)} ()'], 'E274')
1440endfunc
1441
1442func Test_expr_fails()
1443  call CheckDefFailure(["let x = '1'is2"], 'E488:')
1444  call CheckDefFailure(["let x = '1'isnot2"], 'E488:')
1445
1446  call CheckDefFailure(["CallMe ('yes')"], 'E476:')
1447  call CheckDefFailure(["CallMe2('yes','no')"], 'E1069:')
1448  call CheckDefFailure(["CallMe2('yes' , 'no')"], 'E1068:')
1449
1450  call CheckDefFailure(["v:nosuch += 3"], 'E1001:')
1451  call CheckDefFailure(["let v:statusmsg = ''"], 'E1016: Cannot declare a v: variable:')
1452  call CheckDefFailure(["let asdf = v:nosuch"], 'E1001:')
1453
1454  call CheckDefFailure(["echo len('asdf'"], 'E110:')
1455  call CheckDefFailure(["echo Func0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789()"], 'E1011:')
1456  call CheckDefFailure(["echo doesnotexist()"], 'E117:')
1457endfunc
1458