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