0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 8.2.4407: Vim9: some code not covered by tests

Problem:    Vim9: some code not covered by tests.
Solution:   Add more tests.  Avoid giving two errors.  Remove dead code.
This commit is contained in:
Bram Moolenaar
2022-02-17 13:08:26 +00:00
parent 2438430863
commit e08be09a08
5 changed files with 177 additions and 107 deletions

View File

@@ -543,6 +543,13 @@ def Test_assign_index()
d3.one.two.three = 123
assert_equal({one: {two: {three: 123}}}, d3)
# blob
var bl: blob = 0z11223344
bl[0] = 0x77
assert_equal(0z77223344, bl)
bl[-2] = 0x66
assert_equal(0z77226644, bl)
# should not read the next line when generating "a.b"
var a = {}
a.b = {}
@@ -591,6 +598,18 @@ def Test_assign_index()
dl.one = {}
END
v9.CheckDefFailure(lines, 'E1012: Type mismatch; expected list<number> but got dict<unknown>', 2)
lines =<< trim END
g:l = [1, 2]
g:l['x'] = 3
END
v9.CheckDefExecAndScriptFailure(lines, ['E39:', 'E1030:'], 2)
lines =<< trim END
var bl: blob = test_null_blob()
bl[1] = 8
END
v9.CheckDefExecAndScriptFailure(lines, ['E1184:', 'E979:'], 2)
enddef
def Test_init_in_for_loop()
@@ -1201,6 +1220,21 @@ def Test_assignment_default()
assert_equal(5678, nr)
enddef
def Test_script_var_default()
var lines =<< trim END
vim9script
var l: list<number>
var bl: blob
var d: dict<number>
def Echo()
assert_equal([], l)
assert_equal(0z, bl)
assert_equal({}, d)
enddef
END
v9.CheckScriptSuccess(lines)
enddef
let s:scriptvar = 'init'
def Test_assignment_var_list()
@@ -2082,6 +2116,25 @@ def Test_unlet()
'var ll = [1, 2]',
'unlet ll[0: 1]',
], 'E1004:', 2)
v9.CheckDefExecFailure([
'g:ll = [1, 2]',
'g:idx = "x"',
'unlet g:ll[g:idx]',
], 'E1029: Expected number but got string', 3)
v9.CheckDefExecFailure([
'g:ll = [1, 2, 3]',
'g:idx = "x"',
'unlet g:ll[g:idx : 2]',
], 'E1029: Expected number but got string', 3)
v9.CheckDefExecFailure([
'g:ll = [1, 2, 3]',
'g:idx = "x"',
'unlet g:ll[0 : g:idx]',
], 'E1029: Expected number but got string', 3)
# command recognized as assignment when skipping, should not give an error
v9.CheckScriptSuccess([
'vim9script',