summaryrefslogtreecommitdiffstats
path: root/src/testdir
diff options
context:
space:
mode:
Diffstat (limited to 'src/testdir')
-rw-r--r--src/testdir/test_let.vim14
-rw-r--r--src/testdir/test_vim9_script.vim102
2 files changed, 114 insertions, 2 deletions
diff --git a/src/testdir/test_let.vim b/src/testdir/test_let.vim
index 5ee2e9b3c4..e6d9cae8e5 100644
--- a/src/testdir/test_let.vim
+++ b/src/testdir/test_let.vim
@@ -715,6 +715,20 @@ END
LINES
call v9.CheckScriptFailure(lines, 'E15:')
+ " Test for using heredoc in a single string using execute()
+ call assert_equal(["['one', 'two']"],
+ \ execute("let x =<< trim END\n one\n two\nEND\necho x")->split("\n"))
+ call assert_equal(["[' one', ' two']"],
+ \ execute("let x =<< END\n one\n two\nEND\necho x")->split("\n"))
+ let cmd = 'execute("let x =<< END\n one\n two\necho x")'
+ call assert_fails(cmd, "E990: Missing end marker 'END'")
+ let cmd = 'execute("let x =<<\n one\n two\necho x")'
+ call assert_fails(cmd, "E990: Missing end marker ''")
+ let cmd = 'execute("let x =<< trim\n one\n two\necho x")'
+ call assert_fails(cmd, "E221: Marker cannot start with lower case letter")
+ let cmd = 'execute("let x =<< eval END\n one\n two{y}\nEND\necho x")'
+ call assert_fails(cmd, 'E121: Undefined variable: y')
+
" skipped heredoc
if 0
let msg =<< trim eval END
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index cd693e5993..136c81db7d 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,105 @@ 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 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'
}