mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	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:
		| @@ -969,7 +969,7 @@ char *do_bufdel(int command, char *arg, int addr_count, int start_bnr, int end_b | ||||
|   } else { | ||||
|     if (addr_count == 2) { | ||||
|       if (*arg) {               // both range and argument is not allowed | ||||
|         return _(e_trailing); | ||||
|         return ex_errmsg(e_trailing_arg, arg); | ||||
|       } | ||||
|       bnr = start_bnr; | ||||
|     } else {    // addr_count == 1 | ||||
|   | ||||
| @@ -1635,7 +1635,7 @@ static int execute_cmd0(int *retv, exarg_T *eap, char **errormsg, bool preview) | ||||
|       (cmdnames[eap->cmdidx].cmd_func)(eap); | ||||
|     } | ||||
|     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) | ||||
| { | ||||
|   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 | ||||
|                  || tab_number > LAST_TAB_NR) { | ||||
|         // No numbers as argument. | ||||
|         eap->errmsg = e_invarg; | ||||
|         eap->errmsg = ex_errmsg(e_invarg2, eap->arg); | ||||
|         goto theend; | ||||
|       } | ||||
|     } else { | ||||
| @@ -5026,20 +5026,20 @@ static int get_tabpage_arg(exarg_T *eap) | ||||
|         tab_number = 1; | ||||
|       } else if (p == p_save || *p_save == '-' || *p != NUL || tab_number == 0) { | ||||
|         // No numbers as argument. | ||||
|         eap->errmsg = e_invarg; | ||||
|         eap->errmsg = ex_errmsg(e_invarg2, eap->arg); | ||||
|         goto theend; | ||||
|       } | ||||
|       tab_number = tab_number * relative + tabpage_index(curtab); | ||||
|       if (!unaccept_arg0 && relative == -1) { | ||||
|         --tab_number; | ||||
|         tab_number--; | ||||
|       } | ||||
|     } | ||||
|     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) { | ||||
|     if (unaccept_arg0 && eap->line2 == 0) { | ||||
|       eap->errmsg = e_invrange; | ||||
|       eap->errmsg = _(e_invrange); | ||||
|       tab_number = 0; | ||||
|     } else { | ||||
|       tab_number = (int)eap->line2; | ||||
| @@ -5048,7 +5048,7 @@ static int get_tabpage_arg(exarg_T *eap) | ||||
|       if (!unaccept_arg0 && *cmdp == '-') { | ||||
|         tab_number--; | ||||
|         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. | ||||
|   if (secure) { | ||||
|     secure = 2; | ||||
|     eap->errmsg = e_curdir; | ||||
|     eap->errmsg = _(e_curdir); | ||||
|   } else if (eap->cmdidx == CMD_autocmd) { | ||||
|     do_autocmd(eap->arg, eap->forceit); | ||||
|   } else { | ||||
| @@ -5119,7 +5119,7 @@ static void ex_bunload(exarg_T *eap) | ||||
| static void ex_buffer(exarg_T *eap) | ||||
| { | ||||
|   if (*eap->arg) { | ||||
|     eap->errmsg = e_trailing; | ||||
|     eap->errmsg = ex_errmsg(e_trailing_arg, eap->arg); | ||||
|   } else { | ||||
|     if (eap->addr_count == 0) {  // default is current buffer | ||||
|       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. | ||||
| 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 | ||||
| @@ -6052,7 +6052,7 @@ static void ex_tabnext(exarg_T *eap) | ||||
|       if (p == p_save || *p_save == '-' || *p_save == '+' || *p != NUL | ||||
|           || tab_number == 0) { | ||||
|         // No numbers as argument. | ||||
|         eap->errmsg = e_invarg; | ||||
|         eap->errmsg = ex_errmsg(e_invarg2, eap->arg); | ||||
|         return; | ||||
|       } | ||||
|     } else { | ||||
| @@ -6061,7 +6061,7 @@ static void ex_tabnext(exarg_T *eap) | ||||
|       } else { | ||||
|         tab_number = (int)eap->line2; | ||||
|         if (tab_number < 1) { | ||||
|           eap->errmsg = e_invrange; | ||||
|           eap->errmsg = _(e_invrange); | ||||
|           return; | ||||
|         } | ||||
|       } | ||||
| @@ -6339,7 +6339,7 @@ void do_exedit(exarg_T *eap, win_T *old_curwin) | ||||
| /// ":gui" and ":gvim" when there is no GUI. | ||||
| 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) | ||||
| @@ -7559,7 +7559,7 @@ static void ex_findpat(exarg_T *eap) | ||||
|  | ||||
|       // Check for trailing illegal characters. | ||||
|       if (!ends_excmd(*p)) { | ||||
|         eap->errmsg = e_trailing; | ||||
|         eap->errmsg = ex_errmsg(e_trailing_arg, p); | ||||
|       } else { | ||||
|         eap->nextcmd = (char *)check_nextcmd((char_u *)p); | ||||
|       } | ||||
|   | ||||
| @@ -812,7 +812,7 @@ void ex_if(exarg_T *eap) | ||||
|   cstack_T *const cstack = eap->cstack; | ||||
|  | ||||
|   if (cstack->cs_idx == CSTACK_LEN - 1) { | ||||
|     eap->errmsg = N_("E579: :if nesting too deep"); | ||||
|     eap->errmsg = _("E579: :if nesting too deep"); | ||||
|   } else { | ||||
|     ++cstack->cs_idx; | ||||
|     cstack->cs_flags[cstack->cs_idx] = 0; | ||||
| @@ -840,7 +840,7 @@ void ex_endif(exarg_T *eap) | ||||
|   if (eap->cstack->cs_idx < 0 | ||||
|       || (eap->cstack->cs_flags[eap->cstack->cs_idx] | ||||
|           & (CSF_WHILE | CSF_FOR | CSF_TRY))) { | ||||
|     eap->errmsg = N_("E580: :endif without :if"); | ||||
|     eap->errmsg = _("E580: :endif without :if"); | ||||
|   } else { | ||||
|     // When debugging or a breakpoint was encountered, display the debug | ||||
|     // 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] | ||||
|           & (CSF_WHILE | CSF_FOR | CSF_TRY))) { | ||||
|     if (eap->cmdidx == CMD_else) { | ||||
|       eap->errmsg = N_("E581: :else without :if"); | ||||
|       eap->errmsg = _("E581: :else without :if"); | ||||
|       return; | ||||
|     } | ||||
|     eap->errmsg = N_("E582: :elseif without :if"); | ||||
|     eap->errmsg = _("E582: :elseif without :if"); | ||||
|     skip = true; | ||||
|   } else if (cstack->cs_flags[cstack->cs_idx] & CSF_ELSE) { | ||||
|     if (eap->cmdidx == CMD_else) { | ||||
|       eap->errmsg = N_("E583: multiple :else"); | ||||
|       eap->errmsg = _("E583: multiple :else"); | ||||
|       return; | ||||
|     } | ||||
|     eap->errmsg = N_("E584: :elseif after :else"); | ||||
|     eap->errmsg = _("E584: :elseif after :else"); | ||||
|     skip = true; | ||||
|   } | ||||
|  | ||||
| @@ -940,7 +940,7 @@ void ex_while(exarg_T *eap) | ||||
|   cstack_T *const cstack = eap->cstack; | ||||
|  | ||||
|   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 { | ||||
|     /* | ||||
|      * 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; | ||||
|  | ||||
|   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 { | ||||
|     // Try to find the matching ":while".  This might stop at a try | ||||
|     // 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; | ||||
|  | ||||
|   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 { | ||||
|     // Deactivate conditionals until the matching ":while" or a try | ||||
|     // 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) { | ||||
|     eap->errmsg = err; | ||||
|     eap->errmsg = _(err); | ||||
|   } else { | ||||
|     fl = cstack->cs_flags[cstack->cs_idx]; | ||||
|     if (!(fl & csf)) { | ||||
| @@ -1097,9 +1097,9 @@ void ex_endwhile(exarg_T *eap) | ||||
|     } | ||||
|     if (!(fl & (CSF_WHILE | CSF_FOR))) { | ||||
|       if (!(fl & CSF_TRY)) { | ||||
|         eap->errmsg = e_endif; | ||||
|         eap->errmsg = _(e_endif); | ||||
|       } else if (fl & CSF_FINALLY) { | ||||
|         eap->errmsg = e_endtry; | ||||
|         eap->errmsg = _(e_endtry); | ||||
|       } | ||||
|       // Try to find the matching ":while" and report what's missing. | ||||
|       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)) { | ||||
|           // Give up at a try conditional not in its finally clause. | ||||
|           // Ignore the ":endwhile"/":endfor". | ||||
|           eap->errmsg = err; | ||||
|           eap->errmsg = _(err); | ||||
|           return; | ||||
|         } | ||||
|         if (fl & csf) { | ||||
| @@ -1230,7 +1230,7 @@ void ex_try(exarg_T *eap) | ||||
|   cstack_T *const cstack = eap->cstack; | ||||
|  | ||||
|   if (cstack->cs_idx == CSTACK_LEN - 1) { | ||||
|     eap->errmsg = N_("E601: :try nesting too deep"); | ||||
|     eap->errmsg = _("E601: :try nesting too deep"); | ||||
|   } else { | ||||
|     ++cstack->cs_idx; | ||||
|     ++cstack->cs_trylevel; | ||||
| @@ -1289,7 +1289,7 @@ void ex_catch(exarg_T *eap) | ||||
|   char *pat; | ||||
|  | ||||
|   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; | ||||
|   } else { | ||||
|     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) { | ||||
|       // Give up for a ":catch" after ":finally" and ignore it. | ||||
|       // Just parse. | ||||
|       eap->errmsg = N_("E604: :catch after :finally"); | ||||
|       eap->errmsg = _("E604: :catch after :finally"); | ||||
|       give_up = true; | ||||
|     } else { | ||||
|       rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR, | ||||
| @@ -1436,7 +1436,7 @@ void ex_finally(exarg_T *eap) | ||||
|   cstack_T *const cstack = eap->cstack; | ||||
|  | ||||
|   if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) { | ||||
|     eap->errmsg = N_("E606: :finally without :try"); | ||||
|     eap->errmsg = _("E606: :finally without :try"); | ||||
|   } else { | ||||
|     if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) { | ||||
|       eap->errmsg = get_end_emsg(cstack); | ||||
| @@ -1455,7 +1455,7 @@ void ex_finally(exarg_T *eap) | ||||
|  | ||||
|     if (cstack->cs_flags[idx] & CSF_FINALLY) { | ||||
|       // Give up for a multiple ":finally" and ignore it. | ||||
|       eap->errmsg = N_("E607: multiple :finally"); | ||||
|       eap->errmsg = _("E607: multiple :finally"); | ||||
|       return; | ||||
|     } | ||||
|     rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR, | ||||
| @@ -1559,7 +1559,7 @@ void ex_endtry(exarg_T *eap) | ||||
|   cstack_T *const cstack = eap->cstack; | ||||
|  | ||||
|   if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) { | ||||
|     eap->errmsg = N_("E602: :endtry without :try"); | ||||
|     eap->errmsg = _("E602: :endtry without :try"); | ||||
|   } else { | ||||
|     // Don't do something after an error, interrupt or throw in the try | ||||
|     // 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) | ||||
| { | ||||
|   if (cstack->cs_flags[cstack->cs_idx] & CSF_WHILE) { | ||||
|     return e_endwhile; | ||||
|     return _(e_endwhile); | ||||
|   } | ||||
|   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 | ||||
|   | ||||
| @@ -1193,7 +1193,7 @@ void ex_match(exarg_T *eap) | ||||
|     if (!eap->skip) { | ||||
|       if (*end != NUL && !ends_excmd(*skipwhite((char *)end + 1))) { | ||||
|         xfree(g); | ||||
|         eap->errmsg = e_trailing; | ||||
|         eap->errmsg = ex_errmsg(e_trailing_arg, (const char *)end); | ||||
|         return; | ||||
|       } | ||||
|       if (*end != *p) { | ||||
|   | ||||
| @@ -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("tabmove foo", 'E474:') | ||||
|   call assert_fails("tabmove 99", 'E474:') | ||||
|   call assert_fails("tabmove +99", 'E474:') | ||||
|   call assert_fails("tabmove -99", 'E474:') | ||||
|   call assert_fails("tabmove -3+", 'E474:') | ||||
|   call assert_fails("tabmove $3", 'E474:') | ||||
|   call assert_fails("tabmove foo", 'E475:') | ||||
|   call assert_fails("tabmove 99", 'E475:') | ||||
|   call assert_fails("tabmove +99", 'E475:') | ||||
|   call assert_fails("tabmove -99", 'E475:') | ||||
|   call assert_fails("tabmove -3+", 'E475:') | ||||
|   call assert_fails("tabmove $3", 'E475:') | ||||
|   call assert_fails("%tabonly", 'E16:') | ||||
|   1tabonly! | ||||
|   tabmove 1 | ||||
|   call assert_equal(1, tabpagenr()) | ||||
|   tabnew | ||||
|   call assert_fails("-2tabmove", 'E474:') | ||||
|   call assert_fails("-2tabmove", 'E16:') | ||||
|   tabonly! | ||||
| endfunc | ||||
|  | ||||
| @@ -320,14 +320,14 @@ function Test_tabpage_with_tabnext() | ||||
|   call Check_tab_count(4, 'tabnext -', 3) | ||||
|   call Check_tab_count(4, 'tabnext -2', 2) | ||||
|   call Check_tab_count(3, 'tabnext $', 5) | ||||
|   call assert_fails('tabnext 0', 'E474:') | ||||
|   call assert_fails('tabnext .', 'E474:') | ||||
|   call assert_fails('tabnext -+', 'E474:') | ||||
|   call assert_fails('tabnext +2-', 'E474:') | ||||
|   call assert_fails('tabnext $3', 'E474:') | ||||
|   call assert_fails('tabnext 99', 'E474:') | ||||
|   call assert_fails('tabnext +99', 'E474:') | ||||
|   call assert_fails('tabnext -99', 'E474:') | ||||
|   call assert_fails('tabnext 0', 'E475:') | ||||
|   call assert_fails('tabnext .', 'E475:') | ||||
|   call assert_fails('tabnext -+', 'E475:') | ||||
|   call assert_fails('tabnext +2-', 'E475:') | ||||
|   call assert_fails('tabnext $3', 'E475:') | ||||
|   call assert_fails('tabnext 99', 'E475:') | ||||
|   call assert_fails('tabnext +99', 'E475:') | ||||
|   call assert_fails('tabnext -99', 'E475:') | ||||
|  | ||||
|   1tabonly! | ||||
| endfunction | ||||
| @@ -352,7 +352,7 @@ function Test_tabpage_with_tabprevious() | ||||
|           let err_code = 'E16:' | ||||
|         else | ||||
|           let entire_cmd = cmd . ' ' . c | ||||
|           let err_code = 'E474:' | ||||
|           let err_code = 'E475:' | ||||
|         endif | ||||
|         call assert_fails(entire_cmd, err_code) | ||||
|       endfor | ||||
| @@ -451,7 +451,7 @@ function Test_tabpage_with_tabclose() | ||||
|         let err_code = 'E16:' | ||||
|       else | ||||
|         let entire_cmd = 'tabclose ' . c | ||||
|         let err_code = 'E474:' | ||||
|         let err_code = 'E475:' | ||||
|       endif | ||||
|       call assert_fails(entire_cmd, err_code) | ||||
|       call assert_equal(6, tabpagenr('$')) | ||||
| @@ -460,8 +460,8 @@ function Test_tabpage_with_tabclose() | ||||
|  | ||||
|   call assert_fails('3tabclose', 'E37:') | ||||
|   call assert_fails('tabclose 3', 'E37:') | ||||
|   call assert_fails('tabclose -+', 'E474:') | ||||
|   call assert_fails('tabclose +2-', 'E474:') | ||||
|   call assert_fails('tabclose -+', 'E475:') | ||||
|   call assert_fails('tabclose +2-', 'E475:') | ||||
|   call assert_equal(6, tabpagenr('$')) | ||||
|  | ||||
|   1tabonly! | ||||
| @@ -506,7 +506,7 @@ function Test_tabpage_with_tabonly() | ||||
|         let err_code = 'E16:' | ||||
|       else | ||||
|         let entire_cmd = 'tabonly ' . c | ||||
|         let err_code = 'E474:' | ||||
|         let err_code = 'E475:' | ||||
|       endif | ||||
|       call assert_fails(entire_cmd, err_code) | ||||
|       call assert_equal(6, tabpagenr('$')) | ||||
| @@ -517,13 +517,13 @@ function Test_tabpage_with_tabonly() | ||||
|   for c in tc | ||||
|     call s:reconstruct_tabpage_for_test(6) | ||||
|     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_equal(6, tabpagenr('$')) | ||||
|   endfor | ||||
|  | ||||
|   call assert_fails('tabonly -+', 'E474:') | ||||
|   call assert_fails('tabonly +2-', 'E474:') | ||||
|   call assert_fails('tabonly -+', 'E475:') | ||||
|   call assert_fails('tabonly +2-', 'E475:') | ||||
|   call assert_equal(6, tabpagenr('$')) | ||||
|  | ||||
|   1tabonly! | ||||
|   | ||||
| @@ -16,7 +16,7 @@ describe('Ex cmds', function() | ||||
|     command(':echo expand("#<9999999999999999999999999999999999999999")') | ||||
|     command(':lockvar 9999999999999999999999999999999999999999') | ||||
|     command(':winsize 9999999999999999999999999999999999999999 9999999999999999999999999999999999999999') | ||||
|     eq('Vim(tabnext):E474: Invalid argument', | ||||
|     eq('Vim(tabnext):E475: Invalid argument: 9999999999999999999999999999999999999999', | ||||
|       pcall_err(command, ':tabnext 9999999999999999999999999999999999999999')) | ||||
|     eq('Vim(Next):E939: Positive count required', | ||||
|       pcall_err(command, ':N 9999999999999999999999999999999999999999')) | ||||
|   | ||||
| @@ -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) | ||||
		Reference in New Issue
	
	Block a user
	 zeertzjq
					zeertzjq