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 | f32f099 | 2021-07-08 20:53:40 +0200 | [diff] [blame^] | 107 | |
| 108 | lines =<< trim END |
| 109 | vim9script |
| 110 | var l: list<string> = ['a'] |
| 111 | l->add(123) |
| 112 | END |
| 113 | CheckScriptFailure(lines, 'E1012: Type mismatch; expected string but got number', 3) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 114 | enddef |
| 115 | |
| 116 | def Test_add_blob() |
| 117 | var b1: blob = 0z12 |
| 118 | add(b1, 0x34) |
| 119 | assert_equal(0z1234, b1) |
| 120 | |
| 121 | var b2: blob # defaults to empty blob |
| 122 | add(b2, 0x67) |
| 123 | assert_equal(0z67, b2) |
| 124 | |
| 125 | var lines =<< trim END |
| 126 | var b: blob |
| 127 | add(b, "x") |
| 128 | END |
| 129 | CheckDefFailure(lines, 'E1012:', 2) |
| 130 | |
| 131 | lines =<< trim END |
Bram Moolenaar | b7c21af | 2021-04-18 14:12:31 +0200 | [diff] [blame] | 132 | add(test_null_blob(), 123) |
| 133 | END |
| 134 | CheckDefExecAndScriptFailure(lines, 'E1131:', 1) |
| 135 | |
| 136 | lines =<< trim END |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 137 | var b: blob = test_null_blob() |
| 138 | add(b, 123) |
| 139 | END |
| 140 | CheckDefExecFailure(lines, 'E1131:', 2) |
Bram Moolenaar | b7c21af | 2021-04-18 14:12:31 +0200 | [diff] [blame] | 141 | |
| 142 | # Getting variable with NULL blob allocates a new blob at script level |
| 143 | lines =<< trim END |
| 144 | vim9script |
| 145 | var b: blob = test_null_blob() |
| 146 | add(b, 123) |
| 147 | END |
| 148 | CheckScriptSuccess(lines) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 149 | enddef |
| 150 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 151 | def Test_and() |
| 152 | CheckDefFailure(['echo and("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 153 | CheckDefFailure(['echo and(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 154 | enddef |
| 155 | |
Bram Moolenaar | 3af15ab | 2021-01-17 16:16:23 +0100 | [diff] [blame] | 156 | def Test_append() |
| 157 | new |
| 158 | setline(1, range(3)) |
| 159 | var res1: number = append(1, 'one') |
| 160 | assert_equal(0, res1) |
| 161 | var res2: bool = append(3, 'two') |
| 162 | assert_equal(false, res2) |
| 163 | assert_equal(['0', 'one', '1', 'two', '2'], getline(1, 6)) |
Bram Moolenaar | b2ac7d0 | 2021-03-28 15:46:16 +0200 | [diff] [blame] | 164 | |
| 165 | append(0, 'zero') |
| 166 | assert_equal('zero', getline(1)) |
| 167 | bwipe! |
Bram Moolenaar | 3af15ab | 2021-01-17 16:16:23 +0100 | [diff] [blame] | 168 | enddef |
| 169 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 170 | def Test_argc() |
| 171 | CheckDefFailure(['echo argc("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 172 | enddef |
| 173 | |
| 174 | def Test_arglistid() |
| 175 | CheckDefFailure(['echo arglistid("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 176 | CheckDefFailure(['echo arglistid(1, "y")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 177 | CheckDefFailure(['echo arglistid("x", "y")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 178 | enddef |
| 179 | |
| 180 | def Test_argv() |
| 181 | CheckDefFailure(['echo argv("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 182 | CheckDefFailure(['echo argv(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 183 | CheckDefFailure(['echo argv("x", "y")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 184 | enddef |
| 185 | |
Bram Moolenaar | 32105ae | 2021-03-27 18:59:25 +0100 | [diff] [blame] | 186 | def Test_balloon_show() |
| 187 | CheckGui |
| 188 | CheckFeature balloon_eval |
| 189 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 190 | assert_fails('balloon_show(10)', 'E1174:') |
Bram Moolenaar | 32105ae | 2021-03-27 18:59:25 +0100 | [diff] [blame] | 191 | assert_fails('balloon_show(true)', 'E1174:') |
| 192 | enddef |
| 193 | |
| 194 | def Test_balloon_split() |
Bram Moolenaar | 7b45d46 | 2021-03-27 19:09:02 +0100 | [diff] [blame] | 195 | CheckFeature balloon_eval_term |
Bram Moolenaar | 32105ae | 2021-03-27 18:59:25 +0100 | [diff] [blame] | 196 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 197 | assert_fails('balloon_split([])', 'E1174:') |
Bram Moolenaar | 32105ae | 2021-03-27 18:59:25 +0100 | [diff] [blame] | 198 | assert_fails('balloon_split(true)', 'E1174:') |
| 199 | enddef |
| 200 | |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 201 | def Test_browse() |
| 202 | CheckFeature browse |
| 203 | |
| 204 | var lines =<< trim END |
Bram Moolenaar | f49a1fc | 2021-03-27 22:20:21 +0100 | [diff] [blame] | 205 | browse(1, 2, 3, 4) |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 206 | END |
| 207 | CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 2') |
| 208 | lines =<< trim END |
Bram Moolenaar | f49a1fc | 2021-03-27 22:20:21 +0100 | [diff] [blame] | 209 | browse(1, 'title', 3, 4) |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 210 | END |
| 211 | CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 3') |
| 212 | lines =<< trim END |
Bram Moolenaar | f49a1fc | 2021-03-27 22:20:21 +0100 | [diff] [blame] | 213 | browse(1, 'title', 'dir', 4) |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 214 | END |
| 215 | CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 4') |
| 216 | enddef |
| 217 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 218 | def Test_bufadd() |
| 219 | assert_fails('bufadd([])', 'E730:') |
| 220 | enddef |
| 221 | |
Bram Moolenaar | 32105ae | 2021-03-27 18:59:25 +0100 | [diff] [blame] | 222 | def Test_bufexists() |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 223 | assert_fails('bufexists(true)', 'E1174:') |
Bram Moolenaar | 32105ae | 2021-03-27 18:59:25 +0100 | [diff] [blame] | 224 | enddef |
| 225 | |
Bram Moolenaar | 3af15ab | 2021-01-17 16:16:23 +0100 | [diff] [blame] | 226 | def Test_buflisted() |
| 227 | var res: bool = buflisted('asdf') |
| 228 | assert_equal(false, res) |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 229 | assert_fails('buflisted(true)', 'E1174:') |
| 230 | assert_fails('buflisted([])', 'E1174:') |
| 231 | enddef |
| 232 | |
| 233 | def Test_bufload() |
| 234 | assert_fails('bufload([])', 'E730:') |
| 235 | enddef |
| 236 | |
| 237 | def Test_bufloaded() |
| 238 | assert_fails('bufloaded(true)', 'E1174:') |
| 239 | assert_fails('bufloaded([])', 'E1174:') |
Bram Moolenaar | 3af15ab | 2021-01-17 16:16:23 +0100 | [diff] [blame] | 240 | enddef |
| 241 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 242 | def Test_bufname() |
| 243 | split SomeFile |
| 244 | bufname('%')->assert_equal('SomeFile') |
| 245 | edit OtherFile |
| 246 | bufname('#')->assert_equal('SomeFile') |
| 247 | close |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 248 | assert_fails('bufname(true)', 'E1138:') |
| 249 | assert_fails('bufname([])', 'E745:') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 250 | enddef |
| 251 | |
| 252 | def Test_bufnr() |
| 253 | var buf = bufnr() |
| 254 | bufnr('%')->assert_equal(buf) |
| 255 | |
| 256 | buf = bufnr('Xdummy', true) |
| 257 | buf->assert_notequal(-1) |
| 258 | exe 'bwipe! ' .. buf |
| 259 | enddef |
| 260 | |
| 261 | def Test_bufwinid() |
| 262 | var origwin = win_getid() |
| 263 | below split SomeFile |
| 264 | var SomeFileID = win_getid() |
| 265 | below split OtherFile |
| 266 | below split SomeFile |
| 267 | bufwinid('SomeFile')->assert_equal(SomeFileID) |
| 268 | |
| 269 | win_gotoid(origwin) |
| 270 | only |
| 271 | bwipe SomeFile |
| 272 | bwipe OtherFile |
Bram Moolenaar | 32105ae | 2021-03-27 18:59:25 +0100 | [diff] [blame] | 273 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 274 | assert_fails('bufwinid(true)', 'E1138:') |
| 275 | assert_fails('bufwinid([])', 'E745:') |
| 276 | enddef |
| 277 | |
| 278 | def Test_bufwinnr() |
| 279 | assert_fails('bufwinnr(true)', 'E1138:') |
| 280 | assert_fails('bufwinnr([])', 'E745:') |
| 281 | enddef |
| 282 | |
| 283 | def Test_byte2line() |
| 284 | CheckDefFailure(['byte2line("1")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 285 | CheckDefFailure(['byte2line([])'], 'E1013: Argument 1: type mismatch, expected number but got list<unknown>') |
| 286 | assert_equal(-1, byte2line(0)) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 287 | enddef |
| 288 | |
| 289 | def Test_call_call() |
| 290 | var l = [3, 2, 1] |
| 291 | call('reverse', [l]) |
| 292 | l->assert_equal([1, 2, 3]) |
| 293 | enddef |
| 294 | |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 295 | def Test_ch_logfile() |
Bram Moolenaar | 886e5e7 | 2021-04-05 13:36:34 +0200 | [diff] [blame] | 296 | if !has('channel') |
| 297 | CheckFeature channel |
| 298 | endif |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 299 | assert_fails('ch_logfile(true)', 'E1174:') |
| 300 | assert_fails('ch_logfile("foo", true)', 'E1174:') |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 301 | enddef |
| 302 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 303 | def Test_char2nr() |
| 304 | char2nr('あ', true)->assert_equal(12354) |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 305 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 306 | assert_fails('char2nr(true)', 'E1174:') |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 307 | enddef |
| 308 | |
| 309 | def Test_charclass() |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 310 | assert_fails('charclass(true)', 'E1174:') |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 311 | enddef |
| 312 | |
| 313 | def Test_chdir() |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 314 | assert_fails('chdir(true)', 'E1174:') |
| 315 | enddef |
| 316 | |
| 317 | def Test_cindent() |
| 318 | CheckDefFailure(['cindent([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') |
| 319 | CheckDefFailure(['cindent(null)'], 'E1013: Argument 1: type mismatch, expected string but got special') |
| 320 | assert_equal(-1, cindent(0)) |
| 321 | assert_equal(0, cindent('.')) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 322 | enddef |
| 323 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 324 | def Test_clearmatches() |
| 325 | CheckDefFailure(['echo clearmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 326 | enddef |
| 327 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 328 | def Test_col() |
| 329 | new |
| 330 | setline(1, 'asdf') |
| 331 | col([1, '$'])->assert_equal(5) |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 332 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 333 | assert_fails('col(true)', 'E1174:') |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 334 | enddef |
| 335 | |
| 336 | def Test_confirm() |
| 337 | if !has('dialog_con') && !has('dialog_gui') |
| 338 | CheckFeature dialog_con |
| 339 | endif |
| 340 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 341 | assert_fails('confirm(true)', 'E1174:') |
| 342 | assert_fails('confirm("yes", true)', 'E1174:') |
| 343 | assert_fails('confirm("yes", "maybe", 2, true)', 'E1174:') |
| 344 | enddef |
| 345 | |
| 346 | def Test_complete_info() |
| 347 | CheckDefFailure(['complete_info("")'], 'E1013: Argument 1: type mismatch, expected list<string> but got string') |
| 348 | CheckDefFailure(['complete_info({})'], 'E1013: Argument 1: type mismatch, expected list<string> but got dict<unknown>') |
| 349 | assert_equal({'pum_visible': 0, 'mode': '', 'selected': -1, 'items': []}, complete_info()) |
| 350 | assert_equal({'mode': '', 'items': []}, complete_info(['mode', 'items'])) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 351 | enddef |
| 352 | |
| 353 | def Test_copy_return_type() |
| 354 | var l = copy([1, 2, 3]) |
| 355 | var res = 0 |
| 356 | for n in l |
| 357 | res += n |
| 358 | endfor |
| 359 | res->assert_equal(6) |
| 360 | |
| 361 | var dl = deepcopy([1, 2, 3]) |
| 362 | res = 0 |
| 363 | for n in dl |
| 364 | res += n |
| 365 | endfor |
| 366 | res->assert_equal(6) |
| 367 | |
| 368 | dl = deepcopy([1, 2, 3], true) |
| 369 | enddef |
| 370 | |
| 371 | def Test_count() |
| 372 | count('ABC ABC ABC', 'b', true)->assert_equal(3) |
| 373 | count('ABC ABC ABC', 'b', false)->assert_equal(0) |
| 374 | enddef |
| 375 | |
Bram Moolenaar | 9a96337 | 2020-12-21 21:58:46 +0100 | [diff] [blame] | 376 | def Test_cursor() |
| 377 | new |
| 378 | setline(1, range(4)) |
| 379 | cursor(2, 1) |
| 380 | assert_equal(2, getcurpos()[1]) |
| 381 | cursor('$', 1) |
| 382 | assert_equal(4, getcurpos()[1]) |
| 383 | |
| 384 | var lines =<< trim END |
| 385 | cursor('2', 1) |
| 386 | END |
| 387 | CheckDefExecAndScriptFailure(lines, 'E475:') |
| 388 | enddef |
| 389 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 390 | def Test_debugbreak() |
| 391 | CheckMSWindows |
| 392 | CheckDefFailure(['echo debugbreak("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 393 | enddef |
| 394 | |
Bram Moolenaar | 3af15ab | 2021-01-17 16:16:23 +0100 | [diff] [blame] | 395 | def Test_delete() |
| 396 | var res: bool = delete('doesnotexist') |
| 397 | assert_equal(true, res) |
| 398 | enddef |
| 399 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 400 | def Test_diff_filler() |
| 401 | CheckDefFailure(['diff_filler([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') |
| 402 | CheckDefFailure(['diff_filler(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool') |
| 403 | assert_equal(0, diff_filler(1)) |
| 404 | assert_equal(0, diff_filler('.')) |
| 405 | enddef |
| 406 | |
| 407 | def Test_escape() |
| 408 | CheckDefFailure(['escape("a", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 409 | CheckDefFailure(['escape(10, " ")'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 410 | CheckDefFailure(['escape(true, false)'], 'E1013: Argument 1: type mismatch, expected string but got bool') |
| 411 | assert_equal('a\:b', escape("a:b", ":")) |
| 412 | enddef |
| 413 | |
| 414 | def Test_eval() |
| 415 | CheckDefFailure(['eval(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 416 | CheckDefFailure(['eval(null)'], 'E1013: Argument 1: type mismatch, expected string but got special') |
| 417 | assert_equal(2, eval('1 + 1')) |
| 418 | enddef |
| 419 | |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 420 | def Test_executable() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 421 | assert_false(executable("")) |
| 422 | assert_false(executable(test_null_string())) |
| 423 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 424 | CheckDefExecFailure(['echo executable(123)'], 'E1013:') |
| 425 | CheckDefExecFailure(['echo executable(true)'], 'E1013:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 426 | enddef |
| 427 | |
Bram Moolenaar | ca81f0e | 2021-06-20 14:41:01 +0200 | [diff] [blame] | 428 | def Test_execute() |
| 429 | var res = execute("echo 'hello'") |
| 430 | assert_equal("\nhello", res) |
| 431 | res = execute(["echo 'here'", "echo 'there'"]) |
| 432 | assert_equal("\nhere\nthere", res) |
| 433 | |
| 434 | CheckDefFailure(['echo execute(123)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 435 | CheckDefFailure(['echo execute([123])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>') |
| 436 | CheckDefExecFailure(['echo execute(["xx", 123])'], 'E492') |
| 437 | CheckDefFailure(['echo execute("xx", 123)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 438 | enddef |
| 439 | |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 440 | def Test_exepath() |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 441 | CheckDefExecFailure(['echo exepath(true)'], 'E1013:') |
| 442 | CheckDefExecFailure(['echo exepath(v:null)'], 'E1013:') |
Bram Moolenaar | fa98441 | 2021-03-25 22:15:28 +0100 | [diff] [blame] | 443 | CheckDefExecFailure(['echo exepath("")'], 'E1175:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 444 | enddef |
| 445 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 446 | def Test_exists() |
| 447 | CheckDefFailure(['exists(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 448 | call assert_equal(1, exists('&tabstop')) |
| 449 | enddef |
| 450 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 451 | def Test_expand() |
| 452 | split SomeFile |
| 453 | expand('%', true, true)->assert_equal(['SomeFile']) |
| 454 | close |
| 455 | enddef |
| 456 | |
Bram Moolenaar | 0279510 | 2021-05-03 21:40:26 +0200 | [diff] [blame] | 457 | def Test_expandcmd() |
| 458 | $FOO = "blue" |
| 459 | assert_equal("blue sky", expandcmd("`=$FOO .. ' sky'`")) |
| 460 | |
| 461 | assert_equal("yes", expandcmd("`={a: 'yes'}['a']`")) |
| 462 | enddef |
| 463 | |
Bram Moolenaar | fbcbffe | 2020-10-31 19:33:38 +0100 | [diff] [blame] | 464 | def Test_extend_arg_types() |
Bram Moolenaar | c03f5c6 | 2021-01-31 17:48:30 +0100 | [diff] [blame] | 465 | g:number_one = 1 |
| 466 | g:string_keep = 'keep' |
| 467 | var lines =<< trim END |
| 468 | assert_equal([1, 2, 3], extend([1, 2], [3])) |
| 469 | assert_equal([3, 1, 2], extend([1, 2], [3], 0)) |
| 470 | assert_equal([1, 3, 2], extend([1, 2], [3], 1)) |
| 471 | assert_equal([1, 3, 2], extend([1, 2], [3], g:number_one)) |
Bram Moolenaar | fbcbffe | 2020-10-31 19:33:38 +0100 | [diff] [blame] | 472 | |
Bram Moolenaar | c03f5c6 | 2021-01-31 17:48:30 +0100 | [diff] [blame] | 473 | assert_equal({a: 1, b: 2, c: 3}, extend({a: 1, b: 2}, {c: 3})) |
| 474 | assert_equal({a: 1, b: 4}, extend({a: 1, b: 2}, {b: 4})) |
| 475 | assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, 'keep')) |
| 476 | 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] | 477 | |
Bram Moolenaar | c03f5c6 | 2021-01-31 17:48:30 +0100 | [diff] [blame] | 478 | var res: list<dict<any>> |
| 479 | extend(res, mapnew([1, 2], (_, v) => ({}))) |
| 480 | assert_equal([{}, {}], res) |
| 481 | END |
| 482 | CheckDefAndScriptSuccess(lines) |
Bram Moolenaar | fbcbffe | 2020-10-31 19:33:38 +0100 | [diff] [blame] | 483 | |
Yegappan Lakshmanan | 34fcb69 | 2021-05-25 20:14:00 +0200 | [diff] [blame] | 484 | 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] | 485 | CheckDefFailure(['extend([1, 2], 3)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number') |
| 486 | CheckDefFailure(['extend([1, 2], ["x"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>') |
| 487 | CheckDefFailure(['extend([1, 2], [3], "x")'], 'E1013: Argument 3: type mismatch, expected number but got string') |
| 488 | |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 489 | CheckDefFailure(['extend({a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number') |
| 490 | CheckDefFailure(['extend({a: 1}, {b: "x"})'], 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>') |
| 491 | 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] | 492 | |
| 493 | 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] | 494 | 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] | 495 | enddef |
| 496 | |
Bram Moolenaar | b0e6b51 | 2021-01-12 20:23:40 +0100 | [diff] [blame] | 497 | def Test_extendnew() |
| 498 | assert_equal([1, 2, 'a'], extendnew([1, 2], ['a'])) |
| 499 | assert_equal({one: 1, two: 'a'}, extendnew({one: 1}, {two: 'a'})) |
| 500 | |
| 501 | CheckDefFailure(['extendnew({a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number') |
| 502 | CheckDefFailure(['extendnew({a: 1}, [42])'], 'E1013: Argument 2: type mismatch, expected dict<number> but got list<number>') |
| 503 | CheckDefFailure(['extendnew([1, 2], "x")'], 'E1013: Argument 2: type mismatch, expected list<number> but got string') |
| 504 | CheckDefFailure(['extendnew([1, 2], {x: 1})'], 'E1013: Argument 2: type mismatch, expected list<number> but got dict<number>') |
| 505 | enddef |
| 506 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 507 | def Test_extend_return_type() |
| 508 | var l = extend([1, 2], [3]) |
| 509 | var res = 0 |
| 510 | for n in l |
| 511 | res += n |
| 512 | endfor |
| 513 | res->assert_equal(6) |
| 514 | enddef |
| 515 | |
Bram Moolenaar | aa210a3 | 2021-01-02 15:41:03 +0100 | [diff] [blame] | 516 | func g:ExtendDict(d) |
| 517 | call extend(a:d, #{xx: 'x'}) |
| 518 | endfunc |
| 519 | |
| 520 | def Test_extend_dict_item_type() |
| 521 | var lines =<< trim END |
| 522 | var d: dict<number> = {a: 1} |
| 523 | extend(d, {b: 2}) |
| 524 | END |
| 525 | CheckDefAndScriptSuccess(lines) |
| 526 | |
| 527 | lines =<< trim END |
| 528 | var d: dict<number> = {a: 1} |
| 529 | extend(d, {b: 'x'}) |
| 530 | END |
Bram Moolenaar | c03f5c6 | 2021-01-31 17:48:30 +0100 | [diff] [blame] | 531 | 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] | 532 | |
| 533 | lines =<< trim END |
| 534 | var d: dict<number> = {a: 1} |
| 535 | g:ExtendDict(d) |
| 536 | END |
| 537 | CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string', 0) |
| 538 | CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1) |
| 539 | enddef |
| 540 | |
| 541 | func g:ExtendList(l) |
| 542 | call extend(a:l, ['x']) |
| 543 | endfunc |
| 544 | |
| 545 | def Test_extend_list_item_type() |
| 546 | var lines =<< trim END |
| 547 | var l: list<number> = [1] |
| 548 | extend(l, [2]) |
| 549 | END |
| 550 | CheckDefAndScriptSuccess(lines) |
| 551 | |
| 552 | lines =<< trim END |
| 553 | var l: list<number> = [1] |
| 554 | extend(l, ['x']) |
| 555 | END |
Bram Moolenaar | c03f5c6 | 2021-01-31 17:48:30 +0100 | [diff] [blame] | 556 | 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] | 557 | |
| 558 | lines =<< trim END |
| 559 | var l: list<number> = [1] |
| 560 | g:ExtendList(l) |
| 561 | END |
| 562 | CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string', 0) |
| 563 | CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1) |
| 564 | enddef |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 565 | |
Bram Moolenaar | 93e1cae | 2021-03-13 21:24:56 +0100 | [diff] [blame] | 566 | def Test_extend_with_error_function() |
| 567 | var lines =<< trim END |
| 568 | vim9script |
| 569 | def F() |
| 570 | { |
| 571 | var m = 10 |
| 572 | } |
| 573 | echo m |
| 574 | enddef |
| 575 | |
| 576 | def Test() |
| 577 | var d: dict<any> = {} |
| 578 | d->extend({A: 10, Func: function('F', [])}) |
| 579 | enddef |
| 580 | |
| 581 | Test() |
| 582 | END |
| 583 | CheckScriptFailure(lines, 'E1001: Variable not found: m') |
| 584 | enddef |
| 585 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 586 | def Test_feedkeys() |
| 587 | CheckDefFailure(['feedkeys(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 588 | CheckDefFailure(['feedkeys("x", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 589 | CheckDefFailure(['feedkeys([], {})'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') |
| 590 | g:TestVar = 1 |
| 591 | feedkeys(":g:TestVar = 789\n", 'xt') |
| 592 | assert_equal(789, g:TestVar) |
| 593 | unlet g:TestVar |
| 594 | enddef |
| 595 | |
Bram Moolenaar | 64ed4d4 | 2021-01-12 21:22:31 +0100 | [diff] [blame] | 596 | def Test_job_info_return_type() |
| 597 | if has('job') |
| 598 | job_start(&shell) |
| 599 | var jobs = job_info() |
Bram Moolenaar | a47e05f | 2021-01-12 21:49:00 +0100 | [diff] [blame] | 600 | assert_equal('list<job>', typename(jobs)) |
| 601 | assert_equal('dict<any>', typename(job_info(jobs[0]))) |
Bram Moolenaar | 64ed4d4 | 2021-01-12 21:22:31 +0100 | [diff] [blame] | 602 | job_stop(jobs[0]) |
| 603 | endif |
| 604 | enddef |
| 605 | |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 606 | def Test_filereadable() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 607 | assert_false(filereadable("")) |
| 608 | assert_false(filereadable(test_null_string())) |
| 609 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 610 | CheckDefExecFailure(['echo filereadable(123)'], 'E1013:') |
| 611 | CheckDefExecFailure(['echo filereadable(true)'], 'E1013:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 612 | enddef |
| 613 | |
| 614 | def Test_filewritable() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 615 | assert_false(filewritable("")) |
| 616 | assert_false(filewritable(test_null_string())) |
| 617 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 618 | CheckDefExecFailure(['echo filewritable(123)'], 'E1013:') |
| 619 | CheckDefExecFailure(['echo filewritable(true)'], 'E1013:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 620 | enddef |
| 621 | |
| 622 | def Test_finddir() |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 623 | CheckDefExecFailure(['echo finddir(true)'], 'E1174:') |
| 624 | CheckDefExecFailure(['echo finddir(v:null)'], 'E1174:') |
Bram Moolenaar | fa98441 | 2021-03-25 22:15:28 +0100 | [diff] [blame] | 625 | CheckDefExecFailure(['echo finddir("")'], 'E1175:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 626 | enddef |
| 627 | |
| 628 | def Test_findfile() |
Bram Moolenaar | f28f2ac | 2021-03-22 22:21:26 +0100 | [diff] [blame] | 629 | CheckDefExecFailure(['echo findfile(true)'], 'E1174:') |
| 630 | CheckDefExecFailure(['echo findfile(v:null)'], 'E1174:') |
Bram Moolenaar | fa98441 | 2021-03-25 22:15:28 +0100 | [diff] [blame] | 631 | CheckDefExecFailure(['echo findfile("")'], 'E1175:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 632 | enddef |
| 633 | |
Bram Moolenaar | 3b69006 | 2021-02-01 20:14:51 +0100 | [diff] [blame] | 634 | def Test_flattennew() |
| 635 | var lines =<< trim END |
| 636 | var l = [1, [2, [3, 4]], 5] |
| 637 | call assert_equal([1, 2, 3, 4, 5], flattennew(l)) |
| 638 | call assert_equal([1, [2, [3, 4]], 5], l) |
| 639 | |
| 640 | call assert_equal([1, 2, [3, 4], 5], flattennew(l, 1)) |
| 641 | call assert_equal([1, [2, [3, 4]], 5], l) |
| 642 | END |
| 643 | CheckDefAndScriptSuccess(lines) |
| 644 | |
| 645 | lines =<< trim END |
| 646 | echo flatten([1, 2, 3]) |
| 647 | END |
| 648 | CheckDefAndScriptFailure(lines, 'E1158:') |
| 649 | enddef |
| 650 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 651 | " Test for float functions argument type |
| 652 | def Test_float_funcs_args() |
| 653 | CheckFeature float |
| 654 | |
| 655 | # acos() |
| 656 | CheckDefFailure(['echo acos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 657 | # asin() |
| 658 | CheckDefFailure(['echo asin("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 659 | # atan() |
| 660 | CheckDefFailure(['echo atan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 661 | # atan2() |
| 662 | CheckDefFailure(['echo atan2("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 663 | CheckDefFailure(['echo atan2(1.2, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 664 | CheckDefFailure(['echo atan2(1.2)'], 'E119:') |
| 665 | # ceil() |
| 666 | CheckDefFailure(['echo ceil("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 667 | # cos() |
| 668 | CheckDefFailure(['echo cos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 669 | # cosh() |
| 670 | CheckDefFailure(['echo cosh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 671 | # exp() |
| 672 | CheckDefFailure(['echo exp("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 673 | # float2nr() |
| 674 | CheckDefFailure(['echo float2nr("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 675 | # floor() |
| 676 | CheckDefFailure(['echo floor("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 677 | # fmod() |
| 678 | CheckDefFailure(['echo fmod(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 679 | CheckDefFailure(['echo fmod("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 680 | CheckDefFailure(['echo fmod(1.1)'], 'E119:') |
| 681 | # isinf() |
| 682 | CheckDefFailure(['echo isinf("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 683 | # isnan() |
| 684 | CheckDefFailure(['echo isnan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 685 | # log() |
| 686 | CheckDefFailure(['echo log("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 687 | # log10() |
| 688 | CheckDefFailure(['echo log10("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 689 | # pow() |
| 690 | CheckDefFailure(['echo pow("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 691 | CheckDefFailure(['echo pow(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 692 | CheckDefFailure(['echo pow(1.1)'], 'E119:') |
| 693 | # round() |
| 694 | CheckDefFailure(['echo round("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 695 | # sin() |
| 696 | CheckDefFailure(['echo sin("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 697 | # sinh() |
| 698 | CheckDefFailure(['echo sinh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 699 | # sqrt() |
| 700 | CheckDefFailure(['echo sqrt("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 701 | # tan() |
| 702 | CheckDefFailure(['echo tan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 703 | # tanh() |
| 704 | CheckDefFailure(['echo tanh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 705 | # trunc() |
| 706 | CheckDefFailure(['echo trunc("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 707 | enddef |
| 708 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 709 | def Test_fnameescape() |
| 710 | CheckDefFailure(['fnameescape(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 711 | assert_equal('\+a\%b\|', fnameescape('+a%b|')) |
| 712 | enddef |
| 713 | |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 714 | def Test_fnamemodify() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 715 | CheckDefSuccess(['echo fnamemodify(test_null_string(), ":p")']) |
| 716 | CheckDefSuccess(['echo fnamemodify("", ":p")']) |
| 717 | CheckDefSuccess(['echo fnamemodify("file", test_null_string())']) |
| 718 | CheckDefSuccess(['echo fnamemodify("file", "")']) |
| 719 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 720 | CheckDefExecFailure(['echo fnamemodify(true, ":p")'], 'E1013: Argument 1: type mismatch, expected string but got bool') |
| 721 | CheckDefExecFailure(['echo fnamemodify(v:null, ":p")'], 'E1013: Argument 1: type mismatch, expected string but got special') |
| 722 | 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] | 723 | enddef |
| 724 | |
Bram Moolenaar | 2e5910b | 2021-02-03 17:41:24 +0100 | [diff] [blame] | 725 | def Wrong_dict_key_type(items: list<number>): list<number> |
| 726 | return filter(items, (_, val) => get({[val]: 1}, 'x')) |
| 727 | enddef |
| 728 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 729 | def Test_filter_wrong_dict_key_type() |
Bram Moolenaar | 2e5910b | 2021-02-03 17:41:24 +0100 | [diff] [blame] | 730 | assert_fails('Wrong_dict_key_type([1, v:null, 3])', 'E1013:') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 731 | enddef |
| 732 | |
| 733 | def Test_filter_return_type() |
Bram Moolenaar | bb8a7ce | 2021-04-10 20:10:26 +0200 | [diff] [blame] | 734 | var l = filter([1, 2, 3], (_, _) => 1) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 735 | var res = 0 |
| 736 | for n in l |
| 737 | res += n |
| 738 | endfor |
| 739 | res->assert_equal(6) |
| 740 | enddef |
| 741 | |
Bram Moolenaar | fc0e8f5 | 2020-12-25 20:24:51 +0100 | [diff] [blame] | 742 | def Test_filter_missing_argument() |
| 743 | var dict = {aa: [1], ab: [2], ac: [3], de: [4]} |
Bram Moolenaar | bb8a7ce | 2021-04-10 20:10:26 +0200 | [diff] [blame] | 744 | var res = dict->filter((k, _) => k =~ 'a' && k !~ 'b') |
Bram Moolenaar | fc0e8f5 | 2020-12-25 20:24:51 +0100 | [diff] [blame] | 745 | res->assert_equal({aa: [1], ac: [3]}) |
| 746 | enddef |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 747 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 748 | def Test_foldclosed() |
| 749 | CheckDefFailure(['foldclosed(function("min"))'], 'E1013: Argument 1: type mismatch, expected string but got func(...): any') |
| 750 | assert_equal(-1, foldclosed(1)) |
| 751 | assert_equal(-1, foldclosed('$')) |
| 752 | enddef |
| 753 | |
| 754 | def Test_foldclosedend() |
| 755 | CheckDefFailure(['foldclosedend(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool') |
| 756 | assert_equal(-1, foldclosedend(1)) |
| 757 | assert_equal(-1, foldclosedend('w0')) |
| 758 | enddef |
| 759 | |
| 760 | def Test_foldlevel() |
| 761 | CheckDefFailure(['foldlevel(0z10)'], 'E1013: Argument 1: type mismatch, expected string but got blob') |
| 762 | assert_equal(0, foldlevel(1)) |
| 763 | assert_equal(0, foldlevel('.')) |
| 764 | enddef |
| 765 | |
| 766 | def Test_foldtextresult() |
| 767 | CheckDefFailure(['foldtextresult(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float') |
| 768 | assert_equal('', foldtextresult(1)) |
| 769 | assert_equal('', foldtextresult('.')) |
| 770 | enddef |
| 771 | |
Bram Moolenaar | 7d840e9 | 2021-05-26 21:10:11 +0200 | [diff] [blame] | 772 | def Test_fullcommand() |
| 773 | assert_equal('next', fullcommand('n')) |
| 774 | assert_equal('noremap', fullcommand('no')) |
| 775 | assert_equal('noremap', fullcommand('nor')) |
| 776 | assert_equal('normal', fullcommand('norm')) |
| 777 | |
| 778 | assert_equal('', fullcommand('k')) |
| 779 | assert_equal('keepmarks', fullcommand('ke')) |
| 780 | assert_equal('keepmarks', fullcommand('kee')) |
| 781 | assert_equal('keepmarks', fullcommand('keep')) |
| 782 | assert_equal('keepjumps', fullcommand('keepj')) |
| 783 | |
| 784 | assert_equal('dlist', fullcommand('dl')) |
| 785 | assert_equal('', fullcommand('dp')) |
| 786 | assert_equal('delete', fullcommand('del')) |
| 787 | assert_equal('', fullcommand('dell')) |
| 788 | assert_equal('', fullcommand('delp')) |
| 789 | |
| 790 | assert_equal('srewind', fullcommand('sre')) |
| 791 | assert_equal('scriptnames', fullcommand('scr')) |
| 792 | assert_equal('', fullcommand('scg')) |
| 793 | enddef |
| 794 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 795 | def Test_garbagecollect() |
| 796 | garbagecollect(true) |
| 797 | enddef |
| 798 | |
| 799 | def Test_getbufinfo() |
| 800 | var bufinfo = getbufinfo(bufnr()) |
| 801 | getbufinfo('%')->assert_equal(bufinfo) |
| 802 | |
| 803 | edit Xtestfile1 |
| 804 | hide edit Xtestfile2 |
| 805 | hide enew |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 806 | getbufinfo({bufloaded: true, buflisted: true, bufmodified: false}) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 807 | ->len()->assert_equal(3) |
| 808 | bwipe Xtestfile1 Xtestfile2 |
| 809 | enddef |
| 810 | |
| 811 | def Test_getbufline() |
| 812 | e SomeFile |
| 813 | var buf = bufnr() |
| 814 | e # |
| 815 | var lines = ['aaa', 'bbb', 'ccc'] |
| 816 | setbufline(buf, 1, lines) |
| 817 | getbufline('#', 1, '$')->assert_equal(lines) |
Bram Moolenaar | e6e70a1 | 2020-10-22 18:23:38 +0200 | [diff] [blame] | 818 | getbufline(-1, '$', '$')->assert_equal([]) |
| 819 | getbufline(-1, 1, '$')->assert_equal([]) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 820 | |
| 821 | bwipe! |
| 822 | enddef |
| 823 | |
| 824 | def Test_getchangelist() |
| 825 | new |
| 826 | setline(1, 'some text') |
| 827 | var changelist = bufnr()->getchangelist() |
| 828 | getchangelist('%')->assert_equal(changelist) |
| 829 | bwipe! |
| 830 | enddef |
| 831 | |
| 832 | def Test_getchar() |
| 833 | while getchar(0) |
| 834 | endwhile |
| 835 | getchar(true)->assert_equal(0) |
| 836 | enddef |
| 837 | |
Bram Moolenaar | 7ad67d1 | 2021-03-10 16:08:26 +0100 | [diff] [blame] | 838 | def Test_getenv() |
| 839 | if getenv('does-not_exist') == '' |
| 840 | assert_report('getenv() should return null') |
| 841 | endif |
| 842 | if getenv('does-not_exist') == null |
| 843 | else |
| 844 | assert_report('getenv() should return null') |
| 845 | endif |
| 846 | $SOMEENVVAR = 'some' |
| 847 | assert_equal('some', getenv('SOMEENVVAR')) |
| 848 | unlet $SOMEENVVAR |
| 849 | enddef |
| 850 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 851 | def Test_getcompletion() |
| 852 | set wildignore=*.vim,*~ |
| 853 | var l = getcompletion('run', 'file', true) |
| 854 | l->assert_equal([]) |
| 855 | set wildignore& |
| 856 | enddef |
| 857 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 858 | def Test_getcurpos() |
| 859 | CheckDefFailure(['echo getcursorcharpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 860 | enddef |
| 861 | |
| 862 | def Test_getcursorcharpos() |
| 863 | CheckDefFailure(['echo getcursorcharpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 864 | enddef |
| 865 | |
| 866 | def Test_getcwd() |
| 867 | CheckDefFailure(['echo getcwd("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 868 | CheckDefFailure(['echo getcwd("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 869 | CheckDefFailure(['echo getcwd(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 870 | enddef |
| 871 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 872 | def Test_getloclist_return_type() |
| 873 | var l = getloclist(1) |
| 874 | l->assert_equal([]) |
| 875 | |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 876 | var d = getloclist(1, {items: 0}) |
| 877 | d->assert_equal({items: []}) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 878 | enddef |
| 879 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 880 | def Test_getfontname() |
| 881 | CheckDefFailure(['getfontname(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 882 | enddef |
| 883 | |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 884 | def Test_getfperm() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 885 | assert_equal('', getfperm("")) |
| 886 | assert_equal('', getfperm(test_null_string())) |
| 887 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 888 | CheckDefExecFailure(['echo getfperm(true)'], 'E1013:') |
| 889 | CheckDefExecFailure(['echo getfperm(v:null)'], 'E1013:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 890 | enddef |
| 891 | |
| 892 | def Test_getfsize() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 893 | assert_equal(-1, getfsize("")) |
| 894 | assert_equal(-1, getfsize(test_null_string())) |
| 895 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 896 | CheckDefExecFailure(['echo getfsize(true)'], 'E1013:') |
| 897 | CheckDefExecFailure(['echo getfsize(v:null)'], 'E1013:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 898 | enddef |
| 899 | |
| 900 | def Test_getftime() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 901 | assert_equal(-1, getftime("")) |
| 902 | assert_equal(-1, getftime(test_null_string())) |
| 903 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 904 | CheckDefExecFailure(['echo getftime(true)'], 'E1013:') |
| 905 | CheckDefExecFailure(['echo getftime(v:null)'], 'E1013:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 906 | enddef |
| 907 | |
| 908 | def Test_getftype() |
Bram Moolenaar | 2a9d5d3 | 2020-12-12 18:58:40 +0100 | [diff] [blame] | 909 | assert_equal('', getftype("")) |
| 910 | assert_equal('', getftype(test_null_string())) |
| 911 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 912 | CheckDefExecFailure(['echo getftype(true)'], 'E1013:') |
| 913 | CheckDefExecFailure(['echo getftype(v:null)'], 'E1013:') |
Bram Moolenaar | 7bb4e74 | 2020-12-09 12:41:50 +0100 | [diff] [blame] | 914 | enddef |
| 915 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 916 | def Test_getjumplist() |
| 917 | CheckDefFailure(['echo getjumplist("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 918 | CheckDefFailure(['echo getjumplist("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 919 | CheckDefFailure(['echo getjumplist(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 920 | enddef |
| 921 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 922 | def Test_getmarklist() |
| 923 | CheckDefFailure(['getmarklist([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') |
| 924 | assert_equal([], getmarklist(10000)) |
| 925 | assert_fails('getmarklist("a%b@#")', 'E94:') |
| 926 | enddef |
| 927 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 928 | def Test_getmatches() |
| 929 | CheckDefFailure(['echo getmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 930 | enddef |
| 931 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 932 | def Test_getpos() |
| 933 | CheckDefFailure(['getpos(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 934 | assert_equal([0, 1, 1, 0], getpos('.')) |
| 935 | assert_equal([0, 0, 0, 0], getpos('a')) |
| 936 | enddef |
| 937 | |
| 938 | def Test_getqflist() |
| 939 | CheckDefFailure(['getqflist([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>') |
| 940 | call assert_equal({}, getqflist({})) |
| 941 | enddef |
| 942 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 943 | def Test_getqflist_return_type() |
| 944 | var l = getqflist() |
| 945 | l->assert_equal([]) |
| 946 | |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 947 | var d = getqflist({items: 0}) |
| 948 | d->assert_equal({items: []}) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 949 | enddef |
| 950 | |
| 951 | def Test_getreg() |
| 952 | var lines = ['aaa', 'bbb', 'ccc'] |
| 953 | setreg('a', lines) |
| 954 | getreg('a', true, true)->assert_equal(lines) |
Bram Moolenaar | 418a29f | 2021-02-10 22:23:41 +0100 | [diff] [blame] | 955 | assert_fails('getreg("ab")', 'E1162:') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 956 | enddef |
| 957 | |
| 958 | def Test_getreg_return_type() |
| 959 | var s1: string = getreg('"') |
| 960 | var s2: string = getreg('"', 1) |
| 961 | var s3: list<string> = getreg('"', 1, 1) |
| 962 | enddef |
| 963 | |
Bram Moolenaar | 418a29f | 2021-02-10 22:23:41 +0100 | [diff] [blame] | 964 | def Test_getreginfo() |
| 965 | var text = 'abc' |
| 966 | setreg('a', text) |
| 967 | getreginfo('a')->assert_equal({regcontents: [text], regtype: 'v', isunnamed: false}) |
| 968 | assert_fails('getreginfo("ab")', 'E1162:') |
| 969 | enddef |
| 970 | |
| 971 | def Test_getregtype() |
| 972 | var lines = ['aaa', 'bbb', 'ccc'] |
| 973 | setreg('a', lines) |
| 974 | getregtype('a')->assert_equal('V') |
| 975 | assert_fails('getregtype("ab")', 'E1162:') |
| 976 | enddef |
| 977 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 978 | def Test_gettabinfo() |
| 979 | CheckDefFailure(['echo gettabinfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 980 | enddef |
| 981 | |
| 982 | def Test_gettagstack() |
| 983 | CheckDefFailure(['echo gettagstack("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 984 | enddef |
| 985 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 986 | def Test_gettext() |
| 987 | CheckDefFailure(['gettext(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 988 | assert_equal('abc', gettext("abc")) |
| 989 | enddef |
| 990 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 991 | def Test_getwininfo() |
| 992 | CheckDefFailure(['echo getwininfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 993 | enddef |
| 994 | |
| 995 | def Test_getwinpos() |
| 996 | CheckDefFailure(['echo getwinpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 997 | enddef |
| 998 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 999 | def Test_glob() |
| 1000 | glob('runtest.vim', true, true, true)->assert_equal(['runtest.vim']) |
| 1001 | enddef |
| 1002 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1003 | def Test_glob2regpat() |
| 1004 | CheckDefFailure(['glob2regpat(null)'], 'E1013: Argument 1: type mismatch, expected string but got special') |
| 1005 | assert_equal('^$', glob2regpat('')) |
| 1006 | enddef |
| 1007 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1008 | def Test_globpath() |
| 1009 | globpath('.', 'runtest.vim', true, true, true)->assert_equal(['./runtest.vim']) |
| 1010 | enddef |
| 1011 | |
| 1012 | def Test_has() |
| 1013 | has('eval', true)->assert_equal(1) |
| 1014 | enddef |
| 1015 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1016 | def Test_haslocaldir() |
| 1017 | CheckDefFailure(['echo haslocaldir("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1018 | CheckDefFailure(['echo haslocaldir("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1019 | CheckDefFailure(['echo haslocaldir(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 1020 | enddef |
| 1021 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1022 | def Test_hasmapto() |
| 1023 | hasmapto('foobar', 'i', true)->assert_equal(0) |
| 1024 | iabbrev foo foobar |
| 1025 | hasmapto('foobar', 'i', true)->assert_equal(1) |
| 1026 | iunabbrev foo |
| 1027 | enddef |
| 1028 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1029 | def Test_histadd() |
| 1030 | CheckDefFailure(['histadd(1, "x")'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1031 | CheckDefFailure(['histadd(":", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 1032 | histadd("search", 'skyblue') |
| 1033 | assert_equal('skyblue', histget('/', -1)) |
| 1034 | enddef |
| 1035 | |
| 1036 | def Test_histnr() |
| 1037 | CheckDefFailure(['histnr(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1038 | assert_equal(-1, histnr('abc')) |
| 1039 | enddef |
| 1040 | |
| 1041 | def Test_hlID() |
| 1042 | CheckDefFailure(['hlID(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1043 | assert_equal(0, hlID('NonExistingHighlight')) |
| 1044 | enddef |
| 1045 | |
| 1046 | def Test_hlexists() |
| 1047 | CheckDefFailure(['hlexists([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') |
| 1048 | assert_equal(0, hlexists('NonExistingHighlight')) |
| 1049 | enddef |
| 1050 | |
| 1051 | def Test_iconv() |
| 1052 | CheckDefFailure(['iconv(1, "from", "to")'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1053 | CheckDefFailure(['iconv("abc", 10, "to")'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 1054 | CheckDefFailure(['iconv("abc", "from", 20)'], 'E1013: Argument 3: type mismatch, expected string but got number') |
| 1055 | assert_equal('abc', iconv('abc', 'fromenc', 'toenc')) |
| 1056 | enddef |
| 1057 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1058 | def Test_index() |
| 1059 | index(['a', 'b', 'a', 'B'], 'b', 2, true)->assert_equal(3) |
| 1060 | enddef |
| 1061 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1062 | def Test_inputlist() |
| 1063 | CheckDefFailure(['inputlist(10)'], 'E1013: Argument 1: type mismatch, expected list<string> but got number') |
| 1064 | CheckDefFailure(['inputlist("abc")'], 'E1013: Argument 1: type mismatch, expected list<string> but got string') |
| 1065 | CheckDefFailure(['inputlist([1, 2, 3])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>') |
| 1066 | feedkeys("2\<CR>", 't') |
| 1067 | var r: number = inputlist(['a', 'b', 'c']) |
| 1068 | assert_equal(2, r) |
| 1069 | enddef |
| 1070 | |
| 1071 | def Test_inputsecret() |
| 1072 | CheckDefFailure(['inputsecret(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1073 | CheckDefFailure(['inputsecret("Pass:", 20)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 1074 | feedkeys("\<CR>", 't') |
| 1075 | var ans: string = inputsecret('Pass:', '123') |
| 1076 | assert_equal('123', ans) |
| 1077 | enddef |
| 1078 | |
Bram Moolenaar | 193f620 | 2020-11-16 20:08:35 +0100 | [diff] [blame] | 1079 | let s:number_one = 1 |
| 1080 | let s:number_two = 2 |
| 1081 | let s:string_keep = 'keep' |
| 1082 | |
Bram Moolenaar | ca17453 | 2020-10-21 16:42:22 +0200 | [diff] [blame] | 1083 | def Test_insert() |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1084 | var l = insert([2, 1], 3) |
| 1085 | var res = 0 |
| 1086 | for n in l |
| 1087 | res += n |
| 1088 | endfor |
| 1089 | res->assert_equal(6) |
Bram Moolenaar | ca17453 | 2020-10-21 16:42:22 +0200 | [diff] [blame] | 1090 | |
Yegappan Lakshmanan | 34fcb69 | 2021-05-25 20:14:00 +0200 | [diff] [blame] | 1091 | var m: any = [] |
| 1092 | insert(m, 4) |
| 1093 | call assert_equal([4], m) |
| 1094 | extend(m, [6], 0) |
| 1095 | call assert_equal([6, 4], m) |
| 1096 | |
Bram Moolenaar | 39211cb | 2021-04-18 15:48:04 +0200 | [diff] [blame] | 1097 | var lines =<< trim END |
| 1098 | insert(test_null_list(), 123) |
| 1099 | END |
| 1100 | CheckDefExecAndScriptFailure(lines, 'E1130:', 1) |
| 1101 | |
| 1102 | lines =<< trim END |
| 1103 | insert(test_null_blob(), 123) |
| 1104 | END |
| 1105 | CheckDefExecAndScriptFailure(lines, 'E1131:', 1) |
| 1106 | |
Bram Moolenaar | ca17453 | 2020-10-21 16:42:22 +0200 | [diff] [blame] | 1107 | assert_equal([1, 2, 3], insert([2, 3], 1)) |
Bram Moolenaar | 193f620 | 2020-11-16 20:08:35 +0100 | [diff] [blame] | 1108 | assert_equal([1, 2, 3], insert([2, 3], s:number_one)) |
Bram Moolenaar | ca17453 | 2020-10-21 16:42:22 +0200 | [diff] [blame] | 1109 | assert_equal([1, 2, 3], insert([1, 2], 3, 2)) |
Bram Moolenaar | 193f620 | 2020-11-16 20:08:35 +0100 | [diff] [blame] | 1110 | assert_equal([1, 2, 3], insert([1, 2], 3, s:number_two)) |
Bram Moolenaar | ca17453 | 2020-10-21 16:42:22 +0200 | [diff] [blame] | 1111 | assert_equal(['a', 'b', 'c'], insert(['b', 'c'], 'a')) |
| 1112 | assert_equal(0z1234, insert(0z34, 0x12)) |
Bram Moolenaar | 193f620 | 2020-11-16 20:08:35 +0100 | [diff] [blame] | 1113 | |
Yegappan Lakshmanan | 34fcb69 | 2021-05-25 20:14:00 +0200 | [diff] [blame] | 1114 | 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] | 1115 | CheckDefFailure(['insert([2, 3], "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 1) |
| 1116 | 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] | 1117 | enddef |
| 1118 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1119 | def Test_invert() |
| 1120 | CheckDefFailure(['echo invert("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1121 | enddef |
| 1122 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1123 | def Test_isdirectory() |
| 1124 | CheckDefFailure(['isdirectory(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float') |
| 1125 | assert_false(isdirectory('NonExistingDir')) |
| 1126 | enddef |
| 1127 | |
| 1128 | def Test_items() |
| 1129 | CheckDefFailure(['[]->items()'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>') |
| 1130 | assert_equal([['a', 10], ['b', 20]], {'a': 10, 'b': 20}->items()) |
| 1131 | assert_equal([], {}->items()) |
| 1132 | enddef |
| 1133 | |
| 1134 | def Test_js_decode() |
| 1135 | CheckDefFailure(['js_decode(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1136 | assert_equal([1, 2], js_decode('[1,2]')) |
| 1137 | enddef |
| 1138 | |
| 1139 | def Test_json_decode() |
| 1140 | CheckDefFailure(['json_decode(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool') |
| 1141 | assert_equal(1.0, json_decode('1.0')) |
| 1142 | enddef |
| 1143 | |
| 1144 | def Test_keys() |
| 1145 | CheckDefFailure(['keys([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>') |
| 1146 | assert_equal(['a'], {a: 'v'}->keys()) |
| 1147 | assert_equal([], {}->keys()) |
| 1148 | enddef |
| 1149 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1150 | def Test_keys_return_type() |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 1151 | const var: list<string> = {a: 1, b: 2}->keys() |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1152 | var->assert_equal(['a', 'b']) |
| 1153 | enddef |
| 1154 | |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 1155 | def Test_line() |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1156 | assert_fails('line(true)', 'E1174:') |
| 1157 | enddef |
| 1158 | |
| 1159 | def Test_line2byte() |
| 1160 | CheckDefFailure(['line2byte(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool') |
| 1161 | assert_equal(-1, line2byte(1)) |
| 1162 | assert_equal(-1, line2byte(10000)) |
| 1163 | enddef |
| 1164 | |
| 1165 | def Test_lispindent() |
| 1166 | CheckDefFailure(['lispindent({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>') |
| 1167 | assert_equal(0, lispindent(1)) |
Bram Moolenaar | c580943 | 2021-03-27 21:23:30 +0100 | [diff] [blame] | 1168 | enddef |
| 1169 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1170 | def Test_list2str_str2list_utf8() |
| 1171 | var s = "\u3042\u3044" |
| 1172 | var l = [0x3042, 0x3044] |
| 1173 | str2list(s, true)->assert_equal(l) |
| 1174 | list2str(l, true)->assert_equal(s) |
| 1175 | enddef |
| 1176 | |
| 1177 | def SID(): number |
| 1178 | return expand('<SID>') |
| 1179 | ->matchstr('<SNR>\zs\d\+\ze_$') |
| 1180 | ->str2nr() |
| 1181 | enddef |
| 1182 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1183 | def Test_listener_remove() |
| 1184 | CheckDefFailure(['echo listener_remove("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1185 | enddef |
| 1186 | |
Bram Moolenaar | 70250fb | 2021-01-16 19:01:53 +0100 | [diff] [blame] | 1187 | def Test_map_function_arg() |
| 1188 | var lines =<< trim END |
| 1189 | def MapOne(i: number, v: string): string |
| 1190 | return i .. ':' .. v |
| 1191 | enddef |
| 1192 | var l = ['a', 'b', 'c'] |
| 1193 | map(l, MapOne) |
| 1194 | assert_equal(['0:a', '1:b', '2:c'], l) |
| 1195 | END |
| 1196 | CheckDefAndScriptSuccess(lines) |
Bram Moolenaar | 8da6d6d | 2021-06-05 18:15:09 +0200 | [diff] [blame] | 1197 | |
| 1198 | lines =<< trim END |
| 1199 | range(3)->map((a, b, c) => a + b + c) |
| 1200 | END |
| 1201 | CheckDefExecAndScriptFailure(lines, 'E1190: One argument too few') |
| 1202 | lines =<< trim END |
| 1203 | range(3)->map((a, b, c, d) => a + b + c + d) |
| 1204 | END |
| 1205 | CheckDefExecAndScriptFailure(lines, 'E1190: 2 arguments too few') |
Bram Moolenaar | 70250fb | 2021-01-16 19:01:53 +0100 | [diff] [blame] | 1206 | enddef |
| 1207 | |
| 1208 | def Test_map_item_type() |
| 1209 | var lines =<< trim END |
| 1210 | var l = ['a', 'b', 'c'] |
| 1211 | map(l, (k, v) => k .. '/' .. v ) |
| 1212 | assert_equal(['0/a', '1/b', '2/c'], l) |
| 1213 | END |
| 1214 | CheckDefAndScriptSuccess(lines) |
| 1215 | |
| 1216 | lines =<< trim END |
| 1217 | var l: list<number> = [0] |
| 1218 | echo map(l, (_, v) => []) |
| 1219 | END |
| 1220 | CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2) |
| 1221 | |
| 1222 | lines =<< trim END |
| 1223 | var l: list<number> = range(2) |
| 1224 | echo map(l, (_, v) => []) |
| 1225 | END |
| 1226 | CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2) |
| 1227 | |
| 1228 | lines =<< trim END |
| 1229 | var d: dict<number> = {key: 0} |
| 1230 | echo map(d, (_, v) => []) |
| 1231 | END |
| 1232 | CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2) |
| 1233 | enddef |
| 1234 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1235 | def Test_maparg() |
| 1236 | var lnum = str2nr(expand('<sflnum>')) |
| 1237 | map foo bar |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 1238 | maparg('foo', '', false, true)->assert_equal({ |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1239 | lnum: lnum + 1, |
| 1240 | script: 0, |
| 1241 | mode: ' ', |
| 1242 | silent: 0, |
| 1243 | noremap: 0, |
| 1244 | lhs: 'foo', |
| 1245 | lhsraw: 'foo', |
| 1246 | nowait: 0, |
| 1247 | expr: 0, |
| 1248 | sid: SID(), |
| 1249 | rhs: 'bar', |
| 1250 | buffer: 0}) |
| 1251 | unmap foo |
| 1252 | enddef |
| 1253 | |
| 1254 | def Test_mapcheck() |
| 1255 | iabbrev foo foobar |
| 1256 | mapcheck('foo', 'i', true)->assert_equal('foobar') |
| 1257 | iunabbrev foo |
| 1258 | enddef |
| 1259 | |
| 1260 | def Test_maparg_mapset() |
| 1261 | nnoremap <F3> :echo "hit F3"<CR> |
| 1262 | var mapsave = maparg('<F3>', 'n', false, true) |
| 1263 | mapset('n', false, mapsave) |
| 1264 | |
| 1265 | nunmap <F3> |
| 1266 | enddef |
| 1267 | |
Bram Moolenaar | 027c4ab | 2021-02-21 16:20:18 +0100 | [diff] [blame] | 1268 | def Test_map_failure() |
| 1269 | CheckFeature job |
| 1270 | |
| 1271 | var lines =<< trim END |
| 1272 | vim9script |
| 1273 | writefile([], 'Xtmpfile') |
| 1274 | silent e Xtmpfile |
| 1275 | var d = {[bufnr('%')]: {a: 0}} |
| 1276 | au BufReadPost * Func() |
| 1277 | def Func() |
| 1278 | if d->has_key('') |
| 1279 | endif |
| 1280 | eval d[expand('<abuf>')]->mapnew((_, v: dict<job>) => 0) |
| 1281 | enddef |
| 1282 | e |
| 1283 | END |
| 1284 | CheckScriptFailure(lines, 'E1013:') |
| 1285 | au! BufReadPost |
| 1286 | delete('Xtmpfile') |
| 1287 | enddef |
| 1288 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1289 | def Test_matcharg() |
| 1290 | CheckDefFailure(['echo matcharg("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1291 | enddef |
| 1292 | |
| 1293 | def Test_matchdelete() |
| 1294 | CheckDefFailure(['echo matchdelete("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1295 | CheckDefFailure(['echo matchdelete("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1296 | CheckDefFailure(['echo matchdelete(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 1297 | enddef |
| 1298 | |
Bram Moolenaar | 9ae3705 | 2021-01-22 22:31:10 +0100 | [diff] [blame] | 1299 | def Test_max() |
| 1300 | g:flag = true |
| 1301 | var l1: list<number> = g:flag |
| 1302 | ? [1, max([2, 3])] |
| 1303 | : [4, 5] |
| 1304 | assert_equal([1, 3], l1) |
| 1305 | |
| 1306 | g:flag = false |
| 1307 | var l2: list<number> = g:flag |
| 1308 | ? [1, max([2, 3])] |
| 1309 | : [4, 5] |
| 1310 | assert_equal([4, 5], l2) |
| 1311 | enddef |
| 1312 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1313 | def Test_menu_info() |
| 1314 | CheckDefFailure(['menu_info(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1315 | CheckDefFailure(['menu_info(10, "n")'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1316 | CheckDefFailure(['menu_info("File", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 1317 | assert_equal({}, menu_info('aMenu')) |
| 1318 | enddef |
| 1319 | |
Bram Moolenaar | 9ae3705 | 2021-01-22 22:31:10 +0100 | [diff] [blame] | 1320 | def Test_min() |
| 1321 | g:flag = true |
| 1322 | var l1: list<number> = g:flag |
| 1323 | ? [1, min([2, 3])] |
| 1324 | : [4, 5] |
| 1325 | assert_equal([1, 2], l1) |
| 1326 | |
| 1327 | g:flag = false |
| 1328 | var l2: list<number> = g:flag |
| 1329 | ? [1, min([2, 3])] |
| 1330 | : [4, 5] |
| 1331 | assert_equal([4, 5], l2) |
| 1332 | enddef |
| 1333 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1334 | def Test_nextnonblank() |
| 1335 | CheckDefFailure(['nextnonblank(null)'], 'E1013: Argument 1: type mismatch, expected string but got special') |
| 1336 | assert_equal(0, nextnonblank(1)) |
| 1337 | enddef |
| 1338 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1339 | def Test_nr2char() |
| 1340 | nr2char(97, true)->assert_equal('a') |
| 1341 | enddef |
| 1342 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1343 | def Test_or() |
| 1344 | CheckDefFailure(['echo or("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1345 | CheckDefFailure(['echo or(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 1346 | enddef |
| 1347 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1348 | def Test_prevnonblank() |
| 1349 | CheckDefFailure(['prevnonblank(null)'], 'E1013: Argument 1: type mismatch, expected string but got special') |
| 1350 | assert_equal(0, prevnonblank(1)) |
| 1351 | enddef |
| 1352 | |
| 1353 | def Test_prompt_getprompt() |
Dominique Pelle | 7450923 | 2021-07-03 19:27:37 +0200 | [diff] [blame] | 1354 | if has('channel') |
| 1355 | CheckDefFailure(['prompt_getprompt([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') |
| 1356 | assert_equal('', prompt_getprompt('NonExistingBuf')) |
| 1357 | endif |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1358 | enddef |
| 1359 | |
| 1360 | def Test_rand() |
| 1361 | CheckDefFailure(['rand(10)'], 'E1013: Argument 1: type mismatch, expected list<number> but got number') |
| 1362 | CheckDefFailure(['rand(["a"])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<string>') |
| 1363 | assert_true(rand() >= 0) |
| 1364 | assert_true(rand(srand()) >= 0) |
| 1365 | enddef |
| 1366 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1367 | def Test_readdir() |
Bram Moolenaar | 2949cfd | 2020-12-31 21:28:47 +0100 | [diff] [blame] | 1368 | eval expand('sautest')->readdir((e) => e[0] !=# '.') |
| 1369 | eval expand('sautest')->readdirex((e) => e.name[0] !=# '.') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1370 | enddef |
| 1371 | |
Bram Moolenaar | c423ad7 | 2021-01-13 20:38:03 +0100 | [diff] [blame] | 1372 | def Test_readblob() |
| 1373 | var blob = 0z12341234 |
| 1374 | writefile(blob, 'Xreadblob') |
| 1375 | var read: blob = readblob('Xreadblob') |
| 1376 | assert_equal(blob, read) |
| 1377 | |
| 1378 | var lines =<< trim END |
| 1379 | var read: list<string> = readblob('Xreadblob') |
| 1380 | END |
| 1381 | CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<string> but got blob', 1) |
| 1382 | delete('Xreadblob') |
| 1383 | enddef |
| 1384 | |
| 1385 | def Test_readfile() |
| 1386 | var text = ['aaa', 'bbb', 'ccc'] |
| 1387 | writefile(text, 'Xreadfile') |
| 1388 | var read: list<string> = readfile('Xreadfile') |
| 1389 | assert_equal(text, read) |
| 1390 | |
| 1391 | var lines =<< trim END |
| 1392 | var read: dict<string> = readfile('Xreadfile') |
| 1393 | END |
| 1394 | CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected dict<string> but got list<string>', 1) |
| 1395 | delete('Xreadfile') |
| 1396 | enddef |
| 1397 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1398 | def Test_reltime() |
| 1399 | CheckDefFailure(['reltime("x")'], 'E1013: Argument 1: type mismatch, expected list<number> but got string') |
| 1400 | CheckDefFailure(['reltime(["x", "y"])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<string>') |
| 1401 | CheckDefFailure(['reltime([1, 2], 10)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number') |
| 1402 | CheckDefFailure(['reltime([1, 2], ["a", "b"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>') |
| 1403 | var start: list<any> = reltime() |
| 1404 | assert_true(type(reltime(start)) == v:t_list) |
| 1405 | var end: list<any> = reltime() |
| 1406 | assert_true(type(reltime(start, end)) == v:t_list) |
| 1407 | enddef |
| 1408 | |
| 1409 | def Test_reltimefloat() |
| 1410 | CheckDefFailure(['reltimefloat("x")'], 'E1013: Argument 1: type mismatch, expected list<number> but got string') |
| 1411 | CheckDefFailure(['reltimefloat([1.1])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<float>') |
| 1412 | assert_true(type(reltimefloat(reltime())) == v:t_float) |
| 1413 | enddef |
| 1414 | |
| 1415 | def Test_reltimestr() |
| 1416 | CheckDefFailure(['reltimestr(true)'], 'E1013: Argument 1: type mismatch, expected list<number> but got bool') |
| 1417 | CheckDefFailure(['reltimestr([true])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<bool>') |
| 1418 | assert_true(type(reltimestr(reltime())) == v:t_string) |
| 1419 | enddef |
| 1420 | |
| 1421 | def Test_remote_foreground() |
| 1422 | CheckFeature clientserver |
| 1423 | # remote_foreground() doesn't fail on MS-Windows |
| 1424 | CheckNotMSWindows |
Bram Moolenaar | d6fa7bd | 2021-07-05 14:10:04 +0200 | [diff] [blame] | 1425 | CheckEnv DISPLAY |
| 1426 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1427 | CheckDefFailure(['remote_foreground(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1428 | assert_fails('remote_foreground("NonExistingServer")', 'E241:') |
| 1429 | enddef |
| 1430 | |
| 1431 | def Test_remote_startserver() |
| 1432 | CheckDefFailure(['remote_startserver({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>') |
| 1433 | enddef |
| 1434 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1435 | def Test_remove_return_type() |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 1436 | var l = remove({one: [1, 2], two: [3, 4]}, 'one') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1437 | var res = 0 |
| 1438 | for n in l |
| 1439 | res += n |
| 1440 | endfor |
| 1441 | res->assert_equal(3) |
| 1442 | enddef |
| 1443 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1444 | def Test_rename() |
| 1445 | CheckDefFailure(['rename(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1446 | CheckDefFailure(['rename("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 1447 | enddef |
| 1448 | |
| 1449 | def Test_resolve() |
| 1450 | CheckDefFailure(['resolve([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') |
| 1451 | assert_equal('SomeFile', resolve('SomeFile')) |
| 1452 | enddef |
| 1453 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1454 | def Test_reverse_return_type() |
| 1455 | var l = reverse([1, 2, 3]) |
| 1456 | var res = 0 |
| 1457 | for n in l |
| 1458 | res += n |
| 1459 | endfor |
| 1460 | res->assert_equal(6) |
| 1461 | enddef |
| 1462 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1463 | def Test_screenattr() |
| 1464 | CheckDefFailure(['echo screenattr("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1465 | CheckDefFailure(['echo screenattr(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 1466 | enddef |
| 1467 | |
| 1468 | def Test_screenchar() |
| 1469 | CheckDefFailure(['echo screenchar("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1470 | CheckDefFailure(['echo screenchar(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 1471 | enddef |
| 1472 | |
| 1473 | def Test_screenchars() |
| 1474 | CheckDefFailure(['echo screenchars("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1475 | CheckDefFailure(['echo screenchars(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 1476 | enddef |
| 1477 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1478 | def Test_screenpos() |
| 1479 | CheckDefFailure(['screenpos("a", 1, 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1480 | CheckDefFailure(['screenpos(1, "b", 1)'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 1481 | CheckDefFailure(['screenpos(1, 1, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string') |
| 1482 | assert_equal({col: 1, row: 1, endcol: 1, curscol: 1}, screenpos(1, 1, 1)) |
| 1483 | enddef |
| 1484 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1485 | def Test_screenstring() |
| 1486 | CheckDefFailure(['echo screenstring("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1487 | CheckDefFailure(['echo screenstring(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 1488 | enddef |
| 1489 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1490 | def Test_search() |
| 1491 | new |
| 1492 | setline(1, ['foo', 'bar']) |
| 1493 | var val = 0 |
| 1494 | # skip expr returns boolean |
Bram Moolenaar | 2949cfd | 2020-12-31 21:28:47 +0100 | [diff] [blame] | 1495 | search('bar', 'W', 0, 0, () => val == 1)->assert_equal(2) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1496 | :1 |
Bram Moolenaar | 2949cfd | 2020-12-31 21:28:47 +0100 | [diff] [blame] | 1497 | search('bar', 'W', 0, 0, () => val == 0)->assert_equal(0) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1498 | # skip expr returns number, only 0 and 1 are accepted |
| 1499 | :1 |
Bram Moolenaar | 2949cfd | 2020-12-31 21:28:47 +0100 | [diff] [blame] | 1500 | search('bar', 'W', 0, 0, () => 0)->assert_equal(2) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1501 | :1 |
Bram Moolenaar | 2949cfd | 2020-12-31 21:28:47 +0100 | [diff] [blame] | 1502 | search('bar', 'W', 0, 0, () => 1)->assert_equal(0) |
| 1503 | assert_fails("search('bar', '', 0, 0, () => -1)", 'E1023:') |
| 1504 | assert_fails("search('bar', '', 0, 0, () => -1)", 'E1023:') |
Bram Moolenaar | f06ab6b | 2021-05-07 19:44:21 +0200 | [diff] [blame] | 1505 | |
| 1506 | setline(1, "find this word") |
| 1507 | normal gg |
| 1508 | var col = 7 |
| 1509 | assert_equal(1, search('this', '', 0, 0, 'col(".") > col')) |
| 1510 | normal 0 |
| 1511 | assert_equal([1, 6], searchpos('this', '', 0, 0, 'col(".") > col')) |
| 1512 | |
| 1513 | col = 5 |
| 1514 | normal 0 |
| 1515 | assert_equal(0, search('this', '', 0, 0, 'col(".") > col')) |
| 1516 | normal 0 |
| 1517 | assert_equal([0, 0], searchpos('this', '', 0, 0, 'col(".") > col')) |
| 1518 | bwipe! |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1519 | enddef |
| 1520 | |
| 1521 | def Test_searchcount() |
| 1522 | new |
| 1523 | setline(1, "foo bar") |
| 1524 | :/foo |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 1525 | searchcount({recompute: true}) |
| 1526 | ->assert_equal({ |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1527 | exact_match: 1, |
| 1528 | current: 1, |
| 1529 | total: 1, |
| 1530 | maxcount: 99, |
| 1531 | incomplete: 0}) |
| 1532 | bwipe! |
| 1533 | enddef |
| 1534 | |
Bram Moolenaar | f18332f | 2021-05-07 17:55:55 +0200 | [diff] [blame] | 1535 | def Test_searchpair() |
| 1536 | new |
| 1537 | setline(1, "here { and } there") |
Bram Moolenaar | f06ab6b | 2021-05-07 19:44:21 +0200 | [diff] [blame] | 1538 | |
Bram Moolenaar | f18332f | 2021-05-07 17:55:55 +0200 | [diff] [blame] | 1539 | normal f{ |
| 1540 | var col = 15 |
| 1541 | assert_equal(1, searchpair('{', '', '}', '', 'col(".") > col')) |
| 1542 | assert_equal(12, col('.')) |
Bram Moolenaar | f06ab6b | 2021-05-07 19:44:21 +0200 | [diff] [blame] | 1543 | normal 0f{ |
| 1544 | assert_equal([1, 12], searchpairpos('{', '', '}', '', 'col(".") > col')) |
| 1545 | |
Bram Moolenaar | f18332f | 2021-05-07 17:55:55 +0200 | [diff] [blame] | 1546 | col = 8 |
| 1547 | normal 0f{ |
| 1548 | assert_equal(0, searchpair('{', '', '}', '', 'col(".") > col')) |
| 1549 | assert_equal(6, col('.')) |
Bram Moolenaar | f06ab6b | 2021-05-07 19:44:21 +0200 | [diff] [blame] | 1550 | normal 0f{ |
| 1551 | assert_equal([0, 0], searchpairpos('{', '', '}', '', 'col(".") > col')) |
| 1552 | |
Bram Moolenaar | ff65288 | 2021-05-16 15:24:49 +0200 | [diff] [blame] | 1553 | var lines =<< trim END |
| 1554 | vim9script |
| 1555 | setline(1, '()') |
| 1556 | normal gg |
| 1557 | def Fail() |
| 1558 | try |
| 1559 | searchpairpos('(', '', ')', 'nW', '[0]->map("")') |
| 1560 | catch |
Bram Moolenaar | cbe178e | 2021-05-18 17:49:59 +0200 | [diff] [blame] | 1561 | g:caught = 'yes' |
Bram Moolenaar | ff65288 | 2021-05-16 15:24:49 +0200 | [diff] [blame] | 1562 | endtry |
| 1563 | enddef |
| 1564 | Fail() |
| 1565 | END |
Bram Moolenaar | cbe178e | 2021-05-18 17:49:59 +0200 | [diff] [blame] | 1566 | CheckScriptSuccess(lines) |
| 1567 | assert_equal('yes', g:caught) |
Bram Moolenaar | ff65288 | 2021-05-16 15:24:49 +0200 | [diff] [blame] | 1568 | |
Bram Moolenaar | cbe178e | 2021-05-18 17:49:59 +0200 | [diff] [blame] | 1569 | unlet g:caught |
Bram Moolenaar | f18332f | 2021-05-07 17:55:55 +0200 | [diff] [blame] | 1570 | bwipe! |
| 1571 | enddef |
| 1572 | |
Bram Moolenaar | 3445320 | 2021-01-31 13:08:38 +0100 | [diff] [blame] | 1573 | def Test_set_get_bufline() |
| 1574 | # similar to Test_setbufline_getbufline() |
| 1575 | var lines =<< trim END |
| 1576 | new |
| 1577 | var b = bufnr('%') |
| 1578 | hide |
| 1579 | assert_equal(0, setbufline(b, 1, ['foo', 'bar'])) |
| 1580 | assert_equal(['foo'], getbufline(b, 1)) |
| 1581 | assert_equal(['bar'], getbufline(b, '$')) |
| 1582 | assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) |
| 1583 | exe "bd!" b |
| 1584 | assert_equal([], getbufline(b, 1, 2)) |
| 1585 | |
| 1586 | split Xtest |
| 1587 | setline(1, ['a', 'b', 'c']) |
| 1588 | b = bufnr('%') |
| 1589 | wincmd w |
| 1590 | |
| 1591 | assert_equal(1, setbufline(b, 5, 'x')) |
| 1592 | assert_equal(1, setbufline(b, 5, ['x'])) |
| 1593 | assert_equal(1, setbufline(b, 5, [])) |
| 1594 | assert_equal(1, setbufline(b, 5, test_null_list())) |
| 1595 | |
| 1596 | assert_equal(1, 'x'->setbufline(bufnr('$') + 1, 1)) |
| 1597 | assert_equal(1, ['x']->setbufline(bufnr('$') + 1, 1)) |
| 1598 | assert_equal(1, []->setbufline(bufnr('$') + 1, 1)) |
| 1599 | assert_equal(1, test_null_list()->setbufline(bufnr('$') + 1, 1)) |
| 1600 | |
| 1601 | assert_equal(['a', 'b', 'c'], getbufline(b, 1, '$')) |
| 1602 | |
| 1603 | assert_equal(0, setbufline(b, 4, ['d', 'e'])) |
| 1604 | assert_equal(['c'], b->getbufline(3)) |
| 1605 | assert_equal(['d'], getbufline(b, 4)) |
| 1606 | assert_equal(['e'], getbufline(b, 5)) |
| 1607 | assert_equal([], getbufline(b, 6)) |
| 1608 | assert_equal([], getbufline(b, 2, 1)) |
| 1609 | |
Bram Moolenaar | 0038511 | 2021-02-07 14:31:06 +0100 | [diff] [blame] | 1610 | if has('job') |
Bram Moolenaar | 1328bde | 2021-06-05 20:51:38 +0200 | [diff] [blame] | 1611 | setbufline(b, 2, [function('eval'), {key: 123}, string(test_null_job())]) |
Bram Moolenaar | 0038511 | 2021-02-07 14:31:06 +0100 | [diff] [blame] | 1612 | assert_equal(["function('eval')", |
| 1613 | "{'key': 123}", |
| 1614 | "no process"], |
| 1615 | getbufline(b, 2, 4)) |
| 1616 | endif |
Bram Moolenaar | 3445320 | 2021-01-31 13:08:38 +0100 | [diff] [blame] | 1617 | |
| 1618 | exe 'bwipe! ' .. b |
| 1619 | END |
| 1620 | CheckDefAndScriptSuccess(lines) |
| 1621 | enddef |
| 1622 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1623 | def Test_searchdecl() |
| 1624 | searchdecl('blah', true, true)->assert_equal(1) |
| 1625 | enddef |
| 1626 | |
| 1627 | def Test_setbufvar() |
| 1628 | setbufvar(bufnr('%'), '&syntax', 'vim') |
| 1629 | &syntax->assert_equal('vim') |
| 1630 | setbufvar(bufnr('%'), '&ts', 16) |
| 1631 | &ts->assert_equal(16) |
Bram Moolenaar | 31a201a | 2021-01-03 14:47:25 +0100 | [diff] [blame] | 1632 | setbufvar(bufnr('%'), '&ai', true) |
| 1633 | &ai->assert_equal(true) |
| 1634 | setbufvar(bufnr('%'), '&ft', 'filetype') |
| 1635 | &ft->assert_equal('filetype') |
| 1636 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1637 | settabwinvar(1, 1, '&syntax', 'vam') |
| 1638 | &syntax->assert_equal('vam') |
| 1639 | settabwinvar(1, 1, '&ts', 15) |
| 1640 | &ts->assert_equal(15) |
| 1641 | setlocal ts=8 |
Bram Moolenaar | b0d8182 | 2021-01-03 15:55:10 +0100 | [diff] [blame] | 1642 | settabwinvar(1, 1, '&list', false) |
| 1643 | &list->assert_equal(false) |
Bram Moolenaar | 31a201a | 2021-01-03 14:47:25 +0100 | [diff] [blame] | 1644 | settabwinvar(1, 1, '&list', true) |
| 1645 | &list->assert_equal(true) |
| 1646 | setlocal list& |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1647 | |
| 1648 | setbufvar('%', 'myvar', 123) |
| 1649 | getbufvar('%', 'myvar')->assert_equal(123) |
| 1650 | enddef |
| 1651 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1652 | def Test_setcharsearch() |
| 1653 | CheckDefFailure(['setcharsearch("x")'], 'E1013: Argument 1: type mismatch, expected dict<any> but got string') |
| 1654 | CheckDefFailure(['setcharsearch([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>') |
| 1655 | var d: dict<any> = {char: 'x', forward: 1, until: 1} |
| 1656 | setcharsearch(d) |
| 1657 | assert_equal(d, getcharsearch()) |
| 1658 | enddef |
| 1659 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1660 | def Test_setcmdpos() |
| 1661 | CheckDefFailure(['echo setcmdpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1662 | enddef |
| 1663 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1664 | def Test_setfperm() |
| 1665 | CheckDefFailure(['setfperm(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1666 | CheckDefFailure(['setfperm("a", 0z10)'], 'E1013: Argument 2: type mismatch, expected string but got blob') |
| 1667 | enddef |
| 1668 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1669 | def Test_setloclist() |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 1670 | var items = [{filename: '/tmp/file', lnum: 1, valid: true}] |
| 1671 | var what = {items: items} |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1672 | setqflist([], ' ', what) |
| 1673 | setloclist(0, [], ' ', what) |
| 1674 | enddef |
| 1675 | |
| 1676 | def Test_setreg() |
| 1677 | setreg('a', ['aaa', 'bbb', 'ccc']) |
| 1678 | var reginfo = getreginfo('a') |
| 1679 | setreg('a', reginfo) |
| 1680 | getreginfo('a')->assert_equal(reginfo) |
Bram Moolenaar | 418a29f | 2021-02-10 22:23:41 +0100 | [diff] [blame] | 1681 | assert_fails('setreg("ab", 0)', 'E1162:') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1682 | enddef |
| 1683 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1684 | def Test_sha256() |
| 1685 | CheckDefFailure(['sha256(100)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1686 | CheckDefFailure(['sha256(0zABCD)'], 'E1013: Argument 1: type mismatch, expected string but got blob') |
| 1687 | assert_equal('ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad', sha256('abc')) |
| 1688 | enddef |
| 1689 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1690 | def Test_shiftwidth() |
| 1691 | CheckDefFailure(['echo shiftwidth("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1692 | enddef |
| 1693 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1694 | def Test_simplify() |
| 1695 | CheckDefFailure(['simplify(100)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1696 | call assert_equal('NonExistingFile', simplify('NonExistingFile')) |
| 1697 | enddef |
| 1698 | |
Bram Moolenaar | 6601b62 | 2021-01-13 21:47:15 +0100 | [diff] [blame] | 1699 | def Test_slice() |
| 1700 | assert_equal('12345', slice('012345', 1)) |
| 1701 | assert_equal('123', slice('012345', 1, 4)) |
| 1702 | assert_equal('1234', slice('012345', 1, -1)) |
| 1703 | assert_equal('1', slice('012345', 1, -4)) |
| 1704 | assert_equal('', slice('012345', 1, -5)) |
| 1705 | assert_equal('', slice('012345', 1, -6)) |
| 1706 | |
| 1707 | assert_equal([1, 2, 3, 4, 5], slice(range(6), 1)) |
| 1708 | assert_equal([1, 2, 3], slice(range(6), 1, 4)) |
| 1709 | assert_equal([1, 2, 3, 4], slice(range(6), 1, -1)) |
| 1710 | assert_equal([1], slice(range(6), 1, -4)) |
| 1711 | assert_equal([], slice(range(6), 1, -5)) |
| 1712 | assert_equal([], slice(range(6), 1, -6)) |
| 1713 | |
| 1714 | assert_equal(0z1122334455, slice(0z001122334455, 1)) |
| 1715 | assert_equal(0z112233, slice(0z001122334455, 1, 4)) |
| 1716 | assert_equal(0z11223344, slice(0z001122334455, 1, -1)) |
| 1717 | assert_equal(0z11, slice(0z001122334455, 1, -4)) |
| 1718 | assert_equal(0z, slice(0z001122334455, 1, -5)) |
| 1719 | assert_equal(0z, slice(0z001122334455, 1, -6)) |
| 1720 | enddef |
| 1721 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1722 | def Test_spellsuggest() |
| 1723 | if !has('spell') |
| 1724 | MissingFeature 'spell' |
| 1725 | else |
| 1726 | spellsuggest('marrch', 1, true)->assert_equal(['March']) |
| 1727 | endif |
| 1728 | enddef |
| 1729 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1730 | def Test_sound_stop() |
| 1731 | CheckFeature sound |
| 1732 | CheckDefFailure(['sound_stop("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1733 | enddef |
| 1734 | |
| 1735 | def Test_soundfold() |
| 1736 | CheckDefFailure(['soundfold(20)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1737 | assert_equal('abc', soundfold('abc')) |
| 1738 | enddef |
| 1739 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1740 | def Test_sort_return_type() |
| 1741 | var res: list<number> |
| 1742 | res = [1, 2, 3]->sort() |
| 1743 | enddef |
| 1744 | |
| 1745 | def Test_sort_argument() |
Bram Moolenaar | 08cf0c0 | 2020-12-05 21:47:06 +0100 | [diff] [blame] | 1746 | var lines =<< trim END |
| 1747 | var res = ['b', 'a', 'c']->sort('i') |
| 1748 | res->assert_equal(['a', 'b', 'c']) |
| 1749 | |
| 1750 | def Compare(a: number, b: number): number |
| 1751 | return a - b |
| 1752 | enddef |
| 1753 | var l = [3, 6, 7, 1, 8, 2, 4, 5] |
| 1754 | sort(l, Compare) |
| 1755 | assert_equal([1, 2, 3, 4, 5, 6, 7, 8], l) |
| 1756 | END |
| 1757 | CheckDefAndScriptSuccess(lines) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1758 | enddef |
| 1759 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1760 | def Test_spellbadword() |
| 1761 | CheckDefFailure(['spellbadword(100)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1762 | spellbadword('good')->assert_equal(['', '']) |
| 1763 | enddef |
| 1764 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1765 | def Test_split() |
| 1766 | split(' aa bb ', '\W\+', true)->assert_equal(['', 'aa', 'bb', '']) |
| 1767 | enddef |
| 1768 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1769 | def Test_srand() |
| 1770 | CheckDefFailure(['srand("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1771 | type(srand(100))->assert_equal(v:t_list) |
| 1772 | enddef |
| 1773 | |
| 1774 | def Test_state() |
| 1775 | CheckDefFailure(['state({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>') |
| 1776 | assert_equal('', state('a')) |
| 1777 | enddef |
| 1778 | |
Bram Moolenaar | 80ad3e2 | 2021-01-31 20:48:58 +0100 | [diff] [blame] | 1779 | def Run_str2float() |
| 1780 | if !has('float') |
| 1781 | MissingFeature 'float' |
| 1782 | endif |
| 1783 | str2float("1.00")->assert_equal(1.00) |
| 1784 | str2float("2e-2")->assert_equal(0.02) |
| 1785 | |
| 1786 | CheckDefFailure(['echo str2float(123)'], 'E1013:') |
| 1787 | CheckScriptFailure(['vim9script', 'echo str2float(123)'], 'E1024:') |
| 1788 | endif |
| 1789 | enddef |
| 1790 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1791 | def Test_str2nr() |
| 1792 | str2nr("1'000'000", 10, true)->assert_equal(1000000) |
Bram Moolenaar | f2b26bc | 2021-01-30 23:05:11 +0100 | [diff] [blame] | 1793 | |
| 1794 | CheckDefFailure(['echo str2nr(123)'], 'E1013:') |
| 1795 | CheckScriptFailure(['vim9script', 'echo str2nr(123)'], 'E1024:') |
| 1796 | CheckDefFailure(['echo str2nr("123", "x")'], 'E1013:') |
| 1797 | CheckScriptFailure(['vim9script', 'echo str2nr("123", "x")'], 'E1030:') |
| 1798 | CheckDefFailure(['echo str2nr("123", 10, "x")'], 'E1013:') |
| 1799 | CheckScriptFailure(['vim9script', 'echo str2nr("123", 10, "x")'], 'E1135:') |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1800 | enddef |
| 1801 | |
| 1802 | def Test_strchars() |
| 1803 | strchars("A\u20dd", true)->assert_equal(1) |
| 1804 | enddef |
| 1805 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1806 | def Test_strlen() |
| 1807 | CheckDefFailure(['strlen([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') |
| 1808 | "abc"->strlen()->assert_equal(3) |
| 1809 | strlen(99)->assert_equal(2) |
| 1810 | enddef |
| 1811 | |
| 1812 | def Test_strptime() |
| 1813 | CheckFunction strptime |
| 1814 | CheckDefFailure(['strptime(10, "2021")'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1815 | CheckDefFailure(['strptime("%Y", 2021)'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 1816 | # BUG: Directly calling strptime() in this function gives an "E117: Unknown |
| 1817 | # function" error on MS-Windows even with the above CheckFunction call for |
| 1818 | # strptime(). |
| 1819 | #assert_true(strptime('%Y', '2021') != 0) |
| 1820 | enddef |
| 1821 | |
| 1822 | def Test_strtrans() |
| 1823 | CheckDefFailure(['strtrans(20)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1824 | assert_equal('abc', strtrans('abc')) |
| 1825 | enddef |
| 1826 | |
| 1827 | def Test_strwidth() |
| 1828 | CheckDefFailure(['strwidth(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1829 | CheckScriptFailure(['vim9script', 'echo strwidth(10)'], 'E1024:') |
| 1830 | assert_equal(4, strwidth('abcd')) |
| 1831 | enddef |
| 1832 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1833 | def Test_submatch() |
| 1834 | var pat = 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)' |
Bram Moolenaar | 75ab91f | 2021-01-10 22:42:50 +0100 | [diff] [blame] | 1835 | var Rep = () => range(10)->mapnew((_, v) => submatch(v, true))->string() |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1836 | var actual = substitute('A123456789', pat, Rep, '') |
| 1837 | var expected = "[['A123456789'], ['1'], ['2'], ['3'], ['4'], ['5'], ['6'], ['7'], ['8'], ['9']]" |
| 1838 | actual->assert_equal(expected) |
| 1839 | enddef |
| 1840 | |
Bram Moolenaar | 1328bde | 2021-06-05 20:51:38 +0200 | [diff] [blame] | 1841 | def Test_substitute() |
| 1842 | var res = substitute('A1234', '\d', 'X', '') |
| 1843 | assert_equal('AX234', res) |
| 1844 | |
| 1845 | if has('job') |
| 1846 | assert_fails('"text"->substitute(".*", () => job_start(":"), "")', 'E908: using an invalid value as a String: job') |
| 1847 | assert_fails('"text"->substitute(".*", () => job_start(":")->job_getchannel(), "")', 'E908: using an invalid value as a String: channel') |
| 1848 | endif |
| 1849 | enddef |
| 1850 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1851 | def Test_swapinfo() |
| 1852 | CheckDefFailure(['swapinfo({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>') |
| 1853 | call assert_equal({error: 'Cannot open file'}, swapinfo('x')) |
| 1854 | enddef |
| 1855 | |
| 1856 | def Test_swapname() |
| 1857 | CheckDefFailure(['swapname([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') |
| 1858 | assert_fails('swapname("NonExistingBuf")', 'E94:') |
| 1859 | enddef |
| 1860 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1861 | def Test_synID() |
| 1862 | new |
| 1863 | setline(1, "text") |
| 1864 | synID(1, 1, true)->assert_equal(0) |
| 1865 | bwipe! |
| 1866 | enddef |
| 1867 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1868 | def Test_synIDtrans() |
| 1869 | CheckDefFailure(['synIDtrans("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1870 | enddef |
| 1871 | |
| 1872 | def Test_tabpagebuflist() |
| 1873 | CheckDefFailure(['tabpagebuflist("t")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1874 | assert_equal([bufnr('')], tabpagebuflist()) |
| 1875 | assert_equal([bufnr('')], tabpagebuflist(1)) |
| 1876 | enddef |
| 1877 | |
| 1878 | def Test_tabpagenr() |
| 1879 | CheckDefFailure(['tabpagenr(1)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1880 | assert_equal(1, tabpagenr('$')) |
| 1881 | assert_equal(1, tabpagenr()) |
| 1882 | enddef |
| 1883 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1884 | def Test_term_gettty() |
| 1885 | if !has('terminal') |
| 1886 | MissingFeature 'terminal' |
| 1887 | else |
| 1888 | var buf = Run_shell_in_terminal({}) |
| 1889 | term_gettty(buf, true)->assert_notequal('') |
| 1890 | StopShellInTerminal(buf) |
| 1891 | endif |
| 1892 | enddef |
| 1893 | |
| 1894 | def Test_term_start() |
| 1895 | if !has('terminal') |
| 1896 | MissingFeature 'terminal' |
| 1897 | else |
| 1898 | botright new |
| 1899 | var winnr = winnr() |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 1900 | term_start(&shell, {curwin: true}) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1901 | winnr()->assert_equal(winnr) |
| 1902 | bwipe! |
| 1903 | endif |
| 1904 | enddef |
| 1905 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1906 | def Test_timer_info() |
| 1907 | CheckDefFailure(['timer_info("id")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1908 | assert_equal([], timer_info(100)) |
| 1909 | assert_equal([], timer_info()) |
| 1910 | enddef |
| 1911 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1912 | def Test_timer_paused() |
Bram Moolenaar | 2949cfd | 2020-12-31 21:28:47 +0100 | [diff] [blame] | 1913 | var id = timer_start(50, () => 0) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1914 | timer_pause(id, true) |
| 1915 | var info = timer_info(id) |
| 1916 | info[0]['paused']->assert_equal(1) |
| 1917 | timer_stop(id) |
| 1918 | enddef |
| 1919 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1920 | def Test_timer_stop() |
| 1921 | CheckDefFailure(['timer_stop("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1922 | assert_equal(0, timer_stop(100)) |
| 1923 | enddef |
| 1924 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 1925 | def Test_tolower() |
| 1926 | CheckDefFailure(['echo tolower(1)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1927 | enddef |
| 1928 | |
| 1929 | def Test_toupper() |
| 1930 | CheckDefFailure(['echo toupper(1)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1931 | enddef |
| 1932 | |
| 1933 | def Test_tr() |
| 1934 | CheckDefFailure(['echo tr(1, "a", "b")'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1935 | CheckDefFailure(['echo tr("a", 1, "b")'], 'E1013: Argument 2: type mismatch, expected string but got number') |
| 1936 | CheckDefFailure(['echo tr("a", "a", 1)'], 'E1013: Argument 3: type mismatch, expected string but got number') |
| 1937 | enddef |
| 1938 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1939 | def Test_undofile() |
| 1940 | CheckDefFailure(['undofile(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') |
| 1941 | assert_equal('.abc.un~', fnamemodify(undofile('abc'), ':t')) |
| 1942 | enddef |
| 1943 | |
| 1944 | def Test_values() |
| 1945 | CheckDefFailure(['values([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>') |
| 1946 | assert_equal([], {}->values()) |
| 1947 | assert_equal(['sun'], {star: 'sun'}->values()) |
| 1948 | enddef |
| 1949 | |
Bram Moolenaar | 37487e1 | 2021-01-12 22:08:53 +0100 | [diff] [blame] | 1950 | def Test_win_execute() |
| 1951 | assert_equal("\n" .. winnr(), win_execute(win_getid(), 'echo winnr()')) |
| 1952 | assert_equal('', win_execute(342343, 'echo winnr()')) |
| 1953 | enddef |
| 1954 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1955 | def Test_win_findbuf() |
| 1956 | CheckDefFailure(['win_findbuf("a")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1957 | assert_equal([], win_findbuf(1000)) |
| 1958 | assert_equal([win_getid()], win_findbuf(bufnr(''))) |
| 1959 | enddef |
| 1960 | |
| 1961 | def Test_win_getid() |
| 1962 | CheckDefFailure(['win_getid(".")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 1963 | CheckDefFailure(['win_getid(1, ".")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 1964 | assert_equal(win_getid(), win_getid(1, 1)) |
| 1965 | enddef |
| 1966 | |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1967 | def Test_win_splitmove() |
| 1968 | split |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 1969 | win_splitmove(1, 2, {vertical: true, rightbelow: true}) |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 1970 | close |
| 1971 | enddef |
| 1972 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1973 | def Test_winnr() |
| 1974 | CheckDefFailure(['winnr([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') |
| 1975 | assert_equal(1, winnr()) |
| 1976 | assert_equal(1, winnr('$')) |
| 1977 | enddef |
| 1978 | |
Bram Moolenaar | 285b15f | 2020-12-29 20:25:19 +0100 | [diff] [blame] | 1979 | def Test_winrestcmd() |
| 1980 | split |
| 1981 | var cmd = winrestcmd() |
| 1982 | wincmd _ |
| 1983 | exe cmd |
| 1984 | assert_equal(cmd, winrestcmd()) |
| 1985 | close |
| 1986 | enddef |
| 1987 | |
Yegappan Lakshmanan | a26f56f | 2021-07-03 11:58:12 +0200 | [diff] [blame] | 1988 | def Test_winrestview() |
| 1989 | CheckDefFailure(['winrestview([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>') |
| 1990 | :%d _ |
| 1991 | setline(1, 'Hello World') |
| 1992 | winrestview({lnum: 1, col: 6}) |
| 1993 | assert_equal([1, 7], [line('.'), col('.')]) |
| 1994 | enddef |
| 1995 | |
Bram Moolenaar | 43b69b3 | 2021-01-07 20:23:33 +0100 | [diff] [blame] | 1996 | def Test_winsaveview() |
| 1997 | var view: dict<number> = winsaveview() |
| 1998 | |
| 1999 | var lines =<< trim END |
| 2000 | var view: list<number> = winsaveview() |
| 2001 | END |
| 2002 | CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<number> but got dict<number>', 1) |
| 2003 | enddef |
| 2004 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 2005 | def Test_win_gettype() |
| 2006 | CheckDefFailure(['echo win_gettype("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 2007 | enddef |
Bram Moolenaar | 43b69b3 | 2021-01-07 20:23:33 +0100 | [diff] [blame] | 2008 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 2009 | def Test_win_gotoid() |
| 2010 | CheckDefFailure(['echo win_gotoid("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 2011 | enddef |
Bram Moolenaar | 285b15f | 2020-12-29 20:25:19 +0100 | [diff] [blame] | 2012 | |
Yegappan Lakshmanan | 7237cab | 2021-06-22 19:52:27 +0200 | [diff] [blame] | 2013 | def Test_win_id2tabwin() |
| 2014 | CheckDefFailure(['echo win_id2tabwin("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 2015 | enddef |
| 2016 | |
| 2017 | def Test_win_id2win() |
| 2018 | CheckDefFailure(['echo win_id2win("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 2019 | enddef |
| 2020 | |
| 2021 | def Test_win_screenpos() |
| 2022 | CheckDefFailure(['echo win_screenpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 2023 | enddef |
| 2024 | |
| 2025 | def Test_winbufnr() |
| 2026 | CheckDefFailure(['echo winbufnr("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 2027 | enddef |
| 2028 | |
| 2029 | def Test_winheight() |
| 2030 | CheckDefFailure(['echo winheight("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 2031 | enddef |
| 2032 | |
| 2033 | def Test_winlayout() |
| 2034 | CheckDefFailure(['echo winlayout("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 2035 | enddef |
| 2036 | |
| 2037 | def Test_winwidth() |
| 2038 | CheckDefFailure(['echo winwidth("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 2039 | enddef |
| 2040 | |
| 2041 | def Test_xor() |
| 2042 | CheckDefFailure(['echo xor("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string') |
| 2043 | CheckDefFailure(['echo xor(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') |
| 2044 | enddef |
Bram Moolenaar | 94738d8 | 2020-10-21 14:25:07 +0200 | [diff] [blame] | 2045 | |
| 2046 | " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker |