annotate src/testdir/test_vim9_assign.vim @ 23537:7f0fc2ab90e3 v8.2.2311

patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier Commit: https://github.com/vim/vim/commit/17126b13969c3b91516a8e9ff80fb6a1f6924d40 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 7 22:03:02 2021 +0100 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier Problem: Vim9: cannot assign to a variable that shadows a command modifier. Solution: Check for assignment after possible command modifier. (closes #7632)
author Bram Moolenaar <Bram@vim.org>
date Thu, 07 Jan 2021 22:15:05 +0100
parents f39a18a42aed
children 4156f972efb1
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]
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 let g:astring = 'text'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 def Test_assignment_bool()
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
15 var bool1: bool = true
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 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
17 var bool2: bool = false
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 assert_equal(v:false, bool2)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
20 var bool3: bool = 0
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 assert_equal(false, bool3)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
22 var bool4: bool = 1
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 assert_equal(true, bool4)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22458
diff changeset
25 var bool5: bool = 1 && true
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 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
27 var bool6: bool = 0 && 1
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 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
29 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
30 assert_equal(true, bool7)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
32 var lines =<< trim END
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 vim9script
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 def GetFlag(): bool
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
35 var flag: bool = 1
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 return flag
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 enddef
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
38 var flag: bool = GetFlag()
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 assert_equal(true, flag)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 flag = 0
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 assert_equal(false, flag)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 flag = 1
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 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
44 flag = 1 || true
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 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
46 flag = 1 && false
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 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
48
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
49 var cp: bool = &cp
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
50 var fen: bool = &l:fen
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 CheckScriptSuccess(lines)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
53 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
54 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
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 = {}'], '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 = "x"'], 'E1012:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 def Test_syntax()
22433
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
61 var name = 234
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
62 var other: list<string> = ['asdf']
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 def Test_assignment()
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
66 CheckDefFailure(['var x:string'], 'E1069:')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
67 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
68 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
69 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
70 CheckScriptFailure(['var x = "x"'], 'E1124:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
72 var nr: number = 1234
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
73 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
74
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
75 var a: number = 6 #comment
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 assert_equal(6, a)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 if has('channel')
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
79 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
80 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
81
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
82 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
83 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
84
22582
a3df1fb28d44 patch 8.2.1839: Vim9: memory leaks reported in assign test
Bram Moolenaar <Bram@vim.org>
parents: 22545
diff changeset
85 # 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
86 endif
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 if has('float')
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
88 var float1: float = 3.4
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 endif
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
90 var Funky1: func
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
91 var Funky2: func = function('len')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
92 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
93
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 g:newvar = 'new' #comment
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 assert_equal('new', g:newvar)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 assert_equal('yes', g:existing)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 g:existing = 'no'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 assert_equal('no', g:existing)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 v:char = 'abc'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 assert_equal('abc', v:char)
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 $ENVVAR = 'foobar'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 assert_equal('foobar', $ENVVAR)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 $ENVVAR = ''
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
108 var lines =<< trim END
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 vim9script
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 $ENVVAR = 'barfoo'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 assert_equal('barfoo', $ENVVAR)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 $ENVVAR = ''
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 CheckScriptSuccess(lines)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 s:appendToMe ..= 'yyy'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 assert_equal('xxxyyy', s:appendToMe)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 s:addToMe += 222
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 assert_equal(333, s:addToMe)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 s:newVar = 'new'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 assert_equal('new', s:newVar)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 set ts=7
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
124 var ts: number = &ts
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23338
diff changeset
125 assert_equal(7, ts)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 &ts += 1
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 assert_equal(8, &ts)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 &ts -= 3
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 assert_equal(5, &ts)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 &ts *= 2
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 assert_equal(10, &ts)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 &ts /= 3
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 assert_equal(3, &ts)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 set ts=10
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 &ts %= 4
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 assert_equal(2, &ts)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 if has('float')
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
139 var f100: float = 100.0
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 f100 /= 5
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 assert_equal(20.0, f100)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
143 var f200: float = 200.0
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 f200 /= 5.0
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 assert_equal(40.0, f200)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
147 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
148 endif
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 lines =<< trim END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 &ts = 6
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 &ts += 3
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 assert_equal(9, &ts)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 &l:ts = 6
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 assert_equal(6, &ts)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 &l:ts += 2
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 assert_equal(8, &ts)
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 &g:ts = 6
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 assert_equal(6, &g:ts)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 &g:ts += 2
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 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
164
18f3dc6974af patch 8.2.2297: Vim9: cannot set 'number' to a boolean value
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
165 &number = true
18f3dc6974af patch 8.2.2297: Vim9: cannot set 'number' to a boolean value
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
166 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
167 &number = 0
18f3dc6974af patch 8.2.2297: Vim9: cannot set 'number' to a boolean value
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
168 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
169 &number = 1
18f3dc6974af patch 8.2.2297: Vim9: cannot set 'number' to a boolean value
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
170 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
171 &number = false
18f3dc6974af patch 8.2.2297: Vim9: cannot set 'number' to a boolean value
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
172 assert_equal(false, &number)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 CheckDefAndScriptSuccess(lines)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 CheckDefFailure(['&notex += 3'], 'E113:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 CheckDefFailure(['&ts ..= "xxx"'], 'E1019:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 CheckDefFailure(['&ts = [7]'], 'E1012:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 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
180 CheckDefFailure(['&ts = "xx"'], 'E1012:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 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
182 CheckDefFailure(['&path += 3'], 'E1012:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 CheckDefExecFailure(['&bs = "asdf"'], 'E474:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 # test freeing ISN_STOREOPT
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
185 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
186 &ts = 8
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 lines =<< trim END
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
189 var save_TI = &t_TI
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 &t_TI = ''
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 assert_equal('', &t_TI)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 &t_TI = 'xxx'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 assert_equal('xxx', &t_TI)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 &t_TI = save_TI
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 CheckDefAndScriptSuccess(lines)
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 CheckDefFailure(['&t_TI = 123'], 'E1012:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 CheckScriptFailure(['vim9script', '&t_TI = 123'], 'E928:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
201 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
202 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
203
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 lines =<< trim END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 vim9script
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 def SomeFunc()
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 s:var = 123
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 defcompile
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 CheckScriptFailure(lines, 'E1089:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 g:inc_counter += 1
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 assert_equal(2, g:inc_counter)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 $SOME_ENV_VAR ..= 'more'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 assert_equal('somemore', $SOME_ENV_VAR)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 CheckDefFailure(['$SOME_ENV_VAR += "more"'], 'E1051:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 CheckDefFailure(['$SOME_ENV_VAR += 123'], 'E1012:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 lines =<< trim END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 @c = 'areg'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 @c ..= 'add'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 assert_equal('aregadd', @c)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 CheckDefAndScriptSuccess(lines)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 CheckDefFailure(['@a += "more"'], 'E1051:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 CheckDefFailure(['@a += 123'], 'E1012:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 v:errmsg = 'none'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 v:errmsg ..= 'again'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 assert_equal('noneagain', v:errmsg)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 CheckDefFailure(['v:errmsg += "more"'], 'E1051:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 CheckDefFailure(['v:errmsg += 123'], 'E1012:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236
22582
a3df1fb28d44 patch 8.2.1839: Vim9: memory leaks reported in assign test
Bram Moolenaar <Bram@vim.org>
parents: 22545
diff changeset
237 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
238 some text
a3df1fb28d44 patch 8.2.1839: Vim9: memory leaks reported in assign test
Bram Moolenaar <Bram@vim.org>
parents: 22545
diff changeset
239 END
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241
23122
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
242 def Test_assign_unpack()
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
243 var lines =<< trim END
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
244 var v1: number
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
245 var v2: number
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
246 [v1, v2] = [1, 2]
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
247 assert_equal(1, v1)
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
248 assert_equal(2, v2)
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
249 END
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
250 CheckDefAndScriptSuccess(lines)
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
251
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
252 lines =<< trim END
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
253 var v1: number
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
254 var v2: number
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
255 [v1, v2] =
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
256 END
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
257 CheckDefFailure(lines, 'E1097:', 5)
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
258
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
259 lines =<< trim END
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
260 var v1: number
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
261 var v2: number
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
262 [v1, v2] = xxx
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
263 END
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
264 CheckDefFailure(lines, 'E1001:', 3)
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
265
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
266 lines =<< trim END
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
267 var v1: number
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
268 var v2: number
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
269 [v1, v2] = popup_clear()
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
270 END
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
271 CheckDefFailure(lines, 'E1031:', 3)
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
272
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
273 lines =<< trim END
23450
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
274 [v1, v2] = [1, 2]
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
275 END
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
276 CheckDefFailure(lines, 'E1089', 1)
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
277 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
278
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
279 lines =<< trim END
23122
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
280 var v1: number
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
281 var v2: number
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
282 [v1, v2] = ''
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
283 END
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
284 CheckDefFailure(lines, 'E1012: Type mismatch; expected list<any> but got string', 3)
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
285 enddef
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
286
23070
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
287 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
288 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
289 nr =
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
290 123
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
291 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
292
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
293 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
294 [nr, n2] =
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
295 [12, 34]
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
296 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
297 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
298
23122
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
299 CheckDefFailure(["var x = #"], 'E1097:', 3)
23070
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
300 enddef
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
301
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
302 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
303 # list of list
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
304 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
305 l1[0] = 123
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
306 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
307
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
308 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
309 l2[0] = []
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
310 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
311 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
312
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
313 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
314 l3[0] = []
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
315 l3[0][0] = []
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
316 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
317 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
318
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
319 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
320 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
321 l3[0] = []
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
322 l3[0][0] = []
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
323 END
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
324 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
325
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
326 # dict of dict
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
327 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
328 d1.one = 1
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
329 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
330
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
331 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
332 d2.one = {}
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
333 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
334 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
335
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
336 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
337 d3.one = {}
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
338 d3.one.two = {}
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
339 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
340 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
341
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
342 lines =<< trim END
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
343 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
344 d3.one = {}
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
345 d3.one.two = {}
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
346 END
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
347 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
348
23187
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
349 lines =<< trim END
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
350 var lines: list<string>
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
351 lines['a'] = 'asdf'
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
352 END
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
353 CheckDefFailure(lines, 'E39:', 2)
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
354
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
355 lines =<< trim END
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
356 var lines: string
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
357 lines[9] = 'asdf'
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
358 END
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
359 CheckDefFailure(lines, 'E1141:', 2)
013aa8e2be8c patch 8.2.2139: Vim9: unreachable code in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23185
diff changeset
360
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
361 # list of dict
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
362 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
363 ld[0] = {}
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
364 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
365 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
366
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
367 lines =<< trim END
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
368 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
369 ld[0] = []
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
370 END
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
371 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
372
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
373 # dict of list
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
374 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
375 dl.one = []
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
376 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
377 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
378
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
379 lines =<< trim END
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
380 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
381 dl.one = {}
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
382 END
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
383 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
384 enddef
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
385
22365
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
386 def Test_extend_list()
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
387 var lines =<< trim END
22365
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
388 vim9script
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
389 var l: list<number>
22365
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
390 l += [123]
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
391 assert_equal([123], l)
22802
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
392 END
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
393 CheckScriptSuccess(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
394
22802
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
395 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
396 vim9script
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
397 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
398 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
399 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
400 END
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
401 CheckScriptSuccess(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
402
47596deedfb5 patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
403 # 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
404 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
405 vim9script
47596deedfb5 patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
406 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
407 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
408 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
409 enddef
47596deedfb5 patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
410 Func()
47596deedfb5 patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
411 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
412 END
47596deedfb5 patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
413 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
414 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
415 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
416 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
417 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
418 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
419 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
420 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
421 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
422 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
423 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
424
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
425 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
426 vim9script
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
427 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
428 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
429 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
430 END
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
431 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
432
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
433 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
434 vim9script
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
435 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
436 END
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
437 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
438 enddef
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
439
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
440 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
441 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
442 vim9script
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
443 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
444 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
445 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
446
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
447 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
448 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
449 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
450 END
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
451 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
452
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
453 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
454 vim9script
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
455 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
456 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
457 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
458 END
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
459 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
460
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
461 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
462 vim9script
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
463 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
464 END
3e0f909ca1f2 patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
465 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
466 enddef
a4866826cebc patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
467
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 def Test_single_letter_vars()
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 # single letter variables
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
470 var a: number = 123
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 a = 123
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 assert_equal(123, a)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
473 var b: number
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 b = 123
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 assert_equal(123, b)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
476 var g: number
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 g = 123
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 assert_equal(123, g)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
479 var s: number
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 s = 123
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 assert_equal(123, s)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
482 var t: number
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 t = 123
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 assert_equal(123, t)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
485 var v: number
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 v = 123
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 assert_equal(123, v)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
488 var w: number
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 w = 123
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 assert_equal(123, w)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 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
494 var lines =<< trim END
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 vim9script
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 # 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
498 var a: string
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
499 var b: number
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
500 var l: list<any>
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
501 var s: string
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
502 var t: number
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
503 var v: number
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
504 var w: number
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 # 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
507 a = 'script-a'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 b = 111
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 l = [1, 2, 3]
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 s = 'script-s'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 t = 222
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 v = 333
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 w = 444
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 assert_equal('script-a', a)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 assert_equal(111, b)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 assert_equal([1, 2, 3], l)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 assert_equal('script-s', s)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 assert_equal(222, t)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 assert_equal(333, v)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 assert_equal(444, w)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 writefile(lines, 'Xsinglechar')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 source Xsinglechar
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 delete('Xsinglechar')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 def Test_assignment_list()
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
529 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
530 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
531 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
532 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
533 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
534
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
535 var listS: list<string> = []
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
536 var listN: list<number> = []
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 assert_equal([1, 2, 3], list2)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 list2[-1] = 99
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 assert_equal([1, 2, 99], list2)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 list2[-2] = 88
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 assert_equal([1, 88, 99], list2)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 list2[-3] = 77
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 assert_equal([77, 88, 99], list2)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 list2 += [100]
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 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
547
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 list3 += ['end']
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 assert_equal(['sdf', 'asdf', 'end'], list3)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
551 CheckDefExecFailure(['var ll = [1, 2, 3]', 'll[-4] = 6'], 'E684:')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
552 CheckDefExecFailure(['var [v1, v2] = [1, 2]'], 'E1092:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 # type becomes list<any>
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
555 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
556
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
557 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
558 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
559 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
560 END
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
561 CheckDefExecFailure(lines, 'E1147:', 2)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 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
565 var lines =<< trim END
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 vim9script
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
567 var v1: number
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
568 var v2: number
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
569 var v3: number
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 [v1, v2, v3] = [1, 2, 3]
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 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
572 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 CheckScriptSuccess(lines)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 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
577 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
578 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
579 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
580 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
581 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
582
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 # overwrite
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 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
585 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
586 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
587 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
588
23245
ac934fbacc0e patch 8.2.2168: Vim9: error for assigning to dict of dict
Bram Moolenaar <Bram@vim.org>
parents: 23243
diff changeset
589 # 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
590 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
591 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
592 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
593 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
594
22906
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22802
diff changeset
595 var lines =<< trim END
23243
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
596 var dd = {}
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
597 dd.two = 2
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
598 assert_equal({two: 2}, dd)
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
599 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
600 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
601
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
602 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
603 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
604 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
605 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
606 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
607 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
608 END
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
609 CheckDefAndScriptSuccess(lines)
23243
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
610
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
611 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
612 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
613 dd.one) = 2
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22802
diff changeset
614 END
23243
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
615 CheckDefFailure(lines, 'E488:', 2)
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
616
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
617 lines =<< trim END
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
618 var dd = {one: 1}
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
619 var dd.one = 2
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
620 END
0804cb073097 patch 8.2.2167: Vim9: assign test fails
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
621 CheckDefAndScriptFailure(lines, 'E1017:', 2)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 # 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
624 var dd = {}
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 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
626 assert_equal({['']: 6}, dd)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 # 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
629 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
630
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 # 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
632 lines =<< trim END
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 vim9script
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
634 var test: dict<any> = {}
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 def FillDict(): dict<any>
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 test['a'] = 43
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 return test
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 enddef
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
639 assert_equal({a: 43}, FillDict())
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 CheckScriptSuccess(lines)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 lines =<< trim END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 vim9script
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
645 var test: dict<any>
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 def FillDict(): dict<any>
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 test['a'] = 43
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 return test
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 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
651 assert_equal({a: 43}, test)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 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
653 CheckScriptSuccess(lines)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 # assignment to global dict
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 lines =<< trim END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 vim9script
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 g:test = {}
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 def FillDict(): dict<any>
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 g:test['a'] = 43
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 return g:test
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 enddef
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
663 assert_equal({a: 43}, FillDict())
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 CheckScriptSuccess(lines)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 # assignment to buffer dict
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 lines =<< trim END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 vim9script
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 b:test = {}
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 def FillDict(): dict<any>
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 b:test['a'] = 43
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 return b:test
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 enddef
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
675 assert_equal({a: 43}, FillDict())
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 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
678
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
679 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
680 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
681 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
682 END
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
683 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
684
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
685 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
686 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
687 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
688 END
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
689 CheckDefExecFailure(lines, 'E1148:', 2)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 def Test_assignment_local()
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 # 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
694 # changed.
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
695 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
696 let b:existing = 'yes'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 let w:existing = 'yes'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 let t:existing = 'yes'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 def Test_assignment_local_internal()
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 b:newvar = 'new'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 assert_equal('new', b:newvar)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 assert_equal('yes', b:existing)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 b:existing = 'no'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 assert_equal('no', b:existing)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 b:existing ..= 'NO'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 assert_equal('noNO', b:existing)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 w:newvar = 'new'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 assert_equal('new', w:newvar)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 assert_equal('yes', w:existing)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 w:existing = 'no'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 assert_equal('no', w:existing)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 w:existing ..= 'NO'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 assert_equal('noNO', w:existing)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 t:newvar = 'new'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 assert_equal('new', t:newvar)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 assert_equal('yes', t:existing)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 t:existing = 'no'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 assert_equal('no', t:existing)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 t:existing ..= 'NO'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 assert_equal('noNO', t:existing)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 call Test_assignment_local_internal()
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 CheckScriptSuccess(script_lines)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 def Test_assignment_default()
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 # Test default values.
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
732 var thebool: bool
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 assert_equal(v:false, thebool)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
735 var thenumber: number
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 assert_equal(0, thenumber)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 if has('float')
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
739 var thefloat: float
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 assert_equal(0.0, thefloat)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 endif
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
743 var thestring: string
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 assert_equal('', thestring)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
746 var theblob: blob
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 assert_equal(0z, theblob)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
749 var Thefunc: func
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 assert_equal(test_null_function(), Thefunc)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
752 var thelist: list<any>
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 assert_equal([], thelist)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
755 var thedict: dict<any>
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 assert_equal({}, thedict)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 if has('channel')
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
759 var thejob: job
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 assert_equal(test_null_job(), thejob)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
762 var thechannel: channel
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 assert_equal(test_null_channel(), thechannel)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 if has('unix') && executable('cat')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 # 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
767 thejob = job_start("cat ", {})
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 thechannel = job_getchannel(thejob)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 job_stop(thejob, 'kill')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 endif
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 endif
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
773 var nr = 1234 | nr = 5678
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 assert_equal(5678, nr)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776
23450
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
777 let scriptvar = 'init'
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
778
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 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
780 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
781 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
782 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
783 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
784 [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
785 assert_equal('aaa', v1)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786
23050
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
787 [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
788 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
789 assert_equal('two', v2)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790
23050
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
791 [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
792 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
793 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
794 assert_equal([], vrem)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795
23050
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
796 [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
797 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
798 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
799 assert_equal(['three'], vrem)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800
23050
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
801 [&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
802 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
803 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
804 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
805
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23050
diff changeset
806 [@a, @z] = ['aa', 'zz']
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23050
diff changeset
807 assert_equal('aa', @a)
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23050
diff changeset
808 assert_equal('zz', @z)
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23050
diff changeset
809
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23050
diff changeset
810 [$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
811 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
812 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
813
23450
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
814 [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
815 ['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
816 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
817 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
818 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
819 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
820 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
821 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
822 END
50442f932ff7 patch 8.2.2071: Vim9: list assign doesn't except empty remainder list
Bram Moolenaar <Bram@vim.org>
parents: 23039
diff changeset
823 CheckDefAndScriptSuccess(lines)
23450
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
824
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
825 [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
826 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
827 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
828 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
829
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
830 lines =<< trim END
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
831 vim9script
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
832 var s:scriptvar = 'init'
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
833 [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
834 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
835 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
836 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
837 END
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
838 CheckScriptSuccess(lines)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 def Test_assignment_vim9script()
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
842 var lines =<< trim END
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 vim9script
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 def Func(): list<number>
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 return [1, 2]
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 enddef
22433
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
847 var name1: number
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
848 var name2: number
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
849 [name1, name2] =
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 Func()
22433
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
851 assert_equal(1, name1)
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
852 assert_equal(2, name2)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
853 var ll =
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 Func()
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 assert_equal([1, 2], ll)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 @/ = 'text'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 assert_equal('text', @/)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 @0 = 'zero'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 assert_equal('zero', @0)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 @1 = 'one'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 assert_equal('one', @1)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 @9 = 'nine'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 assert_equal('nine', @9)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 @- = 'minus'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 assert_equal('minus', @-)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 if has('clipboard_working')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 @* = 'star'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 assert_equal('star', @*)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 @+ = 'plus'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 assert_equal('plus', @+)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 endif
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
874 var a: number = 123
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 assert_equal(123, a)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
876 var s: string = 'yes'
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 assert_equal('yes', s)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
878 var b: number = 42
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 assert_equal(42, b)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
880 var w: number = 43
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 assert_equal(43, w)
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
882 var t: number = 44
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 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
884
08e2363fd0de patch 8.2.1853: "to_f" is recognized at "topleft" modifier
Bram Moolenaar <Bram@vim.org>
parents: 22582
diff changeset
885 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
886 to_var = 3
08e2363fd0de patch 8.2.1853: "to_f" is recognized at "topleft" modifier
Bram Moolenaar <Bram@vim.org>
parents: 22582
diff changeset
887 assert_equal(3, to_var)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 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
890
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
891 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
892 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
893 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
894 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
895 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
896 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
897 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
898 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
899 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
900 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 def Mess(): string
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 v:foldstart = 123
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 return 'xxx'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 enddef
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 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
908 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
909 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
910 CheckDefFailure(['var name= 234'], 'E1004:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911
22433
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
912 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
913 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
914 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
915 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
916 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
917 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
918 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
919 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
920
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
921 CheckDefFailure(['var true = 1'], 'E1034:')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
922 CheckDefFailure(['var false = 1'], 'E1034:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 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
925 CheckDefExecFailure(['var a: number',
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 '[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
927 CheckDefExecFailure(['var a: number',
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 '[a] = []'], 'E1093:')
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
929 CheckDefExecFailure(['var x: number',
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
930 'var y: number',
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 '[x, y] = [1]'], 'E1093:')
22621
576a69fc0066 patch 8.2.1859: Vim9: crash in unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 22618
diff changeset
932 CheckDefExecFailure(['var x: string',
576a69fc0066 patch 8.2.1859: Vim9: crash in unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 22618
diff changeset
933 'var y: string',
576a69fc0066 patch 8.2.1859: Vim9: crash in unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 22618
diff changeset
934 '[x, y] = ["x"]'], 'E1093:')
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
935 CheckDefExecFailure(['var x: number',
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
936 'var y: number',
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
937 'var z: list<number>',
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 '[x, y; z] = [1]'], 'E1093:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
940 CheckDefFailure(['var somevar'], "E1022:")
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
941 CheckDefFailure(['var &tabstop = 4'], 'E1052:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 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
943 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
944
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
945 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
946 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
947
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 if has('dnd')
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
949 CheckDefFailure(['var @~ = 5'], 'E1066:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 else
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
951 CheckDefFailure(['var @~ = 5'], 'E354:')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 CheckDefFailure(['@~ = 5'], 'E354:')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 endif
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
954 CheckDefFailure(['var @a = 5'], 'E1066:')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
955 CheckDefFailure(['var @/ = "x"'], 'E1066:')
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
956 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
957
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
958 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
959 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
960 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
961 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
962
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
963 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
964 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
965 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
966 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
967 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
968
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
969 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
970
22433
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
971 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
972 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
973
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
974 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
975 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
976
22433
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
977 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
978 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
979
22433
8b5e2f9580db patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
980 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
981 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
982
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 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
984 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
985
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 CheckDefFailure(['w:foo: number = 10'],
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 'E488: Trailing characters: : number = 1')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 CheckDefFailure(['t:foo: bool = true'],
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 'E488: Trailing characters: : bool = true')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 CheckDefFailure(['b:foo: string = "x"'],
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 'E488: Trailing characters: : string = "x"')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 CheckDefFailure(['g:foo: number = 123'],
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 'E488: Trailing characters: : number = 123')
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 def Test_assign_list()
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
997 var l: list<string> = []
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 l[0] = 'value'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 assert_equal('value', l[0])
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 l[1] = 'asdf'
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 assert_equal('value', l[0])
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 assert_equal('asdf', l[1])
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 assert_equal('asdf', l[-1])
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 assert_equal('value', l[-2])
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1007 var nrl: list<number> = []
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 for i in range(5)
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 nrl[i] = i
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 endfor
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 assert_equal([0, 1, 2, 3, 4], nrl)
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22621
diff changeset
1012
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22621
diff changeset
1013 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
1014 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
1015 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 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
1018 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
1019 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
1020 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
1021 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
1022
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1023 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
1024 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
1025 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
1026
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1027 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
1028 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
1029 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
1030 endfor
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1031 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
1032
23448
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1033 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
1034 assert_equal({key: 'value', '123': 'qwerty', somekey: 'someval'}, d)
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1035 # unlet d.somekey
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1036 # assert_equal({key: 'value', '123': 'qwerty'}, d)
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1037 END
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1038 CheckDefAndScriptSuccess(lines)
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039
23448
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1040 # TODO: move to above once "unlet d.somekey" in :def is implemented
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1041 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
1042 vim9script
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1043 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
1044 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
1045 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
1046 assert_equal({key: 'value', somekey: 'someval'}, d)
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1047 unlet d.somekey
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1048 assert_equal({key: 'value'}, d)
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1049 END
8f31b990ab1e patch 8.2.2267: Vim9: cannot use unlet for a dict member
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
1050 CheckScriptSuccess(lines)
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22621
diff changeset
1051
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
1052 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
1053 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
1054 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055
22363
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22351
diff changeset
1056 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
1057 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
1058 vim9script
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1059 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
1060 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
1061 def Func()
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22365
diff changeset
1062 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
1063 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
1064 enddef
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22351
diff changeset
1065 Func()
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22351
diff changeset
1066 END
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22351
diff changeset
1067 CheckScriptSuccess(lines)
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22351
diff changeset
1068
23039
75241f4377a4 patch 8.2.2066: Vim9: assignment with += doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
1069 lines =<< trim END
75241f4377a4 patch 8.2.2066: Vim9: assignment with += doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
1070 vim9script
75241f4377a4 patch 8.2.2066: Vim9: assignment with += doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
1071 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
1072 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
1073 def Func()
75241f4377a4 patch 8.2.2066: Vim9: assignment with += doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
1074 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
1075 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
1076 enddef
75241f4377a4 patch 8.2.2066: Vim9: assignment with += doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
1077 Func()
75241f4377a4 patch 8.2.2066: Vim9: assignment with += doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
1078 END
75241f4377a4 patch 8.2.2066: Vim9: assignment with += doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
1079 CheckScriptSuccess(lines)
22363
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22351
diff changeset
1080 enddef
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22351
diff changeset
1081
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 def Test_assign_lambda()
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 # 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
1084 var lines =<< trim END
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 vim9script
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
1086 var FuncRef = () => 123
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 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
1088 var FuncRef_Func: func = () => 123
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 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
1090 var FuncRef_Any: any = () => 123
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 assert_equal(123, FuncRef_Any())
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 END
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 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
1094
f39a18a42aed patch 8.2.2308: Vim9: no error when assigning lambda to funcref
Bram Moolenaar <Bram@vim.org>
parents: 23523
diff changeset
1095 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
1096 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
1097 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
1098 END
f39a18a42aed patch 8.2.2308: Vim9: no error when assigning lambda to funcref
Bram Moolenaar <Bram@vim.org>
parents: 23523
diff changeset
1099 CheckDefFailure(lines, 'E1012: Type mismatch; expected func(number) but got func(any): bool')
f39a18a42aed patch 8.2.2308: Vim9: no error when assigning lambda to funcref
Bram Moolenaar <Bram@vim.org>
parents: 23523
diff changeset
1100 CheckScriptFailure(['vim9script'] + lines, 'E1012: Type mismatch; expected func(number) but got func(any): any')
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 enddef
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102
22413
66d1131a7eff patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
1103 def Test_heredoc()
66d1131a7eff patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
1104 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
1105 text
66d1131a7eff patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
1106 END
66d1131a7eff patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
1107 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
1108
66d1131a7eff patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
1109 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
1110 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
1111
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1112 lines =<< trim [END]
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1113 def Func()
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1114 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
1115 x
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1116 x
23185
055fa9db6f39 patch 8.2.2138: Vim9: "exit_cb" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1117 enddef
055fa9db6f39 patch 8.2.2138: Vim9: "exit_cb" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1118 defcompile
055fa9db6f39 patch 8.2.2138: Vim9: "exit_cb" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1119 [END]
055fa9db6f39 patch 8.2.2138: Vim9: "exit_cb" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1120 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
1121 delfunc! g:Func
055fa9db6f39 patch 8.2.2138: Vim9: "exit_cb" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1122
055fa9db6f39 patch 8.2.2138: Vim9: "exit_cb" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1123 lines =<< trim [END]
055fa9db6f39 patch 8.2.2138: Vim9: "exit_cb" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1124 def Func()
055fa9db6f39 patch 8.2.2138: Vim9: "exit_cb" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1125 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
1126 x
055fa9db6f39 patch 8.2.2138: Vim9: "exit_cb" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1127 x
22423
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1128 x
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1129 x
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1130 x
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1131 x
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1132 x
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1133 x
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1134 enddef
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1135 call Func()
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22413
diff changeset
1136 [END]
23185
055fa9db6f39 patch 8.2.2138: Vim9: "exit_cb" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1137 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
1138 delfunc! g:Func
22413
66d1131a7eff patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
1139 enddef
66d1131a7eff patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
1140
23124
f8cd5a5e03c4 patch 8.2.2108: Vim9: no test to check for :let error
Bram Moolenaar <Bram@vim.org>
parents: 23122
diff changeset
1141 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
1142 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
1143 vim9script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1144 func GetValue()
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1145 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
1146 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
1147 else
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1148 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
1149 endif
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1150 return 'this'
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1151 endfunc
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1152 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
1153 # 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
1154 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
1155 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1156 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
1157 source Xfinished
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1158 # 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
1159 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
1160
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1161 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
1162 delete('Xfinished')
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1163 enddef
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1164
23124
f8cd5a5e03c4 patch 8.2.2108: Vim9: no test to check for :let error
Bram Moolenaar <Bram@vim.org>
parents: 23122
diff changeset
1165 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
1166 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
1167 vim9script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1168 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
1169 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1170 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
1171
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1172 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
1173 vim9script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1174 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
1175 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
1176 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1177 CheckScriptSuccess(lines)
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1178 enddef
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1179
23124
f8cd5a5e03c4 patch 8.2.2108: Vim9: no test to check for :let error
Bram Moolenaar <Bram@vim.org>
parents: 23122
diff changeset
1180 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
1181 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
1182 vim9script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1183 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
1184 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
1185 name = 'text'
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1186 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
1187 # 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
1188 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
1189 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
1190
23138
1a9705075244 patch 8.2.2115: Vim9: some errors not tested for; dead code
Bram Moolenaar <Bram@vim.org>
parents: 23124
diff changeset
1191 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
1192 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
1193 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
1194 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
1195 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
1196 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
1197 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
1198 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
1199
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1200 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
1201 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
1202 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
1203 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
1204 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
1205 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
1206 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
1207 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
1208
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1209 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
1210 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
1211 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
1212 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
1213 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
1214 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
1215 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
1216 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
1217
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1218 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
1219 other = 1234
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1220 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
1221
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1222 # type is inferred
23450
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23448
diff changeset
1223 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
1224 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
1225 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
1226 enddef
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1227 GetDictVal('a')
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1228 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1229 CheckScriptSuccess(lines)
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1230 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
1231 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
1232 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
1233 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
1234 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
1235
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1236 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
1237 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
1238 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
1239 unlet g:other_var
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
1240 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
1241 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
1242 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
1243 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
1244 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
1245 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
1246 enddef
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1247
23124
f8cd5a5e03c4 patch 8.2.2108: Vim9: no test to check for :let error
Bram Moolenaar <Bram@vim.org>
parents: 23122
diff changeset
1248 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
1249 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
1250 vim9script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1251 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
1252 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1253 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
1254
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1255 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
1256 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
1257 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
1258 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
1259 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
1260 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
1261 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
1262
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1263 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
1264 vim9script
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1265 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
1266 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
1267 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
1268 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
1269 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
1270
40f1d3f0c53e patch 8.2.2194: Vim9: cannot use :const or :final at the script level
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1271 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
1272 vim9script
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1273 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
1274 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1275 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
1276
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1277 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
1278 vim9script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1279 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
1280 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1281 CheckScriptFailure(lines, 'E475:')
23138
1a9705075244 patch 8.2.2115: Vim9: some errors not tested for; dead code
Bram Moolenaar <Bram@vim.org>
parents: 23124
diff changeset
1282
1a9705075244 patch 8.2.2115: Vim9: some errors not tested for; dead code
Bram Moolenaar <Bram@vim.org>
parents: 23124
diff changeset
1283 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
1284 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
1285 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
1286 enddef
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1287
23124
f8cd5a5e03c4 patch 8.2.2108: Vim9: no test to check for :let error
Bram Moolenaar <Bram@vim.org>
parents: 23122
diff changeset
1288 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
1289 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
1290 vim9script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1291 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
1292 name = 1234
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1293 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1294 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
1295
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1296 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
1297 vim9script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1298 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
1299 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1300 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
1301
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1302 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
1303 vim9script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1304 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
1305 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1306 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
1307
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1308 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
1309 vim9script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1310 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
1311 s:l = []
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1312 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1313 CheckScriptSuccess(lines)
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1314
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1315 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
1316 vim9script
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1317 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
1318 s:d = {}
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1319 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1320 CheckScriptSuccess(lines)
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1321 enddef
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1322
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1323 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
1324
23124
f8cd5a5e03c4 patch 8.2.2108: Vim9: no test to check for :let error
Bram Moolenaar <Bram@vim.org>
parents: 23122
diff changeset
1325 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
1326 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
1327 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
1328 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
1329
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1330 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
1331 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
1332 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
1333
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1334 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
1335 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
1336 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
1337 END
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1338 CheckDefExecFailure(lines, 'E1012: Type mismatch; expected list<number> but got list<string>')
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1339 enddef
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1340
23124
f8cd5a5e03c4 patch 8.2.2108: Vim9: no test to check for :let error
Bram Moolenaar <Bram@vim.org>
parents: 23122
diff changeset
1341 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
1342 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
1343 enddef
f8cd5a5e03c4 patch 8.2.2108: Vim9: no test to check for :let error
Bram Moolenaar <Bram@vim.org>
parents: 23122
diff changeset
1344
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1345 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
1346 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
1347 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
1348 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
1349 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
1350 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
1351
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1352 # 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
1353 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
1354 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
1355 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
1356 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
1357 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
1358
23523
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1359 CheckDefExecFailure([
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1360 '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
1361 'unlet dd',
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1362 ], 'E1081:', 2)
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1363
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1364 # dict unlet
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1365 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
1366 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
1367 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
1368 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
1369
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1370 # list unlet
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1371 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
1372 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
1373 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
1374 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
1375
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1376 # 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
1377 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
1378 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
1379 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
1380
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1381 CheckDefExecFailure([
23523
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1382 '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
1383 '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
1384 ], '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
1385 CheckDefExecFailure([
23523
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1386 '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
1387 '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
1388 ], 'E684:', 2)
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1389 CheckDefExecFailure([
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1390 '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
1391 'unlet ll[g:astring]',
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1392 ], 'E39:', 2)
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23509
diff changeset
1393 CheckDefExecFailure([
23523
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1394 '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
1395 '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
1396 ], '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
1397 CheckDefExecFailure([
23523
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1398 '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
1399 '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
1400 ], 'E716:', 2)
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1401 CheckDefExecFailure([
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1402 '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
1403 '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
1404 ], '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
1405
23495
1f85acfb23cd patch 8.2.2290: Vim9: unlet of global variable cannot be compiled
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
1406 # 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
1407 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
1408 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
1409 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
1410 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
1411 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
1412 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
1413
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1414 CheckScriptFailure([
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1415 'vim9script',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1416 '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
1417 'unlet svar',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1418 ], 'E1081:')
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1419 CheckScriptFailure([
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1420 'vim9script',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1421 '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
1422 '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
1423 ], 'E1081:')
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1424 CheckScriptFailure([
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1425 'vim9script',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1426 '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
1427 'def Func()',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1428 ' unlet svar',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1429 'enddef',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1430 'defcompile',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1431 ], 'E1081:')
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1432 CheckScriptFailure([
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1433 'vim9script',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1434 '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
1435 '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
1436 ' 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
1437 '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
1438 '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
1439 ], '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
1440 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
1441 '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
1442 '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
1443 'def Func()',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1444 ' 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
1445 'enddef',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1446 'defcompile',
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1447 ], 'E1081:')
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1448
23523
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1449 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
1450 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
1451 vim9script
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1452 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
1453 def UnletSvar()
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1454 unlet svar
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1455 enddef
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1456 defcompile
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1457 END
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
1458 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
1459 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
1460
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1461 $ENVVAR = 'foobar'
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1462 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
1463 unlet $ENVVAR
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1464 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
1465 enddef
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1466
23537
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
1467 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
1468 var lines =<< trim END
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
1469 var verbose = 0
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
1470 verbose = 1
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
1471 assert_equal(1, verbose)
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
1472 silent verbose = 2
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
1473 assert_equal(2, verbose)
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
1474 silent verbose += 2
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
1475 assert_equal(4, verbose)
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
1476 silent verbose -= 1
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
1477 assert_equal(3, verbose)
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
1478
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
1479 var topleft = {one: 1}
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
1480 sandbox topleft.one = 3
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
1481 assert_equal({one: 3}, topleft)
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
1482 leftabove topleft[' '] = 4
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
1483 assert_equal({one: 3, ' ': 4}, topleft)
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
1484 END
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
1485 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
1486 enddef
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
1487
22458
f5731190bc66 patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents: 22435
diff changeset
1488
22351
4c488004edbc patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1489 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker