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