vim-patch:8.2.1280: Ex command error cannot contain an argument

Problem:    Ex command error cannot contain an argument.
Solution:   Add ex_errmsg() and translate earlier.  Use e_trailing_arg where
            possible.
8930caaa1a

Remove duplicate test file 062_tab_pages_spec.lua
This commit is contained in:
zeertzjq 2022-08-07 13:47:46 +08:00
parent 3b7fc5f793
commit d0686540f5
7 changed files with 63 additions and 302 deletions

View File

@ -969,7 +969,7 @@ char *do_bufdel(int command, char *arg, int addr_count, int start_bnr, int end_b
} else { } else {
if (addr_count == 2) { if (addr_count == 2) {
if (*arg) { // both range and argument is not allowed if (*arg) { // both range and argument is not allowed
return _(e_trailing); return ex_errmsg(e_trailing_arg, arg);
} }
bnr = start_bnr; bnr = start_bnr;
} else { // addr_count == 1 } else { // addr_count == 1

View File

@ -1635,7 +1635,7 @@ static int execute_cmd0(int *retv, exarg_T *eap, char **errormsg, bool preview)
(cmdnames[eap->cmdidx].cmd_func)(eap); (cmdnames[eap->cmdidx].cmd_func)(eap);
} }
if (eap->errmsg != NULL) { if (eap->errmsg != NULL) {
*errormsg = _(eap->errmsg); *errormsg = eap->errmsg;
} }
} }
@ -4381,7 +4381,7 @@ static void get_flags(exarg_T *eap)
void ex_ni(exarg_T *eap) void ex_ni(exarg_T *eap)
{ {
if (!eap->skip) { if (!eap->skip) {
eap->errmsg = N_("E319: The command is not available in this version"); eap->errmsg = _("E319: The command is not available in this version");
} }
} }
@ -5018,7 +5018,7 @@ static int get_tabpage_arg(exarg_T *eap)
} else if (p == p_save || *p_save == '-' || *p != NUL } else if (p == p_save || *p_save == '-' || *p != NUL
|| tab_number > LAST_TAB_NR) { || tab_number > LAST_TAB_NR) {
// No numbers as argument. // No numbers as argument.
eap->errmsg = e_invarg; eap->errmsg = ex_errmsg(e_invarg2, eap->arg);
goto theend; goto theend;
} }
} else { } else {
@ -5026,20 +5026,20 @@ static int get_tabpage_arg(exarg_T *eap)
tab_number = 1; tab_number = 1;
} else if (p == p_save || *p_save == '-' || *p != NUL || tab_number == 0) { } else if (p == p_save || *p_save == '-' || *p != NUL || tab_number == 0) {
// No numbers as argument. // No numbers as argument.
eap->errmsg = e_invarg; eap->errmsg = ex_errmsg(e_invarg2, eap->arg);
goto theend; goto theend;
} }
tab_number = tab_number * relative + tabpage_index(curtab); tab_number = tab_number * relative + tabpage_index(curtab);
if (!unaccept_arg0 && relative == -1) { if (!unaccept_arg0 && relative == -1) {
--tab_number; tab_number--;
} }
} }
if (tab_number < unaccept_arg0 || tab_number > LAST_TAB_NR) { if (tab_number < unaccept_arg0 || tab_number > LAST_TAB_NR) {
eap->errmsg = e_invarg; eap->errmsg = ex_errmsg(e_invarg2, eap->arg);
} }
} else if (eap->addr_count > 0) { } else if (eap->addr_count > 0) {
if (unaccept_arg0 && eap->line2 == 0) { if (unaccept_arg0 && eap->line2 == 0) {
eap->errmsg = e_invrange; eap->errmsg = _(e_invrange);
tab_number = 0; tab_number = 0;
} else { } else {
tab_number = (int)eap->line2; tab_number = (int)eap->line2;
@ -5048,7 +5048,7 @@ static int get_tabpage_arg(exarg_T *eap)
if (!unaccept_arg0 && *cmdp == '-') { if (!unaccept_arg0 && *cmdp == '-') {
tab_number--; tab_number--;
if (tab_number < unaccept_arg0) { if (tab_number < unaccept_arg0) {
eap->errmsg = e_invarg; eap->errmsg = _(e_invrange);
} }
} }
} }
@ -5078,7 +5078,7 @@ static void ex_autocmd(exarg_T *eap)
// directory for security reasons. // directory for security reasons.
if (secure) { if (secure) {
secure = 2; secure = 2;
eap->errmsg = e_curdir; eap->errmsg = _(e_curdir);
} else if (eap->cmdidx == CMD_autocmd) { } else if (eap->cmdidx == CMD_autocmd) {
do_autocmd(eap->arg, eap->forceit); do_autocmd(eap->arg, eap->forceit);
} else { } else {
@ -5119,7 +5119,7 @@ static void ex_bunload(exarg_T *eap)
static void ex_buffer(exarg_T *eap) static void ex_buffer(exarg_T *eap)
{ {
if (*eap->arg) { if (*eap->arg) {
eap->errmsg = e_trailing; eap->errmsg = ex_errmsg(e_trailing_arg, eap->arg);
} else { } else {
if (eap->addr_count == 0) { // default is current buffer if (eap->addr_count == 0) { // default is current buffer
goto_buffer(eap, DOBUF_CURRENT, FORWARD, 0); goto_buffer(eap, DOBUF_CURRENT, FORWARD, 0);
@ -5943,7 +5943,7 @@ static void ex_recover(exarg_T *eap)
/// Command modifier used in a wrong way. /// Command modifier used in a wrong way.
static void ex_wrongmodifier(exarg_T *eap) static void ex_wrongmodifier(exarg_T *eap)
{ {
eap->errmsg = e_invcmd; eap->errmsg = _(e_invcmd);
} }
/// :sview [+command] file split window with new file, read-only /// :sview [+command] file split window with new file, read-only
@ -6052,7 +6052,7 @@ static void ex_tabnext(exarg_T *eap)
if (p == p_save || *p_save == '-' || *p_save == '+' || *p != NUL if (p == p_save || *p_save == '-' || *p_save == '+' || *p != NUL
|| tab_number == 0) { || tab_number == 0) {
// No numbers as argument. // No numbers as argument.
eap->errmsg = e_invarg; eap->errmsg = ex_errmsg(e_invarg2, eap->arg);
return; return;
} }
} else { } else {
@ -6061,7 +6061,7 @@ static void ex_tabnext(exarg_T *eap)
} else { } else {
tab_number = (int)eap->line2; tab_number = (int)eap->line2;
if (tab_number < 1) { if (tab_number < 1) {
eap->errmsg = e_invrange; eap->errmsg = _(e_invrange);
return; return;
} }
} }
@ -6339,7 +6339,7 @@ void do_exedit(exarg_T *eap, win_T *old_curwin)
/// ":gui" and ":gvim" when there is no GUI. /// ":gui" and ":gvim" when there is no GUI.
static void ex_nogui(exarg_T *eap) static void ex_nogui(exarg_T *eap)
{ {
eap->errmsg = N_("E25: Nvim does not have a built-in GUI"); eap->errmsg = _("E25: Nvim does not have a built-in GUI");
} }
static void ex_popup(exarg_T *eap) static void ex_popup(exarg_T *eap)
@ -7559,7 +7559,7 @@ static void ex_findpat(exarg_T *eap)
// Check for trailing illegal characters. // Check for trailing illegal characters.
if (!ends_excmd(*p)) { if (!ends_excmd(*p)) {
eap->errmsg = e_trailing; eap->errmsg = ex_errmsg(e_trailing_arg, p);
} else { } else {
eap->nextcmd = (char *)check_nextcmd((char_u *)p); eap->nextcmd = (char *)check_nextcmd((char_u *)p);
} }

View File

@ -812,7 +812,7 @@ void ex_if(exarg_T *eap)
cstack_T *const cstack = eap->cstack; cstack_T *const cstack = eap->cstack;
if (cstack->cs_idx == CSTACK_LEN - 1) { if (cstack->cs_idx == CSTACK_LEN - 1) {
eap->errmsg = N_("E579: :if nesting too deep"); eap->errmsg = _("E579: :if nesting too deep");
} else { } else {
++cstack->cs_idx; ++cstack->cs_idx;
cstack->cs_flags[cstack->cs_idx] = 0; cstack->cs_flags[cstack->cs_idx] = 0;
@ -840,7 +840,7 @@ void ex_endif(exarg_T *eap)
if (eap->cstack->cs_idx < 0 if (eap->cstack->cs_idx < 0
|| (eap->cstack->cs_flags[eap->cstack->cs_idx] || (eap->cstack->cs_flags[eap->cstack->cs_idx]
& (CSF_WHILE | CSF_FOR | CSF_TRY))) { & (CSF_WHILE | CSF_FOR | CSF_TRY))) {
eap->errmsg = N_("E580: :endif without :if"); eap->errmsg = _("E580: :endif without :if");
} else { } else {
// When debugging or a breakpoint was encountered, display the debug // When debugging or a breakpoint was encountered, display the debug
// prompt (if not already done). This shows the user that an ":endif" // prompt (if not already done). This shows the user that an ":endif"
@ -870,17 +870,17 @@ void ex_else(exarg_T *eap)
|| (cstack->cs_flags[cstack->cs_idx] || (cstack->cs_flags[cstack->cs_idx]
& (CSF_WHILE | CSF_FOR | CSF_TRY))) { & (CSF_WHILE | CSF_FOR | CSF_TRY))) {
if (eap->cmdidx == CMD_else) { if (eap->cmdidx == CMD_else) {
eap->errmsg = N_("E581: :else without :if"); eap->errmsg = _("E581: :else without :if");
return; return;
} }
eap->errmsg = N_("E582: :elseif without :if"); eap->errmsg = _("E582: :elseif without :if");
skip = true; skip = true;
} else if (cstack->cs_flags[cstack->cs_idx] & CSF_ELSE) { } else if (cstack->cs_flags[cstack->cs_idx] & CSF_ELSE) {
if (eap->cmdidx == CMD_else) { if (eap->cmdidx == CMD_else) {
eap->errmsg = N_("E583: multiple :else"); eap->errmsg = _("E583: multiple :else");
return; return;
} }
eap->errmsg = N_("E584: :elseif after :else"); eap->errmsg = _("E584: :elseif after :else");
skip = true; skip = true;
} }
@ -940,7 +940,7 @@ void ex_while(exarg_T *eap)
cstack_T *const cstack = eap->cstack; cstack_T *const cstack = eap->cstack;
if (cstack->cs_idx == CSTACK_LEN - 1) { if (cstack->cs_idx == CSTACK_LEN - 1) {
eap->errmsg = N_("E585: :while/:for nesting too deep"); eap->errmsg = _("E585: :while/:for nesting too deep");
} else { } else {
/* /*
* The loop flag is set when we have jumped back from the matching * The loop flag is set when we have jumped back from the matching
@ -1019,7 +1019,7 @@ void ex_continue(exarg_T *eap)
cstack_T *const cstack = eap->cstack; cstack_T *const cstack = eap->cstack;
if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) { if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) {
eap->errmsg = N_("E586: :continue without :while or :for"); eap->errmsg = _("E586: :continue without :while or :for");
} else { } else {
// Try to find the matching ":while". This might stop at a try // Try to find the matching ":while". This might stop at a try
// conditional not in its finally clause (which is then to be executed // conditional not in its finally clause (which is then to be executed
@ -1051,7 +1051,7 @@ void ex_break(exarg_T *eap)
cstack_T *const cstack = eap->cstack; cstack_T *const cstack = eap->cstack;
if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) { if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) {
eap->errmsg = N_("E587: :break without :while or :for"); eap->errmsg = _("E587: :break without :while or :for");
} else { } else {
// Deactivate conditionals until the matching ":while" or a try // Deactivate conditionals until the matching ":while" or a try
// conditional not in its finally clause (which is then to be // conditional not in its finally clause (which is then to be
@ -1083,7 +1083,7 @@ void ex_endwhile(exarg_T *eap)
} }
if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) { if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) {
eap->errmsg = err; eap->errmsg = _(err);
} else { } else {
fl = cstack->cs_flags[cstack->cs_idx]; fl = cstack->cs_flags[cstack->cs_idx];
if (!(fl & csf)) { if (!(fl & csf)) {
@ -1097,9 +1097,9 @@ void ex_endwhile(exarg_T *eap)
} }
if (!(fl & (CSF_WHILE | CSF_FOR))) { if (!(fl & (CSF_WHILE | CSF_FOR))) {
if (!(fl & CSF_TRY)) { if (!(fl & CSF_TRY)) {
eap->errmsg = e_endif; eap->errmsg = _(e_endif);
} else if (fl & CSF_FINALLY) { } else if (fl & CSF_FINALLY) {
eap->errmsg = e_endtry; eap->errmsg = _(e_endtry);
} }
// Try to find the matching ":while" and report what's missing. // Try to find the matching ":while" and report what's missing.
for (idx = cstack->cs_idx; idx > 0; --idx) { for (idx = cstack->cs_idx; idx > 0; --idx) {
@ -1107,7 +1107,7 @@ void ex_endwhile(exarg_T *eap)
if ((fl & CSF_TRY) && !(fl & CSF_FINALLY)) { if ((fl & CSF_TRY) && !(fl & CSF_FINALLY)) {
// Give up at a try conditional not in its finally clause. // Give up at a try conditional not in its finally clause.
// Ignore the ":endwhile"/":endfor". // Ignore the ":endwhile"/":endfor".
eap->errmsg = err; eap->errmsg = _(err);
return; return;
} }
if (fl & csf) { if (fl & csf) {
@ -1230,7 +1230,7 @@ void ex_try(exarg_T *eap)
cstack_T *const cstack = eap->cstack; cstack_T *const cstack = eap->cstack;
if (cstack->cs_idx == CSTACK_LEN - 1) { if (cstack->cs_idx == CSTACK_LEN - 1) {
eap->errmsg = N_("E601: :try nesting too deep"); eap->errmsg = _("E601: :try nesting too deep");
} else { } else {
++cstack->cs_idx; ++cstack->cs_idx;
++cstack->cs_trylevel; ++cstack->cs_trylevel;
@ -1289,7 +1289,7 @@ void ex_catch(exarg_T *eap)
char *pat; char *pat;
if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) { if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) {
eap->errmsg = N_("E603: :catch without :try"); eap->errmsg = _("E603: :catch without :try");
give_up = true; give_up = true;
} else { } else {
if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) { if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) {
@ -1306,7 +1306,7 @@ void ex_catch(exarg_T *eap)
if (cstack->cs_flags[idx] & CSF_FINALLY) { if (cstack->cs_flags[idx] & CSF_FINALLY) {
// Give up for a ":catch" after ":finally" and ignore it. // Give up for a ":catch" after ":finally" and ignore it.
// Just parse. // Just parse.
eap->errmsg = N_("E604: :catch after :finally"); eap->errmsg = _("E604: :catch after :finally");
give_up = true; give_up = true;
} else { } else {
rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR, rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR,
@ -1436,7 +1436,7 @@ void ex_finally(exarg_T *eap)
cstack_T *const cstack = eap->cstack; cstack_T *const cstack = eap->cstack;
if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) { if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) {
eap->errmsg = N_("E606: :finally without :try"); eap->errmsg = _("E606: :finally without :try");
} else { } else {
if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) { if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) {
eap->errmsg = get_end_emsg(cstack); eap->errmsg = get_end_emsg(cstack);
@ -1455,7 +1455,7 @@ void ex_finally(exarg_T *eap)
if (cstack->cs_flags[idx] & CSF_FINALLY) { if (cstack->cs_flags[idx] & CSF_FINALLY) {
// Give up for a multiple ":finally" and ignore it. // Give up for a multiple ":finally" and ignore it.
eap->errmsg = N_("E607: multiple :finally"); eap->errmsg = _("E607: multiple :finally");
return; return;
} }
rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR, rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR,
@ -1559,7 +1559,7 @@ void ex_endtry(exarg_T *eap)
cstack_T *const cstack = eap->cstack; cstack_T *const cstack = eap->cstack;
if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) { if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) {
eap->errmsg = N_("E602: :endtry without :try"); eap->errmsg = _("E602: :endtry without :try");
} else { } else {
// Don't do something after an error, interrupt or throw in the try // Don't do something after an error, interrupt or throw in the try
// block, catch clause, or finally clause preceding this ":endtry" or // block, catch clause, or finally clause preceding this ":endtry" or
@ -1998,12 +1998,12 @@ int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive)
static char *get_end_emsg(cstack_T *cstack) static char *get_end_emsg(cstack_T *cstack)
{ {
if (cstack->cs_flags[cstack->cs_idx] & CSF_WHILE) { if (cstack->cs_flags[cstack->cs_idx] & CSF_WHILE) {
return e_endwhile; return _(e_endwhile);
} }
if (cstack->cs_flags[cstack->cs_idx] & CSF_FOR) { if (cstack->cs_flags[cstack->cs_idx] & CSF_FOR) {
return e_endfor; return _(e_endfor);
} }
return e_endif; return _(e_endif);
} }
/// Rewind conditionals until index "idx" is reached. "cond_type" and /// Rewind conditionals until index "idx" is reached. "cond_type" and

View File

@ -1193,7 +1193,7 @@ void ex_match(exarg_T *eap)
if (!eap->skip) { if (!eap->skip) {
if (*end != NUL && !ends_excmd(*skipwhite((char *)end + 1))) { if (*end != NUL && !ends_excmd(*skipwhite((char *)end + 1))) {
xfree(g); xfree(g);
eap->errmsg = e_trailing; eap->errmsg = ex_errmsg(e_trailing_arg, (const char *)end);
return; return;
} }
if (*end != *p) { if (*end != *p) {

View File

@ -133,18 +133,18 @@ function Test_tabpage()
call assert_fails("99tabmove", 'E16:') call assert_fails("99tabmove", 'E16:')
call assert_fails("+99tabmove", 'E16:') call assert_fails("+99tabmove", 'E16:')
call assert_fails("-99tabmove", 'E16:') call assert_fails("-99tabmove", 'E16:')
call assert_fails("tabmove foo", 'E474:') call assert_fails("tabmove foo", 'E475:')
call assert_fails("tabmove 99", 'E474:') call assert_fails("tabmove 99", 'E475:')
call assert_fails("tabmove +99", 'E474:') call assert_fails("tabmove +99", 'E475:')
call assert_fails("tabmove -99", 'E474:') call assert_fails("tabmove -99", 'E475:')
call assert_fails("tabmove -3+", 'E474:') call assert_fails("tabmove -3+", 'E475:')
call assert_fails("tabmove $3", 'E474:') call assert_fails("tabmove $3", 'E475:')
call assert_fails("%tabonly", 'E16:') call assert_fails("%tabonly", 'E16:')
1tabonly! 1tabonly!
tabmove 1 tabmove 1
call assert_equal(1, tabpagenr()) call assert_equal(1, tabpagenr())
tabnew tabnew
call assert_fails("-2tabmove", 'E474:') call assert_fails("-2tabmove", 'E16:')
tabonly! tabonly!
endfunc endfunc
@ -320,14 +320,14 @@ function Test_tabpage_with_tabnext()
call Check_tab_count(4, 'tabnext -', 3) call Check_tab_count(4, 'tabnext -', 3)
call Check_tab_count(4, 'tabnext -2', 2) call Check_tab_count(4, 'tabnext -2', 2)
call Check_tab_count(3, 'tabnext $', 5) call Check_tab_count(3, 'tabnext $', 5)
call assert_fails('tabnext 0', 'E474:') call assert_fails('tabnext 0', 'E475:')
call assert_fails('tabnext .', 'E474:') call assert_fails('tabnext .', 'E475:')
call assert_fails('tabnext -+', 'E474:') call assert_fails('tabnext -+', 'E475:')
call assert_fails('tabnext +2-', 'E474:') call assert_fails('tabnext +2-', 'E475:')
call assert_fails('tabnext $3', 'E474:') call assert_fails('tabnext $3', 'E475:')
call assert_fails('tabnext 99', 'E474:') call assert_fails('tabnext 99', 'E475:')
call assert_fails('tabnext +99', 'E474:') call assert_fails('tabnext +99', 'E475:')
call assert_fails('tabnext -99', 'E474:') call assert_fails('tabnext -99', 'E475:')
1tabonly! 1tabonly!
endfunction endfunction
@ -352,7 +352,7 @@ function Test_tabpage_with_tabprevious()
let err_code = 'E16:' let err_code = 'E16:'
else else
let entire_cmd = cmd . ' ' . c let entire_cmd = cmd . ' ' . c
let err_code = 'E474:' let err_code = 'E475:'
endif endif
call assert_fails(entire_cmd, err_code) call assert_fails(entire_cmd, err_code)
endfor endfor
@ -451,7 +451,7 @@ function Test_tabpage_with_tabclose()
let err_code = 'E16:' let err_code = 'E16:'
else else
let entire_cmd = 'tabclose ' . c let entire_cmd = 'tabclose ' . c
let err_code = 'E474:' let err_code = 'E475:'
endif endif
call assert_fails(entire_cmd, err_code) call assert_fails(entire_cmd, err_code)
call assert_equal(6, tabpagenr('$')) call assert_equal(6, tabpagenr('$'))
@ -460,8 +460,8 @@ function Test_tabpage_with_tabclose()
call assert_fails('3tabclose', 'E37:') call assert_fails('3tabclose', 'E37:')
call assert_fails('tabclose 3', 'E37:') call assert_fails('tabclose 3', 'E37:')
call assert_fails('tabclose -+', 'E474:') call assert_fails('tabclose -+', 'E475:')
call assert_fails('tabclose +2-', 'E474:') call assert_fails('tabclose +2-', 'E475:')
call assert_equal(6, tabpagenr('$')) call assert_equal(6, tabpagenr('$'))
1tabonly! 1tabonly!
@ -506,7 +506,7 @@ function Test_tabpage_with_tabonly()
let err_code = 'E16:' let err_code = 'E16:'
else else
let entire_cmd = 'tabonly ' . c let entire_cmd = 'tabonly ' . c
let err_code = 'E474:' let err_code = 'E475:'
endif endif
call assert_fails(entire_cmd, err_code) call assert_fails(entire_cmd, err_code)
call assert_equal(6, tabpagenr('$')) call assert_equal(6, tabpagenr('$'))
@ -517,13 +517,13 @@ function Test_tabpage_with_tabonly()
for c in tc for c in tc
call s:reconstruct_tabpage_for_test(6) call s:reconstruct_tabpage_for_test(6)
let entire_cmd = 'tabonly' . c[2] . ' ' . c[1] let entire_cmd = 'tabonly' . c[2] . ' ' . c[1]
let err_code = 'E474:' let err_code = 'E475:'
call assert_fails(entire_cmd, err_code) call assert_fails(entire_cmd, err_code)
call assert_equal(6, tabpagenr('$')) call assert_equal(6, tabpagenr('$'))
endfor endfor
call assert_fails('tabonly -+', 'E474:') call assert_fails('tabonly -+', 'E475:')
call assert_fails('tabonly +2-', 'E474:') call assert_fails('tabonly +2-', 'E475:')
call assert_equal(6, tabpagenr('$')) call assert_equal(6, tabpagenr('$'))
1tabonly! 1tabonly!

View File

@ -16,7 +16,7 @@ describe('Ex cmds', function()
command(':echo expand("#<9999999999999999999999999999999999999999")') command(':echo expand("#<9999999999999999999999999999999999999999")')
command(':lockvar 9999999999999999999999999999999999999999') command(':lockvar 9999999999999999999999999999999999999999')
command(':winsize 9999999999999999999999999999999999999999 9999999999999999999999999999999999999999') command(':winsize 9999999999999999999999999999999999999999 9999999999999999999999999999999999999999')
eq('Vim(tabnext):E474: Invalid argument', eq('Vim(tabnext):E475: Invalid argument: 9999999999999999999999999999999999999999',
pcall_err(command, ':tabnext 9999999999999999999999999999999999999999')) pcall_err(command, ':tabnext 9999999999999999999999999999999999999999'))
eq('Vim(Next):E939: Positive count required', eq('Vim(Next):E939: Positive count required',
pcall_err(command, ':N 9999999999999999999999999999999999999999')) pcall_err(command, ':N 9999999999999999999999999999999999999999'))

View File

@ -1,239 +0,0 @@
-- Tests for tab pages
local helpers = require('test.functional.helpers')(after_each)
local feed, insert, source, clear, command, expect, eval, eq =
helpers.feed, helpers.insert, helpers.source, helpers.clear,
helpers.command, helpers.expect, helpers.eval, helpers.eq
local exc_exec = helpers.exc_exec
describe('tab pages', function()
before_each(clear)
it('can be opened and closed', function()
command('tabnew')
eq(2, eval('tabpagenr()'))
command('quit')
eq(1, eval('tabpagenr()'))
end)
it('can be iterated with :tabdo', function()
source([[
0tabnew
1tabnew
$tabnew
tabdo call append(line('$'), 'this is tab page ' . tabpagenr())
tabclose! 2
tabrewind
]])
eq('this is tab page 1', eval("getline('$')"))
command('tablast')
eq('this is tab page 4', eval("getline('$')"))
end)
it('have local variables accasible with settabvar()/gettabvar()', function()
-- Test for settabvar() and gettabvar() functions. Open a new tab page and
-- set 3 variables to a number, string and a list. Verify that the
-- variables are correctly set.
source([[
tabnew
tabfirst
call settabvar(2, 'val_num', 100)
call settabvar(2, 'val_str', 'SetTabVar test')
call settabvar(2, 'val_list', ['red', 'blue', 'green'])
]])
eq(100, eval('gettabvar(2, "val_num")'))
eq('SetTabVar test', eval('gettabvar(2, "val_str")'))
eq({'red', 'blue', 'green'}, eval('gettabvar(2, "val_list")'))
command('tabnext 2')
eq(100, eval('t:val_num'))
eq('SetTabVar test', eval('t:val_str'))
eq({'red', 'blue', 'green'}, eval('t:val_list'))
end)
it('work together with the drop feature and loaded buffers', function()
-- Test for ":tab drop exist-file" to keep current window.
command('sp test1')
command('tab drop test1')
eq(1, eval('tabpagenr("$")'))
eq(2, eval('winnr("$")'))
eq(1, eval('winnr()'))
end)
it('work together with the drop feature and new files', function()
-- Test for ":tab drop new-file" to keep current window of tabpage 1.
command('split')
command('tab drop newfile')
eq(2, eval('tabpagenr("$")'))
eq(2, eval('tabpagewinnr(1, "$")'))
eq(1, eval('tabpagewinnr(1)'))
end)
it('work together with the drop feature and multi loaded buffers', function()
-- Test for ":tab drop multi-opend-file" to keep current tabpage and
-- window.
command('new test1')
command('tabnew')
command('new test1')
command('tab drop test1')
eq(2, eval('tabpagenr()'))
eq(2, eval('tabpagewinnr(2, "$")'))
eq(1, eval('tabpagewinnr(2)'))
end)
it('can be navigated with :tabmove', function()
command('lang C')
command('for i in range(9) | tabnew | endfor')
feed('1gt')
eq(1, eval('tabpagenr()'))
command('tabmove 5')
eq(5, eval('tabpagenr()'))
command('.tabmove')
eq(5, eval('tabpagenr()'))
command('tabmove -')
eq(4, eval('tabpagenr()'))
command('tabmove +')
eq(5, eval('tabpagenr()'))
command('tabmove -2')
eq(3, eval('tabpagenr()'))
command('tabmove +4')
eq(7, eval('tabpagenr()'))
command('tabmove')
eq(10, eval('tabpagenr()'))
command('0tabmove')
eq(1, eval('tabpagenr()'))
command('$tabmove')
eq(10, eval('tabpagenr()'))
command('tabmove 0')
eq(1, eval('tabpagenr()'))
command('tabmove $')
eq(10, eval('tabpagenr()'))
command('3tabmove')
eq(4, eval('tabpagenr()'))
command('7tabmove 5')
eq(5, eval('tabpagenr()'))
command('let a="No error caught."')
eq('Vim(tabmove):E474: Invalid argument: tabmove foo',
exc_exec('tabmove foo'))
end)
it('can trigger certain autocommands', function()
insert('Results:')
-- Test autocommands.
source([[
tabonly!
let g:r=[]
command -nargs=1 -bar C :call add(g:r, '=== '.<q-args>.' ===')|<args>
function Test()
autocmd TabEnter * :call add(g:r, 'TabEnter')
autocmd WinEnter * :call add(g:r, 'WinEnter')
autocmd BufEnter * :call add(g:r, 'BufEnter')
autocmd TabLeave * :call add(g:r, 'TabLeave')
autocmd WinLeave * :call add(g:r, 'WinLeave')
autocmd BufLeave * :call add(g:r, 'BufLeave')
let t:a='a'
C tab split
let t:a='b'
C tabnew
let t:a='c'
call add(g:r, join(map(range(1, tabpagenr('$')),
\ 'gettabvar(v:val, "a")')))
C call map(range(1, tabpagenr('$')),
\ 'settabvar(v:val, ''a'', v:val*2)')
call add(g:r, join(map(range(1, tabpagenr('$')),
\ 'gettabvar(v:val, "a")')))
let w:a='a'
C vsplit
let w:a='a'
let tabn=tabpagenr()
let winr=range(1, winnr('$'))
C tabnext 1
call add(g:r, join(map(copy(winr),
\ 'gettabwinvar('.tabn.', v:val, "a")')))
C call map(copy(winr),
\ 'settabwinvar('.tabn.', v:val, ''a'', v:val*2)')
call add(g:r, join(map(copy(winr),
\ 'gettabwinvar('.tabn.', v:val, "a")')))
augroup TabDestructive
autocmd TabEnter * :C tabnext 2 | C tabclose 3
augroup END
C tabnext 3
let g:r+=[tabpagenr().'/'.tabpagenr('$')]
autocmd! TabDestructive TabEnter
C tabnew
C tabnext 1
autocmd TabDestructive TabEnter * nested
\ :C tabnext 2 | C tabclose 3
C tabnext 2
let g:r+=[tabpagenr().'/'.tabpagenr('$')]
endfunction
call Test()
$ put =g:r
]])
-- Assert buffer contents.
expect([[
Results:
=== tab split ===
WinLeave
TabLeave
WinEnter
TabEnter
=== tabnew ===
WinLeave
TabLeave
WinEnter
TabEnter
BufLeave
BufEnter
a b c
=== call map(range(1, tabpagenr('$')), 'settabvar(v:val, ''a'', v:val*2)') ===
2 4 6
=== vsplit ===
WinLeave
WinEnter
=== tabnext 1 ===
BufLeave
WinLeave
TabLeave
WinEnter
TabEnter
BufEnter
a a
=== call map(copy(winr), 'settabwinvar('.tabn.', v:val, ''a'', v:val*2)') ===
2 4
=== tabnext 3 ===
BufLeave
WinLeave
TabLeave
WinEnter
TabEnter
=== tabnext 2 ===
=== tabclose 3 ===
2/2
=== tabnew ===
WinLeave
TabLeave
WinEnter
TabEnter
BufLeave
BufEnter
=== tabnext 1 ===
BufLeave
WinLeave
TabLeave
WinEnter
TabEnter
BufEnter
=== tabnext 2 ===
WinLeave
TabLeave
WinEnter
TabEnter
=== tabnext 2 ===
=== tabclose 3 ===
2/2]])
eq(2, eval("tabpagenr('$')"))
end)
end)