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

patch 8.2.4484: Vim9: some error messages are not tested

Problem:    Vim9: some error messages are not tested.
Solution:   Add a few more test cases.  Delete dead code.
This commit is contained in:
Bram Moolenaar
2022-02-28 20:55:02 +00:00
parent 5de4c4372d
commit 1983f1aa31
5 changed files with 97 additions and 5 deletions

View File

@@ -550,6 +550,13 @@ def Test_assign_index()
bl[-2] = 0x66
assert_equal(0z77226644, bl)
lines =<< trim END
g:val = '22'
var bl = 0z11
bl[1] = g:val
END
v9.CheckDefExecAndScriptFailure(lines, 'E1030: Using a String as a Number: "22"')
# should not read the next line when generating "a.b"
var a = {}
a.b = {}
@@ -1233,12 +1240,18 @@ def Test_script_var_default()
var lines =<< trim END
vim9script
var l: list<number>
var li = [1, 2]
var bl: blob
var bli = 0z12
var d: dict<number>
var di = {'a': 1, 'b': 2}
def Echo()
assert_equal([], l)
assert_equal([1, 2], li)
assert_equal(0z, bl)
assert_equal(0z12, bli)
assert_equal({}, d)
assert_equal({'a': 1, 'b': 2}, di)
enddef
Echo()
END
@@ -1502,6 +1515,30 @@ def Test_assign_list()
END
v9.CheckDefAndScriptSuccess(lines)
lines =<< trim END
var l = [1, 2]
g:idx = 'x'
l[g:idx : 1] = [0]
echo l
END
v9.CheckDefExecAndScriptFailure(lines, 'E1030: Using a String as a Number: "x"')
lines =<< trim END
var l = [1, 2]
g:idx = 3
l[g:idx : 1] = [0]
echo l
END
v9.CheckDefExecAndScriptFailure(lines, 'E684: list index out of range: 3')
lines =<< trim END
var l = [1, 2]
g:idx = 'y'
l[1 : g:idx] = [0]
echo l
END
v9.CheckDefExecAndScriptFailure(lines, ['E1012: Type mismatch; expected number but got string', 'E1030: Using a String as a Number: "y"'])
v9.CheckDefFailure(["var l: list<number> = ['', true]"], 'E1012: Type mismatch; expected list<number> but got list<any>', 1)
v9.CheckDefFailure(["var l: list<list<number>> = [['', true]]"], 'E1012: Type mismatch; expected list<list<number>> but got list<list<any>>', 1)
enddef

View File

@@ -2782,6 +2782,23 @@ def Test_expr8_any_index_slice()
v9.CheckDefAndScriptSuccess(lines)
lines =<< trim END
vim9script
def PosIdx(s: string): string
return s[1]
enddef
def NegIdx(s: string): string
return s[-1]
enddef
set enc=latin1
assert_equal("\xe4", PosIdx("a\xe4\xe5"))
assert_equal("\xe5", NegIdx("a\xe4\xe5"))
set enc=utf-8
END
v9.CheckScriptSuccess(lines)
v9.CheckDefExecAndScriptFailure(['echo g:testblob[2]'], 'E979:', 1)
v9.CheckDefExecAndScriptFailure(['echo g:testblob[-3]'], 'E979:', 1)

View File

@@ -550,6 +550,44 @@ def Test_call_ufunc_count()
unlet g:counter
enddef
def Test_call_ufunc_failure()
var lines =<< trim END
vim9script
def Tryit()
g:Global(1, 2, 3)
enddef
func g:Global(a, b, c)
echo a:a a:b a:c
endfunc
defcompile
func! g:Global(a, b)
echo a:a a:b
endfunc
Tryit()
END
v9.CheckScriptFailure(lines, 'E118: Too many arguments for function: Global')
delfunc g:Global
lines =<< trim END
vim9script
g:Ref = function('len')
def Tryit()
g:Ref('x')
enddef
defcompile
g:Ref = function('add')
Tryit()
END
v9.CheckScriptFailure(lines, 'E119: Not enough arguments for function: add')
unlet g:Ref
enddef
def s:MyVarargs(arg: string, ...rest: list<string>): string
var res = arg
for s in rest

View File

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

View File

@@ -1027,7 +1027,7 @@ call_by_name(
{
int func_idx = find_internal_func(name);
if (func_idx < 0)
if (func_idx < 0) // Impossible?
return FAIL;
if (check_internal_func(func_idx, argcount) < 0)
return FAIL;
@@ -1452,8 +1452,6 @@ get_split_sourceline(
char_u *p;
char_u *line;
if (*sp->nextline == NUL)
return NULL;
p = vim_strchr(sp->nextline, '\n');
if (p == NULL)
{
@@ -1911,11 +1909,11 @@ execute_storerange(isn_T *iptr, ectx_T *ectx)
else
n2 = (long)tv_get_number_chk(tv_idx2, &error);
if (error)
status = FAIL;
status = FAIL; // cannot happen?
else
{
listitem_T *li1 = check_range_index_one(
tv_dest->vval.v_list, &n1, FALSE);
tv_dest->vval.v_list, &n1, FALSE);
if (li1 == NULL)
status = FAIL;