mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 8.2.0348: Vim9: not all code tested
Problem: Vim9: not all code tested. Solution: Add a few more tests. fix using "b:" in literal dictionary.
This commit is contained in:
@@ -5,7 +5,6 @@ char *vartype_name(vartype_T type);
|
|||||||
char *type_name(type_T *type, char **tofree);
|
char *type_name(type_T *type, char **tofree);
|
||||||
int get_script_item_idx(int sid, char_u *name, int check_writable);
|
int get_script_item_idx(int sid, char_u *name, int check_writable);
|
||||||
imported_T *find_imported(char_u *name, size_t len, cctx_T *cctx);
|
imported_T *find_imported(char_u *name, size_t len, cctx_T *cctx);
|
||||||
char_u *to_name_end(char_u *arg);
|
|
||||||
char_u *to_name_const_end(char_u *arg);
|
char_u *to_name_const_end(char_u *arg);
|
||||||
int assignment_len(char_u *p, int *heredoc);
|
int assignment_len(char_u *p, int *heredoc);
|
||||||
void compile_def_function(ufunc_T *ufunc, int set_return_type);
|
void compile_def_function(ufunc_T *ufunc, int set_return_type);
|
||||||
|
@@ -37,9 +37,9 @@ def Test_expr1()
|
|||||||
assert_equal('one', 0.1 ? 'one' : 'two')
|
assert_equal('one', 0.1 ? 'one' : 'two')
|
||||||
endif
|
endif
|
||||||
assert_equal('one', 'x' ? 'one' : 'two')
|
assert_equal('one', 'x' ? 'one' : 'two')
|
||||||
" assert_equal('one', 0z1234 ? 'one' : 'two')
|
assert_equal('one', 0z1234 ? 'one' : 'two')
|
||||||
assert_equal('one', [0] ? 'one' : 'two')
|
assert_equal('one', [0] ? 'one' : 'two')
|
||||||
" assert_equal('one', #{x: 0} ? 'one' : 'two')
|
assert_equal('one', #{x: 0} ? 'one' : 'two')
|
||||||
let var = 1
|
let var = 1
|
||||||
assert_equal('one', var ? 'one' : 'two')
|
assert_equal('one', var ? 'one' : 'two')
|
||||||
|
|
||||||
@@ -49,9 +49,9 @@ def Test_expr1()
|
|||||||
assert_equal('two', 0.0 ? 'one' : 'two')
|
assert_equal('two', 0.0 ? 'one' : 'two')
|
||||||
endif
|
endif
|
||||||
assert_equal('two', '' ? 'one' : 'two')
|
assert_equal('two', '' ? 'one' : 'two')
|
||||||
" assert_equal('one', 0z ? 'one' : 'two')
|
assert_equal('two', 0z ? 'one' : 'two')
|
||||||
assert_equal('two', [] ? 'one' : 'two')
|
assert_equal('two', [] ? 'one' : 'two')
|
||||||
" assert_equal('two', {} ? 'one' : 'two')
|
assert_equal('two', {} ? 'one' : 'two')
|
||||||
var = 0
|
var = 0
|
||||||
assert_equal('two', var ? 'one' : 'two')
|
assert_equal('two', var ? 'one' : 'two')
|
||||||
enddef
|
enddef
|
||||||
@@ -447,6 +447,11 @@ func Test_expr4_fails()
|
|||||||
call CheckDefFailure("let x = [13] <= [88]", 'Cannot compare list with list')
|
call CheckDefFailure("let x = [13] <= [88]", 'Cannot compare list with list')
|
||||||
call CheckDefFailure("let x = [13] =~ [88]", 'Cannot compare list with list')
|
call CheckDefFailure("let x = [13] =~ [88]", 'Cannot compare list with list')
|
||||||
call CheckDefFailure("let x = [13] !~ [88]", 'Cannot compare list with list')
|
call CheckDefFailure("let x = [13] !~ [88]", 'Cannot compare list with list')
|
||||||
|
|
||||||
|
call CheckDefFailureMult(['let j: job', 'let chan: channel', 'let r = j == chan'], 'Cannot compare job with channel')
|
||||||
|
call CheckDefFailureMult(['let j: job', 'let x: list<any>', 'let r = j == x'], 'Cannot compare job with list')
|
||||||
|
call CheckDefFailureMult(['let j: job', 'let x: func', 'let r = j == x'], 'Cannot compare job with func')
|
||||||
|
call CheckDefFailureMult(['let j: job', 'let x: partial', 'let r = j == x'], 'Cannot compare job with partial')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" test addition, subtraction, concatenation
|
" test addition, subtraction, concatenation
|
||||||
|
@@ -68,6 +68,8 @@ def Test_assignment()
|
|||||||
|
|
||||||
" type becomes list<any>
|
" type becomes list<any>
|
||||||
let somelist = rand() > 0 ? [1, 2, 3] : ['a', 'b', 'c']
|
let somelist = rand() > 0 ? [1, 2, 3] : ['a', 'b', 'c']
|
||||||
|
" type becomes dict<any>
|
||||||
|
let somedict = rand() > 0 ? #{a: 1, b: 2} : #{a: 'a', b: 'b'}
|
||||||
|
|
||||||
g:newvar = 'new'
|
g:newvar = 'new'
|
||||||
assert_equal('new', g:newvar)
|
assert_equal('new', g:newvar)
|
||||||
@@ -373,6 +375,7 @@ def Test_vim9script()
|
|||||||
g:imported_name = exp_name
|
g:imported_name = exp_name
|
||||||
exp_name ..= ' Doe'
|
exp_name ..= ' Doe'
|
||||||
g:imported_name_appended = exp_name
|
g:imported_name_appended = exp_name
|
||||||
|
g:imported_later = exported
|
||||||
END
|
END
|
||||||
|
|
||||||
writefile(import_script_lines, 'Ximport.vim')
|
writefile(import_script_lines, 'Ximport.vim')
|
||||||
@@ -384,6 +387,7 @@ def Test_vim9script()
|
|||||||
assert_equal('bob', g:localname)
|
assert_equal('bob', g:localname)
|
||||||
assert_equal(9876, g:imported)
|
assert_equal(9876, g:imported)
|
||||||
assert_equal(9879, g:imported_added)
|
assert_equal(9879, g:imported_added)
|
||||||
|
assert_equal(9879, g:imported_later)
|
||||||
assert_equal('Exported', g:imported_func)
|
assert_equal('Exported', g:imported_func)
|
||||||
assert_equal('John', g:imported_name)
|
assert_equal('John', g:imported_name)
|
||||||
assert_equal('John Doe', g:imported_name_appended)
|
assert_equal('John Doe', g:imported_name_appended)
|
||||||
@@ -393,10 +397,30 @@ def Test_vim9script()
|
|||||||
unlet g:localname
|
unlet g:localname
|
||||||
unlet g:imported
|
unlet g:imported
|
||||||
unlet g:imported_added
|
unlet g:imported_added
|
||||||
|
unlet g:imported_later
|
||||||
unlet g:imported_func
|
unlet g:imported_func
|
||||||
unlet g:imported_name g:imported_name_appended
|
unlet g:imported_name g:imported_name_appended
|
||||||
delete('Ximport.vim')
|
delete('Ximport.vim')
|
||||||
|
|
||||||
|
let import_in_def_lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
def ImportInDef()
|
||||||
|
import exported from './Xexport.vim'
|
||||||
|
g:imported = exported
|
||||||
|
exported += 7
|
||||||
|
g:imported_added = exported
|
||||||
|
enddef
|
||||||
|
ImportInDef()
|
||||||
|
END
|
||||||
|
writefile(import_in_def_lines, 'Ximport2.vim')
|
||||||
|
source Ximport2.vim
|
||||||
|
" TODO: this should be 9879
|
||||||
|
assert_equal(9876, g:imported)
|
||||||
|
assert_equal(9883, g:imported_added)
|
||||||
|
unlet g:imported
|
||||||
|
unlet g:imported_added
|
||||||
|
delete('Ximport2.vim')
|
||||||
|
|
||||||
let import_star_as_lines =<< trim END
|
let import_star_as_lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
import * as Export from './Xexport.vim'
|
import * as Export from './Xexport.vim'
|
||||||
@@ -407,7 +431,7 @@ def Test_vim9script()
|
|||||||
END
|
END
|
||||||
writefile(import_star_as_lines, 'Ximport.vim')
|
writefile(import_star_as_lines, 'Ximport.vim')
|
||||||
source Ximport.vim
|
source Ximport.vim
|
||||||
assert_equal(9876, g:imported)
|
assert_equal(9883, g:imported)
|
||||||
|
|
||||||
let import_star_lines =<< trim END
|
let import_star_lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
|
@@ -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 */
|
||||||
|
/**/
|
||||||
|
348,
|
||||||
/**/
|
/**/
|
||||||
347,
|
347,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -507,7 +507,7 @@ generate_COMPARE(cctx_T *cctx, exptype_T exptype, int ic)
|
|||||||
&& (type1 == VAR_BLOB || type2 == VAR_BLOB
|
&& (type1 == VAR_BLOB || type2 == VAR_BLOB
|
||||||
|| type1 == VAR_LIST || type2 == VAR_LIST))))
|
|| type1 == VAR_LIST || type2 == VAR_LIST))))
|
||||||
{
|
{
|
||||||
semsg(_("E1037: Cannot compare %s with %s"),
|
semsg(_("E1072: Cannot compare %s with %s"),
|
||||||
vartype_name(type1), vartype_name(type2));
|
vartype_name(type1), vartype_name(type2));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@@ -1494,8 +1494,8 @@ vartype_name(vartype_T type)
|
|||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
|
case VAR_UNKNOWN: break;
|
||||||
case VAR_VOID: return "void";
|
case VAR_VOID: return "void";
|
||||||
case VAR_UNKNOWN: return "any";
|
|
||||||
case VAR_SPECIAL: return "special";
|
case VAR_SPECIAL: return "special";
|
||||||
case VAR_BOOL: return "bool";
|
case VAR_BOOL: return "bool";
|
||||||
case VAR_NUMBER: return "number";
|
case VAR_NUMBER: return "number";
|
||||||
@@ -1509,7 +1509,7 @@ vartype_name(vartype_T type)
|
|||||||
case VAR_FUNC: return "func";
|
case VAR_FUNC: return "func";
|
||||||
case VAR_PARTIAL: return "partial";
|
case VAR_PARTIAL: return "partial";
|
||||||
}
|
}
|
||||||
return "???";
|
return "any";
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1907,11 +1907,12 @@ theend:
|
|||||||
/*
|
/*
|
||||||
* Find the end of a variable or function name. Unlike find_name_end() this
|
* Find the end of a variable or function name. Unlike find_name_end() this
|
||||||
* does not recognize magic braces.
|
* does not recognize magic braces.
|
||||||
|
* When "namespace" is TRUE recognize "b:", "s:", etc.
|
||||||
* Return a pointer to just after the name. Equal to "arg" if there is no
|
* Return a pointer to just after the name. Equal to "arg" if there is no
|
||||||
* valid name.
|
* valid name.
|
||||||
*/
|
*/
|
||||||
char_u *
|
static char_u *
|
||||||
to_name_end(char_u *arg)
|
to_name_end(char_u *arg, int namespace)
|
||||||
{
|
{
|
||||||
char_u *p;
|
char_u *p;
|
||||||
|
|
||||||
@@ -1923,6 +1924,7 @@ to_name_end(char_u *arg)
|
|||||||
// Include a namespace such as "s:var" and "v:var". But "n:" is not
|
// Include a namespace such as "s:var" and "v:var". But "n:" is not
|
||||||
// and can be used in slice "[n:]".
|
// and can be used in slice "[n:]".
|
||||||
if (*p == ':' && (p != arg + 1
|
if (*p == ':' && (p != arg + 1
|
||||||
|
|| !namespace
|
||||||
|| vim_strchr(VIM9_NAMESPACE_CHAR, *arg) == NULL))
|
|| vim_strchr(VIM9_NAMESPACE_CHAR, *arg) == NULL))
|
||||||
break;
|
break;
|
||||||
return p;
|
return p;
|
||||||
@@ -1934,7 +1936,7 @@ to_name_end(char_u *arg)
|
|||||||
char_u *
|
char_u *
|
||||||
to_name_const_end(char_u *arg)
|
to_name_const_end(char_u *arg)
|
||||||
{
|
{
|
||||||
char_u *p = to_name_end(arg);
|
char_u *p = to_name_end(arg, TRUE);
|
||||||
typval_T rettv;
|
typval_T rettv;
|
||||||
|
|
||||||
if (p == arg && *arg == '[')
|
if (p == arg && *arg == '[')
|
||||||
@@ -2145,7 +2147,7 @@ compile_dict(char_u **arg, cctx_T *cctx, int literal)
|
|||||||
|
|
||||||
if (literal)
|
if (literal)
|
||||||
{
|
{
|
||||||
char_u *p = to_name_end(*arg);
|
char_u *p = to_name_end(*arg, !literal);
|
||||||
|
|
||||||
if (p == *arg)
|
if (p == *arg)
|
||||||
{
|
{
|
||||||
@@ -2766,7 +2768,7 @@ compile_expr7(char_u **arg, cctx_T *cctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// "name" or "name()"
|
// "name" or "name()"
|
||||||
p = to_name_end(*arg);
|
p = to_name_end(*arg, TRUE);
|
||||||
if (*p == '(')
|
if (*p == '(')
|
||||||
r = compile_call(arg, p - *arg, cctx, 0);
|
r = compile_call(arg, p - *arg, cctx, 0);
|
||||||
else
|
else
|
||||||
@@ -4980,7 +4982,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
|
|||||||
// val".
|
// val".
|
||||||
p = (*ea.cmd == '&' || *ea.cmd == '$' || *ea.cmd == '@')
|
p = (*ea.cmd == '&' || *ea.cmd == '$' || *ea.cmd == '@')
|
||||||
? ea.cmd + 1 : ea.cmd;
|
? ea.cmd + 1 : ea.cmd;
|
||||||
p = to_name_end(p);
|
p = to_name_end(p, TRUE);
|
||||||
if ((p > ea.cmd && *p != NUL) || *p == '(')
|
if ((p > ea.cmd && *p != NUL) || *p == '(')
|
||||||
{
|
{
|
||||||
int oplen;
|
int oplen;
|
||||||
@@ -4992,7 +4994,9 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
|
|||||||
// Recognize an assignment if we recognize the variable
|
// Recognize an assignment if we recognize the variable
|
||||||
// name:
|
// name:
|
||||||
// "g:var = expr"
|
// "g:var = expr"
|
||||||
// "var = expr" where "var" is a local var name.
|
// "local = expr" where "local" is a local var.
|
||||||
|
// "script = expr" where "script" is a script-local var.
|
||||||
|
// "import = expr" where "import" is an imported var
|
||||||
// "&opt = expr"
|
// "&opt = expr"
|
||||||
// "$ENV = expr"
|
// "$ENV = expr"
|
||||||
// "@r = expr"
|
// "@r = expr"
|
||||||
|
Reference in New Issue
Block a user