Compare commits

...

3 Commits

Author SHA1 Message Date
Bram Moolenaar
6a05807092 patch 8.2.4265: autoload tests fails
Problem:    Autoload tests fails.
Solution:   Use export instead of name with #.
2022-01-30 18:56:35 +00:00
Bram Moolenaar
d8fe6d34bb patch 8.2.4264: Vim9: can use old style autoload function name
Problem:    Vim9: can use old style autoload function name.
Solution:   Give an error for old style autoload function name.
2022-01-30 18:40:44 +00:00
Yegappan Lakshmanan
ec3637cbaf patch 8.2.4263: no test for the GUI find/replace dialog
Problem:    No test for the GUI find/replace dialog.
Solution:   Add a test function and a test. (Yegappan Lakshmanan,
            closes #9662)
2022-01-30 18:01:24 +00:00
12 changed files with 183 additions and 60 deletions

View File

@@ -85,10 +85,12 @@ test_getvalue({name}) *test_getvalue()*
*test_gui_event()*
test_gui_event({event}, {args})
Generate a GUI {event} with arguments {args} for testing Vim
functionality.
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.
@@ -107,12 +109,27 @@ test_gui_event({event}, {args})
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.
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. This function only works
when the GUI is running. The supported items in {args} are:
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

View File

@@ -3218,8 +3218,8 @@ EXTERN char e_cannot_import_dot_vim_without_using_as[]
INIT(= N_("E1261: Cannot import .vim without using \"as\""));
EXTERN char e_cannot_import_same_script_twice_str[]
INIT(= N_("E1262: Cannot import the same script twice: %s"));
EXTERN char e_using_autoload_name_in_non_autoload_script_str[]
INIT(= N_("E1263: Using autoload name in a non-autoload script: %s"));
EXTERN char e_cannot_use_name_with_hash_in_vim9_script_use_export_instead[]
INIT(= N_("E1263: cannot use name with # in Vim9 script, use export instead"));
EXTERN char e_autoload_import_cannot_use_absolute_or_relative_path[]
INIT(= N_("E1264: Autoload import cannot use absolute or relative path: %s"));
EXTERN char e_cannot_use_partial_here[]

View File

@@ -1,9 +1,9 @@
vim9script
func auto9#getsome()
export func Getsome()
return 'some'
endfunc
def auto9#add42(count: number): number
export def Add42(count: number): number
return count + 42
enddef

View File

@@ -22,8 +22,8 @@ func Test_source_autoload()
endfunc
func Test_autoload_vim9script()
call assert_equal('some', auto9#getsome())
call assert_equal(49, auto9#add42(7))
call assert_equal('some', auto9#Getsome())
call assert_equal(49, auto9#Add42(7))
endfunc

View File

@@ -1255,10 +1255,6 @@ endfunc
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}
@@ -1345,6 +1341,15 @@ func Test_gui_drop_files()
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,6 +1372,10 @@ func Test_gui_tabline_event()
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,7 +1406,61 @@ func Test_gui_tabmenu_event()
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

View File

@@ -148,7 +148,7 @@ func Test_omni_autoload()
let lines =<< trim END
vim9script
def omni#func(findstart: bool, base: string): any
export def Func(findstart: bool, base: string): any
if findstart
return 1
else
@@ -162,7 +162,7 @@ func Test_omni_autoload()
call writefile(lines, dir .. '/omni.vim')
new
setlocal omnifunc=omni#func
setlocal omnifunc=omni#Func
call feedkeys("i\<C-X>\<C-O>\<Esc>", 'xt')
bwipe!

View File

@@ -46,7 +46,7 @@ def TestCompilingErrorInTry()
var lines =<< trim END
vim9script
def script#OnlyCompiled()
export def OnlyCompiled()
g:runtime = 'yes'
invalid
enddef
@@ -114,7 +114,7 @@ def Test_autoload_name_mismatch()
var lines =<< trim END
vim9script
def scriptX#Function()
export def NoFunction()
# comment
g:runtime = 'yes'
enddef
@@ -126,7 +126,7 @@ def Test_autoload_name_mismatch()
lines =<< trim END
call script#Function()
END
v9.CheckScriptFailure(lines, 'E746:', 2)
v9.CheckScriptFailure(lines, 'E117:', 1)
&rtp = save_rtp
delete(dir, 'rf')

View File

@@ -1614,13 +1614,13 @@ enddef
def Test_vim9_autoload_full_name()
var lines =<< trim END
vim9script
def some#gettest(): string
export def Gettest(): string
return 'test'
enddef
g:some#name = 'name'
g:some#dict = {key: 'value'}
def some#varargs(a1: string, ...l: list<string>): string
export def Varargs(a1: string, ...l: list<string>): string
return a1 .. l[0] .. l[1]
enddef
END
@@ -1630,23 +1630,23 @@ def Test_vim9_autoload_full_name()
var save_rtp = &rtp
exe 'set rtp^=' .. getcwd() .. '/Xdir'
assert_equal('test', g:some#gettest())
assert_equal('test', g:some#Gettest())
assert_equal('name', g:some#name)
assert_equal('value', g:some#dict.key)
g:some#other = 'other'
assert_equal('other', g:some#other)
assert_equal('abc', some#varargs('a', 'b', 'c'))
assert_equal('abc', some#Varargs('a', 'b', 'c'))
# upper case script name works
lines =<< trim END
vim9script
def Other#getOther(): string
export def GetOther(): string
return 'other'
enddef
END
writefile(lines, 'Xdir/autoload/Other.vim')
assert_equal('other', g:Other#getOther())
assert_equal('other', g:Other#GetOther())
delete('Xdir', 'rf')
&rtp = save_rtp
@@ -2020,14 +2020,23 @@ enddef
def Test_autoload_name_wrong()
var lines =<< trim END
vim9script
def Xscriptname#Func()
enddef
END
writefile(lines, 'Xscriptname.vim')
v9.CheckScriptFailure(lines, 'E1263:')
v9.CheckScriptFailure(lines, 'E746:')
delete('Xscriptname.vim')
mkdir('Xdir/autoload', 'p')
lines =<< trim END
vim9script
def somescript#Func()
enddef
END
writefile(lines, 'Xdir/autoload/somescript.vim')
assert_fails('source Xdir/autoload/somescript.vim', 'E1263:')
delete('Xdir', 'rf')
enddef
def Test_import_autoload_postponed()
@@ -2202,7 +2211,7 @@ def Test_vim9_autoload_disass()
var lines =<< trim END
vim9script
def debugit#test(): string
export def Test(): string
return 'debug'
enddef
END
@@ -2210,7 +2219,7 @@ def Test_vim9_autoload_disass()
lines =<< trim END
vim9script
def profileit#test(): string
export def Test(): string
return 'profile'
enddef
END
@@ -2218,10 +2227,10 @@ def Test_vim9_autoload_disass()
lines =<< trim END
vim9script
assert_equal('debug', debugit#test())
disass debugit#test
assert_equal('profile', profileit#test())
disass profileit#test
assert_equal('debug', debugit#Test())
disass debugit#Test
assert_equal('profile', profileit#Test())
disass profileit#Test
END
v9.CheckScriptSuccess(lines)
@@ -2233,7 +2242,7 @@ enddef
def Test_vim9_aucmd_autoload()
var lines =<< trim END
vim9script
def foo#test()
export def Test()
echomsg getreg('"')
enddef
END
@@ -2243,7 +2252,7 @@ def Test_vim9_aucmd_autoload()
var save_rtp = &rtp
exe 'set rtp^=' .. getcwd() .. '/Xdir'
augroup test
autocmd TextYankPost * call foo#test()
autocmd TextYankPost * call foo#Test()
augroup END
normal Y

View File

@@ -3078,7 +3078,7 @@ def Test_error_in_autoload_script()
var lines =<< trim END
vim9script noclear
def script#autoloaded()
export def Autoloaded()
enddef
def Broken()
var x: any = ''
@@ -3091,7 +3091,7 @@ def Test_error_in_autoload_script()
lines =<< trim END
vim9script
def CallAutoloaded()
script#autoloaded()
script#Autoloaded()
enddef
function Legacy()
@@ -3196,7 +3196,7 @@ func Test_no_redraw_when_restoring_cpo()
let lines =<< trim END
vim9script
def script#func()
export def Func()
enddef
END
call mkdir('Xdir/autoload', 'p')
@@ -3206,7 +3206,7 @@ func Test_no_redraw_when_restoring_cpo()
vim9script
set cpo+=M
exe 'set rtp^=' .. getcwd() .. '/Xdir'
au CmdlineEnter : ++once timer_start(0, (_) => script#func())
au CmdlineEnter : ++once timer_start(0, (_) => script#Func())
setline(1, 'some text')
END
call writefile(lines, 'XTest_redraw_cpo')

View File

@@ -1319,7 +1319,7 @@ f_test_setmouse(typval_T *argvars, typval_T *rettv UNUSED)
static int
test_gui_drop_files(dict_T *args UNUSED)
{
#if defined(HAVE_DROP_FILE)
# if defined(HAVE_DROP_FILE)
int row;
int col;
int_u mods;
@@ -1335,16 +1335,15 @@ test_gui_drop_files(dict_T *args UNUSED)
|| dict_find(args, (char_u *)"modifiers", -1) == NULL)
return FALSE;
if (dict_get_tv(args, (char_u *)"files", &t) == FAIL)
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");
l = t.vval.v_list;
if (list_len(l) == 0)
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,7 +1351,8 @@ test_gui_drop_files(dict_T *args UNUSED)
FOR_ALL_LIST_ITEMS(l, li)
{
// ignore non-string items
if (li->li_tv.v_type != VAR_STRING)
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,13 +1370,40 @@ test_gui_drop_files(dict_T *args UNUSED)
gui_handle_drop(TEXT_X(col - 1), TEXT_Y(row - 1), mods, fnames, count);
else
vim_free(fnames);
# endif
# endif
return TRUE;
}
static int
test_gui_mouse_event(dict_T *args UNUSED)
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,7 +1432,7 @@ test_gui_mouse_event(dict_T *args UNUSED)
static int
test_gui_tabline_event(dict_T *args UNUSED)
{
# ifdef FEAT_GUI_TABLINE
# ifdef FEAT_GUI_TABLINE
int tabnr;
if (dict_find(args, (char_u *)"tabnr", -1) == NULL)
@@ -1414,15 +1441,15 @@ test_gui_tabline_event(dict_T *args UNUSED)
tabnr = (int)dict_get_number(args, (char_u *)"tabnr");
return send_tabline_event(tabnr);
# else
# else
return FALSE;
# endif
# endif
}
static int
test_gui_tabmenu_event(dict_T *args UNUSED)
{
# ifdef FEAT_GUI_TABLINE
# ifdef FEAT_GUI_TABLINE
int tabnr;
int item;
@@ -1434,7 +1461,7 @@ test_gui_tabmenu_event(dict_T *args UNUSED)
item = (int)dict_get_number(args, (char_u *)"item");
send_tabline_menu_event(tabnr, item);
# endif
# endif
return TRUE;
}
# endif
@@ -1456,6 +1483,8 @@ f_test_gui_event(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
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)

View File

@@ -4232,6 +4232,11 @@ define_function(exarg_T *eap, char_u *name_arg, garray_T *lines_to_free)
name = prefixed;
}
}
else if (vim9script && vim_strchr(name, AUTOLOAD_CHAR) != NULL)
{
emsg(_(e_cannot_use_name_with_hash_in_vim9_script_use_export_instead));
goto ret_free;
}
}
// An error in a function call during evaluation of an expression in magic
@@ -4540,12 +4545,6 @@ define_function(exarg_T *eap, char_u *name_arg, garray_T *lines_to_free)
}
}
}
else if (vim9script && vim_strchr(name, AUTOLOAD_CHAR) != NULL)
{
semsg(_(e_using_autoload_name_in_non_autoload_script_str),
name);
goto erret;
}
}
if (var_conflict)
{

View File

@@ -750,6 +750,12 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
4265,
/**/
4264,
/**/
4263,
/**/
4262,
/**/