Compare commits

...

14 Commits

Author SHA1 Message Date
c03fe66ade patch 8.2.3146: Vim9: line number wrong for :execute argument
Problem:    Vim9: line number wrong for :execute argument.
Solution:   Use the line number of the :execute command itself. (closes #8537)
2021-07-11 16:52:45 +02:00
4ece152ad6 patch 8.2.3145: Vim9: profile test fails without profile feature
Problem:    Vim9: profile test fails without profile feature.
Solution:   Check the profile feature is present.
2021-07-11 16:31:51 +02:00
0f1227f7d5 patch 8.2.3144: Vim9: no error when using an invalid value for a line number
Problem:    Vim9: no error when using an invalid value for a line number.
Solution:   Give an error if the string value is not recognized.
            (closes #8536)
2021-07-11 16:01:58 +02:00
d9162550aa patch 8.2.3143: Vim9: wrong context if lambda called from profiled function
Problem:    Vim9: A lambda may be compiled with the wrong context if it is
            called from a profiled function.
Solution:   Compile the lambda with and without profiling. (closes #8543)
2021-07-11 15:26:13 +02:00
1aeddeb8bd patch 8.2.3142: Vim9: type check for has_key() argument is too strict
Problem:    Vim9: type check for has_key() argument is too strict.
Solution:   Also allow for a number key argument. (closes #8542)
2021-07-11 14:55:49 +02:00
de69a7353e patch 8.2.3141: no error when using :complete for :command without -nargs
Problem:    No error when using :complete for :command without -nargs.
Solution:   Give an error. (Martin Tournoij, closes #8544, closes #8541)
2021-07-11 14:28:25 +02:00
482d2f37a5 patch 8.2.3140: MS-Windows: ipv6 channel test is very flaky also without GUI
Problem:    MS-Windows: ipv6 channel test is very flaky also without the GUI.
Solution:   Skip the test also without the GUI.
2021-07-10 22:21:40 +02:00
a2438132a6 patch 8.2.3139: functions for string manipulation are spread out
Problem:    Functions for string manipulation are spread out.
Solution:   Move string related functions to a new source file. (Yegappan
            Lakshmanan, closes #8470)
2021-07-10 21:29:18 +02:00
31e21766d6 patch 8.2.3138: debugger test fails
Problem:    Debugger test fails.
Solution:   Adjust eval command.
2021-07-10 20:43:59 +02:00
c323527d67 patch 8.2.3137: Vim9: no error when a line only has a variable name
Problem:    Vim9: no error when a line only has a variable name.
Solution:   Give an error when an expression is evaluated without an effect.
            (closes #8538)
2021-07-10 19:42:03 +02:00
fe3418abe0 patch 8.2.3136: no test for E187 and "No swap file"
Problem:    No test for E187 and "No swap file".
Solution:   Add a test. (Dominique Pellé, closes #8540)
2021-07-10 17:59:48 +02:00
5b73992d8f patch 8.2.3135: Vim9: builtin function arguments not checked at compile time
Problem:    Vim9: builtin function arguments not checked at compile time.
Solution:   Add more type checks. (Yegappan Lakshmanan, closes #8539)
2021-07-10 13:15:41 +02:00
9da32e4d57 patch 8.2.3134: crash when using typename() on a function reference
Problem:    Crash when using typename() on a function reference. (Naohiro Ono)
Solution:   Initialize pointer to NULL. (closes #8531)
2021-07-09 19:53:57 +02:00
90fba5627b patch 8.2.3133: Vim9: memory leak when add() fails
Problem:    Vim9: memory leak when add() fails.
Solution:   Allocate listitem_T after type check.
2021-07-09 19:17:55 +02:00
44 changed files with 2452 additions and 1861 deletions

View File

@ -134,6 +134,7 @@ SRC_ALL = \
src/spell.h \
src/spellfile.c \
src/spellsuggest.c \
src/strings.c \
src/structs.h \
src/syntax.c \
src/tag.c \
@ -296,6 +297,7 @@ SRC_ALL = \
src/proto/spell.pro \
src/proto/spellfile.pro \
src/proto/spellsuggest.pro \
src/proto/strings.pro \
src/proto/syntax.pro \
src/proto/tag.pro \
src/proto/term.pro \

View File

@ -162,6 +162,7 @@ SRC += \
spell.c \
spellfile.c \
spellsuggest.c \
strings.c \
syntax.c \
tag.c \
term.c \

View File

@ -809,6 +809,7 @@ OBJ = \
$(OUTDIR)/spell.o \
$(OUTDIR)/spellfile.o \
$(OUTDIR)/spellsuggest.o \
$(OUTDIR)/strings.o \
$(OUTDIR)/syntax.o \
$(OUTDIR)/tag.o \
$(OUTDIR)/term.o \

View File

@ -819,6 +819,7 @@ OBJ = \
$(OUTDIR)\spell.obj \
$(OUTDIR)\spellfile.obj \
$(OUTDIR)\spellsuggest.obj \
$(OUTDIR)\strings.obj \
$(OUTDIR)\syntax.obj \
$(OUTDIR)\tag.obj \
$(OUTDIR)\term.obj \
@ -1792,6 +1793,8 @@ $(OUTDIR)/spellfile.obj: $(OUTDIR) spellfile.c $(INCL)
$(OUTDIR)/spellsuggest.obj: $(OUTDIR) spellsuggest.c $(INCL)
$(OUTDIR)/strings.obj: $(OUTDIR) strings.c $(INCL)
$(OUTDIR)/syntax.obj: $(OUTDIR) syntax.c $(INCL)
$(OUTDIR)/tag.obj: $(OUTDIR) tag.c $(INCL)
@ -2012,6 +2015,7 @@ proto.h: \
proto/spell.pro \
proto/spellfile.pro \
proto/spellsuggest.pro \
proto/strings.pro \
proto/syntax.pro \
proto/tag.pro \
proto/term.pro \

View File

@ -393,6 +393,7 @@ SRC = \
spell.c \
spellfile.c \
spellsuggest.c \
strings.c \
syntax.c \
tag.c \
term.c \
@ -512,6 +513,7 @@ OBJ = \
spell.obj \
spellfile.obj \
spellsuggest.obj \
strings.obj \
syntax.obj \
tag.obj \
term.obj \
@ -1048,6 +1050,10 @@ spellsuggest.obj : spellsuggest.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h beval.h [.proto]gui_beval.pro alloc.h ex_cmds.h spell.h \
proto.h errors.h globals.h
strings.obj : strings.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h beval.h [.proto]gui_beval.pro alloc.h ex_cmds.h spell.h \
proto.h errors.h globals.h
syntax.obj : syntax.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \

View File

@ -1677,6 +1677,7 @@ BASIC_SRC = \
spell.c \
spellfile.c \
spellsuggest.c \
strings.c \
syntax.c \
tag.c \
term.c \
@ -1828,6 +1829,7 @@ OBJ_COMMON = \
objects/spell.o \
objects/spellfile.o \
objects/spellsuggest.o \
objects/strings.o \
objects/syntax.o \
objects/tag.o \
objects/term.o \
@ -2011,6 +2013,7 @@ PRO_AUTO = \
spell.pro \
spellfile.pro \
spellsuggest.pro \
strings.pro \
syntax.pro \
tag.pro \
term.pro \
@ -3516,6 +3519,9 @@ objects/spellfile.o: spellfile.c
objects/spellsuggest.o: spellsuggest.c
$(CCC) -o $@ spellsuggest.c
objects/strings.o: strings.c
$(CCC) -o $@ strings.c
objects/syntax.o: syntax.c
$(CCC) -o $@ syntax.c
@ -4049,6 +4055,10 @@ objects/spellsuggest.o: spellsuggest.c vim.h protodef.h auto/config.h feature.h
os_unix.h auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \
proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \
proto.h errors.h globals.h
objects/strings.o: strings.c vim.h protodef.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \
proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \
proto.h errors.h globals.h
objects/syntax.o: syntax.c vim.h protodef.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \
proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \

View File

@ -80,6 +80,7 @@ sign.c | signs
spell.c | spell checking core
spellfile.c | spell file handling
spellsuggest.c | spell correction suggestions
strings.c | string manipulation functions
syntax.c | syntax and other highlighting
tag.c | tags
term.c | terminal handling, termcap codes

View File

@ -1311,6 +1311,11 @@ channel_open_func(typval_T *argvars)
jobopt_T opt;
channel_T *channel = NULL;
if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL
|| check_for_dict_arg(argvars, 1) == FAIL))
return NULL;
address = tv_get_string(&argvars[0]);
if (argvars[1].v_type != VAR_UNKNOWN
&& (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL))

View File

@ -492,3 +492,11 @@ EXTERN char e_regexp_number_after_dot_pos_search[]
INIT(= N_("E1204: No Number allowed after .: '\\%%%c'"));
EXTERN char e_no_white_space_allowed_between_option_and[]
INIT(= N_("E1205: No white space allowed between option and"));
EXTERN char e_dict_required_for_argument_nr[]
INIT(= N_("E1206: Dictionary required for argument %d"));
EXTERN char e_expression_without_effect_str[]
INIT(= N_("E1207: Expression without an effect: %s"));
EXTERN char e_complete_used_without_nargs[]
INIT(= N_("E1208: -complete used without -nargs"));
EXTERN char e_invalid_value_for_line_number_str[]
INIT(= N_("E1209: Invalid value for a line number: \"%s\""));

View File

@ -57,6 +57,7 @@ static int eval7_leader(typval_T *rettv, int numeric_only, char_u *start_leader,
static int free_unref_items(int copyID);
static char_u *make_expanded_name(char_u *in_start, char_u *expr_start, char_u *expr_end, char_u *in_end);
static char_u *eval_next_line(evalarg_T *evalarg);
/*
* Return "n1" divided by "n2", taking care of dividing by zero.
@ -2113,7 +2114,7 @@ getline_peek_skip_comments(evalarg_T *evalarg)
* FALSE.
* "arg" must point somewhere inside a line, not at the start.
*/
char_u *
static char_u *
eval_next_non_blank(char_u *arg, evalarg_T *evalarg, int *getnext)
{
char_u *p = skipwhite(arg);
@ -2144,7 +2145,7 @@ eval_next_non_blank(char_u *arg, evalarg_T *evalarg, int *getnext)
* To be called after eval_next_non_blank() sets "getnext" to TRUE.
* Only called for Vim9 script.
*/
char_u *
static char_u *
eval_next_line(evalarg_T *evalarg)
{
garray_T *gap = &evalarg->eval_ga;
@ -5171,50 +5172,6 @@ echo_string(
return echo_string_core(tv, tofree, numbuf, copyID, TRUE, FALSE, FALSE);
}
/*
* Return string "str" in ' quotes, doubling ' characters.
* If "str" is NULL an empty string is assumed.
* If "function" is TRUE make it function('string').
*/
char_u *
string_quote(char_u *str, int function)
{
unsigned len;
char_u *p, *r, *s;
len = (function ? 13 : 3);
if (str != NULL)
{
len += (unsigned)STRLEN(str);
for (p = str; *p != NUL; MB_PTR_ADV(p))
if (*p == '\'')
++len;
}
s = r = alloc(len);
if (r != NULL)
{
if (function)
{
STRCPY(r, "function('");
r += 10;
}
else
*r++ = '\'';
if (str != NULL)
for (p = str; *p != NUL; )
{
if (*p == '\'')
*r++ = '\'';
MB_COPY_CHAR(p, r);
}
*r++ = '\'';
if (function)
*r++ = ')';
*r++ = NUL;
}
return s;
}
/*
* Convert the specified byte index of line 'lnum' in buffer 'buf' to a
* character index. Works only for loaded buffers. Returns -1 on failure.
@ -5419,6 +5376,8 @@ var2fpos(
}
return &pos;
}
if (in_vim9script())
semsg(_(e_invalid_value_for_line_number_str), name);
return NULL;
}
@ -6232,6 +6191,7 @@ ex_execute(exarg_T *eap)
char_u *p;
garray_T ga;
int len;
long start_lnum = SOURCING_LNUM;
ga_init2(&ga, 1, 80);
@ -6285,6 +6245,9 @@ ex_execute(exarg_T *eap)
if (ret != FAIL && ga.ga_data != NULL)
{
// use the first line of continuation lines for messages
SOURCING_LNUM = start_lnum;
if (eap->cmdidx == CMD_echomsg || eap->cmdidx == CMD_echoerr)
{
// Mark the already saved text as finishing the line, so that what

File diff suppressed because it is too large Load Diff

View File

@ -208,7 +208,7 @@ cause_errthrow(
* not skipped. Errors in those commands may affect what of the subsequent
* commands are regarded part of catch and finally clauses. Catching the
* exception would then cause execution of commands not intended by the
* user, who wouldn't even get aware of the problem. Therefor, discard the
* user, who wouldn't even get aware of the problem. Therefore, discard the
* exception currently being thrown to prevent it from being caught. Just
* execute finally clauses and terminate.
*/
@ -896,11 +896,28 @@ ex_eval(exarg_T *eap)
{
typval_T tv;
evalarg_T evalarg;
int name_only = FALSE;
char_u *p;
long lnum = SOURCING_LNUM;
if (in_vim9script())
{
char_u *alias;
p = eap->arg;
get_name_len(&p, &alias, FALSE, FALSE);
name_only = ends_excmd2(eap->arg, skipwhite(p));
vim_free(alias);
}
fill_evalarg_from_eap(&evalarg, eap, eap->skip);
if (eval0(eap->arg, &tv, eap, &evalarg) == OK)
{
clear_tv(&tv);
if (in_vim9script() && name_only && lnum == SOURCING_LNUM)
semsg(_(e_expression_without_effect_str), eap->arg);
}
clear_evalarg(&evalarg, eap);
}
@ -1287,7 +1304,7 @@ ex_continue(exarg_T *eap)
{
// Try to find the matching ":while". This might stop at a try
// conditional not in its finally clause (which is then to be executed
// next). Therefor, inactivate all conditionals except the ":while"
// next). Therefore, inactivate all conditionals except the ":while"
// itself (if reached).
idx = cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, FALSE);
if (idx >= 0 && (cstack->cs_flags[idx] & (CSF_WHILE | CSF_FOR)))

View File

@ -602,11 +602,12 @@ list_append(list_T *l, listitem_T *item)
int
list_append_tv(list_T *l, typval_T *tv)
{
listitem_T *li = listitem_alloc();
listitem_T *li;
if (l->lv_type != NULL && l->lv_type->tt_member != NULL
&& check_typval_arg_type(l->lv_type->tt_member, tv, 0) == FAIL)
return FAIL;
li = listitem_alloc();
if (li == NULL)
return FAIL;
copy_tv(tv, &li->li_tv);

View File

@ -4961,6 +4961,37 @@ f_getimstatus(typval_T *argvars UNUSED, typval_T *rettv)
rettv->vval.v_number = im_get_status();
# endif
}
/*
* iconv() function
*/
void
f_iconv(typval_T *argvars UNUSED, typval_T *rettv)
{
char_u buf1[NUMBUFLEN];
char_u buf2[NUMBUFLEN];
char_u *from, *to, *str;
vimconv_T vimconv;
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
str = tv_get_string(&argvars[0]);
from = enc_canonize(enc_skip(tv_get_string_buf(&argvars[1], buf1)));
to = enc_canonize(enc_skip(tv_get_string_buf(&argvars[2], buf2)));
vimconv.vc_type = CONV_NONE;
convert_setup(&vimconv, from, to);
// If the encodings are equal, no conversion needed.
if (vimconv.vc_type == CONV_NONE)
rettv->vval.v_string = vim_strsave(str);
else
rettv->vval.v_string = string_convert(&vimconv, str, NULL);
convert_setup(&vimconv, NULL, NULL);
vim_free(from);
vim_free(to);
}
#endif
/*

View File

@ -695,7 +695,8 @@ f_mode(typval_T *argvars, typval_T *rettv)
if (finish_op)
{
buf[1] = 'o';
// to be able to detect force-linewise/blockwise/characterwise operations
// to be able to detect force-linewise/blockwise/characterwise
// operations
buf[2] = motion_force;
}
else if (restart_edit == 'I' || restart_edit == 'R'
@ -2099,29 +2100,6 @@ match_user(char_u *name)
return result;
}
/*
* Concatenate two strings and return the result in allocated memory.
* Returns NULL when out of memory.
*/
char_u *
concat_str(char_u *str1, char_u *str2)
{
char_u *dest;
size_t l = str1 == NULL ? 0 : STRLEN(str1);
dest = alloc(l + (str2 == NULL ? 0 : STRLEN(str2)) + 1L);
if (dest != NULL)
{
if (str1 == NULL)
*dest = NUL;
else
STRCPY(dest, str1);
if (str2 != NULL)
STRCPY(dest + l, str2);
}
return dest;
}
static void
prepare_to_exit(void)
{

View File

@ -1267,42 +1267,6 @@ free_all_mem(void)
}
#endif
/*
* Copy "string" into newly allocated memory.
*/
char_u *
vim_strsave(char_u *string)
{
char_u *p;
size_t len;
len = STRLEN(string) + 1;
p = alloc(len);
if (p != NULL)
mch_memmove(p, string, len);
return p;
}
/*
* Copy up to "len" bytes of "string" into newly allocated memory and
* terminate with a NUL.
* The allocated memory always has size "len + 1", also when "string" is
* shorter.
*/
char_u *
vim_strnsave(char_u *string, size_t len)
{
char_u *p;
p = alloc(len + 1);
if (p != NULL)
{
STRNCPY(p, string, len);
p[len] = NUL;
}
return p;
}
/*
* Copy "p[len]" into allocated memory, ignoring NUL characters.
* Returns NULL when out of memory.
@ -1317,465 +1281,6 @@ vim_memsave(char_u *p, size_t len)
return ret;
}
/*
* Same as vim_strsave(), but any characters found in esc_chars are preceded
* by a backslash.
*/
char_u *
vim_strsave_escaped(char_u *string, char_u *esc_chars)
{
return vim_strsave_escaped_ext(string, esc_chars, '\\', FALSE);
}
/*
* Same as vim_strsave_escaped(), but when "bsl" is TRUE also escape
* characters where rem_backslash() would remove the backslash.
* Escape the characters with "cc".
*/
char_u *
vim_strsave_escaped_ext(
char_u *string,
char_u *esc_chars,
int cc,
int bsl)
{
char_u *p;
char_u *p2;
char_u *escaped_string;
unsigned length;
int l;
/*
* First count the number of backslashes required.
* Then allocate the memory and insert them.
*/
length = 1; // count the trailing NUL
for (p = string; *p; p++)
{
if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1)
{
length += l; // count a multibyte char
p += l - 1;
continue;
}
if (vim_strchr(esc_chars, *p) != NULL || (bsl && rem_backslash(p)))
++length; // count a backslash
++length; // count an ordinary char
}
escaped_string = alloc(length);
if (escaped_string != NULL)
{
p2 = escaped_string;
for (p = string; *p; p++)
{
if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1)
{
mch_memmove(p2, p, (size_t)l);
p2 += l;
p += l - 1; // skip multibyte char
continue;
}
if (vim_strchr(esc_chars, *p) != NULL || (bsl && rem_backslash(p)))
*p2++ = cc;
*p2++ = *p;
}
*p2 = NUL;
}
return escaped_string;
}
/*
* Return TRUE when 'shell' has "csh" in the tail.
*/
int
csh_like_shell(void)
{
return (strstr((char *)gettail(p_sh), "csh") != NULL);
}
/*
* Escape "string" for use as a shell argument with system().
* This uses single quotes, except when we know we need to use double quotes
* (MS-DOS and MS-Windows not using PowerShell and without 'shellslash' set).
* PowerShell also uses a novel escaping for enclosed single quotes - double
* them up.
* Escape a newline, depending on the 'shell' option.
* When "do_special" is TRUE also replace "!", "%", "#" and things starting
* with "<" like "<cfile>".
* When "do_newline" is FALSE do not escape newline unless it is csh shell.
* Returns the result in allocated memory, NULL if we have run out.
*/
char_u *
vim_strsave_shellescape(char_u *string, int do_special, int do_newline)
{
unsigned length;
char_u *p;
char_u *d;
char_u *escaped_string;
int l;
int csh_like;
char_u *shname;
int powershell;
# ifdef MSWIN
int double_quotes;
# endif
// Only csh and similar shells expand '!' within single quotes. For sh and
// the like we must not put a backslash before it, it will be taken
// literally. If do_special is set the '!' will be escaped twice.
// Csh also needs to have "\n" escaped twice when do_special is set.
csh_like = csh_like_shell();
// PowerShell uses it's own version for quoting single quotes
shname = gettail(p_sh);
powershell = strstr((char *)shname, "pwsh") != NULL;
# ifdef MSWIN
powershell = powershell || strstr((char *)shname, "powershell") != NULL;
// PowerShell only accepts single quotes so override shellslash.
double_quotes = !powershell && !p_ssl;
# endif
// First count the number of extra bytes required.
length = (unsigned)STRLEN(string) + 3; // two quotes and a trailing NUL
for (p = string; *p != NUL; MB_PTR_ADV(p))
{
# ifdef MSWIN
if (double_quotes)
{
if (*p == '"')
++length; // " -> ""
}
else
# endif
if (*p == '\'')
{
if (powershell)
length +=2; // ' => ''
else
length += 3; // ' => '\''
}
if ((*p == '\n' && (csh_like || do_newline))
|| (*p == '!' && (csh_like || do_special)))
{
++length; // insert backslash
if (csh_like && do_special)
++length; // insert backslash
}
if (do_special && find_cmdline_var(p, &l) >= 0)
{
++length; // insert backslash
p += l - 1;
}
}
// Allocate memory for the result and fill it.
escaped_string = alloc(length);
if (escaped_string != NULL)
{
d = escaped_string;
// add opening quote
# ifdef MSWIN
if (double_quotes)
*d++ = '"';
else
# endif
*d++ = '\'';
for (p = string; *p != NUL; )
{
# ifdef MSWIN
if (double_quotes)
{
if (*p == '"')
{
*d++ = '"';
*d++ = '"';
++p;
continue;
}
}
else
# endif
if (*p == '\'')
{
if (powershell)
{
*d++ = '\'';
*d++ = '\'';
}
else
{
*d++ = '\'';
*d++ = '\\';
*d++ = '\'';
*d++ = '\'';
}
++p;
continue;
}
if ((*p == '\n' && (csh_like || do_newline))
|| (*p == '!' && (csh_like || do_special)))
{
*d++ = '\\';
if (csh_like && do_special)
*d++ = '\\';
*d++ = *p++;
continue;
}
if (do_special && find_cmdline_var(p, &l) >= 0)
{
*d++ = '\\'; // insert backslash
while (--l >= 0) // copy the var
*d++ = *p++;
continue;
}
MB_COPY_CHAR(p, d);
}
// add terminating quote and finish with a NUL
# ifdef MSWIN
if (double_quotes)
*d++ = '"';
else
# endif
*d++ = '\'';
*d = NUL;
}
return escaped_string;
}
/*
* Like vim_strsave(), but make all characters uppercase.
* This uses ASCII lower-to-upper case translation, language independent.
*/
char_u *
vim_strsave_up(char_u *string)
{
char_u *p1;
p1 = vim_strsave(string);
vim_strup(p1);
return p1;
}
/*
* Like vim_strnsave(), but make all characters uppercase.
* This uses ASCII lower-to-upper case translation, language independent.
*/
char_u *
vim_strnsave_up(char_u *string, size_t len)
{
char_u *p1;
p1 = vim_strnsave(string, len);
vim_strup(p1);
return p1;
}
/*
* ASCII lower-to-upper case translation, language independent.
*/
void
vim_strup(
char_u *p)
{
char_u *p2;
int c;
if (p != NULL)
{
p2 = p;
while ((c = *p2) != NUL)
#ifdef EBCDIC
*p2++ = isalpha(c) ? toupper(c) : c;
#else
*p2++ = (c < 'a' || c > 'z') ? c : (c - 0x20);
#endif
}
}
#if defined(FEAT_EVAL) || defined(FEAT_SPELL) || defined(PROTO)
/*
* Make string "s" all upper-case and return it in allocated memory.
* Handles multi-byte characters as well as possible.
* Returns NULL when out of memory.
*/
char_u *
strup_save(char_u *orig)
{
char_u *p;
char_u *res;
res = p = vim_strsave(orig);
if (res != NULL)
while (*p != NUL)
{
int l;
if (enc_utf8)
{
int c, uc;
int newl;
char_u *s;
c = utf_ptr2char(p);
l = utf_ptr2len(p);
if (c == 0)
{
// overlong sequence, use only the first byte
c = *p;
l = 1;
}
uc = utf_toupper(c);
// Reallocate string when byte count changes. This is rare,
// thus it's OK to do another malloc()/free().
newl = utf_char2len(uc);
if (newl != l)
{
s = alloc(STRLEN(res) + 1 + newl - l);
if (s == NULL)
{
vim_free(res);
return NULL;
}
mch_memmove(s, res, p - res);
STRCPY(s + (p - res) + newl, p + l);
p = s + (p - res);
vim_free(res);
res = s;
}
utf_char2bytes(uc, p);
p += newl;
}
else if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1)
p += l; // skip multi-byte character
else
{
*p = TOUPPER_LOC(*p); // note that toupper() can be a macro
p++;
}
}
return res;
}
/*
* Make string "s" all lower-case and return it in allocated memory.
* Handles multi-byte characters as well as possible.
* Returns NULL when out of memory.
*/
char_u *
strlow_save(char_u *orig)
{
char_u *p;
char_u *res;
res = p = vim_strsave(orig);
if (res != NULL)
while (*p != NUL)
{
int l;
if (enc_utf8)
{
int c, lc;
int newl;
char_u *s;
c = utf_ptr2char(p);
l = utf_ptr2len(p);
if (c == 0)
{
// overlong sequence, use only the first byte
c = *p;
l = 1;
}
lc = utf_tolower(c);
// Reallocate string when byte count changes. This is rare,
// thus it's OK to do another malloc()/free().
newl = utf_char2len(lc);
if (newl != l)
{
s = alloc(STRLEN(res) + 1 + newl - l);
if (s == NULL)
{
vim_free(res);
return NULL;
}
mch_memmove(s, res, p - res);
STRCPY(s + (p - res) + newl, p + l);
p = s + (p - res);
vim_free(res);
res = s;
}
utf_char2bytes(lc, p);
p += newl;
}
else if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1)
p += l; // skip multi-byte character
else
{
*p = TOLOWER_LOC(*p); // note that tolower() can be a macro
p++;
}
}
return res;
}
#endif
/*
* delete spaces at the end of a string
*/
void
del_trailing_spaces(char_u *ptr)
{
char_u *q;
q = ptr + STRLEN(ptr);
while (--q > ptr && VIM_ISWHITE(q[0]) && q[-1] != '\\' && q[-1] != Ctrl_V)
*q = NUL;
}
/*
* Like strncpy(), but always terminate the result with one NUL.
* "to" must be "len + 1" long!
*/
void
vim_strncpy(char_u *to, char_u *from, size_t len)
{
STRNCPY(to, from, len);
to[len] = NUL;
}
/*
* Like strcat(), but make sure the result fits in "tosize" bytes and is
* always NUL terminated. "from" and "to" may overlap.
*/
void
vim_strcat(char_u *to, char_u *from, size_t tosize)
{
size_t tolen = STRLEN(to);
size_t fromlen = STRLEN(from);
if (tolen + fromlen + 1 > tosize)
{
mch_memmove(to + tolen, from, tosize - tolen - 1);
to[tosize - 1] = NUL;
}
else
mch_memmove(to + tolen, from, fromlen + 1);
}
/*
* Isolate one part of a string option where parts are separated with
* "sep_chars".
@ -1848,180 +1353,6 @@ vim_memset(void *ptr, int c, size_t size)
}
#endif
#if (!defined(HAVE_STRCASECMP) && !defined(HAVE_STRICMP)) || defined(PROTO)
/*
* Compare two strings, ignoring case, using current locale.
* Doesn't work for multi-byte characters.
* return 0 for match, < 0 for smaller, > 0 for bigger
*/
int
vim_stricmp(char *s1, char *s2)
{
int i;
for (;;)
{
i = (int)TOLOWER_LOC(*s1) - (int)TOLOWER_LOC(*s2);
if (i != 0)
return i; // this character different
if (*s1 == NUL)
break; // strings match until NUL
++s1;
++s2;
}
return 0; // strings match
}
#endif
#if (!defined(HAVE_STRNCASECMP) && !defined(HAVE_STRNICMP)) || defined(PROTO)
/*
* Compare two strings, for length "len", ignoring case, using current locale.
* Doesn't work for multi-byte characters.
* return 0 for match, < 0 for smaller, > 0 for bigger
*/
int
vim_strnicmp(char *s1, char *s2, size_t len)
{
int i;
while (len > 0)
{
i = (int)TOLOWER_LOC(*s1) - (int)TOLOWER_LOC(*s2);
if (i != 0)
return i; // this character different
if (*s1 == NUL)
break; // strings match until NUL
++s1;
++s2;
--len;
}
return 0; // strings match
}
#endif
/*
* Search for first occurrence of "c" in "string".
* Version of strchr() that handles unsigned char strings with characters from
* 128 to 255 correctly. It also doesn't return a pointer to the NUL at the
* end of the string.
*/
char_u *
vim_strchr(char_u *string, int c)
{
char_u *p;
int b;
p = string;
if (enc_utf8 && c >= 0x80)
{
while (*p != NUL)
{
int l = utfc_ptr2len(p);
// Avoid matching an illegal byte here.
if (utf_ptr2char(p) == c && l > 1)
return p;
p += l;
}
return NULL;
}
if (enc_dbcs != 0 && c > 255)
{
int n2 = c & 0xff;
c = ((unsigned)c >> 8) & 0xff;
while ((b = *p) != NUL)
{
if (b == c && p[1] == n2)
return p;
p += (*mb_ptr2len)(p);
}
return NULL;
}
if (has_mbyte)
{
while ((b = *p) != NUL)
{
if (b == c)
return p;
p += (*mb_ptr2len)(p);
}
return NULL;
}
while ((b = *p) != NUL)
{
if (b == c)
return p;
++p;
}
return NULL;
}
/*
* Version of strchr() that only works for bytes and handles unsigned char
* strings with characters above 128 correctly. It also doesn't return a
* pointer to the NUL at the end of the string.
*/
char_u *
vim_strbyte(char_u *string, int c)
{
char_u *p = string;
while (*p != NUL)
{
if (*p == c)
return p;
++p;
}
return NULL;
}
/*
* Search for last occurrence of "c" in "string".
* Version of strrchr() that handles unsigned char strings with characters from
* 128 to 255 correctly. It also doesn't return a pointer to the NUL at the
* end of the string.
* Return NULL if not found.
* Does not handle multi-byte char for "c"!
*/
char_u *
vim_strrchr(char_u *string, int c)
{
char_u *retval = NULL;
char_u *p = string;
while (*p)
{
if (*p == c)
retval = p;
MB_PTR_ADV(p);
}
return retval;
}
/*
* Vim's version of strpbrk(), in case it's missing.
* Don't generate a prototype for this, causes problems when it's not used.
*/
#ifndef PROTO
# ifndef HAVE_STRPBRK
# ifdef vim_strpbrk
# undef vim_strpbrk
# endif
char_u *
vim_strpbrk(char_u *s, char_u *charset)
{
while (*s)
{
if (vim_strchr(charset, *s) != NULL)
return s;
MB_PTR_ADV(s);
}
return NULL;
}
# endif
#endif
/*
* Vim has its own isspace() function, because on some machines isspace()
* can't handle characters above 128.
@ -3974,25 +3305,6 @@ qsort(
}
#endif
/*
* Sort an array of strings.
*/
static int sort_compare(const void *s1, const void *s2);
static int
sort_compare(const void *s1, const void *s2)
{
return STRCMP(*(char **)s1, *(char **)s2);
}
void
sort_strings(
char_u **files,
int count)
{
qsort((void *)files, (size_t)count, sizeof(char_u *), sort_compare);
}
/*
* The putenv() implementation below comes from the "screen" program.
* Included with permission from Juergen Weigert.
@ -4304,24 +3616,6 @@ put_bytes(FILE *fd, long_u nr, int len)
#endif
#if defined(FEAT_QUICKFIX) || defined(FEAT_SPELL) || defined(PROTO)
/*
* Return TRUE if string "s" contains a non-ASCII character (128 or higher).
* When "s" is NULL FALSE is returned.
*/
int
has_non_ascii(char_u *s)
{
char_u *p;
if (s != NULL)
for (p = s; *p != NUL; ++p)
if (*p >= 128)
return TRUE;
return FALSE;
}
#endif
#ifndef PROTO // proto is defined in vim.h
# ifdef ELAPSED_TIMEVAL
/*

View File

@ -211,6 +211,7 @@ void mbyte_im_set_active(int active_arg);
# include "spell.pro"
# include "spellfile.pro"
# include "spellsuggest.pro"
# include "strings.pro"
# include "syntax.pro"
# include "tag.pro"
# include "term.pro"

View File

@ -32,8 +32,6 @@ int next_for_item(void *fi_void, char_u *arg);
void free_for_info(void *fi_void);
void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx);
int pattern_match(char_u *pat, char_u *text, int ic);
char_u *eval_next_non_blank(char_u *arg, evalarg_T *evalarg, int *getnext);
char_u *eval_next_line(evalarg_T *evalarg);
char_u *skipwhite_and_linebreak(char_u *arg, evalarg_T *evalarg);
void clear_evalarg(evalarg_T *evalarg, exarg_T *eap);
int eval0(char_u *arg, typval_T *rettv, exarg_T *eap, evalarg_T *evalarg);
@ -55,7 +53,6 @@ int set_ref_in_list_items(list_T *l, int copyID, ht_stack_T **ht_stack);
int set_ref_in_item(typval_T *tv, int copyID, ht_stack_T **ht_stack, list_stack_T **list_stack);
char_u *echo_string_core(typval_T *tv, char_u **tofree, char_u *numbuf, int copyID, int echo_style, int restore_copyID, int composite_val);
char_u *echo_string(typval_T *tv, char_u **tofree, char_u *numbuf, int copyID);
char_u *string_quote(char_u *str, int function);
int buf_byteidx_to_charidx(buf_T *buf, int lnum, int byteidx);
int buf_charidx_to_byteidx(buf_T *buf, int lnum, int charidx);
pos_T *var2fpos(typval_T *varp, int dollar_lnum, int *fnum, int charcol);

View File

@ -23,5 +23,4 @@ int dynamic_feature(char_u *feature);
void mzscheme_call_vim(char_u *name, typval_T *args, typval_T *rettv);
void range_list_materialize(list_T *list);
long do_searchpair(char_u *spat, char_u *mpat, char_u *epat, int dir, typval_T *skip, int flags, pos_T *match_pos, linenr_T lnum_stop, long time_limit);
void f_string(typval_T *argvars, typval_T *rettv);
/* vim: set ft=c : */

View File

@ -86,4 +86,5 @@ char_u *string_convert(vimconv_T *vcp, char_u *ptr, int *lenp);
char_u *string_convert_ext(vimconv_T *vcp, char_u *ptr, int *lenp, int *unconvlenp);
void f_setcellwidths(typval_T *argvars, typval_T *rettv);
void f_charclass(typval_T *argvars, typval_T *rettv);
void f_iconv(typval_T *argvars UNUSED, typval_T *rettv);
/* vim: set ft=c : */

View File

@ -36,7 +36,6 @@ void vim_setenv(char_u *name, char_u *val);
char_u *get_env_name(expand_T *xp, int idx);
char_u *get_users(expand_T *xp, int idx);
int match_user(char_u *name);
char_u *concat_str(char_u *str1, char_u *str2);
void preserve_exit(void);
void line_breakcheck(void);
void fast_breakcheck(void);

View File

@ -31,28 +31,9 @@ void *lalloc_id(size_t size, int message, alloc_id_T id);
void *mem_realloc(void *ptr, size_t size);
void do_outofmem_msg(size_t size);
void free_all_mem(void);
char_u *vim_strsave(char_u *string);
char_u *vim_strnsave(char_u *string, size_t len);
char_u *vim_memsave(char_u *p, size_t len);
char_u *vim_strsave_escaped(char_u *string, char_u *esc_chars);
char_u *vim_strsave_escaped_ext(char_u *string, char_u *esc_chars, int cc, int bsl);
int csh_like_shell(void);
char_u *vim_strsave_shellescape(char_u *string, int do_special, int do_newline);
char_u *vim_strsave_up(char_u *string);
char_u *vim_strnsave_up(char_u *string, size_t len);
void vim_strup(char_u *p);
char_u *strup_save(char_u *orig);
char_u *strlow_save(char_u *orig);
void del_trailing_spaces(char_u *ptr);
void vim_strncpy(char_u *to, char_u *from, size_t len);
void vim_strcat(char_u *to, char_u *from, size_t tosize);
int copy_option_part(char_u **option, char_u *buf, int maxlen, char *sep_chars);
void vim_free(void *x);
int vim_stricmp(char *s1, char *s2);
int vim_strnicmp(char *s1, char *s2, size_t len);
char_u *vim_strchr(char_u *string, int c);
char_u *vim_strbyte(char_u *string, int c);
char_u *vim_strrchr(char_u *string, int c);
int vim_isspace(int x);
void ga_clear(garray_T *gap);
void ga_clear_strings(garray_T *gap);
@ -93,14 +74,12 @@ int get_shape_idx(int mouse);
void update_mouseshape(int shape_idx);
int vim_chdir(char_u *new_dir);
int get_user_name(char_u *buf, int len);
void sort_strings(char_u **files, int count);
int filewritable(char_u *fname);
int get2c(FILE *fd);
int get3c(FILE *fd);
int get4c(FILE *fd);
char_u *read_string(FILE *fd, int cnt);
int put_bytes(FILE *fd, long_u nr, int len);
int has_non_ascii(char_u *s);
int mch_parse_cmd(char_u *cmd, int use_shcf, char ***argv, int *argc);
int build_argv_from_string(char_u *cmd, char ***argv, int *argc);
int build_argv_from_list(list_T *l, char ***argv, int *argc);

45
src/proto/strings.pro Normal file
View File

@ -0,0 +1,45 @@
/* strings.c */
char_u *vim_strsave(char_u *string);
char_u *vim_strnsave(char_u *string, size_t len);
char_u *vim_strsave_escaped(char_u *string, char_u *esc_chars);
char_u *vim_strsave_escaped_ext(char_u *string, char_u *esc_chars, int cc, int bsl);
int csh_like_shell(void);
char_u *vim_strsave_shellescape(char_u *string, int do_special, int do_newline);
char_u *vim_strsave_up(char_u *string);
char_u *vim_strnsave_up(char_u *string, size_t len);
void vim_strup(char_u *p);
char_u *strlow_save(char_u *orig);
void del_trailing_spaces(char_u *ptr);
void vim_strncpy(char_u *to, char_u *from, size_t len);
void vim_strcat(char_u *to, char_u *from, size_t tosize);
int vim_stricmp(char *s1, char *s2);
int vim_strnicmp(char *s1, char *s2, size_t len);
char_u *vim_strchr(char_u *string, int c);
char_u *vim_strbyte(char_u *string, int c);
char_u *vim_strrchr(char_u *string, int c);
void sort_strings(char_u **files, int count);
int has_non_ascii(char_u *s);
char_u *concat_str(char_u *str1, char_u *str2);
char_u *string_quote(char_u *str, int function);
void f_byteidx(typval_T *argvars, typval_T *rettv);
void f_byteidxcomp(typval_T *argvars, typval_T *rettv);
void f_charidx(typval_T *argvars, typval_T *rettv);
void f_str2list(typval_T *argvars, typval_T *rettv);
void f_str2nr(typval_T *argvars, typval_T *rettv);
void f_strgetchar(typval_T *argvars, typval_T *rettv);
void f_stridx(typval_T *argvars, typval_T *rettv);
void f_string(typval_T *argvars, typval_T *rettv);
void f_strlen(typval_T *argvars, typval_T *rettv);
void f_strcharlen(typval_T *argvars, typval_T *rettv);
void f_strchars(typval_T *argvars, typval_T *rettv);
void f_strdisplaywidth(typval_T *argvars, typval_T *rettv);
void f_strwidth(typval_T *argvars, typval_T *rettv);
void f_strcharpart(typval_T *argvars, typval_T *rettv);
void f_strpart(typval_T *argvars, typval_T *rettv);
void f_strridx(typval_T *argvars, typval_T *rettv);
void f_strtrans(typval_T *argvars, typval_T *rettv);
void f_tolower(typval_T *argvars, typval_T *rettv);
void f_toupper(typval_T *argvars, typval_T *rettv);
void f_tr(typval_T *argvars, typval_T *rettv);
void f_trim(typval_T *argvars, typval_T *rettv);
/* vim: set ft=c : */

View File

@ -11,6 +11,7 @@ varnumber_T tv_get_bool_chk(typval_T *varp, int *denote);
float_T tv_get_float(typval_T *varp);
int check_for_string_arg(typval_T *args, int idx);
int check_for_nonempty_string_arg(typval_T *args, int idx);
int check_for_dict_arg(typval_T *args, int idx);
char_u *tv_get_string(typval_T *varp);
char_u *tv_get_string_strict(typval_T *varp);
char_u *tv_get_string_buf(typval_T *varp, char_u *buf);

1563
src/strings.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -5276,6 +5276,11 @@ term_load_dump(typval_T *argvars, typval_T *rettv, int do_diff)
FILE *fd2 = NULL;
char_u *textline = NULL;
if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL
|| check_for_dict_arg(argvars, 1) == FAIL))
return;
// First open the files. If this fails bail out.
fname1 = tv_get_string_buf_chk(&argvars[0], buf1);
if (do_diff)

View File

@ -1,6 +1,7 @@
" Test for :cd and chdir()
source shared.vim
source check.vim
func Test_cd_large_path()
" This used to crash with a heap write overflow.
@ -177,6 +178,21 @@ func Test_lcd_split()
quit!
endfunc
func Test_cd_from_non_existing_dir()
CheckNotMSWindows
let saveddir = getcwd()
call mkdir('Xdeleted_dir')
cd Xdeleted_dir
call delete(saveddir .. '/Xdeleted_dir', 'd')
" Expect E187 as the current directory was deleted.
call assert_fails('pwd', 'E187:')
call assert_equal('', getcwd())
cd -
call assert_equal(saveddir, getcwd())
endfunc
func Test_cd_completion()
call mkdir('XComplDir1', 'p')
call mkdir('XComplDir2', 'p')

View File

@ -253,9 +253,9 @@ endfunc
func Test_communicate_ipv6()
CheckIPv6
" FIXME: this test is very flaky on MS-Windows with the GUI
if has('gui_running') && has('win32')
throw 'Skipped: test is very flaky with MS-Windows in GUI'
" FIXME: this test is very flaky on MS-Windows
if has('win32')
throw 'Skipped: test is very flaky with MS-Windows'
endif
call Test_communicate()

View File

@ -1006,7 +1006,7 @@ func Test_debug_def_function()
}
# comment
def Inner()
eval 1
eval 1 + 2
enddef
enddef
@ -1019,16 +1019,16 @@ func Test_debug_def_function()
enddef
def g:FuncForLoop()
eval 1
eval 1 + 2
for i in [11, 22, 33]
eval i
eval i + 2
endfor
echo "done"
enddef
def g:FuncWithSplitLine()
eval 1
| eval 2
eval 1 + 2
| eval 2 + 3
enddef
END
call writefile(file, 'Xtest.vim')
@ -1080,7 +1080,7 @@ func Test_debug_def_function()
call RunDbgCmd(buf, ':breakadd func 2 FuncForLoop')
call RunDbgCmd(buf, ':call FuncForLoop()', ['function FuncForLoop', 'line 2: for i in [11, 22, 33]'])
call RunDbgCmd(buf, 'echo i', ['11'])
call RunDbgCmd(buf, 'next', ['function FuncForLoop', 'line 3: eval i'])
call RunDbgCmd(buf, 'next', ['function FuncForLoop', 'line 3: eval i + 2'])
call RunDbgCmd(buf, 'next', ['function FuncForLoop', 'line 4: endfor'])
call RunDbgCmd(buf, 'next', ['function FuncForLoop', 'line 2: for i in [11, 22, 33]'])
call RunDbgCmd(buf, 'echo i', ['22'])
@ -1089,7 +1089,7 @@ func Test_debug_def_function()
call RunDbgCmd(buf, 'cont')
call RunDbgCmd(buf, ':breakadd func FuncWithSplitLine')
call RunDbgCmd(buf, ':call FuncWithSplitLine()', ['function FuncWithSplitLine', 'line 1: eval 1 | eval 2'])
call RunDbgCmd(buf, ':call FuncWithSplitLine()', ['function FuncWithSplitLine', 'line 1: eval 1 + 2 | eval 2 + 3'])
call RunDbgCmd(buf, 'cont')
call StopVimInTerminal(buf)

View File

@ -373,9 +373,9 @@ func Test_searchpairpos()
endfunc
func Test_searchpair_errors()
call assert_fails("call searchpair([0], 'middle', 'end', 'bW', 'skip', 99, 100)", 'E730: using List as a String')
call assert_fails("call searchpair('start', {-> 0}, 'end', 'bW', 'skip', 99, 100)", 'E729: using Funcref as a String')
call assert_fails("call searchpair('start', 'middle', {'one': 1}, 'bW', 'skip', 99, 100)", 'E731: using Dictionary as a String')
call assert_fails("call searchpair([0], 'middle', 'end', 'bW', 'skip', 99, 100)", 'E730: Using a List as a String')
call assert_fails("call searchpair('start', {-> 0}, 'end', 'bW', 'skip', 99, 100)", 'E729: Using a Funcref as a String')
call assert_fails("call searchpair('start', 'middle', {'one': 1}, 'bW', 'skip', 99, 100)", 'E731: Using a Dictionary as a String')
call assert_fails("call searchpair('start', 'middle', 'end', 'flags', 'skip', 99, 100)", 'E475: Invalid argument: flags')
call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 'func', -99, 100)", 'E475: Invalid argument: -99')
call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 'func', 99, -100)", 'E475: Invalid argument: -100')
@ -384,9 +384,9 @@ func Test_searchpair_errors()
endfunc
func Test_searchpairpos_errors()
call assert_fails("call searchpairpos([0], 'middle', 'end', 'bW', 'skip', 99, 100)", 'E730: using List as a String')
call assert_fails("call searchpairpos('start', {-> 0}, 'end', 'bW', 'skip', 99, 100)", 'E729: using Funcref as a String')
call assert_fails("call searchpairpos('start', 'middle', {'one': 1}, 'bW', 'skip', 99, 100)", 'E731: using Dictionary as a String')
call assert_fails("call searchpairpos([0], 'middle', 'end', 'bW', 'skip', 99, 100)", 'E730: Using a List as a String')
call assert_fails("call searchpairpos('start', {-> 0}, 'end', 'bW', 'skip', 99, 100)", 'E729: Using a Funcref as a String')
call assert_fails("call searchpairpos('start', 'middle', {'one': 1}, 'bW', 'skip', 99, 100)", 'E731: Using a Dictionary as a String')
call assert_fails("call searchpairpos('start', 'middle', 'end', 'flags', 'skip', 99, 100)", 'E475: Invalid argument: flags')
call assert_fails("call searchpairpos('start', 'middle', 'end', 'bW', 'func', -99, 100)", 'E475: Invalid argument: -99')
call assert_fails("call searchpairpos('start', 'middle', 'end', 'bW', 'func', 99, -100)", 'E475: Invalid argument: -100')

View File

@ -574,4 +574,8 @@ func Test_swapchoice()
augroup! test_swapchoice
endfunc
func Test_no_swap_file()
call assert_equal("\nNo swap file", execute('swapname'))
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@ -1340,7 +1340,7 @@ endfunc
func Test_prop_func_invalid_args()
call assert_fails('call prop_clear(1, 2, [])', 'E715:')
call assert_fails('call prop_clear(-1, 2)', 'E16:')
call assert_fails('call prop_find(test_null_dict())', 'E474:')
call assert_fails('call prop_find(test_null_dict())', 'E715:')
call assert_fails('call prop_find({"bufnr" : []})', 'E730:')
call assert_fails('call prop_find({})', 'E968:')
call assert_fails('call prop_find({}, "x")', 'E474:')

View File

@ -270,6 +270,8 @@ func Test_CmdErrors()
call assert_fails('com! -complete=custom DoCmd :', 'E467:')
call assert_fails('com! -complete=customlist DoCmd :', 'E467:')
call assert_fails('com! -complete=behave,CustomComplete DoCmd :', 'E468:')
call assert_fails('com! -complete=file DoCmd :', 'E1208:')
call assert_fails('com! -nargs=0 -complete=file DoCmd :', 'E1208:')
call assert_fails('com! -nargs=x DoCmd :', 'E176:')
call assert_fails('com! -count=1 -count=2 DoCmd :', 'E177:')
call assert_fails('com! -count=x DoCmd :', 'E178:')
@ -338,34 +340,30 @@ func Test_CmdCompletion()
call feedkeys(":com DoC\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"com DoC', @:)
com! -complete=behave DoCmd :
com! -nargs=1 -complete=behave DoCmd :
call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"DoCmd mswin xterm', @:)
" This does not work. Why?
"call feedkeys(":DoCmd x\<C-A>\<C-B>\"\<CR>", 'tx')
"call assert_equal('"DoCmd xterm', @:)
com! -complete=custom,CustomComplete DoCmd :
com! -nargs=* -complete=custom,CustomComplete DoCmd :
call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"DoCmd January February Mars', @:)
com! -complete=customlist,CustomCompleteList DoCmd :
com! -nargs=? -complete=customlist,CustomCompleteList DoCmd :
call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"DoCmd Monday Tuesday Wednesday', @:)
com! -complete=custom,CustomCompleteList DoCmd :
com! -nargs=+ -complete=custom,CustomCompleteList DoCmd :
call assert_fails("call feedkeys(':DoCmd \<C-D>', 'tx')", 'E730:')
com! -complete=customlist,CustomComp DoCmd :
com! -nargs=+ -complete=customlist,CustomComp DoCmd :
call assert_fails("call feedkeys(':DoCmd \<C-D>', 'tx')", 'E117:')
" custom completion without a function
com! -complete=custom, DoCmd
com! -nargs=? -complete=custom, DoCmd
call assert_beeps("call feedkeys(':DoCmd \t', 'tx')")
" custom completion failure with the wrong function
com! -complete=custom,min DoCmd
com! -nargs=? -complete=custom,min DoCmd
call assert_fails("call feedkeys(':DoCmd \t', 'tx')", 'E118:')
delcom DoCmd
@ -500,21 +498,21 @@ func Test_command_list()
\ execute('command DoCmd'))
" Test with various -complete= argument values (non-exhaustive list)
command! -complete=arglist DoCmd :
command! -nargs=1 -complete=arglist DoCmd :
call assert_equal("\n Name Args Address Complete Definition"
\ .. "\n DoCmd 0 arglist :",
\ .. "\n DoCmd 1 arglist :",
\ execute('command DoCmd'))
command! -complete=augroup DoCmd :
command! -nargs=* -complete=augroup DoCmd :
call assert_equal("\n Name Args Address Complete Definition"
\ .. "\n DoCmd 0 augroup :",
\ .. "\n DoCmd * augroup :",
\ execute('command DoCmd'))
command! -complete=custom,CustomComplete DoCmd :
command! -nargs=? -complete=custom,CustomComplete DoCmd :
call assert_equal("\n Name Args Address Complete Definition"
\ .. "\n DoCmd 0 custom :",
\ .. "\n DoCmd ? custom :",
\ execute('command DoCmd'))
command! -complete=customlist,CustomComplete DoCmd :
command! -nargs=+ -complete=customlist,CustomComplete DoCmd :
call assert_equal("\n Name Args Address Complete Definition"
\ .. "\n DoCmd 0 customlist :",
\ .. "\n DoCmd + customlist :",
\ execute('command DoCmd'))
" Test with various -narg= argument values.

View File

@ -156,8 +156,8 @@ def Test_add_blob()
enddef
def Test_and()
CheckDefFailure(['echo and("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['echo and(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
CheckDefAndScriptFailure2(['and("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
CheckDefAndScriptFailure2(['and(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
enddef
def Test_append()
@ -175,19 +175,42 @@ def Test_append()
enddef
def Test_argc()
CheckDefFailure(['echo argc("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['argc("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef
def Test_arglistid()
CheckDefFailure(['echo arglistid("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['echo arglistid(1, "y")'], 'E1013: Argument 2: type mismatch, expected number but got string')
CheckDefFailure(['echo arglistid("x", "y")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['arglistid("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['arglistid(1, "y")'], 'E1013: Argument 2: type mismatch, expected number but got string')
CheckDefFailure(['arglistid("x", "y")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef
def Test_argv()
CheckDefFailure(['echo argv("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['echo argv(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
CheckDefFailure(['echo argv("x", "y")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['argv("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['argv(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
CheckDefFailure(['argv("x", "y")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef
def Test_assert_equalfile()
CheckDefFailure(['assert_equalfile(1, "f2")'], 'E1013: Argument 1: type mismatch, expected string but got number')
CheckDefFailure(['assert_equalfile("f1", true)'], 'E1013: Argument 2: type mismatch, expected string but got bool')
CheckDefFailure(['assert_equalfile("f1", "f2", ["a"])'], 'E1013: Argument 3: type mismatch, expected string but got list<string>')
enddef
def Test_assert_exception()
CheckDefFailure(['assert_exception({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>')
CheckDefFailure(['assert_exception("E1:", v:null)'], 'E1013: Argument 2: type mismatch, expected string but got special')
enddef
def Test_assert_match()
CheckDefFailure(['assert_match({}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>')
CheckDefFailure(['assert_match("a", 1)'], 'E1013: Argument 2: type mismatch, expected string but got number')
CheckDefFailure(['assert_match("a", "b", null)'], 'E1013: Argument 3: type mismatch, expected string but got special')
enddef
def Test_assert_notmatch()
CheckDefFailure(['assert_notmatch({}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>')
CheckDefFailure(['assert_notmatch("a", 1)'], 'E1013: Argument 2: type mismatch, expected string but got number')
CheckDefFailure(['assert_notmatch("a", "b", null)'], 'E1013: Argument 3: type mismatch, expected string but got special')
enddef
def Test_balloon_show()
@ -222,6 +245,11 @@ def Test_browse()
CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 4')
enddef
def Test_browsedir()
CheckDefFailure(['browsedir({}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>')
CheckDefFailure(['browsedir("a", [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>')
enddef
def Test_bufadd()
assert_fails('bufadd([])', 'E730:')
enddef
@ -299,12 +327,51 @@ def Test_call_call()
l->assert_equal([1, 2, 3])
enddef
def Test_ch_canread()
if !has('channel')
CheckFeature channel
endif
CheckDefFailure(['ch_canread(10)'], 'E1013: Argument 1: type mismatch, expected channel but got number')
enddef
def Test_ch_close()
if !has('channel')
CheckFeature channel
endif
CheckDefFailure(['ch_close("c")'], 'E1013: Argument 1: type mismatch, expected channel but got string')
enddef
def Test_ch_close_in()
if !has('channel')
CheckFeature channel
endif
CheckDefFailure(['ch_close_in(true)'], 'E1013: Argument 1: type mismatch, expected channel but got bool')
enddef
def Test_ch_info()
if !has('channel')
CheckFeature channel
endif
CheckDefFailure(['ch_info([1])'], 'E1013: Argument 1: type mismatch, expected channel but got list<number>')
enddef
def Test_ch_logfile()
if !has('channel')
CheckFeature channel
endif
assert_fails('ch_logfile(true)', 'E1174:')
assert_fails('ch_logfile("foo", true)', 'E1174:')
CheckDefAndScriptFailure2(['ch_logfile(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['ch_logfile("a", true)'], 'E1013: Argument 2: type mismatch, expected string but got bool', 'E1174: String required for argument 2')
enddef
def Test_ch_open()
if !has('channel')
CheckFeature channel
endif
CheckDefAndScriptFailure2(['ch_open({"a": 10}, "a")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['ch_open("a", [1])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 2')
enddef
def Test_char2nr()
@ -317,6 +384,17 @@ def Test_charclass()
assert_fails('charclass(true)', 'E1174:')
enddef
def Test_charcol()
CheckDefFailure(['charcol(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
CheckDefFailure(['charcol({a: 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>')
enddef
def Test_charidx()
CheckDefFailure(['charidx("a", "b")'], 'E1013: Argument 2: type mismatch, expected number but got string')
CheckDefFailure(['charidx(0z10, 1)'], 'E1013: Argument 1: type mismatch, expected string but got blob')
CheckDefFailure(['charidx("a", 1, "")'], 'E1013: Argument 3: type mismatch, expected bool but got string')
enddef
def Test_chdir()
assert_fails('chdir(true)', 'E1174:')
enddef
@ -329,7 +407,7 @@ def Test_cindent()
enddef
def Test_clearmatches()
CheckDefFailure(['echo clearmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['clearmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef
def Test_col()
@ -338,6 +416,11 @@ def Test_col()
col([1, '$'])->assert_equal(5)
assert_fails('col(true)', 'E1174:')
CheckDefFailure(['col(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
CheckDefFailure(['col({a: 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>')
CheckDefFailure(['col(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
bw!
enddef
def Test_confirm()
@ -391,17 +474,20 @@ def Test_cursor()
var lines =<< trim END
cursor('2', 1)
END
CheckDefExecAndScriptFailure(lines, 'E475:')
CheckDefExecAndScriptFailure(lines, 'E1209:')
enddef
def Test_debugbreak()
CheckMSWindows
CheckDefFailure(['echo debugbreak("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['debugbreak("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef
def Test_delete()
var res: bool = delete('doesnotexist')
assert_equal(true, res)
CheckDefFailure(['delete(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
CheckDefFailure(['delete("a", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
enddef
def Test_diff_filler()
@ -438,10 +524,10 @@ def Test_execute()
res = execute(["echo 'here'", "echo 'there'"])
assert_equal("\nhere\nthere", res)
CheckDefFailure(['echo execute(123)'], 'E1013: Argument 1: type mismatch, expected string but got number')
CheckDefFailure(['echo execute([123])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>')
CheckDefFailure(['execute(123)'], 'E1013: Argument 1: type mismatch, expected string but got number')
CheckDefFailure(['execute([123])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>')
CheckDefExecFailure(['echo execute(["xx", 123])'], 'E492')
CheckDefFailure(['echo execute("xx", 123)'], 'E1013: Argument 2: type mismatch, expected string but got number')
CheckDefFailure(['execute("xx", 123)'], 'E1013: Argument 2: type mismatch, expected string but got number')
enddef
def Test_exepath()
@ -600,6 +686,26 @@ def Test_feedkeys()
unlet g:TestVar
enddef
def Test_indent()
CheckDefAndScriptFailure2(['indent([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E745: Using a List as a Number')
CheckDefAndScriptFailure2(['indent(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1138: Using a Bool as a Number')
assert_equal(0, indent(1))
enddef
def Test_input()
CheckDefFailure(['input(5)'], 'E1013: Argument 1: type mismatch, expected string but got number')
CheckDefAndScriptFailure2(['input(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
CheckDefFailure(['input("p", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
CheckDefAndScriptFailure2(['input("p", "q", 20)'], 'E1013: Argument 3: type mismatch, expected string but got number', 'E180: Invalid complete value')
enddef
def Test_inputdialog()
CheckDefFailure(['inputdialog(5)'], 'E1013: Argument 1: type mismatch, expected string but got number')
CheckDefAndScriptFailure2(['inputdialog(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
CheckDefFailure(['inputdialog("p", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
CheckDefFailure(['inputdialog("p", "q", 20)'], 'E1013: Argument 3: type mismatch, expected string but got number')
enddef
def Test_job_info_return_type()
if has('job')
job_start(&shell)
@ -627,15 +733,19 @@ def Test_filewritable()
enddef
def Test_finddir()
CheckDefExecFailure(['echo finddir(true)'], 'E1174:')
CheckDefExecFailure(['echo finddir(v:null)'], 'E1174:')
CheckDefAndScriptFailure2(['finddir(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['finddir(v:null)'], 'E1013: Argument 1: type mismatch, expected string but got special', 'E1174: String required for argument 1')
CheckDefExecFailure(['echo finddir("")'], 'E1175:')
CheckDefAndScriptFailure2(['finddir("a", [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E730: Using a List as a String')
CheckDefAndScriptFailure2(['finddir("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
enddef
def Test_findfile()
CheckDefExecFailure(['echo findfile(true)'], 'E1174:')
CheckDefExecFailure(['echo findfile(v:null)'], 'E1174:')
CheckDefExecFailure(['echo findfile("")'], 'E1175:')
CheckDefExecFailure(['findfile(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
CheckDefExecFailure(['findfile(v:null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
CheckDefExecFailure(['findfile("")'], 'E1175:')
CheckDefAndScriptFailure2(['findfile("a", [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E730: Using a List as a String')
CheckDefAndScriptFailure2(['findfile("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
enddef
def Test_flattennew()
@ -660,57 +770,57 @@ def Test_float_funcs_args()
CheckFeature float
# acos()
CheckDefFailure(['echo acos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['acos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
# asin()
CheckDefFailure(['echo asin("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['asin("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
# atan()
CheckDefFailure(['echo atan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['atan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
# atan2()
CheckDefFailure(['echo atan2("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['echo atan2(1.2, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string')
CheckDefFailure(['echo atan2(1.2)'], 'E119:')
CheckDefFailure(['atan2("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['atan2(1.2, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string')
CheckDefFailure(['atan2(1.2)'], 'E119:')
# ceil()
CheckDefFailure(['echo ceil("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['ceil("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
# cos()
CheckDefFailure(['echo cos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['cos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
# cosh()
CheckDefFailure(['echo cosh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['cosh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
# exp()
CheckDefFailure(['echo exp("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['exp("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
# float2nr()
CheckDefFailure(['echo float2nr("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['float2nr("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
# floor()
CheckDefFailure(['echo floor("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['floor("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
# fmod()
CheckDefFailure(['echo fmod(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string')
CheckDefFailure(['echo fmod("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['echo fmod(1.1)'], 'E119:')
CheckDefFailure(['fmod(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string')
CheckDefFailure(['fmod("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['fmod(1.1)'], 'E119:')
# isinf()
CheckDefFailure(['echo isinf("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['isinf("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
# isnan()
CheckDefFailure(['echo isnan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['isnan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
# log()
CheckDefFailure(['echo log("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['log("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
# log10()
CheckDefFailure(['echo log10("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['log10("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
# pow()
CheckDefFailure(['echo pow("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['echo pow(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string')
CheckDefFailure(['echo pow(1.1)'], 'E119:')
CheckDefFailure(['pow("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['pow(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string')
CheckDefFailure(['pow(1.1)'], 'E119:')
# round()
CheckDefFailure(['echo round("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['round("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
# sin()
CheckDefFailure(['echo sin("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['sin("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
# sinh()
CheckDefFailure(['echo sinh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['sinh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
# sqrt()
CheckDefFailure(['echo sqrt("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['sqrt("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
# tan()
CheckDefFailure(['echo tan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['tan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
# tanh()
CheckDefFailure(['echo tanh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['tanh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
# trunc()
CheckDefFailure(['echo trunc("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['trunc("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef
def Test_fnameescape()
@ -863,17 +973,17 @@ def Test_getcompletion()
enddef
def Test_getcurpos()
CheckDefFailure(['echo getcursorcharpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['getcursorcharpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef
def Test_getcursorcharpos()
CheckDefFailure(['echo getcursorcharpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['getcursorcharpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef
def Test_getcwd()
CheckDefFailure(['echo getcwd("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['echo getcwd("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['echo getcwd(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
CheckDefFailure(['getcwd("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['getcwd("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['getcwd(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
enddef
def Test_getloclist_return_type()
@ -921,9 +1031,28 @@ def Test_getftype()
enddef
def Test_getjumplist()
CheckDefFailure(['echo getjumplist("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['echo getjumplist("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['echo getjumplist(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
CheckDefFailure(['getjumplist("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['getjumplist("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['getjumplist(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
enddef
def Test_getline()
var lines =<< trim END
new
setline(1, ['hello', 'there', 'again'])
assert_equal('hello', getline(1))
assert_equal('hello', getline('.'))
normal 2Gvjv
assert_equal('there', getline("'<"))
assert_equal('again', getline("'>"))
END
CheckDefAndScriptSuccess(lines)
lines =<< trim END
echo getline('1')
END
CheckDefExecAndScriptFailure(lines, 'E1209:')
enddef
def Test_getmarklist()
@ -933,13 +1062,13 @@ def Test_getmarklist()
enddef
def Test_getmatches()
CheckDefFailure(['echo getmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['getmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef
def Test_getpos()
CheckDefFailure(['getpos(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
assert_equal([0, 1, 1, 0], getpos('.'))
assert_equal([0, 0, 0, 0], getpos('a'))
CheckDefExecFailure(['getpos("a")'], 'E1209:')
enddef
def Test_getqflist()
@ -983,11 +1112,11 @@ def Test_getregtype()
enddef
def Test_gettabinfo()
CheckDefFailure(['echo gettabinfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['gettabinfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef
def Test_gettagstack()
CheckDefFailure(['echo gettagstack("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['gettagstack("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef
def Test_gettext()
@ -996,11 +1125,11 @@ def Test_gettext()
enddef
def Test_getwininfo()
CheckDefFailure(['echo getwininfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['getwininfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef
def Test_getwinpos()
CheckDefFailure(['echo getwinpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['getwinpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef
def Test_glob()
@ -1020,10 +1149,21 @@ def Test_has()
has('eval', true)->assert_equal(1)
enddef
def Test_has_key()
var d = {123: 'xx'}
assert_true(has_key(d, '123'))
assert_true(has_key(d, 123))
assert_false(has_key(d, 'x'))
assert_false(has_key(d, 99))
CheckDefAndScriptFailure2(['has_key([1, 2], "k")'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
CheckDefAndScriptFailure2(['has_key({"a": 10}, ["a"])'], 'E1013: Argument 2: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
enddef
def Test_haslocaldir()
CheckDefFailure(['echo haslocaldir("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['echo haslocaldir("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['echo haslocaldir(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
CheckDefFailure(['haslocaldir("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['haslocaldir("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['haslocaldir(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
enddef
def Test_hasmapto()
@ -1124,7 +1264,7 @@ def Test_insert()
enddef
def Test_invert()
CheckDefFailure(['echo invert("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['invert("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef
def Test_isdirectory()
@ -1187,8 +1327,12 @@ def SID(): number
->str2nr()
enddef
def Test_listener_flush()
CheckDefAndScriptFailure2(['listener_flush([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
enddef
def Test_listener_remove()
CheckDefFailure(['echo listener_remove("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefAndScriptFailure2(['listener_remove("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
enddef
def Test_map_function_arg()
@ -1294,13 +1438,13 @@ def Test_map_failure()
enddef
def Test_matcharg()
CheckDefFailure(['echo matcharg("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['matcharg("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef
def Test_matchdelete()
CheckDefFailure(['echo matchdelete("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['echo matchdelete("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['echo matchdelete(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
CheckDefFailure(['matchdelete("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['matchdelete("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['matchdelete(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
enddef
def Test_max()
@ -1338,6 +1482,13 @@ def Test_min()
assert_equal([4, 5], l2)
enddef
def Test_mkdir()
CheckDefAndScriptFailure2(['mkdir(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
CheckDefAndScriptFailure2(['mkdir("a", {})'], 'E1013: Argument 2: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String')
CheckDefAndScriptFailure2(['mkdir("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
delete('a', 'rf')
enddef
def Test_nextnonblank()
CheckDefFailure(['nextnonblank(null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
assert_equal(0, nextnonblank(1))
@ -1348,8 +1499,13 @@ def Test_nr2char()
enddef
def Test_or()
CheckDefFailure(['echo or("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['echo or(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
CheckDefFailure(['or("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['or(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
enddef
def Test_popup_locate()
CheckDefAndScriptFailure2(['popup_locate("a", 20)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
CheckDefAndScriptFailure2(['popup_locate(10, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
enddef
def Test_prevnonblank()
@ -1364,6 +1520,34 @@ def Test_prompt_getprompt()
endif
enddef
def Test_prop_find()
CheckDefAndScriptFailure2(['prop_find([1, 2])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
CheckDefAndScriptFailure2(['prop_find([1, 2], "k")'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
CheckDefAndScriptFailure2(['prop_find({"a": 10}, ["a"])'], 'E1013: Argument 2: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
enddef
def Test_prop_type_add()
CheckDefAndScriptFailure2(['prop_type_add({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
CheckDefAndScriptFailure2(['prop_type_add("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required')
enddef
def Test_prop_type_change()
CheckDefAndScriptFailure2(['prop_type_change({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
CheckDefAndScriptFailure2(['prop_type_change("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required')
enddef
def Test_prop_type_delete()
CheckDefAndScriptFailure2(['prop_type_delete({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
CheckDefAndScriptFailure2(['prop_type_delete({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
CheckDefAndScriptFailure2(['prop_type_delete("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required')
enddef
def Test_prop_type_get()
CheckDefAndScriptFailure2(['prop_type_get({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
CheckDefAndScriptFailure2(['prop_type_get({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
CheckDefAndScriptFailure2(['prop_type_get("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required')
enddef
def Test_rand()
CheckDefFailure(['rand(10)'], 'E1013: Argument 1: type mismatch, expected list<number> but got number')
CheckDefFailure(['rand(["a"])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<string>')
@ -1371,6 +1555,12 @@ def Test_rand()
assert_true(rand(srand()) >= 0)
enddef
def Test_range()
CheckDefAndScriptFailure2(['range("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
CheckDefAndScriptFailure2(['range(10, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
CheckDefAndScriptFailure2(['range(10, 20, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
enddef
def Test_readdir()
eval expand('sautest')->readdir((e) => e[0] !=# '.')
eval expand('sautest')->readdirex((e) => e.name[0] !=# '.')
@ -1400,6 +1590,9 @@ def Test_readfile()
END
CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected dict<string> but got list<string>', 1)
delete('Xreadfile')
CheckDefAndScriptFailure2(['readfile("a", 0z10)'], 'E1013: Argument 2: type mismatch, expected string but got blob', 'E976: Using a Blob as a String')
CheckDefAndScriptFailure2(['readfile("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
enddef
def Test_reltime()
@ -1435,7 +1628,16 @@ def Test_remote_foreground()
assert_fails('remote_foreground("NonExistingServer")', 'E241:')
enddef
def Test_remote_peek()
CheckFeature clientserver
CheckEnv DISPLAY
CheckDefAndScriptFailure2(['remote_peek(0z10)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E976: Using a Blob as a String')
CheckDefAndScriptFailure2(['remote_peek("a5b6c7", [1])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E573: Invalid server id used')
enddef
def Test_remote_startserver()
CheckFeature clientserver
CheckEnv DISPLAY
CheckDefFailure(['remote_startserver({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>')
enddef
@ -1458,6 +1660,11 @@ def Test_resolve()
assert_equal('SomeFile', resolve('SomeFile'))
enddef
def Test_reverse()
CheckDefAndScriptFailure2(['reverse(10)'], 'E1013: Argument 1: type mismatch, expected list<any> but got number', 'E899: Argument of reverse() must be a List or Blob')
CheckDefAndScriptFailure2(['reverse("abc")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E899: Argument of reverse() must be a List or Blob')
enddef
def Test_reverse_return_type()
var l = reverse([1, 2, 3])
var res = 0
@ -1468,18 +1675,18 @@ def Test_reverse_return_type()
enddef
def Test_screenattr()
CheckDefFailure(['echo screenattr("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['echo screenattr(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
CheckDefFailure(['screenattr("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['screenattr(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
enddef
def Test_screenchar()
CheckDefFailure(['echo screenchar("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['echo screenchar(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
CheckDefFailure(['screenchar("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['screenchar(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
enddef
def Test_screenchars()
CheckDefFailure(['echo screenchars("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['echo screenchars(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
CheckDefFailure(['screenchars("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['screenchars(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
enddef
def Test_screenpos()
@ -1490,8 +1697,8 @@ def Test_screenpos()
enddef
def Test_screenstring()
CheckDefFailure(['echo screenstring("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['echo screenstring(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
CheckDefFailure(['screenstring("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['screenstring(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
enddef
def Test_search()
@ -1577,6 +1784,13 @@ def Test_searchpair()
bwipe!
enddef
def Test_server2client()
CheckFeature clientserver
CheckEnv DISPLAY
CheckDefAndScriptFailure2(['server2client(10, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E573: Invalid server id used:')
CheckDefAndScriptFailure2(['server2client("a", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E573: Invalid server id used:')
enddef
def Test_set_get_bufline()
# similar to Test_setbufline_getbufline()
var lines =<< trim END
@ -1665,7 +1879,7 @@ def Test_setcharsearch()
enddef
def Test_setcmdpos()
CheckDefFailure(['echo setcmdpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['setcmdpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef
def Test_setfperm()
@ -1695,7 +1909,24 @@ def Test_sha256()
enddef
def Test_shiftwidth()
CheckDefFailure(['echo shiftwidth("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['shiftwidth("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef
def Test_sign_define()
CheckDefAndScriptFailure2(['sign_define({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
CheckDefAndScriptFailure2(['sign_define({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
CheckDefAndScriptFailure2(['sign_define("a", ["b"])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<string>', 'E715: Dictionary required')
enddef
def Test_sign_undefine()
CheckDefAndScriptFailure2(['sign_undefine({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String')
CheckDefAndScriptFailure2(['sign_undefine([1])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>', 'E155: Unknown sign:')
enddef
def Test_sign_unplace()
CheckDefAndScriptFailure2(['sign_unplace({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E474: Invalid argument')
CheckDefAndScriptFailure2(['sign_unplace({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E474: Invalid argument')
CheckDefAndScriptFailure2(['sign_unplace("a", ["b"])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<string>', 'E715: Dictionary required')
enddef
def Test_simplify()
@ -1790,7 +2021,7 @@ def Run_str2float()
str2float("1.00")->assert_equal(1.00)
str2float("2e-2")->assert_equal(0.02)
CheckDefFailure(['echo str2float(123)'], 'E1013:')
CheckDefFailure(['str2float(123)'], 'E1013:')
CheckScriptFailure(['vim9script', 'echo str2float(123)'], 'E1024:')
endif
enddef
@ -1798,11 +2029,11 @@ enddef
def Test_str2nr()
str2nr("1'000'000", 10, true)->assert_equal(1000000)
CheckDefFailure(['echo str2nr(123)'], 'E1013:')
CheckDefFailure(['str2nr(123)'], 'E1013:')
CheckScriptFailure(['vim9script', 'echo str2nr(123)'], 'E1024:')
CheckDefFailure(['echo str2nr("123", "x")'], 'E1013:')
CheckDefFailure(['str2nr("123", "x")'], 'E1013:')
CheckScriptFailure(['vim9script', 'echo str2nr("123", "x")'], 'E1030:')
CheckDefFailure(['echo str2nr("123", 10, "x")'], 'E1013:')
CheckDefFailure(['str2nr("123", 10, "x")'], 'E1013:')
CheckScriptFailure(['vim9script', 'echo str2nr("123", 10, "x")'], 'E1135:')
enddef
@ -1810,6 +2041,12 @@ def Test_strchars()
strchars("A\u20dd", true)->assert_equal(1)
enddef
def Test_stridx()
CheckDefAndScriptFailure2(['stridx([1], "b")'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
CheckDefAndScriptFailure2(['stridx("a", {})'], 'E1013: Argument 2: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String')
CheckDefAndScriptFailure2(['stridx("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
enddef
def Test_strlen()
CheckDefFailure(['strlen([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
"abc"->strlen()->assert_equal(3)
@ -1826,6 +2063,12 @@ def Test_strptime()
#assert_true(strptime('%Y', '2021') != 0)
enddef
def Test_strridx()
CheckDefAndScriptFailure2(['strridx([1], "b")'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
CheckDefAndScriptFailure2(['strridx("a", {})'], 'E1013: Argument 2: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String')
CheckDefAndScriptFailure2(['strridx("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
enddef
def Test_strtrans()
CheckDefFailure(['strtrans(20)'], 'E1013: Argument 1: type mismatch, expected string but got number')
assert_equal('abc', strtrans('abc'))
@ -1883,11 +2126,63 @@ def Test_tabpagebuflist()
enddef
def Test_tabpagenr()
CheckDefFailure(['tabpagenr(1)'], 'E1013: Argument 1: type mismatch, expected string but got number')
CheckDefAndScriptFailure2(['tabpagenr(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E15: Invalid expression:')
assert_equal(1, tabpagenr('$'))
assert_equal(1, tabpagenr())
enddef
def Test_taglist()
CheckDefAndScriptFailure2(['taglist([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
CheckDefAndScriptFailure2(['taglist("a", [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
enddef
def Test_term_dumpload()
CheckRunVimInTerminal
CheckDefAndScriptFailure2(['term_dumpload({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['term_dumpload({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['term_dumpload("a", ["b"])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<string>', 'E1206: Dictionary required for argument 2')
enddef
def Test_term_getaltscreen()
CheckRunVimInTerminal
CheckDefAndScriptFailure2(['term_getaltscreen(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1138: Using a Bool as a Number')
enddef
def Test_term_getansicolors()
CheckRunVimInTerminal
CheckDefAndScriptFailure2(['term_getansicolors(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E745: Using a List as a Number')
enddef
def Test_term_getcursor()
CheckRunVimInTerminal
CheckDefAndScriptFailure2(['term_getcursor({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E728: Using a Dictionary as a Number')
enddef
def Test_term_getjob()
CheckRunVimInTerminal
CheckDefAndScriptFailure2(['term_getjob(0z10)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E974: Using a Blob as a Number')
enddef
def Test_term_getscrolled()
CheckRunVimInTerminal
CheckDefAndScriptFailure2(['term_getscrolled(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E805: Using a Float as a Number')
enddef
def Test_term_getsize()
CheckRunVimInTerminal
CheckDefAndScriptFailure2(['term_getsize(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E805: Using a Float as a Number')
enddef
def Test_term_getstatus()
CheckRunVimInTerminal
CheckDefAndScriptFailure2(['term_getstatus(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E805: Using a Float as a Number')
enddef
def Test_term_gettitle()
CheckRunVimInTerminal
CheckDefAndScriptFailure2(['term_gettitle(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E805: Using a Float as a Number')
enddef
def Test_term_gettty()
if !has('terminal')
MissingFeature 'terminal'
@ -1910,6 +2205,44 @@ def Test_term_start()
endif
enddef
def Test_test_alloc_fail()
CheckDefAndScriptFailure2(['test_alloc_fail("a", 10, 20)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E474: Invalid argument')
CheckDefAndScriptFailure2(['test_alloc_fail(10, "b", 20)'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E474: Invalid argument')
CheckDefAndScriptFailure2(['test_alloc_fail(10, 20, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E474: Invalid argument')
enddef
def Test_test_feedinput()
CheckDefAndScriptFailure2(['test_feedinput(test_void())'], 'E1013: Argument 1: type mismatch, expected string but got void', 'E1031: Cannot use void value')
CheckDefAndScriptFailure2(['test_feedinput(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
enddef
def Test_test_getvalue()
CheckDefAndScriptFailure2(['test_getvalue(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E474: Invalid argument')
enddef
def Test_test_ignore_error()
CheckDefAndScriptFailure2(['test_ignore_error([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E474: Invalid argument')
test_ignore_error('RESET')
enddef
def Test_test_option_not_set()
CheckDefAndScriptFailure2(['test_option_not_set([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E474: Invalid argument')
enddef
def Test_test_setmouse()
CheckDefAndScriptFailure2(['test_setmouse("a", 10)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E474: Invalid argument')
CheckDefAndScriptFailure2(['test_setmouse(10, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E474: Invalid argument')
enddef
def Test_test_settime()
CheckDefAndScriptFailure2(['test_settime([1])'], 'E1013: Argument 1: type mismatch, expected number but got list<number>', 'E745: Using a List as a Number')
enddef
def Test_test_srand_seed()
CheckDefAndScriptFailure2(['test_srand_seed([1])'], 'E1013: Argument 1: type mismatch, expected number but got list<number>', 'E745: Using a List as a Number')
CheckDefAndScriptFailure2(['test_srand_seed("10")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
enddef
def Test_timer_info()
CheckDefFailure(['timer_info("id")'], 'E1013: Argument 1: type mismatch, expected number but got string')
assert_equal([], timer_info(100))
@ -1930,17 +2263,29 @@ def Test_timer_stop()
enddef
def Test_tolower()
CheckDefFailure(['echo tolower(1)'], 'E1013: Argument 1: type mismatch, expected string but got number')
CheckDefFailure(['tolower(1)'], 'E1013: Argument 1: type mismatch, expected string but got number')
enddef
def Test_toupper()
CheckDefFailure(['echo toupper(1)'], 'E1013: Argument 1: type mismatch, expected string but got number')
CheckDefFailure(['toupper(1)'], 'E1013: Argument 1: type mismatch, expected string but got number')
enddef
def Test_tr()
CheckDefFailure(['echo tr(1, "a", "b")'], 'E1013: Argument 1: type mismatch, expected string but got number')
CheckDefFailure(['echo tr("a", 1, "b")'], 'E1013: Argument 2: type mismatch, expected string but got number')
CheckDefFailure(['echo tr("a", "a", 1)'], 'E1013: Argument 3: type mismatch, expected string but got number')
CheckDefFailure(['tr(1, "a", "b")'], 'E1013: Argument 1: type mismatch, expected string but got number')
CheckDefFailure(['tr("a", 1, "b")'], 'E1013: Argument 2: type mismatch, expected string but got number')
CheckDefFailure(['tr("a", "a", 1)'], 'E1013: Argument 3: type mismatch, expected string but got number')
enddef
def Test_trim()
CheckDefAndScriptFailure2(['trim(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
CheckDefAndScriptFailure2(['trim("a", ["b"])'], 'E1013: Argument 2: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
CheckDefAndScriptFailure2(['trim("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
enddef
def Test_typename()
if has('float')
assert_equal('func([unknown], [unknown]): float', typename(function('pow')))
endif
enddef
def Test_undofile()
@ -1954,6 +2299,10 @@ def Test_values()
assert_equal(['sun'], {star: 'sun'}->values())
enddef
def Test_virtcol()
CheckDefAndScriptFailure2(['virtcol(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1')
enddef
def Test_win_execute()
assert_equal("\n" .. winnr(), win_execute(win_getid(), 'echo winnr()'))
assert_equal('', win_execute(342343, 'echo winnr()'))
@ -2010,44 +2359,44 @@ def Test_winsaveview()
enddef
def Test_win_gettype()
CheckDefFailure(['echo win_gettype("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefAndScriptFailure2(['win_gettype("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
enddef
def Test_win_gotoid()
CheckDefFailure(['echo win_gotoid("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefAndScriptFailure2(['win_gotoid("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
enddef
def Test_win_id2tabwin()
CheckDefFailure(['echo win_id2tabwin("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefAndScriptFailure2(['win_id2tabwin("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
enddef
def Test_win_id2win()
CheckDefFailure(['echo win_id2win("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefAndScriptFailure2(['win_id2win("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
enddef
def Test_win_screenpos()
CheckDefFailure(['echo win_screenpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefAndScriptFailure2(['win_screenpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
enddef
def Test_winbufnr()
CheckDefFailure(['echo winbufnr("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefAndScriptFailure2(['winbufnr("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
enddef
def Test_winheight()
CheckDefFailure(['echo winheight("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefAndScriptFailure2(['winheight("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
enddef
def Test_winlayout()
CheckDefFailure(['echo winlayout("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefAndScriptFailure2(['winlayout("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
enddef
def Test_winwidth()
CheckDefFailure(['echo winwidth("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefAndScriptFailure2(['winwidth("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
enddef
def Test_xor()
CheckDefFailure(['echo xor("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string')
CheckDefFailure(['echo xor(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
CheckDefAndScriptFailure2(['xor("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
CheckDefAndScriptFailure2(['xor(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
enddef
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

View File

@ -647,7 +647,7 @@ def Test_expr4_equal()
CheckDefFailure(["var x = 'a' == "], 'E1097:', 3)
CheckScriptFailure(['vim9script', "var x = 'a' == "], 'E15:', 2)
CheckDefExecAndScriptFailure2(['var items: any', 'eval 1', 'eval 2', 'if items == []', 'endif'], 'E691:', 'E1072:', 4)
CheckDefExecAndScriptFailure2(['var items: any', 'eval 1 + 1', 'eval 2 + 2', 'if items == []', 'endif'], 'E691:', 'E1072:', 4)
CheckDefExecAndScriptFailure(['var x: any = "a"', 'echo x == true'], 'E1072: Cannot compare string with bool', 2)
CheckDefExecAndScriptFailure(["var x: any = true", 'echo x == ""'], 'E1072: Cannot compare bool with string', 2)

View File

@ -2538,7 +2538,7 @@ def Test_restore_modifiers()
set eventignore=
autocmd QuickFixCmdPost * copen
def AutocmdsDisabled()
eval 0
eval 1 + 2
enddef
func Func()
noautocmd call s:AutocmdsDisabled()
@ -2551,8 +2551,8 @@ def Test_restore_modifiers()
enddef
def StackTop()
eval 1
eval 2
eval 1 + 2
eval 2 + 3
# call not on fourth line
StackBot()
enddef

View File

@ -691,7 +691,7 @@ enddef
def Test_cnext_works_in_catch()
var lines =<< trim END
vim9script
au BufEnter * eval 0
au BufEnter * eval 1 + 2
writefile(['text'], 'Xfile1')
writefile(['text'], 'Xfile2')
var items = [
@ -1754,6 +1754,21 @@ def Test_script_var_shadows_function()
CheckScriptFailure(lines, 'E1041:', 5)
enddef
def Test_script_var_shadows_command()
var lines =<< trim END
var undo = 1
undo = 2
assert_equal(2, undo)
END
CheckDefAndScriptSuccess(lines)
lines =<< trim END
var undo = 1
undo
END
CheckDefAndScriptFailure(lines, 'E1207:', 2)
enddef
def s:RetSome(): string
return 'some'
enddef
@ -2270,7 +2285,7 @@ def Test_if_const_expr()
assert_equal(false, res)
# with constant "false" expression may be invalid so long as the syntax is OK
if false | eval 0 | endif
if false | eval 1 + 2 | endif
if false | eval burp + 234 | endif
if false | echo burp 234 'asd' | endif
if false
@ -4152,6 +4167,31 @@ def Test_option_modifier()
set hlsearch&
enddef
" This must be called last, it may cause following :def functions to fail
def Test_xxx_echoerr_line_number()
var lines =<< trim END
echoerr 'some'
.. ' error'
.. ' continued'
END
CheckDefExecAndScriptFailure(lines, 'some error continued', 1)
enddef
def ProfiledFunc()
var n = 3
echo [[1, 2], [3, 4]]->filter((_, l) => l[0] == n)
enddef
" Execute this near the end, profiling doesn't stop until Vim exists.
" This only tests that it works, not the profiling output.
def Test_xx_profile_with_lambda()
CheckFeature profile
profile start Xprofile.log
profile func ProfiledFunc
ProfiledFunc()
enddef
" Keep this last, it messes up highlighting.
def Test_substitute_cmd()
new

View File

@ -1096,7 +1096,10 @@ f_test_garbagecollect_soon(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
void
f_test_ignore_error(typval_T *argvars, typval_T *rettv UNUSED)
{
ignore_error_for_testing(tv_get_string(&argvars[0]));
if (argvars[0].v_type != VAR_STRING)
emsg(_(e_invarg));
else
ignore_error_for_testing(tv_get_string(&argvars[0]));
}
void

View File

@ -605,7 +605,7 @@ f_prop_find(typval_T *argvars, typval_T *rettv)
if (argvars[0].v_type != VAR_DICT || argvars[0].vval.v_dict == NULL)
{
emsg(_(e_invarg));
emsg(_(e_dictreq));
return;
}
dict = argvars[0].vval.v_dict;

View File

@ -384,6 +384,23 @@ check_for_nonempty_string_arg(typval_T *args, int idx)
return OK;
}
/*
* Give an error and return FAIL unless "tv" is a dict.
*/
int
check_for_dict_arg(typval_T *args, int idx)
{
if (args[idx].v_type != VAR_DICT)
{
if (idx >= 0)
semsg(_(e_dict_required_for_argument_nr), idx + 1);
else
emsg(_(e_dictreq));
return FAIL;
}
return OK;
}
/*
* Get the string value of a variable.
* If it is a Number variable, the number is converted into a string.
@ -456,13 +473,13 @@ tv_get_string_buf_chk_strict(typval_T *varp, char_u *buf, int strict)
return buf;
case VAR_FUNC:
case VAR_PARTIAL:
emsg(_("E729: using Funcref as a String"));
emsg(_("E729: Using a Funcref as a String"));
break;
case VAR_LIST:
emsg(_("E730: using List as a String"));
emsg(_("E730: Using a List as a String"));
break;
case VAR_DICT:
emsg(_("E731: using Dictionary as a String"));
emsg(_("E731: Using a Dictionary as a String"));
break;
case VAR_FLOAT:
#ifdef FEAT_FLOAT
@ -483,7 +500,7 @@ tv_get_string_buf_chk_strict(typval_T *varp, char_u *buf, int strict)
STRCPY(buf, get_var_special_name(varp->vval.v_number));
return buf;
case VAR_BLOB:
emsg(_("E976: using Blob as a String"));
emsg(_("E976: Using a Blob as a String"));
break;
case VAR_JOB:
#ifdef FEAT_JOB_CHANNEL

View File

@ -1019,21 +1019,15 @@ ex_command(exarg_T *eap)
// we are listing commands
p = skipwhite(end);
if (!has_attr && ends_excmd2(eap->arg, p))
{
uc_list(name, end - name);
}
else if (!ASCII_ISUPPER(*name))
{
emsg(_("E183: User defined commands must start with an uppercase letter"));
return;
}
else if ((name_len == 1 && *name == 'X')
|| (name_len <= 4
&& STRNCMP(name, "Next", name_len > 4 ? 4 : name_len) == 0))
{
emsg(_("E841: Reserved name, cannot be used for user defined command"));
return;
}
else if (compl > 0 && (argt & EX_EXTRA) == 0)
emsg(_(e_complete_used_without_nargs));
else
uc_add_command(name, end - name, p, argt, def, flags, compl, compl_arg,
addr_type_arg, eap->forceit);

View File

@ -755,6 +755,34 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
3146,
/**/
3145,
/**/
3144,
/**/
3143,
/**/
3142,
/**/
3141,
/**/
3140,
/**/
3139,
/**/
3138,
/**/
3137,
/**/
3136,
/**/
3135,
/**/
3134,
/**/
3133,
/**/
3132,
/**/

View File

@ -3624,6 +3624,11 @@ compile_lambda(char_u **arg, cctx_T *cctx)
ufunc->uf_ret_type = &t_unknown;
compile_def_function(ufunc, FALSE, cctx->ctx_compile_type, cctx);
// When the outer function is compiled for profiling, the lambda may be
// called without profiling. Compile it here in the right context.
if (cctx->ctx_compile_type == CT_PROFILE)
compile_def_function(ufunc, FALSE, CT_NONE, cctx);
// evalarg.eval_tofree_cmdline may have a copy of the last line and "*arg"
// points into it. Point to the original line to avoid a dangling pointer.
if (evalarg.eval_tofree_cmdline != NULL)
@ -8563,6 +8568,37 @@ compile_throw(char_u *arg, cctx_T *cctx UNUSED)
return p;
}
static char_u *
compile_eval(char_u *arg, cctx_T *cctx)
{
char_u *p = arg;
int name_only;
char_u *alias;
long lnum = SOURCING_LNUM;
// find_ex_command() will consider a variable name an expression, assuming
// that something follows on the next line. Check that something actually
// follows, otherwise it's probably a misplaced command.
get_name_len(&p, &alias, FALSE, FALSE);
name_only = ends_excmd2(arg, skipwhite(p));
vim_free(alias);
p = arg;
if (compile_expr0(&p, cctx) == FAIL)
return NULL;
if (name_only && lnum == SOURCING_LNUM)
{
semsg(_(e_expression_without_effect_str), arg);
return NULL;
}
// drop the result
generate_instr_drop(cctx, ISN_DROP, 1);
return skipwhite(p);
}
/*
* compile "echo expr"
* compile "echomsg expr"
@ -9630,13 +9666,7 @@ compile_def_function(
break;
case CMD_eval:
if (compile_expr0(&p, &cctx) == FAIL)
goto erret;
// drop the result
generate_instr_drop(&cctx, ISN_DROP, 1);
line = skipwhite(p);
line = compile_eval(p, &cctx);
break;
case CMD_echo:

View File

@ -1166,7 +1166,7 @@ type_name(type_T *type, char **tofree)
for (i = 0; i < type->tt_argcount; ++i)
{
char *arg_free;
char *arg_free = NULL;
char *arg_type;
int len;