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