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