0
0
mirror of https://github.com/vim/vim.git synced 2025-09-27 04:14:06 -04:00

patch 8.2.0486: Vim9: some code and error messages not tested

Problem:    Vim9: some code and error messages not tested.
Solution:   Add more tests.
This commit is contained in:
Bram Moolenaar
2020-03-30 22:51:24 +02:00
parent 01b3862956
commit 9be61bbb17
5 changed files with 60 additions and 7 deletions

View File

@@ -930,7 +930,7 @@ skip_var_list(
{ {
if (*semicolon == 1) if (*semicolon == 1)
{ {
emsg(_("Double ; in list of variables")); emsg(_("E452: Double ; in list of variables"));
return NULL; return NULL;
} }
*semicolon = 1; *semicolon = 1;

View File

@@ -58,6 +58,7 @@ enddef
func Test_expr1_fails() func Test_expr1_fails()
call CheckDefFailure("let x = 1 ? 'one'", "Missing ':' after '?'") call CheckDefFailure("let x = 1 ? 'one'", "Missing ':' after '?'")
call CheckDefFailure("let x = 1 ? 'one' : xxx", "E1001:")
let msg = "white space required before and after '?'" let msg = "white space required before and after '?'"
call CheckDefFailure("let x = 1? 'one' : 'two'", msg) call CheckDefFailure("let x = 1? 'one' : 'two'", msg)
@@ -192,11 +193,18 @@ def Test_expr4_equal()
assert_equal(true, g:astring == 'asdf') assert_equal(true, g:astring == 'asdf')
assert_equal(false, 'xyz' == g:astring) assert_equal(false, 'xyz' == g:astring)
assert_equal(false, 'abc' == 'aBc')
assert_equal(false, 'abc' ==# 'aBc')
assert_equal(true, 'abc' ==? 'aBc')
assert_equal(false, 'abc' == 'ABC') assert_equal(false, 'abc' == 'ABC')
set ignorecase set ignorecase
assert_equal(false, 'abc' == 'ABC') assert_equal(false, 'abc' == 'ABC')
assert_equal(false, 'abc' ==# 'ABC')
set noignorecase set noignorecase
call CheckDefFailure("let x = 'a' == xxx", 'E1001:')
assert_equal(true, 0z3f == 0z3f) assert_equal(true, 0z3f == 0z3f)
assert_equal(false, 0z3f == 0z4f) assert_equal(false, 0z3f == 0z4f)
assert_equal(true, g:ablob == 0z01ab) assert_equal(true, g:ablob == 0z01ab)

View File

@@ -53,6 +53,9 @@ def Test_assignment()
let dict4: dict<any> = #{one: 1, two: '2'} let dict4: dict<any> = #{one: 1, two: '2'}
let dict5: dict<blob> = #{one: 0z01, tw: 0z02} let dict5: dict<blob> = #{one: 0z01, tw: 0z02}
let a: number = 6
assert_equal(6, a)
if has('channel') if has('channel')
let chan1: channel let chan1: channel
let job1: job let job1: job
@@ -101,6 +104,21 @@ func Test_assignment_failure()
call CheckDefFailure(['let true = 1'], 'E1034:') call CheckDefFailure(['let true = 1'], 'E1034:')
call CheckDefFailure(['let false = 1'], 'E1034:') call CheckDefFailure(['let false = 1'], 'E1034:')
call CheckDefFailure(['let [a; b; c] = g:list'], 'E452:')
call CheckDefFailure(['let &option'], 'E1052:')
call CheckDefFailure(['&g:option = 5'], 'E113:')
call CheckDefFailure(['let $VAR = 5'], 'E1065:')
call CheckDefFailure(['let @~ = 5'], 'E354:')
call CheckDefFailure(['let @a = 5'], 'E1066:')
call CheckDefFailure(['let g:var = 5'], 'E1016:')
call CheckDefFailure(['let anr = 4', 'anr ..= "text"'], 'E1019:')
call CheckDefFailure(['let xnr += 4'], 'E1020:')
call CheckScriptFailure(['vim9script', 'def Func()', 'let dummy = s:notfound', 'enddef'], 'E1050:') call CheckScriptFailure(['vim9script', 'def Func()', 'let dummy = s:notfound', 'enddef'], 'E1050:')
call CheckDefFailure(['let var: list<string> = [123]'], 'expected list<string> but got list<number>') call CheckDefFailure(['let var: list<string> = [123]'], 'expected list<string> but got list<number>')
@@ -142,6 +160,7 @@ func Test_const()
call CheckDefFailure(['const var = 234', 'var = 99'], 'E1018:') call CheckDefFailure(['const var = 234', 'var = 99'], 'E1018:')
call CheckDefFailure(['const one = 234', 'let one = 99'], 'E1017:') call CheckDefFailure(['const one = 234', 'let one = 99'], 'E1017:')
call CheckDefFailure(['const two'], 'E1021:') call CheckDefFailure(['const two'], 'E1021:')
call CheckDefFailure(['const &option'], 'E996:')
endfunc endfunc
def Test_block() def Test_block()
@@ -172,12 +191,26 @@ def ReturnGlobal(): number
return g:notNumber return g:notNumber
enddef enddef
def Test_return_string() def Test_return_something()
assert_equal('string', ReturnString()) assert_equal('string', ReturnString())
assert_equal(123, ReturnNumber()) assert_equal(123, ReturnNumber())
assert_fails('call ReturnGlobal()', 'E1029: Expected number but got string') assert_fails('call ReturnGlobal()', 'E1029: Expected number but got string')
enddef enddef
let s:nothing = 0
def ReturnNothing()
s:nothing = 1
if true
return
endif
s:nothing = 2
enddef
def Test_return_nothing()
ReturnNothing()
assert_equal(1, s:nothing)
enddef
func Increment() func Increment()
let g:counter += 1 let g:counter += 1
endfunc endfunc
@@ -282,6 +315,8 @@ def Test_return_type_wrong()
CheckScriptFailure(['def Func(): void', 'return "a"', 'enddef'], 'expected void but got string') CheckScriptFailure(['def Func(): void', 'return "a"', 'enddef'], 'expected void but got string')
CheckScriptFailure(['def Func()', 'return "a"', 'enddef'], 'expected void but got string') CheckScriptFailure(['def Func()', 'return "a"', 'enddef'], 'expected void but got string')
CheckScriptFailure(['def Func(): number', 'return', 'enddef'], 'E1003:')
CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:') CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:')
CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:') CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:')
enddef enddef

View File

@@ -738,6 +738,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 */
/**/
486,
/**/ /**/
485, 485,
/**/ /**/

View File

@@ -3353,9 +3353,9 @@ compile_return(char_u *arg, int set_return_type, cctx_T *cctx)
} }
else else
{ {
if (set_return_type) // "set_return_type" cannot be TRUE, only used for a lambda which
cctx->ctx_ufunc->uf_ret_type = &t_void; // always has an argument.
else if (cctx->ctx_ufunc->uf_ret_type->tt_type != VAR_VOID) if (cctx->ctx_ufunc->uf_ret_type->tt_type != VAR_VOID)
{ {
emsg(_("E1003: Missing return value")); emsg(_("E1003: Missing return value"));
return NULL; return NULL;
@@ -3416,7 +3416,10 @@ heredoc_getline(
cctx_T *cctx = (cctx_T *)cookie; cctx_T *cctx = (cctx_T *)cookie;
if (cctx->ctx_lnum == cctx->ctx_ufunc->uf_lines.ga_len) if (cctx->ctx_lnum == cctx->ctx_ufunc->uf_lines.ga_len)
NULL; {
iemsg("Heredoc got to end");
return NULL;
}
++cctx->ctx_lnum; ++cctx->ctx_lnum;
return vim_strsave(((char_u **)cctx->ctx_ufunc->uf_lines.ga_data) return vim_strsave(((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)
[cctx->ctx_lnum]); [cctx->ctx_lnum]);
@@ -3472,6 +3475,10 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
return NULL; return NULL;
} }
// "a: type" is declaring variable "a" with a type, not "a:".
if (is_decl && p == arg + 2 && p[-1] == ':')
--p;
varlen = p - arg; varlen = p - arg;
name = vim_strnsave(arg, (int)varlen); name = vim_strnsave(arg, (int)varlen);
if (name == NULL) if (name == NULL)
@@ -3499,6 +3506,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
p = find_option_end(&p, &opt_flags); p = find_option_end(&p, &opt_flags);
if (p == NULL) if (p == NULL)
{ {
// cannot happen?
emsg(_(e_letunexp)); emsg(_(e_letunexp));
return NULL; return NULL;
} }
@@ -3508,7 +3516,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
*p = cc; *p = cc;
if (opt_type == -3) if (opt_type == -3)
{ {
semsg(_(e_unknown_option), *arg); semsg(_(e_unknown_option), arg);
return NULL; return NULL;
} }
if (opt_type == -2 || opt_type == 0) if (opt_type == -2 || opt_type == 0)