forked from aniani/vim
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:
parent
2438430863
commit
e08be09a08
@ -543,6 +543,13 @@ def Test_assign_index()
|
|||||||
d3.one.two.three = 123
|
d3.one.two.three = 123
|
||||||
assert_equal({one: {two: {three: 123}}}, d3)
|
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"
|
# should not read the next line when generating "a.b"
|
||||||
var a = {}
|
var a = {}
|
||||||
a.b = {}
|
a.b = {}
|
||||||
@ -591,6 +598,18 @@ def Test_assign_index()
|
|||||||
dl.one = {}
|
dl.one = {}
|
||||||
END
|
END
|
||||||
v9.CheckDefFailure(lines, 'E1012: Type mismatch; expected list<number> but got dict<unknown>', 2)
|
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
|
enddef
|
||||||
|
|
||||||
def Test_init_in_for_loop()
|
def Test_init_in_for_loop()
|
||||||
@ -1201,6 +1220,21 @@ def Test_assignment_default()
|
|||||||
assert_equal(5678, nr)
|
assert_equal(5678, nr)
|
||||||
enddef
|
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'
|
let s:scriptvar = 'init'
|
||||||
|
|
||||||
def Test_assignment_var_list()
|
def Test_assignment_var_list()
|
||||||
@ -2082,6 +2116,25 @@ def Test_unlet()
|
|||||||
'var ll = [1, 2]',
|
'var ll = [1, 2]',
|
||||||
'unlet ll[0: 1]',
|
'unlet ll[0: 1]',
|
||||||
], 'E1004:', 2)
|
], '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
|
# command recognized as assignment when skipping, should not give an error
|
||||||
v9.CheckScriptSuccess([
|
v9.CheckScriptSuccess([
|
||||||
'vim9script',
|
'vim9script',
|
||||||
|
@ -1528,6 +1528,17 @@ def Test_lockvar()
|
|||||||
assert_equal({a: 7, b: 5}, d)
|
assert_equal({a: 7, b: 5}, d)
|
||||||
|
|
||||||
var lines =<< trim END
|
var lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
g:bl = 0z1122
|
||||||
|
lockvar g:bl
|
||||||
|
def Tryit()
|
||||||
|
g:bl[1] = 99
|
||||||
|
enddef
|
||||||
|
Tryit()
|
||||||
|
END
|
||||||
|
v9.CheckScriptFailure(lines, 'E741:', 1)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
var theList = [1, 2, 3]
|
var theList = [1, 2, 3]
|
||||||
def SetList()
|
def SetList()
|
||||||
|
@ -910,6 +910,14 @@ def Test_nested_def_list()
|
|||||||
v9.CheckScriptFailure(lines, 'E476:', 1)
|
v9.CheckScriptFailure(lines, 'E476:', 1)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def Test_global_function_not_found()
|
||||||
|
var lines =<< trim END
|
||||||
|
g:Ref = 123
|
||||||
|
call g:Ref()
|
||||||
|
END
|
||||||
|
v9.CheckDefExecAndScriptFailure(lines, ['E117:', 'E1085:'], 2)
|
||||||
|
enddef
|
||||||
|
|
||||||
def Test_global_local_function()
|
def Test_global_local_function()
|
||||||
var lines =<< trim END
|
var lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
|
@ -750,6 +750,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 */
|
||||||
|
/**/
|
||||||
|
4407,
|
||||||
/**/
|
/**/
|
||||||
4406,
|
4406,
|
||||||
/**/
|
/**/
|
||||||
|
@ -1750,16 +1750,10 @@ execute_storeindex(isn_T *iptr, ectx_T *ectx)
|
|||||||
status = FAIL;
|
status = FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (dest_type != tv_dest->v_type)
|
|
||||||
{
|
|
||||||
// just in case, should be OK
|
|
||||||
semsg(_(e_expected_str_but_got_str),
|
|
||||||
vartype_name(dest_type),
|
|
||||||
vartype_name(tv_dest->v_type));
|
|
||||||
status = FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (status == OK && dest_type == VAR_LIST)
|
if (status == OK)
|
||||||
|
{
|
||||||
|
if (dest_type == VAR_LIST)
|
||||||
{
|
{
|
||||||
long lidx = (long)tv_idx->vval.v_number;
|
long lidx = (long)tv_idx->vval.v_number;
|
||||||
list_T *list = tv_dest->vval.v_list;
|
list_T *list = tv_dest->vval.v_list;
|
||||||
@ -1798,7 +1792,7 @@ execute_storeindex(isn_T *iptr, ectx_T *ectx)
|
|||||||
clear_tv(tv);
|
clear_tv(tv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (status == OK && dest_type == VAR_DICT)
|
else if (dest_type == VAR_DICT)
|
||||||
{
|
{
|
||||||
char_u *key = tv_idx->vval.v_string;
|
char_u *key = tv_idx->vval.v_string;
|
||||||
dict_T *dict = tv_dest->vval.v_dict;
|
dict_T *dict = tv_dest->vval.v_dict;
|
||||||
@ -1815,7 +1809,8 @@ execute_storeindex(isn_T *iptr, ectx_T *ectx)
|
|||||||
di = dict_find(dict, key, -1);
|
di = dict_find(dict, key, -1);
|
||||||
if (di != NULL)
|
if (di != NULL)
|
||||||
{
|
{
|
||||||
if (error_if_locked(di->di_tv.v_lock, e_cannot_change_dict_item))
|
if (error_if_locked(di->di_tv.v_lock,
|
||||||
|
e_cannot_change_dict_item))
|
||||||
return FAIL;
|
return FAIL;
|
||||||
// overwrite existing value
|
// overwrite existing value
|
||||||
clear_tv(&di->di_tv);
|
clear_tv(&di->di_tv);
|
||||||
@ -1831,7 +1826,7 @@ execute_storeindex(isn_T *iptr, ectx_T *ectx)
|
|||||||
clear_tv(tv);
|
clear_tv(tv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (status == OK && dest_type == VAR_BLOB)
|
else if (dest_type == VAR_BLOB)
|
||||||
{
|
{
|
||||||
long lidx = (long)tv_idx->vval.v_number;
|
long lidx = (long)tv_idx->vval.v_number;
|
||||||
blob_T *blob = tv_dest->vval.v_blob;
|
blob_T *blob = tv_dest->vval.v_blob;
|
||||||
@ -1867,6 +1862,7 @@ execute_storeindex(isn_T *iptr, ectx_T *ectx)
|
|||||||
status = FAIL;
|
status = FAIL;
|
||||||
semsg(_(e_cannot_index_str), vartype_name(dest_type));
|
semsg(_(e_cannot_index_str), vartype_name(dest_type));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
clear_tv(tv_idx);
|
clear_tv(tv_idx);
|
||||||
clear_tv(tv_dest);
|
clear_tv(tv_dest);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user