int count = 0;
int heredoc_in_string = FALSE;
char_u *line_arg = NULL;
+ char_u *nl_ptr = vim_strchr(cmd, '\n');
- if (eap->ea_getline == NULL && vim_strchr(cmd, '\n') == NULL)
+ if (nl_ptr != NULL)
+ {
+ heredoc_in_string = TRUE;
+ line_arg = nl_ptr + 1;
+ *nl_ptr = NUL;
+ }
+ else if (eap->ea_getline == NULL)
{
emsg(_(e_cannot_use_heredoc_here));
return NULL;
if (*cmd != NUL && *cmd != comment_char)
{
marker = skipwhite(cmd);
- p = skiptowhite_or_nl(marker);
- if (*p == NL)
- {
- // heredoc in a string
- line_arg = p + 1;
- heredoc_in_string = TRUE;
- }
- else if (*skipwhite(p) != NUL && *skipwhite(p) != comment_char)
+ p = skiptowhite(marker);
+ if (*skipwhite(p) != NUL && *skipwhite(p) != comment_char)
{
semsg(_(e_trailing_characters_str), p);
return NULL;
XX
call assert_equal(['Line1'], var1)
+ let var1 =<< trim XX " comment
+ Line1
+ Line2
+ Line3
+ XX
+ call assert_equal(['Line1', ' Line2', 'Line3'], var1)
+
" ignore "endfunc"
let var1 =<< END
something
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"))
+ call assert_equal("\n['one', 'two']",
+ \ execute("let x =<< trim END\n one\n two\nEND\necho x"))
+ call assert_equal("\n['one', ' two']",
+ \ execute("let x =<< trim END\n one\n two\nEND\necho x"))
+ call assert_equal("\n['one', 'two']",
+ \ execute(" let x =<< trim END\n one\n two\n END\necho x"))
+ call assert_equal("\n['one', ' two']",
+ \ execute(" let x =<< trim END\n one\n two\n END\necho x"))
+ call assert_equal("\n[' one', ' two']",
+ \ execute("let x =<< END\n one\n two\nEND\necho x"))
+ call assert_equal("\n['one', 'two']",
+ \ execute("let x =<< END\none\ntwo\nEND\necho x"))
+ call assert_equal("\n['one', 'two']",
+ \ execute("let x =<< END \" comment\none\ntwo\nEND\necho x"))
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 ''")
+ call assert_fails(cmd, "E172: Missing marker")
let cmd = 'execute("let x =<< trim\n one\n two\necho x")'
+ call assert_fails(cmd, "E172: Missing marker")
+ let cmd = 'execute("let x =<< end\n one\n two\nend\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')