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