# HG changeset patch # User Christian Brabandt # Date 1536953405 -7200 # Node ID a179e5cfcab7093bb01ce6905ebea14fc07560a9 # Parent 107d7668e1646817cb5139258c069fc93bab33a2 patch 8.1.0390: scrollbars are not tested commit https://github.com/vim/vim/commit/ab18673731522c18696b9b132d3841646904e1bd Author: Bram Moolenaar Date: Fri Sep 14 21:27:06 2018 +0200 patch 8.1.0390: scrollbars are not tested Problem: Scrollbars are not tested. Solution: Add test_scrollbar() and a test. diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2475,6 +2475,8 @@ test_null_partial() Funcref null value test_null_string() String null value for testing test_option_not_set({name}) none reset flag indicating option was set test_override({expr}, {val}) none test with Vim internal overrides +test_scrollbar({which}, {value}, {dragging}) + none scroll in the GUI for testing test_settime({expr}) none set current time for testing timer_info([{id}]) List information about timers timer_pause({id}, {pause}) none pause or unpause a timer @@ -8773,6 +8775,23 @@ test_override({name}, {val}) *test_ov < The value of "starting" is saved. It is restored by: > call test_override('starting', 0) +test_scrollbar({which}, {value}, {dragging}) *test_scrollbar()* + Pretend using scrollbar {which} to move it to position + {value}. {which} can be: + left Left scrollbar of the current window + right Right scrollbar of the current window + hor Horizontal scrollbar + + For the vertical scrollbars {value} can be 1 to the + line-count of the buffer. For the horizontal scrollbar the + {value} can be between 1 and the maximum line length, assuming + 'wrap' is not set. + + When {dragging} is non-zero it's like dragging the scrollbar, + otherwise it's like clicking in the scrollbar. + Only works when the {which} scrollbar actually exists, + obviously only when using the GUI. + test_settime({expr}) *test_settime()* Set the time Vim uses internally. Currently only used for timestamps in the history, as they are used in viminfo, and diff --git a/src/evalfunc.c b/src/evalfunc.c --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -429,6 +429,9 @@ static void f_test_null_job(typval_T *ar static void f_test_null_list(typval_T *argvars, typval_T *rettv); static void f_test_null_partial(typval_T *argvars, typval_T *rettv); static void f_test_null_string(typval_T *argvars, typval_T *rettv); +#ifdef FEAT_GUI +static void f_test_scrollbar(typval_T *argvars, typval_T *rettv); +#endif static void f_test_settime(typval_T *argvars, typval_T *rettv); #ifdef FEAT_FLOAT static void f_tan(typval_T *argvars, typval_T *rettv); @@ -925,6 +928,9 @@ static struct fst {"test_null_string", 0, 0, f_test_null_string}, {"test_option_not_set", 1, 1, f_test_option_not_set}, {"test_override", 2, 2, f_test_override}, +#ifdef FEAT_GUI + {"test_scrollbar", 3, 3, f_test_scrollbar}, +#endif {"test_settime", 1, 1, f_test_settime}, #ifdef FEAT_TIMERS {"timer_info", 0, 1, f_timer_info}, @@ -13202,6 +13208,41 @@ f_test_null_string(typval_T *argvars UNU rettv->vval.v_string = NULL; } +#ifdef FEAT_GUI + static void +f_test_scrollbar(typval_T *argvars, typval_T *rettv UNUSED) +{ + char_u *which; + long value; + int dragging; + scrollbar_T *sb = NULL; + + if (argvars[0].v_type != VAR_STRING + || (argvars[1].v_type) != VAR_NUMBER + || (argvars[2].v_type) != VAR_NUMBER) + { + EMSG(_(e_invarg)); + return; + } + which = get_tv_string(&argvars[0]); + value = get_tv_number(&argvars[1]); + dragging = get_tv_number(&argvars[2]); + + if (STRCMP(which, "left") == 0) + sb = &curwin->w_scrollbars[SBAR_LEFT]; + else if (STRCMP(which, "right") == 0) + sb = &curwin->w_scrollbars[SBAR_RIGHT]; + else if (STRCMP(which, "hor") == 0) + sb = &gui.bottom_sbar; + if (sb == NULL) + { + EMSG2(_(e_invarg2), which); + return; + } + gui_drag_scrollbar(sb, value, dragging); +} +#endif + static void f_test_settime(typval_T *argvars, typval_T *rettv UNUSED) { diff --git a/src/testdir/test_gui.vim b/src/testdir/test_gui.vim --- a/src/testdir/test_gui.vim +++ b/src/testdir/test_gui.vim @@ -667,6 +667,41 @@ func Test_set_guioptions() let &guioptions = guioptions_saved endfunc +func Test_scrollbars() + new + " buffer with 200 lines + call setline(1, repeat(['one', 'two'], 100)) + set guioptions+=rlb + + " scroll to move line 11 at top, moves the cursor there + call test_scrollbar('left', 10, 0) + redraw + call assert_equal(1, winline()) + call assert_equal(11, line('.')) + + " scroll to move line 1 at top, cursor stays in line 11 + call test_scrollbar('right', 0, 0) + redraw + call assert_equal(11, winline()) + call assert_equal(11, line('.')) + + set nowrap + call setline(11, repeat('x', 150)) + redraw + call assert_equal(1, wincol()) + call assert_equal(1, col('.')) + + " scroll to character 11, cursor is moved + call test_scrollbar('hor', 10, 0) + redraw + call assert_equal(1, wincol()) + call assert_equal(11, col('.')) + + set guioptions& + set wrap& + bwipe! +endfunc + func Test_set_guipty() let guipty_saved = &guipty diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -795,6 +795,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 390, +/**/ 389, /**/ 388,