patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent

Problem:    Vim9: finding global function without g: prefix but not finding
            global variable is inconsistent.
Solution:   Require using g: for a global function.  Change the vim9.vim
            script into a Vim9 script with exports.  Fix that import in legacy
            script does not work.
This commit is contained in:
Bram Moolenaar
2022-01-29 21:45:34 +00:00
parent 135e15251e
commit 62aec93bfd
34 changed files with 3212 additions and 3176 deletions

View File

@@ -963,7 +963,7 @@ get_lval(
if (lp->ll_name == NULL)
return p;
if (*p == '.' && in_vim9script())
if (*p == '.')
{
imported_T *import = find_imported(lp->ll_name, p - lp->ll_name,
TRUE, NULL);

View File

@@ -3830,14 +3830,7 @@ f_exists(typval_T *argvars, typval_T *rettv)
}
else if (*p == '*') // internal or user defined function
{
int save_version = current_sctx.sc_version;
// Vim9 script assumes a function is script-local, but here we want to
// find any matching function.
if (current_sctx.sc_version == SCRIPT_VERSION_VIM9)
current_sctx.sc_version = SCRIPT_VERSION_MAX;
n = function_exists(p + 1, FALSE);
current_sctx.sc_version = save_version;
}
else if (*p == '?') // internal function only
{

View File

@@ -1,6 +1,6 @@
" Tests for the Blob types
source vim9.vim
import './vim9.vim' as v9
func TearDown()
" Run garbage collection after every test
@@ -39,7 +39,7 @@ func Test_blob_create()
call assert_equal(0, len(test_null_blob()))
call assert_equal(0z, copy(test_null_blob()))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
" assignment to a blob
@@ -75,49 +75,49 @@ func Test_blob_assign()
VAR m = deepcopy(l)
LET m[0] = 0z34 #" E742 or E741 should not occur.
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
let lines =<< trim END
VAR b = 0zDEADBEEF
LET b[2 : 3] = 0z112233
END
call CheckLegacyAndVim9Failure(lines, 'E972:')
call v9.CheckLegacyAndVim9Failure(lines, 'E972:')
let lines =<< trim END
VAR b = 0zDEADBEEF
LET b[2 : 3] = 0z11
END
call CheckLegacyAndVim9Failure(lines, 'E972:')
call v9.CheckLegacyAndVim9Failure(lines, 'E972:')
let lines =<< trim END
VAR b = 0zDEADBEEF
LET b[3 : 2] = 0z
END
call CheckLegacyAndVim9Failure(lines, 'E979:')
call v9.CheckLegacyAndVim9Failure(lines, 'E979:')
let lines =<< trim END
VAR b = 0zDEADBEEF
LET b ..= 0z33
END
call CheckLegacyAndVim9Failure(lines, ['E734:', 'E1019:', 'E734:'])
call v9.CheckLegacyAndVim9Failure(lines, ['E734:', 'E1019:', 'E734:'])
let lines =<< trim END
VAR b = 0zDEADBEEF
LET b ..= "xx"
END
call CheckLegacyAndVim9Failure(lines, ['E734:', 'E1019:', 'E734:'])
call v9.CheckLegacyAndVim9Failure(lines, ['E734:', 'E1019:', 'E734:'])
let lines =<< trim END
VAR b = 0zDEADBEEF
LET b += "xx"
END
call CheckLegacyAndVim9Failure(lines, ['E734:', 'E1012:', 'E734:'])
call v9.CheckLegacyAndVim9Failure(lines, ['E734:', 'E1012:', 'E734:'])
let lines =<< trim END
VAR b = 0zDEADBEEF
LET b[1 : 1] ..= 0z55
END
call CheckLegacyAndVim9Failure(lines, ['E734:', 'E1183:', 'E734:'])
call v9.CheckLegacyAndVim9Failure(lines, ['E734:', 'E1183:', 'E734:'])
endfunc
func Test_blob_get_range()
@@ -133,7 +133,7 @@ func Test_blob_get_range()
call assert_equal(0z, b[5 : 6])
call assert_equal(0z0011, b[-10 : 1])
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" legacy script white space
let b = 0z0011223344
@@ -158,19 +158,19 @@ func Test_blob_get()
call assert_equal(0x44, b[4])
call assert_equal(0x44, b[-1])
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
let lines =<< trim END
VAR b = 0z0011223344
echo b[5]
END
call CheckLegacyAndVim9Failure(lines, 'E979:')
call v9.CheckLegacyAndVim9Failure(lines, 'E979:')
let lines =<< trim END
VAR b = 0z0011223344
echo b[-8]
END
call CheckLegacyAndVim9Failure(lines, 'E979:')
call v9.CheckLegacyAndVim9Failure(lines, 'E979:')
endfunc
func Test_blob_to_string()
@@ -184,7 +184,7 @@ func Test_blob_to_string()
call assert_equal('0z', string(b))
call assert_equal('0z', string(test_null_blob()))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
func Test_blob_compare()
@@ -211,54 +211,54 @@ func Test_blob_compare()
call assert_false(b1 is b2)
call assert_true(b1 isnot b2)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
let lines =<< trim END
VAR b1 = 0z0011
echo b1 == 9
END
call CheckLegacyAndVim9Failure(lines, ['E977:', 'E1072', 'E1072'])
call v9.CheckLegacyAndVim9Failure(lines, ['E977:', 'E1072', 'E1072'])
let lines =<< trim END
VAR b1 = 0z0011
echo b1 != 9
END
call CheckLegacyAndVim9Failure(lines, ['E977:', 'E1072', 'E1072'])
call v9.CheckLegacyAndVim9Failure(lines, ['E977:', 'E1072', 'E1072'])
let lines =<< trim END
VAR b1 = 0z0011
VAR b2 = 0z1100
VAR x = b1 > b2
END
call CheckLegacyAndVim9Failure(lines, ['E978:', 'E1072:', 'E1072:'])
call v9.CheckLegacyAndVim9Failure(lines, ['E978:', 'E1072:', 'E1072:'])
let lines =<< trim END
VAR b1 = 0z0011
VAR b2 = 0z1100
VAR x = b1 < b2
END
call CheckLegacyAndVim9Failure(lines, ['E978:', 'E1072:', 'E1072:'])
call v9.CheckLegacyAndVim9Failure(lines, ['E978:', 'E1072:', 'E1072:'])
let lines =<< trim END
VAR b1 = 0z0011
VAR b2 = 0z1100
VAR x = b1 - b2
END
call CheckLegacyAndVim9Failure(lines, ['E974:', 'E1036:', 'E974:'])
call v9.CheckLegacyAndVim9Failure(lines, ['E974:', 'E1036:', 'E974:'])
let lines =<< trim END
VAR b1 = 0z0011
VAR b2 = 0z1100
VAR x = b1 / b2
END
call CheckLegacyAndVim9Failure(lines, ['E974:', 'E1036:', 'E974:'])
call v9.CheckLegacyAndVim9Failure(lines, ['E974:', 'E1036:', 'E974:'])
let lines =<< trim END
VAR b1 = 0z0011
VAR b2 = 0z1100
VAR x = b1 * b2
END
call CheckLegacyAndVim9Failure(lines, ['E974:', 'E1036:', 'E974:'])
call v9.CheckLegacyAndVim9Failure(lines, ['E974:', 'E1036:', 'E974:'])
endfunc
func Test_blob_index_assign()
@@ -268,19 +268,19 @@ func Test_blob_index_assign()
LET b[2] = 0x22
call assert_equal(0z001122, b)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
let lines =<< trim END
VAR b = 0z00
LET b[2] = 0x33
END
call CheckLegacyAndVim9Failure(lines, 'E979:')
call v9.CheckLegacyAndVim9Failure(lines, 'E979:')
let lines =<< trim END
VAR b = 0z00
LET b[-2] = 0x33
END
call CheckLegacyAndVim9Failure(lines, 'E979:')
call v9.CheckLegacyAndVim9Failure(lines, 'E979:')
endfunc
func Test_blob_for_loop()
@@ -313,7 +313,7 @@ func Test_blob_for_loop()
endfor
call assert_equal(5, i)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
func Test_blob_concatenate()
@@ -325,19 +325,19 @@ func Test_blob_concatenate()
LET b = 0zDEAD + 0zBEEF
call assert_equal(0zDEADBEEF, b)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
let lines =<< trim END
VAR b = 0z0011
LET b += "a"
END
call CheckLegacyAndVim9Failure(lines, ['E734:', 'E1012:', 'E734:'])
call v9.CheckLegacyAndVim9Failure(lines, ['E734:', 'E1012:', 'E734:'])
let lines =<< trim END
VAR b = 0z0011
LET b += 88
END
call CheckLegacyAndVim9Failure(lines, ['E734:', 'E1012:', 'E734:'])
call v9.CheckLegacyAndVim9Failure(lines, ['E734:', 'E1012:', 'E734:'])
endfunc
func Test_blob_add()
@@ -346,7 +346,7 @@ func Test_blob_add()
call add(b, 0x22)
call assert_equal(0z001122, b)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" Only works in legacy script
let b = 0z0011
@@ -358,18 +358,18 @@ func Test_blob_add()
VAR b = 0z0011
call add(b, [9])
END
call CheckLegacyAndVim9Failure(lines, ['E745:', 'E1012:', 'E1210:'])
call v9.CheckLegacyAndVim9Failure(lines, ['E745:', 'E1012:', 'E1210:'])
let lines =<< trim END
VAR b = 0z0011
call add("", 0x01)
END
call CheckLegacyAndVim9Failure(lines, ['E897:', 'E1013:', 'E1226:'])
call v9.CheckLegacyAndVim9Failure(lines, ['E897:', 'E1013:', 'E1226:'])
let lines =<< trim END
add(test_null_blob(), 0x22)
END
call CheckDefExecAndScriptFailure(lines, 'E1131:')
call v9.CheckDefExecAndScriptFailure(lines, 'E1131:')
let lines =<< trim END
let b = 0zDEADBEEF
@@ -377,7 +377,7 @@ func Test_blob_add()
call add(b, 0)
unlockvar b
END
call CheckScriptFailure(lines, 'E741:')
call v9.CheckScriptFailure(lines, 'E741:')
endfunc
func Test_blob_empty()
@@ -411,32 +411,32 @@ func Test_blob_func_remove()
call assert_equal(0zADBE, remove(b, 1, 2))
call assert_equal(0zDEEF, b)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" Test invalid cases
let lines =<< trim END
VAR b = 0zDEADBEEF
call remove(b, 5)
END
call CheckLegacyAndVim9Failure(lines, 'E979:')
call v9.CheckLegacyAndVim9Failure(lines, 'E979:')
let lines =<< trim END
VAR b = 0zDEADBEEF
call remove(b, 1, 5)
END
call CheckLegacyAndVim9Failure(lines, 'E979:')
call v9.CheckLegacyAndVim9Failure(lines, 'E979:')
let lines =<< trim END
VAR b = 0zDEADBEEF
call remove(b, 3, 2)
END
call CheckLegacyAndVim9Failure(lines, 'E979:')
call v9.CheckLegacyAndVim9Failure(lines, 'E979:')
let lines =<< trim END
VAR b = 0zDEADBEEF
call remove(test_null_blob(), 1, 2)
END
call CheckLegacyAndVim9Failure(lines, 'E979:')
call v9.CheckLegacyAndVim9Failure(lines, 'E979:')
let lines =<< trim END
let b = 0zDEADBEEF
@@ -444,7 +444,7 @@ func Test_blob_func_remove()
call remove(b, 0)
unlockvar b
END
call CheckScriptFailure(lines, 'E741:')
call v9.CheckScriptFailure(lines, 'E741:')
" can only check at script level, not in a :def function
let lines =<< trim END
@@ -453,7 +453,7 @@ func Test_blob_func_remove()
lockvar b
remove(b, 0)
END
call CheckScriptFailure(lines, 'E741:')
call v9.CheckScriptFailure(lines, 'E741:')
call assert_fails('echo remove(0z1020, [])', 'E745:')
call assert_fails('echo remove(0z1020, 0, [])', 'E745:')
@@ -467,7 +467,7 @@ func Test_blob_read_write()
call assert_equal(b, br)
call delete('Xblob')
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" This was crashing when calling readfile() with a directory.
call assert_fails("call readfile('.', 'B')", 'E17: "." is a directory')
@@ -485,7 +485,7 @@ func Test_blob_filter()
call assert_equal(0z01030103, filter(0z010203010203, 'v:val != 0x02'))
call assert_equal(0zADEF, filter(0zDEADBEEF, 'v:key % 2'))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
call assert_fails('echo filter(0z10, "a10")', 'E121:')
endfunc
@@ -496,12 +496,12 @@ func Test_blob_map()
call assert_equal(0z00010203, map(0zDEADBEEF, 'v:key'))
call assert_equal(0zDEAEC0F2, map(0zDEADBEEF, 'v:key + v:val'))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
let lines =<< trim END
call map(0z00, '[9]')
END
call CheckLegacyAndVim9Failure(lines, 'E978:')
call v9.CheckLegacyAndVim9Failure(lines, 'E978:')
call assert_fails('echo map(0z10, "a10")', 'E121:')
endfunc
@@ -516,7 +516,7 @@ func Test_blob_index()
call assert_equal(0, index(0z11110111, 0x11, -10))
call assert_equal(-1, index(test_null_blob(), 1))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
func Test_blob_insert()
@@ -529,7 +529,7 @@ func Test_blob_insert()
call insert(b, 0x33, 2)
call assert_equal(0zDEAD33BEEF, b)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" only works in legacy script
call assert_equal(0, insert(test_null_blob(), 0x33))
@@ -538,42 +538,42 @@ func Test_blob_insert()
VAR b = 0zDEADBEEF
call insert(b, -1)
END
call CheckLegacyAndVim9Failure(lines, 'E475:')
call v9.CheckLegacyAndVim9Failure(lines, 'E475:')
let lines =<< trim END
VAR b = 0zDEADBEEF
call insert(b, 257)
END
call CheckLegacyAndVim9Failure(lines, 'E475:')
call v9.CheckLegacyAndVim9Failure(lines, 'E475:')
let lines =<< trim END
VAR b = 0zDEADBEEF
call insert(b, 0, [9])
END
call CheckLegacyAndVim9Failure(lines, ['E745:', 'E1013:', 'E1210:'])
call v9.CheckLegacyAndVim9Failure(lines, ['E745:', 'E1013:', 'E1210:'])
let lines =<< trim END
VAR b = 0zDEADBEEF
call insert(b, 0, -20)
END
call CheckLegacyAndVim9Failure(lines, 'E475:')
call v9.CheckLegacyAndVim9Failure(lines, 'E475:')
let lines =<< trim END
VAR b = 0zDEADBEEF
call insert(b, 0, 20)
END
call CheckLegacyAndVim9Failure(lines, 'E475:')
call v9.CheckLegacyAndVim9Failure(lines, 'E475:')
let lines =<< trim END
VAR b = 0zDEADBEEF
call insert(b, [])
END
call CheckLegacyAndVim9Failure(lines, ['E745:', 'E1013:', 'E1210:'])
call v9.CheckLegacyAndVim9Failure(lines, ['E745:', 'E1013:', 'E1210:'])
let lines =<< trim END
insert(test_null_blob(), 0x33)
END
call CheckDefExecAndScriptFailure(lines, 'E1131:')
call v9.CheckDefExecAndScriptFailure(lines, 'E1131:')
let lines =<< trim END
let b = 0zDEADBEEF
@@ -581,7 +581,7 @@ func Test_blob_insert()
call insert(b, 3)
unlockvar b
END
call CheckScriptFailure(lines, 'E741:')
call v9.CheckScriptFailure(lines, 'E741:')
let lines =<< trim END
vim9script
@@ -589,7 +589,7 @@ func Test_blob_insert()
lockvar b
insert(b, 3)
END
call CheckScriptFailure(lines, 'E741:')
call v9.CheckScriptFailure(lines, 'E741:')
endfunc
func Test_blob_reverse()
@@ -600,7 +600,7 @@ func Test_blob_reverse()
call assert_equal(0zDE, reverse(0zDE))
call assert_equal(0z, reverse(test_null_blob()))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
func Test_blob_json_encode()
@@ -608,7 +608,7 @@ func Test_blob_json_encode()
call assert_equal('[222,173,190,239]', json_encode(0zDEADBEEF))
call assert_equal('[]', json_encode(0z))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
func Test_blob_lock()
@@ -618,7 +618,7 @@ func Test_blob_lock()
unlockvar b
let b = 0z44
END
call CheckScriptSuccess(lines)
call v9.CheckScriptSuccess(lines)
let lines =<< trim END
vim9script
@@ -627,14 +627,14 @@ func Test_blob_lock()
unlockvar b
b = 0z44
END
call CheckScriptSuccess(lines)
call v9.CheckScriptSuccess(lines)
let lines =<< trim END
let b = 0z112233
lockvar b
let b = 0z44
END
call CheckScriptFailure(lines, 'E741:')
call v9.CheckScriptFailure(lines, 'E741:')
let lines =<< trim END
vim9script
@@ -642,14 +642,14 @@ func Test_blob_lock()
lockvar b
b = 0z44
END
call CheckScriptFailure(lines, 'E741:')
call v9.CheckScriptFailure(lines, 'E741:')
endfunc
func Test_blob_sort()
if has('float')
call CheckLegacyAndVim9Failure(['call sort([1.0, 0z11], "f")'], 'E975:')
call v9.CheckLegacyAndVim9Failure(['call sort([1.0, 0z11], "f")'], 'E975:')
endif
call CheckLegacyAndVim9Failure(['call sort([11, 0z11], "N")'], 'E974:')
call v9.CheckLegacyAndVim9Failure(['call sort([11, 0z11], "N")'], 'E974:')
endfunc
" Tests for the blob2list() function

View File

@@ -360,16 +360,16 @@ def Test_Debugger_breakadd_expr()
writefile(lines, 'Xtest.vim')
# Start Vim in a terminal
var buf = RunVimInTerminal('-S Xtest.vim', {wait_for_ruler: 0})
call TermWait(buf)
var buf = g:RunVimInTerminal('-S Xtest.vim', {wait_for_ruler: 0})
call g:TermWait(buf)
# Despite the failure the functions are defined
RunDbgCmd(buf, ':function g:EarlyFunc',
g:RunDbgCmd(buf, ':function g:EarlyFunc',
['function EarlyFunc()', 'endfunction'], {match: 'pattern'})
RunDbgCmd(buf, ':function g:LaterFunc',
g:RunDbgCmd(buf, ':function g:LaterFunc',
['function LaterFunc()', 'endfunction'], {match: 'pattern'})
call StopVimInTerminal(buf)
call g:StopVimInTerminal(buf)
call delete('Xtest.vim')
enddef
@@ -386,13 +386,13 @@ def Test_Debugger_break_at_return()
writefile(lines, 'Xtest.vim')
# Start Vim in a terminal
var buf = RunVimInTerminal('-S Xtest.vim', {wait_for_ruler: 0})
call TermWait(buf)
var buf = g:RunVimInTerminal('-S Xtest.vim', {wait_for_ruler: 0})
call g:TermWait(buf)
RunDbgCmd(buf, ':call GetNum()',
g:RunDbgCmd(buf, ':call GetNum()',
['line 1: return 1 + 2 + 3'], {match: 'pattern'})
call StopVimInTerminal(buf)
call g:StopVimInTerminal(buf)
call delete('Xtest.vim')
enddef

View File

@@ -2,7 +2,7 @@
source view_util.vim
source check.vim
source vim9.vim
import './vim9.vim' as v9
source term_util.vim
func NestedEval()
@@ -41,7 +41,7 @@ func Test_execute_string()
if has('float')
call assert_fails('call execute(3.4)', 'E492:')
call assert_equal("\nx", execute("echo \"x\"", 3.4))
call CheckDefExecAndScriptFailure(['execute("echo \"x\"", 3.4)'], ['E1013: Argument 2: type mismatch, expected string but got float', 'E1174:'])
call v9.CheckDefExecAndScriptFailure(['execute("echo \"x\"", 3.4)'], ['E1013: Argument 2: type mismatch, expected string but got float', 'E1174:'])
endif
endfunc

View File

@@ -1,7 +1,7 @@
" Tests for expressions.
source check.vim
source vim9.vim
import './vim9.vim' as v9
func Test_equal()
let base = {}
@@ -51,12 +51,12 @@ func Test_op_trinary()
call assert_fails('echo [1] ? "yes" : "no"', 'E745:')
call assert_fails('echo {} ? "yes" : "no"', 'E728:')
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
call assert_equal('no', 'x' ? 'yes' : 'no')
call CheckDefAndScriptFailure(["'x' ? 'yes' : 'no'"], 'E1135:')
call v9.CheckDefAndScriptFailure(["'x' ? 'yes' : 'no'"], 'E1135:')
call assert_equal('yes', '1x' ? 'yes' : 'no')
call CheckDefAndScriptFailure(["'1x' ? 'yes' : 'no'"], 'E1135:')
call v9.CheckDefAndScriptFailure(["'1x' ? 'yes' : 'no'"], 'E1135:')
endfunc
func Test_op_falsy()
@@ -81,7 +81,7 @@ func Test_op_falsy()
call assert_equal(456, 0.0 ?? 456)
endif
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
func Test_dict()
@@ -101,9 +101,9 @@ func Test_dict()
LET d[ 'b' ] = 'bbb'
call assert_equal('bbb', d[ 'b' ])
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
call CheckLegacyAndVim9Failure(["VAR i = has_key([], 'a')"], ['E715:', 'E1013:', 'E1206:'])
call v9.CheckLegacyAndVim9Failure(["VAR i = has_key([], 'a')"], ['E715:', 'E1013:', 'E1206:'])
endfunc
func Test_strgetchar()
@@ -116,10 +116,10 @@ func Test_strgetchar()
call assert_equal(-1, strgetchar('axb', 3))
call assert_equal(-1, strgetchar('', 0))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
call CheckLegacyAndVim9Failure(["VAR c = strgetchar([], 1)"], ['E730:', 'E1013:', 'E1174:'])
call CheckLegacyAndVim9Failure(["VAR c = strgetchar('axb', [])"], ['E745:', 'E1013:', 'E1210:'])
call v9.CheckLegacyAndVim9Failure(["VAR c = strgetchar([], 1)"], ['E730:', 'E1013:', 'E1174:'])
call v9.CheckLegacyAndVim9Failure(["VAR c = strgetchar('axb', [])"], ['E745:', 'E1013:', 'E1210:'])
endfunc
func Test_strcharpart()
@@ -138,7 +138,7 @@ func Test_strcharpart()
call assert_equal('edit', "editor"[-10 : 3])
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
func Test_getreg_empty_list()
@@ -150,9 +150,9 @@ func Test_getreg_empty_list()
call add(x, 'foo')
call assert_equal(['foo'], y)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
call CheckLegacyAndVim9Failure(['call getreg([])'], ['E730:', 'E1013:', 'E1174:'])
call v9.CheckLegacyAndVim9Failure(['call getreg([])'], ['E730:', 'E1013:', 'E1174:'])
endfunc
func Test_loop_over_null_list()
@@ -162,19 +162,19 @@ func Test_loop_over_null_list()
call assert_report('should not get here')
endfor
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
func Test_setreg_null_list()
let lines =<< trim END
call setreg('x', test_null_list())
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
func Test_special_char()
" The failure is only visible using valgrind.
call CheckLegacyAndVim9Failure(['echo "\<C-">'], ['E15:', 'E1004:', 'E1004:'])
call v9.CheckLegacyAndVim9Failure(['echo "\<C-">'], ['E15:', 'E1004:', 'E1004:'])
endfunc
func Test_method_with_prefix()
@@ -182,13 +182,13 @@ func Test_method_with_prefix()
call assert_equal(TRUE, !range(5)->empty())
call assert_equal(FALSE, !-3)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
call assert_equal([0, 1, 2], --3->range())
call CheckDefAndScriptFailure(['eval --3->range()'], 'E15')
call v9.CheckDefAndScriptFailure(['eval --3->range()'], 'E15')
call assert_equal(1, !+-+0)
call CheckDefAndScriptFailure(['eval !+-+0'], 'E15')
call v9.CheckDefAndScriptFailure(['eval !+-+0'], 'E15')
endfunc
func Test_option_value()
@@ -214,7 +214,7 @@ func Test_option_value()
call assert_equal("abcdefgi", &cpo)
set cpo&vim
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
func Test_printf_misc()
@@ -407,9 +407,9 @@ func Test_printf_misc()
call assert_equal('1%', printf('%d%%', 1))
call assert_notequal('', printf('%p', "abc"))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
call CheckLegacyAndVim9Failure(["call printf('123', 3)"], "E767:")
call v9.CheckLegacyAndVim9Failure(["call printf('123', 3)"], "E767:")
endfunc
func Test_printf_float()
@@ -519,21 +519,21 @@ func Test_printf_float()
call assert_equal('nan', printf('%S', 0.0 / 0.0))
call assert_equal('nan', printf('%S', -0.0 / 0.0))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
call CheckLegacyAndVim9Failure(['echo printf("%f", "a")'], 'E807:')
call v9.CheckLegacyAndVim9Failure(['echo printf("%f", "a")'], 'E807:')
endif
endfunc
func Test_printf_errors()
call CheckLegacyAndVim9Failure(['echo printf("%d", {})'], 'E728:')
call CheckLegacyAndVim9Failure(['echo printf("%d", [])'], 'E745:')
call CheckLegacyAndVim9Failure(['echo printf("%d", 1, 2)'], 'E767:')
call CheckLegacyAndVim9Failure(['echo printf("%*d", 1)'], 'E766:')
call CheckLegacyAndVim9Failure(['echo printf("%s")'], 'E766:')
call v9.CheckLegacyAndVim9Failure(['echo printf("%d", {})'], 'E728:')
call v9.CheckLegacyAndVim9Failure(['echo printf("%d", [])'], 'E745:')
call v9.CheckLegacyAndVim9Failure(['echo printf("%d", 1, 2)'], 'E767:')
call v9.CheckLegacyAndVim9Failure(['echo printf("%*d", 1)'], 'E766:')
call v9.CheckLegacyAndVim9Failure(['echo printf("%s")'], 'E766:')
if has('float')
call CheckLegacyAndVim9Failure(['echo printf("%d", 1.2)'], 'E805:')
call CheckLegacyAndVim9Failure(['echo printf("%f")'], 'E766:')
call v9.CheckLegacyAndVim9Failure(['echo printf("%d", 1.2)'], 'E805:')
call v9.CheckLegacyAndVim9Failure(['echo printf("%f")'], 'E766:')
endif
endfunc
@@ -541,7 +541,7 @@ func Test_printf_64bit()
let lines =<< trim END
call assert_equal("123456789012345", printf('%d', 123456789012345))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
func Test_printf_spec_s()
@@ -571,7 +571,7 @@ func Test_printf_spec_s()
#" partial
call assert_equal(string(function('printf', ['%s'])), printf('%s', function('printf', ['%s'])))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
func Test_printf_spec_b()
@@ -587,14 +587,14 @@ func Test_printf_spec_b()
call assert_equal("11100000100100010000110000011011101111101111001", printf('%b', 123456789012345))
call assert_equal("1111111111111111111111111111111111111111111111111111111111111111", printf('%b', -1))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
func Test_max_min_errors()
call CheckLegacyAndVim9Failure(['call max(v:true)'], ['E712:', 'E1013:', 'E1227:'])
call CheckLegacyAndVim9Failure(['call max(v:true)'], ['max()', 'E1013:', 'E1227:'])
call CheckLegacyAndVim9Failure(['call min(v:true)'], ['E712:', 'E1013:', 'E1227:'])
call CheckLegacyAndVim9Failure(['call min(v:true)'], ['min()', 'E1013:', 'E1227:'])
call v9.CheckLegacyAndVim9Failure(['call max(v:true)'], ['E712:', 'E1013:', 'E1227:'])
call v9.CheckLegacyAndVim9Failure(['call max(v:true)'], ['max()', 'E1013:', 'E1227:'])
call v9.CheckLegacyAndVim9Failure(['call min(v:true)'], ['E712:', 'E1013:', 'E1227:'])
call v9.CheckLegacyAndVim9Failure(['call min(v:true)'], ['min()', 'E1013:', 'E1227:'])
endfunc
func Test_function_with_funcref()
@@ -615,9 +615,9 @@ func Test_function_with_funcref()
call execute('VAR Ref = ' .. name)
call assert_equal(4, Ref('text'))
END
call CheckTransLegacySuccess(lines)
call v9.CheckTransLegacySuccess(lines)
" cannot create s: variable in :def function
call CheckTransVim9Success(lines)
call v9.CheckTransVim9Success(lines)
endfunc
func Test_funcref()
@@ -668,9 +668,9 @@ func Test_setmatches()
eval set->setmatches()
call assert_equal(exp, getmatches())
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
call CheckLegacyAndVim9Failure(['VAR m = setmatches([], [])'], ['E745:', 'E1013:', 'E1210:'])
call v9.CheckLegacyAndVim9Failure(['VAR m = setmatches([], [])'], ['E745:', 'E1013:', 'E1210:'])
endfunc
func Test_empty_concatenate()
@@ -678,19 +678,19 @@ func Test_empty_concatenate()
call assert_equal('b', 'a'[4 : 0] .. 'b')
call assert_equal('b', 'b' .. 'a'[4 : 0])
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
func Test_broken_number()
call CheckLegacyAndVim9Failure(['VAR X = "bad"', 'echo 1X'], 'E15:')
call CheckLegacyAndVim9Failure(['VAR X = "bad"', 'echo 0b1X'], 'E15:')
call CheckLegacyAndVim9Failure(['echo 0b12'], 'E15:')
call CheckLegacyAndVim9Failure(['VAR X = "bad"', 'echo 0x1X'], 'E15:')
call CheckLegacyAndVim9Failure(['VAR X = "bad"', 'echo 011X'], 'E15:')
call v9.CheckLegacyAndVim9Failure(['VAR X = "bad"', 'echo 1X'], 'E15:')
call v9.CheckLegacyAndVim9Failure(['VAR X = "bad"', 'echo 0b1X'], 'E15:')
call v9.CheckLegacyAndVim9Failure(['echo 0b12'], 'E15:')
call v9.CheckLegacyAndVim9Failure(['VAR X = "bad"', 'echo 0x1X'], 'E15:')
call v9.CheckLegacyAndVim9Failure(['VAR X = "bad"', 'echo 011X'], 'E15:')
call CheckLegacyAndVim9Success(['call assert_equal(2, str2nr("2a"))'])
call v9.CheckLegacyAndVim9Success(['call assert_equal(2, str2nr("2a"))'])
call CheckLegacyAndVim9Failure(['inoremap <Char-0b1z> b'], 'E474:')
call v9.CheckLegacyAndVim9Failure(['inoremap <Char-0b1z> b'], 'E474:')
endfunc
func Test_eval_after_if()
@@ -783,11 +783,11 @@ endfunc
" Test for errors in expression evaluation
func Test_expr_eval_error()
call CheckLegacyAndVim9Failure(["VAR i = 'abc' .. []"], ['E730:', 'E1105:', 'E730:'])
call CheckLegacyAndVim9Failure(["VAR l = [] + 10"], ['E745:', 'E1051:', 'E745'])
call CheckLegacyAndVim9Failure(["VAR v = 10 + []"], ['E745:', 'E1051:', 'E745:'])
call CheckLegacyAndVim9Failure(["VAR v = 10 / []"], ['E745:', 'E1036:', 'E745:'])
call CheckLegacyAndVim9Failure(["VAR v = -{}"], ['E728:', 'E1012:', 'E728:'])
call v9.CheckLegacyAndVim9Failure(["VAR i = 'abc' .. []"], ['E730:', 'E1105:', 'E730:'])
call v9.CheckLegacyAndVim9Failure(["VAR l = [] + 10"], ['E745:', 'E1051:', 'E745'])
call v9.CheckLegacyAndVim9Failure(["VAR v = 10 + []"], ['E745:', 'E1051:', 'E745:'])
call v9.CheckLegacyAndVim9Failure(["VAR v = 10 / []"], ['E745:', 'E1036:', 'E745:'])
call v9.CheckLegacyAndVim9Failure(["VAR v = -{}"], ['E728:', 'E1012:', 'E728:'])
endfunc
func Test_white_in_function_call()
@@ -795,13 +795,13 @@ func Test_white_in_function_call()
VAR text = substitute ( 'some text' , 't' , 'T' , 'g' )
call assert_equal('some TexT', text)
END
call CheckTransLegacySuccess(lines)
call v9.CheckTransLegacySuccess(lines)
let lines =<< trim END
var text = substitute ( 'some text' , 't' , 'T' , 'g' )
call assert_equal('some TexT', text)
END
call CheckDefAndScriptFailure(lines, ['E1001:', 'E121:'])
call v9.CheckDefAndScriptFailure(lines, ['E1001:', 'E121:'])
endfunc
" Test for float value comparison
@@ -825,7 +825,7 @@ func Test_float_compare()
#" +infinity != -infinity
call assert_true((1.0 / 0) != -(2.0 / 0))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -1,6 +1,6 @@
" Test filter() and map()
source vim9.vim
import './vim9.vim' as v9
" list with expression string
func Test_filter_map_list_expr_string()
@@ -166,7 +166,7 @@ func Test_filter_map_string()
call assert_equal('', filter('', "v:val == 'a'"))
call assert_equal('', filter(test_null_string(), "v:val == 'a'"))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" map()
let lines =<< trim END
@@ -185,7 +185,7 @@ func Test_filter_map_string()
call assert_fails('echo map("abc", "10")', 'E928:')
call assert_fails('echo map("abc", "a10")', 'E121:')
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" mapnew()
let lines =<< trim END
@@ -202,7 +202,7 @@ func Test_filter_map_string()
call assert_equal('', mapnew('', "v:val == 'a'"))
call assert_equal('', mapnew(test_null_string(), "v:val == 'a'"))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
let lines =<< trim END
#" map() and filter()
@@ -228,7 +228,7 @@ func Test_filter_map_string()
call assert_equal('@ström', map('Åström', LSTART i, x LMIDDLE x =~ nr2char(0xc5) .. '\%C' ? '@' : x LEND))
call assert_equal('Åstr@m', map('Åström', LSTART i, x LMIDDLE x =~ nr2char(0xf6) .. '\%C' ? '@' : x LEND))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -2,7 +2,7 @@
source check.vim
CheckFeature float
source vim9.vim
import './vim9.vim' as v9
func Test_abs()
call assert_equal('1.23', string(abs(1.23)))
@@ -246,7 +246,7 @@ func Test_str2float()
call assert_equal('123456.7', string(str2float("123'456.7'89", 1)))
call assert_equal(1.2, str2float(1.2, 0))
call CheckDefAndScriptFailure(['str2float(1.2)'], ['E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1'])
call v9.CheckDefAndScriptFailure(['str2float(1.2)'], ['E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1'])
call assert_fails("call str2float([])", 'E730:')
call assert_fails("call str2float({})", 'E731:')
call assert_fails("call str2float(function('string'))", 'E729:')

View File

@@ -4,7 +4,7 @@ source shared.vim
source check.vim
source term_util.vim
source screendump.vim
source vim9.vim
import './vim9.vim' as v9
" Must be done first, since the alternate buffer must be unset.
func Test_00_bufexists()
@@ -174,7 +174,7 @@ func Test_strwidth()
if has('float')
call assert_equal(3, strwidth(1.2))
call CheckDefAndScriptFailure(['echo strwidth(1.2)'], ['E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1'])
call v9.CheckDefAndScriptFailure(['echo strwidth(1.2)'], ['E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1'])
endif
set ambiwidth&
@@ -241,7 +241,7 @@ func Test_str2nr()
call assert_fails('call str2nr({->2})', 'E729:')
if has('float')
call assert_equal(1, str2nr(1.2))
call CheckDefAndScriptFailure(['echo str2nr(1.2)'], ['E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1'])
call v9.CheckDefAndScriptFailure(['echo str2nr(1.2)'], ['E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1'])
endif
call assert_fails('call str2nr(10, [])', 'E745:')
endfunc
@@ -503,7 +503,7 @@ func Test_simplify()
call assert_fails('call simplify({})', 'E731:')
if has('float')
call assert_equal('1.2', simplify(1.2))
call CheckDefAndScriptFailure(['echo simplify(1.2)'], ['E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1'])
call v9.CheckDefAndScriptFailure(['echo simplify(1.2)'], ['E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1'])
endif
endfunc
@@ -2265,7 +2265,7 @@ func Test_call()
let Time = 'localtime'
call Time()
END
call CheckScriptFailure(lines, 'E1085:')
call v9.CheckScriptFailure(lines, 'E1085:')
endfunc
func Test_char2nr()
@@ -2800,7 +2800,7 @@ func Test_builtin_check()
vim9script
var s:trim = (x) => " " .. x
END
call CheckScriptFailure(lines, 'E704:')
call v9.CheckScriptFailure(lines, 'E704:')
call assert_fails('call extend(g:, #{foo: { -> "foo" }})', 'E704:')
let g:bar = 123

View File

@@ -1,11 +1,11 @@
" Test glob2regpat()
source vim9.vim
import './vim9.vim' as v9
func Test_glob2regpat_invalid()
if has('float')
call assert_equal('^1\.33$', glob2regpat(1.33))
call CheckDefAndScriptFailure(['echo glob2regpat(1.2)'], ['E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1'])
call v9.CheckDefAndScriptFailure(['echo glob2regpat(1.2)'], ['E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1'])
endif
call assert_fails('call glob2regpat("}")', 'E219:')
call assert_fails('call glob2regpat("{")', 'E220:')

View File

@@ -4,7 +4,7 @@ source view_util.vim
source screendump.vim
source check.vim
source script_util.vim
source vim9.vim
import './vim9.vim' as v9
func ClearDict(d)
for k in keys(a:d)
@@ -1011,7 +1011,7 @@ func Test_hlget()
call assert_equal([], hlget(test_null_string()))
call assert_equal([], hlget(""))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" Test for resolving highlight group links
let lines =<< trim END
@@ -1042,7 +1042,7 @@ func Test_hlget()
call assert_equal([{'id': hlgCid, 'name': 'hlgC',
\ 'term': {'bold': v:true}}], hlget('hlgC', v:true))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
call assert_fails('call hlget([])', 'E1174:')
call assert_fails('call hlget("abc", "xyz")', 'E1212:')
@@ -1098,7 +1098,7 @@ func Test_hlset()
call assert_equal('Search', hlget('NewHLGroup')[0].linksto)
highlight clear NewHLGroup
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" Test for clearing the 'term', 'cterm' and 'gui' attributes of a highlight
" group.
@@ -1117,7 +1117,7 @@ func Test_hlset()
\ hlget('myhlg1'))
highlight clear myhlg1
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" Test for setting all the 'term', 'cterm' and 'gui' attributes of a
" highlight group
@@ -1134,7 +1134,7 @@ func Test_hlset()
call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
\ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" Test for clearing some of the 'term', 'cterm' and 'gui' attributes of a
" highlight group
@@ -1150,7 +1150,7 @@ func Test_hlset()
call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
\ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" Test for clearing the attributes and link of a highlight group
let lines =<< trim END
@@ -1162,7 +1162,7 @@ func Test_hlset()
\ hlget('myhlg3'))
highlight clear hlg3
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" Test for setting default attributes for a highlight group
let lines =<< trim END
@@ -1187,7 +1187,7 @@ func Test_hlset()
\ hlget('hlg6'))
highlight clear hlg6
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" Test for setting default links for a highlight group
let lines =<< trim END
@@ -1217,7 +1217,7 @@ func Test_hlset()
\ 'linksto': 'ErrorMsg'}], hlget('hlg9dup'))
highlight clear hlg9
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" Test for force creating a link to a highlight group
let lines =<< trim END
@@ -1231,7 +1231,7 @@ func Test_hlset()
\ 'linksto': 'Search'}], hlget('hlg10'))
highlight clear hlg10
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" Test for empty values of attributes
call hlset([{'name': 'hlg11', 'cterm': {}}])

View File

@@ -2,7 +2,7 @@
source view_util.vim
source check.vim
source vim9.vim
import './vim9.vim' as v9
let s:imactivatefunc_called = 0
let s:imstatusfunc_called = 0
@@ -165,28 +165,28 @@ func Test_imactivatefunc_imstatusfunc_callback()
normal! i
#" Test for using a lambda function
VAR optval = "LSTART a LMIDDLE IMactivatefunc1(a) LEND"
VAR optval = "LSTART a LMIDDLE g:IMactivatefunc1(a) LEND"
LET optval = substitute(optval, ' ', '\\ ', 'g')
exe "set imactivatefunc=" .. optval
LET optval = "LSTART LMIDDLE IMstatusfunc1() LEND"
LET optval = "LSTART LMIDDLE g:IMstatusfunc1() LEND"
LET optval = substitute(optval, ' ', '\\ ', 'g')
exe "set imstatusfunc=" .. optval
normal! i
#" Set 'imactivatefunc' and 'imstatusfunc' to a lambda expression
LET &imactivatefunc = LSTART a LMIDDLE IMactivatefunc1(a) LEND
LET &imstatusfunc = LSTART LMIDDLE IMstatusfunc1() LEND
LET &imactivatefunc = LSTART a LMIDDLE g:IMactivatefunc1(a) LEND
LET &imstatusfunc = LSTART LMIDDLE g:IMstatusfunc1() LEND
normal! i
#" Set 'imactivatefunc' and 'imstatusfunc' to a string(lambda expression)
LET &imactivatefunc = 'LSTART a LMIDDLE IMactivatefunc1(a) LEND'
LET &imstatusfunc = 'LSTART LMIDDLE IMstatusfunc1() LEND'
LET &imactivatefunc = 'LSTART a LMIDDLE g:IMactivatefunc1(a) LEND'
LET &imstatusfunc = 'LSTART LMIDDLE g:IMstatusfunc1() LEND'
normal! i
#" Set 'imactivatefunc' 'imstatusfunc' to a variable with a lambda
#" expression
VAR Lambda1 = LSTART a LMIDDLE IMactivatefunc1(a) LEND
VAR Lambda2 = LSTART LMIDDLE IMstatusfunc1() LEND
VAR Lambda1 = LSTART a LMIDDLE g:IMactivatefunc1(a) LEND
VAR Lambda2 = LSTART LMIDDLE g:IMstatusfunc1() LEND
LET &imactivatefunc = Lambda1
LET &imstatusfunc = Lambda2
normal! i
@@ -223,7 +223,7 @@ func Test_imactivatefunc_imstatusfunc_callback()
call assert_equal(14, g:IMactivatefunc_called)
call assert_equal(28, g:IMstatusfunc_called)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" Using Vim9 lambda expression in legacy context should fail
set imactivatefunc=(a)\ =>\ IMactivatefunc1(a)
@@ -285,7 +285,7 @@ func Test_imactivatefunc_imstatusfunc_callback()
set imactivatefunc=
set imstatusfunc=
END
call CheckScriptSuccess(lines)
call v9.CheckScriptSuccess(lines)
" cleanup
set iminsert=0

View File

@@ -2,7 +2,7 @@
source screendump.vim
source check.vim
source vim9.vim
import './vim9.vim' as v9
" Test for insert expansion
func Test_ins_complete()
@@ -1359,7 +1359,7 @@ func Test_completefunc_callback()
bw!
#" Test for using a lambda function with set
VAR optval = "LSTART a, b LMIDDLE CompleteFunc1(16, a, b) LEND"
VAR optval = "LSTART a, b LMIDDLE g:CompleteFunc1(16, a, b) LEND"
LET optval = substitute(optval, ' ', '\\ ', 'g')
exe "set completefunc=" .. optval
new
@@ -1370,7 +1370,7 @@ func Test_completefunc_callback()
bw!
#" Set 'completefunc' to a lambda expression
LET &completefunc = LSTART a, b LMIDDLE CompleteFunc1(17, a, b) LEND
LET &completefunc = LSTART a, b LMIDDLE g:CompleteFunc1(17, a, b) LEND
new
call setline(1, 'six')
LET g:CompleteFunc1Args = []
@@ -1379,7 +1379,7 @@ func Test_completefunc_callback()
bw!
#" Set 'completefunc' to string(lambda_expression)
LET &completefunc = 'LSTART a, b LMIDDLE CompleteFunc1(18, a, b) LEND'
LET &completefunc = 'LSTART a, b LMIDDLE g:CompleteFunc1(18, a, b) LEND'
new
call setline(1, 'six')
LET g:CompleteFunc1Args = []
@@ -1388,7 +1388,7 @@ func Test_completefunc_callback()
bw!
#" Set 'completefunc' to a variable with a lambda expression
VAR Lambda = LSTART a, b LMIDDLE CompleteFunc1(19, a, b) LEND
VAR Lambda = LSTART a, b LMIDDLE g:CompleteFunc1(19, a, b) LEND
LET &completefunc = Lambda
new
call setline(1, 'seven')
@@ -1398,7 +1398,7 @@ func Test_completefunc_callback()
bw!
#" Set 'completefunc' to a string(variable with a lambda expression)
LET Lambda = LSTART a, b LMIDDLE CompleteFunc1(20, a, b) LEND
LET Lambda = LSTART a, b LMIDDLE g:CompleteFunc1(20, a, b) LEND
LET &completefunc = string(Lambda)
new
call setline(1, 'seven')
@@ -1431,7 +1431,7 @@ func Test_completefunc_callback()
call assert_equal([[1, ''], [0, 'five']], g:CompleteFunc2Args)
bw!
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" Test for using a script-local function name
func s:CompleteFunc3(findstart, base)
@@ -1460,7 +1460,7 @@ func Test_completefunc_callback()
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
" Using Vim9 lambda expression in legacy context should fail
set completefunc=(a,\ b)\ =>\ CompleteFunc1(21,\ a,\ b)
set completefunc=(a,\ b)\ =>\ g:CompleteFunc1(21,\ a,\ b)
new | only
let g:CompleteFunc1Args = []
call assert_fails('call feedkeys("A\<C-X>\<C-U>\<Esc>", "x")', 'E117:')
@@ -1526,7 +1526,7 @@ func Test_completefunc_callback()
assert_equal([[1, ''], [0, 'three']], g:LocalCompleteFuncArgs)
bw!
END
call CheckScriptSuccess(lines)
call v9.CheckScriptSuccess(lines)
" cleanup
set completefunc&
@@ -1616,7 +1616,7 @@ func Test_omnifunc_callback()
bw!
#" Test for using a lambda function with set
VAR optval = "LSTART a, b LMIDDLE OmniFunc1(16, a, b) LEND"
VAR optval = "LSTART a, b LMIDDLE g:OmniFunc1(16, a, b) LEND"
LET optval = substitute(optval, ' ', '\\ ', 'g')
exe "set omnifunc=" .. optval
new
@@ -1627,7 +1627,7 @@ func Test_omnifunc_callback()
bw!
#" Set 'omnifunc' to a lambda expression
LET &omnifunc = LSTART a, b LMIDDLE OmniFunc1(17, a, b) LEND
LET &omnifunc = LSTART a, b LMIDDLE g:OmniFunc1(17, a, b) LEND
new
call setline(1, 'six')
LET g:OmniFunc1Args = []
@@ -1636,7 +1636,7 @@ func Test_omnifunc_callback()
bw!
#" Set 'omnifunc' to a string(lambda_expression)
LET &omnifunc = 'LSTART a, b LMIDDLE OmniFunc1(18, a, b) LEND'
LET &omnifunc = 'LSTART a, b LMIDDLE g:OmniFunc1(18, a, b) LEND'
new
call setline(1, 'six')
LET g:OmniFunc1Args = []
@@ -1645,7 +1645,7 @@ func Test_omnifunc_callback()
bw!
#" Set 'omnifunc' to a variable with a lambda expression
VAR Lambda = LSTART a, b LMIDDLE OmniFunc1(19, a, b) LEND
VAR Lambda = LSTART a, b LMIDDLE g:OmniFunc1(19, a, b) LEND
LET &omnifunc = Lambda
new
call setline(1, 'seven')
@@ -1655,7 +1655,7 @@ func Test_omnifunc_callback()
bw!
#" Set 'omnifunc' to a string(variable with a lambda expression)
LET Lambda = LSTART a, b LMIDDLE OmniFunc1(20, a, b) LEND
LET Lambda = LSTART a, b LMIDDLE g:OmniFunc1(20, a, b) LEND
LET &omnifunc = string(Lambda)
new
call setline(1, 'seven')
@@ -1688,7 +1688,7 @@ func Test_omnifunc_callback()
call assert_equal([[1, ''], [0, 'nine']], g:OmniFunc2Args)
bw!
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" Test for using a script-local function name
func s:OmniFunc3(findstart, base)
@@ -1783,7 +1783,7 @@ func Test_omnifunc_callback()
assert_equal([[1, ''], [0, 'three']], g:LocalOmniFuncArgs)
bw!
END
call CheckScriptSuccess(lines)
call v9.CheckScriptSuccess(lines)
" cleanup
set omnifunc&
@@ -1873,7 +1873,7 @@ func Test_thesaurusfunc_callback()
bw!
#" Test for using a lambda function
VAR optval = "LSTART a, b LMIDDLE TsrFunc1(16, a, b) LEND"
VAR optval = "LSTART a, b LMIDDLE g:TsrFunc1(16, a, b) LEND"
LET optval = substitute(optval, ' ', '\\ ', 'g')
exe "set thesaurusfunc=" .. optval
new
@@ -1884,7 +1884,7 @@ func Test_thesaurusfunc_callback()
bw!
#" Test for using a lambda function with set
LET &thesaurusfunc = LSTART a, b LMIDDLE TsrFunc1(17, a, b) LEND
LET &thesaurusfunc = LSTART a, b LMIDDLE g:TsrFunc1(17, a, b) LEND
new
call setline(1, 'six')
LET g:TsrFunc1Args = []
@@ -1893,7 +1893,7 @@ func Test_thesaurusfunc_callback()
bw!
#" Set 'thesaurusfunc' to a string(lambda expression)
LET &thesaurusfunc = 'LSTART a, b LMIDDLE TsrFunc1(18, a, b) LEND'
LET &thesaurusfunc = 'LSTART a, b LMIDDLE g:TsrFunc1(18, a, b) LEND'
new
call setline(1, 'six')
LET g:TsrFunc1Args = []
@@ -1902,7 +1902,7 @@ func Test_thesaurusfunc_callback()
bw!
#" Set 'thesaurusfunc' to a variable with a lambda expression
VAR Lambda = LSTART a, b LMIDDLE TsrFunc1(19, a, b) LEND
VAR Lambda = LSTART a, b LMIDDLE g:TsrFunc1(19, a, b) LEND
LET &thesaurusfunc = Lambda
new
call setline(1, 'seven')
@@ -1912,7 +1912,7 @@ func Test_thesaurusfunc_callback()
bw!
#" Set 'thesaurusfunc' to a string(variable with a lambda expression)
LET Lambda = LSTART a, b LMIDDLE TsrFunc1(20, a, b) LEND
LET Lambda = LSTART a, b LMIDDLE g:TsrFunc1(20, a, b) LEND
LET &thesaurusfunc = string(Lambda)
new
call setline(1, 'seven')
@@ -1968,7 +1968,7 @@ func Test_thesaurusfunc_callback()
call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:TsrFunc1Args)
:%bw!
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" Test for using a script-local function name
func s:TsrFunc3(findstart, base)
@@ -2076,7 +2076,7 @@ func Test_thesaurusfunc_callback()
assert_equal([[1, ''], [0, 'three']], g:LocalTsrFuncArgs)
bw!
END
call CheckScriptSuccess(lines)
call v9.CheckScriptSuccess(lines)
" cleanup
set thesaurusfunc&

View File

@@ -1,7 +1,7 @@
" Tests for the List and Dict types
scriptencoding utf-8
source vim9.vim
import './vim9.vim' as v9
func TearDown()
" Run garbage collection after every test
@@ -50,7 +50,7 @@ func Test_list_slice()
call assert_equal([2], l[-1 : -1])
call assert_equal([1, 2], l[-2 : -1])
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
let l = [1, 2]
call assert_equal([], l[-3 : -1])
@@ -59,7 +59,7 @@ func Test_list_slice()
var l = [1, 2]
assert_equal([1, 2], l[-3 : -1])
END
call CheckDefAndScriptSuccess(lines)
call v9.CheckDefAndScriptSuccess(lines)
endfunc
" List identity
@@ -75,7 +75,7 @@ func Test_list_identity()
call assert_false(l is lx)
call assert_true(l isnot lx)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
" removing items with :unlet
@@ -118,7 +118,7 @@ func Test_list_unlet()
unlet l[-6 : 2]
call assert_equal([3], l)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
let l = [0, 1, 2, 3]
unlet l[2:2]
@@ -131,13 +131,13 @@ func Test_list_unlet()
VAR l = [0, 1, 2, 3]
unlet l[2 : 1]
END
call CheckLegacyAndVim9Failure(lines, 'E684:')
call v9.CheckLegacyAndVim9Failure(lines, 'E684:')
let lines =<< trim END
VAR l = [0, 1, 2, 3]
unlet l[-1 : 2]
END
call CheckLegacyAndVim9Failure(lines, 'E684:')
call v9.CheckLegacyAndVim9Failure(lines, 'E684:')
endfunc
" assignment to a list
@@ -149,35 +149,35 @@ func Test_list_assign()
LET [va, vb] = l[2 : 3]
call assert_equal([2, 3], [va, vb])
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
let lines =<< trim END
let l = [0, 1, 2, 3]
let [va, vb] = l
END
call CheckScriptFailure(lines, 'E687:')
call v9.CheckScriptFailure(lines, 'E687:')
let lines =<< trim END
var l = [0, 1, 2, 3]
var va = 0
var vb = 0
[va, vb] = l
END
call CheckScriptFailure(['vim9script'] + lines, 'E687:')
call CheckDefExecFailure(lines, 'E1093: Expected 2 items but got 4')
call v9.CheckScriptFailure(['vim9script'] + lines, 'E687:')
call v9.CheckDefExecFailure(lines, 'E1093: Expected 2 items but got 4')
let lines =<< trim END
let l = [0, 1, 2, 3]
let [va, vb] = l[1:1]
END
call CheckScriptFailure(lines, 'E688:')
call v9.CheckScriptFailure(lines, 'E688:')
let lines =<< trim END
var l = [0, 1, 2, 3]
var va = 0
var vb = 0
[va, vb] = l[1 : 1]
END
call CheckScriptFailure(['vim9script'] + lines, 'E688:')
call CheckDefExecFailure(lines, 'E1093: Expected 2 items but got 1')
call v9.CheckScriptFailure(['vim9script'] + lines, 'E688:')
call v9.CheckDefExecFailure(lines, 'E1093: Expected 2 items but got 1')
endfunc
" test for range assign
@@ -189,13 +189,13 @@ func Test_list_range_assign()
LET l[-4 : -1] = [5, 6]
call assert_equal([5, 6], l)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
let lines =<< trim END
var l = [7]
l[:] = ['text']
END
call CheckDefAndScriptFailure(lines, 'E1012:', 2)
call v9.CheckDefAndScriptFailure(lines, 'E1012:', 2)
endfunc
" Test removing items in list
@@ -227,7 +227,7 @@ func Test_list_func_remove()
call assert_equal([2, 3], remove(l, -3, -2))
call assert_equal([1, 4], l)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" Test invalid cases
let l = [1, 2, 3, 4]
@@ -251,7 +251,7 @@ func Test_list_add()
call add(l, test_null_dict())
call assert_equal([1, [2, 3], [], [], {'k': 3}, {}, {}], l)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" weird legacy behavior
call assert_equal(1, add(test_null_list(), 4))
@@ -271,7 +271,7 @@ func Test_dict()
call extend(d, {'b': 'bbb', 'c': 'ccc'}, "keep")
call assert_equal({'c': 'ccc', '1': 99, 'b': [1, 2, function('strlen')], '3': 33, '-1': {'a': 1}}, d)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},}
call assert_equal("{'1': 'asd', 'b': [1, 2, function('strlen')], '-1': {'a': 1}}", string(d))
@@ -320,7 +320,7 @@ func Test_dict_identity()
call assert_false(d is dx)
call assert_true(d isnot dx)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
" removing items with :unlet
@@ -331,7 +331,7 @@ func Test_dict_unlet()
unlet d[-1]
call assert_equal({'1': 99, '3': 33}, d)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
" manipulating a big Dictionary (hashtable.c has a border of 1000 entries)
@@ -405,24 +405,24 @@ func Test_dict_assign()
LET d._ = 2
call assert_equal({'a': 1, '_': 2}, d)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
let lines =<< trim END
let n = 0
let n.key = 3
END
call CheckScriptFailure(lines, 'E1203: Dot can only be used on a dictionary: n.key = 3')
call v9.CheckScriptFailure(lines, 'E1203: Dot can only be used on a dictionary: n.key = 3')
let lines =<< trim END
vim9script
var n = 0
n.key = 3
END
call CheckScriptFailure(lines, 'E1203: Dot can only be used on a dictionary: n.key = 3')
call v9.CheckScriptFailure(lines, 'E1203: Dot can only be used on a dictionary: n.key = 3')
let lines =<< trim END
var n = 0
n.key = 3
END
call CheckDefFailure(lines, 'E1141:')
call v9.CheckDefFailure(lines, 'E1141:')
endfunc
" Function in script-local List or Dict
@@ -444,55 +444,55 @@ func Test_dict_func_remove()
call assert_equal('b', remove(d, 2))
call assert_equal({1: 'a', 3: 'c'}, d)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
let lines =<< trim END
VAR d = {1: 'a', 3: 'c'}
call remove(d, 1, 2)
END
call CheckLegacyAndVim9Failure(lines, 'E118:')
call v9.CheckLegacyAndVim9Failure(lines, 'E118:')
let lines =<< trim END
VAR d = {1: 'a', 3: 'c'}
call remove(d, 'a')
END
call CheckLegacyAndVim9Failure(lines, 'E716:')
call v9.CheckLegacyAndVim9Failure(lines, 'E716:')
let lines =<< trim END
let d = {'a-b': 55}
echo d.a-b
END
call CheckScriptFailure(lines, 'E716: Key not present in Dictionary: "a"')
call v9.CheckScriptFailure(lines, 'E716: Key not present in Dictionary: "a"')
let lines =<< trim END
vim9script
var d = {'a-b': 55}
echo d.a-b
END
call CheckScriptFailure(lines, 'E716: Key not present in Dictionary: "a"')
call v9.CheckScriptFailure(lines, 'E716: Key not present in Dictionary: "a"')
let lines =<< trim END
var d = {'a-b': 55}
echo d.a-b
END
call CheckDefFailure(lines, 'E1004: White space required before and after ''-''')
call v9.CheckDefFailure(lines, 'E1004: White space required before and after ''-''')
let lines =<< trim END
let d = {1: 'a', 3: 'c'}
call remove(d, [])
END
call CheckScriptFailure(lines, 'E730:')
call v9.CheckScriptFailure(lines, 'E730:')
let lines =<< trim END
vim9script
var d = {1: 'a', 3: 'c'}
call remove(d, [])
END
call CheckScriptFailure(lines, 'E1220: String or Number required for argument 2')
call v9.CheckScriptFailure(lines, 'E1220: String or Number required for argument 2')
let lines =<< trim END
var d = {1: 'a', 3: 'c'}
call remove(d, [])
END
call CheckDefExecFailure(lines, 'E1013: Argument 2: type mismatch, expected string but got list<unknown>')
call v9.CheckDefExecFailure(lines, 'E1013: Argument 2: type mismatch, expected string but got list<unknown>')
endfunc
" Nasty: remove func from Dict that's being called (works)
@@ -514,8 +514,8 @@ func Test_dict_func_remove_in_use()
VAR expected = 'a:' .. string(get(d, 'func'))
call assert_equal(expected, d.func(string(remove(d, 'func'))))
END
call CheckTransLegacySuccess(lines)
call CheckTransVim9Success(lines)
call v9.CheckTransLegacySuccess(lines)
call v9.CheckTransVim9Success(lines)
endfunc
func Test_dict_literal_keys()
@@ -535,7 +535,7 @@ func Test_dict_deepcopy()
VAR dc = deepcopy(d)
call deepcopy(d, 1)
END
call CheckLegacyAndVim9Failure(lines, 'E698:')
call v9.CheckLegacyAndVim9Failure(lines, 'E698:')
let lines =<< trim END
VAR d = {1: 1, 2: '2'}
@@ -546,7 +546,7 @@ func Test_dict_deepcopy()
VAR l3 = deepcopy(l2)
call assert_true(l3[1] is l3[2])
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
call assert_fails("call deepcopy([1, 2], 2)", 'E1023:')
endfunc
@@ -631,8 +631,8 @@ func Test_list_locked_var()
endfor
endfor
END
call CheckTransLegacySuccess(lines)
call CheckTransVim9Success(lines)
call v9.CheckTransLegacySuccess(lines)
call v9.CheckTransVim9Success(lines)
call assert_fails("let x=islocked('a b')", 'E488:')
let mylist = [1, 2, 3]
@@ -745,7 +745,7 @@ func Test_dict_item_lock_unlet()
unlet d.a
call assert_equal({'b': 100}, d)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
" filter() after lock on dict item
@@ -756,7 +756,7 @@ func Test_dict_lock_filter()
call filter(d, 'v:key != "a"')
call assert_equal({'b': 100}, d)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
" map() after lock on dict
@@ -768,8 +768,8 @@ func Test_dict_lock_map()
call assert_equal({'a': 299, 'b': 300}, d)
END
" This won't work in a :def function
call CheckTransLegacySuccess(lines)
call CheckTransVim9Success(lines)
call v9.CheckTransLegacySuccess(lines)
call v9.CheckTransVim9Success(lines)
" For a :def function use a global dict.
let lines =<< trim END
@@ -780,7 +780,7 @@ func Test_dict_lock_map()
enddef
call Delkey()
END
call CheckScriptFailure(lines, 'E741:')
call v9.CheckScriptFailure(lines, 'E741:')
endfunc
" Lock one item in a list
@@ -792,8 +792,8 @@ func Test_list_item_lock_map()
call assert_equal([299, 100, 101], l)
END
" This won't work in a :def function
call CheckTransLegacySuccess(lines)
call CheckTransVim9Success(lines)
call v9.CheckTransLegacySuccess(lines)
call v9.CheckTransVim9Success(lines)
endfunc
" Lock one item in a dict
@@ -805,8 +805,8 @@ func Test_dict_item_lock_map()
call assert_equal({'a': 299, 'b': 100, 'c': 101}, d)
END
" This won't work in a :def function
call CheckTransLegacySuccess(lines)
call CheckTransVim9Success(lines)
call v9.CheckTransLegacySuccess(lines)
call v9.CheckTransVim9Success(lines)
endfunc
" No extend() after lock on dict item
@@ -885,7 +885,7 @@ func Test_let_lock_list()
lockvar! l
call TryUnletListItem(l)
END
call CheckScriptFailure(lines, 'E741:')
call v9.CheckScriptFailure(lines, 'E741:')
unlet g:l
endfunc
@@ -954,7 +954,7 @@ func Test_reverse_sort_uniq()
call assert_equal(['BAR', 'Bar', 'FOO', 'FOOBAR', 'Foo', 'bar', 'foo', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l)))
endif
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
call assert_fails('call reverse("")', 'E899:')
call assert_fails('call uniq([1, 2], {x, y -> []})', 'E745:')
@@ -997,7 +997,7 @@ func Test_reduce()
call assert_equal('Å,s,t,r,ö,m', reduce('Åström', LSTART acc, val LMIDDLE acc .. ',' .. val LEND))
call assert_equal(',a,b,c', reduce('abc', LSTART acc, val LMIDDLE acc .. ',' .. val LEND, test_null_string()))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
call assert_equal({'x': 1, 'y': 1, 'z': 1 }, ['x', 'y', 'z']->reduce({ acc, val -> extend(acc, { val: 1 }) }, {}))
vim9 assert_equal({'x': 1, 'y': 1, 'z': 1 }, ['x', 'y', 'z']->reduce((acc, val) => extend(acc, {[val]: 1 }), {}))
@@ -1055,7 +1055,7 @@ func Test_str_split()
call assert_equal(['', 'a', '', 'b', '', 'c', ''], split('abc', '\zs', 1))
call assert_equal(['abc'], split('abc', '\\%('))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
call assert_fails("call split('abc', [])", 'E730:')
call assert_fails("call split('abc', 'b', [])", 'E745:')
@@ -1072,7 +1072,7 @@ func Test_listdict_compare()
call assert_false(l != deepcopy(l))
call assert_false(d != deepcopy(d))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" comparison errors
call assert_fails('echo [1, 2] =~ {}', 'E691:')
@@ -1093,7 +1093,7 @@ func Test_listdict_compare_complex()
call assert_true(l == lcopy)
call assert_true(dict4 == dict4copy)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
" Test for extending lists and dictionaries
@@ -1130,7 +1130,7 @@ func Test_listdict_extend()
call extend(l, [4, 5, 6], -3)
call assert_equal([4, 5, 6, 1, 2, 3], l)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
let l = [1, 2, 3]
call assert_fails("call extend(l, [4, 5, 6], 4)", 'E684:')
@@ -1159,7 +1159,7 @@ func Test_listdict_extend()
call extend(d, {'b': 0, 'c': 'C'}, "keep")
call assert_equal({'a': 'A', 'b': 9, 'c': 'C'}, d)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
let d = {'a': 'A', 'b': 'B'}
call assert_fails("call extend(d, {'b': 0, 'c':'C'}, 'error')", 'E737:')
@@ -1191,7 +1191,7 @@ func Test_listdict_extend()
call extend(l, l, 3)
call assert_equal([1, 5, 7, 1, 5, 7], l)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
func Test_listdict_extendnew()
@@ -1318,30 +1318,30 @@ endfunc
" List and dict indexing tests
func Test_listdict_index()
call CheckLegacyAndVim9Failure(['echo function("min")[0]'], 'E695:')
call CheckLegacyAndVim9Failure(['echo v:true[0]'], 'E909:')
call CheckLegacyAndVim9Failure(['echo v:null[0]'], 'E909:')
call CheckLegacyAndVim9Failure(['VAR d = {"k": 10}', 'echo d.'], ['E15:', 'E1127:', 'E15:'])
call CheckLegacyAndVim9Failure(['VAR d = {"k": 10}', 'echo d[1 : 2]'], 'E719:')
call v9.CheckLegacyAndVim9Failure(['echo function("min")[0]'], 'E695:')
call v9.CheckLegacyAndVim9Failure(['echo v:true[0]'], 'E909:')
call v9.CheckLegacyAndVim9Failure(['echo v:null[0]'], 'E909:')
call v9.CheckLegacyAndVim9Failure(['VAR d = {"k": 10}', 'echo d.'], ['E15:', 'E1127:', 'E15:'])
call v9.CheckLegacyAndVim9Failure(['VAR d = {"k": 10}', 'echo d[1 : 2]'], 'E719:')
call assert_fails("let v = [4, 6][{-> 1}]", 'E729:')
call CheckDefAndScriptFailure(['var v = [4, 6][() => 1]'], ['E1012', 'E703:'])
call v9.CheckDefAndScriptFailure(['var v = [4, 6][() => 1]'], ['E1012', 'E703:'])
call CheckLegacyAndVim9Failure(['VAR v = range(5)[2 : []]'], ['E730:', 'E1012:', 'E730:'])
call v9.CheckLegacyAndVim9Failure(['VAR v = range(5)[2 : []]'], ['E730:', 'E1012:', 'E730:'])
call assert_fails("let v = range(5)[2:{-> 2}(]", ['E15:', 'E116:'])
call CheckDefAndScriptFailure(['var v = range(5)[2 : () => 2(]'], 'E15:')
call v9.CheckDefAndScriptFailure(['var v = range(5)[2 : () => 2(]'], 'E15:')
call CheckLegacyAndVim9Failure(['VAR v = range(5)[2 : 3'], ['E111:', 'E1097:', 'E111:'])
call CheckLegacyAndVim9Failure(['VAR l = insert([1, 2, 3], 4, 10)'], 'E684:')
call CheckLegacyAndVim9Failure(['VAR l = insert([1, 2, 3], 4, -10)'], 'E684:')
call CheckLegacyAndVim9Failure(['VAR l = insert([1, 2, 3], 4, [])'], ['E745:', 'E1013:', 'E1210:'])
call v9.CheckLegacyAndVim9Failure(['VAR v = range(5)[2 : 3'], ['E111:', 'E1097:', 'E111:'])
call v9.CheckLegacyAndVim9Failure(['VAR l = insert([1, 2, 3], 4, 10)'], 'E684:')
call v9.CheckLegacyAndVim9Failure(['VAR l = insert([1, 2, 3], 4, -10)'], 'E684:')
call v9.CheckLegacyAndVim9Failure(['VAR l = insert([1, 2, 3], 4, [])'], ['E745:', 'E1013:', 'E1210:'])
call CheckLegacyAndVim9Failure(['VAR l = [1, 2, 3]', 'LET l[i] = 3'], ['E121:', 'E1001:', 'E121:'])
call CheckLegacyAndVim9Failure(['VAR l = [1, 2, 3]', 'LET l[1.1] = 4'], ['E805:', 'E1012:', 'E805:'])
call CheckLegacyAndVim9Failure(['VAR l = [1, 2, 3]', 'LET l[: i] = [4, 5]'], ['E121:', 'E1001:', 'E121:'])
call CheckLegacyAndVim9Failure(['VAR l = [1, 2, 3]', 'LET l[: 3.2] = [4, 5]'], ['E805:', 'E1012:', 'E805:'])
call CheckLegacyAndVim9Failure(['VAR t = test_unknown()', 'echo t[0]'], 'E685:')
call v9.CheckLegacyAndVim9Failure(['VAR l = [1, 2, 3]', 'LET l[i] = 3'], ['E121:', 'E1001:', 'E121:'])
call v9.CheckLegacyAndVim9Failure(['VAR l = [1, 2, 3]', 'LET l[1.1] = 4'], ['E805:', 'E1012:', 'E805:'])
call v9.CheckLegacyAndVim9Failure(['VAR l = [1, 2, 3]', 'LET l[: i] = [4, 5]'], ['E121:', 'E1001:', 'E121:'])
call v9.CheckLegacyAndVim9Failure(['VAR l = [1, 2, 3]', 'LET l[: 3.2] = [4, 5]'], ['E805:', 'E1012:', 'E805:'])
call v9.CheckLegacyAndVim9Failure(['VAR t = test_unknown()', 'echo t[0]'], 'E685:')
endfunc
" Test for a null list
@@ -1379,7 +1379,7 @@ func Test_null_list()
call assert_equal([], sort(l))
call assert_equal('[]', string(l))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
let l = test_null_list()
call assert_equal([], extend(l, l, 0))
@@ -1420,7 +1420,7 @@ func Test_null_dict()
call assert_equal(0, remove(test_null_dict(), 'k'))
call assert_equal('{}', string(d))
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
let d = test_null_dict()
call assert_equal({}, extend(d, d, 'keep'))

View File

@@ -4,7 +4,7 @@ source shared.vim
source check.vim
source screendump.vim
source term_util.vim
source vim9.vim
import './vim9.vim' as v9
func Test_abbreviation()
" abbreviation with 0x80 should work
@@ -1415,7 +1415,7 @@ func Test_map_script_cmd_restore()
vim9script
nnoremap <F3> <ScriptCmd>eval 1 + 2<CR>
END
call CheckScriptSuccess(lines)
call v9.CheckScriptSuccess(lines)
call feedkeys("\<F3>:let g:result = 3+4\<CR>", 'xtc')
call assert_equal(7, g:result)
@@ -1431,7 +1431,7 @@ func Test_map_script_cmd_finds_func()
g:func_called = 'yes'
enddef
END
call CheckScriptSuccess(lines)
call v9.CheckScriptSuccess(lines)
call feedkeys("y\<F3>\<Esc>", 'xtc')
call assert_equal('yes', g:func_called)
@@ -1449,7 +1449,7 @@ func Test_map_script_cmd_survives_unmap()
feedkeys("\<F3>\<CR>", 'xct')
assert_equal(123, b:result)
END
call CheckScriptSuccess(lines)
call v9.CheckScriptSuccess(lines)
nunmap <F3>
unlet b:result

View File

@@ -3,7 +3,7 @@
source shared.vim
source check.vim
source view_util.vim
source vim9.vim
import './vim9.vim' as v9
func Setup_NewWindow()
10new
@@ -626,7 +626,7 @@ func Test_opfunc_callback()
normal! g@l
call assert_equal([23, 'char'], g:OpFunc1Args)
END
call CheckTransLegacySuccess(lines)
call v9.CheckTransLegacySuccess(lines)
" Test for using a script-local function name
func s:OpFunc3(type)
@@ -693,7 +693,7 @@ func Test_opfunc_callback()
assert_equal(['char'], g:LocalOpFuncArgs)
bw!
END
call CheckScriptSuccess(lines)
call v9.CheckScriptSuccess(lines)
" setting 'opfunc' to a script local function outside of a script context
" should fail

View File

@@ -2801,7 +2801,7 @@ def Popupwin_close_prevwin()
assert_equal(2, winnr())
var buf = term_start(&shell, {hidden: 1})
popup_create(buf, {})
TermWait(buf, 100)
g:TermWait(buf, 100)
popup_clear(true)
assert_equal(2, winnr())

View File

@@ -5,7 +5,6 @@ CheckFeature profile
source shared.vim
source screendump.vim
source vim9.vim
func Test_profile_func()
call RunProfileFunc('func', 'let', 'let')

View File

@@ -1,7 +1,7 @@
" Test for the quickfix feature.
source check.vim
source vim9.vim
import './vim9.vim' as v9
CheckFeature quickfix
source screendump.vim
@@ -5347,7 +5347,7 @@ func Test_qftextfunc_callback()
cclose
#" Test for using a lambda function with set
VAR optval = "LSTART a LMIDDLE Tqfexpr(a) LEND"
VAR optval = "LSTART a LMIDDLE g:Tqfexpr(a) LEND"
LET optval = substitute(optval, ' ', '\\ ', 'g')
exe "set qftf=" .. optval
cexpr "F6:6:6:L6"
@@ -5356,21 +5356,21 @@ func Test_qftextfunc_callback()
cclose
#" Set 'quickfixtextfunc' to a lambda expression
LET &qftf = LSTART a LMIDDLE Tqfexpr(a) LEND
LET &qftf = LSTART a LMIDDLE g:Tqfexpr(a) LEND
cexpr "F7:7:7:L7"
copen
call assert_equal('F7-L7C7-L7', getline(1))
cclose
#" Set 'quickfixtextfunc' to string(lambda_expression)
LET &qftf = "LSTART a LMIDDLE Tqfexpr(a) LEND"
LET &qftf = "LSTART a LMIDDLE g:Tqfexpr(a) LEND"
cexpr "F8:8:8:L8"
copen
call assert_equal('F8-L8C8-L8', getline(1))
cclose
#" Set 'quickfixtextfunc' to a variable with a lambda expression
VAR Lambda = LSTART a LMIDDLE Tqfexpr(a) LEND
VAR Lambda = LSTART a LMIDDLE g:Tqfexpr(a) LEND
LET &qftf = Lambda
cexpr "F9:9:9:L9"
copen
@@ -5378,14 +5378,14 @@ func Test_qftextfunc_callback()
cclose
#" Set 'quickfixtextfunc' to a string(variable with a lambda expression)
LET Lambda = LSTART a LMIDDLE Tqfexpr(a) LEND
LET Lambda = LSTART a LMIDDLE g:Tqfexpr(a) LEND
LET &qftf = string(Lambda)
cexpr "F9:9:9:L9"
copen
call assert_equal('F9-L9C9-L9', getline(1))
cclose
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" Test for using a script-local function name
func s:TqfFunc2(info)

View File

@@ -1,6 +1,6 @@
" Test 'tagfunc'
source vim9.vim
import './vim9.vim' as v9
source check.vim
source screendump.vim
@@ -200,7 +200,7 @@ func Test_tagfunc_callback()
bw!
#" Test for using a lambda function
VAR optval = "LSTART a, b, c LMIDDLE TagFunc1(16, a, b, c) LEND"
VAR optval = "LSTART a, b, c LMIDDLE g:TagFunc1(16, a, b, c) LEND"
LET optval = substitute(optval, ' ', '\\ ', 'g')
exe "set tagfunc=" .. optval
new
@@ -210,7 +210,7 @@ func Test_tagfunc_callback()
bw!
#" Set 'tagfunc' to a lambda expression
LET &tagfunc = LSTART a, b, c LMIDDLE TagFunc1(17, a, b, c) LEND
LET &tagfunc = LSTART a, b, c LMIDDLE g:TagFunc1(17, a, b, c) LEND
new
LET g:TagFunc1Args = []
call assert_fails('tag a18', 'E433:')
@@ -218,7 +218,7 @@ func Test_tagfunc_callback()
bw!
#" Set 'tagfunc' to a string(lambda expression)
LET &tagfunc = 'LSTART a, b, c LMIDDLE TagFunc1(18, a, b, c) LEND'
LET &tagfunc = 'LSTART a, b, c LMIDDLE g:TagFunc1(18, a, b, c) LEND'
new
LET g:TagFunc1Args = []
call assert_fails('tag a18', 'E433:')
@@ -226,7 +226,7 @@ func Test_tagfunc_callback()
bw!
#" Set 'tagfunc' to a variable with a lambda expression
VAR Lambda = LSTART a, b, c LMIDDLE TagFunc1(19, a, b, c) LEND
VAR Lambda = LSTART a, b, c LMIDDLE g:TagFunc1(19, a, b, c) LEND
LET &tagfunc = Lambda
new
LET g:TagFunc1Args = []
@@ -235,7 +235,7 @@ func Test_tagfunc_callback()
bw!
#" Set 'tagfunc' to a string(variable with a lambda expression)
LET Lambda = LSTART a, b, c LMIDDLE TagFunc1(20, a, b, c) LEND
LET Lambda = LSTART a, b, c LMIDDLE g:TagFunc1(20, a, b, c) LEND
LET &tagfunc = string(Lambda)
new
LET g:TagFunc1Args = []
@@ -265,7 +265,7 @@ func Test_tagfunc_callback()
call assert_equal([], g:TagFunc2Args)
bw!
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" Test for using a script-local function name
func s:TagFunc3(pat, flags, info)
@@ -380,7 +380,7 @@ func Test_tagfunc_callback()
assert_equal(['a12', '', {}], g:LocalTagFuncArgs)
bw!
END
call CheckScriptSuccess(lines)
call v9.CheckScriptSuccess(lines)
" cleanup
delfunc TagFunc1

View File

@@ -5,7 +5,7 @@ source check.vim
CheckFeature textprop
source screendump.vim
source vim9.vim
import './vim9.vim' as v9
func Test_proptype_global()
call prop_type_add('comment', {'highlight': 'Directory', 'priority': 123, 'start_incl': 1, 'end_incl': 1})
@@ -429,10 +429,10 @@ enddef
def Test_prop_remove_vim9()
new
AddPropTypes()
SetupPropsInFirstLine()
g:AddPropTypes()
g:SetupPropsInFirstLine()
assert_equal(1, prop_remove({type: 'three', id: 13, both: true, all: true}))
DeletePropTypes()
g:DeletePropTypes()
bwipe!
enddef
@@ -1704,7 +1704,7 @@ enddef
func Test_prop_list()
let lines =<< trim END
new
call AddPropTypes()
call g:AddPropTypes()
call setline(1, repeat([repeat('a', 60)], 10))
call prop_add(1, 4, {'type': 'one', 'id': 5, 'end_col': 6})
call prop_add(1, 5, {'type': 'two', 'id': 10, 'end_col': 7})
@@ -1844,10 +1844,10 @@ func Test_prop_list()
bunload! Xaaa
call assert_equal([], prop_list(1, {'bufnr': bnr, 'end_lnum': -1}))
call DeletePropTypes()
call g:DeletePropTypes()
:%bw!
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -1,6 +1,6 @@
" Tests for user defined commands
source vim9.vim
import './vim9.vim' as v9
" Test for <mods> in user defined commands
function Test_cmdmods()
@@ -287,13 +287,13 @@ func Test_CmdErrors()
vim9script
com! -complete=file DoCmd :
END
call CheckScriptFailure(lines, 'E1208', 2)
call v9.CheckScriptFailure(lines, 'E1208', 2)
let lines =<< trim END
vim9script
com! -nargs=0 -complete=file DoCmd :
END
call CheckScriptFailure(lines, 'E1208', 2)
call v9.CheckScriptFailure(lines, 'E1208', 2)
com! -nargs=0 DoCmd :
call assert_fails('DoCmd x', 'E488:')
@@ -645,7 +645,7 @@ func Test_usercmd_with_block()
command DoesNotEnd {
echo 'hello'
END
call CheckScriptFailure(lines, 'E1026:')
call v9.CheckScriptFailure(lines, 'E1026:')
let lines =<< trim END
command HelloThere {
@@ -653,7 +653,7 @@ func Test_usercmd_with_block()
}
HelloThere
END
call CheckScriptSuccess(lines)
call v9.CheckScriptSuccess(lines)
delcommand HelloThere
let lines =<< trim END
@@ -664,7 +664,7 @@ func Test_usercmd_with_block()
}
BadCommand
END
call CheckScriptFailure(lines, 'E1128:')
call v9.CheckScriptFailure(lines, 'E1128:')
endfunc
func Test_delcommand_buffer()

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
" Test commands that are not compiled in a :def function
source check.vim
source vim9.vim
import './vim9.vim' as v9
source term_util.vim
source view_util.vim
@@ -12,7 +12,7 @@ def Test_vim9cmd()
vim9c assert_equal(123, x)
vim9cm assert_equal('yes', y)
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
assert_fails('vim9cmd', 'E1164:')
assert_fails('legacy', 'E1234:')
@@ -22,7 +22,7 @@ def Test_vim9cmd()
let str = 'con'
vim9cmd str .= 'cat'
END
CheckScriptFailure(lines, 'E492:')
v9.CheckScriptFailure(lines, 'E492:')
lines =<< trim END
vim9script
@@ -30,7 +30,7 @@ def Test_vim9cmd()
legacy let str = 'con'
legacy let str .= 'cat'
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
lines =<< trim END
vim9script
@@ -39,7 +39,7 @@ def Test_vim9cmd()
enddef
nmap ,; :vim9cmd <SID>Foo()<CR>
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
feedkeys(',;', 'xt')
assert_equal("bar", g:found_bar)
@@ -50,23 +50,23 @@ def Test_vim9cmd()
vim9script
legacy echo 1'000
END
CheckScriptFailure(lines, 'E115:')
v9.CheckScriptFailure(lines, 'E115:')
if has('float')
lines =<< trim END
vim9script
echo .10
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
lines =<< trim END
vim9cmd echo .10
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
lines =<< trim END
vim9script
legacy echo .10
END
CheckScriptFailure(lines, 'E15:')
v9.CheckScriptFailure(lines, 'E15:')
endif
echo v:version
@@ -75,12 +75,12 @@ def Test_vim9cmd()
vim9script
echo version
END
CheckScriptFailure(lines, 'E121:')
v9.CheckScriptFailure(lines, 'E121:')
lines =<< trim END
vim9script
legacy echo version
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
enddef
def Test_edit_wildcards()
@@ -99,8 +99,8 @@ def Test_edit_wildcards()
edit X`=filename`xx`=filenr`yy
assert_equal('XXtestxx77yy', bufname())
CheckDefFailure(['edit `=xxx`'], 'E1001:')
CheckDefFailure(['edit `="foo"'], 'E1083:')
v9.CheckDefFailure(['edit `=xxx`'], 'E1001:')
v9.CheckDefFailure(['edit `="foo"'], 'E1083:')
var files = ['file 1', 'file%2', 'file# 3']
args `=files`
@@ -179,7 +179,7 @@ def Test_expand_alternate_file()
bwipe! altfoo
bwipe! bar
END
CheckDefAndScriptSuccess(lines)
v9.CheckDefAndScriptSuccess(lines)
enddef
def Test_global_backtick_expansion()
@@ -221,7 +221,7 @@ def Test_folddo_backtick_expansion()
enddef
call Test()
END
CheckScriptFailure(lines, 'E15: Invalid expression: "`=g:val`"')
v9.CheckScriptFailure(lines, 'E15: Invalid expression: "`=g:val`"')
enddef
def Test_hardcopy_wildcards()
@@ -257,7 +257,7 @@ def Test_echo_linebreak()
redir END
assert_equal("\nonetwo", @a)
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
lines =<< trim END
vim9script
@@ -268,7 +268,7 @@ def Test_echo_linebreak()
redir END
assert_equal("\n66", @a)
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
enddef
def Test_condition_types()
@@ -276,21 +276,21 @@ def Test_condition_types()
if 'text'
endif
END
CheckDefAndScriptFailure(lines, 'E1135:', 1)
v9.CheckDefAndScriptFailure(lines, 'E1135:', 1)
lines =<< trim END
if [1]
endif
END
CheckDefFailure(lines, 'E1012:', 1)
CheckScriptFailure(['vim9script'] + lines, 'E745:', 2)
v9.CheckDefFailure(lines, 'E1012:', 1)
v9.CheckScriptFailure(['vim9script'] + lines, 'E745:', 2)
lines =<< trim END
g:cond = 'text'
if g:cond
endif
END
CheckDefExecAndScriptFailure(lines, 'E1135:', 2)
v9.CheckDefExecAndScriptFailure(lines, 'E1135:', 2)
lines =<< trim END
g:cond = 0
@@ -298,7 +298,7 @@ def Test_condition_types()
elseif 'text'
endif
END
CheckDefAndScriptFailure(lines, 'E1135:', 3)
v9.CheckDefAndScriptFailure(lines, 'E1135:', 3)
lines =<< trim END
g:cond = 0
@@ -306,7 +306,7 @@ def Test_condition_types()
elseif 'text' garbage
endif
END
CheckDefAndScriptFailure(lines, 'E488:', 3)
v9.CheckDefAndScriptFailure(lines, 'E488:', 3)
lines =<< trim END
g:cond = 0
@@ -314,8 +314,8 @@ def Test_condition_types()
elseif [1]
endif
END
CheckDefFailure(lines, 'E1012:', 3)
CheckScriptFailure(['vim9script'] + lines, 'E745:', 4)
v9.CheckDefFailure(lines, 'E1012:', 3)
v9.CheckScriptFailure(['vim9script'] + lines, 'E745:', 4)
lines =<< trim END
g:cond = 'text'
@@ -323,28 +323,28 @@ def Test_condition_types()
elseif g:cond
endif
END
CheckDefExecAndScriptFailure(lines, 'E1135:', 3)
v9.CheckDefExecAndScriptFailure(lines, 'E1135:', 3)
lines =<< trim END
while 'text'
endwhile
END
CheckDefFailure(lines, 'E1012:', 1)
CheckScriptFailure(['vim9script'] + lines, 'E1135:', 2)
v9.CheckDefFailure(lines, 'E1012:', 1)
v9.CheckScriptFailure(['vim9script'] + lines, 'E1135:', 2)
lines =<< trim END
while [1]
endwhile
END
CheckDefFailure(lines, 'E1012:', 1)
CheckScriptFailure(['vim9script'] + lines, 'E745:', 2)
v9.CheckDefFailure(lines, 'E1012:', 1)
v9.CheckScriptFailure(['vim9script'] + lines, 'E745:', 2)
lines =<< trim END
g:cond = 'text'
while g:cond
endwhile
END
CheckDefExecAndScriptFailure(lines, 'E1135:', 2)
v9.CheckDefExecAndScriptFailure(lines, 'E1135:', 2)
enddef
def Test_if_linebreak()
@@ -357,7 +357,7 @@ def Test_if_linebreak()
endif
assert_equal(42, g:res)
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
unlet g:res
lines =<< trim END
@@ -372,7 +372,7 @@ def Test_if_linebreak()
endif
assert_equal(12, g:res)
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
unlet g:res
enddef
@@ -387,7 +387,7 @@ def Test_while_linebreak()
endwhile
assert_equal(16, nr)
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
lines =<< trim END
vim9script
@@ -403,7 +403,7 @@ def Test_while_linebreak()
endwhile
assert_equal(16, nr)
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
enddef
def Test_for_linebreak()
@@ -417,7 +417,7 @@ def Test_for_linebreak()
endfor
assert_equal(10, nr)
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
lines =<< trim END
vim9script
@@ -433,10 +433,10 @@ def Test_for_linebreak()
endfor
assert_equal(10, nr)
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
enddef
def MethodAfterLinebreak(arg: string)
def s:MethodAfterLinebreak(arg: string)
arg
->setline(1)
enddef
@@ -455,7 +455,7 @@ def Test_method_call_linebreak()
3]->RetArg()
assert_equal([1, 2, 3], res)
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
lines =<< trim END
new
@@ -466,7 +466,7 @@ def Test_method_call_linebreak()
assert_equal(['1', '2'], getline(1, 2))
bwipe!
END
CheckDefAndScriptSuccess(lines)
v9.CheckDefAndScriptSuccess(lines)
lines =<< trim END
new
@@ -484,7 +484,7 @@ def Test_method_call_linebreak()
assert_equal('the text', getline(1))
bwipe!
END
CheckDefAndScriptSuccess(lines)
v9.CheckDefAndScriptSuccess(lines)
lines =<< trim END
new
@@ -495,7 +495,7 @@ def Test_method_call_linebreak()
bwipe!
END
g:shortlist = [1, 2]
CheckDefAndScriptSuccess(lines)
v9.CheckDefAndScriptSuccess(lines)
unlet g:shortlist
new
@@ -516,7 +516,7 @@ def Test_method_call_linebreak()
Foo->Bar()
->setline(1)
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
assert_equal('# some text', getline(1))
bwipe!
enddef
@@ -532,7 +532,7 @@ def Test_method_call_whitespace()
assert_equal(['text', 'text', 'text', 'text'], getline(1, 4))
bwipe!
END
CheckDefAndScriptSuccess(lines)
v9.CheckDefAndScriptSuccess(lines)
enddef
def Test_method_and_user_command()
@@ -559,7 +559,7 @@ def Test_method_and_user_command()
enddef
InDefFunc()
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
enddef
def Test_option_use_linebreak()
@@ -575,7 +575,7 @@ def Test_option_use_linebreak()
assert_equal(['(:)', '[:]', '{:}'], getline(1, '$'))
bwipe!
END
CheckDefAndScriptSuccess(lines)
v9.CheckDefAndScriptSuccess(lines)
enddef
def Test_use_register()
@@ -591,46 +591,46 @@ def Test_use_register()
assert_equal(['one', 'two', 'three'], getline(1, '$'))
bwipe!
END
CheckDefAndScriptSuccess(lines)
v9.CheckDefAndScriptSuccess(lines)
lines =<< trim END
@a = 'echo "text"'
@a
END
CheckDefAndScriptFailure(lines, 'E1207:', 2)
v9.CheckDefAndScriptFailure(lines, 'E1207:', 2)
lines =<< trim END
@/ = 'pattern'
@/
END
CheckDefAndScriptFailure(lines, 'E1207:', 2)
v9.CheckDefAndScriptFailure(lines, 'E1207:', 2)
lines =<< trim END
&opfunc = 'nothing'
&opfunc
END
CheckDefAndScriptFailure(lines, 'E1207:', 2)
v9.CheckDefAndScriptFailure(lines, 'E1207:', 2)
&opfunc = ''
lines =<< trim END
&l:showbreak = 'nothing'
&l:showbreak
END
CheckDefAndScriptFailure(lines, 'E1207:', 2)
v9.CheckDefAndScriptFailure(lines, 'E1207:', 2)
&l:showbreak = ''
lines =<< trim END
&g:showbreak = 'nothing'
&g:showbreak
END
CheckDefAndScriptFailure(lines, 'E1207:', 2)
v9.CheckDefAndScriptFailure(lines, 'E1207:', 2)
&g:showbreak = ''
lines =<< trim END
$SomeEnv = 'value'
$SomeEnv
END
CheckDefAndScriptFailure(lines, 'E1207:', 2)
v9.CheckDefAndScriptFailure(lines, 'E1207:', 2)
$SomeEnv = ''
enddef
@@ -647,7 +647,7 @@ def Test_environment_use_linebreak()
assert_equal(['one', 'two', 'three'], getline(1, '$'))
bwipe!
END
CheckDefAndScriptSuccess(lines)
v9.CheckDefAndScriptSuccess(lines)
enddef
def Test_skipped_expr_linebreak()
@@ -671,7 +671,7 @@ def Test_dict_member()
test.data->sort()
assert_equal({data: [1, 2, 3]}, test)
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
enddef
def Test_bar_after_command()
@@ -680,14 +680,14 @@ def Test_bar_after_command()
redraw | echo x
enddef
RedrawAndEcho()
assert_match('did redraw', Screenline(&lines))
assert_match('did redraw', g:Screenline(&lines))
def CallAndEcho()
var x = 'did redraw'
reg_executing() | echo x
enddef
CallAndEcho()
assert_match('did redraw', Screenline(&lines))
assert_match('did redraw', g:Screenline(&lines))
if has('unix')
# bar in filter write command does not start new command
@@ -729,15 +729,15 @@ def Test_command_modifier_filter()
assert_equal(execute('filter /piyo/ registers abc'), expected)
END
CheckDefAndScriptSuccess(lines)
v9.CheckDefAndScriptSuccess(lines)
# also do this compiled
lines =<< trim END
@a = 'very specific z3d37dh234 string'
filter z3d37dh234 registers
assert_match('very specific z3d37dh234 string', Screenline(&lines))
assert_match('very specific z3d37dh234 string', g:Screenline(&lines))
END
CheckDefAndScriptSuccess(lines)
v9.CheckDefAndScriptSuccess(lines)
lines =<< trim END
edit foobar
@@ -747,7 +747,7 @@ def Test_command_modifier_filter()
assert_match('"foobar"', g:filter_out)
unlet g:filter_out
END
CheckDefAndScriptSuccess(lines)
v9.CheckDefAndScriptSuccess(lines)
enddef
def Test_win_command_modifiers()
@@ -930,7 +930,7 @@ def Test_bar_line_continuation()
unlet g:readExtra
unlet g:readMore
END
CheckDefAndScriptSuccess(lines)
v9.CheckDefAndScriptSuccess(lines)
enddef
def Test_command_modifier_other()
@@ -972,10 +972,10 @@ def Test_command_modifier_other()
unlet g:verbose_now
enddef
def EchoHere()
def s:EchoHere()
echomsg 'here'
enddef
def EchoThere()
def s:EchoThere()
unsilent echomsg 'there'
enddef
@@ -1009,21 +1009,21 @@ def Test_modifier_silent_unsilent()
assert_equal(11, &history)
set history&
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
enddef
def Test_range_after_command_modifier()
CheckScriptFailure(['vim9script', 'silent keepjump 1d _'], 'E1050: Colon required before a range: 1d _', 2)
v9.CheckScriptFailure(['vim9script', 'silent keepjump 1d _'], 'E1050: Colon required before a range: 1d _', 2)
new
setline(1, 'xxx')
CheckScriptSuccess(['vim9script', 'silent keepjump :1d _'])
v9.CheckScriptSuccess(['vim9script', 'silent keepjump :1d _'])
assert_equal('', getline(1))
bwipe!
var lines =<< trim END
legacy /pat/
END
CheckDefExecAndScriptFailure(lines, 'E486: Pattern not found: pat')
v9.CheckDefExecAndScriptFailure(lines, 'E486: Pattern not found: pat')
enddef
def Test_silent_pattern()
@@ -1038,50 +1038,50 @@ def Test_useless_command_modifier()
if g:maybe
silent endif
END
CheckDefAndScriptFailure(lines, 'E1176:', 2)
v9.CheckDefAndScriptFailure(lines, 'E1176:', 2)
lines =<< trim END
for i in [0]
silent endfor
END
CheckDefFailure(lines, 'E1176:', 2)
CheckScriptSuccess(['vim9script'] + lines)
v9.CheckDefFailure(lines, 'E1176:', 2)
v9.CheckScriptSuccess(['vim9script'] + lines)
lines =<< trim END
while g:maybe
silent endwhile
END
CheckDefFailure(lines, 'E1176:', 2)
v9.CheckDefFailure(lines, 'E1176:', 2)
g:maybe = false
CheckScriptSuccess(['vim9script'] + lines)
v9.CheckScriptSuccess(['vim9script'] + lines)
lines =<< trim END
silent try
finally
endtry
END
CheckDefAndScriptFailure(lines, 'E1176:', 1)
v9.CheckDefAndScriptFailure(lines, 'E1176:', 1)
lines =<< trim END
try
silent catch
endtry
END
CheckDefAndScriptFailure(lines, 'E1176:', 2)
v9.CheckDefAndScriptFailure(lines, 'E1176:', 2)
lines =<< trim END
try
silent finally
endtry
END
CheckDefAndScriptFailure(lines, 'E1176:', 2)
v9.CheckDefAndScriptFailure(lines, 'E1176:', 2)
lines =<< trim END
try
finally
silent endtry
END
CheckDefAndScriptFailure(lines, 'E1176:', 3)
v9.CheckDefAndScriptFailure(lines, 'E1176:', 3)
enddef
def Test_eval_command()
@@ -1109,7 +1109,7 @@ def Test_eval_command()
assert_equal('yes', g:caught)
unlet g:caught
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
enddef
def Test_map_command()
@@ -1117,8 +1117,8 @@ def Test_map_command()
nnoremap <F3> :echo 'hit F3 #'<CR>
assert_equal(":echo 'hit F3 #'<CR>", maparg("<F3>", "n"))
END
CheckDefSuccess(lines)
CheckScriptSuccess(['vim9script'] + lines)
v9.CheckDefSuccess(lines)
v9.CheckScriptSuccess(['vim9script'] + lines)
enddef
def Test_normal_command()
@@ -1173,7 +1173,7 @@ def Test_put_command()
bwipe!
CheckDefFailure(['put =xxx'], 'E1001:')
v9.CheckDefFailure(['put =xxx'], 'E1001:')
enddef
def Test_put_with_linebreak()
@@ -1183,7 +1183,7 @@ def Test_put_with_linebreak()
pu =split('abc', '\zs')
->join()
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
getline(2)->assert_equal('a b c')
bwipe!
enddef
@@ -1215,7 +1215,7 @@ def Test_f_args()
TestFArgs one two three
assert_equal(['one', 'two', 'three'], g:args)
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
enddef
def Test_user_command_comment()
@@ -1225,13 +1225,13 @@ def Test_user_command_comment()
vim9script
Comd # comment
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
lines =<< trim END
vim9script
Comd# comment
END
CheckScriptFailure(lines, 'E1144:')
v9.CheckScriptFailure(lines, 'E1144:')
delcommand Comd
lines =<< trim END
@@ -1239,7 +1239,7 @@ def Test_user_command_comment()
command Foo echo 'Foo'
Foo3Bar
END
CheckScriptFailure(lines, 'E1144: Command "Foo" is not followed by white space: Foo3Bar')
v9.CheckScriptFailure(lines, 'E1144: Command "Foo" is not followed by white space: Foo3Bar')
delcommand Foo
enddef
@@ -1255,7 +1255,7 @@ def Test_star_command()
set cpo-=*
assert_fails("exe '*s'", 'E1050:')
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
enddef
def Test_cmd_argument_without_colon()
@@ -1276,7 +1276,7 @@ def Test_ambiguous_user_cmd()
var lines =<< trim END
Cmd
END
CheckDefAndScriptFailure(lines, 'E464:', 1)
v9.CheckDefAndScriptFailure(lines, 'E464:', 1)
delcommand Cmd1
delcommand Cmd2
enddef
@@ -1285,12 +1285,12 @@ def Test_command_not_recognized()
var lines =<< trim END
d.key = 'asdf'
END
CheckDefFailure(lines, 'E1146:', 1)
v9.CheckDefFailure(lines, 'E1146:', 1)
lines =<< trim END
d['key'] = 'asdf'
END
CheckDefFailure(lines, 'E1146:', 1)
v9.CheckDefFailure(lines, 'E1146:', 1)
enddef
def Test_magic_not_used()
@@ -1378,7 +1378,7 @@ def Test_windo_missing_endif()
var lines =<< trim END
windo if 1
END
CheckDefExecFailure(lines, 'E171:', 1)
v9.CheckDefExecFailure(lines, 'E171:', 1)
enddef
let s:theList = [1, 2, 3]
@@ -1464,26 +1464,26 @@ def Test_lockvar()
enddef
SetList()
END
CheckScriptFailure(lines, 'E1119', 4)
v9.CheckScriptFailure(lines, 'E1119', 4)
lines =<< trim END
var theList = [1, 2, 3]
lockvar theList
END
CheckDefFailure(lines, 'E1178', 2)
v9.CheckDefFailure(lines, 'E1178', 2)
lines =<< trim END
var theList = [1, 2, 3]
unlockvar theList
END
CheckDefFailure(lines, 'E1178', 2)
v9.CheckDefFailure(lines, 'E1178', 2)
lines =<< trim END
vim9script
var name = 'john'
lockvar nameX
END
CheckScriptFailure(lines, 'E1246', 3)
v9.CheckScriptFailure(lines, 'E1246', 3)
lines =<< trim END
vim9script
@@ -1493,7 +1493,7 @@ def Test_lockvar()
enddef
LockIt()
END
CheckScriptFailure(lines, 'E1246', 1)
v9.CheckScriptFailure(lines, 'E1246', 1)
enddef
def Test_substitute_expr()
@@ -1520,8 +1520,8 @@ def Test_substitute_expr()
bwipe!
CheckDefFailure(['s/from/\="x")/'], 'E488:')
CheckDefFailure(['s/from/\="x"/9'], 'E488:')
v9.CheckDefFailure(['s/from/\="x")/'], 'E488:')
v9.CheckDefFailure(['s/from/\="x"/9'], 'E488:')
# When calling a function the right instruction list needs to be restored.
g:cond = true
@@ -1545,7 +1545,7 @@ def Test_substitute_expr()
assert_equal('rep', getline(1))
bwipe!
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
unlet g:cond
# List results in multiple lines
@@ -1594,14 +1594,14 @@ def Test_redir_to_var()
var lines =<< trim END
redir => notexist
END
CheckDefFailure(lines, 'E1089:')
v9.CheckDefFailure(lines, 'E1089:')
lines =<< trim END
var ls = 'asdf'
redir => ls[1]
redir END
END
CheckDefFailure(lines, 'E1141:')
v9.CheckDefFailure(lines, 'E1141:')
lines =<< trim END
var text: string
@@ -1610,7 +1610,7 @@ def Test_redir_to_var()
redir > Xfile
redir END
END
CheckDefFailure(lines, 'E1185:')
v9.CheckDefFailure(lines, 'E1185:')
lines =<< trim END
var text: number
@@ -1618,7 +1618,7 @@ def Test_redir_to_var()
echo 'hello'
redir END
END
CheckDefFailure(lines, 'E1012:')
v9.CheckDefFailure(lines, 'E1012:')
enddef
def Test_echo_void()
@@ -1629,7 +1629,7 @@ def Test_echo_void()
enddef
echo NoReturn()
END
CheckScriptFailure(lines, 'E1186:', 5)
v9.CheckScriptFailure(lines, 'E1186:', 5)
lines =<< trim END
vim9script
@@ -1641,7 +1641,7 @@ def Test_echo_void()
enddef
defcompile
END
CheckScriptFailure(lines, 'E1186:', 1)
v9.CheckScriptFailure(lines, 'E1186:', 1)
enddef
def Test_cmdwin_block()
@@ -1661,81 +1661,81 @@ def Test_var_not_cmd()
var lines =<< trim END
g:notexist:cmd
END
CheckDefAndScriptFailure(lines, ['E488: Trailing characters: :cmd', 'E121: Undefined variable: g:notexist'], 1)
v9.CheckDefAndScriptFailure(lines, ['E488: Trailing characters: :cmd', 'E121: Undefined variable: g:notexist'], 1)
lines =<< trim END
g-pat-cmd
END
CheckDefAndScriptFailure(lines, 'E1241:', 1)
v9.CheckDefAndScriptFailure(lines, 'E1241:', 1)
lines =<< trim END
g.pat.cmd
END
CheckDefAndScriptFailure(lines, ['E1001: Variable not found: g', 'E121: Undefined variable: g'], 1)
v9.CheckDefAndScriptFailure(lines, ['E1001: Variable not found: g', 'E121: Undefined variable: g'], 1)
lines =<< trim END
s:notexist:repl
END
CheckDefAndScriptFailure(lines, ['E488: Trailing characters: :repl', 'E121: Undefined variable: s:notexist'], 1)
v9.CheckDefAndScriptFailure(lines, ['E488: Trailing characters: :repl', 'E121: Undefined variable: s:notexist'], 1)
lines =<< trim END
s-pat-repl
END
CheckDefAndScriptFailure(lines, 'E1241:', 1)
v9.CheckDefAndScriptFailure(lines, 'E1241:', 1)
lines =<< trim END
s.pat.repl
END
CheckDefAndScriptFailure(lines, ['E1001: Variable not found: s', 'E121: Undefined variable: s'], 1)
v9.CheckDefAndScriptFailure(lines, ['E1001: Variable not found: s', 'E121: Undefined variable: s'], 1)
lines =<< trim END
w:notexist->len()
END
CheckDefExecAndScriptFailure(lines, 'E121: Undefined variable: w:notexist', 1)
v9.CheckDefExecAndScriptFailure(lines, 'E121: Undefined variable: w:notexist', 1)
lines =<< trim END
b:notexist->len()
END
CheckDefExecAndScriptFailure(lines, 'E121: Undefined variable: b:notexist', 1)
v9.CheckDefExecAndScriptFailure(lines, 'E121: Undefined variable: b:notexist', 1)
lines =<< trim END
t:notexist->len()
END
CheckDefExecAndScriptFailure(lines, 'E121: Undefined variable: t:notexist', 1)
v9.CheckDefExecAndScriptFailure(lines, 'E121: Undefined variable: t:notexist', 1)
enddef
def Test_no_space_after_command()
var lines =<< trim END
g /pat/cmd
END
CheckDefAndScriptFailure(lines, 'E1242:', 1)
v9.CheckDefAndScriptFailure(lines, 'E1242:', 1)
lines =<< trim END
g #pat#cmd
END
CheckDefAndScriptFailure(lines, 'E1242:', 1)
v9.CheckDefAndScriptFailure(lines, 'E1242:', 1)
lines =<< trim END
g#pat#cmd
END
CheckDefAndScriptSuccess(lines)
v9.CheckDefAndScriptSuccess(lines)
lines =<< trim END
g# pat#cmd
END
CheckDefAndScriptSuccess(lines)
v9.CheckDefAndScriptSuccess(lines)
lines =<< trim END
s /pat/repl
END
CheckDefAndScriptFailure(lines, 'E1242:', 1)
v9.CheckDefAndScriptFailure(lines, 'E1242:', 1)
lines =<< trim END
s #pat#repl
END
CheckDefAndScriptFailure(lines, 'E1242:', 1)
v9.CheckDefAndScriptFailure(lines, 'E1242:', 1)
lines =<< trim END
s#pat#repl
END
CheckDefExecAndScriptFailure(lines, 'E486:', 1)
v9.CheckDefExecAndScriptFailure(lines, 'E486:', 1)
lines =<< trim END
s# pat#repl
END
CheckDefExecAndScriptFailure(lines, 'E486:', 1)
v9.CheckDefExecAndScriptFailure(lines, 'E486:', 1)
enddef
" Test for the 'previewpopup' option

View File

@@ -1,9 +1,9 @@
" Test the :disassemble command, and compilation as a side effect
source check.vim
source vim9.vim
import './vim9.vim' as v9
func NotCompiled()
func s:NotCompiled()
echo "not"
endfunc
@@ -312,7 +312,7 @@ def Test_disassemble_push()
'2 RETURN void',
res)
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
delete('Xdir', 'rf')
&rtp = save_rtp
@@ -690,22 +690,22 @@ def Test_disassemble_new()
res)
enddef
def FuncWithArg(arg: any)
def s:FuncWithArg(arg: any)
echo arg
enddef
func UserFunc()
func s:UserFunc()
echo 'nothing'
endfunc
func UserFuncWithArg(arg)
func s:UserFuncWithArg(arg)
echo a:arg
endfunc
def s:ScriptFuncCall(): string
changenr()
char2nr("abc")
Test_disassemble_new()
g:Test_disassemble_new()
FuncWithArg(343)
ScriptFuncNew()
s:ScriptFuncNew()
@@ -728,12 +728,12 @@ def Test_disassemble_call()
'\d PUSHS "abc"\_s*' ..
'\d BCALL char2nr(argc 1)\_s*' ..
'\d DROP\_s*' ..
'Test_disassemble_new()\_s*' ..
'g:Test_disassemble_new()\_s*' ..
'\d DCALL Test_disassemble_new(argc 0)\_s*' ..
'\d DROP\_s*' ..
'FuncWithArg(343)\_s*' ..
'\d\+ PUSHNR 343\_s*' ..
'\d\+ DCALL FuncWithArg(argc 1)\_s*' ..
'\d\+ DCALL <SNR>\d\+_FuncWithArg(argc 1)\_s*' ..
'\d\+ DROP\_s*' ..
'ScriptFuncNew()\_s*' ..
'\d\+ DCALL <SNR>\d\+_ScriptFuncNew(argc 0)\_s*' ..
@@ -742,11 +742,11 @@ def Test_disassemble_call()
'\d\+ DCALL <SNR>\d\+_ScriptFuncNew(argc 0)\_s*' ..
'\d\+ DROP\_s*' ..
'UserFunc()\_s*' ..
'\d\+ UCALL UserFunc(argc 0)\_s*' ..
'\d\+ UCALL <80><fd>R\d\+_UserFunc(argc 0)\_s*' ..
'\d\+ DROP\_s*' ..
'UserFuncWithArg("foo")\_s*' ..
'\d\+ PUSHS "foo"\_s*' ..
'\d\+ UCALL UserFuncWithArg(argc 1)\_s*' ..
'\d\+ UCALL <80><fd>R\d\+_UserFuncWithArg(argc 1)\_s*' ..
'\d\+ DROP\_s*' ..
'var FuncRef = function("UserFunc")\_s*' ..
'\d\+ PUSHS "UserFunc"\_s*' ..
@@ -811,7 +811,7 @@ enddef
def EchoArg(arg: string): string
return arg
enddef
def RefThis(): func
def s:RefThis(): func
return function('EchoArg')
enddef
def s:ScriptPCall()
@@ -822,7 +822,7 @@ def Test_disassemble_pcall()
var res = execute('disass s:ScriptPCall')
assert_match('<SNR>\d\+_ScriptPCall\_s*' ..
'RefThis()("text")\_s*' ..
'\d DCALL RefThis(argc 0)\_s*' ..
'\d DCALL <SNR>\d\+_RefThis(argc 0)\_s*' ..
'\d PUSHS "text"\_s*' ..
'\d PCALL top (argc 1)\_s*' ..
'\d PCALL end\_s*' ..
@@ -1116,7 +1116,7 @@ def Test_disassemble_channel()
instr)
enddef
def WithLambda(): string
def s:WithLambda(): string
var F = (a) => "X" .. a .. "X"
return F("x")
enddef
@@ -1149,7 +1149,7 @@ def Test_disassemble_lambda()
instr)
enddef
def LambdaWithType(): number
def s:LambdaWithType(): number
var Ref = (a: number) => a + 10
return Ref(g:value)
enddef
@@ -1210,7 +1210,7 @@ def Test_disassemble_nested_def_list()
instr)
enddef
def AndOr(arg: any): string
def s:AndOr(arg: any): string
if arg == 1 && arg != 2 || arg == 4
return 'yes'
endif
@@ -1239,7 +1239,7 @@ def Test_disassemble_and_or()
instr)
enddef
def AndConstant(arg: any): string
def s:AndConstant(arg: any): string
if true && arg
return "yes"
endif
@@ -1271,7 +1271,7 @@ def Test_disassemble_and_constant()
instr)
enddef
def ForLoop(): list<number>
def s:ForLoop(): list<number>
var res: list<number>
for i in range(3)
res->add(i)
@@ -1304,7 +1304,7 @@ def Test_disassemble_for_loop()
instr)
enddef
def ForLoopEval(): string
def s:ForLoopEval(): string
var res = ""
for str in eval('["one", "two"]')
res ..= str
@@ -1340,7 +1340,7 @@ def Test_disassemble_for_loop_eval()
instr)
enddef
def ForLoopUnpack()
def s:ForLoopUnpack()
for [x1, x2] in [[1, 2], [3, 4]]
echo x1 x2
endfor
@@ -1373,7 +1373,7 @@ def Test_disassemble_for_loop_unpack()
instr)
enddef
def ForLoopContinue()
def s:ForLoopContinue()
for nr in [1, 2]
try
echo "ok"
@@ -1432,7 +1432,7 @@ enddef
let g:number = 42
def TypeCast()
def s:TypeCast()
var l: list<number> = [23, <number>g:number]
enddef
@@ -1450,7 +1450,7 @@ def Test_disassemble_typecast()
instr)
enddef
def Computing()
def s:Computing()
var nr = 3
var nrres = nr + 7
nrres = nr - 7
@@ -1525,7 +1525,7 @@ def Test_disassemble_computing()
endif
enddef
def AddListBlob()
def s:AddListBlob()
var reslist = [1, 2] + [3, 4]
var resblob = 0z1122 + 0z3344
enddef
@@ -1551,7 +1551,7 @@ def Test_disassemble_add_list_blob()
enddef
let g:aa = 'aa'
def ConcatString(): string
def s:ConcatString(): string
var res = g:aa .. "bb"
return res
enddef
@@ -1569,7 +1569,7 @@ def Test_disassemble_concat()
assert_equal('aabb', ConcatString())
enddef
def StringIndex(): string
def s:StringIndex(): string
var s = "abcd"
var res = s[1]
return res
@@ -1590,7 +1590,7 @@ def Test_disassemble_string_index()
assert_equal('b', StringIndex())
enddef
def StringSlice(): string
def s:StringSlice(): string
var s = "abcd"
var res = s[1 : 8]
return res
@@ -1612,7 +1612,7 @@ def Test_disassemble_string_slice()
assert_equal('bcd', StringSlice())
enddef
def ListIndex(): number
def s:ListIndex(): number
var l = [1, 2, 3]
var res = l[1]
return res
@@ -1636,7 +1636,7 @@ def Test_disassemble_list_index()
assert_equal(2, ListIndex())
enddef
def ListSlice(): list<number>
def s:ListSlice(): list<number>
var l = [1, 2, 3]
var res = l[1 : 8]
return res
@@ -1661,7 +1661,7 @@ def Test_disassemble_list_slice()
assert_equal([2, 3], ListSlice())
enddef
def DictMember(): number
def s:DictMember(): number
var d = {item: 1}
var res = d.item
res = d["item"]
@@ -1692,7 +1692,7 @@ def Test_disassemble_dict_member()
enddef
let somelist = [1, 2, 3, 4, 5]
def AnyIndex(): number
def s:AnyIndex(): number
var res = g:somelist[2]
return res
enddef
@@ -1713,7 +1713,7 @@ def Test_disassemble_any_index()
assert_equal(3, AnyIndex())
enddef
def AnySlice(): list<number>
def s:AnySlice(): list<number>
var res = g:somelist[1 : 3]
return res
enddef
@@ -1735,7 +1735,7 @@ def Test_disassemble_any_slice()
assert_equal([2, 3, 4], AnySlice())
enddef
def NegateNumber(): number
def s:NegateNumber(): number
g:nr = 9
var plus = +g:nr
var minus = -g:nr
@@ -1761,7 +1761,7 @@ def Test_disassemble_negate_number()
assert_equal(-9, NegateNumber())
enddef
def InvertBool(): bool
def s:InvertBool(): bool
var flag = true
var invert = !flag
var res = !!flag
@@ -1786,7 +1786,7 @@ def Test_disassemble_invert_bool()
assert_equal(true, InvertBool())
enddef
def ReturnBool(): bool
def s:ReturnBool(): bool
var one = 1
var zero = 0
var none: number
@@ -1818,7 +1818,7 @@ def Test_disassemble_return_bool()
assert_equal(true, InvertBool())
enddef
def AutoInit()
def s:AutoInit()
var t: number
t = 1
t = 0

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,7 @@
source check.vim
source term_util.vim
source vim9.vim
import './vim9.vim' as v9
let s:export_script_lines =<< trim END
vim9script
@@ -33,7 +33,7 @@ let s:export_script_lines =<< trim END
export var AddRef = AddSome
END
def Undo_export_script_lines()
def s:Undo_export_script_lines()
unlet g:result
unlet g:localname
enddef
@@ -411,7 +411,7 @@ def Test_import_funcref()
enddef
DoTest()
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
delete('Xlib.vim')
enddef
@@ -422,42 +422,42 @@ def Test_import_fails()
import './Xfoo.vim' as foo
foo = 'bar'
END
CheckDefAndScriptFailure(lines, ['E1094:', 'E1236: Cannot use foo itself'])
v9.CheckDefAndScriptFailure(lines, ['E1094:', 'E1236: Cannot use foo itself'])
lines =<< trim END
vim9script
import './Xfoo.vim' as foo
var that = foo
END
CheckScriptFailure(lines, 'E1060: Expected dot after name: foo')
v9.CheckScriptFailure(lines, 'E1060: Expected dot after name: foo')
lines =<< trim END
vim9script
import './Xfoo.vim' as foo
var that: any
that += foo
END
CheckScriptFailure(lines, 'E1060: Expected dot after name: foo')
v9.CheckScriptFailure(lines, 'E1060: Expected dot after name: foo')
lines =<< trim END
vim9script
import './Xfoo.vim' as foo
foo += 9
END
CheckScriptFailure(lines, 'E1060: Expected dot after name: foo')
v9.CheckScriptFailure(lines, 'E1060: Expected dot after name: foo')
lines =<< trim END
vim9script
import './Xfoo.vim' as 9foo
END
CheckScriptFailure(lines, 'E1047:')
v9.CheckScriptFailure(lines, 'E1047:')
lines =<< trim END
vim9script
import './Xfoo.vim' as the#foo
END
CheckScriptFailure(lines, 'E1047:')
v9.CheckScriptFailure(lines, 'E1047:')
lines =<< trim END
vim9script
import './Xfoo.vim' as g:foo
END
CheckScriptFailure(lines, 'E1047:')
v9.CheckScriptFailure(lines, 'E1047:')
delete('Xfoo.vim')
@@ -474,7 +474,7 @@ def Test_import_fails()
import './Xthat.vim' as That
That()
END
CheckDefAndScriptFailure(lines, ['E1094:', 'E1236: Cannot use That itself'])
v9.CheckDefAndScriptFailure(lines, ['E1094:', 'E1236: Cannot use That itself'])
lines =<< trim END
vim9script
@@ -484,13 +484,13 @@ def Test_import_fails()
enddef
Func()
END
CheckScriptFailure(lines, 'E1236: Cannot use That itself')
v9.CheckScriptFailure(lines, 'E1236: Cannot use That itself')
lines =<< trim END
import './Xthat.vim' as one
import './Xthat.vim' as two
END
CheckScriptFailure(lines, 'E1262:')
v9.CheckScriptFailure(lines, 'E1262:')
delete('Xthat.vim')
@@ -501,24 +501,24 @@ def Test_import_fails()
vim9script
import './Ximport/.vim'
END
CheckScriptFailure(lines, 'E1261: Cannot import .vim without using "as"')
v9.CheckScriptFailure(lines, 'E1261: Cannot import .vim without using "as"')
lines =<< trim END
vim9script
import './Ximport/.vim' as vim
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
writefile(['vim9script'], 'Ximport/.vimrc')
lines =<< trim END
vim9script
import './Ximport/.vimrc'
END
CheckScriptFailure(lines, 'E1257: Imported script must use "as" or end in .vim')
v9.CheckScriptFailure(lines, 'E1257: Imported script must use "as" or end in .vim')
lines =<< trim END
vim9script
import './Ximport/.vimrc' as vimrc
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
delete('Ximport', 'rf')
enddef
@@ -626,7 +626,7 @@ def Test_use_import_in_command_completion()
feedkeys(":Cmd ab\<Tab>\<C-B>#\<CR>", 'xnt')
assert_equal('#Cmd abcd', @:)
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
delcommand Cmd
delete('Xscript.vim')
@@ -665,7 +665,7 @@ def Test_use_autoload_import_in_insert_completion()
assert_equal('experiment', getline(1))
assert_equal('yes', g:completion_loaded)
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
set thesaurusfunc=
bwipe!
@@ -698,7 +698,7 @@ def Test_use_autoload_import_partial_in_opfunc()
feedkeys("\<F3>l", 'xt')
assert_equal('yes', g:opfunc_called)
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
set opfunc=
bwipe!
@@ -732,7 +732,7 @@ def Test_set_opfunc_to_autoload_func_directly()
feedkeys("\<F3>l", 'xt')
assert_equal('yes', g:opfunc_called)
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
set opfunc=
bwipe!
@@ -769,7 +769,7 @@ def Test_use_autoload_import_in_fold_expression()
new
setline(1, ['# one', 'text', '# two', 'text'])
g:fold_loaded = 'no'
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
assert_equal('no', g:fold_loaded)
redraw
assert_equal('yes', g:fold_loaded)
@@ -810,7 +810,7 @@ def Run_Test_import_in_diffexpr()
set diffexpr=diff.DiffExpr()
set diffopt=foldcolumn:0
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
enew!
call setline(1, ['one', 'two', 'three'])
@@ -842,7 +842,7 @@ def Test_import_in_patchexpr()
import './Xpatchexpr' as patch
set patchexpr=patch.TPatch()
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
call writefile(['input file'], 'Xinput')
call writefile(['diff file'], 'Xdiff')
@@ -873,7 +873,7 @@ def Test_import_in_formatexpr()
import './Xformatter' as format
set formatexpr=format.MyFormatExpr()
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
new
setline(1, ['a', 'b', 'c'])
@@ -903,7 +903,7 @@ def Test_import_in_includeexpr()
import './Xinclude.vim'
set includeexpr=Xinclude.DoSub()
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
setline(1, ['Xthatfile'])
exe "normal \<C-W>f"
@@ -931,7 +931,7 @@ def Test_import_in_indentexpr()
set indentexpr=indent.GetIndent()
set debug=throw
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
new
setline(1, 'hello')
@@ -964,7 +964,7 @@ def Run_Test_import_in_printexpr()
import './Xprint.vim'
set printexpr=Xprint.PrintFile()
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
help
hardcopy dummy args
@@ -991,7 +991,7 @@ def Test_import_in_charconvert()
import './Xconvert.vim' as conv
set charconvert=conv.MakeUpper()
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
writefile(['one', 'two'], 'Xfile')
new Xfile
@@ -1024,7 +1024,7 @@ def Run_Test_import_in_spellsuggest_expr()
import './Xsuggest.vim' as sugg
set spell spellsuggest=expr:sugg.MySuggest()
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
set verbose=1 # report errors
call assert_equal(['Fox', 'Fop'], spellsuggest('Fo', 2))
@@ -1056,7 +1056,7 @@ def Test_export_shadows_global_function()
import autoload 'shadow.vim'
assert_equal('Shadow()', shadow.Shadow())
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
delfunc g:Shadow
bwipe!
@@ -1065,9 +1065,9 @@ def Test_export_shadows_global_function()
enddef
def Test_export_fails()
CheckScriptFailure(['export var some = 123'], 'E1042:')
CheckScriptFailure(['vim9script', 'export var g:some'], 'E1022:')
CheckScriptFailure(['vim9script', 'export echo 134'], 'E1043:')
v9.CheckScriptFailure(['export var some = 123'], 'E1042:')
v9.CheckScriptFailure(['vim9script', 'export var g:some'], 'E1022:')
v9.CheckScriptFailure(['vim9script', 'export echo 134'], 'E1043:')
assert_fails('export something', 'E1043:')
enddef
@@ -1088,12 +1088,12 @@ def Run_Test_import_fails_on_command_line()
END
writefile(export, 'XexportCmd.vim')
var buf = RunVimInTerminal('-c "import Foo from ''./XexportCmd.vim''"', {
var buf = g:RunVimInTerminal('-c "import Foo from ''./XexportCmd.vim''"', {
rows: 6, wait_for_ruler: 0})
WaitForAssert(() => assert_match('^E1094:', term_getline(buf, 5)))
g:WaitForAssert(() => assert_match('^E1094:', term_getline(buf, 5)))
delete('XexportCmd.vim')
StopVimInTerminal(buf)
g:StopVimInTerminal(buf)
enddef
def Test_vim9_reload_noclear()
@@ -1348,7 +1348,7 @@ def Test_vim9_funcref_other_script()
enddef
TestDirect()
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
delete('Xfilter.vim')
enddef
@@ -1461,7 +1461,7 @@ def Test_func_overrules_import_fails()
echo 'local to function'
enddef
END
CheckScriptFailure(lines, 'E1213: Redefining imported item "Func"')
v9.CheckScriptFailure(lines, 'E1213: Redefining imported item "Func"')
lines =<< trim END
vim9script
@@ -1473,7 +1473,7 @@ def Test_func_overrules_import_fails()
enddef
defcompile
END
CheckScriptFailure(lines, 'E1236:')
v9.CheckScriptFailure(lines, 'E1236:')
delete('XexportedFunc.vim')
enddef
@@ -1696,10 +1696,10 @@ def Test_vim9script_autoload()
assert_equal('final', prefixed.fname)
assert_equal('const', prefixed.cname)
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
# can source it again, autoload script not loaded again
g:expected_loaded = 1
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
# can also get the items by autoload name
lines =<< trim END
@@ -1709,7 +1709,7 @@ def Test_vim9script_autoload()
call assert_equal('final', prefixed#fname)
call assert_equal('const', prefixed#cname)
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
unlet g:prefixed_loaded
unlet g:expected_loaded
@@ -1737,42 +1737,42 @@ def Test_import_autoload_not_exported()
import autoload 'notExport1.vim'
echo notExport1.notFound
END
CheckScriptFailure(lines, 'E1048: Item not found in script: notFound')
v9.CheckScriptFailure(lines, 'E1048: Item not found in script: notFound')
lines =<< trim END
vim9script
import autoload 'notExport1.vim'
echo notExport1.notExported
END
CheckScriptFailure(lines, 'E1049: Item not exported in script: notExported')
v9.CheckScriptFailure(lines, 'E1049: Item not exported in script: notExported')
lines =<< trim END
vim9script
import autoload 'notExport1.vim'
echo notExport1.NotFunc()
END
CheckScriptFailure(lines, 'E1048: Item not found in script: NotFunc')
v9.CheckScriptFailure(lines, 'E1048: Item not found in script: NotFunc')
lines =<< trim END
vim9script
import autoload 'notExport1.vim'
echo notExport1.NotExport()
END
CheckScriptFailure(lines, 'E1049: Item not exported in script: NotExport')
v9.CheckScriptFailure(lines, 'E1049: Item not exported in script: NotExport')
lines =<< trim END
vim9script
import autoload 'notExport1.vim'
echo 'text'->notExport1.NotFunc()
END
CheckScriptFailure(lines, 'E1048: Item not found in script: NotFunc')
v9.CheckScriptFailure(lines, 'E1048: Item not found in script: NotFunc')
lines =<< trim END
vim9script
import autoload 'notExport1.vim'
echo 'text'->notExport1.NotExport()
END
CheckScriptFailure(lines, 'E1049: Item not exported in script: NotExport')
v9.CheckScriptFailure(lines, 'E1049: Item not exported in script: NotExport')
# using a :def function we use a different autoload script every time so that
# the function is compiled without the script loaded
@@ -1785,7 +1785,7 @@ def Test_import_autoload_not_exported()
enddef
Testit()
END
CheckScriptFailure(lines, 'E1048: Item not found in script: notExport2#notFound')
v9.CheckScriptFailure(lines, 'E1048: Item not found in script: notExport2#notFound')
writefile(exportLines, 'Xdir/autoload/notExport3.vim')
lines =<< trim END
@@ -1797,7 +1797,7 @@ def Test_import_autoload_not_exported()
Testit()
END
# don't get E1049 because it is too complicated to figure out
CheckScriptFailure(lines, 'E1048: Item not found in script: notExport3#notExported')
v9.CheckScriptFailure(lines, 'E1048: Item not found in script: notExport3#notExported')
writefile(exportLines, 'Xdir/autoload/notExport4.vim')
lines =<< trim END
@@ -1808,7 +1808,7 @@ def Test_import_autoload_not_exported()
enddef
Testit()
END
CheckScriptFailure(lines, 'E117: Unknown function: notExport4#NotFunc')
v9.CheckScriptFailure(lines, 'E117: Unknown function: notExport4#NotFunc')
writefile(exportLines, 'Xdir/autoload/notExport5.vim')
lines =<< trim END
@@ -1819,7 +1819,7 @@ def Test_import_autoload_not_exported()
enddef
Testit()
END
CheckScriptFailure(lines, 'E117: Unknown function: notExport5#NotExport')
v9.CheckScriptFailure(lines, 'E117: Unknown function: notExport5#NotExport')
writefile(exportLines, 'Xdir/autoload/notExport6.vim')
lines =<< trim END
@@ -1830,7 +1830,7 @@ def Test_import_autoload_not_exported()
enddef
Testit()
END
CheckScriptFailure(lines, 'E117: Unknown function: notExport6#NotFunc')
v9.CheckScriptFailure(lines, 'E117: Unknown function: notExport6#NotFunc')
writefile(exportLines, 'Xdir/autoload/notExport7.vim')
lines =<< trim END
@@ -1841,7 +1841,7 @@ def Test_import_autoload_not_exported()
enddef
Testit()
END
CheckScriptFailure(lines, 'E117: Unknown function: notExport7#NotExport')
v9.CheckScriptFailure(lines, 'E117: Unknown function: notExport7#NotExport')
delete('Xdir', 'rf')
&rtp = save_rtp
@@ -1880,7 +1880,7 @@ def Test_vim9script_autoload_call()
assert_equal('arg', call('another.RetArg', ['arg']))
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
unlet g:result
delete('Xdir', 'rf')
@@ -2025,7 +2025,7 @@ def Test_autoload_name_wring()
enddef
END
writefile(lines, 'Xscriptname.vim')
CheckScriptFailure(lines, 'E1263:')
v9.CheckScriptFailure(lines, 'E1263:')
delete('Xscriptname.vim')
enddef
@@ -2056,9 +2056,9 @@ def Test_import_autoload_postponed()
enddef
defcompile
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
assert_false(exists('g:loaded_postponed'))
CheckScriptSuccess(lines + ['Tryit()'])
v9.CheckScriptSuccess(lines + ['Tryit()'])
assert_equal('true', g:loaded_postponed)
unlet g:loaded_postponed
@@ -2094,7 +2094,7 @@ def Test_import_autoload_override()
enddef
defcompile
END
CheckScriptFailure(lines, 'E1048: Item not found in script: doesNotExist', 1)
v9.CheckScriptFailure(lines, 'E1048: Item not found in script: doesNotExist', 1)
test_override('autoload', 0)
unlet g:loaded_override
@@ -2130,7 +2130,7 @@ def Test_autoload_mapping()
nnoremap <silent> xx <ScriptCmd>toggle.Doit()<CR>
nnoremap <silent> yy <Cmd>toggle.Doit()<CR>
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
assert_false(exists("g:toggle_loaded"))
assert_false(exists("g:toggle_called"))
assert_match('\d A: \f*[/\\]toggle.vim', execute('scriptnames'))
@@ -2159,13 +2159,13 @@ def Test_vim9script_autoload_fails()
vim9script autoload
var n = 0
END
CheckScriptFailure(lines, 'E475: Invalid argument: autoload')
v9.CheckScriptFailure(lines, 'E475: Invalid argument: autoload')
lines =<< trim END
vim9script noclear noclear
var n = 0
END
CheckScriptFailure(lines, 'E983: Duplicate argument: noclear')
v9.CheckScriptFailure(lines, 'E983: Duplicate argument: noclear')
enddef
def Test_import_autoload_fails()
@@ -2173,25 +2173,25 @@ def Test_import_autoload_fails()
vim9script
import autoload autoload 'prefixed.vim'
END
CheckScriptFailure(lines, 'E121: Undefined variable: autoload')
v9.CheckScriptFailure(lines, 'E121: Undefined variable: autoload')
lines =<< trim END
vim9script
import autoload './doesNotExist.vim'
END
CheckScriptFailure(lines, 'E1264:')
v9.CheckScriptFailure(lines, 'E1264:')
lines =<< trim END
vim9script
import autoload '/dir/doesNotExist.vim'
END
CheckScriptFailure(lines, 'E1264:')
v9.CheckScriptFailure(lines, 'E1264:')
lines =<< trim END
vim9script
import autoload 'doesNotExist.vim'
END
CheckScriptFailure(lines, 'E1053: Could not import "doesNotExist.vim"')
v9.CheckScriptFailure(lines, 'E1053: Could not import "doesNotExist.vim"')
enddef
" test disassembling an auto-loaded function starting with "debug"
@@ -2223,7 +2223,7 @@ def Test_vim9_autoload_disass()
assert_equal('profile', profileit#test())
disass profileit#test
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
delete('Xdir', 'rf')
&rtp = save_rtp
@@ -2274,7 +2274,7 @@ def Test_vim9_autoload_case_sensitive()
import autoload 'CaseSensitive.vim'
assert_equal('done', CaseSensitive.CaseSensitive())
END
CheckScriptSuccess(lines)
v9.CheckScriptSuccess(lines)
if !has('fname_case')
lines =<< trim END
@@ -2282,7 +2282,7 @@ def Test_vim9_autoload_case_sensitive()
import autoload 'CaseSensitive.vim'
import autoload 'casesensitive.vim'
END
CheckScriptFailure(lines, 'E1262:')
v9.CheckScriptFailure(lines, 'E1262:')
endif
delete('Xdir', 'rf')
@@ -2320,7 +2320,7 @@ def Test_vim9_autoload_error()
qall!
END
writefile(lines, 'Xscript')
RunVim([], [], '-S Xscript')
g:RunVim([], [], '-S Xscript')
assert_equal(['ok'], readfile('Xdidit'))
delete('Xdidit')
@@ -2331,7 +2331,7 @@ def Test_vim9_autoload_error()
vim9script
var foo#bar = 'asdf'
END
CheckScriptFailure(lines, 'E461: Illegal variable name: foo#bar', 2)
v9.CheckScriptFailure(lines, 'E461: Illegal variable name: foo#bar', 2)
enddef

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +1,12 @@
" Utility functions for testing vim9 script
vim9script
" Use a different file name for each run.
let s:sequence = 1
# Utility functions for testing vim9 script
" Check that "lines" inside a ":def" function has no error when called.
func CheckDefSuccess(lines)
# Use a different file name for each run.
var sequence = 1
# Check that "lines" inside a ":def" function has no error when called.
export func CheckDefSuccess(lines)
let cwd = getcwd()
let fname = 'XdefSuccess' .. s:sequence
let s:sequence += 1
@@ -19,8 +21,8 @@ func CheckDefSuccess(lines)
endtry
endfunc
" Check that "lines" inside a ":def" function has no error when compiled.
func CheckDefCompileSuccess(lines)
# Check that "lines" inside a ":def" function has no error when compiled.
export func CheckDefCompileSuccess(lines)
let fname = 'XdefSuccess' .. s:sequence
let s:sequence += 1
call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], fname)
@@ -32,11 +34,11 @@ func CheckDefCompileSuccess(lines)
endtry
endfunc
" Check that "lines" inside ":def" results in an "error" message.
" If "lnum" is given check that the error is reported for this line.
" Add a line before and after to make it less likely that the line number is
" accidentally correct.
func CheckDefFailure(lines, error, lnum = -3)
# Check that "lines" inside ":def" results in an "error" message.
# If "lnum" is given check that the error is reported for this line.
# Add a line before and after to make it less likely that the line number is
# accidentally correct.
export func CheckDefFailure(lines, error, lnum = -3)
let cwd = getcwd()
let fname = 'XdefFailure' .. s:sequence
let s:sequence += 1
@@ -50,11 +52,11 @@ func CheckDefFailure(lines, error, lnum = -3)
endtry
endfunc
" Check that "lines" inside ":def" results in an "error" message when executed.
" If "lnum" is given check that the error is reported for this line.
" Add a line before and after to make it less likely that the line number is
" accidentally correct.
func CheckDefExecFailure(lines, error, lnum = -3)
# Check that "lines" inside ":def" results in an "error" message when executed.
# If "lnum" is given check that the error is reported for this line.
# Add a line before and after to make it less likely that the line number is
# accidentally correct.
export func CheckDefExecFailure(lines, error, lnum = -3)
let cwd = getcwd()
let fname = 'XdefExecFailure' .. s:sequence
let s:sequence += 1
@@ -69,7 +71,7 @@ func CheckDefExecFailure(lines, error, lnum = -3)
endtry
endfunc
def CheckScriptFailure(lines: list<string>, error: string, lnum = -3)
export def CheckScriptFailure(lines: list<string>, error: string, lnum = -3)
var cwd = getcwd()
var fname = 'XScriptFailure' .. s:sequence
s:sequence += 1
@@ -82,7 +84,7 @@ def CheckScriptFailure(lines: list<string>, error: string, lnum = -3)
endtry
enddef
def CheckScriptFailureList(lines: list<string>, errors: list<string>, lnum = -3)
export def CheckScriptFailureList(lines: list<string>, errors: list<string>, lnum = -3)
var cwd = getcwd()
var fname = 'XScriptFailure' .. s:sequence
s:sequence += 1
@@ -95,7 +97,7 @@ def CheckScriptFailureList(lines: list<string>, errors: list<string>, lnum = -3)
endtry
enddef
def CheckScriptSuccess(lines: list<string>)
export def CheckScriptSuccess(lines: list<string>)
var cwd = getcwd()
var fname = 'XScriptSuccess' .. s:sequence
s:sequence += 1
@@ -108,17 +110,17 @@ def CheckScriptSuccess(lines: list<string>)
endtry
enddef
def CheckDefAndScriptSuccess(lines: list<string>)
export def CheckDefAndScriptSuccess(lines: list<string>)
CheckDefSuccess(lines)
CheckScriptSuccess(['vim9script'] + lines)
enddef
" Check that a command fails when used in a :def function and when used in
" Vim9 script.
" When "error" is a string, both with the same error.
" When "error" is a list, the :def function fails with "error[0]" , the script
" fails with "error[1]".
def CheckDefAndScriptFailure(lines: list<string>, error: any, lnum = -3)
# Check that a command fails when used in a :def function and when used in
# Vim9 script.
# When "error" is a string, both with the same error.
# When "error" is a list, the :def function fails with "error[0]" , the script
# fails with "error[1]".
export def CheckDefAndScriptFailure(lines: list<string>, error: any, lnum = -3)
var errorDef: string
var errorScript: string
if type(error) == v:t_string
@@ -135,12 +137,12 @@ def CheckDefAndScriptFailure(lines: list<string>, error: any, lnum = -3)
CheckScriptFailure(['vim9script'] + lines, errorScript, lnum + 1)
enddef
" Check that a command fails when executed in a :def function and when used in
" Vim9 script.
" When "error" is a string, both with the same error.
" When "error" is a list, the :def function fails with "error[0]" , the script
" fails with "error[1]".
def CheckDefExecAndScriptFailure(lines: list<string>, error: any, lnum = -3)
# Check that a command fails when executed in a :def function and when used in
# Vim9 script.
# When "error" is a string, both with the same error.
# When "error" is a list, the :def function fails with "error[0]" , the script
# fails with "error[1]".
export def CheckDefExecAndScriptFailure(lines: list<string>, error: any, lnum = -3)
var errorDef: string
var errorScript: string
if type(error) == v:t_string
@@ -158,8 +160,8 @@ def CheckDefExecAndScriptFailure(lines: list<string>, error: any, lnum = -3)
enddef
" Check that "lines" inside a legacy function has no error.
func CheckLegacySuccess(lines)
# Check that "lines" inside a legacy function has no error.
export func CheckLegacySuccess(lines)
let cwd = getcwd()
let fname = 'XlegacySuccess' .. s:sequence
let s:sequence += 1
@@ -174,8 +176,8 @@ func CheckLegacySuccess(lines)
endtry
endfunc
" Check that "lines" inside a legacy function results in the expected error
func CheckLegacyFailure(lines, error)
# Check that "lines" inside a legacy function results in the expected error
export func CheckLegacyFailure(lines, error)
let cwd = getcwd()
let fname = 'XlegacyFails' .. s:sequence
let s:sequence += 1
@@ -189,9 +191,9 @@ func CheckLegacyFailure(lines, error)
endtry
endfunc
" Execute "lines" in a legacy function, translated as in
" CheckLegacyAndVim9Success()
def CheckTransLegacySuccess(lines: list<string>)
# Execute "lines" in a legacy function, translated as in
# CheckLegacyAndVim9Success()
export def CheckTransLegacySuccess(lines: list<string>)
var legacylines = lines->mapnew((_, v) =>
v->substitute('\<VAR\>', 'let', 'g')
->substitute('\<LET\>', 'let', 'g')
@@ -204,7 +206,7 @@ def CheckTransLegacySuccess(lines: list<string>)
CheckLegacySuccess(legacylines)
enddef
def Vim9Trans(lines: list<string>): list<string>
export def Vim9Trans(lines: list<string>): list<string>
return lines->mapnew((_, v) =>
v->substitute('\<VAR\>', 'var', 'g')
->substitute('\<LET ', '', 'g')
@@ -215,36 +217,36 @@ def Vim9Trans(lines: list<string>): list<string>
->substitute('\<FALSE\>', 'false', 'g'))
enddef
" Execute "lines" in a :def function, translated as in
" CheckLegacyAndVim9Success()
def CheckTransDefSuccess(lines: list<string>)
# Execute "lines" in a :def function, translated as in
# CheckLegacyAndVim9Success()
export def CheckTransDefSuccess(lines: list<string>)
CheckDefSuccess(Vim9Trans(lines))
enddef
" Execute "lines" in a Vim9 script, translated as in
" CheckLegacyAndVim9Success()
def CheckTransVim9Success(lines: list<string>)
# Execute "lines" in a Vim9 script, translated as in
# CheckLegacyAndVim9Success()
export def CheckTransVim9Success(lines: list<string>)
CheckScriptSuccess(['vim9script'] + Vim9Trans(lines))
enddef
" Execute "lines" in a legacy function, :def function and Vim9 script.
" Use 'VAR' for a declaration.
" Use 'LET' for an assignment
" Use ' #"' for a comment
" Use LSTART arg LMIDDLE expr LEND for lambda
" Use 'TRUE' for 1 in legacy, true in Vim9
" Use 'FALSE' for 0 in legacy, false in Vim9
def CheckLegacyAndVim9Success(lines: list<string>)
# Execute "lines" in a legacy function, :def function and Vim9 script.
# Use 'VAR' for a declaration.
# Use 'LET' for an assignment
# Use ' #"' for a comment
# Use LSTART arg LMIDDLE expr LEND for lambda
# Use 'TRUE' for 1 in legacy, true in Vim9
# Use 'FALSE' for 0 in legacy, false in Vim9
export def CheckLegacyAndVim9Success(lines: list<string>)
CheckTransLegacySuccess(lines)
CheckTransDefSuccess(lines)
CheckTransVim9Success(lines)
enddef
" Execute "lines" in a legacy function, :def function and Vim9 script.
" Use 'VAR' for a declaration.
" Use 'LET' for an assignment
" Use ' #"' for a comment
def CheckLegacyAndVim9Failure(lines: list<string>, error: any)
# Execute "lines" in a legacy function, :def function and Vim9 script.
# Use 'VAR' for a declaration.
# Use 'LET' for an assignment
# Use ' #"' for a comment
export def CheckLegacyAndVim9Failure(lines: list<string>, error: any)
var legacyError: string
var defError: string
var scriptError: string

View File

@@ -3789,7 +3789,7 @@ trans_function_name(
sid_buf[1] = KS_EXTRA;
sid_buf[2] = (int)KE_SNR;
vim_snprintf((char *)sid_buf + 3, sizeof(sid_buf) - 3,
"%ld_", (long)current_sctx.sc_sid);
"%ld_", (long)lv.ll_sid);
name = concat_str(sid_buf, lv.ll_name);
}
*lv.ll_name_end = cc;

View File

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

View File

@@ -254,12 +254,6 @@ compile_load_scriptvar(
return FAIL;
si = SCRIPT_ITEM(current_sctx.sc_sid);
idx = get_script_item_idx(current_sctx.sc_sid, name, 0, cctx);
if (idx == -1 || si->sn_version != SCRIPT_VERSION_VIM9)
{
// variable is not in sn_var_vals: old style script.
return generate_OLDSCRIPT(cctx, ISN_LOADS, name, current_sctx.sc_sid,
&t_any);
}
if (idx >= 0)
{
svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) + idx;
@@ -344,6 +338,11 @@ compile_load_scriptvar(
return OK;
}
if (idx == -1 || si->sn_version != SCRIPT_VERSION_VIM9)
// variable is not in sn_var_vals: old style script.
return generate_OLDSCRIPT(cctx, ISN_LOADS, name, current_sctx.sc_sid,
&t_any);
if (error)
semsg(_(e_item_not_found_str), name);
return FAIL;
@@ -667,6 +666,7 @@ compile_call(
ufunc_T *ufunc = NULL;
int res = FAIL;
int is_autoload;
int has_g_namespace;
int is_searchpair;
imported_T *import;
@@ -783,6 +783,8 @@ compile_call(
goto theend;
}
has_g_namespace = STRNCMP(namebuf, "g:", 2) == 0;
// An argument or local variable can be a function reference, this
// overrules a function name.
if (lookup_local(namebuf, varlen, NULL, cctx) == FAIL
@@ -791,18 +793,28 @@ compile_call(
// If we can find the function by name generate the right call.
// Skip global functions here, a local funcref takes precedence.
ufunc = find_func(name, FALSE);
if (ufunc != NULL && !func_is_global(ufunc))
if (ufunc != NULL)
{
if (!func_is_global(ufunc))
{
res = generate_CALL(cctx, ufunc, argcount);
goto theend;
}
if (!has_g_namespace
&& vim_strchr(ufunc->uf_name, AUTOLOAD_CHAR) == NULL)
{
// A function name without g: prefix must be found locally.
semsg(_(e_unknown_function_str), namebuf);
goto theend;
}
}
}
// If the name is a variable, load it and use PCALL.
// Not for g:Func(), we don't know if it is a variable or not.
// Not for eome#Func(), it will be loaded later.
p = namebuf;
if (STRNCMP(namebuf, "g:", 2) != 0 && !is_autoload
if (!has_g_namespace && !is_autoload
&& compile_load(&p, namebuf + varlen, cctx, FALSE, FALSE) == OK)
{
type_T *type = get_type_on_stack(cctx, 0);
@@ -820,7 +832,7 @@ compile_call(
// A global function may be defined only later. Need to figure out at
// runtime. Also handles a FuncRef at runtime.
if (STRNCMP(namebuf, "g:", 2) == 0 || is_autoload)
if (has_g_namespace || is_autoload)
res = generate_UCALL(cctx, name, argcount);
else
semsg(_(e_unknown_function_str), namebuf);