Merge pull request #23386 from zeertzjq/vim-8.2.0551

vim-patch:8.2.{0551,0578,0672}: heredoc for interfaces does not support "trim"
This commit is contained in:
zeertzjq 2023-04-29 10:07:51 +08:00 committed by GitHub
commit 3287fc2ba9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 347 additions and 67 deletions

View File

@ -19,7 +19,7 @@ See |provider-perl| for more information.
working: > working: >
:perl print "Hello" :perl print "Hello"
:[range]perl << [endmarker] :[range]perl << [trim] [{endmarker}]
{script} {script}
{endmarker} {endmarker}
Execute perl script {script}. Execute perl script {script}.

View File

@ -19,17 +19,16 @@ Commands *python-commands*
the `:python` command is working: >vim the `:python` command is working: >vim
:python print "Hello" :python print "Hello"
:[range]py[thon] << [endmarker] :[range]py[thon] << [trim] [{endmarker}]
{script} {script}
{endmarker} {endmarker}
Execute Python script {script}. Useful for including Execute Python script {script}. Useful for including
python code in Vim scripts. Requires Python, see python code in Vim scripts. Requires Python, see
|script-here|. |script-here|.
The {endmarker} below the {script} must NOT be preceded by any white space.
If [endmarker] is omitted from after the "<<", a dot '.' must be used after If [endmarker] is omitted from after the "<<", a dot '.' must be used after
{script}, like for the |:append| and |:insert| commands. {script}, like for the |:append| and |:insert| commands. Refer to
|:let-heredoc| for more information.
Example: >vim Example: >vim
function! IcecreamInitialize() function! IcecreamInitialize()
@ -597,12 +596,12 @@ variants explicitly if Python 3 is required.
*:py3* *:python3* *:py3* *:python3*
:[range]py3 {stmt} :[range]py3 {stmt}
:[range]py3 << [endmarker] :[range]py3 << [trim] [{endmarker}]
{script} {script}
{endmarker} {endmarker}
:[range]python3 {stmt} :[range]python3 {stmt}
:[range]python3 << [endmarker] :[range]python3 << [trim] [{endmarker}]
{script} {script}
{endmarker} {endmarker}
The `:py3` and `:python3` commands work similar to `:python`. A The `:py3` and `:python3` commands work similar to `:python`. A

View File

@ -19,15 +19,15 @@ downloading Ruby there.
:rub[y] {cmd} Execute Ruby command {cmd}. A command to try it out: > :rub[y] {cmd} Execute Ruby command {cmd}. A command to try it out: >
:ruby print "Hello" :ruby print "Hello"
:rub[y] << [endmarker] :rub[y] << [trim] [{endmarker}]
{script} {script}
{endmarker} {endmarker}
Execute Ruby script {script}. Execute Ruby script {script}.
The {endmarker} after {script} must NOT be preceded by
any white space.
If [endmarker] is omitted, it defaults to a dot '.' If [endmarker] is omitted, it defaults to a dot '.'
like for the |:append| and |:insert| commands. like for the |:append| and |:insert| commands. Refer
to |:let-heredoc| for more information.
This form of the |:ruby| command is mainly useful for This form of the |:ruby| command is mainly useful for
including ruby code in vim scripts. including ruby code in vim scripts.

View File

@ -247,12 +247,12 @@ arguments separated by " " (space) instead of "\t" (tab).
:lua =jit.version :lua =jit.version
< <
*:lua-heredoc* *:lua-heredoc*
:lua << [endmarker] :lua << [trim] [{endmarker}]
{script} {script}
{endmarker} {endmarker}
Executes Lua script {script} from within Vimscript. {endmarker} must NOT Executes Lua script {script} from within Vimscript. You can omit
be preceded by whitespace. You can omit [endmarker] after the "<<" and use [endmarker] after the "<<" and use a dot "." after {script} (similar to
a dot "." after {script} (similar to |:append|, |:insert|). |:append|, |:insert|). Refer to |let-heredoc| for more information.
Example: >vim Example: >vim
function! CurrentLineInfo() function! CurrentLineInfo()

View File

@ -2571,11 +2571,18 @@ void ex_function(exarg_T *eap)
&& (!ASCII_ISALPHA(p[2]) || p[2] == 's')))) { && (!ASCII_ISALPHA(p[2]) || p[2] == 's')))) {
// ":python <<" continues until a dot, like ":append" // ":python <<" continues until a dot, like ":append"
p = skipwhite(arg + 2); p = skipwhite(arg + 2);
if (strncmp(p, "trim", 4) == 0) {
// Ignore leading white space.
p = skipwhite(p + 4);
heredoc_trimmed = xstrnsave(theline, (size_t)(skipwhite(theline) - theline));
}
if (*p == NUL) { if (*p == NUL) {
skip_until = xstrdup("."); skip_until = xstrdup(".");
} else { } else {
skip_until = xstrdup(p); skip_until = xstrnsave(p, (size_t)(skiptowhite(p) - p));
} }
do_concat = false;
is_heredoc = true;
} }
// Check for ":let v =<< [trim] EOF" // Check for ":let v =<< [trim] EOF"

View File

@ -155,14 +155,18 @@ char *eval_all_expr_in_str(char *str)
/// marker, then the leading indentation before the lines (matching the /// marker, then the leading indentation before the lines (matching the
/// indentation in the 'cmd' line) is stripped. /// indentation in the 'cmd' line) is stripped.
/// ///
/// When getting lines for an embedded script (e.g. python, lua, perl, ruby,
/// tcl, mzscheme), "script_get" is set to true. In this case, if the marker is
/// missing, then '.' is accepted as a marker.
///
/// @return a List with {lines} or NULL on failure. /// @return a List with {lines} or NULL on failure.
static list_T *heredoc_get(exarg_T *eap, char *cmd) list_T *heredoc_get(exarg_T *eap, char *cmd, bool script_get)
{ {
char *marker; char *marker;
char *p;
int marker_indent_len = 0; int marker_indent_len = 0;
int text_indent_len = 0; int text_indent_len = 0;
char *text_indent = NULL; char *text_indent = NULL;
char dot[] = ".";
if (eap->getline == NULL) { if (eap->getline == NULL) {
emsg(_("E991: cannot use =<< here")); emsg(_("E991: cannot use =<< here"));
@ -182,7 +186,7 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd)
// The amount of indentation trimmed is the same as the indentation // The amount of indentation trimmed is the same as the indentation
// of the first line after the :let command line. To find the end // of the first line after the :let command line. To find the end
// marker the indent of the :let command line is trimmed. // marker the indent of the :let command line is trimmed.
p = *eap->cmdlinep; char *p = *eap->cmdlinep;
while (ascii_iswhite(*p)) { while (ascii_iswhite(*p)) {
p++; p++;
marker_indent_len++; marker_indent_len++;
@ -203,19 +207,25 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd)
// The marker is the next word. // The marker is the next word.
if (*cmd != NUL && *cmd != '"') { if (*cmd != NUL && *cmd != '"') {
marker = skipwhite(cmd); marker = skipwhite(cmd);
p = skiptowhite(marker); char *p = skiptowhite(marker);
if (*skipwhite(p) != NUL && *skipwhite(p) != '"') { if (*skipwhite(p) != NUL && *skipwhite(p) != '"') {
semsg(_(e_trailing_arg), p); semsg(_(e_trailing_arg), p);
return NULL; return NULL;
} }
*p = NUL; *p = NUL;
if (islower((uint8_t)(*marker))) { if (!script_get && islower((uint8_t)(*marker))) {
emsg(_("E221: Marker cannot start with lower case letter")); emsg(_("E221: Marker cannot start with lower case letter"));
return NULL; return NULL;
} }
} else { } else {
emsg(_("E172: Missing marker")); // When getting lines for an embedded script, if the marker is missing,
return NULL; // accept '.' as the marker.
if (script_get) {
marker = dot;
} else {
emsg(_("E172: Missing marker"));
return NULL;
}
} }
char *theline = NULL; char *theline = NULL;
@ -227,7 +237,9 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd)
xfree(theline); xfree(theline);
theline = eap->getline(NUL, eap->cookie, 0, false); theline = eap->getline(NUL, eap->cookie, 0, false);
if (theline == NULL) { if (theline == NULL) {
semsg(_("E990: Missing end marker '%s'"), marker); if (!script_get) {
semsg(_("E990: Missing end marker '%s'"), marker);
}
break; break;
} }
@ -249,7 +261,7 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd)
if (text_indent_len == -1 && *theline != NUL) { if (text_indent_len == -1 && *theline != NUL) {
// set the text indent from the first line. // set the text indent from the first line.
p = theline; char *p = theline;
text_indent_len = 0; text_indent_len = 0;
while (ascii_iswhite(*p)) { while (ascii_iswhite(*p)) {
p++; p++;
@ -353,7 +365,7 @@ void ex_let(exarg_T *eap)
if (expr[0] == '=' && expr[1] == '<' && expr[2] == '<') { if (expr[0] == '=' && expr[1] == '<' && expr[2] == '<') {
// HERE document // HERE document
list_T *l = heredoc_get(eap, expr + 3); list_T *l = heredoc_get(eap, expr + 3, false);
if (l != NULL) { if (l != NULL) {
tv_list_set_ret(&rettv, l); tv_list_set_ret(&rettv, l);
if (!eap->skip) { if (!eap->skip) {

View File

@ -29,6 +29,7 @@
#include "nvim/edit.h" #include "nvim/edit.h"
#include "nvim/eval.h" #include "nvim/eval.h"
#include "nvim/eval/typval.h" #include "nvim/eval/typval.h"
#include "nvim/eval/vars.h"
#include "nvim/ex_cmds.h" #include "nvim/ex_cmds.h"
#include "nvim/ex_cmds_defs.h" #include "nvim/ex_cmds_defs.h"
#include "nvim/ex_docmd.h" #include "nvim/ex_docmd.h"
@ -4561,39 +4562,37 @@ bool is_in_cmdwin(void)
char *script_get(exarg_T *const eap, size_t *const lenp) char *script_get(exarg_T *const eap, size_t *const lenp)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC
{ {
const char *const cmd = eap->arg; char *cmd = eap->arg;
if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL) { if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL) {
*lenp = strlen(eap->arg); *lenp = strlen(eap->arg);
return eap->skip ? NULL : xmemdupz(eap->arg, *lenp); return eap->skip ? NULL : xmemdupz(eap->arg, *lenp);
} }
cmd += 2;
garray_T ga = { .ga_data = NULL, .ga_len = 0 }; garray_T ga = { .ga_data = NULL, .ga_len = 0 };
list_T *const l = heredoc_get(eap, cmd, true);
if (l == NULL) {
return NULL;
}
if (!eap->skip) { if (!eap->skip) {
ga_init(&ga, 1, 0x400); ga_init(&ga, 1, 0x400);
} }
const char *const end_pattern = (cmd[2] != NUL ? skipwhite(cmd + 2) : "."); TV_LIST_ITER_CONST(l, li, {
while (true) {
char *const theline = eap->getline(eap->cstack->cs_looplevel > 0 ? -1 : NUL, eap->cookie, 0,
true);
if (theline == NULL || strcmp(end_pattern, theline) == 0) {
xfree(theline);
break;
}
if (!eap->skip) { if (!eap->skip) {
ga_concat(&ga, theline); ga_concat(&ga, tv_get_string(TV_LIST_ITEM_TV(li)));
ga_append(&ga, '\n'); ga_append(&ga, '\n');
} }
xfree(theline); });
}
*lenp = (size_t)ga.ga_len; // Set length without trailing NUL. *lenp = (size_t)ga.ga_len; // Set length without trailing NUL.
if (!eap->skip) { if (!eap->skip) {
ga_append(&ga, NUL); ga_append(&ga, NUL);
} }
tv_list_free(l);
return (char *)ga.ga_data; return (char *)ga.ga_data;
} }

View File

@ -1619,7 +1619,7 @@ void ex_lua(exarg_T *const eap)
{ {
size_t len; size_t len;
char *code = script_get(eap, &len); char *code = script_get(eap, &len);
if (eap->skip) { if (eap->skip || code == NULL) {
xfree(code); xfree(code);
return; return;
} }

View File

@ -7,6 +7,7 @@ local NIL = helpers.NIL
local eval = helpers.eval local eval = helpers.eval
local feed = helpers.feed local feed = helpers.feed
local clear = helpers.clear local clear = helpers.clear
local matches = helpers.matches
local meths = helpers.meths local meths = helpers.meths
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local exec_capture = helpers.exec_capture local exec_capture = helpers.exec_capture
@ -27,22 +28,27 @@ describe(':lua command', function()
eq('', exec_capture( eq('', exec_capture(
'lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TEST"})')) 'lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TEST"})'))
eq({'', 'TEST'}, curbufmeths.get_lines(0, 100, false)) eq({'', 'TEST'}, curbufmeths.get_lines(0, 100, false))
source(dedent([[ source([[
lua << EOF lua << EOF
vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TSET"}) vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TSET"})
EOF]])) EOF]])
eq({'', 'TSET'}, curbufmeths.get_lines(0, 100, false)) eq({'', 'TSET'}, curbufmeths.get_lines(0, 100, false))
source(dedent([[ source([[
lua << EOF lua << EOF
vim.api.nvim_buf_set_lines(1, 1, 2, false, {"SETT"})]])) vim.api.nvim_buf_set_lines(1, 1, 2, false, {"SETT"})]])
eq({'', 'SETT'}, curbufmeths.get_lines(0, 100, false)) eq({'', 'SETT'}, curbufmeths.get_lines(0, 100, false))
source(dedent([[ source([[
lua << EOF lua << EOF
vim.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"}) vim.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"})
vim.api.nvim_buf_set_lines(1, 2, 3, false, {"TTSE"}) vim.api.nvim_buf_set_lines(1, 2, 3, false, {"TTSE"})
vim.api.nvim_buf_set_lines(1, 3, 4, false, {"STTE"}) vim.api.nvim_buf_set_lines(1, 3, 4, false, {"STTE"})
EOF]])) EOF]])
eq({'', 'ETTS', 'TTSE', 'STTE'}, curbufmeths.get_lines(0, 100, false)) eq({'', 'ETTS', 'TTSE', 'STTE'}, curbufmeths.get_lines(0, 100, false))
matches('.*Vim%(lua%):E15: Invalid expression: .*', pcall_err(source, [[
lua << eval EOF
{}
EOF
]]))
end) end)
it('throws catchable errors', function() it('throws catchable errors', function()
eq([[Vim(lua):E5107: Error loading lua [string ":lua"]:0: unexpected symbol near ')']], eq([[Vim(lua):E5107: Error loading lua [string ":lua"]:0: unexpected symbol near ')']],

View File

@ -321,9 +321,54 @@ func Test_set_completion()
call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx') call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:) call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
set tags& set tags&
" Expanding the option names
call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set all', @:)
" Expanding a second set of option names
call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set wrapscan all', @:)
" Expanding a special keycode
" call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt')
" call assert_equal('"set <Home>', @:)
" Expanding an invalid special keycode
call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal("\"set <abcd>\<Tab>", @:)
" Expanding a terminal keycode
" call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt')
" call assert_equal("\"set t_AB", @:)
" Expanding an invalid option name
call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal("\"set abcde=\<Tab>", @:)
" Expanding after a = for a boolean option
call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal("\"set wrapscan=\<Tab>", @:)
" Expanding a numeric option
call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal("\"set tabstop+=" .. &tabstop, @:)
" Expanding a non-boolean option
call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal("\"set invtabstop=", @:)
" Expand options for 'spellsuggest'
call feedkeys(":set spellsuggest=best,file:xyz\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal("\"set spellsuggest=best,file:xyz", @:)
" Expand value for 'key'
" set key=abcd
" call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt')
" call assert_equal('"set key=*****', @:)
" set key=
" Expand values for 'filetype' " Expand values for 'filetype'
call feedkeys(":set filetype=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt') call feedkeys(":set filetype=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set filetype=sshdconfig', @:) call assert_equal('"set filetype=sshdconfig', @:)
@ -411,7 +456,14 @@ func Test_set_errors()
set backupext& patchmode& set backupext& patchmode&
call assert_fails('set winminheight=10 winheight=9', 'E591:') call assert_fails('set winminheight=10 winheight=9', 'E591:')
set winminheight& winheight&
set winheight=10 winminheight=10
call assert_fails('set winheight=9', 'E591:')
set winminheight& winheight&
call assert_fails('set winminwidth=10 winwidth=9', 'E592:') call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
set winminwidth& winwidth&
call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
set winwidth& winminwidth&
call assert_fails("set showbreak=\x01", 'E595:') call assert_fails("set showbreak=\x01", 'E595:')
call assert_fails('set t_foo=', 'E846:') call assert_fails('set t_foo=', 'E846:')
call assert_fails('set tabstop??', 'E488:') call assert_fails('set tabstop??', 'E488:')
@ -944,7 +996,9 @@ endfunc
func Test_opt_sandbox() func Test_opt_sandbox()
for opt in ['backupdir', 'cdpath', 'exrc'] for opt in ['backupdir', 'cdpath', 'exrc']
call assert_fails('sandbox set ' .. opt .. '?', 'E48:') call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
endfor endfor
call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
endfunc endfunc
" Test for setting an option with local value to global value " Test for setting an option with local value to global value

View File

@ -224,11 +224,11 @@ endfunc
func Test_stdio() func Test_stdio()
throw 'skipped: TODO: ' throw 'skipped: TODO: '
redir =>l:out redir =>l:out
perl <<EOF perl << trim EOF
VIM::Msg("&VIM::Msg"); VIM::Msg("&VIM::Msg");
print "STDOUT"; print "STDOUT";
print STDERR "STDERR"; print STDERR "STDERR";
EOF EOF
redir END redir END
call assert_equal(['&VIM::Msg', 'STDOUT', 'STDERR'], split(l:out, "\n")) call assert_equal(['&VIM::Msg', 'STDOUT', 'STDERR'], split(l:out, "\n"))
endfunc endfunc
@ -305,7 +305,16 @@ END
perl << perl <<
VIM::DoCommand('let s ..= "B"') VIM::DoCommand('let s ..= "B"')
. .
call assert_equal('AB', s) perl << trim END
VIM::DoCommand('let s ..= "C"')
END
perl << trim
VIM::DoCommand('let s ..= "D"')
.
perl << trim eof
VIM::DoCommand('let s ..= "E"')
eof
call assert_equal('ABCDE', s)
endfunc endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@ -40,7 +40,7 @@ func Test_set_cursor()
endfunc endfunc
func Test_vim_function() func Test_vim_function()
throw 'skipped: Nvim does not support vim.bindeval()' throw 'Skipped: Nvim does not support vim.bindeval()'
" Check creating vim.Function object " Check creating vim.Function object
py import vim py import vim
@ -171,3 +171,25 @@ func Test_Catch_Exception_Message()
call assert_match('^Vim(.*):.*RuntimeError: TEST$', v:exception ) call assert_match('^Vim(.*):.*RuntimeError: TEST$', v:exception )
endtry endtry
endfunc endfunc
" Test for various heredoc syntax
func Test_python_heredoc()
python << END
s='A'
END
python <<
s+='B'
.
python << trim END
s+='C'
END
python << trim
s+='D'
.
python << trim eof
s+='E'
eof
call assert_equal('ABCDE', pyxeval('s'))
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@ -40,7 +40,7 @@ func Test_set_cursor()
endfunc endfunc
func Test_vim_function() func Test_vim_function()
throw 'skipped: Nvim does not support vim.bindeval()' throw 'Skipped: Nvim does not support vim.bindeval()'
" Check creating vim.Function object " Check creating vim.Function object
py3 import vim py3 import vim
@ -68,7 +68,7 @@ func Test_vim_function()
endfunc endfunc
func Test_skipped_python3_command_does_not_affect_pyxversion() func Test_skipped_python3_command_does_not_affect_pyxversion()
throw 'skipped: Nvim hardcodes pyxversion=3' throw 'Skipped: Nvim hardcodes pyxversion=3'
set pyxversion=0 set pyxversion=0
if 0 if 0
python3 import vim python3 import vim
@ -190,3 +190,101 @@ func Test_unicode()
set encoding=utf8 set encoding=utf8
endfunc endfunc
" Test for resetting options with local values to global values
func Test_python3_opt_reset_local_to_global()
throw 'Skipped: Nvim does not support vim.bindeval()'
new
py3 curbuf = vim.current.buffer
py3 curwin = vim.current.window
" List of buffer-local options. Each list item has [option name, global
" value, buffer-local value, buffer-local value after reset] to use in the
" test.
let bopts = [
\ ['autoread', 1, 0, -1],
\ ['equalprg', 'geprg', 'leprg', ''],
\ ['keywordprg', 'gkprg', 'lkprg', ''],
\ ['path', 'gpath', 'lpath', ''],
\ ['backupcopy', 'yes', 'no', ''],
\ ['tags', 'gtags', 'ltags', ''],
\ ['tagcase', 'ignore', 'match', ''],
\ ['define', 'gdef', 'ldef', ''],
\ ['include', 'ginc', 'linc', ''],
\ ['dict', 'gdict', 'ldict', ''],
\ ['thesaurus', 'gtsr', 'ltsr', ''],
\ ['formatprg', 'gfprg', 'lfprg', ''],
\ ['errorformat', '%f:%l:%m', '%s-%l-%m', ''],
\ ['grepprg', 'ggprg', 'lgprg', ''],
\ ['makeprg', 'gmprg', 'lmprg', ''],
\ ['balloonexpr', 'gbexpr', 'lbexpr', ''],
\ ['cryptmethod', 'blowfish2', 'zip', ''],
\ ['lispwords', 'abc', 'xyz', ''],
\ ['makeencoding', 'utf-8', 'latin1', ''],
\ ['undolevels', 100, 200, -123456]]
" Set the global and buffer-local option values and then clear the
" buffer-local option value.
for opt in bopts
py3 << trim END
pyopt = vim.bindeval("opt")
vim.options[pyopt[0]] = pyopt[1]
curbuf.options[pyopt[0]] = pyopt[2]
END
exe "call assert_equal(opt[2], &" .. opt[0] .. ")"
exe "call assert_equal(opt[1], &g:" .. opt[0] .. ")"
exe "call assert_equal(opt[2], &l:" .. opt[0] .. ")"
py3 del curbuf.options[pyopt[0]]
exe "call assert_equal(opt[1], &" .. opt[0] .. ")"
exe "call assert_equal(opt[1], &g:" .. opt[0] .. ")"
exe "call assert_equal(opt[3], &l:" .. opt[0] .. ")"
exe "set " .. opt[0] .. "&"
endfor
" Set the global and window-local option values and then clear the
" window-local option value.
let wopts = [
\ ['scrolloff', 5, 10, -1],
\ ['sidescrolloff', 6, 12, -1],
\ ['statusline', '%<%f', '%<%F', '']]
for opt in wopts
py3 << trim
pyopt = vim.bindeval("opt")
vim.options[pyopt[0]] = pyopt[1]
curwin.options[pyopt[0]] = pyopt[2]
.
exe "call assert_equal(opt[2], &" .. opt[0] .. ")"
exe "call assert_equal(opt[1], &g:" .. opt[0] .. ")"
exe "call assert_equal(opt[2], &l:" .. opt[0] .. ")"
py3 del curwin.options[pyopt[0]]
exe "call assert_equal(opt[1], &" .. opt[0] .. ")"
exe "call assert_equal(opt[1], &g:" .. opt[0] .. ")"
exe "call assert_equal(opt[3], &l:" .. opt[0] .. ")"
exe "set " .. opt[0] .. "&"
endfor
close!
endfunc
" Test for various heredoc syntax
func Test_python3_heredoc()
python3 << END
s='A'
END
python3 <<
s+='B'
.
python3 << trim END
s+='C'
END
python3 << trim
s+='D'
.
python3 << trim eof
s+='E'
eof
call assert_equal('ABCDE', pyxeval('s'))
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@ -15,10 +15,10 @@ endfunc
func Test_pyx() func Test_pyx()
redir => var redir => var
pyx << EOF pyx << trim EOF
import sys import sys
print(sys.version) print(sys.version)
EOF EOF
redir END redir END
call assert_match(s:py2pattern, split(var)[0]) call assert_match(s:py2pattern, split(var)[0])
endfunc endfunc
@ -79,3 +79,25 @@ func Test_Catch_Exception_Message()
call assert_match('^Vim(.*):.*RuntimeError: TEST$', v:exception ) call assert_match('^Vim(.*):.*RuntimeError: TEST$', v:exception )
endtry endtry
endfunc endfunc
" Test for various heredoc syntaxes
func Test_pyx2_heredoc()
pyx << END
result='A'
END
pyx <<
result+='B'
.
pyx << trim END
result+='C'
END
pyx << trim
result+='D'
.
pyx << trim eof
result+='E'
eof
call assert_equal('ABCDE', pyxeval('result'))
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@ -15,10 +15,10 @@ endfunc
func Test_pyx() func Test_pyx()
redir => var redir => var
pyx << EOF pyx << trim EOF
import sys import sys
print(sys.version) print(sys.version)
EOF EOF
redir END redir END
call assert_match(s:py3pattern, split(var)[0]) call assert_match(s:py3pattern, split(var)[0])
endfunc endfunc
@ -79,3 +79,25 @@ func Test_Catch_Exception_Message()
call assert_match('^Vim(.*):.*RuntimeError: TEST$', v:exception ) call assert_match('^Vim(.*):.*RuntimeError: TEST$', v:exception )
endtry endtry
endfunc endfunc
" Test for various heredoc syntaxes
func Test_pyx3_heredoc()
pyx << END
result='A'
END
pyx <<
result+='B'
.
pyx << trim END
result+='C'
END
pyx << trim
result+='D'
.
pyx << trim eof
result+='E'
eof
call assert_equal('ABCDE', pyxeval('result'))
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@ -341,11 +341,11 @@ func Test_ruby_Vim_evaluate_list()
call setline(line('$'), ['2 line 2']) call setline(line('$'), ['2 line 2'])
ruby Vim.command("normal /^2\n") ruby Vim.command("normal /^2\n")
let l = ["abc", "def"] let l = ["abc", "def"]
ruby << EOF ruby << trim EOF
curline = $curbuf.line_number curline = $curbuf.line_number
l = Vim.evaluate("l"); l = Vim.evaluate("l");
$curbuf.append(curline, l.join("|")) $curbuf.append(curline, l.join("|"))
EOF EOF
normal j normal j
.rubydo $_ = $_.gsub(/\|/, '/') .rubydo $_ = $_.gsub(/\|/, '/')
call assert_equal('abc/def', getline('$')) call assert_equal('abc/def', getline('$'))
@ -414,4 +414,24 @@ func Test_rubyeval_error()
call assert_fails('call rubyeval("(")') call assert_fails('call rubyeval("(")')
endfunc endfunc
" Test for various heredoc syntax
func Test_ruby_heredoc()
ruby << END
Vim.command('let s = "A"')
END
ruby <<
Vim.command('let s ..= "B"')
.
ruby << trim END
Vim.command('let s ..= "C"')
END
ruby << trim
Vim.command('let s ..= "D"')
.
ruby << trim eof
Vim.command('let s ..= "E"')
eof
call assert_equal('ABCDE', s)
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@ -126,6 +126,11 @@ func Test_global_local_undolevels()
call assert_equal(50, &g:undolevels) call assert_equal(50, &g:undolevels)
call assert_equal(-123456, &l:undolevels) call assert_equal(-123456, &l:undolevels)
" Resetting the local 'undolevels' value to use the global value
setlocal undolevels=5
setlocal undolevels<
call assert_equal(-123456, &l:undolevels)
" Drop created windows " Drop created windows
set ul& set ul&
new new

View File

@ -6705,6 +6705,11 @@ func Test_echo_and_string()
let l = split(result, "\n") let l = split(result, "\n")
call assert_equal(["{'a': [], 'b': []}", call assert_equal(["{'a': [], 'b': []}",
\ "{'a': [], 'b': []}"], l) \ "{'a': [], 'b': []}"], l)
call assert_fails('echo &:', 'E112:')
call assert_fails('echo &g:', 'E112:')
call assert_fails('echo &l:', 'E112:')
endfunc endfunc
"------------------------------------------------------------------------------- "-------------------------------------------------------------------------------