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