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