Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d986b9d

Browse files
committed
vim-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 vim/vim#4551) vim/vim@1c196e7
1 parent d14052c commit d986b9d

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

runtime/doc/eval.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9631,15 +9631,10 @@ This does NOT work: >
96319631
If the system does not support deleting an environment
96329632
variable, it is made empty.
96339633

9634-
*:cons* *:const* *E996*
9634+
*:cons* *:const*
96359635
:cons[t] {var-name} = {expr1}
96369636
:cons[t] [{name1}, {name2}, ...] = {expr1}
9637-
:cons[t] [{name1}, {name2}, ...] .= {expr1}
96389637
:cons[t] [{name}, ..., ; {lastname}] = {expr1}
9639-
:cons[t] {var-name} =<< [trim] {marker}
9640-
text...
9641-
text...
9642-
{marker}
96439638
Similar to |:let|, but additionally lock the variable
96449639
after setting the value. This is the same as locking
96459640
the variable with |:lockvar| just after |:let|, thus: >
@@ -9653,7 +9648,11 @@ text...
96539648
|:const| does not allow to for changing a variable. >
96549649
:let x = 1
96559650
:const x = 2 " Error!
9656-
<
9651+
< *E996*
9652+
Note that environment variables, option values and
9653+
register values cannot be used here, since they cannot
9654+
be locked.
9655+
96579656
:lockv[ar][!] [depth] {name} ... *:lockvar* *:lockv*
96589657
Lock the internal variable {name}. Locking means that
96599658
it can no longer be changed (until it is unlocked).

src/nvim/testdir/test_const.vim

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ func Test_define_var_with_lock()
1818
const b = v:true
1919
const n = v:null
2020

21+
call assert_true(exists('i'))
22+
call assert_true(exists('f'))
23+
call assert_true(exists('s'))
24+
call assert_true(exists('F'))
25+
call assert_true(exists('l'))
26+
call assert_true(exists('d'))
27+
if has('channel')
28+
call assert_true(exists('j'))
29+
call assert_true(exists('c'))
30+
endif
31+
call assert_true(exists('b'))
32+
call assert_true(exists('n'))
33+
2134
call assert_fails('let i = 1', 'E741:')
2235
call assert_fails('let f = 1.1', 'E741:')
2336
call assert_fails('let s = "vim"', 'E741:')
@@ -199,6 +212,17 @@ func Test_const_with_special_variables()
199212
call assert_fails('const &g:encoding = "utf-8"', 'E996:')
200213
endfunc
201214

215+
func Test_const_with_eval_name()
216+
let s = 'foo'
217+
218+
" eval name with :const should work
219+
const abc_{s} = 1
220+
const {s}{s} = 1
221+
222+
let s2 = 'abc_foo'
223+
call assert_fails('const {s2} = "bar"', 'E995:')
224+
endfunc
225+
202226
func Test_lock_depth_is_1()
203227
const l = [1, 2, 3]
204228
const d = {'foo': 10}

src/nvim/version.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ static const int included_patches[] = {
367367
1557,
368368
1556,
369369
1555,
370-
// 1554,
370+
1554,
371371
1553,
372372
// 1552,
373373
// 1551,

0 commit comments

Comments
 (0)