diff options
Diffstat (limited to 'src/testdir/test_vim9_builtin.vim')
-rw-r--r-- | src/testdir/test_vim9_builtin.vim | 524 |
1 files changed, 421 insertions, 103 deletions
diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim index 5964ded70c..6b6278b8d0 100644 --- a/src/testdir/test_vim9_builtin.vim +++ b/src/testdir/test_vim9_builtin.vim @@ -156,8 +156,8 @@ def Test_add_blob() 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') + CheckDefAndScriptFailure2(['and("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') + CheckDefAndScriptFailure2(['and(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1030: Using a String as a Number') enddef def Test_append() @@ -175,19 +175,42 @@ def Test_append() enddef def Test_argc() - CheckDefFailure(['echo argc("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['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') + CheckDefFailure(['arglistid("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['arglistid(1, "y")'], 'E1013: Argument 2: type mismatch, expected number but got string') + CheckDefFailure(['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') + CheckDefFailure(['argv("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['argv(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') + CheckDefFailure(['argv("x", "y")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + +def Test_assert_equalfile() + CheckDefFailure(['assert_equalfile(1, "f2")'], 'E1013: Argument 1: type mismatch, expected string but got number') + CheckDefFailure(['assert_equalfile("f1", true)'], 'E1013: Argument 2: type mismatch, expected string but got bool') + CheckDefFailure(['assert_equalfile("f1", "f2", ["a"])'], 'E1013: Argument 3: type mismatch, expected string but got list<string>') +enddef + +def Test_assert_exception() + CheckDefFailure(['assert_exception({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>') + CheckDefFailure(['assert_exception("E1:", v:null)'], 'E1013: Argument 2: type mismatch, expected string but got special') +enddef + +def Test_assert_match() + CheckDefFailure(['assert_match({}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>') + CheckDefFailure(['assert_match("a", 1)'], 'E1013: Argument 2: type mismatch, expected string but got number') + CheckDefFailure(['assert_match("a", "b", null)'], 'E1013: Argument 3: type mismatch, expected string but got special') +enddef + +def Test_assert_notmatch() + CheckDefFailure(['assert_notmatch({}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>') + CheckDefFailure(['assert_notmatch("a", 1)'], 'E1013: Argument 2: type mismatch, expected string but got number') + CheckDefFailure(['assert_notmatch("a", "b", null)'], 'E1013: Argument 3: type mismatch, expected string but got special') enddef def Test_balloon_show() @@ -222,6 +245,11 @@ def Test_browse() CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 4') enddef +def Test_browsedir() + CheckDefFailure(['browsedir({}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>') + CheckDefFailure(['browsedir("a", [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>') +enddef + def Test_bufadd() assert_fails('bufadd([])', 'E730:') enddef @@ -299,12 +327,51 @@ def Test_call_call() l->assert_equal([1, 2, 3]) enddef +def Test_ch_canread() + if !has('channel') + CheckFeature channel + endif + CheckDefFailure(['ch_canread(10)'], 'E1013: Argument 1: type mismatch, expected channel but got number') +enddef + +def Test_ch_close() + if !has('channel') + CheckFeature channel + endif + CheckDefFailure(['ch_close("c")'], 'E1013: Argument 1: type mismatch, expected channel but got string') +enddef + +def Test_ch_close_in() + if !has('channel') + CheckFeature channel + endif + CheckDefFailure(['ch_close_in(true)'], 'E1013: Argument 1: type mismatch, expected channel but got bool') +enddef + +def Test_ch_info() + if !has('channel') + CheckFeature channel + endif + CheckDefFailure(['ch_info([1])'], 'E1013: Argument 1: type mismatch, expected channel but got list<number>') +enddef + def Test_ch_logfile() if !has('channel') CheckFeature channel endif assert_fails('ch_logfile(true)', 'E1174:') assert_fails('ch_logfile("foo", true)', 'E1174:') + + CheckDefAndScriptFailure2(['ch_logfile(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') + CheckDefAndScriptFailure2(['ch_logfile("a", true)'], 'E1013: Argument 2: type mismatch, expected string but got bool', 'E1174: String required for argument 2') +enddef + +def Test_ch_open() + if !has('channel') + CheckFeature channel + endif + CheckDefAndScriptFailure2(['ch_open({"a": 10}, "a")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E1174: String required for argument 1') + CheckDefAndScriptFailure2(['ch_open("a", [1])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 2') enddef def Test_char2nr() @@ -317,6 +384,17 @@ def Test_charclass() assert_fails('charclass(true)', 'E1174:') enddef +def Test_charcol() + CheckDefFailure(['charcol(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') + CheckDefFailure(['charcol({a: 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>') +enddef + +def Test_charidx() + CheckDefFailure(['charidx("a", "b")'], 'E1013: Argument 2: type mismatch, expected number but got string') + CheckDefFailure(['charidx(0z10, 1)'], 'E1013: Argument 1: type mismatch, expected string but got blob') + CheckDefFailure(['charidx("a", 1, "")'], 'E1013: Argument 3: type mismatch, expected bool but got string') +enddef + def Test_chdir() assert_fails('chdir(true)', 'E1174:') enddef @@ -329,7 +407,7 @@ def Test_cindent() enddef def Test_clearmatches() - CheckDefFailure(['echo clearmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['clearmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') enddef def Test_col() @@ -338,6 +416,11 @@ def Test_col() col([1, '$'])->assert_equal(5) assert_fails('col(true)', 'E1174:') + + CheckDefFailure(['col(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') + CheckDefFailure(['col({a: 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>') + CheckDefFailure(['col(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool') + bw! enddef def Test_confirm() @@ -396,12 +479,15 @@ enddef def Test_debugbreak() CheckMSWindows - CheckDefFailure(['echo debugbreak("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['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) + + CheckDefFailure(['delete(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') + CheckDefFailure(['delete("a", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number') enddef def Test_diff_filler() @@ -438,10 +524,10 @@ def Test_execute() res = execute(["echo 'here'", "echo 'there'"]) assert_equal("\nhere\nthere", res) - CheckDefFailure(['echo execute(123)'], 'E1013: Argument 1: type mismatch, expected string but got number') - CheckDefFailure(['echo execute([123])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>') + CheckDefFailure(['execute(123)'], 'E1013: Argument 1: type mismatch, expected string but got number') + CheckDefFailure(['execute([123])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>') CheckDefExecFailure(['echo execute(["xx", 123])'], 'E492') - CheckDefFailure(['echo execute("xx", 123)'], 'E1013: Argument 2: type mismatch, expected string but got number') + CheckDefFailure(['execute("xx", 123)'], 'E1013: Argument 2: type mismatch, expected string but got number') enddef def Test_exepath() @@ -600,6 +686,26 @@ def Test_feedkeys() unlet g:TestVar enddef +def Test_indent() + CheckDefAndScriptFailure2(['indent([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E745: Using a List as a Number') + CheckDefAndScriptFailure2(['indent(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1138: Using a Bool as a Number') + assert_equal(0, indent(1)) +enddef + +def Test_input() + CheckDefFailure(['input(5)'], 'E1013: Argument 1: type mismatch, expected string but got number') + CheckDefAndScriptFailure2(['input(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String') + CheckDefFailure(['input("p", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number') + CheckDefAndScriptFailure2(['input("p", "q", 20)'], 'E1013: Argument 3: type mismatch, expected string but got number', 'E180: Invalid complete value') +enddef + +def Test_inputdialog() + CheckDefFailure(['inputdialog(5)'], 'E1013: Argument 1: type mismatch, expected string but got number') + CheckDefAndScriptFailure2(['inputdialog(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String') + CheckDefFailure(['inputdialog("p", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number') + CheckDefFailure(['inputdialog("p", "q", 20)'], 'E1013: Argument 3: type mismatch, expected string but got number') +enddef + def Test_job_info_return_type() if has('job') job_start(&shell) @@ -627,15 +733,19 @@ def Test_filewritable() enddef def Test_finddir() - CheckDefExecFailure(['echo finddir(true)'], 'E1174:') - CheckDefExecFailure(['echo finddir(v:null)'], 'E1174:') + CheckDefAndScriptFailure2(['finddir(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1174: String required for argument 1') + CheckDefAndScriptFailure2(['finddir(v:null)'], 'E1013: Argument 1: type mismatch, expected string but got special', 'E1174: String required for argument 1') CheckDefExecFailure(['echo finddir("")'], 'E1175:') + CheckDefAndScriptFailure2(['finddir("a", [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E730: Using a List as a String') + CheckDefAndScriptFailure2(['finddir("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number') enddef def Test_findfile() - CheckDefExecFailure(['echo findfile(true)'], 'E1174:') - CheckDefExecFailure(['echo findfile(v:null)'], 'E1174:') - CheckDefExecFailure(['echo findfile("")'], 'E1175:') + CheckDefExecFailure(['findfile(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool') + CheckDefExecFailure(['findfile(v:null)'], 'E1013: Argument 1: type mismatch, expected string but got special') + CheckDefExecFailure(['findfile("")'], 'E1175:') + CheckDefAndScriptFailure2(['findfile("a", [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E730: Using a List as a String') + CheckDefAndScriptFailure2(['findfile("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number') enddef def Test_flattennew() @@ -660,57 +770,57 @@ def Test_float_funcs_args() CheckFeature float # acos() - CheckDefFailure(['echo acos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['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') + CheckDefFailure(['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') + CheckDefFailure(['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:') + CheckDefFailure(['atan2("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['atan2(1.2, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string') + CheckDefFailure(['atan2(1.2)'], 'E119:') # ceil() - CheckDefFailure(['echo ceil("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['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') + CheckDefFailure(['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') + CheckDefFailure(['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') + CheckDefFailure(['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') + CheckDefFailure(['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') + CheckDefFailure(['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:') + CheckDefFailure(['fmod(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string') + CheckDefFailure(['fmod("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['fmod(1.1)'], 'E119:') # isinf() - CheckDefFailure(['echo isinf("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['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') + CheckDefFailure(['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') + CheckDefFailure(['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') + CheckDefFailure(['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:') + CheckDefFailure(['pow("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['pow(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string') + CheckDefFailure(['pow(1.1)'], 'E119:') # round() - CheckDefFailure(['echo round("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['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') + CheckDefFailure(['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') + CheckDefFailure(['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') + CheckDefFailure(['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') + CheckDefFailure(['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') + CheckDefFailure(['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') + CheckDefFailure(['trunc("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') enddef def Test_fnameescape() @@ -863,17 +973,17 @@ def Test_getcompletion() enddef def Test_getcurpos() - CheckDefFailure(['echo getcursorcharpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['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') + CheckDefFailure(['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') + CheckDefFailure(['getcwd("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['getcwd("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['getcwd(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') enddef def Test_getloclist_return_type() @@ -921,9 +1031,9 @@ def Test_getftype() 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') + CheckDefFailure(['getjumplist("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['getjumplist("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['getjumplist(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') enddef def Test_getmarklist() @@ -933,7 +1043,7 @@ def Test_getmarklist() enddef def Test_getmatches() - CheckDefFailure(['echo getmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['getmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') enddef def Test_getpos() @@ -983,11 +1093,11 @@ def Test_getregtype() enddef def Test_gettabinfo() - CheckDefFailure(['echo gettabinfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['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') + CheckDefFailure(['gettagstack("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') enddef def Test_gettext() @@ -996,11 +1106,11 @@ def Test_gettext() enddef def Test_getwininfo() - CheckDefFailure(['echo getwininfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['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') + CheckDefFailure(['getwinpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') enddef def Test_glob() @@ -1020,10 +1130,15 @@ def Test_has() has('eval', true)->assert_equal(1) enddef +def Test_has_key() + CheckDefAndScriptFailure2(['has_key([1, 2], "k")'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required') + CheckDefAndScriptFailure2(['has_key({"a": 10}, ["a"])'], 'E1013: Argument 2: type mismatch, expected string but got list<string>', 'E730: Using a List as a String') +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') + CheckDefFailure(['haslocaldir("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['haslocaldir("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['haslocaldir(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') enddef def Test_hasmapto() @@ -1124,7 +1239,7 @@ def Test_insert() enddef def Test_invert() - CheckDefFailure(['echo invert("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['invert("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') enddef def Test_isdirectory() @@ -1187,8 +1302,12 @@ def SID(): number ->str2nr() enddef +def Test_listener_flush() + CheckDefAndScriptFailure2(['listener_flush([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String') +enddef + def Test_listener_remove() - CheckDefFailure(['echo listener_remove("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefAndScriptFailure2(['listener_remove("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') enddef def Test_map_function_arg() @@ -1294,13 +1413,13 @@ def Test_map_failure() enddef def Test_matcharg() - CheckDefFailure(['echo matcharg("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['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') + CheckDefFailure(['matchdelete("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['matchdelete("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['matchdelete(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') enddef def Test_max() @@ -1338,6 +1457,13 @@ def Test_min() assert_equal([4, 5], l2) enddef +def Test_mkdir() + CheckDefAndScriptFailure2(['mkdir(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String') + CheckDefAndScriptFailure2(['mkdir("a", {})'], 'E1013: Argument 2: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String') + CheckDefAndScriptFailure2(['mkdir("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number') + delete('a', 'rf') +enddef + def Test_nextnonblank() CheckDefFailure(['nextnonblank(null)'], 'E1013: Argument 1: type mismatch, expected string but got special') assert_equal(0, nextnonblank(1)) @@ -1348,8 +1474,13 @@ def Test_nr2char() 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') + CheckDefFailure(['or("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['or(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') +enddef + +def Test_popup_locate() + CheckDefAndScriptFailure2(['popup_locate("a", 20)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') + CheckDefAndScriptFailure2(['popup_locate(10, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1030: Using a String as a Number') enddef def Test_prevnonblank() @@ -1364,6 +1495,34 @@ def Test_prompt_getprompt() endif enddef +def Test_prop_find() + CheckDefAndScriptFailure2(['prop_find([1, 2])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required') + CheckDefAndScriptFailure2(['prop_find([1, 2], "k")'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required') + CheckDefAndScriptFailure2(['prop_find({"a": 10}, ["a"])'], 'E1013: Argument 2: type mismatch, expected string but got list<string>', 'E730: Using a List as a String') +enddef + +def Test_prop_type_add() + CheckDefAndScriptFailure2(['prop_type_add({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String') + CheckDefAndScriptFailure2(['prop_type_add("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required') +enddef + +def Test_prop_type_change() + CheckDefAndScriptFailure2(['prop_type_change({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String') + CheckDefAndScriptFailure2(['prop_type_change("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required') +enddef + +def Test_prop_type_delete() + CheckDefAndScriptFailure2(['prop_type_delete({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String') + CheckDefAndScriptFailure2(['prop_type_delete({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String') + CheckDefAndScriptFailure2(['prop_type_delete("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required') +enddef + +def Test_prop_type_get() + CheckDefAndScriptFailure2(['prop_type_get({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String') + CheckDefAndScriptFailure2(['prop_type_get({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String') + CheckDefAndScriptFailure2(['prop_type_get("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required') +enddef + def Test_rand() CheckDefFailure(['rand(10)'], 'E1013: Argument 1: type mismatch, expected list<number> but got number') CheckDefFailure(['rand(["a"])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<string>') @@ -1371,6 +1530,12 @@ def Test_rand() assert_true(rand(srand()) >= 0) enddef +def Test_range() + CheckDefAndScriptFailure2(['range("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') + CheckDefAndScriptFailure2(['range(10, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1030: Using a String as a Number') + CheckDefAndScriptFailure2(['range(10, 20, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number') +enddef + def Test_readdir() eval expand('sautest')->readdir((e) => e[0] !=# '.') eval expand('sautest')->readdirex((e) => e.name[0] !=# '.') @@ -1400,6 +1565,9 @@ def Test_readfile() END CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected dict<string> but got list<string>', 1) delete('Xreadfile') + + CheckDefAndScriptFailure2(['readfile("a", 0z10)'], 'E1013: Argument 2: type mismatch, expected string but got blob', 'E976: Using a Blob as a String') + CheckDefAndScriptFailure2(['readfile("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number') enddef def Test_reltime() @@ -1435,7 +1603,16 @@ def Test_remote_foreground() assert_fails('remote_foreground("NonExistingServer")', 'E241:') enddef +def Test_remote_peek() + CheckFeature clientserver + CheckEnv DISPLAY + CheckDefAndScriptFailure2(['remote_peek(0z10)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E976: Using a Blob as a String') + CheckDefAndScriptFailure2(['remote_peek("a5b6c7", [1])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E573: Invalid server id used') +enddef + def Test_remote_startserver() + CheckFeature clientserver + CheckEnv DISPLAY CheckDefFailure(['remote_startserver({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>') enddef @@ -1458,6 +1635,11 @@ def Test_resolve() assert_equal('SomeFile', resolve('SomeFile')) enddef +def Test_reverse() + CheckDefAndScriptFailure2(['reverse(10)'], 'E1013: Argument 1: type mismatch, expected list<any> but got number', 'E899: Argument of reverse() must be a List or Blob') + CheckDefAndScriptFailure2(['reverse("abc")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E899: Argument of reverse() must be a List or Blob') +enddef + def Test_reverse_return_type() var l = reverse([1, 2, 3]) var res = 0 @@ -1468,18 +1650,18 @@ def Test_reverse_return_type() 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') + CheckDefFailure(['screenattr("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['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') + CheckDefFailure(['screenchar("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['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') + CheckDefFailure(['screenchars("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['screenchars(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') enddef def Test_screenpos() @@ -1490,8 +1672,8 @@ def Test_screenpos() 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') + CheckDefFailure(['screenstring("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['screenstring(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') enddef def Test_search() @@ -1577,6 +1759,13 @@ def Test_searchpair() bwipe! enddef +def Test_server2client() + CheckFeature clientserver + CheckEnv DISPLAY + CheckDefAndScriptFailure2(['server2client(10, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E573: Invalid server id used:') + CheckDefAndScriptFailure2(['server2client("a", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E573: Invalid server id used:') +enddef + def Test_set_get_bufline() # similar to Test_setbufline_getbufline() var lines =<< trim END @@ -1665,7 +1854,7 @@ def Test_setcharsearch() enddef def Test_setcmdpos() - CheckDefFailure(['echo setcmdpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['setcmdpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') enddef def Test_setfperm() @@ -1695,7 +1884,24 @@ def Test_sha256() enddef def Test_shiftwidth() - CheckDefFailure(['echo shiftwidth("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') + CheckDefFailure(['shiftwidth("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') +enddef + +def Test_sign_define() + CheckDefAndScriptFailure2(['sign_define({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String') + CheckDefAndScriptFailure2(['sign_define({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String') + CheckDefAndScriptFailure2(['sign_define("a", ["b"])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<string>', 'E715: Dictionary required') +enddef + +def Test_sign_undefine() + CheckDefAndScriptFailure2(['sign_undefine({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String') + CheckDefAndScriptFailure2(['sign_undefine([1])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>', 'E155: Unknown sign:') +enddef + +def Test_sign_unplace() + CheckDefAndScriptFailure2(['sign_unplace({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E474: Invalid argument') + CheckDefAndScriptFailure2(['sign_unplace({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E474: Invalid argument') + CheckDefAndScriptFailure2(['sign_unplace("a", ["b"])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<string>', 'E715: Dictionary required') enddef def Test_simplify() @@ -1790,7 +1996,7 @@ def Run_str2float() str2float("1.00")->assert_equal(1.00) str2float("2e-2")->assert_equal(0.02) - CheckDefFailure(['echo str2float(123)'], 'E1013:') + CheckDefFailure(['str2float(123)'], 'E1013:') CheckScriptFailure(['vim9script', 'echo str2float(123)'], 'E1024:') endif enddef @@ -1798,11 +2004,11 @@ enddef def Test_str2nr() str2nr("1'000'000", 10, true)->assert_equal(1000000) - CheckDefFailure(['echo str2nr(123)'], 'E1013:') + CheckDefFailure(['str2nr(123)'], 'E1013:') CheckScriptFailure(['vim9script', 'echo str2nr(123)'], 'E1024:') - CheckDefFailure(['echo str2nr("123", "x")'], 'E1013:') + CheckDefFailure(['str2nr("123", "x")'], 'E1013:') CheckScriptFailure(['vim9script', 'echo str2nr("123", "x")'], 'E1030:') - CheckDefFailure(['echo str2nr("123", 10, "x")'], 'E1013:') + CheckDefFailure(['str2nr("123", 10, "x")'], 'E1013:') CheckScriptFailure(['vim9script', 'echo str2nr("123", 10, "x")'], 'E1135:') enddef @@ -1810,6 +2016,12 @@ def Test_strchars() strchars("A\u20dd", true)->assert_equal(1) enddef +def Test_stridx() + CheckDefAndScriptFailure2(['stridx([1], "b")'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String') + CheckDefAndScriptFailure2(['stridx("a", {})'], 'E1013: Argument 2: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String') + CheckDefAndScriptFailure2(['stridx("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number') +enddef + def Test_strlen() CheckDefFailure(['strlen([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') "abc"->strlen()->assert_equal(3) @@ -1826,6 +2038,12 @@ def Test_strptime() #assert_true(strptime('%Y', '2021') != 0) enddef +def Test_strridx() + CheckDefAndScriptFailure2(['strridx([1], "b")'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String') + CheckDefAndScriptFailure2(['strridx("a", {})'], 'E1013: Argument 2: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String') + CheckDefAndScriptFailure2(['strridx("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number') +enddef + def Test_strtrans() CheckDefFailure(['strtrans(20)'], 'E1013: Argument 1: type mismatch, expected string but got number') assert_equal('abc', strtrans('abc')) @@ -1883,11 +2101,63 @@ def Test_tabpagebuflist() enddef def Test_tabpagenr() - CheckDefFailure(['tabpagenr(1)'], 'E1013: Argument 1: type mismatch, expected string but got number') + CheckDefAndScriptFailure2(['tabpagenr(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E15: Invalid expression:') assert_equal(1, tabpagenr('$')) assert_equal(1, tabpagenr()) enddef +def Test_taglist() + CheckDefAndScriptFailure2(['taglist([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String') + CheckDefAndScriptFailure2(['taglist("a", [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E730: Using a List as a String') +enddef + +def Test_term_dumpload() + CheckRunVimInTerminal + CheckDefAndScriptFailure2(['term_dumpload({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E1174: String required for argument 1') + CheckDefAndScriptFailure2(['term_dumpload({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E1174: String required for argument 1') + CheckDefAndScriptFailure2(['term_dumpload("a", ["b"])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<string>', 'E1206: Dictionary required for argument 2') +enddef + +def Test_term_getaltscreen() + CheckRunVimInTerminal + CheckDefAndScriptFailure2(['term_getaltscreen(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1138: Using a Bool as a Number') +enddef + +def Test_term_getansicolors() + CheckRunVimInTerminal + CheckDefAndScriptFailure2(['term_getansicolors(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E745: Using a List as a Number') +enddef + +def Test_term_getcursor() + CheckRunVimInTerminal + CheckDefAndScriptFailure2(['term_getcursor({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E728: Using a Dictionary as a Number') +enddef + +def Test_term_getjob() |