Mercurial > vim
annotate src/testdir/test_const.vim @ 17087:bc730bb54a7c v8.1.1543
patch 8.1.1543: const test fails with small features
commit https://github.com/vim/vim/commit/b6e3b88ec8b757b3acf940f8b4938e975c39ba67
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jun 15 17:50:57 2019 +0200
patch 8.1.1543: const test fails with small features
Problem: Const test fails with small features.
Solution: Don't unlet non-existing variables.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 15 Jun 2019 18:00:07 +0200 |
parents | 00ffed9bbb65 |
children | cc5d4b4bae83 |
rev | line source |
---|---|
17079
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 " Test for :const |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 func s:noop() |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 endfunc |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 func Test_define_var_with_lock() |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 const i = 1 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 const f = 1.1 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 const s = 'vim' |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 const F = funcref('s:noop') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 const l = [1, 2, 3] |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 const d = {'foo': 10} |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 if has('channel') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 const j = test_null_job() |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 const c = test_null_channel() |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 endif |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 const b = v:true |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 const n = v:null |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 const bl = 0zC0FFEE |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 const here =<< trim EOS |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 hello |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 EOS |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 call assert_fails('let i = 1', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 call assert_fails('let f = 1.1', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 call assert_fails('let s = "vim"', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 call assert_fails('let F = funcref("s:noop")', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 call assert_fails('let l = [1, 2, 3]', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 call assert_fails('let d = {"foo": 10}', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 if has('channel') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 call assert_fails('let j = test_null_job()', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 call assert_fails('let c = test_null_channel()', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 endif |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 call assert_fails('let b = v:true', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 call assert_fails('let n = v:null', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 call assert_fails('let bl = 0zC0FFEE', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 call assert_fails('let here = "xxx"', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 " Unlet |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 unlet i |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 unlet f |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 unlet s |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 unlet F |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 unlet l |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 unlet d |
17087
bc730bb54a7c
patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents:
17079
diff
changeset
|
46 if has('channel') |
bc730bb54a7c
patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents:
17079
diff
changeset
|
47 unlet j |
bc730bb54a7c
patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents:
17079
diff
changeset
|
48 unlet c |
bc730bb54a7c
patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents:
17079
diff
changeset
|
49 endif |
17079
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 unlet b |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 unlet n |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 unlet bl |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 unlet here |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 endfunc |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 func Test_define_l_var_with_lock() |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 " With l: prefix |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 const l:i = 1 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 const l:f = 1.1 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 const l:s = 'vim' |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 const l:F = funcref('s:noop') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 const l:l = [1, 2, 3] |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 const l:d = {'foo': 10} |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 if has('channel') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 const l:j = test_null_job() |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 const l:c = test_null_channel() |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 endif |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 const l:b = v:true |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 const l:n = v:null |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 const l:bl = 0zC0FFEE |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 const l:here =<< trim EOS |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 hello |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 EOS |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 call assert_fails('let l:i = 1', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 call assert_fails('let l:f = 1.1', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 call assert_fails('let l:s = "vim"', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 call assert_fails('let l:F = funcref("s:noop")', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 call assert_fails('let l:l = [1, 2, 3]', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 call assert_fails('let l:d = {"foo": 10}', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 if has('channel') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 call assert_fails('let l:j = test_null_job()', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 call assert_fails('let l:c = test_null_channel()', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 endif |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 call assert_fails('let l:b = v:true', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 call assert_fails('let l:n = v:null', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 call assert_fails('let l:bl = 0zC0FFEE', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 call assert_fails('let l:here = "xxx"', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 " Unlet |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 unlet l:i |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 unlet l:f |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 unlet l:s |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 unlet l:F |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 unlet l:l |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 unlet l:d |
17087
bc730bb54a7c
patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents:
17079
diff
changeset
|
97 if has('channel') |
bc730bb54a7c
patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents:
17079
diff
changeset
|
98 unlet l:j |
bc730bb54a7c
patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents:
17079
diff
changeset
|
99 unlet l:c |
bc730bb54a7c
patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents:
17079
diff
changeset
|
100 endif |
17079
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
101 unlet l:b |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 unlet l:n |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 unlet l:bl |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 unlet l:here |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 endfunc |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 func Test_define_script_var_with_lock() |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 const s:x = 0 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 call assert_fails('let s:x = 1', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
110 unlet s:x |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 endfunc |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 func Test_descructuring_with_lock() |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
114 const [a, b, c] = [1, 1.1, 'vim'] |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
115 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 call assert_fails('let a = 1', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 call assert_fails('let b = 1.1', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 call assert_fails('let c = "vim"', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 const [d; e] = [1, 1.1, 'vim'] |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
121 call assert_fails('let d = 1', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
122 call assert_fails('let e = [2.2, "a"]', 'E741:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
123 endfunc |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
124 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 func Test_cannot_modify_existing_variable() |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
126 let i = 1 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 let f = 1.1 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
128 let s = 'vim' |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
129 let F = funcref('s:noop') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
130 let l = [1, 2, 3] |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
131 let d = {'foo': 10} |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
132 if has('channel') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 let j = test_null_job() |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
134 let c = test_null_channel() |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
135 endif |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
136 let b = v:true |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
137 let n = v:null |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
138 let bl = 0zC0FFEE |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
139 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
140 call assert_fails('const i = 1', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
141 call assert_fails('const f = 1.1', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
142 call assert_fails('const s = "vim"', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
143 call assert_fails('const F = funcref("s:noop")', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
144 call assert_fails('const l = [1, 2, 3]', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
145 call assert_fails('const d = {"foo": 10}', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
146 if has('channel') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
147 call assert_fails('const j = test_null_job()', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
148 call assert_fails('const c = test_null_channel()', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
149 endif |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
150 call assert_fails('const b = v:true', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
151 call assert_fails('const n = v:null', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
152 call assert_fails('const bl = 0zC0FFEE', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
153 call assert_fails('const [i, f, s] = [1, 1.1, "vim"]', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
154 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
155 const i2 = 1 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
156 const f2 = 1.1 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
157 const s2 = 'vim' |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
158 const F2 = funcref('s:noop') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
159 const l2 = [1, 2, 3] |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
160 const d2 = {'foo': 10} |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
161 if has('channel') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
162 const j2 = test_null_job() |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
163 const c2 = test_null_channel() |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
164 endif |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
165 const b2 = v:true |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
166 const n2 = v:null |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
167 const bl2 = 0zC0FFEE |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
168 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
169 call assert_fails('const i2 = 1', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
170 call assert_fails('const f2 = 1.1', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
171 call assert_fails('const s2 = "vim"', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
172 call assert_fails('const F2 = funcref("s:noop")', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
173 call assert_fails('const l2 = [1, 2, 3]', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
174 call assert_fails('const d2 = {"foo": 10}', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
175 if has('channel') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
176 call assert_fails('const j2 = test_null_job()', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
177 call assert_fails('const c2 = test_null_channel()', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
178 endif |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
179 call assert_fails('const b2 = v:true', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
180 call assert_fails('const n2 = v:null', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
181 call assert_fails('const bl2 = 0zC0FFEE', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
182 call assert_fails('const [i2, f2, s2] = [1, 1.1, "vim"]', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
183 endfunc |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
184 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
185 func Test_const_with_index_access() |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
186 let l = [1, 2, 3] |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
187 call assert_fails('const l[0] = 4', 'E996:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
188 call assert_fails('const l[0:1] = [1, 2]', 'E996:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
189 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
190 let d = {'aaa': 0} |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
191 call assert_fails("const d['aaa'] = 4", 'E996:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
192 call assert_fails("const d.aaa = 4", 'E996:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
193 endfunc |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
194 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
195 func Test_const_with_compound_assign() |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
196 let i = 0 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
197 call assert_fails('const i += 4', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
198 call assert_fails('const i -= 4', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
199 call assert_fails('const i *= 4', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
200 call assert_fails('const i /= 4', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
201 call assert_fails('const i %= 4', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
202 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
203 let s = 'a' |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
204 call assert_fails('const s .= "b"', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
205 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
206 let [a, b, c] = [1, 2, 3] |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
207 call assert_fails('const [a, b, c] += [4, 5, 6]', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
208 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
209 let [d; e] = [1, 2, 3] |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
210 call assert_fails('const [d; e] += [4, 5, 6]', 'E995:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
211 endfunc |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
212 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
213 func Test_const_with_special_variables() |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
214 call assert_fails('const $FOO = "hello"', 'E996:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
215 call assert_fails('const @a = "hello"', 'E996:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
216 call assert_fails('const &filetype = "vim"', 'E996:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
217 call assert_fails('const &l:filetype = "vim"', 'E996:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
218 call assert_fails('const &g:encoding = "utf-8"', 'E996:') |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
219 endfunc |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
220 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
221 func Test_lock_depth_is_1() |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
222 const l = [1, 2, 3] |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
223 const d = {'foo': 10} |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
224 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
225 " Modify list |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
226 call add(l, 4) |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
227 let l[0] = 42 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
228 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
229 " Modify dict |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
230 let d['bar'] = 'hello' |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
231 let d.foo = 44 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
232 endfunc |