annotate src/testdir/test_const.vim @ 18715:bd4c34db84ab v8.1.2349

patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif" Commit: https://github.com/vim/vim/commit/cc4423ae13d78367a3d0b5756783523d3b3a1d31 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Nov 26 17:05:00 2019 +0100 patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif" Problem: :lockvar and :unlockvar cannot be followed by "| endif". Solution: Check for following commands. (closes https://github.com/vim/vim/issues/5269)
author Bram Moolenaar <Bram@vim.org>
date Tue, 26 Nov 2019 17:15:03 +0100
parents baf890fa1621
children da98d2ed8dc5
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
17918
9606c0adc148 patch 8.1.1955: tests contain typos
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
128 func Test_destructuring_with_lock()
17079
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
18713
baf890fa1621 patch 8.1.2348: :const cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 17918
diff changeset
200 func Test_const_with_condition()
baf890fa1621 patch 8.1.2348: :const cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 17918
diff changeset
201 const x = 0
baf890fa1621 patch 8.1.2348: :const cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 17918
diff changeset
202 if 0 | const x = 1 | endif
baf890fa1621 patch 8.1.2348: :const cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 17918
diff changeset
203 call assert_equal(0, x)
baf890fa1621 patch 8.1.2348: :const cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 17918
diff changeset
204 endfunc
baf890fa1621 patch 8.1.2348: :const cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 17918
diff changeset
205
18715
bd4c34db84ab patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
206 func Test_lockvar()
bd4c34db84ab patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
207 let x = 'hello'
bd4c34db84ab patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
208 lockvar x
bd4c34db84ab patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
209 call assert_fails('let x = "there"', 'E741')
bd4c34db84ab patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
210 if 0 | unlockvar x | endif
bd4c34db84ab patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
211 call assert_fails('let x = "there"', 'E741')
bd4c34db84ab patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
212 unlockvar x
bd4c34db84ab patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
213 let x = 'there'
bd4c34db84ab patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
214
bd4c34db84ab patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
215 if 0 | lockvar x | endif
bd4c34db84ab patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
216 let x = 'again'
bd4c34db84ab patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
217 endfunc
bd4c34db84ab patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
218
bd4c34db84ab patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
219
17079
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 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
221 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
222 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
223 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
224
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 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
226 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
227 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
228 endfunc
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 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
231 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
232 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
233 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
234 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
235 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
236 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
237
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 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
239 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
240
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 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
242 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
243
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 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
245 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
246 endfunc
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 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
249 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
250 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
251 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
252 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
253 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
254 endfunc
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255
17109
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
256 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
257 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
258
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
259 " 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
260 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
261 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
262
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
263 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
264 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
265 endfunc
cc5d4b4bae83 patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents: 17087
diff changeset
266
17079
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 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
268 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
269 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
270
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 " Modify list
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 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
273 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
274
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 " Modify dict
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 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
277 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
278 endfunc