summaryrefslogtreecommitdiffstats
path: root/src/testdir/test_vim9_script.vim
diff options
context:
space:
mode:
Diffstat (limited to 'src/testdir/test_vim9_script.vim')
-rw-r--r--src/testdir/test_vim9_script.vim130
1 files changed, 127 insertions, 3 deletions
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index 77b8831..a3f21be 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -458,7 +458,7 @@ func s:InvokeSomeCommand()
SomeCommand
endfunc
-def Test_autocommand_block()
+def Test_command_block()
com SomeCommand {
g:someVar = 'some'
}
@@ -469,7 +469,121 @@ def Test_autocommand_block()
unlet g:someVar
enddef
-def Test_command_block()
+" Test for using heredoc in a :command command block
+def Test_command_block_heredoc()
+ var lines =<< trim CODE
+ vim9script
+ com SomeCommand {
+ g:someVar =<< trim END
+ aaa
+ bbb
+ END
+ }
+ SomeCommand
+ assert_equal(['aaa', 'bbb'], g:someVar)
+ def Foo()
+ g:someVar = []
+ SomeCommand
+ assert_equal(['aaa', 'bbb'], g:someVar)
+ enddef
+ Foo()
+ delcommand SomeCommand
+ unlet g:someVar
+ CODE
+ v9.CheckSourceSuccess( lines)
+
+ # Execute a command with heredoc in a block
+ lines =<< trim CODE
+ vim9script
+ com SomeCommand {
+ g:someVar =<< trim END
+ aaa
+ bbb
+ END
+ }
+ execute('SomeCommand')
+ assert_equal(['aaa', 'bbb'], g:someVar)
+ delcommand SomeCommand
+ unlet g:someVar
+ CODE
+ v9.CheckSourceSuccess(lines)
+
+ # Heredoc with comment
+ lines =<< trim CODE
+ vim9script
+ com SomeCommand {
+ g:someVar =<< trim END # comment
+ aaa
+ bbb
+ END
+ }
+ execute('SomeCommand')
+ assert_equal(['aaa', 'bbb'], g:someVar)
+ delcommand SomeCommand
+ unlet g:someVar
+ CODE
+ v9.CheckSourceSuccess(lines)
+
+ # heredoc evaluation
+ lines =<< trim CODE
+ vim9script
+ com SomeCommand {
+ var suffix = '---'
+ g:someVar =<< trim eval END
+ ccc{suffix}
+ ddd
+ END
+ }
+ SomeCommand
+ assert_equal(['ccc---', 'ddd'], g:someVar)
+ def Foo()
+ g:someVar = []
+ SomeCommand
+ assert_equal(['ccc---', 'ddd'], g:someVar)
+ enddef
+ Foo()
+ delcommand SomeCommand
+ unlet g:someVar
+ CODE
+ v9.CheckSourceSuccess(lines)
+
+ # command following heredoc
+ lines =<< trim CODE
+ vim9script
+ com SomeCommand {
+ var l =<< trim END
+ eee
+ fff
+ END
+ g:someVar = l
+ }
+ SomeCommand
+ assert_equal(['eee', 'fff'], g:someVar)
+ delcommand SomeCommand
+ unlet g:someVar
+ CODE
+ v9.CheckSourceSuccess(lines)
+
+ # Error in heredoc
+ lines =<< trim CODE
+ vim9script
+ com SomeCommand {
+ g:someVar =<< trim END
+ eee
+ fff
+ }
+ try
+ SomeCommand
+ catch
+ assert_match("E990: Missing end marker 'END'", v:exception)
+ endtry
+ delcommand SomeCommand
+ unlet g:someVar
+ CODE
+ v9.CheckSourceSuccess(lines)
+enddef
+
+def Test_autocommand_block()
au BufNew *.xml {
g:otherVar = 'other'
}
@@ -4906,7 +5020,7 @@ def Test_for_stmt_space_before_type()
v9.CheckSourceFailure(lines, 'E1059: No white space allowed before colon: :number in range(10)', 2)
enddef
-" This test used to cause an use-after-free memory access
+" This test used to cause a use-after-free memory access
def Test_for_empty_line_after_lambda()
var lines =<< trim END
vim9script
@@ -4931,6 +5045,16 @@ def Test_for_empty_line_after_lambda()
v9.CheckSourceSuccess(lines)
enddef
+" Test for evaluating a lambda block from a string
+def Test_eval_lambda_block()
+ var lines =<< trim END
+ vim9script
+ var Fn = eval("(x: number): number => {\nreturn x * 2\n}")
+ assert_equal(6, Fn(3))
+ END
+ v9.CheckSourceSuccess(lines)
+enddef
+
" Keep this last, it messes up highlighting.
def Test_substitute_cmd()
new