]> granicus.if.org Git - vim/commitdiff
patch 8.2.4276: separate test function for the GUI scrollbar v8.2.4276
authorYegappan Lakshmanan <yegappan@yahoo.com>
Mon, 31 Jan 2022 17:40:55 +0000 (17:40 +0000)
committerBram Moolenaar <Bram@vim.org>
Mon, 31 Jan 2022 17:40:55 +0000 (17:40 +0000)
Problem:    Separate test function for the GUI scrollbar.
Solution:   Use test_gui_event(). (Yegappan Lakshmanan, closes #9674)

runtime/doc/builtin.txt
runtime/doc/usr_41.txt
src/evalfunc.c
src/proto/testing.pro
src/testdir/test_gui.vim
src/testdir/test_vim9_builtin.vim
src/testing.c
src/version.c

index 943cd517583c1f0985492f0cc50cde5066dc683f..98c358d6a52f832d27219be73b50554c0e9e33b5 100644 (file)
@@ -654,8 +654,6 @@ 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_refcount({expr})          Number  get the reference count of {expr}
-test_scrollbar({which}, {value}, {dragging})
-                               none    scroll in the GUI for testing
 test_setmouse({row}, {col})    none    set the mouse position for testing
 test_settime({expr})           none    set current time for testing
 test_srand_seed([seed])                none    set seed for testing srand()
index ebfbbe6bbafea1dd985b3afd732ca2b1706bbb56..7bb363b43600243a4749630c296f3eb034cd44d8 100644 (file)
@@ -1130,7 +1130,6 @@ Testing:                              *test-functions*
        test_setmouse()         set the mouse position
        test_feedinput()        add key sequence to input buffer
        test_option_not_set()   reset flag indicating option was set
-       test_scrollbar()        simulate scrollbar movement in the GUI
        test_refcount()         return an expression's reference count
        test_srand_seed()       set the seed value for srand()
        test_unknown()          return a value with unknown type
index 1b788db9c4fb57e70cde2d67dc3461a71473028c..1c08f3dfc2357a99de2c329ebc0a8fad603abfe4 100644 (file)
@@ -933,7 +933,6 @@ static argcheck_T arg3_string_any_string[] = {arg_string, NULL, arg_string};
 static argcheck_T arg3_string_bool_bool[] = {arg_string, arg_bool, arg_bool};
 static argcheck_T arg3_string_bool_dict[] = {arg_string, arg_bool, arg_dict_any};
 static argcheck_T arg3_string_number_bool[] = {arg_string, arg_number, arg_bool};
-static argcheck_T arg3_string_number_number[] = {arg_string, arg_number, arg_number};
 static argcheck_T arg3_string_string_bool[] = {arg_string, arg_string, arg_bool};
 static argcheck_T arg3_string_string_dict[] = {arg_string, arg_string, arg_dict_any};
 static argcheck_T arg3_string_string_number[] = {arg_string, arg_string, arg_number};
@@ -2359,14 +2358,6 @@ static funcentry_T global_functions[] =
                        ret_void,           f_test_override},
     {"test_refcount",  1, 1, FEARG_1,      NULL,
                        ret_number,         f_test_refcount},
-    {"test_scrollbar", 3, 3, FEARG_2,      arg3_string_number_number,
-                       ret_void,
-#ifdef FEAT_GUI
-       f_test_scrollbar
-#else
-       NULL
-#endif
-                       },
     {"test_setmouse",  2, 2, 0,            arg2_number,
                        ret_void,           f_test_setmouse},
     {"test_settime",   1, 1, FEARG_1,      arg1_number,
index 1277a2e05b691d7f2c06939c3496805060364944..2192e91ec7154f563dc42c423ea4111a61d00b0a 100644 (file)
@@ -32,7 +32,6 @@ void f_test_null_partial(typval_T *argvars, typval_T *rettv);
 void f_test_null_string(typval_T *argvars, typval_T *rettv);
 void f_test_unknown(typval_T *argvars, typval_T *rettv);
 void f_test_void(typval_T *argvars, typval_T *rettv);
-void f_test_scrollbar(typval_T *argvars, typval_T *rettv);
 void f_test_setmouse(typval_T *argvars, typval_T *rettv);
 void f_test_gui_event(typval_T *argvars, typval_T *rettv);
 void f_test_settime(typval_T *argvars, typval_T *rettv);
index 5516c8904a8990731b6a72683c650e75fbda60fe..61451bc3ee3c95df161eeb5da62c1a4f2baaf57a 100644 (file)
@@ -714,13 +714,15 @@ func Test_scrollbars()
   set guioptions+=rlb
 
   " scroll to move line 11 at top, moves the cursor there
-  eval 10->test_scrollbar('left', 0)
+  let args = #{which: 'left', value: 10, dragging: 0}
+  call test_gui_event('scrollbar', args)
   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)
+  let args = #{which: 'right', value: 0, dragging: 0}
+  call test_gui_event('scrollbar', args)
   redraw
   call assert_equal(11, winline())
   call assert_equal(11, line('.'))
@@ -737,7 +739,8 @@ func Test_scrollbars()
   call assert_equal(1, col('.'))
 
   " scroll to character 11, cursor is moved
-  call test_scrollbar('hor', 10, 0)
+  let args = #{which: 'hor', value: 10, dragging: 0}
+  call test_gui_event('scrollbar', args)
   redraw
   call assert_equal(1, wincol())
   set number
@@ -747,6 +750,13 @@ func Test_scrollbars()
   redraw
   call assert_equal(11, col('.'))
 
+  " Invalid arguments
+  call assert_false(test_gui_event('scrollbar', {}))
+  call assert_false(test_gui_event('scrollbar', #{value: 10, dragging: 0}))
+  call assert_false(test_gui_event('scrollbar', #{which: 'hor', dragging: 0}))
+  call assert_false(test_gui_event('scrollbar', #{which: 'hor', value: 1}))
+  call assert_fails("call test_gui_event('scrollbar', #{which: 'a', value: 1, dragging: 0})", 'E475:')
+
   set guioptions&
   set wrap&
   bwipe!
@@ -1346,6 +1356,8 @@ func Test_gui_drop_files()
   call assert_false(test_gui_event("dropfiles", {}))
   let d = #{row: 1, col: 1, modifiers: 0}
   call assert_false(test_gui_event("dropfiles", d))
+  let d = #{files: 1, row: 1, col: 1, modifiers: 0}
+  call assert_false(test_gui_event("dropfiles", d))
   let d = #{files: test_null_list(), row: 1, col: 1, modifiers: 0}
   call assert_false(test_gui_event("dropfiles", d))
   let d = #{files: [test_null_string()], row: 1, col: 1, modifiers: 0}
@@ -1460,6 +1472,18 @@ func Test_gui_findrepl()
   let args = #{find_text: 'TWO', repl_text: 'two', flags: 0x1C, forward: 1}
   call test_gui_event('findrepl', args)
   call assert_equal(['ONE two ONE', 'Twoo ONE two ONEo'], getline(1, '$'))
+
+  " Invalid arguments
+  call assert_false(test_gui_event('findrepl', {}))
+  let args = #{repl_text: 'a', flags: 1, forward: 1}
+  call assert_false(test_gui_event('findrepl', args))
+  let args = #{find_text: 'a', flags: 1, forward: 1}
+  call assert_false(test_gui_event('findrepl', args))
+  let args = #{find_text: 'a', repl_text: 'b', forward: 1}
+  call assert_false(test_gui_event('findrepl', args))
+  let args = #{find_text: 'a', repl_text: 'b', flags: 1}
+  call assert_false(test_gui_event('findrepl', args))
+
   bw!
 endfunc
 
index d6b42bbfd63c697473b335e606137793a70ee716..2e84011ac81ebcd3af05d6d4b0c658eed322e45a 100644 (file)
@@ -4089,13 +4089,6 @@ def Test_test_override()
   v9.CheckDefAndScriptFailure(['test_override("a", "x")'], ['E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2'])
 enddef
 
-def Test_test_scrollbar()
-  CheckGui
-  v9.CheckDefAndScriptFailure(['test_scrollbar(1, 2, 3)'], ['E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1'])
-  v9.CheckDefAndScriptFailure(['test_scrollbar("a", "b", 3)'], ['E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2'])
-  v9.CheckDefAndScriptFailure(['test_scrollbar("a", 2, "c")'], ['E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3'])
-enddef
-
 def Test_test_setmouse()
   v9.CheckDefAndScriptFailure(['test_setmouse("a", 10)'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1'])
   v9.CheckDefAndScriptFailure(['test_setmouse(10, "b")'], ['E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2'])
index 5c4f118ceff41a0849ce2a85fdb4769514f8661f..6fcbaa72abbb99abd2788975ca7d7eb44e7619dc 100644 (file)
@@ -1253,50 +1253,6 @@ f_test_void(typval_T *argvars UNUSED, typval_T *rettv)
     rettv->v_type = VAR_VOID;
 }
 
-#ifdef FEAT_GUI
-    void
-f_test_scrollbar(typval_T *argvars, typval_T *rettv UNUSED)
-{
-    char_u     *which;
-    long       value;
-    int                dragging;
-    scrollbar_T *sb = NULL;
-
-    if (check_for_string_arg(argvars, 0) == FAIL
-           || check_for_number_arg(argvars, 1) == FAIL
-           || check_for_number_arg(argvars, 2) == FAIL)
-       return;
-
-    if (argvars[0].v_type != VAR_STRING
-           || (argvars[1].v_type) != VAR_NUMBER
-           || (argvars[2].v_type) != VAR_NUMBER)
-    {
-       emsg(_(e_invalid_argument));
-       return;
-    }
-    which = tv_get_string(&argvars[0]);
-    value = tv_get_number(&argvars[1]);
-    dragging = tv_get_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)
-    {
-       semsg(_(e_invalid_argument_str), which);
-       return;
-    }
-    gui_drag_scrollbar(sb, value, dragging);
-# ifndef USE_ON_FLY_SCROLL
-    // need to loop through normal_cmd() to handle the scroll events
-    exec_normal(FALSE, TRUE, FALSE);
-# endif
-}
-#endif
-
     void
 f_test_setmouse(typval_T *argvars, typval_T *rettv UNUSED)
 {
@@ -1429,6 +1385,43 @@ test_gui_mouse_event(dict_T *args)
     return TRUE;
 }
 
+    static int
+test_gui_scrollbar(dict_T *args)
+{
+    char_u     *which;
+    long       value;
+    int                dragging;
+    scrollbar_T *sb = NULL;
+
+    if (dict_find(args, (char_u *)"which", -1) == NULL
+           || dict_find(args, (char_u *)"value", -1) == NULL
+           || dict_find(args, (char_u *)"dragging", -1) == NULL)
+       return FALSE;
+
+    which = dict_get_string(args, (char_u *)"which", FALSE);
+    value = (long)dict_get_number(args, (char_u *)"value");
+    dragging = (int)dict_get_number(args, (char_u *)"dragging");
+
+    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)
+    {
+       semsg(_(e_invalid_argument_str), which);
+       return FALSE;
+    }
+    gui_drag_scrollbar(sb, value, dragging);
+#  ifndef USE_ON_FLY_SCROLL
+    // need to loop through normal_cmd() to handle the scroll events
+    exec_normal(FALSE, TRUE, FALSE);
+#  endif
+
+    return TRUE;
+}
+
     static int
 test_gui_tabline_event(dict_T *args UNUSED)
 {
@@ -1487,6 +1480,8 @@ f_test_gui_event(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
        rettv->vval.v_number = test_gui_find_repl(argvars[1].vval.v_dict);
     else if (STRCMP(event, "mouse") == 0)
        rettv->vval.v_number = test_gui_mouse_event(argvars[1].vval.v_dict);
+    else if (STRCMP(event, "scrollbar") == 0)
+       rettv->vval.v_number = test_gui_scrollbar(argvars[1].vval.v_dict);
     else if (STRCMP(event, "tabline") == 0)
        rettv->vval.v_number = test_gui_tabline_event(argvars[1].vval.v_dict);
     else if (STRCMP(event, "tabmenu") == 0)
index d3b7bf846192a5d276cfc67987c1f40b069a14b0..301f54421b638597e5e55148b99699943164c11e 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4276,
 /**/
     4275,
 /**/