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 | |
| 78 | def Test_add_list() |
| 79 | var l: list<number> # defaults to empty list |
| 80 | add(l, 9) |
| 81 | assert_equal([9], l) |
| 82 | |
| 83 | var lines =<< trim END |
| 84 | var l: list<number> |
| 85 | add(l, "x") |
| 86 | END |
| 87 | CheckDefFailure(lines, 'E1012:', 2) |
| 88 | |
| 89 | lines =<< trim END |
Bram Moolenaar | b7c21af | 2021-04-18 14:12:31 +0200 | [diff] [blame] | 90 | add(test_null_list(), 123) |
| 91 | END |
| 92 | CheckDefExecAndScriptFailure(lines, 'E1130:', 1) |
| 93 | |
| 94 | lines =<< trim END |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 95 | var l: list<number> = test_null_list() |
| 96 | add(l, 123) |
| 97 | END |
| 98 | CheckDefExecFailure(lines, 'E1130:', 2) |
Bram Moolenaar | b7c21af | 2021-04-18 14:12:31 +0200 | [diff] [blame] | 99 | |
| 100 | # Getting variable with NULL list allocates a new list at script level |
| 101 | lines =<< trim END |
| 102 | vim9script |
| 103 | var l: list<number> = test_null_list() |
| 104 | add(l, 123) |
| 105 | END |
| 106 | CheckScriptSuccess(lines) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 107 | enddef |
| 108 | |
| 109 | def Test_add_blob() |
| 110 | var b1: blob = 0z12 |
| 111 | add(b1, 0x34) |
| 112 | assert_equal(0z1234, b1) |
| 113 | |
| 114 | var b2: blob # defaults to empty blob |
| 115 | add(b2, 0x67) |
| 116 | assert_equal(0z67, b2) |
| 117 | |
| 118 | var lines =<< trim END |
| 119 | var b: blob |
| 120 | add(b, "x") |
| 121 | END |
| 122 | CheckDefFailure(lines, 'E1012:', 2) |
| 123 | |
| 124 | lines =<< trim END |
Bram Moolenaar | b7c21af | 2021-04-18 14:12:31 +0200 | [diff] [blame] | 125 | add(test_null_blob(), 123) |
| 126 | END |
| 127 | CheckDefExecAndScriptFailure(lines, 'E1131:', 1) |
| 128 | |
| 129 | lines =<< trim END |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 130 | var b: blob = test_null_blob() |
| 131 | add(b, 123) |
| 132 | END |
| 133 | CheckDefExecFailure(lines, 'E1131:', 2) |
Bram Moolenaar | b7c21af | 2021-04-18 14:12:31 +0200 | [diff] [blame] | 134 | |
| 135 | # Getting variable with NULL blob allocates a new blob at script level |
| 136 | lines =<< trim END |
| 137 | vim9script |
| 138 | var b: blob = test_null_blob() |
| 139 | add(b, 123) |
| 140 | END |
| 141 | CheckScriptSuccess(lines) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 142 | enddef |
| 143 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame^] | 144 | def Test_and() |
| 145 | CheckDefFailure(['echo and("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 146 | CheckDefFailure(['echo and(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 147 | enddef |
| 148 | |
Bram Moolenaar | 3af15ab | 2021-01-17 16:16:23 +0100 | [diff] [blame] | 149 | def Test_append() |
| 150 | new |
| 151 | setline(1, range(3)) |
| 152 | var res1: number = append(1, 'one') |
| 153 | assert_equal(0, res1) |
| 154 | var res2: bool = append(3, 'two') |
| 155 | assert_equal(false, res2) |
| 156 | assert_equal(['0', 'one', '1', 'two', '2'], getline(1, 6)) |
Bram Moolenaar | b2ac7d0 | 2021-03-28 15:46:16 +0200 | [diff] [blame] | 157 | |
| 158 | append(0, 'zero') |
| 159 | assert_equal('zero', getline(1)) |
| 160 | bwipe! |
Bram Moolenaar | 3af15ab | 2021-01-17 16:16:23 +0100 | [diff] [blame] | 161 | enddef |
| 162 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame^] | 163 | def Test_argc() |
| 164 | CheckDefFailure(['echo argc("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 165 | enddef |
| 166 | |
| 167 | def Test_arglistid() |
| 168 | CheckDefFailure(['echo arglistid("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 169 | CheckDefFailure(['echo arglistid(1, "y")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 170 | CheckDefFailure(['echo arglistid("x", "y")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 171 | enddef |
| 172 | |
| 173 | def Test_argv() |
| 174 | CheckDefFailure(['echo argv("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 175 | CheckDefFailure(['echo argv(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 176 | CheckDefFailure(['echo argv("x", "y")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 177 | enddef |
| 178 | |
Bram Moolenaar | 32105ae | 2021-03-27 18:59:25 +0100 | [diff] [blame] | 179 | def Test_balloon_show() |
| 180 | CheckGui |
| 181 | CheckFeature balloon_eval |
| 182 | |
| 183 | assert_fails('balloon_show(true)', 'E1174:') |
| 184 | enddef |
| 185 | |
| 186 | def Test_balloon_split() |
Bram Moolenaar | 7b45d46 | 2021-03-27 19:09:02 +0100 | [diff] [blame] | 187 | CheckFeature balloon_eval_term |
Bram Moolenaar | 32105ae | 2021-03-27 18:59:25 +0100 | [diff] [blame] | 188 | |
| 189 | assert_fails('balloon_split(true)', 'E1174:') |
| 190 | enddef |
| 191 | |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 192 | def Test_browse() |
| 193 | CheckFeature browse |
| 194 | |
| 195 | var lines =<< trim END |
Bram Moolenaar | f49a1fc | 2021-03-27 22:20:21 +0100 | [diff] [blame] | 196 | browse(1, 2, 3, 4) |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 197 | END |
| 198 | CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 2') |
| 199 | lines =<< trim END |
Bram Moolenaar | f49a1fc | 2021-03-27 22:20:21 +0100 | [diff] [blame] | 200 | browse(1, 'title', 3, 4) |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 201 | END |
| 202 | CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 3') |
| 203 | lines =<< trim END |
Bram Moolenaar | f49a1fc | 2021-03-27 22:20:21 +0100 | [diff] [blame] | 204 | browse(1, 'title', 'dir', 4) |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 205 | END |
| 206 | CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 4') |
| 207 | enddef |
| 208 | |
Bram Moolenaar | 32105ae | 2021-03-27 18:59:25 +0100 | [diff] [blame] | 209 | def Test_bufexists() |
| 210 | assert_fails('bufexists(true)', 'E1174') |
| 211 | enddef |
| 212 | |
Bram Moolenaar | 3af15ab | 2021-01-17 16:16:23 +0100 | [diff] [blame] | 213 | def Test_buflisted() |
| 214 | var res: bool = buflisted('asdf') |
| 215 | assert_equal(false, res) |
Bram Moolenaar | 32105ae | 2021-03-27 18:59:25 +0100 | [diff] [blame] | 216 | assert_fails('buflisted(true)', 'E1174') |
Bram Moolenaar | 3af15ab | 2021-01-17 16:16:23 +0100 | [diff] [blame] | 217 | enddef |
| 218 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 219 | def Test_bufname() |
| 220 | split SomeFile |
| 221 | bufname('%')->assert_equal('SomeFile') |
| 222 | edit OtherFile |
| 223 | bufname('#')->assert_equal('SomeFile') |
| 224 | close |
| 225 | enddef |
| 226 | |
| 227 | def Test_bufnr() |
| 228 | var buf = bufnr() |
| 229 | bufnr('%')->assert_equal(buf) |
| 230 | |
| 231 | buf = bufnr('Xdummy', true) |
| 232 | buf->assert_notequal(-1) |
| 233 | exe 'bwipe! ' .. buf |
| 234 | enddef |
| 235 | |
| 236 | def Test_bufwinid() |
| 237 | var origwin = win_getid() |
| 238 | below split SomeFile |
| 239 | var SomeFileID = win_getid() |
| 240 | below split OtherFile |
| 241 | below split SomeFile |
| 242 | bufwinid('SomeFile')->assert_equal(SomeFileID) |
| 243 | |
| 244 | win_gotoid(origwin) |
| 245 | only |
| 246 | bwipe SomeFile |
| 247 | bwipe OtherFile |
Bram Moolenaar | 32105ae | 2021-03-27 18:59:25 +0100 | [diff] [blame] | 248 | |
| 249 | assert_fails('bufwinid(true)', 'E1138') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 250 | enddef |
| 251 | |
| 252 | def Test_call_call() |
| 253 | var l = [3, 2, 1] |
| 254 | call('reverse', [l]) |
| 255 | l->assert_equal([1, 2, 3]) |
| 256 | enddef |
| 257 | |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 258 | def Test_ch_logfile() |
Bram Moolenaar | 886e5e7 | 2021-04-05 13:36:34 +0200 | [diff] [blame] | 259 | if !has('channel') |
| 260 | CheckFeature channel |
| 261 | endif |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 262 | assert_fails('ch_logfile(true)', 'E1174') |
| 263 | assert_fails('ch_logfile("foo", true)', 'E1174') |
| 264 | enddef |
| 265 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 266 | def Test_char2nr() |
| 267 | char2nr('あ', true)->assert_equal(12354) |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 268 | |
| 269 | assert_fails('char2nr(true)', 'E1174') |
| 270 | enddef |
| 271 | |
| 272 | def Test_charclass() |
| 273 | assert_fails('charclass(true)', 'E1174') |
| 274 | enddef |
| 275 | |
| 276 | def Test_chdir() |
| 277 | assert_fails('chdir(true)', 'E1174') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 278 | enddef |
| 279 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame^] | 280 | def Test_clearmatches() |
| 281 | CheckDefFailure(['echo clearmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 282 | enddef |
| 283 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 284 | def Test_col() |
| 285 | new |
| 286 | setline(1, 'asdf') |
| 287 | col([1, '$'])->assert_equal(5) |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 288 | |
| 289 | assert_fails('col(true)', 'E1174') |
| 290 | enddef |
| 291 | |
| 292 | def Test_confirm() |
| 293 | if !has('dialog_con') && !has('dialog_gui') |
| 294 | CheckFeature dialog_con |
| 295 | endif |
| 296 | |
Bram Moolenaar | f49a1fc | 2021-03-27 22:20:21 +0100 | [diff] [blame] | 297 | assert_fails('confirm(true)', 'E1174') |
| 298 | assert_fails('confirm("yes", true)', 'E1174') |
| 299 | assert_fails('confirm("yes", "maybe", 2, true)', 'E1174') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 300 | enddef |
| 301 | |
| 302 | def Test_copy_return_type() |
| 303 | var l = copy([1, 2, 3]) |
| 304 | var res = 0 |
| 305 | for n in l |
| 306 | res += n |
| 307 | endfor |
| 308 | res->assert_equal(6) |
| 309 | |
| 310 | var dl = deepcopy([1, 2, 3]) |
| 311 | res = 0 |
| 312 | for n in dl |
| 313 | res += n |
| 314 | endfor |
| 315 | res->assert_equal(6) |
| 316 | |
| 317 | dl = deepcopy([1, 2, 3], true) |
| 318 | enddef |
| 319 | |
| 320 | def Test_count() |
| 321 | count('ABC ABC ABC', 'b', true)->assert_equal(3) |
| 322 | count('ABC ABC ABC', 'b', false)->assert_equal(0) |
| 323 | enddef |
| 324 | |
Bram Moolenaar | 9a96337 | 2020-12-21 21:58:46 +0100 | [diff] [blame] | 325 | def Test_cursor() |
| 326 | new |
| 327 | setline(1, range(4)) |
| 328 | cursor(2, 1) |
| 329 | assert_equal(2, getcurpos()[1]) |
| 330 | cursor('$', 1) |
| 331 | assert_equal(4, getcurpos()[1]) |
| 332 | |
| 333 | var lines =<< trim END |
| 334 | cursor('2', 1) |
| 335 | END |
| 336 | CheckDefExecAndScriptFailure(lines, 'E475:') |
| 337 | enddef |
| 338 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame^] | 339 | def Test_debugbreak() |
| 340 | CheckMSWindows |
| 341 | CheckDefFailure(['echo debugbreak("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 342 | enddef |
| 343 | |
Bram Moolenaar | 3af15ab | 2021-01-17 16:16:23 +0100 | [diff] [blame] | 344 | def Test_delete() |
| 345 | var res: bool = delete('doesnotexist') |
| 346 | assert_equal(true, res) |
| 347 | enddef |
| 348 | |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 349 | def Test_executable() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 350 | assert_false(executable("")) |
| 351 | assert_false(executable(test_null_string())) |
| 352 | |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 353 | CheckDefExecFailure(['echo executable(123)'], 'E1174:') |
| 354 | CheckDefExecFailure(['echo executable(true)'], 'E1174:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 355 | enddef |
| 356 | |
Bram Moolenaar | ca81f0e | 2021-06-20 14:41:01 +0200 | [diff] [blame] | 357 | def Test_execute() |
| 358 | var res = execute("echo 'hello'") |
| 359 | assert_equal("\nhello", res) |
| 360 | res = execute(["echo 'here'", "echo 'there'"]) |
| 361 | assert_equal("\nhere\nthere", res) |
| 362 | |
| 363 | CheckDefFailure(['echo execute(123)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 364 | CheckDefFailure(['echo execute([123])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>') |
| 365 | CheckDefExecFailure(['echo execute(["xx", 123])'], 'E492') |
| 366 | CheckDefFailure(['echo execute("xx", 123)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 367 | enddef |
| 368 | |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 369 | def Test_exepath() |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 370 | CheckDefExecFailure(['echo exepath(true)'], 'E1174:') |
| 371 | CheckDefExecFailure(['echo exepath(v:null)'], 'E1174:') |
Bram Moolenaar | fa98441 | 2021-03-25 22:15:28 +0100 | [diff] [blame] | 372 | CheckDefExecFailure(['echo exepath("")'], 'E1175:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 373 | enddef |
| 374 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 375 | def Test_expand() |
| 376 | split SomeFile |
| 377 | expand('%', true, true)->assert_equal(['SomeFile']) |
| 378 | close |
| 379 | enddef |
| 380 | |
Bram Moolenaar | 0279510 | 2021-05-03 21:40:26 +0200 | [diff] [blame] | 381 | def Test_expandcmd() |
| 382 | $FOO = "blue" |
| 383 | assert_equal("blue sky", expandcmd("`=$FOO .. ' sky'`")) |
| 384 | |
| 385 | assert_equal("yes", expandcmd("`={a: 'yes'}['a']`")) |
| 386 | enddef |
| 387 | |
Bram Moolenaar | fbcbffe | 2020-10-31 19:33:38 +0100 | [diff] [blame] | 388 | def Test_extend_arg_types() |
Bram Moolenaar | c03f5c6 | 2021-01-31 17:48:30 +0100 | [diff] [blame] | 389 | g:number_one = 1 |
| 390 | g:string_keep = 'keep' |
| 391 | var lines =<< trim END |
| 392 | assert_equal([1, 2, 3], extend([1, 2], [3])) |
| 393 | assert_equal([3, 1, 2], extend([1, 2], [3], 0)) |
| 394 | assert_equal([1, 3, 2], extend([1, 2], [3], 1)) |
| 395 | assert_equal([1, 3, 2], extend([1, 2], [3], g:number_one)) |
Bram Moolenaar | fbcbffe | 2020-10-31 19:33:38 +0100 | [diff] [blame] | 396 | |
Bram Moolenaar | c03f5c6 | 2021-01-31 17:48:30 +0100 | [diff] [blame] | 397 | assert_equal({a: 1, b: 2, c: 3}, extend({a: 1, b: 2}, {c: 3})) |
| 398 | assert_equal({a: 1, b: 4}, extend({a: 1, b: 2}, {b: 4})) |
| 399 | assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, 'keep')) |
| 400 | 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] | 401 | |
Bram Moolenaar | c03f5c6 | 2021-01-31 17:48:30 +0100 | [diff] [blame] | 402 | var res: list<dict<any>> |
| 403 | extend(res, mapnew([1, 2], (_, v) => ({}))) |
| 404 | assert_equal([{}, {}], res) |
| 405 | END |
| 406 | CheckDefAndScriptSuccess(lines) |
Bram Moolenaar | fbcbffe | 2020-10-31 19:33:38 +0100 | [diff] [blame] | 407 | |
Yegappan Lakshmanan | 34fcb69 | 2021-05-25 20:14:00 +0200 | [diff] [blame] | 408 | 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] | 409 | CheckDefFailure(['extend([1, 2], 3)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number') |
| 410 | CheckDefFailure(['extend([1, 2], ["x"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>') |
| 411 | CheckDefFailure(['extend([1, 2], [3], "x")'], 'E1013: Argument 3: type mismatch, expected number but got string') |
| 412 | |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 413 | CheckDefFailure(['extend({a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number') |
| 414 | CheckDefFailure(['extend({a: 1}, {b: "x"})'], 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>') |
| 415 | 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] | 416 | |
| 417 | 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] | 418 | CheckDefExecFailure(['extend([1], ["b", 1])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<any>') |
Bram Moolenaar | fbcbffe | 2020-10-31 19:33:38 +0100 | [diff] [blame] | 419 | enddef |
| 420 | |
Bram Moolenaar | b0e6b51 | 2021-01-12 20:23:40 +0100 | [diff] [blame] | 421 | def Test_extendnew() |
| 422 | assert_equal([1, 2, 'a'], extendnew([1, 2], ['a'])) |
| 423 | assert_equal({one: 1, two: 'a'}, extendnew({one: 1}, {two: 'a'})) |
| 424 | |
| 425 | CheckDefFailure(['extendnew({a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number') |
| 426 | CheckDefFailure(['extendnew({a: 1}, [42])'], 'E1013: Argument 2: type mismatch, expected dict<number> but got list<number>') |
| 427 | CheckDefFailure(['extendnew([1, 2], "x")'], 'E1013: Argument 2: type mismatch, expected list<number> but got string') |
| 428 | CheckDefFailure(['extendnew([1, 2], {x: 1})'], 'E1013: Argument 2: type mismatch, expected list<number> but got dict<number>') |
| 429 | enddef |
| 430 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 431 | def Test_extend_return_type() |
| 432 | var l = extend([1, 2], [3]) |
| 433 | var res = 0 |
| 434 | for n in l |
| 435 | res += n |
| 436 | endfor |
| 437 | res->assert_equal(6) |
| 438 | enddef |
| 439 | |
Bram Moolenaar | aa210a3 | 2021-01-02 15:41:03 +0100 | [diff] [blame] | 440 | func g:ExtendDict(d) |
| 441 | call extend(a:d, #{xx: 'x'}) |
| 442 | endfunc |
| 443 | |
| 444 | def Test_extend_dict_item_type() |
| 445 | var lines =<< trim END |
| 446 | var d: dict<number> = {a: 1} |
| 447 | extend(d, {b: 2}) |
| 448 | END |
| 449 | CheckDefAndScriptSuccess(lines) |
| 450 | |
| 451 | lines =<< trim END |
| 452 | var d: dict<number> = {a: 1} |
| 453 | extend(d, {b: 'x'}) |
| 454 | END |
Bram Moolenaar | c03f5c6 | 2021-01-31 17:48:30 +0100 | [diff] [blame] | 455 | 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] | 456 | |
| 457 | lines =<< trim END |
| 458 | var d: dict<number> = {a: 1} |
| 459 | g:ExtendDict(d) |
| 460 | END |
| 461 | CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string', 0) |
| 462 | CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1) |
| 463 | enddef |
| 464 | |
| 465 | func g:ExtendList(l) |
| 466 | call extend(a:l, ['x']) |
| 467 | endfunc |
| 468 | |
| 469 | def Test_extend_list_item_type() |
| 470 | var lines =<< trim END |
| 471 | var l: list<number> = [1] |
| 472 | extend(l, [2]) |
| 473 | END |
| 474 | CheckDefAndScriptSuccess(lines) |
| 475 | |
| 476 | lines =<< trim END |
| 477 | var l: list<number> = [1] |
| 478 | extend(l, ['x']) |
| 479 | END |
Bram Moolenaar | c03f5c6 | 2021-01-31 17:48:30 +0100 | [diff] [blame] | 480 | 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] | 481 | |
| 482 | lines =<< trim END |
| 483 | var l: list<number> = [1] |
| 484 | g:ExtendList(l) |
| 485 | END |
| 486 | CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string', 0) |
| 487 | CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1) |
| 488 | enddef |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 489 | |
Bram Moolenaar | 93e1cae | 2021-03-13 21:24:56 +0100 | [diff] [blame] | 490 | def Test_extend_with_error_function() |
| 491 | var lines =<< trim END |
| 492 | vim9script |
| 493 | def F() |
| 494 | { |
| 495 | var m = 10 |
| 496 | } |
| 497 | echo m |
| 498 | enddef |
| 499 | |
| 500 | def Test() |
| 501 | var d: dict<any> = {} |
| 502 | d->extend({A: 10, Func: function('F', [])}) |
| 503 | enddef |
| 504 | |
| 505 | Test() |
| 506 | END |
| 507 | CheckScriptFailure(lines, 'E1001: Variable not found: m') |
| 508 | enddef |
| 509 | |
Bram Moolenaar | 64ed4d4 | 2021-01-12 21:22:31 +0100 | [diff] [blame] | 510 | def Test_job_info_return_type() |
| 511 | if has('job') |
| 512 | job_start(&shell) |
| 513 | var jobs = job_info() |
Bram Moolenaar | a47e05f | 2021-01-12 21:49:00 +0100 | [diff] [blame] | 514 | assert_equal('list<job>', typename(jobs)) |
| 515 | assert_equal('dict<any>', typename(job_info(jobs[0]))) |
Bram Moolenaar | 64ed4d4 | 2021-01-12 21:22:31 +0100 | [diff] [blame] | 516 | job_stop(jobs[0]) |
| 517 | endif |
| 518 | enddef |
| 519 | |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 520 | def Test_filereadable() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 521 | assert_false(filereadable("")) |
| 522 | assert_false(filereadable(test_null_string())) |
| 523 | |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 524 | CheckDefExecFailure(['echo filereadable(123)'], 'E1174:') |
| 525 | CheckDefExecFailure(['echo filereadable(true)'], 'E1174:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 526 | enddef |
| 527 | |
| 528 | def Test_filewritable() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 529 | assert_false(filewritable("")) |
| 530 | assert_false(filewritable(test_null_string())) |
| 531 | |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 532 | CheckDefExecFailure(['echo filewritable(123)'], 'E1174:') |
| 533 | CheckDefExecFailure(['echo filewritable(true)'], 'E1174:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 534 | enddef |
| 535 | |
| 536 | def Test_finddir() |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 537 | CheckDefExecFailure(['echo finddir(true)'], 'E1174:') |
| 538 | CheckDefExecFailure(['echo finddir(v:null)'], 'E1174:') |
Bram Moolenaar | fa98441 | 2021-03-25 22:15:28 +0100 | [diff] [blame] | 539 | CheckDefExecFailure(['echo finddir("")'], 'E1175:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 540 | enddef |
| 541 | |
| 542 | def Test_findfile() |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 543 | CheckDefExecFailure(['echo findfile(true)'], 'E1174:') |
| 544 | CheckDefExecFailure(['echo findfile(v:null)'], 'E1174:') |
Bram Moolenaar | fa98441 | 2021-03-25 22:15:28 +0100 | [diff] [blame] | 545 | CheckDefExecFailure(['echo findfile("")'], 'E1175:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 546 | enddef |
| 547 | |
Bram Moolenaar | 3b69006 | 2021-02-01 20:14:51 +0100 | [diff] [blame] | 548 | def Test_flattennew() |
| 549 | var lines =<< trim END |
| 550 | var l = [1, [2, [3, 4]], 5] |
| 551 | call assert_equal([1, 2, 3, 4, 5], flattennew(l)) |
| 552 | call assert_equal([1, [2, [3, 4]], 5], l) |
| 553 | |
| 554 | call assert_equal([1, 2, [3, 4], 5], flattennew(l, 1)) |
| 555 | call assert_equal([1, [2, [3, 4]], 5], l) |
| 556 | END |
| 557 | CheckDefAndScriptSuccess(lines) |
| 558 | |
| 559 | lines =<< trim END |
| 560 | echo flatten([1, 2, 3]) |
| 561 | END |
| 562 | CheckDefAndScriptFailure(lines, 'E1158:') |
| 563 | enddef |
| 564 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame^] | 565 | " Test for float functions argument type |
| 566 | def Test_float_funcs_args() |
| 567 | CheckFeature float |
| 568 | |
| 569 | # acos() |
| 570 | CheckDefFailure(['echo acos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 571 | # asin() |
| 572 | CheckDefFailure(['echo asin("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 573 | # atan() |
| 574 | CheckDefFailure(['echo atan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 575 | # atan2() |
| 576 | CheckDefFailure(['echo atan2("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 577 | CheckDefFailure(['echo atan2(1.2, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 578 | CheckDefFailure(['echo atan2(1.2)'], 'E119:') |
| 579 | # ceil() |
| 580 | CheckDefFailure(['echo ceil("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 581 | # cos() |
| 582 | CheckDefFailure(['echo cos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 583 | # cosh() |
| 584 | CheckDefFailure(['echo cosh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 585 | # exp() |
| 586 | CheckDefFailure(['echo exp("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 587 | # float2nr() |
| 588 | CheckDefFailure(['echo float2nr("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 589 | # floor() |
| 590 | CheckDefFailure(['echo floor("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 591 | # fmod() |
| 592 | CheckDefFailure(['echo fmod(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 593 | CheckDefFailure(['echo fmod("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 594 | CheckDefFailure(['echo fmod(1.1)'], 'E119:') |
| 595 | # isinf() |
| 596 | CheckDefFailure(['echo isinf("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 597 | # isnan() |
| 598 | CheckDefFailure(['echo isnan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 599 | # log() |
| 600 | CheckDefFailure(['echo log("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 601 | # log10() |
| 602 | CheckDefFailure(['echo log10("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 603 | # pow() |
| 604 | CheckDefFailure(['echo pow("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 605 | CheckDefFailure(['echo pow(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 606 | CheckDefFailure(['echo pow(1.1)'], 'E119:') |
| 607 | # round() |
| 608 | CheckDefFailure(['echo round("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 609 | # sin() |
| 610 | CheckDefFailure(['echo sin("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 611 | # sinh() |
| 612 | CheckDefFailure(['echo sinh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 613 | # sqrt() |
| 614 | CheckDefFailure(['echo sqrt("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 615 | # tan() |
| 616 | CheckDefFailure(['echo tan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 617 | # tanh() |
| 618 | CheckDefFailure(['echo tanh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 619 | # trunc() |
| 620 | CheckDefFailure(['echo trunc("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 621 | enddef |
| 622 | |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 623 | def Test_fnamemodify() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 624 | CheckDefSuccess(['echo fnamemodify(test_null_string(), ":p")']) |
| 625 | CheckDefSuccess(['echo fnamemodify("", ":p")']) |
| 626 | CheckDefSuccess(['echo fnamemodify("file", test_null_string())']) |
| 627 | CheckDefSuccess(['echo fnamemodify("file", "")']) |
| 628 | |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 629 | CheckDefExecFailure(['echo fnamemodify(true, ":p")'], 'E1174: String required for argument 1') |
| 630 | CheckDefExecFailure(['echo fnamemodify(v:null, ":p")'], 'E1174: String required for argument 1') |
| 631 | CheckDefExecFailure(['echo fnamemodify("file", true)'], 'E1174: String required for argument 2') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 632 | enddef |
| 633 | |
Bram Moolenaar | 2e5910b | 2021-02-03 17:41:24 +0100 | [diff] [blame] | 634 | def Wrong_dict_key_type(items: list<number>): list<number> |
| 635 | return filter(items, (_, val) => get({[val]: 1}, 'x')) |
| 636 | enddef |
| 637 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 638 | def Test_filter_wrong_dict_key_type() |
Bram Moolenaar | 2e5910b | 2021-02-03 17:41:24 +0100 | [diff] [blame] | 639 | assert_fails('Wrong_dict_key_type([1, v:null, 3])', 'E1013:') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 640 | enddef |
| 641 | |
| 642 | def Test_filter_return_type() |
Bram Moolenaar | bb8a7ce | 2021-04-10 20:10:26 +0200 | [diff] [blame] | 643 | var l = filter([1, 2, 3], (_, _) => 1) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 644 | var res = 0 |
| 645 | for n in l |
| 646 | res += n |
| 647 | endfor |
| 648 | res->assert_equal(6) |
| 649 | enddef |
| 650 | |
Bram Moolenaar | fc0e8f5 | 2020-12-25 20:24:51 +0100 | [diff] [blame] | 651 | def Test_filter_missing_argument() |
| 652 | var dict = {aa: [1], ab: [2], ac: [3], de: [4]} |
Bram Moolenaar | bb8a7ce | 2021-04-10 20:10:26 +0200 | [diff] [blame] | 653 | var res = dict->filter((k, _) => k =~ 'a' && k !~ 'b') |
Bram Moolenaar | fc0e8f5 | 2020-12-25 20:24:51 +0100 | [diff] [blame] | 654 | res->assert_equal({aa: [1], ac: [3]}) |
| 655 | enddef |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 656 | |
Bram Moolenaar | 7d840e9 | 2021-05-26 21:10:11 +0200 | [diff] [blame] | 657 | def Test_fullcommand() |
| 658 | assert_equal('next', fullcommand('n')) |
| 659 | assert_equal('noremap', fullcommand('no')) |
| 660 | assert_equal('noremap', fullcommand('nor')) |
| 661 | assert_equal('normal', fullcommand('norm')) |
| 662 | |
| 663 | assert_equal('', fullcommand('k')) |
| 664 | assert_equal('keepmarks', fullcommand('ke')) |
| 665 | assert_equal('keepmarks', fullcommand('kee')) |
| 666 | assert_equal('keepmarks', fullcommand('keep')) |
| 667 | assert_equal('keepjumps', fullcommand('keepj')) |
| 668 | |
| 669 | assert_equal('dlist', fullcommand('dl')) |
| 670 | assert_equal('', fullcommand('dp')) |
| 671 | assert_equal('delete', fullcommand('del')) |
| 672 | assert_equal('', fullcommand('dell')) |
| 673 | assert_equal('', fullcommand('delp')) |
| 674 | |
| 675 | assert_equal('srewind', fullcommand('sre')) |
| 676 | assert_equal('scriptnames', fullcommand('scr')) |
| 677 | assert_equal('', fullcommand('scg')) |
| 678 | enddef |
| 679 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 680 | def Test_garbagecollect() |
| 681 | garbagecollect(true) |
| 682 | enddef |
| 683 | |
| 684 | def Test_getbufinfo() |
| 685 | var bufinfo = getbufinfo(bufnr()) |
| 686 | getbufinfo('%')->assert_equal(bufinfo) |
| 687 | |
| 688 | edit Xtestfile1 |
| 689 | hide edit Xtestfile2 |
| 690 | hide enew |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 691 | getbufinfo({bufloaded: true, buflisted: true, bufmodified: false}) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 692 | ->len()->assert_equal(3) |
| 693 | bwipe Xtestfile1 Xtestfile2 |
| 694 | enddef |
| 695 | |
| 696 | def Test_getbufline() |
| 697 | e SomeFile |
| 698 | var buf = bufnr() |
| 699 | e # |
| 700 | var lines = ['aaa', 'bbb', 'ccc'] |
| 701 | setbufline(buf, 1, lines) |
| 702 | getbufline('#', 1, '$')->assert_equal(lines) |
Bram Moolenaar | e6e70a1 | 2020-10-22 18:23:38 +0200 | [diff] [blame] | 703 | getbufline(-1, '$', '$')->assert_equal([]) |
| 704 | getbufline(-1, 1, '$')->assert_equal([]) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 705 | |
| 706 | bwipe! |
| 707 | enddef |
| 708 | |
| 709 | def Test_getchangelist() |
| 710 | new |
| 711 | setline(1, 'some text') |
| 712 | var changelist = bufnr()->getchangelist() |
| 713 | getchangelist('%')->assert_equal(changelist) |
| 714 | bwipe! |
| 715 | enddef |
| 716 | |
| 717 | def Test_getchar() |
| 718 | while getchar(0) |
| 719 | endwhile |
| 720 | getchar(true)->assert_equal(0) |
| 721 | enddef |
| 722 | |
Bram Moolenaar | 7ad67d1 | 2021-03-10 16:08:26 +0100 | [diff] [blame] | 723 | def Test_getenv() |
| 724 | if getenv('does-not_exist') == '' |
| 725 | assert_report('getenv() should return null') |
| 726 | endif |
| 727 | if getenv('does-not_exist') == null |
| 728 | else |
| 729 | assert_report('getenv() should return null') |
| 730 | endif |
| 731 | $SOMEENVVAR = 'some' |
| 732 | assert_equal('some', getenv('SOMEENVVAR')) |
| 733 | unlet $SOMEENVVAR |
| 734 | enddef |
| 735 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 736 | def Test_getcompletion() |
| 737 | set wildignore=*.vim,*~ |
| 738 | var l = getcompletion('run', 'file', true) |
| 739 | l->assert_equal([]) |
| 740 | set wildignore& |
| 741 | enddef |
| 742 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame^] | 743 | def Test_getcurpos() |
| 744 | CheckDefFailure(['echo getcursorcharpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 745 | enddef |
| 746 | |
| 747 | def Test_getcursorcharpos() |
| 748 | CheckDefFailure(['echo getcursorcharpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 749 | enddef |
| 750 | |
| 751 | def Test_getcwd() |
| 752 | CheckDefFailure(['echo getcwd("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 753 | CheckDefFailure(['echo getcwd("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 754 | CheckDefFailure(['echo getcwd(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 755 | enddef |
| 756 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 757 | def Test_getloclist_return_type() |
| 758 | var l = getloclist(1) |
| 759 | l->assert_equal([]) |
| 760 | |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 761 | var d = getloclist(1, {items: 0}) |
| 762 | d->assert_equal({items: []}) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 763 | enddef |
| 764 | |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 765 | def Test_getfperm() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 766 | assert_equal('', getfperm("")) |
| 767 | assert_equal('', getfperm(test_null_string())) |
| 768 | |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 769 | CheckDefExecFailure(['echo getfperm(true)'], 'E1174:') |
| 770 | CheckDefExecFailure(['echo getfperm(v:null)'], 'E1174:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 771 | enddef |
| 772 | |
| 773 | def Test_getfsize() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 774 | assert_equal(-1, getfsize("")) |
| 775 | assert_equal(-1, getfsize(test_null_string())) |
| 776 | |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 777 | CheckDefExecFailure(['echo getfsize(true)'], 'E1174:') |
| 778 | CheckDefExecFailure(['echo getfsize(v:null)'], 'E1174:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 779 | enddef |
| 780 | |
| 781 | def Test_getftime() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 782 | assert_equal(-1, getftime("")) |
| 783 | assert_equal(-1, getftime(test_null_string())) |
| 784 | |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 785 | CheckDefExecFailure(['echo getftime(true)'], 'E1174:') |
| 786 | CheckDefExecFailure(['echo getftime(v:null)'], 'E1174:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 787 | enddef |
| 788 | |
| 789 | def Test_getftype() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 790 | assert_equal('', getftype("")) |
| 791 | assert_equal('', getftype(test_null_string())) |
| 792 | |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 793 | CheckDefExecFailure(['echo getftype(true)'], 'E1174:') |
| 794 | CheckDefExecFailure(['echo getftype(v:null)'], 'E1174:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 795 | enddef |
| 796 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame^] | 797 | def Test_getjumplist() |
| 798 | CheckDefFailure(['echo getjumplist("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 799 | CheckDefFailure(['echo getjumplist("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 800 | CheckDefFailure(['echo getjumplist(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 801 | enddef |
| 802 | |
| 803 | def Test_getmatches() |
| 804 | CheckDefFailure(['echo getmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 805 | enddef |
| 806 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 807 | def Test_getqflist_return_type() |
| 808 | var l = getqflist() |
| 809 | l->assert_equal([]) |
| 810 | |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 811 | var d = getqflist({items: 0}) |
| 812 | d->assert_equal({items: []}) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 813 | enddef |
| 814 | |
| 815 | def Test_getreg() |
| 816 | var lines = ['aaa', 'bbb', 'ccc'] |
| 817 | setreg('a', lines) |
| 818 | getreg('a', true, true)->assert_equal(lines) |
Bram Moolenaar | 418a29f | 2021-02-10 22:23:41 +0100 | [diff] [blame] | 819 | assert_fails('getreg("ab")', 'E1162:') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 820 | enddef |
| 821 | |
| 822 | def Test_getreg_return_type() |
| 823 | var s1: string = getreg('"') |
| 824 | var s2: string = getreg('"', 1) |
| 825 | var s3: list<string> = getreg('"', 1, 1) |
| 826 | enddef |
| 827 | |
Bram Moolenaar | 418a29f | 2021-02-10 22:23:41 +0100 | [diff] [blame] | 828 | def Test_getreginfo() |
| 829 | var text = 'abc' |
| 830 | setreg('a', text) |
| 831 | getreginfo('a')->assert_equal({regcontents: [text], regtype: 'v', isunnamed: false}) |
| 832 | assert_fails('getreginfo("ab")', 'E1162:') |
| 833 | enddef |
| 834 | |
| 835 | def Test_getregtype() |
| 836 | var lines = ['aaa', 'bbb', 'ccc'] |
| 837 | setreg('a', lines) |
| 838 | getregtype('a')->assert_equal('V') |
| 839 | assert_fails('getregtype("ab")', 'E1162:') |
| 840 | enddef |
| 841 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame^] | 842 | def Test_gettabinfo() |
| 843 | CheckDefFailure(['echo gettabinfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 844 | enddef |
| 845 | |
| 846 | def Test_gettagstack() |
| 847 | CheckDefFailure(['echo gettagstack("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 848 | enddef |
| 849 | |
| 850 | def Test_getwininfo() |
| 851 | CheckDefFailure(['echo getwininfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 852 | enddef |
| 853 | |
| 854 | def Test_getwinpos() |
| 855 | CheckDefFailure(['echo getwinpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 856 | enddef |
| 857 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 858 | def Test_glob() |
| 859 | glob('runtest.vim', true, true, true)->assert_equal(['runtest.vim']) |
| 860 | enddef |
| 861 | |
| 862 | def Test_globpath() |
| 863 | globpath('.', 'runtest.vim', true, true, true)->assert_equal(['./runtest.vim']) |
| 864 | enddef |
| 865 | |
| 866 | def Test_has() |
| 867 | has('eval', true)->assert_equal(1) |
| 868 | enddef |
| 869 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame^] | 870 | def Test_haslocaldir() |
| 871 | CheckDefFailure(['echo haslocaldir("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 872 | CheckDefFailure(['echo haslocaldir("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 873 | CheckDefFailure(['echo haslocaldir(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 874 | enddef |
| 875 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 876 | def Test_hasmapto() |
| 877 | hasmapto('foobar', 'i', true)->assert_equal(0) |
| 878 | iabbrev foo foobar |
| 879 | hasmapto('foobar', 'i', true)->assert_equal(1) |
| 880 | iunabbrev foo |
| 881 | enddef |
| 882 | |
| 883 | def Test_index() |
| 884 | index(['a', 'b', 'a', 'B'], 'b', 2, true)->assert_equal(3) |
| 885 | enddef |
| 886 | |
Bram Moolenaar | 193f620 | 2020-11-16 20:08:35 +0100 | [diff] [blame] | 887 | let s:number_one = 1 |
| 888 | let s:number_two = 2 |
| 889 | let s:string_keep = 'keep' |
| 890 | |
Bram Moolenaar | ca17453 | 2020-10-21 16:42:22 +0200 | [diff] [blame] | 891 | def Test_insert() |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 892 | var l = insert([2, 1], 3) |
| 893 | var res = 0 |
| 894 | for n in l |
| 895 | res += n |
| 896 | endfor |
| 897 | res->assert_equal(6) |
Bram Moolenaar | ca17453 | 2020-10-21 16:42:22 +0200 | [diff] [blame] | 898 | |
Yegappan Lakshmanan | 34fcb69 | 2021-05-25 20:14:00 +0200 | [diff] [blame] | 899 | var m: any = [] |
| 900 | insert(m, 4) |
| 901 | call assert_equal([4], m) |
| 902 | extend(m, [6], 0) |
| 903 | call assert_equal([6, 4], m) |
| 904 | |
Bram Moolenaar | 39211cb | 2021-04-18 15:48:04 +0200 | [diff] [blame] | 905 | var lines =<< trim END |
| 906 | insert(test_null_list(), 123) |
| 907 | END |
| 908 | CheckDefExecAndScriptFailure(lines, 'E1130:', 1) |
| 909 | |
| 910 | lines =<< trim END |
| 911 | insert(test_null_blob(), 123) |
| 912 | END |
| 913 | CheckDefExecAndScriptFailure(lines, 'E1131:', 1) |
| 914 | |
Bram Moolenaar | ca17453 | 2020-10-21 16:42:22 +0200 | [diff] [blame] | 915 | assert_equal([1, 2, 3], insert([2, 3], 1)) |
Bram Moolenaar | 193f620 | 2020-11-16 20:08:35 +0100 | [diff] [blame] | 916 | assert_equal([1, 2, 3], insert([2, 3], s:number_one)) |
Bram Moolenaar | ca17453 | 2020-10-21 16:42:22 +0200 | [diff] [blame] | 917 | assert_equal([1, 2, 3], insert([1, 2], 3, 2)) |
Bram Moolenaar | 193f620 | 2020-11-16 20:08:35 +0100 | [diff] [blame] | 918 | assert_equal([1, 2, 3], insert([1, 2], 3, s:number_two)) |
Bram Moolenaar | ca17453 | 2020-10-21 16:42:22 +0200 | [diff] [blame] | 919 | assert_equal(['a', 'b', 'c'], insert(['b', 'c'], 'a')) |
| 920 | assert_equal(0z1234, insert(0z34, 0x12)) |
Bram Moolenaar | 193f620 | 2020-11-16 20:08:35 +0100 | [diff] [blame] | 921 | |
Yegappan Lakshmanan | 34fcb69 | 2021-05-25 20:14:00 +0200 | [diff] [blame] | 922 | 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] | 923 | CheckDefFailure(['insert([2, 3], "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 1) |
| 924 | 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] | 925 | enddef |
| 926 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame^] | 927 | def Test_invert() |
| 928 | CheckDefFailure(['echo invert("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 929 | enddef |
| 930 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 931 | def Test_keys_return_type() |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 932 | const var: list<string> = {a: 1, b: 2}->keys() |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 933 | var->assert_equal(['a', 'b']) |
| 934 | enddef |
| 935 | |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 936 | def Test_line() |
| 937 | assert_fails('line(true)', 'E1174') |
| 938 | enddef |
| 939 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 940 | def Test_list2str_str2list_utf8() |
| 941 | var s = "\u3042\u3044" |
| 942 | var l = [0x3042, 0x3044] |
| 943 | str2list(s, true)->assert_equal(l) |
| 944 | list2str(l, true)->assert_equal(s) |
| 945 | enddef |
| 946 | |
| 947 | def SID(): number |
| 948 | return expand('<SID>') |
| 949 | ->matchstr('<SNR>\zs\d\+\ze_$') |
| 950 | ->str2nr() |
| 951 | enddef |
| 952 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame^] | 953 | def Test_listener_remove() |
| 954 | CheckDefFailure(['echo listener_remove("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 955 | enddef |
| 956 | |
Bram Moolenaar | 70250fb | 2021-01-16 19:01:53 +0100 | [diff] [blame] | 957 | def Test_map_function_arg() |
| 958 | var lines =<< trim END |
| 959 | def MapOne(i: number, v: string): string |
| 960 | return i .. ':' .. v |
| 961 | enddef |
| 962 | var l = ['a', 'b', 'c'] |
| 963 | map(l, MapOne) |
| 964 | assert_equal(['0:a', '1:b', '2:c'], l) |
| 965 | END |
| 966 | CheckDefAndScriptSuccess(lines) |
Bram Moolenaar | 8da6d6d | 2021-06-05 18:15:09 +0200 | [diff] [blame] | 967 | |
| 968 | lines =<< trim END |
| 969 | range(3)->map((a, b, c) => a + b + c) |
| 970 | END |
| 971 | CheckDefExecAndScriptFailure(lines, 'E1190: One argument too few') |
| 972 | lines =<< trim END |
| 973 | range(3)->map((a, b, c, d) => a + b + c + d) |
| 974 | END |
| 975 | CheckDefExecAndScriptFailure(lines, 'E1190: 2 arguments too few') |
Bram Moolenaar | 70250fb | 2021-01-16 19:01:53 +0100 | [diff] [blame] | 976 | enddef |
| 977 | |
| 978 | def Test_map_item_type() |
| 979 | var lines =<< trim END |
| 980 | var l = ['a', 'b', 'c'] |
| 981 | map(l, (k, v) => k .. '/' .. v ) |
| 982 | assert_equal(['0/a', '1/b', '2/c'], l) |
| 983 | END |
| 984 | CheckDefAndScriptSuccess(lines) |
| 985 | |
| 986 | lines =<< trim END |
| 987 | var l: list<number> = [0] |
| 988 | echo map(l, (_, v) => []) |
| 989 | END |
| 990 | CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2) |
| 991 | |
| 992 | lines =<< trim END |
| 993 | var l: list<number> = range(2) |
| 994 | echo map(l, (_, v) => []) |
| 995 | END |
| 996 | CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2) |
| 997 | |
| 998 | lines =<< trim END |
| 999 | var d: dict<number> = {key: 0} |
| 1000 | echo map(d, (_, v) => []) |
| 1001 | END |
| 1002 | CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2) |
| 1003 | enddef |
| 1004 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1005 | def Test_maparg() |
| 1006 | var lnum = str2nr(expand('<sflnum>')) |
| 1007 | map foo bar |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 1008 | maparg('foo', '', false, true)->assert_equal({ |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1009 | lnum: lnum + 1, |
| 1010 | script: 0, |
| 1011 | mode: ' ', |
| 1012 | silent: 0, |
| 1013 | noremap: 0, |
| 1014 | lhs: 'foo', |
| 1015 | lhsraw: 'foo', |
| 1016 | nowait: 0, |
| 1017 | expr: 0, |
| 1018 | sid: SID(), |
| 1019 | rhs: 'bar', |
| 1020 | buffer: 0}) |
| 1021 | unmap foo |
| 1022 | enddef |
| 1023 | |
| 1024 | def Test_mapcheck() |
| 1025 | iabbrev foo foobar |
| 1026 | mapcheck('foo', 'i', true)->assert_equal('foobar') |
| 1027 | iunabbrev foo |
| 1028 | enddef |
| 1029 | |
| 1030 | def Test_maparg_mapset() |
| 1031 | nnoremap <F3> :echo "hit F3"<CR> |
| 1032 | var mapsave = maparg('<F3>', 'n', false, true) |
| 1033 | mapset('n', false, mapsave) |
| 1034 | |
| 1035 | nunmap <F3> |
| 1036 | enddef |
| 1037 | |
Bram Moolenaar | 027c4ab | 2021-02-21 16:20:18 +0100 | [diff] [blame] | 1038 | def Test_map_failure() |
| 1039 | CheckFeature job |
| 1040 | |
| 1041 | var lines =<< trim END |
| 1042 | vim9script |
| 1043 | writefile([], 'Xtmpfile') |
| 1044 | silent e Xtmpfile |
| 1045 | var d = {[bufnr('%')]: {a: 0}} |
| 1046 | au BufReadPost * Func() |
| 1047 | def Func() |
| 1048 | if d->has_key('') |
| 1049 | endif |
| 1050 | eval d[expand('<abuf>')]->mapnew((_, v: dict<job>) => 0) |
| 1051 | enddef |
| 1052 | e |
| 1053 | END |
| 1054 | CheckScriptFailure(lines, 'E1013:') |
| 1055 | au! BufReadPost |
| 1056 | delete('Xtmpfile') |
| 1057 | enddef |
| 1058 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame^] | 1059 | def Test_matcharg() |
| 1060 | CheckDefFailure(['echo matcharg("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1061 | enddef |
| 1062 | |
| 1063 | def Test_matchdelete() |
| 1064 | CheckDefFailure(['echo matchdelete("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1065 | CheckDefFailure(['echo matchdelete("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1066 | CheckDefFailure(['echo matchdelete(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 1067 | enddef |
| 1068 | |
Bram Moolenaar | 9ae3705 | 2021-01-22 22:31:10 +0100 | [diff] [blame] | 1069 | def Test_max() |
| 1070 | g:flag = true |
| 1071 | var l1: list<number> = g:flag |
| 1072 | ? [1, max([2, 3])] |
| 1073 | : [4, 5] |
| 1074 | assert_equal([1, 3], l1) |
| 1075 | |
| 1076 | g:flag = false |
| 1077 | var l2: list<number> = g:flag |
| 1078 | ? [1, max([2, 3])] |
| 1079 | : [4, 5] |
| 1080 | assert_equal([4, 5], l2) |
| 1081 | enddef |
| 1082 | |
| 1083 | def Test_min() |
| 1084 | g:flag = true |
| 1085 | var l1: list<number> = g:flag |
| 1086 | ? [1, min([2, 3])] |
| 1087 | : [4, 5] |
| 1088 | assert_equal([1, 2], l1) |
| 1089 | |
| 1090 | g:flag = false |
| 1091 | var l2: list<number> = g:flag |
| 1092 | ? [1, min([2, 3])] |
| 1093 | : [4, 5] |
| 1094 | assert_equal([4, 5], l2) |
| 1095 | enddef |
| 1096 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1097 | def Test_nr2char() |
| 1098 | nr2char(97, true)->assert_equal('a') |
| 1099 | enddef |
| 1100 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame^] | 1101 | def Test_or() |
| 1102 | CheckDefFailure(['echo or("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1103 | CheckDefFailure(['echo or(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 1104 | enddef |
| 1105 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1106 | def Test_readdir() |
Bram Moolenaar | 2949cfd | 2020-12-31 21:28:47 +0100 | [diff] [blame] | 1107 | eval expand('sautest')->readdir((e) => e[0] !=# '.') |
| 1108 | eval expand('sautest')->readdirex((e) => e.name[0] !=# '.') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1109 | enddef |
| 1110 | |
Bram Moolenaar | c423ad7 | 2021-01-13 20:38:03 +0100 | [diff] [blame] | 1111 | def Test_readblob() |
| 1112 | var blob = 0z12341234 |
| 1113 | writefile(blob, 'Xreadblob') |
| 1114 | var read: blob = readblob('Xreadblob') |
| 1115 | assert_equal(blob, read) |
| 1116 | |
| 1117 | var lines =<< trim END |
| 1118 | var read: list<string> = readblob('Xreadblob') |
| 1119 | END |
| 1120 | CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<string> but got blob', 1) |
| 1121 | delete('Xreadblob') |
| 1122 | enddef |
| 1123 | |
| 1124 | def Test_readfile() |
| 1125 | var text = ['aaa', 'bbb', 'ccc'] |
| 1126 | writefile(text, 'Xreadfile') |
| 1127 | var read: list<string> = readfile('Xreadfile') |
| 1128 | assert_equal(text, read) |
| 1129 | |
| 1130 | var lines =<< trim END |
| 1131 | var read: dict<string> = readfile('Xreadfile') |
| 1132 | END |
| 1133 | CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected dict<string> but got list<string>', 1) |
| 1134 | delete('Xreadfile') |
| 1135 | enddef |
| 1136 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1137 | def Test_remove_return_type() |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 1138 | var l = remove({one: [1, 2], two: [3, 4]}, 'one') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1139 | var res = 0 |
| 1140 | for n in l |
| 1141 | res += n |
| 1142 | endfor |
| 1143 | res->assert_equal(3) |
| 1144 | enddef |
| 1145 | |
| 1146 | def Test_reverse_return_type() |
| 1147 | var l = reverse([1, 2, 3]) |
| 1148 | var res = 0 |
| 1149 | for n in l |
| 1150 | res += n |
| 1151 | endfor |
| 1152 | res->assert_equal(6) |
| 1153 | enddef |
| 1154 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame^] | 1155 | def Test_screenattr() |
| 1156 | CheckDefFailure(['echo screenattr("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1157 | CheckDefFailure(['echo screenattr(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 1158 | enddef |
| 1159 | |
| 1160 | def Test_screenchar() |
| 1161 | CheckDefFailure(['echo screenchar("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1162 | CheckDefFailure(['echo screenchar(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 1163 | enddef |
| 1164 | |
| 1165 | def Test_screenchars() |
| 1166 | CheckDefFailure(['echo screenchars("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1167 | CheckDefFailure(['echo screenchars(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 1168 | enddef |
| 1169 | |
| 1170 | def Test_screenstring() |
| 1171 | CheckDefFailure(['echo screenstring("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1172 | CheckDefFailure(['echo screenstring(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 1173 | enddef |
| 1174 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1175 | def Test_search() |
| 1176 | new |
| 1177 | setline(1, ['foo', 'bar']) |
| 1178 | var val = 0 |
| 1179 | # skip expr returns boolean |
Bram Moolenaar | 2949cfd | 2020-12-31 21:28:47 +0100 | [diff] [blame] | 1180 | search('bar', 'W', 0, 0, () => val == 1)->assert_equal(2) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1181 | :1 |
Bram Moolenaar | 2949cfd | 2020-12-31 21:28:47 +0100 | [diff] [blame] | 1182 | search('bar', 'W', 0, 0, () => val == 0)->assert_equal(0) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1183 | # skip expr returns number, only 0 and 1 are accepted |
| 1184 | :1 |
Bram Moolenaar | 2949cfd | 2020-12-31 21:28:47 +0100 | [diff] [blame] | 1185 | search('bar', 'W', 0, 0, () => 0)->assert_equal(2) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1186 | :1 |
Bram Moolenaar | 2949cfd | 2020-12-31 21:28:47 +0100 | [diff] [blame] | 1187 | search('bar', 'W', 0, 0, () => 1)->assert_equal(0) |
| 1188 | assert_fails("search('bar', '', 0, 0, () => -1)", 'E1023:') |
| 1189 | assert_fails("search('bar', '', 0, 0, () => -1)", 'E1023:') |
Bram Moolenaar | f06ab6b | 2021-05-07 19:44:21 +0200 | [diff] [blame] | 1190 | |
| 1191 | setline(1, "find this word") |
| 1192 | normal gg |
| 1193 | var col = 7 |
| 1194 | assert_equal(1, search('this', '', 0, 0, 'col(".") > col')) |
| 1195 | normal 0 |
| 1196 | assert_equal([1, 6], searchpos('this', '', 0, 0, 'col(".") > col')) |
| 1197 | |
| 1198 | col = 5 |
| 1199 | normal 0 |
| 1200 | assert_equal(0, search('this', '', 0, 0, 'col(".") > col')) |
| 1201 | normal 0 |
| 1202 | assert_equal([0, 0], searchpos('this', '', 0, 0, 'col(".") > col')) |
| 1203 | bwipe! |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1204 | enddef |
| 1205 | |
| 1206 | def Test_searchcount() |
| 1207 | new |
| 1208 | setline(1, "foo bar") |
| 1209 | :/foo |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 1210 | searchcount({recompute: true}) |
| 1211 | ->assert_equal({ |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1212 | exact_match: 1, |
| 1213 | current: 1, |
| 1214 | total: 1, |
| 1215 | maxcount: 99, |
| 1216 | incomplete: 0}) |
| 1217 | bwipe! |
| 1218 | enddef |
| 1219 | |
Bram Moolenaar | f18332f | 2021-05-07 17:55:55 +0200 | [diff] [blame] | 1220 | def Test_searchpair() |
| 1221 | new |
| 1222 | setline(1, "here { and } there") |
Bram Moolenaar | f06ab6b | 2021-05-07 19:44:21 +0200 | [diff] [blame] | 1223 | |
Bram Moolenaar | f18332f | 2021-05-07 17:55:55 +0200 | [diff] [blame] | 1224 | normal f{ |
| 1225 | var col = 15 |
| 1226 | assert_equal(1, searchpair('{', '', '}', '', 'col(".") > col')) |
| 1227 | assert_equal(12, col('.')) |
Bram Moolenaar | f06ab6b | 2021-05-07 19:44:21 +0200 | [diff] [blame] | 1228 | normal 0f{ |
| 1229 | assert_equal([1, 12], searchpairpos('{', '', '}', '', 'col(".") > col')) |
| 1230 | |
Bram Moolenaar | f18332f | 2021-05-07 17:55:55 +0200 | [diff] [blame] | 1231 | col = 8 |
| 1232 | normal 0f{ |
| 1233 | assert_equal(0, searchpair('{', '', '}', '', 'col(".") > col')) |
| 1234 | assert_equal(6, col('.')) |
Bram Moolenaar | f06ab6b | 2021-05-07 19:44:21 +0200 | [diff] [blame] | 1235 | normal 0f{ |
| 1236 | assert_equal([0, 0], searchpairpos('{', '', '}', '', 'col(".") > col')) |
| 1237 | |
Bram Moolenaar | ff65288 | 2021-05-16 15:24:49 +0200 | [diff] [blame] | 1238 | var lines =<< trim END |
| 1239 | vim9script |
| 1240 | setline(1, '()') |
| 1241 | normal gg |
| 1242 | def Fail() |
| 1243 | try |
| 1244 | searchpairpos('(', '', ')', 'nW', '[0]->map("")') |
| 1245 | catch |
Bram Moolenaar | cbe178e | 2021-05-18 17:49:59 +0200 | [diff] [blame] | 1246 | g:caught = 'yes' |
Bram Moolenaar | ff65288 | 2021-05-16 15:24:49 +0200 | [diff] [blame] | 1247 | endtry |
| 1248 | enddef |
| 1249 | Fail() |
| 1250 | END |
Bram Moolenaar | cbe178e | 2021-05-18 17:49:59 +0200 | [diff] [blame] | 1251 | CheckScriptSuccess(lines) |
| 1252 | assert_equal('yes', g:caught) |
Bram Moolenaar | ff65288 | 2021-05-16 15:24:49 +0200 | [diff] [blame] | 1253 | |
Bram Moolenaar | cbe178e | 2021-05-18 17:49:59 +0200 | [diff] [blame] | 1254 | unlet g:caught |
Bram Moolenaar | f18332f | 2021-05-07 17:55:55 +0200 | [diff] [blame] | 1255 | bwipe! |
| 1256 | enddef |
| 1257 | |
Bram Moolenaar | 3445320 | 2021-01-31 13:08:38 +0100 | [diff] [blame] | 1258 | def Test_set_get_bufline() |
| 1259 | # similar to Test_setbufline_getbufline() |
| 1260 | var lines =<< trim END |
| 1261 | new |
| 1262 | var b = bufnr('%') |
| 1263 | hide |
| 1264 | assert_equal(0, setbufline(b, 1, ['foo', 'bar'])) |
| 1265 | assert_equal(['foo'], getbufline(b, 1)) |
| 1266 | assert_equal(['bar'], getbufline(b, '$')) |
| 1267 | assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) |
| 1268 | exe "bd!" b |
| 1269 | assert_equal([], getbufline(b, 1, 2)) |
| 1270 | |
| 1271 | split Xtest |
| 1272 | setline(1, ['a', 'b', 'c']) |
| 1273 | b = bufnr('%') |
| 1274 | wincmd w |
| 1275 | |
| 1276 | assert_equal(1, setbufline(b, 5, 'x')) |
| 1277 | assert_equal(1, setbufline(b, 5, ['x'])) |
| 1278 | assert_equal(1, setbufline(b, 5, [])) |
| 1279 | assert_equal(1, setbufline(b, 5, test_null_list())) |
| 1280 | |
| 1281 | assert_equal(1, 'x'->setbufline(bufnr('$') + 1, 1)) |
| 1282 | assert_equal(1, ['x']->setbufline(bufnr('$') + 1, 1)) |
| 1283 | assert_equal(1, []->setbufline(bufnr('$') + 1, 1)) |
| 1284 | assert_equal(1, test_null_list()->setbufline(bufnr('$') + 1, 1)) |
| 1285 | |
| 1286 | assert_equal(['a', 'b', 'c'], getbufline(b, 1, '$')) |
| 1287 | |
| 1288 | assert_equal(0, setbufline(b, 4, ['d', 'e'])) |
| 1289 | assert_equal(['c'], b->getbufline(3)) |
| 1290 | assert_equal(['d'], getbufline(b, 4)) |
| 1291 | assert_equal(['e'], getbufline(b, 5)) |
| 1292 | assert_equal([], getbufline(b, 6)) |
| 1293 | assert_equal([], getbufline(b, 2, 1)) |
| 1294 | |
Bram Moolenaar | 0038511 | 2021-02-07 14:31:06 +0100 | [diff] [blame] | 1295 | if has('job') |
Bram Moolenaar | 1328bde | 2021-06-05 20:51:38 +0200 | [diff] [blame] | 1296 | setbufline(b, 2, [function('eval'), {key: 123}, string(test_null_job())]) |
Bram Moolenaar | 0038511 | 2021-02-07 14:31:06 +0100 | [diff] [blame] | 1297 | assert_equal(["function('eval')", |
| 1298 | "{'key': 123}", |
| 1299 | "no process"], |
| 1300 | getbufline(b, 2, 4)) |
| 1301 | endif |
Bram Moolenaar | 3445320 | 2021-01-31 13:08:38 +0100 | [diff] [blame] | 1302 | |
| 1303 | exe 'bwipe! ' .. b |
| 1304 | END |
| 1305 | CheckDefAndScriptSuccess(lines) |
| 1306 | enddef |
| 1307 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1308 | def Test_searchdecl() |
| 1309 | searchdecl('blah', true, true)->assert_equal(1) |
| 1310 | enddef |
| 1311 | |
| 1312 | def Test_setbufvar() |
| 1313 | setbufvar(bufnr('%'), '&syntax', 'vim') |
| 1314 | &syntax->assert_equal('vim') |
| 1315 | setbufvar(bufnr('%'), '&ts', 16) |
| 1316 | &ts->assert_equal(16) |
Bram Moolenaar | 31a201a | 2021-01-03 14:47:25 +0100 | [diff] [blame] | 1317 | setbufvar(bufnr('%'), '&ai', true) |
| 1318 | &ai->assert_equal(true) |
| 1319 | setbufvar(bufnr('%'), '&ft', 'filetype') |
| 1320 | &ft->assert_equal('filetype') |
| 1321 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1322 | settabwinvar(1, 1, '&syntax', 'vam') |
| 1323 | &syntax->assert_equal('vam') |
| 1324 | settabwinvar(1, 1, '&ts', 15) |
| 1325 | &ts->assert_equal(15) |
| 1326 | setlocal ts=8 |
Bram Moolenaar | b0d8182 | 2021-01-03 15:55:10 +0100 | [diff] [blame] | 1327 | settabwinvar(1, 1, '&list', false) |
| 1328 | &list->assert_equal(false) |
Bram Moolenaar | 31a201a | 2021-01-03 14:47:25 +0100 | [diff] [blame] | 1329 | settabwinvar(1, 1, '&list', true) |
| 1330 | &list->assert_equal(true) |
| 1331 | setlocal list& |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1332 | |
| 1333 | setbufvar('%', 'myvar', 123) |
| 1334 | getbufvar('%', 'myvar')->assert_equal(123) |
| 1335 | enddef |
| 1336 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame^] | 1337 | def Test_setcmdpos() |
| 1338 | CheckDefFailure(['echo setcmdpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1339 | enddef |
| 1340 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1341 | def Test_setloclist() |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 1342 | var items = [{filename: '/tmp/file', lnum: 1, valid: true}] |
| 1343 | var what = {items: items} |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1344 | setqflist([], ' ', what) |
| 1345 | setloclist(0, [], ' ', what) |
| 1346 | enddef |
| 1347 | |
| 1348 | def Test_setreg() |
| 1349 | setreg('a', ['aaa', 'bbb', 'ccc']) |
| 1350 | var reginfo = getreginfo('a') |
| 1351 | setreg('a', reginfo) |
| 1352 | getreginfo('a')->assert_equal(reginfo) |
Bram Moolenaar | 418a29f | 2021-02-10 22:23:41 +0100 | [diff] [blame] | 1353 | assert_fails('setreg("ab", 0)', 'E1162:') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1354 | enddef |
| 1355 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame^] | 1356 | def Test_shiftwidth() |
| 1357 | CheckDefFailure(['echo shiftwidth("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1358 | enddef |
| 1359 | |
Bram Moolenaar | 6601b62 | 2021-01-13 21:47:15 +0100 | [diff] [blame] | 1360 | def Test_slice() |
| 1361 | assert_equal('12345', slice('012345', 1)) |
| 1362 | assert_equal('123', slice('012345', 1, 4)) |
| 1363 | assert_equal('1234', slice('012345', 1, -1)) |
| 1364 | assert_equal('1', slice('012345', 1, -4)) |
| 1365 | assert_equal('', slice('012345', 1, -5)) |
| 1366 | assert_equal('', slice('012345', 1, -6)) |
| 1367 | |
| 1368 | assert_equal([1, 2, 3, 4, 5], slice(range(6), 1)) |
| 1369 | assert_equal([1, 2, 3], slice(range(6), 1, 4)) |
| 1370 | assert_equal([1, 2, 3, 4], slice(range(6), 1, -1)) |
| 1371 | assert_equal([1], slice(range(6), 1, -4)) |
| 1372 | assert_equal([], slice(range(6), 1, -5)) |
| 1373 | assert_equal([], slice(range(6), 1, -6)) |
| 1374 | |
| 1375 | assert_equal(0z1122334455, slice(0z001122334455, 1)) |
| 1376 | assert_equal(0z112233, slice(0z001122334455, 1, 4)) |
| 1377 | assert_equal(0z11223344, slice(0z001122334455, 1, -1)) |
| 1378 | assert_equal(0z11, slice(0z001122334455, 1, -4)) |
| 1379 | assert_equal(0z, slice(0z001122334455, 1, -5)) |
| 1380 | assert_equal(0z, slice(0z001122334455, 1, -6)) |
| 1381 | enddef |
| 1382 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1383 | def Test_spellsuggest() |
| 1384 | if !has('spell') |
| 1385 | MissingFeature 'spell' |
| 1386 | else |
| 1387 | spellsuggest('marrch', 1, true)->assert_equal(['March']) |
| 1388 | endif |
| 1389 | enddef |
| 1390 | |
| 1391 | def Test_sort_return_type() |
| 1392 | var res: list<number> |
| 1393 | res = [1, 2, 3]->sort() |
| 1394 | enddef |
| 1395 | |
| 1396 | def Test_sort_argument() |
Bram Moolenaar | 08cf0c0 | 2020-12-05 21:47:06 +0100 | [diff] [blame] | 1397 | var lines =<< trim END |
| 1398 | var res = ['b', 'a', 'c']->sort('i') |
| 1399 | res->assert_equal(['a', 'b', 'c']) |
| 1400 | |
| 1401 | def Compare(a: number, b: number): number |
| 1402 | return a - b |
| 1403 | enddef |
| 1404 | var l = [3, 6, 7, 1, 8, 2, 4, 5] |
| 1405 | sort(l, Compare) |
| 1406 | assert_equal([1, 2, 3, 4, 5, 6, 7, 8], l) |
| 1407 | END |
| 1408 | CheckDefAndScriptSuccess(lines) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1409 | enddef |
| 1410 | |
| 1411 | def Test_split() |
| 1412 | split(' aa bb ', '\W\+', true)->assert_equal(['', 'aa', 'bb', '']) |
| 1413 | enddef |
| 1414 | |
Bram Moolenaar | 80ad3e2 | 2021-01-31 20:48:58 +0100 | [diff] [blame] | 1415 | def Run_str2float() |
| 1416 | if !has('float') |
| 1417 | MissingFeature 'float' |
| 1418 | endif |
| 1419 | str2float("1.00")->assert_equal(1.00) |
| 1420 | str2float("2e-2")->assert_equal(0.02) |
| 1421 | |
| 1422 | CheckDefFailure(['echo str2float(123)'], 'E1013:') |
| 1423 | CheckScriptFailure(['vim9script', 'echo str2float(123)'], 'E1024:') |
| 1424 | endif |
| 1425 | enddef |
| 1426 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1427 | def Test_str2nr() |
| 1428 | str2nr("1'000'000", 10, true)->assert_equal(1000000) |
Bram Moolenaar | f2b26bc | 2021-01-30 23:05:11 +0100 | [diff] [blame] | 1429 | |
| 1430 | CheckDefFailure(['echo str2nr(123)'], 'E1013:') |
| 1431 | CheckScriptFailure(['vim9script', 'echo str2nr(123)'], 'E1024:') |
| 1432 | CheckDefFailure(['echo str2nr("123", "x")'], 'E1013:') |
| 1433 | CheckScriptFailure(['vim9script', 'echo str2nr("123", "x")'], 'E1030:') |
| 1434 | CheckDefFailure(['echo str2nr("123", 10, "x")'], 'E1013:') |
| 1435 | CheckScriptFailure(['vim9script', 'echo str2nr("123", 10, "x")'], 'E1135:') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1436 | enddef |
| 1437 | |
| 1438 | def Test_strchars() |
| 1439 | strchars("A\u20dd", true)->assert_equal(1) |
| 1440 | enddef |
| 1441 | |
| 1442 | def Test_submatch() |
| 1443 | var pat = 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)' |
Bram Moolenaar | 75ab91f | 2021-01-10 22:42:50 +0100 | [diff] [blame] | 1444 | var Rep = () => range(10)->mapnew((_, v) => submatch(v, true))->string() |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1445 | var actual = substitute('A123456789', pat, Rep, '') |
| 1446 | var expected = "[['A123456789'], ['1'], ['2'], ['3'], ['4'], ['5'], ['6'], ['7'], ['8'], ['9']]" |
| 1447 | actual->assert_equal(expected) |
| 1448 | enddef |
| 1449 | |
Bram Moolenaar | 1328bde | 2021-06-05 20:51:38 +0200 | [diff] [blame] | 1450 | def Test_substitute() |
| 1451 | var res = substitute('A1234', '\d', 'X', '') |
| 1452 | assert_equal('AX234', res) |
| 1453 | |
| 1454 | if has('job') |
| 1455 | assert_fails('"text"->substitute(".*", () => job_start(":"), "")', 'E908: using an invalid value as a String: job') |
| 1456 | assert_fails('"text"->substitute(".*", () => job_start(":")->job_getchannel(), "")', 'E908: using an invalid value as a String: channel') |
| 1457 | endif |
| 1458 | enddef |
| 1459 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1460 | def Test_synID() |
| 1461 | new |
| 1462 | setline(1, "text") |
| 1463 | synID(1, 1, true)->assert_equal(0) |
| 1464 | bwipe! |
| 1465 | enddef |
| 1466 | |
| 1467 | def Test_term_gettty() |
| 1468 | if !has('terminal') |
| 1469 | MissingFeature 'terminal' |
| 1470 | else |
| 1471 | var buf = Run_shell_in_terminal({}) |
| 1472 | term_gettty(buf, true)->assert_notequal('') |
| 1473 | StopShellInTerminal(buf) |
| 1474 | endif |
| 1475 | enddef |
| 1476 | |
| 1477 | def Test_term_start() |
| 1478 | if !has('terminal') |
| 1479 | MissingFeature 'terminal' |
| 1480 | else |
| 1481 | botright new |
| 1482 | var winnr = winnr() |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 1483 | term_start(&shell, {curwin: true}) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1484 | winnr()->assert_equal(winnr) |
| 1485 | bwipe! |
| 1486 | endif |
| 1487 | enddef |
| 1488 | |
| 1489 | def Test_timer_paused() |
Bram Moolenaar | 2949cfd | 2020-12-31 21:28:47 +0100 | [diff] [blame] | 1490 | var id = timer_start(50, () => 0) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1491 | timer_pause(id, true) |
| 1492 | var info = timer_info(id) |
| 1493 | info[0]['paused']->assert_equal(1) |
| 1494 | timer_stop(id) |
| 1495 | enddef |
| 1496 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame^] | 1497 | def Test_tolower() |
| 1498 | CheckDefFailure(['echo tolower(1)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1499 | enddef |
| 1500 | |
| 1501 | def Test_toupper() |
| 1502 | CheckDefFailure(['echo toupper(1)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1503 | enddef |
| 1504 | |
| 1505 | def Test_tr() |
| 1506 | CheckDefFailure(['echo tr(1, "a", "b")'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1507 | CheckDefFailure(['echo tr("a", 1, "b")'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 1508 | CheckDefFailure(['echo tr("a", "a", 1)'], 'E1013: Argument 3: type mismatch, expected string but got number') |
| 1509 | enddef |
| 1510 | |
Bram Moolenaar | 37487e1 | 2021-01-12 22:08:53 +0100 | [diff] [blame] | 1511 | def Test_win_execute() |
| 1512 | assert_equal("\n" .. winnr(), win_execute(win_getid(), 'echo winnr()')) |
| 1513 | assert_equal('', win_execute(342343, 'echo winnr()')) |
| 1514 | enddef |
| 1515 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1516 | def Test_win_splitmove() |
| 1517 | split |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 1518 | win_splitmove(1, 2, {vertical: true, rightbelow: true}) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1519 | close |
| 1520 | enddef |
| 1521 | |
Bram Moolenaar | 285b15f | 2020-12-29 20:25:19 +0100 | [diff] [blame] | 1522 | def Test_winrestcmd() |
| 1523 | split |
| 1524 | var cmd = winrestcmd() |
| 1525 | wincmd _ |
| 1526 | exe cmd |
| 1527 | assert_equal(cmd, winrestcmd()) |
| 1528 | close |
| 1529 | enddef |
| 1530 | |
Bram Moolenaar | 43b69b3 | 2021-01-07 20:23:33 +0100 | [diff] [blame] | 1531 | def Test_winsaveview() |
| 1532 | var view: dict<number> = winsaveview() |
| 1533 | |
| 1534 | var lines =<< trim END |
| 1535 | var view: list<number> = winsaveview() |
| 1536 | END |
| 1537 | CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<number> but got dict<number>', 1) |
| 1538 | enddef |
| 1539 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame^] | 1540 | def Test_win_gettype() |
| 1541 | CheckDefFailure(['echo win_gettype("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1542 | enddef |
Bram Moolenaar | 43b69b3 | 2021-01-07 20:23:33 +0100 | [diff] [blame] | 1543 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame^] | 1544 | def Test_win_gotoid() |
| 1545 | CheckDefFailure(['echo win_gotoid("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1546 | enddef |
Bram Moolenaar | 285b15f | 2020-12-29 20:25:19 +0100 | [diff] [blame] | 1547 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame^] | 1548 | def Test_win_id2tabwin() |
| 1549 | CheckDefFailure(['echo win_id2tabwin("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1550 | enddef |
| 1551 | |
| 1552 | def Test_win_id2win() |
| 1553 | CheckDefFailure(['echo win_id2win("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1554 | enddef |
| 1555 | |
| 1556 | def Test_win_screenpos() |
| 1557 | CheckDefFailure(['echo win_screenpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1558 | enddef |
| 1559 | |
| 1560 | def Test_winbufnr() |
| 1561 | CheckDefFailure(['echo winbufnr("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1562 | enddef |
| 1563 | |
| 1564 | def Test_winheight() |
| 1565 | CheckDefFailure(['echo winheight("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1566 | enddef |
| 1567 | |
| 1568 | def Test_winlayout() |
| 1569 | CheckDefFailure(['echo winlayout("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1570 | enddef |
| 1571 | |
| 1572 | def Test_winwidth() |
| 1573 | CheckDefFailure(['echo winwidth("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1574 | enddef |
| 1575 | |
| 1576 | def Test_xor() |
| 1577 | CheckDefFailure(['echo xor("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1578 | CheckDefFailure(['echo xor(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 1579 | enddef |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1580 | |
| 1581 | " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker |