0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.2.3334: Vim9: not enough tests run with Vim9

Problem:    Vim9: not enough tests run with Vim9.
Solution:   Run a few more tests in Vim9 script and :def function. Fix
            islocked().  Fix error for locking local variable.
This commit is contained in:
Bram Moolenaar
2021-08-12 17:06:05 +02:00
parent 3e9c0b9608
commit bd77aa9274
4 changed files with 136 additions and 98 deletions

View File

@@ -6556,7 +6556,8 @@ f_islocked(typval_T *argvars, typval_T *rettv)
return; return;
end = get_lval(tv_get_string(&argvars[0]), NULL, &lv, FALSE, FALSE, end = get_lval(tv_get_string(&argvars[0]), NULL, &lv, FALSE, FALSE,
GLV_NO_AUTOLOAD | GLV_READ_ONLY, FNE_CHECK_START); GLV_NO_AUTOLOAD | GLV_READ_ONLY | GLV_NO_DECL,
FNE_CHECK_START);
if (end != NULL && lv.ll_name != NULL) if (end != NULL && lv.ll_name != NULL)
{ {
if (*end != NUL) if (*end != NUL)

View File

@@ -482,95 +482,112 @@ endfunc
" Nasty: deepcopy() dict that refers to itself (fails when noref used) " Nasty: deepcopy() dict that refers to itself (fails when noref used)
func Test_dict_deepcopy() func Test_dict_deepcopy()
let d = {1:1, 2:2} let lines =<< trim END
let l = [4, d, 6] VAR d = {1: 1, 2: '2'}
let d[3] = l VAR l = [4, d, 6]
let dc = deepcopy(d) LET d[3] = l
call assert_fails('call deepcopy(d, 1)', 'E698:') VAR dc = deepcopy(d)
let l2 = [0, l, l, 3] call deepcopy(d, 1)
let l[1] = l2 END
let l3 = deepcopy(l2) call CheckLegacyAndVim9Failure(lines, 'E698:')
call assert_true(l3[1] is l3[2])
let lines =<< trim END
VAR d = {1: 1, 2: '2'}
VAR l = [4, d, 6]
LET d[3] = l
VAR l2 = [0, l, l, 3]
LET l[1] = l2
VAR l3 = deepcopy(l2)
call assert_true(l3[1] is l3[2])
END
call CheckLegacyAndVim9Success(lines)
call assert_fails("call deepcopy([1, 2], 2)", 'E1023:') call assert_fails("call deepcopy([1, 2], 2)", 'E1023:')
endfunc endfunc
" Locked variables " Locked variables
func Test_list_locked_var() func Test_list_locked_var()
let expected = [ " Not tested with :def function, local vars cannot be locked.
\ [['1000-000', 'ppppppF'], let lines =<< trim END
\ ['0000-000', 'ppppppp'], VAR expected = [
\ ['0000-000', 'ppppppp']], \ [['1000-000', 'ppppppF'],
\ [['1000-000', 'ppppppF'], \ ['0000-000', 'ppppppp'],
\ ['0000-000', 'ppppppp'], \ ['0000-000', 'ppppppp']],
\ ['0000-000', 'ppppppp']], \ [['1000-000', 'ppppppF'],
\ [['1100-100', 'ppFppFF'], \ ['0000-000', 'ppppppp'],
\ ['0000-000', 'ppppppp'], \ ['0000-000', 'ppppppp']],
\ ['0000-000', 'ppppppp']], \ [['1100-100', 'ppFppFF'],
\ [['1110-110', 'pFFpFFF'], \ ['0000-000', 'ppppppp'],
\ ['0010-010', 'pFppFpp'], \ ['0000-000', 'ppppppp']],
\ ['0000-000', 'ppppppp']], \ [['1110-110', 'pFFpFFF'],
\ [['1111-111', 'FFFFFFF'], \ ['0010-010', 'pFppFpp'],
\ ['0011-011', 'FFpFFpp'], \ ['0000-000', 'ppppppp']],
\ ['0000-000', 'ppppppp']] \ [['1111-111', 'FFFFFFF'],
\ ] \ ['0011-011', 'FFpFFpp'],
for depth in range(5) \ ['0000-000', 'ppppppp']]
for u in range(3) \ ]
unlet! l for depth in range(5)
let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}] for u in range(3)
exe "lockvar " . depth . " l" VAR l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}]
if u == 1 exe "lockvar " .. depth .. " l"
exe "unlockvar l" if u == 1
elseif u == 2 exe "unlockvar l"
exe "unlockvar " . depth . " l" elseif u == 2
endif exe "unlockvar " .. depth .. " l"
let ps = islocked("l").islocked("l[1]").islocked("l[1][1]").islocked("l[1][1][0]").'-'.islocked("l[2]").islocked("l[2]['6']").islocked("l[2]['6'][7]") endif
call assert_equal(expected[depth][u][0], ps, 'depth: ' .. depth) VAR ps = islocked("l") .. islocked("l[1]") .. islocked("l[1][1]") .. islocked("l[1][1][0]") .. '-' .. islocked("l[2]") .. islocked("l[2]['6']") .. islocked("l[2]['6'][7]")
let ps = '' call assert_equal(expected[depth][u][0], ps, 'depth: ' .. depth)
try LET ps = ''
let l[1][1][0] = 99 try
let ps .= 'p' LET l[1][1][0] = 99
catch LET ps ..= 'p'
let ps .= 'F' catch
endtry LET ps ..= 'F'
try endtry
let l[1][1] = [99] try
let ps .= 'p' LET l[1][1] = [99]
catch LET ps ..= 'p'
let ps .= 'F' catch
endtry LET ps ..= 'F'
try endtry
let l[1] = [99] try
let ps .= 'p' LET l[1] = [99]
catch LET ps ..= 'p'
let ps .= 'F' catch
endtry LET ps ..= 'F'
try endtry
let l[2]['6'][7] = 99 try
let ps .= 'p' LET l[2]['6'][7] = 99
catch LET ps ..= 'p'
let ps .= 'F' catch
endtry LET ps ..= 'F'
try endtry
let l[2][6] = {99: 99} try
let ps .= 'p' LET l[2][6] = {99: 99}
catch LET ps ..= 'p'
let ps .= 'F' catch
endtry LET ps ..= 'F'
try endtry
let l[2] = {99: 99} try
let ps .= 'p' LET l[2] = {99: 99}
catch LET ps ..= 'p'
let ps .= 'F' catch
endtry LET ps ..= 'F'
try endtry
let l = [99] try
let ps .= 'p' LET l = [99]
catch LET ps ..= 'p'
let ps .= 'F' catch
endtry LET ps ..= 'F'
call assert_equal(expected[depth][u][1], ps, 'depth: ' .. depth) endtry
endfor call assert_equal(expected[depth][u][1], ps, 'depth: ' .. depth)
endfor unlock! l
endfor
endfor
END
call CheckTransLegacySuccess(lines)
call CheckTransVim9Success(lines)
call assert_fails("let x=islocked('a b')", 'E488:') call assert_fails("let x=islocked('a b')", 'E488:')
let mylist = [1, 2, 3] let mylist = [1, 2, 3]
call assert_fails("let x = islocked('mylist[1:2]')", 'E786:') call assert_fails("let x = islocked('mylist[1:2]')", 'E786:')
@@ -580,6 +597,7 @@ endfunc
" Unletting locked variables " Unletting locked variables
func Test_list_locked_var_unlet() func Test_list_locked_var_unlet()
" Not tested with Vim9: script and local variables cannot be unlocked
let expected = [ let expected = [
\ [['1000-000', 'ppppppp'], \ [['1000-000', 'ppppppp'],
\ ['0000-000', 'ppppppp'], \ ['0000-000', 'ppppppp'],
@@ -674,26 +692,43 @@ endfunc
" unlet after lock on dict item " unlet after lock on dict item
func Test_dict_item_lock_unlet() func Test_dict_item_lock_unlet()
let d = {'a': 99, 'b': 100} let lines =<< trim END
lockvar d.a VAR d = {'a': 99, 'b': 100}
unlet d.a lockvar d.a
call assert_equal({'b' : 100}, d) unlet d.a
call assert_equal({'b': 100}, d)
END
" TODO: make this work in a :def function
"call CheckLegacyAndVim9Success(lines)
call CheckTransLegacySuccess(lines)
call CheckTransVim9Success(lines)
endfunc endfunc
" filter() after lock on dict item " filter() after lock on dict item
func Test_dict_lock_filter() func Test_dict_lock_filter()
let d = {'a': 99, 'b': 100} let lines =<< trim END
lockvar d.a VAR d = {'a': 99, 'b': 100}
call filter(d, 'v:key != "a"') lockvar d.a
call assert_equal({'b' : 100}, d) call filter(d, 'v:key != "a"')
call assert_equal({'b': 100}, d)
END
" TODO: make this work in a :def function
"call CheckLegacyAndVim9Success(lines)
call CheckTransLegacySuccess(lines)
call CheckTransVim9Success(lines)
endfunc endfunc
" map() after lock on dict " map() after lock on dict
func Test_dict_lock_map() func Test_dict_lock_map()
let d = {'a': 99, 'b': 100} let lines =<< trim END
lockvar 1 d VAR d = {'a': 99, 'b': 100}
call map(d, 'v:val + 200') lockvar 1 d
call assert_equal({'a' : 299, 'b' : 300}, d) call map(d, 'v:val + 200')
call assert_equal({'a': 299, 'b': 300}, d)
END
" This won't work in a :def function
call CheckTransLegacySuccess(lines)
call CheckTransVim9Success(lines)
endfunc endfunc
" No extend() after lock on dict item " No extend() after lock on dict item

View File

@@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
3334,
/**/ /**/
3333, 3333,
/**/ /**/

View File

@@ -7433,7 +7433,7 @@ compile_lock_unlock(
// Cannot use :lockvar and :unlockvar on local variables. // Cannot use :lockvar and :unlockvar on local variables.
if (p[1] != ':') if (p[1] != ':')
{ {
char_u *end = skip_var_one(p, FALSE); char_u *end = find_name_end(p, NULL, NULL, FNE_CHECK_START);
if (lookup_local(p, end - p, NULL, cctx) == OK) if (lookup_local(p, end - p, NULL, cctx) == OK)
{ {