annotate src/testdir/test_const.vim @ 17246:a437ebad37b8

Added tag v8.1.1622 for changeset 13a2d3364b3feee58df6aa63e280592095b1db60
author Bram Moolenaar <Bram@vim.org>
date Wed, 03 Jul 2019 23:30:07 +0200
parents 6990c1160ea5
children 9606c0adc148
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
17172
6990c1160ea5 patch 8.1.1585: :let-heredoc does not trim enough
Bram Moolenaar <Bram@vim.org>
parents: 17109
diff changeset
21 hello
17079
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
17109
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
24 call assert_true(exists('i'))
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
25 call assert_true(exists('f'))
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
26 call assert_true(exists('s'))
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
27 call assert_true(exists('F'))
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
28 call assert_true(exists('l'))
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
29 call assert_true(exists('d'))
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
30 if has('channel')
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
31 call assert_true(exists('j'))
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
32 call assert_true(exists('c'))
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
33 endif
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
34 call assert_true(exists('b'))
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
35 call assert_true(exists('n'))
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
36 call assert_true(exists('bl'))
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
37 call assert_true(exists('here'))
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
38
17079
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 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
40 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
41 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
42 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
43 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
44 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
45 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
46 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
47 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
48 endif
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 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
50 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
51 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
52 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
53
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 " Unlet
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 unlet i
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 unlet f
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 unlet s
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 unlet F
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 unlet l
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 unlet d
17087
bc730bb54a7c patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents: 17079
diff changeset
61 if has('channel')
bc730bb54a7c patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents: 17079
diff changeset
62 unlet j
bc730bb54a7c patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents: 17079
diff changeset
63 unlet c
bc730bb54a7c patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents: 17079
diff changeset
64 endif
17079
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 unlet b
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 unlet n
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 unlet bl
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 unlet here
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 endfunc
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 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
72 " 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
73 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
74 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
75 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
76 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
77 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
78 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
79 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
80 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
81 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
82 endif
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 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
84 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
85 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
86 const l:here =<< trim EOS
17172
6990c1160ea5 patch 8.1.1585: :let-heredoc does not trim enough
Bram Moolenaar <Bram@vim.org>
parents: 17109
diff changeset
87 hello
17079
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 EOS
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 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
91 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
92 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
93 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
94 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
95 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
96 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
97 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
98 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
99 endif
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 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
101 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
102 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
103 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
104
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 " Unlet
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 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
107 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
108 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
109 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
110 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
111 unlet l:d
17087
bc730bb54a7c patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents: 17079
diff changeset
112 if has('channel')
bc730bb54a7c patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents: 17079
diff changeset
113 unlet l:j
bc730bb54a7c patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents: 17079
diff changeset
114 unlet l:c
bc730bb54a7c patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents: 17079
diff changeset
115 endif
17079
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 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
117 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
118 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
119 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
120 endfunc
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 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
123 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
124 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
125 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
126 endfunc
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 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
129 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
130
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 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
132 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
133 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
134
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 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
136 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
137 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
138 endfunc
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 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
141 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
142 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
143 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
144 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
145 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
146 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
147 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
148 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
149 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
150 endif
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 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
152 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
153 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
154
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 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
156 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
157 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
158 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
159 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
160 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
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 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
163 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
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 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
166 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
167 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
168 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
169
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 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
171 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
172 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
173 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
174 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
175 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
176 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
177 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
178 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
179 endif
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 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
181 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
182 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
183
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 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
185 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
186 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
187 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
188 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
189 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
190 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
191 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
192 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
193 endif
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 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
195 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
196 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
197 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
198 endfunc
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 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
201 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
202 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
203 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
204
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 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
206 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
207 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
208 endfunc
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 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
211 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
212 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
213 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
214 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
215 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
216 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
217
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 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
219 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
220
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 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
222 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
223
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 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
225 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
226 endfunc
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 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
229 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
230 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
231 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
232 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
233 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
234 endfunc
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235
17109
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
236 func Test_const_with_eval_name()
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
237 let s = 'foo'
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
238
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
239 " eval name with :const should work
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
240 const abc_{s} = 1
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
241 const {s}{s} = 1
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
242
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
243 let s2 = 'abc_foo'
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
244 call assert_fails('const {s2} = "bar"', 'E995:')
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
245 endfunc
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
246
17079
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 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
248 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
249 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
250
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 " Modify list
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 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
253 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
254
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 " Modify dict
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 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
257 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
258 endfunc