Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1 | " Test using builtin functions in the Vim9 script language. |
| 2 | |
| 3 | source check.vim |
| 4 | source vim9.vim |
| 5 | |
| 6 | " Test for passing too many or too few arguments to builtin functions |
| 7 | func Test_internalfunc_arg_error() |
| 8 | let l =<< trim END |
| 9 | def! FArgErr(): float |
| 10 | return ceil(1.1, 2) |
| 11 | enddef |
| 12 | defcompile |
| 13 | END |
| 14 | call writefile(l, 'Xinvalidarg') |
| 15 | call assert_fails('so Xinvalidarg', 'E118:', '', 1, 'FArgErr') |
| 16 | let l =<< trim END |
| 17 | def! FArgErr(): float |
| 18 | return ceil() |
| 19 | enddef |
| 20 | defcompile |
| 21 | END |
| 22 | call writefile(l, 'Xinvalidarg') |
| 23 | call assert_fails('so Xinvalidarg', 'E119:', '', 1, 'FArgErr') |
| 24 | call delete('Xinvalidarg') |
| 25 | endfunc |
| 26 | |
| 27 | " Test for builtin functions returning different types |
| 28 | func Test_InternalFuncRetType() |
| 29 | let lines =<< trim END |
| 30 | def RetFloat(): float |
| 31 | return ceil(1.456) |
| 32 | enddef |
| 33 | |
| 34 | def RetListAny(): list<any> |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 35 | return items({k: 'v'}) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 36 | enddef |
| 37 | |
| 38 | def RetListString(): list<string> |
| 39 | return split('a:b:c', ':') |
| 40 | enddef |
| 41 | |
| 42 | def RetListDictAny(): list<dict<any>> |
| 43 | return getbufinfo() |
| 44 | enddef |
| 45 | |
| 46 | def RetDictNumber(): dict<number> |
| 47 | return wordcount() |
| 48 | enddef |
| 49 | |
| 50 | def RetDictString(): dict<string> |
| 51 | return environ() |
| 52 | enddef |
| 53 | END |
| 54 | call writefile(lines, 'Xscript') |
| 55 | source Xscript |
| 56 | |
| 57 | call RetFloat()->assert_equal(2.0) |
| 58 | call RetListAny()->assert_equal([['k', 'v']]) |
| 59 | call RetListString()->assert_equal(['a', 'b', 'c']) |
| 60 | call RetListDictAny()->assert_notequal([]) |
| 61 | call RetDictNumber()->assert_notequal({}) |
| 62 | call RetDictString()->assert_notequal({}) |
| 63 | call delete('Xscript') |
| 64 | endfunc |
| 65 | |
| 66 | def Test_abs() |
| 67 | assert_equal(0, abs(0)) |
| 68 | assert_equal(2, abs(-2)) |
| 69 | assert_equal(3, abs(3)) |
| 70 | CheckDefFailure(['abs("text")'], 'E1013: Argument 1: type mismatch, expected number but got string', 1) |
| 71 | if has('float') |
| 72 | assert_equal(0, abs(0)) |
| 73 | assert_equal(2.0, abs(-2.0)) |
| 74 | assert_equal(3.0, abs(3.0)) |
| 75 | endif |
| 76 | enddef |
| 77 | |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 78 | def Test_add() |
| 79 | CheckDefAndScriptFailure2(['add({}, 1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<unknown>', 'E1211: List required for argument 1') |
| 80 | CheckDefFailure(['add([1], "a")'], 'E1012: Type mismatch; expected number but got string') |
| 81 | enddef |
| 82 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 83 | def Test_add_blob() |
| 84 | var b1: blob = 0z12 |
| 85 | add(b1, 0x34) |
| 86 | assert_equal(0z1234, b1) |
| 87 | |
| 88 | var b2: blob # defaults to empty blob |
| 89 | add(b2, 0x67) |
| 90 | assert_equal(0z67, b2) |
| 91 | |
| 92 | var lines =<< trim END |
| 93 | var b: blob |
| 94 | add(b, "x") |
| 95 | END |
| 96 | CheckDefFailure(lines, 'E1012:', 2) |
| 97 | |
| 98 | lines =<< trim END |
| 99 | add(test_null_blob(), 123) |
| 100 | END |
| 101 | CheckDefExecAndScriptFailure(lines, 'E1131:', 1) |
| 102 | |
| 103 | lines =<< trim END |
| 104 | var b: blob = test_null_blob() |
| 105 | add(b, 123) |
| 106 | END |
| 107 | CheckDefExecFailure(lines, 'E1131:', 2) |
| 108 | |
| 109 | # Getting variable with NULL blob allocates a new blob at script level |
| 110 | lines =<< trim END |
| 111 | vim9script |
| 112 | var b: blob = test_null_blob() |
| 113 | add(b, 123) |
| 114 | END |
| 115 | CheckScriptSuccess(lines) |
| 116 | enddef |
| 117 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 118 | def Test_add_list() |
| 119 | var l: list<number> # defaults to empty list |
| 120 | add(l, 9) |
| 121 | assert_equal([9], l) |
| 122 | |
| 123 | var lines =<< trim END |
| 124 | var l: list<number> |
| 125 | add(l, "x") |
| 126 | END |
| 127 | CheckDefFailure(lines, 'E1012:', 2) |
| 128 | |
| 129 | lines =<< trim END |
Bram Moolenaar | b7c21af | 2021-04-18 14:12:31 +0200 | [diff] [blame] | 130 | add(test_null_list(), 123) |
| 131 | END |
| 132 | CheckDefExecAndScriptFailure(lines, 'E1130:', 1) |
| 133 | |
| 134 | lines =<< trim END |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 135 | var l: list<number> = test_null_list() |
| 136 | add(l, 123) |
| 137 | END |
| 138 | CheckDefExecFailure(lines, 'E1130:', 2) |
Bram Moolenaar | b7c21af | 2021-04-18 14:12:31 +0200 | [diff] [blame] | 139 | |
| 140 | # Getting variable with NULL list allocates a new list at script level |
| 141 | lines =<< trim END |
| 142 | vim9script |
| 143 | var l: list<number> = test_null_list() |
| 144 | add(l, 123) |
| 145 | END |
| 146 | CheckScriptSuccess(lines) |
Bram Moolenaar | f32f099 | 2021-07-08 20:53:40 +0200 | [diff] [blame] | 147 | |
| 148 | lines =<< trim END |
| 149 | vim9script |
| 150 | var l: list<string> = ['a'] |
| 151 | l->add(123) |
| 152 | END |
| 153 | CheckScriptFailure(lines, 'E1012: Type mismatch; expected string but got number', 3) |
Bram Moolenaar | f055d45 | 2021-07-08 20:57:24 +0200 | [diff] [blame] | 154 | |
| 155 | lines =<< trim END |
| 156 | vim9script |
| 157 | var l: list<string> |
| 158 | l->add(123) |
| 159 | END |
| 160 | CheckScriptFailure(lines, 'E1012: Type mismatch; expected string but got number', 3) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 161 | enddef |
| 162 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 163 | def Test_and() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 164 | CheckDefAndScriptFailure2(['and("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 165 | CheckDefAndScriptFailure2(['and(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 166 | enddef |
| 167 | |
Bram Moolenaar | 3af15ab | 2021-01-17 16:16:23 +0100 | [diff] [blame] | 168 | def Test_append() |
| 169 | new |
| 170 | setline(1, range(3)) |
| 171 | var res1: number = append(1, 'one') |
| 172 | assert_equal(0, res1) |
| 173 | var res2: bool = append(3, 'two') |
| 174 | assert_equal(false, res2) |
| 175 | assert_equal(['0', 'one', '1', 'two', '2'], getline(1, 6)) |
Bram Moolenaar | b2ac7d0 | 2021-03-28 15:46:16 +0200 | [diff] [blame] | 176 | |
| 177 | append(0, 'zero') |
| 178 | assert_equal('zero', getline(1)) |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 179 | append(0, {a: 10}) |
| 180 | assert_equal("{'a': 10}", getline(1)) |
| 181 | append(0, function('min')) |
| 182 | assert_equal("function('min')", getline(1)) |
| 183 | CheckDefAndScriptFailure2(['append([1], "x")'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E745: Using a List as a Number') |
| 184 | bwipe! |
| 185 | enddef |
| 186 | |
| 187 | def Test_appendbufline() |
| 188 | new |
| 189 | var bnum: number = bufnr() |
| 190 | :wincmd w |
| 191 | appendbufline(bnum, 0, range(3)) |
| 192 | var res1: number = appendbufline(bnum, 1, 'one') |
| 193 | assert_equal(0, res1) |
| 194 | var res2: bool = appendbufline(bnum, 3, 'two') |
| 195 | assert_equal(false, res2) |
| 196 | assert_equal(['0', 'one', '1', 'two', '2', ''], getbufline(bnum, 1, '$')) |
| 197 | appendbufline(bnum, 0, 'zero') |
| 198 | assert_equal(['zero'], getbufline(bnum, 1)) |
| 199 | CheckDefFailure(['appendbufline([1], 1, "x")'], 'E1013: Argument 1: type mismatch, expected string but got list<number>') |
| 200 | CheckDefFailure(['appendbufline(1, [1], "x")'], 'E1013: Argument 2: type mismatch, expected string but got list<number>') |
| 201 | CheckDefFailure(['appendbufline(1, 1, {"a": 10})'], 'E1013: Argument 3: type mismatch, expected string but got dict<number>') |
| 202 | bnum->bufwinid()->win_gotoid() |
Bram Moolenaar | b2ac7d0 | 2021-03-28 15:46:16 +0200 | [diff] [blame] | 203 | bwipe! |
Bram Moolenaar | 3af15ab | 2021-01-17 16:16:23 +0100 | [diff] [blame] | 204 | enddef |
| 205 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 206 | def Test_argc() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 207 | CheckDefFailure(['argc("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 208 | enddef |
| 209 | |
| 210 | def Test_arglistid() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 211 | CheckDefFailure(['arglistid("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 212 | CheckDefFailure(['arglistid(1, "y")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 213 | CheckDefFailure(['arglistid("x", "y")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 214 | enddef |
| 215 | |
| 216 | def Test_argv() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 217 | CheckDefFailure(['argv("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 218 | CheckDefFailure(['argv(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 219 | CheckDefFailure(['argv("x", "y")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 220 | enddef |
| 221 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 222 | def Test_assert_beeps() |
| 223 | CheckDefAndScriptFailure2(['assert_beeps(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 224 | enddef |
| 225 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 226 | def Test_assert_equalfile() |
| 227 | CheckDefFailure(['assert_equalfile(1, "f2")'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 228 | CheckDefFailure(['assert_equalfile("f1", true)'], 'E1013: Argument 2: type mismatch, expected string but got bool') |
| 229 | CheckDefFailure(['assert_equalfile("f1", "f2", ["a"])'], 'E1013: Argument 3: type mismatch, expected string but got list<string>') |
| 230 | enddef |
| 231 | |
| 232 | def Test_assert_exception() |
| 233 | CheckDefFailure(['assert_exception({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>') |
| 234 | CheckDefFailure(['assert_exception("E1:", v:null)'], 'E1013: Argument 2: type mismatch, expected string but got special') |
| 235 | enddef |
| 236 | |
| 237 | def Test_assert_match() |
| 238 | CheckDefFailure(['assert_match({}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>') |
| 239 | CheckDefFailure(['assert_match("a", 1)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 240 | CheckDefFailure(['assert_match("a", "b", null)'], 'E1013: Argument 3: type mismatch, expected string but got special') |
| 241 | enddef |
| 242 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 243 | def Test_assert_nobeep() |
| 244 | CheckDefAndScriptFailure2(['assert_nobeep(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 245 | enddef |
| 246 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 247 | def Test_assert_notmatch() |
| 248 | CheckDefFailure(['assert_notmatch({}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>') |
| 249 | CheckDefFailure(['assert_notmatch("a", 1)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 250 | CheckDefFailure(['assert_notmatch("a", "b", null)'], 'E1013: Argument 3: type mismatch, expected string but got special') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 251 | enddef |
| 252 | |
Yegappan Lakshmanan | c72bdd2 | 2021-07-11 19:44:18 +0200 | [diff] [blame] | 253 | def Test_assert_report() |
| 254 | CheckDefAndScriptFailure2(['assert_report([1, 2])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E1174: String required for argument 1') |
| 255 | enddef |
| 256 | |
Bram Moolenaar | 32105ae | 2021-03-27 18:59:25 +0100 | [diff] [blame] | 257 | def Test_balloon_show() |
| 258 | CheckGui |
| 259 | CheckFeature balloon_eval |
| 260 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 261 | assert_fails('balloon_show(10)', 'E1174:') |
Bram Moolenaar | 32105ae | 2021-03-27 18:59:25 +0100 | [diff] [blame] | 262 | assert_fails('balloon_show(true)', 'E1174:') |
Yegappan Lakshmanan | c72bdd2 | 2021-07-11 19:44:18 +0200 | [diff] [blame] | 263 | |
| 264 | CheckDefAndScriptFailure2(['balloon_show(1.2)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1') |
| 265 | CheckDefAndScriptFailure2(['balloon_show({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E1174: String required for argument 1') |
Bram Moolenaar | 32105ae | 2021-03-27 18:59:25 +0100 | [diff] [blame] | 266 | enddef |
| 267 | |
| 268 | def Test_balloon_split() |
Bram Moolenaar | 7b45d46 | 2021-03-27 19:09:02 +0100 | [diff] [blame] | 269 | CheckFeature balloon_eval_term |
Bram Moolenaar | 32105ae | 2021-03-27 18:59:25 +0100 | [diff] [blame] | 270 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 271 | assert_fails('balloon_split([])', 'E1174:') |
Bram Moolenaar | 32105ae | 2021-03-27 18:59:25 +0100 | [diff] [blame] | 272 | assert_fails('balloon_split(true)', 'E1174:') |
| 273 | enddef |
| 274 | |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 275 | def Test_browse() |
| 276 | CheckFeature browse |
| 277 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 278 | CheckDefAndScriptFailure2(['browse(2, "title", "dir", "file")'], 'E1013: Argument 1: type mismatch, expected bool but got number', 'E1212: Bool required for argument 1') |
| 279 | CheckDefAndScriptFailure2(['browse(true, 2, "dir", "file")'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 280 | CheckDefAndScriptFailure2(['browse(true, "title", 3, "file")'], 'E1013: Argument 3: type mismatch, expected string but got number', 'E1174: String required for argument 3') |
| 281 | CheckDefAndScriptFailure2(['browse(true, "title", "dir", 4)'], 'E1013: Argument 4: type mismatch, expected string but got number', 'E1174: String required for argument 4') |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 282 | enddef |
| 283 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 284 | def Test_browsedir() |
| 285 | CheckDefFailure(['browsedir({}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>') |
| 286 | CheckDefFailure(['browsedir("a", [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>') |
| 287 | enddef |
| 288 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 289 | def Test_bufadd() |
| 290 | assert_fails('bufadd([])', 'E730:') |
| 291 | enddef |
| 292 | |
Bram Moolenaar | 32105ae | 2021-03-27 18:59:25 +0100 | [diff] [blame] | 293 | def Test_bufexists() |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 294 | assert_fails('bufexists(true)', 'E1174:') |
Bram Moolenaar | 32105ae | 2021-03-27 18:59:25 +0100 | [diff] [blame] | 295 | enddef |
| 296 | |
Bram Moolenaar | 3af15ab | 2021-01-17 16:16:23 +0100 | [diff] [blame] | 297 | def Test_buflisted() |
| 298 | var res: bool = buflisted('asdf') |
| 299 | assert_equal(false, res) |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 300 | assert_fails('buflisted(true)', 'E1174:') |
| 301 | assert_fails('buflisted([])', 'E1174:') |
| 302 | enddef |
| 303 | |
| 304 | def Test_bufload() |
| 305 | assert_fails('bufload([])', 'E730:') |
| 306 | enddef |
| 307 | |
| 308 | def Test_bufloaded() |
| 309 | assert_fails('bufloaded(true)', 'E1174:') |
| 310 | assert_fails('bufloaded([])', 'E1174:') |
Bram Moolenaar | 3af15ab | 2021-01-17 16:16:23 +0100 | [diff] [blame] | 311 | enddef |
| 312 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 313 | def Test_bufname() |
| 314 | split SomeFile |
| 315 | bufname('%')->assert_equal('SomeFile') |
| 316 | edit OtherFile |
| 317 | bufname('#')->assert_equal('SomeFile') |
| 318 | close |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 319 | assert_fails('bufname(true)', 'E1138:') |
| 320 | assert_fails('bufname([])', 'E745:') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 321 | enddef |
| 322 | |
| 323 | def Test_bufnr() |
| 324 | var buf = bufnr() |
| 325 | bufnr('%')->assert_equal(buf) |
| 326 | |
| 327 | buf = bufnr('Xdummy', true) |
| 328 | buf->assert_notequal(-1) |
| 329 | exe 'bwipe! ' .. buf |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 330 | CheckDefAndScriptFailure2(['bufnr([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E1174: String required for argument 1') |
| 331 | CheckDefAndScriptFailure2(['bufnr(1, 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 332 | enddef |
| 333 | |
| 334 | def Test_bufwinid() |
| 335 | var origwin = win_getid() |
| 336 | below split SomeFile |
| 337 | var SomeFileID = win_getid() |
| 338 | below split OtherFile |
| 339 | below split SomeFile |
| 340 | bufwinid('SomeFile')->assert_equal(SomeFileID) |
| 341 | |
| 342 | win_gotoid(origwin) |
| 343 | only |
| 344 | bwipe SomeFile |
| 345 | bwipe OtherFile |
Bram Moolenaar | 32105ae | 2021-03-27 18:59:25 +0100 | [diff] [blame] | 346 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 347 | assert_fails('bufwinid(true)', 'E1138:') |
| 348 | assert_fails('bufwinid([])', 'E745:') |
| 349 | enddef |
| 350 | |
| 351 | def Test_bufwinnr() |
| 352 | assert_fails('bufwinnr(true)', 'E1138:') |
| 353 | assert_fails('bufwinnr([])', 'E745:') |
| 354 | enddef |
| 355 | |
| 356 | def Test_byte2line() |
| 357 | CheckDefFailure(['byte2line("1")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 358 | CheckDefFailure(['byte2line([])'], 'E1013: Argument 1: type mismatch, expected number but got list<unknown>') |
| 359 | assert_equal(-1, byte2line(0)) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 360 | enddef |
| 361 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 362 | def Test_byteidx() |
| 363 | CheckDefAndScriptFailure2(['byteidx(1, 2)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 364 | CheckDefAndScriptFailure2(['byteidx("a", "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 365 | enddef |
| 366 | |
| 367 | def Test_byteidxcomp() |
| 368 | CheckDefAndScriptFailure2(['byteidxcomp(1, 2)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 369 | CheckDefAndScriptFailure2(['byteidxcomp("a", "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 370 | enddef |
| 371 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 372 | def Test_call_call() |
| 373 | var l = [3, 2, 1] |
| 374 | call('reverse', [l]) |
| 375 | l->assert_equal([1, 2, 3]) |
| 376 | enddef |
| 377 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 378 | def Test_ch_canread() |
| 379 | if !has('channel') |
| 380 | CheckFeature channel |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 381 | else |
| 382 | CheckDefFailure(['ch_canread(10)'], 'E1013: Argument 1: type mismatch, expected channel but got number') |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 383 | endif |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 384 | enddef |
| 385 | |
| 386 | def Test_ch_close() |
| 387 | if !has('channel') |
| 388 | CheckFeature channel |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 389 | else |
| 390 | CheckDefFailure(['ch_close("c")'], 'E1013: Argument 1: type mismatch, expected channel but got string') |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 391 | endif |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 392 | enddef |
| 393 | |
| 394 | def Test_ch_close_in() |
| 395 | if !has('channel') |
| 396 | CheckFeature channel |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 397 | else |
| 398 | CheckDefFailure(['ch_close_in(true)'], 'E1013: Argument 1: type mismatch, expected channel but got bool') |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 399 | endif |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 400 | enddef |
| 401 | |
| 402 | def Test_ch_evalexpr() |
| 403 | if !has('channel') |
| 404 | CheckFeature channel |
| 405 | else |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 406 | CheckDefAndScriptFailure2(['ch_evalexpr(1, "a")'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E1217: Channel or Job required for argument 1') |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 407 | CheckDefAndScriptFailure2(['ch_evalexpr(test_null_channel(), 1, [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3') |
| 408 | endif |
| 409 | enddef |
| 410 | |
| 411 | def Test_ch_evalraw() |
| 412 | if !has('channel') |
| 413 | CheckFeature channel |
| 414 | else |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 415 | CheckDefAndScriptFailure2(['ch_evalraw(1, "")'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E1217: Channel or Job required for argument 1') |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 416 | CheckDefAndScriptFailure2(['ch_evalraw(test_null_channel(), 1)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 417 | CheckDefAndScriptFailure2(['ch_evalraw(test_null_channel(), "", [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3') |
| 418 | endif |
| 419 | enddef |
| 420 | |
| 421 | def Test_ch_getbufnr() |
| 422 | if !has('channel') |
| 423 | CheckFeature channel |
| 424 | else |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 425 | CheckDefAndScriptFailure2(['ch_getbufnr(1, "a")'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E1217: Channel or Job required for argument 1') |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 426 | CheckDefAndScriptFailure2(['ch_getbufnr(test_null_channel(), 1)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 427 | endif |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 428 | enddef |
| 429 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 430 | def Test_ch_getjob() |
Dominique Pelle | 9ff9c7b | 2021-07-18 21:44:37 +0200 | [diff] [blame] | 431 | if !has('channel') |
| 432 | CheckFeature channel |
| 433 | else |
| 434 | CheckDefAndScriptFailure2(['ch_getjob(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument:') |
| 435 | CheckDefAndScriptFailure2(['ch_getjob({"a": 10})'], 'E1013: Argument 1: type mismatch, expected channel but got dict<number>', 'E731: Using a Dictionary as a String') |
| 436 | assert_equal(0, ch_getjob(test_null_channel())) |
| 437 | endif |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 438 | enddef |
| 439 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 440 | def Test_ch_info() |
| 441 | if !has('channel') |
| 442 | CheckFeature channel |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 443 | else |
| 444 | CheckDefFailure(['ch_info([1])'], 'E1013: Argument 1: type mismatch, expected channel but got list<number>') |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 445 | endif |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 446 | enddef |
| 447 | |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 448 | def Test_ch_logfile() |
Bram Moolenaar | 886e5e7 | 2021-04-05 13:36:34 +0200 | [diff] [blame] | 449 | if !has('channel') |
| 450 | CheckFeature channel |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 451 | else |
| 452 | assert_fails('ch_logfile(true)', 'E1174:') |
| 453 | assert_fails('ch_logfile("foo", true)', 'E1174:') |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 454 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 455 | CheckDefAndScriptFailure2(['ch_logfile(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 456 | CheckDefAndScriptFailure2(['ch_logfile("a", true)'], 'E1013: Argument 2: type mismatch, expected string but got bool', 'E1174: String required for argument 2') |
| 457 | endif |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 458 | enddef |
| 459 | |
| 460 | def Test_ch_open() |
| 461 | if !has('channel') |
| 462 | CheckFeature channel |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 463 | else |
| 464 | CheckDefAndScriptFailure2(['ch_open({"a": 10}, "a")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E1174: String required for argument 1') |
| 465 | CheckDefAndScriptFailure2(['ch_open("a", [1])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 2') |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 466 | endif |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 467 | enddef |
| 468 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 469 | def Test_ch_read() |
| 470 | if !has('channel') |
| 471 | CheckFeature channel |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 472 | else |
| 473 | CheckDefAndScriptFailure2(['ch_read(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument') |
| 474 | CheckDefAndScriptFailure2(['ch_read(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required') |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 475 | endif |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 476 | enddef |
| 477 | |
| 478 | def Test_ch_readblob() |
| 479 | if !has('channel') |
| 480 | CheckFeature channel |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 481 | else |
| 482 | CheckDefAndScriptFailure2(['ch_readblob(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument') |
| 483 | CheckDefAndScriptFailure2(['ch_readblob(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required') |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 484 | endif |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 485 | enddef |
| 486 | |
| 487 | def Test_ch_readraw() |
| 488 | if !has('channel') |
| 489 | CheckFeature channel |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 490 | else |
| 491 | CheckDefAndScriptFailure2(['ch_readraw(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument') |
| 492 | CheckDefAndScriptFailure2(['ch_readraw(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required') |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 493 | endif |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 494 | enddef |
| 495 | |
| 496 | def Test_ch_sendexpr() |
| 497 | if !has('channel') |
| 498 | CheckFeature channel |
| 499 | else |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 500 | CheckDefAndScriptFailure2(['ch_sendexpr(1, "a")'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E1217: Channel or Job required for argument 1') |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 501 | CheckDefAndScriptFailure2(['ch_sendexpr(test_null_channel(), 1, [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3') |
| 502 | endif |
| 503 | enddef |
| 504 | |
| 505 | def Test_ch_sendraw() |
| 506 | if !has('channel') |
| 507 | CheckFeature channel |
| 508 | else |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 509 | CheckDefAndScriptFailure2(['ch_sendraw(1, "")'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E1217: Channel or Job required for argument 1') |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 510 | CheckDefAndScriptFailure2(['ch_sendraw(test_null_channel(), 1)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 511 | CheckDefAndScriptFailure2(['ch_sendraw(test_null_channel(), "", [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3') |
| 512 | endif |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 513 | enddef |
| 514 | |
| 515 | def Test_ch_setoptions() |
| 516 | if !has('channel') |
| 517 | CheckFeature channel |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 518 | else |
| 519 | CheckDefAndScriptFailure2(['ch_setoptions(1, {})'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument') |
| 520 | CheckDefFailure(['ch_setoptions(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>') |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 521 | endif |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 522 | enddef |
| 523 | |
| 524 | def Test_ch_status() |
| 525 | if !has('channel') |
| 526 | CheckFeature channel |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 527 | else |
| 528 | CheckDefAndScriptFailure2(['ch_status(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument') |
| 529 | CheckDefAndScriptFailure2(['ch_status(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required') |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 530 | endif |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 531 | enddef |
| 532 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 533 | def Test_char2nr() |
| 534 | char2nr('あ', true)->assert_equal(12354) |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 535 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 536 | assert_fails('char2nr(true)', 'E1174:') |
Yegappan Lakshmanan | a9a7c0c | 2021-07-17 19:11:07 +0200 | [diff] [blame] | 537 | CheckDefAndScriptFailure2(['char2nr(10)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
Bram Moolenaar | 98c2eae | 2021-07-19 10:38:49 +0200 | [diff] [blame] | 538 | CheckDefAndScriptFailure2(['char2nr("a", 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2') |
Yegappan Lakshmanan | a9a7c0c | 2021-07-17 19:11:07 +0200 | [diff] [blame] | 539 | assert_equal(97, char2nr('a', 1)) |
| 540 | assert_equal(97, char2nr('a', 0)) |
| 541 | assert_equal(97, char2nr('a', true)) |
| 542 | assert_equal(97, char2nr('a', false)) |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 543 | enddef |
| 544 | |
| 545 | def Test_charclass() |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 546 | assert_fails('charclass(true)', 'E1174:') |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 547 | enddef |
| 548 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 549 | def Test_charcol() |
| 550 | CheckDefFailure(['charcol(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 551 | CheckDefFailure(['charcol({a: 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>') |
Yegappan Lakshmanan | c72bdd2 | 2021-07-11 19:44:18 +0200 | [diff] [blame] | 552 | new |
| 553 | setline(1, ['abcdefgh']) |
| 554 | cursor(1, 4) |
| 555 | assert_equal(4, charcol('.')) |
| 556 | assert_equal(9, charcol([1, '$'])) |
| 557 | assert_equal(0, charcol([10, '$'])) |
| 558 | bw! |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 559 | enddef |
| 560 | |
| 561 | def Test_charidx() |
| 562 | CheckDefFailure(['charidx("a", "b")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 563 | CheckDefFailure(['charidx(0z10, 1)'], 'E1013: Argument 1: type mismatch, expected string but got blob') |
| 564 | CheckDefFailure(['charidx("a", 1, "")'], 'E1013: Argument 3: type mismatch, expected bool but got string') |
| 565 | enddef |
| 566 | |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 567 | def Test_chdir() |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 568 | assert_fails('chdir(true)', 'E1174:') |
| 569 | enddef |
| 570 | |
| 571 | def Test_cindent() |
| 572 | CheckDefFailure(['cindent([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') |
| 573 | CheckDefFailure(['cindent(null)'], 'E1013: Argument 1: type mismatch, expected string but got special') |
| 574 | assert_equal(-1, cindent(0)) |
| 575 | assert_equal(0, cindent('.')) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 576 | enddef |
| 577 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 578 | def Test_clearmatches() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 579 | CheckDefFailure(['clearmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 580 | enddef |
| 581 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 582 | def Test_col() |
| 583 | new |
Yegappan Lakshmanan | c72bdd2 | 2021-07-11 19:44:18 +0200 | [diff] [blame] | 584 | setline(1, 'abcdefgh') |
| 585 | cursor(1, 4) |
| 586 | assert_equal(4, col('.')) |
| 587 | col([1, '$'])->assert_equal(9) |
| 588 | assert_equal(0, col([10, '$'])) |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 589 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 590 | assert_fails('col(true)', 'E1174:') |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 591 | |
| 592 | CheckDefFailure(['col(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 593 | CheckDefFailure(['col({a: 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>') |
| 594 | CheckDefFailure(['col(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool') |
| 595 | bw! |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 596 | enddef |
| 597 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 598 | def Test_complete() |
| 599 | CheckDefAndScriptFailure2(['complete("1", [])'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 600 | CheckDefAndScriptFailure2(['complete(1, {})'], 'E1013: Argument 2: type mismatch, expected list<any> but got dict<unknown>', 'E1211: List required for argument 2') |
| 601 | enddef |
| 602 | |
| 603 | def Test_complete_add() |
| 604 | CheckDefAndScriptFailure2(['complete_add([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1') |
| 605 | enddef |
| 606 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 607 | def Test_complete_info() |
| 608 | CheckDefFailure(['complete_info("")'], 'E1013: Argument 1: type mismatch, expected list<string> but got string') |
| 609 | CheckDefFailure(['complete_info({})'], 'E1013: Argument 1: type mismatch, expected list<string> but got dict<unknown>') |
| 610 | assert_equal({'pum_visible': 0, 'mode': '', 'selected': -1, 'items': []}, complete_info()) |
| 611 | assert_equal({'mode': '', 'items': []}, complete_info(['mode', 'items'])) |
| 612 | enddef |
| 613 | |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 614 | def Test_confirm() |
| 615 | if !has('dialog_con') && !has('dialog_gui') |
| 616 | CheckFeature dialog_con |
| 617 | endif |
| 618 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 619 | assert_fails('confirm(true)', 'E1174:') |
| 620 | assert_fails('confirm("yes", true)', 'E1174:') |
| 621 | assert_fails('confirm("yes", "maybe", 2, true)', 'E1174:') |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 622 | CheckDefAndScriptFailure2(['confirm(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 623 | CheckDefAndScriptFailure2(['confirm("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 624 | CheckDefAndScriptFailure2(['confirm("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3') |
| 625 | CheckDefAndScriptFailure2(['confirm("a", "b", 3, 4)'], 'E1013: Argument 4: type mismatch, expected string but got number', 'E1174: String required for argument 4') |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 626 | enddef |
| 627 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 628 | def Test_copy_return_type() |
| 629 | var l = copy([1, 2, 3]) |
| 630 | var res = 0 |
| 631 | for n in l |
| 632 | res += n |
| 633 | endfor |
| 634 | res->assert_equal(6) |
| 635 | |
| 636 | var dl = deepcopy([1, 2, 3]) |
| 637 | res = 0 |
| 638 | for n in dl |
| 639 | res += n |
| 640 | endfor |
| 641 | res->assert_equal(6) |
| 642 | |
| 643 | dl = deepcopy([1, 2, 3], true) |
| 644 | enddef |
| 645 | |
| 646 | def Test_count() |
| 647 | count('ABC ABC ABC', 'b', true)->assert_equal(3) |
| 648 | count('ABC ABC ABC', 'b', false)->assert_equal(0) |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 649 | CheckDefAndScriptFailure2(['count(10, 1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 650 | CheckDefAndScriptFailure2(['count("a", [1], 2)'], 'E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3') |
| 651 | CheckDefAndScriptFailure2(['count("a", [1], 0, "b")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4') |
| 652 | count([1, 2, 2, 3], 2)->assert_equal(2) |
| 653 | count([1, 2, 2, 3], 2, false, 2)->assert_equal(1) |
| 654 | count({a: 1.1, b: 2.2, c: 1.1}, 1.1)->assert_equal(2) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 655 | enddef |
| 656 | |
Bram Moolenaar | 9a96337 | 2020-12-21 21:58:46 +0100 | [diff] [blame] | 657 | def Test_cursor() |
| 658 | new |
| 659 | setline(1, range(4)) |
| 660 | cursor(2, 1) |
| 661 | assert_equal(2, getcurpos()[1]) |
| 662 | cursor('$', 1) |
| 663 | assert_equal(4, getcurpos()[1]) |
Yegappan Lakshmanan | cd91720 | 2021-07-21 19:09:09 +0200 | [diff] [blame] | 664 | cursor([2, 1]) |
| 665 | assert_equal(2, getcurpos()[1]) |
Bram Moolenaar | 9a96337 | 2020-12-21 21:58:46 +0100 | [diff] [blame] | 666 | |
| 667 | var lines =<< trim END |
| 668 | cursor('2', 1) |
| 669 | END |
Bram Moolenaar | 0f1227f | 2021-07-11 16:01:58 +0200 | [diff] [blame] | 670 | CheckDefExecAndScriptFailure(lines, 'E1209:') |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 671 | CheckDefAndScriptFailure2(['cursor(0z10, 1)'], 'E1013: Argument 1: type mismatch, expected number but got blob', 'E1210: Number required for argument 1') |
| 672 | CheckDefAndScriptFailure2(['cursor(1, "2")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 673 | CheckDefAndScriptFailure2(['cursor(1, 2, "3")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3') |
Bram Moolenaar | 9a96337 | 2020-12-21 21:58:46 +0100 | [diff] [blame] | 674 | enddef |
| 675 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 676 | def Test_debugbreak() |
| 677 | CheckMSWindows |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 678 | CheckDefFailure(['debugbreak("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 679 | enddef |
| 680 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 681 | def Test_deepcopy() |
| 682 | CheckDefAndScriptFailure2(['deepcopy({}, 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2') |
| 683 | enddef |
| 684 | |
Bram Moolenaar | 3af15ab | 2021-01-17 16:16:23 +0100 | [diff] [blame] | 685 | def Test_delete() |
| 686 | var res: bool = delete('doesnotexist') |
| 687 | assert_equal(true, res) |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 688 | |
| 689 | CheckDefFailure(['delete(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 690 | CheckDefFailure(['delete("a", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
Bram Moolenaar | 3af15ab | 2021-01-17 16:16:23 +0100 | [diff] [blame] | 691 | enddef |
| 692 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 693 | def Test_deletebufline() |
| 694 | CheckDefAndScriptFailure2(['deletebufline([], 2)'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1') |
| 695 | CheckDefAndScriptFailure2(['deletebufline("a", [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2') |
| 696 | CheckDefAndScriptFailure2(['deletebufline("a", 2, 0z10)'], 'E1013: Argument 3: type mismatch, expected string but got blob', 'E1174: String required for argument 3') |
| 697 | enddef |
| 698 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 699 | def Test_diff_filler() |
| 700 | CheckDefFailure(['diff_filler([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') |
| 701 | CheckDefFailure(['diff_filler(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool') |
| 702 | assert_equal(0, diff_filler(1)) |
| 703 | assert_equal(0, diff_filler('.')) |
| 704 | enddef |
| 705 | |
Yegappan Lakshmanan | a9a7c0c | 2021-07-17 19:11:07 +0200 | [diff] [blame] | 706 | def Test_diff_hlID() |
| 707 | CheckDefAndScriptFailure2(['diff_hlID(0z10, 1)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1') |
| 708 | CheckDefAndScriptFailure2(['diff_hlID(1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 709 | enddef |
| 710 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 711 | def Test_echoraw() |
| 712 | CheckDefAndScriptFailure2(['echoraw(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 713 | CheckDefAndScriptFailure2(['echoraw(["x"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E1174: String required for argument 1') |
| 714 | enddef |
| 715 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 716 | def Test_escape() |
| 717 | CheckDefFailure(['escape("a", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 718 | CheckDefFailure(['escape(10, " ")'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 719 | CheckDefFailure(['escape(true, false)'], 'E1013: Argument 1: type mismatch, expected string but got bool') |
| 720 | assert_equal('a\:b', escape("a:b", ":")) |
| 721 | enddef |
| 722 | |
| 723 | def Test_eval() |
| 724 | CheckDefFailure(['eval(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 725 | CheckDefFailure(['eval(null)'], 'E1013: Argument 1: type mismatch, expected string but got special') |
| 726 | assert_equal(2, eval('1 + 1')) |
| 727 | enddef |
| 728 | |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 729 | def Test_executable() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 730 | assert_false(executable("")) |
| 731 | assert_false(executable(test_null_string())) |
| 732 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 733 | CheckDefExecFailure(['echo executable(123)'], 'E1013:') |
| 734 | CheckDefExecFailure(['echo executable(true)'], 'E1013:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 735 | enddef |
| 736 | |
Bram Moolenaar | ca81f0e | 2021-06-20 14:41:01 +0200 | [diff] [blame] | 737 | def Test_execute() |
| 738 | var res = execute("echo 'hello'") |
| 739 | assert_equal("\nhello", res) |
| 740 | res = execute(["echo 'here'", "echo 'there'"]) |
| 741 | assert_equal("\nhere\nthere", res) |
| 742 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 743 | CheckDefFailure(['execute(123)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 744 | CheckDefFailure(['execute([123])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>') |
Bram Moolenaar | ca81f0e | 2021-06-20 14:41:01 +0200 | [diff] [blame] | 745 | CheckDefExecFailure(['echo execute(["xx", 123])'], 'E492') |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 746 | CheckDefFailure(['execute("xx", 123)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
Bram Moolenaar | ca81f0e | 2021-06-20 14:41:01 +0200 | [diff] [blame] | 747 | enddef |
| 748 | |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 749 | def Test_exepath() |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 750 | CheckDefExecFailure(['echo exepath(true)'], 'E1013:') |
| 751 | CheckDefExecFailure(['echo exepath(v:null)'], 'E1013:') |
Bram Moolenaar | fa98441 | 2021-03-25 22:15:28 +0100 | [diff] [blame] | 752 | CheckDefExecFailure(['echo exepath("")'], 'E1175:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 753 | enddef |
| 754 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 755 | def Test_exists() |
| 756 | CheckDefFailure(['exists(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 757 | call assert_equal(1, exists('&tabstop')) |
| 758 | enddef |
| 759 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 760 | def Test_expand() |
| 761 | split SomeFile |
| 762 | expand('%', true, true)->assert_equal(['SomeFile']) |
| 763 | close |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 764 | CheckDefAndScriptFailure2(['expand(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 765 | CheckDefAndScriptFailure2(['expand("a", 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2') |
| 766 | CheckDefAndScriptFailure2(['expand("a", true, 2)'], 'E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 767 | enddef |
| 768 | |
Bram Moolenaar | 0279510 | 2021-05-03 21:40:26 +0200 | [diff] [blame] | 769 | def Test_expandcmd() |
| 770 | $FOO = "blue" |
| 771 | assert_equal("blue sky", expandcmd("`=$FOO .. ' sky'`")) |
| 772 | |
| 773 | assert_equal("yes", expandcmd("`={a: 'yes'}['a']`")) |
| 774 | enddef |
| 775 | |
Bram Moolenaar | fbcbffe | 2020-10-31 19:33:38 +0100 | [diff] [blame] | 776 | def Test_extend_arg_types() |
Bram Moolenaar | c03f5c6 | 2021-01-31 17:48:30 +0100 | [diff] [blame] | 777 | g:number_one = 1 |
| 778 | g:string_keep = 'keep' |
| 779 | var lines =<< trim END |
| 780 | assert_equal([1, 2, 3], extend([1, 2], [3])) |
| 781 | assert_equal([3, 1, 2], extend([1, 2], [3], 0)) |
| 782 | assert_equal([1, 3, 2], extend([1, 2], [3], 1)) |
| 783 | assert_equal([1, 3, 2], extend([1, 2], [3], g:number_one)) |
Bram Moolenaar | fbcbffe | 2020-10-31 19:33:38 +0100 | [diff] [blame] | 784 | |
Bram Moolenaar | c03f5c6 | 2021-01-31 17:48:30 +0100 | [diff] [blame] | 785 | assert_equal({a: 1, b: 2, c: 3}, extend({a: 1, b: 2}, {c: 3})) |
| 786 | assert_equal({a: 1, b: 4}, extend({a: 1, b: 2}, {b: 4})) |
| 787 | assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, 'keep')) |
| 788 | assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, g:string_keep)) |
Bram Moolenaar | 193f620 | 2020-11-16 20:08:35 +0100 | [diff] [blame] | 789 | |
Bram Moolenaar | c03f5c6 | 2021-01-31 17:48:30 +0100 | [diff] [blame] | 790 | var res: list<dict<any>> |
| 791 | extend(res, mapnew([1, 2], (_, v) => ({}))) |
| 792 | assert_equal([{}, {}], res) |
| 793 | END |
| 794 | CheckDefAndScriptSuccess(lines) |
Bram Moolenaar | fbcbffe | 2020-10-31 19:33:38 +0100 | [diff] [blame] | 795 | |
Yegappan Lakshmanan | 34fcb69 | 2021-05-25 20:14:00 +0200 | [diff] [blame] | 796 | CheckDefFailure(['extend("a", 1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got string') |
Bram Moolenaar | fbcbffe | 2020-10-31 19:33:38 +0100 | [diff] [blame] | 797 | CheckDefFailure(['extend([1, 2], 3)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number') |
| 798 | CheckDefFailure(['extend([1, 2], ["x"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>') |
| 799 | CheckDefFailure(['extend([1, 2], [3], "x")'], 'E1013: Argument 3: type mismatch, expected number but got string') |
| 800 | |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 801 | CheckDefFailure(['extend({a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number') |
| 802 | CheckDefFailure(['extend({a: 1}, {b: "x"})'], 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>') |
| 803 | CheckDefFailure(['extend({a: 1}, {b: 2}, 1)'], 'E1013: Argument 3: type mismatch, expected string but got number') |
Bram Moolenaar | 351ead0 | 2021-01-16 16:07:01 +0100 | [diff] [blame] | 804 | |
| 805 | CheckDefFailure(['extend([1], ["b"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>') |
Bram Moolenaar | e32e516 | 2021-01-21 20:21:29 +0100 | [diff] [blame] | 806 | CheckDefExecFailure(['extend([1], ["b", 1])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<any>') |
Bram Moolenaar | 7a3fe3e | 2021-07-22 14:58:47 +0200 | [diff] [blame] | 807 | |
| 808 | CheckScriptFailure(['vim9script', 'extend([1], ["b", 1])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<any> in extend()') |
Bram Moolenaar | fbcbffe | 2020-10-31 19:33:38 +0100 | [diff] [blame] | 809 | enddef |
| 810 | |
Bram Moolenaar | aa210a3 | 2021-01-02 15:41:03 +0100 | [diff] [blame] | 811 | func g:ExtendDict(d) |
| 812 | call extend(a:d, #{xx: 'x'}) |
| 813 | endfunc |
| 814 | |
| 815 | def Test_extend_dict_item_type() |
| 816 | var lines =<< trim END |
| 817 | var d: dict<number> = {a: 1} |
| 818 | extend(d, {b: 2}) |
| 819 | END |
| 820 | CheckDefAndScriptSuccess(lines) |
| 821 | |
| 822 | lines =<< trim END |
| 823 | var d: dict<number> = {a: 1} |
| 824 | extend(d, {b: 'x'}) |
| 825 | END |
Bram Moolenaar | c03f5c6 | 2021-01-31 17:48:30 +0100 | [diff] [blame] | 826 | CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>', 2) |
Bram Moolenaar | aa210a3 | 2021-01-02 15:41:03 +0100 | [diff] [blame] | 827 | |
| 828 | lines =<< trim END |
| 829 | var d: dict<number> = {a: 1} |
| 830 | g:ExtendDict(d) |
| 831 | END |
| 832 | CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string', 0) |
| 833 | CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1) |
| 834 | enddef |
| 835 | |
| 836 | func g:ExtendList(l) |
| 837 | call extend(a:l, ['x']) |
| 838 | endfunc |
| 839 | |
| 840 | def Test_extend_list_item_type() |
| 841 | var lines =<< trim END |
| 842 | var l: list<number> = [1] |
| 843 | extend(l, [2]) |
| 844 | END |
| 845 | CheckDefAndScriptSuccess(lines) |
| 846 | |
| 847 | lines =<< trim END |
| 848 | var l: list<number> = [1] |
| 849 | extend(l, ['x']) |
| 850 | END |
Bram Moolenaar | c03f5c6 | 2021-01-31 17:48:30 +0100 | [diff] [blame] | 851 | CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>', 2) |
Bram Moolenaar | aa210a3 | 2021-01-02 15:41:03 +0100 | [diff] [blame] | 852 | |
| 853 | lines =<< trim END |
| 854 | var l: list<number> = [1] |
| 855 | g:ExtendList(l) |
| 856 | END |
| 857 | CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string', 0) |
| 858 | CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1) |
| 859 | enddef |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 860 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 861 | def Test_extend_return_type() |
| 862 | var l = extend([1, 2], [3]) |
| 863 | var res = 0 |
| 864 | for n in l |
| 865 | res += n |
| 866 | endfor |
| 867 | res->assert_equal(6) |
| 868 | enddef |
| 869 | |
Bram Moolenaar | 93e1cae | 2021-03-13 21:24:56 +0100 | [diff] [blame] | 870 | def Test_extend_with_error_function() |
| 871 | var lines =<< trim END |
| 872 | vim9script |
| 873 | def F() |
| 874 | { |
| 875 | var m = 10 |
| 876 | } |
| 877 | echo m |
| 878 | enddef |
| 879 | |
| 880 | def Test() |
| 881 | var d: dict<any> = {} |
| 882 | d->extend({A: 10, Func: function('F', [])}) |
| 883 | enddef |
| 884 | |
| 885 | Test() |
| 886 | END |
| 887 | CheckScriptFailure(lines, 'E1001: Variable not found: m') |
| 888 | enddef |
| 889 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 890 | def Test_extendnew() |
| 891 | assert_equal([1, 2, 'a'], extendnew([1, 2], ['a'])) |
| 892 | assert_equal({one: 1, two: 'a'}, extendnew({one: 1}, {two: 'a'})) |
| 893 | |
| 894 | CheckDefFailure(['extendnew({a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number') |
| 895 | CheckDefFailure(['extendnew({a: 1}, [42])'], 'E1013: Argument 2: type mismatch, expected dict<number> but got list<number>') |
| 896 | CheckDefFailure(['extendnew([1, 2], "x")'], 'E1013: Argument 2: type mismatch, expected list<number> but got string') |
| 897 | CheckDefFailure(['extendnew([1, 2], {x: 1})'], 'E1013: Argument 2: type mismatch, expected list<number> but got dict<number>') |
| 898 | enddef |
| 899 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 900 | def Test_feedkeys() |
| 901 | CheckDefFailure(['feedkeys(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 902 | CheckDefFailure(['feedkeys("x", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 903 | CheckDefFailure(['feedkeys([], {})'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') |
| 904 | g:TestVar = 1 |
| 905 | feedkeys(":g:TestVar = 789\n", 'xt') |
| 906 | assert_equal(789, g:TestVar) |
| 907 | unlet g:TestVar |
| 908 | enddef |
| 909 | |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 910 | def Test_filereadable() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 911 | assert_false(filereadable("")) |
| 912 | assert_false(filereadable(test_null_string())) |
| 913 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 914 | CheckDefExecFailure(['echo filereadable(123)'], 'E1013:') |
| 915 | CheckDefExecFailure(['echo filereadable(true)'], 'E1013:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 916 | enddef |
| 917 | |
| 918 | def Test_filewritable() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 919 | assert_false(filewritable("")) |
| 920 | assert_false(filewritable(test_null_string())) |
| 921 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 922 | CheckDefExecFailure(['echo filewritable(123)'], 'E1013:') |
| 923 | CheckDefExecFailure(['echo filewritable(true)'], 'E1013:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 924 | enddef |
| 925 | |
| 926 | def Test_finddir() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 927 | CheckDefAndScriptFailure2(['finddir(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1174: String required for argument 1') |
| 928 | CheckDefAndScriptFailure2(['finddir(v:null)'], 'E1013: Argument 1: type mismatch, expected string but got special', 'E1174: String required for argument 1') |
Bram Moolenaar | fa98441 | 2021-03-25 22:15:28 +0100 | [diff] [blame] | 929 | CheckDefExecFailure(['echo finddir("")'], 'E1175:') |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 930 | CheckDefAndScriptFailure2(['finddir("a", [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E730: Using a List as a String') |
| 931 | CheckDefAndScriptFailure2(['finddir("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 932 | enddef |
| 933 | |
| 934 | def Test_findfile() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 935 | CheckDefExecFailure(['findfile(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool') |
| 936 | CheckDefExecFailure(['findfile(v:null)'], 'E1013: Argument 1: type mismatch, expected string but got special') |
| 937 | CheckDefExecFailure(['findfile("")'], 'E1175:') |
| 938 | CheckDefAndScriptFailure2(['findfile("a", [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E730: Using a List as a String') |
| 939 | CheckDefAndScriptFailure2(['findfile("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 940 | enddef |
| 941 | |
Bram Moolenaar | 3b69006 | 2021-02-01 20:14:51 +0100 | [diff] [blame] | 942 | def Test_flattennew() |
| 943 | var lines =<< trim END |
| 944 | var l = [1, [2, [3, 4]], 5] |
| 945 | call assert_equal([1, 2, 3, 4, 5], flattennew(l)) |
| 946 | call assert_equal([1, [2, [3, 4]], 5], l) |
| 947 | |
| 948 | call assert_equal([1, 2, [3, 4], 5], flattennew(l, 1)) |
| 949 | call assert_equal([1, [2, [3, 4]], 5], l) |
| 950 | END |
| 951 | CheckDefAndScriptSuccess(lines) |
| 952 | |
| 953 | lines =<< trim END |
| 954 | echo flatten([1, 2, 3]) |
| 955 | END |
| 956 | CheckDefAndScriptFailure(lines, 'E1158:') |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 957 | CheckDefAndScriptFailure2(['flattennew({})'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<unknown>', 'E1211: List required for argument 1') |
| 958 | CheckDefAndScriptFailure2(['flattennew([], "1")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
Bram Moolenaar | 3b69006 | 2021-02-01 20:14:51 +0100 | [diff] [blame] | 959 | enddef |
| 960 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 961 | " Test for float functions argument type |
| 962 | def Test_float_funcs_args() |
| 963 | CheckFeature float |
| 964 | |
| 965 | # acos() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 966 | CheckDefFailure(['acos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 967 | # asin() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 968 | CheckDefFailure(['asin("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 969 | # atan() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 970 | CheckDefFailure(['atan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 971 | # atan2() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 972 | CheckDefFailure(['atan2("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 973 | CheckDefFailure(['atan2(1.2, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 974 | CheckDefFailure(['atan2(1.2)'], 'E119:') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 975 | # ceil() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 976 | CheckDefFailure(['ceil("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 977 | # cos() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 978 | CheckDefFailure(['cos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 979 | # cosh() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 980 | CheckDefFailure(['cosh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 981 | # exp() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 982 | CheckDefFailure(['exp("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 983 | # float2nr() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 984 | CheckDefFailure(['float2nr("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 985 | # floor() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 986 | CheckDefFailure(['floor("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 987 | # fmod() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 988 | CheckDefFailure(['fmod(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 989 | CheckDefFailure(['fmod("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 990 | CheckDefFailure(['fmod(1.1)'], 'E119:') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 991 | # isinf() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 992 | CheckDefFailure(['isinf("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 993 | # isnan() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 994 | CheckDefFailure(['isnan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 995 | # log() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 996 | CheckDefFailure(['log("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 997 | # log10() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 998 | CheckDefFailure(['log10("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 999 | # pow() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1000 | CheckDefFailure(['pow("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1001 | CheckDefFailure(['pow(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 1002 | CheckDefFailure(['pow(1.1)'], 'E119:') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1003 | # round() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1004 | CheckDefFailure(['round("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1005 | # sin() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1006 | CheckDefFailure(['sin("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1007 | # sinh() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1008 | CheckDefFailure(['sinh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1009 | # sqrt() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1010 | CheckDefFailure(['sqrt("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1011 | # tan() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1012 | CheckDefFailure(['tan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1013 | # tanh() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1014 | CheckDefFailure(['tanh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1015 | # trunc() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1016 | CheckDefFailure(['trunc("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1017 | enddef |
| 1018 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1019 | def Test_fnameescape() |
| 1020 | CheckDefFailure(['fnameescape(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1021 | assert_equal('\+a\%b\|', fnameescape('+a%b|')) |
| 1022 | enddef |
| 1023 | |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 1024 | def Test_fnamemodify() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 1025 | CheckDefSuccess(['echo fnamemodify(test_null_string(), ":p")']) |
| 1026 | CheckDefSuccess(['echo fnamemodify("", ":p")']) |
| 1027 | CheckDefSuccess(['echo fnamemodify("file", test_null_string())']) |
| 1028 | CheckDefSuccess(['echo fnamemodify("file", "")']) |
| 1029 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1030 | CheckDefExecFailure(['echo fnamemodify(true, ":p")'], 'E1013: Argument 1: type mismatch, expected string but got bool') |
| 1031 | CheckDefExecFailure(['echo fnamemodify(v:null, ":p")'], 'E1013: Argument 1: type mismatch, expected string but got special') |
| 1032 | CheckDefExecFailure(['echo fnamemodify("file", true)'], 'E1013: Argument 2: type mismatch, expected string but got bool') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 1033 | enddef |
| 1034 | |
Bram Moolenaar | 2e5910b | 2021-02-03 17:41:24 +0100 | [diff] [blame] | 1035 | def Wrong_dict_key_type(items: list<number>): list<number> |
| 1036 | return filter(items, (_, val) => get({[val]: 1}, 'x')) |
| 1037 | enddef |
| 1038 | |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 1039 | def Test_filter() |
| 1040 | CheckDefAndScriptFailure2(['filter(1.1, "1")'], 'E1013: Argument 1: type mismatch, expected list<any> but got float', 'E1211: List required for argument 1') |
| 1041 | assert_equal([], filter([1, 2, 3], '0')) |
| 1042 | assert_equal([1, 2, 3], filter([1, 2, 3], '1')) |
| 1043 | assert_equal({b: 20}, filter({a: 10, b: 20}, 'v:val == 20')) |
| 1044 | enddef |
| 1045 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1046 | def Test_filter_wrong_dict_key_type() |
Bram Moolenaar | 2e5910b | 2021-02-03 17:41:24 +0100 | [diff] [blame] | 1047 | assert_fails('Wrong_dict_key_type([1, v:null, 3])', 'E1013:') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1048 | enddef |
| 1049 | |
| 1050 | def Test_filter_return_type() |
Bram Moolenaar | bb8a7ce | 2021-04-10 20:10:26 +0200 | [diff] [blame] | 1051 | var l = filter([1, 2, 3], (_, _) => 1) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1052 | var res = 0 |
| 1053 | for n in l |
| 1054 | res += n |
| 1055 | endfor |
| 1056 | res->assert_equal(6) |
| 1057 | enddef |
| 1058 | |
Bram Moolenaar | fc0e8f5 | 2020-12-25 20:24:51 +0100 | [diff] [blame] | 1059 | def Test_filter_missing_argument() |
| 1060 | var dict = {aa: [1], ab: [2], ac: [3], de: [4]} |
Bram Moolenaar | bb8a7ce | 2021-04-10 20:10:26 +0200 | [diff] [blame] | 1061 | var res = dict->filter((k, _) => k =~ 'a' && k !~ 'b') |
Bram Moolenaar | fc0e8f5 | 2020-12-25 20:24:51 +0100 | [diff] [blame] | 1062 | res->assert_equal({aa: [1], ac: [3]}) |
| 1063 | enddef |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1064 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1065 | def Test_foldclosed() |
| 1066 | CheckDefFailure(['foldclosed(function("min"))'], 'E1013: Argument 1: type mismatch, expected string but got func(...): any') |
| 1067 | assert_equal(-1, foldclosed(1)) |
| 1068 | assert_equal(-1, foldclosed('$')) |
| 1069 | enddef |
| 1070 | |
| 1071 | def Test_foldclosedend() |
| 1072 | CheckDefFailure(['foldclosedend(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool') |
| 1073 | assert_equal(-1, foldclosedend(1)) |
| 1074 | assert_equal(-1, foldclosedend('w0')) |
| 1075 | enddef |
| 1076 | |
| 1077 | def Test_foldlevel() |
| 1078 | CheckDefFailure(['foldlevel(0z10)'], 'E1013: Argument 1: type mismatch, expected string but got blob') |
| 1079 | assert_equal(0, foldlevel(1)) |
| 1080 | assert_equal(0, foldlevel('.')) |
| 1081 | enddef |
| 1082 | |
| 1083 | def Test_foldtextresult() |
| 1084 | CheckDefFailure(['foldtextresult(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float') |
| 1085 | assert_equal('', foldtextresult(1)) |
| 1086 | assert_equal('', foldtextresult('.')) |
| 1087 | enddef |
| 1088 | |
Bram Moolenaar | 7d840e9 | 2021-05-26 21:10:11 +0200 | [diff] [blame] | 1089 | def Test_fullcommand() |
| 1090 | assert_equal('next', fullcommand('n')) |
| 1091 | assert_equal('noremap', fullcommand('no')) |
| 1092 | assert_equal('noremap', fullcommand('nor')) |
| 1093 | assert_equal('normal', fullcommand('norm')) |
| 1094 | |
| 1095 | assert_equal('', fullcommand('k')) |
| 1096 | assert_equal('keepmarks', fullcommand('ke')) |
| 1097 | assert_equal('keepmarks', fullcommand('kee')) |
| 1098 | assert_equal('keepmarks', fullcommand('keep')) |
| 1099 | assert_equal('keepjumps', fullcommand('keepj')) |
| 1100 | |
| 1101 | assert_equal('dlist', fullcommand('dl')) |
| 1102 | assert_equal('', fullcommand('dp')) |
| 1103 | assert_equal('delete', fullcommand('del')) |
| 1104 | assert_equal('', fullcommand('dell')) |
| 1105 | assert_equal('', fullcommand('delp')) |
| 1106 | |
| 1107 | assert_equal('srewind', fullcommand('sre')) |
| 1108 | assert_equal('scriptnames', fullcommand('scr')) |
| 1109 | assert_equal('', fullcommand('scg')) |
| 1110 | enddef |
| 1111 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1112 | def Test_garbagecollect() |
| 1113 | garbagecollect(true) |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 1114 | CheckDefAndScriptFailure2(['garbagecollect("1")'], 'E1013: Argument 1: type mismatch, expected bool but got string', 'E1135: Using a String as a Bool') |
| 1115 | CheckDefAndScriptFailure2(['garbagecollect(20)'], 'E1013: Argument 1: type mismatch, expected bool but got number', 'E1023: Using a Number as a Bool') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1116 | enddef |
| 1117 | |
| 1118 | def Test_getbufinfo() |
| 1119 | var bufinfo = getbufinfo(bufnr()) |
| 1120 | getbufinfo('%')->assert_equal(bufinfo) |
| 1121 | |
| 1122 | edit Xtestfile1 |
| 1123 | hide edit Xtestfile2 |
| 1124 | hide enew |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 1125 | getbufinfo({bufloaded: true, buflisted: true, bufmodified: false}) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1126 | ->len()->assert_equal(3) |
| 1127 | bwipe Xtestfile1 Xtestfile2 |
Yegappan Lakshmanan | cd91720 | 2021-07-21 19:09:09 +0200 | [diff] [blame] | 1128 | CheckDefAndScriptFailure2(['getbufinfo(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1174: String required for argument 1') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1129 | enddef |
| 1130 | |
| 1131 | def Test_getbufline() |
| 1132 | e SomeFile |
| 1133 | var buf = bufnr() |
| 1134 | e # |
| 1135 | var lines = ['aaa', 'bbb', 'ccc'] |
| 1136 | setbufline(buf, 1, lines) |
| 1137 | getbufline('#', 1, '$')->assert_equal(lines) |
Bram Moolenaar | e6e70a1 | 2020-10-22 18:23:38 +0200 | [diff] [blame] | 1138 | getbufline(-1, '$', '$')->assert_equal([]) |
| 1139 | getbufline(-1, 1, '$')->assert_equal([]) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1140 | |
| 1141 | bwipe! |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 1142 | CheckDefAndScriptFailure2(['getbufline([], 2)'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1') |
| 1143 | CheckDefAndScriptFailure2(['getbufline("a", [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2') |
| 1144 | CheckDefAndScriptFailure2(['getbufline("a", 2, 0z10)'], 'E1013: Argument 3: type mismatch, expected string but got blob', 'E1174: String required for argument 3') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1145 | enddef |
| 1146 | |
| 1147 | def Test_getchangelist() |
| 1148 | new |
| 1149 | setline(1, 'some text') |
| 1150 | var changelist = bufnr()->getchangelist() |
| 1151 | getchangelist('%')->assert_equal(changelist) |
| 1152 | bwipe! |
| 1153 | enddef |
| 1154 | |
| 1155 | def Test_getchar() |
| 1156 | while getchar(0) |
| 1157 | endwhile |
| 1158 | getchar(true)->assert_equal(0) |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 1159 | getchar(1)->assert_equal(0) |
| 1160 | CheckDefAndScriptFailure2(['getchar(2)'], 'E1013: Argument 1: type mismatch, expected bool but got number', 'E1023: Using a Number as a Bool') |
| 1161 | CheckDefAndScriptFailure2(['getchar("1")'], 'E1013: Argument 1: type mismatch, expected bool but got string', 'E1135: Using a String as a Bool') |
| 1162 | enddef |
| 1163 | |
| 1164 | def Test_getcharpos() |
| 1165 | CheckDefAndScriptFailure2(['getcharpos(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1174: String required for argument 1') |
| 1166 | CheckDefAndScriptFailure2(['getcharpos(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 1167 | enddef |
| 1168 | |
| 1169 | def Test_getcharstr() |
| 1170 | CheckDefAndScriptFailure2(['getcharstr(2)'], 'E1013: Argument 1: type mismatch, expected bool but got number', 'E1023: Using a Number as a Bool') |
| 1171 | CheckDefAndScriptFailure2(['getcharstr("1")'], 'E1013: Argument 1: type mismatch, expected bool but got string', 'E1135: Using a String as a Bool') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1172 | enddef |
| 1173 | |
| 1174 | def Test_getcompletion() |
| 1175 | set wildignore=*.vim,*~ |
| 1176 | var l = getcompletion('run', 'file', true) |
| 1177 | l->assert_equal([]) |
| 1178 | set wildignore& |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 1179 | CheckDefAndScriptFailure2(['getcompletion(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 1180 | CheckDefAndScriptFailure2(['getcompletion("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 1181 | CheckDefAndScriptFailure2(['getcompletion("a", "b", 2)'], 'E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1182 | enddef |
| 1183 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1184 | def Test_getcurpos() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1185 | CheckDefFailure(['getcursorcharpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1186 | enddef |
| 1187 | |
| 1188 | def Test_getcursorcharpos() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1189 | CheckDefFailure(['getcursorcharpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1190 | enddef |
| 1191 | |
| 1192 | def Test_getcwd() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1193 | CheckDefFailure(['getcwd("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1194 | CheckDefFailure(['getcwd("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1195 | CheckDefFailure(['getcwd(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1196 | enddef |
| 1197 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 1198 | def Test_getenv() |
| 1199 | if getenv('does-not_exist') == '' |
| 1200 | assert_report('getenv() should return null') |
| 1201 | endif |
| 1202 | if getenv('does-not_exist') == null |
| 1203 | else |
| 1204 | assert_report('getenv() should return null') |
| 1205 | endif |
| 1206 | $SOMEENVVAR = 'some' |
| 1207 | assert_equal('some', getenv('SOMEENVVAR')) |
| 1208 | unlet $SOMEENVVAR |
| 1209 | enddef |
| 1210 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1211 | def Test_getfontname() |
| 1212 | CheckDefFailure(['getfontname(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1213 | enddef |
| 1214 | |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 1215 | def Test_getfperm() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 1216 | assert_equal('', getfperm("")) |
| 1217 | assert_equal('', getfperm(test_null_string())) |
| 1218 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1219 | CheckDefExecFailure(['echo getfperm(true)'], 'E1013:') |
| 1220 | CheckDefExecFailure(['echo getfperm(v:null)'], 'E1013:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 1221 | enddef |
| 1222 | |
| 1223 | def Test_getfsize() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 1224 | assert_equal(-1, getfsize("")) |
| 1225 | assert_equal(-1, getfsize(test_null_string())) |
| 1226 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1227 | CheckDefExecFailure(['echo getfsize(true)'], 'E1013:') |
| 1228 | CheckDefExecFailure(['echo getfsize(v:null)'], 'E1013:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 1229 | enddef |
| 1230 | |
| 1231 | def Test_getftime() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 1232 | assert_equal(-1, getftime("")) |
| 1233 | assert_equal(-1, getftime(test_null_string())) |
| 1234 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1235 | CheckDefExecFailure(['echo getftime(true)'], 'E1013:') |
| 1236 | CheckDefExecFailure(['echo getftime(v:null)'], 'E1013:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 1237 | enddef |
| 1238 | |
| 1239 | def Test_getftype() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 1240 | assert_equal('', getftype("")) |
| 1241 | assert_equal('', getftype(test_null_string())) |
| 1242 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1243 | CheckDefExecFailure(['echo getftype(true)'], 'E1013:') |
| 1244 | CheckDefExecFailure(['echo getftype(v:null)'], 'E1013:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 1245 | enddef |
| 1246 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1247 | def Test_getjumplist() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1248 | CheckDefFailure(['getjumplist("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1249 | CheckDefFailure(['getjumplist("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1250 | CheckDefFailure(['getjumplist(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1251 | enddef |
| 1252 | |
Bram Moolenaar | 0f1227f | 2021-07-11 16:01:58 +0200 | [diff] [blame] | 1253 | def Test_getline() |
| 1254 | var lines =<< trim END |
| 1255 | new |
| 1256 | setline(1, ['hello', 'there', 'again']) |
| 1257 | assert_equal('hello', getline(1)) |
| 1258 | assert_equal('hello', getline('.')) |
| 1259 | |
| 1260 | normal 2Gvjv |
| 1261 | assert_equal('there', getline("'<")) |
| 1262 | assert_equal('again', getline("'>")) |
| 1263 | END |
| 1264 | CheckDefAndScriptSuccess(lines) |
| 1265 | |
| 1266 | lines =<< trim END |
| 1267 | echo getline('1') |
| 1268 | END |
| 1269 | CheckDefExecAndScriptFailure(lines, 'E1209:') |
Yegappan Lakshmanan | cd91720 | 2021-07-21 19:09:09 +0200 | [diff] [blame] | 1270 | CheckDefAndScriptFailure2(['getline(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1174: String required for argument 1') |
| 1271 | CheckDefAndScriptFailure2(['getline(1, true)'], 'E1013: Argument 2: type mismatch, expected string but got bool', 'E1174: String required for argument 2') |
Bram Moolenaar | 0f1227f | 2021-07-11 16:01:58 +0200 | [diff] [blame] | 1272 | enddef |
| 1273 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 1274 | def Test_getloclist() |
| 1275 | CheckDefAndScriptFailure2(['getloclist("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 1276 | CheckDefAndScriptFailure2(['getloclist(1, [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required') |
| 1277 | enddef |
| 1278 | |
| 1279 | def Test_getloclist_return_type() |
| 1280 | var l = getloclist(1) |
| 1281 | l->assert_equal([]) |
| 1282 | |
| 1283 | var d = getloclist(1, {items: 0}) |
| 1284 | d->assert_equal({items: []}) |
| 1285 | enddef |
| 1286 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1287 | def Test_getmarklist() |
| 1288 | CheckDefFailure(['getmarklist([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') |
| 1289 | assert_equal([], getmarklist(10000)) |
| 1290 | assert_fails('getmarklist("a%b@#")', 'E94:') |
| 1291 | enddef |
| 1292 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1293 | def Test_getmatches() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1294 | CheckDefFailure(['getmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1295 | enddef |
| 1296 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1297 | def Test_getpos() |
| 1298 | CheckDefFailure(['getpos(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1299 | assert_equal([0, 1, 1, 0], getpos('.')) |
Bram Moolenaar | 0f1227f | 2021-07-11 16:01:58 +0200 | [diff] [blame] | 1300 | CheckDefExecFailure(['getpos("a")'], 'E1209:') |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1301 | enddef |
| 1302 | |
| 1303 | def Test_getqflist() |
| 1304 | CheckDefFailure(['getqflist([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>') |
| 1305 | call assert_equal({}, getqflist({})) |
| 1306 | enddef |
| 1307 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1308 | def Test_getqflist_return_type() |
| 1309 | var l = getqflist() |
| 1310 | l->assert_equal([]) |
| 1311 | |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 1312 | var d = getqflist({items: 0}) |
| 1313 | d->assert_equal({items: []}) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1314 | enddef |
| 1315 | |
| 1316 | def Test_getreg() |
| 1317 | var lines = ['aaa', 'bbb', 'ccc'] |
| 1318 | setreg('a', lines) |
| 1319 | getreg('a', true, true)->assert_equal(lines) |
Bram Moolenaar | 418a29f | 2021-02-10 22:23:41 +0100 | [diff] [blame] | 1320 | assert_fails('getreg("ab")', 'E1162:') |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 1321 | CheckDefAndScriptFailure2(['getreg(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 1322 | CheckDefAndScriptFailure2(['getreg(".", 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2') |
| 1323 | CheckDefAndScriptFailure2(['getreg(".", 1, "b")'], 'E1013: Argument 3: type mismatch, expected bool but got string', 'E1212: Bool required for argument 3') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1324 | enddef |
| 1325 | |
| 1326 | def Test_getreg_return_type() |
| 1327 | var s1: string = getreg('"') |
| 1328 | var s2: string = getreg('"', 1) |
| 1329 | var s3: list<string> = getreg('"', 1, 1) |
| 1330 | enddef |
| 1331 | |
Bram Moolenaar | 418a29f | 2021-02-10 22:23:41 +0100 | [diff] [blame] | 1332 | def Test_getreginfo() |
| 1333 | var text = 'abc' |
| 1334 | setreg('a', text) |
| 1335 | getreginfo('a')->assert_equal({regcontents: [text], regtype: 'v', isunnamed: false}) |
| 1336 | assert_fails('getreginfo("ab")', 'E1162:') |
| 1337 | enddef |
| 1338 | |
| 1339 | def Test_getregtype() |
| 1340 | var lines = ['aaa', 'bbb', 'ccc'] |
| 1341 | setreg('a', lines) |
| 1342 | getregtype('a')->assert_equal('V') |
| 1343 | assert_fails('getregtype("ab")', 'E1162:') |
| 1344 | enddef |
| 1345 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1346 | def Test_gettabinfo() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1347 | CheckDefFailure(['gettabinfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1348 | enddef |
| 1349 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 1350 | def Test_gettabvar() |
| 1351 | CheckDefAndScriptFailure2(['gettabvar("a", "b")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 1352 | CheckDefAndScriptFailure2(['gettabvar(1, 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 1353 | enddef |
| 1354 | |
| 1355 | def Test_gettabwinvar() |
| 1356 | CheckDefAndScriptFailure2(['gettabwinvar("a", 2, "c")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 1357 | CheckDefAndScriptFailure2(['gettabwinvar(1, "b", "c", [])'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 1358 | CheckDefAndScriptFailure2(['gettabwinvar(1, 1, 3, {})'], 'E1013: Argument 3: type mismatch, expected string but got number', 'E1174: String required for argument 3') |
| 1359 | enddef |
| 1360 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1361 | def Test_gettagstack() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1362 | CheckDefFailure(['gettagstack("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1363 | enddef |
| 1364 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1365 | def Test_gettext() |
| 1366 | CheckDefFailure(['gettext(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1367 | assert_equal('abc', gettext("abc")) |
| 1368 | enddef |
| 1369 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1370 | def Test_getwininfo() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1371 | CheckDefFailure(['getwininfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1372 | enddef |
| 1373 | |
| 1374 | def Test_getwinpos() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1375 | CheckDefFailure(['getwinpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1376 | enddef |
| 1377 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 1378 | def Test_getwinvar() |
| 1379 | CheckDefAndScriptFailure2(['getwinvar("a", "b")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 1380 | CheckDefAndScriptFailure2(['getwinvar(1, 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 1381 | enddef |
| 1382 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1383 | def Test_glob() |
| 1384 | glob('runtest.vim', true, true, true)->assert_equal(['runtest.vim']) |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 1385 | CheckDefAndScriptFailure2(['glob(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 1386 | CheckDefAndScriptFailure2(['glob("a", 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2') |
| 1387 | CheckDefAndScriptFailure2(['glob("a", 1, "b")'], 'E1013: Argument 3: type mismatch, expected bool but got string', 'E1212: Bool required for argument 3') |
| 1388 | CheckDefAndScriptFailure2(['glob("a", 1, true, 2)'], 'E1013: Argument 4: type mismatch, expected bool but got number', 'E1212: Bool required for argument 4') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1389 | enddef |
| 1390 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1391 | def Test_glob2regpat() |
| 1392 | CheckDefFailure(['glob2regpat(null)'], 'E1013: Argument 1: type mismatch, expected string but got special') |
| 1393 | assert_equal('^$', glob2regpat('')) |
| 1394 | enddef |
| 1395 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1396 | def Test_globpath() |
| 1397 | globpath('.', 'runtest.vim', true, true, true)->assert_equal(['./runtest.vim']) |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 1398 | CheckDefAndScriptFailure2(['globpath(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 1399 | CheckDefAndScriptFailure2(['globpath("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 1400 | CheckDefAndScriptFailure2(['globpath("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected bool but got string', 'E1212: Bool required for argument 3') |
| 1401 | CheckDefAndScriptFailure2(['globpath("a", "b", true, "d")'], 'E1013: Argument 4: type mismatch, expected bool but got string', 'E1212: Bool required for argument 4') |
| 1402 | CheckDefAndScriptFailure2(['globpath("a", "b", true, false, "e")'], 'E1013: Argument 5: type mismatch, expected bool but got string', 'E1212: Bool required for argument 5') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1403 | enddef |
| 1404 | |
| 1405 | def Test_has() |
| 1406 | has('eval', true)->assert_equal(1) |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 1407 | CheckDefAndScriptFailure2(['has(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E1174: String required for argument 1') |
| 1408 | CheckDefAndScriptFailure2(['has("a", "b")'], 'E1013: Argument 2: type mismatch, expected bool but got string', 'E1212: Bool required for argument 2') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1409 | enddef |
| 1410 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1411 | def Test_has_key() |
Bram Moolenaar | 1aeddeb | 2021-07-11 14:55:49 +0200 | [diff] [blame] | 1412 | var d = {123: 'xx'} |
| 1413 | assert_true(has_key(d, '123')) |
| 1414 | assert_true(has_key(d, 123)) |
| 1415 | assert_false(has_key(d, 'x')) |
| 1416 | assert_false(has_key(d, 99)) |
| 1417 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1418 | CheckDefAndScriptFailure2(['has_key([1, 2], "k")'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required') |
| 1419 | CheckDefAndScriptFailure2(['has_key({"a": 10}, ["a"])'], 'E1013: Argument 2: type mismatch, expected string but got list<string>', 'E730: Using a List as a String') |
| 1420 | enddef |
| 1421 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1422 | def Test_haslocaldir() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1423 | CheckDefFailure(['haslocaldir("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1424 | CheckDefFailure(['haslocaldir("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1425 | CheckDefFailure(['haslocaldir(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1426 | enddef |
| 1427 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1428 | def Test_hasmapto() |
| 1429 | hasmapto('foobar', 'i', true)->assert_equal(0) |
| 1430 | iabbrev foo foobar |
| 1431 | hasmapto('foobar', 'i', true)->assert_equal(1) |
| 1432 | iunabbrev foo |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 1433 | CheckDefAndScriptFailure2(['hasmapto(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 1434 | CheckDefAndScriptFailure2(['hasmapto("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 1435 | CheckDefAndScriptFailure2(['hasmapto("a", "b", 2)'], 'E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1436 | enddef |
| 1437 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1438 | def Test_histadd() |
| 1439 | CheckDefFailure(['histadd(1, "x")'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1440 | CheckDefFailure(['histadd(":", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 1441 | histadd("search", 'skyblue') |
| 1442 | assert_equal('skyblue', histget('/', -1)) |
| 1443 | enddef |
| 1444 | |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 1445 | def Test_histdel() |
| 1446 | CheckDefAndScriptFailure2(['histdel(1, "x")'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 1447 | CheckDefAndScriptFailure2(['histdel(":", true)'], 'E1013: Argument 2: type mismatch, expected string but got bool', 'E1174: String required for argument 2') |
| 1448 | enddef |
| 1449 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 1450 | def Test_histget() |
| 1451 | CheckDefAndScriptFailure2(['histget(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 1452 | CheckDefAndScriptFailure2(['histget("a", "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 1453 | enddef |
| 1454 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1455 | def Test_histnr() |
| 1456 | CheckDefFailure(['histnr(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1457 | assert_equal(-1, histnr('abc')) |
| 1458 | enddef |
| 1459 | |
| 1460 | def Test_hlID() |
| 1461 | CheckDefFailure(['hlID(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1462 | assert_equal(0, hlID('NonExistingHighlight')) |
| 1463 | enddef |
| 1464 | |
| 1465 | def Test_hlexists() |
| 1466 | CheckDefFailure(['hlexists([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') |
| 1467 | assert_equal(0, hlexists('NonExistingHighlight')) |
| 1468 | enddef |
| 1469 | |
| 1470 | def Test_iconv() |
| 1471 | CheckDefFailure(['iconv(1, "from", "to")'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1472 | CheckDefFailure(['iconv("abc", 10, "to")'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 1473 | CheckDefFailure(['iconv("abc", "from", 20)'], 'E1013: Argument 3: type mismatch, expected string but got number') |
| 1474 | assert_equal('abc', iconv('abc', 'fromenc', 'toenc')) |
| 1475 | enddef |
| 1476 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 1477 | def Test_indent() |
| 1478 | CheckDefAndScriptFailure2(['indent([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E745: Using a List as a Number') |
| 1479 | CheckDefAndScriptFailure2(['indent(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1138: Using a Bool as a Number') |
| 1480 | assert_equal(0, indent(1)) |
| 1481 | enddef |
| 1482 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1483 | def Test_index() |
| 1484 | index(['a', 'b', 'a', 'B'], 'b', 2, true)->assert_equal(3) |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 1485 | CheckDefAndScriptFailure2(['index("a", "a")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E1211: List required for argument 1') |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 1486 | CheckDefFailure(['index(["1"], 1)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 1487 | CheckDefAndScriptFailure2(['index(0z10, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 1488 | CheckDefAndScriptFailure2(['index([1], 1, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3') |
| 1489 | CheckDefAndScriptFailure2(['index(0z1020, 10, 1, 2)'], 'E1013: Argument 4: type mismatch, expected bool but got number', 'E1212: Bool required for argument 4') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1490 | enddef |
| 1491 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 1492 | def Test_input() |
| 1493 | CheckDefFailure(['input(5)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1494 | CheckDefAndScriptFailure2(['input(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String') |
| 1495 | CheckDefFailure(['input("p", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 1496 | CheckDefAndScriptFailure2(['input("p", "q", 20)'], 'E1013: Argument 3: type mismatch, expected string but got number', 'E180: Invalid complete value') |
| 1497 | enddef |
| 1498 | |
| 1499 | def Test_inputdialog() |
| 1500 | CheckDefFailure(['inputdialog(5)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1501 | CheckDefAndScriptFailure2(['inputdialog(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String') |
| 1502 | CheckDefFailure(['inputdialog("p", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 1503 | CheckDefFailure(['inputdialog("p", "q", 20)'], 'E1013: Argument 3: type mismatch, expected string but got number') |
| 1504 | enddef |
| 1505 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1506 | def Test_inputlist() |
| 1507 | CheckDefFailure(['inputlist(10)'], 'E1013: Argument 1: type mismatch, expected list<string> but got number') |
| 1508 | CheckDefFailure(['inputlist("abc")'], 'E1013: Argument 1: type mismatch, expected list<string> but got string') |
| 1509 | CheckDefFailure(['inputlist([1, 2, 3])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>') |
| 1510 | feedkeys("2\<CR>", 't') |
| 1511 | var r: number = inputlist(['a', 'b', 'c']) |
| 1512 | assert_equal(2, r) |
| 1513 | enddef |
| 1514 | |
| 1515 | def Test_inputsecret() |
| 1516 | CheckDefFailure(['inputsecret(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1517 | CheckDefFailure(['inputsecret("Pass:", 20)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 1518 | feedkeys("\<CR>", 't') |
| 1519 | var ans: string = inputsecret('Pass:', '123') |
| 1520 | assert_equal('123', ans) |
| 1521 | enddef |
| 1522 | |
Bram Moolenaar | 193f620 | 2020-11-16 20:08:35 +0100 | [diff] [blame] | 1523 | let s:number_one = 1 |
| 1524 | let s:number_two = 2 |
| 1525 | let s:string_keep = 'keep' |
| 1526 | |
Bram Moolenaar | ca17453 | 2020-10-21 16:42:22 +0200 | [diff] [blame] | 1527 | def Test_insert() |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1528 | var l = insert([2, 1], 3) |
| 1529 | var res = 0 |
| 1530 | for n in l |
| 1531 | res += n |
| 1532 | endfor |
| 1533 | res->assert_equal(6) |
Bram Moolenaar | ca17453 | 2020-10-21 16:42:22 +0200 | [diff] [blame] | 1534 | |
Yegappan Lakshmanan | 34fcb69 | 2021-05-25 20:14:00 +0200 | [diff] [blame] | 1535 | var m: any = [] |
| 1536 | insert(m, 4) |
| 1537 | call assert_equal([4], m) |
| 1538 | extend(m, [6], 0) |
| 1539 | call assert_equal([6, 4], m) |
| 1540 | |
Bram Moolenaar | 39211cb | 2021-04-18 15:48:04 +0200 | [diff] [blame] | 1541 | var lines =<< trim END |
| 1542 | insert(test_null_list(), 123) |
| 1543 | END |
| 1544 | CheckDefExecAndScriptFailure(lines, 'E1130:', 1) |
| 1545 | |
| 1546 | lines =<< trim END |
| 1547 | insert(test_null_blob(), 123) |
| 1548 | END |
| 1549 | CheckDefExecAndScriptFailure(lines, 'E1131:', 1) |
| 1550 | |
Bram Moolenaar | ca17453 | 2020-10-21 16:42:22 +0200 | [diff] [blame] | 1551 | assert_equal([1, 2, 3], insert([2, 3], 1)) |
Bram Moolenaar | 193f620 | 2020-11-16 20:08:35 +0100 | [diff] [blame] | 1552 | assert_equal([1, 2, 3], insert([2, 3], s:number_one)) |
Bram Moolenaar | ca17453 | 2020-10-21 16:42:22 +0200 | [diff] [blame] | 1553 | assert_equal([1, 2, 3], insert([1, 2], 3, 2)) |
Bram Moolenaar | 193f620 | 2020-11-16 20:08:35 +0100 | [diff] [blame] | 1554 | assert_equal([1, 2, 3], insert([1, 2], 3, s:number_two)) |
Bram Moolenaar | ca17453 | 2020-10-21 16:42:22 +0200 | [diff] [blame] | 1555 | assert_equal(['a', 'b', 'c'], insert(['b', 'c'], 'a')) |
| 1556 | assert_equal(0z1234, insert(0z34, 0x12)) |
Bram Moolenaar | 193f620 | 2020-11-16 20:08:35 +0100 | [diff] [blame] | 1557 | |
Yegappan Lakshmanan | 34fcb69 | 2021-05-25 20:14:00 +0200 | [diff] [blame] | 1558 | CheckDefFailure(['insert("a", 1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 1) |
Bram Moolenaar | ca17453 | 2020-10-21 16:42:22 +0200 | [diff] [blame] | 1559 | CheckDefFailure(['insert([2, 3], "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 1) |
| 1560 | CheckDefFailure(['insert([2, 3], 1, "x")'], 'E1013: Argument 3: type mismatch, expected number but got string', 1) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1561 | enddef |
| 1562 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1563 | def Test_invert() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1564 | CheckDefFailure(['invert("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1565 | enddef |
| 1566 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1567 | def Test_isdirectory() |
| 1568 | CheckDefFailure(['isdirectory(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float') |
| 1569 | assert_false(isdirectory('NonExistingDir')) |
| 1570 | enddef |
| 1571 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 1572 | def Test_islocked() |
| 1573 | CheckDefAndScriptFailure2(['islocked(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1174: String required for argument 1') |
| 1574 | CheckDefAndScriptFailure2(['var n1: number = 10', 'islocked(n1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 1575 | g:v1 = 10 |
| 1576 | assert_false(islocked('g:v1')) |
| 1577 | lockvar g:v1 |
| 1578 | assert_true(islocked('g:v1')) |
| 1579 | unlet g:v1 |
| 1580 | enddef |
| 1581 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1582 | def Test_items() |
| 1583 | CheckDefFailure(['[]->items()'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>') |
| 1584 | assert_equal([['a', 10], ['b', 20]], {'a': 10, 'b': 20}->items()) |
| 1585 | assert_equal([], {}->items()) |
| 1586 | enddef |
| 1587 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 1588 | def Test_job_getchannel() |
Dominique Pelle | 9ff9c7b | 2021-07-18 21:44:37 +0200 | [diff] [blame] | 1589 | if !has('job') |
| 1590 | CheckFeature job |
| 1591 | else |
| 1592 | CheckDefAndScriptFailure2(['job_getchannel("a")'], 'E1013: Argument 1: type mismatch, expected job but got string', 'E475: Invalid argument') |
| 1593 | assert_fails('job_getchannel(test_null_job())', 'E916: not a valid job') |
| 1594 | endif |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 1595 | enddef |
| 1596 | |
| 1597 | def Test_job_info() |
Dominique Pelle | 9ff9c7b | 2021-07-18 21:44:37 +0200 | [diff] [blame] | 1598 | if !has('job') |
| 1599 | CheckFeature job |
| 1600 | else |
| 1601 | CheckDefAndScriptFailure2(['job_info("a")'], 'E1013: Argument 1: type mismatch, expected job but got string', 'E475: Invalid argument') |
| 1602 | assert_fails('job_info(test_null_job())', 'E916: not a valid job') |
| 1603 | endif |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 1604 | enddef |
| 1605 | |
| 1606 | def Test_job_info_return_type() |
Dominique Pelle | 9ff9c7b | 2021-07-18 21:44:37 +0200 | [diff] [blame] | 1607 | if !has('job') |
| 1608 | CheckFeature job |
| 1609 | else |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 1610 | job_start(&shell) |
| 1611 | var jobs = job_info() |
| 1612 | assert_equal('list<job>', typename(jobs)) |
| 1613 | assert_equal('dict<any>', typename(job_info(jobs[0]))) |
| 1614 | job_stop(jobs[0]) |
| 1615 | endif |
| 1616 | enddef |
| 1617 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 1618 | def Test_job_setoptions() |
| 1619 | if !has('job') |
| 1620 | CheckFeature job |
| 1621 | else |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 1622 | CheckDefAndScriptFailure2(['job_setoptions(test_null_channel(), {})'], 'E1013: Argument 1: type mismatch, expected job but got channel', 'E1218: Job required for argument 1') |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 1623 | CheckDefAndScriptFailure2(['job_setoptions(test_null_job(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 2') |
| 1624 | assert_equal('fail', job_status(test_null_job())) |
| 1625 | endif |
| 1626 | enddef |
| 1627 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 1628 | def Test_job_status() |
Dominique Pelle | 9ff9c7b | 2021-07-18 21:44:37 +0200 | [diff] [blame] | 1629 | if !has('job') |
| 1630 | CheckFeature job |
| 1631 | else |
| 1632 | CheckDefAndScriptFailure2(['job_status("a")'], 'E1013: Argument 1: type mismatch, expected job but got string', 'E475: Invalid argument') |
| 1633 | assert_equal('fail', job_status(test_null_job())) |
| 1634 | endif |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 1635 | enddef |
| 1636 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 1637 | def Test_job_stop() |
| 1638 | if !has('job') |
| 1639 | CheckFeature job |
| 1640 | else |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 1641 | CheckDefAndScriptFailure2(['job_stop("a")'], 'E1013: Argument 1: type mismatch, expected job but got string', 'E1218: Job required for argument 1') |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 1642 | CheckDefAndScriptFailure2(['job_stop(test_null_job(), true)'], 'E1013: Argument 2: type mismatch, expected string but got bool', 'E1174: String required for argument 2') |
| 1643 | endif |
| 1644 | enddef |
| 1645 | |
| 1646 | def Test_join() |
| 1647 | CheckDefAndScriptFailure2(['join("abc")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E1211: List required for argument 1') |
| 1648 | CheckDefAndScriptFailure2(['join([], 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 1649 | enddef |
| 1650 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1651 | def Test_js_decode() |
| 1652 | CheckDefFailure(['js_decode(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1653 | assert_equal([1, 2], js_decode('[1,2]')) |
| 1654 | enddef |
| 1655 | |
| 1656 | def Test_json_decode() |
| 1657 | CheckDefFailure(['json_decode(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool') |
| 1658 | assert_equal(1.0, json_decode('1.0')) |
| 1659 | enddef |
| 1660 | |
| 1661 | def Test_keys() |
| 1662 | CheckDefFailure(['keys([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>') |
| 1663 | assert_equal(['a'], {a: 'v'}->keys()) |
| 1664 | assert_equal([], {}->keys()) |
| 1665 | enddef |
| 1666 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1667 | def Test_keys_return_type() |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 1668 | const var: list<string> = {a: 1, b: 2}->keys() |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1669 | var->assert_equal(['a', 'b']) |
| 1670 | enddef |
| 1671 | |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 1672 | def Test_line() |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1673 | assert_fails('line(true)', 'E1174:') |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 1674 | CheckDefAndScriptFailure2(['line(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 1675 | CheckDefAndScriptFailure2(['line(".", "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1676 | enddef |
| 1677 | |
| 1678 | def Test_line2byte() |
| 1679 | CheckDefFailure(['line2byte(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool') |
| 1680 | assert_equal(-1, line2byte(1)) |
| 1681 | assert_equal(-1, line2byte(10000)) |
| 1682 | enddef |
| 1683 | |
| 1684 | def Test_lispindent() |
| 1685 | CheckDefFailure(['lispindent({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>') |
| 1686 | assert_equal(0, lispindent(1)) |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 1687 | enddef |
| 1688 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1689 | def Test_list2str_str2list_utf8() |
| 1690 | var s = "\u3042\u3044" |
| 1691 | var l = [0x3042, 0x3044] |
| 1692 | str2list(s, true)->assert_equal(l) |
| 1693 | list2str(l, true)->assert_equal(s) |
| 1694 | enddef |
| 1695 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 1696 | def Test_list2str() |
| 1697 | CheckDefAndScriptFailure2(['list2str(".", true)'], 'E1013: Argument 1: type mismatch, expected list<number> but got string', 'E1211: List required for argument 1') |
| 1698 | CheckDefAndScriptFailure2(['list2str([1], 0z10)'], 'E1013: Argument 2: type mismatch, expected bool but got blob', 'E1212: Bool required for argument 2') |
| 1699 | enddef |
| 1700 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1701 | def SID(): number |
| 1702 | return expand('<SID>') |
| 1703 | ->matchstr('<SNR>\zs\d\+\ze_$') |
| 1704 | ->str2nr() |
| 1705 | enddef |
| 1706 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1707 | def Test_listener_flush() |
| 1708 | CheckDefAndScriptFailure2(['listener_flush([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String') |
| 1709 | enddef |
| 1710 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1711 | def Test_listener_remove() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1712 | CheckDefAndScriptFailure2(['listener_remove("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1713 | enddef |
| 1714 | |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 1715 | def Test_map() |
| 1716 | CheckDefAndScriptFailure2(['map("x", "1")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E1211: List required for argument 1') |
| 1717 | CheckDefAndScriptFailure2(['map(1, "1")'], 'E1013: Argument 1: type mismatch, expected list<any> but got number', 'E1211: List required for argument 1') |
| 1718 | enddef |
| 1719 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 1720 | def Test_map_failure() |
| 1721 | CheckFeature job |
| 1722 | |
| 1723 | var lines =<< trim END |
| 1724 | vim9script |
| 1725 | writefile([], 'Xtmpfile') |
| 1726 | silent e Xtmpfile |
| 1727 | var d = {[bufnr('%')]: {a: 0}} |
| 1728 | au BufReadPost * Func() |
| 1729 | def Func() |
| 1730 | if d->has_key('') |
| 1731 | endif |
| 1732 | eval d[expand('<abuf>')]->mapnew((_, v: dict<job>) => 0) |
| 1733 | enddef |
| 1734 | e |
| 1735 | END |
| 1736 | CheckScriptFailure(lines, 'E1013:') |
| 1737 | au! BufReadPost |
| 1738 | delete('Xtmpfile') |
| 1739 | enddef |
| 1740 | |
Bram Moolenaar | 70250fb | 2021-01-16 19:01:53 +0100 | [diff] [blame] | 1741 | def Test_map_function_arg() |
| 1742 | var lines =<< trim END |
| 1743 | def MapOne(i: number, v: string): string |
| 1744 | return i .. ':' .. v |
| 1745 | enddef |
| 1746 | var l = ['a', 'b', 'c'] |
| 1747 | map(l, MapOne) |
| 1748 | assert_equal(['0:a', '1:b', '2:c'], l) |
| 1749 | END |
| 1750 | CheckDefAndScriptSuccess(lines) |
Bram Moolenaar | 8da6d6d | 2021-06-05 18:15:09 +0200 | [diff] [blame] | 1751 | |
| 1752 | lines =<< trim END |
| 1753 | range(3)->map((a, b, c) => a + b + c) |
| 1754 | END |
| 1755 | CheckDefExecAndScriptFailure(lines, 'E1190: One argument too few') |
| 1756 | lines =<< trim END |
| 1757 | range(3)->map((a, b, c, d) => a + b + c + d) |
| 1758 | END |
| 1759 | CheckDefExecAndScriptFailure(lines, 'E1190: 2 arguments too few') |
Bram Moolenaar | 70250fb | 2021-01-16 19:01:53 +0100 | [diff] [blame] | 1760 | enddef |
| 1761 | |
| 1762 | def Test_map_item_type() |
| 1763 | var lines =<< trim END |
| 1764 | var l = ['a', 'b', 'c'] |
| 1765 | map(l, (k, v) => k .. '/' .. v ) |
| 1766 | assert_equal(['0/a', '1/b', '2/c'], l) |
| 1767 | END |
| 1768 | CheckDefAndScriptSuccess(lines) |
| 1769 | |
| 1770 | lines =<< trim END |
| 1771 | var l: list<number> = [0] |
| 1772 | echo map(l, (_, v) => []) |
| 1773 | END |
Bram Moolenaar | 7a3fe3e | 2021-07-22 14:58:47 +0200 | [diff] [blame] | 1774 | CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown> in map()', 2) |
Bram Moolenaar | 70250fb | 2021-01-16 19:01:53 +0100 | [diff] [blame] | 1775 | |
| 1776 | lines =<< trim END |
| 1777 | var l: list<number> = range(2) |
| 1778 | echo map(l, (_, v) => []) |
| 1779 | END |
Bram Moolenaar | 7a3fe3e | 2021-07-22 14:58:47 +0200 | [diff] [blame] | 1780 | CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown> in map()', 2) |
Bram Moolenaar | 70250fb | 2021-01-16 19:01:53 +0100 | [diff] [blame] | 1781 | |
| 1782 | lines =<< trim END |
| 1783 | var d: dict<number> = {key: 0} |
| 1784 | echo map(d, (_, v) => []) |
| 1785 | END |
Bram Moolenaar | 7a3fe3e | 2021-07-22 14:58:47 +0200 | [diff] [blame] | 1786 | CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown> in map()', 2) |
Bram Moolenaar | 70250fb | 2021-01-16 19:01:53 +0100 | [diff] [blame] | 1787 | enddef |
| 1788 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1789 | def Test_maparg() |
| 1790 | var lnum = str2nr(expand('<sflnum>')) |
| 1791 | map foo bar |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 1792 | maparg('foo', '', false, true)->assert_equal({ |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1793 | lnum: lnum + 1, |
| 1794 | script: 0, |
| 1795 | mode: ' ', |
| 1796 | silent: 0, |
| 1797 | noremap: 0, |
| 1798 | lhs: 'foo', |
| 1799 | lhsraw: 'foo', |
| 1800 | nowait: 0, |
| 1801 | expr: 0, |
| 1802 | sid: SID(), |
| 1803 | rhs: 'bar', |
| 1804 | buffer: 0}) |
| 1805 | unmap foo |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 1806 | CheckDefAndScriptFailure2(['maparg(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 1807 | CheckDefAndScriptFailure2(['maparg("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 1808 | CheckDefAndScriptFailure2(['maparg("a", "b", 2)'], 'E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3') |
| 1809 | CheckDefAndScriptFailure2(['maparg("a", "b", true, 2)'], 'E1013: Argument 4: type mismatch, expected bool but got number', 'E1212: Bool required for argument 4') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1810 | enddef |
| 1811 | |
| 1812 | def Test_maparg_mapset() |
| 1813 | nnoremap <F3> :echo "hit F3"<CR> |
| 1814 | var mapsave = maparg('<F3>', 'n', false, true) |
| 1815 | mapset('n', false, mapsave) |
| 1816 | |
| 1817 | nunmap <F3> |
| 1818 | enddef |
| 1819 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 1820 | def Test_mapcheck() |
| 1821 | iabbrev foo foobar |
| 1822 | mapcheck('foo', 'i', true)->assert_equal('foobar') |
| 1823 | iunabbrev foo |
| 1824 | CheckDefAndScriptFailure2(['mapcheck(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 1825 | CheckDefAndScriptFailure2(['mapcheck("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 1826 | CheckDefAndScriptFailure2(['mapcheck("a", "b", 2)'], 'E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3') |
| 1827 | enddef |
Bram Moolenaar | 027c4ab | 2021-02-21 16:20:18 +0100 | [diff] [blame] | 1828 | |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 1829 | def Test_mapnew() |
| 1830 | CheckDefAndScriptFailure2(['mapnew("x", "1")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E1211: List required for argument 1') |
| 1831 | CheckDefAndScriptFailure2(['mapnew(1, "1")'], 'E1013: Argument 1: type mismatch, expected list<any> but got number', 'E1211: List required for argument 1') |
| 1832 | enddef |
| 1833 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 1834 | def Test_mapset() |
| 1835 | CheckDefAndScriptFailure2(['mapset(1, true, {})'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 1836 | CheckDefAndScriptFailure2(['mapset("a", 2, {})'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2') |
| 1837 | CheckDefAndScriptFailure2(['mapset("a", false, [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3') |
Bram Moolenaar | 027c4ab | 2021-02-21 16:20:18 +0100 | [diff] [blame] | 1838 | enddef |
| 1839 | |
Yegappan Lakshmanan | a9a7c0c | 2021-07-17 19:11:07 +0200 | [diff] [blame] | 1840 | def Test_match() |
| 1841 | CheckDefAndScriptFailure2(['match(0z12, "p")'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1') |
| 1842 | CheckDefAndScriptFailure2(['match(["s"], [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E1174: String required for argument 2') |
| 1843 | CheckDefAndScriptFailure2(['match("s", "p", "q")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3') |
| 1844 | CheckDefAndScriptFailure2(['match("s", "p", 1, "r")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4') |
| 1845 | assert_equal(2, match('ab12cd', '12')) |
| 1846 | assert_equal(-1, match('ab12cd', '34')) |
| 1847 | assert_equal(6, match('ab12cd12ef', '12', 4)) |
| 1848 | assert_equal(2, match('abcd', '..', 0, 3)) |
| 1849 | assert_equal(1, match(['a', 'b', 'c'], 'b')) |
| 1850 | assert_equal(-1, match(['a', 'b', 'c'], 'd')) |
| 1851 | assert_equal(3, match(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2)) |
| 1852 | assert_equal(5, match(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2, 2)) |
| 1853 | enddef |
| 1854 | |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 1855 | def Test_matchadd() |
| 1856 | CheckDefAndScriptFailure2(['matchadd(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 1857 | CheckDefAndScriptFailure2(['matchadd("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 1858 | CheckDefAndScriptFailure2(['matchadd("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3') |
| 1859 | CheckDefAndScriptFailure2(['matchadd("a", "b", 1, "d")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4') |
| 1860 | CheckDefAndScriptFailure2(['matchadd("a", "b", 1, 1, [])'], 'E1013: Argument 5: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 5') |
| 1861 | enddef |
| 1862 | |
| 1863 | def Test_matchaddpos() |
| 1864 | CheckDefAndScriptFailure2(['matchaddpos(1, [1])'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 1865 | CheckDefAndScriptFailure2(['matchaddpos("a", "b")'], 'E1013: Argument 2: type mismatch, expected list<number> but got string', 'E1211: List required for argument 2') |
| 1866 | CheckDefFailure(['matchaddpos("a", ["2"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>') |
| 1867 | CheckDefAndScriptFailure2(['matchaddpos("a", [1], "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3') |
| 1868 | CheckDefAndScriptFailure2(['matchaddpos("a", [1], 1, "d")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4') |
| 1869 | CheckDefAndScriptFailure2(['matchaddpos("a", [1], 1, 1, [])'], 'E1013: Argument 5: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 5') |
| 1870 | enddef |
| 1871 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1872 | def Test_matcharg() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1873 | CheckDefFailure(['matcharg("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1874 | enddef |
| 1875 | |
| 1876 | def Test_matchdelete() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1877 | CheckDefFailure(['matchdelete("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1878 | CheckDefFailure(['matchdelete("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1879 | CheckDefFailure(['matchdelete(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1880 | enddef |
| 1881 | |
Yegappan Lakshmanan | a9a7c0c | 2021-07-17 19:11:07 +0200 | [diff] [blame] | 1882 | def Test_matchend() |
| 1883 | CheckDefAndScriptFailure2(['matchend(0z12, "p")'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1') |
| 1884 | CheckDefAndScriptFailure2(['matchend(["s"], [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E1174: String required for argument 2') |
| 1885 | CheckDefAndScriptFailure2(['matchend("s", "p", "q")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3') |
| 1886 | CheckDefAndScriptFailure2(['matchend("s", "p", 1, "r")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4') |
| 1887 | assert_equal(4, matchend('ab12cd', '12')) |
| 1888 | assert_equal(-1, matchend('ab12cd', '34')) |
| 1889 | assert_equal(8, matchend('ab12cd12ef', '12', 4)) |
| 1890 | assert_equal(4, matchend('abcd', '..', 0, 3)) |
| 1891 | assert_equal(1, matchend(['a', 'b', 'c'], 'b')) |
| 1892 | assert_equal(-1, matchend(['a', 'b', 'c'], 'd')) |
| 1893 | assert_equal(3, matchend(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2)) |
| 1894 | assert_equal(5, matchend(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2, 2)) |
| 1895 | enddef |
| 1896 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 1897 | def Test_matchfuzzy() |
| 1898 | CheckDefAndScriptFailure2(['matchfuzzy({}, "p")'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<unknown>', 'E1211: List required for argument 1') |
| 1899 | CheckDefAndScriptFailure2(['matchfuzzy([], 1)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 1900 | CheckDefAndScriptFailure2(['matchfuzzy([], "a", [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3') |
| 1901 | enddef |
| 1902 | |
| 1903 | def Test_matchfuzzypos() |
| 1904 | CheckDefAndScriptFailure2(['matchfuzzypos({}, "p")'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<unknown>', 'E1211: List required for argument 1') |
| 1905 | CheckDefAndScriptFailure2(['matchfuzzypos([], 1)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 1906 | CheckDefAndScriptFailure2(['matchfuzzypos([], "a", [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3') |
| 1907 | enddef |
| 1908 | |
Yegappan Lakshmanan | a9a7c0c | 2021-07-17 19:11:07 +0200 | [diff] [blame] | 1909 | def Test_matchlist() |
| 1910 | CheckDefAndScriptFailure2(['matchlist(0z12, "p")'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1') |
| 1911 | CheckDefAndScriptFailure2(['matchlist(["s"], [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E1174: String required for argument 2') |
| 1912 | CheckDefAndScriptFailure2(['matchlist("s", "p", "q")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3') |
| 1913 | CheckDefAndScriptFailure2(['matchlist("s", "p", 1, "r")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4') |
| 1914 | var l: list<string> = ['12', '', '', '', '', '', '', '', '', ''] |
| 1915 | assert_equal(l, matchlist('ab12cd', '12')) |
| 1916 | assert_equal([], matchlist('ab12cd', '34')) |
| 1917 | assert_equal(l, matchlist('ab12cd12ef', '12', 4)) |
| 1918 | l[0] = 'cd' |
| 1919 | assert_equal(l, matchlist('abcd', '..', 0, 3)) |
| 1920 | l[0] = 'b' |
| 1921 | assert_equal(l, matchlist(['a', 'b', 'c'], 'b')) |
| 1922 | assert_equal([], matchlist(['a', 'b', 'c'], 'd')) |
| 1923 | assert_equal(l, matchlist(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2)) |
| 1924 | assert_equal(l, matchlist(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2, 2)) |
| 1925 | enddef |
| 1926 | |
| 1927 | def Test_matchstr() |
| 1928 | CheckDefAndScriptFailure2(['matchstr(0z12, "p")'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1') |
| 1929 | CheckDefAndScriptFailure2(['matchstr(["s"], [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E1174: String required for argument 2') |
| 1930 | CheckDefAndScriptFailure2(['matchstr("s", "p", "q")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3') |
| 1931 | CheckDefAndScriptFailure2(['matchstr("s", "p", 1, "r")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4') |
| 1932 | assert_equal('12', matchstr('ab12cd', '12')) |
| 1933 | assert_equal('', matchstr('ab12cd', '34')) |
| 1934 | assert_equal('12', matchstr('ab12cd12ef', '12', 4)) |
| 1935 | assert_equal('cd', matchstr('abcd', '..', 0, 3)) |
| 1936 | assert_equal('b', matchstr(['a', 'b', 'c'], 'b')) |
| 1937 | assert_equal('', matchstr(['a', 'b', 'c'], 'd')) |
| 1938 | assert_equal('b', matchstr(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2)) |
| 1939 | assert_equal('b', matchstr(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2, 2)) |
| 1940 | enddef |
| 1941 | |
| 1942 | def Test_matchstrpos() |
| 1943 | CheckDefAndScriptFailure2(['matchstrpos(0z12, "p")'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1') |
| 1944 | CheckDefAndScriptFailure2(['matchstrpos(["s"], [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E1174: String required for argument 2') |
| 1945 | CheckDefAndScriptFailure2(['matchstrpos("s", "p", "q")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3') |
| 1946 | CheckDefAndScriptFailure2(['matchstrpos("s", "p", 1, "r")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4') |
| 1947 | assert_equal(['12', 2, 4], matchstrpos('ab12cd', '12')) |
| 1948 | assert_equal(['', -1, -1], matchstrpos('ab12cd', '34')) |
| 1949 | assert_equal(['12', 6, 8], matchstrpos('ab12cd12ef', '12', 4)) |
| 1950 | assert_equal(['cd', 2, 4], matchstrpos('abcd', '..', 0, 3)) |
| 1951 | assert_equal(['b', 1, 0, 1], matchstrpos(['a', 'b', 'c'], 'b')) |
| 1952 | assert_equal(['', -1, -1, -1], matchstrpos(['a', 'b', 'c'], 'd')) |
| 1953 | assert_equal(['b', 3, 0, 1], |
| 1954 | matchstrpos(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2)) |
| 1955 | assert_equal(['b', 5, 0, 1], |
| 1956 | matchstrpos(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2, 2)) |
| 1957 | enddef |
| 1958 | |
Bram Moolenaar | 9ae3705 | 2021-01-22 22:31:10 +0100 | [diff] [blame] | 1959 | def Test_max() |
| 1960 | g:flag = true |
| 1961 | var l1: list<number> = g:flag |
| 1962 | ? [1, max([2, 3])] |
| 1963 | : [4, 5] |
| 1964 | assert_equal([1, 3], l1) |
| 1965 | |
| 1966 | g:flag = false |
| 1967 | var l2: list<number> = g:flag |
| 1968 | ? [1, max([2, 3])] |
| 1969 | : [4, 5] |
| 1970 | assert_equal([4, 5], l2) |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 1971 | CheckDefAndScriptFailure2(['max(5)'], 'E1013: Argument 1: type mismatch, expected list<any> but got number', 'E712: Argument of max() must be a List or Dictionary') |
Bram Moolenaar | 9ae3705 | 2021-01-22 22:31:10 +0100 | [diff] [blame] | 1972 | enddef |
| 1973 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1974 | def Test_menu_info() |
| 1975 | CheckDefFailure(['menu_info(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1976 | CheckDefFailure(['menu_info(10, "n")'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1977 | CheckDefFailure(['menu_info("File", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 1978 | assert_equal({}, menu_info('aMenu')) |
| 1979 | enddef |
| 1980 | |
Bram Moolenaar | 9ae3705 | 2021-01-22 22:31:10 +0100 | [diff] [blame] | 1981 | def Test_min() |
| 1982 | g:flag = true |
| 1983 | var l1: list<number> = g:flag |
| 1984 | ? [1, min([2, 3])] |
| 1985 | : [4, 5] |
| 1986 | assert_equal([1, 2], l1) |
| 1987 | |
| 1988 | g:flag = false |
| 1989 | var l2: list<number> = g:flag |
| 1990 | ? [1, min([2, 3])] |
| 1991 | : [4, 5] |
| 1992 | assert_equal([4, 5], l2) |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 1993 | CheckDefAndScriptFailure2(['min(5)'], 'E1013: Argument 1: type mismatch, expected list<any> but got number', 'E712: Argument of min() must be a List or Dictionary') |
Bram Moolenaar | 9ae3705 | 2021-01-22 22:31:10 +0100 | [diff] [blame] | 1994 | enddef |
| 1995 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1996 | def Test_mkdir() |
| 1997 | CheckDefAndScriptFailure2(['mkdir(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String') |
| 1998 | CheckDefAndScriptFailure2(['mkdir("a", {})'], 'E1013: Argument 2: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String') |
| 1999 | CheckDefAndScriptFailure2(['mkdir("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 2000 | delete('a', 'rf') |
| 2001 | enddef |
| 2002 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 2003 | def Test_mode() |
| 2004 | CheckDefFailure(['mode("1")'], 'E1013: Argument 1: type mismatch, expected bool but got string') |
| 2005 | CheckDefFailure(['mode(2)'], 'E1013: Argument 1: type mismatch, expected bool but got number') |
| 2006 | enddef |
| 2007 | |
| 2008 | def Test_mzeval() |
| 2009 | if !has('mzscheme') |
| 2010 | CheckFeature mzscheme |
| 2011 | endif |
Bram Moolenaar | 20c370d | 2021-07-16 10:39:28 +0200 | [diff] [blame] | 2012 | CheckDefAndScriptFailure2(['mzeval(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String') |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 2013 | enddef |
| 2014 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 2015 | def Test_nextnonblank() |
| 2016 | CheckDefFailure(['nextnonblank(null)'], 'E1013: Argument 1: type mismatch, expected string but got special') |
| 2017 | assert_equal(0, nextnonblank(1)) |
| 2018 | enddef |
| 2019 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2020 | def Test_nr2char() |
| 2021 | nr2char(97, true)->assert_equal('a') |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 2022 | CheckDefAndScriptFailure2(['nr2char("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 2023 | CheckDefAndScriptFailure2(['nr2char(1, "a")'], 'E1013: Argument 2: type mismatch, expected bool but got string', 'E1212: Bool required for argument 2') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2024 | enddef |
| 2025 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 2026 | def Test_or() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 2027 | CheckDefFailure(['or("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 2028 | CheckDefFailure(['or(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 2029 | enddef |
| 2030 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 2031 | def Test_pathshorten() |
| 2032 | CheckDefAndScriptFailure2(['pathshorten(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 2033 | CheckDefAndScriptFailure2(['pathshorten("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 2034 | enddef |
| 2035 | |
| 2036 | def Test_perleval() |
| 2037 | if !has('perl') |
| 2038 | CheckFeature perl |
| 2039 | endif |
| 2040 | CheckDefAndScriptFailure2(['perleval(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String') |
| 2041 | enddef |
| 2042 | |
Yegappan Lakshmanan | c72bdd2 | 2021-07-11 19:44:18 +0200 | [diff] [blame] | 2043 | def Test_popup_atcursor() |
| 2044 | CheckDefAndScriptFailure2(['popup_atcursor({"a": 10}, {})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E450: buffer number, text or a list required') |
| 2045 | CheckDefAndScriptFailure2(['popup_atcursor("a", [1, 2])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required') |
Yegappan Lakshmanan | 841e498 | 2021-07-11 22:04:25 +0200 | [diff] [blame] | 2046 | |
| 2047 | # Pass variable of type 'any' to popup_atcursor() |
| 2048 | var what: any = 'Hello' |
| 2049 | var popupID = what->popup_atcursor({moved: 'any'}) |
| 2050 | assert_equal(0, popupID->popup_getoptions().tabpage) |
| 2051 | popupID->popup_close() |
Yegappan Lakshmanan | c72bdd2 | 2021-07-11 19:44:18 +0200 | [diff] [blame] | 2052 | enddef |
| 2053 | |
| 2054 | def Test_popup_beval() |
| 2055 | CheckDefAndScriptFailure2(['popup_beval({"a": 10}, {})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E450: buffer number, text or a list required') |
| 2056 | CheckDefAndScriptFailure2(['popup_beval("a", [1, 2])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required') |
| 2057 | enddef |
| 2058 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 2059 | def Test_popup_clear() |
| 2060 | CheckDefAndScriptFailure2(['popup_clear(["a"])'], 'E1013: Argument 1: type mismatch, expected bool but got list<string>', 'E745: Using a List as a Number') |
| 2061 | CheckDefAndScriptFailure2(['popup_clear(2)'], 'E1013: Argument 1: type mismatch, expected bool but got number', 'E1023: Using a Number as a Bool') |
| 2062 | enddef |
| 2063 | |
Yegappan Lakshmanan | 841e498 | 2021-07-11 22:04:25 +0200 | [diff] [blame] | 2064 | def Test_popup_create() |
| 2065 | # Pass variable of type 'any' to popup_create() |
| 2066 | var what: any = 'Hello' |
| 2067 | var popupID = what->popup_create({}) |
| 2068 | assert_equal(0, popupID->popup_getoptions().tabpage) |
| 2069 | popupID->popup_close() |
| 2070 | enddef |
| 2071 | |
Yegappan Lakshmanan | c72bdd2 | 2021-07-11 19:44:18 +0200 | [diff] [blame] | 2072 | def Test_popup_dialog() |
| 2073 | CheckDefAndScriptFailure2(['popup_dialog({"a": 10}, {})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E450: buffer number, text or a list required') |
| 2074 | CheckDefAndScriptFailure2(['popup_dialog("a", [1, 2])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required') |
| 2075 | enddef |
| 2076 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 2077 | def Test_popup_filter_menu() |
| 2078 | CheckDefAndScriptFailure2(['popup_filter_menu("x", "")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 2079 | CheckDefAndScriptFailure2(['popup_filter_menu(1, 1)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 2080 | enddef |
| 2081 | |
| 2082 | def Test_popup_filter_yesno() |
| 2083 | CheckDefAndScriptFailure2(['popup_filter_yesno("x", "")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 2084 | CheckDefAndScriptFailure2(['popup_filter_yesno(1, 1)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 2085 | enddef |
| 2086 | |
| 2087 | def Test_popup_getoptions() |
| 2088 | CheckDefAndScriptFailure2(['popup_getoptions("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 2089 | CheckDefAndScriptFailure2(['popup_getoptions(true)'], 'E1013: Argument 1: type mismatch, expected number but got bool', 'E1138: Using a Bool as a Number') |
| 2090 | enddef |
| 2091 | |
| 2092 | def Test_popup_getpos() |
| 2093 | CheckDefAndScriptFailure2(['popup_getpos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 2094 | CheckDefAndScriptFailure2(['popup_getpos(true)'], 'E1013: Argument 1: type mismatch, expected number but got bool', 'E1138: Using a Bool as a Number') |
| 2095 | enddef |
| 2096 | |
| 2097 | def Test_popup_hide() |
| 2098 | CheckDefAndScriptFailure2(['popup_hide("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 2099 | CheckDefAndScriptFailure2(['popup_hide(true)'], 'E1013: Argument 1: type mismatch, expected number but got bool', 'E1138: Using a Bool as a Number') |
| 2100 | enddef |
| 2101 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 2102 | def Test_popup_locate() |
| 2103 | CheckDefAndScriptFailure2(['popup_locate("a", 20)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 2104 | CheckDefAndScriptFailure2(['popup_locate(10, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 2105 | enddef |
| 2106 | |
Yegappan Lakshmanan | c72bdd2 | 2021-07-11 19:44:18 +0200 | [diff] [blame] | 2107 | def Test_popup_menu() |
| 2108 | CheckDefAndScriptFailure2(['popup_menu({"a": 10}, {})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E450: buffer number, text or a list required') |
| 2109 | CheckDefAndScriptFailure2(['popup_menu("a", [1, 2])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required') |
| 2110 | enddef |
| 2111 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 2112 | def Test_popup_move() |
| 2113 | CheckDefAndScriptFailure2(['popup_move("x", {})'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 2114 | CheckDefAndScriptFailure2(['popup_move(1, [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 2') |
| 2115 | enddef |
| 2116 | |
Yegappan Lakshmanan | c72bdd2 | 2021-07-11 19:44:18 +0200 | [diff] [blame] | 2117 | def Test_popup_notification() |
| 2118 | CheckDefAndScriptFailure2(['popup_notification({"a": 10}, {})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E450: buffer number, text or a list required') |
| 2119 | CheckDefAndScriptFailure2(['popup_notification("a", [1, 2])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required') |
| 2120 | enddef |
| 2121 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 2122 | def Test_popup_setoptions() |
| 2123 | CheckDefAndScriptFailure2(['popup_setoptions("x", {})'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 2124 | CheckDefAndScriptFailure2(['popup_setoptions(1, [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 2') |
| 2125 | enddef |
| 2126 | |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 2127 | def Test_popup_settext() |
| 2128 | CheckDefAndScriptFailure2(['popup_settext("x", [])'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 2129 | CheckDefAndScriptFailure2(['popup_settext(1, 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 2130 | enddef |
| 2131 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 2132 | def Test_popup_show() |
| 2133 | CheckDefAndScriptFailure2(['popup_show("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 2134 | CheckDefAndScriptFailure2(['popup_show(true)'], 'E1013: Argument 1: type mismatch, expected number but got bool', 'E1138: Using a Bool as a Number') |
| 2135 | enddef |
| 2136 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 2137 | def Test_prevnonblank() |
| 2138 | CheckDefFailure(['prevnonblank(null)'], 'E1013: Argument 1: type mismatch, expected string but got special') |
| 2139 | assert_equal(0, prevnonblank(1)) |
| 2140 | enddef |
| 2141 | |
| 2142 | def Test_prompt_getprompt() |
Dominique Pelle | 9ff9c7b | 2021-07-18 21:44:37 +0200 | [diff] [blame] | 2143 | if !has('channel') |
| 2144 | CheckFeature channel |
| 2145 | else |
Dominique Pelle | 7450923 | 2021-07-03 19:27:37 +0200 | [diff] [blame] | 2146 | CheckDefFailure(['prompt_getprompt([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') |
| 2147 | assert_equal('', prompt_getprompt('NonExistingBuf')) |
| 2148 | endif |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 2149 | enddef |
| 2150 | |
Yegappan Lakshmanan | a9a7c0c | 2021-07-17 19:11:07 +0200 | [diff] [blame] | 2151 | def Test_prompt_setprompt() |
| 2152 | if !has('channel') |
| 2153 | CheckFeature channel |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 2154 | else |
| 2155 | CheckDefAndScriptFailure2(['prompt_setprompt([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1') |
| 2156 | CheckDefAndScriptFailure2(['prompt_setprompt(1, [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2') |
Yegappan Lakshmanan | a9a7c0c | 2021-07-17 19:11:07 +0200 | [diff] [blame] | 2157 | endif |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 2158 | enddef |
| 2159 | |
| 2160 | def Test_prop_add() |
| 2161 | CheckDefAndScriptFailure2(['prop_add("a", 2, {})'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 2162 | CheckDefAndScriptFailure2(['prop_add(1, "b", {})'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 2163 | CheckDefAndScriptFailure2(['prop_add(1, 2, [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3') |
| 2164 | enddef |
| 2165 | |
| 2166 | def Test_prop_clear() |
| 2167 | CheckDefAndScriptFailure2(['prop_clear("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 2168 | CheckDefAndScriptFailure2(['prop_clear(1, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 2169 | CheckDefAndScriptFailure2(['prop_clear(1, 2, [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3') |
Yegappan Lakshmanan | a9a7c0c | 2021-07-17 19:11:07 +0200 | [diff] [blame] | 2170 | enddef |
| 2171 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 2172 | def Test_prop_find() |
| 2173 | CheckDefAndScriptFailure2(['prop_find([1, 2])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required') |
| 2174 | CheckDefAndScriptFailure2(['prop_find([1, 2], "k")'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required') |
| 2175 | CheckDefAndScriptFailure2(['prop_find({"a": 10}, ["a"])'], 'E1013: Argument 2: type mismatch, expected string but got list<string>', 'E730: Using a List as a String') |
| 2176 | enddef |
| 2177 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 2178 | def Test_prop_list() |
| 2179 | CheckDefAndScriptFailure2(['prop_list("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 2180 | CheckDefAndScriptFailure2(['prop_list(1, [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 2') |
| 2181 | enddef |
| 2182 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 2183 | def Test_prop_remove() |
| 2184 | CheckDefAndScriptFailure2(['prop_remove([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 1') |
| 2185 | CheckDefAndScriptFailure2(['prop_remove({}, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 2186 | CheckDefAndScriptFailure2(['prop_remove({}, 1, "b")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3') |
| 2187 | enddef |
| 2188 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 2189 | def Test_prop_type_add() |
| 2190 | 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') |
| 2191 | CheckDefAndScriptFailure2(['prop_type_add("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required') |
| 2192 | enddef |
| 2193 | |
| 2194 | def Test_prop_type_change() |
| 2195 | 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') |
| 2196 | CheckDefAndScriptFailure2(['prop_type_change("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required') |
| 2197 | enddef |
| 2198 | |
| 2199 | def Test_prop_type_delete() |
| 2200 | CheckDefAndScriptFailure2(['prop_type_delete({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String') |
| 2201 | 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') |
| 2202 | CheckDefAndScriptFailure2(['prop_type_delete("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required') |
| 2203 | enddef |
| 2204 | |
| 2205 | def Test_prop_type_get() |
| 2206 | CheckDefAndScriptFailure2(['prop_type_get({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String') |
| 2207 | 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') |
| 2208 | CheckDefAndScriptFailure2(['prop_type_get("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required') |
| 2209 | enddef |
| 2210 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 2211 | def Test_prop_type_list() |
| 2212 | CheckDefAndScriptFailure2(['prop_type_list(["a"])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<string>', 'E715: Dictionary required') |
| 2213 | CheckDefAndScriptFailure2(['prop_type_list(2)'], 'E1013: Argument 1: type mismatch, expected dict<any> but got number', 'E715: Dictionary required') |
| 2214 | enddef |
| 2215 | |
| 2216 | def Test_py3eval() |
| 2217 | if !has('python3') |
| 2218 | CheckFeature python3 |
| 2219 | endif |
| 2220 | CheckDefAndScriptFailure2(['py3eval([2])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String') |
| 2221 | enddef |
| 2222 | |
| 2223 | def Test_pyeval() |
| 2224 | if !has('python') |
| 2225 | CheckFeature python |
| 2226 | endif |
| 2227 | CheckDefAndScriptFailure2(['pyeval([2])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String') |
| 2228 | enddef |
| 2229 | |
| 2230 | def Test_pyxeval() |
| 2231 | if !has('python') && !has('python3') |
| 2232 | CheckFeature python |
| 2233 | endif |
| 2234 | CheckDefAndScriptFailure2(['pyxeval([2])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String') |
| 2235 | enddef |
| 2236 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 2237 | def Test_rand() |
| 2238 | CheckDefFailure(['rand(10)'], 'E1013: Argument 1: type mismatch, expected list<number> but got number') |
| 2239 | CheckDefFailure(['rand(["a"])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<string>') |
| 2240 | assert_true(rand() >= 0) |
| 2241 | assert_true(rand(srand()) >= 0) |
| 2242 | enddef |
| 2243 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 2244 | def Test_range() |
| 2245 | CheckDefAndScriptFailure2(['range("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 2246 | CheckDefAndScriptFailure2(['range(10, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 2247 | CheckDefAndScriptFailure2(['range(10, 20, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 2248 | enddef |
| 2249 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2250 | def Test_readdir() |
Bram Moolenaar | 2949cfd | 2020-12-31 21:28:47 +0100 | [diff] [blame] | 2251 | eval expand('sautest')->readdir((e) => e[0] !=# '.') |
| 2252 | eval expand('sautest')->readdirex((e) => e.name[0] !=# '.') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2253 | enddef |
| 2254 | |
Bram Moolenaar | c423ad7 | 2021-01-13 20:38:03 +0100 | [diff] [blame] | 2255 | def Test_readblob() |
| 2256 | var blob = 0z12341234 |
| 2257 | writefile(blob, 'Xreadblob') |
| 2258 | var read: blob = readblob('Xreadblob') |
| 2259 | assert_equal(blob, read) |
| 2260 | |
| 2261 | var lines =<< trim END |
| 2262 | var read: list<string> = readblob('Xreadblob') |
| 2263 | END |
| 2264 | CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<string> but got blob', 1) |
| 2265 | delete('Xreadblob') |
| 2266 | enddef |
| 2267 | |
| 2268 | def Test_readfile() |
| 2269 | var text = ['aaa', 'bbb', 'ccc'] |
| 2270 | writefile(text, 'Xreadfile') |
| 2271 | var read: list<string> = readfile('Xreadfile') |
| 2272 | assert_equal(text, read) |
| 2273 | |
| 2274 | var lines =<< trim END |
| 2275 | var read: dict<string> = readfile('Xreadfile') |
| 2276 | END |
| 2277 | CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected dict<string> but got list<string>', 1) |
| 2278 | delete('Xreadfile') |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 2279 | |
| 2280 | CheckDefAndScriptFailure2(['readfile("a", 0z10)'], 'E1013: Argument 2: type mismatch, expected string but got blob', 'E976: Using a Blob as a String') |
| 2281 | CheckDefAndScriptFailure2(['readfile("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
Bram Moolenaar | c423ad7 | 2021-01-13 20:38:03 +0100 | [diff] [blame] | 2282 | enddef |
| 2283 | |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 2284 | def Test_reduce() |
| 2285 | CheckDefAndScriptFailure2(['reduce({a: 10}, "1")'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<number>', 'E897: List or Blob required') |
| 2286 | assert_equal(6, [1, 2, 3]->reduce((r, c) => r + c, 0)) |
| 2287 | assert_equal(11, 0z0506->reduce((r, c) => r + c, 0)) |
| 2288 | enddef |
| 2289 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 2290 | def Test_reltime() |
Bram Moolenaar | c816a2c | 2021-07-14 21:00:41 +0200 | [diff] [blame] | 2291 | CheckFeature reltime |
| 2292 | |
| 2293 | CheckDefExecAndScriptFailure(['[]->reltime()'], 'E474:') |
| 2294 | CheckDefExecAndScriptFailure(['[]->reltime([])'], 'E474:') |
| 2295 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 2296 | CheckDefFailure(['reltime("x")'], 'E1013: Argument 1: type mismatch, expected list<number> but got string') |
| 2297 | CheckDefFailure(['reltime(["x", "y"])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<string>') |
| 2298 | CheckDefFailure(['reltime([1, 2], 10)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number') |
| 2299 | CheckDefFailure(['reltime([1, 2], ["a", "b"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>') |
| 2300 | var start: list<any> = reltime() |
| 2301 | assert_true(type(reltime(start)) == v:t_list) |
| 2302 | var end: list<any> = reltime() |
| 2303 | assert_true(type(reltime(start, end)) == v:t_list) |
| 2304 | enddef |
| 2305 | |
| 2306 | def Test_reltimefloat() |
Bram Moolenaar | c816a2c | 2021-07-14 21:00:41 +0200 | [diff] [blame] | 2307 | CheckFeature reltime |
| 2308 | |
| 2309 | CheckDefExecAndScriptFailure(['[]->reltimefloat()'], 'E474:') |
| 2310 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 2311 | CheckDefFailure(['reltimefloat("x")'], 'E1013: Argument 1: type mismatch, expected list<number> but got string') |
| 2312 | CheckDefFailure(['reltimefloat([1.1])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<float>') |
| 2313 | assert_true(type(reltimefloat(reltime())) == v:t_float) |
| 2314 | enddef |
| 2315 | |
| 2316 | def Test_reltimestr() |
Bram Moolenaar | c816a2c | 2021-07-14 21:00:41 +0200 | [diff] [blame] | 2317 | CheckFeature reltime |
| 2318 | |
| 2319 | CheckDefExecAndScriptFailure(['[]->reltimestr()'], 'E474:') |
| 2320 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 2321 | CheckDefFailure(['reltimestr(true)'], 'E1013: Argument 1: type mismatch, expected list<number> but got bool') |
| 2322 | CheckDefFailure(['reltimestr([true])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<bool>') |
| 2323 | assert_true(type(reltimestr(reltime())) == v:t_string) |
| 2324 | enddef |
| 2325 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 2326 | def Test_remote_expr() |
| 2327 | CheckFeature clientserver |
| 2328 | CheckEnv DISPLAY |
| 2329 | CheckDefAndScriptFailure2(['remote_expr(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 2330 | CheckDefAndScriptFailure2(['remote_expr("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 2331 | CheckDefAndScriptFailure2(['remote_expr("a", "b", 3)'], 'E1013: Argument 3: type mismatch, expected string but got number', 'E1174: String required for argument 3') |
| 2332 | CheckDefAndScriptFailure2(['remote_expr("a", "b", "c", "d")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4') |
| 2333 | enddef |
| 2334 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 2335 | def Test_remote_foreground() |
| 2336 | CheckFeature clientserver |
| 2337 | # remote_foreground() doesn't fail on MS-Windows |
| 2338 | CheckNotMSWindows |
Bram Moolenaar | d6fa7bd | 2021-07-05 14:10:04 +0200 | [diff] [blame] | 2339 | CheckEnv DISPLAY |
| 2340 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 2341 | CheckDefFailure(['remote_foreground(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 2342 | assert_fails('remote_foreground("NonExistingServer")', 'E241:') |
| 2343 | enddef |
| 2344 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 2345 | def Test_remote_peek() |
| 2346 | CheckFeature clientserver |
| 2347 | CheckEnv DISPLAY |
| 2348 | CheckDefAndScriptFailure2(['remote_peek(0z10)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E976: Using a Blob as a String') |
| 2349 | CheckDefAndScriptFailure2(['remote_peek("a5b6c7", [1])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E573: Invalid server id used') |
| 2350 | enddef |
| 2351 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 2352 | def Test_remote_read() |
| 2353 | CheckFeature clientserver |
| 2354 | CheckEnv DISPLAY |
| 2355 | CheckDefAndScriptFailure2(['remote_read(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 2356 | CheckDefAndScriptFailure2(['remote_read("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 2357 | enddef |
| 2358 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 2359 | def Test_remote_send() |
| 2360 | CheckFeature clientserver |
| 2361 | CheckEnv DISPLAY |
| 2362 | CheckDefAndScriptFailure2(['remote_send(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 2363 | CheckDefAndScriptFailure2(['remote_send("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 2364 | CheckDefAndScriptFailure2(['remote_send("a", "b", 3)'], 'E1013: Argument 3: type mismatch, expected string but got number', 'E1174: String required for argument 3') |
| 2365 | enddef |
| 2366 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 2367 | def Test_remote_startserver() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 2368 | CheckFeature clientserver |
| 2369 | CheckEnv DISPLAY |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 2370 | CheckDefFailure(['remote_startserver({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>') |
| 2371 | enddef |
| 2372 | |
Bram Moolenaar | 885971e | 2021-07-18 22:25:29 +0200 | [diff] [blame] | 2373 | def Test_remove_const_list() |
| 2374 | var l: list<number> = [1, 2, 3, 4] |
| 2375 | assert_equal([1, 2], remove(l, 0, 1)) |
| 2376 | assert_equal([3, 4], l) |
| 2377 | enddef |
| 2378 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 2379 | def Test_remove() |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 2380 | CheckDefAndScriptFailure2(['remove("a", 1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E1211: List required for argument 1') |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 2381 | CheckDefAndScriptFailure2(['remove([], "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 2382 | CheckDefAndScriptFailure2(['remove([], 1, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3') |
| 2383 | CheckDefAndScriptFailure2(['remove({}, 1.1)'], 'E1013: Argument 2: type mismatch, expected string but got float', 'E1174: String required for argument 2') |
| 2384 | CheckDefAndScriptFailure2(['remove(0z10, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 2385 | CheckDefAndScriptFailure2(['remove(0z20, 1, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3') |
| 2386 | var l: any = [1, 2, 3, 4] |
| 2387 | remove(l, 1) |
| 2388 | assert_equal([1, 3, 4], l) |
| 2389 | remove(l, 0, 1) |
| 2390 | assert_equal([4], l) |
| 2391 | var b: any = 0z1234.5678.90 |
| 2392 | remove(b, 1) |
| 2393 | assert_equal(0z1256.7890, b) |
| 2394 | remove(b, 1, 2) |
| 2395 | assert_equal(0z1290, b) |
| 2396 | var d: any = {a: 10, b: 20, c: 30} |
| 2397 | remove(d, 'b') |
| 2398 | assert_equal({a: 10, c: 30}, d) |
| 2399 | var d2: any = {1: 'a', 2: 'b', 3: 'c'} |
| 2400 | remove(d2, 2) |
| 2401 | assert_equal({1: 'a', 3: 'c'}, d2) |
| 2402 | enddef |
| 2403 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2404 | def Test_remove_return_type() |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 2405 | var l = remove({one: [1, 2], two: [3, 4]}, 'one') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2406 | var res = 0 |
| 2407 | for n in l |
| 2408 | res += n |
| 2409 | endfor |
| 2410 | res->assert_equal(3) |
| 2411 | enddef |
| 2412 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 2413 | def Test_rename() |
| 2414 | CheckDefFailure(['rename(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 2415 | CheckDefFailure(['rename("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 2416 | enddef |
| 2417 | |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 2418 | def Test_repeat() |
| 2419 | CheckDefAndScriptFailure2(['repeat(1.1, 2)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1') |
| 2420 | CheckDefAndScriptFailure2(['repeat({a: 10}, 2)'], 'E1013: Argument 1: type mismatch, expected string but got dict<', 'E1174: String required for argument 1') |
| 2421 | assert_equal('aaa', repeat('a', 3)) |
| 2422 | assert_equal('111', repeat(1, 3)) |
| 2423 | assert_equal([1, 1, 1], repeat([1], 3)) |
| 2424 | enddef |
| 2425 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 2426 | def Test_resolve() |
| 2427 | CheckDefFailure(['resolve([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') |
| 2428 | assert_equal('SomeFile', resolve('SomeFile')) |
| 2429 | enddef |
| 2430 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 2431 | def Test_reverse() |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 2432 | CheckDefAndScriptFailure2(['reverse(10)'], 'E1013: Argument 1: type mismatch, expected list<any> but got number', 'E1211: List required for argument 1') |
| 2433 | CheckDefAndScriptFailure2(['reverse("abc")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E1211: List required for argument 1') |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 2434 | enddef |
| 2435 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2436 | def Test_reverse_return_type() |
| 2437 | var l = reverse([1, 2, 3]) |
| 2438 | var res = 0 |
| 2439 | for n in l |
| 2440 | res += n |
| 2441 | endfor |
| 2442 | res->assert_equal(6) |
| 2443 | enddef |
| 2444 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 2445 | def Test_rubyeval() |
| 2446 | if !has('ruby') |
| 2447 | CheckFeature ruby |
| 2448 | endif |
| 2449 | CheckDefAndScriptFailure2(['rubyeval([2])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String') |
| 2450 | enddef |
| 2451 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 2452 | def Test_screenattr() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 2453 | CheckDefFailure(['screenattr("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 2454 | CheckDefFailure(['screenattr(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 2455 | enddef |
| 2456 | |
| 2457 | def Test_screenchar() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 2458 | CheckDefFailure(['screenchar("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 2459 | CheckDefFailure(['screenchar(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 2460 | enddef |
| 2461 | |
| 2462 | def Test_screenchars() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 2463 | CheckDefFailure(['screenchars("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 2464 | CheckDefFailure(['screenchars(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 2465 | enddef |
| 2466 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 2467 | def Test_screenpos() |
| 2468 | CheckDefFailure(['screenpos("a", 1, 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 2469 | CheckDefFailure(['screenpos(1, "b", 1)'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 2470 | CheckDefFailure(['screenpos(1, 1, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string') |
| 2471 | assert_equal({col: 1, row: 1, endcol: 1, curscol: 1}, screenpos(1, 1, 1)) |
| 2472 | enddef |
| 2473 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 2474 | def Test_screenstring() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 2475 | CheckDefFailure(['screenstring("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 2476 | CheckDefFailure(['screenstring(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 2477 | enddef |
| 2478 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2479 | def Test_search() |
| 2480 | new |
| 2481 | setline(1, ['foo', 'bar']) |
| 2482 | var val = 0 |
| 2483 | # skip expr returns boolean |
Bram Moolenaar | 2949cfd | 2020-12-31 21:28:47 +0100 | [diff] [blame] | 2484 | search('bar', 'W', 0, 0, () => val == 1)->assert_equal(2) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2485 | :1 |
Bram Moolenaar | 2949cfd | 2020-12-31 21:28:47 +0100 | [diff] [blame] | 2486 | search('bar', 'W', 0, 0, () => val == 0)->assert_equal(0) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2487 | # skip expr returns number, only 0 and 1 are accepted |
| 2488 | :1 |
Bram Moolenaar | 2949cfd | 2020-12-31 21:28:47 +0100 | [diff] [blame] | 2489 | search('bar', 'W', 0, 0, () => 0)->assert_equal(2) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2490 | :1 |
Bram Moolenaar | 2949cfd | 2020-12-31 21:28:47 +0100 | [diff] [blame] | 2491 | search('bar', 'W', 0, 0, () => 1)->assert_equal(0) |
| 2492 | assert_fails("search('bar', '', 0, 0, () => -1)", 'E1023:') |
| 2493 | assert_fails("search('bar', '', 0, 0, () => -1)", 'E1023:') |
Bram Moolenaar | f06ab6b | 2021-05-07 19:44:21 +0200 | [diff] [blame] | 2494 | |
| 2495 | setline(1, "find this word") |
| 2496 | normal gg |
| 2497 | var col = 7 |
| 2498 | assert_equal(1, search('this', '', 0, 0, 'col(".") > col')) |
| 2499 | normal 0 |
| 2500 | assert_equal([1, 6], searchpos('this', '', 0, 0, 'col(".") > col')) |
| 2501 | |
| 2502 | col = 5 |
| 2503 | normal 0 |
| 2504 | assert_equal(0, search('this', '', 0, 0, 'col(".") > col')) |
| 2505 | normal 0 |
| 2506 | assert_equal([0, 0], searchpos('this', '', 0, 0, 'col(".") > col')) |
| 2507 | bwipe! |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 2508 | CheckDefAndScriptFailure2(['search(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 2509 | CheckDefAndScriptFailure2(['search("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 2510 | CheckDefAndScriptFailure2(['search("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3') |
| 2511 | CheckDefAndScriptFailure2(['search("a", "b", 3, "d")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2512 | enddef |
| 2513 | |
| 2514 | def Test_searchcount() |
| 2515 | new |
| 2516 | setline(1, "foo bar") |
| 2517 | :/foo |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 2518 | searchcount({recompute: true}) |
| 2519 | ->assert_equal({ |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2520 | exact_match: 1, |
| 2521 | current: 1, |
| 2522 | total: 1, |
| 2523 | maxcount: 99, |
| 2524 | incomplete: 0}) |
| 2525 | bwipe! |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 2526 | CheckDefAndScriptFailure2(['searchcount([1])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2527 | enddef |
| 2528 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 2529 | def Test_searchdecl() |
| 2530 | searchdecl('blah', true, true)->assert_equal(1) |
| 2531 | CheckDefAndScriptFailure2(['searchdecl(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 2532 | CheckDefAndScriptFailure2(['searchdecl("a", 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2') |
| 2533 | CheckDefAndScriptFailure2(['searchdecl("a", true, 2)'], 'E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3') |
| 2534 | enddef |
| 2535 | |
Bram Moolenaar | f18332f | 2021-05-07 17:55:55 +0200 | [diff] [blame] | 2536 | def Test_searchpair() |
| 2537 | new |
| 2538 | setline(1, "here { and } there") |
Bram Moolenaar | f06ab6b | 2021-05-07 19:44:21 +0200 | [diff] [blame] | 2539 | |
Bram Moolenaar | f18332f | 2021-05-07 17:55:55 +0200 | [diff] [blame] | 2540 | normal f{ |
| 2541 | var col = 15 |
| 2542 | assert_equal(1, searchpair('{', '', '}', '', 'col(".") > col')) |
| 2543 | assert_equal(12, col('.')) |
Bram Moolenaar | f06ab6b | 2021-05-07 19:44:21 +0200 | [diff] [blame] | 2544 | normal 0f{ |
| 2545 | assert_equal([1, 12], searchpairpos('{', '', '}', '', 'col(".") > col')) |
| 2546 | |
Bram Moolenaar | f18332f | 2021-05-07 17:55:55 +0200 | [diff] [blame] | 2547 | col = 8 |
| 2548 | normal 0f{ |
| 2549 | assert_equal(0, searchpair('{', '', '}', '', 'col(".") > col')) |
| 2550 | assert_equal(6, col('.')) |
Bram Moolenaar | f06ab6b | 2021-05-07 19:44:21 +0200 | [diff] [blame] | 2551 | normal 0f{ |
| 2552 | assert_equal([0, 0], searchpairpos('{', '', '}', '', 'col(".") > col')) |
| 2553 | |
Bram Moolenaar | ff65288 | 2021-05-16 15:24:49 +0200 | [diff] [blame] | 2554 | var lines =<< trim END |
| 2555 | vim9script |
| 2556 | setline(1, '()') |
| 2557 | normal gg |
| 2558 | def Fail() |
| 2559 | try |
| 2560 | searchpairpos('(', '', ')', 'nW', '[0]->map("")') |
| 2561 | catch |
Bram Moolenaar | cbe178e | 2021-05-18 17:49:59 +0200 | [diff] [blame] | 2562 | g:caught = 'yes' |
Bram Moolenaar | ff65288 | 2021-05-16 15:24:49 +0200 | [diff] [blame] | 2563 | endtry |
| 2564 | enddef |
| 2565 | Fail() |
| 2566 | END |
Bram Moolenaar | cbe178e | 2021-05-18 17:49:59 +0200 | [diff] [blame] | 2567 | CheckScriptSuccess(lines) |
| 2568 | assert_equal('yes', g:caught) |
Bram Moolenaar | cbe178e | 2021-05-18 17:49:59 +0200 | [diff] [blame] | 2569 | unlet g:caught |
Bram Moolenaar | 5a234eb | 2021-07-24 13:18:48 +0200 | [diff] [blame^] | 2570 | |
| 2571 | lines =<< trim END |
| 2572 | echo searchpair("a", "b", "c", "d", "1", "f") |
| 2573 | END |
| 2574 | CheckDefAndScriptFailure2(lines, 'E1001:', 'E475:') |
| 2575 | |
Bram Moolenaar | f18332f | 2021-05-07 17:55:55 +0200 | [diff] [blame] | 2576 | bwipe! |
| 2577 | enddef |
| 2578 | |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 2579 | def Test_searchpos() |
| 2580 | CheckDefAndScriptFailure2(['searchpos(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 2581 | CheckDefAndScriptFailure2(['searchpos("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 2582 | CheckDefAndScriptFailure2(['searchpos("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3') |
| 2583 | CheckDefAndScriptFailure2(['searchpos("a", "b", 3, "d")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4') |
| 2584 | enddef |
| 2585 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 2586 | def Test_server2client() |
| 2587 | CheckFeature clientserver |
| 2588 | CheckEnv DISPLAY |
| 2589 | CheckDefAndScriptFailure2(['server2client(10, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E573: Invalid server id used:') |
| 2590 | CheckDefAndScriptFailure2(['server2client("a", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E573: Invalid server id used:') |
| 2591 | enddef |
| 2592 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 2593 | def Test_shellescape() |
| 2594 | CheckDefAndScriptFailure2(['shellescape(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 2595 | CheckDefAndScriptFailure2(['shellescape("a", 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2') |
| 2596 | enddef |
| 2597 | |
Bram Moolenaar | 3445320 | 2021-01-31 13:08:38 +0100 | [diff] [blame] | 2598 | def Test_set_get_bufline() |
| 2599 | # similar to Test_setbufline_getbufline() |
| 2600 | var lines =<< trim END |
| 2601 | new |
| 2602 | var b = bufnr('%') |
| 2603 | hide |
| 2604 | assert_equal(0, setbufline(b, 1, ['foo', 'bar'])) |
| 2605 | assert_equal(['foo'], getbufline(b, 1)) |
| 2606 | assert_equal(['bar'], getbufline(b, '$')) |
| 2607 | assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) |
| 2608 | exe "bd!" b |
| 2609 | assert_equal([], getbufline(b, 1, 2)) |
| 2610 | |
| 2611 | split Xtest |
| 2612 | setline(1, ['a', 'b', 'c']) |
| 2613 | b = bufnr('%') |
| 2614 | wincmd w |
| 2615 | |
| 2616 | assert_equal(1, setbufline(b, 5, 'x')) |
| 2617 | assert_equal(1, setbufline(b, 5, ['x'])) |
| 2618 | assert_equal(1, setbufline(b, 5, [])) |
| 2619 | assert_equal(1, setbufline(b, 5, test_null_list())) |
| 2620 | |
| 2621 | assert_equal(1, 'x'->setbufline(bufnr('$') + 1, 1)) |
| 2622 | assert_equal(1, ['x']->setbufline(bufnr('$') + 1, 1)) |
| 2623 | assert_equal(1, []->setbufline(bufnr('$') + 1, 1)) |
| 2624 | assert_equal(1, test_null_list()->setbufline(bufnr('$') + 1, 1)) |
| 2625 | |
| 2626 | assert_equal(['a', 'b', 'c'], getbufline(b, 1, '$')) |
| 2627 | |
| 2628 | assert_equal(0, setbufline(b, 4, ['d', 'e'])) |
| 2629 | assert_equal(['c'], b->getbufline(3)) |
| 2630 | assert_equal(['d'], getbufline(b, 4)) |
| 2631 | assert_equal(['e'], getbufline(b, 5)) |
| 2632 | assert_equal([], getbufline(b, 6)) |
| 2633 | assert_equal([], getbufline(b, 2, 1)) |
| 2634 | |
Bram Moolenaar | 0038511 | 2021-02-07 14:31:06 +0100 | [diff] [blame] | 2635 | if has('job') |
Bram Moolenaar | 1328bde | 2021-06-05 20:51:38 +0200 | [diff] [blame] | 2636 | setbufline(b, 2, [function('eval'), {key: 123}, string(test_null_job())]) |
Bram Moolenaar | 0038511 | 2021-02-07 14:31:06 +0100 | [diff] [blame] | 2637 | assert_equal(["function('eval')", |
| 2638 | "{'key': 123}", |
| 2639 | "no process"], |
| 2640 | getbufline(b, 2, 4)) |
| 2641 | endif |
Bram Moolenaar | 3445320 | 2021-01-31 13:08:38 +0100 | [diff] [blame] | 2642 | |
| 2643 | exe 'bwipe! ' .. b |
| 2644 | END |
| 2645 | CheckDefAndScriptSuccess(lines) |
| 2646 | enddef |
| 2647 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2648 | def Test_setbufvar() |
| 2649 | setbufvar(bufnr('%'), '&syntax', 'vim') |
| 2650 | &syntax->assert_equal('vim') |
| 2651 | setbufvar(bufnr('%'), '&ts', 16) |
| 2652 | &ts->assert_equal(16) |
Bram Moolenaar | 31a201a | 2021-01-03 14:47:25 +0100 | [diff] [blame] | 2653 | setbufvar(bufnr('%'), '&ai', true) |
| 2654 | &ai->assert_equal(true) |
| 2655 | setbufvar(bufnr('%'), '&ft', 'filetype') |
| 2656 | &ft->assert_equal('filetype') |
| 2657 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2658 | settabwinvar(1, 1, '&syntax', 'vam') |
| 2659 | &syntax->assert_equal('vam') |
| 2660 | settabwinvar(1, 1, '&ts', 15) |
| 2661 | &ts->assert_equal(15) |
| 2662 | setlocal ts=8 |
Bram Moolenaar | b0d8182 | 2021-01-03 15:55:10 +0100 | [diff] [blame] | 2663 | settabwinvar(1, 1, '&list', false) |
| 2664 | &list->assert_equal(false) |
Bram Moolenaar | 31a201a | 2021-01-03 14:47:25 +0100 | [diff] [blame] | 2665 | settabwinvar(1, 1, '&list', true) |
| 2666 | &list->assert_equal(true) |
| 2667 | setlocal list& |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2668 | |
| 2669 | setbufvar('%', 'myvar', 123) |
| 2670 | getbufvar('%', 'myvar')->assert_equal(123) |
| 2671 | enddef |
| 2672 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 2673 | def Test_setbufline() |
| 2674 | new |
| 2675 | var bnum = bufnr('%') |
| 2676 | :wincmd w |
| 2677 | setbufline(bnum, 1, range(1, 3)) |
| 2678 | setbufline(bnum, 4, 'one') |
| 2679 | setbufline(bnum, 5, 10) |
| 2680 | setbufline(bnum, 6, ['two', 11]) |
| 2681 | assert_equal(['1', '2', '3', 'one', '10', 'two', '11'], getbufline(bnum, 1, '$')) |
| 2682 | CheckDefFailure(['setbufline([1], 1, "x")'], 'E1013: Argument 1: type mismatch, expected string but got list<number>') |
| 2683 | CheckDefFailure(['setbufline(1, [1], "x")'], 'E1013: Argument 2: type mismatch, expected string but got list<number>') |
| 2684 | CheckDefFailure(['setbufline(1, 1, {"a": 10})'], 'E1013: Argument 3: type mismatch, expected string but got dict<number>') |
| 2685 | bnum->bufwinid()->win_gotoid() |
| 2686 | bw! |
| 2687 | enddef |
| 2688 | |
| 2689 | def Test_setcellwidths() |
| 2690 | CheckDefAndScriptFailure2(['setcellwidths(1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got number', 'E714: List required') |
| 2691 | CheckDefAndScriptFailure2(['setcellwidths({"a": 10})'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<number>', 'E714: List required') |
| 2692 | enddef |
| 2693 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 2694 | def Test_setcharpos() |
| 2695 | CheckDefAndScriptFailure2(['setcharpos(1, [])'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 2696 | CheckDefFailure(['setcharpos(".", ["a"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>') |
| 2697 | CheckDefAndScriptFailure2(['setcharpos(".", 1)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number', 'E1211: List required for argument 2') |
| 2698 | enddef |
| 2699 | |
| 2700 | def Test_setcharsearch() |
| 2701 | CheckDefFailure(['setcharsearch("x")'], 'E1013: Argument 1: type mismatch, expected dict<any> but got string') |
| 2702 | CheckDefFailure(['setcharsearch([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>') |
| 2703 | var d: dict<any> = {char: 'x', forward: 1, until: 1} |
| 2704 | setcharsearch(d) |
| 2705 | assert_equal(d, getcharsearch()) |
| 2706 | enddef |
| 2707 | |
| 2708 | def Test_setcmdpos() |
| 2709 | CheckDefFailure(['setcmdpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 2710 | enddef |
| 2711 | |
| 2712 | def Test_setcursorcharpos() |
| 2713 | CheckDefAndScriptFailure2(['setcursorcharpos(0z10, 1)'], 'E1013: Argument 1: type mismatch, expected number but got blob', 'E1210: Number required for argument 1') |
| 2714 | CheckDefAndScriptFailure2(['setcursorcharpos(1, "2")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 2715 | CheckDefAndScriptFailure2(['setcursorcharpos(1, 2, "3")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3') |
| 2716 | enddef |
| 2717 | |
| 2718 | def Test_setfperm() |
| 2719 | CheckDefFailure(['setfperm(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 2720 | CheckDefFailure(['setfperm("a", 0z10)'], 'E1013: Argument 2: type mismatch, expected string but got blob') |
| 2721 | enddef |
| 2722 | |
Yegappan Lakshmanan | c72bdd2 | 2021-07-11 19:44:18 +0200 | [diff] [blame] | 2723 | def Test_setline() |
| 2724 | new |
| 2725 | setline(1, range(1, 4)) |
| 2726 | assert_equal(['1', '2', '3', '4'], getline(1, '$')) |
| 2727 | setline(1, ['a', 'b', 'c', 'd']) |
| 2728 | assert_equal(['a', 'b', 'c', 'd'], getline(1, '$')) |
| 2729 | setline(1, 'one') |
| 2730 | assert_equal(['one', 'b', 'c', 'd'], getline(1, '$')) |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 2731 | setline(1, 10) |
| 2732 | assert_equal(['10', 'b', 'c', 'd'], getline(1, '$')) |
| 2733 | CheckDefAndScriptFailure2(['setline([1], "x")'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E745: Using a List as a Number') |
Yegappan Lakshmanan | c72bdd2 | 2021-07-11 19:44:18 +0200 | [diff] [blame] | 2734 | bw! |
| 2735 | enddef |
| 2736 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2737 | def Test_setloclist() |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 2738 | var items = [{filename: '/tmp/file', lnum: 1, valid: true}] |
| 2739 | var what = {items: items} |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2740 | setqflist([], ' ', what) |
| 2741 | setloclist(0, [], ' ', what) |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 2742 | CheckDefAndScriptFailure2(['setloclist("1", [])'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 2743 | CheckDefAndScriptFailure2(['setloclist(1, 2)'], 'E1013: Argument 2: type mismatch, expected list<any> but got number', 'E1211: List required for argument 2') |
| 2744 | CheckDefAndScriptFailure2(['setloclist(1, [], 3)'], 'E1013: Argument 3: type mismatch, expected string but got number', 'E1174: String required for argument 3') |
| 2745 | CheckDefAndScriptFailure2(['setloclist(1, [], "a", [])'], 'E1013: Argument 4: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 4') |
| 2746 | enddef |
| 2747 | |
| 2748 | def Test_setmatches() |
| 2749 | CheckDefAndScriptFailure2(['setmatches({})'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<unknown>', 'E1211: List required for argument 1') |
| 2750 | CheckDefAndScriptFailure2(['setmatches([], "1")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 2751 | enddef |
| 2752 | |
| 2753 | def Test_setpos() |
| 2754 | CheckDefAndScriptFailure2(['setpos(1, [])'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 2755 | CheckDefFailure(['setpos(".", ["a"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>') |
| 2756 | CheckDefAndScriptFailure2(['setpos(".", 1)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number', 'E1211: List required for argument 2') |
| 2757 | enddef |
| 2758 | |
| 2759 | def Test_setqflist() |
| 2760 | CheckDefAndScriptFailure2(['setqflist(1, "")'], 'E1013: Argument 1: type mismatch, expected list<any> but got number', 'E1211: List required for argument 1') |
| 2761 | CheckDefAndScriptFailure2(['setqflist([], 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 2762 | CheckDefAndScriptFailure2(['setqflist([], "", [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2763 | enddef |
| 2764 | |
| 2765 | def Test_setreg() |
| 2766 | setreg('a', ['aaa', 'bbb', 'ccc']) |
| 2767 | var reginfo = getreginfo('a') |
| 2768 | setreg('a', reginfo) |
| 2769 | getreginfo('a')->assert_equal(reginfo) |
Bram Moolenaar | 418a29f | 2021-02-10 22:23:41 +0100 | [diff] [blame] | 2770 | assert_fails('setreg("ab", 0)', 'E1162:') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2771 | enddef |
| 2772 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 2773 | def Test_settabvar() |
| 2774 | CheckDefAndScriptFailure2(['settabvar("a", "b", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 2775 | CheckDefAndScriptFailure2(['settabvar(1, 2, "c")'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 2776 | enddef |
| 2777 | |
| 2778 | def Test_settabwinvar() |
| 2779 | CheckDefAndScriptFailure2(['settabwinvar("a", 2, "c", true)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 2780 | CheckDefAndScriptFailure2(['settabwinvar(1, "b", "c", [])'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 2781 | CheckDefAndScriptFailure2(['settabwinvar(1, 1, 3, {})'], 'E1013: Argument 3: type mismatch, expected string but got number', 'E1174: String required for argument 3') |
| 2782 | enddef |
| 2783 | |
| 2784 | def Test_settagstack() |
| 2785 | CheckDefAndScriptFailure2(['settagstack(true, {})'], 'E1013: Argument 1: type mismatch, expected number but got bool', 'E1210: Number required for argument 1') |
| 2786 | CheckDefAndScriptFailure2(['settagstack(1, [1])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 2') |
| 2787 | CheckDefAndScriptFailure2(['settagstack(1, {}, 2)'], 'E1013: Argument 3: type mismatch, expected string but got number', 'E1174: String required for argument 3') |
| 2788 | enddef |
| 2789 | |
| 2790 | def Test_setwinvar() |
| 2791 | CheckDefAndScriptFailure2(['setwinvar("a", "b", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 2792 | CheckDefAndScriptFailure2(['setwinvar(1, 2, "c")'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 2793 | enddef |
| 2794 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 2795 | def Test_sha256() |
| 2796 | CheckDefFailure(['sha256(100)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 2797 | CheckDefFailure(['sha256(0zABCD)'], 'E1013: Argument 1: type mismatch, expected string but got blob') |
| 2798 | assert_equal('ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad', sha256('abc')) |
| 2799 | enddef |
| 2800 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 2801 | def Test_shiftwidth() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 2802 | CheckDefFailure(['shiftwidth("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 2803 | enddef |
| 2804 | |
| 2805 | def Test_sign_define() |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 2806 | CheckDefAndScriptFailure2(['sign_define({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E1174: String required for argument 1') |
| 2807 | CheckDefAndScriptFailure2(['sign_define({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E1174: String required for argument 1') |
| 2808 | CheckDefAndScriptFailure2(['sign_define("a", ["b"])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<string>', 'E1206: Dictionary required for argument 2') |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 2809 | enddef |
| 2810 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 2811 | def Test_sign_getdefined() |
| 2812 | CheckDefAndScriptFailure2(['sign_getdefined(["x"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E1174: String required for argument 1') |
| 2813 | CheckDefAndScriptFailure2(['sign_getdefined(2)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 2814 | enddef |
| 2815 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 2816 | def Test_sign_getplaced() |
| 2817 | CheckDefAndScriptFailure2(['sign_getplaced(["x"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E1174: String required for argument 1') |
| 2818 | CheckDefAndScriptFailure2(['sign_getplaced(1, ["a"])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<string>', 'E1206: Dictionary required for argument 2') |
| 2819 | CheckDefAndScriptFailure2(['sign_getplaced("a", 1.1)'], 'E1013: Argument 2: type mismatch, expected dict<any> but got float', 'E1206: Dictionary required for argument 2') |
| 2820 | enddef |
| 2821 | |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 2822 | def Test_sign_jump() |
| 2823 | CheckDefAndScriptFailure2(['sign_jump("a", "b", "c")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 2824 | CheckDefAndScriptFailure2(['sign_jump(1, 2, 3)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 2825 | CheckDefAndScriptFailure2(['sign_jump(1, "b", true)'], 'E1013: Argument 3: type mismatch, expected string but got bool', 'E1174: String required for argument 3') |
| 2826 | enddef |
| 2827 | |
| 2828 | def Test_sign_place() |
| 2829 | CheckDefAndScriptFailure2(['sign_place("a", "b", "c", "d")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 2830 | CheckDefAndScriptFailure2(['sign_place(1, 2, "c", "d")'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 2831 | CheckDefAndScriptFailure2(['sign_place(1, "b", 3, "d")'], 'E1013: Argument 3: type mismatch, expected string but got number', 'E1174: String required for argument 3') |
| 2832 | CheckDefAndScriptFailure2(['sign_place(1, "b", "c", 1.1)'], 'E1013: Argument 4: type mismatch, expected string but got float', 'E1174: String required for argument 4') |
| 2833 | CheckDefAndScriptFailure2(['sign_place(1, "b", "c", "d", [1])'], 'E1013: Argument 5: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 5') |
| 2834 | enddef |
| 2835 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 2836 | def Test_sign_placelist() |
| 2837 | CheckDefAndScriptFailure2(['sign_placelist("x")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E714: List required') |
| 2838 | CheckDefAndScriptFailure2(['sign_placelist({"a": 10})'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<number>', 'E714: List required') |
| 2839 | enddef |
| 2840 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 2841 | def Test_sign_undefine() |
| 2842 | CheckDefAndScriptFailure2(['sign_undefine({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String') |
| 2843 | CheckDefAndScriptFailure2(['sign_undefine([1])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>', 'E155: Unknown sign:') |
| 2844 | enddef |
| 2845 | |
| 2846 | def Test_sign_unplace() |
| 2847 | CheckDefAndScriptFailure2(['sign_unplace({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E474: Invalid argument') |
| 2848 | CheckDefAndScriptFailure2(['sign_unplace({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E474: Invalid argument') |
| 2849 | CheckDefAndScriptFailure2(['sign_unplace("a", ["b"])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<string>', 'E715: Dictionary required') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 2850 | enddef |
| 2851 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 2852 | def Test_sign_unplacelist() |
| 2853 | CheckDefAndScriptFailure2(['sign_unplacelist("x")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E714: List required') |
| 2854 | CheckDefAndScriptFailure2(['sign_unplacelist({"a": 10})'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<number>', 'E714: List required') |
| 2855 | enddef |
| 2856 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 2857 | def Test_simplify() |
| 2858 | CheckDefFailure(['simplify(100)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 2859 | call assert_equal('NonExistingFile', simplify('NonExistingFile')) |
| 2860 | enddef |
| 2861 | |
Bram Moolenaar | 6601b62 | 2021-01-13 21:47:15 +0100 | [diff] [blame] | 2862 | def Test_slice() |
| 2863 | assert_equal('12345', slice('012345', 1)) |
| 2864 | assert_equal('123', slice('012345', 1, 4)) |
| 2865 | assert_equal('1234', slice('012345', 1, -1)) |
| 2866 | assert_equal('1', slice('012345', 1, -4)) |
| 2867 | assert_equal('', slice('012345', 1, -5)) |
| 2868 | assert_equal('', slice('012345', 1, -6)) |
| 2869 | |
| 2870 | assert_equal([1, 2, 3, 4, 5], slice(range(6), 1)) |
| 2871 | assert_equal([1, 2, 3], slice(range(6), 1, 4)) |
| 2872 | assert_equal([1, 2, 3, 4], slice(range(6), 1, -1)) |
| 2873 | assert_equal([1], slice(range(6), 1, -4)) |
| 2874 | assert_equal([], slice(range(6), 1, -5)) |
| 2875 | assert_equal([], slice(range(6), 1, -6)) |
| 2876 | |
| 2877 | assert_equal(0z1122334455, slice(0z001122334455, 1)) |
| 2878 | assert_equal(0z112233, slice(0z001122334455, 1, 4)) |
| 2879 | assert_equal(0z11223344, slice(0z001122334455, 1, -1)) |
| 2880 | assert_equal(0z11, slice(0z001122334455, 1, -4)) |
| 2881 | assert_equal(0z, slice(0z001122334455, 1, -5)) |
| 2882 | assert_equal(0z, slice(0z001122334455, 1, -6)) |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 2883 | CheckDefAndScriptFailure2(['slice({"a": 10}, 1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<number>', 'E1211: List required for argument 1') |
| 2884 | CheckDefAndScriptFailure2(['slice([1, 2, 3], "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 2885 | CheckDefAndScriptFailure2(['slice("abc", 1, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3') |
Bram Moolenaar | 6601b62 | 2021-01-13 21:47:15 +0100 | [diff] [blame] | 2886 | enddef |
| 2887 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2888 | def Test_spellsuggest() |
| 2889 | if !has('spell') |
Dominique Pelle | 9ff9c7b | 2021-07-18 21:44:37 +0200 | [diff] [blame] | 2890 | CheckFeature spell |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2891 | else |
| 2892 | spellsuggest('marrch', 1, true)->assert_equal(['March']) |
| 2893 | endif |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 2894 | CheckDefAndScriptFailure2(['spellsuggest(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 2895 | CheckDefAndScriptFailure2(['spellsuggest("a", "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 2896 | CheckDefAndScriptFailure2(['spellsuggest("a", 1, 0z01)'], 'E1013: Argument 3: type mismatch, expected bool but got blob', 'E1212: Bool required for argument 3') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2897 | enddef |
| 2898 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 2899 | def Test_sound_stop() |
| 2900 | CheckFeature sound |
| 2901 | CheckDefFailure(['sound_stop("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 2902 | enddef |
| 2903 | |
| 2904 | def Test_soundfold() |
| 2905 | CheckDefFailure(['soundfold(20)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 2906 | assert_equal('abc', soundfold('abc')) |
| 2907 | enddef |
| 2908 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2909 | def Test_sort_return_type() |
| 2910 | var res: list<number> |
| 2911 | res = [1, 2, 3]->sort() |
| 2912 | enddef |
| 2913 | |
| 2914 | def Test_sort_argument() |
Bram Moolenaar | 08cf0c0 | 2020-12-05 21:47:06 +0100 | [diff] [blame] | 2915 | var lines =<< trim END |
| 2916 | var res = ['b', 'a', 'c']->sort('i') |
| 2917 | res->assert_equal(['a', 'b', 'c']) |
| 2918 | |
| 2919 | def Compare(a: number, b: number): number |
| 2920 | return a - b |
| 2921 | enddef |
| 2922 | var l = [3, 6, 7, 1, 8, 2, 4, 5] |
| 2923 | sort(l, Compare) |
| 2924 | assert_equal([1, 2, 3, 4, 5, 6, 7, 8], l) |
| 2925 | END |
| 2926 | CheckDefAndScriptSuccess(lines) |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 2927 | CheckDefAndScriptFailure2(['sort("a")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E1211: List required for argument 1') |
| 2928 | CheckDefAndScriptFailure2(['sort([1], "", [1])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 3') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2929 | enddef |
| 2930 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 2931 | def Test_spellbadword() |
| 2932 | CheckDefFailure(['spellbadword(100)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 2933 | spellbadword('good')->assert_equal(['', '']) |
| 2934 | enddef |
| 2935 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2936 | def Test_split() |
| 2937 | split(' aa bb ', '\W\+', true)->assert_equal(['', 'aa', 'bb', '']) |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 2938 | CheckDefAndScriptFailure2(['split(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 2939 | CheckDefAndScriptFailure2(['split("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 2940 | CheckDefAndScriptFailure2(['split("a", "b", 2)'], 'E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2941 | enddef |
| 2942 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 2943 | def Test_srand() |
| 2944 | CheckDefFailure(['srand("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 2945 | type(srand(100))->assert_equal(v:t_list) |
| 2946 | enddef |
| 2947 | |
| 2948 | def Test_state() |
| 2949 | CheckDefFailure(['state({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>') |
| 2950 | assert_equal('', state('a')) |
| 2951 | enddef |
| 2952 | |
Bram Moolenaar | 80ad3e2 | 2021-01-31 20:48:58 +0100 | [diff] [blame] | 2953 | def Run_str2float() |
| 2954 | if !has('float') |
Dominique Pelle | 9ff9c7b | 2021-07-18 21:44:37 +0200 | [diff] [blame] | 2955 | CheckFeature float |
Bram Moolenaar | 80ad3e2 | 2021-01-31 20:48:58 +0100 | [diff] [blame] | 2956 | endif |
| 2957 | str2float("1.00")->assert_equal(1.00) |
| 2958 | str2float("2e-2")->assert_equal(0.02) |
| 2959 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 2960 | CheckDefFailure(['str2float(123)'], 'E1013:') |
Bram Moolenaar | 80ad3e2 | 2021-01-31 20:48:58 +0100 | [diff] [blame] | 2961 | CheckScriptFailure(['vim9script', 'echo str2float(123)'], 'E1024:') |
| 2962 | endif |
| 2963 | enddef |
| 2964 | |
Yegappan Lakshmanan | a9a7c0c | 2021-07-17 19:11:07 +0200 | [diff] [blame] | 2965 | def Test_str2list() |
| 2966 | CheckDefAndScriptFailure2(['str2list(10)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
Bram Moolenaar | 98c2eae | 2021-07-19 10:38:49 +0200 | [diff] [blame] | 2967 | CheckDefAndScriptFailure2(['str2list("a", 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2') |
Yegappan Lakshmanan | a9a7c0c | 2021-07-17 19:11:07 +0200 | [diff] [blame] | 2968 | assert_equal([97], str2list('a')) |
| 2969 | assert_equal([97], str2list('a', 1)) |
| 2970 | assert_equal([97], str2list('a', true)) |
| 2971 | enddef |
| 2972 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2973 | def Test_str2nr() |
| 2974 | str2nr("1'000'000", 10, true)->assert_equal(1000000) |
Bram Moolenaar | f2b26bc | 2021-01-30 23:05:11 +0100 | [diff] [blame] | 2975 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 2976 | CheckDefFailure(['str2nr(123)'], 'E1013:') |
Bram Moolenaar | f2b26bc | 2021-01-30 23:05:11 +0100 | [diff] [blame] | 2977 | CheckScriptFailure(['vim9script', 'echo str2nr(123)'], 'E1024:') |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 2978 | CheckDefFailure(['str2nr("123", "x")'], 'E1013:') |
Bram Moolenaar | f2b26bc | 2021-01-30 23:05:11 +0100 | [diff] [blame] | 2979 | CheckScriptFailure(['vim9script', 'echo str2nr("123", "x")'], 'E1030:') |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 2980 | CheckDefFailure(['str2nr("123", 10, "x")'], 'E1013:') |
Bram Moolenaar | f2b26bc | 2021-01-30 23:05:11 +0100 | [diff] [blame] | 2981 | CheckScriptFailure(['vim9script', 'echo str2nr("123", 10, "x")'], 'E1135:') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2982 | enddef |
| 2983 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 2984 | def Test_strcharlen() |
| 2985 | CheckDefAndScriptFailure2(['strcharlen([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String') |
| 2986 | "abc"->strcharlen()->assert_equal(3) |
| 2987 | strcharlen(99)->assert_equal(2) |
| 2988 | enddef |
| 2989 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 2990 | def Test_strcharpart() |
| 2991 | CheckDefAndScriptFailure2(['strcharpart(1, 2)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 2992 | CheckDefAndScriptFailure2(['strcharpart("a", "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 2993 | CheckDefAndScriptFailure2(['strcharpart("a", 1, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3') |
| 2994 | CheckDefAndScriptFailure2(['strcharpart("a", 1, 1, 2)'], 'E1013: Argument 4: type mismatch, expected bool but got number', 'E1212: Bool required for argument 4') |
| 2995 | enddef |
| 2996 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2997 | def Test_strchars() |
| 2998 | strchars("A\u20dd", true)->assert_equal(1) |
Yegappan Lakshmanan | a9a7c0c | 2021-07-17 19:11:07 +0200 | [diff] [blame] | 2999 | CheckDefAndScriptFailure2(['strchars(10)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
Bram Moolenaar | 98c2eae | 2021-07-19 10:38:49 +0200 | [diff] [blame] | 3000 | CheckDefAndScriptFailure2(['strchars("a", 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2') |
Yegappan Lakshmanan | a9a7c0c | 2021-07-17 19:11:07 +0200 | [diff] [blame] | 3001 | assert_equal(3, strchars('abc')) |
| 3002 | assert_equal(3, strchars('abc', 1)) |
| 3003 | assert_equal(3, strchars('abc', true)) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 3004 | enddef |
| 3005 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 3006 | def Test_strdisplaywidth() |
| 3007 | CheckDefAndScriptFailure2(['strdisplaywidth(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 3008 | CheckDefAndScriptFailure2(['strdisplaywidth("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 3009 | enddef |
| 3010 | |
| 3011 | def Test_strftime() |
| 3012 | CheckDefAndScriptFailure2(['strftime(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 3013 | CheckDefAndScriptFailure2(['strftime("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 3014 | enddef |
| 3015 | |
| 3016 | def Test_strgetchar() |
| 3017 | CheckDefAndScriptFailure2(['strgetchar(1, 1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 3018 | CheckDefAndScriptFailure2(['strgetchar("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 3019 | enddef |
| 3020 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 3021 | def Test_stridx() |
| 3022 | CheckDefAndScriptFailure2(['stridx([1], "b")'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String') |
| 3023 | CheckDefAndScriptFailure2(['stridx("a", {})'], 'E1013: Argument 2: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String') |
| 3024 | CheckDefAndScriptFailure2(['stridx("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 3025 | enddef |
| 3026 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 3027 | def Test_strlen() |
| 3028 | CheckDefFailure(['strlen([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') |
| 3029 | "abc"->strlen()->assert_equal(3) |
| 3030 | strlen(99)->assert_equal(2) |
| 3031 | enddef |
| 3032 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 3033 | def Test_strpart() |
| 3034 | CheckDefAndScriptFailure2(['strpart(1, 2)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 3035 | CheckDefAndScriptFailure2(['strpart("a", "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 3036 | CheckDefAndScriptFailure2(['strpart("a", 1, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3') |
| 3037 | CheckDefAndScriptFailure2(['strpart("a", 1, 1, 2)'], 'E1013: Argument 4: type mismatch, expected bool but got number', 'E1212: Bool required for argument 4') |
| 3038 | enddef |
| 3039 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 3040 | def Test_strptime() |
| 3041 | CheckFunction strptime |
| 3042 | CheckDefFailure(['strptime(10, "2021")'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 3043 | CheckDefFailure(['strptime("%Y", 2021)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 3044 | # BUG: Directly calling strptime() in this function gives an "E117: Unknown |
| 3045 | # function" error on MS-Windows even with the above CheckFunction call for |
| 3046 | # strptime(). |
| 3047 | #assert_true(strptime('%Y', '2021') != 0) |
| 3048 | enddef |
| 3049 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 3050 | def Test_strridx() |
| 3051 | CheckDefAndScriptFailure2(['strridx([1], "b")'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String') |
| 3052 | CheckDefAndScriptFailure2(['strridx("a", {})'], 'E1013: Argument 2: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String') |
| 3053 | CheckDefAndScriptFailure2(['strridx("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 3054 | enddef |
| 3055 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 3056 | def Test_strtrans() |
| 3057 | CheckDefFailure(['strtrans(20)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 3058 | assert_equal('abc', strtrans('abc')) |
| 3059 | enddef |
| 3060 | |
| 3061 | def Test_strwidth() |
| 3062 | CheckDefFailure(['strwidth(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 3063 | CheckScriptFailure(['vim9script', 'echo strwidth(10)'], 'E1024:') |
| 3064 | assert_equal(4, strwidth('abcd')) |
| 3065 | enddef |
| 3066 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 3067 | def Test_submatch() |
| 3068 | var pat = 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)' |
Bram Moolenaar | 75ab91f | 2021-01-10 22:42:50 +0100 | [diff] [blame] | 3069 | var Rep = () => range(10)->mapnew((_, v) => submatch(v, true))->string() |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 3070 | var actual = substitute('A123456789', pat, Rep, '') |
| 3071 | var expected = "[['A123456789'], ['1'], ['2'], ['3'], ['4'], ['5'], ['6'], ['7'], ['8'], ['9']]" |
| 3072 | actual->assert_equal(expected) |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 3073 | CheckDefAndScriptFailure2(['submatch("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 3074 | CheckDefAndScriptFailure2(['submatch(1, "a")'], 'E1013: Argument 2: type mismatch, expected bool but got string', 'E1212: Bool required for argument 2') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 3075 | enddef |
| 3076 | |
Bram Moolenaar | 1328bde | 2021-06-05 20:51:38 +0200 | [diff] [blame] | 3077 | def Test_substitute() |
| 3078 | var res = substitute('A1234', '\d', 'X', '') |
| 3079 | assert_equal('AX234', res) |
| 3080 | |
| 3081 | if has('job') |
| 3082 | assert_fails('"text"->substitute(".*", () => job_start(":"), "")', 'E908: using an invalid value as a String: job') |
| 3083 | assert_fails('"text"->substitute(".*", () => job_start(":")->job_getchannel(), "")', 'E908: using an invalid value as a String: channel') |
| 3084 | endif |
| 3085 | enddef |
| 3086 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 3087 | def Test_swapinfo() |
| 3088 | CheckDefFailure(['swapinfo({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>') |
| 3089 | call assert_equal({error: 'Cannot open file'}, swapinfo('x')) |
| 3090 | enddef |
| 3091 | |
| 3092 | def Test_swapname() |
| 3093 | CheckDefFailure(['swapname([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') |
| 3094 | assert_fails('swapname("NonExistingBuf")', 'E94:') |
| 3095 | enddef |
| 3096 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 3097 | def Test_synID() |
| 3098 | new |
| 3099 | setline(1, "text") |
| 3100 | synID(1, 1, true)->assert_equal(0) |
| 3101 | bwipe! |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 3102 | CheckDefAndScriptFailure2(['synID(0z10, 1, true)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1') |
| 3103 | CheckDefAndScriptFailure2(['synID("a", true, false)'], 'E1013: Argument 2: type mismatch, expected number but got bool', 'E1210: Number required for argument 2') |
| 3104 | CheckDefAndScriptFailure2(['synID(1, 1, 2)'], 'E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 3105 | enddef |
| 3106 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 3107 | def Test_synIDtrans() |
| 3108 | CheckDefFailure(['synIDtrans("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 3109 | enddef |
| 3110 | |
Yegappan Lakshmanan | a9a7c0c | 2021-07-17 19:11:07 +0200 | [diff] [blame] | 3111 | def Test_synconcealed() |
| 3112 | CheckDefAndScriptFailure2(['synconcealed(0z10, 1)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1') |
| 3113 | CheckDefAndScriptFailure2(['synconcealed(1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 3114 | enddef |
| 3115 | |
| 3116 | def Test_synstack() |
| 3117 | CheckDefAndScriptFailure2(['synstack(0z10, 1)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1') |
| 3118 | CheckDefAndScriptFailure2(['synstack(1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 3119 | enddef |
| 3120 | |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 3121 | def Test_system() |
| 3122 | CheckDefAndScriptFailure2(['system(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 3123 | CheckDefAndScriptFailure2(['system("a", {})'], 'E1013: Argument 2: type mismatch, expected string but got dict<unknown>', 'E1174: String required for argument 2') |
| 3124 | enddef |
| 3125 | |
| 3126 | def Test_systemlist() |
| 3127 | CheckDefAndScriptFailure2(['systemlist(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 3128 | CheckDefAndScriptFailure2(['systemlist("a", {})'], 'E1013: Argument 2: type mismatch, expected string but got dict<unknown>', 'E1174: String required for argument 2') |
| 3129 | enddef |
| 3130 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 3131 | def Test_tabpagebuflist() |
| 3132 | CheckDefFailure(['tabpagebuflist("t")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 3133 | assert_equal([bufnr('')], tabpagebuflist()) |
| 3134 | assert_equal([bufnr('')], tabpagebuflist(1)) |
| 3135 | enddef |
| 3136 | |
| 3137 | def Test_tabpagenr() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 3138 | CheckDefAndScriptFailure2(['tabpagenr(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E15: Invalid expression:') |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 3139 | assert_equal(1, tabpagenr('$')) |
| 3140 | assert_equal(1, tabpagenr()) |
| 3141 | enddef |
| 3142 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 3143 | def Test_tabpagewinnr() |
| 3144 | CheckDefAndScriptFailure2(['tabpagewinnr("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 3145 | CheckDefAndScriptFailure2(['tabpagewinnr(1, 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 3146 | enddef |
| 3147 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 3148 | def Test_taglist() |
| 3149 | CheckDefAndScriptFailure2(['taglist([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String') |
| 3150 | CheckDefAndScriptFailure2(['taglist("a", [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E730: Using a List as a String') |
| 3151 | enddef |
| 3152 | |
| 3153 | def Test_term_dumpload() |
| 3154 | CheckRunVimInTerminal |
| 3155 | CheckDefAndScriptFailure2(['term_dumpload({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E1174: String required for argument 1') |
| 3156 | CheckDefAndScriptFailure2(['term_dumpload({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E1174: String required for argument 1') |
| 3157 | CheckDefAndScriptFailure2(['term_dumpload("a", ["b"])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<string>', 'E1206: Dictionary required for argument 2') |
| 3158 | enddef |
| 3159 | |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 3160 | def Test_term_dumpdiff() |
| 3161 | CheckRunVimInTerminal |
| 3162 | CheckDefAndScriptFailure2(['term_dumpdiff(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 3163 | CheckDefAndScriptFailure2(['term_dumpdiff("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 3164 | CheckDefAndScriptFailure2(['term_dumpdiff("a", "b", [1])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 3') |
| 3165 | enddef |
| 3166 | |
| 3167 | def Test_term_dumpwrite() |
| 3168 | CheckRunVimInTerminal |
| 3169 | CheckDefAndScriptFailure2(['term_dumpwrite(true, "b")'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1174: String required for argument 1') |
| 3170 | CheckDefAndScriptFailure2(['term_dumpwrite(1, 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 3171 | CheckDefAndScriptFailure2(['term_dumpwrite("a", "b", [1])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 3') |
| 3172 | enddef |
| 3173 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 3174 | def Test_term_getaltscreen() |
| 3175 | CheckRunVimInTerminal |
| 3176 | CheckDefAndScriptFailure2(['term_getaltscreen(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1138: Using a Bool as a Number') |
| 3177 | enddef |
| 3178 | |
| 3179 | def Test_term_getansicolors() |
| 3180 | CheckRunVimInTerminal |
Dominique Pelle | ee41052 | 2021-07-12 22:15:24 +0200 | [diff] [blame] | 3181 | CheckFeature termguicolors |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 3182 | CheckDefAndScriptFailure2(['term_getansicolors(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E745: Using a List as a Number') |
| 3183 | enddef |
| 3184 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 3185 | def Test_term_getattr() |
| 3186 | CheckRunVimInTerminal |
| 3187 | CheckDefAndScriptFailure2(['term_getattr("x", "a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 3188 | CheckDefAndScriptFailure2(['term_getattr(1, 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2') |
| 3189 | enddef |
| 3190 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 3191 | def Test_term_getcursor() |
| 3192 | CheckRunVimInTerminal |
| 3193 | CheckDefAndScriptFailure2(['term_getcursor({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E728: Using a Dictionary as a Number') |
| 3194 | enddef |
| 3195 | |
| 3196 | def Test_term_getjob() |
| 3197 | CheckRunVimInTerminal |
| 3198 | CheckDefAndScriptFailure2(['term_getjob(0z10)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E974: Using a Blob as a Number') |
| 3199 | enddef |
| 3200 | |
Yegappan Lakshmanan | cd91720 | 2021-07-21 19:09:09 +0200 | [diff] [blame] | 3201 | def Test_term_getline() |
| 3202 | CheckRunVimInTerminal |
| 3203 | CheckDefAndScriptFailure2(['term_getline(1.1, 1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1') |
| 3204 | CheckDefAndScriptFailure2(['term_getline(1, 1.1)'], 'E1013: Argument 2: type mismatch, expected string but got float', 'E1174: String required for argument 2') |
| 3205 | enddef |
| 3206 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 3207 | def Test_term_getscrolled() |
| 3208 | CheckRunVimInTerminal |
| 3209 | CheckDefAndScriptFailure2(['term_getscrolled(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E805: Using a Float as a Number') |
| 3210 | enddef |
| 3211 | |
| 3212 | def Test_term_getsize() |
| 3213 | CheckRunVimInTerminal |
| 3214 | CheckDefAndScriptFailure2(['term_getsize(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E805: Using a Float as a Number') |
| 3215 | enddef |
| 3216 | |
| 3217 | def Test_term_getstatus() |
| 3218 | CheckRunVimInTerminal |
| 3219 | CheckDefAndScriptFailure2(['term_getstatus(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E805: Using a Float as a Number') |
| 3220 | enddef |
| 3221 | |
| 3222 | def Test_term_gettitle() |
| 3223 | CheckRunVimInTerminal |
| 3224 | CheckDefAndScriptFailure2(['term_gettitle(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E805: Using a Float as a Number') |
| 3225 | enddef |
| 3226 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 3227 | def Test_term_gettty() |
| 3228 | if !has('terminal') |
Dominique Pelle | 9ff9c7b | 2021-07-18 21:44:37 +0200 | [diff] [blame] | 3229 | CheckFeature terminal |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 3230 | else |
| 3231 | var buf = Run_shell_in_terminal({}) |
| 3232 | term_gettty(buf, true)->assert_notequal('') |
| 3233 | StopShellInTerminal(buf) |
| 3234 | endif |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 3235 | CheckDefAndScriptFailure2(['term_gettty([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E1174: String required for argument 1') |
| 3236 | CheckDefAndScriptFailure2(['term_gettty(1, 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 3237 | enddef |
| 3238 | |
Yegappan Lakshmanan | cd91720 | 2021-07-21 19:09:09 +0200 | [diff] [blame] | 3239 | def Test_term_scrape() |
| 3240 | CheckRunVimInTerminal |
| 3241 | CheckDefAndScriptFailure2(['term_scrape(1.1, 1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1') |
| 3242 | CheckDefAndScriptFailure2(['term_scrape(1, 1.1)'], 'E1013: Argument 2: type mismatch, expected string but got float', 'E1174: String required for argument 2') |
| 3243 | enddef |
| 3244 | |
Yegappan Lakshmanan | a9a7c0c | 2021-07-17 19:11:07 +0200 | [diff] [blame] | 3245 | def Test_term_sendkeys() |
| 3246 | CheckRunVimInTerminal |
| 3247 | CheckDefAndScriptFailure2(['term_sendkeys([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1') |
| 3248 | CheckDefAndScriptFailure2(['term_sendkeys(1, [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2') |
| 3249 | enddef |
| 3250 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 3251 | def Test_term_setansicolors() |
| 3252 | CheckRunVimInTerminal |
| 3253 | CheckDefAndScriptFailure2(['term_setansicolors([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1') |
| 3254 | CheckDefAndScriptFailure2(['term_setansicolors(10, {})'], 'E1013: Argument 2: type mismatch, expected list<any> but got dict<unknown>', 'E1211: List required for argument 2') |
| 3255 | enddef |
| 3256 | |
Yegappan Lakshmanan | a9a7c0c | 2021-07-17 19:11:07 +0200 | [diff] [blame] | 3257 | def Test_term_setapi() |
| 3258 | CheckRunVimInTerminal |
| 3259 | CheckDefAndScriptFailure2(['term_setapi([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1') |
| 3260 | CheckDefAndScriptFailure2(['term_setapi(1, [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2') |
| 3261 | enddef |
| 3262 | |
| 3263 | def Test_term_setkill() |
| 3264 | CheckRunVimInTerminal |
| 3265 | CheckDefAndScriptFailure2(['term_setkill([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1') |
| 3266 | CheckDefAndScriptFailure2(['term_setkill(1, [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2') |
| 3267 | enddef |
| 3268 | |
| 3269 | def Test_term_setrestore() |
| 3270 | CheckRunVimInTerminal |
| 3271 | CheckDefAndScriptFailure2(['term_setrestore([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1') |
| 3272 | CheckDefAndScriptFailure2(['term_setrestore(1, [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2') |
| 3273 | enddef |
Yegappan Lakshmanan | cd91720 | 2021-07-21 19:09:09 +0200 | [diff] [blame] | 3274 | |
| 3275 | def Test_term_setsize() |
| 3276 | CheckRunVimInTerminal |
| 3277 | CheckDefAndScriptFailure2(['term_setsize(1.1, 2, 3)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1') |
| 3278 | CheckDefAndScriptFailure2(['term_setsize(1, "2", 3)'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 3279 | CheckDefAndScriptFailure2(['term_setsize(1, 2, "3")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3') |
| 3280 | enddef |
| 3281 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 3282 | def Test_term_start() |
| 3283 | if !has('terminal') |
Dominique Pelle | 9ff9c7b | 2021-07-18 21:44:37 +0200 | [diff] [blame] | 3284 | CheckFeature terminal |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 3285 | else |
| 3286 | botright new |
| 3287 | var winnr = winnr() |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 3288 | term_start(&shell, {curwin: true}) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 3289 | winnr()->assert_equal(winnr) |
| 3290 | bwipe! |
| 3291 | endif |
Yegappan Lakshmanan | cd91720 | 2021-07-21 19:09:09 +0200 | [diff] [blame] | 3292 | CheckDefAndScriptFailure2(['term_start({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>', 'E1174: String required for argument 1') |
| 3293 | CheckDefAndScriptFailure2(['term_start([], [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 2') |
| 3294 | CheckDefAndScriptFailure2(['term_start("", "")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E1206: Dictionary required for argument 2') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 3295 | enddef |
| 3296 | |
Yegappan Lakshmanan | a9a7c0c | 2021-07-17 19:11:07 +0200 | [diff] [blame] | 3297 | def Test_term_wait() |
| 3298 | CheckRunVimInTerminal |
| 3299 | CheckDefAndScriptFailure2(['term_wait(0z10, 1)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1') |
| 3300 | CheckDefAndScriptFailure2(['term_wait(1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 3301 | enddef |
| 3302 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 3303 | def Test_test_alloc_fail() |
| 3304 | CheckDefAndScriptFailure2(['test_alloc_fail("a", 10, 20)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E474: Invalid argument') |
| 3305 | CheckDefAndScriptFailure2(['test_alloc_fail(10, "b", 20)'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E474: Invalid argument') |
| 3306 | CheckDefAndScriptFailure2(['test_alloc_fail(10, 20, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E474: Invalid argument') |
| 3307 | enddef |
| 3308 | |
| 3309 | def Test_test_feedinput() |
| 3310 | CheckDefAndScriptFailure2(['test_feedinput(test_void())'], 'E1013: Argument 1: type mismatch, expected string but got void', 'E1031: Cannot use void value') |
| 3311 | CheckDefAndScriptFailure2(['test_feedinput(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String') |
| 3312 | enddef |
| 3313 | |
| 3314 | def Test_test_getvalue() |
| 3315 | CheckDefAndScriptFailure2(['test_getvalue(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E474: Invalid argument') |
| 3316 | enddef |
| 3317 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 3318 | def Test_test_gui_mouse_event() |
| 3319 | CheckGui |
| 3320 | CheckDefAndScriptFailure2(['test_gui_mouse_event(1.1, 1, 1, 1, 1)'], 'E1013: Argument 1: type mismatch, expected number but got float', 'E1210: Number required for argument 1') |
| 3321 | CheckDefAndScriptFailure2(['test_gui_mouse_event(1, "1", 1, 1, 1)'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 3322 | CheckDefAndScriptFailure2(['test_gui_mouse_event(1, 1, "1", 1, 1)'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3') |
| 3323 | CheckDefAndScriptFailure2(['test_gui_mouse_event(1, 1, 1, "1", 1)'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4') |
| 3324 | CheckDefAndScriptFailure2(['test_gui_mouse_event(1, 1, 1, 1, "1")'], 'E1013: Argument 5: type mismatch, expected number but got string', 'E1210: Number required for argument 5') |
| 3325 | enddef |
| 3326 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 3327 | def Test_test_ignore_error() |
| 3328 | CheckDefAndScriptFailure2(['test_ignore_error([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E474: Invalid argument') |
| 3329 | test_ignore_error('RESET') |
| 3330 | enddef |
| 3331 | |
| 3332 | def Test_test_option_not_set() |
| 3333 | CheckDefAndScriptFailure2(['test_option_not_set([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E474: Invalid argument') |
| 3334 | enddef |
| 3335 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 3336 | def Test_test_override() |
| 3337 | CheckDefAndScriptFailure2(['test_override(1, 1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') |
| 3338 | CheckDefAndScriptFailure2(['test_override("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 3339 | enddef |
| 3340 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 3341 | def Test_test_setmouse() |
| 3342 | CheckDefAndScriptFailure2(['test_setmouse("a", 10)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E474: Invalid argument') |
| 3343 | CheckDefAndScriptFailure2(['test_setmouse(10, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E474: Invalid argument') |
| 3344 | enddef |
| 3345 | |
| 3346 | def Test_test_settime() |
| 3347 | CheckDefAndScriptFailure2(['test_settime([1])'], 'E1013: Argument 1: type mismatch, expected number but got list<number>', 'E745: Using a List as a Number') |
| 3348 | enddef |
| 3349 | |
| 3350 | def Test_test_srand_seed() |
| 3351 | CheckDefAndScriptFailure2(['test_srand_seed([1])'], 'E1013: Argument 1: type mismatch, expected number but got list<number>', 'E745: Using a List as a Number') |
| 3352 | CheckDefAndScriptFailure2(['test_srand_seed("10")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 3353 | enddef |
| 3354 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 3355 | def Test_timer_info() |
| 3356 | CheckDefFailure(['timer_info("id")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 3357 | assert_equal([], timer_info(100)) |
| 3358 | assert_equal([], timer_info()) |
| 3359 | enddef |
| 3360 | |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 3361 | def Test_timer_pause() |
| 3362 | CheckDefAndScriptFailure2(['timer_pause("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 3363 | CheckDefAndScriptFailure2(['timer_pause(1, "a")'], 'E1013: Argument 2: type mismatch, expected bool but got string', 'E1212: Bool required for argument 2') |
| 3364 | enddef |
| 3365 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 3366 | def Test_timer_paused() |
Bram Moolenaar | 2949cfd | 2020-12-31 21:28:47 +0100 | [diff] [blame] | 3367 | var id = timer_start(50, () => 0) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 3368 | timer_pause(id, true) |
| 3369 | var info = timer_info(id) |
| 3370 | info[0]['paused']->assert_equal(1) |
| 3371 | timer_stop(id) |
| 3372 | enddef |
| 3373 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 3374 | def Test_timer_stop() |
| 3375 | CheckDefFailure(['timer_stop("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 3376 | assert_equal(0, timer_stop(100)) |
| 3377 | enddef |
| 3378 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 3379 | def Test_tolower() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 3380 | CheckDefFailure(['tolower(1)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 3381 | enddef |
| 3382 | |
| 3383 | def Test_toupper() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 3384 | CheckDefFailure(['toupper(1)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 3385 | enddef |
| 3386 | |
| 3387 | def Test_tr() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 3388 | CheckDefFailure(['tr(1, "a", "b")'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 3389 | CheckDefFailure(['tr("a", 1, "b")'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 3390 | CheckDefFailure(['tr("a", "a", 1)'], 'E1013: Argument 3: type mismatch, expected string but got number') |
| 3391 | enddef |
| 3392 | |
| 3393 | def Test_trim() |
| 3394 | CheckDefAndScriptFailure2(['trim(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String') |
| 3395 | CheckDefAndScriptFailure2(['trim("a", ["b"])'], 'E1013: Argument 2: type mismatch, expected string but got list<string>', 'E730: Using a List as a String') |
| 3396 | CheckDefAndScriptFailure2(['trim("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 3397 | enddef |
| 3398 | |
Bram Moolenaar | 9da32e4 | 2021-07-09 19:53:57 +0200 | [diff] [blame] | 3399 | def Test_typename() |
| 3400 | if has('float') |
| 3401 | assert_equal('func([unknown], [unknown]): float', typename(function('pow'))) |
| 3402 | endif |
| 3403 | enddef |
| 3404 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 3405 | def Test_undofile() |
| 3406 | CheckDefFailure(['undofile(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 3407 | assert_equal('.abc.un~', fnamemodify(undofile('abc'), ':t')) |
| 3408 | enddef |
| 3409 | |
Yegappan Lakshmanan | 0ad871d | 2021-07-23 20:37:56 +0200 | [diff] [blame] | 3410 | def Test_uniq() |
| 3411 | CheckDefAndScriptFailure2(['uniq("a")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E1211: List required for argument 1') |
| 3412 | CheckDefAndScriptFailure2(['uniq([1], "", [1])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 3') |
| 3413 | enddef |
| 3414 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 3415 | def Test_values() |
| 3416 | CheckDefFailure(['values([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>') |
| 3417 | assert_equal([], {}->values()) |
| 3418 | assert_equal(['sun'], {star: 'sun'}->values()) |
| 3419 | enddef |
| 3420 | |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 3421 | def Test_virtcol() |
| 3422 | CheckDefAndScriptFailure2(['virtcol(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1') |
Yegappan Lakshmanan | c72bdd2 | 2021-07-11 19:44:18 +0200 | [diff] [blame] | 3423 | new |
| 3424 | setline(1, ['abcdefgh']) |
| 3425 | cursor(1, 4) |
| 3426 | assert_equal(4, virtcol('.')) |
Yegappan Lakshmanan | 841e498 | 2021-07-11 22:04:25 +0200 | [diff] [blame] | 3427 | assert_equal(4, virtcol([1, 4])) |
Yegappan Lakshmanan | c72bdd2 | 2021-07-11 19:44:18 +0200 | [diff] [blame] | 3428 | assert_equal(9, virtcol([1, '$'])) |
| 3429 | assert_equal(0, virtcol([10, '$'])) |
| 3430 | bw! |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 3431 | enddef |
| 3432 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 3433 | def Test_visualmode() |
| 3434 | CheckDefFailure(['visualmode("1")'], 'E1013: Argument 1: type mismatch, expected bool but got string') |
| 3435 | CheckDefFailure(['visualmode(2)'], 'E1013: Argument 1: type mismatch, expected bool but got number') |
| 3436 | enddef |
| 3437 | |
Bram Moolenaar | 37487e1 | 2021-01-12 22:08:53 +0100 | [diff] [blame] | 3438 | def Test_win_execute() |
| 3439 | assert_equal("\n" .. winnr(), win_execute(win_getid(), 'echo winnr()')) |
Bram Moolenaar | 5231224 | 2021-07-11 18:23:19 +0200 | [diff] [blame] | 3440 | assert_equal("\n" .. winnr(), 'echo winnr()'->win_execute(win_getid())) |
| 3441 | assert_equal("\n" .. winnr(), win_execute(win_getid(), 'echo winnr()', 'silent')) |
Bram Moolenaar | 37487e1 | 2021-01-12 22:08:53 +0100 | [diff] [blame] | 3442 | assert_equal('', win_execute(342343, 'echo winnr()')) |
| 3443 | enddef |
| 3444 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 3445 | def Test_win_findbuf() |
| 3446 | CheckDefFailure(['win_findbuf("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 3447 | assert_equal([], win_findbuf(1000)) |
| 3448 | assert_equal([win_getid()], win_findbuf(bufnr(''))) |
| 3449 | enddef |
| 3450 | |
| 3451 | def Test_win_getid() |
| 3452 | CheckDefFailure(['win_getid(".")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 3453 | CheckDefFailure(['win_getid(1, ".")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 3454 | assert_equal(win_getid(), win_getid(1, 1)) |
| 3455 | enddef |
| 3456 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 3457 | def Test_win_gettype() |
| 3458 | CheckDefAndScriptFailure2(['win_gettype("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 3459 | enddef |
| 3460 | |
| 3461 | def Test_win_gotoid() |
| 3462 | CheckDefAndScriptFailure2(['win_gotoid("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 3463 | enddef |
| 3464 | |
| 3465 | def Test_win_id2tabwin() |
| 3466 | CheckDefAndScriptFailure2(['win_id2tabwin("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 3467 | enddef |
| 3468 | |
| 3469 | def Test_win_id2win() |
| 3470 | CheckDefAndScriptFailure2(['win_id2win("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 3471 | enddef |
| 3472 | |
| 3473 | def Test_win_screenpos() |
| 3474 | CheckDefAndScriptFailure2(['win_screenpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 3475 | enddef |
| 3476 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 3477 | def Test_win_splitmove() |
| 3478 | split |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 3479 | win_splitmove(1, 2, {vertical: true, rightbelow: true}) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 3480 | close |
Yegappan Lakshmanan | 83494b4 | 2021-07-20 17:51:51 +0200 | [diff] [blame] | 3481 | CheckDefAndScriptFailure2(['win_splitmove("a", 2)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1') |
| 3482 | CheckDefAndScriptFailure2(['win_splitmove(1, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') |
| 3483 | CheckDefAndScriptFailure2(['win_splitmove(1, 2, [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 3484 | enddef |
| 3485 | |
Yegappan Lakshmanan | 1a71d31 | 2021-07-15 12:49:58 +0200 | [diff] [blame] | 3486 | def Test_winbufnr() |
| 3487 | CheckDefAndScriptFailure2(['winbufnr("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 3488 | enddef |
| 3489 | |
| 3490 | def Test_winheight() |
| 3491 | CheckDefAndScriptFailure2(['winheight("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 3492 | enddef |
| 3493 | |
| 3494 | def Test_winlayout() |
| 3495 | CheckDefAndScriptFailure2(['winlayout("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 3496 | enddef |
| 3497 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 3498 | def Test_winnr() |
| 3499 | CheckDefFailure(['winnr([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') |
| 3500 | assert_equal(1, winnr()) |
| 3501 | assert_equal(1, winnr('$')) |
| 3502 | enddef |
| 3503 | |
Bram Moolenaar | 285b15f | 2020-12-29 20:25:19 +0100 | [diff] [blame] | 3504 | def Test_winrestcmd() |
| 3505 | split |
| 3506 | var cmd = winrestcmd() |
| 3507 | wincmd _ |
| 3508 | exe cmd |
| 3509 | assert_equal(cmd, winrestcmd()) |
| 3510 | close |
| 3511 | enddef |
| 3512 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 3513 | def Test_winrestview() |
| 3514 | CheckDefFailure(['winrestview([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>') |
| 3515 | :%d _ |
| 3516 | setline(1, 'Hello World') |
| 3517 | winrestview({lnum: 1, col: 6}) |
| 3518 | assert_equal([1, 7], [line('.'), col('.')]) |
| 3519 | enddef |
| 3520 | |
Bram Moolenaar | 43b69b3 | 2021-01-07 20:23:33 +0100 | [diff] [blame] | 3521 | def Test_winsaveview() |
| 3522 | var view: dict<number> = winsaveview() |
| 3523 | |
| 3524 | var lines =<< trim END |
| 3525 | var view: list<number> = winsaveview() |
| 3526 | END |
| 3527 | CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<number> but got dict<number>', 1) |
| 3528 | enddef |
| 3529 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 3530 | def Test_winwidth() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 3531 | CheckDefAndScriptFailure2(['winwidth("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 3532 | enddef |
| 3533 | |
| 3534 | def Test_xor() |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 3535 | CheckDefAndScriptFailure2(['xor("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
| 3536 | CheckDefAndScriptFailure2(['xor(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1030: Using a String as a Number') |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 3537 | enddef |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 3538 | |
| 3539 | " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker |