vim-patch:8.2.0502: Vim9: some code is not tested

Problem:    Vim9: some code is not tested.
Solution:   Add more tests.  Fix uncovered problems.

e8c4abbbd7

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq
2022-11-05 11:17:10 +08:00
parent 81722896e4
commit 45ca7d4a62
11 changed files with 28 additions and 18 deletions

View File

@@ -1246,7 +1246,7 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, cons
arg = (const char *)skipwhite(skiptowhite(arg));
if (*arg != NUL) {
xp->xp_context = EXPAND_NOTHING;
arg = (const char *)skip_regexp((char *)arg + 1, (uint8_t)(*arg), p_magic, NULL);
arg = (const char *)skip_regexp((char *)arg + 1, (uint8_t)(*arg), p_magic);
}
}
return (const char *)find_nextcmd(arg);
@@ -1285,7 +1285,7 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, cons
if (delim) {
// Skip "from" part.
arg++;
arg = (const char *)skip_regexp((char *)arg, delim, p_magic, NULL);
arg = (const char *)skip_regexp((char *)arg, delim, p_magic);
}
// Skip "to" part.
while (arg[0] != NUL && (uint8_t)arg[0] != delim) {

View File

@@ -1964,7 +1964,7 @@ void ex_function(exarg_T *eap)
// ":function /pat": list functions matching pattern.
if (*eap->arg == '/') {
p = skip_regexp(eap->arg + 1, '/', true, NULL);
p = skip_regexp(eap->arg + 1, '/', true);
if (!eap->skip) {
regmatch_T regmatch;

View File

@@ -504,7 +504,7 @@ void ex_sort(exarg_T *eap)
eap->nextcmd = check_nextcmd(p);
break;
} else if (!ASCII_ISALPHA(*p) && regmatch.regprog == NULL) {
s = skip_regexp(p + 1, *p, true, NULL);
s = skip_regexp(p + 1, *p, true);
if (*s != *p) {
emsg(_(e_invalpat));
goto sortend;
@@ -3503,7 +3503,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T
which_pat = RE_LAST; // use last used regexp
delimiter = (char_u)(*cmd++); // remember delimiter character
pat = cmd; // remember start of search pat
cmd = skip_regexp(cmd, delimiter, p_magic, &eap->arg);
cmd = skip_regexp_ex(cmd, delimiter, p_magic, &eap->arg, NULL);
if (cmd[0] == delimiter) { // end delimiter found
*cmd++ = NUL; // replace it with a NUL
has_second_delim = true;
@@ -4536,7 +4536,7 @@ void ex_global(exarg_T *eap)
delim = *cmd; // get the delimiter
cmd++; // skip delimiter if there is one
pat = cmd; // remember start of pattern
cmd = skip_regexp(cmd, delim, p_magic, &eap->arg);
cmd = skip_regexp_ex(cmd, delim, p_magic, &eap->arg, NULL);
if (cmd[0] == delim) { // end delimiter found
*cmd++ = NUL; // replace it with a NUL
}
@@ -4849,7 +4849,7 @@ char *skip_vimgrep_pat(char *p, char **s, int *flags)
*s = p + 1;
}
c = (char_u)(*p);
p = skip_regexp(p + 1, c, true, NULL);
p = skip_regexp(p + 1, c, true);
if (*p != c) {
return NULL;
}

View File

@@ -3351,7 +3351,7 @@ static linenr_T get_address(exarg_T *eap, char **ptr, cmd_addr_T addr_type, int
goto error;
}
if (skip) { // skip "/pat/"
cmd = skip_regexp(cmd, c, p_magic, NULL);
cmd = skip_regexp(cmd, c, p_magic);
if (*cmd == c) {
cmd++;
}
@@ -6494,7 +6494,7 @@ static void ex_findpat(exarg_T *eap)
if (*eap->arg == '/') { // Match regexp, not just whole words
whole = false;
eap->arg++;
char *p = skip_regexp(eap->arg, '/', p_magic, NULL);
char *p = skip_regexp(eap->arg, '/', p_magic);
if (*p) {
*p++ = NUL;
p = skipwhite(p);

View File

@@ -1296,7 +1296,7 @@ void ex_catch(exarg_T *eap)
eap->nextcmd = find_nextcmd(eap->arg);
} else {
pat = eap->arg + 1;
end = skip_regexp(pat, *eap->arg, true, NULL);
end = skip_regexp(pat, *eap->arg, true);
}
if (!give_up) {

View File

@@ -314,7 +314,7 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s
p = skipwhite(p);
delim = (delim_optional && vim_isIDc(*p)) ? ' ' : *p++;
*search_delim = delim;
end = skip_regexp(p, delim, p_magic, NULL);
end = skip_regexp(p, delim, p_magic);
use_last_pat = end == p && *end == delim;
if (end == p && !use_last_pat) {

View File

@@ -1206,7 +1206,7 @@ void ex_match(exarg_T *eap)
semsg(_(e_invarg2), eap->arg);
return;
}
end = skip_regexp(p + 1, *p, true, NULL);
end = skip_regexp(p + 1, *p, true);
if (!eap->skip) {
if (*end != NUL && !ends_excmd(*skipwhite(end + 1))) {
xfree(g);

View File

@@ -484,10 +484,17 @@ static char_u *skip_anyof(char *p)
/// Stop at end of "startp" or where "dirc" is found ('/', '?', etc).
/// Take care of characters with a backslash in front of it.
/// Skip strings inside [ and ].
char *skip_regexp(char *startp, int dirc, int magic)
{
return skip_regexp_ex(startp, dirc, magic, NULL, NULL);
}
/// skip_regexp() with extra arguments:
/// When "newp" is not NULL and "dirc" is '?', make an allocated copy of the
/// expression and change "\?" to "?". If "*newp" is not NULL the expression
/// is changed in-place.
char *skip_regexp(char *startp, int dirc, int magic, char **newp)
/// If a "\?" is changed to "?" then "dropped" is incremented, unless NULL.
char *skip_regexp_ex(char *startp, int dirc, int magic, char **newp, int *dropped)
{
int mymagic;
char *p = startp;
@@ -516,6 +523,9 @@ char *skip_regexp(char *startp, int dirc, int magic, char **newp)
*newp = xstrdup(startp);
p = *newp + (p - startp);
}
if (dropped != NULL) {
(*dropped)++;
}
STRMOVE(p, p + 1);
} else {
p++; // skip next character

View File

@@ -1080,7 +1080,7 @@ int do_search(oparg_T *oap, int dirc, int search_delim, char_u *pat, long count,
// Find end of regular expression.
// If there is a matching '/' or '?', toss it.
ps = (char_u *)strcopy;
p = (char_u *)skip_regexp((char *)pat, search_delim, p_magic, &strcopy);
p = (char_u *)skip_regexp_ex((char *)pat, search_delim, p_magic, &strcopy, NULL);
if (strcopy != (char *)ps) {
// made a copy of "pat" to change "\?" to "?"
searchcmdlen += (int)(STRLEN(pat) - strlen(strcopy));

View File

@@ -4749,7 +4749,7 @@ static char *get_syn_pattern(char *arg, synpat_T *ci)
return NULL;
}
end = skip_regexp(arg + 1, *arg, true, NULL);
end = skip_regexp(arg + 1, *arg, true);
if (*end != *arg) { // end delimiter not found
semsg(_("E401: Pattern delimiter not found: %s"), arg);
return NULL;
@@ -4902,7 +4902,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing)
finished = true;
break;
}
arg_end = skip_regexp(next_arg + 1, *next_arg, true, NULL);
arg_end = skip_regexp(next_arg + 1, *next_arg, true);
if (*arg_end != *next_arg) { // end delimiter not found
illegal = true;
break;

View File

@@ -2670,7 +2670,7 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help)
// anything following.
str = pbuf;
if (pbuf[0] == '/' || pbuf[0] == '?') {
str = (char_u *)skip_regexp((char *)pbuf + 1, pbuf[0], false, NULL) + 1;
str = (char_u *)skip_regexp((char *)pbuf + 1, pbuf[0], false) + 1;
}
if (str > pbuf_end - 1) { // search command with nothing following
save_p_ws = p_ws;
@@ -2883,7 +2883,7 @@ static int find_extra(char_u **pp)
if (ascii_isdigit(*str)) {
str = (char_u *)skipdigits((char *)str + 1);
} else if (*str == '/' || *str == '?') {
str = (char_u *)skip_regexp((char *)str + 1, *str, false, NULL);
str = (char_u *)skip_regexp((char *)str + 1, *str, false);
if (*str != first_char) {
str = NULL;
} else {