Patch 8.2.4263
Problem: No test for the GUI find/replace dialog.
Solution: Add a test function and a test. (Yegappan Lakshmanan,
closes #9662)
Files: runtime/doc/testing.txt, src/testdir/test_gui.vim, src/testing.c
*** ../vim-8.2.4262/runtime/doc/testing.txt 2022-01-30 12:36:48.728985579 +0000
--- runtime/doc/testing.txt 2022-01-30 17:48:49.753051744 +0000
***************
*** 82,91 ****
*test_gui_event()*
test_gui_event({event}, {args})
Generate a GUI {event} with arguments {args} for testing Vim
! functionality.
{event} is a String and the supported values are:
"dropfiles" drop one or more files in a window.
"mouse" mouse button click event.
"tabline" select a tab page by mouse click.
"tabmenu" select a tabline menu entry.
--- 85,96 ----
*test_gui_event()*
test_gui_event({event}, {args})
Generate a GUI {event} with arguments {args} for testing Vim
! functionality. This function works only when the GUI is
! running.
{event} is a String and the supported values are:
"dropfiles" drop one or more files in a window.
+ "findrepl" search and replace text
"mouse" mouse button click event.
"tabline" select a tab page by mouse click.
"tabmenu" select a tabline menu entry.
***************
*** 104,115 ****
0x10 Ctrl
The files are added to the |argument-list| and the first
file in {files} is edited in the window. See |drag-n-drop|
! for more information. This function only works when the GUI
! is running and the |drop_file| feature is present.
"mouse":
! Inject a mouse button click event. This function only works
! when the GUI is running. The supported items in {args} are:
button: mouse button. The supported values are:
0 right mouse button
1 middle mouse button
--- 109,135 ----
0x10 Ctrl
The files are added to the |argument-list| and the first
file in {files} is edited in the window. See |drag-n-drop|
! for more information. This event works only when the
! |drop_file| feature is present.
!
! "findrepl":
! Perform a search and replace of text. The supported items
! in {args} are:
! find_text: string to find.
! repl_text: replacement string
! flags: flags controlling the find/replace. Supported
! values are:
! 1 search next string (find dialog)
! 2 search next string (replace dialog)
! 3 replace string once
! 4 replace all matches
! 8 match whole words only
! 16 match case
! forward: set to 1 for forward search.
"mouse":
! Inject a mouse button click event. The supported items in
! {args} are:
button: mouse button. The supported values are:
0 right mouse button
1 middle mouse button
*** ../vim-8.2.4262/src/testdir/test_gui.vim 2022-01-30 12:36:48.732985521 +0000
--- src/testdir/test_gui.vim 2022-01-30 17:48:49.753051744 +0000
***************
*** 1255,1264 ****
func Test_gui_drop_files()
CheckFeature drop_file
- call assert_false(test_gui_event("dropfiles", {}))
- let d = #{row: 1, col: 1, modifiers: 0}
- call assert_false(test_gui_event("dropfiles", d))
-
%bw!
%argdelete
let d = #{files: [], row: 1, col: 1, modifiers: 0}
--- 1255,1260 ----
***************
*** 1345,1350 ****
--- 1341,1355 ----
call feedkeys('k', 'Lx!')
call assert_equal('"a.c b.c', @:)
cunmap <buffer> <F4>
+
+ " Invalid arguments
+ 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: 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}
+ call assert_true(test_gui_event("dropfiles", d))
endfunc
" Test for generating a GUI tabline event to select a tab page
***************
*** 1367,1372 ****
--- 1372,1381 ----
call feedkeys("q::let t = test_gui_event('tabline', #{tabnr: 2})\<CR>:q\<CR>", 'x!')
call assert_equal(v:false, t)
+ " Invalid arguments
+ call assert_false(test_gui_event('tabline', {}))
+ call assert_false(test_gui_event('tabline', #{abc: 1}))
+
%bw!
endfunc
***************
*** 1397,1403 ****
--- 1406,1466 ----
call feedkeys("y", "Lx!")
call assert_equal(2, tabpagenr('$'))
+ " Invalid arguments
+ call assert_false(test_gui_event('tabmenu', {}))
+ call assert_false(test_gui_event('tabmenu', #{tabnr: 1}))
+ call assert_false(test_gui_event('tabmenu', #{item: 1}))
+ call assert_false(test_gui_event('tabmenu', #{abc: 1}))
+
%bw!
endfunc
+ " Test for find/replace text dialog event
+ func Test_gui_findrepl()
+ new
+ call setline(1, ['one two one', 'Twoo One two oneo'])
+
+ " Replace all instances of a string with another
+ let args = #{find_text: 'one', repl_text: 'ONE', flags: 0x4, forward: 1}
+ call test_gui_event('findrepl', args)
+ call assert_equal(['ONE two ONE', 'Twoo ONE two ONEo'], getline(1, '$'))
+
+ " Replace all instances of a whole string with another
+ call cursor(1, 1)
+ let args = #{find_text: 'two', repl_text: 'TWO', flags: 0xC, forward: 1}
+ call test_gui_event('findrepl', args)
+ call assert_equal(['ONE TWO ONE', 'Twoo ONE TWO ONEo'], getline(1, '$'))
+
+ " Find next occurance of a string (in a find dialog)
+ call cursor(1, 11)
+ let args = #{find_text: 'TWO', repl_text: '', flags: 0x11, forward: 1}
+ call test_gui_event('findrepl', args)
+ call assert_equal([2, 10], [line('.'), col('.')])
+
+ " Find previous occurances of a string (in a find dialog)
+ call cursor(1, 11)
+ let args = #{find_text: 'TWO', repl_text: '', flags: 0x11, forward: 0}
+ call test_gui_event('findrepl', args)
+ call assert_equal([1, 5], [line('.'), col('.')])
+
+ " Find next occurance of a string (in a replace dialog)
+ call cursor(1, 1)
+ let args = #{find_text: 'Twoo', repl_text: '', flags: 0x2, forward: 1}
+ call test_gui_event('findrepl', args)
+ call assert_equal([2, 1], [line('.'), col('.')])
+
+ " Replace only the next occurance of a string (once)
+ call cursor(1, 5)
+ let args = #{find_text: 'TWO', repl_text: 'two', flags: 0x3, forward: 1}
+ call test_gui_event('findrepl', args)
+ call assert_equal(['ONE two ONE', 'Twoo ONE TWO ONEo'], getline(1, '$'))
+
+ " Replace all instances of a whole string with another matching case
+ call cursor(1, 1)
+ 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, '$'))
+ bw!
+ endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.4262/src/testing.c 2022-01-30 12:36:48.732985521 +0000
--- src/testing.c 2022-01-30 17:48:49.753051744 +0000
***************
*** 1319,1325 ****
static int
test_gui_drop_files(dict_T *args UNUSED)
{
! #if defined(HAVE_DROP_FILE)
int row;
int col;
int_u mods;
--- 1319,1325 ----
static int
test_gui_drop_files(dict_T *args UNUSED)
{
! # if defined(HAVE_DROP_FILE)
int row;
int col;
int_u mods;
***************
*** 1335,1350 ****
|| dict_find(args, (char_u *)"modifiers", -1) == NULL)
return FALSE;
! if (dict_get_tv(args, (char_u *)"files", &t) == FAIL)
! return FALSE;
row = (int)dict_get_number(args, (char_u *)"row");
col = (int)dict_get_number(args, (char_u *)"col");
mods = (int)dict_get_number(args, (char_u *)"modifiers");
! l = t.vval.v_list;
! if (list_len(l) == 0)
return FALSE;
fnames = ALLOC_MULT(char_u *, list_len(l));
if (fnames == NULL)
return FALSE;
--- 1335,1349 ----
|| dict_find(args, (char_u *)"modifiers", -1) == NULL)
return FALSE;
! (void)dict_get_tv(args, (char_u *)"files", &t);
row = (int)dict_get_number(args, (char_u *)"row");
col = (int)dict_get_number(args, (char_u *)"col");
mods = (int)dict_get_number(args, (char_u *)"modifiers");
! if (t.v_type != VAR_LIST || list_len(t.vval.v_list) == 0)
return FALSE;
+ l = t.vval.v_list;
fnames = ALLOC_MULT(char_u *, list_len(l));
if (fnames == NULL)
return FALSE;
***************
*** 1352,1358 ****
FOR_ALL_LIST_ITEMS(l, li)
{
// ignore non-string items
! if (li->li_tv.v_type != VAR_STRING)
continue;
fnames[count] = vim_strsave(li->li_tv.vval.v_string);
--- 1351,1358 ----
FOR_ALL_LIST_ITEMS(l, li)
{
// ignore non-string items
! if (li->li_tv.v_type != VAR_STRING
! || li->li_tv.vval.v_string == NULL)
continue;
fnames[count] = vim_strsave(li->li_tv.vval.v_string);
***************
*** 1370,1382 ****
gui_handle_drop(TEXT_X(col - 1), TEXT_Y(row - 1), mods, fnames, count);
else
vim_free(fnames);
! # endif
return TRUE;
}
static int
! test_gui_mouse_event(dict_T *args UNUSED)
{
int button;
int row;
--- 1370,1409 ----
gui_handle_drop(TEXT_X(col - 1), TEXT_Y(row - 1), mods, fnames, count);
else
vim_free(fnames);
! # endif
return TRUE;
}
static int
! test_gui_find_repl(dict_T *args)
! {
! int flags;
! char_u *find_text;
! char_u *repl_text;
! int forward;
! int retval;
!
! if (dict_find(args, (char_u *)"find_text", -1) == NULL
! || dict_find(args, (char_u *)"repl_text", -1) == NULL
! || dict_find(args, (char_u *)"flags", -1) == NULL
! || dict_find(args, (char_u *)"forward", -1) == NULL)
! return FALSE;
!
! find_text = dict_get_string(args, (char_u *)"find_text", TRUE);
! repl_text = dict_get_string(args, (char_u *)"repl_text", TRUE);
! flags = (int)dict_get_number(args, (char_u *)"flags");
! forward = (int)dict_get_number(args, (char_u *)"forward");
!
! retval = gui_do_findrepl(flags, find_text, repl_text, forward);
! vim_free(find_text);
! vim_free(repl_text);
!
! return retval;
! }
!
! static int
! test_gui_mouse_event(dict_T *args)
{
int button;
int row;
***************
*** 1405,1411 ****
static int
test_gui_tabline_event(dict_T *args UNUSED)
{
! # ifdef FEAT_GUI_TABLINE
int tabnr;
if (dict_find(args, (char_u *)"tabnr", -1) == NULL)
--- 1432,1438 ----
static int
test_gui_tabline_event(dict_T *args UNUSED)
{
! # ifdef FEAT_GUI_TABLINE
int tabnr;
if (dict_find(args, (char_u *)"tabnr", -1) == NULL)
***************
*** 1414,1428 ****
tabnr = (int)dict_get_number(args, (char_u *)"tabnr");
return send_tabline_event(tabnr);
! # else
return FALSE;
! # endif
}
static int
test_gui_tabmenu_event(dict_T *args UNUSED)
{
! # ifdef FEAT_GUI_TABLINE
int tabnr;
int item;
--- 1441,1455 ----
tabnr = (int)dict_get_number(args, (char_u *)"tabnr");
return send_tabline_event(tabnr);
! # else
return FALSE;
! # endif
}
static int
test_gui_tabmenu_event(dict_T *args UNUSED)
{
! # ifdef FEAT_GUI_TABLINE
int tabnr;
int item;
***************
*** 1434,1440 ****
item = (int)dict_get_number(args, (char_u *)"item");
send_tabline_menu_event(tabnr, item);
! # endif
return TRUE;
}
# endif
--- 1461,1467 ----
item = (int)dict_get_number(args, (char_u *)"item");
send_tabline_menu_event(tabnr, item);
! # endif
return TRUE;
}
# endif
***************
*** 1456,1461 ****
--- 1483,1490 ----
event = tv_get_string(&argvars[0]);
if (STRCMP(event, "dropfiles") == 0)
rettv->vval.v_number = test_gui_drop_files(argvars[1].vval.v_dict);
+ else if (STRCMP(event, "findrepl") == 0)
+ 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, "tabline") == 0)
*** ../vim-8.2.4262/src/version.c 2022-01-30 17:17:38.437273118 +0000
--- src/version.c 2022-01-30 17:50:07.811991688 +0000
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 4263,
/**/
--
"The future's already arrived - it's just not evenly distributed yet."
-- William Gibson
/// Bram Moolenaar -- Br...@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 ///