summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-09-14 21:27:06 +0200
committerBram Moolenaar <Bram@vim.org>2018-09-14 21:27:06 +0200
commitab18673731522c18696b9b132d3841646904e1bd (patch)
tree03234ad6705334d62dbd6c32bd0fed716a06f590
parentda1f71d75f0bf5d5ef876a09aa08fb19f6f24b3b (diff)
patch 8.1.0390: scrollbars are not testedv8.1.0390
Problem: Scrollbars are not tested. Solution: Add test_scrollbar() and a test.
-rw-r--r--runtime/doc/eval.txt19
-rw-r--r--src/evalfunc.c41
-rw-r--r--src/testdir/test_gui.vim35
-rw-r--r--src/version.c2
4 files changed, 97 insertions, 0 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index fdac40586b..fff19da1a3 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -2475,6 +2475,8 @@ test_null_partial() Funcref null value for testing
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_override()*
< 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
index f49bcb843d..0daf5903a7 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -429,6 +429,9 @@ static void f_test_null_job(typval_T *argvars, typval_T *rettv);
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 UNUSED, typval_T *rettv)
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
index 9b42134ac9..0775b178fb 100644
--- 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
index a5f251255c..f9e9cf495b 100644
--- 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,