Mercurial > vim
changeset 24998:3b1770226f85 v8.2.3036
patch 8.2.3036: Vim9: builtin function arguments not checked at compile time
Commit: https://github.com/vim/vim/commit/7237cab8f1d1a4391372cafdb57f2d97f3b32d05
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Tue Jun 22 19:52:27 2021 +0200
patch 8.2.3036: Vim9: builtin function arguments not checked at compile time
Problem: Vim9: builtin function arguments not checked at compile time.
Solution: Add more argument type specs. Check arguments to test_setmouse()
and test_gui_mouse_event(). (Yegappan Lakshmanan, closes #8425)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 22 Jun 2021 20:00:05 +0200 |
parents | 6cd844668030 |
children | 1900b1b14d15 |
files | src/evalfunc.c src/testdir/test_assert.vim src/testdir/test_gui.vim src/testdir/test_popupwin.vim src/testdir/test_vim9_builtin.vim src/testing.c src/version.c |
diffstat | 7 files changed, 400 insertions(+), 72 deletions(-) [+] |
line wrap: on
line diff
--- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -403,12 +403,16 @@ arg_extend3(type_T *type, argcontext_T * * Lists of functions that check the argument types of a builtin function. */ argcheck_T arg1_string[] = {arg_string}; -argcheck_T arg3_string_nr_bool[] = {arg_string, arg_number, arg_bool}; +argcheck_T arg1_number[] = {arg_number}; argcheck_T arg1_float_or_nr[] = {arg_float_or_nr}; +argcheck_T arg2_float_or_nr[] = {arg_float_or_nr, arg_float_or_nr}; +argcheck_T arg2_number[] = {arg_number, arg_number}; argcheck_T arg2_listblob_item[] = {arg_list_or_blob, arg_item_of_prev}; argcheck_T arg2_execute[] = {arg_string_or_list, arg_string}; argcheck_T arg23_extend[] = {arg_list_or_dict, arg_same_as_prev, arg_extend3}; argcheck_T arg23_extendnew[] = {arg_list_or_dict, arg_same_struct_as_prev, arg_extend3}; +argcheck_T arg3_string[] = {arg_string, arg_string, arg_string}; +argcheck_T arg3_string_nr_bool[] = {arg_string, arg_number, arg_bool}; argcheck_T arg3_insert[] = {arg_list_or_blob, arg_item_of_prev, arg_number}; /* @@ -670,25 +674,25 @@ static funcentry_T global_functions[] = { {"abs", 1, 1, FEARG_1, arg1_float_or_nr, ret_any, FLOAT_FUNC(f_abs)}, - {"acos", 1, 1, FEARG_1, NULL, + {"acos", 1, 1, FEARG_1, arg1_float_or_nr, ret_float, FLOAT_FUNC(f_acos)}, {"add", 2, 2, FEARG_1, NULL /* arg2_listblob_item */, ret_first_arg, f_add}, - {"and", 2, 2, FEARG_1, NULL, + {"and", 2, 2, FEARG_1, arg2_number, ret_number, f_and}, {"append", 2, 2, FEARG_2, NULL, ret_number_bool, f_append}, {"appendbufline", 3, 3, FEARG_3, NULL, ret_number_bool, f_appendbufline}, - {"argc", 0, 1, 0, NULL, + {"argc", 0, 1, 0, arg1_number, ret_number, f_argc}, {"argidx", 0, 0, 0, NULL, ret_number, f_argidx}, - {"arglistid", 0, 2, 0, NULL, + {"arglistid", 0, 2, 0, arg2_number, ret_number, f_arglistid}, - {"argv", 0, 2, 0, NULL, + {"argv", 0, 2, 0, arg2_number, ret_argv, f_argv}, - {"asin", 1, 1, FEARG_1, NULL, + {"asin", 1, 1, FEARG_1, arg1_float_or_nr, ret_float, FLOAT_FUNC(f_asin)}, {"assert_beeps", 1, 2, FEARG_1, NULL, ret_number_bool, f_assert_beeps}, @@ -716,9 +720,9 @@ static funcentry_T global_functions[] = ret_number_bool, f_assert_report}, {"assert_true", 1, 2, FEARG_1, NULL, ret_number_bool, f_assert_true}, - {"atan", 1, 1, FEARG_1, NULL, + {"atan", 1, 1, FEARG_1, arg1_float_or_nr, ret_float, FLOAT_FUNC(f_atan)}, - {"atan2", 2, 2, FEARG_1, NULL, + {"atan2", 2, 2, FEARG_1, arg2_float_or_nr, ret_float, FLOAT_FUNC(f_atan2)}, {"balloon_gettext", 0, 0, 0, NULL, ret_string, @@ -780,7 +784,7 @@ static funcentry_T global_functions[] = ret_number, f_byteidxcomp}, {"call", 2, 3, FEARG_1, NULL, ret_any, f_call}, - {"ceil", 1, 1, FEARG_1, NULL, + {"ceil", 1, 1, FEARG_1, arg1_float_or_nr, ret_float, FLOAT_FUNC(f_ceil)}, {"ch_canread", 1, 1, FEARG_1, NULL, ret_number_bool, JOB_FUNC(f_ch_canread)}, @@ -832,7 +836,7 @@ static funcentry_T global_functions[] = ret_string, f_chdir}, {"cindent", 1, 1, FEARG_1, NULL, ret_number, f_cindent}, - {"clearmatches", 0, 1, FEARG_1, NULL, + {"clearmatches", 0, 1, FEARG_1, arg1_number, ret_void, f_clearmatches}, {"col", 1, 1, FEARG_1, NULL, ret_number, f_col}, @@ -848,9 +852,9 @@ static funcentry_T global_functions[] = ret_number, f_confirm}, {"copy", 1, 1, FEARG_1, NULL, ret_first_arg, f_copy}, - {"cos", 1, 1, FEARG_1, NULL, + {"cos", 1, 1, FEARG_1, arg1_float_or_nr, ret_float, FLOAT_FUNC(f_cos)}, - {"cosh", 1, 1, FEARG_1, NULL, + {"cosh", 1, 1, FEARG_1, arg1_float_or_nr, ret_float, FLOAT_FUNC(f_cosh)}, {"count", 2, 4, FEARG_1, NULL, ret_number, f_count}, @@ -858,7 +862,7 @@ static funcentry_T global_functions[] = ret_number, f_cscope_connection}, {"cursor", 1, 3, FEARG_1, NULL, ret_number, f_cursor}, - {"debugbreak", 1, 1, FEARG_1, NULL, + {"debugbreak", 1, 1, FEARG_1, arg1_number, ret_number, #ifdef MSWIN f_debugbreak @@ -898,7 +902,7 @@ static funcentry_T global_functions[] = ret_string, f_exepath}, {"exists", 1, 1, FEARG_1, NULL, ret_number_bool, f_exists}, - {"exp", 1, 1, FEARG_1, NULL, + {"exp", 1, 1, FEARG_1, arg1_float_or_nr, ret_float, FLOAT_FUNC(f_exp)}, {"expand", 1, 3, FEARG_1, NULL, ret_any, f_expand}, @@ -926,11 +930,11 @@ static funcentry_T global_functions[] = ret_list_any, f_flatten}, {"flattennew", 1, 2, FEARG_1, NULL, ret_list_any, f_flattennew}, - {"float2nr", 1, 1, FEARG_1, NULL, + {"float2nr", 1, 1, FEARG_1, arg1_float_or_nr, ret_number, FLOAT_FUNC(f_float2nr)}, - {"floor", 1, 1, FEARG_1, NULL, + {"floor", 1, 1, FEARG_1, arg1_float_or_nr, ret_float, FLOAT_FUNC(f_floor)}, - {"fmod", 2, 2, FEARG_1, NULL, + {"fmod", 2, 2, FEARG_1, arg2_float_or_nr, ret_float, FLOAT_FUNC(f_fmod)}, {"fnameescape", 1, 1, FEARG_1, NULL, ret_string, f_fnameescape}, @@ -986,11 +990,11 @@ static funcentry_T global_functions[] = ret_string, f_getcmdwintype}, {"getcompletion", 2, 3, FEARG_1, NULL, ret_list_string, f_getcompletion}, - {"getcurpos", 0, 1, FEARG_1, NULL, + {"getcurpos", 0, 1, FEARG_1, arg1_number, ret_list_number, f_getcurpos}, - {"getcursorcharpos", 0, 1, FEARG_1, NULL, + {"getcursorcharpos", 0, 1, FEARG_1, arg1_number, ret_list_number, f_getcursorcharpos}, - {"getcwd", 0, 2, FEARG_1, NULL, + {"getcwd", 0, 2, FEARG_1, arg2_number, ret_string, f_getcwd}, {"getenv", 1, 1, FEARG_1, NULL, ret_any, f_getenv}, @@ -1006,7 +1010,7 @@ static funcentry_T global_functions[] = ret_string, f_getftype}, {"getimstatus", 0, 0, 0, NULL, ret_number_bool, f_getimstatus}, - {"getjumplist", 0, 2, FEARG_1, NULL, + {"getjumplist", 0, 2, FEARG_1, arg2_number, ret_list_any, f_getjumplist}, {"getline", 1, 2, FEARG_1, NULL, ret_f_getline, f_getline}, @@ -1014,7 +1018,7 @@ static funcentry_T global_functions[] = ret_list_or_dict_1, f_getloclist}, {"getmarklist", 0, 1, FEARG_1, NULL, ret_list_dict_any, f_getmarklist}, - {"getmatches", 0, 1, 0, NULL, + {"getmatches", 0, 1, 0, arg1_number, ret_list_dict_any, f_getmatches}, {"getmousepos", 0, 0, 0, NULL, ret_dict_number, f_getmousepos}, @@ -1030,19 +1034,19 @@ static funcentry_T global_functions[] = ret_dict_any, f_getreginfo}, {"getregtype", 0, 1, FEARG_1, NULL, ret_string, f_getregtype}, - {"gettabinfo", 0, 1, FEARG_1, NULL, + {"gettabinfo", 0, 1, FEARG_1, arg1_number, ret_list_dict_any, f_gettabinfo}, {"gettabvar", 2, 3, FEARG_1, NULL, ret_any, f_gettabvar}, {"gettabwinvar", 3, 4, FEARG_1, NULL, ret_any, f_gettabwinvar}, - {"gettagstack", 0, 1, FEARG_1, NULL, + {"gettagstack", 0, 1, FEARG_1, arg1_number, ret_dict_any, f_gettagstack}, {"gettext", 1, 1, FEARG_1, NULL, ret_string, f_gettext}, - {"getwininfo", 0, 1, FEARG_1, NULL, + {"getwininfo", 0, 1, FEARG_1, arg1_number, ret_list_dict_any, f_getwininfo}, - {"getwinpos", 0, 1, FEARG_1, NULL, + {"getwinpos", 0, 1, FEARG_1, arg1_number, ret_list_number, f_getwinpos}, {"getwinposx", 0, 0, 0, NULL, ret_number, f_getwinposx}, @@ -1060,7 +1064,7 @@ static funcentry_T global_functions[] = ret_number_bool, f_has}, {"has_key", 2, 2, FEARG_1, NULL, ret_number_bool, f_has_key}, - {"haslocaldir", 0, 2, FEARG_1, NULL, + {"haslocaldir", 0, 2, FEARG_1, arg2_number, ret_number, f_haslocaldir}, {"hasmapto", 1, 3, FEARG_1, NULL, ret_number_bool, f_hasmapto}, @@ -1104,15 +1108,15 @@ static funcentry_T global_functions[] = ret_first_arg, f_insert}, {"interrupt", 0, 0, 0, NULL, ret_void, f_interrupt}, - {"invert", 1, 1, FEARG_1, NULL, + {"invert", 1, 1, FEARG_1, arg1_number, ret_number, f_invert}, {"isdirectory", 1, 1, FEARG_1, NULL, ret_number_bool, f_isdirectory}, - {"isinf", 1, 1, FEARG_1, NULL, + {"isinf", 1, 1, FEARG_1, arg1_float_or_nr, ret_number, MATH_FUNC(f_isinf)}, {"islocked", 1, 1, FEARG_1, NULL, ret_number_bool, f_islocked}, - {"isnan", 1, 1, FEARG_1, NULL, + {"isnan", 1, 1, FEARG_1, arg1_float_or_nr, ret_number_bool, MATH_FUNC(f_isnan)}, {"items", 1, 1, FEARG_1, NULL, ret_list_any, f_items}, @@ -1160,13 +1164,13 @@ static funcentry_T global_functions[] = ret_number, f_listener_add}, {"listener_flush", 0, 1, FEARG_1, NULL, ret_void, f_listener_flush}, - {"listener_remove", 1, 1, FEARG_1, NULL, + {"listener_remove", 1, 1, FEARG_1, arg1_number, ret_number_bool, f_listener_remove}, {"localtime", 0, 0, 0, NULL, ret_number, f_localtime}, - {"log", 1, 1, FEARG_1, NULL, + {"log", 1, 1, FEARG_1, arg1_float_or_nr, ret_float, FLOAT_FUNC(f_log)}, - {"log10", 1, 1, FEARG_1, NULL, + {"log10", 1, 1, FEARG_1, arg1_float_or_nr, ret_float, FLOAT_FUNC(f_log10)}, {"luaeval", 1, 2, FEARG_1, NULL, ret_any, @@ -1192,9 +1196,9 @@ static funcentry_T global_functions[] = ret_number, f_matchadd}, {"matchaddpos", 2, 5, FEARG_1, NULL, ret_number, f_matchaddpos}, - {"matcharg", 1, 1, FEARG_1, NULL, + {"matcharg", 1, 1, FEARG_1, arg1_number, ret_list_string, f_matcharg}, - {"matchdelete", 1, 2, FEARG_1, NULL, + {"matchdelete", 1, 2, FEARG_1, arg2_number, ret_number_bool, f_matchdelete}, {"matchend", 2, 4, FEARG_1, NULL, ret_number, f_matchend}, @@ -1236,7 +1240,7 @@ static funcentry_T global_functions[] = ret_number, f_nextnonblank}, {"nr2char", 1, 2, FEARG_1, NULL, ret_string, f_nr2char}, - {"or", 2, 2, FEARG_1, NULL, + {"or", 2, 2, FEARG_1, arg2_number, ret_number, f_or}, {"pathshorten", 1, 2, FEARG_1, NULL, ret_string, f_pathshorten}, @@ -1290,7 +1294,7 @@ static funcentry_T global_functions[] = ret_void, PROP_FUNC(f_popup_settext)}, {"popup_show", 1, 1, FEARG_1, NULL, ret_void, PROP_FUNC(f_popup_show)}, - {"pow", 2, 2, FEARG_1, NULL, + {"pow", 2, 2, FEARG_1, arg2_float_or_nr, ret_float, FLOAT_FUNC(f_pow)}, {"prevnonblank", 1, 1, FEARG_1, NULL, ret_number, f_prevnonblank}, @@ -1398,7 +1402,7 @@ static funcentry_T global_functions[] = ret_string, f_resolve}, {"reverse", 1, 1, FEARG_1, NULL, ret_first_arg, f_reverse}, - {"round", 1, 1, FEARG_1, NULL, + {"round", 1, 1, FEARG_1, arg1_float_or_nr, ret_float, FLOAT_FUNC(f_round)}, {"rubyeval", 1, 1, FEARG_1, NULL, ret_any, @@ -1408,11 +1412,11 @@ static funcentry_T global_functions[] = NULL #endif }, - {"screenattr", 2, 2, FEARG_1, NULL, + {"screenattr", 2, 2, FEARG_1, arg2_number, ret_number, f_screenattr}, - {"screenchar", 2, 2, FEARG_1, NULL, + {"screenchar", 2, 2, FEARG_1, arg2_number, ret_number, f_screenchar}, - {"screenchars", 2, 2, FEARG_1, NULL, + {"screenchars", 2, 2, FEARG_1, arg2_number, ret_list_number, f_screenchars}, {"screencol", 0, 0, 0, NULL, ret_number, f_screencol}, @@ -1420,7 +1424,7 @@ static funcentry_T global_functions[] = ret_dict_number, f_screenpos}, {"screenrow", 0, 0, 0, NULL, ret_number, f_screenrow}, - {"screenstring", 2, 2, FEARG_1, NULL, + {"screenstring", 2, 2, FEARG_1, arg2_number, ret_string, f_screenstring}, {"search", 1, 5, FEARG_1, NULL, ret_number, f_search}, @@ -1448,7 +1452,7 @@ static funcentry_T global_functions[] = ret_number_bool, f_setcharpos}, {"setcharsearch", 1, 1, FEARG_1, NULL, ret_void, f_setcharsearch}, - {"setcmdpos", 1, 1, FEARG_1, NULL, + {"setcmdpos", 1, 1, FEARG_1, arg1_number, ret_number_bool, f_setcmdpos}, {"setcursorcharpos", 1, 3, FEARG_1, NULL, ret_number_bool, f_setcursorcharpos}, @@ -1486,7 +1490,7 @@ static funcentry_T global_functions[] = }, {"shellescape", 1, 2, FEARG_1, NULL, ret_string, f_shellescape}, - {"shiftwidth", 0, 1, FEARG_1, NULL, + {"shiftwidth", 0, 1, FEARG_1, arg1_number, ret_number, f_shiftwidth}, {"sign_define", 1, 2, FEARG_1, NULL, ret_any, SIGN_FUNC(f_sign_define)}, @@ -1508,9 +1512,9 @@ static funcentry_T global_functions[] = ret_list_number, SIGN_FUNC(f_sign_unplacelist)}, {"simplify", 1, 1, FEARG_1, NULL, ret_string, f_simplify}, - {"sin", 1, 1, FEARG_1, NULL, + {"sin", 1, 1, FEARG_1, arg1_float_or_nr, ret_float, FLOAT_FUNC(f_sin)}, - {"sinh", 1, 1, FEARG_1, NULL, + {"sinh", 1, 1, FEARG_1, arg1_float_or_nr, ret_float, FLOAT_FUNC(f_sinh)}, {"slice", 2, 3, FEARG_1, NULL, ret_first_arg, f_slice}, @@ -1532,7 +1536,7 @@ static funcentry_T global_functions[] = ret_list_string, f_spellsuggest}, {"split", 1, 3, FEARG_1, NULL, ret_list_string, f_split}, - {"sqrt", 1, 1, FEARG_1, NULL, + {"sqrt", 1, 1, FEARG_1, arg1_float_or_nr, ret_float, FLOAT_FUNC(f_sqrt)}, {"srand", 0, 1, FEARG_1, NULL, ret_list_number, f_srand}, @@ -1616,9 +1620,9 @@ static funcentry_T global_functions[] = ret_list_string, f_tagfiles}, {"taglist", 1, 2, FEARG_1, NULL, ret_list_dict_any, f_taglist}, - {"tan", 1, 1, FEARG_1, NULL, + {"tan", 1, 1, FEARG_1, arg1_float_or_nr, ret_float, FLOAT_FUNC(f_tan)}, - {"tanh", 1, 1, FEARG_1, NULL, + {"tanh", 1, 1, FEARG_1, arg1_float_or_nr, ret_float, FLOAT_FUNC(f_tanh)}, {"tempname", 0, 0, 0, NULL, ret_string, f_tempname}, @@ -1750,15 +1754,15 @@ static funcentry_T global_functions[] = ret_void, TIMER_FUNC(f_timer_stop)}, {"timer_stopall", 0, 0, 0, NULL, ret_void, TIMER_FUNC(f_timer_stopall)}, - {"tolower", 1, 1, FEARG_1, NULL, + {"tolower", 1, 1, FEARG_1, arg1_string, ret_string, f_tolower}, - {"toupper", 1, 1, FEARG_1, NULL, + {"toupper", 1, 1, FEARG_1, arg1_string, ret_string, f_toupper}, - {"tr", 3, 3, FEARG_1, NULL, + {"tr", 3, 3, FEARG_1, arg3_string, ret_string, f_tr}, {"trim", 1, 3, FEARG_1, NULL, ret_string, f_trim}, - {"trunc", 1, 1, FEARG_1, NULL, + {"trunc", 1, 1, FEARG_1, arg1_float_or_nr, ret_float, FLOAT_FUNC(f_trunc)}, {"type", 1, 1, FEARG_1, NULL, ret_number, f_type}, @@ -1784,27 +1788,27 @@ static funcentry_T global_functions[] = ret_list_number, f_win_findbuf}, {"win_getid", 0, 2, FEARG_1, NULL, ret_number, f_win_getid}, - {"win_gettype", 0, 1, FEARG_1, NULL, + {"win_gettype", 0, 1, FEARG_1, arg1_number, ret_string, f_win_gettype}, - {"win_gotoid", 1, 1, FEARG_1, NULL, + {"win_gotoid", 1, 1, FEARG_1, arg1_number, ret_number_bool, f_win_gotoid}, - {"win_id2tabwin", 1, 1, FEARG_1, NULL, + {"win_id2tabwin", 1, 1, FEARG_1, arg1_number, ret_list_number, f_win_id2tabwin}, - {"win_id2win", 1, 1, FEARG_1, NULL, + {"win_id2win", 1, 1, FEARG_1, arg1_number, ret_number, f_win_id2win}, - {"win_screenpos", 1, 1, FEARG_1, NULL, + {"win_screenpos", 1, 1, FEARG_1, arg1_number, ret_list_number, f_win_screenpos}, {"win_splitmove", 2, 3, FEARG_1, NULL, ret_number_bool, f_win_splitmove}, - {"winbufnr", 1, 1, FEARG_1, NULL, + {"winbufnr", 1, 1, FEARG_1, arg1_number, ret_number, f_winbufnr}, {"wincol", 0, 0, 0, NULL, ret_number, f_wincol}, {"windowsversion", 0, 0, 0, NULL, ret_string, f_windowsversion}, - {"winheight", 1, 1, FEARG_1, NULL, + {"winheight", 1, 1, FEARG_1, arg1_number, ret_number, f_winheight}, - {"winlayout", 0, 1, FEARG_1, NULL, + {"winlayout", 0, 1, FEARG_1, arg1_number, ret_list_any, f_winlayout}, {"winline", 0, 0, 0, NULL, ret_number, f_winline}, @@ -1816,13 +1820,13 @@ static funcentry_T global_functions[] = ret_void, f_winrestview}, {"winsaveview", 0, 0, 0, NULL, ret_dict_number, f_winsaveview}, - {"winwidth", 1, 1, FEARG_1, NULL, + {"winwidth", 1, 1, FEARG_1, arg1_number, ret_number, f_winwidth}, {"wordcount", 0, 0, 0, NULL, ret_dict_number, f_wordcount}, {"writefile", 2, 3, FEARG_1, NULL, ret_number_bool, f_writefile}, - {"xor", 2, 2, FEARG_1, NULL, + {"xor", 2, 2, FEARG_1, arg2_number, ret_number, f_xor}, };
--- a/src/testdir/test_assert.vim +++ b/src/testdir/test_assert.vim @@ -374,6 +374,8 @@ func Test_mouse_position() call test_setmouse(5, 1) call feedkeys("\<LeftMouse>", "xt") call assert_equal([0, 2, 1, 0], getpos('.')) + call assert_fails('call test_setmouse("", 2)', 'E474:') + call assert_fails('call test_setmouse(1, "")', 'E474:') bwipe! let &mouse = save_mouse endfunc
--- a/src/testdir/test_gui.vim +++ b/src/testdir/test_gui.vim @@ -882,7 +882,7 @@ func Test_gui_mouse_event() new call setline(1, ['one two three', 'four five six']) - " place the cursor using left click + " place the cursor using left click in normal mode call cursor(1, 1) call test_gui_mouse_event(0, 2, 4, 0, 0) call test_gui_mouse_event(3, 2, 4, 0, 0) @@ -1092,9 +1092,70 @@ func Test_gui_mouse_event() set mouse& let &guioptions = save_guioptions + " Test invalid parameters for test_gui_mouse_event() + call assert_fails('call test_gui_mouse_event("", 1, 2, 3, 4)', 'E474:') + call assert_fails('call test_gui_mouse_event(0, "", 2, 3, 4)', 'E474:') + call assert_fails('call test_gui_mouse_event(0, 1, "", 3, 4)', 'E474:') + call assert_fails('call test_gui_mouse_event(0, 1, 2, "", 4)', 'E474:') + call assert_fails('call test_gui_mouse_event(0, 1, 2, 3, "")', 'E474:') + bw! call test_override('no_query_mouse', 0) set mousemodel& endfunc +" Test for 'guitablabel' and 'guitabtooltip' options +func TestGuiTabLabel() + call add(g:TabLabels, v:lnum + 100) + let bufnrlist = tabpagebuflist(v:lnum) + return bufname(bufnrlist[tabpagewinnr(v:lnum) - 1]) +endfunc + +func TestGuiTabToolTip() + call add(g:TabToolTips, v:lnum + 200) + let bufnrlist = tabpagebuflist(v:lnum) + return bufname(bufnrlist[tabpagewinnr(v:lnum) - 1]) +endfunc + +func Test_gui_tablabel_tooltip() + %bw! + " Removing the tabline at the end of this test, reduces the window height by + " one. Save and restore it after the test. + let save_lines = &lines + edit one + set modified + tabnew two + set modified + tabnew three + set modified + let g:TabLabels = [] + set guitablabel=%{TestGuiTabLabel()} + call test_override('starting', 1) + redrawtabline + call test_override('starting', 0) + call assert_true(index(g:TabLabels, 101) != -1) + call assert_true(index(g:TabLabels, 102) != -1) + call assert_true(index(g:TabLabels, 103) != -1) + set guitablabel& + unlet g:TabLabels + + if has('gui_gtk') + " Only on GTK+, the tooltip function is called even if the mouse is not + " on the tabline. on Win32 and Motif, the tooltip function is called only + " when the mouse pointer is over the tabline. + let g:TabToolTips = [] + set guitabtooltip=%{TestGuiTabToolTip()} + call test_override('starting', 1) + redrawtabline + call test_override('starting', 0) + call assert_true(index(g:TabToolTips, 201) != -1) + call assert_true(index(g:TabToolTips, 202) != -1) + call assert_true(index(g:TabToolTips, 203) != -1) + set guitabtooltip& + unlet g:TabToolTips + endif + %bw! + let &lines = save_lines +endfunc + " vim: shiftwidth=2 sts=2 expandtab
--- a/src/testdir/test_popupwin.vim +++ b/src/testdir/test_popupwin.vim @@ -1552,8 +1552,8 @@ func Test_popup_filter() call assert_equal(9, getcurpos()[2]) call feedkeys('0', 'xt') call assert_equal('0', g:ignored) - redraw - call assert_equal(1, getcurpos()[2]) + normal! l + call assert_equal(2, getcurpos()[2]) " x closes the popup call feedkeys('x', 'xt')
--- a/src/testdir/test_vim9_builtin.vim +++ b/src/testdir/test_vim9_builtin.vim @@ -141,6 +141,11 @@ def Test_add_blob() CheckScriptSuccess(lines) enddef +def Test_and() + CheckDefFailure(['echo and("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['echo and(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') +enddef + def Test_append() new setline(1, range(3)) @@ -155,6 +160,22 @@ def Test_append() bwipe! enddef +def Test_argc() + CheckDefFailure(['echo argc("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + +def Test_arglistid() + CheckDefFailure(['echo arglistid("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['echo arglistid(1, "y")'], 'E1013: Argument 2: type mismatch, expected number but got string') + CheckDefFailure(['echo arglistid("x", "y")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + +def Test_argv() + CheckDefFailure(['echo argv("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['echo argv(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') + CheckDefFailure(['echo argv("x", "y")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + def Test_balloon_show() CheckGui CheckFeature balloon_eval @@ -256,6 +277,10 @@ def Test_chdir() assert_fails('chdir(true)', 'E1174') enddef +def Test_clearmatches() + CheckDefFailure(['echo clearmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + def Test_col() new setline(1, 'asdf') @@ -311,6 +336,11 @@ def Test_cursor() CheckDefExecAndScriptFailure(lines, 'E475:') enddef +def Test_debugbreak() + CheckMSWindows + CheckDefFailure(['echo debugbreak("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + def Test_delete() var res: bool = delete('doesnotexist') assert_equal(true, res) @@ -532,6 +562,64 @@ def Test_flattennew() CheckDefAndScriptFailure(lines, 'E1158:') enddef +" Test for float functions argument type +def Test_float_funcs_args() + CheckFeature float + + # acos() + CheckDefFailure(['echo acos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + # asin() + CheckDefFailure(['echo asin("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + # atan() + CheckDefFailure(['echo atan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + # atan2() + CheckDefFailure(['echo atan2("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['echo atan2(1.2, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string') + CheckDefFailure(['echo atan2(1.2)'], 'E119:') + # ceil() + CheckDefFailure(['echo ceil("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + # cos() + CheckDefFailure(['echo cos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + # cosh() + CheckDefFailure(['echo cosh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + # exp() + CheckDefFailure(['echo exp("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + # float2nr() + CheckDefFailure(['echo float2nr("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + # floor() + CheckDefFailure(['echo floor("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + # fmod() + CheckDefFailure(['echo fmod(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string') + CheckDefFailure(['echo fmod("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['echo fmod(1.1)'], 'E119:') + # isinf() + CheckDefFailure(['echo isinf("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + # isnan() + CheckDefFailure(['echo isnan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + # log() + CheckDefFailure(['echo log("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + # log10() + CheckDefFailure(['echo log10("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + # pow() + CheckDefFailure(['echo pow("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['echo pow(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string') + CheckDefFailure(['echo pow(1.1)'], 'E119:') + # round() + CheckDefFailure(['echo round("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + # sin() + CheckDefFailure(['echo sin("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + # sinh() + CheckDefFailure(['echo sinh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + # sqrt() + CheckDefFailure(['echo sqrt("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + # tan() + CheckDefFailure(['echo tan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + # tanh() + CheckDefFailure(['echo tanh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + # trunc() + CheckDefFailure(['echo trunc("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + def Test_fnamemodify() CheckDefSuccess(['echo fnamemodify(test_null_string(), ":p")']) CheckDefSuccess(['echo fnamemodify("", ":p")']) @@ -652,6 +740,20 @@ def Test_getcompletion() set wildignore& enddef +def Test_getcurpos() + CheckDefFailure(['echo getcursorcharpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + +def Test_getcursorcharpos() + CheckDefFailure(['echo getcursorcharpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + +def Test_getcwd() + CheckDefFailure(['echo getcwd("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['echo getcwd("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['echo getcwd(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') +enddef + def Test_getloclist_return_type() var l = getloclist(1) l->assert_equal([]) @@ -692,6 +794,16 @@ def Test_getftype() CheckDefExecFailure(['echo getftype(v:null)'], 'E1174:') enddef +def Test_getjumplist() + CheckDefFailure(['echo getjumplist("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['echo getjumplist("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['echo getjumplist(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') +enddef + +def Test_getmatches() + CheckDefFailure(['echo getmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + def Test_getqflist_return_type() var l = getqflist() l->assert_equal([]) @@ -727,6 +839,22 @@ def Test_getregtype() assert_fails('getregtype("ab")', 'E1162:') enddef +def Test_gettabinfo() + CheckDefFailure(['echo gettabinfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + +def Test_gettagstack() + CheckDefFailure(['echo gettagstack("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + +def Test_getwininfo() + CheckDefFailure(['echo getwininfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + +def Test_getwinpos() + CheckDefFailure(['echo getwinpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + def Test_glob() glob('runtest.vim', true, true, true)->assert_equal(['runtest.vim']) enddef @@ -739,6 +867,12 @@ def Test_has() has('eval', true)->assert_equal(1) enddef +def Test_haslocaldir() + CheckDefFailure(['echo haslocaldir("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['echo haslocaldir("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['echo haslocaldir(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') +enddef + def Test_hasmapto() hasmapto('foobar', 'i', true)->assert_equal(0) iabbrev foo foobar @@ -790,6 +924,10 @@ def Test_insert() CheckDefFailure(['insert([2, 3], 1, "x")'], 'E1013: Argument 3: type mismatch, expected number but got string', 1) enddef +def Test_invert() + CheckDefFailure(['echo invert("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + def Test_keys_return_type() const var: list<string> = {a: 1, b: 2}->keys() var->assert_equal(['a', 'b']) @@ -812,6 +950,10 @@ def SID(): number ->str2nr() enddef +def Test_listener_remove() + CheckDefFailure(['echo listener_remove("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + def Test_map_function_arg() var lines =<< trim END def MapOne(i: number, v: string): string @@ -914,6 +1056,16 @@ def Test_map_failure() delete('Xtmpfile') enddef +def Test_matcharg() + CheckDefFailure(['echo matcharg("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + +def Test_matchdelete() + CheckDefFailure(['echo matchdelete("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['echo matchdelete("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['echo matchdelete(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') +enddef + def Test_max() g:flag = true var l1: list<number> = g:flag @@ -946,6 +1098,11 @@ def Test_nr2char() nr2char(97, true)->assert_equal('a') enddef +def Test_or() + CheckDefFailure(['echo or("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['echo or(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') +enddef + def Test_readdir() eval expand('sautest')->readdir((e) => e[0] !=# '.') eval expand('sautest')->readdirex((e) => e.name[0] !=# '.') @@ -995,6 +1152,26 @@ def Test_reverse_return_type() res->assert_equal(6) enddef +def Test_screenattr() + CheckDefFailure(['echo screenattr("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['echo screenattr(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') +enddef + +def Test_screenchar() + CheckDefFailure(['echo screenchar("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['echo screenchar(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') +enddef + +def Test_screenchars() + CheckDefFailure(['echo screenchars("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['echo screenchars(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') +enddef + +def Test_screenstring() + CheckDefFailure(['echo screenstring("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['echo screenstring(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') +enddef + def Test_search() new setline(1, ['foo', 'bar']) @@ -1157,6 +1334,10 @@ def Test_setbufvar() getbufvar('%', 'myvar')->assert_equal(123) enddef +def Test_setcmdpos() + CheckDefFailure(['echo setcmdpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + def Test_setloclist() var items = [{filename: '/tmp/file', lnum: 1, valid: true}] var what = {items: items} @@ -1172,6 +1353,10 @@ def Test_setreg() assert_fails('setreg("ab", 0)', 'E1162:') enddef +def Test_shiftwidth() + CheckDefFailure(['echo shiftwidth("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + def Test_slice() assert_equal('12345', slice('012345', 1)) assert_equal('123', slice('012345', 1, 4)) @@ -1309,6 +1494,20 @@ def Test_timer_paused() timer_stop(id) enddef +def Test_tolower() + CheckDefFailure(['echo tolower(1)'], 'E1013: Argument 1: type mismatch, expected string but got number') +enddef + +def Test_toupper() + CheckDefFailure(['echo toupper(1)'], 'E1013: Argument 1: type mismatch, expected string but got number') +enddef + +def Test_tr() + CheckDefFailure(['echo tr(1, "a", "b")'], 'E1013: Argument 1: type mismatch, expected string but got number') + CheckDefFailure(['echo tr("a", 1, "b")'], 'E1013: Argument 2: type mismatch, expected string but got number') + CheckDefFailure(['echo tr("a", "a", 1)'], 'E1013: Argument 3: type mismatch, expected string but got number') +enddef + def Test_win_execute() assert_equal("\n" .. winnr(), win_execute(win_getid(), 'echo winnr()')) assert_equal('', win_execute(342343, 'echo winnr()')) @@ -1338,7 +1537,45 @@ def Test_winsaveview() CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<number> but got dict<number>', 1) enddef +def Test_win_gettype() + CheckDefFailure(['echo win_gettype("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef +def Test_win_gotoid() + CheckDefFailure(['echo win_gotoid("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef +def Test_win_id2tabwin() + CheckDefFailure(['echo win_id2tabwin("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + +def Test_win_id2win() + CheckDefFailure(['echo win_id2win("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + +def Test_win_screenpos() + CheckDefFailure(['echo win_screenpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + +def Test_winbufnr() + CheckDefFailure(['echo winbufnr("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + +def Test_winheight() + CheckDefFailure(['echo winheight("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + +def Test_winlayout() + CheckDefFailure(['echo winlayout("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + +def Test_winwidth() + CheckDefFailure(['echo winwidth("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + +def Test_xor() + CheckDefFailure(['echo xor("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['echo xor(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') +enddef " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
--- a/src/testing.c +++ b/src/testing.c @@ -1211,6 +1211,12 @@ f_test_scrollbar(typval_T *argvars, typv void f_test_setmouse(typval_T *argvars, typval_T *rettv UNUSED) { + if (argvars[0].v_type != VAR_NUMBER || (argvars[1].v_type) != VAR_NUMBER) + { + emsg(_(e_invarg)); + return; + } + mouse_row = (time_t)tv_get_number(&argvars[0]) - 1; mouse_col = (time_t)tv_get_number(&argvars[1]) - 1; } @@ -1219,11 +1225,27 @@ f_test_setmouse(typval_T *argvars, typva 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]); + int button; + int row; + int col; + int repeated_click; + int_u mods; + + if (argvars[0].v_type != VAR_NUMBER + || (argvars[1].v_type) != VAR_NUMBER + || (argvars[2].v_type) != VAR_NUMBER + || (argvars[3].v_type) != VAR_NUMBER + || (argvars[4].v_type) != VAR_NUMBER) + { + emsg(_(e_invarg)); + return; + } + + button = tv_get_number(&argvars[0]); + row = tv_get_number(&argvars[1]); + col = tv_get_number(&argvars[2]); + repeated_click = tv_get_number(&argvars[3]); + mods = tv_get_number(&argvars[4]); gui_send_mouse_event(button, TEXT_X(col - 1), TEXT_Y(row - 1), repeated_click, mods); #endif