Merge pull request #20987 from zeertzjq/vim-8.2.3751

vim-patch:8.2.{3735,3751,3756,3758,3788,3792}
This commit is contained in:
zeertzjq 2022-11-07 14:49:53 +08:00 committed by GitHub
commit e9c1cb71f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 1280 additions and 636 deletions

View File

@ -313,9 +313,10 @@ Note: In the future more global options can be made |global-local|. Using
*option-value-function*
Some options ('completefunc', 'imactivatefunc', 'imstatusfunc', 'omnifunc',
'operatorfunc', 'quickfixtextfunc', 'tagfunc' and 'thesaurusfunc') are set to
a function name or a function reference or a lambda function. Examples:
Some options ('completefunc', 'omnifunc', 'operatorfunc', 'quickfixtextfunc',
'tagfunc' and 'thesaurusfunc') are set to a function name or a function
reference or a lambda function. When using a lambda it will be converted to
the name, e.g. "<lambda>123". Examples:
>
set opfunc=MyOpFunc
set opfunc=function('MyOpFunc')
@ -325,10 +326,10 @@ a function name or a function reference or a lambda function. Examples:
let Fn = function('MyTagFunc')
let &tagfunc = string(Fn)
" set using a lambda expression
let &tagfunc = "{t -> MyTagFunc(t)}"
let &tagfunc = {t -> MyTagFunc(t)}
" set using a variable with lambda expression
let L = {a, b, c -> MyTagFunc(a, b , c)}
let &tagfunc = string(L)
let &tagfunc = L
<
Setting the filetype

View File

@ -487,7 +487,7 @@ static getoption_T access_option_value(char *key, long *numval, char **stringval
bool get, Error *err)
{
if (get) {
return get_option_value(key, numval, stringval, opt_flags);
return get_option_value(key, numval, stringval, NULL, opt_flags);
} else {
char *errmsg;
if ((errmsg = set_option_value(key, *numval, *stringval, opt_flags))) {

View File

@ -131,7 +131,7 @@ bool ctx_restore(Context *ctx, const int flags)
}
char *op_shada;
get_option_value("shada", NULL, &op_shada, OPT_GLOBAL);
get_option_value("shada", NULL, &op_shada, NULL, OPT_GLOBAL);
set_option_value("shada", 0L, "!,'100,%", OPT_GLOBAL);
if (flags & kCtxRegs) {

View File

@ -30,6 +30,7 @@
#include "nvim/ex_session.h"
#include "nvim/getchar.h"
#include "nvim/highlight_group.h"
#include "nvim/insexpand.h"
#include "nvim/locale.h"
#include "nvim/lua/executor.h"
#include "nvim/mark.h"
@ -49,6 +50,7 @@
#include "nvim/search.h"
#include "nvim/sign.h"
#include "nvim/syntax.h"
#include "nvim/tag.h"
#include "nvim/ui.h"
#include "nvim/ui_compositor.h"
#include "nvim/undo.h"
@ -3689,10 +3691,10 @@ static int eval_index(char **arg, typval_T *rettv, int evaluate, int verbose)
int get_option_tv(const char **const arg, typval_T *const rettv, const bool evaluate)
FUNC_ATTR_NONNULL_ARG(1)
{
int opt_flags;
int scope;
// Isolate the option name and find its value.
char *option_end = (char *)find_option_end(arg, &opt_flags);
char *option_end = (char *)find_option_end(arg, &scope);
if (option_end == NULL) {
if (rettv != NULL) {
semsg(_("E112: Option name missing: %s"), *arg);
@ -3712,7 +3714,7 @@ int get_option_tv(const char **const arg, typval_T *const rettv, const bool eval
char c = *option_end;
*option_end = NUL;
getoption_T opt_type = get_option_value(*arg, &numval,
rettv == NULL ? NULL : &stringval, opt_flags);
rettv == NULL ? NULL : &stringval, NULL, scope);
if (opt_type == gov_unknown) {
if (rettv != NULL) {
@ -4168,10 +4170,23 @@ bool garbage_collect(bool testing)
ABORTING(set_ref_dict)(buf->additional_data, copyID);
// buffer callback functions
set_ref_in_callback(&buf->b_prompt_callback, copyID, NULL, NULL);
set_ref_in_callback(&buf->b_prompt_interrupt, copyID, NULL, NULL);
ABORTING(set_ref_in_callback)(&buf->b_prompt_callback, copyID, NULL, NULL);
ABORTING(set_ref_in_callback)(&buf->b_prompt_interrupt, copyID, NULL, NULL);
ABORTING(set_ref_in_callback)(&buf->b_cfu_cb, copyID, NULL, NULL);
ABORTING(set_ref_in_callback)(&buf->b_ofu_cb, copyID, NULL, NULL);
ABORTING(set_ref_in_callback)(&buf->b_tsrfu_cb, copyID, NULL, NULL);
ABORTING(set_ref_in_callback)(&buf->b_tfu_cb, copyID, NULL, NULL);
}
// 'completefunc', 'omnifunc' and 'thesaurusfunc' callbacks
ABORTING(set_ref_in_insexpand_funcs)(copyID);
// 'operatorfunc' callback
ABORTING(set_ref_in_opfunc)(copyID);
// 'tagfunc' callback
ABORTING(set_ref_in_tagfunc)(copyID);
FOR_ALL_TAB_WINDOWS(tp, wp) {
// window-local variables
ABORTING(set_ref_in_item)(&wp->w_winvar.di_tv, copyID, NULL, NULL);
@ -5860,6 +5875,7 @@ bool callback_from_typval(Callback *const callback, typval_T *const arg)
return true;
}
/// @return whether the callback could be called.
bool callback_call(Callback *const callback, const int argcount_in, typval_T *const argvars_in,
typval_T *const rettv)
FUNC_ATTR_NONNULL_ALL
@ -5909,8 +5925,8 @@ bool callback_call(Callback *const callback, const int argcount_in, typval_T *co
return call_func(name, -1, rettv, argcount_in, argvars_in, &funcexe);
}
static bool set_ref_in_callback(Callback *callback, int copyID, ht_stack_T **ht_stack,
list_stack_T **list_stack)
bool set_ref_in_callback(Callback *callback, int copyID, ht_stack_T **ht_stack,
list_stack_T **list_stack)
{
typval_T tv;
switch (callback->type) {
@ -7794,19 +7810,19 @@ void ex_execute(exarg_T *eap)
///
/// @return NULL when no option name found. Otherwise pointer to the char
/// after the option name.
const char *find_option_end(const char **const arg, int *const opt_flags)
const char *find_option_end(const char **const arg, int *const scope)
{
const char *p = *arg;
p++;
if (*p == 'g' && p[1] == ':') {
*opt_flags = OPT_GLOBAL;
*scope = OPT_GLOBAL;
p += 2;
} else if (*p == 'l' && p[1] == ':') {
*opt_flags = OPT_LOCAL;
*scope = OPT_LOCAL;
p += 2;
} else {
*opt_flags = 0;
*scope = 0;
}
if (!ASCII_ISALPHA(*p)) {
@ -8705,9 +8721,9 @@ bool invoke_prompt_interrupt(void)
argv[0].v_type = VAR_UNKNOWN;
got_int = false; // don't skip executing commands
callback_call(&curbuf->b_prompt_interrupt, 0, argv, &rettv);
int ret = callback_call(&curbuf->b_prompt_interrupt, 0, argv, &rettv);
tv_clear(&rettv);
return true;
return ret != FAIL;
}
/// Compare "typ1" and "typ2". Put the result in "typ1".

View File

@ -1394,7 +1394,7 @@ func_call_skip_call:
}
/// call the 'callback' function and return the result as a number.
/// Returns -1 when calling the function fails. Uses argv[0] to argv[argc - 1]
/// Returns -2 when calling the function fails. Uses argv[0] to argv[argc - 1]
/// for the function arguments. argv[argc] should have type VAR_UNKNOWN.
///
/// @param argcount number of "argvars"
@ -1403,7 +1403,7 @@ varnumber_T callback_call_retnr(Callback *callback, int argcount, typval_T *argv
{
typval_T rettv;
if (!callback_call(callback, argcount, argvars, &rettv)) {
return -1;
return -2;
}
varnumber_T retval = tv_get_number_chk(&rettv, NULL);

View File

@ -560,8 +560,6 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo
{
char *arg_end = NULL;
int len;
int opt_flags;
char *tofree = NULL;
// ":let $VAR = expr": Set environment variable.
if (*arg == '$') {
@ -582,12 +580,12 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo
&& vim_strchr(endchars, *skipwhite(arg)) == NULL) {
emsg(_(e_letunexp));
} else if (!check_secure()) {
char *tofree = NULL;
const char c1 = name[len];
name[len] = NUL;
const char *p = tv_get_string_chk(tv);
if (p != NULL && op != NULL && *op == '.') {
char *s = vim_getenv(name);
if (s != NULL) {
tofree = concat_str(s, p);
p = (const char *)tofree;
@ -611,7 +609,8 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo
return NULL;
}
// Find the end of the name.
char *const p = (char *)find_option_end((const char **)&arg, &opt_flags);
int scope;
char *const p = (char *)find_option_end((const char **)&arg, &scope);
if (p == NULL
|| (endchars != NULL
&& vim_strchr(endchars, *skipwhite(p)) == NULL)) {
@ -623,11 +622,13 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo
char *stringval = NULL;
const char *s = NULL;
bool failed = false;
uint32_t opt_p_flags;
char *tofree = NULL;
const char c1 = *p;
*p = NUL;
opt_type = get_option_value(arg, &numval, &stringval, opt_flags);
opt_type = get_option_value(arg, &numval, &stringval, &opt_p_flags, scope);
if (opt_type == gov_bool
|| opt_type == gov_number
|| opt_type == gov_hidden_bool
@ -636,8 +637,13 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo
n = (long)tv_get_number(tv);
}
// Avoid setting a string option to the text "v:false" or similar.
if (tv->v_type != VAR_BOOL && tv->v_type != VAR_SPECIAL) {
if ((opt_p_flags & P_FUNC) && tv_is_func(*tv)) {
// If the option can be set to a function reference or a lambda
// and the passed value is a function reference, then convert it to
// the name (string) of the function reference.
s = tofree = encode_tv2string(tv, NULL);
} else if (tv->v_type != VAR_BOOL && tv->v_type != VAR_SPECIAL) {
// Avoid setting a string option to the text "v:false" or similar.
s = tv_get_string_chk(tv);
}
@ -674,7 +680,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo
if (!failed) {
if (opt_type != gov_string || s != NULL) {
char *err = set_option_value(arg, n, s, opt_flags);
char *err = set_option_value(arg, n, s, scope);
arg_end = p;
if (err != NULL) {
emsg(_(err));
@ -685,6 +691,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo
}
*p = c1;
xfree(stringval);
xfree(tofree);
}
// ":let @r = expr": Set register contents.
} else if (*arg == '@') {

View File

@ -29,14 +29,14 @@ local type_flags={
}
local redraw_flags={
ui_option='P_UI_OPTION',
tabline='P_RTABL',
statuslines='P_RSTAT',
tabline = 'P_RTABL',
current_window='P_RWIN',
current_window_only='P_RWINONLY',
current_buffer='P_RBUF',
all_windows='P_RALL',
curswant='P_CURSWANT',
ui_option='P_UI_OPTION',
}
local list_flags={
@ -78,6 +78,7 @@ local get_flags = function(o)
{'deny_in_modelines', 'P_NO_ML'},
{'deny_duplicates', 'P_NODUP'},
{'modelineexpr', 'P_MLE'},
{'func'}
}) do
local key_name = flag_desc[1]
local def_name = flag_desc[2] or ('P_' .. key_name:upper())

View File

@ -2233,7 +2233,7 @@ static Callback tsrfu_cb; ///< 'thesaurusfunc' callback function
static void copy_global_to_buflocal_cb(Callback *globcb, Callback *bufcb)
{
callback_free(bufcb);
if (globcb->data.funcref != NULL && *globcb->data.funcref != NUL) {
if (globcb->type != kCallbackNone) {
callback_copy(bufcb, globcb);
}
}
@ -2290,17 +2290,26 @@ int set_thesaurusfunc_option(void)
if (*curbuf->b_p_tsrfu != NUL) {
// buffer-local option set
callback_free(&curbuf->b_tsrfu_cb);
retval = option_set_callback_func(curbuf->b_p_tsrfu, &curbuf->b_tsrfu_cb);
} else {
// global option set
callback_free(&tsrfu_cb);
retval = option_set_callback_func(p_tsrfu, &tsrfu_cb);
}
return retval;
}
/// Mark the global 'completefunc' 'omnifunc' and 'thesaurusfunc' callbacks with
/// "copyID" so that they are not garbage collected.
bool set_ref_in_insexpand_funcs(int copyID)
{
bool abort = set_ref_in_callback(&cfu_cb, copyID, NULL, NULL);
abort = abort || set_ref_in_callback(&ofu_cb, copyID, NULL, NULL);
abort = abort || set_ref_in_callback(&tsrfu_cb, copyID, NULL, NULL);
return abort;
}
/// Get the user-defined completion function name for completion "type"
static char_u *get_complete_funcname(int type)
{

View File

@ -5606,6 +5606,13 @@ void free_operatorfunc_option(void)
}
#endif
/// Mark the global 'operatorfunc' callback with "copyID" so that it is not
/// garbage collected.
bool set_ref_in_opfunc(int copyID)
{
return set_ref_in_callback(&opfunc_cb, copyID, NULL, NULL);
}
/// Handle the "g@" operator: call 'operatorfunc'.
static void op_function(const oparg_T *oap)
FUNC_ATTR_NONNULL_ALL

View File

@ -2842,6 +2842,7 @@ int findoption(const char *const arg)
/// Gets the value for an option.
///
/// @param stringval NULL when only checking existence
/// @param flagsp set to the option flags (P_xxxx) (if not NULL)
///
/// @returns:
/// Number option: gov_number, *numval gets value.
@ -2851,7 +2852,8 @@ int findoption(const char *const arg)
/// Hidden Toggle option: gov_hidden_bool.
/// Hidden String option: gov_hidden_string.
/// Unknown option: gov_unknown.
getoption_T get_option_value(const char *name, long *numval, char **stringval, int opt_flags)
getoption_T get_option_value(const char *name, long *numval, char **stringval, uint32_t *flagsp,
int scope)
{
if (get_tty_option(name, stringval)) {
return gov_string;
@ -2862,7 +2864,12 @@ getoption_T get_option_value(const char *name, long *numval, char **stringval, i
return gov_unknown;
}
char_u *varp = (char_u *)get_varp_scope(&(options[opt_idx]), opt_flags);
char_u *varp = (char_u *)get_varp_scope(&(options[opt_idx]), scope);
if (flagsp != NULL) {
// Return the P_xxxx option flags.
*flagsp = options[opt_idx].flags;
}
if (options[opt_idx].flags & P_STRING) {
if (varp == NULL) { // hidden option
@ -3092,7 +3099,7 @@ char *set_option_value(const char *const name, const long number, const char *co
numval = -1;
} else {
char *s = NULL;
(void)get_option_value(name, &numval, &s, OPT_GLOBAL);
(void)get_option_value(name, &numval, &s, NULL, OPT_GLOBAL);
}
}
if (flags & P_NUM) {
@ -3701,15 +3708,17 @@ void unset_global_local_option(char *name, void *from)
}
/// Get pointer to option variable, depending on local or global scope.
char *get_varp_scope(vimoption_T *p, int opt_flags)
///
/// @param scope can be OPT_LOCAL, OPT_GLOBAL or a combination.
char *get_varp_scope(vimoption_T *p, int scope)
{
if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE) {
if ((scope & OPT_GLOBAL) && p->indir != PV_NONE) {
if (p->var == VAR_WIN) {
return GLOBAL_WO(get_varp(p));
}
return (char *)p->var;
}
if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH)) {
if ((scope & OPT_LOCAL) && ((int)p->indir & PV_BOTH)) {
switch ((int)p->indir) {
case PV_FP:
return (char *)&(curbuf->b_p_fp);
@ -4863,9 +4872,9 @@ void ExpandOldSetting(int *num_file, char ***file)
/// NameBuff[]. Must not be called with a hidden option!
///
/// @param opt_flags OPT_GLOBAL and/or OPT_LOCAL
static void option_value2string(vimoption_T *opp, int opt_flags)
static void option_value2string(vimoption_T *opp, int scope)
{
char_u *varp = (char_u *)get_varp_scope(opp, opt_flags);
char_u *varp = (char_u *)get_varp_scope(opp, scope);
if (opp->flags & P_NUM) {
long wc = 0;
@ -5184,7 +5193,7 @@ int option_set_callback_func(char *optval, Callback *optcb)
}
Callback cb;
if (!callback_from_typval(&cb, tv)) {
if (!callback_from_typval(&cb, tv) || cb.type == kCallbackNone) {
tv_free(tv);
return FAIL;
}

View File

@ -24,6 +24,7 @@
#define P_NO_MKRC 0x200U ///< don't include in :mkvimrc output
// when option changed, what to display:
#define P_UI_OPTION 0x400U ///< send option to remote UI
#define P_RTABL 0x800U ///< redraw tabline
#define P_RSTAT 0x1000U ///< redraw status lines
#define P_RWIN 0x2000U ///< redraw current window and recompute text
@ -50,9 +51,9 @@
#define P_NDNAME 0x8000000U ///< only normal dir name chars allowed
#define P_RWINONLY 0x10000000U ///< only redraw current window
#define P_MLE 0x20000000U ///< under control of 'modelineexpr'
#define P_FUNC 0x40000000U ///< accept a function reference or a lambda
#define P_NO_DEF_EXP 0x40000000U ///< Do not expand default value.
#define P_UI_OPTION 0x80000000U ///< send option to remote ui
#define P_NO_DEF_EXP 0x80000000U ///< Do not expand default value.
/// Flags for option-setting functions
///

View File

@ -10,6 +10,7 @@
-- secure=nil, gettext=nil, noglob=nil, normal_fname_chars=nil,
-- pri_mkrc=nil, deny_in_modelines=nil, normal_dname_chars=nil,
-- modelineexpr=nil,
-- func=nil,
-- expand=nil, nodefault=nil, no_mkrc=nil,
-- alloced=nil,
-- save_pv_indir=nil,
@ -455,6 +456,7 @@ return {
type='string', scope={'buffer'},
secure=true,
alloced=true,
func=true,
varname='p_cfu',
defaults={if_true=""}
},
@ -1638,6 +1640,7 @@ return {
type='string', scope={'buffer'},
secure=true,
alloced=true,
func=true,
varname='p_ofu',
defaults={if_true=""}
},
@ -1653,6 +1656,7 @@ return {
short_desc=N_("function to be called for |g@| operator"),
type='string', scope={'global'},
secure=true,
func=true,
varname='p_opfunc',
defaults={if_true=""}
},
@ -1835,6 +1839,8 @@ return {
full_name='quickfixtextfunc', abbreviation='qftf',
short_desc=N_("customize the quickfix window"),
type='string', scope={'global'},
secure=true,
func=true,
varname='p_qftf',
defaults={if_true=""}
},
@ -2408,6 +2414,8 @@ return {
full_name='tagfunc', abbreviation='tfu',
short_desc=N_("function used to perform tag searches"),
type='string', scope={'buffer'},
secure=true,
func=true,
varname='p_tfu',
defaults={if_true=""}
},
@ -2538,6 +2546,7 @@ return {
type='string', scope={'global', 'buffer'},
secure=true,
alloced=true,
func=true,
varname='p_tsrfu',
defaults={if_true=""}
},

View File

@ -6686,7 +6686,8 @@ int set_errorlist(win_T *wp, list_T *list, int action, char *title, dict_T *what
return retval;
}
/// Mark the context as in use for all the lists in a quickfix stack.
/// Mark the quickfix context and callback function as in use for all the lists
/// in a quickfix stack.
static bool mark_quickfix_ctx(qf_info_T *qi, int copyID)
{
bool abort = false;
@ -6695,8 +6696,11 @@ static bool mark_quickfix_ctx(qf_info_T *qi, int copyID)
typval_T *ctx = qi->qf_lists[i].qf_ctx;
if (ctx != NULL && ctx->v_type != VAR_NUMBER
&& ctx->v_type != VAR_STRING && ctx->v_type != VAR_FLOAT) {
abort = set_ref_in_item(ctx, copyID, NULL, NULL);
abort = abort || set_ref_in_item(ctx, copyID, NULL, NULL);
}
Callback *cb = &qi->qf_lists[i].qf_qftf_cb;
abort = abort || set_ref_in_callback(cb, copyID, NULL, NULL);
}
return abort;
@ -6711,6 +6715,11 @@ bool set_ref_in_quickfix(int copyID)
return abort;
}
abort = set_ref_in_callback(&qftf_cb, copyID, NULL, NULL);
if (abort) {
return abort;
}
FOR_ALL_TAB_WINDOWS(tp, win) {
if (win->w_llist != NULL) {
abort = mark_quickfix_ctx(win->w_llist, copyID);

View File

@ -3145,7 +3145,7 @@ void ex_spelldump(exarg_T *eap)
}
char *spl;
long dummy;
(void)get_option_value("spl", &dummy, &spl, OPT_LOCAL);
(void)get_option_value("spl", &dummy, &spl, NULL, OPT_LOCAL);
// Create a new empty buffer in a new window.
do_cmdline_cmd("new");

View File

@ -149,12 +149,19 @@ void free_tagfunc_option(void)
}
#endif
/// Mark the global 'tagfunc' callback with "copyID" so that it is not garbage
/// collected.
bool set_ref_in_tagfunc(int copyID)
{
return set_ref_in_callback(&tfu_cb, copyID, NULL, NULL);
}
/// Copy the global 'tagfunc' callback function to the buffer-local 'tagfunc'
/// callback for 'buf'.
void set_buflocal_tfu_callback(buf_T *buf)
{
callback_free(&buf->b_tfu_cb);
if (tfu_cb.data.funcref != NULL && *tfu_cb.data.funcref != NUL) {
if (tfu_cb.type != kCallbackNone) {
callback_copy(&buf->b_tfu_cb, &tfu_cb);
}
}
@ -1153,7 +1160,7 @@ static int find_tagfunc_tags(char_u *pat, garray_T *ga, int *match_count, int fl
}
}
if (*curbuf->b_p_tfu == NUL) {
if (*curbuf->b_p_tfu == NUL || curbuf->b_tfu_cb.type == kCallbackNone) {
return FAIL;
}

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,7 @@
source shared.vim
source check.vim
source view_util.vim
source vim9.vim
source screendump.vim
func Setup_NewWindow()
@ -388,70 +389,6 @@ func Test_normal09a_operatorfunc()
norm V10j,,
call assert_equal(22, g:a)
" Use a lambda function for 'opfunc'
unmap <buffer> ,,
call cursor(1, 1)
let g:a=0
nmap <buffer><silent> ,, :set opfunc={type\ ->\ CountSpaces(type)}<CR>g@
vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR>
50
norm V2j,,
call assert_equal(6, g:a)
norm V,,
call assert_equal(2, g:a)
norm ,,l
call assert_equal(0, g:a)
50
exe "norm 0\<c-v>10j2l,,"
call assert_equal(11, g:a)
50
norm V10j,,
call assert_equal(22, g:a)
" use a partial function for 'opfunc'
let g:OpVal = 0
func! Test_opfunc1(x, y, type)
let g:OpVal = a:x + a:y
endfunc
set opfunc=function('Test_opfunc1',\ [5,\ 7])
normal! g@l
call assert_equal(12, g:OpVal)
" delete the function and try to use g@
delfunc Test_opfunc1
call test_garbagecollect_now()
call assert_fails('normal! g@l', 'E117:')
set opfunc=
" use a funcref for 'opfunc'
let g:OpVal = 0
func! Test_opfunc2(x, y, type)
let g:OpVal = a:x + a:y
endfunc
set opfunc=funcref('Test_opfunc2',\ [4,\ 3])
normal! g@l
call assert_equal(7, g:OpVal)
" delete the function and try to use g@
delfunc Test_opfunc2
call test_garbagecollect_now()
call assert_fails('normal! g@l', 'E933:')
set opfunc=
" Try to use a function with two arguments for 'operatorfunc'
let g:OpVal = 0
func! Test_opfunc3(x, y)
let g:OpVal = 4
endfunc
set opfunc=Test_opfunc3
call assert_fails('normal! g@l', 'E119:')
call assert_equal(0, g:OpVal)
set opfunc=
delfunc Test_opfunc3
unlet g:OpVal
" Try to use a lambda function with two arguments for 'operatorfunc'
set opfunc={x,\ y\ ->\ 'done'}
call assert_fails('normal! g@l', 'E119:')
" clean up
unmap <buffer> ,,
set opfunc=
@ -520,6 +457,182 @@ func Test_normal09c_operatorfunc()
set operatorfunc=
endfunc
" Test for different ways of setting the 'operatorfunc' option
func Test_opfunc_callback()
new
func OpFunc1(callnr, type)
let g:OpFunc1Args = [a:callnr, a:type]
endfunc
func OpFunc2(type)
let g:OpFunc2Args = [a:type]
endfunc
let lines =<< trim END
#" Test for using a function name
LET &opfunc = 'g:OpFunc2'
LET g:OpFunc2Args = []
normal! g@l
call assert_equal(['char'], g:OpFunc2Args)
#" Test for using a function()
set opfunc=function('g:OpFunc1',\ [10])
LET g:OpFunc1Args = []
normal! g@l
call assert_equal([10, 'char'], g:OpFunc1Args)
#" Using a funcref variable to set 'operatorfunc'
VAR Fn = function('g:OpFunc1', [11])
LET &opfunc = Fn
LET g:OpFunc1Args = []
normal! g@l
call assert_equal([11, 'char'], g:OpFunc1Args)
#" Using a string(funcref_variable) to set 'operatorfunc'
LET Fn = function('g:OpFunc1', [12])
LET &operatorfunc = string(Fn)
LET g:OpFunc1Args = []
normal! g@l
call assert_equal([12, 'char'], g:OpFunc1Args)
#" Test for using a funcref()
set operatorfunc=funcref('g:OpFunc1',\ [13])
LET g:OpFunc1Args = []
normal! g@l
call assert_equal([13, 'char'], g:OpFunc1Args)
#" Using a funcref variable to set 'operatorfunc'
LET Fn = funcref('g:OpFunc1', [14])
LET &opfunc = Fn
LET g:OpFunc1Args = []
normal! g@l
call assert_equal([14, 'char'], g:OpFunc1Args)
#" Using a string(funcref_variable) to set 'operatorfunc'
LET Fn = funcref('g:OpFunc1', [15])
LET &opfunc = string(Fn)
LET g:OpFunc1Args = []
normal! g@l
call assert_equal([15, 'char'], g:OpFunc1Args)
#" Test for using a lambda function using set
VAR optval = "LSTART a LMIDDLE OpFunc1(16, a) LEND"
LET optval = substitute(optval, ' ', '\\ ', 'g')
exe "set opfunc=" .. optval
LET g:OpFunc1Args = []
normal! g@l
call assert_equal([16, 'char'], g:OpFunc1Args)
#" Test for using a lambda function using LET
LET &opfunc = LSTART a LMIDDLE OpFunc1(17, a) LEND
LET g:OpFunc1Args = []
normal! g@l
call assert_equal([17, 'char'], g:OpFunc1Args)
#" Set 'operatorfunc' to a string(lambda expression)
LET &opfunc = 'LSTART a LMIDDLE OpFunc1(18, a) LEND'
LET g:OpFunc1Args = []
normal! g@l
call assert_equal([18, 'char'], g:OpFunc1Args)
#" Set 'operatorfunc' to a variable with a lambda expression
VAR Lambda = LSTART a LMIDDLE OpFunc1(19, a) LEND
LET &opfunc = Lambda
LET g:OpFunc1Args = []
normal! g@l
call assert_equal([19, 'char'], g:OpFunc1Args)
#" Set 'operatorfunc' to a string(variable with a lambda expression)
LET Lambda = LSTART a LMIDDLE OpFunc1(20, a) LEND
LET &opfunc = string(Lambda)
LET g:OpFunc1Args = []
normal! g@l
call assert_equal([20, 'char'], g:OpFunc1Args)
#" Try to use 'operatorfunc' after the function is deleted
func g:TmpOpFunc1(type)
let g:TmpOpFunc1Args = [21, a:type]
endfunc
LET &opfunc = function('g:TmpOpFunc1')
delfunc g:TmpOpFunc1
call test_garbagecollect_now()
LET g:TmpOpFunc1Args = []
call assert_fails('normal! g@l', 'E117:')
call assert_equal([], g:TmpOpFunc1Args)
#" Try to use a function with two arguments for 'operatorfunc'
func g:TmpOpFunc2(x, y)
let g:TmpOpFunc2Args = [a:x, a:y]
endfunc
set opfunc=TmpOpFunc2
LET g:TmpOpFunc2Args = []
call assert_fails('normal! g@l', 'E119:')
call assert_equal([], g:TmpOpFunc2Args)
delfunc TmpOpFunc2
#" Try to use a lambda function with two arguments for 'operatorfunc'
LET &opfunc = LSTART a, b LMIDDLE OpFunc1(22, b) LEND
LET g:OpFunc1Args = []
call assert_fails('normal! g@l', 'E119:')
call assert_equal([], g:OpFunc1Args)
#" Test for clearing the 'operatorfunc' option
set opfunc=''
set opfunc&
call assert_fails("set opfunc=function('abc')", "E700:")
call assert_fails("set opfunc=funcref('abc')", "E700:")
#" set 'operatorfunc' to a non-existing function
LET &opfunc = function('g:OpFunc1', [23])
call assert_fails("set opfunc=function('NonExistingFunc')", 'E700:')
call assert_fails("LET &opfunc = function('NonExistingFunc')", 'E700:')
LET g:OpFunc1Args = []
normal! g@l
call assert_equal([23, 'char'], g:OpFunc1Args)
END
call CheckTransLegacySuccess(lines)
" Using Vim9 lambda expression in legacy context should fail
" set opfunc=(a)\ =>\ OpFunc1(24,\ a)
let g:OpFunc1Args = []
" call assert_fails('normal! g@l', 'E117:')
call assert_equal([], g:OpFunc1Args)
" set 'operatorfunc' to a partial with dict. This used to cause a crash.
func SetOpFunc()
let operator = {'execute': function('OperatorExecute')}
let &opfunc = operator.execute
endfunc
func OperatorExecute(_) dict
endfunc
call SetOpFunc()
call test_garbagecollect_now()
set operatorfunc=
delfunc SetOpFunc
delfunc OperatorExecute
" Vim9 tests
let lines =<< trim END
vim9script
# Test for using a def function with opfunc
def g:Vim9opFunc(val: number, type: string): void
g:OpFunc1Args = [val, type]
enddef
set opfunc=function('g:Vim9opFunc',\ [60])
g:OpFunc1Args = []
normal! g@l
assert_equal([60, 'char'], g:OpFunc1Args)
END
" call CheckScriptSuccess(lines)
" cleanup
set opfunc&
delfunc OpFunc1
delfunc OpFunc2
unlet g:OpFunc1Args g:OpFunc2Args
%bw!
endfunc
func Test_normal10_expand()
" Test for expand()
10new

View File

@ -1,6 +1,7 @@
" Test for the quickfix feature.
source check.vim
source vim9.vim
CheckFeature quickfix
source screendump.vim
@ -5690,6 +5691,138 @@ func Test_qftextfunc()
call Xtest_qftextfunc('l')
endfunc
func Test_qftextfunc_callback()
let lines =<< trim END
set efm=%f:%l:%c:%m
#" Test for using a function name
LET &qftf = 'g:Tqfexpr'
cexpr "F0:0:0:L0"
copen
call assert_equal('F0-L0C0-L0', getline(1))
cclose
#" Test for using a function()
set qftf=function('g:Tqfexpr')
cexpr "F1:1:1:L1"
copen
call assert_equal('F1-L1C1-L1', getline(1))
cclose
#" Using a funcref variable to set 'quickfixtextfunc'
VAR Fn = function('g:Tqfexpr')
LET &qftf = Fn
cexpr "F2:2:2:L2"
copen
call assert_equal('F2-L2C2-L2', getline(1))
cclose
#" Using string(funcref_variable) to set 'quickfixtextfunc'
LET Fn = function('g:Tqfexpr')
LET &qftf = string(Fn)
cexpr "F3:3:3:L3"
copen
call assert_equal('F3-L3C3-L3', getline(1))
cclose
#" Test for using a funcref()
set qftf=funcref('g:Tqfexpr')
cexpr "F4:4:4:L4"
copen
call assert_equal('F4-L4C4-L4', getline(1))
cclose
#" Using a funcref variable to set 'quickfixtextfunc'
LET Fn = funcref('g:Tqfexpr')
LET &qftf = Fn
cexpr "F5:5:5:L5"
copen
call assert_equal('F5-L5C5-L5', getline(1))
cclose
#" Using a string(funcref_variable) to set 'quickfixtextfunc'
LET Fn = funcref('g:Tqfexpr')
LET &qftf = string(Fn)
cexpr "F5:5:5:L5"
copen
call assert_equal('F5-L5C5-L5', getline(1))
cclose
#" Test for using a lambda function with set
VAR optval = "LSTART a LMIDDLE Tqfexpr(a) LEND"
LET optval = substitute(optval, ' ', '\\ ', 'g')
exe "set qftf=" .. optval
cexpr "F6:6:6:L6"
copen
call assert_equal('F6-L6C6-L6', getline(1))
cclose
#" Set 'quickfixtextfunc' to a lambda expression
LET &qftf = LSTART a LMIDDLE Tqfexpr(a) LEND
cexpr "F7:7:7:L7"
copen
call assert_equal('F7-L7C7-L7', getline(1))
cclose
#" Set 'quickfixtextfunc' to string(lambda_expression)
LET &qftf = "LSTART a LMIDDLE Tqfexpr(a) LEND"
cexpr "F8:8:8:L8"
copen
call assert_equal('F8-L8C8-L8', getline(1))
cclose
#" Set 'quickfixtextfunc' to a variable with a lambda expression
VAR Lambda = LSTART a LMIDDLE Tqfexpr(a) LEND
LET &qftf = Lambda
cexpr "F9:9:9:L9"
copen
call assert_equal('F9-L9C9-L9', getline(1))
cclose
#" Set 'quickfixtextfunc' to a string(variable with a lambda expression)
LET Lambda = LSTART a LMIDDLE Tqfexpr(a) LEND
LET &qftf = string(Lambda)
cexpr "F9:9:9:L9"
copen
call assert_equal('F9-L9C9-L9', getline(1))
cclose
END
call CheckLegacyAndVim9Success(lines)
" set 'quickfixtextfunc' to a partial with dict. This used to cause a crash.
func SetQftfFunc()
let params = {'qftf': function('g:DictQftfFunc')}
let &quickfixtextfunc = params.qftf
endfunc
func g:DictQftfFunc(_) dict
endfunc
call SetQftfFunc()
new
call SetQftfFunc()
bw
call test_garbagecollect_now()
new
set qftf=
wincmd w
set qftf=
:%bw!
" set per-quickfix list 'quickfixtextfunc' to a partial with dict. This used
" to cause a crash.
let &qftf = ''
func SetLocalQftfFunc()
let params = {'qftf': function('g:DictQftfFunc')}
call setqflist([], 'a', {'quickfixtextfunc' : params.qftf})
endfunc
call SetLocalQftfFunc()
call test_garbagecollect_now()
call setqflist([], 'a', {'quickfixtextfunc' : ''})
delfunc g:DictQftfFunc
delfunc SetQftfFunc
delfunc SetLocalQftfFunc
set efm&
endfunc
" Test for updating a location list for some other window and check that
" 'qftextfunc' uses the correct location list.
func Test_qftextfunc_other_loclist()

View File

@ -1,5 +1,7 @@
" Test 'tagfunc'
source vim9.vim
func TagFunc(pat, flag, info)
let g:tagfunc_args = [a:pat, a:flag, a:info]
let tags = []
@ -125,45 +127,153 @@ endfunc
" Test for different ways of setting the 'tagfunc' option
func Test_tagfunc_callback()
" Test for using a function()
func MytagFunc1(pat, flags, info)
let g:MytagFunc1_args = [a:pat, a:flags, a:info]
func TagFunc1(callnr, pat, flags, info)
let g:TagFunc1Args = [a:callnr, a:pat, a:flags, a:info]
return v:null
endfunc
set tagfunc=function('MytagFunc1')
new | only
let g:MytagFunc1_args = []
call assert_fails('tag a11', 'E433:')
call assert_equal(['a11', '', {}], g:MytagFunc1_args)
" Using a funcref variable to set 'tagfunc'
let Fn = function('MytagFunc1')
let &tagfunc = string(Fn)
new | only
let g:MytagFunc1_args = []
call assert_fails('tag a12', 'E433:')
call assert_equal(['a12', '', {}], g:MytagFunc1_args)
call assert_fails('let &tagfunc = Fn', 'E729:')
" Test for using a funcref()
func MytagFunc2(pat, flags, info)
let g:MytagFunc2_args = [a:pat, a:flags, a:info]
func TagFunc2(pat, flags, info)
let g:TagFunc2Args = [a:pat, a:flags, a:info]
return v:null
endfunc
set tagfunc=funcref('MytagFunc2')
new | only
let g:MytagFunc2_args = []
call assert_fails('tag a13', 'E433:')
call assert_equal(['a13', '', {}], g:MytagFunc2_args)
" Using a funcref variable to set 'tagfunc'
let Fn = funcref('MytagFunc2')
let &tagfunc = string(Fn)
let lines =<< trim END
#" Test for using a function name
LET &tagfunc = 'g:TagFunc2'
new
LET g:TagFunc2Args = []
call assert_fails('tag a10', 'E433:')
call assert_equal(['a10', '', {}], g:TagFunc2Args)
bw!
#" Test for using a function()
set tagfunc=function('g:TagFunc1',\ [10])
new
LET g:TagFunc1Args = []
call assert_fails('tag a11', 'E433:')
call assert_equal([10, 'a11', '', {}], g:TagFunc1Args)
bw!
#" Using a funcref variable to set 'tagfunc'
VAR Fn = function('g:TagFunc1', [11])
LET &tagfunc = Fn
new
LET g:TagFunc1Args = []
call assert_fails('tag a12', 'E433:')
call assert_equal([11, 'a12', '', {}], g:TagFunc1Args)
bw!
#" Using a string(funcref_variable) to set 'tagfunc'
LET Fn = function('g:TagFunc1', [12])
LET &tagfunc = string(Fn)
new
LET g:TagFunc1Args = []
call assert_fails('tag a12', 'E433:')
call assert_equal([12, 'a12', '', {}], g:TagFunc1Args)
bw!
#" Test for using a funcref()
set tagfunc=funcref('g:TagFunc1',\ [13])
new
LET g:TagFunc1Args = []
call assert_fails('tag a13', 'E433:')
call assert_equal([13, 'a13', '', {}], g:TagFunc1Args)
bw!
#" Using a funcref variable to set 'tagfunc'
LET Fn = funcref('g:TagFunc1', [14])
LET &tagfunc = Fn
new
LET g:TagFunc1Args = []
call assert_fails('tag a14', 'E433:')
call assert_equal([14, 'a14', '', {}], g:TagFunc1Args)
bw!
#" Using a string(funcref_variable) to set 'tagfunc'
LET Fn = funcref('g:TagFunc1', [15])
LET &tagfunc = string(Fn)
new
LET g:TagFunc1Args = []
call assert_fails('tag a14', 'E433:')
call assert_equal([15, 'a14', '', {}], g:TagFunc1Args)
bw!
#" Test for using a lambda function
VAR optval = "LSTART a, b, c LMIDDLE TagFunc1(16, a, b, c) LEND"
LET optval = substitute(optval, ' ', '\\ ', 'g')
exe "set tagfunc=" .. optval
new
LET g:TagFunc1Args = []
call assert_fails('tag a17', 'E433:')
call assert_equal([16, 'a17', '', {}], g:TagFunc1Args)
bw!
#" Set 'tagfunc' to a lambda expression
LET &tagfunc = LSTART a, b, c LMIDDLE TagFunc1(17, a, b, c) LEND
new
LET g:TagFunc1Args = []
call assert_fails('tag a18', 'E433:')
call assert_equal([17, 'a18', '', {}], g:TagFunc1Args)
bw!
#" Set 'tagfunc' to a string(lambda expression)
LET &tagfunc = 'LSTART a, b, c LMIDDLE TagFunc1(18, a, b, c) LEND'
new
LET g:TagFunc1Args = []
call assert_fails('tag a18', 'E433:')
call assert_equal([18, 'a18', '', {}], g:TagFunc1Args)
bw!
#" Set 'tagfunc' to a variable with a lambda expression
VAR Lambda = LSTART a, b, c LMIDDLE TagFunc1(19, a, b, c) LEND
LET &tagfunc = Lambda
new
LET g:TagFunc1Args = []
call assert_fails("tag a19", "E433:")
call assert_equal([19, 'a19', '', {}], g:TagFunc1Args)
bw!
#" Set 'tagfunc' to a string(variable with a lambda expression)
LET Lambda = LSTART a, b, c LMIDDLE TagFunc1(20, a, b, c) LEND
LET &tagfunc = string(Lambda)
new
LET g:TagFunc1Args = []
call assert_fails("tag a19", "E433:")
call assert_equal([20, 'a19', '', {}], g:TagFunc1Args)
bw!
#" Test for using a lambda function with incorrect return value
LET Lambda = LSTART a, b, c LMIDDLE strlen(a) LEND
LET &tagfunc = string(Lambda)
new
call assert_fails("tag a20", "E987:")
bw!
#" Test for clearing the 'tagfunc' option
set tagfunc=''
set tagfunc&
call assert_fails("set tagfunc=function('abc')", "E700:")
call assert_fails("set tagfunc=funcref('abc')", "E700:")
#" set 'tagfunc' to a non-existing function
LET &tagfunc = function('g:TagFunc2', [21])
LET g:TagFunc2Args = []
call assert_fails("set tagfunc=function('NonExistingFunc')", 'E700:')
call assert_fails("LET &tagfunc = function('NonExistingFunc')", 'E700:')
call assert_fails("tag axb123", 'E426:')
call assert_equal([], g:TagFunc2Args)
bw!
END
call CheckLegacyAndVim9Success(lines)
let &tagfunc = "{a -> 'abc'}"
call assert_fails("echo taglist('a')", "E987:")
" Using Vim9 lambda expression in legacy context should fail
" set tagfunc=(a,\ b,\ c)\ =>\ g:TagFunc1(21,\ a,\ b,\ c)
new | only
let g:MytagFunc2_args = []
call assert_fails('tag a14', 'E433:')
call assert_equal(['a14', '', {}], g:MytagFunc2_args)
call assert_fails('let &tagfunc = Fn', 'E729:')
let g:TagFunc1Args = []
" call assert_fails("tag a17", "E117:")
call assert_equal([], g:TagFunc1Args)
" Test for using a script local function
set tagfunc=<SID>ScriptLocalTagFunc
@ -174,101 +284,60 @@ func Test_tagfunc_callback()
" Test for using a script local funcref variable
let Fn = function("s:ScriptLocalTagFunc")
let &tagfunc= Fn
new | only
let g:ScriptLocalFuncArgs = []
call assert_fails('tag a16', 'E433:')
call assert_equal(['a16', '', {}], g:ScriptLocalFuncArgs)
" Test for using a string(script local funcref variable)
let Fn = function("s:ScriptLocalTagFunc")
let &tagfunc= string(Fn)
new | only
let g:ScriptLocalFuncArgs = []
call assert_fails('tag a16', 'E433:')
call assert_equal(['a16', '', {}], g:ScriptLocalFuncArgs)
" Test for using a lambda function
func MytagFunc3(pat, flags, info)
let g:MytagFunc3_args = [a:pat, a:flags, a:info]
return v:null
" set 'tagfunc' to a partial with dict. This used to cause a crash.
func SetTagFunc()
let params = {'tagfn': function('g:DictTagFunc')}
let &tagfunc = params.tagfn
endfunc
set tagfunc={a,\ b,\ c\ ->\ MytagFunc3(a,\ b,\ c)}
new | only
let g:MytagFunc3_args = []
call assert_fails('tag a17', 'E433:')
call assert_equal(['a17', '', {}], g:MytagFunc3_args)
" Set 'tagfunc' to a lambda expression
let &tagfunc = '{a, b, c -> MytagFunc3(a, b, c)}'
new | only
let g:MytagFunc3_args = []
call assert_fails('tag a18', 'E433:')
call assert_equal(['a18', '', {}], g:MytagFunc3_args)
" Set 'tagfunc' to a variable with a lambda expression
let Lambda = {a, b, c -> MytagFunc3(a, b, c)}
let &tagfunc = string(Lambda)
new | only
let g:MytagFunc3_args = []
call assert_fails("tag a19", "E433:")
call assert_equal(['a19', '', {}], g:MytagFunc3_args)
call assert_fails('let &tagfunc = Lambda', 'E729:')
" Test for using a lambda function with incorrect return value
let Lambda = {s -> strlen(s)}
let &tagfunc = string(Lambda)
new | only
call assert_fails("tag a20", "E987:")
" Test for clearing the 'tagfunc' option
set tagfunc=''
set tagfunc&
call assert_fails("set tagfunc=function('abc')", "E700:")
call assert_fails("set tagfunc=funcref('abc')", "E700:")
let &tagfunc = "{a -> 'abc'}"
call assert_fails("echo taglist('a')", "E987:")
func g:DictTagFunc(_) dict
endfunc
call SetTagFunc()
new
call SetTagFunc()
bw
call test_garbagecollect_now()
new
set tagfunc=
wincmd w
set tagfunc=
:%bw!
delfunc g:DictTagFunc
delfunc SetTagFunc
" Vim9 tests
let lines =<< trim END
vim9script
# Test for using function()
def MytagFunc1(pat: string, flags: string, info: dict<any>): any
g:MytagFunc1_args = [pat, flags, info]
def Vim9tagFunc(val: number, pat: string, flags: string, info: dict<any>): any
g:Vim9tagFuncArgs = [val, pat, flags, info]
return null
enddef
set tagfunc=function('MytagFunc1')
set tagfunc=function('Vim9tagFunc',\ [60])
new | only
g:MytagFunc1_args = []
g:Vim9tagFuncArgs = []
assert_fails('tag a10', 'E433:')
assert_equal(['a10', '', {}], g:MytagFunc1_args)
# Test for using a lambda
def MytagFunc2(pat: string, flags: string, info: dict<any>): any
g:MytagFunc2_args = [pat, flags, info]
return null
enddef
&tagfunc = '(a, b, c) => MytagFunc2(a, b, c)'
new | only
g:MytagFunc2_args = []
assert_fails('tag a20', 'E433:')
assert_equal(['a20', '', {}], g:MytagFunc2_args)
# Test for using a variable with a lambda expression
var Fn: func = (a, b, c) => MytagFunc2(a, b, c)
&tagfunc = string(Fn)
new | only
g:MytagFunc2_args = []
assert_fails('tag a30', 'E433:')
assert_equal(['a30', '', {}], g:MytagFunc2_args)
assert_equal([60, 'a10', '', {}], g:Vim9tagFuncArgs)
END
" call CheckScriptSuccess(lines)
" Using Vim9 lambda expression in legacy context should fail
" set tagfunc=(a,\ b,\ c)\ =>\ g:MytagFunc2(a,\ b,\ c)
" new | only
" let g:MytagFunc3_args = []
" call assert_fails("tag a17", "E117:")
" call assert_equal([], g:MytagFunc3_args)
" cleanup
delfunc MytagFunc1
delfunc MytagFunc2
delfunc MytagFunc3
delfunc TagFunc1
delfunc TagFunc2
set tagfunc&
%bw!
endfunc

80
src/nvim/testdir/vim9.vim Normal file
View File

@ -0,0 +1,80 @@
" Use a different file name for each run.
let s:sequence = 1
" Check that "lines" inside a legacy function has no error.
func CheckLegacySuccess(lines)
let cwd = getcwd()
let fname = 'XlegacySuccess' .. s:sequence
let s:sequence += 1
call writefile(['func Func()'] + a:lines + ['endfunc'], fname)
try
exe 'so ' .. fname
call Func()
finally
delfunc! Func
call chdir(cwd)
call delete(fname)
endtry
endfunc
" Check that "lines" inside a legacy function results in the expected error
func CheckLegacyFailure(lines, error)
let cwd = getcwd()
let fname = 'XlegacyFails' .. s:sequence
let s:sequence += 1
call writefile(['func Func()'] + a:lines + ['endfunc', 'call Func()'], fname)
try
call assert_fails('so ' .. fname, a:error)
finally
delfunc! Func
call chdir(cwd)
call delete(fname)
endtry
endfunc
" Execute "lines" in a legacy function, translated as in
" CheckLegacyAndVim9Success()
func CheckTransLegacySuccess(lines)
let legacylines = a:lines->deepcopy()->map({_, v ->
\ v->substitute('\<VAR\>', 'let', 'g')
\ ->substitute('\<LET\>', 'let', 'g')
\ ->substitute('\<LSTART\>', '{', 'g')
\ ->substitute('\<LMIDDLE\>', '->', 'g')
\ ->substitute('\<LEND\>', '}', 'g')
\ ->substitute('\<TRUE\>', '1', 'g')
\ ->substitute('\<FALSE\>', '0', 'g')
\ ->substitute('#"', ' "', 'g')
\ })
call CheckLegacySuccess(legacylines)
endfunc
" Execute "lines" in a legacy function
" Use 'VAR' for a declaration.
" Use 'LET' for an assignment
" Use ' #"' for a comment
" Use LSTART arg LMIDDLE expr LEND for lambda
" Use 'TRUE' for 1
" Use 'FALSE' for 0
func CheckLegacyAndVim9Success(lines)
call CheckTransLegacySuccess(a:lines)
endfunc
" Execute "lines" in a legacy function
" Use 'VAR' for a declaration.
" Use 'LET' for an assignment
" Use ' #"' for a comment
func CheckLegacyAndVim9Failure(lines, error)
if type(a:error) == type('string')
let legacyError = error
else
let legacyError = error[0]
endif
let legacylines = a:lines->deepcopy()->map({_, v ->
\ v->substitute('\<VAR\>', 'let', 'g')
\ ->substitute('\<LET\>', 'let', 'g')
\ ->substitute('#"', ' "', 'g')
\ })
call CheckLegacyFailure(legacylines, legacyError)
endfunc