forked from aniani/vim
patch 8.2.2099: Vim9: some checks are not tested
Problem: Vim9: some checks are not tested. Solution: Add a few more tests. Give better error messages.
This commit is contained in:
@@ -188,6 +188,12 @@ func Test_expr1_trinary_fails()
|
|||||||
call CheckDefExecFailure(["var x = [] ? 'one' : 'two'"], 'E745:', 1)
|
call CheckDefExecFailure(["var x = [] ? 'one' : 'two'"], 'E745:', 1)
|
||||||
call CheckDefExecFailure(["var x = {} ? 'one' : 'two'"], 'E728:', 1)
|
call CheckDefExecFailure(["var x = {} ? 'one' : 'two'"], 'E728:', 1)
|
||||||
|
|
||||||
|
call CheckDefExecFailure(["var x = false ? "], 'E1097:', 2)
|
||||||
|
call CheckDefExecFailure(["var x = false ? 'one' : "], 'E1097:', 2)
|
||||||
|
|
||||||
|
call CheckDefExecFailure(["var x = true ? xxx : 'foo'"], 'E1001:', 1)
|
||||||
|
call CheckDefExecFailure(["var x = false ? 'foo' : xxx"], 'E1001:', 1)
|
||||||
|
|
||||||
if has('float')
|
if has('float')
|
||||||
call CheckDefFailure(["var x = 0.1 ? 'one' : 'two'"], 'E805:', 1)
|
call CheckDefFailure(["var x = 0.1 ? 'one' : 'two'"], 'E805:', 1)
|
||||||
endif
|
endif
|
||||||
@@ -346,6 +352,8 @@ def Test_expr2_fails()
|
|||||||
call CheckDefFailure(["var x = 1 ||2"], msg, 1)
|
call CheckDefFailure(["var x = 1 ||2"], msg, 1)
|
||||||
call CheckDefFailure(["var x = 1|| 2"], msg, 1)
|
call CheckDefFailure(["var x = 1|| 2"], msg, 1)
|
||||||
|
|
||||||
|
call CheckDefFailure(["var x = false || "], 'E1097:', 2)
|
||||||
|
|
||||||
call CheckDefFailure(["var x = 1 || xxx"], 'E1001:', 1)
|
call CheckDefFailure(["var x = 1 || xxx"], 'E1001:', 1)
|
||||||
call CheckDefFailure(["var x = [] || false"], 'E1012:', 1)
|
call CheckDefFailure(["var x = [] || false"], 'E1012:', 1)
|
||||||
call CheckDefFailure(["if 'yes' || 0", 'echo 0', 'endif'], 'E1012: Type mismatch; expected bool but got string', 1)
|
call CheckDefFailure(["if 'yes' || 0", 'echo 0', 'endif'], 'E1012: Type mismatch; expected bool but got string', 1)
|
||||||
@@ -579,6 +587,8 @@ def Test_expr4_equal()
|
|||||||
CheckDefAndScriptSuccess(lines)
|
CheckDefAndScriptSuccess(lines)
|
||||||
|
|
||||||
CheckDefFailure(["var x = 'a' == xxx"], 'E1001:', 1)
|
CheckDefFailure(["var x = 'a' == xxx"], 'E1001:', 1)
|
||||||
|
CheckDefFailure(["var x = 'a' == "], 'E1097:', 2)
|
||||||
|
|
||||||
CheckDefExecFailure(['var items: any', 'eval 1', 'eval 2', 'if items == []', 'endif'], 'E691:', 4)
|
CheckDefExecFailure(['var items: any', 'eval 1', 'eval 2', 'if items == []', 'endif'], 'E691:', 4)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
@@ -1349,6 +1359,7 @@ def Test_expr6()
|
|||||||
CheckDefAndScriptSuccess(lines)
|
CheckDefAndScriptSuccess(lines)
|
||||||
|
|
||||||
CheckDefFailure(["var x = 6 * xxx"], 'E1001:', 1)
|
CheckDefFailure(["var x = 6 * xxx"], 'E1001:', 1)
|
||||||
|
CheckDefFailure(["var d = 6 * "], 'E1097:', 2)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_expr6_vim9script()
|
def Test_expr6_vim9script()
|
||||||
@@ -1520,6 +1531,7 @@ def Test_expr7t()
|
|||||||
assert_equal(234, nr)
|
assert_equal(234, nr)
|
||||||
|
|
||||||
CheckDefFailure(["var x = <nr>123"], 'E1010:', 1)
|
CheckDefFailure(["var x = <nr>123"], 'E1010:', 1)
|
||||||
|
CheckDefFailure(["var x = <number>"], 'E1097:', 2)
|
||||||
CheckDefFailure(["var x = <number >123"], 'E1068:', 1)
|
CheckDefFailure(["var x = <number >123"], 'E1068:', 1)
|
||||||
CheckDefFailure(["var x = <number 123"], 'E1104:', 1)
|
CheckDefFailure(["var x = <number 123"], 'E1104:', 1)
|
||||||
enddef
|
enddef
|
||||||
@@ -2052,6 +2064,33 @@ def Test_expr7_dict_vim9script()
|
|||||||
END
|
END
|
||||||
CheckScriptFailure(lines, 'E1012:', 2)
|
CheckScriptFailure(lines, 'E1012:', 2)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
var d = {['a']: 234, ['b': 'x'}
|
||||||
|
END
|
||||||
|
CheckScriptFailure(lines, 'E1139:', 2)
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
def Func()
|
||||||
|
var d = {['a']: 234, ['b': 'x'}
|
||||||
|
enddef
|
||||||
|
defcompile
|
||||||
|
END
|
||||||
|
CheckScriptFailure(lines, 'E1139:', 1)
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
var d = {'a':
|
||||||
|
END
|
||||||
|
CheckScriptFailure(lines, 'E15:', 2)
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
def Func()
|
||||||
|
var d = {'a':
|
||||||
|
enddef
|
||||||
|
defcompile
|
||||||
|
END
|
||||||
|
CheckScriptFailure(lines, 'E723:', 1)
|
||||||
|
|
||||||
lines =<< trim END
|
lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
def Failing()
|
def Failing()
|
||||||
@@ -2566,6 +2605,39 @@ def Test_expr7_string_subscript()
|
|||||||
END
|
END
|
||||||
CheckDefSuccess(lines)
|
CheckDefSuccess(lines)
|
||||||
CheckScriptSuccess(['vim9script'] + lines)
|
CheckScriptSuccess(['vim9script'] + lines)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
var d = 'asdf'[1:
|
||||||
|
END
|
||||||
|
CheckDefFailure(lines, 'E1097:', 2)
|
||||||
|
lines =<< trim END
|
||||||
|
var d = 'asdf'[1:xxx]
|
||||||
|
END
|
||||||
|
CheckDefFailure(lines, 'E1001:', 1)
|
||||||
|
lines =<< trim END
|
||||||
|
var d = 'asdf'[1:2
|
||||||
|
END
|
||||||
|
CheckDefFailure(lines, 'E1097:', 2)
|
||||||
|
lines =<< trim END
|
||||||
|
var d = 'asdf'[1:2
|
||||||
|
echo d
|
||||||
|
END
|
||||||
|
CheckDefFailure(lines, 'E111:', 2)
|
||||||
|
lines =<< trim END
|
||||||
|
var d = 'asdf'['1']
|
||||||
|
echo d
|
||||||
|
END
|
||||||
|
CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got string', 1)
|
||||||
|
lines =<< trim END
|
||||||
|
var d = 'asdf'['1':2]
|
||||||
|
echo d
|
||||||
|
END
|
||||||
|
CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got string', 1)
|
||||||
|
lines =<< trim END
|
||||||
|
var d = 'asdf'[1:'2']
|
||||||
|
echo d
|
||||||
|
END
|
||||||
|
CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got string', 1)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_expr7_list_subscript()
|
def Test_expr7_list_subscript()
|
||||||
|
@@ -962,6 +962,18 @@ def Test_vim9_import_export()
|
|||||||
writefile(import_already_defined, 'Ximport.vim')
|
writefile(import_already_defined, 'Ximport.vim')
|
||||||
assert_fails('source Ximport.vim', 'E1073:', '', 3, 'Ximport.vim')
|
assert_fails('source Ximport.vim', 'E1073:', '', 3, 'Ximport.vim')
|
||||||
|
|
||||||
|
# try changing an imported const
|
||||||
|
var import_assign_to_const =<< trim END
|
||||||
|
vim9script
|
||||||
|
import CONST from './Xexport.vim'
|
||||||
|
def Assign()
|
||||||
|
CONST = 987
|
||||||
|
enddef
|
||||||
|
defcompile
|
||||||
|
END
|
||||||
|
writefile(import_assign_to_const, 'Ximport.vim')
|
||||||
|
assert_fails('source Ximport.vim', 'E46:', '', 1, '_Assign')
|
||||||
|
|
||||||
# import a very long name, requires making a copy
|
# import a very long name, requires making a copy
|
||||||
var import_long_name_lines =<< trim END
|
var import_long_name_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 */
|
||||||
|
/**/
|
||||||
|
2099,
|
||||||
/**/
|
/**/
|
||||||
2098,
|
2098,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -2503,7 +2503,8 @@ compile_load(
|
|||||||
case 'w': isn_type = ISN_LOADW; break;
|
case 'w': isn_type = ISN_LOADW; break;
|
||||||
case 't': isn_type = ISN_LOADT; break;
|
case 't': isn_type = ISN_LOADT; break;
|
||||||
case 'b': isn_type = ISN_LOADB; break;
|
case 'b': isn_type = ISN_LOADB; break;
|
||||||
default: semsg(_(e_namespace_not_supported_str), *arg);
|
default: // cannot happen, just in case
|
||||||
|
semsg(_(e_namespace_not_supported_str), *arg);
|
||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
if (isn_type != ISN_DROP)
|
if (isn_type != ISN_DROP)
|
||||||
@@ -3581,7 +3582,7 @@ compile_subscript(
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (compile_expr0(arg, cctx) == FAIL)
|
if (compile_expr0(arg, cctx) == FAIL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
if (may_get_next_line_error(p, arg, cctx) == FAIL)
|
if (may_get_next_line_error(p, arg, cctx) == FAIL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
*arg = skipwhite(*arg);
|
*arg = skipwhite(*arg);
|
||||||
@@ -4084,7 +4085,7 @@ compile_expr6(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
*arg = skipwhite(op + 1);
|
*arg = skipwhite(op + 1);
|
||||||
if (may_get_next_line(op + 1, arg, cctx) == FAIL)
|
if (may_get_next_line_error(op + 1, arg, cctx) == FAIL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
|
||||||
// get the second expression
|
// get the second expression
|
||||||
@@ -4291,7 +4292,7 @@ compile_expr4(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
|
|||||||
|
|
||||||
// get the second variable
|
// get the second variable
|
||||||
*arg = skipwhite(p + len);
|
*arg = skipwhite(p + len);
|
||||||
if (may_get_next_line(p + len, arg, cctx) == FAIL)
|
if (may_get_next_line_error(p + len, arg, cctx) == FAIL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
|
||||||
if (compile_expr5(arg, cctx, ppconst) == FAIL)
|
if (compile_expr5(arg, cctx, ppconst) == FAIL)
|
||||||
@@ -4390,7 +4391,7 @@ compile_and_or(
|
|||||||
|
|
||||||
// eval the next expression
|
// eval the next expression
|
||||||
*arg = skipwhite(p + 2);
|
*arg = skipwhite(p + 2);
|
||||||
if (may_get_next_line(p + 2, arg, cctx) == FAIL)
|
if (may_get_next_line_error(p + 2, arg, cctx) == FAIL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
|
||||||
if ((opchar == '|' ? compile_expr3(arg, cctx, ppconst)
|
if ((opchar == '|' ? compile_expr3(arg, cctx, ppconst)
|
||||||
@@ -4584,7 +4585,7 @@ compile_expr1(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
|
|||||||
|
|
||||||
// evaluate the second expression; any type is accepted
|
// evaluate the second expression; any type is accepted
|
||||||
*arg = skipwhite(p + 1 + op_falsy);
|
*arg = skipwhite(p + 1 + op_falsy);
|
||||||
if (may_get_next_line(p + 1 + op_falsy, arg, cctx) == FAIL)
|
if (may_get_next_line_error(p + 1 + op_falsy, arg, cctx) == FAIL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
if (compile_expr1(arg, cctx, ppconst) == FAIL)
|
if (compile_expr1(arg, cctx, ppconst) == FAIL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
@@ -4634,7 +4635,7 @@ compile_expr1(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
|
|||||||
cctx->ctx_skip = save_skip == SKIP_YES || const_value
|
cctx->ctx_skip = save_skip == SKIP_YES || const_value
|
||||||
? SKIP_YES : SKIP_NOT;
|
? SKIP_YES : SKIP_NOT;
|
||||||
*arg = skipwhite(p + 1);
|
*arg = skipwhite(p + 1);
|
||||||
if (may_get_next_line(p + 1, arg, cctx) == FAIL)
|
if (may_get_next_line_error(p + 1, arg, cctx) == FAIL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
if (compile_expr1(arg, cctx, ppconst) == FAIL)
|
if (compile_expr1(arg, cctx, ppconst) == FAIL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
Reference in New Issue
Block a user