Mercurial > vim
changeset 27400:722db0819111 v8.2.4228
patch 8.2.4228: no tests for clicking in the GUI tabline
Commit: https://github.com/vim/vim/commit/b0ad2d92fd19e673ddbbc66742bae3f71778efde
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Thu Jan 27 13:16:59 2022 +0000
patch 8.2.4228: no tests for clicking in the GUI tabline
Problem: No tests for clicking in the GUI tabline.
Solution: Add test functions to generate the events. Add tests using the
functions. (Yegappan Lakshmanan, closes #9638)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 27 Jan 2022 14:30:04 +0100 |
parents | 53c64ca1c4f3 |
children | 2e0189a2be26 |
files | runtime/doc/builtin.txt runtime/doc/testing.txt runtime/doc/usr_41.txt src/evalfunc.c src/normal.c src/proto/testing.pro src/testdir/test_diffmode.vim src/testdir/test_gui.vim src/testdir/test_normal.vim src/testing.c src/version.c |
diffstat | 11 files changed, 169 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -645,6 +645,9 @@ test_gui_drop_files({list}, {row}, {col} none drop a list of files in a window test_gui_mouse_event({button}, {row}, {col}, {repeated}, {mods}) none add a mouse event to the input buffer +test_gui_tabline_event({tabnr}) Bool add a tabline event to the input buffer +test_gui_tabmenu_event({tabnr}, {event}) + none add a tabmenu event to the input buffer test_ignore_error({expr}) none ignore a specific error test_null_blob() Blob null value for testing test_null_channel() Channel null value for testing
--- a/runtime/doc/testing.txt +++ b/runtime/doc/testing.txt @@ -121,6 +121,24 @@ test_gui_mouse_event({button}, {row}, {c |feedkeys()| to have them processed, e.g.: > call feedkeys("y", 'Lx!') + *test_gui_tabline_event()* +test_gui_tabline_event({tabnr}) + Add an event that simulates a click on the tabline to select + tabpage {tabnr} to the input buffer. + Returns TRUE if the event is successfully added, FALSE if + already in the tabpage {tabnr} or the cmdline window is open. + After injecting the event you probably should call + |feedkeys()| to have them processed, e.g.: > + call feedkeys("y", 'Lx!') + + *test_gui_tabmenu_event()* +test_gui_tabmenu_event({tabnr}, {event}) + Add an event that simulates selecting a tabline menu entry for + tabpage {tabnr} to the input buffer. {event} is 1 for the + first menu entry, 2 for the second entry and so on. + After injecting the event you probably should call + |feedkeys()| to have them processed, e.g.: > + call feedkeys("y", 'Lx!') test_ignore_error({expr}) *test_ignore_error()* Ignore any error containing {expr}. A normal message is given
--- a/runtime/doc/usr_41.txt +++ b/runtime/doc/usr_41.txt @@ -1118,6 +1118,8 @@ Testing: *test-functions* test_getvalue() get value of an internal variable test_gui_drop_files() drop file(s) in a window test_gui_mouse_event() add a GUI mouse event to the input buffer + test_gui_tabline_event() add a GUI tabline event to the input buffer + test_gui_tabmenu_event() add a GUI tabmenu event to the input buffer test_ignore_error() ignore a specific error message test_null_blob() return a null Blob test_null_channel() return a null Channel
--- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -2330,6 +2330,10 @@ static funcentry_T global_functions[] = ret_void, f_test_gui_drop_files}, {"test_gui_mouse_event", 5, 5, 0, arg5_number, ret_void, f_test_gui_mouse_event}, + {"test_gui_tabline_event", 1, 1, 0, arg1_number, + ret_bool, f_test_gui_tabline_event}, + {"test_gui_tabmenu_event", 2, 2, 0, arg2_number, + ret_void, f_test_gui_tabmenu_event}, {"test_ignore_error", 1, 1, FEARG_1, arg1_string, ret_void, f_test_ignore_error}, {"test_null_blob", 0, 0, 0, NULL,
--- a/src/normal.c +++ b/src/normal.c @@ -2801,8 +2801,9 @@ scroll_redraw(int up, long count) } /* - * Get the count specified after a 'z' command. Returns TRUE to process - * the 'z' command and FALSE to skip it. + * Get the count specified after a 'z' command. Only the 'z<CR>', 'zl', 'zh', + * 'z<Left>', and 'z<Right>' commands accept a count after 'z'. + * Returns TRUE to process the 'z' command and FALSE to skip it. */ static int nv_z_get_count(cmdarg_T *cap, int *nchar_arg)
--- a/src/proto/testing.pro +++ b/src/proto/testing.pro @@ -35,6 +35,8 @@ void f_test_void(typval_T *argvars, typv void f_test_scrollbar(typval_T *argvars, typval_T *rettv); void f_test_setmouse(typval_T *argvars, typval_T *rettv); void f_test_gui_mouse_event(typval_T *argvars, typval_T *rettv); +void f_test_gui_tabline_event(typval_T *argvars, typval_T *rettv); +void f_test_gui_tabmenu_event(typval_T *argvars, typval_T *rettv); void f_test_settime(typval_T *argvars, typval_T *rettv); void f_test_gui_drop_files(typval_T *argvars, typval_T *rettv); /* vim: set ft=c : */
--- a/src/testdir/test_diffmode.vim +++ b/src/testdir/test_diffmode.vim @@ -1464,4 +1464,50 @@ func Test_diff_binary() set diffopt&vim endfunc +" Test for using the 'zi' command to invert 'foldenable' in diff windows (test +" for the issue fixed by patch 6.2.317) +func Test_diff_foldinvert() + %bw! + edit Xfile1 + new Xfile2 + new Xfile3 + windo diffthis + " open a non-diff window + botright new + 1wincmd w + call assert_true(getwinvar(1, '&foldenable')) + call assert_true(getwinvar(2, '&foldenable')) + call assert_true(getwinvar(3, '&foldenable')) + normal zi + call assert_false(getwinvar(1, '&foldenable')) + call assert_false(getwinvar(2, '&foldenable')) + call assert_false(getwinvar(3, '&foldenable')) + normal zi + call assert_true(getwinvar(1, '&foldenable')) + call assert_true(getwinvar(2, '&foldenable')) + call assert_true(getwinvar(3, '&foldenable')) + + " If the current window has 'noscrollbind', then 'zi' should not change + " 'foldenable' in other windows. + 1wincmd w + set noscrollbind + normal zi + call assert_false(getwinvar(1, '&foldenable')) + call assert_true(getwinvar(2, '&foldenable')) + call assert_true(getwinvar(3, '&foldenable')) + + " 'zi' should not change the 'foldenable' for windows with 'noscrollbind' + 1wincmd w + set scrollbind + normal zi + call setwinvar(2, '&scrollbind', v:false) + normal zi + call assert_false(getwinvar(1, '&foldenable')) + call assert_true(getwinvar(2, '&foldenable')) + call assert_false(getwinvar(3, '&foldenable')) + + %bw! + set scrollbind& +endfunc + " vim: shiftwidth=2 sts=2 expandtab
--- a/src/testdir/test_gui.vim +++ b/src/testdir/test_gui.vim @@ -1266,4 +1266,57 @@ func Test_gui_drop_files() cunmap <buffer> <F4> endfunc +" Test for generating a GUI tabline event to select a tab page +func Test_gui_tabline_event() + %bw! + edit Xfile1 + tabedit Xfile2 + tabedit Xfile3 + + tabfirst + call assert_equal(v:true, test_gui_tabline_event(2)) + call feedkeys("y", "Lx!") + call assert_equal(2, tabpagenr()) + call assert_equal(v:true, test_gui_tabline_event(3)) + call feedkeys("y", "Lx!") + call assert_equal(3, tabpagenr()) + call assert_equal(v:false, test_gui_tabline_event(3)) + + " From the cmdline window, tabline event should not be handled + call feedkeys("q::let t = test_gui_tabline_event(2)\<CR>:q\<CR>", 'x!') + call assert_equal(v:false, t) + + %bw! +endfunc + +" Test for generating a GUI tabline menu event to execute an action +func Test_gui_tabmenu_event() + %bw! + + " Try to close the last tab page + call test_gui_tabmenu_event(1, 1) + call feedkeys("y", "Lx!") + + edit Xfile1 + tabedit Xfile2 + call test_gui_tabmenu_event(1, 1) + call feedkeys("y", "Lx!") + call assert_equal(1, tabpagenr('$')) + call assert_equal('Xfile2', bufname()) + + call test_gui_tabmenu_event(1, 2) + call feedkeys("y", "Lx!") + call assert_equal(2, tabpagenr('$')) + + " If tabnr is 0, then the current tabpage should be used. + call test_gui_tabmenu_event(0, 2) + call feedkeys("y", "Lx!") + call assert_equal(3, tabpagenr('$')) + call test_gui_tabmenu_event(0, 1) + call feedkeys("y", "Lx!") + call assert_equal(2, tabpagenr('$')) + + %bw! +endfunc + " vim: shiftwidth=2 sts=2 expandtab
--- a/src/testdir/test_normal.vim +++ b/src/testdir/test_normal.vim @@ -891,6 +891,7 @@ endfunc func Test_normal_z_error() call assert_beeps('normal! z2p') call assert_beeps('normal! zq') + call assert_beeps('normal! cz1') endfunc func Test_normal15_z_scroll_vert() @@ -930,7 +931,7 @@ func Test_normal15_z_scroll_vert() call assert_equal(10, winheight(0)) exe "norm! z12\<cr>" call assert_equal(12, winheight(0)) - exe "norm! z10\<cr>" + exe "norm! z15\<Del>0\<cr>" call assert_equal(10, winheight(0)) " Test for z.
--- a/src/testing.c +++ b/src/testing.c @@ -1340,6 +1340,40 @@ f_test_gui_mouse_event(typval_T *argvars } void +f_test_gui_tabline_event(typval_T *argvars UNUSED, typval_T *rettv UNUSED) +{ +# ifdef FEAT_GUI + int tabnr; + + if (check_for_number_arg(argvars, 0) == FAIL) + return; + + tabnr = tv_get_number(&argvars[0]); + + rettv->v_type = VAR_BOOL; + rettv->vval.v_number = send_tabline_event(tabnr); +# endif +} + + void +f_test_gui_tabmenu_event(typval_T *argvars UNUSED, typval_T *rettv UNUSED) +{ +# ifdef FEAT_GUI + int tabnr; + int event; + + if (check_for_number_arg(argvars, 0) == FAIL + || check_for_number_arg(argvars, 1) == FAIL) + return; + + tabnr = tv_get_number(&argvars[0]); + event = tv_get_number(&argvars[1]); + + send_tabline_menu_event(tabnr, event); +# endif +} + + void f_test_settime(typval_T *argvars, typval_T *rettv UNUSED) { if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL)