Patch 8.2.4276
Problem:    Separate test function for the GUI scrollbar.
Solution:   Use test_gui_event(). (Yegappan Lakshmanan, closes #9674)
Files:      runtime/doc/builtin.txt, runtime/doc/testing.txt,
            runtime/doc/usr_41.txt, src/evalfunc.c, src/testing.c,
            src/proto/testing.pro, src/testdir/test_gui.vim,
            src/testdir/test_vim9_builtin.vim


*** ../vim-8.2.4275/runtime/doc/builtin.txt     2022-01-31 12:26:47.847706522 
+0000
--- runtime/doc/builtin.txt     2022-01-31 17:35:24.613849342 +0000
***************
*** 654,661 ****
  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()
--- 654,659 ----
***************
*** 89,94 ****
--- 92,98 ----
                    "dropfiles" drop one or more files in a window.
                    "findrepl"  search and replace text
                    "mouse"     mouse button click event.
+                   "scrollbar" move or drag the scrollbar
                    "tabline"   select a tab page by mouse click.
                    "tabmenu"   select a tabline menu entry.
  
***************
*** 146,151 ****
--- 150,171 ----
                                    8   alt is pressed
                                   16   ctrl is pressed
  
+               "scrollbar":
+                 Set or drag the left, right or horizontal scrollbar.  Only
+                 works when the scrollbar actually exists.  The supported
+                 items in {args} are:
+                   which:      scrollbar. The supported values are:
+                                   left  Left scrollbar of the current window
+                                   right Right scrollbar of the current window
+                                   hor   Horizontal scrollbar
+                   value:      amount to scroll.  For the vertical scrollbars
+                               the 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.
+                   dragging:   1 to drag the scrollbar and 0 to click in the
+                               scrollbar.
+ 
                "tabline":
                  Inject a mouse click event on the tabline to select a
                  tabpage. The supported items in {args} are:
***************
*** 287,312 ****
                        GetVarname()->test_refcount()
  
  
- 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.
- 
-               Can also be used as a |method|: >
-                       GetValue()->test_scrollbar('right', 0)
- 
  test_setmouse({row}, {col})                           *test_setmouse()*
                Set the mouse position to be used for the next mouse action.
                {row} and {col} are one based.
--- 301,306 ----
*** ../vim-8.2.4275/runtime/doc/usr_41.txt      2022-01-31 12:26:47.847706522 
+0000
--- runtime/doc/usr_41.txt      2022-01-31 17:35:24.613849342 +0000
***************
*** 1039,1045 ****
        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
--- 1130,1135 ----
*** ../vim-8.2.4275/src/evalfunc.c      2022-01-31 14:59:33.514943760 +0000
--- src/evalfunc.c      2022-01-31 17:35:24.617849284 +0000
***************
*** 933,939 ****
  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};
--- 933,938 ----
***************
*** 2359,2372 ****
                        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,
--- 2358,2363 ----
*** ../vim-8.2.4275/src/testing.c       2022-01-30 18:00:22.703274483 +0000
--- src/testing.c       2022-01-31 17:35:24.617849284 +0000
***************
*** 1253,1302 ****
      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)
  {
--- 1253,1258 ----
***************
*** 1430,1435 ****
--- 1386,1428 ----
  }
  
      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)
  {
  #  ifdef FEAT_GUI_TABLINE
***************
*** 1487,1492 ****
--- 1480,1487 ----
        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)
*** ../vim-8.2.4275/src/proto/testing.pro       2022-01-30 12:36:48.732985521 
+0000
--- src/proto/testing.pro       2022-01-31 17:35:24.617849284 +0000
***************
*** 32,38 ****
  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);
--- 32,37 ----
*** ../vim-8.2.4275/src/testdir/test_gui.vim    2022-01-30 18:00:22.703274483 
+0000
--- src/testdir/test_gui.vim    2022-01-31 17:35:24.617849284 +0000
***************
*** 714,726 ****
    set guioptions+=rlb
  
    " scroll to move line 11 at top, moves the cursor there
!   eval 10->test_scrollbar('left', 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('.'))
--- 714,728 ----
    set guioptions+=rlb
  
    " scroll to move line 11 at top, moves the cursor there
!   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
!   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,743 ****
    call assert_equal(1, col('.'))
  
    " scroll to character 11, cursor is moved
!   call test_scrollbar('hor', 10, 0)
    redraw
    call assert_equal(1, wincol())
    set number
--- 739,746 ----
    call assert_equal(1, col('.'))
  
    " scroll to character 11, cursor is moved
!   let args = #{which: 'hor', value: 10, dragging: 0}
!   call test_gui_event('scrollbar', args)
    redraw
    call assert_equal(1, wincol())
    set number
***************
*** 747,752 ****
--- 750,762 ----
    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,1351 ****
--- 1356,1363 ----
    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,1465 ****
--- 1472,1489 ----
    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
  
*** ../vim-8.2.4275/src/testdir/test_vim9_builtin.vim   2022-01-30 
15:28:26.642295028 +0000
--- src/testdir/test_vim9_builtin.vim   2022-01-31 17:35:24.617849284 +0000
***************
*** 4089,4101 ****
    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'])
--- 4089,4094 ----
*** ../vim-8.2.4275/src/version.c       2022-01-31 17:26:00.602083093 +0000
--- src/version.c       2022-01-31 17:37:25.828074482 +0000
***************
*** 748,749 ****
--- 748,751 ----
  {   /* Add new patch number below this line */
+ /**/
+     4276,
  /**/

-- 
BEDEVERE:        Why do you think she is a witch?
SECOND VILLAGER: She turned me into a newt.
BEDEVERE:        A newt?
SECOND VILLAGER: (After looking at himself for some time) I got better.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220131174124.E27111C1918%40moolenaar.net.

Raspunde prin e-mail lui