annotate src/testdir/test_vim9_assign.vim @ 26346:8be6413a8e27 v8.2.3704

patch 8.2.3704: Vim9: cannot use a list declaration in a :def function Commit: https://github.com/vim/vim/commit/ab36e6ae7b87b0295fb19270e4339a734875c6b1 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Nov 30 16:14:49 2021 +0000 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function Problem: Vim9: cannot use a list declaration in a :def function. Solution: Make it work.
author Bram Moolenaar <Bram@vim.org>
date Tue, 30 Nov 2021 17:15:03 +0100
parents 55e658312376
children f5727e2603f0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Test Vim9 assignments
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 source check.vim
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 source vim9.vim
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 let s:appendToMe = 'xxx'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 let s:addToMe = 111
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 let g:existing = 'yes'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 let g:inc_counter = 1
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 let $SOME_ENV_VAR = 'some'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 let g:alist = [7]
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
12 let g:adict = #{a: 1}
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 let g:astring = 'text'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 def Test_assignment_bool()
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
16 var bool1: bool = true
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 assert_equal(v:true, bool1)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
18 var bool2: bool = false
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 assert_equal(v:false, bool2)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
21 var bool3: bool = 0
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 assert_equal(false, bool3)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
23 var bool4: bool = 1
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 assert_equal(true, bool4)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22458
diff changeset
26 var bool5: bool = 1 && true
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 assert_equal(true, bool5)
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22458
diff changeset
28 var bool6: bool = 0 && 1
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 assert_equal(false, bool6)
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22458
diff changeset
30 var bool7: bool = 0 || 1 && true
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 assert_equal(true, bool7)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
33 var lines =<< trim END
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 vim9script
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 def GetFlag(): bool
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
36 var flag: bool = 1
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 return flag
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 enddef
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
39 var flag: bool = GetFlag()
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 assert_equal(true, flag)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 flag = 0
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 assert_equal(false, flag)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 flag = 1
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 assert_equal(true, flag)
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22458
diff changeset
45 flag = 1 || true
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 assert_equal(true, flag)
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22458
diff changeset
47 flag = 1 && false
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 assert_equal(false, flag)
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
49
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
50 var cp: bool = &cp
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
51 var fen: bool = &l:fen
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 CheckScriptSuccess(lines)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
54 CheckDefAndScriptFailure(['var x: bool = 2'], 'E1012:')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
55 CheckDefAndScriptFailure(['var x: bool = -1'], 'E1012:')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
56 CheckDefAndScriptFailure(['var x: bool = [1]'], 'E1012:')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
57 CheckDefAndScriptFailure(['var x: bool = {}'], 'E1012:')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
58 CheckDefAndScriptFailure(['var x: bool = "x"'], 'E1012:')
23707
6e8a4a30d94d patch 8.2.2395: Vim9: error for wrong type may report wrong line number
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
59
6e8a4a30d94d patch 8.2.2395: Vim9: error for wrong type may report wrong line number
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
60 CheckDefAndScriptFailure(['var x: bool = "x"', '', 'eval 0'], 'E1012:', 1)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 def Test_syntax()
22433
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
64 var name = 234
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
65 var other: list<string> = ['asdf']
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 def Test_assignment()
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
69 CheckDefFailure(['var x:string'], 'E1069:')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
70 CheckDefFailure(['var x:string = "x"'], 'E1069:')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
71 CheckDefFailure(['var a:string = "x"'], 'E1069:')
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
72 CheckDefFailure(['var lambda = () => "lambda"'], 'E704:')
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
73 CheckScriptFailure(['var x = "x"'], 'E1124:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74
24154
6e8f49a4a193 patch 8.2.2618: Vim9: cannot use a normal list name to store function refs
Bram Moolenaar <Bram@vim.org>
parents: 24047
diff changeset
75 # lower case name is OK for a list
6e8f49a4a193 patch 8.2.2618: Vim9: cannot use a normal list name to store function refs
Bram Moolenaar <Bram@vim.org>
parents: 24047
diff changeset
76 var lambdaLines =<< trim END
6e8f49a4a193 patch 8.2.2618: Vim9: cannot use a normal list name to store function refs
Bram Moolenaar <Bram@vim.org>
parents: 24047
diff changeset
77 var lambdaList: list<func> = [Test_syntax]
6e8f49a4a193 patch 8.2.2618: Vim9: cannot use a normal list name to store function refs
Bram Moolenaar <Bram@vim.org>
parents: 24047
diff changeset
78 lambdaList[0] = () => "lambda"
6e8f49a4a193 patch 8.2.2618: Vim9: cannot use a normal list name to store function refs
Bram Moolenaar <Bram@vim.org>
parents: 24047
diff changeset
79 END
6e8f49a4a193 patch 8.2.2618: Vim9: cannot use a normal list name to store function refs
Bram Moolenaar <Bram@vim.org>
parents: 24047
diff changeset
80 CheckDefAndScriptSuccess(lambdaLines)
6e8f49a4a193 patch 8.2.2618: Vim9: cannot use a normal list name to store function refs
Bram Moolenaar <Bram@vim.org>
parents: 24047
diff changeset
81
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
82 var nr: number = 1234
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
83 CheckDefFailure(['var nr: number = "asdf"'], 'E1012:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
85 var a: number = 6 #comment
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 assert_equal(6, a)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 if has('channel')
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
89 var chan1: channel
22618
c2d8b596dd0f patch 8.2.1857: Vim9: using job_status() on an unused var gives an error
Bram Moolenaar <Bram@vim.org>
parents: 22610
diff changeset
90 assert_equal('fail', ch_status(chan1))
c2d8b596dd0f patch 8.2.1857: Vim9: using job_status() on an unused var gives an error
Bram Moolenaar <Bram@vim.org>
parents: 22610
diff changeset
91
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
92 var job1: job
22618
c2d8b596dd0f patch 8.2.1857: Vim9: using job_status() on an unused var gives an error
Bram Moolenaar <Bram@vim.org>
parents: 22610
diff changeset
93 assert_equal('fail', job_status(job1))
c2d8b596dd0f patch 8.2.1857: Vim9: using job_status() on an unused var gives an error
Bram Moolenaar <Bram@vim.org>
parents: 22610
diff changeset
94
22582
a3df1fb28d44 patch 8.2.1839: Vim9: memory leaks reported in assign test
Bram Moolenaar <Bram@vim.org>
parents: 22545
diff changeset
95 # calling job_start() is in test_vim9_fails.vim, it causes leak reports
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 endif
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 if has('float')
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
98 var float1: float = 3.4
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 endif
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
100 var Funky1: func
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
101 var Funky2: func = function('len')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
102 var Party2: func = funcref('g:Test_syntax')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 g:newvar = 'new' #comment
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 assert_equal('new', g:newvar)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 assert_equal('yes', g:existing)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 g:existing = 'no'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 assert_equal('no', g:existing)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 v:char = 'abc'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 assert_equal('abc', v:char)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 $ENVVAR = 'foobar'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 assert_equal('foobar', $ENVVAR)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 $ENVVAR = ''
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
118 var lines =<< trim END
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 vim9script
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 $ENVVAR = 'barfoo'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 assert_equal('barfoo', $ENVVAR)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 $ENVVAR = ''
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 CheckScriptSuccess(lines)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 s:appendToMe ..= 'yyy'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 assert_equal('xxxyyy', s:appendToMe)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 s:addToMe += 222
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 assert_equal(333, s:addToMe)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 s:newVar = 'new'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 assert_equal('new', s:newVar)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 set ts=7
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
134 var ts: number = &ts
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
135 assert_equal(7, ts)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 &ts += 1
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 assert_equal(8, &ts)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 &ts -= 3
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 assert_equal(5, &ts)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 &ts *= 2
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 assert_equal(10, &ts)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 &ts /= 3
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 assert_equal(3, &ts)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 set ts=10
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 &ts %= 4
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 assert_equal(2, &ts)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 if has('float')
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
149 var f100: float = 100.0
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 f100 /= 5
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 assert_equal(20.0, f100)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
153 var f200: float = 200.0
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 f200 /= 5.0
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 assert_equal(40.0, f200)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
157 CheckDefFailure(['var nr: number = 200', 'nr /= 5.0'], 'E1012:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 endif
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 lines =<< trim END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 &ts = 6
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 &ts += 3
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 assert_equal(9, &ts)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 &l:ts = 6
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 assert_equal(6, &ts)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 &l:ts += 2
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 assert_equal(8, &ts)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 &g:ts = 6
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 assert_equal(6, &g:ts)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 &g:ts += 2
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 assert_equal(8, &g:ts)
23509
18f3dc6974af patch 8.2.2297: Vim9: cannot set 'number' to a boolean value
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
174
18f3dc6974af patch 8.2.2297: Vim9: cannot set 'number' to a boolean value
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
175 &number = true
18f3dc6974af patch 8.2.2297: Vim9: cannot set 'number' to a boolean value
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
176 assert_equal(true, &number)
18f3dc6974af patch 8.2.2297: Vim9: cannot set 'number' to a boolean value
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
177 &number = 0
18f3dc6974af patch 8.2.2297: Vim9: cannot set 'number' to a boolean value
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
178 assert_equal(false, &number)
18f3dc6974af patch 8.2.2297: Vim9: cannot set 'number' to a boolean value
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
179 &number = 1
18f3dc6974af patch 8.2.2297: Vim9: cannot set 'number' to a boolean value
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
180 assert_equal(true, &number)
18f3dc6974af patch 8.2.2297: Vim9: cannot set 'number' to a boolean value
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
181 &number = false
18f3dc6974af patch 8.2.2297: Vim9: cannot set 'number' to a boolean value
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
182 assert_equal(false, &number)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 CheckDefAndScriptSuccess(lines)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 CheckDefFailure(['&notex += 3'], 'E113:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 CheckDefFailure(['&ts ..= "xxx"'], 'E1019:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 CheckDefFailure(['&ts = [7]'], 'E1012:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 CheckDefExecFailure(['&ts = g:alist'], 'E1012: Type mismatch; expected number but got list<number>')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 CheckDefFailure(['&ts = "xx"'], 'E1012:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 CheckDefExecFailure(['&ts = g:astring'], 'E1012: Type mismatch; expected number but got string')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 CheckDefFailure(['&path += 3'], 'E1012:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 CheckDefExecFailure(['&bs = "asdf"'], 'E474:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 # test freeing ISN_STOREOPT
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
195 CheckDefFailure(['&ts = 3', 'var asdf'], 'E1022:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 &ts = 8
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 lines =<< trim END
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
199 var save_TI = &t_TI
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 &t_TI = ''
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 assert_equal('', &t_TI)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 &t_TI = 'xxx'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 assert_equal('xxx', &t_TI)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 &t_TI = save_TI
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 CheckDefAndScriptSuccess(lines)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 CheckDefFailure(['&t_TI = 123'], 'E1012:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 CheckScriptFailure(['vim9script', '&t_TI = 123'], 'E928:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
211 CheckDefFailure(['var s:var = 123'], 'E1101:')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
212 CheckDefFailure(['var s:var: number'], 'E1101:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 lines =<< trim END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 vim9script
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 def SomeFunc()
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 s:var = 123
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 defcompile
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 CheckScriptFailure(lines, 'E1089:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 g:inc_counter += 1
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 assert_equal(2, g:inc_counter)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225
25483
0160aff01c32 patch 8.2.3278: Vim9: error when adding 1 to float
Bram Moolenaar <Bram@vim.org>
parents: 25459
diff changeset
226 if has('float')
0160aff01c32 patch 8.2.3278: Vim9: error when adding 1 to float
Bram Moolenaar <Bram@vim.org>
parents: 25459
diff changeset
227 var f: float
0160aff01c32 patch 8.2.3278: Vim9: error when adding 1 to float
Bram Moolenaar <Bram@vim.org>
parents: 25459
diff changeset
228 f += 1
0160aff01c32 patch 8.2.3278: Vim9: error when adding 1 to float
Bram Moolenaar <Bram@vim.org>
parents: 25459
diff changeset
229 assert_equal(1.0, f)
0160aff01c32 patch 8.2.3278: Vim9: error when adding 1 to float
Bram Moolenaar <Bram@vim.org>
parents: 25459
diff changeset
230 endif
0160aff01c32 patch 8.2.3278: Vim9: error when adding 1 to float
Bram Moolenaar <Bram@vim.org>
parents: 25459
diff changeset
231
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 $SOME_ENV_VAR ..= 'more'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 assert_equal('somemore', $SOME_ENV_VAR)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 CheckDefFailure(['$SOME_ENV_VAR += "more"'], 'E1051:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 CheckDefFailure(['$SOME_ENV_VAR += 123'], 'E1012:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 v:errmsg = 'none'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 v:errmsg ..= 'again'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 assert_equal('noneagain', v:errmsg)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 CheckDefFailure(['v:errmsg += "more"'], 'E1051:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 CheckDefFailure(['v:errmsg += 123'], 'E1012:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242
22582
a3df1fb28d44 patch 8.2.1839: Vim9: memory leaks reported in assign test
Bram Moolenaar <Bram@vim.org>
parents: 22545
diff changeset
243 var text =<< trim END
a3df1fb28d44 patch 8.2.1839: Vim9: memory leaks reported in assign test
Bram Moolenaar <Bram@vim.org>
parents: 22545
diff changeset
244 some text
a3df1fb28d44 patch 8.2.1839: Vim9: memory leaks reported in assign test
Bram Moolenaar <Bram@vim.org>
parents: 22545
diff changeset
245 END
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247
25519
f7db86111acd patch 8.2.3296: Vim9: cannot add a number to a float
Bram Moolenaar <Bram@vim.org>
parents: 25489
diff changeset
248 def Test_float_and_number()
f7db86111acd patch 8.2.3296: Vim9: cannot add a number to a float
Bram Moolenaar <Bram@vim.org>
parents: 25489
diff changeset
249 if !has('float')
f7db86111acd patch 8.2.3296: Vim9: cannot add a number to a float
Bram Moolenaar <Bram@vim.org>
parents: 25489
diff changeset
250 MissingFeature float
f7db86111acd patch 8.2.3296: Vim9: cannot add a number to a float
Bram Moolenaar <Bram@vim.org>
parents: 25489
diff changeset
251 else
f7db86111acd patch 8.2.3296: Vim9: cannot add a number to a float
Bram Moolenaar <Bram@vim.org>
parents: 25489
diff changeset
252 var lines =<< trim END
f7db86111acd patch 8.2.3296: Vim9: cannot add a number to a float
Bram Moolenaar <Bram@vim.org>
parents: 25489
diff changeset
253 var f: float
f7db86111acd patch 8.2.3296: Vim9: cannot add a number to a float
Bram Moolenaar <Bram@vim.org>
parents: 25489
diff changeset
254 f += 2
f7db86111acd patch 8.2.3296: Vim9: cannot add a number to a float
Bram Moolenaar <Bram@vim.org>
parents: 25489
diff changeset
255 f -= 1
f7db86111acd patch 8.2.3296: Vim9: cannot add a number to a float
Bram Moolenaar <Bram@vim.org>
parents: 25489
diff changeset
256 assert_equal(1.0, f)
f7db86111acd patch 8.2.3296: Vim9: cannot add a number to a float
Bram Moolenaar <Bram@vim.org>
parents: 25489
diff changeset
257 ++f
f7db86111acd patch 8.2.3296: Vim9: cannot add a number to a float
Bram Moolenaar <Bram@vim.org>
parents: 25489
diff changeset
258 --f
f7db86111acd patch 8.2.3296: Vim9: cannot add a number to a float
Bram Moolenaar <Bram@vim.org>
parents: 25489
diff changeset
259 assert_equal(1.0, f)
f7db86111acd patch 8.2.3296: Vim9: cannot add a number to a float
Bram Moolenaar <Bram@vim.org>
parents: 25489
diff changeset
260 END
f7db86111acd patch 8.2.3296: Vim9: cannot add a number to a float
Bram Moolenaar <Bram@vim.org>
parents: 25489
diff changeset
261 CheckDefAndScriptSuccess(lines)
f7db86111acd patch 8.2.3296: Vim9: cannot add a number to a float
Bram Moolenaar <Bram@vim.org>
parents: 25489
diff changeset
262 endif
f7db86111acd patch 8.2.3296: Vim9: cannot add a number to a float
Bram Moolenaar <Bram@vim.org>
parents: 25489
diff changeset
263 enddef
f7db86111acd patch 8.2.3296: Vim9: cannot add a number to a float
Bram Moolenaar <Bram@vim.org>
parents: 25489
diff changeset
264
25453
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
265 let g:someNumber = 43
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
266
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
267 def Test_assign_concat()
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
268 var lines =<< trim END
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
269 var s = '-'
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
270 s ..= 99
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
271 s ..= true
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
272 s ..= '-'
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
273 s ..= v:null
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
274 s ..= g:someNumber
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
275 assert_equal('-99true-null43', s)
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
276 END
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
277 CheckDefAndScriptSuccess(lines)
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
278
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
279 lines =<< trim END
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
280 var s = '-'
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
281 s ..= [1, 2]
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
282 END
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
283 CheckDefAndScriptFailure2(lines, 'E1105: Cannot convert list to string', 'E734: Wrong variable type for .=', 2)
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
284 lines =<< trim END
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
285 var s = '-'
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
286 s ..= {a: 2}
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
287 END
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
288 CheckDefAndScriptFailure2(lines, 'E1105: Cannot convert dict to string', 'E734: Wrong variable type for .=', 2)
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
289 enddef
21b70bab366c patch 8.2.3263: Vim9: "..=" does not accept same types as the ".." operator
Bram Moolenaar <Bram@vim.org>
parents: 25405
diff changeset
290
25032
123590c942b7 patch 8.2.3053: Vim9: cannot assign to @@ in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25022
diff changeset
291 def Test_assign_register()
123590c942b7 patch 8.2.3053: Vim9: cannot assign to @@ in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25022
diff changeset
292 var lines =<< trim END
123590c942b7 patch 8.2.3053: Vim9: cannot assign to @@ in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25022
diff changeset
293 @c = 'areg'
123590c942b7 patch 8.2.3053: Vim9: cannot assign to @@ in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25022
diff changeset
294 @c ..= 'add'
123590c942b7 patch 8.2.3053: Vim9: cannot assign to @@ in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25022
diff changeset
295 assert_equal('aregadd', @c)
123590c942b7 patch 8.2.3053: Vim9: cannot assign to @@ in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25022
diff changeset
296
123590c942b7 patch 8.2.3053: Vim9: cannot assign to @@ in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25022
diff changeset
297 @@ = 'some text'
123590c942b7 patch 8.2.3053: Vim9: cannot assign to @@ in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25022
diff changeset
298 assert_equal('some text', getreg('"'))
123590c942b7 patch 8.2.3053: Vim9: cannot assign to @@ in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25022
diff changeset
299 END
123590c942b7 patch 8.2.3053: Vim9: cannot assign to @@ in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25022
diff changeset
300 CheckDefAndScriptSuccess(lines)
123590c942b7 patch 8.2.3053: Vim9: cannot assign to @@ in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25022
diff changeset
301
123590c942b7 patch 8.2.3053: Vim9: cannot assign to @@ in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25022
diff changeset
302 CheckDefFailure(['@a += "more"'], 'E1051:')
123590c942b7 patch 8.2.3053: Vim9: cannot assign to @@ in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25022
diff changeset
303 CheckDefFailure(['@a += 123'], 'E1012:')
123590c942b7 patch 8.2.3053: Vim9: cannot assign to @@ in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25022
diff changeset
304 enddef
123590c942b7 patch 8.2.3053: Vim9: cannot assign to @@ in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25022
diff changeset
305
24717
bf8feac8a89a patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24555
diff changeset
306 def Test_reserved_name()
bf8feac8a89a patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24555
diff changeset
307 for name in ['true', 'false', 'null']
bf8feac8a89a patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24555
diff changeset
308 CheckDefExecAndScriptFailure(['var ' .. name .. ' = 0'], 'E1034:')
bf8feac8a89a patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24555
diff changeset
309 CheckDefExecAndScriptFailure(['var ' .. name .. ': bool'], 'E1034:')
bf8feac8a89a patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24555
diff changeset
310 endfor
bf8feac8a89a patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24555
diff changeset
311 enddef
bf8feac8a89a patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24555
diff changeset
312
24462
7c4f50c02e18 patch 8.2.2771: Vim9: assignment not recognized if declaration was skipped
Bram Moolenaar <Bram@vim.org>
parents: 24426
diff changeset
313 def Test_skipped_assignment()
7c4f50c02e18 patch 8.2.2771: Vim9: assignment not recognized if declaration was skipped
Bram Moolenaar <Bram@vim.org>
parents: 24426
diff changeset
314 var lines =<< trim END
7c4f50c02e18 patch 8.2.2771: Vim9: assignment not recognized if declaration was skipped
Bram Moolenaar <Bram@vim.org>
parents: 24426
diff changeset
315 for x in []
7c4f50c02e18 patch 8.2.2771: Vim9: assignment not recognized if declaration was skipped
Bram Moolenaar <Bram@vim.org>
parents: 24426
diff changeset
316 var i: number = 1
7c4f50c02e18 patch 8.2.2771: Vim9: assignment not recognized if declaration was skipped
Bram Moolenaar <Bram@vim.org>
parents: 24426
diff changeset
317 while false
7c4f50c02e18 patch 8.2.2771: Vim9: assignment not recognized if declaration was skipped
Bram Moolenaar <Bram@vim.org>
parents: 24426
diff changeset
318 i += 1
7c4f50c02e18 patch 8.2.2771: Vim9: assignment not recognized if declaration was skipped
Bram Moolenaar <Bram@vim.org>
parents: 24426
diff changeset
319 endwhile
7c4f50c02e18 patch 8.2.2771: Vim9: assignment not recognized if declaration was skipped
Bram Moolenaar <Bram@vim.org>
parents: 24426
diff changeset
320 endfor
7c4f50c02e18 patch 8.2.2771: Vim9: assignment not recognized if declaration was skipped
Bram Moolenaar <Bram@vim.org>
parents: 24426
diff changeset
321 END
7c4f50c02e18 patch 8.2.2771: Vim9: assignment not recognized if declaration was skipped
Bram Moolenaar <Bram@vim.org>
parents: 24426
diff changeset
322 CheckDefAndScriptSuccess(lines)
7c4f50c02e18 patch 8.2.2771: Vim9: assignment not recognized if declaration was skipped
Bram Moolenaar <Bram@vim.org>
parents: 24426
diff changeset
323 enddef
7c4f50c02e18 patch 8.2.2771: Vim9: assignment not recognized if declaration was skipped
Bram Moolenaar <Bram@vim.org>
parents: 24426
diff changeset
324
26302
7351926fbe9e patch 8.2.3682: Vim9: assigning to a script variable drops the type
Bram Moolenaar <Bram@vim.org>
parents: 25776
diff changeset
325 def Test_assign_keep_type()
7351926fbe9e patch 8.2.3682: Vim9: assigning to a script variable drops the type
Bram Moolenaar <Bram@vim.org>
parents: 25776
diff changeset
326 var lines =<< trim END
7351926fbe9e patch 8.2.3682: Vim9: assigning to a script variable drops the type
Bram Moolenaar <Bram@vim.org>
parents: 25776
diff changeset
327 vim9script
7351926fbe9e patch 8.2.3682: Vim9: assigning to a script variable drops the type
Bram Moolenaar <Bram@vim.org>
parents: 25776
diff changeset
328 var l: list<number> = [123]
7351926fbe9e patch 8.2.3682: Vim9: assigning to a script variable drops the type
Bram Moolenaar <Bram@vim.org>
parents: 25776
diff changeset
329 l = [123]
7351926fbe9e patch 8.2.3682: Vim9: assigning to a script variable drops the type
Bram Moolenaar <Bram@vim.org>
parents: 25776
diff changeset
330 l->add('string')
7351926fbe9e patch 8.2.3682: Vim9: assigning to a script variable drops the type
Bram Moolenaar <Bram@vim.org>
parents: 25776
diff changeset
331 END
7351926fbe9e patch 8.2.3682: Vim9: assigning to a script variable drops the type
Bram Moolenaar <Bram@vim.org>
parents: 25776
diff changeset
332 CheckScriptFailure(lines, 'E1012:', 4)
7351926fbe9e patch 8.2.3682: Vim9: assigning to a script variable drops the type
Bram Moolenaar <Bram@vim.org>
parents: 25776
diff changeset
333 enddef
7351926fbe9e patch 8.2.3682: Vim9: assigning to a script variable drops the type
Bram Moolenaar <Bram@vim.org>
parents: 25776
diff changeset
334
23122
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
335 def Test_assign_unpack()
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
336 var lines =<< trim END
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
337 var v1: number
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
338 var v2: number
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
339 [v1, v2] = [1, 2]
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
340 assert_equal(1, v1)
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
341 assert_equal(2, v2)
24426
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24377
diff changeset
342
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24377
diff changeset
343 [v1, _, v2, _] = [1, 99, 2, 77]
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24377
diff changeset
344 assert_equal(1, v1)
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24377
diff changeset
345 assert_equal(2, v2)
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24377
diff changeset
346
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24377
diff changeset
347 [v1, v2; _] = [1, 2, 3, 4, 5]
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24377
diff changeset
348 assert_equal(1, v1)
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24377
diff changeset
349 assert_equal(2, v2)
24984
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
350
25034
8d660d1cca8d patch 8.2.3054: Vim9: unpack assignment using "_" after semicolon fails
Bram Moolenaar <Bram@vim.org>
parents: 25032
diff changeset
351 var reslist = []
8d660d1cca8d patch 8.2.3054: Vim9: unpack assignment using "_" after semicolon fails
Bram Moolenaar <Bram@vim.org>
parents: 25032
diff changeset
352 for text in ['aaa {bbb} ccc', 'ddd {eee} fff']
8d660d1cca8d patch 8.2.3054: Vim9: unpack assignment using "_" after semicolon fails
Bram Moolenaar <Bram@vim.org>
parents: 25032
diff changeset
353 var before: string
8d660d1cca8d patch 8.2.3054: Vim9: unpack assignment using "_" after semicolon fails
Bram Moolenaar <Bram@vim.org>
parents: 25032
diff changeset
354 var middle: string
8d660d1cca8d patch 8.2.3054: Vim9: unpack assignment using "_" after semicolon fails
Bram Moolenaar <Bram@vim.org>
parents: 25032
diff changeset
355 var after: string
8d660d1cca8d patch 8.2.3054: Vim9: unpack assignment using "_" after semicolon fails
Bram Moolenaar <Bram@vim.org>
parents: 25032
diff changeset
356 [_, before, middle, after; _] = text->matchlist('\(.\{-\}\){\(.\{-\}\)}\(.*\)')
8d660d1cca8d patch 8.2.3054: Vim9: unpack assignment using "_" after semicolon fails
Bram Moolenaar <Bram@vim.org>
parents: 25032
diff changeset
357 reslist->add(before)->add(middle)->add(after)
8d660d1cca8d patch 8.2.3054: Vim9: unpack assignment using "_" after semicolon fails
Bram Moolenaar <Bram@vim.org>
parents: 25032
diff changeset
358 endfor
8d660d1cca8d patch 8.2.3054: Vim9: unpack assignment using "_" after semicolon fails
Bram Moolenaar <Bram@vim.org>
parents: 25032
diff changeset
359 assert_equal(['aaa ', 'bbb', ' ccc', 'ddd ', 'eee', ' fff'], reslist)
8d660d1cca8d patch 8.2.3054: Vim9: unpack assignment using "_" after semicolon fails
Bram Moolenaar <Bram@vim.org>
parents: 25032
diff changeset
360
24984
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
361 var a = 1
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
362 var b = 3
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
363 [a, b] += [2, 4]
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
364 assert_equal(3, a)
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
365 assert_equal(7, b)
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
366
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
367 [a, b] -= [1, 2]
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
368 assert_equal(2, a)
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
369 assert_equal(5, b)
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
370
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
371 [a, b] *= [3, 2]
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
372 assert_equal(6, a)
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
373 assert_equal(10, b)
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
374
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
375 [a, b] /= [2, 4]
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
376 assert_equal(3, a)
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
377 assert_equal(2, b)
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
378
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
379 [a, b] = [17, 15]
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
380 [a, b] %= [5, 3]
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
381 assert_equal(2, a)
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
382 assert_equal(0, b)
23122
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
383 END
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
384 CheckDefAndScriptSuccess(lines)
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
385
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
386 lines =<< trim END
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
387 var v1: number
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
388 var v2: number
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
389 [v1, v2] =
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
390 END
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
391 CheckDefFailure(lines, 'E1097:', 5)
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
392
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
393 lines =<< trim END
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
394 var v1: number
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
395 var v2: number
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
396 [v1, v2] = xxx
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
397 END
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
398 CheckDefFailure(lines, 'E1001:', 3)
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
399
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
400 lines =<< trim END
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
401 var v1: number
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
402 var v2: number
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
403 [v1, v2] = popup_clear()
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
404 END
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
405 CheckDefFailure(lines, 'E1031:', 3)
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
406
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
407 lines =<< trim END
23450
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
408 [v1, v2] = [1, 2]
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
409 END
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
410 CheckDefFailure(lines, 'E1089', 1)
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
411 CheckScriptFailure(['vim9script'] + lines, 'E1089', 2)
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
412
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
413 lines =<< trim END
23122
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
414 var v1: number
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
415 var v2: number
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
416 [v1, v2] = ''
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
417 END
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
418 CheckDefFailure(lines, 'E1012: Type mismatch; expected list<any> but got string', 3)
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23707
diff changeset
419
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23707
diff changeset
420 lines =<< trim END
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23707
diff changeset
421 g:values = [false, 0]
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23707
diff changeset
422 var x: bool
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23707
diff changeset
423 var y: string
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23707
diff changeset
424 [x, y] = g:values
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23707
diff changeset
425 END
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23707
diff changeset
426 CheckDefExecAndScriptFailure(lines, 'E1163: Variable 2: type mismatch, expected string but got number')
25547
ec4df0b982da patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents: 25519
diff changeset
427
ec4df0b982da patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents: 25519
diff changeset
428 lines =<< trim END
ec4df0b982da patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents: 25519
diff changeset
429 var x: number
ec4df0b982da patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents: 25519
diff changeset
430 var y: number
ec4df0b982da patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents: 25519
diff changeset
431 var z: string
ec4df0b982da patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents: 25519
diff changeset
432 [x, y, z] = [1, 2, 3]
ec4df0b982da patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents: 25519
diff changeset
433 END
ec4df0b982da patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents: 25519
diff changeset
434 CheckDefAndScriptFailure(lines, 'E1163: Variable 3: type mismatch, expected string but got number')
ec4df0b982da patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents: 25519
diff changeset
435
ec4df0b982da patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents: 25519
diff changeset
436 lines =<< trim END
ec4df0b982da patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents: 25519
diff changeset
437 var x: number
ec4df0b982da patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents: 25519
diff changeset
438 var y: string
ec4df0b982da patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents: 25519
diff changeset
439 var z: string
ec4df0b982da patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents: 25519
diff changeset
440 [x, y, z] = [1, '2', 3]
ec4df0b982da patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents: 25519
diff changeset
441 END
ec4df0b982da patch 8.2.3310: Vim9: unpack assignment does not mention source of type error
Bram Moolenaar <Bram@vim.org>
parents: 25519
diff changeset
442 CheckDefExecAndScriptFailure(lines, 'E1163: Variable 3: type mismatch, expected string but got number')
23122
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
443 enddef
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
444
23070
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
445 def Test_assign_linebreak()
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
446 var nr: number
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
447 nr =
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
448 123
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
449 assert_equal(123, nr)
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
450
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
451 var n2: number
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
452 [nr, n2] =
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
453 [12, 34]
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
454 assert_equal(12, nr)
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
455 assert_equal(34, n2)
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
456
23122
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
457 CheckDefFailure(["var x = #"], 'E1097:', 3)
24329
cd9f77409393 patch 8.2.2705: Vim9: misleading reported line number for wrong type
Bram Moolenaar <Bram@vim.org>
parents: 24325
diff changeset
458
cd9f77409393 patch 8.2.2705: Vim9: misleading reported line number for wrong type
Bram Moolenaar <Bram@vim.org>
parents: 24325
diff changeset
459 var lines =<< trim END
cd9f77409393 patch 8.2.2705: Vim9: misleading reported line number for wrong type
Bram Moolenaar <Bram@vim.org>
parents: 24325
diff changeset
460 var x: list<string> = ['a']
cd9f77409393 patch 8.2.2705: Vim9: misleading reported line number for wrong type
Bram Moolenaar <Bram@vim.org>
parents: 24325
diff changeset
461 var y: list<number> = x
cd9f77409393 patch 8.2.2705: Vim9: misleading reported line number for wrong type
Bram Moolenaar <Bram@vim.org>
parents: 24325
diff changeset
462 ->copy()
cd9f77409393 patch 8.2.2705: Vim9: misleading reported line number for wrong type
Bram Moolenaar <Bram@vim.org>
parents: 24325
diff changeset
463 ->copy()
cd9f77409393 patch 8.2.2705: Vim9: misleading reported line number for wrong type
Bram Moolenaar <Bram@vim.org>
parents: 24325
diff changeset
464 END
cd9f77409393 patch 8.2.2705: Vim9: misleading reported line number for wrong type
Bram Moolenaar <Bram@vim.org>
parents: 24325
diff changeset
465 CheckDefFailure(lines, 'E1012:', 2)
25139
7fa520b85244 patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents: 25137
diff changeset
466
7fa520b85244 patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents: 25137
diff changeset
467 lines =<< trim END
7fa520b85244 patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents: 25137
diff changeset
468 var x: any
7fa520b85244 patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents: 25137
diff changeset
469 x.key = 1
7fa520b85244 patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents: 25137
diff changeset
470 + 2
7fa520b85244 patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents: 25137
diff changeset
471 + 3
7fa520b85244 patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents: 25137
diff changeset
472 + 4
7fa520b85244 patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents: 25137
diff changeset
473 + 5
7fa520b85244 patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents: 25137
diff changeset
474 END
7fa520b85244 patch 8.2.3106: Vim9: confusing line number reported for error
Bram Moolenaar <Bram@vim.org>
parents: 25137
diff changeset
475 CheckDefExecAndScriptFailure2(lines, 'E1148:', 'E1203:', 2)
23070
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
476 enddef
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
477
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
478 def Test_assign_index()
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
479 # list of list
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
480 var l1: list<number>
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
481 l1[0] = 123
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
482 assert_equal([123], l1)
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
483
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
484 var l2: list<list<number>>
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
485 l2[0] = []
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
486 l2[0][0] = 123
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
487 assert_equal([[123]], l2)
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
488
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
489 var l3: list<list<list<number>>>
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
490 l3[0] = []
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
491 l3[0][0] = []
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
492 l3[0][0][0] = 123
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
493 assert_equal([[[123]]], l3)
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
494
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
495 var lines =<< trim END
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
496 var l3: list<list<number>>
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
497 l3[0] = []
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
498 l3[0][0] = []
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
499 END
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
500 CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 3)
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
501
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
502 # dict of dict
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
503 var d1: dict<number>
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
504 d1.one = 1
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
505 assert_equal({one: 1}, d1)
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
506
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
507 var d2: dict<dict<number>>
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
508 d2.one = {}
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
509 d2.one.two = 123
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
510 assert_equal({one: {two: 123}}, d2)
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
511
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
512 var d3: dict<dict<dict<number>>>
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
513 d3.one = {}
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
514 d3.one.two = {}
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
515 d3.one.two.three = 123
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
516 assert_equal({one: {two: {three: 123}}}, d3)
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
517
25459
9adaa0c056c7 patch 8.2.3266: Vim9: assignment with two indexes may check next line
Bram Moolenaar <Bram@vim.org>
parents: 25453
diff changeset
518 # should not read the next line when generating "a.b"
9adaa0c056c7 patch 8.2.3266: Vim9: assignment with two indexes may check next line
Bram Moolenaar <Bram@vim.org>
parents: 25453
diff changeset
519 var a = {}
9adaa0c056c7 patch 8.2.3266: Vim9: assignment with two indexes may check next line
Bram Moolenaar <Bram@vim.org>
parents: 25453
diff changeset
520 a.b = {}
9adaa0c056c7 patch 8.2.3266: Vim9: assignment with two indexes may check next line
Bram Moolenaar <Bram@vim.org>
parents: 25453
diff changeset
521 a.b.c = {}
9adaa0c056c7 patch 8.2.3266: Vim9: assignment with two indexes may check next line
Bram Moolenaar <Bram@vim.org>
parents: 25453
diff changeset
522 ->copy()
9adaa0c056c7 patch 8.2.3266: Vim9: assignment with two indexes may check next line
Bram Moolenaar <Bram@vim.org>
parents: 25453
diff changeset
523
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
524 lines =<< trim END
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
525 var d3: dict<dict<number>>
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
526 d3.one = {}
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
527 d3.one.two = {}
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
528 END
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
529 CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got dict<unknown>', 3)
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
530
23187
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
531 lines =<< trim END
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
532 var lines: list<string>
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
533 lines['a'] = 'asdf'
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
534 END
23662
c761fcb89dfe patch 8.2.2373: Vim9: list assignment only accepts a number index
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
535 CheckDefFailure(lines, 'E1012:', 2)
23187
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
536
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
537 lines =<< trim END
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
538 var lines: string
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
539 lines[9] = 'asdf'
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
540 END
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
541 CheckDefFailure(lines, 'E1141:', 2)
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
542
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
543 # list of dict
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
544 var ld: list<dict<number>>
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
545 ld[0] = {}
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
546 ld[0].one = 123
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
547 assert_equal([{one: 123}], ld)
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
548
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
549 lines =<< trim END
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
550 var ld: list<dict<number>>
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
551 ld[0] = []
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
552 END
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
553 CheckDefFailure(lines, 'E1012: Type mismatch; expected dict<number> but got list<unknown>', 2)
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
554
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
555 # dict of list
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
556 var dl: dict<list<number>>
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
557 dl.one = []
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
558 dl.one[0] = 123
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
559 assert_equal({one: [123]}, dl)
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
560
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
561 lines =<< trim END
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
562 var dl: dict<list<number>>
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
563 dl.one = {}
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
564 END
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
565 CheckDefFailure(lines, 'E1012: Type mismatch; expected list<number> but got dict<unknown>', 2)
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
566 enddef
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
567
22365
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
568 def Test_extend_list()
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
569 var lines =<< trim END
25776
f31cf0388eab patch 8.2.3423: Vim9: list += list creates a new list in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25668
diff changeset
570 var l1: list<number>
f31cf0388eab patch 8.2.3423: Vim9: list += list creates a new list in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25668
diff changeset
571 var l2 = l1
f31cf0388eab patch 8.2.3423: Vim9: list += list creates a new list in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25668
diff changeset
572 assert_true(l1 is l2)
f31cf0388eab patch 8.2.3423: Vim9: list += list creates a new list in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25668
diff changeset
573 l1 += [123]
f31cf0388eab patch 8.2.3423: Vim9: list += list creates a new list in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25668
diff changeset
574 assert_equal([123], l1)
f31cf0388eab patch 8.2.3423: Vim9: list += list creates a new list in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25668
diff changeset
575 assert_true(l1 is l2)
22802
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
576 END
25776
f31cf0388eab patch 8.2.3423: Vim9: list += list creates a new list in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25668
diff changeset
577 CheckDefAndScriptSuccess(lines)
22365
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
578
22802
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
579 lines =<< trim END
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
580 var list: list<string>
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
581 extend(list, ['x'])
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
582 assert_equal(['x'], list)
22365
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
583 END
25776
f31cf0388eab patch 8.2.3423: Vim9: list += list creates a new list in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25668
diff changeset
584 CheckDefAndScriptSuccess(lines)
22545
47596deedfb5 patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
585
47596deedfb5 patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
586 # appending to NULL list from a function
47596deedfb5 patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
587 lines =<< trim END
47596deedfb5 patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
588 vim9script
47596deedfb5 patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
589 var list: list<string>
47596deedfb5 patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
590 def Func()
47596deedfb5 patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
591 list += ['a', 'b']
47596deedfb5 patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
592 enddef
47596deedfb5 patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
593 Func()
47596deedfb5 patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
594 assert_equal(['a', 'b'], list)
47596deedfb5 patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
595 END
47596deedfb5 patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
596 CheckScriptSuccess(lines)
23227
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23223
diff changeset
597 lines =<< trim END
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23223
diff changeset
598 vim9script
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23223
diff changeset
599 var list: list<string>
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23223
diff changeset
600 def Func()
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23223
diff changeset
601 extend(list, ['x', 'b'])
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23223
diff changeset
602 enddef
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23223
diff changeset
603 Func()
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23223
diff changeset
604 assert_equal(['x', 'b'], list)
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23223
diff changeset
605 END
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23223
diff changeset
606 CheckScriptSuccess(lines)
22802
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
607
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
608 lines =<< trim END
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
609 vim9script
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
610 var l: list<string> = test_null_list()
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
611 extend(l, ['x'])
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
612 assert_equal(['x'], l)
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
613 END
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
614 CheckScriptSuccess(lines)
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
615
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
616 lines =<< trim END
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
617 vim9script
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
618 extend(test_null_list(), ['x'])
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
619 END
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
620 CheckScriptFailure(lines, 'E1134:', 2)
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
621 enddef
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
622
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
623 def Test_extend_dict()
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
624 var lines =<< trim END
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
625 vim9script
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
626 var d: dict<number>
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
627 extend(d, {a: 1})
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
628 assert_equal({a: 1}, d)
22802
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
629
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
630 var d2: dict<number>
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
631 d2['one'] = 1
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
632 assert_equal({one: 1}, d2)
22802
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
633 END
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
634 CheckScriptSuccess(lines)
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
635
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
636 lines =<< trim END
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
637 vim9script
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
638 var d: dict<string> = test_null_dict()
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
639 extend(d, {a: 'x'})
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
640 assert_equal({a: 'x'}, d)
22802
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
641 END
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
642 CheckScriptSuccess(lines)
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
643
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
644 lines =<< trim END
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
645 vim9script
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
646 extend(test_null_dict(), {a: 'x'})
22802
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
647 END
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
648 CheckScriptFailure(lines, 'E1133:', 2)
22365
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
649 enddef
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
650
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 def Test_single_letter_vars()
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 # single letter variables
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
653 var a: number = 123
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 a = 123
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 assert_equal(123, a)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
656 var b: number
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 b = 123
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 assert_equal(123, b)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
659 var g: number
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 g = 123
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 assert_equal(123, g)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
662 var s: number
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 s = 123
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 assert_equal(123, s)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
665 var t: number
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 t = 123
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 assert_equal(123, t)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
668 var v: number
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 v = 123
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 assert_equal(123, v)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
671 var w: number
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 w = 123
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 assert_equal(123, w)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 def Test_vim9_single_char_vars()
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
677 var lines =<< trim END
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 vim9script
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 # single character variable declarations work
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
681 var a: string
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
682 var b: number
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
683 var l: list<any>
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
684 var s: string
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
685 var t: number
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
686 var v: number
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
687 var w: number
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 # script-local variables can be used without s: prefix
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 a = 'script-a'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 b = 111
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 l = [1, 2, 3]
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 s = 'script-s'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 t = 222
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 v = 333
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 w = 444
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 assert_equal('script-a', a)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 assert_equal(111, b)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 assert_equal([1, 2, 3], l)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 assert_equal('script-s', s)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 assert_equal(222, t)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 assert_equal(333, v)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 assert_equal(444, w)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 writefile(lines, 'Xsinglechar')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 source Xsinglechar
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 delete('Xsinglechar')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 def Test_assignment_list()
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
712 var list1: list<bool> = [false, true, false]
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
713 var list2: list<number> = [1, 2, 3]
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
714 var list3: list<string> = ['sdf', 'asdf']
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
715 var list4: list<any> = ['yes', true, 1234]
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
716 var list5: list<blob> = [0z01, 0z02]
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
718 var listS: list<string> = []
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
719 var listN: list<number> = []
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 assert_equal([1, 2, 3], list2)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 list2[-1] = 99
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 assert_equal([1, 2, 99], list2)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 list2[-2] = 88
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 assert_equal([1, 88, 99], list2)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 list2[-3] = 77
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 assert_equal([77, 88, 99], list2)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 list2 += [100]
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 assert_equal([77, 88, 99, 100], list2)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 list3 += ['end']
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 assert_equal(['sdf', 'asdf', 'end'], list3)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
734 CheckDefExecFailure(['var ll = [1, 2, 3]', 'll[-4] = 6'], 'E684:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 # type becomes list<any>
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
737 var somelist = rand() > 0 ? [1, 2, 3] : ['a', 'b', 'c']
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
738
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
739 var lines =<< trim END
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
740 var d = {dd: test_null_list()}
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
741 d.dd[0] = 0
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
742 END
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
743 CheckDefExecFailure(lines, 'E1147:', 2)
25126
b825efff9790 patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents: 25054
diff changeset
744
b825efff9790 patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents: 25054
diff changeset
745 lines =<< trim END
b825efff9790 patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents: 25054
diff changeset
746 def OneArg(x: bool)
b825efff9790 patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents: 25054
diff changeset
747 enddef
b825efff9790 patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents: 25054
diff changeset
748 def TwoArgs(x: bool, y: bool)
b825efff9790 patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents: 25054
diff changeset
749 enddef
b825efff9790 patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents: 25054
diff changeset
750 var fl: list<func(bool, bool, bool)> = [OneArg, TwoArgs]
b825efff9790 patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents: 25054
diff changeset
751 END
b825efff9790 patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents: 25054
diff changeset
752 CheckDefExecAndScriptFailure(lines, 'E1012:', 5)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754
26346
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
755 def Test_list_declaration()
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
756 var [v1, v2] = [1, 2]
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
757 v1 += 3
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
758 assert_equal(4, v1)
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
759 v2 *= 3
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
760 assert_equal(6, v2)
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
761
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
762 var lines =<< trim END
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
763 var [v1, v2] = [1]
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
764 END
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
765 CheckDefExecAndScriptFailure2(lines, 'E1093: Expected 2 items but got 1', 'E688:')
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
766 lines =<< trim END
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
767 var testlist = [1]
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
768 var [v1, v2] = testlist
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
769 END
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
770 CheckDefExecAndScriptFailure2(lines, 'E1093: Expected 2 items but got 1', 'E688:')
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
771 lines =<< trim END
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
772 var [v1, v2] = [1, 2, 3]
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
773 END
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
774 CheckDefExecAndScriptFailure2(lines, 'E1093: Expected 2 items but got 3', 'E687:')
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
775 lines =<< trim END
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
776 var testlist = [1, 2, 3]
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
777 var [v1, v2] = testlist
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
778 END
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
779 CheckDefExecAndScriptFailure2(lines, 'E1093: Expected 2 items but got 3', 'E687:')
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
780
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
781 var [vnr, vstr] = [123, 'text']
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
782 vnr += 3
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
783 assert_equal(126, vnr)
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
784 vstr ..= 'end'
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
785 assert_equal('textend', vstr)
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
786
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
787 var [vnr2: number, vstr2: string] = [123, 'text']
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
788 vnr2 += 3
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
789 assert_equal(126, vnr2)
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
790 vstr2 ..= 'end'
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
791 assert_equal('textend', vstr2)
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
792
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
793 var [vnr3: number; vlist: list<string>] = [123, 'foo', 'bar']
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
794 vnr3 += 5
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
795 assert_equal(128, vnr3)
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
796 assert_equal(['foo', 'bar'], vlist)
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
797
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
798 lines =<< trim END
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
799 var [vnr2: number, vstr2: number] = [123, 'text']
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
800 END
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
801 CheckDefExecAndScriptFailure2(lines, 'E1163: Variable 2: type mismatch, expected number but got string', 'E1012: Type mismatch; expected number but got string')
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
802 lines =<< trim END
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
803 var testlist = [234, 'text']
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
804 var [vnr2: number, vstr2: number] = testlist
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
805 END
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
806 CheckDefExecAndScriptFailure2(lines, 'E1163: Variable 2: type mismatch, expected number but got string', 'E1012: Type mismatch; expected number but got string')
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
807 enddef
8be6413a8e27 patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 26330
diff changeset
808
25137
34f18d4081af patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents: 25135
diff changeset
809 def PartFuncBool(b: bool): string
25135
5731bcaaabcb patch 8.2.3104: Vim9: unspecified function type causes type error
Bram Moolenaar <Bram@vim.org>
parents: 25126
diff changeset
810 return 'done'
5731bcaaabcb patch 8.2.3104: Vim9: unspecified function type causes type error
Bram Moolenaar <Bram@vim.org>
parents: 25126
diff changeset
811 enddef
5731bcaaabcb patch 8.2.3104: Vim9: unspecified function type causes type error
Bram Moolenaar <Bram@vim.org>
parents: 25126
diff changeset
812
5731bcaaabcb patch 8.2.3104: Vim9: unspecified function type causes type error
Bram Moolenaar <Bram@vim.org>
parents: 25126
diff changeset
813 def Test_assignment_partial()
25137
34f18d4081af patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents: 25135
diff changeset
814 var lines =<< trim END
34f18d4081af patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents: 25135
diff changeset
815 var Partial: func(): string = function(PartFuncBool, [true])
34f18d4081af patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents: 25135
diff changeset
816 assert_equal('done', Partial())
34f18d4081af patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents: 25135
diff changeset
817 END
34f18d4081af patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents: 25135
diff changeset
818 CheckDefAndScriptSuccess(lines)
25141
99f6087a5fd2 patch 8.2.3107: Vim9: error for arguments while type didn't specify arguments
Bram Moolenaar <Bram@vim.org>
parents: 25139
diff changeset
819
99f6087a5fd2 patch 8.2.3107: Vim9: error for arguments while type didn't specify arguments
Bram Moolenaar <Bram@vim.org>
parents: 25139
diff changeset
820 lines =<< trim END
99f6087a5fd2 patch 8.2.3107: Vim9: error for arguments while type didn't specify arguments
Bram Moolenaar <Bram@vim.org>
parents: 25139
diff changeset
821 vim9script
99f6087a5fd2 patch 8.2.3107: Vim9: error for arguments while type didn't specify arguments
Bram Moolenaar <Bram@vim.org>
parents: 25139
diff changeset
822 def Func(b: bool)
99f6087a5fd2 patch 8.2.3107: Vim9: error for arguments while type didn't specify arguments
Bram Moolenaar <Bram@vim.org>
parents: 25139
diff changeset
823 enddef
99f6087a5fd2 patch 8.2.3107: Vim9: error for arguments while type didn't specify arguments
Bram Moolenaar <Bram@vim.org>
parents: 25139
diff changeset
824 var Ref: func = function(Func, [true])
99f6087a5fd2 patch 8.2.3107: Vim9: error for arguments while type didn't specify arguments
Bram Moolenaar <Bram@vim.org>
parents: 25139
diff changeset
825 assert_equal('func()', typename(Ref))
99f6087a5fd2 patch 8.2.3107: Vim9: error for arguments while type didn't specify arguments
Bram Moolenaar <Bram@vim.org>
parents: 25139
diff changeset
826 Ref()
99f6087a5fd2 patch 8.2.3107: Vim9: error for arguments while type didn't specify arguments
Bram Moolenaar <Bram@vim.org>
parents: 25139
diff changeset
827 END
99f6087a5fd2 patch 8.2.3107: Vim9: error for arguments while type didn't specify arguments
Bram Moolenaar <Bram@vim.org>
parents: 25139
diff changeset
828 CheckScriptSuccess(lines)
25135
5731bcaaabcb patch 8.2.3104: Vim9: unspecified function type causes type error
Bram Moolenaar <Bram@vim.org>
parents: 25126
diff changeset
829 enddef
5731bcaaabcb patch 8.2.3104: Vim9: unspecified function type causes type error
Bram Moolenaar <Bram@vim.org>
parents: 25126
diff changeset
830
23662
c761fcb89dfe patch 8.2.2373: Vim9: list assignment only accepts a number index
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
831 def Test_assignment_list_any_index()
c761fcb89dfe patch 8.2.2373: Vim9: list assignment only accepts a number index
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
832 var l: list<number> = [1, 2]
c761fcb89dfe patch 8.2.2373: Vim9: list assignment only accepts a number index
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
833 for [x, y, _]
c761fcb89dfe patch 8.2.2373: Vim9: list assignment only accepts a number index
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
834 in [[0, 1, ''], [1, 3, '']]
c761fcb89dfe patch 8.2.2373: Vim9: list assignment only accepts a number index
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
835 l[x] = l[x] + y
c761fcb89dfe patch 8.2.2373: Vim9: list assignment only accepts a number index
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
836 endfor
c761fcb89dfe patch 8.2.2373: Vim9: list assignment only accepts a number index
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
837 assert_equal([2, 5], l)
c761fcb89dfe patch 8.2.2373: Vim9: list assignment only accepts a number index
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
838 enddef
c761fcb89dfe patch 8.2.2373: Vim9: list assignment only accepts a number index
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
839
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 def Test_assignment_list_vim9script()
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
841 var lines =<< trim END
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 vim9script
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
843 var v1: number
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
844 var v2: number
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
845 var v3: number
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 [v1, v2, v3] = [1, 2, 3]
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 assert_equal([1, 2, 3], [v1, v2, v3])
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 CheckScriptSuccess(lines)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 def Test_assignment_dict()
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
853 var dict1: dict<bool> = {one: false, two: true}
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
854 var dict2: dict<number> = {one: 1, two: 2}
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
855 var dict3: dict<string> = {key: 'value'}
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
856 var dict4: dict<any> = {one: 1, two: '2'}
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
857 var dict5: dict<blob> = {one: 0z01, two: 0z02}
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 # overwrite
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 dict3['key'] = 'another'
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
861 assert_equal(dict3, {key: 'another'})
22906
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22802
diff changeset
862 dict3.key = 'yet another'
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
863 assert_equal(dict3, {key: 'yet another'})
22906
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22802
diff changeset
864
23245
ac934fbacc0e patch 8.2.2168: Vim9: error for assigning to dict of dict
Bram Moolenaar <Bram@vim.org>
parents: 23243
diff changeset
865 # member "any" can also be a dict and assigned to
ac934fbacc0e patch 8.2.2168: Vim9: error for assigning to dict of dict
Bram Moolenaar <Bram@vim.org>
parents: 23243
diff changeset
866 var anydict: dict<any> = {nest: {}, nr: 0}
ac934fbacc0e patch 8.2.2168: Vim9: error for assigning to dict of dict
Bram Moolenaar <Bram@vim.org>
parents: 23243
diff changeset
867 anydict.nest['this'] = 123
ac934fbacc0e patch 8.2.2168: Vim9: error for assigning to dict of dict
Bram Moolenaar <Bram@vim.org>
parents: 23243
diff changeset
868 anydict.nest.that = 456
ac934fbacc0e patch 8.2.2168: Vim9: error for assigning to dict of dict
Bram Moolenaar <Bram@vim.org>
parents: 23243
diff changeset
869 assert_equal({nest: {this: 123, that: 456}, nr: 0}, anydict)
ac934fbacc0e patch 8.2.2168: Vim9: error for assigning to dict of dict
Bram Moolenaar <Bram@vim.org>
parents: 23243
diff changeset
870
22906
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22802
diff changeset
871 var lines =<< trim END
23243
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
872 var dd = {}
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
873 dd.two = 2
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
874 assert_equal({two: 2}, dd)
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
875 END
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
876 CheckDefAndScriptSuccess(lines)
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
877
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
878 lines =<< trim END
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
879 var d = {dd: {}}
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
880 d.dd[0] = 2
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
881 d.dd['x'] = 3
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
882 d.dd.y = 4
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
883 assert_equal({dd: {0: 2, x: 3, y: 4}}, d)
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
884 END
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
885 CheckDefAndScriptSuccess(lines)
23243
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
886
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
887 lines =<< trim END
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
888 var dd = {one: 1}
22906
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22802
diff changeset
889 dd.one) = 2
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22802
diff changeset
890 END
23243
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
891 CheckDefFailure(lines, 'E488:', 2)
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
892
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
893 lines =<< trim END
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
894 var dd = {one: 1}
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
895 var dd.one = 2
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
896 END
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
897 CheckDefAndScriptFailure(lines, 'E1017:', 2)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 # empty key can be used
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
900 var dd = {}
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 dd[""] = 6
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
902 assert_equal({['']: 6}, dd)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 # type becomes dict<any>
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
905 var somedict = rand() > 0 ? {a: 1, b: 2} : {a: 'a', b: 'b'}
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 # assignment to script-local dict
22906
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22802
diff changeset
908 lines =<< trim END
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 vim9script
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
910 var test: dict<any> = {}
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 def FillDict(): dict<any>
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 test['a'] = 43
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 return test
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 enddef
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
915 assert_equal({a: 43}, FillDict())
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 CheckScriptSuccess(lines)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 lines =<< trim END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 vim9script
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
921 var test: dict<any>
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 def FillDict(): dict<any>
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 test['a'] = 43
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 return test
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 FillDict()
23227
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23223
diff changeset
927 assert_equal({a: 43}, test)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 END
23227
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23223
diff changeset
929 CheckScriptSuccess(lines)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 # assignment to global dict
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 lines =<< trim END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 vim9script
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 g:test = {}
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 def FillDict(): dict<any>
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 g:test['a'] = 43
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 return g:test
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 enddef
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
939 assert_equal({a: 43}, FillDict())
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 CheckScriptSuccess(lines)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 # assignment to buffer dict
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 lines =<< trim END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 vim9script
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 b:test = {}
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 def FillDict(): dict<any>
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 b:test['a'] = 43
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 return b:test
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 enddef
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
951 assert_equal({a: 43}, FillDict())
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 CheckScriptSuccess(lines)
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
954
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
955 lines =<< trim END
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
956 var d = {dd: test_null_dict()}
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
957 d.dd[0] = 0
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
958 END
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
959 CheckDefExecFailure(lines, 'E1103:', 2)
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
960
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
961 lines =<< trim END
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
962 var d = {dd: 'string'}
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
963 d.dd[0] = 0
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
964 END
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
965 CheckDefExecFailure(lines, 'E1148:', 2)
25036
3b8d3b383fd6 patch 8.2.3055: strange error for assigning to "x.key" on non-dictionary
Bram Moolenaar <Bram@vim.org>
parents: 25034
diff changeset
966
3b8d3b383fd6 patch 8.2.3055: strange error for assigning to "x.key" on non-dictionary
Bram Moolenaar <Bram@vim.org>
parents: 25034
diff changeset
967 lines =<< trim END
3b8d3b383fd6 patch 8.2.3055: strange error for assigning to "x.key" on non-dictionary
Bram Moolenaar <Bram@vim.org>
parents: 25034
diff changeset
968 var n: any
3b8d3b383fd6 patch 8.2.3055: strange error for assigning to "x.key" on non-dictionary
Bram Moolenaar <Bram@vim.org>
parents: 25034
diff changeset
969 n.key = 5
3b8d3b383fd6 patch 8.2.3055: strange error for assigning to "x.key" on non-dictionary
Bram Moolenaar <Bram@vim.org>
parents: 25034
diff changeset
970 END
3b8d3b383fd6 patch 8.2.3055: strange error for assigning to "x.key" on non-dictionary
Bram Moolenaar <Bram@vim.org>
parents: 25034
diff changeset
971 CheckDefExecAndScriptFailure2(lines, 'E1148:', 'E1203: Dot can only be used on a dictionary: n.key = 5', 2)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 def Test_assignment_local()
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 # Test in a separated file in order not to the current buffer/window/tab is
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 # changed.
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
977 var script_lines: list<string> =<< trim END
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 let b:existing = 'yes'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 let w:existing = 'yes'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 let t:existing = 'yes'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 def Test_assignment_local_internal()
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 b:newvar = 'new'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 assert_equal('new', b:newvar)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 assert_equal('yes', b:existing)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 b:existing = 'no'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 assert_equal('no', b:existing)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 b:existing ..= 'NO'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 assert_equal('noNO', b:existing)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 w:newvar = 'new'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 assert_equal('new', w:newvar)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 assert_equal('yes', w:existing)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 w:existing = 'no'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 assert_equal('no', w:existing)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 w:existing ..= 'NO'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 assert_equal('noNO', w:existing)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 t:newvar = 'new'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 assert_equal('new', t:newvar)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 assert_equal('yes', t:existing)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 t:existing = 'no'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 assert_equal('no', t:existing)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 t:existing ..= 'NO'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 assert_equal('noNO', t:existing)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 call Test_assignment_local_internal()
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 CheckScriptSuccess(script_lines)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 def Test_assignment_default()
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 # Test default values.
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1014 var thebool: bool
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 assert_equal(v:false, thebool)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1017 var thenumber: number
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 assert_equal(0, thenumber)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 if has('float')
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1021 var thefloat: float
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 assert_equal(0.0, thefloat)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 endif
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1025 var thestring: string
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 assert_equal('', thestring)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1028 var theblob: blob
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 assert_equal(0z, theblob)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1031 var Thefunc: func
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 assert_equal(test_null_function(), Thefunc)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1034 var thelist: list<any>
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 assert_equal([], thelist)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1037 var thedict: dict<any>
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 assert_equal({}, thedict)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 if has('channel')
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1041 var thejob: job
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 assert_equal(test_null_job(), thejob)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1044 var thechannel: channel
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 assert_equal(test_null_channel(), thechannel)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 if has('unix') && executable('cat')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 # check with non-null job and channel, types must match
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
1049 thejob = job_start("cat ", {})
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 thechannel = job_getchannel(thejob)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 job_stop(thejob, 'kill')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 endif
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 endif
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1055 var nr = 1234 | nr = 5678
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 assert_equal(5678, nr)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058
23450
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
1059 let scriptvar = 'init'
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
1060
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 def Test_assignment_var_list()
23050
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1062 var lines =<< trim END
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1063 var v1: string
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1064 var v2: string
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1065 var vrem: list<string>
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1066 [v1] = ['aaa']
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1067 assert_equal('aaa', v1)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068
23050
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1069 [v1, v2] = ['one', 'two']
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1070 assert_equal('one', v1)
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1071 assert_equal('two', v2)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072
23050
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1073 [v1, v2; vrem] = ['one', 'two']
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1074 assert_equal('one', v1)
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1075 assert_equal('two', v2)
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1076 assert_equal([], vrem)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077
23050
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1078 [v1, v2; vrem] = ['one', 'two', 'three']
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1079 assert_equal('one', v1)
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1080 assert_equal('two', v2)
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1081 assert_equal(['three'], vrem)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082
23050
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1083 [&ts, &sw] = [3, 4]
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1084 assert_equal(3, &ts)
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1085 assert_equal(4, &sw)
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1086 set ts=8 sw=4
23052
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23050
diff changeset
1087
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23050
diff changeset
1088 [@a, @z] = ['aa', 'zz']
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23050
diff changeset
1089 assert_equal('aa', @a)
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23050
diff changeset
1090 assert_equal('zz', @z)
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23050
diff changeset
1091
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23050
diff changeset
1092 [$SOME_VAR, $OTHER_VAR] = ['some', 'other']
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23050
diff changeset
1093 assert_equal('some', $SOME_VAR)
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23050
diff changeset
1094 assert_equal('other', $OTHER_VAR)
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23050
diff changeset
1095
23450
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
1096 [g:globalvar, b:bufvar, w:winvar, t:tabvar, v:errmsg] =
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
1097 ['global', 'buf', 'win', 'tab', 'error']
23052
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23050
diff changeset
1098 assert_equal('global', g:globalvar)
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23050
diff changeset
1099 assert_equal('buf', b:bufvar)
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23050
diff changeset
1100 assert_equal('win', w:winvar)
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23050
diff changeset
1101 assert_equal('tab', t:tabvar)
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23050
diff changeset
1102 assert_equal('error', v:errmsg)
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23050
diff changeset
1103 unlet g:globalvar
23050
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1104 END
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
1105 CheckDefAndScriptSuccess(lines)
23450
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
1106
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
1107 [g:globalvar, s:scriptvar, b:bufvar] = ['global', 'script', 'buf']
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
1108 assert_equal('global', g:globalvar)
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
1109 assert_equal('script', s:scriptvar)
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
1110 assert_equal('buf', b:bufvar)
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
1111
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
1112 lines =<< trim END
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
1113 vim9script
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
1114 var s:scriptvar = 'init'
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
1115 [g:globalvar, s:scriptvar, w:winvar] = ['global', 'script', 'win']
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
1116 assert_equal('global', g:globalvar)
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
1117 assert_equal('script', s:scriptvar)
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
1118 assert_equal('win', w:winvar)
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
1119 END
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
1120 CheckScriptSuccess(lines)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 def Test_assignment_vim9script()
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1124 var lines =<< trim END
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 vim9script
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 def Func(): list<number>
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 return [1, 2]
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 enddef
22433
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1129 var name1: number
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1130 var name2: number
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1131 [name1, name2] =
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 Func()
22433
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1133 assert_equal(1, name1)
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1134 assert_equal(2, name2)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1135 var ll =
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 Func()
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 assert_equal([1, 2], ll)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 @/ = 'text'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 assert_equal('text', @/)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 @0 = 'zero'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 assert_equal('zero', @0)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 @1 = 'one'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 assert_equal('one', @1)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 @9 = 'nine'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 assert_equal('nine', @9)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 @- = 'minus'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 assert_equal('minus', @-)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 if has('clipboard_working')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150 @* = 'star'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 assert_equal('star', @*)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 @+ = 'plus'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 assert_equal('plus', @+)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 endif
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1156 var a: number = 123
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 assert_equal(123, a)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1158 var s: string = 'yes'
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 assert_equal('yes', s)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1160 var b: number = 42
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 assert_equal(42, b)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1162 var w: number = 43
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 assert_equal(43, w)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1164 var t: number = 44
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 assert_equal(44, t)
22610
08e2363fd0de patch 8.2.1853: "to_f" is recognized at "topleft" modifier
Bram Moolenaar <Bram@vim.org>
parents: 22582
diff changeset
1166
08e2363fd0de patch 8.2.1853: "to_f" is recognized at "topleft" modifier
Bram Moolenaar <Bram@vim.org>
parents: 22582
diff changeset
1167 var to_var = 0
08e2363fd0de patch 8.2.1853: "to_f" is recognized at "topleft" modifier
Bram Moolenaar <Bram@vim.org>
parents: 22582
diff changeset
1168 to_var = 3
08e2363fd0de patch 8.2.1853: "to_f" is recognized at "topleft" modifier
Bram Moolenaar <Bram@vim.org>
parents: 22582
diff changeset
1169 assert_equal(3, to_var)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 CheckScriptSuccess(lines)
22431
685909aa5641 patch 8.2.1764: Vim9: no error when assigning to script var with wrong type
Bram Moolenaar <Bram@vim.org>
parents: 22425
diff changeset
1172
685909aa5641 patch 8.2.1764: Vim9: no error when assigning to script var with wrong type
Bram Moolenaar <Bram@vim.org>
parents: 22425
diff changeset
1173 lines =<< trim END
685909aa5641 patch 8.2.1764: Vim9: no error when assigning to script var with wrong type
Bram Moolenaar <Bram@vim.org>
parents: 22425
diff changeset
1174 vim9script
685909aa5641 patch 8.2.1764: Vim9: no error when assigning to script var with wrong type
Bram Moolenaar <Bram@vim.org>
parents: 22425
diff changeset
1175 var n: number
685909aa5641 patch 8.2.1764: Vim9: no error when assigning to script var with wrong type
Bram Moolenaar <Bram@vim.org>
parents: 22425
diff changeset
1176 def Func()
685909aa5641 patch 8.2.1764: Vim9: no error when assigning to script var with wrong type
Bram Moolenaar <Bram@vim.org>
parents: 22425
diff changeset
1177 n = 'string'
685909aa5641 patch 8.2.1764: Vim9: no error when assigning to script var with wrong type
Bram Moolenaar <Bram@vim.org>
parents: 22425
diff changeset
1178 enddef
685909aa5641 patch 8.2.1764: Vim9: no error when assigning to script var with wrong type
Bram Moolenaar <Bram@vim.org>
parents: 22425
diff changeset
1179 defcompile
685909aa5641 patch 8.2.1764: Vim9: no error when assigning to script var with wrong type
Bram Moolenaar <Bram@vim.org>
parents: 22425
diff changeset
1180 END
685909aa5641 patch 8.2.1764: Vim9: no error when assigning to script var with wrong type
Bram Moolenaar <Bram@vim.org>
parents: 22425
diff changeset
1181 CheckScriptFailure(lines, 'E1012: Type mismatch; expected number but got string')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 def Mess(): string
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 v:foldstart = 123
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 return 'xxx'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 def Test_assignment_failure()
22433
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1190 CheckDefFailure(['var name=234'], 'E1004:')
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1191 CheckDefFailure(['var name =234'], 'E1004:')
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1192 CheckDefFailure(['var name= 234'], 'E1004:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193
22433
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1194 CheckScriptFailure(['vim9script', 'var name=234'], 'E1004:')
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1195 CheckScriptFailure(['vim9script', 'var name=234'], "before and after '='")
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1196 CheckScriptFailure(['vim9script', 'var name =234'], 'E1004:')
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1197 CheckScriptFailure(['vim9script', 'var name= 234'], 'E1004:')
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1198 CheckScriptFailure(['vim9script', 'var name = 234', 'name+=234'], 'E1004:')
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1199 CheckScriptFailure(['vim9script', 'var name = 234', 'name+=234'], "before and after '+='")
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1200 CheckScriptFailure(['vim9script', 'var name = "x"', 'name..="y"'], 'E1004:')
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1201 CheckScriptFailure(['vim9script', 'var name = "x"', 'name..="y"'], "before and after '..='")
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1203 CheckDefFailure(['var true = 1'], 'E1034:')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1204 CheckDefFailure(['var false = 1'], 'E1034:')
24888
b6ac4ed5e2d2 patch 8.2.2982: Vim9: future commands are not reserved yet
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
1205 CheckDefFailure(['var null = 1'], 'E1034:')
b6ac4ed5e2d2 patch 8.2.2982: Vim9: future commands are not reserved yet
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
1206 CheckDefFailure(['var this = 1'], 'E1034:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208 CheckDefFailure(['[a; b; c] = g:list'], 'E452:')
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1209 CheckDefExecFailure(['var a: number',
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210 '[a] = test_null_list()'], 'E1093:')
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1211 CheckDefExecFailure(['var a: number',
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212 '[a] = []'], 'E1093:')
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1213 CheckDefExecFailure(['var x: number',
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1214 'var y: number',
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 '[x, y] = [1]'], 'E1093:')
22621
576a69fc0066 patch 8.2.1859: Vim9: crash in unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 22618
diff changeset
1216 CheckDefExecFailure(['var x: string',
576a69fc0066 patch 8.2.1859: Vim9: crash in unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 22618
diff changeset
1217 'var y: string',
576a69fc0066 patch 8.2.1859: Vim9: crash in unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 22618
diff changeset
1218 '[x, y] = ["x"]'], 'E1093:')
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1219 CheckDefExecFailure(['var x: number',
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1220 'var y: number',
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1221 'var z: list<number>',
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 '[x, y; z] = [1]'], 'E1093:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1224 CheckDefFailure(['var somevar'], "E1022:")
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1225 CheckDefFailure(['var &tabstop = 4'], 'E1052:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 CheckDefFailure(['&g:option = 5'], 'E113:')
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1227 CheckScriptFailure(['vim9script', 'var &tabstop = 4'], 'E1052:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1229 CheckDefFailure(['var $VAR = 5'], 'E1016: Cannot declare an environment variable:')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1230 CheckScriptFailure(['vim9script', 'var $ENV = "xxx"'], 'E1016:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1232 if has('dnd')
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1233 CheckDefFailure(['var @~ = 5'], 'E1066:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234 else
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1235 CheckDefFailure(['var @~ = 5'], 'E354:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236 CheckDefFailure(['@~ = 5'], 'E354:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 endif
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1238 CheckDefFailure(['var @a = 5'], 'E1066:')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1239 CheckDefFailure(['var @/ = "x"'], 'E1066:')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1240 CheckScriptFailure(['vim9script', 'var @a = "abc"'], 'E1066:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1242 CheckDefFailure(['var g:var = 5'], 'E1016: Cannot declare a global variable:')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1243 CheckDefFailure(['var w:var = 5'], 'E1016: Cannot declare a window variable:')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1244 CheckDefFailure(['var b:var = 5'], 'E1016: Cannot declare a buffer variable:')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1245 CheckDefFailure(['var t:var = 5'], 'E1016: Cannot declare a tab variable:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1247 CheckDefFailure(['var anr = 4', 'anr ..= "text"'], 'E1019:')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1248 CheckDefFailure(['var xnr += 4'], 'E1020:', 1)
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1249 CheckScriptFailure(['vim9script', 'var xnr += 4'], 'E1020:')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1250 CheckDefFailure(["var xnr = xnr + 1"], 'E1001:', 1)
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1251 CheckScriptFailure(['vim9script', 'var xnr = xnr + 4'], 'E121:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1253 CheckScriptFailure(['vim9script', 'def Func()', 'var dummy = s:notfound', 'enddef', 'defcompile'], 'E1108:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254
22433
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1255 CheckDefFailure(['var name: list<string> = [123]'], 'expected list<string> but got list<number>')
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1256 CheckDefFailure(['var name: list<number> = ["xx"]'], 'expected list<number> but got list<string>')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
1258 CheckDefFailure(['var name: dict<string> = {key: 123}'], 'expected dict<string> but got dict<number>')
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
1259 CheckDefFailure(['var name: dict<number> = {key: "xx"}'], 'expected dict<number> but got dict<string>')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260
22433
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1261 CheckDefFailure(['var name = feedkeys("0")'], 'E1031:')
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1262 CheckDefFailure(['var name: number = feedkeys("0")'], 'expected number but got void')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1263
22433
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1264 CheckDefFailure(['var name: dict <number>'], 'E1068:')
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1265 CheckDefFailure(['var name: dict<number'], 'E1009:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1266
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 assert_fails('s/^/\=Mess()/n', 'E794:')
22433
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
1268 CheckDefFailure(['var name: dict<number'], 'E1009:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 CheckDefFailure(['w:foo: number = 10'],
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 'E488: Trailing characters: : number = 1')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 CheckDefFailure(['t:foo: bool = true'],
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273 'E488: Trailing characters: : bool = true')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 CheckDefFailure(['b:foo: string = "x"'],
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 'E488: Trailing characters: : string = "x"')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1276 CheckDefFailure(['g:foo: number = 123'],
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277 'E488: Trailing characters: : number = 123')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 def Test_assign_list()
25054
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1281 var lines =<< trim END
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1282 var l: list<string> = []
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1283 l[0] = 'value'
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1284 assert_equal('value', l[0])
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1285
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1286 l[1] = 'asdf'
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1287 assert_equal('value', l[0])
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1288 assert_equal('asdf', l[1])
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1289 assert_equal('asdf', l[-1])
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1290 assert_equal('value', l[-2])
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291
25054
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1292 var nrl: list<number> = []
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1293 for i in range(5)
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1294 nrl[i] = i
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1295 endfor
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1296 assert_equal([0, 1, 2, 3, 4], nrl)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297
25054
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1298 var ul: list<any>
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1299 ul[0] = 1
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1300 ul[1] = 2
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1301 ul[2] = 3
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1302 assert_equal([1, 2, 3], ul)
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1303 END
64bef59f11ef patch 8.2.3064: Vim9: in script cannot set item in uninitialized list
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
1304 CheckDefAndScriptSuccess(lines)
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22621
diff changeset
1305
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22621
diff changeset
1306 CheckDefFailure(["var l: list<number> = ['', true]"], 'E1012: Type mismatch; expected list<number> but got list<any>', 1)
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22621
diff changeset
1307 CheckDefFailure(["var l: list<list<number>> = [['', true]]"], 'E1012: Type mismatch; expected list<list<number>> but got list<list<any>>', 1)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1308 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1310 def Test_assign_dict()
23448
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1311 var lines =<< trim END
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1312 var d: dict<string> = {}
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1313 d['key'] = 'value'
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1314 assert_equal('value', d['key'])
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1315
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1316 d[123] = 'qwerty'
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1317 assert_equal('qwerty', d[123])
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1318 assert_equal('qwerty', d['123'])
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1319
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1320 var nrd: dict<number> = {}
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1321 for i in range(3)
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1322 nrd[i] = i
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1323 endfor
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1324 assert_equal({0: 0, 1: 1, 2: 2}, nrd)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325
23448
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1326 d.somekey = 'someval'
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1327 assert_equal({key: 'value', '123': 'qwerty', somekey: 'someval'}, d)
25489
911fdca7f736 patch 8.2.3281: Vim9: TODO items in tests can be taken care of
Bram Moolenaar <Bram@vim.org>
parents: 25483
diff changeset
1328 unlet d.somekey
911fdca7f736 patch 8.2.3281: Vim9: TODO items in tests can be taken care of
Bram Moolenaar <Bram@vim.org>
parents: 25483
diff changeset
1329 assert_equal({key: 'value', '123': 'qwerty'}, d)
23448
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1330 END
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1331 CheckDefAndScriptSuccess(lines)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
1333 CheckDefFailure(["var d: dict<number> = {a: '', b: true}"], 'E1012: Type mismatch; expected dict<number> but got dict<any>', 1)
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
1334 CheckDefFailure(["var d: dict<dict<number>> = {x: {a: '', b: true}}"], 'E1012: Type mismatch; expected dict<dict<number>> but got dict<dict<any>>', 1)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336
22363
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22351
diff changeset
1337 def Test_assign_dict_unknown_type()
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1338 var lines =<< trim END
22363
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22351
diff changeset
1339 vim9script
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1340 var mylist = []
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
1341 mylist += [{one: 'one'}]
22363
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22351
diff changeset
1342 def Func()
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1343 var dd = mylist[0]
22363
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22351
diff changeset
1344 assert_equal('one', dd.one)
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22351
diff changeset
1345 enddef
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22351
diff changeset
1346 Func()
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22351
diff changeset
1347 END
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22351
diff changeset
1348 CheckScriptSuccess(lines)
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22351
diff changeset
1349
23039
75241f4377a4 patch 8.2.2066: Vim9: assignment with += doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
1350 lines =<< trim END
75241f4377a4 patch 8.2.2066: Vim9: assignment with += doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
1351 vim9script
75241f4377a4 patch 8.2.2066: Vim9: assignment with += doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
1352 var mylist = [[]]
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
1353 mylist[0] += [{one: 'one'}]
23039
75241f4377a4 patch 8.2.2066: Vim9: assignment with += doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
1354 def Func()
75241f4377a4 patch 8.2.2066: Vim9: assignment with += doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
1355 var dd = mylist[0][0]
75241f4377a4 patch 8.2.2066: Vim9: assignment with += doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
1356 assert_equal('one', dd.one)
75241f4377a4 patch 8.2.2066: Vim9: assignment with += doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
1357 enddef
75241f4377a4 patch 8.2.2066: Vim9: assignment with += doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
1358 Func()
75241f4377a4 patch 8.2.2066: Vim9: assignment with += doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
1359 END
75241f4377a4 patch 8.2.2066: Vim9: assignment with += doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
1360 CheckScriptSuccess(lines)
22363
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22351
diff changeset
1361 enddef
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22351
diff changeset
1362
24047
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1363 def Test_assign_dict_with_op()
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1364 var lines =<< trim END
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1365 var ds: dict<string> = {a: 'x'}
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1366 ds['a'] ..= 'y'
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1367 ds.a ..= 'z'
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1368 assert_equal('xyz', ds.a)
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1369
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1370 var dn: dict<number> = {a: 9}
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1371 dn['a'] += 2
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1372 assert_equal(11, dn.a)
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1373 dn.a += 2
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1374 assert_equal(13, dn.a)
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1375
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1376 dn['a'] -= 3
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1377 assert_equal(10, dn.a)
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1378 dn.a -= 2
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1379 assert_equal(8, dn.a)
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1380
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1381 dn['a'] *= 2
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1382 assert_equal(16, dn.a)
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1383 dn.a *= 2
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1384 assert_equal(32, dn.a)
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1385
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1386 dn['a'] /= 3
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1387 assert_equal(10, dn.a)
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1388 dn.a /= 2
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1389 assert_equal(5, dn.a)
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1390
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1391 dn['a'] %= 3
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1392 assert_equal(2, dn.a)
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1393 dn.a %= 6
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1394 assert_equal(2, dn.a)
24363
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
1395
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
1396 var dd: dict<dict<list<any>>>
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
1397 dd.a = {}
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
1398 dd.a.b = [0]
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
1399 dd.a.b += [1]
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
1400 assert_equal({a: {b: [0, 1]}}, dd)
24367
95b8937804d3 patch 8.2.2724: Vim9: concatenating to list in dict not tested
Bram Moolenaar <Bram@vim.org>
parents: 24363
diff changeset
1401
95b8937804d3 patch 8.2.2724: Vim9: concatenating to list in dict not tested
Bram Moolenaar <Bram@vim.org>
parents: 24363
diff changeset
1402 var dab = {a: ['b']}
95b8937804d3 patch 8.2.2724: Vim9: concatenating to list in dict not tested
Bram Moolenaar <Bram@vim.org>
parents: 24363
diff changeset
1403 dab.a[0] ..= 'c'
95b8937804d3 patch 8.2.2724: Vim9: concatenating to list in dict not tested
Bram Moolenaar <Bram@vim.org>
parents: 24363
diff changeset
1404 assert_equal({a: ['bc']}, dab)
24047
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1405 END
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1406 CheckDefAndScriptSuccess(lines)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1407 enddef
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1408
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1409 def Test_assign_list_with_op()
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1410 var lines =<< trim END
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1411 var ls: list<string> = ['x']
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1412 ls[0] ..= 'y'
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1413 assert_equal('xy', ls[0])
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1414
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1415 var ln: list<number> = [9]
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1416 ln[0] += 2
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1417 assert_equal(11, ln[0])
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1418
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1419 ln[0] -= 3
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1420 assert_equal(8, ln[0])
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1421
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1422 ln[0] *= 2
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1423 assert_equal(16, ln[0])
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1424
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1425 ln[0] /= 3
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1426 assert_equal(5, ln[0])
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1427
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1428 ln[0] %= 3
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1429 assert_equal(2, ln[0])
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1430 END
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1431 CheckDefAndScriptSuccess(lines)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1432 enddef
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1433
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1434 def Test_assign_with_op_fails()
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1435 var lines =<< trim END
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1436 var s = 'abc'
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1437 s[1] += 'x'
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1438 END
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1439 CheckDefAndScriptFailure2(lines, 'E1141:', 'E689:', 2)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1440
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1441 lines =<< trim END
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1442 var s = 'abc'
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1443 s[1] ..= 'x'
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1444 END
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
1445 CheckDefAndScriptFailure2(lines, 'E1141:', 'E689:', 2)
24363
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
1446
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
1447 lines =<< trim END
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
1448 var dd: dict<dict<list<any>>>
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
1449 dd.a = {}
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
1450 dd.a.b += [1]
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
1451 END
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
1452 CheckDefExecAndScriptFailure(lines, 'E716:', 3)
24047
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1453 enddef
b535ab17d160 patch 8.2.2565: Vim9: "..=" not always recognized
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
1454
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455 def Test_assign_lambda()
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1456 # check if assign a lambda to a variable which type is func or any.
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1457 var lines =<< trim END
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1458 vim9script
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
1459 var FuncRef = () => 123
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1460 assert_equal(123, FuncRef())
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
1461 var FuncRef_Func: func = () => 123
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1462 assert_equal(123, FuncRef_Func())
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
1463 var FuncRef_Any: any = () => 123
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1464 assert_equal(123, FuncRef_Any())
23970
ba79ceac82ec patch 8.2.2527: Vim9: lambda return type is not determined at script level
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
1465 var FuncRef_Number: func(): number = () => 321
ba79ceac82ec patch 8.2.2527: Vim9: lambda return type is not determined at script level
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
1466 assert_equal(321, FuncRef_Number())
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1467 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1468 CheckScriptSuccess(lines)
23531
f39a18a42aed patch 8.2.2308: Vim9: no error when assigning lambda to funcref
Bram Moolenaar <Bram@vim.org>
parents: 23523
diff changeset
1469
f39a18a42aed patch 8.2.2308: Vim9: no error when assigning lambda to funcref
Bram Moolenaar <Bram@vim.org>
parents: 23523
diff changeset
1470 lines =<< trim END
f39a18a42aed patch 8.2.2308: Vim9: no error when assigning lambda to funcref
Bram Moolenaar <Bram@vim.org>
parents: 23523
diff changeset
1471 var Ref: func(number)
f39a18a42aed patch 8.2.2308: Vim9: no error when assigning lambda to funcref
Bram Moolenaar <Bram@vim.org>
parents: 23523
diff changeset
1472 Ref = (j) => !j
f39a18a42aed patch 8.2.2308: Vim9: no error when assigning lambda to funcref
Bram Moolenaar <Bram@vim.org>
parents: 23523
diff changeset
1473 END
23970
ba79ceac82ec patch 8.2.2527: Vim9: lambda return type is not determined at script level
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
1474 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected func(number) but got func(any): bool')
23972
a620df0ebbe5 patch 8.2.2528: Vim9: crash when compiling lambda fails
Bram Moolenaar <Bram@vim.org>
parents: 23970
diff changeset
1475
a620df0ebbe5 patch 8.2.2528: Vim9: crash when compiling lambda fails
Bram Moolenaar <Bram@vim.org>
parents: 23970
diff changeset
1476 lines =<< trim END
a620df0ebbe5 patch 8.2.2528: Vim9: crash when compiling lambda fails
Bram Moolenaar <Bram@vim.org>
parents: 23970
diff changeset
1477 echo filter([1, 2, 3], (_, v: string) => v + 1)
a620df0ebbe5 patch 8.2.2528: Vim9: crash when compiling lambda fails
Bram Moolenaar <Bram@vim.org>
parents: 23970
diff changeset
1478 END
a620df0ebbe5 patch 8.2.2528: Vim9: crash when compiling lambda fails
Bram Moolenaar <Bram@vim.org>
parents: 23970
diff changeset
1479 CheckDefAndScriptFailure(lines, 'E1051:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1480 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481
22413
66d1131a7eff patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
1482 def Test_heredoc()
66d1131a7eff patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
1483 var lines =<< trim END # comment
66d1131a7eff patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
1484 text
66d1131a7eff patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
1485 END
66d1131a7eff patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
1486 assert_equal(['text'], lines)
66d1131a7eff patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
1487
66d1131a7eff patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
1488 CheckDefFailure(['var lines =<< trim END X', 'END'], 'E488:')
66d1131a7eff patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
1489 CheckDefFailure(['var lines =<< trim END " comment', 'END'], 'E488:')
22423
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1490
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1491 lines =<< trim [END]
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1492 def Func()
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1493 var&lines =<< trim END
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1494 x
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1495 x
23185
055fa9db6f39 patch 8.2.2138: Vim9: "exit_cb" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1496 enddef
055fa9db6f39 patch 8.2.2138: Vim9: "exit_cb" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1497 defcompile
055fa9db6f39 patch 8.2.2138: Vim9: "exit_cb" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1498 [END]
055fa9db6f39 patch 8.2.2138: Vim9: "exit_cb" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1499 CheckScriptFailure(lines, 'E1145: Missing heredoc end marker: END')
055fa9db6f39 patch 8.2.2138: Vim9: "exit_cb" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1500 delfunc! g:Func
055fa9db6f39 patch 8.2.2138: Vim9: "exit_cb" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1501
055fa9db6f39 patch 8.2.2138: Vim9: "exit_cb" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1502 lines =<< trim [END]
055fa9db6f39 patch 8.2.2138: Vim9: "exit_cb" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1503 def Func()
055fa9db6f39 patch 8.2.2138: Vim9: "exit_cb" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1504 var lines =<< trim END
055fa9db6f39 patch 8.2.2138: Vim9: "exit_cb" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1505 x
055fa9db6f39 patch 8.2.2138: Vim9: "exit_cb" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1506 x
22423
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1507 x
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1508 x
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1509 x
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1510 x
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1511 x
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1512 x
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1513 enddef
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1514 call Func()
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1515 [END]
23185
055fa9db6f39 patch 8.2.2138: Vim9: "exit_cb" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1516 CheckScriptFailure(lines, 'E1145: Missing heredoc end marker: END')
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
1517 delfunc! g:Func
25405
747ebbce2421 patch 8.2.3239: Vim9: no error using heredoc for a number variable
Bram Moolenaar <Bram@vim.org>
parents: 25400
diff changeset
1518
747ebbce2421 patch 8.2.3239: Vim9: no error using heredoc for a number variable
Bram Moolenaar <Bram@vim.org>
parents: 25400
diff changeset
1519 lines =<< trim END
747ebbce2421 patch 8.2.3239: Vim9: no error using heredoc for a number variable
Bram Moolenaar <Bram@vim.org>
parents: 25400
diff changeset
1520 var lines: number =<< trim STOP
747ebbce2421 patch 8.2.3239: Vim9: no error using heredoc for a number variable
Bram Moolenaar <Bram@vim.org>
parents: 25400
diff changeset
1521 aaa
747ebbce2421 patch 8.2.3239: Vim9: no error using heredoc for a number variable
Bram Moolenaar <Bram@vim.org>
parents: 25400
diff changeset
1522 bbb
747ebbce2421 patch 8.2.3239: Vim9: no error using heredoc for a number variable
Bram Moolenaar <Bram@vim.org>
parents: 25400
diff changeset
1523 STOP
747ebbce2421 patch 8.2.3239: Vim9: no error using heredoc for a number variable
Bram Moolenaar <Bram@vim.org>
parents: 25400
diff changeset
1524 END
747ebbce2421 patch 8.2.3239: Vim9: no error using heredoc for a number variable
Bram Moolenaar <Bram@vim.org>
parents: 25400
diff changeset
1525 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<string>', 1)
22413
66d1131a7eff patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
1526 enddef
66d1131a7eff patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
1527
23124
f8cd5a5e03c4 patch 8.2.2108: Vim9: no test to check for :let error
Bram Moolenaar <Bram@vim.org>
parents: 23122
diff changeset
1528 def Test_var_func_call()
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1529 var lines =<< trim END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1530 vim9script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1531 func GetValue()
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1532 if exists('g:count')
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1533 let g:count += 1
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1534 else
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1535 let g:count = 1
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1536 endif
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1537 return 'this'
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1538 endfunc
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1539 var val: string = GetValue()
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1540 # env var is always a string
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1541 var env = $TERM
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1542 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1543 writefile(lines, 'Xfinished')
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1544 source Xfinished
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1545 # GetValue() is not called during discovery phase
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1546 assert_equal(1, g:count)
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1547
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1548 unlet g:count
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1549 delete('Xfinished')
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1550 enddef
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1551
23124
f8cd5a5e03c4 patch 8.2.2108: Vim9: no test to check for :let error
Bram Moolenaar <Bram@vim.org>
parents: 23122
diff changeset
1552 def Test_var_missing_type()
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1553 var lines =<< trim END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1554 vim9script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1555 var name = g:unknown
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1556 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1557 CheckScriptFailure(lines, 'E121:')
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1558
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1559 lines =<< trim END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1560 vim9script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1561 var nr: number = 123
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1562 var name = nr
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1563 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1564 CheckScriptSuccess(lines)
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1565 enddef
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1566
23124
f8cd5a5e03c4 patch 8.2.2108: Vim9: no test to check for :let error
Bram Moolenaar <Bram@vim.org>
parents: 23122
diff changeset
1567 def Test_var_declaration()
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1568 var lines =<< trim END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1569 vim9script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1570 var name: string
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1571 g:var_uninit = name
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1572 name = 'text'
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1573 g:var_test = name
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1574 # prefixing s: is optional
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1575 s:name = 'prefixed'
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1576 g:var_prefixed = s:name
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1577
23138
1a9705075244 patch 8.2.2115: Vim9: some errors not tested for; dead code
Bram Moolenaar <Bram@vim.org>
parents: 23124
diff changeset
1578 const FOO: number = 123
1a9705075244 patch 8.2.2115: Vim9: some errors not tested for; dead code
Bram Moolenaar <Bram@vim.org>
parents: 23124
diff changeset
1579 assert_equal(123, FOO)
23297
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1580 const FOOS = 'foos'
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1581 assert_equal('foos', FOOS)
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1582 final FLIST = [1]
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1583 assert_equal([1], FLIST)
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1584 FLIST[0] = 11
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1585 assert_equal([11], FLIST)
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1586
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1587 const g:FOO: number = 321
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1588 assert_equal(321, g:FOO)
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1589 const g:FOOS = 'gfoos'
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1590 assert_equal('gfoos', g:FOOS)
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1591 final g:FLIST = [2]
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1592 assert_equal([2], g:FLIST)
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1593 g:FLIST[0] = 22
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1594 assert_equal([22], g:FLIST)
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1595
24293
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24264
diff changeset
1596 def SetGlobalConst()
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24264
diff changeset
1597 const g:globConst = 123
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24264
diff changeset
1598 enddef
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24264
diff changeset
1599 SetGlobalConst()
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24264
diff changeset
1600 assert_equal(123, g:globConst)
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24264
diff changeset
1601 assert_true(islocked('g:globConst'))
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24264
diff changeset
1602
23297
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1603 const w:FOO: number = 46
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1604 assert_equal(46, w:FOO)
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1605 const w:FOOS = 'wfoos'
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1606 assert_equal('wfoos', w:FOOS)
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1607 final w:FLIST = [3]
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1608 assert_equal([3], w:FLIST)
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1609 w:FLIST[0] = 33
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1610 assert_equal([33], w:FLIST)
23138
1a9705075244 patch 8.2.2115: Vim9: some errors not tested for; dead code
Bram Moolenaar <Bram@vim.org>
parents: 23124
diff changeset
1611
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1612 var s:other: number
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1613 other = 1234
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1614 g:other_var = other
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1615
24238
e5cd25f7ffcd patch 8.2.2660: Vim9: no error for declaration with trailing text
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
1616 var xyz: string # comment
e5cd25f7ffcd patch 8.2.2660: Vim9: no error for declaration with trailing text
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
1617
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1618 # type is inferred
23450
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
1619 var s:dict = {['a']: 222}
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1620 def GetDictVal(key: any)
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1621 g:dict_val = s:dict[key]
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1622 enddef
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1623 GetDictVal('a')
23578
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23549
diff changeset
1624
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23549
diff changeset
1625 final adict: dict<string> = {}
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23549
diff changeset
1626 def ChangeAdict()
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23549
diff changeset
1627 adict.foo = 'foo'
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23549
diff changeset
1628 enddef
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23549
diff changeset
1629 ChangeAdict()
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1630 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1631 CheckScriptSuccess(lines)
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1632 assert_equal('', g:var_uninit)
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1633 assert_equal('text', g:var_test)
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1634 assert_equal('prefixed', g:var_prefixed)
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1635 assert_equal(1234, g:other_var)
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1636 assert_equal(222, g:dict_val)
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1637
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1638 unlet g:var_uninit
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1639 unlet g:var_test
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1640 unlet g:var_prefixed
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1641 unlet g:other_var
24325
52a0e187264b patch 8.2.2703: Vim9: memory leak when failing on locked variable
Bram Moolenaar <Bram@vim.org>
parents: 24305
diff changeset
1642 unlet g:globConst
23297
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1643 unlet g:FOO
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1644 unlet g:FOOS
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1645 unlet g:FLIST
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1646 unlet w:FOO
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1647 unlet w:FOOS
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1648 unlet w:FLIST
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1649 enddef
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1650
23124
f8cd5a5e03c4 patch 8.2.2108: Vim9: no test to check for :let error
Bram Moolenaar <Bram@vim.org>
parents: 23122
diff changeset
1651 def Test_var_declaration_fails()
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1652 var lines =<< trim END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1653 vim9script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1654 final var: string
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1655 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1656 CheckScriptFailure(lines, 'E1125:')
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1657
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1658 lines =<< trim END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1659 vim9script
23297
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1660 const g:constvar = 'string'
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1661 g:constvar = 'xx'
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1662 END
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1663 CheckScriptFailure(lines, 'E741:')
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1664 unlet g:constvar
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1665
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1666 lines =<< trim END
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1667 vim9script
24303
17b49af76766 patch 8.2.2692: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24293
diff changeset
1668 var name = 'one'
17b49af76766 patch 8.2.2692: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24293
diff changeset
1669 lockvar name
17b49af76766 patch 8.2.2692: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24293
diff changeset
1670 def SetLocked()
17b49af76766 patch 8.2.2692: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24293
diff changeset
1671 name = 'two'
17b49af76766 patch 8.2.2692: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24293
diff changeset
1672 enddef
17b49af76766 patch 8.2.2692: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24293
diff changeset
1673 SetLocked()
17b49af76766 patch 8.2.2692: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24293
diff changeset
1674 END
24305
c88d0b5c5a42 patch 8.2.2693: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24303
diff changeset
1675 CheckScriptFailure(lines, 'E741: Value is locked: name', 1)
c88d0b5c5a42 patch 8.2.2693: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24303
diff changeset
1676
c88d0b5c5a42 patch 8.2.2693: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24303
diff changeset
1677 lines =<< trim END
c88d0b5c5a42 patch 8.2.2693: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24303
diff changeset
1678 let s:legacy = 'one'
c88d0b5c5a42 patch 8.2.2693: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24303
diff changeset
1679 lockvar s:legacy
c88d0b5c5a42 patch 8.2.2693: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24303
diff changeset
1680 def SetLocked()
c88d0b5c5a42 patch 8.2.2693: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24303
diff changeset
1681 s:legacy = 'two'
c88d0b5c5a42 patch 8.2.2693: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24303
diff changeset
1682 enddef
c88d0b5c5a42 patch 8.2.2693: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24303
diff changeset
1683 call SetLocked()
c88d0b5c5a42 patch 8.2.2693: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24303
diff changeset
1684 END
c88d0b5c5a42 patch 8.2.2693: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24303
diff changeset
1685 CheckScriptFailure(lines, 'E741: Value is locked: s:legacy', 1)
24303
17b49af76766 patch 8.2.2692: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24293
diff changeset
1686
17b49af76766 patch 8.2.2692: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24293
diff changeset
1687 lines =<< trim END
17b49af76766 patch 8.2.2692: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24293
diff changeset
1688 vim9script
24293
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24264
diff changeset
1689 def SetGlobalConst()
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24264
diff changeset
1690 const g:globConst = 123
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24264
diff changeset
1691 enddef
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24264
diff changeset
1692 SetGlobalConst()
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24264
diff changeset
1693 g:globConst = 234
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24264
diff changeset
1694 END
24325
52a0e187264b patch 8.2.2703: Vim9: memory leak when failing on locked variable
Bram Moolenaar <Bram@vim.org>
parents: 24305
diff changeset
1695 CheckScriptFailure(lines, 'E741: Value is locked: g:globConst', 6)
24293
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24264
diff changeset
1696 unlet g:globConst
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24264
diff changeset
1697
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24264
diff changeset
1698 lines =<< trim END
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24264
diff changeset
1699 vim9script
23578
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23549
diff changeset
1700 const cdict: dict<string> = {}
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23549
diff changeset
1701 def Change()
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23549
diff changeset
1702 cdict.foo = 'foo'
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23549
diff changeset
1703 enddef
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23549
diff changeset
1704 defcompile
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23549
diff changeset
1705 END
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23549
diff changeset
1706 CheckScriptFailure(lines, 'E46:')
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23549
diff changeset
1707
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23549
diff changeset
1708 lines =<< trim END
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23549
diff changeset
1709 vim9script
23297
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1710 final w:finalvar = [9]
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1711 w:finalvar = [8]
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1712 END
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1713 CheckScriptFailure(lines, 'E1122:')
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1714 unlet w:finalvar
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1715
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1716 lines =<< trim END
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1717 vim9script
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1718 const var: string
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1719 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1720 CheckScriptFailure(lines, 'E1021:')
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1721
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1722 lines =<< trim END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1723 vim9script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1724 var 9var: string
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1725 END
24238
e5cd25f7ffcd patch 8.2.2660: Vim9: no error for declaration with trailing text
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
1726 CheckScriptFailure(lines, 'E488:')
23138
1a9705075244 patch 8.2.2115: Vim9: some errors not tested for; dead code
Bram Moolenaar <Bram@vim.org>
parents: 23124
diff changeset
1727
1a9705075244 patch 8.2.2115: Vim9: some errors not tested for; dead code
Bram Moolenaar <Bram@vim.org>
parents: 23124
diff changeset
1728 CheckDefFailure(['var foo.bar = 2'], 'E1087:')
1a9705075244 patch 8.2.2115: Vim9: some errors not tested for; dead code
Bram Moolenaar <Bram@vim.org>
parents: 23124
diff changeset
1729 CheckDefFailure(['var foo[3] = 2'], 'E1087:')
1a9705075244 patch 8.2.2115: Vim9: some errors not tested for; dead code
Bram Moolenaar <Bram@vim.org>
parents: 23124
diff changeset
1730 CheckDefFailure(['const foo: number'], 'E1021:')
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1731 enddef
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1732
24377
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1733 def Test_script_local_in_legacy()
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1734 # OK to define script-local later when prefixed with s:
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1735 var lines =<< trim END
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1736 def SetLater()
24531
3bfec39ce31c patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 24462
diff changeset
1737 s:legvar = 'two'
24377
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1738 enddef
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1739 defcompile
24531
3bfec39ce31c patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 24462
diff changeset
1740 let s:legvar = 'one'
24377
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1741 call SetLater()
24531
3bfec39ce31c patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 24462
diff changeset
1742 call assert_equal('two', s:legvar)
24377
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1743 END
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1744 CheckScriptSuccess(lines)
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1745
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1746 # OK to leave out s: prefix when script-local already defined
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1747 lines =<< trim END
24531
3bfec39ce31c patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 24462
diff changeset
1748 let s:legvar = 'one'
24377
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1749 def SetNoPrefix()
24531
3bfec39ce31c patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 24462
diff changeset
1750 legvar = 'two'
24377
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1751 enddef
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1752 call SetNoPrefix()
24531
3bfec39ce31c patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 24462
diff changeset
1753 call assert_equal('two', s:legvar)
24377
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1754 END
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1755 CheckScriptSuccess(lines)
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1756
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1757 # Not OK to leave out s: prefix when script-local defined later
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1758 lines =<< trim END
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1759 def SetLaterNoPrefix()
24531
3bfec39ce31c patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 24462
diff changeset
1760 legvar = 'two'
24377
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1761 enddef
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1762 defcompile
24531
3bfec39ce31c patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 24462
diff changeset
1763 let s:legvar = 'one'
24377
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1764 END
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1765 CheckScriptFailure(lines, 'E476:', 1)
25274
84d5cda23b34 patch 8.2.3174: Vim9: "legacy undo" finds "undo" variable
Bram Moolenaar <Bram@vim.org>
parents: 25263
diff changeset
1766
84d5cda23b34 patch 8.2.3174: Vim9: "legacy undo" finds "undo" variable
Bram Moolenaar <Bram@vim.org>
parents: 25263
diff changeset
1767 edit! Xfile
84d5cda23b34 patch 8.2.3174: Vim9: "legacy undo" finds "undo" variable
Bram Moolenaar <Bram@vim.org>
parents: 25263
diff changeset
1768 lines =<< trim END
84d5cda23b34 patch 8.2.3174: Vim9: "legacy undo" finds "undo" variable
Bram Moolenaar <Bram@vim.org>
parents: 25263
diff changeset
1769 var edit: bool
84d5cda23b34 patch 8.2.3174: Vim9: "legacy undo" finds "undo" variable
Bram Moolenaar <Bram@vim.org>
parents: 25263
diff changeset
1770 legacy edit
84d5cda23b34 patch 8.2.3174: Vim9: "legacy undo" finds "undo" variable
Bram Moolenaar <Bram@vim.org>
parents: 25263
diff changeset
1771 END
84d5cda23b34 patch 8.2.3174: Vim9: "legacy undo" finds "undo" variable
Bram Moolenaar <Bram@vim.org>
parents: 25263
diff changeset
1772 CheckDefAndScriptSuccess(lines)
24377
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1773 enddef
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24367
diff changeset
1774
23124
f8cd5a5e03c4 patch 8.2.2108: Vim9: no test to check for :let error
Bram Moolenaar <Bram@vim.org>
parents: 23122
diff changeset
1775 def Test_var_type_check()
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1776 var lines =<< trim END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1777 vim9script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1778 var name: string
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1779 name = 1234
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1780 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1781 CheckScriptFailure(lines, 'E1012:')
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1782
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1783 lines =<< trim END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1784 vim9script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1785 var name:string
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1786 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1787 CheckScriptFailure(lines, 'E1069:')
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1788
25668
ba4e6e74c89f patch 8.2.3370: Vim9: no check for white space before type in declaration
Bram Moolenaar <Bram@vim.org>
parents: 25591
diff changeset
1789 CheckDefAndScriptFailure(['var n:number = 42'], 'E1069:')
ba4e6e74c89f patch 8.2.3370: Vim9: no check for white space before type in declaration
Bram Moolenaar <Bram@vim.org>
parents: 25591
diff changeset
1790
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1791 lines =<< trim END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1792 vim9script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1793 var name: asdf
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1794 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1795 CheckScriptFailure(lines, 'E1010:')
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1796
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1797 lines =<< trim END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1798 vim9script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1799 var s:l: list<number>
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1800 s:l = []
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1801 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1802 CheckScriptSuccess(lines)
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1803
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1804 lines =<< trim END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1805 vim9script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1806 var s:d: dict<number>
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1807 s:d = {}
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1808 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1809 CheckScriptSuccess(lines)
25263
5861cc1f5704 patch 8.2.3168: Vim9: type error for constant of type any
Bram Moolenaar <Bram@vim.org>
parents: 25141
diff changeset
1810
5861cc1f5704 patch 8.2.3168: Vim9: type error for constant of type any
Bram Moolenaar <Bram@vim.org>
parents: 25141
diff changeset
1811 lines =<< trim END
5861cc1f5704 patch 8.2.3168: Vim9: type error for constant of type any
Bram Moolenaar <Bram@vim.org>
parents: 25141
diff changeset
1812 vim9script
5861cc1f5704 patch 8.2.3168: Vim9: type error for constant of type any
Bram Moolenaar <Bram@vim.org>
parents: 25141
diff changeset
1813 var d = {a: 1, b: [2]}
5861cc1f5704 patch 8.2.3168: Vim9: type error for constant of type any
Bram Moolenaar <Bram@vim.org>
parents: 25141
diff changeset
1814 def Func(b: bool)
5861cc1f5704 patch 8.2.3168: Vim9: type error for constant of type any
Bram Moolenaar <Bram@vim.org>
parents: 25141
diff changeset
1815 var l: list<number> = b ? d.b : [3]
5861cc1f5704 patch 8.2.3168: Vim9: type error for constant of type any
Bram Moolenaar <Bram@vim.org>
parents: 25141
diff changeset
1816 enddef
5861cc1f5704 patch 8.2.3168: Vim9: type error for constant of type any
Bram Moolenaar <Bram@vim.org>
parents: 25141
diff changeset
1817 defcompile
5861cc1f5704 patch 8.2.3168: Vim9: type error for constant of type any
Bram Moolenaar <Bram@vim.org>
parents: 25141
diff changeset
1818 END
5861cc1f5704 patch 8.2.3168: Vim9: type error for constant of type any
Bram Moolenaar <Bram@vim.org>
parents: 25141
diff changeset
1819 CheckScriptSuccess(lines)
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1820 enddef
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1821
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1822 let g:dict_number = #{one: 1, two: 2}
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1823
23124
f8cd5a5e03c4 patch 8.2.2108: Vim9: no test to check for :let error
Bram Moolenaar <Bram@vim.org>
parents: 23122
diff changeset
1824 def Test_var_list_dict_type()
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1825 var ll: list<number>
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1826 ll = [1, 2, 2, 3, 3, 3]->uniq()
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1827 ll->assert_equal([1, 2, 3])
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1828
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1829 var dd: dict<number>
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1830 dd = g:dict_number
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1831 dd->assert_equal(g:dict_number)
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1832
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1833 var lines =<< trim END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1834 var ll: list<number>
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1835 ll = [1, 2, 3]->map('"one"')
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1836 END
23646
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23578
diff changeset
1837 CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string')
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1838 enddef
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1839
23124
f8cd5a5e03c4 patch 8.2.2108: Vim9: no test to check for :let error
Bram Moolenaar <Bram@vim.org>
parents: 23122
diff changeset
1840 def Test_cannot_use_let()
f8cd5a5e03c4 patch 8.2.2108: Vim9: no test to check for :let error
Bram Moolenaar <Bram@vim.org>
parents: 23122
diff changeset
1841 CheckDefAndScriptFailure(['let a = 34'], 'E1126:', 1)
f8cd5a5e03c4 patch 8.2.2108: Vim9: no test to check for :let error
Bram Moolenaar <Bram@vim.org>
parents: 23122
diff changeset
1842 enddef
f8cd5a5e03c4 patch 8.2.2108: Vim9: no test to check for :let error
Bram Moolenaar <Bram@vim.org>
parents: 23122
diff changeset
1843
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1844 def Test_unlet()
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1845 g:somevar = 'yes'
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1846 assert_true(exists('g:somevar'))
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1847 unlet g:somevar
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1848 assert_false(exists('g:somevar'))
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1849 unlet! g:somevar
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1850
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1851 # also works for script-local variable in legacy Vim script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1852 s:somevar = 'legacy'
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1853 assert_true(exists('s:somevar'))
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1854 unlet s:somevar
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1855 assert_false(exists('s:somevar'))
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1856 unlet! s:somevar
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1857
23523
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1858 CheckDefExecFailure([
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1859 'var dd = 111',
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1860 'unlet dd',
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1861 ], 'E1081:', 2)
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1862
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1863 # dict unlet
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1864 var dd = {a: 1, b: 2, c: 3}
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1865 unlet dd['a']
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1866 unlet dd.c
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1867 assert_equal({b: 2}, dd)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1868
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1869 # list unlet
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1870 var ll = [1, 2, 3, 4]
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1871 unlet ll[1]
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1872 unlet ll[-1]
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1873 assert_equal([1, 3], ll)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1874
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1875 ll = [1, 2, 3, 4]
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1876 unlet ll[0 : 1]
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1877 assert_equal([3, 4], ll)
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1878
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1879 ll = [1, 2, 3, 4]
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1880 unlet ll[2 : 8]
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1881 assert_equal([1, 2], ll)
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1882
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1883 ll = [1, 2, 3, 4]
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1884 unlet ll[-2 : -1]
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1885 assert_equal([1, 2], ll)
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1886
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1887 CheckDefFailure([
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1888 'var ll = [1, 2]',
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1889 'll[1 : 2] = 7',
25591
ea69398b40d1 patch 8.2.3332: Vim9: cannot assign to range in list
Bram Moolenaar <Bram@vim.org>
parents: 25547
diff changeset
1890 ], 'E1012: Type mismatch; expected list<number> but got number', 2)
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1891 CheckDefFailure([
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1892 'var dd = {a: 1}',
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1893 'unlet dd["a" : "a"]',
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1894 ], 'E1166:', 2)
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1895 CheckDefExecFailure([
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1896 'unlet g:adict[0 : 1]',
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1897 ], 'E1148:', 1)
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1898 CheckDefFailure([
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1899 'var ll = [1, 2]',
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1900 'unlet ll[0:1]',
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1901 ], 'E1004:', 2)
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1902 CheckDefFailure([
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1903 'var ll = [1, 2]',
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1904 'unlet ll[0 :1]',
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1905 ], 'E1004:', 2)
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1906 CheckDefFailure([
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1907 'var ll = [1, 2]',
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1908 'unlet ll[0: 1]',
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1909 ], 'E1004:', 2)
26330
55e658312376 patch 8.2.3696: Vim9: error for invalid assignment when skipping
Bram Moolenaar <Bram@vim.org>
parents: 26302
diff changeset
1910 # command recognized as assignment when skipping, should not give an error
55e658312376 patch 8.2.3696: Vim9: error for invalid assignment when skipping
Bram Moolenaar <Bram@vim.org>
parents: 26302
diff changeset
1911 CheckScriptSuccess([
55e658312376 patch 8.2.3696: Vim9: error for invalid assignment when skipping
Bram Moolenaar <Bram@vim.org>
parents: 26302
diff changeset
1912 'vim9script',
55e658312376 patch 8.2.3696: Vim9: error for invalid assignment when skipping
Bram Moolenaar <Bram@vim.org>
parents: 26302
diff changeset
1913 'for i in []',
55e658312376 patch 8.2.3696: Vim9: error for invalid assignment when skipping
Bram Moolenaar <Bram@vim.org>
parents: 26302
diff changeset
1914 " put =''",
55e658312376 patch 8.2.3696: Vim9: error for invalid assignment when skipping
Bram Moolenaar <Bram@vim.org>
parents: 26302
diff changeset
1915 'endfor'])
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1916
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1917 CheckDefFailure([
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1918 'var ll = [1, 2]',
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1919 'unlet ll["x" : 1]',
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1920 ], 'E1012:', 2)
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1921 CheckDefFailure([
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1922 'var ll = [1, 2]',
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1923 'unlet ll[0 : "x"]',
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1924 ], 'E1012:', 2)
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23972
diff changeset
1925
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1926 # list of dict unlet
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1927 var dl = [{a: 1, b: 2}, {c: 3}]
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1928 unlet dl[0]['b']
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1929 assert_equal([{a: 1}, {c: 3}], dl)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1930
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1931 CheckDefExecFailure([
23523
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1932 'var ll = test_null_list()',
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1933 'unlet ll[0]',
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1934 ], 'E684:', 2)
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1935 CheckDefExecFailure([
23523
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1936 'var ll = [1]',
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1937 'unlet ll[2]',
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1938 ], 'E684:', 2)
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1939 CheckDefExecFailure([
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1940 'var ll = [1]',
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1941 'unlet ll[g:astring]',
23662
c761fcb89dfe patch 8.2.2373: Vim9: list assignment only accepts a number index
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
1942 ], 'E1012:', 2)
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1943 CheckDefExecFailure([
23523
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1944 'var dd = test_null_dict()',
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1945 'unlet dd["a"]',
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1946 ], 'E716:', 2)
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1947 CheckDefExecFailure([
23523
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1948 'var dd = {a: 1}',
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1949 'unlet dd["b"]',
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1950 ], 'E716:', 2)
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1951 CheckDefExecFailure([
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1952 'var dd = {a: 1}',
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1953 'unlet dd[g:alist]',
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1954 ], 'E1105:', 2)
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1955
23495
1f85acfb23cd patch 8.2.2290: Vim9: unlet of global variable cannot be compiled
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
1956 # can compile unlet before variable exists
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1957 g:someDict = {key: 'val'}
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1958 var k = 'key'
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1959 unlet g:someDict[k]
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1960 assert_equal({}, g:someDict)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1961 unlet g:someDict
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1962 assert_false(exists('g:someDict'))
23495
1f85acfb23cd patch 8.2.2290: Vim9: unlet of global variable cannot be compiled
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
1963
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1964 CheckScriptFailure([
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1965 'vim9script',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1966 'var svar = 123',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1967 'unlet svar',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1968 ], 'E1081:')
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1969 CheckScriptFailure([
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1970 'vim9script',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1971 'var svar = 123',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1972 'unlet s:svar',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1973 ], 'E1081:')
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1974 CheckScriptFailure([
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1975 'vim9script',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1976 'var svar = 123',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1977 'def Func()',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1978 ' unlet svar',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1979 'enddef',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1980 'defcompile',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1981 ], 'E1081:')
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1982 CheckScriptFailure([
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1983 'vim9script',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1984 'var svar = 123',
23223
98548b8fbc98 patch 8.2.2157: Vim9: can delete a Vim9 script variable from a function
Bram Moolenaar <Bram@vim.org>
parents: 23187
diff changeset
1985 'func Func()',
98548b8fbc98 patch 8.2.2157: Vim9: can delete a Vim9 script variable from a function
Bram Moolenaar <Bram@vim.org>
parents: 23187
diff changeset
1986 ' unlet s:svar',
98548b8fbc98 patch 8.2.2157: Vim9: can delete a Vim9 script variable from a function
Bram Moolenaar <Bram@vim.org>
parents: 23187
diff changeset
1987 'endfunc',
98548b8fbc98 patch 8.2.2157: Vim9: can delete a Vim9 script variable from a function
Bram Moolenaar <Bram@vim.org>
parents: 23187
diff changeset
1988 'Func()',
98548b8fbc98 patch 8.2.2157: Vim9: can delete a Vim9 script variable from a function
Bram Moolenaar <Bram@vim.org>
parents: 23187
diff changeset
1989 ], 'E1081:')
98548b8fbc98 patch 8.2.2157: Vim9: can delete a Vim9 script variable from a function
Bram Moolenaar <Bram@vim.org>
parents: 23187
diff changeset
1990 CheckScriptFailure([
98548b8fbc98 patch 8.2.2157: Vim9: can delete a Vim9 script variable from a function
Bram Moolenaar <Bram@vim.org>
parents: 23187
diff changeset
1991 'vim9script',
98548b8fbc98 patch 8.2.2157: Vim9: can delete a Vim9 script variable from a function
Bram Moolenaar <Bram@vim.org>
parents: 23187
diff changeset
1992 'var svar = 123',
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1993 'def Func()',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1994 ' unlet s:svar',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1995 'enddef',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1996 'defcompile',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1997 ], 'E1081:')
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1998
23523
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1999 writefile(['vim9script', 'export var svar = 1234'], 'XunletExport.vim')
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
2000 var lines =<< trim END
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
2001 vim9script
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
2002 import svar from './XunletExport.vim'
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
2003 def UnletSvar()
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
2004 unlet svar
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
2005 enddef
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
2006 defcompile
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
2007 END
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
2008 CheckScriptFailure(lines, 'E1081:', 1)
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
2009 delete('XunletExport.vim')
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
2010
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
2011 $ENVVAR = 'foobar'
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
2012 assert_equal('foobar', $ENVVAR)
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
2013 unlet $ENVVAR
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
2014 assert_equal('', $ENVVAR)
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
2015 enddef
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
2016
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
2017 def Test_expr_error_no_assign()
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
2018 var lines =<< trim END
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
2019 vim9script
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
2020 var x = invalid
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
2021 echo x
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
2022 END
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
2023 CheckScriptFailureList(lines, ['E121:', 'E121:'])
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
2024
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
2025 lines =<< trim END
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
2026 vim9script
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
2027 var x = 1 / 0
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
2028 echo x
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
2029 END
24555
83877a1b66fd patch 8.2.2817: Vim9: script sourcing continues after an error
Bram Moolenaar <Bram@vim.org>
parents: 24537
diff changeset
2030 CheckScriptFailure(lines, 'E1154:')
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
2031
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
2032 lines =<< trim END
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
2033 vim9script
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
2034 var x = 1 % 0
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
2035 echo x
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
2036 END
24555
83877a1b66fd patch 8.2.2817: Vim9: script sourcing continues after an error
Bram Moolenaar <Bram@vim.org>
parents: 24537
diff changeset
2037 CheckScriptFailure(lines, 'E1154:')
24238
e5cd25f7ffcd patch 8.2.2660: Vim9: no error for declaration with trailing text
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
2038
e5cd25f7ffcd patch 8.2.2660: Vim9: no error for declaration with trailing text
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
2039 lines =<< trim END
e5cd25f7ffcd patch 8.2.2660: Vim9: no error for declaration with trailing text
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
2040 var x: string 'string'
e5cd25f7ffcd patch 8.2.2660: Vim9: no error for declaration with trailing text
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
2041 END
e5cd25f7ffcd patch 8.2.2660: Vim9: no error for declaration with trailing text
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
2042 CheckDefAndScriptFailure(lines, 'E488:')
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
2043 enddef
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
2044
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
2045
23537
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
2046 def Test_assign_command_modifier()
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
2047 var lines =<< trim END
23549
4156f972efb1 patch 8.2.2317: Vim9: command modifier before list unpack doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
2048 var verbose = 0
4156f972efb1 patch 8.2.2317: Vim9: command modifier before list unpack doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
2049 verbose = 1
4156f972efb1 patch 8.2.2317: Vim9: command modifier before list unpack doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
2050 assert_equal(1, verbose)
4156f972efb1 patch 8.2.2317: Vim9: command modifier before list unpack doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
2051 silent verbose = 2
4156f972efb1 patch 8.2.2317: Vim9: command modifier before list unpack doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
2052 assert_equal(2, verbose)
4156f972efb1 patch 8.2.2317: Vim9: command modifier before list unpack doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
2053 silent verbose += 2
4156f972efb1 patch 8.2.2317: Vim9: command modifier before list unpack doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
2054 assert_equal(4, verbose)
4156f972efb1 patch 8.2.2317: Vim9: command modifier before list unpack doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
2055 silent verbose -= 1
4156f972efb1 patch 8.2.2317: Vim9: command modifier before list unpack doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
2056 assert_equal(3, verbose)
23537
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
2057
23549
4156f972efb1 patch 8.2.2317: Vim9: command modifier before list unpack doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
2058 var topleft = {one: 1}
4156f972efb1 patch 8.2.2317: Vim9: command modifier before list unpack doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
2059 sandbox topleft.one = 3
4156f972efb1 patch 8.2.2317: Vim9: command modifier before list unpack doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
2060 assert_equal({one: 3}, topleft)
4156f972efb1 patch 8.2.2317: Vim9: command modifier before list unpack doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
2061 leftabove topleft[' '] = 4
4156f972efb1 patch 8.2.2317: Vim9: command modifier before list unpack doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
2062 assert_equal({one: 3, ' ': 4}, topleft)
4156f972efb1 patch 8.2.2317: Vim9: command modifier before list unpack doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
2063
4156f972efb1 patch 8.2.2317: Vim9: command modifier before list unpack doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
2064 var x: number
4156f972efb1 patch 8.2.2317: Vim9: command modifier before list unpack doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
2065 var y: number
4156f972efb1 patch 8.2.2317: Vim9: command modifier before list unpack doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
2066 silent [x, y] = [1, 2]
4156f972efb1 patch 8.2.2317: Vim9: command modifier before list unpack doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
2067 assert_equal(1, x)
4156f972efb1 patch 8.2.2317: Vim9: command modifier before list unpack doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
2068 assert_equal(2, y)
23537
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
2069 END
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
2070 CheckDefAndScriptSuccess(lines)
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
2071 enddef
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
2072
24956
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24888
diff changeset
2073 def Test_assign_alt_buf_register()
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24888
diff changeset
2074 var lines =<< trim END
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24888
diff changeset
2075 edit 'file_b1'
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24888
diff changeset
2076 var b1 = bufnr()
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24888
diff changeset
2077 edit 'file_b2'
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24888
diff changeset
2078 var b2 = bufnr()
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24888
diff changeset
2079 assert_equal(b1, bufnr('#'))
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24888
diff changeset
2080 @# = b2
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24888
diff changeset
2081 assert_equal(b2, bufnr('#'))
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24888
diff changeset
2082 END
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24888
diff changeset
2083 CheckDefAndScriptSuccess(lines)
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24888
diff changeset
2084 enddef
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24888
diff changeset
2085
24264
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2086 def Test_script_funcref_case()
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2087 var lines =<< trim END
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2088 var Len = (s: string): number => len(s) + 1
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2089 assert_equal(5, Len('asdf'))
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2090 END
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2091 CheckDefAndScriptSuccess(lines)
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2092
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2093 lines =<< trim END
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2094 var len = (s: string): number => len(s) + 1
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2095 END
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2096 CheckDefAndScriptFailure(lines, 'E704:')
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2097
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2098 lines =<< trim END
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2099 vim9script
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2100 var s:Len = (s: string): number => len(s) + 2
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2101 assert_equal(6, Len('asdf'))
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2102 END
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2103 CheckScriptSuccess(lines)
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2104
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2105 lines =<< trim END
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2106 vim9script
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2107 var s:len = (s: string): number => len(s) + 1
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2108 END
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2109 CheckScriptFailure(lines, 'E704:')
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2110 enddef
db5eaad456cc patch 8.2.2673: Vim9: script-local funcref can have lower case name
Bram Moolenaar <Bram@vim.org>
parents: 24238
diff changeset
2111
24533
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2112 def Test_inc_dec()
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2113 var lines =<< trim END
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2114 var nr = 7
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2115 ++nr
24537
95bcea9faa52 patch 8.2.2808: Vim9: increment and decrement not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
2116 assert_equal(8, nr)
24533
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2117 --nr
24537
95bcea9faa52 patch 8.2.2808: Vim9: increment and decrement not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
2118 assert_equal(7, nr)
25020
91f396f149d5 patch 8.2.3047: increment and decrement don't allow for next command
Bram Moolenaar <Bram@vim.org>
parents: 24984
diff changeset
2119 ++nr | ++nr
91f396f149d5 patch 8.2.3047: increment and decrement don't allow for next command
Bram Moolenaar <Bram@vim.org>
parents: 24984
diff changeset
2120 assert_equal(9, nr)
91f396f149d5 patch 8.2.3047: increment and decrement don't allow for next command
Bram Moolenaar <Bram@vim.org>
parents: 24984
diff changeset
2121 ++nr # comment
91f396f149d5 patch 8.2.3047: increment and decrement don't allow for next command
Bram Moolenaar <Bram@vim.org>
parents: 24984
diff changeset
2122 assert_equal(10, nr)
24533
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2123
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2124 var ll = [1, 2]
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2125 --ll[0]
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2126 ++ll[1]
24537
95bcea9faa52 patch 8.2.2808: Vim9: increment and decrement not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
2127 assert_equal([0, 3], ll)
95bcea9faa52 patch 8.2.2808: Vim9: increment and decrement not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
2128
95bcea9faa52 patch 8.2.2808: Vim9: increment and decrement not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
2129 g:count = 1
95bcea9faa52 patch 8.2.2808: Vim9: increment and decrement not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
2130 ++g:count
95bcea9faa52 patch 8.2.2808: Vim9: increment and decrement not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
2131 --g:count
95bcea9faa52 patch 8.2.2808: Vim9: increment and decrement not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
2132 assert_equal(1, g:count)
95bcea9faa52 patch 8.2.2808: Vim9: increment and decrement not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
2133 unlet g:count
24533
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2134 END
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2135 CheckDefAndScriptSuccess(lines)
25022
39551b6e0112 patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents: 25020
diff changeset
2136
39551b6e0112 patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents: 25020
diff changeset
2137 lines =<< trim END
39551b6e0112 patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents: 25020
diff changeset
2138 var nr = 7
39551b6e0112 patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents: 25020
diff changeset
2139 ++ nr
39551b6e0112 patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents: 25020
diff changeset
2140 END
39551b6e0112 patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents: 25020
diff changeset
2141 CheckDefAndScriptFailure(lines, "E1202: No white space allowed after '++': ++ nr")
24533
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2142 enddef
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
2143
25400
5c7192180b89 patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents: 25274
diff changeset
2144 def Test_abort_after_error()
5c7192180b89 patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents: 25274
diff changeset
2145 # should abort after strpart() fails, not give another type error
5c7192180b89 patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents: 25274
diff changeset
2146 var lines =<< trim END
5c7192180b89 patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents: 25274
diff changeset
2147 vim9script
5c7192180b89 patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents: 25274
diff changeset
2148 var x: string
5c7192180b89 patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents: 25274
diff changeset
2149 x = strpart(1, 2)
5c7192180b89 patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents: 25274
diff changeset
2150 END
5c7192180b89 patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents: 25274
diff changeset
2151 writefile(lines, 'Xtestscript')
5c7192180b89 patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents: 25274
diff changeset
2152 var expected = 'E1174: String required for argument 1'
5c7192180b89 patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents: 25274
diff changeset
2153 assert_fails('so Xtestscript', [expected, expected], 3)
5c7192180b89 patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents: 25274
diff changeset
2154
5c7192180b89 patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents: 25274
diff changeset
2155 delete('Xtestscript')
5c7192180b89 patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents: 25274
diff changeset
2156 enddef
5c7192180b89 patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents: 25274
diff changeset
2157
5c7192180b89 patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents: 25274
diff changeset
2158
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
2159
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2160 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker