annotate src/testdir/test_const.vim @ 17079:00ffed9bbb65 v8.1.1539

patch 8.1.1539: not easy to define a variable and lock it commit https://github.com/vim/vim/commit/9937a055437ef67b57a1bdec8f0799b669c9dbf0 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jun 15 15:45:06 2019 +0200 patch 8.1.1539: not easy to define a variable and lock it Problem: Not easy to define a variable and lock it. Solution: Add ":const".
author Bram Moolenaar <Bram@vim.org>
date Sat, 15 Jun 2019 16:00:05 +0200
parents
children bc730bb54a7c
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
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
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 unlet j
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 unlet c
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 unlet b
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 unlet n
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 unlet bl
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 unlet here
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 endfunc
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 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
55 " 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
56 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
57 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
58 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
59 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
60 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
61 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
62 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
63 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
64 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
65 endif
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: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
67 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
68 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
69 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
70 hello
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 EOS
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 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
74 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
75 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
76 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
77 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
78 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
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 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
81 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
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 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
84 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
85 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
86 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
87
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 " Unlet
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 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
90 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
91 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
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:l
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:d
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:j
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:c
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 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
98 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
99 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
100 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
101 endfunc
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 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
104 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
105 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
106 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
107 endfunc
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 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
110 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
111
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 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
113 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
114 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
115
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 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
117 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
118 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
119 endfunc
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 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
122 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
123 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
124 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
125 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
126 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
127 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
128 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
129 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
130 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
131 endif
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 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
133 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
134 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
135
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('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
137 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
138 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
139 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
140 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
141 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
142 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
143 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
144 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
145 endif
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 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
147 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
148 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
149 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
150
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 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
152 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
153 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
154 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
155 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
156 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
157 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
158 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
159 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
160 endif
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 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
162 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
163 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
164
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 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
166 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
167 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
168 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
169 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
170 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
171 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
172 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
173 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
174 endif
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 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
176 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
177 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
178 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
179 endfunc
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 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
182 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
183 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
184 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
185
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 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
187 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
188 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
189 endfunc
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 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
192 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
193 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
194 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
195 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
196 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
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
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 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
200 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
201
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 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
203 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
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; 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
206 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
207 endfunc
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 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
210 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
211 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
212 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
213 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
214 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
215 endfunc
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 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
218 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
219 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
220
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 " Modify list
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 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
223 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
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 dict
00ffed9bbb65 patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 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
227 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
228 endfunc