diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-01-29 21:45:34 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-01-29 21:45:34 +0000 |
commit | 62aec93bfdb9e1b40d03a6d2e8e9511f8b1bdb2d (patch) | |
tree | 8f2962626c458f5ac5fa1f2ec46e79248683c81d /src/testdir/test_vim9_script.vim | |
parent | 135e15251efd96c960e51e8ab31333c2d6887983 (diff) |
patch 8.2.4257: Vim9: finding global function without g: prefix inconsistentv8.2.4257
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.
Diffstat (limited to 'src/testdir/test_vim9_script.vim')
-rw-r--r-- | src/testdir/test_vim9_script.vim | 754 |
1 files changed, 378 insertions, 376 deletions
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim index eb84c35892..d6142a695b 100644 --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -2,7 +2,7 @@ source check.vim source term_util.vim -source vim9.vim +import './vim9.vim' as v9 source screendump.vim source shared.vim @@ -18,7 +18,7 @@ def Test_vim9script_feature() # Vim9 script commands go here g:didit = true END - CheckScriptSuccess(lines) + v9.CheckScriptSuccess(lines) assert_equal(true, g:didit) unlet g:didit enddef @@ -35,20 +35,20 @@ def Test_range_only() setline(1, ['one', 'two', 'three']) :2 print - assert_equal('two', Screenline(&lines)) + assert_equal('two', g:Screenline(&lines)) :3 list - assert_equal('three$', Screenline(&lines)) + assert_equal('three$', g:Screenline(&lines)) # missing command does not print the line var lines =<< trim END vim9script :1| - assert_equal('three$', Screenline(&lines)) + assert_equal('three$', g:Screenline(&lines)) :| - assert_equal('three$', Screenline(&lines)) + assert_equal('three$', g:Screenline(&lines)) END - CheckScriptSuccess(lines) + v9.CheckScriptSuccess(lines) bwipe! @@ -64,7 +64,7 @@ let g:anumber = 123 def Test_delfunction() # Check function is defined in script namespace - CheckScriptSuccess([ + v9.CheckScriptSuccess([ 'vim9script', 'func CheckMe()', ' return 123', @@ -73,13 +73,13 @@ def Test_delfunction() ]) # Check function in script namespace cannot be deleted - CheckScriptFailure([ + v9.CheckScriptFailure([ 'vim9script', 'func DeleteMe1()', 'endfunc', 'delfunction DeleteMe1', ], 'E1084:') - CheckScriptFailure([ + v9.CheckScriptFailure([ 'vim9script', 'func DeleteMe2()', 'endfunc', @@ -88,13 +88,13 @@ def Test_delfunction() 'enddef', 'DoThat()', ], 'E1084:') - CheckScriptFailure([ + v9.CheckScriptFailure([ 'vim9script', 'def DeleteMe3()', 'enddef', 'delfunction DeleteMe3', ], 'E1084:') - CheckScriptFailure([ + v9.CheckScriptFailure([ 'vim9script', 'def DeleteMe4()', 'enddef', @@ -118,7 +118,7 @@ def Test_delfunction() delfunc g:Global assert_false(exists('*g:Global')) END - CheckScriptSuccess(lines) + v9.CheckScriptSuccess(lines) # Check that global function can be replaced by a :def function and deleted lines =<< trim END @@ -134,7 +134,7 @@ def Test_delfunction() delfunc g:Global assert_false(exists('*g:Global')) END - CheckScriptSuccess(lines) + v9.CheckScriptSuccess(lines) # Check that global :def function can be replaced by a function and deleted lines =<< trim END @@ -150,32 +150,32 @@ def Test_delfunction() delfunc g:Global assert_false(exists('*g:Global')) END - CheckScriptSuccess(lines) + v9.CheckScriptSuccess(lines) enddef def Test_wrong_type() - CheckDefFailure(['var name: list<nothing>'], 'E1010:') - CheckDefFailure(['var name: list<list<nothing>>'], 'E1010:') - CheckDefFailure(['var name: dict<nothing>'], 'E1010:') - CheckDefFailure(['var name: dict<dict<nothing>>'], 'E1010:') - - CheckDefFailure(['var name: dict<number'], 'E1009:') - CheckDefFailure(['var name: dict<list<number>'], 'E1009:') - - CheckDefFailure(['var name: ally'], 'E1010:') - CheckDefFailure(['var name: bram'], 'E1010:') - CheckDefFailure(['var name: cathy'], 'E1010:') - CheckDefFailure(['var name: dom'], 'E1010:') - CheckDefFailure(['var name: freddy'], 'E1010:') - CheckDefFailure(['var name: john'], 'E1010:') - CheckDefFailure(['var name: larry'], 'E1010:') - CheckDefFailure(['var name: ned'], 'E1010:') - CheckDefFailure(['var name: pam'], 'E1010:') - CheckDefFailure(['var name: sam'], 'E1010:') - CheckDefFailure(['var name: vim'], 'E1010:') - - CheckDefFailure(['var Ref: number', 'Ref()'], 'E1085:') - CheckDefFailure(['var Ref: string', 'var res = Ref()'], 'E1085:') + v9.CheckDefFailure(['var name: list<nothing>'], 'E1010:') + v9.CheckDefFailure(['var name: list<list<nothing>>'], 'E1010:') + v9.CheckDefFailure(['var name: dict<nothing>'], 'E1010:') + v9.CheckDefFailure(['var name: dict<dict<nothing>>'], 'E1010:') + + v9.CheckDefFailure(['var name: dict<number'], 'E1009:') + v9.CheckDefFailure(['var name: dict<list<number>'], 'E1009:') + + v9.CheckDefFailure(['var name: ally'], 'E1010:') + v9.CheckDefFailure(['var name: bram'], 'E1010:') + v9.CheckDefFailure(['var name: cathy'], 'E1010:') + v9.CheckDefFailure(['var name: dom'], 'E1010:') + v9.CheckDefFailure(['var name: freddy'], 'E1010:') + v9.CheckDefFailure(['var name: john'], 'E1010:') + v9.CheckDefFailure(['var name: larry'], 'E1010:') + v9.CheckDefFailure(['var name: ned'], 'E1010:') + v9.CheckDefFailure(['var name: pam'], 'E1010:') + v9.CheckDefFailure(['var name: sam'], 'E1010:') + v9.CheckDefFailure(['var name: vim'], 'E1010:') + + v9.CheckDefFailure(['var Ref: number', 'Ref()'], 'E1085:') + v9.CheckDefFailure(['var Ref: string', 'var res = Ref()'], 'E1085:') enddef def Test_script_wrong_type() @@ -184,15 +184,15 @@ def Test_script_wrong_type() var s:dict: dict<string> s:dict['a'] = ['x'] END - CheckScriptFailure(lines, 'E1012: Type mismatch; expected string but got list<string>', 3) + v9.CheckScriptFailure(lines, 'E1012: Type mismatch; expected string but got list<string>', 3) enddef def Test_const() - CheckDefFailure(['final name = 234', 'name = 99'], 'E1018:') - CheckDefFailure(['final one = 234', 'var one = 99'], 'E1017:') - CheckDefFailure(['final list = [1, 2]', 'var list = [3, 4]'], 'E1017:') - CheckDefFailure(['final two'], 'E1125:') - CheckDefFailure(['final &option'], 'E996:') + v9.CheckDefFailure(['final name = 234', 'name = 99'], 'E1018:') + v9.CheckDefFailure(['final one = 234', 'var one = 99'], 'E1017:') + v9.CheckDefFailure(['final list = [1, 2]', 'var list = [3, 4]'], 'E1017:') + v9.CheckDefFailure(['final two'], 'E1125:') + v9.CheckDefFailure(['final &option'], 'E996:') var lines =<< trim END final list = [1, 2, 3] @@ -217,7 +217,7 @@ def Test_const() cd['six'] = 66 constdict->assert_equal({one: 1, two: {five: 55, six: 66}, three: 3}) END - CheckDefAndScriptSuccess(lines) + v9.CheckDefAndScriptSuccess(lines) enddef def Test_const_bang() @@ -225,43 +225,43 @@ def Test_const_bang() const var = 234 var = 99 END - CheckDefExecFailure(lines, 'E1018:', 2) - CheckScriptFailure(['vim9script'] + lines, 'E46:', 3) + v9.CheckDefExecFailure(lines, 'E1018:', 2) + v9.CheckScriptFailure(['vim9script'] + lines, 'E46:', 3) lines =<< trim END const ll = [2, 3, 4] ll[0] = 99 END - CheckDefExecFailure(lines, 'E1119:', 2) - CheckScriptFailure(['vim9script'] + lines, 'E741:', 3) + v9.CheckDefExecFailure(lines, 'E1119:', 2) + v9.CheckScriptFailure(['vim9script'] + lines, 'E741:', 3) lines =<< trim END const ll = [2, 3, 4] ll[3] = 99 END - CheckDefExecFailure(lines, 'E1118:', 2) - CheckScriptFailure(['vim9script'] + lines, 'E684:', 3) + v9.CheckDefExecFailure(lines, 'E1118:', 2) + v9.CheckScriptFailure(['vim9script'] + lines, 'E684:', 3) lines =<< trim END const dd = {one: 1, two: 2} dd["one"] = 99 END - CheckDefExecFailure(lines, 'E1121:', 2) - CheckScriptFailure(['vim9script'] + lines, 'E741:', 3) + v9.CheckDefExecFailure(lines, 'E1121:', 2) + v9.CheckScriptFailure(['vim9script'] + lines, 'E741:', 3) lines =<< trim END const dd = {one: 1, two: 2} dd["three"] = 99 END - CheckDefExecFailure(lines, 'E1120:') - CheckScriptFailure(['vim9script'] + lines, 'E741:', 3) + v9.CheckDefExecFailure(lines, 'E1120:') + v9.CheckScriptFailure(['vim9script'] + lines, 'E741:', 3) enddef def Test_range_no_colon() - CheckDefFailure(['%s/a/b/'], 'E1050:') - CheckDefFailure(['+ s/a/b/'], 'E1050:') - CheckDefFailure(['- s/a/b/'], 'E1050:') - CheckDefFailure(['. s/a/b/'], 'E1050:') + v9.CheckDefFailure(['%s/a/b/'], 'E1050:') + v9.CheckDefFailure(['+ s/a/b/'], 'E1050:') + v9.CheckDefFailure(['- s/a/b/'], 'E1050:') + v9.CheckDefFailure(['. s/a/b/'], 'E1050:') enddef @@ -278,9 +278,9 @@ def Test_block() enddef def Test_block_failure() - CheckDefFailure(['{', 'var inner = 1', '}', 'echo inner'], 'E1001:') - CheckDefFailure(['}'], 'E1025:') - CheckDefFailure(['{', 'echo 1'], 'E1026:') + v9.CheckDefFailure(['{', 'var inner = 1', '}', 'echo inner'], 'E1001:') + v9.CheckDefFailure(['}'], 'E1025:') + v9.CheckDefFailure(['{', 'echo 1'], 'E1026:') enddef def Test_block_local_vars() @@ -322,7 +322,7 @@ def Test_block_local_vars() # need to execute this with a separate Vim instance to avoid the current # context gets garbage collected. writefile(lines, 'Xscript') - RunVim([], [], '-S Xscript') + g:RunVim([], [], '-S Xscript') assert_equal(['ok'], readfile('Xdidit')) delete('Xscript') @@ -345,11 +345,11 @@ def Test_block_local_vars_with_func() # "foo" and "bar" assert_equal(['foo', 'bar'], Func()) END - CheckScriptSuccess(lines) + v9.CheckScriptSuccess(lines) enddef " legacy func for command that's defined later -func InvokeSomeCommand() +func s:InvokeSomeCommand() SomeCommand endfunc @@ -557,7 +557,7 @@ def Test_try_catch_throw() assert_equal(333, n) try - l = DeletedFunc() + l = g:DeletedFunc() catch /E933:/ n = 344 endtry @@ -679,7 +679,7 @@ def Test_try_catch_throw() g:caught = v:exception endtry END - CheckScriptSuccess(lines) + v9.CheckScriptSuccess(lines) assert_match('E1219: Float or Number required for argument 1', g:caught) unlet g:caught @@ -690,7 +690,7 @@ def Test_try_catch_throw() echo 'something' endtry END - CheckScriptFailure(lines, 'E1032:') + v9.CheckScriptFailure(lines, 'E1032:') # skipping try-finally-endtry when try-finally-endtry is used in another block lines =<< trim END @@ -704,7 +704,7 @@ def Test_try_catch_throw() endtry endif END - CheckDefAndScriptSuccess(lines) + v9.CheckDefAndScriptSuccess(lines) enddef def Test_try_ends_in_return() @@ -719,7 +719,7 @@ def Test_try_ends_in_return() enddef assert_equal('foo', Foo()) END - CheckScriptSuccess(lines) + v9.CheckScriptSuccess(lines) lines =<< trim END vim9script @@ -733,7 +733,7 @@ def Test_try_ends_in_return() enddef assert_equal('foo', Foo()) END - CheckScriptFailure(lines, 'E1095:') + v9.CheckScriptFailure(lines, 'E1095:') lines =<< trim END vim9script @@ -746,7 +746,7 @@ def Test_try_ends_in_return() enddef assert_equal('foo', Foo()) END - CheckScriptFailure(lines, 'E1027:') + v9.CheckScriptFailure(lines, 'E1027:') lines =<< trim END vim9script @@ -761,7 +761,7 @@ def Test_try_ends_in_return() enddef assert_equal('done', Foo()) END - CheckScriptSuccess(lines) + v9.CheckScriptSuccess(lines) enddef @@ -799,11 +799,11 @@ def Test_error_in_catch() eval [][0] endtry END - CheckDefExecFailure(lines, 'E684:', 4) + v9.CheckDefExecFailure(lines, 'E684:', 4) enddef " :while at the very start of a function that :continue jumps to -def TryContinueFunc() +def s:TryContinueFunc() while g:Count < 2 g:sequence ..= 't' try @@ -867,7 +867,7 @@ def Test_cnext_works_in_catch() qall END writefile(lines, 'XCatchCnext') - RunVim([], [], '--clean -S XCatchCnext') + g:RunVim([], [], '--clean -S XCatchCnext') assert_equal(['1'], readfile('Xresult')) delete('Xfile1') @@ -901,19 +901,19 @@ enddef defcompile delfunc DeletedFunc -def ThrowFromDef() +def s:ThrowFromDef() throw "getout" # comment enddef -func CatchInFunc() +func s:CatchInFunc() try - call ThrowFromDef() + call s:ThrowFromDef() catch let g:thrown_func = v:exception endtry endfunc -def CatchInDef() +def s:CatchInDef() try ThrowFromDef() catch @@ -921,7 +921,7 @@ def CatchInDef() endtry enddef -def ReturnFinally(): string +def s:ReturnFinally(): string try return 'intry' finall @@ -984,7 +984,7 @@ def Test_try_catch_nested() assert_equal(['1', '2', '3', '4'], l) enddef -def TryOne(): number +def s:TryOne(): number try return 0 catch @@ -992,7 +992,7 @@ def TryOne(): number return 0 enddef -def TryTwo(n: number): string +def s:TryTwo(n: number): string try var x = {} catch @@ -1023,19 +1023,19 @@ def Test_try_catch_match() enddef def Test_try_catch_fails() - CheckDefFailure(['catch'], 'E603:') - CheckDefFailure(['try', 'echo 0', 'catch', 'catch'], 'E1033:') - CheckDefFailure(['try', 'echo 0', 'catch /pat'], 'E1067:') - CheckDefFailure(['finally'], 'E606:') - CheckDefFailure(['try', 'echo 0', 'finally', 'echo 1', 'finally'], 'E607:') - CheckDefFailure(['endtry'], 'E602:') - CheckDefFailure(['while 1', 'endtry'], 'E170:') - CheckDefFailure(['for i in range(5)', 'endtry'], 'E170:') - CheckDefFailure(['if 1', 'endtry'], 'E171:') - CheckDefFailure(['try', 'echo 1', 'endtry'], 'E1032:') + v9.CheckDefFailure(['catch'], 'E603:') + v9.CheckDefFailure(['try', 'echo 0', 'catch', 'catch'], 'E1033:') + v9.CheckDefFailure(['try', 'echo 0', 'catch /pat'], 'E1067:') + v9.CheckDefFailure(['finally'], 'E606:') + v9.CheckDefFailure(['try', 'echo 0', 'finally', 'echo 1', 'finally'], 'E607:') + v9.CheckDefFailure(['endtry'], 'E602:') + v9.CheckDefFailure(['while 1', 'endtry'], 'E170:') + v9.CheckDefFailure(['for i in range(5)', 'endtry'], 'E170:') + v9.CheckDefFailure(['if 1', 'endtry'], 'E171:') + v9.CheckDefFailure(['try', 'echo 1', 'endtry'], 'E1032:') - CheckDefFailure(['throw'], 'E1143:') - CheckDefFailure(['throw xxx'], 'E1001:') + v9.CheckDefFailure(['throw'], 'E1143:') + v9.CheckDefFailure(['throw xxx'], 'E1001:') enddef def Try_catch_skipped() @@ -1070,7 +1070,7 @@ def Test_throw_vimscript() assert_equal('onetwo', v:exception) endtry END - CheckScriptSuccess(lines) + v9.CheckScriptSuccess(lines) lines =<< trim END vim9script @@ -1086,7 +1086,7 @@ def Test_throw_vimscript() endtry assert_equal('caught', result) END - CheckScriptSuccess(lines) + v9.CheckScriptSuccess(lines) enddef def Test_error_in_nested_function() @@ -1103,7 +1103,7 @@ def Test_error_in_nested_function() Func() END g:test_var = 0 - CheckScriptFailure(lines, 'E684:') + v9.CheckScriptFailure(lines, 'E684:') assert_equal(0, g:test_var) enddef @@ -1116,7 +1116,7 @@ def Test_abort_after_error() g:gotthere = true END g:gotthere = false - CheckScriptFailure(lines, 'E121:') + v9.CheckScriptFailure(lines, 'E121:') assert_false(g:gotthere) unlet g:gotthere enddef @@ -1131,7 +1131,7 @@ def Test_cexpr_vimscript() ' line 19' assert_equal(19, getqflist()[0].lnum) END - CheckScriptSuccess(lines) + v9.CheckScriptSuccess(lines) set errorformat& enddef @@ -1146,7 +1146,7 @@ def Test_statusline_syntax() redrawstatus set laststatus statusline= END - CheckScriptSuccess(lines) + v9.CheckScriptSuccess(lines) enddef def Test_list_vimscript() @@ -1162,7 +1162,7 @@ def Test_list_vimscript() ] assert_equal(['one', 'two', 'three'], mylist) END - CheckScriptSuccess(lines) + v9.CheckScriptSuccess(lines) # check all lines from heredoc are kept lines =<< trim END @@ -1179,7 +1179,7 @@ def Test_list_vimscript() [{ a: 0}]->string()->assert_equal("[{'a': 0}]") END - CheckDefAndScriptSuccess(lines) + v9.CheckDefAndScriptSuccess(lines) enddef if has('channel') @@ -1210,21 +1210,21 @@ def Test_vim9script_mix() END g:feature = 'eval' g:legacy = -1 - CheckScriptSuccess(lines) + v9.CheckScriptSuccess(lines) assert_equal(1, g:legacy) g:feature = 'noteval' g:legacy = -1 - CheckScriptSuccess(lines) + v9.CheckScriptSuccess(lines) assert_equal(0, g:legacy) enddef def Test_vim9script_fails() - CheckScriptFailure(['scriptversion 2', 'vim9script'], 'E1039:') - CheckScriptFailure(['vim9script', 'scriptversion 2'], 'E1040:') + v9.CheckScriptFailure(['scriptversion 2', 'vim9script'], 'E1039:') + v9.CheckScriptFailure(['vim9script', 'scriptversion 2'], 'E1040:') - CheckScriptFailure(['vim9script', 'var str: string', 'str = 1234'], 'E1012:') - CheckScriptFailure(['vim9script', 'const str = "asdf"', 'str = "xxx"'], 'E46:') + v9.CheckScriptFailure(['vim9script', 'var str: string', 'str = 1234'], 'E1012:') + v9.CheckScriptFailure(['vim9script', 'const str = "asdf"', 'str = "xxx"'], 'E46:') assert_fails('vim9script', 'E1038:') enddef @@ -1237,7 +1237,7 @@ def Test_script_var_shadows_function() enddef var Func = 1 END - CheckScriptFailure(lines, 'E1041:', 5) + v9.CheckScriptFailure(lines, 'E1041:', 5) enddef def Test_function_shadows_script_var() @@ -1248,7 +1248,7 @@ def Test_function_shadows_script_var() return 123 enddef END - CheckScriptFailure(lines, 'E1041:', 3) + v9.CheckScriptFailure(lines, 'E1041:', 3) enddef def Test_script_var_shadows_command() @@ -1257,13 +1257,13 @@ def Test_script_var_shadows_command() undo = 2 assert_equal(2, undo) END - CheckDefAndScriptSuccess(lines) + v9.CheckDefAndScriptSuccess(lines) lines =<< trim END var undo = 1 undo END - CheckDefAndScriptFailure(lines, 'E1207:', 2) + v9.CheckDefAndScriptFailure(lines, 'E1207:', 2) enddef def Test_vim9script_call_wrong_type() @@ -1272,7 +1272,7 @@ def Test_vim9script_call_wrong_type() var Time = 'localtime' Time() END - CheckScriptFailure(lines, 'E1085:') + v9.CheckScriptFailure(lines, 'E1085:') enddef def Test_vim9script_reload_delfunc() @@ -1371,7 +1371,7 @@ def Test_func_redefine_fails() echo 'two' enddef END - CheckScriptFailure(lines, 'E1073:') + v9.CheckScriptFailure(lines, 'E1073:') lines =<< trim END vim9script @@ -1383,7 +1383,7 @@ def Test_func_redefine_fails() enddef defcompile END - CheckScriptFailure(lines, 'E1073:') + v9.CheckScriptFailure(lines, 'E1073:') enddef def Test_fixed_size_list() @@ -1396,26 +1396,26 @@ def Test_fixed_size_list() enddef def Test_no_insert_xit() - CheckDefExecFailure(['a = 1'], 'E1100:') - CheckDefExecFailure(['c = 1'], 'E1100:') - CheckDefExecFailure(['i = 1'], 'E1100:') - CheckDefExecFailure(['t = 1'], 'E1100:') - CheckDefExecFailure(['x = 1'], 'E1100:') - - CheckScriptFailure(['vim9script', 'a = 1'], 'E488:') - CheckScriptFailure(['vim9script', 'a'], 'E1100:') - CheckScriptFailure(['vim9script', 'c = 1'], 'E488:') - CheckScriptFailure(['vim9script', 'c'], 'E1100:') - CheckScriptFailure(['vim9script', 'i = 1'], 'E488:') - CheckScriptFailure(['vim9script', 'i'], 'E1100:') - CheckScriptFailure(['vim9script', 'o = 1'], 'E1100:') - CheckScriptFailure(['vim9script', 'o'], 'E1100:') - CheckScriptFailure(['vim9script', 't'], 'E1100:') - CheckScriptFailure(['vim9script', 't = 1'], 'E1100:') - CheckScriptFailure(['vim9script', 'x = 1'], 'E1100:') -enddef - -def IfElse(what: number): string + v9.CheckDefExecFailure(['a = 1'], 'E1100:') + v9.CheckDefExecFailure(['c = 1'], 'E1100:') + v9.CheckDefExecFailure(['i = 1'], 'E1100:') + v9.CheckDefExecFailure(['t = 1'], 'E1100:') + v9.CheckDefExecFailure(['x = 1'], 'E1100:') + + v9.CheckScriptFailure(['vim9script', 'a = 1'], 'E488:') + v9.CheckScriptFailure(['vim9script', 'a'], 'E1100:') + v9.CheckScriptFailure(['vim9script', 'c = 1'], 'E488:') + v9.CheckScriptFailure(['vim9script', 'c'], 'E1100:') + v9.CheckScriptFailure(['vim9script', 'i = 1'], 'E488:') + v9.CheckScriptFailure(['vim9script', 'i'], 'E1100:') + v9.CheckScriptFailure(['vim9script', 'o = 1'], 'E1100:') + v9.CheckScriptFailure(['vim9script', 'o'], 'E1100:') + v9.CheckScriptFailure(['vim9script', 't'], 'E1100:') + v9.CheckScriptFailure(['vim9script', 't = 1'], 'E1100:') + v9.CheckScriptFailure(['vim9script', 'x = 1'], 'E1100:') +enddef + +def s:IfElse(what: number): string var res = '' if what == 1 res = "one" @@ -1434,18 +1434,18 @@ def Test_if_elseif_else() enddef def Test_if_elseif_else_fails() - CheckDefFailure(['elseif true'], 'E582:') - CheckDefFailure(['else'], 'E581:') - CheckDefFailure(['endif'], 'E580:') - CheckDefFailure(['if g:abool', 'elseif xxx'], 'E1001:') - CheckDefFailure(['if true', 'echo 1'], 'E171:') + v9.CheckDefFailure(['elseif true'], 'E582:') + v9.CheckDefFailure(['else'], 'E581:') + v9.CheckDefFailure(['endif'], 'E580:') + v9.CheckDefFailure(['if g:abool', 'elseif xxx'], 'E1001:') + v9.CheckDefFailure(['if true', 'echo 1'], 'E171:') var lines =<< trim END var s = '' if s = '' endif END - CheckDefFailure(lines, 'E488:') + v9.CheckDefFailure(lines, 'E488:') lines =<< trim END var s = '' @@ -1453,7 +1453,7 @@ def Test_if_elseif_else_fails() elseif s = '' endif END - CheckDefFailure(lines, 'E488:') + v9.CheckDefFailure(lines, 'E488:') enddef let g:bool_true = v:true @@ -1590,13 +1590,13 @@ def Test_if_const_expr() enddef def Test_if_const_expr_fails() - CheckDefFailure(['if "aaa" == "bbb'], 'E114:') - CheckDefFailure(["if 'aaa' == 'bbb"], 'E115:') - CheckDefFailure(["if has('aaa'"], 'E110:') - CheckDefFailure(["if has('aaa') ? true false"], 'E109:') + v9.CheckDefFailure(['if "aaa" == "bbb'], 'E114:') + v9.CheckDefFailure(["if 'aaa' == 'bbb"], 'E115:') + v9.CheckDefFailure(["if has('aaa'"], 'E110:') + v9.CheckDefFailure(["if has('aaa') ? true false"], 'E109:') enddef -def RunNested(i: number): number +def s:RunNested(i: number): number var x: number = 0 if i % 2 if 1 @@ -1645,14 +1645,14 @@ def Test_execute_cmd() var n = true execute 'echomsg' (n ? '"true"' : '"no"') - assert_match('^true$', Screenline(&lines)) + assert_match('^true$', g:Screenline(&lines)) echomsg [1, 2, 3] {a: 1, b: 2} - assert_match('^\[1, 2, 3\] {''a'': 1, ''b'': 2}$', Screenline(&lines)) + assert_match('^\[1, 2, 3\] {''a'': 1, ''b'': 2}$', g:Screenline(&lines)) - CheckDefFailure(['execute xxx'], 'E1001:', 1) - CheckDefExecFailure(['execute "tabnext " .. 8'], 'E475:', 1) - CheckDefFailure(['execute "cmd"# comment'], 'E488:', 1) + v9.CheckDefFailure(['execute xxx'], 'E1001:', 1) + v9.CheckDefExecFailure(['execute "tabnext " .. 8'], 'E475:', 1) + v9.CheckDefFailure(['execute "cmd"# comment'], 'E488:', 1) enddef def Test_execute_cmd_vimscript() @@ -1665,34 +1665,34 @@ def Test_execute_cmd_vimscript() assert_equal(28, g:someVar) unlet g:someVar END - CheckScriptSuccess(lines) + v9.CheckScriptSuccess(lines) enddef def Test_echo_cmd() echo 'some' # comment echon 'thing' - assert_match('^something$', Screenline(&lines)) + assert_match('^something$', g:Screenline(&lines)) echo "some" # comment echon "thing" - assert_match('^something$', Screenline(&lines)) + assert_match('^something$', g:Screenline(&lines)) var str1 = 'some' var str2 = 'more' echo str1 str2 - assert_match('^some more$', Screenline(&lines)) + assert_match('^some more$', g:Screenline(&lines)) - CheckDefFailure(['echo "xxx"# comment'], 'E488:') + v9.CheckDefFailure(['echo "xxx"# comment'], 'E488:') enddef def Test_echomsg_cmd() echomsg 'some' 'more' # comment - assert_match('^some more$', Screenline(&lines)) + assert_match('^some more$', g:Screenline(&lines)) echo 'clear' :1messages - assert_match('^some more$', Screenline(&lines)) + assert_match('^some more$', g:Screenline(&lines)) - CheckDefFailure(['echomsg "xxx"# comment'], 'E488:') + v9.CheckDefFailure(['echomsg "xxx"# comment'], 'E488:') enddef def Test_echomsg_cmd_vimscript() @@ -1702,9 +1702,9 @@ def Test_echomsg_cmd_vimscript() echomsg 'here' .. ' is ' .. 'a message' - assert_match('^here is a message$', Screenline(&lines)) + assert_match('^here is a message$', g:Screenline(&lines)) END - CheckScriptSuccess(lines) + v9.CheckScriptSuccess(lines) enddef def Test_echoerr_cmd() @@ -1728,7 +1728,7 @@ def Test_echoerr_cmd_vimscript() assert_match('this is wrong', v:exception) endtry END - CheckScriptSuccess(lines) + v9.CheckScriptSuccess(lines) enddef def Test_echoconsole_cmd() @@ -1786,7 +1786,7 @@ def Test_for_skipped_block() endif assert_equal([3, 4], result) END - CheckDefAndScriptSuccess(lines) + v9.CheckDefAndScriptSuccess(lines) # test skipped blocks at inside of function lines =<< trim END @@ -1820,7 +1820,7 @@ def Test_for_skipped_block() enddef DefFalse() END - CheckDefAndScriptSuccess(lines) + v9.CheckDefAndScriptSuccess(lines) enddef def Test_for_loop() @@ -1931,7 +1931,7 @@ def Test_for_loop() endfor assert_equal(['x', 'x', 'x'], reslist) END - CheckDefAndScriptSuccess(lines) + v9.CheckDefAndScriptSuccess(lines) enddef def Test_for_loop_with_closure() @@ -1945,7 +1945,7 @@ def Test_for_loop_with_closure() assert_equal(4, flist[i]()) endfor END - CheckDefAndScriptSuccess(lines) + v9.CheckDefAndScriptSuccess(lines) lines =<< trim END var flist: list<func> @@ -1959,29 +1959,29 @@ def Test_for_loop_with_closure() assert_equal(4, flist[i]()) endfor END - CheckDefAndScriptSuccess(lines) + v9.CheckDefAndScriptSuccess(lines) enddef def Test_for_loop_fails() - CheckDefAndScriptFailure(['for '], ['E1097:', 'E690:']) - CheckDefAndScriptFailure(['for x'], ['E1097:', 'E690:']) - CheckDefAndScriptFailure(['for x in'], ['E1097:', 'E15:']) - CheckDefAndScriptFailure(['for # in range(5)'], 'E690:') - CheckDefAndScriptFailure(['for i In range(5)'], 'E690:') - CheckDefAndScriptFailure(['var x = 5', 'for x in range(5)', 'endfor'], ['E1017:', 'E1041:']) - CheckScriptFailure(['vim9script', 'var x = 5', 'for x in range(5)', '# comment', 'endfor'], 'E1041:', 3) - CheckScriptFailure(['def Func(arg: any)', 'for arg in range(5)', 'enddef', 'defcompile'], 'E1006:') + v9.CheckDefAndScriptFailure(['for '], ['E1097:', 'E690:']) + v9.CheckDefAndScriptFailure(['for x'], ['E1097:', 'E690:']) + v9.CheckDefAndScriptFailure(['for x in'], ['E1097:', 'E15:']) + v9.CheckDefAndScriptFailure(['for # in range(5)'], 'E690:') + v9.CheckDefAndScriptFailure(['for i In range(5)'], 'E690:') + v9.CheckDefAndScriptFailure(['var x = 5', 'for x in range(5)', 'endfor'], ['E1017:', 'E1041:']) + v9.CheckScriptFailure(['vim9script', 'var x = 5', 'for x in range(5)', '# comment', 'endfor'], 'E1041:', 3) + v9.CheckScriptFailure(['def Func(arg: any)', 'for arg in range(5)', 'enddef', 'defcompile'], 'E1006:') delfunc! g:Func - CheckDefFailure(['for i in xxx'], 'E1001:') - CheckDefFailure(['endfor'], 'E588:') - CheckDefFailure(['for i in range(3)', 'echo 3'], 'E170:') + v9.CheckDefFailure(['for i in xxx'], 'E1001:') + v9.CheckDefFailure(['endfor'], 'E588:') + v9.CheckDefFailure(['for i in range(3)', 'echo 3'], 'E170:') # wrong type detected at compile time - CheckDefFailure(['for i in {a: 1}', 'echo 3', 'endfor'], 'E1177: For loop on dict not supported') + v9.CheckDefFailure(['for i in {a: 1}', 'echo 3', 'endfor'], 'E1177: For loop on dict not supported') # wrong type detected at runtime g:adict = {a: 1} - CheckDefExecFailure(['for i in g:adict', 'echo 3', 'endfor'], 'E1177: For loop on dict not supported') + v9.CheckDefExecFailure(['for i in g:adict', 'echo 3', 'endfor'], 'E1177: For loop on dict not supported') unlet g:adict var lines =<< trim END @@ -1990,20 +1990,20 @@ def Test_for_loop_fails() e = {a: 0, b: ''} endfor END - CheckDefAndScriptFailure(lines, ['E1018:', 'E46:'], 3) + v9.CheckDefAndScriptFailure(lines, ['E1018:', 'E46:'], 3) lines =<< trim END for nr: number in ['foo'] endfor END - CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got string', 1) + v9.CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got string', 1) lines =<< trim END for n : number in [1, 2] echo n endfor END - CheckDefAndScriptFailure(lines, 'E1059:', 1) + v9.CheckDefAndScriptFailure(lines, 'E1059:', 1) lines =<< trim END var d: dict<number> = {a: 1, b: 2} @@ -2011,7 +2011,7 @@ def Test_for_loop_fails() echo k v endfor END - CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected job but got string', 2) + v9.CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected job but got string', 2) lines =<< trim END var i = 0 @@ -2019,7 +2019,7 @@ def Test_for_loop_fails() echo i endfor END - CheckDefExecAndScriptFailure(lines, ['E1017:', 'E1041:']) + v9.CheckDefExecAndScriptFailure(lines, ['E1017:', 'E1041:']) lines =<< trim END var l = [0] @@ -2027,7 +2027,7 @@ def Test_for_loop_fails() echo l[0] endfor END - CheckDefExecAndScriptFailure(lines, ['E461:', 'E1017:']) + v9.CheckDefExecAndScriptFailure(lines, ['E461:', 'E1017:']) lines =<< trim END var d = {x: 0} @@ -2035,12 +2035,12 @@ def Test_for_loop_fails() echo d.x endfor END - CheckDefExecAndScriptFailure(lines, ['E461:', 'E1017:']) + v9.CheckDefExecAndScriptFailure(lines, ['E461:', 'E1017:']) enddef def Test_for_loop_script_var() # cannot use s:var in a :def function - CheckDefFailure(['for s:var in range(3)', 'echo 3'], 'E1254:') + v9.CheckDefFailure(['for s:var in range(3)', 'echo 3'], 'E1254:') # can use s:var in Vim9 script, with or without s: var lines =<< trim END @@ -2107,28 +2107,28 @@ def Test_for_loop_unpack() endfor assert_equal([2, 5], res) END - CheckDefAndScriptSuccess(lines) + v9.CheckDefAndScriptSuccess(lines) lines =<< trim END for [v1, v2] in [[1, 2, 3], [3, 4]] echo v1 v2 endfor END - CheckDefExecFailure(lines, 'E710:', 1) + v9.CheckDefExecFailure(lines, 'E710:', 1) lines =<< trim END for [v1, v2] in [[1], [3, 4]] echo v1 v2 endfor END - CheckDefExecFailure(lines, 'E711:', 1) + v9.CheckDefExecFailure(lines, 'E711:', 1) lines =<< trim END for [v1, v1] in [[1, 2], [3, 4]] echo v1 endfor END - CheckDefExecFailure(lines, 'E1017:', 1) + v9.CheckDefExecFailure(lines, 'E1017:', 1) enddef def Test_for_loop_with_try_continue() @@ -2148,7 +2148,7 @@ def Test_for_loop_with_try_continue() assert_equal(3, looped) assert_equal(3, cleanup) END - CheckDefAndScriptSuccess(lines) + v9.CheckDefAndScriptSuccess(lines) enddef def Test_while_skipped_block() @@ -2187,7 +2187,7 @@ def Test_while_skipped_block() endif assert_equal([3, 4], result) END - CheckDefAndScriptSuccess(lines) + v9.CheckDefAndScriptSuccess(lines) # test skipped blocks at inside of function lines =<< trim END @@ -2231,7 +2231,7 @@ def Test_while_skipped_block() enddef DefFalse() END - CheckDefAndScriptSuccess(lines) + v9.CheckDefAndScriptSuccess(lines) enddef def Test_while_loop() @@ -2266,24 +2266,24 @@ def Test_while_loop_in_script() endwhile assert_equal('v0v1v2', result) END - CheckScriptSuccess(lines) + v9.CheckScriptSuccess(lines) enddef def Test_while_loop_fails() - CheckDefFailure(['while xxx'], 'E1001:') - CheckDefFailure(['endwhile'], 'E588:') - CheckDefFailure(['continue'], 'E586:') - CheckDefFailure(['if true', 'continue'], 'E586:') - CheckDefFailure(['break'], 'E587:') - CheckDefFailure(['if true', 'break'], 'E587:') - CheckDefFailure(['while 1', 'echo 3'], 'E170:') + v9.CheckDefFailure(['while xxx'], 'E1001:') + v9.CheckDefFailure(['endwhile'], 'E588:') + v9.CheckDefFailure(['continue'], 'E586:') + v9.CheckDefFailure(['if true', 'continue'], 'E586:') + v9.CheckDefFailure(['break'], 'E587:') + v9.CheckDefFailure(['if true', 'break'], 'E587:') + v9.CheckDefFailure(['while 1', 'echo 3'], 'E170:') var lines =<< trim END var s = '' while s = '' endwhile END - CheckDefFailure(lines, 'E488:') + v9.CheckDefFailure(lines, 'E488:') enddef def Test_interrupt_loop() @@ -2342,7 +2342,7 @@ def Test_automatic_line_continuation() enddef def Test_vim9_comment() - CheckScriptSuccess([ + v9.CheckScriptSuccess([ 'vim9script', '# something', '#something', @@ -2350,126 +2350,126 @@ def Test_vim9_comment() ]) split Xfile - CheckScriptSuccess([ + v9.CheckScriptSuccess([ 'vim9script', 'edit #something', ]) - CheckScriptSuccess([ + v9.CheckScriptSuccess([ 'vim9script', 'edit #{something', ]) close - CheckScriptFailure([ + v9.CheckScriptFailure([ 'vim9script', ':# something', ], 'E488:') - CheckScriptFailure([ + v9.CheckScriptFailure([ '# something', ], 'E488:') - CheckScriptFailure([ + v9.CheckScriptFailure([ ':# something', ], 'E488:') { # block start } # block end - CheckDefFailure([ + v9.Chec |