Skip to content

Commit 1c196e7

Browse files
committed
patch 8.1.1554: docs and tests for :const can be improved
Problem: Docs and tests for :const can be improved. Solution: Improve documentation, add a few more tests. (Ryuichi Hayashida, closes #4551)
1 parent dc2ce58 commit 1c196e7

3 files changed

Lines changed: 34 additions & 3 deletions

File tree

runtime/doc/eval.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11619,10 +11619,9 @@ text...
1161911619
If the system does not support deleting an environment
1162011620
variable, it is made empty.
1162111621

11622-
*:cons* *:const* *E996*
11622+
*:cons* *:const*
1162311623
:cons[t] {var-name} = {expr1}
1162411624
:cons[t] [{name1}, {name2}, ...] = {expr1}
11625-
:cons[t] [{name1}, {name2}, ...] .= {expr1}
1162611625
:cons[t] [{name}, ..., ; {lastname}] = {expr1}
1162711626
:cons[t] {var-name} =<< [trim] {marker}
1162811627
text...
@@ -11641,7 +11640,11 @@ text...
1164111640
|:const| does not allow to for changing a variable. >
1164211641
:let x = 1
1164311642
:const x = 2 " Error!
11644-
<
11643+
< *E996*
11644+
Note that environment variables, option values and
11645+
register values cannot be used here, since they cannot
11646+
be locked.
11647+
1164511648
:lockv[ar][!] [depth] {name} ... *:lockvar* *:lockv*
1164611649
Lock the internal variable {name}. Locking means that
1164711650
it can no longer be changed (until it is unlocked).

src/testdir/test_const.vim

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@ func Test_define_var_with_lock()
2121
hello
2222
EOS
2323

24+
call assert_true(exists('i'))
25+
call assert_true(exists('f'))
26+
call assert_true(exists('s'))
27+
call assert_true(exists('F'))
28+
call assert_true(exists('l'))
29+
call assert_true(exists('d'))
30+
if has('channel')
31+
call assert_true(exists('j'))
32+
call assert_true(exists('c'))
33+
endif
34+
call assert_true(exists('b'))
35+
call assert_true(exists('n'))
36+
call assert_true(exists('bl'))
37+
call assert_true(exists('here'))
38+
2439
call assert_fails('let i = 1', 'E741:')
2540
call assert_fails('let f = 1.1', 'E741:')
2641
call assert_fails('let s = "vim"', 'E741:')
@@ -218,6 +233,17 @@ func Test_const_with_special_variables()
218233
call assert_fails('const &g:encoding = "utf-8"', 'E996:')
219234
endfunc
220235

236+
func Test_const_with_eval_name()
237+
let s = 'foo'
238+
239+
" eval name with :const should work
240+
const abc_{s} = 1
241+
const {s}{s} = 1
242+
243+
let s2 = 'abc_foo'
244+
call assert_fails('const {s2} = "bar"', 'E995:')
245+
endfunc
246+
221247
func Test_lock_depth_is_1()
222248
const l = [1, 2, 3]
223249
const d = {'foo': 10}

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,8 @@ static char *(features[]) =
777777

778778
static int included_patches[] =
779779
{ /* Add new patch number below this line */
780+
/**/
781+
1554,
780782
/**/
781783
1553,
782784
/**/

0 commit comments

Comments
 (0)