blob: 638d7daa13f9f340301e484a12ba3cb2735399ca [file] [log] [blame]
Bram Moolenaar94738d82020-10-21 14:25:07 +02001" Test using builtin functions in the Vim9 script language.
2
3source check.vim
4source vim9.vim
5
6" Test for passing too many or too few arguments to builtin functions
7func 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')
25endfunc
26
27" Test for builtin functions returning different types
28func 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 Moolenaare0de1712020-12-02 17:36:54 +010035 return items({k: 'v'})
Bram Moolenaar94738d82020-10-21 14:25:07 +020036 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')
64endfunc
65
66def 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
76enddef
77
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +020078def 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)
111enddef
112
Bram Moolenaar94738d82020-10-21 14:25:07 +0200113def 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 Moolenaarb7c21af2021-04-18 14:12:31 +0200125 add(test_null_list(), 123)
126 END
127 CheckDefExecAndScriptFailure(lines, 'E1130:', 1)
128
129 lines =<< trim END
Bram Moolenaar94738d82020-10-21 14:25:07 +0200130 var l: list<number> = test_null_list()
131 add(l, 123)
132 END
133 CheckDefExecFailure(lines, 'E1130:', 2)
Bram Moolenaarb7c21af2021-04-18 14:12:31 +0200134
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 Moolenaarf32f0992021-07-08 20:53:40 +0200142
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 Moolenaarf055d452021-07-08 20:57:24 +0200149
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 Moolenaar94738d82020-10-21 14:25:07 +0200156enddef
157
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200158def Test_and()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200159 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 Lakshmanan7237cab2021-06-22 19:52:27 +0200161enddef
162
Bram Moolenaar3af15ab2021-01-17 16:16:23 +0100163def 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 Moolenaarb2ac7d02021-03-28 15:46:16 +0200171
172 append(0, 'zero')
173 assert_equal('zero', getline(1))
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +0200174 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!
180enddef
181
182def 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 Moolenaarb2ac7d02021-03-28 15:46:16 +0200198 bwipe!
Bram Moolenaar3af15ab2021-01-17 16:16:23 +0100199enddef
200
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200201def Test_argc()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200202 CheckDefFailure(['argc("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200203enddef
204
205def Test_arglistid()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200206 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 Lakshmanan7237cab2021-06-22 19:52:27 +0200209enddef
210
211def Test_argv()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200212 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')
215enddef
216
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +0200217def Test_assert_beeps()
218 CheckDefAndScriptFailure2(['assert_beeps(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
219enddef
220
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200221def 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>')
225enddef
226
227def 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')
230enddef
231
232def 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')
236enddef
237
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +0200238def Test_assert_nobeep()
239 CheckDefAndScriptFailure2(['assert_nobeep(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
240enddef
241
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200242def 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 Lakshmanan7237cab2021-06-22 19:52:27 +0200246enddef
247
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +0200248def 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')
250enddef
251
Bram Moolenaar32105ae2021-03-27 18:59:25 +0100252def Test_balloon_show()
253 CheckGui
254 CheckFeature balloon_eval
255
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200256 assert_fails('balloon_show(10)', 'E1174:')
Bram Moolenaar32105ae2021-03-27 18:59:25 +0100257 assert_fails('balloon_show(true)', 'E1174:')
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +0200258
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 Moolenaar32105ae2021-03-27 18:59:25 +0100261enddef
262
263def Test_balloon_split()
Bram Moolenaar7b45d462021-03-27 19:09:02 +0100264 CheckFeature balloon_eval_term
Bram Moolenaar32105ae2021-03-27 18:59:25 +0100265
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200266 assert_fails('balloon_split([])', 'E1174:')
Bram Moolenaar32105ae2021-03-27 18:59:25 +0100267 assert_fails('balloon_split(true)', 'E1174:')
268enddef
269
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100270def Test_browse()
271 CheckFeature browse
272
273 var lines =<< trim END
Bram Moolenaarf49a1fc2021-03-27 22:20:21 +0100274 browse(1, 2, 3, 4)
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100275 END
276 CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 2')
277 lines =<< trim END
Bram Moolenaarf49a1fc2021-03-27 22:20:21 +0100278 browse(1, 'title', 3, 4)
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100279 END
280 CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 3')
281 lines =<< trim END
Bram Moolenaarf49a1fc2021-03-27 22:20:21 +0100282 browse(1, 'title', 'dir', 4)
Bram Moolenaarf28f2ac2021-03-22 22:21:26 +0100283 END
284 CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 4')
285enddef
286
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200287def Test_browsedir()
288 CheckDefFailure(['browsedir({}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>')
289 CheckDefFailure(['browsedir("a", [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>')
290enddef
291
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200292def Test_bufadd()
293 assert_fails('bufadd([])', 'E730:')
294enddef
295
Bram Moolenaar32105ae2021-03-27 18:59:25 +0100296def Test_bufexists()
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200297 assert_fails('bufexists(true)', 'E1174:')
Bram Moolenaar32105ae2021-03-27 18:59:25 +0100298enddef
299
Bram Moolenaar3af15ab2021-01-17 16:16:23 +0100300def Test_buflisted()
301 var res: bool = buflisted('asdf')
302 assert_equal(false, res)
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200303 assert_fails('buflisted(true)', 'E1174:')
304 assert_fails('buflisted([])', 'E1174:')
305enddef
306
307def Test_bufload()
308 assert_fails('bufload([])', 'E730:')
309enddef
310
311def Test_bufloaded()
312 assert_fails('bufloaded(true)', 'E1174:')
313 assert_fails('bufloaded([])', 'E1174:')
Bram Moolenaar3af15ab2021-01-17 16:16:23 +0100314enddef
315
Bram Moolenaar94738d82020-10-21 14:25:07 +0200316def Test_bufname()
317 split SomeFile
318 bufname('%')->assert_equal('SomeFile')
319 edit OtherFile
320 bufname('#')->assert_equal('SomeFile')
321 close
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200322 assert_fails('bufname(true)', 'E1138:')
323 assert_fails('bufname([])', 'E745:')
Bram Moolenaar94738d82020-10-21 14:25:07 +0200324enddef
325
326def Test_bufnr()
327 var buf = bufnr()
328 bufnr('%')->assert_equal(buf)
329
330 buf = bufnr('Xdummy', true)
331 buf->assert_notequal(-1)
332 exe 'bwipe! ' .. buf
333enddef
334
335def Test_bufwinid()
336 var origwin = win_getid()
337 below split SomeFile
338 var SomeFileID = win_getid()
339 below split OtherFile
340 below split SomeFile
341 bufwinid('SomeFile')->assert_equal(SomeFileID)
342
343 win_gotoid(origwin)
344 only
345 bwipe SomeFile
346 bwipe OtherFile
Bram Moolenaar32105ae2021-03-27 18:59:25 +0100347
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200348 assert_fails('bufwinid(true)', 'E1138:')
349 assert_fails('bufwinid([])', 'E745:')
350enddef
351
352def Test_bufwinnr()
353 assert_fails('bufwinnr(true)', 'E1138:')
354 assert_fails('bufwinnr([])', 'E745:')
355enddef
356
357def Test_byte2line()
358 CheckDefFailure(['byte2line("1")'], 'E1013: Argument 1: type mismatch, expected number but got string')
359 CheckDefFailure(['byte2line([])'], 'E1013: Argument 1: type mismatch, expected number but got list<unknown>')
360 assert_equal(-1, byte2line(0))
Bram Moolenaar94738d82020-10-21 14:25:07 +0200361enddef
362
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +0200363def Test_byteidx()
364 CheckDefAndScriptFailure2(['byteidx(1, 2)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
365 CheckDefAndScriptFailure2(['byteidx("a", "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
366enddef
367
368def Test_byteidxcomp()
369 CheckDefAndScriptFailure2(['byteidxcomp(1, 2)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
370 CheckDefAndScriptFailure2(['byteidxcomp("a", "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
371enddef
372
Bram Moolenaar94738d82020-10-21 14:25:07 +0200373def Test_call_call()
374 var l = [3, 2, 1]
375 call('reverse', [l])
376 l->assert_equal([1, 2, 3])
377enddef
378
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200379def Test_ch_canread()
380 if !has('channel')
381 CheckFeature channel
382 endif
383 CheckDefFailure(['ch_canread(10)'], 'E1013: Argument 1: type mismatch, expected channel but got number')
384enddef
385
386def Test_ch_close()
387 if !has('channel')
388 CheckFeature channel
389 endif
390 CheckDefFailure(['ch_close("c")'], 'E1013: Argument 1: type mismatch, expected channel but got string')
391enddef
392
393def Test_ch_close_in()
394 if !has('channel')
395 CheckFeature channel
396 endif
397 CheckDefFailure(['ch_close_in(true)'], 'E1013: Argument 1: type mismatch, expected channel but got bool')
398enddef
399
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +0200400def Test_ch_getjob()
Dominique Pelle9ff9c7b2021-07-18 21:44:37 +0200401 if !has('channel')
402 CheckFeature channel
403 else
404 CheckDefAndScriptFailure2(['ch_getjob(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument:')
405 CheckDefAndScriptFailure2(['ch_getjob({"a": 10})'], 'E1013: Argument 1: type mismatch, expected channel but got dict<number>', 'E731: Using a Dictionary as a String')
406 assert_equal(0, ch_getjob(test_null_channel()))
407 endif
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +0200408enddef
409
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200410def Test_ch_info()
411 if !has('channel')
412 CheckFeature channel
413 endif
414 CheckDefFailure(['ch_info([1])'], 'E1013: Argument 1: type mismatch, expected channel but got list<number>')
415enddef
416
Bram Moolenaarc5809432021-03-27 21:23:30 +0100417def Test_ch_logfile()
Bram Moolenaar886e5e72021-04-05 13:36:34 +0200418 if !has('channel')
419 CheckFeature channel
420 endif
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200421 assert_fails('ch_logfile(true)', 'E1174:')
422 assert_fails('ch_logfile("foo", true)', 'E1174:')
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200423
424 CheckDefAndScriptFailure2(['ch_logfile(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
425 CheckDefAndScriptFailure2(['ch_logfile("a", true)'], 'E1013: Argument 2: type mismatch, expected string but got bool', 'E1174: String required for argument 2')
426enddef
427
428def Test_ch_open()
429 if !has('channel')
430 CheckFeature channel
431 endif
432 CheckDefAndScriptFailure2(['ch_open({"a": 10}, "a")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E1174: String required for argument 1')
433 CheckDefAndScriptFailure2(['ch_open("a", [1])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 2')
Bram Moolenaarc5809432021-03-27 21:23:30 +0100434enddef
435
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +0200436def Test_ch_read()
437 if !has('channel')
438 CheckFeature channel
439 endif
440 CheckDefAndScriptFailure2(['ch_read(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument')
441 CheckDefAndScriptFailure2(['ch_read(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required')
442enddef
443
444def Test_ch_readblob()
445 if !has('channel')
446 CheckFeature channel
447 endif
448 CheckDefAndScriptFailure2(['ch_readblob(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument')
449 CheckDefAndScriptFailure2(['ch_readblob(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required')
450enddef
451
452def Test_ch_readraw()
453 if !has('channel')
454 CheckFeature channel
455 endif
456 CheckDefAndScriptFailure2(['ch_readraw(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument')
457 CheckDefAndScriptFailure2(['ch_readraw(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required')
458enddef
459
460def Test_ch_setoptions()
461 if !has('channel')
462 CheckFeature channel
463 endif
464 CheckDefAndScriptFailure2(['ch_setoptions(1, {})'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument')
465 CheckDefFailure(['ch_setoptions(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>')
466enddef
467
468def Test_ch_status()
469 if !has('channel')
470 CheckFeature channel
471 endif
472 CheckDefAndScriptFailure2(['ch_status(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument')
473 CheckDefAndScriptFailure2(['ch_status(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required')
474enddef
475
Bram Moolenaar94738d82020-10-21 14:25:07 +0200476def Test_char2nr()
477 char2nr('あ', true)->assert_equal(12354)
Bram Moolenaarc5809432021-03-27 21:23:30 +0100478
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200479 assert_fails('char2nr(true)', 'E1174:')
Yegappan Lakshmanana9a7c0c2021-07-17 19:11:07 +0200480 CheckDefAndScriptFailure2(['char2nr(10)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
481 CheckDefAndScriptFailure2(['char2nr("a", 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1211: Bool required for argument 2')
482 assert_equal(97, char2nr('a', 1))
483 assert_equal(97, char2nr('a', 0))
484 assert_equal(97, char2nr('a', true))
485 assert_equal(97, char2nr('a', false))
Bram Moolenaarc5809432021-03-27 21:23:30 +0100486enddef
487
488def Test_charclass()
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200489 assert_fails('charclass(true)', 'E1174:')
Bram Moolenaarc5809432021-03-27 21:23:30 +0100490enddef
491
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200492def Test_charcol()
493 CheckDefFailure(['charcol(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
494 CheckDefFailure(['charcol({a: 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>')
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +0200495 new
496 setline(1, ['abcdefgh'])
497 cursor(1, 4)
498 assert_equal(4, charcol('.'))
499 assert_equal(9, charcol([1, '$']))
500 assert_equal(0, charcol([10, '$']))
501 bw!
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200502enddef
503
504def Test_charidx()
505 CheckDefFailure(['charidx("a", "b")'], 'E1013: Argument 2: type mismatch, expected number but got string')
506 CheckDefFailure(['charidx(0z10, 1)'], 'E1013: Argument 1: type mismatch, expected string but got blob')
507 CheckDefFailure(['charidx("a", 1, "")'], 'E1013: Argument 3: type mismatch, expected bool but got string')
508enddef
509
Bram Moolenaarc5809432021-03-27 21:23:30 +0100510def Test_chdir()
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200511 assert_fails('chdir(true)', 'E1174:')
512enddef
513
514def Test_cindent()
515 CheckDefFailure(['cindent([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
516 CheckDefFailure(['cindent(null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
517 assert_equal(-1, cindent(0))
518 assert_equal(0, cindent('.'))
Bram Moolenaar94738d82020-10-21 14:25:07 +0200519enddef
520
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200521def Test_clearmatches()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200522 CheckDefFailure(['clearmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200523enddef
524
Bram Moolenaar94738d82020-10-21 14:25:07 +0200525def Test_col()
526 new
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +0200527 setline(1, 'abcdefgh')
528 cursor(1, 4)
529 assert_equal(4, col('.'))
530 col([1, '$'])->assert_equal(9)
531 assert_equal(0, col([10, '$']))
Bram Moolenaarc5809432021-03-27 21:23:30 +0100532
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200533 assert_fails('col(true)', 'E1174:')
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200534
535 CheckDefFailure(['col(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
536 CheckDefFailure(['col({a: 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>')
537 CheckDefFailure(['col(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
538 bw!
Bram Moolenaarc5809432021-03-27 21:23:30 +0100539enddef
540
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +0200541def Test_complete_info()
542 CheckDefFailure(['complete_info("")'], 'E1013: Argument 1: type mismatch, expected list<string> but got string')
543 CheckDefFailure(['complete_info({})'], 'E1013: Argument 1: type mismatch, expected list<string> but got dict<unknown>')
544 assert_equal({'pum_visible': 0, 'mode': '', 'selected': -1, 'items': []}, complete_info())
545 assert_equal({'mode': '', 'items': []}, complete_info(['mode', 'items']))
546enddef
547
Bram Moolenaarc5809432021-03-27 21:23:30 +0100548def Test_confirm()
549 if !has('dialog_con') && !has('dialog_gui')
550 CheckFeature dialog_con
551 endif
552
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200553 assert_fails('confirm(true)', 'E1174:')
554 assert_fails('confirm("yes", true)', 'E1174:')
555 assert_fails('confirm("yes", "maybe", 2, true)', 'E1174:')
556enddef
557
Bram Moolenaar94738d82020-10-21 14:25:07 +0200558def Test_copy_return_type()
559 var l = copy([1, 2, 3])
560 var res = 0
561 for n in l
562 res += n
563 endfor
564 res->assert_equal(6)
565
566 var dl = deepcopy([1, 2, 3])
567 res = 0
568 for n in dl
569 res += n
570 endfor
571 res->assert_equal(6)
572
573 dl = deepcopy([1, 2, 3], true)
574enddef
575
576def Test_count()
577 count('ABC ABC ABC', 'b', true)->assert_equal(3)
578 count('ABC ABC ABC', 'b', false)->assert_equal(0)
579enddef
580
Bram Moolenaar9a963372020-12-21 21:58:46 +0100581def Test_cursor()
582 new
583 setline(1, range(4))
584 cursor(2, 1)
585 assert_equal(2, getcurpos()[1])
586 cursor('$', 1)
587 assert_equal(4, getcurpos()[1])
588
589 var lines =<< trim END
590 cursor('2', 1)
591 END
Bram Moolenaar0f1227f2021-07-11 16:01:58 +0200592 CheckDefExecAndScriptFailure(lines, 'E1209:')
Bram Moolenaar9a963372020-12-21 21:58:46 +0100593enddef
594
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200595def Test_debugbreak()
596 CheckMSWindows
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200597 CheckDefFailure(['debugbreak("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200598enddef
599
Bram Moolenaar3af15ab2021-01-17 16:16:23 +0100600def Test_delete()
601 var res: bool = delete('doesnotexist')
602 assert_equal(true, res)
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200603
604 CheckDefFailure(['delete(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
605 CheckDefFailure(['delete("a", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
Bram Moolenaar3af15ab2021-01-17 16:16:23 +0100606enddef
607
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200608def Test_diff_filler()
609 CheckDefFailure(['diff_filler([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
610 CheckDefFailure(['diff_filler(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
611 assert_equal(0, diff_filler(1))
612 assert_equal(0, diff_filler('.'))
613enddef
614
Yegappan Lakshmanana9a7c0c2021-07-17 19:11:07 +0200615def Test_diff_hlID()
616 CheckDefAndScriptFailure2(['diff_hlID(0z10, 1)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1')
617 CheckDefAndScriptFailure2(['diff_hlID(1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
618enddef
619
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +0200620def Test_echoraw()
621 CheckDefAndScriptFailure2(['echoraw(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
622 CheckDefAndScriptFailure2(['echoraw(["x"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E1174: String required for argument 1')
623enddef
624
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200625def Test_escape()
626 CheckDefFailure(['escape("a", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
627 CheckDefFailure(['escape(10, " ")'], 'E1013: Argument 1: type mismatch, expected string but got number')
628 CheckDefFailure(['escape(true, false)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
629 assert_equal('a\:b', escape("a:b", ":"))
630enddef
631
632def Test_eval()
633 CheckDefFailure(['eval(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
634 CheckDefFailure(['eval(null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
635 assert_equal(2, eval('1 + 1'))
636enddef
637
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100638def Test_executable()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100639 assert_false(executable(""))
640 assert_false(executable(test_null_string()))
641
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200642 CheckDefExecFailure(['echo executable(123)'], 'E1013:')
643 CheckDefExecFailure(['echo executable(true)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100644enddef
645
Bram Moolenaarca81f0e2021-06-20 14:41:01 +0200646def Test_execute()
647 var res = execute("echo 'hello'")
648 assert_equal("\nhello", res)
649 res = execute(["echo 'here'", "echo 'there'"])
650 assert_equal("\nhere\nthere", res)
651
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200652 CheckDefFailure(['execute(123)'], 'E1013: Argument 1: type mismatch, expected string but got number')
653 CheckDefFailure(['execute([123])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>')
Bram Moolenaarca81f0e2021-06-20 14:41:01 +0200654 CheckDefExecFailure(['echo execute(["xx", 123])'], 'E492')
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200655 CheckDefFailure(['execute("xx", 123)'], 'E1013: Argument 2: type mismatch, expected string but got number')
Bram Moolenaarca81f0e2021-06-20 14:41:01 +0200656enddef
657
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100658def Test_exepath()
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200659 CheckDefExecFailure(['echo exepath(true)'], 'E1013:')
660 CheckDefExecFailure(['echo exepath(v:null)'], 'E1013:')
Bram Moolenaarfa984412021-03-25 22:15:28 +0100661 CheckDefExecFailure(['echo exepath("")'], 'E1175:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100662enddef
663
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200664def Test_exists()
665 CheckDefFailure(['exists(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
666 call assert_equal(1, exists('&tabstop'))
667enddef
668
Bram Moolenaar94738d82020-10-21 14:25:07 +0200669def Test_expand()
670 split SomeFile
671 expand('%', true, true)->assert_equal(['SomeFile'])
672 close
673enddef
674
Bram Moolenaar02795102021-05-03 21:40:26 +0200675def Test_expandcmd()
676 $FOO = "blue"
677 assert_equal("blue sky", expandcmd("`=$FOO .. ' sky'`"))
678
679 assert_equal("yes", expandcmd("`={a: 'yes'}['a']`"))
680enddef
681
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100682def Test_extend_arg_types()
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100683 g:number_one = 1
684 g:string_keep = 'keep'
685 var lines =<< trim END
686 assert_equal([1, 2, 3], extend([1, 2], [3]))
687 assert_equal([3, 1, 2], extend([1, 2], [3], 0))
688 assert_equal([1, 3, 2], extend([1, 2], [3], 1))
689 assert_equal([1, 3, 2], extend([1, 2], [3], g:number_one))
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100690
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100691 assert_equal({a: 1, b: 2, c: 3}, extend({a: 1, b: 2}, {c: 3}))
692 assert_equal({a: 1, b: 4}, extend({a: 1, b: 2}, {b: 4}))
693 assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, 'keep'))
694 assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, g:string_keep))
Bram Moolenaar193f6202020-11-16 20:08:35 +0100695
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100696 var res: list<dict<any>>
697 extend(res, mapnew([1, 2], (_, v) => ({})))
698 assert_equal([{}, {}], res)
699 END
700 CheckDefAndScriptSuccess(lines)
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100701
Yegappan Lakshmanan34fcb692021-05-25 20:14:00 +0200702 CheckDefFailure(['extend("a", 1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got string')
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100703 CheckDefFailure(['extend([1, 2], 3)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number')
704 CheckDefFailure(['extend([1, 2], ["x"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
705 CheckDefFailure(['extend([1, 2], [3], "x")'], 'E1013: Argument 3: type mismatch, expected number but got string')
706
Bram Moolenaare0de1712020-12-02 17:36:54 +0100707 CheckDefFailure(['extend({a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number')
708 CheckDefFailure(['extend({a: 1}, {b: "x"})'], 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>')
709 CheckDefFailure(['extend({a: 1}, {b: 2}, 1)'], 'E1013: Argument 3: type mismatch, expected string but got number')
Bram Moolenaar351ead02021-01-16 16:07:01 +0100710
711 CheckDefFailure(['extend([1], ["b"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
Bram Moolenaare32e5162021-01-21 20:21:29 +0100712 CheckDefExecFailure(['extend([1], ["b", 1])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<any>')
Bram Moolenaarfbcbffe2020-10-31 19:33:38 +0100713enddef
714
Bram Moolenaaraa210a32021-01-02 15:41:03 +0100715func g:ExtendDict(d)
716 call extend(a:d, #{xx: 'x'})
717endfunc
718
719def Test_extend_dict_item_type()
720 var lines =<< trim END
721 var d: dict<number> = {a: 1}
722 extend(d, {b: 2})
723 END
724 CheckDefAndScriptSuccess(lines)
725
726 lines =<< trim END
727 var d: dict<number> = {a: 1}
728 extend(d, {b: 'x'})
729 END
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100730 CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>', 2)
Bram Moolenaaraa210a32021-01-02 15:41:03 +0100731
732 lines =<< trim END
733 var d: dict<number> = {a: 1}
734 g:ExtendDict(d)
735 END
736 CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string', 0)
737 CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1)
738enddef
739
740func g:ExtendList(l)
741 call extend(a:l, ['x'])
742endfunc
743
744def Test_extend_list_item_type()
745 var lines =<< trim END
746 var l: list<number> = [1]
747 extend(l, [2])
748 END
749 CheckDefAndScriptSuccess(lines)
750
751 lines =<< trim END
752 var l: list<number> = [1]
753 extend(l, ['x'])
754 END
Bram Moolenaarc03f5c62021-01-31 17:48:30 +0100755 CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>', 2)
Bram Moolenaaraa210a32021-01-02 15:41:03 +0100756
757 lines =<< trim END
758 var l: list<number> = [1]
759 g:ExtendList(l)
760 END
761 CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string', 0)
762 CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1)
763enddef
Bram Moolenaar94738d82020-10-21 14:25:07 +0200764
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +0200765def Test_extend_return_type()
766 var l = extend([1, 2], [3])
767 var res = 0
768 for n in l
769 res += n
770 endfor
771 res->assert_equal(6)
772enddef
773
Bram Moolenaar93e1cae2021-03-13 21:24:56 +0100774def Test_extend_with_error_function()
775 var lines =<< trim END
776 vim9script
777 def F()
778 {
779 var m = 10
780 }
781 echo m
782 enddef
783
784 def Test()
785 var d: dict<any> = {}
786 d->extend({A: 10, Func: function('F', [])})
787 enddef
788
789 Test()
790 END
791 CheckScriptFailure(lines, 'E1001: Variable not found: m')
792enddef
793
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +0200794def Test_extendnew()
795 assert_equal([1, 2, 'a'], extendnew([1, 2], ['a']))
796 assert_equal({one: 1, two: 'a'}, extendnew({one: 1}, {two: 'a'}))
797
798 CheckDefFailure(['extendnew({a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number')
799 CheckDefFailure(['extendnew({a: 1}, [42])'], 'E1013: Argument 2: type mismatch, expected dict<number> but got list<number>')
800 CheckDefFailure(['extendnew([1, 2], "x")'], 'E1013: Argument 2: type mismatch, expected list<number> but got string')
801 CheckDefFailure(['extendnew([1, 2], {x: 1})'], 'E1013: Argument 2: type mismatch, expected list<number> but got dict<number>')
802enddef
803
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200804def Test_feedkeys()
805 CheckDefFailure(['feedkeys(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
806 CheckDefFailure(['feedkeys("x", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
807 CheckDefFailure(['feedkeys([], {})'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
808 g:TestVar = 1
809 feedkeys(":g:TestVar = 789\n", 'xt')
810 assert_equal(789, g:TestVar)
811 unlet g:TestVar
812enddef
813
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100814def Test_filereadable()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100815 assert_false(filereadable(""))
816 assert_false(filereadable(test_null_string()))
817
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200818 CheckDefExecFailure(['echo filereadable(123)'], 'E1013:')
819 CheckDefExecFailure(['echo filereadable(true)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100820enddef
821
822def Test_filewritable()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100823 assert_false(filewritable(""))
824 assert_false(filewritable(test_null_string()))
825
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200826 CheckDefExecFailure(['echo filewritable(123)'], 'E1013:')
827 CheckDefExecFailure(['echo filewritable(true)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100828enddef
829
830def Test_finddir()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200831 CheckDefAndScriptFailure2(['finddir(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1174: String required for argument 1')
832 CheckDefAndScriptFailure2(['finddir(v:null)'], 'E1013: Argument 1: type mismatch, expected string but got special', 'E1174: String required for argument 1')
Bram Moolenaarfa984412021-03-25 22:15:28 +0100833 CheckDefExecFailure(['echo finddir("")'], 'E1175:')
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200834 CheckDefAndScriptFailure2(['finddir("a", [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E730: Using a List as a String')
835 CheckDefAndScriptFailure2(['finddir("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100836enddef
837
838def Test_findfile()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200839 CheckDefExecFailure(['findfile(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
840 CheckDefExecFailure(['findfile(v:null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
841 CheckDefExecFailure(['findfile("")'], 'E1175:')
842 CheckDefAndScriptFailure2(['findfile("a", [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E730: Using a List as a String')
843 CheckDefAndScriptFailure2(['findfile("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100844enddef
845
Bram Moolenaar3b690062021-02-01 20:14:51 +0100846def Test_flattennew()
847 var lines =<< trim END
848 var l = [1, [2, [3, 4]], 5]
849 call assert_equal([1, 2, 3, 4, 5], flattennew(l))
850 call assert_equal([1, [2, [3, 4]], 5], l)
851
852 call assert_equal([1, 2, [3, 4], 5], flattennew(l, 1))
853 call assert_equal([1, [2, [3, 4]], 5], l)
854 END
855 CheckDefAndScriptSuccess(lines)
856
857 lines =<< trim END
858 echo flatten([1, 2, 3])
859 END
860 CheckDefAndScriptFailure(lines, 'E1158:')
861enddef
862
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200863" Test for float functions argument type
864def Test_float_funcs_args()
865 CheckFeature float
866
867 # acos()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200868 CheckDefFailure(['acos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200869 # asin()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200870 CheckDefFailure(['asin("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200871 # atan()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200872 CheckDefFailure(['atan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200873 # atan2()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200874 CheckDefFailure(['atan2("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
875 CheckDefFailure(['atan2(1.2, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string')
876 CheckDefFailure(['atan2(1.2)'], 'E119:')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200877 # ceil()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200878 CheckDefFailure(['ceil("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200879 # cos()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200880 CheckDefFailure(['cos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200881 # cosh()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200882 CheckDefFailure(['cosh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200883 # exp()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200884 CheckDefFailure(['exp("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200885 # float2nr()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200886 CheckDefFailure(['float2nr("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200887 # floor()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200888 CheckDefFailure(['floor("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200889 # fmod()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200890 CheckDefFailure(['fmod(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string')
891 CheckDefFailure(['fmod("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
892 CheckDefFailure(['fmod(1.1)'], 'E119:')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200893 # isinf()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200894 CheckDefFailure(['isinf("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200895 # isnan()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200896 CheckDefFailure(['isnan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200897 # log()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200898 CheckDefFailure(['log("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200899 # log10()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200900 CheckDefFailure(['log10("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200901 # pow()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200902 CheckDefFailure(['pow("a", 1.1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
903 CheckDefFailure(['pow(1.1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string')
904 CheckDefFailure(['pow(1.1)'], 'E119:')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200905 # round()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200906 CheckDefFailure(['round("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200907 # sin()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200908 CheckDefFailure(['sin("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200909 # sinh()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200910 CheckDefFailure(['sinh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200911 # sqrt()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200912 CheckDefFailure(['sqrt("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200913 # tan()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200914 CheckDefFailure(['tan("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200915 # tanh()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200916 CheckDefFailure(['tanh("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200917 # trunc()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +0200918 CheckDefFailure(['trunc("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +0200919enddef
920
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200921def Test_fnameescape()
922 CheckDefFailure(['fnameescape(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
923 assert_equal('\+a\%b\|', fnameescape('+a%b|'))
924enddef
925
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100926def Test_fnamemodify()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +0100927 CheckDefSuccess(['echo fnamemodify(test_null_string(), ":p")'])
928 CheckDefSuccess(['echo fnamemodify("", ":p")'])
929 CheckDefSuccess(['echo fnamemodify("file", test_null_string())'])
930 CheckDefSuccess(['echo fnamemodify("file", "")'])
931
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200932 CheckDefExecFailure(['echo fnamemodify(true, ":p")'], 'E1013: Argument 1: type mismatch, expected string but got bool')
933 CheckDefExecFailure(['echo fnamemodify(v:null, ":p")'], 'E1013: Argument 1: type mismatch, expected string but got special')
934 CheckDefExecFailure(['echo fnamemodify("file", true)'], 'E1013: Argument 2: type mismatch, expected string but got bool')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +0100935enddef
936
Bram Moolenaar2e5910b2021-02-03 17:41:24 +0100937def Wrong_dict_key_type(items: list<number>): list<number>
938 return filter(items, (_, val) => get({[val]: 1}, 'x'))
939enddef
940
Bram Moolenaar94738d82020-10-21 14:25:07 +0200941def Test_filter_wrong_dict_key_type()
Bram Moolenaar2e5910b2021-02-03 17:41:24 +0100942 assert_fails('Wrong_dict_key_type([1, v:null, 3])', 'E1013:')
Bram Moolenaar94738d82020-10-21 14:25:07 +0200943enddef
944
945def Test_filter_return_type()
Bram Moolenaarbb8a7ce2021-04-10 20:10:26 +0200946 var l = filter([1, 2, 3], (_, _) => 1)
Bram Moolenaar94738d82020-10-21 14:25:07 +0200947 var res = 0
948 for n in l
949 res += n
950 endfor
951 res->assert_equal(6)
952enddef
953
Bram Moolenaarfc0e8f52020-12-25 20:24:51 +0100954def Test_filter_missing_argument()
955 var dict = {aa: [1], ab: [2], ac: [3], de: [4]}
Bram Moolenaarbb8a7ce2021-04-10 20:10:26 +0200956 var res = dict->filter((k, _) => k =~ 'a' && k !~ 'b')
Bram Moolenaarfc0e8f52020-12-25 20:24:51 +0100957 res->assert_equal({aa: [1], ac: [3]})
958enddef
Bram Moolenaar94738d82020-10-21 14:25:07 +0200959
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +0200960def Test_foldclosed()
961 CheckDefFailure(['foldclosed(function("min"))'], 'E1013: Argument 1: type mismatch, expected string but got func(...): any')
962 assert_equal(-1, foldclosed(1))
963 assert_equal(-1, foldclosed('$'))
964enddef
965
966def Test_foldclosedend()
967 CheckDefFailure(['foldclosedend(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
968 assert_equal(-1, foldclosedend(1))
969 assert_equal(-1, foldclosedend('w0'))
970enddef
971
972def Test_foldlevel()
973 CheckDefFailure(['foldlevel(0z10)'], 'E1013: Argument 1: type mismatch, expected string but got blob')
974 assert_equal(0, foldlevel(1))
975 assert_equal(0, foldlevel('.'))
976enddef
977
978def Test_foldtextresult()
979 CheckDefFailure(['foldtextresult(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float')
980 assert_equal('', foldtextresult(1))
981 assert_equal('', foldtextresult('.'))
982enddef
983
Bram Moolenaar7d840e92021-05-26 21:10:11 +0200984def Test_fullcommand()
985 assert_equal('next', fullcommand('n'))
986 assert_equal('noremap', fullcommand('no'))
987 assert_equal('noremap', fullcommand('nor'))
988 assert_equal('normal', fullcommand('norm'))
989
990 assert_equal('', fullcommand('k'))
991 assert_equal('keepmarks', fullcommand('ke'))
992 assert_equal('keepmarks', fullcommand('kee'))
993 assert_equal('keepmarks', fullcommand('keep'))
994 assert_equal('keepjumps', fullcommand('keepj'))
995
996 assert_equal('dlist', fullcommand('dl'))
997 assert_equal('', fullcommand('dp'))
998 assert_equal('delete', fullcommand('del'))
999 assert_equal('', fullcommand('dell'))
1000 assert_equal('', fullcommand('delp'))
1001
1002 assert_equal('srewind', fullcommand('sre'))
1003 assert_equal('scriptnames', fullcommand('scr'))
1004 assert_equal('', fullcommand('scg'))
1005enddef
1006
Bram Moolenaar94738d82020-10-21 14:25:07 +02001007def Test_garbagecollect()
1008 garbagecollect(true)
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001009 CheckDefAndScriptFailure2(['garbagecollect("1")'], 'E1013: Argument 1: type mismatch, expected bool but got string', 'E1135: Using a String as a Bool')
1010 CheckDefAndScriptFailure2(['garbagecollect(20)'], 'E1013: Argument 1: type mismatch, expected bool but got number', 'E1023: Using a Number as a Bool')
Bram Moolenaar94738d82020-10-21 14:25:07 +02001011enddef
1012
1013def Test_getbufinfo()
1014 var bufinfo = getbufinfo(bufnr())
1015 getbufinfo('%')->assert_equal(bufinfo)
1016
1017 edit Xtestfile1
1018 hide edit Xtestfile2
1019 hide enew
Bram Moolenaare0de1712020-12-02 17:36:54 +01001020 getbufinfo({bufloaded: true, buflisted: true, bufmodified: false})
Bram Moolenaar94738d82020-10-21 14:25:07 +02001021 ->len()->assert_equal(3)
1022 bwipe Xtestfile1 Xtestfile2
1023enddef
1024
1025def Test_getbufline()
1026 e SomeFile
1027 var buf = bufnr()
1028 e #
1029 var lines = ['aaa', 'bbb', 'ccc']
1030 setbufline(buf, 1, lines)
1031 getbufline('#', 1, '$')->assert_equal(lines)
Bram Moolenaare6e70a12020-10-22 18:23:38 +02001032 getbufline(-1, '$', '$')->assert_equal([])
1033 getbufline(-1, 1, '$')->assert_equal([])
Bram Moolenaar94738d82020-10-21 14:25:07 +02001034
1035 bwipe!
1036enddef
1037
1038def Test_getchangelist()
1039 new
1040 setline(1, 'some text')
1041 var changelist = bufnr()->getchangelist()
1042 getchangelist('%')->assert_equal(changelist)
1043 bwipe!
1044enddef
1045
1046def Test_getchar()
1047 while getchar(0)
1048 endwhile
1049 getchar(true)->assert_equal(0)
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001050 getchar(1)->assert_equal(0)
1051 CheckDefAndScriptFailure2(['getchar(2)'], 'E1013: Argument 1: type mismatch, expected bool but got number', 'E1023: Using a Number as a Bool')
1052 CheckDefAndScriptFailure2(['getchar("1")'], 'E1013: Argument 1: type mismatch, expected bool but got string', 'E1135: Using a String as a Bool')
1053enddef
1054
1055def Test_getcharpos()
1056 CheckDefAndScriptFailure2(['getcharpos(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1174: String required for argument 1')
1057 CheckDefAndScriptFailure2(['getcharpos(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
1058enddef
1059
1060def Test_getcharstr()
1061 CheckDefAndScriptFailure2(['getcharstr(2)'], 'E1013: Argument 1: type mismatch, expected bool but got number', 'E1023: Using a Number as a Bool')
1062 CheckDefAndScriptFailure2(['getcharstr("1")'], 'E1013: Argument 1: type mismatch, expected bool but got string', 'E1135: Using a String as a Bool')
Bram Moolenaar94738d82020-10-21 14:25:07 +02001063enddef
1064
Bram Moolenaar7ad67d12021-03-10 16:08:26 +01001065def Test_getenv()
1066 if getenv('does-not_exist') == ''
1067 assert_report('getenv() should return null')
1068 endif
1069 if getenv('does-not_exist') == null
1070 else
1071 assert_report('getenv() should return null')
1072 endif
1073 $SOMEENVVAR = 'some'
1074 assert_equal('some', getenv('SOMEENVVAR'))
1075 unlet $SOMEENVVAR
1076enddef
1077
Bram Moolenaar94738d82020-10-21 14:25:07 +02001078def Test_getcompletion()
1079 set wildignore=*.vim,*~
1080 var l = getcompletion('run', 'file', true)
1081 l->assert_equal([])
1082 set wildignore&
1083enddef
1084
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001085def Test_getcurpos()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001086 CheckDefFailure(['getcursorcharpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001087enddef
1088
1089def Test_getcursorcharpos()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001090 CheckDefFailure(['getcursorcharpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001091enddef
1092
1093def Test_getcwd()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001094 CheckDefFailure(['getcwd("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1095 CheckDefFailure(['getcwd("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1096 CheckDefFailure(['getcwd(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001097enddef
1098
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001099def Test_getfontname()
1100 CheckDefFailure(['getfontname(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1101enddef
1102
Bram Moolenaar7bb4e742020-12-09 12:41:50 +01001103def Test_getfperm()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +01001104 assert_equal('', getfperm(""))
1105 assert_equal('', getfperm(test_null_string()))
1106
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001107 CheckDefExecFailure(['echo getfperm(true)'], 'E1013:')
1108 CheckDefExecFailure(['echo getfperm(v:null)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +01001109enddef
1110
1111def Test_getfsize()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +01001112 assert_equal(-1, getfsize(""))
1113 assert_equal(-1, getfsize(test_null_string()))
1114
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001115 CheckDefExecFailure(['echo getfsize(true)'], 'E1013:')
1116 CheckDefExecFailure(['echo getfsize(v:null)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +01001117enddef
1118
1119def Test_getftime()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +01001120 assert_equal(-1, getftime(""))
1121 assert_equal(-1, getftime(test_null_string()))
1122
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001123 CheckDefExecFailure(['echo getftime(true)'], 'E1013:')
1124 CheckDefExecFailure(['echo getftime(v:null)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +01001125enddef
1126
1127def Test_getftype()
Bram Moolenaar2a9d5d32020-12-12 18:58:40 +01001128 assert_equal('', getftype(""))
1129 assert_equal('', getftype(test_null_string()))
1130
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001131 CheckDefExecFailure(['echo getftype(true)'], 'E1013:')
1132 CheckDefExecFailure(['echo getftype(v:null)'], 'E1013:')
Bram Moolenaar7bb4e742020-12-09 12:41:50 +01001133enddef
1134
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001135def Test_getjumplist()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001136 CheckDefFailure(['getjumplist("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1137 CheckDefFailure(['getjumplist("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1138 CheckDefFailure(['getjumplist(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001139enddef
1140
Bram Moolenaar0f1227f2021-07-11 16:01:58 +02001141def Test_getline()
1142 var lines =<< trim END
1143 new
1144 setline(1, ['hello', 'there', 'again'])
1145 assert_equal('hello', getline(1))
1146 assert_equal('hello', getline('.'))
1147
1148 normal 2Gvjv
1149 assert_equal('there', getline("'<"))
1150 assert_equal('again', getline("'>"))
1151 END
1152 CheckDefAndScriptSuccess(lines)
1153
1154 lines =<< trim END
1155 echo getline('1')
1156 END
1157 CheckDefExecAndScriptFailure(lines, 'E1209:')
1158enddef
1159
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001160def Test_getloclist()
1161 CheckDefAndScriptFailure2(['getloclist("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1162 CheckDefAndScriptFailure2(['getloclist(1, [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required')
1163enddef
1164
1165def Test_getloclist_return_type()
1166 var l = getloclist(1)
1167 l->assert_equal([])
1168
1169 var d = getloclist(1, {items: 0})
1170 d->assert_equal({items: []})
1171enddef
1172
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001173def Test_getmarklist()
1174 CheckDefFailure(['getmarklist([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
1175 assert_equal([], getmarklist(10000))
1176 assert_fails('getmarklist("a%b@#")', 'E94:')
1177enddef
1178
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001179def Test_getmatches()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001180 CheckDefFailure(['getmatches("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001181enddef
1182
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001183def Test_getpos()
1184 CheckDefFailure(['getpos(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1185 assert_equal([0, 1, 1, 0], getpos('.'))
Bram Moolenaar0f1227f2021-07-11 16:01:58 +02001186 CheckDefExecFailure(['getpos("a")'], 'E1209:')
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001187enddef
1188
1189def Test_getqflist()
1190 CheckDefFailure(['getqflist([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
1191 call assert_equal({}, getqflist({}))
1192enddef
1193
Bram Moolenaar94738d82020-10-21 14:25:07 +02001194def Test_getqflist_return_type()
1195 var l = getqflist()
1196 l->assert_equal([])
1197
Bram Moolenaare0de1712020-12-02 17:36:54 +01001198 var d = getqflist({items: 0})
1199 d->assert_equal({items: []})
Bram Moolenaar94738d82020-10-21 14:25:07 +02001200enddef
1201
1202def Test_getreg()
1203 var lines = ['aaa', 'bbb', 'ccc']
1204 setreg('a', lines)
1205 getreg('a', true, true)->assert_equal(lines)
Bram Moolenaar418a29f2021-02-10 22:23:41 +01001206 assert_fails('getreg("ab")', 'E1162:')
Bram Moolenaar94738d82020-10-21 14:25:07 +02001207enddef
1208
1209def Test_getreg_return_type()
1210 var s1: string = getreg('"')
1211 var s2: string = getreg('"', 1)
1212 var s3: list<string> = getreg('"', 1, 1)
1213enddef
1214
Bram Moolenaar418a29f2021-02-10 22:23:41 +01001215def Test_getreginfo()
1216 var text = 'abc'
1217 setreg('a', text)
1218 getreginfo('a')->assert_equal({regcontents: [text], regtype: 'v', isunnamed: false})
1219 assert_fails('getreginfo("ab")', 'E1162:')
1220enddef
1221
1222def Test_getregtype()
1223 var lines = ['aaa', 'bbb', 'ccc']
1224 setreg('a', lines)
1225 getregtype('a')->assert_equal('V')
1226 assert_fails('getregtype("ab")', 'E1162:')
1227enddef
1228
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001229def Test_gettabinfo()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001230 CheckDefFailure(['gettabinfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001231enddef
1232
1233def Test_gettagstack()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001234 CheckDefFailure(['gettagstack("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001235enddef
1236
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001237def Test_gettext()
1238 CheckDefFailure(['gettext(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1239 assert_equal('abc', gettext("abc"))
1240enddef
1241
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001242def Test_getwininfo()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001243 CheckDefFailure(['getwininfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001244enddef
1245
1246def Test_getwinpos()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001247 CheckDefFailure(['getwinpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001248enddef
1249
Bram Moolenaar94738d82020-10-21 14:25:07 +02001250def Test_glob()
1251 glob('runtest.vim', true, true, true)->assert_equal(['runtest.vim'])
1252enddef
1253
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001254def Test_glob2regpat()
1255 CheckDefFailure(['glob2regpat(null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
1256 assert_equal('^$', glob2regpat(''))
1257enddef
1258
Bram Moolenaar94738d82020-10-21 14:25:07 +02001259def Test_globpath()
1260 globpath('.', 'runtest.vim', true, true, true)->assert_equal(['./runtest.vim'])
1261enddef
1262
1263def Test_has()
1264 has('eval', true)->assert_equal(1)
1265enddef
1266
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001267def Test_has_key()
Bram Moolenaar1aeddeb2021-07-11 14:55:49 +02001268 var d = {123: 'xx'}
1269 assert_true(has_key(d, '123'))
1270 assert_true(has_key(d, 123))
1271 assert_false(has_key(d, 'x'))
1272 assert_false(has_key(d, 99))
1273
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001274 CheckDefAndScriptFailure2(['has_key([1, 2], "k")'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
1275 CheckDefAndScriptFailure2(['has_key({"a": 10}, ["a"])'], 'E1013: Argument 2: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
1276enddef
1277
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001278def Test_haslocaldir()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001279 CheckDefFailure(['haslocaldir("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1280 CheckDefFailure(['haslocaldir("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1281 CheckDefFailure(['haslocaldir(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001282enddef
1283
Bram Moolenaar94738d82020-10-21 14:25:07 +02001284def Test_hasmapto()
1285 hasmapto('foobar', 'i', true)->assert_equal(0)
1286 iabbrev foo foobar
1287 hasmapto('foobar', 'i', true)->assert_equal(1)
1288 iunabbrev foo
1289enddef
1290
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001291def Test_histadd()
1292 CheckDefFailure(['histadd(1, "x")'], 'E1013: Argument 1: type mismatch, expected string but got number')
1293 CheckDefFailure(['histadd(":", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
1294 histadd("search", 'skyblue')
1295 assert_equal('skyblue', histget('/', -1))
1296enddef
1297
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001298def Test_histget()
1299 CheckDefAndScriptFailure2(['histget(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
1300 CheckDefAndScriptFailure2(['histget("a", "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
1301enddef
1302
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001303def Test_histnr()
1304 CheckDefFailure(['histnr(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1305 assert_equal(-1, histnr('abc'))
1306enddef
1307
1308def Test_hlID()
1309 CheckDefFailure(['hlID(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1310 assert_equal(0, hlID('NonExistingHighlight'))
1311enddef
1312
1313def Test_hlexists()
1314 CheckDefFailure(['hlexists([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
1315 assert_equal(0, hlexists('NonExistingHighlight'))
1316enddef
1317
1318def Test_iconv()
1319 CheckDefFailure(['iconv(1, "from", "to")'], 'E1013: Argument 1: type mismatch, expected string but got number')
1320 CheckDefFailure(['iconv("abc", 10, "to")'], 'E1013: Argument 2: type mismatch, expected string but got number')
1321 CheckDefFailure(['iconv("abc", "from", 20)'], 'E1013: Argument 3: type mismatch, expected string but got number')
1322 assert_equal('abc', iconv('abc', 'fromenc', 'toenc'))
1323enddef
1324
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001325def Test_indent()
1326 CheckDefAndScriptFailure2(['indent([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E745: Using a List as a Number')
1327 CheckDefAndScriptFailure2(['indent(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1138: Using a Bool as a Number')
1328 assert_equal(0, indent(1))
1329enddef
1330
Bram Moolenaar94738d82020-10-21 14:25:07 +02001331def Test_index()
1332 index(['a', 'b', 'a', 'B'], 'b', 2, true)->assert_equal(3)
1333enddef
1334
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001335def Test_input()
1336 CheckDefFailure(['input(5)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1337 CheckDefAndScriptFailure2(['input(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
1338 CheckDefFailure(['input("p", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
1339 CheckDefAndScriptFailure2(['input("p", "q", 20)'], 'E1013: Argument 3: type mismatch, expected string but got number', 'E180: Invalid complete value')
1340enddef
1341
1342def Test_inputdialog()
1343 CheckDefFailure(['inputdialog(5)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1344 CheckDefAndScriptFailure2(['inputdialog(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
1345 CheckDefFailure(['inputdialog("p", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
1346 CheckDefFailure(['inputdialog("p", "q", 20)'], 'E1013: Argument 3: type mismatch, expected string but got number')
1347enddef
1348
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001349def Test_inputlist()
1350 CheckDefFailure(['inputlist(10)'], 'E1013: Argument 1: type mismatch, expected list<string> but got number')
1351 CheckDefFailure(['inputlist("abc")'], 'E1013: Argument 1: type mismatch, expected list<string> but got string')
1352 CheckDefFailure(['inputlist([1, 2, 3])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>')
1353 feedkeys("2\<CR>", 't')
1354 var r: number = inputlist(['a', 'b', 'c'])
1355 assert_equal(2, r)
1356enddef
1357
1358def Test_inputsecret()
1359 CheckDefFailure(['inputsecret(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1360 CheckDefFailure(['inputsecret("Pass:", 20)'], 'E1013: Argument 2: type mismatch, expected string but got number')
1361 feedkeys("\<CR>", 't')
1362 var ans: string = inputsecret('Pass:', '123')
1363 assert_equal('123', ans)
1364enddef
1365
Bram Moolenaar193f6202020-11-16 20:08:35 +01001366let s:number_one = 1
1367let s:number_two = 2
1368let s:string_keep = 'keep'
1369
Bram Moolenaarca174532020-10-21 16:42:22 +02001370def Test_insert()
Bram Moolenaar94738d82020-10-21 14:25:07 +02001371 var l = insert([2, 1], 3)
1372 var res = 0
1373 for n in l
1374 res += n
1375 endfor
1376 res->assert_equal(6)
Bram Moolenaarca174532020-10-21 16:42:22 +02001377
Yegappan Lakshmanan34fcb692021-05-25 20:14:00 +02001378 var m: any = []
1379 insert(m, 4)
1380 call assert_equal([4], m)
1381 extend(m, [6], 0)
1382 call assert_equal([6, 4], m)
1383
Bram Moolenaar39211cb2021-04-18 15:48:04 +02001384 var lines =<< trim END
1385 insert(test_null_list(), 123)
1386 END
1387 CheckDefExecAndScriptFailure(lines, 'E1130:', 1)
1388
1389 lines =<< trim END
1390 insert(test_null_blob(), 123)
1391 END
1392 CheckDefExecAndScriptFailure(lines, 'E1131:', 1)
1393
Bram Moolenaarca174532020-10-21 16:42:22 +02001394 assert_equal([1, 2, 3], insert([2, 3], 1))
Bram Moolenaar193f6202020-11-16 20:08:35 +01001395 assert_equal([1, 2, 3], insert([2, 3], s:number_one))
Bram Moolenaarca174532020-10-21 16:42:22 +02001396 assert_equal([1, 2, 3], insert([1, 2], 3, 2))
Bram Moolenaar193f6202020-11-16 20:08:35 +01001397 assert_equal([1, 2, 3], insert([1, 2], 3, s:number_two))
Bram Moolenaarca174532020-10-21 16:42:22 +02001398 assert_equal(['a', 'b', 'c'], insert(['b', 'c'], 'a'))
1399 assert_equal(0z1234, insert(0z34, 0x12))
Bram Moolenaar193f6202020-11-16 20:08:35 +01001400
Yegappan Lakshmanan34fcb692021-05-25 20:14:00 +02001401 CheckDefFailure(['insert("a", 1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 1)
Bram Moolenaarca174532020-10-21 16:42:22 +02001402 CheckDefFailure(['insert([2, 3], "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 1)
1403 CheckDefFailure(['insert([2, 3], 1, "x")'], 'E1013: Argument 3: type mismatch, expected number but got string', 1)
Bram Moolenaar94738d82020-10-21 14:25:07 +02001404enddef
1405
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001406def Test_invert()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001407 CheckDefFailure(['invert("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001408enddef
1409
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001410def Test_isdirectory()
1411 CheckDefFailure(['isdirectory(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float')
1412 assert_false(isdirectory('NonExistingDir'))
1413enddef
1414
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001415def Test_islocked()
1416 CheckDefAndScriptFailure2(['islocked(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1174: String required for argument 1')
1417 CheckDefAndScriptFailure2(['var n1: number = 10', 'islocked(n1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
1418 g:v1 = 10
1419 assert_false(islocked('g:v1'))
1420 lockvar g:v1
1421 assert_true(islocked('g:v1'))
1422 unlet g:v1
1423enddef
1424
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001425def Test_items()
1426 CheckDefFailure(['[]->items()'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
1427 assert_equal([['a', 10], ['b', 20]], {'a': 10, 'b': 20}->items())
1428 assert_equal([], {}->items())
1429enddef
1430
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001431def Test_job_getchannel()
Dominique Pelle9ff9c7b2021-07-18 21:44:37 +02001432 if !has('job')
1433 CheckFeature job
1434 else
1435 CheckDefAndScriptFailure2(['job_getchannel("a")'], 'E1013: Argument 1: type mismatch, expected job but got string', 'E475: Invalid argument')
1436 assert_fails('job_getchannel(test_null_job())', 'E916: not a valid job')
1437 endif
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001438enddef
1439
1440def Test_job_info()
Dominique Pelle9ff9c7b2021-07-18 21:44:37 +02001441 if !has('job')
1442 CheckFeature job
1443 else
1444 CheckDefAndScriptFailure2(['job_info("a")'], 'E1013: Argument 1: type mismatch, expected job but got string', 'E475: Invalid argument')
1445 assert_fails('job_info(test_null_job())', 'E916: not a valid job')
1446 endif
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001447enddef
1448
1449def Test_job_info_return_type()
Dominique Pelle9ff9c7b2021-07-18 21:44:37 +02001450 if !has('job')
1451 CheckFeature job
1452 else
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001453 job_start(&shell)
1454 var jobs = job_info()
1455 assert_equal('list<job>', typename(jobs))
1456 assert_equal('dict<any>', typename(job_info(jobs[0])))
1457 job_stop(jobs[0])
1458 endif
1459enddef
1460
1461def Test_job_status()
Dominique Pelle9ff9c7b2021-07-18 21:44:37 +02001462 if !has('job')
1463 CheckFeature job
1464 else
1465 CheckDefAndScriptFailure2(['job_status("a")'], 'E1013: Argument 1: type mismatch, expected job but got string', 'E475: Invalid argument')
1466 assert_equal('fail', job_status(test_null_job()))
1467 endif
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001468enddef
1469
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001470def Test_js_decode()
1471 CheckDefFailure(['js_decode(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1472 assert_equal([1, 2], js_decode('[1,2]'))
1473enddef
1474
1475def Test_json_decode()
1476 CheckDefFailure(['json_decode(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
1477 assert_equal(1.0, json_decode('1.0'))
1478enddef
1479
1480def Test_keys()
1481 CheckDefFailure(['keys([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
1482 assert_equal(['a'], {a: 'v'}->keys())
1483 assert_equal([], {}->keys())
1484enddef
1485
Bram Moolenaar94738d82020-10-21 14:25:07 +02001486def Test_keys_return_type()
Bram Moolenaare0de1712020-12-02 17:36:54 +01001487 const var: list<string> = {a: 1, b: 2}->keys()
Bram Moolenaar94738d82020-10-21 14:25:07 +02001488 var->assert_equal(['a', 'b'])
1489enddef
1490
Bram Moolenaarc5809432021-03-27 21:23:30 +01001491def Test_line()
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001492 assert_fails('line(true)', 'E1174:')
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001493 CheckDefAndScriptFailure2(['line(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
1494 CheckDefAndScriptFailure2(['line(".", "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001495enddef
1496
1497def Test_line2byte()
1498 CheckDefFailure(['line2byte(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
1499 assert_equal(-1, line2byte(1))
1500 assert_equal(-1, line2byte(10000))
1501enddef
1502
1503def Test_lispindent()
1504 CheckDefFailure(['lispindent({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>')
1505 assert_equal(0, lispindent(1))
Bram Moolenaarc5809432021-03-27 21:23:30 +01001506enddef
1507
Bram Moolenaar94738d82020-10-21 14:25:07 +02001508def Test_list2str_str2list_utf8()
1509 var s = "\u3042\u3044"
1510 var l = [0x3042, 0x3044]
1511 str2list(s, true)->assert_equal(l)
1512 list2str(l, true)->assert_equal(s)
1513enddef
1514
1515def SID(): number
1516 return expand('<SID>')
1517 ->matchstr('<SNR>\zs\d\+\ze_$')
1518 ->str2nr()
1519enddef
1520
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001521def Test_listener_flush()
1522 CheckDefAndScriptFailure2(['listener_flush([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
1523enddef
1524
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001525def Test_listener_remove()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001526 CheckDefAndScriptFailure2(['listener_remove("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001527enddef
1528
Bram Moolenaar70250fb2021-01-16 19:01:53 +01001529def Test_map_function_arg()
1530 var lines =<< trim END
1531 def MapOne(i: number, v: string): string
1532 return i .. ':' .. v
1533 enddef
1534 var l = ['a', 'b', 'c']
1535 map(l, MapOne)
1536 assert_equal(['0:a', '1:b', '2:c'], l)
1537 END
1538 CheckDefAndScriptSuccess(lines)
Bram Moolenaar8da6d6d2021-06-05 18:15:09 +02001539
1540 lines =<< trim END
1541 range(3)->map((a, b, c) => a + b + c)
1542 END
1543 CheckDefExecAndScriptFailure(lines, 'E1190: One argument too few')
1544 lines =<< trim END
1545 range(3)->map((a, b, c, d) => a + b + c + d)
1546 END
1547 CheckDefExecAndScriptFailure(lines, 'E1190: 2 arguments too few')
Bram Moolenaar70250fb2021-01-16 19:01:53 +01001548enddef
1549
1550def Test_map_item_type()
1551 var lines =<< trim END
1552 var l = ['a', 'b', 'c']
1553 map(l, (k, v) => k .. '/' .. v )
1554 assert_equal(['0/a', '1/b', '2/c'], l)
1555 END
1556 CheckDefAndScriptSuccess(lines)
1557
1558 lines =<< trim END
1559 var l: list<number> = [0]
1560 echo map(l, (_, v) => [])
1561 END
1562 CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2)
1563
1564 lines =<< trim END
1565 var l: list<number> = range(2)
1566 echo map(l, (_, v) => [])
1567 END
1568 CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2)
1569
1570 lines =<< trim END
1571 var d: dict<number> = {key: 0}
1572 echo map(d, (_, v) => [])
1573 END
1574 CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2)
1575enddef
1576
Bram Moolenaar94738d82020-10-21 14:25:07 +02001577def Test_maparg()
1578 var lnum = str2nr(expand('<sflnum>'))
1579 map foo bar
Bram Moolenaare0de1712020-12-02 17:36:54 +01001580 maparg('foo', '', false, true)->assert_equal({
Bram Moolenaar94738d82020-10-21 14:25:07 +02001581 lnum: lnum + 1,
1582 script: 0,
1583 mode: ' ',
1584 silent: 0,
1585 noremap: 0,
1586 lhs: 'foo',
1587 lhsraw: 'foo',
1588 nowait: 0,
1589 expr: 0,
1590 sid: SID(),
1591 rhs: 'bar',
1592 buffer: 0})
1593 unmap foo
1594enddef
1595
1596def Test_mapcheck()
1597 iabbrev foo foobar
1598 mapcheck('foo', 'i', true)->assert_equal('foobar')
1599 iunabbrev foo
1600enddef
1601
1602def Test_maparg_mapset()
1603 nnoremap <F3> :echo "hit F3"<CR>
1604 var mapsave = maparg('<F3>', 'n', false, true)
1605 mapset('n', false, mapsave)
1606
1607 nunmap <F3>
1608enddef
1609
Bram Moolenaar027c4ab2021-02-21 16:20:18 +01001610def Test_map_failure()
1611 CheckFeature job
1612
1613 var lines =<< trim END
1614 vim9script
1615 writefile([], 'Xtmpfile')
1616 silent e Xtmpfile
1617 var d = {[bufnr('%')]: {a: 0}}
1618 au BufReadPost * Func()
1619 def Func()
1620 if d->has_key('')
1621 endif
1622 eval d[expand('<abuf>')]->mapnew((_, v: dict<job>) => 0)
1623 enddef
1624 e
1625 END
1626 CheckScriptFailure(lines, 'E1013:')
1627 au! BufReadPost
1628 delete('Xtmpfile')
1629enddef
1630
Yegappan Lakshmanana9a7c0c2021-07-17 19:11:07 +02001631def Test_match()
1632 CheckDefAndScriptFailure2(['match(0z12, "p")'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1')
1633 CheckDefAndScriptFailure2(['match(["s"], [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E1174: String required for argument 2')
1634 CheckDefAndScriptFailure2(['match("s", "p", "q")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3')
1635 CheckDefAndScriptFailure2(['match("s", "p", 1, "r")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4')
1636 assert_equal(2, match('ab12cd', '12'))
1637 assert_equal(-1, match('ab12cd', '34'))
1638 assert_equal(6, match('ab12cd12ef', '12', 4))
1639 assert_equal(2, match('abcd', '..', 0, 3))
1640 assert_equal(1, match(['a', 'b', 'c'], 'b'))
1641 assert_equal(-1, match(['a', 'b', 'c'], 'd'))
1642 assert_equal(3, match(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2))
1643 assert_equal(5, match(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2, 2))
1644enddef
1645
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001646def Test_matcharg()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001647 CheckDefFailure(['matcharg("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001648enddef
1649
1650def Test_matchdelete()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001651 CheckDefFailure(['matchdelete("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
1652 CheckDefFailure(['matchdelete("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1653 CheckDefFailure(['matchdelete(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001654enddef
1655
Yegappan Lakshmanana9a7c0c2021-07-17 19:11:07 +02001656def Test_matchend()
1657 CheckDefAndScriptFailure2(['matchend(0z12, "p")'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1')
1658 CheckDefAndScriptFailure2(['matchend(["s"], [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E1174: String required for argument 2')
1659 CheckDefAndScriptFailure2(['matchend("s", "p", "q")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3')
1660 CheckDefAndScriptFailure2(['matchend("s", "p", 1, "r")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4')
1661 assert_equal(4, matchend('ab12cd', '12'))
1662 assert_equal(-1, matchend('ab12cd', '34'))
1663 assert_equal(8, matchend('ab12cd12ef', '12', 4))
1664 assert_equal(4, matchend('abcd', '..', 0, 3))
1665 assert_equal(1, matchend(['a', 'b', 'c'], 'b'))
1666 assert_equal(-1, matchend(['a', 'b', 'c'], 'd'))
1667 assert_equal(3, matchend(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2))
1668 assert_equal(5, matchend(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2, 2))
1669enddef
1670
1671def Test_matchlist()
1672 CheckDefAndScriptFailure2(['matchlist(0z12, "p")'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1')
1673 CheckDefAndScriptFailure2(['matchlist(["s"], [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E1174: String required for argument 2')
1674 CheckDefAndScriptFailure2(['matchlist("s", "p", "q")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3')
1675 CheckDefAndScriptFailure2(['matchlist("s", "p", 1, "r")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4')
1676 var l: list<string> = ['12', '', '', '', '', '', '', '', '', '']
1677 assert_equal(l, matchlist('ab12cd', '12'))
1678 assert_equal([], matchlist('ab12cd', '34'))
1679 assert_equal(l, matchlist('ab12cd12ef', '12', 4))
1680 l[0] = 'cd'
1681 assert_equal(l, matchlist('abcd', '..', 0, 3))
1682 l[0] = 'b'
1683 assert_equal(l, matchlist(['a', 'b', 'c'], 'b'))
1684 assert_equal([], matchlist(['a', 'b', 'c'], 'd'))
1685 assert_equal(l, matchlist(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2))
1686 assert_equal(l, matchlist(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2, 2))
1687enddef
1688
1689def Test_matchstr()
1690 CheckDefAndScriptFailure2(['matchstr(0z12, "p")'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1')
1691 CheckDefAndScriptFailure2(['matchstr(["s"], [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E1174: String required for argument 2')
1692 CheckDefAndScriptFailure2(['matchstr("s", "p", "q")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3')
1693 CheckDefAndScriptFailure2(['matchstr("s", "p", 1, "r")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4')
1694 assert_equal('12', matchstr('ab12cd', '12'))
1695 assert_equal('', matchstr('ab12cd', '34'))
1696 assert_equal('12', matchstr('ab12cd12ef', '12', 4))
1697 assert_equal('cd', matchstr('abcd', '..', 0, 3))
1698 assert_equal('b', matchstr(['a', 'b', 'c'], 'b'))
1699 assert_equal('', matchstr(['a', 'b', 'c'], 'd'))
1700 assert_equal('b', matchstr(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2))
1701 assert_equal('b', matchstr(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2, 2))
1702enddef
1703
1704def Test_matchstrpos()
1705 CheckDefAndScriptFailure2(['matchstrpos(0z12, "p")'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1')
1706 CheckDefAndScriptFailure2(['matchstrpos(["s"], [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E1174: String required for argument 2')
1707 CheckDefAndScriptFailure2(['matchstrpos("s", "p", "q")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3')
1708 CheckDefAndScriptFailure2(['matchstrpos("s", "p", 1, "r")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4')
1709 assert_equal(['12', 2, 4], matchstrpos('ab12cd', '12'))
1710 assert_equal(['', -1, -1], matchstrpos('ab12cd', '34'))
1711 assert_equal(['12', 6, 8], matchstrpos('ab12cd12ef', '12', 4))
1712 assert_equal(['cd', 2, 4], matchstrpos('abcd', '..', 0, 3))
1713 assert_equal(['b', 1, 0, 1], matchstrpos(['a', 'b', 'c'], 'b'))
1714 assert_equal(['', -1, -1, -1], matchstrpos(['a', 'b', 'c'], 'd'))
1715 assert_equal(['b', 3, 0, 1],
1716 matchstrpos(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2))
1717 assert_equal(['b', 5, 0, 1],
1718 matchstrpos(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2, 2))
1719enddef
1720
Bram Moolenaar9ae37052021-01-22 22:31:10 +01001721def Test_max()
1722 g:flag = true
1723 var l1: list<number> = g:flag
1724 ? [1, max([2, 3])]
1725 : [4, 5]
1726 assert_equal([1, 3], l1)
1727
1728 g:flag = false
1729 var l2: list<number> = g:flag
1730 ? [1, max([2, 3])]
1731 : [4, 5]
1732 assert_equal([4, 5], l2)
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001733 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 Moolenaar9ae37052021-01-22 22:31:10 +01001734enddef
1735
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001736def Test_menu_info()
1737 CheckDefFailure(['menu_info(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
1738 CheckDefFailure(['menu_info(10, "n")'], 'E1013: Argument 1: type mismatch, expected string but got number')
1739 CheckDefFailure(['menu_info("File", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
1740 assert_equal({}, menu_info('aMenu'))
1741enddef
1742
Bram Moolenaar9ae37052021-01-22 22:31:10 +01001743def Test_min()
1744 g:flag = true
1745 var l1: list<number> = g:flag
1746 ? [1, min([2, 3])]
1747 : [4, 5]
1748 assert_equal([1, 2], l1)
1749
1750 g:flag = false
1751 var l2: list<number> = g:flag
1752 ? [1, min([2, 3])]
1753 : [4, 5]
1754 assert_equal([4, 5], l2)
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001755 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 Moolenaar9ae37052021-01-22 22:31:10 +01001756enddef
1757
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001758def Test_mkdir()
1759 CheckDefAndScriptFailure2(['mkdir(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
1760 CheckDefAndScriptFailure2(['mkdir("a", {})'], 'E1013: Argument 2: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String')
1761 CheckDefAndScriptFailure2(['mkdir("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1762 delete('a', 'rf')
1763enddef
1764
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001765def Test_mode()
1766 CheckDefFailure(['mode("1")'], 'E1013: Argument 1: type mismatch, expected bool but got string')
1767 CheckDefFailure(['mode(2)'], 'E1013: Argument 1: type mismatch, expected bool but got number')
1768enddef
1769
1770def Test_mzeval()
1771 if !has('mzscheme')
1772 CheckFeature mzscheme
1773 endif
Bram Moolenaar20c370d2021-07-16 10:39:28 +02001774 CheckDefAndScriptFailure2(['mzeval(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001775enddef
1776
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001777def Test_nextnonblank()
1778 CheckDefFailure(['nextnonblank(null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
1779 assert_equal(0, nextnonblank(1))
1780enddef
1781
Bram Moolenaar94738d82020-10-21 14:25:07 +02001782def Test_nr2char()
1783 nr2char(97, true)->assert_equal('a')
1784enddef
1785
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001786def Test_or()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001787 CheckDefFailure(['or("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string')
1788 CheckDefFailure(['or(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
1789enddef
1790
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001791def Test_pathshorten()
1792 CheckDefAndScriptFailure2(['pathshorten(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
1793 CheckDefAndScriptFailure2(['pathshorten("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
1794enddef
1795
1796def Test_perleval()
1797 if !has('perl')
1798 CheckFeature perl
1799 endif
1800 CheckDefAndScriptFailure2(['perleval(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
1801enddef
1802
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02001803def Test_popup_atcursor()
1804 CheckDefAndScriptFailure2(['popup_atcursor({"a": 10}, {})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E450: buffer number, text or a list required')
1805 CheckDefAndScriptFailure2(['popup_atcursor("a", [1, 2])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
Yegappan Lakshmanan841e4982021-07-11 22:04:25 +02001806
1807 # Pass variable of type 'any' to popup_atcursor()
1808 var what: any = 'Hello'
1809 var popupID = what->popup_atcursor({moved: 'any'})
1810 assert_equal(0, popupID->popup_getoptions().tabpage)
1811 popupID->popup_close()
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02001812enddef
1813
1814def Test_popup_beval()
1815 CheckDefAndScriptFailure2(['popup_beval({"a": 10}, {})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E450: buffer number, text or a list required')
1816 CheckDefAndScriptFailure2(['popup_beval("a", [1, 2])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
1817enddef
1818
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001819def Test_popup_clear()
1820 CheckDefAndScriptFailure2(['popup_clear(["a"])'], 'E1013: Argument 1: type mismatch, expected bool but got list<string>', 'E745: Using a List as a Number')
1821 CheckDefAndScriptFailure2(['popup_clear(2)'], 'E1013: Argument 1: type mismatch, expected bool but got number', 'E1023: Using a Number as a Bool')
1822enddef
1823
Yegappan Lakshmanan841e4982021-07-11 22:04:25 +02001824def Test_popup_create()
1825 # Pass variable of type 'any' to popup_create()
1826 var what: any = 'Hello'
1827 var popupID = what->popup_create({})
1828 assert_equal(0, popupID->popup_getoptions().tabpage)
1829 popupID->popup_close()
1830enddef
1831
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02001832def Test_popup_dialog()
1833 CheckDefAndScriptFailure2(['popup_dialog({"a": 10}, {})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E450: buffer number, text or a list required')
1834 CheckDefAndScriptFailure2(['popup_dialog("a", [1, 2])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
1835enddef
1836
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001837def Test_popup_filter_menu()
1838 CheckDefAndScriptFailure2(['popup_filter_menu("x", "")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
1839 CheckDefAndScriptFailure2(['popup_filter_menu(1, 1)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
1840enddef
1841
1842def Test_popup_filter_yesno()
1843 CheckDefAndScriptFailure2(['popup_filter_yesno("x", "")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
1844 CheckDefAndScriptFailure2(['popup_filter_yesno(1, 1)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
1845enddef
1846
1847def Test_popup_getoptions()
1848 CheckDefAndScriptFailure2(['popup_getoptions("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1849 CheckDefAndScriptFailure2(['popup_getoptions(true)'], 'E1013: Argument 1: type mismatch, expected number but got bool', 'E1138: Using a Bool as a Number')
1850enddef
1851
1852def Test_popup_getpos()
1853 CheckDefAndScriptFailure2(['popup_getpos("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1854 CheckDefAndScriptFailure2(['popup_getpos(true)'], 'E1013: Argument 1: type mismatch, expected number but got bool', 'E1138: Using a Bool as a Number')
1855enddef
1856
1857def Test_popup_hide()
1858 CheckDefAndScriptFailure2(['popup_hide("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1859 CheckDefAndScriptFailure2(['popup_hide(true)'], 'E1013: Argument 1: type mismatch, expected number but got bool', 'E1138: Using a Bool as a Number')
1860enddef
1861
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001862def Test_popup_locate()
1863 CheckDefAndScriptFailure2(['popup_locate("a", 20)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1864 CheckDefAndScriptFailure2(['popup_locate(10, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02001865enddef
1866
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02001867def Test_popup_menu()
1868 CheckDefAndScriptFailure2(['popup_menu({"a": 10}, {})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E450: buffer number, text or a list required')
1869 CheckDefAndScriptFailure2(['popup_menu("a", [1, 2])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
1870enddef
1871
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001872def Test_popup_move()
1873 CheckDefAndScriptFailure2(['popup_move("x", {})'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
1874 CheckDefAndScriptFailure2(['popup_move(1, [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 2')
1875enddef
1876
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02001877def Test_popup_notification()
1878 CheckDefAndScriptFailure2(['popup_notification({"a": 10}, {})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E450: buffer number, text or a list required')
1879 CheckDefAndScriptFailure2(['popup_notification("a", [1, 2])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
1880enddef
1881
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001882def Test_popup_setoptions()
1883 CheckDefAndScriptFailure2(['popup_setoptions("x", {})'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
1884 CheckDefAndScriptFailure2(['popup_setoptions(1, [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 2')
1885enddef
1886
1887def Test_popup_show()
1888 CheckDefAndScriptFailure2(['popup_show("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1889 CheckDefAndScriptFailure2(['popup_show(true)'], 'E1013: Argument 1: type mismatch, expected number but got bool', 'E1138: Using a Bool as a Number')
1890enddef
1891
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001892def Test_prevnonblank()
1893 CheckDefFailure(['prevnonblank(null)'], 'E1013: Argument 1: type mismatch, expected string but got special')
1894 assert_equal(0, prevnonblank(1))
1895enddef
1896
1897def Test_prompt_getprompt()
Dominique Pelle9ff9c7b2021-07-18 21:44:37 +02001898 if !has('channel')
1899 CheckFeature channel
1900 else
Dominique Pelle74509232021-07-03 19:27:37 +02001901 CheckDefFailure(['prompt_getprompt([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
1902 assert_equal('', prompt_getprompt('NonExistingBuf'))
1903 endif
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001904enddef
1905
Yegappan Lakshmanana9a7c0c2021-07-17 19:11:07 +02001906def Test_prompt_setprompt()
1907 if !has('channel')
1908 CheckFeature channel
1909 endif
1910 CheckDefAndScriptFailure2(['prompt_setprompt([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1')
1911 CheckDefAndScriptFailure2(['prompt_setprompt(1, [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2')
1912enddef
1913
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001914def Test_prop_find()
1915 CheckDefAndScriptFailure2(['prop_find([1, 2])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
1916 CheckDefAndScriptFailure2(['prop_find([1, 2], "k")'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
1917 CheckDefAndScriptFailure2(['prop_find({"a": 10}, ["a"])'], 'E1013: Argument 2: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
1918enddef
1919
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001920def Test_prop_list()
1921 CheckDefAndScriptFailure2(['prop_list("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
1922 CheckDefAndScriptFailure2(['prop_list(1, [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 2')
1923enddef
1924
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001925def Test_prop_type_add()
1926 CheckDefAndScriptFailure2(['prop_type_add({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
1927 CheckDefAndScriptFailure2(['prop_type_add("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required')
1928enddef
1929
1930def Test_prop_type_change()
1931 CheckDefAndScriptFailure2(['prop_type_change({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
1932 CheckDefAndScriptFailure2(['prop_type_change("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required')
1933enddef
1934
1935def Test_prop_type_delete()
1936 CheckDefAndScriptFailure2(['prop_type_delete({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
1937 CheckDefAndScriptFailure2(['prop_type_delete({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
1938 CheckDefAndScriptFailure2(['prop_type_delete("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required')
1939enddef
1940
1941def Test_prop_type_get()
1942 CheckDefAndScriptFailure2(['prop_type_get({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
1943 CheckDefAndScriptFailure2(['prop_type_get({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
1944 CheckDefAndScriptFailure2(['prop_type_get("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required')
1945enddef
1946
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02001947def Test_prop_type_list()
1948 CheckDefAndScriptFailure2(['prop_type_list(["a"])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<string>', 'E715: Dictionary required')
1949 CheckDefAndScriptFailure2(['prop_type_list(2)'], 'E1013: Argument 1: type mismatch, expected dict<any> but got number', 'E715: Dictionary required')
1950enddef
1951
1952def Test_py3eval()
1953 if !has('python3')
1954 CheckFeature python3
1955 endif
1956 CheckDefAndScriptFailure2(['py3eval([2])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
1957enddef
1958
1959def Test_pyeval()
1960 if !has('python')
1961 CheckFeature python
1962 endif
1963 CheckDefAndScriptFailure2(['pyeval([2])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
1964enddef
1965
1966def Test_pyxeval()
1967 if !has('python') && !has('python3')
1968 CheckFeature python
1969 endif
1970 CheckDefAndScriptFailure2(['pyxeval([2])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
1971enddef
1972
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02001973def Test_rand()
1974 CheckDefFailure(['rand(10)'], 'E1013: Argument 1: type mismatch, expected list<number> but got number')
1975 CheckDefFailure(['rand(["a"])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<string>')
1976 assert_true(rand() >= 0)
1977 assert_true(rand(srand()) >= 0)
1978enddef
1979
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02001980def Test_range()
1981 CheckDefAndScriptFailure2(['range("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1982 CheckDefAndScriptFailure2(['range(10, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1983 CheckDefAndScriptFailure2(['range(10, 20, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
1984enddef
1985
Bram Moolenaar94738d82020-10-21 14:25:07 +02001986def Test_readdir()
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01001987 eval expand('sautest')->readdir((e) => e[0] !=# '.')
1988 eval expand('sautest')->readdirex((e) => e.name[0] !=# '.')
Bram Moolenaar94738d82020-10-21 14:25:07 +02001989enddef
1990
Bram Moolenaarc423ad72021-01-13 20:38:03 +01001991def Test_readblob()
1992 var blob = 0z12341234
1993 writefile(blob, 'Xreadblob')
1994 var read: blob = readblob('Xreadblob')
1995 assert_equal(blob, read)
1996
1997 var lines =<< trim END
1998 var read: list<string> = readblob('Xreadblob')
1999 END
2000 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<string> but got blob', 1)
2001 delete('Xreadblob')
2002enddef
2003
2004def Test_readfile()
2005 var text = ['aaa', 'bbb', 'ccc']
2006 writefile(text, 'Xreadfile')
2007 var read: list<string> = readfile('Xreadfile')
2008 assert_equal(text, read)
2009
2010 var lines =<< trim END
2011 var read: dict<string> = readfile('Xreadfile')
2012 END
2013 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected dict<string> but got list<string>', 1)
2014 delete('Xreadfile')
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002015
2016 CheckDefAndScriptFailure2(['readfile("a", 0z10)'], 'E1013: Argument 2: type mismatch, expected string but got blob', 'E976: Using a Blob as a String')
2017 CheckDefAndScriptFailure2(['readfile("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
Bram Moolenaarc423ad72021-01-13 20:38:03 +01002018enddef
2019
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002020def Test_reltime()
Bram Moolenaarc816a2c2021-07-14 21:00:41 +02002021 CheckFeature reltime
2022
2023 CheckDefExecAndScriptFailure(['[]->reltime()'], 'E474:')
2024 CheckDefExecAndScriptFailure(['[]->reltime([])'], 'E474:')
2025
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002026 CheckDefFailure(['reltime("x")'], 'E1013: Argument 1: type mismatch, expected list<number> but got string')
2027 CheckDefFailure(['reltime(["x", "y"])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<string>')
2028 CheckDefFailure(['reltime([1, 2], 10)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number')
2029 CheckDefFailure(['reltime([1, 2], ["a", "b"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
2030 var start: list<any> = reltime()
2031 assert_true(type(reltime(start)) == v:t_list)
2032 var end: list<any> = reltime()
2033 assert_true(type(reltime(start, end)) == v:t_list)
2034enddef
2035
2036def Test_reltimefloat()
Bram Moolenaarc816a2c2021-07-14 21:00:41 +02002037 CheckFeature reltime
2038
2039 CheckDefExecAndScriptFailure(['[]->reltimefloat()'], 'E474:')
2040
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002041 CheckDefFailure(['reltimefloat("x")'], 'E1013: Argument 1: type mismatch, expected list<number> but got string')
2042 CheckDefFailure(['reltimefloat([1.1])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<float>')
2043 assert_true(type(reltimefloat(reltime())) == v:t_float)
2044enddef
2045
2046def Test_reltimestr()
Bram Moolenaarc816a2c2021-07-14 21:00:41 +02002047 CheckFeature reltime
2048
2049 CheckDefExecAndScriptFailure(['[]->reltimestr()'], 'E474:')
2050
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002051 CheckDefFailure(['reltimestr(true)'], 'E1013: Argument 1: type mismatch, expected list<number> but got bool')
2052 CheckDefFailure(['reltimestr([true])'], 'E1013: Argument 1: type mismatch, expected list<number> but got list<bool>')
2053 assert_true(type(reltimestr(reltime())) == v:t_string)
2054enddef
2055
2056def Test_remote_foreground()
2057 CheckFeature clientserver
2058 # remote_foreground() doesn't fail on MS-Windows
2059 CheckNotMSWindows
Bram Moolenaard6fa7bd2021-07-05 14:10:04 +02002060 CheckEnv DISPLAY
2061
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002062 CheckDefFailure(['remote_foreground(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2063 assert_fails('remote_foreground("NonExistingServer")', 'E241:')
2064enddef
2065
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002066def Test_remote_peek()
2067 CheckFeature clientserver
2068 CheckEnv DISPLAY
2069 CheckDefAndScriptFailure2(['remote_peek(0z10)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E976: Using a Blob as a String')
2070 CheckDefAndScriptFailure2(['remote_peek("a5b6c7", [1])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E573: Invalid server id used')
2071enddef
2072
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002073def Test_remote_read()
2074 CheckFeature clientserver
2075 CheckEnv DISPLAY
2076 CheckDefAndScriptFailure2(['remote_read(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
2077 CheckDefAndScriptFailure2(['remote_read("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
2078enddef
2079
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002080def Test_remote_startserver()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002081 CheckFeature clientserver
2082 CheckEnv DISPLAY
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002083 CheckDefFailure(['remote_startserver({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>')
2084enddef
2085
Bram Moolenaar94738d82020-10-21 14:25:07 +02002086def Test_remove_return_type()
Bram Moolenaare0de1712020-12-02 17:36:54 +01002087 var l = remove({one: [1, 2], two: [3, 4]}, 'one')
Bram Moolenaar94738d82020-10-21 14:25:07 +02002088 var res = 0
2089 for n in l
2090 res += n
2091 endfor
2092 res->assert_equal(3)
2093enddef
2094
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002095def Test_rename()
2096 CheckDefFailure(['rename(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number')
2097 CheckDefFailure(['rename("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number')
2098enddef
2099
2100def Test_resolve()
2101 CheckDefFailure(['resolve([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
2102 assert_equal('SomeFile', resolve('SomeFile'))
2103enddef
2104
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002105def Test_reverse()
2106 CheckDefAndScriptFailure2(['reverse(10)'], 'E1013: Argument 1: type mismatch, expected list<any> but got number', 'E899: Argument of reverse() must be a List or Blob')
2107 CheckDefAndScriptFailure2(['reverse("abc")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E899: Argument of reverse() must be a List or Blob')
2108enddef
2109
Bram Moolenaar94738d82020-10-21 14:25:07 +02002110def Test_reverse_return_type()
2111 var l = reverse([1, 2, 3])
2112 var res = 0
2113 for n in l
2114 res += n
2115 endfor
2116 res->assert_equal(6)
2117enddef
2118
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002119def Test_rubyeval()
2120 if !has('ruby')
2121 CheckFeature ruby
2122 endif
2123 CheckDefAndScriptFailure2(['rubyeval([2])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
2124enddef
2125
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002126def Test_screenattr()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002127 CheckDefFailure(['screenattr("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
2128 CheckDefFailure(['screenattr(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002129enddef
2130
2131def Test_screenchar()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002132 CheckDefFailure(['screenchar("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
2133 CheckDefFailure(['screenchar(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002134enddef
2135
2136def Test_screenchars()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002137 CheckDefFailure(['screenchars("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
2138 CheckDefFailure(['screenchars(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002139enddef
2140
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002141def Test_screenpos()
2142 CheckDefFailure(['screenpos("a", 1, 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
2143 CheckDefFailure(['screenpos(1, "b", 1)'], 'E1013: Argument 2: type mismatch, expected number but got string')
2144 CheckDefFailure(['screenpos(1, 1, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string')
2145 assert_equal({col: 1, row: 1, endcol: 1, curscol: 1}, screenpos(1, 1, 1))
2146enddef
2147
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002148def Test_screenstring()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002149 CheckDefFailure(['screenstring("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string')
2150 CheckDefFailure(['screenstring(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002151enddef
2152
Bram Moolenaar94738d82020-10-21 14:25:07 +02002153def Test_search()
2154 new
2155 setline(1, ['foo', 'bar'])
2156 var val = 0
2157 # skip expr returns boolean
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01002158 search('bar', 'W', 0, 0, () => val == 1)->assert_equal(2)
Bram Moolenaar94738d82020-10-21 14:25:07 +02002159 :1
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01002160 search('bar', 'W', 0, 0, () => val == 0)->assert_equal(0)
Bram Moolenaar94738d82020-10-21 14:25:07 +02002161 # skip expr returns number, only 0 and 1 are accepted
2162 :1
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01002163 search('bar', 'W', 0, 0, () => 0)->assert_equal(2)
Bram Moolenaar94738d82020-10-21 14:25:07 +02002164 :1
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01002165 search('bar', 'W', 0, 0, () => 1)->assert_equal(0)
2166 assert_fails("search('bar', '', 0, 0, () => -1)", 'E1023:')
2167 assert_fails("search('bar', '', 0, 0, () => -1)", 'E1023:')
Bram Moolenaarf06ab6b2021-05-07 19:44:21 +02002168
2169 setline(1, "find this word")
2170 normal gg
2171 var col = 7
2172 assert_equal(1, search('this', '', 0, 0, 'col(".") > col'))
2173 normal 0
2174 assert_equal([1, 6], searchpos('this', '', 0, 0, 'col(".") > col'))
2175
2176 col = 5
2177 normal 0
2178 assert_equal(0, search('this', '', 0, 0, 'col(".") > col'))
2179 normal 0
2180 assert_equal([0, 0], searchpos('this', '', 0, 0, 'col(".") > col'))
2181 bwipe!
Bram Moolenaar94738d82020-10-21 14:25:07 +02002182enddef
2183
2184def Test_searchcount()
2185 new
2186 setline(1, "foo bar")
2187 :/foo
Bram Moolenaare0de1712020-12-02 17:36:54 +01002188 searchcount({recompute: true})
2189 ->assert_equal({
Bram Moolenaar94738d82020-10-21 14:25:07 +02002190 exact_match: 1,
2191 current: 1,
2192 total: 1,
2193 maxcount: 99,
2194 incomplete: 0})
2195 bwipe!
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002196 CheckDefAndScriptFailure2(['searchcount([1])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
Bram Moolenaar94738d82020-10-21 14:25:07 +02002197enddef
2198
Bram Moolenaarf18332f2021-05-07 17:55:55 +02002199def Test_searchpair()
2200 new
2201 setline(1, "here { and } there")
Bram Moolenaarf06ab6b2021-05-07 19:44:21 +02002202
Bram Moolenaarf18332f2021-05-07 17:55:55 +02002203 normal f{
2204 var col = 15
2205 assert_equal(1, searchpair('{', '', '}', '', 'col(".") > col'))
2206 assert_equal(12, col('.'))
Bram Moolenaarf06ab6b2021-05-07 19:44:21 +02002207 normal 0f{
2208 assert_equal([1, 12], searchpairpos('{', '', '}', '', 'col(".") > col'))
2209
Bram Moolenaarf18332f2021-05-07 17:55:55 +02002210 col = 8
2211 normal 0f{
2212 assert_equal(0, searchpair('{', '', '}', '', 'col(".") > col'))
2213 assert_equal(6, col('.'))
Bram Moolenaarf06ab6b2021-05-07 19:44:21 +02002214 normal 0f{
2215 assert_equal([0, 0], searchpairpos('{', '', '}', '', 'col(".") > col'))
2216
Bram Moolenaarff652882021-05-16 15:24:49 +02002217 var lines =<< trim END
2218 vim9script
2219 setline(1, '()')
2220 normal gg
2221 def Fail()
2222 try
2223 searchpairpos('(', '', ')', 'nW', '[0]->map("")')
2224 catch
Bram Moolenaarcbe178e2021-05-18 17:49:59 +02002225 g:caught = 'yes'
Bram Moolenaarff652882021-05-16 15:24:49 +02002226 endtry
2227 enddef
2228 Fail()
2229 END
Bram Moolenaarcbe178e2021-05-18 17:49:59 +02002230 CheckScriptSuccess(lines)
2231 assert_equal('yes', g:caught)
Bram Moolenaarff652882021-05-16 15:24:49 +02002232
Bram Moolenaarcbe178e2021-05-18 17:49:59 +02002233 unlet g:caught
Bram Moolenaarf18332f2021-05-07 17:55:55 +02002234 bwipe!
2235enddef
2236
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002237def Test_server2client()
2238 CheckFeature clientserver
2239 CheckEnv DISPLAY
2240 CheckDefAndScriptFailure2(['server2client(10, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E573: Invalid server id used:')
2241 CheckDefAndScriptFailure2(['server2client("a", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E573: Invalid server id used:')
2242enddef
2243
Bram Moolenaar34453202021-01-31 13:08:38 +01002244def Test_set_get_bufline()
2245 # similar to Test_setbufline_getbufline()
2246 var lines =<< trim END
2247 new
2248 var b = bufnr('%')
2249 hide
2250 assert_equal(0, setbufline(b, 1, ['foo', 'bar']))
2251 assert_equal(['foo'], getbufline(b, 1))
2252 assert_equal(['bar'], getbufline(b, '$'))
2253 assert_equal(['foo', 'bar'], getbufline(b, 1, 2))
2254 exe "bd!" b
2255 assert_equal([], getbufline(b, 1, 2))
2256
2257 split Xtest
2258 setline(1, ['a', 'b', 'c'])
2259 b = bufnr('%')
2260 wincmd w
2261
2262 assert_equal(1, setbufline(b, 5, 'x'))
2263 assert_equal(1, setbufline(b, 5, ['x']))
2264 assert_equal(1, setbufline(b, 5, []))
2265 assert_equal(1, setbufline(b, 5, test_null_list()))
2266
2267 assert_equal(1, 'x'->setbufline(bufnr('$') + 1, 1))
2268 assert_equal(1, ['x']->setbufline(bufnr('$') + 1, 1))
2269 assert_equal(1, []->setbufline(bufnr('$') + 1, 1))
2270 assert_equal(1, test_null_list()->setbufline(bufnr('$') + 1, 1))
2271
2272 assert_equal(['a', 'b', 'c'], getbufline(b, 1, '$'))
2273
2274 assert_equal(0, setbufline(b, 4, ['d', 'e']))
2275 assert_equal(['c'], b->getbufline(3))
2276 assert_equal(['d'], getbufline(b, 4))
2277 assert_equal(['e'], getbufline(b, 5))
2278 assert_equal([], getbufline(b, 6))
2279 assert_equal([], getbufline(b, 2, 1))
2280
Bram Moolenaar00385112021-02-07 14:31:06 +01002281 if has('job')
Bram Moolenaar1328bde2021-06-05 20:51:38 +02002282 setbufline(b, 2, [function('eval'), {key: 123}, string(test_null_job())])
Bram Moolenaar00385112021-02-07 14:31:06 +01002283 assert_equal(["function('eval')",
2284 "{'key': 123}",
2285 "no process"],
2286 getbufline(b, 2, 4))
2287 endif
Bram Moolenaar34453202021-01-31 13:08:38 +01002288
2289 exe 'bwipe! ' .. b
2290 END
2291 CheckDefAndScriptSuccess(lines)
2292enddef
2293
Bram Moolenaar94738d82020-10-21 14:25:07 +02002294def Test_searchdecl()
2295 searchdecl('blah', true, true)->assert_equal(1)
2296enddef
2297
2298def Test_setbufvar()
2299 setbufvar(bufnr('%'), '&syntax', 'vim')
2300 &syntax->assert_equal('vim')
2301 setbufvar(bufnr('%'), '&ts', 16)
2302 &ts->assert_equal(16)
Bram Moolenaar31a201a2021-01-03 14:47:25 +01002303 setbufvar(bufnr('%'), '&ai', true)
2304 &ai->assert_equal(true)
2305 setbufvar(bufnr('%'), '&ft', 'filetype')
2306 &ft->assert_equal('filetype')
2307
Bram Moolenaar94738d82020-10-21 14:25:07 +02002308 settabwinvar(1, 1, '&syntax', 'vam')
2309 &syntax->assert_equal('vam')
2310 settabwinvar(1, 1, '&ts', 15)
2311 &ts->assert_equal(15)
2312 setlocal ts=8
Bram Moolenaarb0d81822021-01-03 15:55:10 +01002313 settabwinvar(1, 1, '&list', false)
2314 &list->assert_equal(false)
Bram Moolenaar31a201a2021-01-03 14:47:25 +01002315 settabwinvar(1, 1, '&list', true)
2316 &list->assert_equal(true)
2317 setlocal list&
Bram Moolenaar94738d82020-10-21 14:25:07 +02002318
2319 setbufvar('%', 'myvar', 123)
2320 getbufvar('%', 'myvar')->assert_equal(123)
2321enddef
2322
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002323def Test_setcharsearch()
2324 CheckDefFailure(['setcharsearch("x")'], 'E1013: Argument 1: type mismatch, expected dict<any> but got string')
2325 CheckDefFailure(['setcharsearch([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
2326 var d: dict<any> = {char: 'x', forward: 1, until: 1}
2327 setcharsearch(d)
2328 assert_equal(d, getcharsearch())
2329enddef
2330
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002331def Test_setcmdpos()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002332 CheckDefFailure(['setcmdpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002333enddef
2334
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002335def Test_setfperm()
2336 CheckDefFailure(['setfperm(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number')
2337 CheckDefFailure(['setfperm("a", 0z10)'], 'E1013: Argument 2: type mismatch, expected string but got blob')
2338enddef
2339
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002340def Test_setbufline()
2341 new
2342 var bnum = bufnr('%')
2343 :wincmd w
2344 setbufline(bnum, 1, range(1, 3))
2345 setbufline(bnum, 4, 'one')
2346 setbufline(bnum, 5, 10)
2347 setbufline(bnum, 6, ['two', 11])
2348 assert_equal(['1', '2', '3', 'one', '10', 'two', '11'], getbufline(bnum, 1, '$'))
2349 CheckDefFailure(['setbufline([1], 1, "x")'], 'E1013: Argument 1: type mismatch, expected string but got list<number>')
2350 CheckDefFailure(['setbufline(1, [1], "x")'], 'E1013: Argument 2: type mismatch, expected string but got list<number>')
2351 CheckDefFailure(['setbufline(1, 1, {"a": 10})'], 'E1013: Argument 3: type mismatch, expected string but got dict<number>')
2352 bnum->bufwinid()->win_gotoid()
2353 bw!
2354enddef
2355
2356def Test_setcellwidths()
2357 CheckDefAndScriptFailure2(['setcellwidths(1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got number', 'E714: List required')
2358 CheckDefAndScriptFailure2(['setcellwidths({"a": 10})'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<number>', 'E714: List required')
2359enddef
2360
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02002361def Test_setline()
2362 new
2363 setline(1, range(1, 4))
2364 assert_equal(['1', '2', '3', '4'], getline(1, '$'))
2365 setline(1, ['a', 'b', 'c', 'd'])
2366 assert_equal(['a', 'b', 'c', 'd'], getline(1, '$'))
2367 setline(1, 'one')
2368 assert_equal(['one', 'b', 'c', 'd'], getline(1, '$'))
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002369 setline(1, 10)
2370 assert_equal(['10', 'b', 'c', 'd'], getline(1, '$'))
2371 CheckDefAndScriptFailure2(['setline([1], "x")'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E745: Using a List as a Number')
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02002372 bw!
2373enddef
2374
Bram Moolenaar94738d82020-10-21 14:25:07 +02002375def Test_setloclist()
Bram Moolenaare0de1712020-12-02 17:36:54 +01002376 var items = [{filename: '/tmp/file', lnum: 1, valid: true}]
2377 var what = {items: items}
Bram Moolenaar94738d82020-10-21 14:25:07 +02002378 setqflist([], ' ', what)
2379 setloclist(0, [], ' ', what)
2380enddef
2381
2382def Test_setreg()
2383 setreg('a', ['aaa', 'bbb', 'ccc'])
2384 var reginfo = getreginfo('a')
2385 setreg('a', reginfo)
2386 getreginfo('a')->assert_equal(reginfo)
Bram Moolenaar418a29f2021-02-10 22:23:41 +01002387 assert_fails('setreg("ab", 0)', 'E1162:')
Bram Moolenaar94738d82020-10-21 14:25:07 +02002388enddef
2389
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002390def Test_sha256()
2391 CheckDefFailure(['sha256(100)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2392 CheckDefFailure(['sha256(0zABCD)'], 'E1013: Argument 1: type mismatch, expected string but got blob')
2393 assert_equal('ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad', sha256('abc'))
2394enddef
2395
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002396def Test_shiftwidth()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002397 CheckDefFailure(['shiftwidth("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2398enddef
2399
2400def Test_sign_define()
2401 CheckDefAndScriptFailure2(['sign_define({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
2402 CheckDefAndScriptFailure2(['sign_define({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
2403 CheckDefAndScriptFailure2(['sign_define("a", ["b"])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<string>', 'E715: Dictionary required')
2404enddef
2405
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002406def Test_sign_getdefined()
2407 CheckDefAndScriptFailure2(['sign_getdefined(["x"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E1174: String required for argument 1')
2408 CheckDefAndScriptFailure2(['sign_getdefined(2)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
2409enddef
2410
2411def Test_sign_placelist()
2412 CheckDefAndScriptFailure2(['sign_placelist("x")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E714: List required')
2413 CheckDefAndScriptFailure2(['sign_placelist({"a": 10})'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<number>', 'E714: List required')
2414enddef
2415
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002416def Test_sign_undefine()
2417 CheckDefAndScriptFailure2(['sign_undefine({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String')
2418 CheckDefAndScriptFailure2(['sign_undefine([1])'], 'E1013: Argument 1: type mismatch, expected list<string> but got list<number>', 'E155: Unknown sign:')
2419enddef
2420
2421def Test_sign_unplace()
2422 CheckDefAndScriptFailure2(['sign_unplace({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E474: Invalid argument')
2423 CheckDefAndScriptFailure2(['sign_unplace({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E474: Invalid argument')
2424 CheckDefAndScriptFailure2(['sign_unplace("a", ["b"])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<string>', 'E715: Dictionary required')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002425enddef
2426
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002427def Test_sign_unplacelist()
2428 CheckDefAndScriptFailure2(['sign_unplacelist("x")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E714: List required')
2429 CheckDefAndScriptFailure2(['sign_unplacelist({"a": 10})'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<number>', 'E714: List required')
2430enddef
2431
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002432def Test_simplify()
2433 CheckDefFailure(['simplify(100)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2434 call assert_equal('NonExistingFile', simplify('NonExistingFile'))
2435enddef
2436
Bram Moolenaar6601b622021-01-13 21:47:15 +01002437def Test_slice()
2438 assert_equal('12345', slice('012345', 1))
2439 assert_equal('123', slice('012345', 1, 4))
2440 assert_equal('1234', slice('012345', 1, -1))
2441 assert_equal('1', slice('012345', 1, -4))
2442 assert_equal('', slice('012345', 1, -5))
2443 assert_equal('', slice('012345', 1, -6))
2444
2445 assert_equal([1, 2, 3, 4, 5], slice(range(6), 1))
2446 assert_equal([1, 2, 3], slice(range(6), 1, 4))
2447 assert_equal([1, 2, 3, 4], slice(range(6), 1, -1))
2448 assert_equal([1], slice(range(6), 1, -4))
2449 assert_equal([], slice(range(6), 1, -5))
2450 assert_equal([], slice(range(6), 1, -6))
2451
2452 assert_equal(0z1122334455, slice(0z001122334455, 1))
2453 assert_equal(0z112233, slice(0z001122334455, 1, 4))
2454 assert_equal(0z11223344, slice(0z001122334455, 1, -1))
2455 assert_equal(0z11, slice(0z001122334455, 1, -4))
2456 assert_equal(0z, slice(0z001122334455, 1, -5))
2457 assert_equal(0z, slice(0z001122334455, 1, -6))
2458enddef
2459
Bram Moolenaar94738d82020-10-21 14:25:07 +02002460def Test_spellsuggest()
2461 if !has('spell')
Dominique Pelle9ff9c7b2021-07-18 21:44:37 +02002462 CheckFeature spell
Bram Moolenaar94738d82020-10-21 14:25:07 +02002463 else
2464 spellsuggest('marrch', 1, true)->assert_equal(['March'])
2465 endif
2466enddef
2467
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002468def Test_sound_stop()
2469 CheckFeature sound
2470 CheckDefFailure(['sound_stop("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2471enddef
2472
2473def Test_soundfold()
2474 CheckDefFailure(['soundfold(20)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2475 assert_equal('abc', soundfold('abc'))
2476enddef
2477
Bram Moolenaar94738d82020-10-21 14:25:07 +02002478def Test_sort_return_type()
2479 var res: list<number>
2480 res = [1, 2, 3]->sort()
2481enddef
2482
2483def Test_sort_argument()
Bram Moolenaar08cf0c02020-12-05 21:47:06 +01002484 var lines =<< trim END
2485 var res = ['b', 'a', 'c']->sort('i')
2486 res->assert_equal(['a', 'b', 'c'])
2487
2488 def Compare(a: number, b: number): number
2489 return a - b
2490 enddef
2491 var l = [3, 6, 7, 1, 8, 2, 4, 5]
2492 sort(l, Compare)
2493 assert_equal([1, 2, 3, 4, 5, 6, 7, 8], l)
2494 END
2495 CheckDefAndScriptSuccess(lines)
Bram Moolenaar94738d82020-10-21 14:25:07 +02002496enddef
2497
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002498def Test_spellbadword()
2499 CheckDefFailure(['spellbadword(100)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2500 spellbadword('good')->assert_equal(['', ''])
2501enddef
2502
Bram Moolenaar94738d82020-10-21 14:25:07 +02002503def Test_split()
2504 split(' aa bb ', '\W\+', true)->assert_equal(['', 'aa', 'bb', ''])
2505enddef
2506
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002507def Test_srand()
2508 CheckDefFailure(['srand("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2509 type(srand(100))->assert_equal(v:t_list)
2510enddef
2511
2512def Test_state()
2513 CheckDefFailure(['state({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>')
2514 assert_equal('', state('a'))
2515enddef
2516
Bram Moolenaar80ad3e22021-01-31 20:48:58 +01002517def Run_str2float()
2518 if !has('float')
Dominique Pelle9ff9c7b2021-07-18 21:44:37 +02002519 CheckFeature float
Bram Moolenaar80ad3e22021-01-31 20:48:58 +01002520 endif
2521 str2float("1.00")->assert_equal(1.00)
2522 str2float("2e-2")->assert_equal(0.02)
2523
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002524 CheckDefFailure(['str2float(123)'], 'E1013:')
Bram Moolenaar80ad3e22021-01-31 20:48:58 +01002525 CheckScriptFailure(['vim9script', 'echo str2float(123)'], 'E1024:')
2526 endif
2527enddef
2528
Yegappan Lakshmanana9a7c0c2021-07-17 19:11:07 +02002529def Test_str2list()
2530 CheckDefAndScriptFailure2(['str2list(10)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
2531 CheckDefAndScriptFailure2(['str2list("a", 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1211: Bool required for argument 2')
2532 assert_equal([97], str2list('a'))
2533 assert_equal([97], str2list('a', 1))
2534 assert_equal([97], str2list('a', true))
2535enddef
2536
Bram Moolenaar94738d82020-10-21 14:25:07 +02002537def Test_str2nr()
2538 str2nr("1'000'000", 10, true)->assert_equal(1000000)
Bram Moolenaarf2b26bc2021-01-30 23:05:11 +01002539
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002540 CheckDefFailure(['str2nr(123)'], 'E1013:')
Bram Moolenaarf2b26bc2021-01-30 23:05:11 +01002541 CheckScriptFailure(['vim9script', 'echo str2nr(123)'], 'E1024:')
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002542 CheckDefFailure(['str2nr("123", "x")'], 'E1013:')
Bram Moolenaarf2b26bc2021-01-30 23:05:11 +01002543 CheckScriptFailure(['vim9script', 'echo str2nr("123", "x")'], 'E1030:')
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002544 CheckDefFailure(['str2nr("123", 10, "x")'], 'E1013:')
Bram Moolenaarf2b26bc2021-01-30 23:05:11 +01002545 CheckScriptFailure(['vim9script', 'echo str2nr("123", 10, "x")'], 'E1135:')
Bram Moolenaar94738d82020-10-21 14:25:07 +02002546enddef
2547
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002548def Test_strcharlen()
2549 CheckDefAndScriptFailure2(['strcharlen([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
2550 "abc"->strcharlen()->assert_equal(3)
2551 strcharlen(99)->assert_equal(2)
2552enddef
2553
Bram Moolenaar94738d82020-10-21 14:25:07 +02002554def Test_strchars()
2555 strchars("A\u20dd", true)->assert_equal(1)
Yegappan Lakshmanana9a7c0c2021-07-17 19:11:07 +02002556 CheckDefAndScriptFailure2(['strchars(10)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
2557 CheckDefAndScriptFailure2(['strchars("a", 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1211: Bool required for argument 2')
2558 assert_equal(3, strchars('abc'))
2559 assert_equal(3, strchars('abc', 1))
2560 assert_equal(3, strchars('abc', true))
Bram Moolenaar94738d82020-10-21 14:25:07 +02002561enddef
2562
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002563def Test_strdisplaywidth()
2564 CheckDefAndScriptFailure2(['strdisplaywidth(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
2565 CheckDefAndScriptFailure2(['strdisplaywidth("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
2566enddef
2567
2568def Test_strftime()
2569 CheckDefAndScriptFailure2(['strftime(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
2570 CheckDefAndScriptFailure2(['strftime("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
2571enddef
2572
2573def Test_strgetchar()
2574 CheckDefAndScriptFailure2(['strgetchar(1, 1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
2575 CheckDefAndScriptFailure2(['strgetchar("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
2576enddef
2577
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002578def Test_stridx()
2579 CheckDefAndScriptFailure2(['stridx([1], "b")'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
2580 CheckDefAndScriptFailure2(['stridx("a", {})'], 'E1013: Argument 2: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String')
2581 CheckDefAndScriptFailure2(['stridx("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2582enddef
2583
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002584def Test_strlen()
2585 CheckDefFailure(['strlen([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
2586 "abc"->strlen()->assert_equal(3)
2587 strlen(99)->assert_equal(2)
2588enddef
2589
2590def Test_strptime()
2591 CheckFunction strptime
2592 CheckDefFailure(['strptime(10, "2021")'], 'E1013: Argument 1: type mismatch, expected string but got number')
2593 CheckDefFailure(['strptime("%Y", 2021)'], 'E1013: Argument 2: type mismatch, expected string but got number')
2594 # BUG: Directly calling strptime() in this function gives an "E117: Unknown
2595 # function" error on MS-Windows even with the above CheckFunction call for
2596 # strptime().
2597 #assert_true(strptime('%Y', '2021') != 0)
2598enddef
2599
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002600def Test_strridx()
2601 CheckDefAndScriptFailure2(['strridx([1], "b")'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
2602 CheckDefAndScriptFailure2(['strridx("a", {})'], 'E1013: Argument 2: type mismatch, expected string but got dict<unknown>', 'E731: Using a Dictionary as a String')
2603 CheckDefAndScriptFailure2(['strridx("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2604enddef
2605
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002606def Test_strtrans()
2607 CheckDefFailure(['strtrans(20)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2608 assert_equal('abc', strtrans('abc'))
2609enddef
2610
2611def Test_strwidth()
2612 CheckDefFailure(['strwidth(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2613 CheckScriptFailure(['vim9script', 'echo strwidth(10)'], 'E1024:')
2614 assert_equal(4, strwidth('abcd'))
2615enddef
2616
Bram Moolenaar94738d82020-10-21 14:25:07 +02002617def Test_submatch()
2618 var pat = 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)'
Bram Moolenaar75ab91f2021-01-10 22:42:50 +01002619 var Rep = () => range(10)->mapnew((_, v) => submatch(v, true))->string()
Bram Moolenaar94738d82020-10-21 14:25:07 +02002620 var actual = substitute('A123456789', pat, Rep, '')
2621 var expected = "[['A123456789'], ['1'], ['2'], ['3'], ['4'], ['5'], ['6'], ['7'], ['8'], ['9']]"
2622 actual->assert_equal(expected)
2623enddef
2624
Bram Moolenaar1328bde2021-06-05 20:51:38 +02002625def Test_substitute()
2626 var res = substitute('A1234', '\d', 'X', '')
2627 assert_equal('AX234', res)
2628
2629 if has('job')
2630 assert_fails('"text"->substitute(".*", () => job_start(":"), "")', 'E908: using an invalid value as a String: job')
2631 assert_fails('"text"->substitute(".*", () => job_start(":")->job_getchannel(), "")', 'E908: using an invalid value as a String: channel')
2632 endif
2633enddef
2634
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002635def Test_swapinfo()
2636 CheckDefFailure(['swapinfo({})'], 'E1013: Argument 1: type mismatch, expected string but got dict<unknown>')
2637 call assert_equal({error: 'Cannot open file'}, swapinfo('x'))
2638enddef
2639
2640def Test_swapname()
2641 CheckDefFailure(['swapname([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
2642 assert_fails('swapname("NonExistingBuf")', 'E94:')
2643enddef
2644
Bram Moolenaar94738d82020-10-21 14:25:07 +02002645def Test_synID()
2646 new
2647 setline(1, "text")
2648 synID(1, 1, true)->assert_equal(0)
2649 bwipe!
2650enddef
2651
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002652def Test_synIDtrans()
2653 CheckDefFailure(['synIDtrans("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2654enddef
2655
Yegappan Lakshmanana9a7c0c2021-07-17 19:11:07 +02002656def Test_synconcealed()
2657 CheckDefAndScriptFailure2(['synconcealed(0z10, 1)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1')
2658 CheckDefAndScriptFailure2(['synconcealed(1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
2659enddef
2660
2661def Test_synstack()
2662 CheckDefAndScriptFailure2(['synstack(0z10, 1)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1')
2663 CheckDefAndScriptFailure2(['synstack(1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
2664enddef
2665
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002666def Test_tabpagebuflist()
2667 CheckDefFailure(['tabpagebuflist("t")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2668 assert_equal([bufnr('')], tabpagebuflist())
2669 assert_equal([bufnr('')], tabpagebuflist(1))
2670enddef
2671
2672def Test_tabpagenr()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002673 CheckDefAndScriptFailure2(['tabpagenr(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E15: Invalid expression:')
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002674 assert_equal(1, tabpagenr('$'))
2675 assert_equal(1, tabpagenr())
2676enddef
2677
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002678def Test_tabpagewinnr()
2679 CheckDefAndScriptFailure2(['tabpagewinnr("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
2680 CheckDefAndScriptFailure2(['tabpagewinnr(1, 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
2681enddef
2682
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002683def Test_taglist()
2684 CheckDefAndScriptFailure2(['taglist([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
2685 CheckDefAndScriptFailure2(['taglist("a", [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E730: Using a List as a String')
2686enddef
2687
2688def Test_term_dumpload()
2689 CheckRunVimInTerminal
2690 CheckDefAndScriptFailure2(['term_dumpload({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E1174: String required for argument 1')
2691 CheckDefAndScriptFailure2(['term_dumpload({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E1174: String required for argument 1')
2692 CheckDefAndScriptFailure2(['term_dumpload("a", ["b"])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<string>', 'E1206: Dictionary required for argument 2')
2693enddef
2694
2695def Test_term_getaltscreen()
2696 CheckRunVimInTerminal
2697 CheckDefAndScriptFailure2(['term_getaltscreen(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool', 'E1138: Using a Bool as a Number')
2698enddef
2699
2700def Test_term_getansicolors()
2701 CheckRunVimInTerminal
Dominique Pelleee410522021-07-12 22:15:24 +02002702 CheckFeature termguicolors
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002703 CheckDefAndScriptFailure2(['term_getansicolors(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E745: Using a List as a Number')
2704enddef
2705
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002706def Test_term_getattr()
2707 CheckRunVimInTerminal
2708 CheckDefAndScriptFailure2(['term_getattr("x", "a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
2709 CheckDefAndScriptFailure2(['term_getattr(1, 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
2710enddef
2711
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002712def Test_term_getcursor()
2713 CheckRunVimInTerminal
2714 CheckDefAndScriptFailure2(['term_getcursor({"a": 10})'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E728: Using a Dictionary as a Number')
2715enddef
2716
2717def Test_term_getjob()
2718 CheckRunVimInTerminal
2719 CheckDefAndScriptFailure2(['term_getjob(0z10)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E974: Using a Blob as a Number')
2720enddef
2721
2722def Test_term_getscrolled()
2723 CheckRunVimInTerminal
2724 CheckDefAndScriptFailure2(['term_getscrolled(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E805: Using a Float as a Number')
2725enddef
2726
2727def Test_term_getsize()
2728 CheckRunVimInTerminal
2729 CheckDefAndScriptFailure2(['term_getsize(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E805: Using a Float as a Number')
2730enddef
2731
2732def Test_term_getstatus()
2733 CheckRunVimInTerminal
2734 CheckDefAndScriptFailure2(['term_getstatus(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E805: Using a Float as a Number')
2735enddef
2736
2737def Test_term_gettitle()
2738 CheckRunVimInTerminal
2739 CheckDefAndScriptFailure2(['term_gettitle(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E805: Using a Float as a Number')
2740enddef
2741
Bram Moolenaar94738d82020-10-21 14:25:07 +02002742def Test_term_gettty()
2743 if !has('terminal')
Dominique Pelle9ff9c7b2021-07-18 21:44:37 +02002744 CheckFeature terminal
Bram Moolenaar94738d82020-10-21 14:25:07 +02002745 else
2746 var buf = Run_shell_in_terminal({})
2747 term_gettty(buf, true)->assert_notequal('')
2748 StopShellInTerminal(buf)
2749 endif
2750enddef
2751
Yegappan Lakshmanana9a7c0c2021-07-17 19:11:07 +02002752def Test_term_sendkeys()
2753 CheckRunVimInTerminal
2754 CheckDefAndScriptFailure2(['term_sendkeys([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1')
2755 CheckDefAndScriptFailure2(['term_sendkeys(1, [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2')
2756enddef
2757
2758def Test_term_setapi()
2759 CheckRunVimInTerminal
2760 CheckDefAndScriptFailure2(['term_setapi([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1')
2761 CheckDefAndScriptFailure2(['term_setapi(1, [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2')
2762enddef
2763
2764def Test_term_setkill()
2765 CheckRunVimInTerminal
2766 CheckDefAndScriptFailure2(['term_setkill([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1')
2767 CheckDefAndScriptFailure2(['term_setkill(1, [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2')
2768enddef
2769
2770def Test_term_setrestore()
2771 CheckRunVimInTerminal
2772 CheckDefAndScriptFailure2(['term_setrestore([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1')
2773 CheckDefAndScriptFailure2(['term_setrestore(1, [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2')
2774enddef
Bram Moolenaar94738d82020-10-21 14:25:07 +02002775def Test_term_start()
2776 if !has('terminal')
Dominique Pelle9ff9c7b2021-07-18 21:44:37 +02002777 CheckFeature terminal
Bram Moolenaar94738d82020-10-21 14:25:07 +02002778 else
2779 botright new
2780 var winnr = winnr()
Bram Moolenaare0de1712020-12-02 17:36:54 +01002781 term_start(&shell, {curwin: true})
Bram Moolenaar94738d82020-10-21 14:25:07 +02002782 winnr()->assert_equal(winnr)
2783 bwipe!
2784 endif
2785enddef
2786
Yegappan Lakshmanana9a7c0c2021-07-17 19:11:07 +02002787def Test_term_wait()
2788 CheckRunVimInTerminal
2789 CheckDefAndScriptFailure2(['term_wait(0z10, 1)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1')
2790 CheckDefAndScriptFailure2(['term_wait(1, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
2791enddef
2792
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002793def Test_test_alloc_fail()
2794 CheckDefAndScriptFailure2(['test_alloc_fail("a", 10, 20)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E474: Invalid argument')
2795 CheckDefAndScriptFailure2(['test_alloc_fail(10, "b", 20)'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E474: Invalid argument')
2796 CheckDefAndScriptFailure2(['test_alloc_fail(10, 20, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E474: Invalid argument')
2797enddef
2798
2799def Test_test_feedinput()
2800 CheckDefAndScriptFailure2(['test_feedinput(test_void())'], 'E1013: Argument 1: type mismatch, expected string but got void', 'E1031: Cannot use void value')
2801 CheckDefAndScriptFailure2(['test_feedinput(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
2802enddef
2803
2804def Test_test_getvalue()
2805 CheckDefAndScriptFailure2(['test_getvalue(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E474: Invalid argument')
2806enddef
2807
2808def Test_test_ignore_error()
2809 CheckDefAndScriptFailure2(['test_ignore_error([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E474: Invalid argument')
2810 test_ignore_error('RESET')
2811enddef
2812
2813def Test_test_option_not_set()
2814 CheckDefAndScriptFailure2(['test_option_not_set([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E474: Invalid argument')
2815enddef
2816
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002817def Test_test_override()
2818 CheckDefAndScriptFailure2(['test_override(1, 1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
2819 CheckDefAndScriptFailure2(['test_override("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
2820enddef
2821
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002822def Test_test_setmouse()
2823 CheckDefAndScriptFailure2(['test_setmouse("a", 10)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E474: Invalid argument')
2824 CheckDefAndScriptFailure2(['test_setmouse(10, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E474: Invalid argument')
2825enddef
2826
2827def Test_test_settime()
2828 CheckDefAndScriptFailure2(['test_settime([1])'], 'E1013: Argument 1: type mismatch, expected number but got list<number>', 'E745: Using a List as a Number')
2829enddef
2830
2831def Test_test_srand_seed()
2832 CheckDefAndScriptFailure2(['test_srand_seed([1])'], 'E1013: Argument 1: type mismatch, expected number but got list<number>', 'E745: Using a List as a Number')
2833 CheckDefAndScriptFailure2(['test_srand_seed("10")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2834enddef
2835
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002836def Test_timer_info()
2837 CheckDefFailure(['timer_info("id")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2838 assert_equal([], timer_info(100))
2839 assert_equal([], timer_info())
2840enddef
2841
Bram Moolenaar94738d82020-10-21 14:25:07 +02002842def Test_timer_paused()
Bram Moolenaar2949cfd2020-12-31 21:28:47 +01002843 var id = timer_start(50, () => 0)
Bram Moolenaar94738d82020-10-21 14:25:07 +02002844 timer_pause(id, true)
2845 var info = timer_info(id)
2846 info[0]['paused']->assert_equal(1)
2847 timer_stop(id)
2848enddef
2849
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002850def Test_timer_stop()
2851 CheckDefFailure(['timer_stop("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2852 assert_equal(0, timer_stop(100))
2853enddef
2854
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002855def Test_tolower()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002856 CheckDefFailure(['tolower(1)'], 'E1013: Argument 1: type mismatch, expected string but got number')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002857enddef
2858
2859def Test_toupper()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002860 CheckDefFailure(['toupper(1)'], 'E1013: Argument 1: type mismatch, expected string but got number')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002861enddef
2862
2863def Test_tr()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002864 CheckDefFailure(['tr(1, "a", "b")'], 'E1013: Argument 1: type mismatch, expected string but got number')
2865 CheckDefFailure(['tr("a", 1, "b")'], 'E1013: Argument 2: type mismatch, expected string but got number')
2866 CheckDefFailure(['tr("a", "a", 1)'], 'E1013: Argument 3: type mismatch, expected string but got number')
2867enddef
2868
2869def Test_trim()
2870 CheckDefAndScriptFailure2(['trim(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
2871 CheckDefAndScriptFailure2(['trim("a", ["b"])'], 'E1013: Argument 2: type mismatch, expected string but got list<string>', 'E730: Using a List as a String')
2872 CheckDefAndScriptFailure2(['trim("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002873enddef
2874
Bram Moolenaar9da32e42021-07-09 19:53:57 +02002875def Test_typename()
2876 if has('float')
2877 assert_equal('func([unknown], [unknown]): float', typename(function('pow')))
2878 endif
2879enddef
2880
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002881def Test_undofile()
2882 CheckDefFailure(['undofile(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
2883 assert_equal('.abc.un~', fnamemodify(undofile('abc'), ':t'))
2884enddef
2885
2886def Test_values()
2887 CheckDefFailure(['values([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
2888 assert_equal([], {}->values())
2889 assert_equal(['sun'], {star: 'sun'}->values())
2890enddef
2891
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002892def Test_virtcol()
2893 CheckDefAndScriptFailure2(['virtcol(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1')
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02002894 new
2895 setline(1, ['abcdefgh'])
2896 cursor(1, 4)
2897 assert_equal(4, virtcol('.'))
Yegappan Lakshmanan841e4982021-07-11 22:04:25 +02002898 assert_equal(4, virtcol([1, 4]))
Yegappan Lakshmananc72bdd22021-07-11 19:44:18 +02002899 assert_equal(9, virtcol([1, '$']))
2900 assert_equal(0, virtcol([10, '$']))
2901 bw!
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002902enddef
2903
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002904def Test_visualmode()
2905 CheckDefFailure(['visualmode("1")'], 'E1013: Argument 1: type mismatch, expected bool but got string')
2906 CheckDefFailure(['visualmode(2)'], 'E1013: Argument 1: type mismatch, expected bool but got number')
2907enddef
2908
Bram Moolenaar37487e12021-01-12 22:08:53 +01002909def Test_win_execute()
2910 assert_equal("\n" .. winnr(), win_execute(win_getid(), 'echo winnr()'))
Bram Moolenaar52312242021-07-11 18:23:19 +02002911 assert_equal("\n" .. winnr(), 'echo winnr()'->win_execute(win_getid()))
2912 assert_equal("\n" .. winnr(), win_execute(win_getid(), 'echo winnr()', 'silent'))
Bram Moolenaar37487e12021-01-12 22:08:53 +01002913 assert_equal('', win_execute(342343, 'echo winnr()'))
2914enddef
2915
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002916def Test_win_findbuf()
2917 CheckDefFailure(['win_findbuf("a")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2918 assert_equal([], win_findbuf(1000))
2919 assert_equal([win_getid()], win_findbuf(bufnr('')))
2920enddef
2921
2922def Test_win_getid()
2923 CheckDefFailure(['win_getid(".")'], 'E1013: Argument 1: type mismatch, expected number but got string')
2924 CheckDefFailure(['win_getid(1, ".")'], 'E1013: Argument 2: type mismatch, expected number but got string')
2925 assert_equal(win_getid(), win_getid(1, 1))
2926enddef
2927
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002928def Test_win_gettype()
2929 CheckDefAndScriptFailure2(['win_gettype("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2930enddef
2931
2932def Test_win_gotoid()
2933 CheckDefAndScriptFailure2(['win_gotoid("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2934enddef
2935
2936def Test_win_id2tabwin()
2937 CheckDefAndScriptFailure2(['win_id2tabwin("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2938enddef
2939
2940def Test_win_id2win()
2941 CheckDefAndScriptFailure2(['win_id2win("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2942enddef
2943
2944def Test_win_screenpos()
2945 CheckDefAndScriptFailure2(['win_screenpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2946enddef
2947
Bram Moolenaar94738d82020-10-21 14:25:07 +02002948def Test_win_splitmove()
2949 split
Bram Moolenaare0de1712020-12-02 17:36:54 +01002950 win_splitmove(1, 2, {vertical: true, rightbelow: true})
Bram Moolenaar94738d82020-10-21 14:25:07 +02002951 close
2952enddef
2953
Yegappan Lakshmanan1a71d312021-07-15 12:49:58 +02002954def Test_winbufnr()
2955 CheckDefAndScriptFailure2(['winbufnr("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2956enddef
2957
2958def Test_winheight()
2959 CheckDefAndScriptFailure2(['winheight("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2960enddef
2961
2962def Test_winlayout()
2963 CheckDefAndScriptFailure2(['winlayout("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
2964enddef
2965
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002966def Test_winnr()
2967 CheckDefFailure(['winnr([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
2968 assert_equal(1, winnr())
2969 assert_equal(1, winnr('$'))
2970enddef
2971
Bram Moolenaar285b15f2020-12-29 20:25:19 +01002972def Test_winrestcmd()
2973 split
2974 var cmd = winrestcmd()
2975 wincmd _
2976 exe cmd
2977 assert_equal(cmd, winrestcmd())
2978 close
2979enddef
2980
Yegappan Lakshmanana26f56f2021-07-03 11:58:12 +02002981def Test_winrestview()
2982 CheckDefFailure(['winrestview([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
2983 :%d _
2984 setline(1, 'Hello World')
2985 winrestview({lnum: 1, col: 6})
2986 assert_equal([1, 7], [line('.'), col('.')])
2987enddef
2988
Bram Moolenaar43b69b32021-01-07 20:23:33 +01002989def Test_winsaveview()
2990 var view: dict<number> = winsaveview()
2991
2992 var lines =<< trim END
2993 var view: list<number> = winsaveview()
2994 END
2995 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<number> but got dict<number>', 1)
2996enddef
2997
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02002998def Test_winwidth()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02002999 CheckDefAndScriptFailure2(['winwidth("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02003000enddef
3001
3002def Test_xor()
Yegappan Lakshmanan5b739922021-07-10 13:15:41 +02003003 CheckDefAndScriptFailure2(['xor("x", 0x2)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
3004 CheckDefAndScriptFailure2(['xor(0x1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
Yegappan Lakshmanan7237cab2021-06-22 19:52:27 +02003005enddef
Bram Moolenaar94738d82020-10-21 14:25:07 +02003006
3007" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker