Skip to content

Commit 3d93630

Browse files
zeertzjqchrisbra
authored andcommitted
patch 9.1.0319: Using heredoc in string not tested with :execute
Problem: Using heredoc in string not tested with :execute. Solution: Test with both :execute and execute() (zeertzjq). closes: #14546 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent acba5af commit 3d93630

2 files changed

Lines changed: 29 additions & 25 deletions

File tree

src/testdir/test_let.vim

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -722,31 +722,33 @@ END
722722
LINES
723723
call v9.CheckScriptFailure(lines, 'E15:')
724724

725-
" Test for using heredoc in a single string using execute()
726-
call assert_equal("\n['one', 'two']",
727-
\ execute("let x =<< trim END\n one\n two\nEND\necho x"))
728-
call assert_equal("\n['one', ' two']",
729-
\ execute("let x =<< trim END\n one\n two\nEND\necho x"))
730-
call assert_equal("\n['one', 'two']",
731-
\ execute(" let x =<< trim END\n one\n two\n END\necho x"))
732-
call assert_equal("\n['one', ' two']",
733-
\ execute(" let x =<< trim END\n one\n two\n END\necho x"))
734-
call assert_equal("\n[' one', ' two']",
735-
\ execute("let x =<< END\n one\n two\nEND\necho x"))
736-
call assert_equal("\n['one', 'two']",
737-
\ execute("let x =<< END\none\ntwo\nEND\necho x"))
738-
call assert_equal("\n['one', 'two']",
739-
\ execute("let x =<< END \" comment\none\ntwo\nEND\necho x"))
740-
let cmd = 'execute("let x =<< END\n one\n two\necho x")'
741-
call assert_fails(cmd, "E990: Missing end marker 'END'")
742-
let cmd = 'execute("let x =<<\n one\n two\necho x")'
743-
call assert_fails(cmd, "E172: Missing marker")
744-
let cmd = 'execute("let x =<< trim\n one\n two\necho x")'
745-
call assert_fails(cmd, "E172: Missing marker")
746-
let cmd = 'execute("let x =<< end\n one\n two\nend\necho x")'
747-
call assert_fails(cmd, "E221: Marker cannot start with lower case letter")
748-
let cmd = 'execute("let x =<< eval END\n one\n two{y}\nEND\necho x")'
749-
call assert_fails(cmd, 'E121: Undefined variable: y')
725+
" Test for using heredoc in a single string using :execute or execute()
726+
for [cmd, res] in items({
727+
\ "let x =<< trim END\n one\n two\nEND": ['one', 'two'],
728+
\ "let x =<< trim END\n one\n two\nEND": ['one', ' two'],
729+
\ " let x =<< trim END\n one\n two\n END": ['one', 'two'],
730+
\ " let x =<< trim END\n one\n two\n END": ['one', ' two'],
731+
\ "let x =<< END\n one\n two\nEND": [' one', ' two'],
732+
\ "let x =<< END\none\ntwo\nEND": ['one', 'two'],
733+
\ "let x =<< END \" comment\none\ntwo\nEND": ['one', 'two'],
734+
\ })
735+
execute cmd
736+
call assert_equal(res, x)
737+
unlet x
738+
call assert_equal($"\n{string(res)}", execute($"{cmd}\necho x"))
739+
unlet x
740+
endfor
741+
for [cmd, err] in items({
742+
\ "let x =<<\none\ntwo": "E172:",
743+
\ "let x =<< trim\n one\n two": "E172:",
744+
\ "let x =<< end\none\ntwo\nend": "E221:",
745+
\ "let x =<< END\none\ntwo": "E990: Missing end marker 'END'",
746+
\ "let x =<< END !\none\ntwo\nEND": "E488: Trailing characters: !",
747+
\ "let x =<< eval END\none\ntwo{y}\nEND": "E121: Undefined variable: y",
748+
\ })
749+
call assert_fails('execute cmd', err)
750+
call assert_fails('call execute(cmd)', err)
751+
endfor
750752

751753
" skipped heredoc
752754
if 0

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
319,
707709
/**/
708710
318,
709711
/**/

0 commit comments

Comments
 (0)