]> granicus.if.org Git - vim/commitdiff
patch 8.2.3028: GUI mouse events not tested v8.2.3028
authorYegappan Lakshmanan <yegappan@yahoo.com>
Mon, 21 Jun 2021 16:44:26 +0000 (18:44 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 21 Jun 2021 16:44:26 +0000 (18:44 +0200)
Problem:    GUI mouse events not tested.
Solution:   Add test_gui_mouse_event().  Add mouse tests. Also add a few
            viminfo tests. (Yegappan Lakshmanan, closes #8407)

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

index 4620623c631839c27b26c3fb97b7b29515ecee20..1f52d9f05bacccb8ec248fe23ec5556bd1651f61 100644 (file)
@@ -3022,6 +3022,8 @@ test_feedinput({string})  none    add key sequence to input buffer
 test_garbagecollect_now()      none    free memory right now for testing
 test_garbagecollect_soon()     none    free memory soon for testing
 test_getvalue({string})                any     get value of an internal variable
+test_gui_mouse_event({button}, {row}, {col}, {repeated}, {mods})
+                               none    add a mouse 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
index 6fd2d458876893723a02cbf0002b21e1823f839b..db505e7efce75522bc1618e02858b114877d450a 100644 (file)
@@ -1,4 +1,4 @@
-*testing.txt*  For Vim version 8.2.  Last change: 2021 Apr 02
+*testing.txt*  For Vim version 8.2.  Last change: 2021 Jun 21
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -78,6 +78,30 @@ test_getvalue({name})                                        *test_getvalue()*
 
                Can also be used as a |method|: >
                        GetName()->test_getvalue()
+<
+                                               *test_gui_mouse_event()*
+test_gui_mouse_event({button}, {row}, {col}, {multiclick}, {modifiers})
+               Inject a mouse button click event.  This function works only
+               when GUI is running.
+               The supported values for {button} are:
+                       0       right mouse button
+                       1       middle mouse button
+                       2       left mouse button
+                       3       mouse button release
+                       4       scroll wheel down
+                       5       scroll wheel up
+                       6       scroll wheel left
+                       7       scroll wheel right
+               {row} and {col} specify the location of the mouse click.
+               To inject a multiclick event, set {multiclick} to 1.
+               The supported values for {modifiers} are:
+                       4       shift is pressed
+                       8       alt is pressed
+                       16      ctrl is pressed
+               After injecting the mouse 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
index 09d5a39db7576a312f463f8d7346fb70a140b569..de7f19707880335e8af43384aff729328c6b74cf 100644 (file)
@@ -1021,6 +1021,7 @@ Testing:                              *test-functions*
        test_garbagecollect_now()   free memory right now
        test_garbagecollect_soon()  set a flag to free memory soon
        test_getvalue()         get value of an internal variable
+       test_gui_mouse_event()  add a GUI mouse 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
index fdcc00fe87cfdae561f49ffd778a20de2194190d..f8af8ef8125092f64cf0478353fea72a5dc62b31 100644 (file)
@@ -1696,6 +1696,8 @@ static funcentry_T global_functions[] =
                        ret_void,           f_test_garbagecollect_soon},
     {"test_getvalue",  1, 1, FEARG_1,      NULL,
                        ret_number,         f_test_getvalue},
+    {"test_gui_mouse_event",   5, 5, 0,            NULL,
+                       ret_void,           f_test_gui_mouse_event},
     {"test_ignore_error", 1, 1, FEARG_1,    NULL,
                        ret_void,           f_test_ignore_error},
     {"test_null_blob", 0, 0, 0,            NULL,
index d229030cb503bff14d8cd01dcc7a01df0ee6690a..3e203f8fd608d384ec1691c8efd6ed8e9f175ac0 100644 (file)
@@ -34,5 +34,6 @@ 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_mouse_event(typval_T *argvars, typval_T *rettv);
 void f_test_settime(typval_T *argvars, typval_T *rettv);
 /* vim: set ft=c : */
index 69f140b713e7bcd4b4e5c21a6c5e87b6e01bbe97..3472012c4ae06289daa94a34b5189cac51748b1f 100644 (file)
@@ -389,7 +389,7 @@ func Test_set_guifont()
   endif
 
   " This only works if 'renderoptions' exists and does not work for Windows XP
-  " and older. 
+  " and older.
   if exists('+renderoptions') && windowsversion() !~ '^[345]\.'
     " doing this four times used to cause a crash
     set renderoptions=type:directx
@@ -875,4 +875,226 @@ func Test_gui_recursive_mapping()
   nunmap <C-W>a
 endfunc
 
+" Test GUI mouse events
+func Test_gui_mouse_event()
+  set mousemodel=extend
+  call test_override('no_query_mouse', 1)
+  new
+  call setline(1, ['one two three', 'four five six'])
+
+  " place the cursor using left click
+  call cursor(1, 1)
+  call test_gui_mouse_event(0, 2, 4, 0, 0)
+  call test_gui_mouse_event(3, 2, 4, 0, 0)
+  call feedkeys("\<Esc>", 'Lx!')
+  call assert_equal([0, 2, 4, 0], getpos('.'))
+
+  " select and yank a word
+  let @" = ''
+  call test_gui_mouse_event(0, 1, 9, 0, 0)
+  call test_gui_mouse_event(0, 1, 9, 1, 0)
+  call test_gui_mouse_event(3, 1, 9, 0, 0)
+  call feedkeys("y", 'Lx!')
+  call assert_equal('three', @")
+
+  " create visual selection using right click
+  let @" = ''
+  call test_gui_mouse_event(0, 2, 6, 0, 0)
+  call test_gui_mouse_event(3, 2, 6, 0, 0)
+  call test_gui_mouse_event(2, 2, 13, 0, 0)
+  call test_gui_mouse_event(3, 2, 13, 0, 0)
+  call feedkeys("y", 'Lx!')
+  call assert_equal('five six', @")
+
+  " paste using middle mouse button
+  let @* = 'abc '
+  call feedkeys('""', 'Lx!')
+  call test_gui_mouse_event(1, 1, 9, 0, 0)
+  call test_gui_mouse_event(3, 1, 9, 0, 0)
+  call feedkeys("\<Esc>", 'Lx!')
+  call assert_equal(['one two abc three', 'four five six'], getline(1, '$'))
+
+  " extend visual selection using right click in visual mode
+  let @" = ''
+  call cursor(1, 1)
+  call feedkeys('v', 'Lx!')
+  call test_gui_mouse_event(2, 1, 17, 0, 0)
+  call test_gui_mouse_event(3, 1, 17, 0, 0)
+  call feedkeys("y", 'Lx!')
+  call assert_equal('one two abc three', @")
+
+  " extend visual selection using mouse drag
+  let @" = ''
+  call cursor(1, 1)
+  call test_gui_mouse_event(0, 2, 1, 0, 0)
+  call test_gui_mouse_event(0x43, 2, 9, 0, 0)
+  call test_gui_mouse_event(0x3, 2, 9, 0, 0)
+  call feedkeys("y", 'Lx!')
+  call assert_equal('four five', @")
+
+  " select text by moving the mouse
+  let @" = ''
+  call cursor(1, 1)
+  redraw!
+  call test_gui_mouse_event(0, 1, 4, 0, 0)
+  call test_gui_mouse_event(0x700, 1, 9, 0, 0)
+  call test_gui_mouse_event(0x700, 1, 13, 0, 0)
+  call test_gui_mouse_event(0x3, 1, 13, 0, 0)
+  call feedkeys("y", 'Lx!')
+  call assert_equal(' two abc t', @")
+
+  " Using mouse in insert mode
+  call cursor(1, 1)
+  call feedkeys('i', 't')
+  call test_gui_mouse_event(0, 2, 11, 0, 0)
+  call test_gui_mouse_event(3, 2, 11, 0, 0)
+  call feedkeys("po\<Esc>", 'Lx!')
+  call assert_equal(['one two abc three', 'four five posix'], getline(1, '$'))
+
+  %d _
+  call setline(1, range(1, 100))
+  " scroll up
+  call test_gui_mouse_event(0x200, 2, 1, 0, 0)
+  call test_gui_mouse_event(0x200, 2, 1, 0, 0)
+  call test_gui_mouse_event(0x200, 2, 1, 0, 0)
+  call feedkeys("H", 'Lx!')
+  call assert_equal(10, line('.'))
+
+  " scroll down
+  call test_gui_mouse_event(0x100, 2, 1, 0, 0)
+  call test_gui_mouse_event(0x100, 2, 1, 0, 0)
+  call feedkeys("H", 'Lx!')
+  call assert_equal(4, line('.'))
+
+  %d _
+  set nowrap
+  call setline(1, range(10)->join('')->repeat(10))
+  " scroll left
+  call test_gui_mouse_event(0x500, 1, 5, 0, 0)
+  call test_gui_mouse_event(0x500, 1, 10, 0, 0)
+  call test_gui_mouse_event(0x500, 1, 15, 0, 0)
+  call feedkeys('g0', 'Lx!')
+  call assert_equal(19, col('.'))
+
+  " scroll right
+  call test_gui_mouse_event(0x600, 1, 15, 0, 0)
+  call test_gui_mouse_event(0x600, 1, 10, 0, 0)
+  call feedkeys('g0', 'Lx!')
+  call assert_equal(7, col('.'))
+  set wrap&
+
+  %d _
+  call setline(1, repeat([repeat('a', 60)], 10))
+
+  " record various mouse events
+  let mouseEventNames = [
+        \ 'LeftMouse', 'LeftRelease', '2-LeftMouse', '3-LeftMouse',
+        \ 'S-LeftMouse', 'A-LeftMouse', 'C-LeftMouse', 'MiddleMouse',
+        \ 'MiddleRelease', '2-MiddleMouse', '3-MiddleMouse',
+        \ 'S-MiddleMouse', 'A-MiddleMouse', 'C-MiddleMouse',
+        \ 'RightMouse', 'RightRelease', '2-RightMouse',
+        \ '3-RightMouse', 'S-RightMouse', 'A-RightMouse', 'C-RightMouse',
+        \ 'X1Mouse', 'S-X1Mouse', 'A-X1Mouse', 'C-X1Mouse', 'X2Mouse',
+        \ 'S-X2Mouse', 'A-X2Mouse', 'C-X2Mouse'
+        \ ]
+  let mouseEventCodes = map(copy(mouseEventNames), "'<' .. v:val .. '>'")
+  let g:events = []
+  for e in mouseEventCodes
+    exe 'nnoremap ' .. e .. ' <Cmd>call add(g:events, "' ..
+          \ substitute(e, '[<>]', '', 'g') .. '")<CR>'
+  endfor
+
+  " Test various mouse buttons (0 - Left, 1 - Middle, 2 - Right, 0x300 - X1,
+  " 0x300- X2)
+  for button in [0, 1, 2, 0x300, 0x400]
+    " Single click
+    call test_gui_mouse_event(button, 2, 5, 0, 0)
+    call test_gui_mouse_event(3, 2, 5, 0, 0)
+
+    " Double/Triple click is supported by only the Left/Middle/Right mouse
+    " buttons
+    if button <= 2
+      " Double Click
+      call test_gui_mouse_event(button, 2, 5, 0, 0)
+      call test_gui_mouse_event(button, 2, 5, 1, 0)
+      call test_gui_mouse_event(3, 2, 5, 0, 0)
+
+      " Triple Click
+      call test_gui_mouse_event(button, 2, 5, 0, 0)
+      call test_gui_mouse_event(button, 2, 5, 1, 0)
+      call test_gui_mouse_event(button, 2, 5, 1, 0)
+      call test_gui_mouse_event(3, 2, 5, 0, 0)
+    endif
+
+    " Shift click
+    call test_gui_mouse_event(button, 3, 7, 0, 4)
+    call test_gui_mouse_event(3, 3, 7, 0, 4)
+
+    " Alt click
+    call test_gui_mouse_event(button, 3, 7, 0, 8)
+    call test_gui_mouse_event(3, 3, 7, 0, 8)
+
+    " Ctrl click
+    call test_gui_mouse_event(button, 3, 7, 0, 16)
+    call test_gui_mouse_event(3, 3, 7, 0, 16)
+
+    call feedkeys("\<Esc>", 'Lx!')
+  endfor
+
+  call assert_equal(['LeftMouse', 'LeftRelease', 'LeftMouse', '2-LeftMouse',
+        \ 'LeftMouse', '2-LeftMouse', '3-LeftMouse', 'S-LeftMouse',
+        \ 'A-LeftMouse', 'C-LeftMouse', 'MiddleMouse', 'MiddleRelease',
+        \ 'MiddleMouse', '2-MiddleMouse', 'MiddleMouse', '2-MiddleMouse',
+        \ '3-MiddleMouse', 'S-MiddleMouse', 'A-MiddleMouse', 'C-MiddleMouse',
+        \ 'RightMouse', 'RightRelease', 'RightMouse', '2-RightMouse',
+        \ 'RightMouse', '2-RightMouse', '3-RightMouse', 'S-RightMouse',
+        \ 'A-RightMouse', 'C-RightMouse', 'X1Mouse', 'S-X1Mouse', 'A-X1Mouse',
+        \ 'C-X1Mouse', 'X2Mouse', 'S-X2Mouse', 'A-X2Mouse', 'C-X2Mouse'],
+        \ g:events)
+
+  for e in mouseEventCodes
+    exe 'nunmap ' .. e
+  endfor
+
+  " modeless selection
+  set mouse=
+  let save_guioptions = &guioptions
+  set guioptions+=A
+  %d _
+  call setline(1, ['one two three', 'four five sixteen'])
+  call cursor(1, 1)
+  redraw!
+  " Double click should select the word and copy it to clipboard
+  let @* = ''
+  call test_gui_mouse_event(0, 2, 11, 0, 0)
+  call test_gui_mouse_event(0, 2, 11, 1, 0)
+  call test_gui_mouse_event(3, 2, 11, 0, 0)
+  call feedkeys("\<Esc>", 'Lx!')
+  call assert_equal([0, 1, 1, 0], getpos('.'))
+  call assert_equal('sixteen', @*)
+  " Right click should extend the selection from cursor
+  call cursor(1, 6)
+  redraw!
+  let @* = ''
+  call test_gui_mouse_event(2, 1, 11, 0, 0)
+  call test_gui_mouse_event(3, 1, 11, 0, 0)
+  call feedkeys("\<Esc>", 'Lx!')
+  call assert_equal([0, 1, 6, 0], getpos('.'))
+  call assert_equal('wo thr', @*)
+  " Middle click should paste the clipboard contents
+  call cursor(2, 1)
+  redraw!
+  call test_gui_mouse_event(1, 1, 11, 0, 0)
+  call test_gui_mouse_event(3, 1, 11, 0, 0)
+  call feedkeys("\<Esc>", 'Lx!')
+  call assert_equal([0, 2, 7, 0], getpos('.'))
+  call assert_equal('wo thrfour five sixteen', getline(2))
+  set mouse&
+  let &guioptions = save_guioptions
+
+  bw!
+  call test_override('no_query_mouse', 0)
+  set mousemodel&
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 0518b91d06ea67e7b555edf622772fe335b776c4..6c1a711668e8e5d9e16470e19fe92d51511ea0fd 100644 (file)
@@ -63,6 +63,7 @@ func Test_global_vars()
   let g:MY_GLOBAL_NULL = test_null
   let test_none = v:none
   let g:MY_GLOBAL_NONE = test_none
+  let g:MY_GLOBAL_FUNCREF = function('min')
 
   set viminfo='100,<50,s10,h,!,nviminfo
   wv! Xviminfo
@@ -77,6 +78,7 @@ func Test_global_vars()
   unlet g:MY_GLOBAL_TRUE
   unlet g:MY_GLOBAL_NULL
   unlet g:MY_GLOBAL_NONE
+  unlet g:MY_GLOBAL_FUNCREF
 
   rv! Xviminfo
   call assert_equal("Vim Editor", g:MY_GLOBAL_STRING)
@@ -89,6 +91,7 @@ func Test_global_vars()
   call assert_equal(test_true, g:MY_GLOBAL_TRUE)
   call assert_equal(test_null, g:MY_GLOBAL_NULL)
   call assert_equal(test_none, g:MY_GLOBAL_NONE)
+  call assert_false(exists("g:MY_GLOBAL_FUNCREF"))
 
   " When reading global variables from viminfo, if a variable cannot be
   " modified, then the value should not be changed.
@@ -230,7 +233,26 @@ func Test_cmdline_history()
   call assert_equal("echo " . long800, histget(':', -2))
   call assert_equal("echo 'one'", histget(':', -3))
 
+  " If the value for the '/' or ':' or '@' field in 'viminfo' is zero, then
+  " the corresponding history entries are not saved.
+  set viminfo='100,/0,:0,@0,<50,s10,h,!,nviminfo
+  call histdel('/')
+  call histdel(':')
+  call histdel('@')
+  call histadd('/', 'foo')
+  call histadd(':', 'bar')
+  call histadd('@', 'baz')
+  wviminfo! Xviminfo
+  call histdel('/')
+  call histdel(':')
+  call histdel('@')
+  rviminfo! Xviminfo
+  call assert_equal('', histget('/'))
+  call assert_equal('', histget(':'))
+  call assert_equal('', histget('@'))
+
   call delete('Xviminfo')
+  set viminfo&vim
 endfunc
 
 func Test_cmdline_history_order()
@@ -346,7 +368,33 @@ func Test_viminfo_registers()
     let len += 1
   endwhile
 
+  " If the maximum number of lines saved for a register ('<' in 'viminfo') is
+  " zero, then register values should not be saved.
+  let @a = 'abc'
+  set viminfo='100,<0,s10,h,!,nviminfo
+  wviminfo Xviminfo
+  let @a = 'xyz'
+  rviminfo! Xviminfo
+  call assert_equal('xyz', @a)
+  " repeat the test with '"' instead of '<'
+  let @b = 'def'
+  set viminfo='100,\"0,s10,h,!,nviminfo
+  wviminfo Xviminfo
+  let @b = 'rst'
+  rviminfo! Xviminfo
+  call assert_equal('rst', @b)
+
+  " If the maximum size of an item ('s' in 'viminfo') is zero, then register
+  " values should not be saved.
+  let @c = '123'
+  set viminfo='100,<20,s0,h,!,nviminfo
+  wviminfo Xviminfo
+  let @c = '456'
+  rviminfo! Xviminfo
+  call assert_equal('456', @c)
+
   call delete('Xviminfo')
+  set viminfo&vim
 endfunc
 
 func Test_viminfo_marks()
@@ -541,15 +589,30 @@ func Test_viminfo_bad_syntax()
   call delete('Xviminfo')
 endfunc
 
-func Test_viminfo_bad_register_syntax()
+func Test_viminfo_bad_syntax2()
   let lines = []
   call add(lines, '|1,4')
-  call add(lines, '|3') " invalid number of fields for a register type
-  call add(lines, '|3,1,1,1,1,,1,"x"') " invalid value for the width field
+
+  " bad viminfo syntax for history barline
+  call add(lines, '|2') " invalid number of fields in a history barline
+  call add(lines, '|2,9,1,1,"x"') " invalid value for the history type
+  call add(lines, '|2,0,,1,"x"') " no timestamp
+  call add(lines, '|2,0,1,1,10') " non-string text
+
+  " bad viminfo syntax for register barline
+  call add(lines, '|3') " invalid number of fields in a register barline
+  call add(lines, '|3,1,1,1,1,,1,"x"') " missing width field
   call add(lines, '|3,0,80,1,1,1,1,"x"') " invalid register number
   call add(lines, '|3,0,10,5,1,1,1,"x"') " invalid register type
   call add(lines, '|3,0,10,1,20,1,1,"x"') " invalid line count
   call add(lines, '|3,0,10,1,0,1,1') " zero line count
+
+  " bad viminfo syntax for mark barline
+  call add(lines, '|4') " invalid number of fields in a mark barline
+  call add(lines, '|4,1,1,1,1,1') " invalid value for file name
+  call add(lines, '|4,20,1,1,1,"x"') " invalid value for file name
+  call add(lines, '|4,49,0,1,1,"x"') " invalid value for line number
+
   call writefile(lines, 'Xviminfo')
   rviminfo Xviminfo
   call delete('Xviminfo')
@@ -901,6 +964,7 @@ func Test_viminfo_perm()
   " Try to write the viminfo to a directory
   call mkdir('Xdir')
   call assert_fails('wviminfo Xdir', 'E137:')
+  call assert_fails('rviminfo Xdir', 'E195:')
   call delete('Xdir', 'rf')
 endfunc
 
index cded3c73a0aa41b58ca87a2f4af2d28fedf5471a..9f5a2f5acb58aa7dd4d6d2eac03ede1de0719a92 100644 (file)
@@ -1215,6 +1215,20 @@ f_test_setmouse(typval_T *argvars, typval_T *rettv UNUSED)
     mouse_col = (time_t)tv_get_number(&argvars[1]) - 1;
 }
 
+    void
+f_test_gui_mouse_event(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
+{
+#ifdef FEAT_GUI
+    int                button = tv_get_number(&argvars[0]);
+    int                row = tv_get_number(&argvars[1]);
+    int                col = tv_get_number(&argvars[2]);
+    int                repeated_click = tv_get_number(&argvars[3]);
+    int_u      mods = tv_get_number(&argvars[4]);
+
+    gui_send_mouse_event(button, TEXT_X(col - 1), TEXT_Y(row - 1), repeated_click, mods);
+#endif
+}
+
     void
 f_test_settime(typval_T *argvars, typval_T *rettv UNUSED)
 {
index 58d99e8af1c4b7a927a2eef47311da4b77641581..db2433db9962491009fb1d1287a3f32253595a25 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3028,
 /**/
     3027,
 /**/