Mercurial > vim
annotate src/testdir/test_vim9_assign.vim @ 22502:1503ecd54f8a v8.2.1799
patch 8.2.1799: some Normal mode commands not fully tested
Commit: https://github.com/vim/vim/commit/d1ad99b65470d3e754f6a0588a6b0dc2214a1eab
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Oct 4 16:16:54 2020 +0200
patch 8.2.1799: some Normal mode commands not fully tested
Problem: Some Normal mode commands not fully tested.
Solution: Add a few more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/7073)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 04 Oct 2020 16:30:03 +0200 |
parents | 4c21f7f6f9e3 |
children | 47596deedfb5 |
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) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 END |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 CheckScriptSuccess(lines) |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
50 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
|
51 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
|
52 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
|
53 CheckDefAndScriptFailure(['var x: bool = {}'], '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 = "x"'], 'E1012:') |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 def Test_syntax() |
22433
8b5e2f9580db
patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents:
22431
diff
changeset
|
58 var name = 234 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
59 var other: list<string> = ['asdf'] |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 def Test_assignment() |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
63 CheckDefFailure(['var x:string'], 'E1069:') |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
64 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
|
65 CheckDefFailure(['var a:string = "x"'], 'E1069:') |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
66 CheckDefFailure(['var lambda = {-> "lambda"}'], 'E704:') |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
67 CheckScriptFailure(['var x = "x"'], 'E1124:') |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
69 var nr: number = 1234 |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
70 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
|
71 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
72 var a: number = 6 #comment |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 assert_equal(6, a) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 if has('channel') |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
76 var chan1: channel |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
77 var job1: job |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
78 var job2: job = job_start('willfail') |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 endif |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 if has('float') |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
81 var float1: float = 3.4 |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 endif |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
83 var Funky1: func |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
84 var Funky2: func = function('len') |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
85 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
|
86 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 g:newvar = 'new' #comment |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 assert_equal('new', g:newvar) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 assert_equal('yes', g:existing) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 g:existing = 'no' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 assert_equal('no', g:existing) |
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 v:char = 'abc' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 assert_equal('abc', v:char) |
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 $ENVVAR = 'foobar' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 assert_equal('foobar', $ENVVAR) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
99 $ENVVAR = '' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
101 var lines =<< trim END |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 vim9script |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 $ENVVAR = 'barfoo' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 assert_equal('barfoo', $ENVVAR) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 $ENVVAR = '' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 END |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 CheckScriptSuccess(lines) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 s:appendToMe ..= 'yyy' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
110 assert_equal('xxxyyy', s:appendToMe) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 s:addToMe += 222 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 assert_equal(333, s:addToMe) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 s:newVar = 'new' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
114 assert_equal('new', s:newVar) |
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 set ts=7 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 &ts += 1 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 assert_equal(8, &ts) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 &ts -= 3 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 assert_equal(5, &ts) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
121 &ts *= 2 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
122 assert_equal(10, &ts) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
123 &ts /= 3 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
124 assert_equal(3, &ts) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 set ts=10 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
126 &ts %= 4 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 assert_equal(2, &ts) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
128 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
129 if has('float') |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
130 var f100: float = 100.0 |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
131 f100 /= 5 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
132 assert_equal(20.0, f100) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
134 var f200: float = 200.0 |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
135 f200 /= 5.0 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
136 assert_equal(40.0, f200) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
137 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
138 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
|
139 endif |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
140 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
141 lines =<< trim END |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
142 &ts = 6 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
143 &ts += 3 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
144 assert_equal(9, &ts) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
145 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
146 &l:ts = 6 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
147 assert_equal(6, &ts) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
148 &l:ts += 2 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
149 assert_equal(8, &ts) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
150 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
151 &g:ts = 6 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
152 assert_equal(6, &g:ts) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
153 &g:ts += 2 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
154 assert_equal(8, &g:ts) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
155 END |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
156 CheckDefAndScriptSuccess(lines) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
157 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
158 CheckDefFailure(['¬ex += 3'], 'E113:') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
159 CheckDefFailure(['&ts ..= "xxx"'], 'E1019:') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
160 CheckDefFailure(['&ts = [7]'], 'E1012:') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
161 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
|
162 CheckDefFailure(['&ts = "xx"'], 'E1012:') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
163 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
|
164 CheckDefFailure(['&path += 3'], 'E1012:') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
165 CheckDefExecFailure(['&bs = "asdf"'], 'E474:') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
166 # test freeing ISN_STOREOPT |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
167 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
|
168 &ts = 8 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
169 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
170 lines =<< trim END |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
171 var save_TI = &t_TI |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
172 &t_TI = '' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
173 assert_equal('', &t_TI) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
174 &t_TI = 'xxx' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
175 assert_equal('xxx', &t_TI) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
176 &t_TI = save_TI |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
177 END |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
178 CheckDefAndScriptSuccess(lines) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
179 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
180 CheckDefFailure(['&t_TI = 123'], 'E1012:') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
181 CheckScriptFailure(['vim9script', '&t_TI = 123'], 'E928:') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
182 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
183 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
|
184 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
|
185 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
186 lines =<< trim END |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
187 vim9script |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
188 def SomeFunc() |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
189 s:var = 123 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
190 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
191 defcompile |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
192 END |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
193 CheckScriptFailure(lines, 'E1089:') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
194 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
195 g:inc_counter += 1 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
196 assert_equal(2, g:inc_counter) |
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 $SOME_ENV_VAR ..= 'more' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
199 assert_equal('somemore', $SOME_ENV_VAR) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
200 CheckDefFailure(['$SOME_ENV_VAR += "more"'], 'E1051:') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
201 CheckDefFailure(['$SOME_ENV_VAR += 123'], 'E1012:') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
202 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
203 lines =<< trim END |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
204 @c = 'areg' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
205 @c ..= 'add' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
206 assert_equal('aregadd', @c) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
207 END |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
208 CheckDefAndScriptSuccess(lines) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
209 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
210 CheckDefFailure(['@a += "more"'], 'E1051:') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
211 CheckDefFailure(['@a += 123'], 'E1012:') |
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 v:errmsg = 'none' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
214 v:errmsg ..= 'again' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
215 assert_equal('noneagain', v:errmsg) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
216 CheckDefFailure(['v:errmsg += "more"'], 'E1051:') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
217 CheckDefFailure(['v:errmsg += 123'], 'E1012:') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
218 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
219 # this should not leak |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
220 if 0 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
221 var text =<< trim END |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
222 some text |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
223 END |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
224 endif |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
225 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
226 |
22365
a4866826cebc
patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents:
22363
diff
changeset
|
227 def Test_extend_list() |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
228 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
|
229 vim9script |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
230 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
|
231 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
|
232 assert_equal([123], l) |
a4866826cebc
patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents:
22363
diff
changeset
|
233 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
234 var d: dict<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
|
235 d['one'] = 1 |
a4866826cebc
patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents:
22363
diff
changeset
|
236 assert_equal(#{one: 1}, d) |
a4866826cebc
patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents:
22363
diff
changeset
|
237 END |
a4866826cebc
patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents:
22363
diff
changeset
|
238 CheckScriptSuccess(lines) |
a4866826cebc
patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents:
22363
diff
changeset
|
239 enddef |
a4866826cebc
patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Bram Moolenaar <Bram@vim.org>
parents:
22363
diff
changeset
|
240 |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
241 def Test_single_letter_vars() |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
242 # single letter variables |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
243 var a: number = 123 |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
244 a = 123 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
245 assert_equal(123, a) |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
246 var b: number |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
247 b = 123 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
248 assert_equal(123, b) |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
249 var g: number |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
250 g = 123 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
251 assert_equal(123, g) |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
252 var s: number |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
253 s = 123 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
254 assert_equal(123, s) |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
255 var t: number |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
256 t = 123 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
257 assert_equal(123, t) |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
258 var v: number |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
259 v = 123 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
260 assert_equal(123, v) |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
261 var w: number |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
262 w = 123 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
263 assert_equal(123, w) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
264 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
265 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
266 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
|
267 var lines =<< trim END |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
268 vim9script |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
269 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
270 # 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
|
271 var a: string |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
272 var b: number |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
273 var l: list<any> |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
274 var s: string |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
275 var t: number |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
276 var v: number |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
277 var w: number |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
278 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
279 # 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
|
280 a = 'script-a' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
281 b = 111 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
282 l = [1, 2, 3] |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
283 s = 'script-s' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
284 t = 222 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
285 v = 333 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
286 w = 444 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
287 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
288 assert_equal('script-a', a) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
289 assert_equal(111, b) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
290 assert_equal([1, 2, 3], l) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
291 assert_equal('script-s', s) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
292 assert_equal(222, t) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
293 assert_equal(333, v) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
294 assert_equal(444, w) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
295 END |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
296 writefile(lines, 'Xsinglechar') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
297 source Xsinglechar |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
298 delete('Xsinglechar') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
299 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
300 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
301 def Test_assignment_list() |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
308 var listS: list<string> = [] |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
309 var listN: list<number> = [] |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
310 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
311 assert_equal([1, 2, 3], list2) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
312 list2[-1] = 99 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
313 assert_equal([1, 2, 99], list2) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
314 list2[-2] = 88 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
315 assert_equal([1, 88, 99], list2) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
316 list2[-3] = 77 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
317 assert_equal([77, 88, 99], list2) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
318 list2 += [100] |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
319 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
|
320 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
321 list3 += ['end'] |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
322 assert_equal(['sdf', 'asdf', 'end'], list3) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
323 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
324 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
|
325 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
|
326 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
327 # type becomes list<any> |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
328 var somelist = rand() > 0 ? [1, 2, 3] : ['a', 'b', 'c'] |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
329 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
330 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
331 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
|
332 var lines =<< trim END |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
333 vim9script |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
334 var v1: number |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
335 var v2: number |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
336 var v3: number |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
337 [v1, v2, v3] = [1, 2, 3] |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
338 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
|
339 END |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
340 CheckScriptSuccess(lines) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
341 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
342 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
343 def Test_assignment_dict() |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
344 var dict1: dict<bool> = #{one: false, two: true} |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
345 var dict2: dict<number> = #{one: 1, two: 2} |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
346 var dict3: dict<string> = #{key: 'value'} |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
347 var dict4: dict<any> = #{one: 1, two: '2'} |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
348 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
|
349 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
350 # overwrite |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
351 dict3['key'] = 'another' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
352 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
353 # 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
|
354 var dd = {} |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
355 dd[""] = 6 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
356 assert_equal({'': 6}, dd) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
357 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
358 # type becomes dict<any> |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
359 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
|
360 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
361 # assignment to script-local dict |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
362 var lines =<< trim END |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
363 vim9script |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
364 var test: dict<any> = {} |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
365 def FillDict(): dict<any> |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
366 test['a'] = 43 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
367 return test |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
368 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
369 assert_equal(#{a: 43}, FillDict()) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
370 END |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
371 CheckScriptSuccess(lines) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
372 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
373 lines =<< trim END |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
374 vim9script |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
375 var test: dict<any> |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
376 def FillDict(): dict<any> |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
377 test['a'] = 43 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
378 return test |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
379 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
380 FillDict() |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
381 END |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
382 CheckScriptFailure(lines, 'E1103:') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
383 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
384 # assignment to global dict |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
385 lines =<< trim END |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
386 vim9script |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
387 g:test = {} |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
388 def FillDict(): dict<any> |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
389 g:test['a'] = 43 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
390 return g:test |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
391 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
392 assert_equal(#{a: 43}, FillDict()) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
393 END |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
394 CheckScriptSuccess(lines) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
395 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
396 # assignment to buffer dict |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
397 lines =<< trim END |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
398 vim9script |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
399 b:test = {} |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
400 def FillDict(): dict<any> |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
401 b:test['a'] = 43 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
402 return b:test |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
403 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
404 assert_equal(#{a: 43}, FillDict()) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
405 END |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
406 CheckScriptSuccess(lines) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
407 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
408 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
409 def Test_assignment_local() |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
410 # 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
|
411 # changed. |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
412 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
|
413 let b:existing = 'yes' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
414 let w:existing = 'yes' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
415 let t:existing = 'yes' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
416 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
417 def Test_assignment_local_internal() |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
418 b:newvar = 'new' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
419 assert_equal('new', b:newvar) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
420 assert_equal('yes', b:existing) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
421 b:existing = 'no' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
422 assert_equal('no', b:existing) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
423 b:existing ..= 'NO' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
424 assert_equal('noNO', b:existing) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
425 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
426 w:newvar = 'new' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
427 assert_equal('new', w:newvar) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
428 assert_equal('yes', w:existing) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
429 w:existing = 'no' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
430 assert_equal('no', w:existing) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
431 w:existing ..= 'NO' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
432 assert_equal('noNO', w:existing) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
433 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
434 t:newvar = 'new' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
435 assert_equal('new', t:newvar) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
436 assert_equal('yes', t:existing) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
437 t:existing = 'no' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
438 assert_equal('no', t:existing) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
439 t:existing ..= 'NO' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
440 assert_equal('noNO', t:existing) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
441 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
442 call Test_assignment_local_internal() |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
443 END |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
444 CheckScriptSuccess(script_lines) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
445 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
446 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
447 def Test_assignment_default() |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
448 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
449 # Test default values. |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
450 var thebool: bool |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
451 assert_equal(v:false, thebool) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
452 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
453 var thenumber: number |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
454 assert_equal(0, thenumber) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
455 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
456 if has('float') |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
457 var thefloat: float |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
458 assert_equal(0.0, thefloat) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
459 endif |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
460 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
461 var thestring: string |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
462 assert_equal('', thestring) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
463 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
464 var theblob: blob |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
465 assert_equal(0z, theblob) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
466 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
467 var Thefunc: func |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
468 assert_equal(test_null_function(), Thefunc) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
469 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
470 var thelist: list<any> |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
471 assert_equal([], thelist) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
472 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
473 var thedict: dict<any> |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
474 assert_equal({}, thedict) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
475 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
476 if has('channel') |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
477 var thejob: job |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
478 assert_equal(test_null_job(), thejob) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
479 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
480 var thechannel: channel |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
481 assert_equal(test_null_channel(), thechannel) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
482 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
483 if has('unix') && executable('cat') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
484 # check with non-null job and channel, types must match |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
485 thejob = job_start("cat ", #{}) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
486 thechannel = job_getchannel(thejob) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
487 job_stop(thejob, 'kill') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
488 endif |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
489 endif |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
490 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
491 var nr = 1234 | nr = 5678 |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
492 assert_equal(5678, nr) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
493 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
494 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
495 def Test_assignment_var_list() |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
496 var v1: string |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
497 var v2: string |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
498 var vrem: list<string> |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
499 [v1] = ['aaa'] |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
500 assert_equal('aaa', v1) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
501 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
502 [v1, v2] = ['one', 'two'] |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
503 assert_equal('one', v1) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
504 assert_equal('two', v2) |
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 [v1, v2; vrem] = ['one', 'two'] |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
507 assert_equal('one', v1) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
508 assert_equal('two', v2) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
509 assert_equal([], vrem) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
510 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
511 [v1, v2; vrem] = ['one', 'two', 'three'] |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
512 assert_equal('one', v1) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
513 assert_equal('two', v2) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
514 assert_equal(['three'], vrem) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
515 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
516 [&ts, &sw] = [3, 4] |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
517 assert_equal(3, &ts) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
518 assert_equal(4, &sw) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
519 set ts=8 sw=4 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
520 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
521 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
522 def Test_assignment_vim9script() |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
523 var lines =<< trim END |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
524 vim9script |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
525 def Func(): list<number> |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
526 return [1, 2] |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
527 enddef |
22433
8b5e2f9580db
patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents:
22431
diff
changeset
|
528 var name1: number |
8b5e2f9580db
patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents:
22431
diff
changeset
|
529 var name2: number |
8b5e2f9580db
patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents:
22431
diff
changeset
|
530 [name1, name2] = |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
531 Func() |
22433
8b5e2f9580db
patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents:
22431
diff
changeset
|
532 assert_equal(1, name1) |
8b5e2f9580db
patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents:
22431
diff
changeset
|
533 assert_equal(2, name2) |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
534 var ll = |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
535 Func() |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
536 assert_equal([1, 2], ll) |
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 @/ = 'text' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
539 assert_equal('text', @/) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
540 @0 = 'zero' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
541 assert_equal('zero', @0) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
542 @1 = 'one' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
543 assert_equal('one', @1) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
544 @9 = 'nine' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
545 assert_equal('nine', @9) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
546 @- = 'minus' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
547 assert_equal('minus', @-) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
548 if has('clipboard_working') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
549 @* = 'star' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
550 assert_equal('star', @*) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
551 @+ = 'plus' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
552 assert_equal('plus', @+) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
553 endif |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
554 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
555 var a: number = 123 |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
556 assert_equal(123, a) |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
557 var s: string = 'yes' |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
558 assert_equal('yes', s) |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
559 var b: number = 42 |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
560 assert_equal(42, b) |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
561 var w: number = 43 |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
562 assert_equal(43, w) |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
563 var t: number = 44 |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
564 assert_equal(44, t) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
565 END |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
566 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
|
567 |
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
|
568 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
|
569 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
|
570 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
|
571 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
|
572 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
|
573 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
|
574 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
|
575 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
|
576 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
|
577 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
578 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
579 def Mess(): string |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
580 v:foldstart = 123 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
581 return 'xxx' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
582 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
583 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
584 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
|
585 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
|
586 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
|
587 CheckDefFailure(['var name= 234'], 'E1004:') |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
588 |
22433
8b5e2f9580db
patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents:
22431
diff
changeset
|
589 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
|
590 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
|
591 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
|
592 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
|
593 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
|
594 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
|
595 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
|
596 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
|
597 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
598 CheckDefFailure(['var true = 1'], 'E1034:') |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
599 CheckDefFailure(['var false = 1'], 'E1034:') |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
600 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
601 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
|
602 CheckDefExecFailure(['var a: number', |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
603 '[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
|
604 CheckDefExecFailure(['var a: number', |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
605 '[a] = []'], 'E1093:') |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
606 CheckDefExecFailure(['var x: number', |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
607 'var y: number', |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
608 '[x, y] = [1]'], 'E1093:') |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
609 CheckDefExecFailure(['var x: number', |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
610 'var y: number', |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
611 'var z: list<number>', |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
612 '[x, y; z] = [1]'], 'E1093:') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
613 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
614 CheckDefFailure(['var somevar'], "E1022:") |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
615 CheckDefFailure(['var &tabstop = 4'], 'E1052:') |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
616 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
|
617 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
|
618 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
619 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
|
620 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
|
621 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
622 if has('dnd') |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
623 CheckDefFailure(['var @~ = 5'], 'E1066:') |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
624 else |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
625 CheckDefFailure(['var @~ = 5'], 'E354:') |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
626 CheckDefFailure(['@~ = 5'], 'E354:') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
627 endif |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
628 CheckDefFailure(['var @a = 5'], 'E1066:') |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
629 CheckDefFailure(['var @/ = "x"'], 'E1066:') |
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
630 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
|
631 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
632 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
|
633 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
|
634 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
|
635 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
|
636 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
637 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
|
638 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
|
639 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
|
640 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
|
641 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
|
642 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
643 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
|
644 |
22433
8b5e2f9580db
patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents:
22431
diff
changeset
|
645 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
|
646 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
|
647 |
22433
8b5e2f9580db
patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents:
22431
diff
changeset
|
648 CheckDefFailure(['var name: dict<string> = #{key: 123}'], 'expected dict<string> but got dict<number>') |
8b5e2f9580db
patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents:
22431
diff
changeset
|
649 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
|
650 |
22433
8b5e2f9580db
patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents:
22431
diff
changeset
|
651 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
|
652 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
|
653 |
22433
8b5e2f9580db
patch 8.2.1765: Vim9: some tests use "var var"
Bram Moolenaar <Bram@vim.org>
parents:
22431
diff
changeset
|
654 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
|
655 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
|
656 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
657 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
|
658 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
|
659 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
660 CheckDefFailure(['w:foo: number = 10'], |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
661 'E488: Trailing characters: : number = 1') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
662 CheckDefFailure(['t:foo: bool = true'], |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
663 'E488: Trailing characters: : bool = true') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
664 CheckDefFailure(['b:foo: string = "x"'], |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
665 'E488: Trailing characters: : string = "x"') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
666 CheckDefFailure(['g:foo: number = 123'], |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
667 'E488: Trailing characters: : number = 123') |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
668 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
669 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
670 def Test_assign_list() |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
671 var l: list<string> = [] |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
672 l[0] = 'value' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
673 assert_equal('value', l[0]) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
674 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
675 l[1] = 'asdf' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
676 assert_equal('value', l[0]) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
677 assert_equal('asdf', l[1]) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
678 assert_equal('asdf', l[-1]) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
679 assert_equal('value', l[-2]) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
680 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
681 var nrl: list<number> = [] |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
682 for i in range(5) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
683 nrl[i] = i |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
684 endfor |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
685 assert_equal([0, 1, 2, 3, 4], nrl) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
686 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
687 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
688 def Test_assign_dict() |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
689 var d: dict<string> = {} |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
690 d['key'] = 'value' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
691 assert_equal('value', d['key']) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
692 |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
693 d[123] = 'qwerty' |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
694 assert_equal('qwerty', d[123]) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
695 assert_equal('qwerty', d['123']) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
696 |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
697 var nrd: dict<number> = {} |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
698 for i in range(3) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
699 nrd[i] = i |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
700 endfor |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
701 assert_equal({'0': 0, '1': 1, '2': 2}, nrd) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
702 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
703 |
22363
6c3d15011081
patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents:
22351
diff
changeset
|
704 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
|
705 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
|
706 vim9script |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
707 var mylist = [] |
22363
6c3d15011081
patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents:
22351
diff
changeset
|
708 mylist += [#{one: 'one'}] |
6c3d15011081
patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents:
22351
diff
changeset
|
709 def Func() |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
710 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
|
711 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
|
712 enddef |
6c3d15011081
patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents:
22351
diff
changeset
|
713 Func() |
6c3d15011081
patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents:
22351
diff
changeset
|
714 END |
6c3d15011081
patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents:
22351
diff
changeset
|
715 CheckScriptSuccess(lines) |
6c3d15011081
patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents:
22351
diff
changeset
|
716 |
6c3d15011081
patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents:
22351
diff
changeset
|
717 # doesn't work yet |
6c3d15011081
patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents:
22351
diff
changeset
|
718 #lines =<< trim END |
6c3d15011081
patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents:
22351
diff
changeset
|
719 # vim9script |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
720 # var mylist = [[]] |
22363
6c3d15011081
patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents:
22351
diff
changeset
|
721 # mylist[0] += [#{one: 'one'}] |
6c3d15011081
patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents:
22351
diff
changeset
|
722 # def Func() |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
723 # var dd = mylist[0][0] |
22363
6c3d15011081
patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents:
22351
diff
changeset
|
724 # 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
|
725 # enddef |
6c3d15011081
patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents:
22351
diff
changeset
|
726 # Func() |
6c3d15011081
patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents:
22351
diff
changeset
|
727 #END |
6c3d15011081
patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents:
22351
diff
changeset
|
728 #CheckScriptSuccess(lines) |
6c3d15011081
patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents:
22351
diff
changeset
|
729 enddef |
6c3d15011081
patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents:
22351
diff
changeset
|
730 |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
731 def Test_assign_lambda() |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
732 # 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
|
733 var lines =<< trim END |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
734 vim9script |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
735 var FuncRef = {->123} |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
736 assert_equal(123, FuncRef()) |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
737 var FuncRef_Func: func = {->123} |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
738 assert_equal(123, FuncRef_Func()) |
22391
a9fb7efa31d6
patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents:
22365
diff
changeset
|
739 var FuncRef_Any: any = {->123} |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
740 assert_equal(123, FuncRef_Any()) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
741 END |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
742 CheckScriptSuccess(lines) |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
743 enddef |
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
744 |
22413
66d1131a7eff
patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
745 def Test_heredoc() |
66d1131a7eff
patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
746 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
|
747 text |
66d1131a7eff
patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
748 END |
66d1131a7eff
patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
749 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
|
750 |
66d1131a7eff
patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
751 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
|
752 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
|
753 |
5b35b477eff0
patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents:
22413
diff
changeset
|
754 lines =<< trim [END] |
5b35b477eff0
patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents:
22413
diff
changeset
|
755 def Func() |
5b35b477eff0
patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents:
22413
diff
changeset
|
756 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
|
757 x |
5b35b477eff0
patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents:
22413
diff
changeset
|
758 x |
5b35b477eff0
patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents:
22413
diff
changeset
|
759 x |
5b35b477eff0
patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents:
22413
diff
changeset
|
760 x |
5b35b477eff0
patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents:
22413
diff
changeset
|
761 x |
5b35b477eff0
patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents:
22413
diff
changeset
|
762 x |
5b35b477eff0
patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents:
22413
diff
changeset
|
763 x |
5b35b477eff0
patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents:
22413
diff
changeset
|
764 x |
5b35b477eff0
patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents:
22413
diff
changeset
|
765 enddef |
5b35b477eff0
patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents:
22413
diff
changeset
|
766 call Func() |
5b35b477eff0
patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents:
22413
diff
changeset
|
767 [END] |
5b35b477eff0
patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents:
22413
diff
changeset
|
768 CheckScriptFailure(lines, 'E990:') |
22413
66d1131a7eff
patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
769 enddef |
66d1131a7eff
patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents:
22391
diff
changeset
|
770 |
22458
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
771 def Test_let_func_call() |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
772 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
|
773 vim9script |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
774 func GetValue() |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
775 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
|
776 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
|
777 else |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
778 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
|
779 endif |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
780 return 'this' |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
781 endfunc |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
782 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
|
783 # 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
|
784 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
|
785 END |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
786 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
|
787 source Xfinished |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
788 # 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
|
789 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
|
790 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
791 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
|
792 delete('Xfinished') |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
793 enddef |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
794 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
795 def Test_let_missing_type() |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
796 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
|
797 vim9script |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
798 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
|
799 END |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
800 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
|
801 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
802 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
|
803 vim9script |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
804 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
|
805 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
|
806 END |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
807 CheckScriptSuccess(lines) |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
808 enddef |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
809 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
810 def Test_let_declaration() |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
811 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
|
812 vim9script |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
813 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
|
814 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
|
815 name = 'text' |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
816 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
|
817 # 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
|
818 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
|
819 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
|
820 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
821 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
|
822 other = 1234 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
823 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
|
824 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
825 # type is inferred |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
826 s:dict = {'a': 222} |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
827 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
|
828 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
|
829 enddef |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
830 GetDictVal('a') |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
831 END |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
832 CheckScriptSuccess(lines) |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
833 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
|
834 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
|
835 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
|
836 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
|
837 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
|
838 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
839 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
|
840 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
|
841 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
|
842 unlet 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
|
843 enddef |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
844 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
845 def Test_let_declaration_fails() |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
846 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
|
847 vim9script |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
848 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
|
849 END |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
850 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
|
851 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
852 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
|
853 vim9script |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
854 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
|
855 END |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
856 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
|
857 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
858 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
|
859 vim9script |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
860 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
|
861 END |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
862 CheckScriptFailure(lines, 'E475:') |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
863 enddef |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
864 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
865 def Test_let_type_check() |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
866 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
|
867 vim9script |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
868 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
|
869 name = 1234 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
870 END |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
871 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
|
872 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
873 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
|
874 vim9script |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
875 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
|
876 END |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
877 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
|
878 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
879 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
|
880 vim9script |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
881 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
|
882 END |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
883 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
|
884 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
885 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
|
886 vim9script |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
887 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
|
888 s:l = [] |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
889 END |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
890 CheckScriptSuccess(lines) |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
891 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
892 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
|
893 vim9script |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
894 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
|
895 s:d = {} |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
896 END |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
897 CheckScriptSuccess(lines) |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
898 enddef |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
899 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
900 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
|
901 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
902 def Test_let_list_dict_type() |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
903 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
|
904 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
|
905 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
|
906 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
907 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
|
908 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
|
909 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
|
910 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
911 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
|
912 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
|
913 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
|
914 END |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
915 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
|
916 enddef |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
917 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
918 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
|
919 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
|
920 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
|
921 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
|
922 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
|
923 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
|
924 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
925 # 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
|
926 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
|
927 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
|
928 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
|
929 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
|
930 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
|
931 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
932 CheckScriptFailure([ |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
933 'vim9script', |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
934 '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
|
935 'unlet svar', |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
936 ], 'E1081:') |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
937 CheckScriptFailure([ |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
938 'vim9script', |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
939 '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
|
940 '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
|
941 ], 'E1081:') |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
942 CheckScriptFailure([ |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
943 'vim9script', |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
944 '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
|
945 'def Func()', |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
946 ' unlet svar', |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
947 'enddef', |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
948 'defcompile', |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
949 ], 'E1081:') |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
950 CheckScriptFailure([ |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
951 'vim9script', |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
952 '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
|
953 'def Func()', |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
954 ' 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
|
955 'enddef', |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
956 'defcompile', |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
957 ], 'E1081:') |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
958 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
959 $ENVVAR = 'foobar' |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
960 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
|
961 unlet $ENVVAR |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
962 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
|
963 enddef |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
964 |
f5731190bc66
patch 8.2.1777: Vim9: some assignment tests in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
22435
diff
changeset
|
965 |
22351
4c488004edbc
patch 8.2.1724: Vim9: assignment tests spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
966 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker |