Mercurial > vim
annotate src/testdir/test_const.vim @ 34493:1fa23ccd6d9a v9.1.0153
patch 9.1.0153: Text properties corrupted with fo+=aw and backspace
Commit: https://github.com/vim/vim/commit/7ac1145fbebb66dfee325dc5265309877d941c4e
Author: zeertzjq <zeertzjq@outlook.com>
Date: Wed Mar 6 20:54:22 2024 +0100
patch 9.1.0153: Text properties corrupted with fo+=aw and backspace
Problem: Text properties corrupted with fo+=aw and backspace
Solution: Allocate line and move text properties
(zeertzjq)
closes: #14147
Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 06 Mar 2024 21:00:11 +0100 |
parents | 04205b7d67d5 |
children |
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:') |
21843
4a4678d26822
patch 8.2.1471: :const only locks the variable, not the value
Bram Moolenaar <Bram@vim.org>
parents:
19689
diff
changeset
|
44 call assert_fails('call filter(l, "v:val % 2 == 0")', 'E741:') |
17079
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 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
|
46 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
|
47 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
|
48 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
|
49 endif |
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 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
|
51 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
|
52 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
|
53 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
|
54 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 " Unlet |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 unlet i |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 unlet f |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 unlet s |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 unlet F |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 unlet l |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 unlet d |
17087
bc730bb54a7c
patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents:
17079
diff
changeset
|
62 if has('channel') |
bc730bb54a7c
patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents:
17079
diff
changeset
|
63 unlet j |
bc730bb54a7c
patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents:
17079
diff
changeset
|
64 unlet c |
bc730bb54a7c
patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents:
17079
diff
changeset
|
65 endif |
17079
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 unlet b |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 unlet n |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 unlet bl |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 unlet here |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 endfunc |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 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
|
73 " 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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 endif |
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: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
|
85 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
|
86 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
|
87 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
|
88 hello |
17079
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 EOS |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 |
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: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
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 endif |
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: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
|
102 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
|
103 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
|
104 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
|
105 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 " Unlet |
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:i |
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:f |
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:s |
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:F |
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:l |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 unlet l:d |
17087
bc730bb54a7c
patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents:
17079
diff
changeset
|
113 if has('channel') |
bc730bb54a7c
patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents:
17079
diff
changeset
|
114 unlet l:j |
bc730bb54a7c
patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents:
17079
diff
changeset
|
115 unlet l:c |
bc730bb54a7c
patch 8.1.1543: const test fails with small features
Bram Moolenaar <Bram@vim.org>
parents:
17079
diff
changeset
|
116 endif |
17079
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:b |
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:n |
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:bl |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 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
|
121 endfunc |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
122 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
123 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
|
124 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
|
125 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
|
126 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
|
127 endfunc |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
128 |
17918
9606c0adc148
patch 8.1.1955: tests contain typos
Bram Moolenaar <Bram@vim.org>
parents:
17172
diff
changeset
|
129 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
|
130 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
|
131 |
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 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
|
133 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
|
134 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
|
135 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
136 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
|
137 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
|
138 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
|
139 endfunc |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
140 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 endif |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
152 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
|
153 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
|
154 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
|
155 |
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 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 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
|
164 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
|
165 endif |
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 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
|
167 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
|
168 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
|
169 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
|
170 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 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
|
179 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
|
180 endif |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
181 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
|
182 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
|
183 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
|
184 |
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 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
|
186 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
|
187 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
|
188 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
|
189 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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 endif |
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 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
|
196 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
|
197 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
|
198 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
|
199 endfunc |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
200 |
18713
baf890fa1621
patch 8.1.2348: :const cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents:
17918
diff
changeset
|
201 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
|
202 const x = 0 |
baf890fa1621
patch 8.1.2348: :const cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents:
17918
diff
changeset
|
203 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
|
204 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
|
205 endfunc |
baf890fa1621
patch 8.1.2348: :const cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents:
17918
diff
changeset
|
206 |
18715
bd4c34db84ab
patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents:
18713
diff
changeset
|
207 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
|
208 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
|
209 lockvar x |
22087
ff21e2962490
patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
210 call assert_fails('let x = "there"', 'E741:') |
18715
bd4c34db84ab
patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents:
18713
diff
changeset
|
211 if 0 | unlockvar x | endif |
22087
ff21e2962490
patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents:
21847
diff
changeset
|
212 call assert_fails('let x = "there"', 'E741:') |
18715
bd4c34db84ab
patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents:
18713
diff
changeset
|
213 unlockvar x |
bd4c34db84ab
patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents:
18713
diff
changeset
|
214 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
|
215 |
bd4c34db84ab
patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents:
18713
diff
changeset
|
216 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
|
217 let x = 'again' |
22298
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22087
diff
changeset
|
218 |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22087
diff
changeset
|
219 let val = [1, 2, 3] |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22087
diff
changeset
|
220 lockvar 0 val |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22087
diff
changeset
|
221 let val[0] = 9 |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22087
diff
changeset
|
222 call assert_equal([9, 2, 3], val) |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22087
diff
changeset
|
223 call add(val, 4) |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22087
diff
changeset
|
224 call assert_equal([9, 2, 3, 4], val) |
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22087
diff
changeset
|
225 call assert_fails('let val = [4, 5, 6]', 'E1122:') |
24685
04205b7d67d5
patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
226 |
04205b7d67d5
patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
227 let l =<< trim END |
04205b7d67d5
patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
228 let d = {} |
04205b7d67d5
patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
229 lockvar d |
04205b7d67d5
patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
230 func d.fn() |
04205b7d67d5
patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
231 return 1 |
04205b7d67d5
patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
232 endfunc |
04205b7d67d5
patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
233 END |
04205b7d67d5
patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
234 let @a = l->join("\n") |
04205b7d67d5
patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
235 call assert_fails('exe @a', 'E741:') |
04205b7d67d5
patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
236 |
04205b7d67d5
patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
237 let l =<< trim END |
04205b7d67d5
patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
238 let d = {} |
04205b7d67d5
patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
239 let d.fn = function("min") |
04205b7d67d5
patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
240 lockvar d.fn |
04205b7d67d5
patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
241 func! d.fn() |
04205b7d67d5
patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
242 return 1 |
04205b7d67d5
patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
243 endfunc |
04205b7d67d5
patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
244 END |
04205b7d67d5
patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
245 let @a = l->join("\n") |
04205b7d67d5
patch 8.2.2881: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
246 call assert_fails('exe @a', 'E741:') |
18715
bd4c34db84ab
patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents:
18713
diff
changeset
|
247 endfunc |
bd4c34db84ab
patch 8.1.2349: :lockvar and :unlockvar cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents:
18713
diff
changeset
|
248 |
17079
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
249 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
|
250 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
|
251 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
|
252 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
|
253 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
254 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
|
255 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
|
256 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
|
257 endfunc |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
258 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 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
|
266 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
267 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
|
268 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
|
269 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
270 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
|
271 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
|
272 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
273 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
|
274 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
|
275 endfunc |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
276 |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
277 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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 call assert_fails('const &g:encoding = "utf-8"', 'E996:') |
19689
da98d2ed8dc5
patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
18715
diff
changeset
|
283 |
da98d2ed8dc5
patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
18715
diff
changeset
|
284 call assert_fails('const [a, $CONST_FOO] = [369, "abc"]', 'E996:') |
da98d2ed8dc5
patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
18715
diff
changeset
|
285 call assert_equal(369, a) |
da98d2ed8dc5
patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
18715
diff
changeset
|
286 call assert_equal(v:null, getenv("CONST_FOO")) |
da98d2ed8dc5
patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
18715
diff
changeset
|
287 |
da98d2ed8dc5
patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
18715
diff
changeset
|
288 call assert_fails('const [b; $CONST_FOO] = [246, 2, "abc"]', 'E996:') |
da98d2ed8dc5
patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
18715
diff
changeset
|
289 call assert_equal(246, b) |
da98d2ed8dc5
patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
18715
diff
changeset
|
290 call assert_equal(v:null, getenv("CONST_FOO")) |
17079
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
291 endfunc |
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
292 |
17109
cc5d4b4bae83
patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents:
17087
diff
changeset
|
293 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
|
294 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
|
295 |
cc5d4b4bae83
patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents:
17087
diff
changeset
|
296 " 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
|
297 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
|
298 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
|
299 |
cc5d4b4bae83
patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents:
17087
diff
changeset
|
300 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
|
301 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
|
302 endfunc |
cc5d4b4bae83
patch 8.1.1554: docs and tests for :const can be improved
Bram Moolenaar <Bram@vim.org>
parents:
17087
diff
changeset
|
303 |
21847
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
304 func Test_lock_depth_is_2() |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
305 " Modify list - error when changing item or adding/removing items |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
306 const l = [1, 2, [3, 4]] |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
307 call assert_fails('let l[0] = 42', 'E741:') |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
308 call assert_fails('let l[2][0] = 42', 'E741:') |
21843
4a4678d26822
patch 8.2.1471: :const only locks the variable, not the value
Bram Moolenaar <Bram@vim.org>
parents:
19689
diff
changeset
|
309 call assert_fails('call add(l, 4)', 'E741:') |
4a4678d26822
patch 8.2.1471: :const only locks the variable, not the value
Bram Moolenaar <Bram@vim.org>
parents:
19689
diff
changeset
|
310 call assert_fails('unlet l[1]', 'E741:') |
17079
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
311 |
21847
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
312 " Modify blob - error when changing |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
313 const b = 0z001122 |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
314 call assert_fails('let b[0] = 42', 'E741:') |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
315 |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
316 " Modify dict - error when changing item or adding/removing items |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
317 const d = {'foo': 10} |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
318 call assert_fails("let d['foo'] = 'hello'", 'E741:') |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
319 call assert_fails("let d.foo = 'hello'", 'E741:') |
21843
4a4678d26822
patch 8.2.1471: :const only locks the variable, not the value
Bram Moolenaar <Bram@vim.org>
parents:
19689
diff
changeset
|
320 call assert_fails("let d['bar'] = 'hello'", 'E741:') |
4a4678d26822
patch 8.2.1471: :const only locks the variable, not the value
Bram Moolenaar <Bram@vim.org>
parents:
19689
diff
changeset
|
321 call assert_fails("unlet d['foo']", 'E741:') |
21847
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
322 |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
323 " Modifying list or dict item contents is OK. |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
324 let lvar = ['a', 'b'] |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
325 let bvar = 0z1122 |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
326 const l2 = [0, lvar, bvar] |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
327 let l2[1][0] = 'c' |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
328 let l2[2][1] = 0x33 |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
329 call assert_equal([0, ['c', 'b'], 0z1133], l2) |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
330 |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
331 const d2 = #{a: 0, b: lvar, c: 4} |
fb74a3387694
patch 8.2.1473: items in a list given to :const can still be modified
Bram Moolenaar <Bram@vim.org>
parents:
21843
diff
changeset
|
332 let d2.b[1] = 'd' |
17079
00ffed9bbb65
patch 8.1.1539: not easy to define a variable and lock it
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
333 endfunc |
19689
da98d2ed8dc5
patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
18715
diff
changeset
|
334 |
da98d2ed8dc5
patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
18715
diff
changeset
|
335 " vim: shiftwidth=2 sts=2 expandtab |