diff options
Diffstat (limited to 'src/testdir/test_vim9_script.vim')
-rw-r--r-- | src/testdir/test_vim9_script.vim | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim index 3ac106eaaf..0b17150094 100644 --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -2159,6 +2159,18 @@ def Test_echo_cmd() assert_match('^two$', g:Screenline(&lines)) v9.CheckDefFailure(['echo "xxx"# comment'], 'E488:') + + # Test for echoing a script local function name + var lines =<< trim END + vim9script + def ScriptLocalEcho() + enddef + echo ScriptLocalEcho + END + new + setline(1, lines) + assert_match('<SNR>\d\+_ScriptLocalEcho', execute('source')->split("\n")[0]) + bw! enddef def Test_echomsg_cmd() @@ -2510,8 +2522,20 @@ def Test_for_loop() reslist->add('x') endfor assert_equal(['x', 'x', 'x'], reslist) + + # Test for trying to use the loop variable "_" inside the loop + for _ in "a" + assert_fails('echo _', 'E1181: Cannot use an underscore here') + endfor END v9.CheckDefAndScriptSuccess(lines) + + lines =<< trim END + for i : number : [1, 2] + echo i + endfor + END + v9.CheckSourceDefAndScriptFailure(lines, 'E1059: No white space allowed before colon: : [1, 2]', 1) enddef def Test_for_loop_list_of_lists() @@ -5002,7 +5026,7 @@ def Test_invalid_type_in_for() enddef defcompile END - v9.CheckSourceFailure(lines, 'E1010: Type not recognized: x in range(10)', 1) + v9.CheckSourceFailure(lines, 'E1010: Type not recognized: x', 1) enddef " Test for using a line break between the variable name and the type in a for @@ -5083,6 +5107,28 @@ def Test_null_values() v9.CheckSourceDefAndScriptSuccess(lines) enddef +" Test for using an unknown type in a typecast +def Test_unknown_type_in_typecast() + var lines =<< trim END + vim9script + var a = <MyType>b + END + v9.CheckSourceFailure(lines, 'E1010: Type not recognized: MyType', 2) + + lines =<< trim END + vim9script + var Fn = <funcx(number, number): number>b + END + v9.CheckSourceFailure(lines, 'E1010: Type not recognized: funcx(number, number): number', 2) + + # Wrong type in a type cast + lines =<< trim END + vim9script + var i: number = <number>true + END + v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected number but got bool', 2) +enddef + " Keep this last, it messes up highlighting. def Test_substitute_cmd() new |